Cleanup some code (fix warns, fix NPE, remove duplicates)

This commit is contained in:
MrMicky
2020-02-19 14:57:07 +01:00
parent a6667129c9
commit fbf4b46858
35 changed files with 169 additions and 573 deletions
@@ -13,10 +13,7 @@ import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
/**
* @author Jitse Boonstra
@@ -28,7 +25,6 @@ public class NPC_v1_14_R1 extends NPCBase {
private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove;
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
private Set<UUID> hasTeamRegistered = new HashSet<>();
public NPC_v1_14_R1(NPCLib instance, List<String> lines) {
super(instance, lines);
@@ -60,12 +56,6 @@ public class NPC_v1_14_R1 extends NPCBase {
this.packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(entityId); // First packet to send.
}
@Override
public void onLogout(Player player) {
super.onLogout(player);
hasTeamRegistered.remove(player.getUniqueId());
}
@Override
public void sendShowPackets(Player player) {
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
@@ -104,39 +94,8 @@ public class NPC_v1_14_R1 extends NPCBase {
public void sendEquipmentPacket(Player player, NPCSlot slot, boolean auto) {
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
EnumItemSlot nmsSlot;
ItemStack item;
switch (slot) {
case HELMET:
item = helmet;
nmsSlot = EnumItemSlot.HEAD;
break;
case CHESTPLATE:
item = chestplate;
nmsSlot = EnumItemSlot.CHEST;
break;
case LEGGINGS:
item = leggings;
nmsSlot = EnumItemSlot.LEGS;
break;
case BOOTS:
item = boots;
nmsSlot = EnumItemSlot.FEET;
break;
case MAINHAND:
item = inHand;
nmsSlot = EnumItemSlot.MAINHAND;
break;
case OFFHAND:
item = offHand;
nmsSlot = EnumItemSlot.OFFHAND;
break;
default:
if (!auto) {
throw new IllegalArgumentException(slot.toString() + " is not a supported slot for the version of your server");
}
return;
}
EnumItemSlot nmsSlot = slot.getNmsEnum(EnumItemSlot.class);
ItemStack item = getItem(slot);
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsSlot, CraftItemStack.asNMSCopy(item));
playerConnection.sendPacket(packet);
@@ -6,9 +6,11 @@ import net.minecraft.server.v1_14_R1.DataWatcherObject;
import net.minecraft.server.v1_14_R1.DataWatcherRegistry;
import net.minecraft.server.v1_14_R1.PacketPlayOutEntityMetadata;
import java.util.Collection;
public class PacketPlayOutEntityMetadataWrapper {
public PacketPlayOutEntityMetadata create(NPCState[] activateStates, int entityId) {
public PacketPlayOutEntityMetadata create(Collection<NPCState> activateStates, int entityId) {
DataWatcher dataWatcher = new DataWatcher(null);
byte masked = NPCState.getMasked(activateStates);
// TODO: Find out why NPCState#CROUCHED doesn't work.