From 63aa8b7a20d0c6a0ce0e86ad4d4074d52f9c5164 Mon Sep 17 00:00:00 2001 From: Tofaa <82680183+Tofaa2@users.noreply.github.com> Date: Thu, 9 May 2024 23:50:03 +0400 Subject: [PATCH] Fix equipment --- .idea/workspace.xml | 14 +------- .../wrapper/WrapperEntityEquipment.java | 35 +++++++++---------- .../testentitylib/TestPlayerCommand.java | 11 +++++- 3 files changed, 27 insertions(+), 33 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 29f2b72..b1a67bd 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,20 +5,7 @@ </component> <component name="ChangeListManager"> <list default="true" id="9d5d9b6f-43c8-41a4-bb42-a66ffc96c9b0" name="Changes" comment=""> - <change afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/extras/MojangApiError.java" afterDir="false" /> - <change afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/extras/skin/CSFBImpl.java" afterDir="false" /> - <change afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/extras/skin/CachedSkinFetcherBuilder.java" afterDir="false" /> - <change afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/extras/skin/CachedSkinFetcherImpl.java" afterDir="false" /> - <change afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/extras/skin/ErroredTextureProperties.java" afterDir="false" /> - <change afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/extras/skin/SFBImpl.java" afterDir="false" /> - <change afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/extras/skin/SFUtils.java" afterDir="false" /> - <change afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/extras/skin/SkinFetcher.java" afterDir="false" /> - <change afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/extras/skin/SkinFetcherBuilder.java" afterDir="false" /> - <change afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/extras/skin/SkinFetcherImpl.java" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/EntityLib.java" beforeDir="false" afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/EntityLib.java" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/test-plugin/src/main/java/me/tofaa/testentitylib/TestPlayerCommand.java" beforeDir="false" afterPath="$PROJECT_DIR$/test-plugin/src/main/java/me/tofaa/testentitylib/TestPlayerCommand.java" afterDir="false" /> </list> <option name="SHOW_DIALOG" value="false" /> <option name="HIGHLIGHT_CONFLICTS" value="true" /> @@ -324,6 +311,7 @@ <workItem from="1709139306864" duration="1813000" /> <workItem from="1709142473633" duration="2565000" /> <workItem from="1714477887801" duration="3618000" /> + <workItem from="1714566597065" duration="351000" /> </task> <servers /> </component> diff --git a/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntityEquipment.java b/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntityEquipment.java index 9b2aa8f..720ea2a 100644 --- a/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntityEquipment.java +++ b/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntityEquipment.java @@ -7,6 +7,7 @@ import com.github.retrooper.packetevents.protocol.player.EquipmentSlot; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityEquipment; import me.tofaa.entitylib.EntityLib; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; @@ -29,39 +30,38 @@ public class WrapperEntityEquipment { Arrays.fill(equipment, ItemStack.EMPTY); } - public void setHelmet(@NotNull ItemStack itemStack) { - equipment[5] = itemStack; + public void setHelmet(@Nullable ItemStack itemStack) { + equipment[5] = itemStack == null ? ItemStack.EMPTY : itemStack; refresh(); } - public void setChestplate(@NotNull ItemStack itemStack) { - equipment[4] = itemStack; + public void setChestplate(@Nullable ItemStack itemStack) { + equipment[4] = itemStack == null ? ItemStack.EMPTY : itemStack; refresh(); } - public void setLeggings(@NotNull ItemStack itemStack) { - equipment[3] = itemStack; + public void setLeggings(@Nullable ItemStack itemStack) { + equipment[3] = itemStack == null ? ItemStack.EMPTY : itemStack; refresh(); } - public void setBoots(@NotNull ItemStack itemStack) { - equipment[2] = itemStack; + public void setBoots(@Nullable ItemStack itemStack) { + equipment[2] = itemStack == null ? ItemStack.EMPTY : itemStack; refresh(); } - public void setMainHand(@NotNull ItemStack itemStack) { - equipment[0] = itemStack; + public void setMainHand(@Nullable ItemStack itemStack) { + equipment[0] = itemStack == null ? ItemStack.EMPTY : itemStack; refresh(); } - public void setOffhand(@NotNull ItemStack itemStack) { - verifyVersion(ServerVersion.V_1_9, "Offhand is only supported on 1.9+"); - equipment[1] = itemStack; + public void setOffhand(@Nullable ItemStack itemStack) { + equipment[1] = itemStack == null ? ItemStack.EMPTY : itemStack; refresh(); } - public void setItem(@NotNull EquipmentSlot slot, @NotNull ItemStack itemStack) { - equipment[slot.ordinal()] = itemStack; + public void setItem(@NotNull EquipmentSlot slot, @Nullable ItemStack itemStack) { + equipment[slot.ordinal()] = itemStack == null ? ItemStack.EMPTY : itemStack; refresh(); } @@ -102,7 +102,6 @@ public class WrapperEntityEquipment { List<Equipment> equipment = new ArrayList<>(); for (int i = 0; i < this.equipment.length; i++) { ItemStack itemStack = this.equipment[i]; - if (itemStack == null || itemStack.equals(ItemStack.EMPTY)) continue; equipment.add(new Equipment(EQUIPMENT_SLOTS[i], itemStack)); } return new WrapperPlayServerEntityEquipment( @@ -124,8 +123,6 @@ public class WrapperEntityEquipment { public void setNotifyChanges(boolean notifyChanges) { this.notifyChanges = notifyChanges; - if (notifyChanges) { - refresh(); - } + refresh(); } } diff --git a/test-plugin/src/main/java/me/tofaa/testentitylib/TestPlayerCommand.java b/test-plugin/src/main/java/me/tofaa/testentitylib/TestPlayerCommand.java index 79ffc4e..a0c828c 100644 --- a/test-plugin/src/main/java/me/tofaa/testentitylib/TestPlayerCommand.java +++ b/test-plugin/src/main/java/me/tofaa/testentitylib/TestPlayerCommand.java @@ -79,6 +79,15 @@ public class TestPlayerCommand extends BukkitCommand { p.remove(); player.sendMessage("Entity removed"); break; + case "hidearmor": + p.getEquipment().setNotifyChanges(false); + p.getEquipment().setBoots(null); + p.getEquipment().setChestplate(null); + p.getEquipment().setHelmet(null); + p.getEquipment().setLeggings(null); + p.getEquipment().setMainHand(null); + p.getEquipment().setOffhand(null); + p.getEquipment().setNotifyChanges(true); } return true; } @@ -87,7 +96,7 @@ public class TestPlayerCommand extends BukkitCommand { @Override public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException { if (args.length == 1) { - return Arrays.asList("spawn", "texture", "ping", "gamemode", "displayname", "tablist", "remove", "sneak"); + return Arrays.asList("spawn", "texture", "ping", "gamemode", "displayname", "tablist", "remove", "sneak", "hidearmor"); } return Collections.emptyList(); }