mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-11-07 19:40:23 +01:00
Restore old inventory clear behavior for 1.9
This commit is contained in:
parent
7eac272386
commit
873f9404bf
@ -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
|
||||
|
@ -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()));
|
||||
|
Loading…
Reference in New Issue
Block a user