From 82cd0d1a81ee6a59a767ddf46e3c02c129f331de Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Mon, 2 Oct 2023 09:59:14 +0530 Subject: [PATCH] added sniffer_state property --- .../lol/pyr/znpcsplus/util/SnifferState.java | 11 +++++++ .../java/lol/pyr/znpcsplus/ZNpcsPlus.java | 1 + .../entity/EntityPropertyRegistryImpl.java | 1 + .../properties/SnifferStateProperty.java | 30 +++++++++++++++++++ .../znpcsplus/npc/NpcTypeRegistryImpl.java | 3 +- 5 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 api/src/main/java/lol/pyr/znpcsplus/util/SnifferState.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SnifferStateProperty.java diff --git a/api/src/main/java/lol/pyr/znpcsplus/util/SnifferState.java b/api/src/main/java/lol/pyr/znpcsplus/util/SnifferState.java new file mode 100644 index 0000000..a532947 --- /dev/null +++ b/api/src/main/java/lol/pyr/znpcsplus/util/SnifferState.java @@ -0,0 +1,11 @@ +package lol.pyr.znpcsplus.util; + +public enum SnifferState { + IDLING, + FEELING_HAPPY, + SCENTING, + SNIFFING, + SEARCHING, + DIGGING, + RISING +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java index f4736d6..e4f548c 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java @@ -279,6 +279,7 @@ public class ZNpcsPlus extends JavaPlugin { registerEnumParser(manager, PuffState.class, incorrectUsageMessage); registerEnumParser(manager, LookType.class, incorrectUsageMessage); registerEnumParser(manager, TropicalFishVariant.TropicalFishPattern.class, incorrectUsageMessage); + registerEnumParser(manager, SnifferState.class, incorrectUsageMessage); manager.registerCommand("npc", new MultiCommand(loadHelpMessage("root")) .addSubcommand("center", new CenterCommand(npcRegistry)) 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 e97658c..c7a188c 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -77,6 +77,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerEnumSerializer(PandaGene.class); registerEnumSerializer(PuffState.class); registerEnumSerializer(TropicalFishVariant.TropicalFishPattern.class); + registerEnumSerializer(SnifferState.class); registerPrimitiveSerializers(Integer.class, Boolean.class, Double.class, Float.class, Long.class, Short.class, Byte.class, String.class); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SnifferStateProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SnifferStateProperty.java new file mode 100644 index 0000000..c0e1ef5 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/SnifferStateProperty.java @@ -0,0 +1,30 @@ +package lol.pyr.znpcsplus.entity.properties; + +import com.github.retrooper.packetevents.protocol.entity.data.EntityData; +import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; +import lol.pyr.znpcsplus.entity.EntityPropertyImpl; +import lol.pyr.znpcsplus.entity.PacketEntity; +import lol.pyr.znpcsplus.util.SnifferState; +import org.bukkit.entity.Player; + +import java.util.Map; + +public class SnifferStateProperty extends EntityPropertyImpl { + private final int index; + + public SnifferStateProperty(int index) { + super("sniffer_state", SnifferState.IDLING, SnifferState.class); + this.index = index; + } + + @Override + public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { + SnifferState state = entity.getProperty(this); + if (state == null) return; + try { + properties.put(index, newEntityData(index, EntityDataTypes.SNIFFER_STATE, com.github.retrooper.packetevents.protocol.entity.sniffer.SnifferState.valueOf(state.name()))); + } catch (IllegalArgumentException e) { + // ignore + } + } +} 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 9227d99..1ff68cb 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java @@ -352,7 +352,8 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry { if (!version.isNewerThanOrEquals(ServerVersion.V_1_20)) return; register(builder(p, "sniffer", EntityTypes.SNIFFER) - .setHologramOffset(0.125)); + .setHologramOffset(0.125) + .addProperties("sniffer_state")); register(builder(p, "camel", EntityTypes.CAMEL) .setHologramOffset(0.25)