mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-03 23:07:40 +01:00
handle BODY slot for non-mobs (#10822)
This commit is contained in:
parent
cae5734b19
commit
82ece252bc
@ -182,6 +182,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+ *
|
+ *
|
||||||
+ * @param slot the equipment slot to get
|
+ * @param slot the equipment slot to get
|
||||||
+ * @return the ItemStack in the equipment slot
|
+ * @return the ItemStack in the equipment slot
|
||||||
|
+ * @throws IllegalArgumentException if the slot is invalid for the entity
|
||||||
+ */
|
+ */
|
||||||
+ @NotNull
|
+ @NotNull
|
||||||
+ ItemStack getItem(@NotNull final org.bukkit.inventory.EquipmentSlot slot);
|
+ ItemStack getItem(@NotNull final org.bukkit.inventory.EquipmentSlot slot);
|
||||||
@ -192,6 +193,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+ *
|
+ *
|
||||||
+ * @param slot the equipment slot to set
|
+ * @param slot the equipment slot to set
|
||||||
+ * @param item the item to hold
|
+ * @param item the item to hold
|
||||||
|
+ * @throws IllegalArgumentException if the slot is invalid for the entity
|
||||||
+ */
|
+ */
|
||||||
+ void setItem(@NotNull final org.bukkit.inventory.EquipmentSlot slot, @Nullable final ItemStack item);
|
+ void setItem(@NotNull final org.bukkit.inventory.EquipmentSlot slot, @Nullable final ItemStack item);
|
||||||
+
|
+
|
||||||
|
@ -17,6 +17,36 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
public EquipmentSlot getSlot() {
|
public EquipmentSlot getSlot() {
|
||||||
return slot == EquipmentSlotGroup.ANY ? null : slot.getExample();
|
return slot == EquipmentSlotGroup.ANY ? null : slot.getExample();
|
||||||
}
|
}
|
||||||
|
diff --git a/src/main/java/org/bukkit/inventory/EntityEquipment.java b/src/main/java/org/bukkit/inventory/EntityEquipment.java
|
||||||
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
|
--- a/src/main/java/org/bukkit/inventory/EntityEquipment.java
|
||||||
|
+++ b/src/main/java/org/bukkit/inventory/EntityEquipment.java
|
||||||
|
@@ -0,0 +0,0 @@ public interface EntityEquipment {
|
||||||
|
*
|
||||||
|
* @param slot the slot to put the ItemStack
|
||||||
|
* @param item the ItemStack to set
|
||||||
|
+ * @throws IllegalArgumentException if the slot is invalid for the entity
|
||||||
|
*/
|
||||||
|
public void setItem(@NotNull EquipmentSlot slot, @Nullable ItemStack item);
|
||||||
|
|
||||||
|
@@ -0,0 +0,0 @@ public interface EntityEquipment {
|
||||||
|
*
|
||||||
|
* @param slot the slot to put the ItemStack
|
||||||
|
* @param item the ItemStack to set
|
||||||
|
- * @param silent whether or not the equip sound should be silenced
|
||||||
|
+ * @param silent whether the equip sound should be silenced
|
||||||
|
+ * @throws IllegalArgumentException if the slot is invalid for the entity
|
||||||
|
*/
|
||||||
|
public void setItem(@NotNull EquipmentSlot slot, @Nullable ItemStack item, boolean silent);
|
||||||
|
|
||||||
|
@@ -0,0 +0,0 @@ public interface EntityEquipment {
|
||||||
|
*
|
||||||
|
* @param slot the slot to get the ItemStack
|
||||||
|
* @return the ItemStack in the given slot
|
||||||
|
+ * @throws IllegalArgumentException if the slot is invalid for the entity
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public ItemStack getItem(@NotNull EquipmentSlot slot);
|
||||||
diff --git a/src/main/java/org/bukkit/inventory/EquipmentSlotGroup.java b/src/main/java/org/bukkit/inventory/EquipmentSlotGroup.java
|
diff --git a/src/main/java/org/bukkit/inventory/EquipmentSlotGroup.java b/src/main/java/org/bukkit/inventory/EquipmentSlotGroup.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/org/bukkit/inventory/EquipmentSlotGroup.java
|
--- a/src/main/java/org/bukkit/inventory/EquipmentSlotGroup.java
|
||||||
|
@ -23,13 +23,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
|
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public ItemStack getItem(org.bukkit.inventory.EquipmentSlot slot) {
|
+ public ItemStack getItem(org.bukkit.inventory.EquipmentSlot slot) {
|
||||||
+ com.google.common.base.Preconditions.checkNotNull(slot, "slot");
|
+ com.google.common.base.Preconditions.checkArgument(slot != null, "slot");
|
||||||
|
+ com.google.common.base.Preconditions.checkArgument(slot != EquipmentSlot.BODY, "Cannot get body item");
|
||||||
+ return getHandle().getItemBySlot(org.bukkit.craftbukkit.CraftEquipmentSlot.getNMS(slot)).asBukkitMirror();
|
+ return getHandle().getItemBySlot(org.bukkit.craftbukkit.CraftEquipmentSlot.getNMS(slot)).asBukkitMirror();
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public void setItem(org.bukkit.inventory.EquipmentSlot slot, ItemStack item) {
|
+ public void setItem(org.bukkit.inventory.EquipmentSlot slot, ItemStack item) {
|
||||||
+ com.google.common.base.Preconditions.checkNotNull(slot, "slot");
|
+ com.google.common.base.Preconditions.checkArgument(slot != null, "slot");
|
||||||
|
+ com.google.common.base.Preconditions.checkArgument(slot != EquipmentSlot.BODY, "Cannot set body item");
|
||||||
+ switch (slot) {
|
+ switch (slot) {
|
||||||
+ case HAND:
|
+ case HAND:
|
||||||
+ getEquipment().setItemInMainHand(item);
|
+ getEquipment().setItemInMainHand(item);
|
||||||
|
@ -5,6 +5,32 @@ Subject: [PATCH] Fix equipment slot and group API
|
|||||||
|
|
||||||
Add test for EquipmentSlotGroup
|
Add test for EquipmentSlotGroup
|
||||||
|
|
||||||
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java
|
||||||
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java
|
||||||
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java
|
||||||
|
@@ -0,0 +0,0 @@ public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.i
|
||||||
|
case HEAD:
|
||||||
|
this.setHelmet(item);
|
||||||
|
break;
|
||||||
|
+ // Paper start
|
||||||
|
+ case BODY:
|
||||||
|
+ throw new IllegalArgumentException("BODY is not valid for players!");
|
||||||
|
+ // Paper end
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Not implemented. This is a bug");
|
||||||
|
}
|
||||||
|
@@ -0,0 +0,0 @@ public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.i
|
||||||
|
return java.util.Objects.requireNonNullElseGet(this.getChestplate(), () -> new ItemStack(org.bukkit.Material.AIR)); // Paper - make nonnull
|
||||||
|
case HEAD:
|
||||||
|
return java.util.Objects.requireNonNullElseGet(this.getHelmet(), () -> new ItemStack(org.bukkit.Material.AIR)); // Paper - make nonnull
|
||||||
|
+ // Paper start
|
||||||
|
+ case BODY:
|
||||||
|
+ throw new IllegalArgumentException("BODY is not valid for players!");
|
||||||
|
+ // Paper end
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Not implemented. This is a bug");
|
||||||
|
}
|
||||||
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
||||||
|
Loading…
Reference in New Issue
Block a user