handle BODY slot for non-mobs (#10822)

This commit is contained in:
Jake Potrebic 2024-05-29 11:23:51 -07:00 committed by GitHub
parent 84f6e6e0b1
commit 672c07728f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 67 additions and 7 deletions

View File

@ -150,7 +150,7 @@ index 0000000000000000000000000000000000000000..53359ab4a6659bce895deef6a21cde84
+
+}
diff --git a/src/main/java/org/bukkit/entity/ArmorStand.java b/src/main/java/org/bukkit/entity/ArmorStand.java
index 2ee3814a52945f541e049b621b9552f8ae9e261d..7530eb5d2a506e13e2bc7e189fd6e957c013cdf5 100644
index 2ee3814a52945f541e049b621b9552f8ae9e261d..575d58d96445e9ef3711cd6613471d5fe17bbb10 100644
--- a/src/main/java/org/bukkit/entity/ArmorStand.java
+++ b/src/main/java/org/bukkit/entity/ArmorStand.java
@@ -14,7 +14,7 @@ public interface ArmorStand extends LivingEntity {
@ -171,7 +171,7 @@ index 2ee3814a52945f541e049b621b9552f8ae9e261d..7530eb5d2a506e13e2bc7e189fd6e957
*/
@Deprecated
void setItemInHand(@Nullable ItemStack item);
@@ -379,5 +379,167 @@ public interface ArmorStand extends LivingEntity {
@@ -379,5 +379,169 @@ public interface ArmorStand extends LivingEntity {
* @param tick {@code true} if this armour stand can tick, {@code false} otherwise
*/
void setCanTick(final boolean tick);
@ -182,6 +182,7 @@ index 2ee3814a52945f541e049b621b9552f8ae9e261d..7530eb5d2a506e13e2bc7e189fd6e957
+ *
+ * @param slot the equipment slot to get
+ * @return the ItemStack in the equipment slot
+ * @throws IllegalArgumentException if the slot is invalid for the entity
+ */
+ @NotNull
+ ItemStack getItem(@NotNull final org.bukkit.inventory.EquipmentSlot slot);
@ -192,6 +193,7 @@ index 2ee3814a52945f541e049b621b9552f8ae9e261d..7530eb5d2a506e13e2bc7e189fd6e957
+ *
+ * @param slot the equipment slot to set
+ * @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);
+

View File

@ -17,6 +17,36 @@ index 8ba00f743b61cd33dd41ae7f1c272ee2b0c8546d..7cc1fd241e1f62a9fe9b5849110c0a3d
public EquipmentSlot getSlot() {
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 1b34286fb6cbedb3841c84c499eb626f61885126..0829418cc4b586ea9c800617f7184b1e60f756a6 100644
--- a/src/main/java/org/bukkit/inventory/EntityEquipment.java
+++ b/src/main/java/org/bukkit/inventory/EntityEquipment.java
@@ -15,6 +15,7 @@ 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);
@@ -23,7 +24,8 @@ 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);
@@ -32,6 +34,7 @@ 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
index 82416a078f697f627916c578e6c2dbc003519acf..f72aa9cfd2d1472cf26600ac0f2380660069407d 100644
--- a/src/main/java/org/bukkit/inventory/EquipmentSlotGroup.java

View File

@ -14,22 +14,24 @@ public net.minecraft.world.entity.decoration.ArmorStand isDisabled(Lnet/minecraf
Co-authored-by: SoSeDiK <mrsosedik@gmail.com>
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftArmorStand.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftArmorStand.java
index 9923cea74ba39a774d6b16a225bc3e455e54c418..2c16cedf8cb2e4047415e056c419ed9c33c80e93 100644
index 9923cea74ba39a774d6b16a225bc3e455e54c418..1087840331f68ffe79e79f6493137b2b894832f9 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftArmorStand.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftArmorStand.java
@@ -233,6 +233,147 @@ public class CraftArmorStand extends CraftLivingEntity implements ArmorStand {
@@ -233,6 +233,149 @@ public class CraftArmorStand extends CraftLivingEntity implements ArmorStand {
getHandle().canMove = move;
}
+ @Override
+ 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();
+ }
+
+ @Override
+ 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) {
+ case HAND:
+ getEquipment().setItemInMainHand(item);

View File

@ -5,8 +5,34 @@ Subject: [PATCH] Fix equipment slot and group API
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 9d74577af071954e1e37201a96368c1360076209..eafa54c870c3e2aef30c3f9f96f516607a7cae24 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java
@@ -135,6 +135,10 @@ 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");
}
@@ -162,6 +166,10 @@ 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
index 860bc5ec4baec5e09a456cc5559d0de2aa10797a..554dc8b6b142c185d1dd0c4a3450232b7b708f1b 100644
index c235b80b94fdb6c77766016114713cd501ffd67c..d5789326d70bb8b029c5448270bbaa6faf52e6e1 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
@@ -1331,7 +1331,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {