Fix equipment

This commit is contained in:
Tofaa 2024-05-09 23:50:03 +04:00
parent f7b5bd6246
commit 63aa8b7a20
3 changed files with 27 additions and 33 deletions

View file

@ -5,20 +5,7 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="9d5d9b6f-43c8-41a4-bb42-a66ffc96c9b0" name="Changes" comment=""> <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$/.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> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -324,6 +311,7 @@
<workItem from="1709139306864" duration="1813000" /> <workItem from="1709139306864" duration="1813000" />
<workItem from="1709142473633" duration="2565000" /> <workItem from="1709142473633" duration="2565000" />
<workItem from="1714477887801" duration="3618000" /> <workItem from="1714477887801" duration="3618000" />
<workItem from="1714566597065" duration="351000" />
</task> </task>
<servers /> <servers />
</component> </component>

View file

@ -7,6 +7,7 @@ import com.github.retrooper.packetevents.protocol.player.EquipmentSlot;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityEquipment; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityEquipment;
import me.tofaa.entitylib.EntityLib; import me.tofaa.entitylib.EntityLib;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -29,39 +30,38 @@ public class WrapperEntityEquipment {
Arrays.fill(equipment, ItemStack.EMPTY); Arrays.fill(equipment, ItemStack.EMPTY);
} }
public void setHelmet(@NotNull ItemStack itemStack) { public void setHelmet(@Nullable ItemStack itemStack) {
equipment[5] = itemStack; equipment[5] = itemStack == null ? ItemStack.EMPTY : itemStack;
refresh(); refresh();
} }
public void setChestplate(@NotNull ItemStack itemStack) { public void setChestplate(@Nullable ItemStack itemStack) {
equipment[4] = itemStack; equipment[4] = itemStack == null ? ItemStack.EMPTY : itemStack;
refresh(); refresh();
} }
public void setLeggings(@NotNull ItemStack itemStack) { public void setLeggings(@Nullable ItemStack itemStack) {
equipment[3] = itemStack; equipment[3] = itemStack == null ? ItemStack.EMPTY : itemStack;
refresh(); refresh();
} }
public void setBoots(@NotNull ItemStack itemStack) { public void setBoots(@Nullable ItemStack itemStack) {
equipment[2] = itemStack; equipment[2] = itemStack == null ? ItemStack.EMPTY : itemStack;
refresh(); refresh();
} }
public void setMainHand(@NotNull ItemStack itemStack) { public void setMainHand(@Nullable ItemStack itemStack) {
equipment[0] = itemStack; equipment[0] = itemStack == null ? ItemStack.EMPTY : itemStack;
refresh(); refresh();
} }
public void setOffhand(@NotNull ItemStack itemStack) { public void setOffhand(@Nullable ItemStack itemStack) {
verifyVersion(ServerVersion.V_1_9, "Offhand is only supported on 1.9+"); equipment[1] = itemStack == null ? ItemStack.EMPTY : itemStack;
equipment[1] = itemStack;
refresh(); refresh();
} }
public void setItem(@NotNull EquipmentSlot slot, @NotNull ItemStack itemStack) { public void setItem(@NotNull EquipmentSlot slot, @Nullable ItemStack itemStack) {
equipment[slot.ordinal()] = itemStack; equipment[slot.ordinal()] = itemStack == null ? ItemStack.EMPTY : itemStack;
refresh(); refresh();
} }
@ -102,7 +102,6 @@ public class WrapperEntityEquipment {
List<Equipment> equipment = new ArrayList<>(); List<Equipment> equipment = new ArrayList<>();
for (int i = 0; i < this.equipment.length; i++) { for (int i = 0; i < this.equipment.length; i++) {
ItemStack itemStack = this.equipment[i]; ItemStack itemStack = this.equipment[i];
if (itemStack == null || itemStack.equals(ItemStack.EMPTY)) continue;
equipment.add(new Equipment(EQUIPMENT_SLOTS[i], itemStack)); equipment.add(new Equipment(EQUIPMENT_SLOTS[i], itemStack));
} }
return new WrapperPlayServerEntityEquipment( return new WrapperPlayServerEntityEquipment(
@ -124,8 +123,6 @@ public class WrapperEntityEquipment {
public void setNotifyChanges(boolean notifyChanges) { public void setNotifyChanges(boolean notifyChanges) {
this.notifyChanges = notifyChanges; this.notifyChanges = notifyChanges;
if (notifyChanges) { refresh();
refresh();
}
} }
} }

View file

@ -79,6 +79,15 @@ public class TestPlayerCommand extends BukkitCommand {
p.remove(); p.remove();
player.sendMessage("Entity removed"); player.sendMessage("Entity removed");
break; 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; return true;
} }
@ -87,7 +96,7 @@ public class TestPlayerCommand extends BukkitCommand {
@Override @Override
public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException { public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException {
if (args.length == 1) { 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(); return Collections.emptyList();
} }