better property definitions

This commit is contained in:
Pyrbu 2023-04-25 00:08:13 +01:00
parent c97f4a697e
commit 679552a40c

@ -1,16 +1,19 @@
package lol.pyr.znpcsplus.npc; 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.EntityType;
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes; 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.List;
import java.util.Set; import java.util.Set;
public class NPCType { public class NPCType {
private final static ImmutableList<NPCType> npcTypes; private final static Set<NPCType> npcTypes;
public static List<NPCType> values() { public static Set<NPCType> values() {
return npcTypes; return npcTypes;
} }
@ -19,7 +22,10 @@ public class NPCType {
public NPCType(EntityType type, NPCProperty<?>... allowedProperties) { public NPCType(EntityType type, NPCProperty<?>... allowedProperties) {
this.type = type; this.type = type;
this.allowedProperties = Set.of(allowedProperties); ArrayList<NPCProperty<?>> 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() { public EntityType getType() {
@ -31,13 +37,11 @@ public class NPCType {
} }
static { static {
ImmutableList.Builder<NPCType> builder = new ImmutableList.Builder<>(); Set<NPCType> set = new HashSet<>();
set.add(new NPCType(EntityTypes.PLAYER, NPCProperty.SKIN, NPCProperty.SKIN_LAYERS));
builder.add(new NPCType(EntityTypes.PLAYER, NPCProperty.GLOW, NPCProperty.FIRE, NPCProperty.SKIN, NPCProperty.SKIN_LAYERS)); set.add(new NPCType(EntityTypes.CREEPER));
builder.add(new NPCType(EntityTypes.CREEPER, NPCProperty.GLOW, NPCProperty.FIRE)); set.add(new NPCType(EntityTypes.ZOMBIE));
builder.add(new NPCType(EntityTypes.ZOMBIE, NPCProperty.GLOW, NPCProperty.FIRE)); set.add(new NPCType(EntityTypes.SKELETON));
builder.add(new NPCType(EntityTypes.SKELETON, NPCProperty.GLOW, NPCProperty.FIRE)); npcTypes = Set.copyOf(set);
npcTypes = builder.build();
} }
} }