From ea293bd3760fe056040cfe155061a8d297b65798 Mon Sep 17 00:00:00 2001 From: TheMode Date: Sat, 10 Apr 2021 19:30:25 +0200 Subject: [PATCH] Added EquipmentHandler#setEquipment --- .../server/inventory/EquipmentHandler.java | 52 ++++++++++++------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/src/main/java/net/minestom/server/inventory/EquipmentHandler.java b/src/main/java/net/minestom/server/inventory/EquipmentHandler.java index 9c01d75eb..e515112aa 100644 --- a/src/main/java/net/minestom/server/inventory/EquipmentHandler.java +++ b/src/main/java/net/minestom/server/inventory/EquipmentHandler.java @@ -20,8 +20,7 @@ public interface EquipmentHandler { * * @return the {@link ItemStack} in main hand */ - @NotNull - ItemStack getItemInMainHand(); + @NotNull ItemStack getItemInMainHand(); /** * Changes the main hand {@link ItemStack}. @@ -35,8 +34,7 @@ public interface EquipmentHandler { * * @return the item in off hand */ - @NotNull - ItemStack getItemInOffHand(); + @NotNull ItemStack getItemInOffHand(); /** * Changes the off hand {@link ItemStack}. @@ -51,8 +49,7 @@ public interface EquipmentHandler { * @param hand the Hand to get the {@link ItemStack} from * @return the {@link ItemStack} in {@code hand} */ - @NotNull - default ItemStack getItemInHand(@NotNull Player.Hand hand) { + default @NotNull ItemStack getItemInHand(@NotNull Player.Hand hand) { switch (hand) { case MAIN: return getItemInMainHand(); @@ -85,8 +82,7 @@ public interface EquipmentHandler { * * @return the helmet */ - @NotNull - ItemStack getHelmet(); + @NotNull ItemStack getHelmet(); /** * Changes the helmet. @@ -100,8 +96,7 @@ public interface EquipmentHandler { * * @return the chestplate */ - @NotNull - ItemStack getChestplate(); + @NotNull ItemStack getChestplate(); /** * Changes the chestplate. @@ -115,8 +110,7 @@ public interface EquipmentHandler { * * @return the leggings */ - @NotNull - ItemStack getLeggings(); + @NotNull ItemStack getLeggings(); /** * Changes the leggings. @@ -130,8 +124,7 @@ public interface EquipmentHandler { * * @return the boots */ - @NotNull - ItemStack getBoots(); + @NotNull ItemStack getBoots(); /** * Changes the boots. @@ -146,8 +139,7 @@ public interface EquipmentHandler { * @param slot the equipment to get the item from * @return the equipment {@link ItemStack} */ - @NotNull - default ItemStack getEquipment(@NotNull EntityEquipmentPacket.Slot slot) { + default @NotNull ItemStack getEquipment(@NotNull EntityEquipmentPacket.Slot slot) { switch (slot) { case MAIN_HAND: return getItemInMainHand(); @@ -165,6 +157,31 @@ public interface EquipmentHandler { throw new IllegalStateException("Something weird happened"); } + default void setEquipment(@NotNull EntityEquipmentPacket.Slot slot, @NotNull ItemStack itemStack) { + switch (slot) { + case MAIN_HAND: + setItemInMainHand(itemStack); + break; + case OFF_HAND: + setItemInOffHand(itemStack); + break; + case HELMET: + setHelmet(itemStack); + break; + case CHESTPLATE: + setChestplate(itemStack); + break; + case LEGGINGS: + setLeggings(itemStack); + break; + case BOOTS: + setBoots(itemStack); + break; + default: + throw new IllegalStateException("Something weird happened"); + } + } + /** * Sends a specific equipment to viewers. * @@ -191,8 +208,7 @@ public interface EquipmentHandler { * @return the packet with the equipments * @throws IllegalStateException if 'this' is not an {@link Entity} */ - @NotNull - default EntityEquipmentPacket getEquipmentsPacket() { + default @NotNull EntityEquipmentPacket getEquipmentsPacket() { Check.stateCondition(!(this instanceof Entity), "Only accessible for Entity"); final Entity entity = (Entity) this;