Restore old inventory clear behavior for 1.9

This commit is contained in:
vemacs 2016-03-08 18:07:04 -07:00
parent 7eac272386
commit 873f9404bf
2 changed files with 14 additions and 2 deletions

View File

@ -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

View File

@ -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()));