Skip to content

Commit

Permalink
Fix equipment
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofaa2 committed May 9, 2024
1 parent f7b5bd6 commit 63aa8b7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 33 deletions.
14 changes: 1 addition & 13 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
Expand All @@ -29,39 +30,38 @@ public WrapperEntityEquipment(WrapperLivingEntity entity) {
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();
}

Expand Down Expand Up @@ -102,7 +102,6 @@ public WrapperPlayServerEntityEquipment createPacket() {
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(
Expand All @@ -124,8 +123,6 @@ public boolean isNotifyingChanges() {

public void setNotifyChanges(boolean notifyChanges) {
this.notifyChanges = notifyChanges;
if (notifyChanges) {
refresh();
}
refresh();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ public boolean execute(@NotNull CommandSender commandSender, @NotNull String s,
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;
}
Expand All @@ -87,7 +96,7 @@ public boolean execute(@NotNull CommandSender commandSender, @NotNull String s,
@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();
}
Expand Down

0 comments on commit 63aa8b7

Please sign in to comment.