From 0569df795bf30b0ffac59cfb639b280a63b79dd1 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Sun, 10 Sep 2023 14:31:38 +0530 Subject: [PATCH] added spell property --- .../commands/property/PropertySetCommand.java | 20 +++++++++++++++++++ .../entity/EntityPropertyRegistryImpl.java | 14 +++++++++---- .../lol/pyr/znpcsplus/npc/NpcTypeImpl.java | 3 +++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java index 752f8cb..d8e7a21 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java @@ -1,5 +1,7 @@ package lol.pyr.znpcsplus.commands.property; +import com.github.retrooper.packetevents.PacketEvents; +import com.github.retrooper.packetevents.manager.server.ServerVersion; import com.github.retrooper.packetevents.protocol.world.states.WrappedBlockState; import com.github.retrooper.packetevents.protocol.world.states.type.StateType; import com.github.retrooper.packetevents.protocol.world.states.type.StateTypes; @@ -18,6 +20,7 @@ import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Color; import com.github.retrooper.packetevents.protocol.item.ItemStack; +import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -96,6 +99,20 @@ public class PropertySetCommand implements CommandHandler { return; } } + else if (type == SpellType.class) { + if (PacketEvents.getAPI().getServerManager().getVersion().isOlderThan(ServerVersion.V_1_13)) { + value = context.parse(type); + valueName = String.valueOf(value); + if (((SpellType) value).ordinal() > 3) { + context.send(Component.text("Spell type " + valueName + " is not supported on this version", NamedTextColor.RED)); + return; + } + } + else { + value = context.parse(type); + valueName = String.valueOf(value); + } + } else { value = context.parse(type); valueName = String.valueOf(value); @@ -119,6 +136,9 @@ public class PropertySetCommand implements CommandHandler { if (type == NamedTextColor.class) return context.suggestCollection(NamedTextColor.NAMES.keys()); if (type == Color.class) return context.suggestLiteral("0x0F00FF", "#FFFFFF"); if (type == BlockState.class) return context.suggestLiteral("hand", "looking_at", "block"); + if (type == SpellType.class) return PacketEvents.getAPI().getServerManager().getVersion().isOlderThan(ServerVersion.V_1_13) ? + context.suggestEnum(Arrays.stream(SpellType.values()).filter(spellType -> spellType.ordinal() <= 3).toArray(SpellType[]::new)) : + context.suggestEnum(SpellType.values()); // Suggest enum values directly if (type.isEnum()) { 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 56d8788..a18b539 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -84,9 +84,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerType("enderman_screaming", false); // TODO registerType("enderman_staring", false); // TODO - // Evoker - registerType("evoker_spell", SpellType.NONE); - // Frog registerType("frog_variant", FrogVariant.TEMPERATE); @@ -271,7 +268,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) batIndex = 12; else if (ver.isNewerThanOrEquals(ServerVersion.V_1_9)) batIndex = 11; else batIndex = 16; - register(new BooleanProperty("hanging", batIndex, false, true /* This isnt a mistake */)); + register(new BooleanProperty("hanging", batIndex, false, true /* This isn't a mistake */)); // Blaze final int blazeIndex; @@ -344,6 +341,15 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { linkProperties("is_saddled", "is_eating", "is_rearing", "has_mouth_open"); } + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_11)) return; + // Spellcaster Illager + int spellIndex = 12; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) spellIndex = 17; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) spellIndex = 16; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) spellIndex = 15; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_12)) spellIndex = 13; + register(new EncodedByteProperty<>("spell", SpellType.NONE, spellIndex, obj -> (byte) Math.min(obj.ordinal(), ver.isOlderThan(ServerVersion.V_1_13) ? 3 : 5))); + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_14)) return; // Pose register(new NpcPoseProperty()); 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 b22810a..81fa7b0 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java @@ -129,6 +129,9 @@ public class NpcTypeImpl implements NpcType { } else if (version.isOlderThan(ServerVersion.V_1_11) && type.equals(EntityTypes.HORSE)) { addProperties("has_chest"); } + if (EntityTypes.isTypeInstanceOf(type, EntityTypes.ABSTRACT_EVO_ILLU_ILLAGER)) { + addProperties("spell"); + } return new NpcTypeImpl(name, type, hologramOffset, new HashSet<>(allowedProperties), defaultProperties); } }