From eed9170519755f0efa0cee5238cca16a563ac404 Mon Sep 17 00:00:00 2001 From: fullwall Date: Fri, 6 Jan 2023 23:34:47 +0800 Subject: [PATCH] Add op/server toggles to shop --- .../trait/shop/CommandAction.java | 22 +++++++++++++++++-- .../citizensnpcs/trait/shop/ItemAction.java | 5 ++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/trait/shop/CommandAction.java b/main/src/main/java/net/citizensnpcs/trait/shop/CommandAction.java index a06e1fcac..3626e82ab 100644 --- a/main/src/main/java/net/citizensnpcs/trait/shop/CommandAction.java +++ b/main/src/main/java/net/citizensnpcs/trait/shop/CommandAction.java @@ -3,6 +3,7 @@ package net.citizensnpcs.trait.shop; import java.util.List; import java.util.function.Consumer; +import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.entity.Entity; import org.bukkit.entity.HumanEntity; @@ -21,6 +22,10 @@ import net.citizensnpcs.util.Util; public class CommandAction extends NPCShopAction { @Persist public List commands = Lists.newArrayList(); + @Persist + public boolean op = false; + @Persist + public boolean server = false; public CommandAction() { } @@ -62,13 +67,13 @@ public class CommandAction extends NPCShopAction { Player player = (Player) entity; return Transaction.create(() -> true, () -> { for (String command : commands) { - Util.runCommand(null, player, command, false, true); + Util.runCommand(null, player, command, op, !server); } }, () -> { }); } - @Menu(title = "Command editor", dimensions = { 3, 9 }) + @Menu(title = "Command editor", dimensions = { 4, 9 }) public static class CommandActionEditor extends InventoryMenuPage { private CommandAction base; private Consumer callback; @@ -115,6 +120,19 @@ public class CommandAction extends NPCShopAction { })); }); } + ctx.getSlot(3 * 9 + 3).setItemStack(new ItemStack(Util.getFallbackMaterial("COMMAND_BLOCK", "COMMAND")), + "Run commands as server", base.server ? ChatColor.GREEN + "On" : ChatColor.RED + "OFF"); + ctx.getSlot(3 * 9 + 3).addClickHandler(InputMenus.clickToggle((res) -> { + base.server = res; + return res ? ChatColor.GREEN + "On" : ChatColor.RED + "Off"; + }, base.server)); + ctx.getSlot(3 * 9 + 4).setItemStack( + new ItemStack(Util.getFallbackMaterial("COMPARATOR", "REDSTONE_COMPARATOR")), "Run commands as op", + base.op ? ChatColor.GREEN + "On" : ChatColor.RED + "OFF"); + ctx.getSlot(3 * 9 + 4).addClickHandler(InputMenus.clickToggle((res) -> { + base.op = res; + return res ? ChatColor.GREEN + "On" : ChatColor.RED + "Off"; + }, base.server)); } @Override diff --git a/main/src/main/java/net/citizensnpcs/trait/shop/ItemAction.java b/main/src/main/java/net/citizensnpcs/trait/shop/ItemAction.java index 153c8089f..24777fb70 100644 --- a/main/src/main/java/net/citizensnpcs/trait/shop/ItemAction.java +++ b/main/src/main/java/net/citizensnpcs/trait/shop/ItemAction.java @@ -18,7 +18,6 @@ import org.bukkit.inventory.meta.Damageable; import com.google.common.base.Joiner; import com.google.common.collect.Lists; -import net.citizensnpcs.api.gui.BooleanSlotHandler; import net.citizensnpcs.api.gui.InputMenus; import net.citizensnpcs.api.gui.InventoryMenuPage; import net.citizensnpcs.api.gui.InventoryMenuSlot; @@ -206,14 +205,14 @@ public class ItemAction extends NPCShopAction { ctx.getSlot(3 * 9 + 1).setItemStack(new ItemStack(Material.ANVIL), "Must have no damage", base.requireUndamaged ? ChatColor.GREEN + "On" : ChatColor.RED + "Off"); - ctx.getSlot(3 * 9 + 1).addClickHandler(new BooleanSlotHandler((res) -> { + ctx.getSlot(3 * 9 + 1).addClickHandler(InputMenus.clickToggle((res) -> { base.requireUndamaged = res; return res ? ChatColor.GREEN + "On" : ChatColor.RED + "Off"; }, base.requireUndamaged)); ctx.getSlot(3 * 9 + 2).setItemStack( new ItemStack(Util.getFallbackMaterial("COMPARATOR", "REDSTONE_COMPARATOR")), "Compare item similarity", base.compareSimilarity ? ChatColor.GREEN + "On" : ChatColor.RED + "Off"); - ctx.getSlot(3 * 9 + 2).addClickHandler(new BooleanSlotHandler((res) -> { + ctx.getSlot(3 * 9 + 2).addClickHandler(InputMenus.clickToggle((res) -> { base.compareSimilarity = res; return res ? ChatColor.GREEN + "On" : ChatColor.RED + "Off"; }, base.compareSimilarity));