Fixed the asynchronous command dispatch issue. The issue was being thrown on PaperSpigot and its forks.

This commit is contained in:
Stefan923 2020-05-08 20:29:54 +03:00 committed by BrowkS
parent 868e7f4102
commit 5fb8d06d98

View File

@ -8,9 +8,11 @@ import com.massivecraft.factions.zcore.util.TL;
import com.massivecraft.factions.zcore.util.TagReplacer; import com.massivecraft.factions.zcore.util.TagReplacer;
import com.massivecraft.factions.zcore.util.TagUtil; import com.massivecraft.factions.zcore.util.TagUtil;
import mkremins.fanciful.FancyMessage; import mkremins.fanciful.FancyMessage;
import org.bukkit.scheduler.BukkitScheduler;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
public class CmdShow extends FCommand { public class CmdShow extends FCommand {
@ -24,17 +26,21 @@ public class CmdShow extends FCommand {
this.aliases.addAll(Aliases.show_show); this.aliases.addAll(Aliases.show_show);
// add defaults to /f show in case config doesnt have it // add defaults to /f show in case config doesnt have it
defaults.add("{header}"); defaults.add("&8&m--------------&7 &8<&e{faction}&8> &8&m--------------");
defaults.add("<a>Description: <i>{description}"); defaults.add("&4* &cOwner: &f{leader}");
defaults.add("<a>Joining: <i>{joining} {peaceful}"); defaults.add("&4* &cDescription: &f{description}");
defaults.add("<a>Land / Power / Maxpower: <i> {chunks} / {power} / {maxPower}"); defaults.add("&4* &cLand / Power / Max Power: &f{chunks} &8/ &f{power} &8/ &f{maxPower}");
defaults.add("<a>Founded: <i>{create-date}"); defaults.add("&4* &cFaction Strikes: &f{strikes}");
defaults.add("<a>This faction is permanent, remaining even with no members."); defaults.add("&4* &cFaction Points: &f{faction-points}");
defaults.add("<a>Land value: <i>{land-value} {land-refund}"); defaults.add("&4* &cFounded: &f{create-date}");
defaults.add("<a>Balance: <i>{faction-balance}"); defaults.add("&4* &cBalance: &f{faction-balance}");
defaults.add("<a>Allies(<i>{allies}<a>/<i>{max-allies}<a>): {allies-list}"); defaults.add("&4* &cAllies: &a{allies-list}");
defaults.add("<a>Online: (<i>{online}<a>/<i>{members}<a>): {online-list}"); defaults.add("&4* &cEnemies: &4{enemies-list}");
defaults.add("<a>Offline: (<i>{offline}<a>/<i>{members}<a>): {offline-list}"); defaults.add("&4* &cOnline Members: &8[&f{online}/{members}&8] &a{online-list}");
defaults.add("&4* &cOffline Members: &8[&f{offline}/{members}&8] &a{offline-list}");
defaults.add("&4* &cAlts: &f{alts}");
defaults.add("&4* &cBans: &f{faction-bancount}");
defaults.add("&8&m----------------------------------------");
// this.requiredArgs.add(""); // this.requiredArgs.add("");
this.optionalArgs.put("faction tag", "yours"); this.optionalArgs.put("faction tag", "yours");
@ -45,6 +51,7 @@ public class CmdShow extends FCommand {
@Override @Override
public void perform(CommandContext context) { public void perform(CommandContext context) {
Faction faction = context.faction; Faction faction = context.faction;
FactionsPlugin instance = FactionsPlugin.getInstance();
if (context.argIsSet(0)) if (context.argIsSet(0))
faction = context.argAsFaction(0); faction = context.argAsFaction(0);
@ -52,7 +59,7 @@ public class CmdShow extends FCommand {
return; return;
if (context.fPlayer != null && !context.player.getPlayer().hasPermission("factions.show.bypassexempt") if (context.fPlayer != null && !context.player.getPlayer().hasPermission("factions.show.bypassexempt")
&& FactionsPlugin.getInstance().getConfig().getStringList("show-exempt").contains(faction.getTag())) { && instance.getConfig().getStringList("show-exempt").contains(faction.getTag())) {
context.msg(TL.COMMAND_SHOW_EXEMPT); context.msg(TL.COMMAND_SHOW_EXEMPT);
return; return;
} }
@ -62,7 +69,7 @@ public class CmdShow extends FCommand {
return; return;
} }
List<String> show = FactionsPlugin.getInstance().getConfig().getStringList("show"); List<String> show = instance.getConfig().getStringList("show");
if (show == null || show.isEmpty()) if (show == null || show.isEmpty())
show = defaults; show = defaults;
@ -71,16 +78,17 @@ public class CmdShow extends FCommand {
// send header and that's all // send header and that's all
String header = show.get(0); String header = show.get(0);
if (TagReplacer.HEADER.contains(header)) { if (TagReplacer.HEADER.contains(header)) {
context.msg(FactionsPlugin.getInstance().txt.titleize(tag)); context.msg(instance.txt.titleize(tag));
} else { } else {
context.msg(FactionsPlugin.getInstance().txt.parse(TagReplacer.FACTION.replace(header, tag))); context.msg(instance.txt.parse(TagReplacer.FACTION.replace(header, tag)));
} }
return; // we only show header for non-normal factions return; // we only show header for non-normal factions
} }
List<String> finalShow = show; List<String> finalShow = show;
Faction finalFaction = faction; Faction finalFaction = faction;
FactionsPlugin.getInstance().getServer().getScheduler().runTaskAsynchronously(FactionsPlugin.instance, () -> { List<FancyMessage> fancy = new ArrayList<>();
instance.getServer().getScheduler().runTaskAsynchronously(instance, () -> {
for (String raw : finalShow) { for (String raw : finalShow) {
String parsed = TagUtil.parsePlain(finalFaction, context.fPlayer, raw); // use relations String parsed = TagUtil.parsePlain(finalFaction, context.fPlayer, raw); // use relations
if (parsed == null) { if (parsed == null) {
@ -92,9 +100,9 @@ public class CmdShow extends FCommand {
} }
if (TagUtil.hasFancy(parsed)) { if (TagUtil.hasFancy(parsed)) {
List<FancyMessage> fancy = TagUtil.parseFancy(finalFaction, context.fPlayer, parsed); List<FancyMessage> localFancy = TagUtil.parseFancy(finalFaction, context.fPlayer, parsed);
if (fancy != null) if (localFancy != null)
context.sendFancyMessage(fancy); fancy.addAll(localFancy);
continue; continue;
} }
@ -106,9 +114,12 @@ public class CmdShow extends FCommand {
if (parsed.contains("%")) { if (parsed.contains("%")) {
parsed = parsed.replaceAll("%", ""); // Just in case it got in there before we disallowed it. parsed = parsed.replaceAll("%", ""); // Just in case it got in there before we disallowed it.
} }
context.msg(FactionsPlugin.getInstance().txt.parse(parsed)); parsed = FactionsPlugin.getInstance().txt.parse(parsed);
FancyMessage localFancy = instance.txt.parseFancy(parsed);
fancy.add(localFancy);
} }
} }
instance.getServer().getScheduler().runTask(instance, () -> context.sendFancyMessage(fancy));
}); });
} }