mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-22 17:07:34 +01:00
#664: Add methods to get/set ItemStacks in EquipmentSlots
This commit is contained in:
parent
1872231235
commit
933e9094bf
@ -9,6 +9,7 @@ import org.apache.commons.lang.Validate;
|
|||||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.inventory.EntityEquipment;
|
import org.bukkit.inventory.EntityEquipment;
|
||||||
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.inventory.PlayerInventory, EntityEquipment {
|
public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.inventory.PlayerInventory, EntityEquipment {
|
||||||
@ -102,6 +103,56 @@ public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.i
|
|||||||
player.playerConnection.sendPacket(new PacketPlayOutSetSlot(player.defaultContainer.windowId, index, CraftItemStack.asNMSCopy(item)));
|
player.playerConnection.sendPacket(new PacketPlayOutSetSlot(player.defaultContainer.windowId, index, CraftItemStack.asNMSCopy(item)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setItem(EquipmentSlot slot, ItemStack item) {
|
||||||
|
Preconditions.checkArgument(slot != null, "slot must not be null");
|
||||||
|
|
||||||
|
switch (slot) {
|
||||||
|
case HAND:
|
||||||
|
this.setItemInMainHand(item);
|
||||||
|
break;
|
||||||
|
case OFF_HAND:
|
||||||
|
this.setItemInOffHand(item);
|
||||||
|
break;
|
||||||
|
case FEET:
|
||||||
|
this.setBoots(item);
|
||||||
|
break;
|
||||||
|
case LEGS:
|
||||||
|
this.setLeggings(item);
|
||||||
|
break;
|
||||||
|
case CHEST:
|
||||||
|
this.setChestplate(item);
|
||||||
|
break;
|
||||||
|
case HEAD:
|
||||||
|
this.setHelmet(item);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Not implemented. This is a bug");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getItem(EquipmentSlot slot) {
|
||||||
|
Preconditions.checkArgument(slot != null, "slot must not be null");
|
||||||
|
|
||||||
|
switch (slot) {
|
||||||
|
case HAND:
|
||||||
|
return getItemInMainHand();
|
||||||
|
case OFF_HAND:
|
||||||
|
return getItemInOffHand();
|
||||||
|
case FEET:
|
||||||
|
return getBoots();
|
||||||
|
case LEGS:
|
||||||
|
return getLeggings();
|
||||||
|
case CHEST:
|
||||||
|
return getChestplate();
|
||||||
|
case HEAD:
|
||||||
|
return getHelmet();
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Not implemented. This is a bug");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getHeldItemSlot() {
|
public int getHeldItemSlot() {
|
||||||
return getInventory().itemInHandIndex;
|
return getInventory().itemInHandIndex;
|
||||||
|
Loading…
Reference in New Issue
Block a user