Fix itemcost, don't execute commands if cost not reached

This commit is contained in:
fullwall 2022-07-17 02:28:17 +08:00
parent bbf5ca9ebb
commit 674a621cf3
2 changed files with 14 additions and 11 deletions

View File

@ -1318,13 +1318,13 @@ public class NPCCommands {
if (args.argsLength() != 3) { if (args.argsLength() != 3) {
throw new CommandException(); throw new CommandException();
} }
Messaging.send(sender, npc.data().get(key, "null")); sender.sendMessage(npc.data().get(key, "null"));
} else if (command.equals("remove")) { } else if (command.equals("remove")) {
if (args.argsLength() != 3) { if (args.argsLength() != 3) {
throw new CommandException(); throw new CommandException();
} }
npc.data().remove(key); npc.data().remove(key);
Messaging.sendTr(sender, Messages.METADATA_UNSET, key); Messaging.sendTr(sender, Messages.METADATA_UNSET, key, npc.getName());
} else { } else {
throw new CommandUsageException(); throw new CommandUsageException();
} }

View File

@ -15,6 +15,7 @@ import org.bukkit.Material;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -34,6 +35,7 @@ import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.event.NPCCommandDispatchEvent; import net.citizensnpcs.api.event.NPCCommandDispatchEvent;
import net.citizensnpcs.api.gui.InventoryMenuPage; import net.citizensnpcs.api.gui.InventoryMenuPage;
import net.citizensnpcs.api.gui.InventoryMenuSlot;
import net.citizensnpcs.api.gui.Menu; import net.citizensnpcs.api.gui.Menu;
import net.citizensnpcs.api.gui.MenuContext; import net.citizensnpcs.api.gui.MenuContext;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
@ -194,7 +196,7 @@ public class CommandTrait extends Trait {
return; return;
} }
Runnable task = new Runnable() { Runnable task = new Runnable() {
boolean charged = false; Boolean charged = null;
@Override @Override
public void run() { public void run() {
@ -240,7 +242,7 @@ public class CommandTrait extends Trait {
} }
} }
runCommand(player, command); runCommand(player, command);
if (executionMode == ExecutionMode.SEQUENTIAL) { if (executionMode == ExecutionMode.SEQUENTIAL || charged == false) {
break; break;
} }
} }
@ -258,11 +260,12 @@ public class CommandTrait extends Trait {
if (info != null && !info.canUse(CommandTrait.this, player, command)) { if (info != null && !info.canUse(CommandTrait.this, player, command)) {
return; return;
} }
if (!charged) { if (charged == null) {
charged = true;
if (!chargeCommandCosts(player, hand)) { if (!chargeCommandCosts(player, hand)) {
charged = false;
return; return;
} }
charged = true;
} }
PermissionAttachment attachment = player.addAttachment(CitizensAPI.getPlugin()); PermissionAttachment attachment = player.addAttachment(CitizensAPI.getPlugin());
if (temporaryPermissions.size() > 0) { if (temporaryPermissions.size() > 0) {
@ -377,11 +380,6 @@ public class CommandTrait extends Trait {
} }
} }
public enum ErrorHandling {
ERROR_MESSAGE,
RUN_ANYWAY;
}
public enum ExecutionMode { public enum ExecutionMode {
LINEAR, LINEAR,
RANDOM, RANDOM,
@ -420,6 +418,11 @@ public class CommandTrait extends Trait {
} }
} }
@Override
public void onClick(InventoryMenuSlot slot, InventoryClickEvent event) {
event.setCancelled(false);
}
@Override @Override
public void onClose(HumanEntity player) { public void onClose(HumanEntity player) {
List<ItemStack> requirements = Lists.newArrayList(); List<ItemStack> requirements = Lists.newArrayList();