From 3afcd4ef91e4a3632c620f3985ca95939e70bde7 Mon Sep 17 00:00:00 2001 From: Phoenix616 Date: Thu, 22 Jul 2021 12:10:49 +0100 Subject: [PATCH] Make sure to remove perm/op after command --- .../mechanics/crafting/CustomCrafting.java | 13 +++++++++---- .../craftbook/mechanics/items/CommandItems.java | 17 ++++++++++------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/sk89q/craftbook/mechanics/crafting/CustomCrafting.java b/src/main/java/com/sk89q/craftbook/mechanics/crafting/CustomCrafting.java index eb02ec37c1..fa565a83ff 100644 --- a/src/main/java/com/sk89q/craftbook/mechanics/crafting/CustomCrafting.java +++ b/src/main/java/com/sk89q/craftbook/mechanics/crafting/CustomCrafting.java @@ -364,10 +364,15 @@ public void applyPostData(RecipeManager.Recipe recipe, Player p, InventoryClickE PermissionAttachment att = p.addAttachment(CraftBookPlugin.inst()); att.setPermission("*", true); boolean wasOp = p.isOp(); - p.setOp(true); - Bukkit.dispatchCommand(p, s); - att.remove(); - p.setOp(wasOp); + if (!wasOp) + p.setOp(true); + try { + Bukkit.dispatchCommand(p, s); + } finally { + att.remove(); + if (!wasOp) + p.setOp(false); + } } } } diff --git a/src/main/java/com/sk89q/craftbook/mechanics/items/CommandItems.java b/src/main/java/com/sk89q/craftbook/mechanics/items/CommandItems.java index ad20d68d4d..7fd16667f7 100644 --- a/src/main/java/com/sk89q/craftbook/mechanics/items/CommandItems.java +++ b/src/main/java/com/sk89q/craftbook/mechanics/items/CommandItems.java @@ -552,14 +552,17 @@ else if (comdef.type == CommandType.PLAYER) { boolean wasOp = player.isOp(); if(!wasOp) player.setOp(true); - if (comdef.fakeCommand) { - ProtectionUtil.canSendCommand(player, command); - } else { - Bukkit.dispatchCommand(player, command); + try { + if (comdef.fakeCommand) { + ProtectionUtil.canSendCommand(player, command); + } else { + Bukkit.dispatchCommand(player, command); + } + } finally { + att.remove(); + if(!wasOp) + player.setOp(false); } - att.remove(); - if(!wasOp) - player.setOp(wasOp); } }