From 85d2b852f9a759577aae85ca3c6795d988508f52 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Tue, 25 Apr 2023 00:08:13 +0100 Subject: [PATCH] better property definitions --- .../java/lol/pyr/znpcsplus/npc/NPCType.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/main/java/lol/pyr/znpcsplus/npc/NPCType.java b/src/main/java/lol/pyr/znpcsplus/npc/NPCType.java index db8a12a..f29463c 100644 --- a/src/main/java/lol/pyr/znpcsplus/npc/NPCType.java +++ b/src/main/java/lol/pyr/znpcsplus/npc/NPCType.java @@ -1,16 +1,19 @@ package lol.pyr.znpcsplus.npc; +import com.github.retrooper.packetevents.PacketEvents; +import com.github.retrooper.packetevents.manager.server.ServerVersion; import com.github.retrooper.packetevents.protocol.entity.type.EntityType; import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes; -import com.google.common.collect.ImmutableList; +import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Set; public class NPCType { - private final static ImmutableList npcTypes; + private final static Set npcTypes; - public static List values() { + public static Set values() { return npcTypes; } @@ -19,7 +22,10 @@ public class NPCType { public NPCType(EntityType type, NPCProperty... allowedProperties) { this.type = type; - this.allowedProperties = Set.of(allowedProperties); + ArrayList> list = new ArrayList<>(List.of(allowedProperties)); + list.add(NPCProperty.FIRE); + if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) list.add(NPCProperty.GLOW); + this.allowedProperties = Set.copyOf(list); } public EntityType getType() { @@ -31,13 +37,11 @@ public class NPCType { } static { - ImmutableList.Builder builder = new ImmutableList.Builder<>(); - - builder.add(new NPCType(EntityTypes.PLAYER, NPCProperty.GLOW, NPCProperty.FIRE, NPCProperty.SKIN, NPCProperty.SKIN_LAYERS)); - builder.add(new NPCType(EntityTypes.CREEPER, NPCProperty.GLOW, NPCProperty.FIRE)); - builder.add(new NPCType(EntityTypes.ZOMBIE, NPCProperty.GLOW, NPCProperty.FIRE)); - builder.add(new NPCType(EntityTypes.SKELETON, NPCProperty.GLOW, NPCProperty.FIRE)); - - npcTypes = builder.build(); + Set set = new HashSet<>(); + set.add(new NPCType(EntityTypes.PLAYER, NPCProperty.SKIN, NPCProperty.SKIN_LAYERS)); + set.add(new NPCType(EntityTypes.CREEPER)); + set.add(new NPCType(EntityTypes.ZOMBIE)); + set.add(new NPCType(EntityTypes.SKELETON)); + npcTypes = Set.copyOf(set); } }