diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/CitizensImporter.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/CitizensImporter.java index 2a17d34..86e3895 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/CitizensImporter.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/citizens/CitizensImporter.java @@ -82,6 +82,8 @@ public class CitizensImporter implements DataImporter { world = Bukkit.getWorlds().get(0).getName(); } NpcImpl npc = new NpcImpl(uuid, propertyRegistry, configManager, packetFactory, textSerializer, world, typeRegistry.getByName("armor_stand"), new NpcLocation(0, 0, 0, 0, 0)); + npc.getType().applyDefaultProperties(npc); + npc.getHologram().addTextLineComponent(textSerializer.deserialize(name)); ConfigurationSection traits = npcSection.getConfigurationSection("traits"); if (traits != null) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/znpcs/ZNpcImporter.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/znpcs/ZNpcImporter.java index 202d477..4fa3c76 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/znpcs/ZNpcImporter.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/znpcs/ZNpcImporter.java @@ -103,6 +103,7 @@ public class ZNpcImporter implements DataImporter { NpcLocation location = new NpcLocation(oldLoc.getX(), oldLoc.getY(), oldLoc.getZ(), oldLoc.getYaw(), oldLoc.getPitch()); UUID uuid = model.getUuid() == null ? UUID.randomUUID() : model.getUuid(); NpcImpl npc = new NpcImpl(uuid, propertyRegistry, configManager, packetFactory, textSerializer, oldLoc.getWorld(), typeRegistry.getByName(type), location); + npc.getType().applyDefaultProperties(npc); HologramImpl hologram = npc.getHologram(); hologram.setOffset(model.getHologramHeight()); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcRegistryImpl.java index 6de6b1e..78ab624 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcRegistryImpl.java @@ -139,6 +139,7 @@ public class NpcRegistryImpl implements NpcRegistry { id = id.toLowerCase(); if (npcIdLookupMap.containsKey(id)) throw new IllegalArgumentException("An npc with the id " + id + " already exists!"); NpcImpl npc = new NpcImpl(UUID.randomUUID(), propertyRegistry, configManager, textSerializer, world, type, location, packetFactory); + type.applyDefaultProperties(npc); NpcEntryImpl entry = new NpcEntryImpl(id, npc); register(entry); return entry; diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java index 5a9131e..6c42efe 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java @@ -16,14 +16,16 @@ import java.util.stream.Collectors; public class NpcTypeImpl implements NpcType { private final EntityType type; private final Set> allowedProperties; + private final Map, Object> defaultProperties; private final String name; private final double hologramOffset; - private NpcTypeImpl(String name, EntityType type, double hologramOffset, Set> allowedProperties) { + private NpcTypeImpl(String name, EntityType type, double hologramOffset, Set> allowedProperties, Map, Object> defaultProperties) { this.name = name.toLowerCase(); this.type = type; this.hologramOffset = hologramOffset; this.allowedProperties = allowedProperties; + this.defaultProperties = defaultProperties; } public String getName() { @@ -42,6 +44,12 @@ public class NpcTypeImpl implements NpcType { return allowedProperties.stream().map(property -> (EntityProperty) property).collect(Collectors.toSet()); } + public void applyDefaultProperties(NpcImpl npc) { + for (Map.Entry, Object> entry : defaultProperties.entrySet()) { + npc.UNSAFE_setProperty(entry.getKey(), entry.getValue()); + } + } + protected static final class Builder { private final static Logger logger = Logger.getLogger("NpcTypeBuilder"); @@ -49,6 +57,7 @@ public class NpcTypeImpl implements NpcType { private final String name; private final EntityType type; private final List> allowedProperties = new ArrayList<>(); + private final Map, Object> defaultProperties = new HashMap<>(); private double hologramOffset = 0; Builder(EntityPropertyRegistryImpl propertyRegistry, String name, EntityType type) { @@ -81,6 +90,17 @@ public class NpcTypeImpl implements NpcType { return this; } + @SuppressWarnings("unchecked") + public Builder addDefaultProperty(String name, T value) { + EntityPropertyImpl property = (EntityPropertyImpl) propertyRegistry.getByName(name); + if (property == null) { + logger.warning("Tried to register the non-existent \"" + name + "\" default property to the \"" + this.name + "\" npc type"); + return this; + } + defaultProperties.put(property, value); + return this; + } + public Builder setHologramOffset(double hologramOffset) { this.hologramOffset = hologramOffset; return this; @@ -109,7 +129,7 @@ public class NpcTypeImpl implements NpcType { } else if (version.isOlderThan(ServerVersion.V_1_11) && type.equals(EntityTypes.HORSE)) { addProperties("has_chest"); } - return new NpcTypeImpl(name, type, hologramOffset, new HashSet<>(allowedProperties)); + return new NpcTypeImpl(name, type, hologramOffset, new HashSet<>(allowedProperties), defaultProperties); } } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java index 6835ead..bcb0856 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java @@ -36,7 +36,14 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry { register(builder(p, "player", EntityTypes.PLAYER) .setHologramOffset(-0.15D) .addEquipmentProperties() - .addProperties("skin_cape", "skin_jacket", "skin_left_sleeve", "skin_right_sleeve", "skin_left_leg", "skin_right_leg", "skin_hat", "shoulder_entity_left", "shoulder_entity_right")); + .addProperties("skin_cape", "skin_jacket", "skin_left_sleeve", "skin_right_sleeve", "skin_left_leg", "skin_right_leg", "skin_hat", "shoulder_entity_left", "shoulder_entity_right") + .addDefaultProperty("skin_cape", true) + .addDefaultProperty("skin_jacket", true) + .addDefaultProperty("skin_left_sleeve", true) + .addDefaultProperty("skin_right_sleeve", true) + .addDefaultProperty("skin_left_leg", true) + .addDefaultProperty("skin_right_leg", true) + .addDefaultProperty("skin_hat", true)); // Most hologram offsets generated using Entity#getHeight() in 1.19.4