add NPCType builder
This commit is contained in:
parent
24c6e9695e
commit
499780bd24
1 changed files with 43 additions and 10 deletions
|
@ -22,14 +22,10 @@ public class NPCType {
|
||||||
private final Set<NPCProperty<?>> allowedProperties;
|
private final Set<NPCProperty<?>> allowedProperties;
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
private NPCType(String name, EntityType type, NPCProperty<?>... allowedProperties) {
|
private NPCType(String name, EntityType type, Set<NPCProperty<?>> allowedProperties) {
|
||||||
this.name = name.toUpperCase();
|
this.name = name.toUpperCase();
|
||||||
this.type = type;
|
this.type = type;
|
||||||
ArrayList<NPCProperty<?>> list = new ArrayList<>(List.of(allowedProperties));
|
this.allowedProperties = allowedProperties;
|
||||||
list.add(NPCProperty.FIRE);
|
|
||||||
list.add(NPCProperty.INVISIBLE);
|
|
||||||
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) list.add(NPCProperty.GLOW);
|
|
||||||
this.allowedProperties = Set.copyOf(list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -44,15 +40,52 @@ public class NPCType {
|
||||||
return allowedProperties;
|
return allowedProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void register(Builder builder) {
|
||||||
|
register(builder.build());
|
||||||
|
}
|
||||||
|
|
||||||
private static void register(NPCType type) {
|
private static void register(NPCType type) {
|
||||||
BY_NAME.put(type.getName(), type);
|
BY_NAME.put(type.getName(), type);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
register(new NPCType("player", EntityTypes.PLAYER, NPCProperty.SKIN, NPCProperty.SKIN_LAYERS));
|
register(new Builder("player", EntityTypes.PLAYER)
|
||||||
register(new NPCType("creeper", EntityTypes.CREEPER));
|
.addProperties(NPCProperty.SKIN, NPCProperty.SKIN_LAYERS));
|
||||||
register(new NPCType("zombie", EntityTypes.ZOMBIE));
|
register(new Builder("creeper", EntityTypes.CREEPER));
|
||||||
register(new NPCType("skeleton", EntityTypes.SKELETON));
|
register(new Builder("zombie", EntityTypes.ZOMBIE));
|
||||||
|
register(new Builder("skeleton", EntityTypes.SKELETON));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class Builder {
|
||||||
|
private final String name;
|
||||||
|
private final EntityType type;
|
||||||
|
private final List<NPCProperty<?>> allowedProperties = new ArrayList<>();
|
||||||
|
private boolean globalProperties = true;
|
||||||
|
|
||||||
|
private Builder(String name, EntityType type) {
|
||||||
|
this.name = name;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder addProperties(NPCProperty<?>... properties) {
|
||||||
|
allowedProperties.addAll(List.of(properties));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setEnableGlobalProperties(boolean enabled) {
|
||||||
|
globalProperties = enabled;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NPCType build() {
|
||||||
|
if (globalProperties) {
|
||||||
|
allowedProperties.add(NPCProperty.FIRE);
|
||||||
|
allowedProperties.add(NPCProperty.INVISIBLE);
|
||||||
|
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9))
|
||||||
|
allowedProperties.add(NPCProperty.GLOW);
|
||||||
|
}
|
||||||
|
return new NPCType(name, type, Set.copyOf(allowedProperties));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue