diff --git a/api/src/main/java/lol/pyr/znpcsplus/api/entity/PropertyHolder.java b/api/src/main/java/lol/pyr/znpcsplus/api/entity/PropertyHolder.java index 1c4fb67..cd10b37 100644 --- a/api/src/main/java/lol/pyr/znpcsplus/api/entity/PropertyHolder.java +++ b/api/src/main/java/lol/pyr/znpcsplus/api/entity/PropertyHolder.java @@ -10,7 +10,7 @@ public interface PropertyHolder { * Method used to get the value of a property from a property holder * * @param key Unique key representing a property - * @return The value associated with the provided property key & this holder + * @return The value associated with the provided property key and this holder * @param The type of the property value */ T getProperty(EntityProperty key); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java index 11e6fdb..86662d7 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -127,6 +127,8 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new DummyProperty<>("look_distance", configManager.getConfig().lookPropertyDistance())); register(new DummyProperty<>("view_distance", configManager.getConfig().viewDistance())); + register(new DummyProperty<>("permission_required", false)); + register(new GlowProperty(packetFactory)); register(new BitsetProperty("fire", 0, 0x01)); register(new BitsetProperty("invisible", 0, 0x20)); @@ -274,6 +276,13 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new BitsetProperty("is_retracting_spikes", guardianIndex++, 0x02, false, legacyBooleans)); linkProperties("is_elder", "is_retracting_spikes"); // TODO: add guardian beam target + } else { + int guardianIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) guardianIndex = 16; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) guardianIndex = 15; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) guardianIndex = 14; + else guardianIndex = 12; + register(new BooleanProperty("is_retracting_spikes", guardianIndex, false, false)); } // Horse 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 3a4527e..846e420 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java @@ -115,7 +115,7 @@ public class NpcTypeImpl implements NpcType { public NpcTypeImpl build() { ServerVersion version = PacketEvents.getAPI().getServerManager().getVersion(); addProperties("fire", "invisible", "silent", "look", "look_distance", "view_distance", - "potion_color", "potion_ambient", "display_name"); + "potion_color", "potion_ambient", "display_name", "permission_required"); if (!type.equals(EntityTypes.PLAYER)) addProperties("dinnerbone"); // TODO: make this look nicer after completing the rest of the properties if (version.isNewerThanOrEquals(ServerVersion.V_1_9)) addProperties("glow"); @@ -161,6 +161,9 @@ public class NpcTypeImpl implements NpcType { if (EntityTypes.isTypeInstanceOf(type, EntityTypes.ABSTRACT_TAMEABLE_ANIMAL)) { addProperties("tamed", "sitting"); } + if (EntityTypes.isTypeInstanceOf(type, EntityTypes.GUARDIAN)) { + addProperties("is_retracting_spikes"); + } 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 5e8bb6f..2cc382f 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java @@ -97,7 +97,7 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry { register(builder(p, "guardian", EntityTypes.GUARDIAN) .setHologramOffset(-1.125) - .addProperties("is_elder", "is_retracting_spikes")); + .addProperties("is_elder")); register(builder(p, "horse", EntityTypes.HORSE) .setHologramOffset(-0.375) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/tasks/NpcProcessorTask.java b/plugin/src/main/java/lol/pyr/znpcsplus/tasks/NpcProcessorTask.java index 2f45c55..054daaa 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/tasks/NpcProcessorTask.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/tasks/NpcProcessorTask.java @@ -30,6 +30,7 @@ public class NpcProcessorTask extends BukkitRunnable { EntityPropertyImpl viewDistanceProperty = propertyRegistry.getByName("view_distance", Integer.class); // Not sure why this is an Integer, but it is EntityPropertyImpl lookProperty = propertyRegistry.getByName("look", LookType.class); EntityPropertyImpl lookDistanceProperty = propertyRegistry.getByName("look_distance", Double.class); + EntityPropertyImpl permissionRequiredProperty = propertyRegistry.getByName("permission_required", Boolean.class); double lookDistance; for (NpcEntryImpl entry : npcRegistry.getProcessable()) { NpcImpl npc = entry.getNpc(); @@ -39,11 +40,16 @@ public class NpcProcessorTask extends BukkitRunnable { Player closest = null; LookType lookType = npc.getProperty(lookProperty); lookDistance = NumberConversions.square(npc.getProperty(lookDistanceProperty)); + boolean permissionRequired = npc.getProperty(permissionRequiredProperty); for (Player player : Bukkit.getOnlinePlayers()) { if (!player.getWorld().equals(npc.getWorld())) { if (npc.isVisibleTo(player)) npc.hide(player); continue; } + if (permissionRequired && !player.hasPermission("znpcsplus.npc." + entry.getId())) { + if (npc.isVisibleTo(player)) npc.hide(player); + continue; + } double distance = player.getLocation().distanceSquared(npc.getBukkitLocation()); // visibility