From 873f9404bfbb9d9dfb104d74695bf881db21ff36 Mon Sep 17 00:00:00 2001 From: vemacs Date: Tue, 8 Mar 2016 18:07:04 -0700 Subject: [PATCH] Restore old inventory clear behavior for 1.9 --- .../essentials/commands/Commandclearinventory.java | 5 +++-- .../essentials/craftbukkit/InventoryWorkaround.java | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java b/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java index 853ae8f65..4f8695252 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.User; +import com.earth2me.essentials.craftbukkit.InventoryWorkaround; import com.earth2me.essentials.utils.NumberUtil; import org.bukkit.Server; import org.bukkit.entity.Player; @@ -86,13 +87,13 @@ public class Commandclearinventory extends EssentialsCommand { if (showExtended) { sender.sendMessage(tl("inventoryClearingAllItems", player.getDisplayName())); } - player.getInventory().clear(); + InventoryWorkaround.clearInventoryNoArmor(player.getInventory()); } else if (type == -2) // type -2 represents double wildcard or all items and armor { if (showExtended) { sender.sendMessage(tl("inventoryClearingAllArmor", player.getDisplayName())); } - player.getInventory().clear(); + InventoryWorkaround.clearInventoryNoArmor(player.getInventory()); player.getInventory().setArmorContents(null); } else { if (data == -1) // data -1 means that all subtypes will be cleared diff --git a/Essentials/src/com/earth2me/essentials/craftbukkit/InventoryWorkaround.java b/Essentials/src/com/earth2me/essentials/craftbukkit/InventoryWorkaround.java index 6847e51c2..ed4dec1a7 100644 --- a/Essentials/src/com/earth2me/essentials/craftbukkit/InventoryWorkaround.java +++ b/Essentials/src/com/earth2me/essentials/craftbukkit/InventoryWorkaround.java @@ -42,6 +42,17 @@ public final class InventoryWorkaround { return inventory instanceof PlayerInventory && inventory.getContents().length > USABLE_PLAYER_INV_SIZE; } + // Clears inventory without clearing armor + public static void clearInventoryNoArmor(PlayerInventory inventory) { + if (isCombinedInventory(inventory)) { + for (int i = 0; i < USABLE_PLAYER_INV_SIZE; i++) { + inventory.setItem(i, null); + } + } else { + inventory.clear(); + } + } + private static Inventory makeTruncatedPlayerInventory(PlayerInventory playerInventory) { Inventory fakeInventory = Bukkit.getServer().createInventory(null, USABLE_PLAYER_INV_SIZE); fakeInventory.setContents(Arrays.copyOf(playerInventory.getContents(), fakeInventory.getSize()));