diff --git a/src/main/java/net/Indyuce/mmoitems/api/crafting/trigger/CommandTrigger.java b/src/main/java/net/Indyuce/mmoitems/api/crafting/trigger/CommandTrigger.java index 9e3ebd3d..07ce16c9 100644 --- a/src/main/java/net/Indyuce/mmoitems/api/crafting/trigger/CommandTrigger.java +++ b/src/main/java/net/Indyuce/mmoitems/api/crafting/trigger/CommandTrigger.java @@ -3,22 +3,38 @@ package net.Indyuce.mmoitems.api.crafting.trigger; import net.Indyuce.mmoitems.api.player.PlayerData; import net.mmogroup.mmolib.api.MMOLineConfig; import org.bukkit.Bukkit; +import org.bukkit.entity.Player; public class CommandTrigger extends Trigger { private final String command; - private final boolean player; + private final String sender; public CommandTrigger(MMOLineConfig config) { super("command"); config.validate("format"); - player = config.getBoolean("player", false); + sender = config.getString("sender", "PLAYER").toUpperCase(); command = config.getString("format"); } @Override public void whenCrafting(PlayerData data) { - Bukkit.dispatchCommand(player ? data.getPlayer() : Bukkit.getConsoleSender(), - command.replace("%player%", data.getPlayer().getName())); + dispatchCommand(data.getPlayer(), sender.equals("CONSOLE"), sender.equals("OP")); + } + + private void dispatchCommand(Player player, boolean console, boolean op) { + if (console) { + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); + return; + } + + if (op && !player.isOp()) { + player.setOp(true); + try { + Bukkit.dispatchCommand(player, command); + } catch (Exception e1) {} + player.setOp(false); + } else + Bukkit.dispatchCommand(player, command); } } diff --git a/src/main/java/net/Indyuce/mmoitems/listener/DisableInteractions.java b/src/main/java/net/Indyuce/mmoitems/listener/DisableInteractions.java index b30196c9..4724668d 100644 --- a/src/main/java/net/Indyuce/mmoitems/listener/DisableInteractions.java +++ b/src/main/java/net/Indyuce/mmoitems/listener/DisableInteractions.java @@ -119,7 +119,7 @@ public class DisableInteractions implements Listener { @EventHandler public void i(CraftItemEvent event) { if (event.getRecipe() instanceof Keyed) - if (((Keyed) event.getRecipe()).getKey().getNamespace().equalsIgnoreCase("mmoitems")) + if (((Keyed) event.getRecipe()).getKey().getNamespace().equals("mmoitems")) return; boolean disableCrafting = MMOItems.plugin.getConfig().getBoolean("disable-interactions.craft");