diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java b/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java index 5a2ebda1f..65d49d44f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java @@ -137,7 +137,7 @@ public class Commandclearinventory extends EssentialsCommand { if (amount == -1) { stack.setAmount(BASE_AMOUNT); final ItemStack removedStack = player.getInventory().removeItem(stack).get(0); - final int removedAmount = BASE_AMOUNT - removedStack.getAmount(); + final int removedAmount = BASE_AMOUNT - removedStack.getAmount() + InventoryWorkaround.clearItemInOffHand(player, stack); if (removedAmount > 0 || showExtended) { sender.sendMessage(tl("inventoryClearingStack", removedAmount, stack.getType().toString().toLowerCase(Locale.ENGLISH), player.getDisplayName())); } diff --git a/Essentials/src/com/earth2me/essentials/craftbukkit/InventoryWorkaround.java b/Essentials/src/com/earth2me/essentials/craftbukkit/InventoryWorkaround.java index 177520879..2abe5e24d 100644 --- a/Essentials/src/com/earth2me/essentials/craftbukkit/InventoryWorkaround.java +++ b/Essentials/src/com/earth2me/essentials/craftbukkit/InventoryWorkaround.java @@ -267,4 +267,22 @@ public final class InventoryWorkaround { } } } + + public static int clearItemInOffHand(final Player p, final ItemStack item) { + // This should be added because if `/clear` itself is not initilized it will return an Error: null. + if (hasMainHandSupport == null || hasMainHandSupport) { + try { + int removedAmount = 0; + if (p.getInventory().getItemInOffHand().getType().equals(item.getType())) { + removedAmount = p.getInventory().getItemInOffHand().getAmount(); + p.getInventory().setItemInOffHand(null); + } + hasMainHandSupport = true; + return removedAmount; + } catch (final Throwable e) { + hasMainHandSupport = false; + } + } + return 0; + } }