Move costs to after other precondition check

This commit is contained in:
fullwall 2021-07-16 23:23:57 +08:00
parent bc3df49775
commit 0ff3ee72e9

View File

@ -166,12 +166,13 @@ public class CommandTrait extends Trait {
public void dispatch(final Player player, final Hand hand) {
NPCCommandDispatchEvent event = new NPCCommandDispatchEvent(npc, player);
event.setCancelled(!checkPreconditions(player, hand));
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
Runnable task = new Runnable() {
boolean charged = false;
@Override
public void run() {
List<NPCCommand> commandList = Lists
@ -234,6 +235,10 @@ public class CommandTrait extends Trait {
if (info != null && !info.canUse(CommandTrait.this, player, command)) {
return;
}
if (!charged && !checkPreconditions(player, hand)) {
charged = true;
return;
}
PermissionAttachment attachment = player.addAttachment(CitizensAPI.getPlugin());
if (temporaryPermissions.size() > 0) {
for (String permission : temporaryPermissions) {