diff --git a/src/main/java/io/github/znetworkw/znpcservers/configuration/Configuration.java b/src/main/java/io/github/znetworkw/znpcservers/configuration/Configuration.java index 15d49c8..751c110 100644 --- a/src/main/java/io/github/znetworkw/znpcservers/configuration/Configuration.java +++ b/src/main/java/io/github/znetworkw/znpcservers/configuration/Configuration.java @@ -1,6 +1,5 @@ package io.github.znetworkw.znpcservers.configuration; -import com.google.common.collect.ImmutableList; import com.google.gson.JsonElement; import com.google.gson.JsonParser; import com.google.gson.internal.$Gson$Types; @@ -25,9 +24,6 @@ public class Configuration { private final Map configurationValues; public static final Configuration CONFIGURATION = new Configuration("config"); public static final Configuration MESSAGES = new Configuration("messages"); - public static final Configuration CONVERSATIONS = new Configuration("conversations"); - public static final Configuration DATA = new Configuration("data"); - public static final ImmutableList SAVE_CONFIGURATIONS = ImmutableList.of(CONVERSATIONS, DATA); protected Configuration(String name) { this(name, ZNPCsPlus.PLUGIN_FOLDER.toPath().resolve(name + ".json")); diff --git a/src/main/java/io/github/znetworkw/znpcservers/npc/NPCType.java b/src/main/java/io/github/znetworkw/znpcservers/npc/NPCType.java deleted file mode 100644 index 416fa87..0000000 --- a/src/main/java/io/github/znetworkw/znpcservers/npc/NPCType.java +++ /dev/null @@ -1,98 +0,0 @@ -package io.github.znetworkw.znpcservers.npc; - -import io.github.znetworkw.znpcservers.utility.Utils; - -import static io.github.znetworkw.znpcservers.reflection.Reflections.*; - -/** - * Delete after information transferred - */ -@SuppressWarnings("unused") -public enum NPCType { - ALLAY(ENTITY_ALLAY_CLASS, -1.14), - ARMOR_STAND(ENTITY_ARMOR_STAND_CLASS, 0.2775, "setSmall", "setArms"), - AXOLOTL(ENTITY_AXOLOTL_CLASS, -1.395, "setVariant", "setAge"), - BAT(ENTITY_BAT_CLASS, -0.915, "setAwake"), - BEE(ENTITY_BEE_CLASS, -1.215, "setAnger", "setHasNectar", "setHasStung"), - BLAZE(ENTITY_BLAZE_CLASS, -0.015), - CAT(ENTITY_CAT_CLASS, -1.115, "setCatType", "setAge", "setCollarColor", "setTamed"), - CAVE_SPIDER(ENTITY_CAVE_SPIDER_CLASS, -1.315), - CHICKEN(ENTITY_CHICKEN_CLASS, -1.115, "setAge"), - COD(ENTITY_COD_CLASS, -1.515), - COW(ENTITY_COW_CLASS, -0.415, "setAge"), - CREEPER(ENTITY_CREEPER_CLASS, -0.115, "setPowered"), - DOLPHIN(ENTITY_DOLPHIN_CLASS, -1.215), - DONKEY(ENTITY_DONKEY_CLASS, -0.315, "setAge", "setCarryingChest"), - DROWNED(ENTITY_DROWNED_CLASS, 0.135), - ELDER_GUARDIAN(ENTITY_ELDER_GUARDIAN_CLASS, 0.182), - ENDER_DRAGON(ENTITY_ENDER_DRAGON_CLASS, 6.185, "setSilent"), - ENDERMAN(ENTITY_ENDERMAN_CLASS, 1.085), - ENDERMITE(ENTITY_ENDERMITE_CLASS, -1.515), - EVOKER(ENTITY_EVOKER_CLASS, 0.135, "setCurrentSpell"), - FOX(ENTITY_FOX_CLASS, -1.115, "setFoxType", "setSitting", "setSleeping", "setAge", "setCrouching"), - FROG(ENTITY_FROG_CLASS, -1.315, "setVariant"), - GHAST(ENTITY_GHAST_CLASS, 2.185), - GIANT(ENTITY_GIANT_ZOMBIE_CLASS, 10.185), - GLOW_SQUID(ENTITY_GLOW_SQUID_CLASS, -1.015), - GOAT(ENTITY_GOAT_CLASS, -0.515, "setScreamingGoat", "setAge", "setLeftHorn", "setRightHorn"), - GUARDIAN(ENTITY_GUARDIAN_CLASS, -0.965), - HORSE(ENTITY_HORSE_CLASS, -0.215, "setStyle", "setAge", "setColor", "setVariant"), - HOGLIN(ENTITY_HOGLIN_CLASS, -0.415, "setAge"), - HUSK(ENTITY_HUSK_CLASS, 0.135), - ILLUSIONER(ENTITY_ILLUSIONER_CLASS, 0.135), - IRON_GOLEM(ENTITY_IRON_GOLEM_CLASS, 0.885), - LLAMA(ENTITY_LLAMA_CLASS, 0.055, "setAge", "setColor"), - MAGMA_CUBE(ENTITY_MAGMA_CUBE_CLASS, 0.225, "setSize"), - MUSHROOM_COW(ENTITY_MUSHROOM_COW_CLASS, -0.415, "setAge", "setVariant"), - MULE(ENTITY_MULE_CLASS, -0.215, "setAge", "setCarryingChest"), - OCELOT(ENTITY_OCELOT_CLASS, -1.115, "setCatType", "setAge"), - PANDA(ENTITY_PANDA_CLASS, -0.565, "setAge", "setMainGene", "setHiddenGene"), - PARROT(ENTITY_PARROT_CLASS, -0.915, "setVariant", "setAge", "setSitting"), - PHANTOM(ENTITY_PHANTOM_CLASS, -1.315, "setSize"), - PIG(ENTITY_PIG_CLASS, -0.915, "setAge", "setSaddle"), - PIGLIN(ENTITY_PIGLIN_CLASS, 0.135, "setBaby"), - PIGLIN_BRUTE(ENTITY_PIGLIN_BRUTE_CLASS, 0.135, "setBaby"), - PILLAGER(ENTITY_PILLAGER_CLASS, 0.135), - PLAYER(ENTITY_PLAYER_CLASS, 0.0), - POLAR_BEAR(ENTITY_POLAR_BEAR_CLASS, -0.415, "setAge"), - PUFFERFISH(ENTITY_PUFFERFISH_CLASS, -1.115, "setPuffState"), - RABBIT(ENTITY_RABBIT_CLASS, -1.315, "setRabbitType"), - RAVAGER(ENTITY_RAVAGER_CLASS, 0.385), - SALMON(ENTITY_SALMON_CLASS, -1.415), - SHEEP(ENTITY_SHEEP_CLASS, -0.515, "setAge", "setSheared", "setColor"), - SHULKER(ENTITY_SHULKER_CLASS, -0.815, "setPeek", "setColor"), - SILVERFISH(ENTITY_SILVERFISH_CLASS, -1.515), - SKELETON(ENTITY_SKELETON_CLASS, 0.175, "setSkeletonType"), - SKELETON_HORSE(ENTITY_SKELETON_HORSE_CLASS, -0.215), - SLIME(ENTITY_SLIME_CLASS, 0.225, "setSize"), - SNOWMAN(ENTITY_SNOWMAN_CLASS, 0.085, "setHasPumpkin", "setDerp"), - SPIDER(ENTITY_SPIDER_CLASS, -0.915), - SQUID(ENTITY_SQUID_CLASS, -1.015), - STRAY(ENTITY_STRAY_CLASS, 0.175), - STRIDER(ENTITY_STRIDER_CLASS, -0.115, "setSaddled", "setShivering", "setBaby"), - TADPOLE(ENTITY_TADPOLE_CLASS, -1.515, "setAge"), - TRADER_LLAMA(ENTITY_TRADER_LLAMA_CLASS, 0.055, "setAge", "setColor"), - TROPICAL_FISH(ENTITY_TROPICAL_FISH_CLASS, -1.415, "setPattern", "setBodyColor", "setPatternColor"), - TURTLE(ENTITY_TURTLE, -1.415, "setAge"), - VEX(ENTITY_VEX_CLASS, -1.015, "setCharging"), - VILLAGER(ENTITY_VILLAGER_CLASS, 0.135, "setProfession", "setVillagerType", "setAge", "setVillagerLevel"), - VINDICATOR(ENTITY_VINDICATOR_CLASS, 0.135), - WANDERING_TRADER(ENTITY_WANDERING_TRADER_CLASS, 0.135), - WARDEN(ENTITY_WARDEN, 1.085, "setSilent"), - WITCH(ENTITY_WITCH_CLASS, 0.135), - WITHER(ENTITY_WITHER_CLASS, 1.685), - WITHER_SKELETON(ENTITY_WITHER_SKELETON_CLASS, 0.585), - WOLF(ENTITY_WOLF_CLASS, -0.965, "setSitting", "setTamed", "setAngry", "setAge", "setCollarColor"), - ZOGLIN(ENTITY_ZOGLIN_CLASS, -0.415, "setBaby"), - ZOMBIE(ENTITY_ZOMBIE_CLASS, 0.135, "setBaby"), - ZOMBIE_HORSE(ENTITY_ZOMBIE_HORSE_CLASS, -0.215, "setBaby"), - ZOMBIE_VILLAGER(ENTITY_ZOMBIE_VILLAGER_CLASS, 0.135, "setVillagerType", "setVillagerProfession", "setBaby"), - ZOMBIFIED_PIGLIN(Utils.versionNewer(16) ? ENTITY_ZOMBIFIED_PIGLIN_CLASS : null, 0.135, "setBaby"), - PIG_ZOMBIE(Utils.versionNewer(16) ? null : ENTITY_ZOMBIFIED_PIGLIN_CLASS, 0.135); - - NPCType(Class entityClass, String newName, double holoHeight, String ... methods) { - } - - NPCType(Class entityClass, double holoHeight, String ... customization) { - } -} \ No newline at end of file diff --git a/src/main/java/io/github/znetworkw/znpcservers/reflection/EnumPropertyCache.java b/src/main/java/io/github/znetworkw/znpcservers/reflection/EnumPropertyCache.java deleted file mode 100644 index 2907ba3..0000000 --- a/src/main/java/io/github/znetworkw/znpcservers/reflection/EnumPropertyCache.java +++ /dev/null @@ -1,43 +0,0 @@ -package io.github.znetworkw.znpcservers.reflection; - -import java.util.Objects; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -/** - * Gonalez decided to make every single enum we load be stored in this map - * to make NPC property application easier however this is terribly inefficient - * for memory. The entire NPC property system will most likely need a rewrite. - */ -public class EnumPropertyCache { - protected static final ConcurrentMap CACHE = new ConcurrentHashMap<>(); - - public static Object find(String name, Class objectClass) { - return CACHE.get(new CacheKey(name, objectClass)); - } - - public static void register(String name, Object object, Class objectClass) { - CACHE.putIfAbsent(new CacheKey(name, objectClass), object); - } - - private static class CacheKey { - private final Class type; - private final String value; - - public CacheKey(String value, Class type) { - this.type = type; - this.value = value; - } - - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - CacheKey classKey = (CacheKey) o; - return (Objects.equals(this.type, classKey.type) && Objects.equals(this.value, classKey.value)); - } - - public int hashCode() { - return Objects.hash(this.type, this.value); - } - } -} \ No newline at end of file diff --git a/src/main/java/io/github/znetworkw/znpcservers/reflection/ReflectionPackage.java b/src/main/java/io/github/znetworkw/znpcservers/reflection/ReflectionPackage.java index b7a3df1..08f88db 100644 --- a/src/main/java/io/github/znetworkw/znpcservers/reflection/ReflectionPackage.java +++ b/src/main/java/io/github/znetworkw/znpcservers/reflection/ReflectionPackage.java @@ -21,20 +21,7 @@ public class ReflectionPackage { * package string which is another quirk of the old server jars. */ public static final String MINECRAFT = join("net.minecraft", flattened ? "server." + Utils.getBukkitPackage() : ""); - - public static final String NETWORK = flattened ? MINECRAFT : join(MINECRAFT, "network"); - public static final String PROTOCOL = flattened ? MINECRAFT : join(MINECRAFT, "network.protocol"); - public static final String CHAT = flattened ? MINECRAFT : join(MINECRAFT, "network.chat"); - public static final String PACKET = flattened ? MINECRAFT : join(MINECRAFT, "network.protocol.game"); - public static final String SYNCHER = flattened ? MINECRAFT : join(MINECRAFT, "network.syncher"); public static final String ENTITY = flattened ? MINECRAFT : join(MINECRAFT, "world.entity"); - public static final String WORLD_ENTITY_PLAYER = flattened ? MINECRAFT : join(MINECRAFT, "world.entity.player"); - public static final String ITEM = flattened ? MINECRAFT : join(MINECRAFT, "world.item"); - public static final String WORLD_LEVEL = flattened ? MINECRAFT : join(MINECRAFT, "world.level"); - public static final String WORLD_SCORES = flattened ? MINECRAFT : join(MINECRAFT, "world.scores"); - public static final String SERVER_LEVEL = flattened ? MINECRAFT : join(MINECRAFT, "server.level"); - public static final String SERVER_NETWORK = flattened ? MINECRAFT : join(MINECRAFT, "server.network"); - public static final String SERVER = flattened ? MINECRAFT : join(MINECRAFT, "server"); // Simple method that joins all the non-null & non-empty arguments with a dot and returns the result public static String join(String... parts) { diff --git a/src/main/java/io/github/znetworkw/znpcservers/reflection/Reflections.java b/src/main/java/io/github/znetworkw/znpcservers/reflection/Reflections.java index 1ea090f..c6cf81a 100644 --- a/src/main/java/io/github/znetworkw/znpcservers/reflection/Reflections.java +++ b/src/main/java/io/github/znetworkw/znpcservers/reflection/Reflections.java @@ -2,663 +2,33 @@ package io.github.znetworkw.znpcservers.reflection; import com.mojang.authlib.GameProfile; import io.github.znetworkw.znpcservers.reflection.types.ClassReflection; -import io.github.znetworkw.znpcservers.reflection.types.ConstructorReflection; import io.github.znetworkw.znpcservers.reflection.types.FieldReflection; import io.github.znetworkw.znpcservers.reflection.types.MethodReflection; import io.github.znetworkw.znpcservers.utility.Utils; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandMap; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; import java.lang.reflect.Method; -import java.util.Collection; -import java.util.List; -import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; /** - * Class containing all of the lazy-loaded reflections that the plugin uses to access - * inaccessible things from the server jar like packets, raw entity classes, etc. + * Class containing all of the lazy-loaded reflections that the plugin + * uses to accessinaccessible things from the server jar. */ public final class Reflections { - public static final Class ENUM_PLAYER_INFO_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName("PacketPlayOutPlayerInfo$EnumPlayerInfoAction") - .withClassName("ClientboundPlayerInfoUpdatePacket$a")).get(); - - public static final Class PACKET_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.PROTOCOL) - .withClassName("Packet")).get(); - public static final Class ENTITY_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) .withClassName("Entity")).get(); - public static final Class ENTITY_LIVING = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withClassName("EntityLiving")).get(); - - public static final Class ENTITY_ALLAY_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal.allay") - .withClassName("Allay").setStrict(Utils.versionNewer(19))).get(); - - public static final Class ENTITY_AXOLOTL_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal.axolotl") - .withClassName("Axolotl").setStrict(Utils.versionNewer(17))).get(); - - public static final Class ENTITY_ARMOR_STAND_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("decoration") - .withClassName("EntityArmorStand")).get(); - - public static final Class ENTITY_BAT_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("ambient") - .withClassName("EntityBat")).get(); - - public static final Class ENTITY_BEE_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal") - .withClassName("EntityBee").setStrict(Utils.versionNewer(15))).get(); - - public static final Class ENTITY_BLAZE_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntityBlaze")).get(); - - public static final Class ENTITY_CAT_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal") - .withClassName("EntityCat").setStrict(Utils.versionNewer(14))).get(); - - public static final Class ENTITY_CAVE_SPIDER_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntityCaveSpider")).get(); - - public static final Class ENTITY_CHICKEN_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal") - .withClassName("EntityChicken")).get(); - - public static final Class ENTITY_COD_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal") - .withClassName("EntityCod").setStrict(Utils.versionNewer(13))).get(); - - public static final Class ENTITY_COW_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal") - .withClassName("EntityCow")).get(); - - public static final Class ENTITY_CREEPER_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntityCreeper")).get(); - - public static final Class ENTITY_DOLPHIN_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal") - .withClassName("EntityDolphin").setStrict(Utils.versionNewer(13))).get(); - - public static final Class ENTITY_DONKEY_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal.horse") - .withClassName("EntityHorseDonkey") - .setStrict(Utils.versionNewer(11))).get(); - - public static final Class ENTITY_DROWNED_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntityDrowned") - .setStrict(Utils.versionNewer(13))).get(); - - public static final Class ENTITY_ELDER_GUARDIAN_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntityGuardianElder") - .setStrict(Utils.versionNewer(11))).get(); - - public static final Class ENTITY_ENDER_DRAGON_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("boss.enderdragon") - .withClassName("EntityEnderDragon")).get(); - - public static final Class ENTITY_ENDERMAN_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntityEnderman")).get(); - - public static final Class ENTITY_ENDERMITE_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntityEndermite")).get(); - - public static final Class ENTITY_EVOKER_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntityEvoker").setStrict(Utils.versionNewer(11))).get(); - - public static final Class ENTITY_FOX_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal") - .withClassName("EntityFox").setStrict(Utils.versionNewer(14))).get(); - - public static final Class ENTITY_FROG_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal.frog") - .withClassName("Frog").setStrict(Utils.versionNewer(19))).get(); - - public static final Class ENTITY_GHAST_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntityGhast")).get(); - - public static final Class ENTITY_GIANT_ZOMBIE_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntityGiantZombie")).get(); - - public static final Class ENTITY_GLOW_SQUID_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withClassName("GlowSquid").setStrict(Utils.versionNewer(17))).get(); - - public static final Class ENTITY_GOAT_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal.goat") - .withClassName("Goat").setStrict(Utils.versionNewer(17))).get(); - - public static final Class ENTITY_GUARDIAN_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntityGuardian")).get(); - - public static final Class ENTITY_HORSE_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal.horse") - .withClassName("EntityHorse")).get(); - - public static final Class ENTITY_HOGLIN_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster.hoglin") - .withClassName("EntityHoglin").setStrict(Utils.versionNewer(16))).get(); - - public static final Class ENTITY_HUSK_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntityZombieHusk") - .setStrict(Utils.versionNewer(11))).get(); - - public static final Class ENTITY_ILLUSIONER_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntityIllagerIllusioner") - .setStrict(Utils.versionNewer(12))).get(); - - public static final Class ENTITY_IRON_GOLEM_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal") - .withClassName("EntityIronGolem")).get(); - - public static final Class ENTITY_LLAMA_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal.horse") - .withClassName("EntityLlama").setStrict(Utils.versionNewer(11))).get(); - - public static final Class ENTITY_MAGMA_CUBE_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntityMagmaCube")).get(); - - public static final Class ENTITY_MUSHROOM_COW_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal") - .withClassName("EntityMushroomCow")).get(); - - public static final Class ENTITY_MULE_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal.horse") - .withClassName("EntityHorseMule") - .setStrict(Utils.versionNewer(11))).get(); - - public static final Class ENTITY_OCELOT_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal") - .withClassName("EntityOcelot")).get(); - - public static final Class ENTITY_PANDA_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal") - .withClassName("EntityPanda").setStrict(Utils.versionNewer(14))).get(); - - public static final Class ENTITY_PARROT_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal") - .withClassName("EntityParrot").setStrict(Utils.versionNewer(12))).get(); - - public static final Class ENTITY_PHANTOM_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntityPhantom").setStrict(Utils.versionNewer(13))).get(); - - public static final Class ENTITY_PIG_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal") - .withClassName("EntityPig")).get(); - - public static final Class ENTITY_PIGLIN_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster.piglin") - .withClassName("EntityPiglin").setStrict(Utils.versionNewer(16))).get(); - - public static final Class ENTITY_PIGLIN_BRUTE_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster.piglin") - .withClassName("EntityPiglinBrute").setStrict(Utils.versionNewer(16))).get(); - - public static final Class ENTITY_PILLAGER_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntityPillager").setStrict(Utils.versionNewer(14))).get(); - - public static final Class ENTITY_PLAYER_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.SERVER_LEVEL) - .withClassName("EntityPlayer")).get(); - - public static final Class ENTITY_POLAR_BEAR_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal") - .withClassName("EntityPolarBear").setStrict(Utils.versionNewer(10))).get(); - - public static final Class ENTITY_PUFFERFISH_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal") - .withClassName("EntityPufferFish").setStrict(Utils.versionNewer(13))).get(); - - public static final Class ENTITY_RABBIT_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal") - .withClassName("EntityRabbit")).get(); - - public static final Class ENTITY_RAVAGER_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntityRavager").setStrict(Utils.versionNewer(14))).get(); - - public static final Class ENTITY_SALMON_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal") - .withClassName("EntitySalmon").setStrict(Utils.versionNewer(13))).get(); - - public static final Class ENTITY_SHEEP_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal") - .withClassName("EntitySheep")).get(); - - public static final Class ENTITY_SHULKER_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntityShulker").setStrict(Utils.versionNewer(9))).get(); - - public static final Class ENTITY_SILVERFISH_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntitySilverfish")).get(); - - public static final Class ENTITY_SKELETON_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntitySkeleton")).get(); - - public static final Class ENTITY_SKELETON_HORSE_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal.horse") - .withClassName("EntityHorseSkeleton") - .setStrict(Utils.versionNewer(11))).get(); - - public static final Class ENTITY_SLIME_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntitySlime")).get(); - - public static final Class ENTITY_SNOWMAN_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal") - .withClassName("EntitySnowman")).get(); - - - public static final Class ENTITY_SPIDER_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntitySpider")).get(); - - public static final Class ENTITY_SQUID_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal") - .withClassName("EntitySquid")).get(); - - public static final Class ENTITY_STRAY_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntitySkeletonStray") - .setStrict(Utils.versionNewer(11))).get(); - - public static final Class ENTITY_STRIDER_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntityStrider") - .setStrict(Utils.versionNewer(16))).get(); - - public static final Class ENTITY_TADPOLE_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal.frog") - .withClassName("Tadpole") - .setStrict(Utils.versionNewer(19))).get(); - - public static final Class ENTITY_TRADER_LLAMA_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal.horse") - .withClassName("EntityLlamaTrader") - .setStrict(Utils.versionNewer(14))).get(); - - public static final Class ENTITY_TROPICAL_FISH_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal") - .withClassName("EntityTropicalFish").setStrict(Utils.versionNewer(13))).get(); - - public static final Class ENTITY_TURTLE = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal") - .withClassName("EntityTurtle").setStrict(Utils.versionNewer(13))).get(); - - public static final Class ENTITY_VEX_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntityVex") - .setStrict(Utils.versionNewer(11))).get(); - - public static final Class ENTITY_VILLAGER_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("npc") - .withClassName("EntityVillager")).get(); - - public static final Class ENTITY_VINDICATOR_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntityVindicator").setStrict(Utils.versionNewer(11))).get(); - - public static final Class ENTITY_WANDERING_TRADER_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("npc") - .withClassName("EntityVillagerTrader") - .setStrict(Utils.versionNewer(14))).get(); - - public static final Class ENTITY_WARDEN = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster.warden") - .withClassName("EntityWarden") - .withClassName("Warden") - .setStrict(Utils.versionNewer(19))).get(); - - public static final Class ENTITY_WITCH_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntityWitch")).get(); - - public static final Class ENTITY_WITHER_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("boss.wither") - .withClassName("EntityWither")).get(); - - public static final Class ENTITY_WITHER_SKELETON_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntitySkeletonWither") - .setStrict(Utils.versionNewer(11))).get(); - - public static final Class ENTITY_WOLF_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal") - .withClassName("EntityWolf")).get(); - - public static final Class ENTITY_ZOGLIN_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntityZoglin").setStrict(Utils.versionNewer(16))).get(); - - public static final Class ENTITY_ZOMBIE_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntityZombie")).get(); - - public static final Class ENTITY_ZOMBIE_HORSE_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("animal.horse") - .withClassName("EntityHorseZombie") - .setStrict(Utils.versionNewer(11))).get(); - - public static final Class ENTITY_ZOMBIE_VILLAGER_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntityZombieVillager") - .setStrict(Utils.versionNewer(11))).get(); - - public static final Class ENTITY_ZOMBIFIED_PIGLIN_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withSubClass("monster") - .withClassName("EntityPigZombie")).get(); - - public static final Class ENTITY_TYPES_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withClassName("EntityTypes")).get(); - public static final Class ENTITY_HUMAN_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) .withSubClass("player") .withClassName("EntityHuman")).get(); - public static final Class ENUM_CHAT_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.MINECRAFT) - .withClassName("EnumChatFormat")).get(); - - public static final Class I_CHAT_BASE_COMPONENT = new ClassReflection(new ReflectionBuilder(ReflectionPackage.CHAT) - .withClassName("IChatBaseComponent")).get(); - - public static final Class DATA_WATCHER_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.SYNCHER) - .withClassName("DataWatcher") - .setStrict(Utils.versionNewer(9))).get(); - - public static final Class DATA_WATCHER_OBJECT = new ClassReflection(new ReflectionBuilder(ReflectionPackage.SYNCHER) - .withClassName("DataWatcherObject") - .setStrict(Utils.versionNewer(9))).get(); - - public static final Class DATA_WATCHER_REGISTRY = new ClassReflection(new ReflectionBuilder(ReflectionPackage.SYNCHER) - .withClassName("DataWatcherRegistry") - .setStrict(Utils.versionNewer(9))).get(); - - public static final Class DATA_WATCHER_SERIALIZER = new ClassReflection(new ReflectionBuilder(ReflectionPackage.SYNCHER) - .withClassName("DataWatcherSerializer") - .setStrict(Utils.versionNewer(9))).get(); - - public static final Class WORLD_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.WORLD_LEVEL) - .withClassName("World")).get(); - - public static final Class WORLD_SERVER_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.SERVER_LEVEL) - .withClassName("WorldServer")).get(); - - public static final Class MINECRAFT_SERVER_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.SERVER) - .withClassName("MinecraftServer")).get(); - - public static final Class PLAYER_INTERACT_MANAGER_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.SERVER_LEVEL) - .withClassName("PlayerInteractManager")).get(); - - public static final Class PLAYER_CONNECTION_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.SERVER_NETWORK) - .withClassName("PlayerConnection")).get(); - - public static final Class PACKET_PLAY_OUT_PLAYER_INFO_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName("PacketPlayOutPlayerInfo") - .withClassName("ClientboundPlayerInfoUpdatePacket")).get(); - - public static final Class PACKET_PLAY_OUT_SCOREBOARD_TEAM_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName("PacketPlayOutScoreboardTeam")).get(); - - public static final Class SCOREBOARD_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.WORLD_SCORES) - .withClassName("Scoreboard")).get(); - - public static final Class SCOREBOARD_TEAM_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.WORLD_SCORES) - .withClassName("ScoreboardTeam")).get(); - - public static final Class ENUM_TAG_VISIBILITY = new ClassReflection(new ReflectionBuilder(ReflectionPackage.WORLD_SCORES) - .withClassName("ScoreboardTeamBase$EnumNameTagVisibility")).get(); - - public static final Class CRAFT_CHAT_MESSAGE_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.BUKKIT) - .withClassName("util.CraftChatMessage")).get(); - - public static final Class PROFILE_PUBLIC_KEY_CLASS = new ClassReflection(new ReflectionBuilder(ReflectionPackage.WORLD_ENTITY_PLAYER) - .withClassName("ProfilePublicKey") - .setStrict(Utils.versionNewer(19))).get(); - - public static final ReflectionLazyLoader> SCOREBOARD_TEAM_CONSTRUCTOR = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName(SCOREBOARD_TEAM_CLASS) - .withParameterTypes(SCOREBOARD_CLASS, String.class)); - - public static final ReflectionLazyLoader> PLAYER_CONSTRUCTOR_OLD = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName(ENTITY_PLAYER_CLASS) - .withParameterTypes(MINECRAFT_SERVER_CLASS, WORLD_SERVER_CLASS, GameProfile.class, PLAYER_INTERACT_MANAGER_CLASS)); - - public static final ReflectionLazyLoader> PLAYER_CONSTRUCTOR_NEW = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName(ENTITY_PLAYER_CLASS) - .withParameterTypes(MINECRAFT_SERVER_CLASS, WORLD_SERVER_CLASS, GameProfile.class)); - - public static final ReflectionLazyLoader> PLAYER_CONSTRUCTOR_NEW_1 = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName(ENTITY_PLAYER_CLASS) - .withParameterTypes(MINECRAFT_SERVER_CLASS, WORLD_SERVER_CLASS, GameProfile.class, PROFILE_PUBLIC_KEY_CLASS) - .setStrict(false)); - - public static final ReflectionLazyLoader> PLAYER_CONSTRUCTOR_NEW_2 = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName(ENTITY_PLAYER_CLASS) - .withParameterTypes(MINECRAFT_SERVER_CLASS, WORLD_SERVER_CLASS, GameProfile.class)); - - public static final ReflectionLazyLoader> PACKET_PLAY_OUT_PLAYER_INFO_CONSTRUCTOR = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName(PACKET_PLAY_OUT_PLAYER_INFO_CLASS) - .withParameterTypes(ENUM_PLAYER_INFO_CLASS, (Utils.BUKKIT_VERSION > 16) ? Collection.class : Iterable.class).withParameterTypes(ENUM_PLAYER_INFO_CLASS, ENTITY_PLAYER_CLASS)); - - public static final ReflectionLazyLoader> PACKET_PLAY_OUT_ENTITY_LOOK_CONSTRUCTOR = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName("PacketPlayOutEntity$PacketPlayOutEntityLook") - .withParameterTypes(int.class, byte.class, byte.class, boolean.class)); - - public static final ReflectionLazyLoader> PACKET_PLAY_OUT_ENTITY_HEAD_ROTATION_CONSTRUCTOR = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName("PacketPlayOutEntityHeadRotation") - .withParameterTypes(ENTITY_CLASS, byte.class)); - - public static final ReflectionLazyLoader> PACKET_PLAY_OUT_ENTITY_TELEPORT_CONSTRUCTOR = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName("PacketPlayOutEntityTeleport") - .withParameterTypes(ENTITY_CLASS)); - - public static final ReflectionLazyLoader> PACKET_PLAY_OUT_ENTITY_META_DATA_CONSTRUCTOR = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName("PacketPlayOutEntityMetadata") - .withParameterTypes(int.class, DATA_WATCHER_CLASS, boolean.class) - .setStrict(false)); - - public static final ReflectionLazyLoader> PACKET_PLAY_OUT_ENTITY_META_DATA_CONSTRUCTOR_V1 = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName("PacketPlayOutEntityMetadata") - .withParameterTypes(int.class, List.class)); - - public static final ReflectionLazyLoader> PACKET_PLAY_OUT_SPAWN_ENTITY_CONSTRUCTOR = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName("PacketPlayOutSpawnEntity") - .withClassName("PacketPlayOutSpawnEntityLiving") - .withParameterTypes(ENTITY_LIVING).withParameterTypes(ENTITY_CLASS)); - - public static final ReflectionLazyLoader> PLAYER_INTERACT_MANAGER_OLD_CONSTRUCTOR = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName("PlayerInteractManager") - .withParameterTypes(WORLD_CLASS)); - - public static final ReflectionLazyLoader> PLAYER_INTERACT_MANAGER_NEW_CONSTRUCTOR = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName("PlayerInteractManager") - .withParameterTypes(WORLD_SERVER_CLASS)); - - public static final ReflectionLazyLoader> PACKET_PLAY_OUT_SCOREBOARD_TEAM_CONSTRUCTOR_OLD = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName(PACKET_PLAY_OUT_SCOREBOARD_TEAM_CLASS)); - - public static final ReflectionLazyLoader> I_CHAT_BASE_COMPONENT_A_CONSTRUCTOR = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.CHAT) - .withClassName("ChatComponentText") - .withParameterTypes(String.class)); - - public static final ReflectionLazyLoader> ENTITY_CONSTRUCTOR = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName(ENTITY_ARMOR_STAND_CLASS) - .withParameterTypes(WORLD_CLASS, double.class, double.class, double.class)); - - public static final ReflectionLazyLoader> DATA_WATCHER_OBJECT_CONSTRUCTOR = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName(DATA_WATCHER_OBJECT) - .withParameterTypes(int.class, DATA_WATCHER_SERIALIZER)); - public static final ReflectionLazyLoader GET_PROFILE_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) .withClassName(ENTITY_HUMAN_CLASS) .withExpectResult(GameProfile.class)); - public static final ReflectionLazyLoader GET_ENTITY_ID = new MethodReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName(ENTITY_CLASS) - .withMethodName("getId") - .withMethodName("ae") - .withMethodName("ah") - .withMethodName("af") - .withExpectResult(int.class)); - public static final ReflectionLazyLoader GET_HANDLE_PLAYER_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.BUKKIT) .withClassName("entity.CraftPlayer").withClassName("entity.CraftHumanEntity") .withMethodName("getHandle")); - public static final ReflectionLazyLoader GET_HANDLE_WORLD_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.BUKKIT) - .withClassName("CraftWorld") - .withMethodName("getHandle")); - - public static final ReflectionLazyLoader GET_SERVER_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.BUKKIT) - .withClassName("CraftServer") - .withMethodName("getServer")); - - public static final ReflectionLazyLoader SEND_PACKET_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName(PLAYER_CONNECTION_CLASS) - .withMethodName("sendPacket").withMethodName("a") - .withParameterTypes(PACKET_CLASS)); - - public static final ReflectionLazyLoader SET_CUSTOM_NAME_OLD_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName(ENTITY_CLASS) - .withMethodName("setCustomName") - .withParameterTypes(String.class)); - - public static final ReflectionLazyLoader SET_CUSTOM_NAME_NEW_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName(ENTITY_CLASS) - .withMethodName("setCustomName") - .withMethodName("a") - .withMethodName("b") - .withParameterTypes(I_CHAT_BASE_COMPONENT).withExpectResult(void.class)); - - public static final ReflectionLazyLoader SET_CUSTOM_NAME_VISIBLE_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName(ENTITY_CLASS) - .withMethodName("setCustomNameVisible") - .withMethodName("n") - .withParameterTypes(boolean.class)); - - public static final ReflectionLazyLoader SET_INVISIBLE_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName(ENTITY_ARMOR_STAND_CLASS) - .withMethodName("setInvisible").withMethodName("j") - .withParameterTypes(boolean.class)); - - public static final ReflectionLazyLoader SET_LOCATION_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName(ENTITY_CLASS) - .withMethodName("setPositionRotation") - .withMethodName("a") - .withParameterTypes(double.class, double.class, double.class, float.class, float.class)); - - public static final ReflectionLazyLoader SET_DATA_WATCHER_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName(DATA_WATCHER_CLASS) - .withMethodName("set").withMethodName("b") - .withParameterTypes(DATA_WATCHER_OBJECT, Object.class)); - - public static final ReflectionLazyLoader WATCH_DATA_WATCHER_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName(DATA_WATCHER_CLASS) - .withMethodName("watch") - .withParameterTypes(int.class, Object.class)); - - public static final ReflectionLazyLoader GET_DATA_WATCHER_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName(ENTITY_CLASS) - .withMethodName("getDataWatcher") - .withMethodName("ai") - .withMethodName("al") - .withMethodName("aj") - .withExpectResult(DATA_WATCHER_CLASS)); - - public static final ReflectionLazyLoader GET_BUKKIT_ENTITY_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName(ENTITY_CLASS) - .withMethodName("getBukkitEntity")); - - public static final ReflectionLazyLoader GET_ENUM_CHAT_ID_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName(ENUM_CHAT_CLASS) - .withMethodName("b")); - - public static final ReflectionLazyLoader ENUM_CHAT_TO_STRING_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName(ENUM_CHAT_CLASS) - .withExpectResult(String.class) - .withMethodName("toString")); - - public static final ReflectionLazyLoader ENTITY_TYPES_A_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) - .withClassName(ENTITY_TYPES_CLASS) - .withMethodName("a") - .withParameterTypes(String.class)); - - public static final ReflectionLazyLoader PACKET_PLAY_OUT_SCOREBOARD_TEAM_CREATE_V1 = new MethodReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName(PACKET_PLAY_OUT_SCOREBOARD_TEAM_CLASS) - .withMethodName("a") - .withParameterTypes(SCOREBOARD_TEAM_CLASS)); - - public static final ReflectionLazyLoader PACKET_PLAY_OUT_SCOREBOARD_TEAM_CREATE = new MethodReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName(PACKET_PLAY_OUT_SCOREBOARD_TEAM_CLASS) - .withMethodName("a") - .withParameterTypes(SCOREBOARD_TEAM_CLASS, boolean.class)); - - public static final ReflectionLazyLoader SCOREBOARD_PLAYER_LIST = new MethodReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName(SCOREBOARD_TEAM_CLASS) - .withMethodName("getPlayerNameSet").withMethodName("g")); - - public static final ReflectionLazyLoader ENUM_CHAT_FORMAT_FIND = new MethodReflection(new ReflectionBuilder(ReflectionPackage.MINECRAFT) - .withClassName(ENUM_CHAT_CLASS) - .withParameterTypes(String.class).withExpectResult(ENUM_CHAT_CLASS)); - - public static final ReflectionLazyLoader CRAFT_CHAT_MESSAGE_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.BUKKIT) - .withClassName(CRAFT_CHAT_MESSAGE_CLASS) - .withMethodName("fromStringOrNull") - .withParameterTypes(String.class)); - - public static final ReflectionLazyLoader GET_UNIQUE_ID_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.MINECRAFT) - .withClassName(ENTITY_CLASS) - .withExpectResult(UUID.class)); - - public static final ReflectionLazyLoader GET_DATAWATCHER_B_LIST = new MethodReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withMethodName("c") - .withClassName(DATA_WATCHER_CLASS)); - - public static final ReflectionLazyLoader PLAYER_CONNECTION_FIELD = new FieldReflection(new ReflectionBuilder(ReflectionPackage.SERVER_LEVEL) - .withClassName(ENTITY_PLAYER_CLASS) - .withFieldName((Utils.BUKKIT_VERSION > 16) ? "b" : "playerConnection")); - - public static final ReflectionLazyLoader ADD_PLAYER_FIELD = new FieldReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName("PacketPlayOutPlayerInfo$EnumPlayerInfoAction") - .withClassName("ClientboundPlayerInfoUpdatePacket$a") - .withFieldName((Utils.BUKKIT_VERSION > 16) ? "a" : "ADD_PLAYER")).staticValueLoader(); - - public static final ReflectionLazyLoader UPDATE_LISTED_FIELD = new FieldReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName("ClientboundPlayerInfoUpdatePacket$a") - .withFieldName("d")).staticValueLoader(); - - public static final ReflectionLazyLoader DATA_WATCHER_REGISTER_FIELD = new FieldReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName(DATA_WATCHER_REGISTRY) - .withFieldName("a")).staticValueLoader(); - - public static final ReflectionLazyLoader ENUM_TAG_VISIBILITY_NEVER_FIELD = new FieldReflection(new ReflectionBuilder(ReflectionPackage.PACKET) - .withClassName(ENUM_TAG_VISIBILITY) - .withFieldName("b")).staticValueLoader(); - - public static final ReflectionLazyLoader COMMAND_MAP_FIELD = new FieldReflection(new ReflectionBuilder(ReflectionPackage.BUKKIT) - .withClassName("CraftServer") - .withFieldName("commandMap")).valueLoader(Bukkit.getServer(), CommandMap.class); - public static final FieldReflection.ValueModifier ENTITY_ID_MODIFIER = new FieldReflection(new ReflectionBuilder(ReflectionPackage.ENTITY) .withClassName(ENTITY_CLASS) .withFieldName("entityCount") diff --git a/src/main/java/io/github/znetworkw/znpcservers/reflection/types/ConstructorReflection.java b/src/main/java/io/github/znetworkw/znpcservers/reflection/types/ConstructorReflection.java deleted file mode 100644 index 87871b0..0000000 --- a/src/main/java/io/github/znetworkw/znpcservers/reflection/types/ConstructorReflection.java +++ /dev/null @@ -1,44 +0,0 @@ -package io.github.znetworkw.znpcservers.reflection.types; - -import com.google.common.collect.ImmutableList; -import io.github.znetworkw.znpcservers.reflection.ReflectionBuilder; -import io.github.znetworkw.znpcservers.reflection.ReflectionLazyLoader; - -import java.lang.reflect.Constructor; -import java.util.Arrays; -import java.util.function.Consumer; - -public class ConstructorReflection extends ReflectionLazyLoader> { - private final ImmutableList[]> parameterTypes; - - public ConstructorReflection(ReflectionBuilder reflectionBuilder) { - super(reflectionBuilder); - this.parameterTypes = reflectionBuilder.getParameterTypes(); - } - - protected Constructor load() throws NoSuchMethodException { - for (Class clazz : this.reflectionClasses) { - Constructor constructor = load(clazz); - if (constructor != null) return constructor; - } - return null; - } - - private Constructor load(Class clazz) { - if (parameterTypes != null && parameterTypes.size() > 0) for (Class[] possibleConstructor : parameterTypes) try { - Constructor constructor = clazz.getDeclaredConstructor(possibleConstructor); - constructor.setAccessible(true); - return constructor; - } catch (NoSuchMethodException ignored) {} - else try { - return clazz.getDeclaredConstructor(); - } catch (NoSuchMethodException ignored) {} - return null; - } - - @Override - protected void printDebugInfo(Consumer logger) { - logger.accept("Possible Parameter Type Combinations:"); - for (Class[] possible : parameterTypes) logger.accept(Arrays.toString(possible)); - } -} \ No newline at end of file diff --git a/src/main/java/io/github/znetworkw/znpcservers/reflection/types/EnumReflection.java b/src/main/java/io/github/znetworkw/znpcservers/reflection/types/EnumReflection.java deleted file mode 100644 index 43737ec..0000000 --- a/src/main/java/io/github/znetworkw/znpcservers/reflection/types/EnumReflection.java +++ /dev/null @@ -1,18 +0,0 @@ -package io.github.znetworkw.znpcservers.reflection.types; - -import io.github.znetworkw.znpcservers.reflection.EnumPropertyCache; -import io.github.znetworkw.znpcservers.reflection.ReflectionBuilder; -import io.github.znetworkw.znpcservers.reflection.ReflectionLazyLoader; - -public class EnumReflection extends ReflectionLazyLoader[]> { - public EnumReflection(ReflectionBuilder reflectionBuilder) { - super(reflectionBuilder); - } - - protected Enum[] load() { - if (reflectionClasses.size() == 0) return null; - Enum[] enums = (Enum[]) this.reflectionClasses.get(0).getEnumConstants(); - for (Enum enumConstant : enums) EnumPropertyCache.register(enumConstant.name(), enumConstant, this.reflectionClasses.get(0)); - return enums; - } -} \ No newline at end of file diff --git a/src/main/java/io/github/znetworkw/znpcservers/reflection/types/FieldReflection.java b/src/main/java/io/github/znetworkw/znpcservers/reflection/types/FieldReflection.java index b222326..029e5b5 100644 --- a/src/main/java/io/github/znetworkw/znpcservers/reflection/types/FieldReflection.java +++ b/src/main/java/io/github/znetworkw/znpcservers/reflection/types/FieldReflection.java @@ -17,7 +17,7 @@ public class FieldReflection extends ReflectionLazyLoader { this.expectType = reflectionBuilder.getExpectType(); } - protected Field load() throws NoSuchFieldException { + protected Field load() { if (fieldName != null && fieldName.length() > 0) for (Class clazz : this.reflectionClasses) { Field field = loadByName(clazz); if (field != null) return field; diff --git a/src/main/java/io/github/znetworkw/znpcservers/utility/Utils.java b/src/main/java/io/github/znetworkw/znpcservers/utility/Utils.java index c33f47b..cc0fa04 100644 --- a/src/main/java/io/github/znetworkw/znpcservers/utility/Utils.java +++ b/src/main/java/io/github/znetworkw/znpcservers/utility/Utils.java @@ -1,19 +1,10 @@ package io.github.znetworkw.znpcservers.utility; -import io.github.znetworkw.znpcservers.configuration.ConfigurationConstants; -import io.github.znetworkw.znpcservers.reflection.Reflections; -import io.github.znetworkw.znpcservers.user.ZUser; -import me.clip.placeholderapi.PlaceholderAPI; import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import java.lang.reflect.Field; -import java.util.concurrent.ThreadLocalRandom; public final class Utils { public static final int BUKKIT_VERSION; - public static boolean PLACEHOLDER_SUPPORT = Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI"); static { int version = 0; @@ -39,46 +30,4 @@ public final class Utils { public static String toColor(String string) { return ChatColor.translateAlternateColorCodes('&', string); } - - public static String getWithPlaceholders(String string, Player player) { - return PlaceholderAPI.setPlaceholders(player, string).replace(ConfigurationConstants.SPACE_SYMBOL, " "); - } - - public static String randomString(int length) { - StringBuilder stringBuilder = new StringBuilder(); - for (int index = 0; index < length; index++) - stringBuilder.append(ThreadLocalRandom.current().nextInt(0, 9)); - return stringBuilder.toString(); - } - - public static void sendTitle(Player player, String title, String subTitle) { - player.sendTitle(toColor(title), toColor(subTitle), 20, 60, 20); - } - - public static void setValue(Object fieldInstance, String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException { - Field f = fieldInstance.getClass().getDeclaredField(fieldName); - f.setAccessible(true); - f.set(fieldInstance, value); - } - - public static void setValue(Object fieldInstance, Object value, Class expectedType) throws NoSuchFieldException, IllegalAccessException { - for (Field field : fieldInstance.getClass().getDeclaredFields()) { - if (field.getType() == expectedType) - setValue(fieldInstance, field.getName(), value); - } - } - - public static Object getValue(Object instance, String fieldName) throws NoSuchFieldException, IllegalAccessException { - Field f = instance.getClass().getDeclaredField(fieldName); - f.setAccessible(true); - return f.get(instance); - } - - public static void sendPackets(ZUser user, Object... packets) { - try { - for (Object packet : packets) if (packet != null) Reflections.SEND_PACKET_METHOD.get().invoke(user.getPlayerConnection(), packet); - } catch (IllegalAccessException | java.lang.reflect.InvocationTargetException e) { - e.printStackTrace(); - } - } } diff --git a/src/main/java/lol/pyr/znpcsplus/ZNPCsPlus.java b/src/main/java/lol/pyr/znpcsplus/ZNPCsPlus.java index ec0c7ea..2b30206 100644 --- a/src/main/java/lol/pyr/znpcsplus/ZNPCsPlus.java +++ b/src/main/java/lol/pyr/znpcsplus/ZNPCsPlus.java @@ -6,16 +6,15 @@ import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder; -import io.github.znetworkw.znpcservers.configuration.Configuration; import io.github.znetworkw.znpcservers.configuration.ConfigurationConstants; import io.github.znetworkw.znpcservers.listeners.InventoryListener; import io.github.znetworkw.znpcservers.utility.BungeeUtils; import io.github.znetworkw.znpcservers.utility.SchedulerUtils; import io.github.znetworkw.znpcservers.utility.itemstack.ItemStackSerializer; +import lol.pyr.znpcsplus.entity.EntityProperty; import lol.pyr.znpcsplus.entity.PacketLocation; import lol.pyr.znpcsplus.interaction.InteractionPacketListener; import lol.pyr.znpcsplus.npc.NPC; -import lol.pyr.znpcsplus.npc.NPCProperty; import lol.pyr.znpcsplus.npc.NPCRegistry; import lol.pyr.znpcsplus.npc.NPCType; import lol.pyr.znpcsplus.skin.cache.SkinCache; @@ -138,11 +137,11 @@ public class ZNPCsPlus extends JavaPlugin { for (NPCType type : NPCType.values()) { NPC npc = new NPC(world, type, new PacketLocation(x * 3, 200, z * 3, 0, 0)); if (type.getType() == EntityTypes.PLAYER) { - SkinCache.fetchByName("Notch").thenAccept(skin -> npc.setProperty(NPCProperty.SKIN, new PrefetchedDescriptor(skin))); - npc.setProperty(NPCProperty.INVISIBLE, true); + SkinCache.fetchByName("Notch").thenAccept(skin -> npc.setProperty(EntityProperty.SKIN, new PrefetchedDescriptor(skin))); + npc.setProperty(EntityProperty.INVISIBLE, true); } - npc.setProperty(NPCProperty.GLOW, NamedTextColor.RED); - npc.setProperty(NPCProperty.FIRE, true); + npc.setProperty(EntityProperty.GLOW, NamedTextColor.RED); + npc.setProperty(EntityProperty.FIRE, true); NPCRegistry.register("debug_npc" + (z * wrap + x), npc); if (x++ > wrap) { x = 0; @@ -150,11 +149,11 @@ public class ZNPCsPlus extends JavaPlugin { } } NPC npc = new NPC(world, NPCType.byName("player"), new PacketLocation(x * 3, 200, z * 3, 0, 0)); - npc.setProperty(NPCProperty.SKIN, new FetchingDescriptor("jeb_")); + npc.setProperty(EntityProperty.SKIN, new FetchingDescriptor("jeb_")); NPCRegistry.register("debug_npc" + (z * wrap + x), npc); x++; npc = new NPC(world, NPCType.byName("player"), new PacketLocation(x * 3, 200, z * 3, 0, 0)); - npc.setProperty(NPCProperty.SKIN, new MirrorDescriptor()); + npc.setProperty(EntityProperty.SKIN, new MirrorDescriptor()); NPCRegistry.register("debug_npc" + (z * wrap + x), npc); } } @@ -162,10 +161,8 @@ public class ZNPCsPlus extends JavaPlugin { @Override public void onDisable() { if (!enabled) return; - Configuration.SAVE_CONFIGURATIONS.forEach(Configuration::save); Bukkit.getOnlinePlayers().forEach(User::remove); ADVENTURE.close(); ADVENTURE = null; } - } diff --git a/src/main/java/lol/pyr/znpcsplus/entity/EntityProperty.java b/src/main/java/lol/pyr/znpcsplus/entity/EntityProperty.java new file mode 100644 index 0000000..31f2776 --- /dev/null +++ b/src/main/java/lol/pyr/znpcsplus/entity/EntityProperty.java @@ -0,0 +1,45 @@ +package lol.pyr.znpcsplus.entity; + +import lol.pyr.znpcsplus.skin.SkinDescriptor; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; + +import java.util.HashMap; +import java.util.Map; + +public class EntityProperty { + private final String name; + private final T defaultValue; + + public EntityProperty(String name) { + this(name, null); + } + + public EntityProperty(String name, T defaultValue) { + this.name = name.toUpperCase(); + this.defaultValue = defaultValue; + BY_NAME.put(this.name, this); + } + + public String name() { + return name; + } + + public T getDefaultValue() { + return defaultValue; + } + + private final static Map> BY_NAME = new HashMap<>(); + + public static EntityProperty getByName(String name) { + return BY_NAME.get(name.toUpperCase()); + } + + public static EntityProperty SKIN_LAYERS = new EntityProperty<>("skin_layers", true); + public static EntityProperty SKIN = new EntityProperty<>("skin"); + public static EntityProperty GLOW = new EntityProperty<>("glow"); + public static EntityProperty FIRE = new EntityProperty<>("fire", false); + public static EntityProperty INVISIBLE = new EntityProperty<>("invisible", false); + public static EntityProperty SILENT = new EntityProperty<>("silent", false); + public static EntityProperty NAME = new EntityProperty<>("name"); +} \ No newline at end of file diff --git a/src/main/java/lol/pyr/znpcsplus/entity/PacketEntity.java b/src/main/java/lol/pyr/znpcsplus/entity/PacketEntity.java index bfe8075..e98ed6b 100644 --- a/src/main/java/lol/pyr/znpcsplus/entity/PacketEntity.java +++ b/src/main/java/lol/pyr/znpcsplus/entity/PacketEntity.java @@ -4,23 +4,22 @@ import com.github.retrooper.packetevents.protocol.entity.type.EntityType; import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes; import io.github.znetworkw.znpcservers.reflection.Reflections; import io.github.znetworkw.znpcservers.utility.Utils; -import lol.pyr.znpcsplus.npc.NPC; import lol.pyr.znpcsplus.packets.PacketFactory; import org.bukkit.entity.Player; -import java.util.Set; +import java.util.Collection; import java.util.UUID; public class PacketEntity { - private final NPC owner; + private final PropertyHolder properties; private final int entityId; private final UUID uuid; private final EntityType type; private PacketLocation location; - public PacketEntity(NPC owner, EntityType type, PacketLocation location) { - this.owner = owner; + public PacketEntity(PropertyHolder properties, EntityType type, PacketLocation location) { + this.properties = properties; this.entityId = reserveEntityID(); this.uuid = UUID.randomUUID(); this.type = type; @@ -43,22 +42,22 @@ public class PacketEntity { return type; } - public NPC getOwner() { - return owner; - } - - public void setLocation(PacketLocation location, Set viewers) { + public void setLocation(PacketLocation location, Collection viewers) { this.location = location; for (Player viewer : viewers) PacketFactory.get().teleportEntity(viewer, this); } public void spawn(Player player) { - if (type == EntityTypes.PLAYER) PacketFactory.get().spawnPlayer(player, this); - else PacketFactory.get().spawnEntity(player, this); + if (type == EntityTypes.PLAYER) PacketFactory.get().spawnPlayer(player, this, properties); + else PacketFactory.get().spawnEntity(player, this, properties); } public void despawn(Player player) { - PacketFactory.get().destroyEntity(player, this); + PacketFactory.get().destroyEntity(player, this, properties); + } + + public void refreshMeta(Player player) { + PacketFactory.get().sendAllMetadata(player, this, properties); } private static int reserveEntityID() { diff --git a/src/main/java/lol/pyr/znpcsplus/entity/PropertyHolder.java b/src/main/java/lol/pyr/znpcsplus/entity/PropertyHolder.java new file mode 100644 index 0000000..a776fcb --- /dev/null +++ b/src/main/java/lol/pyr/znpcsplus/entity/PropertyHolder.java @@ -0,0 +1,18 @@ +package lol.pyr.znpcsplus.entity; + +public interface PropertyHolder { + T getProperty(EntityProperty key); + boolean hasProperty(EntityProperty key); + + PropertyHolder EMPTY = new PropertyHolder() { + @Override + public T getProperty(EntityProperty key) { + return null; + } + + @Override + public boolean hasProperty(EntityProperty key) { + return false; + } + }; +} diff --git a/src/main/java/lol/pyr/znpcsplus/hologram/Hologram.java b/src/main/java/lol/pyr/znpcsplus/hologram/Hologram.java new file mode 100644 index 0000000..79a6e51 --- /dev/null +++ b/src/main/java/lol/pyr/znpcsplus/hologram/Hologram.java @@ -0,0 +1,38 @@ +package lol.pyr.znpcsplus.hologram; + +import lol.pyr.znpcsplus.util.Viewable; +import net.kyori.adventure.text.Component; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +public class Hologram extends Viewable { + private final List lines = new ArrayList<>(); + + public Hologram() { + + } + + public void addLine(Component line) { + lines.add(new HologramLine(null, line)); // TODO: Location + } + + public HologramLine getLine(int index) { + return lines.get(index); + } + + public void insertLine(int index, Component line) { + lines.add(index, new HologramLine(null, line)); // TODO: Location + } + + @Override + protected void _show(Player player) { + for (HologramLine line : lines) line.show(player); + } + + @Override + protected void _hide(Player player) { + for (HologramLine line : lines) line.hide(player); + } +} diff --git a/src/main/java/lol/pyr/znpcsplus/hologram/HologramLine.java b/src/main/java/lol/pyr/znpcsplus/hologram/HologramLine.java new file mode 100644 index 0000000..eeb48e3 --- /dev/null +++ b/src/main/java/lol/pyr/znpcsplus/hologram/HologramLine.java @@ -0,0 +1,54 @@ +package lol.pyr.znpcsplus.hologram; + +import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes; +import lol.pyr.znpcsplus.entity.EntityProperty; +import lol.pyr.znpcsplus.entity.PacketEntity; +import lol.pyr.znpcsplus.entity.PacketLocation; +import lol.pyr.znpcsplus.entity.PropertyHolder; +import net.kyori.adventure.text.Component; +import org.bukkit.entity.Player; + +import java.util.Collection; + +public class HologramLine implements PropertyHolder { + private Component text; + private final PacketEntity armorStand; + + public HologramLine(PacketLocation location, Component text) { + this.text = text; + armorStand = new PacketEntity(this, EntityTypes.ARMOR_STAND, location); + } + + public Component getText() { + return text; + } + + public void setText(Component text) { + this.text = text; + } + + protected void show(Player player) { + armorStand.spawn(player); + } + + protected void hide(Player player) { + armorStand.despawn(player); + } + + public void setLocation(PacketLocation location, Collection viewers) { + armorStand.setLocation(location, viewers); + } + + @SuppressWarnings("unchecked") + @Override + public T getProperty(EntityProperty key) { + if (key == EntityProperty.INVISIBLE) return (T) Boolean.TRUE; + if (key == EntityProperty.NAME) return (T) text; + return null; + } + + @Override + public boolean hasProperty(EntityProperty key) { + return key == EntityProperty.NAME || key == EntityProperty.INVISIBLE; + } +} diff --git a/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java b/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java index 22c674d..c49b978 100644 --- a/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java +++ b/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java @@ -4,7 +4,9 @@ import com.github.retrooper.packetevents.PacketEvents; import com.github.retrooper.packetevents.manager.server.ServerVersion; import com.github.retrooper.packetevents.protocol.entity.data.EntityData; import lol.pyr.znpcsplus.util.LazyLoader; +import net.kyori.adventure.text.Component; +import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -25,6 +27,8 @@ import java.util.Map; public interface MetadataFactory { EntityData skinLayers(); EntityData effects(boolean onFire, boolean glowing, boolean invisible); + Collection name(Component name); + EntityData silent(); MetadataFactory factory = get(); diff --git a/src/main/java/lol/pyr/znpcsplus/metadata/V1_13Factory.java b/src/main/java/lol/pyr/znpcsplus/metadata/V1_13Factory.java new file mode 100644 index 0000000..3e45cf5 --- /dev/null +++ b/src/main/java/lol/pyr/znpcsplus/metadata/V1_13Factory.java @@ -0,0 +1,19 @@ +package lol.pyr.znpcsplus.metadata; + +import com.github.retrooper.packetevents.protocol.entity.data.EntityData; +import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; +import com.github.retrooper.packetevents.util.adventure.AdventureSerializer; +import net.kyori.adventure.text.Component; + +import java.util.Collection; +import java.util.List; + +public class V1_13Factory extends V1_8Factory { + @Override + public Collection name(Component name) { + return List.of( + new EntityData(2, EntityDataTypes.OPTIONAL_COMPONENT, AdventureSerializer.getGsonSerializer().serialize(name)), + new EntityData(3, EntityDataTypes.BOOLEAN, true) + ); + } +} diff --git a/src/main/java/lol/pyr/znpcsplus/metadata/V1_14Factory.java b/src/main/java/lol/pyr/znpcsplus/metadata/V1_14Factory.java index af0efe8..e312af2 100644 --- a/src/main/java/lol/pyr/znpcsplus/metadata/V1_14Factory.java +++ b/src/main/java/lol/pyr/znpcsplus/metadata/V1_14Factory.java @@ -2,7 +2,7 @@ package lol.pyr.znpcsplus.metadata; import com.github.retrooper.packetevents.protocol.entity.data.EntityData; -public class V1_14Factory extends V1_9Factory { +public class V1_14Factory extends V1_13Factory { @Override public EntityData skinLayers() { return createSkinLayers(15); diff --git a/src/main/java/lol/pyr/znpcsplus/metadata/V1_8Factory.java b/src/main/java/lol/pyr/znpcsplus/metadata/V1_8Factory.java index 201aa2d..a669d85 100644 --- a/src/main/java/lol/pyr/znpcsplus/metadata/V1_8Factory.java +++ b/src/main/java/lol/pyr/znpcsplus/metadata/V1_8Factory.java @@ -2,6 +2,11 @@ package lol.pyr.znpcsplus.metadata; import com.github.retrooper.packetevents.protocol.entity.data.EntityData; import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; +import com.github.retrooper.packetevents.util.adventure.AdventureSerializer; +import net.kyori.adventure.text.Component; + +import java.util.Collection; +import java.util.List; public class V1_8Factory implements MetadataFactory { @Override @@ -14,6 +19,19 @@ public class V1_8Factory implements MetadataFactory { return new EntityData(0, EntityDataTypes.BYTE, (onFire ? 0x01 : 0) | (invisible ? 0x20 : 0)); } + @Override + public Collection name(Component name) { + return List.of( + new EntityData(2, EntityDataTypes.STRING, AdventureSerializer.getGsonSerializer().serialize(name)), + new EntityData(3, EntityDataTypes.BYTE, 1) + ); + } + + @Override + public EntityData silent() { + return new EntityData(4, EntityDataTypes.BYTE, 1); + } + protected EntityData createSkinLayers(int index) { return new EntityData(index, EntityDataTypes.BYTE, Byte.MAX_VALUE); } diff --git a/src/main/java/lol/pyr/znpcsplus/metadata/V1_9Factory.java b/src/main/java/lol/pyr/znpcsplus/metadata/V1_9Factory.java index 5e9ebc3..49fb334 100644 --- a/src/main/java/lol/pyr/znpcsplus/metadata/V1_9Factory.java +++ b/src/main/java/lol/pyr/znpcsplus/metadata/V1_9Factory.java @@ -2,6 +2,11 @@ package lol.pyr.znpcsplus.metadata; import com.github.retrooper.packetevents.protocol.entity.data.EntityData; import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; +import com.github.retrooper.packetevents.util.adventure.AdventureSerializer; +import net.kyori.adventure.text.Component; + +import java.util.Collection; +import java.util.List; public class V1_9Factory extends V1_8Factory { @Override @@ -13,4 +18,17 @@ public class V1_9Factory extends V1_8Factory { public EntityData effects(boolean onFire, boolean glowing, boolean invisible) { return new EntityData(0, EntityDataTypes.BYTE, (byte) ((onFire ? 0x01 : 0) | (invisible ? 0x20 : 0) | (glowing ? 0x40 : 0))); } + + @Override + public Collection name(Component name) { + return List.of( + new EntityData(2, EntityDataTypes.STRING, AdventureSerializer.getGsonSerializer().serialize(name)), + new EntityData(3, EntityDataTypes.BOOLEAN, true) + ); + } + + @Override + public EntityData silent() { + return new EntityData(4, EntityDataTypes.BOOLEAN, true); + } } diff --git a/src/main/java/lol/pyr/znpcsplus/npc/NPC.java b/src/main/java/lol/pyr/znpcsplus/npc/NPC.java index 0518fc3..befc4c9 100644 --- a/src/main/java/lol/pyr/znpcsplus/npc/NPC.java +++ b/src/main/java/lol/pyr/znpcsplus/npc/NPC.java @@ -1,15 +1,18 @@ package lol.pyr.znpcsplus.npc; +import lol.pyr.znpcsplus.entity.EntityProperty; import lol.pyr.znpcsplus.entity.PacketEntity; import lol.pyr.znpcsplus.entity.PacketLocation; +import lol.pyr.znpcsplus.entity.PropertyHolder; import lol.pyr.znpcsplus.interaction.NPCAction; +import lol.pyr.znpcsplus.util.Viewable; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.Player; import java.util.*; -public class NPC { +public class NPC extends Viewable implements PropertyHolder { protected static final Set _ALL_NPCS = new HashSet<>(); private final Set viewers = new HashSet<>(); @@ -18,7 +21,7 @@ public class NPC { private PacketLocation location; private NPCType type; - private final Map, Object> propertyMap = new HashMap<>(); + private final Map, Object> propertyMap = new HashMap<>(); private final Set actions = new HashSet<>(); public NPC(World world, NPCType type, PacketLocation location) { @@ -31,10 +34,10 @@ public class NPC { } public void setType(NPCType type) { - _hideAll(); + UNSAFE_hideAll(); this.type = type; entity = new PacketEntity(this, type.getType(), entity.getLocation()); - _showAll(); + UNSAFE_showAll(); } public NPCType getType() { @@ -58,74 +61,50 @@ public class NPC { return Bukkit.getWorld(worldName); } + @Override public void delete() { _ALL_NPCS.remove(this); - _hideAll(); - viewers.clear(); + super.delete(); } - public void respawn() { - _hideAll(); - _showAll(); + public void undelete() { + _ALL_NPCS.add(this); } - public void respawn(Player player) { - _hide(player); - _show(player); - } - - public void show(Player player) { - if (viewers.contains(player)) return; - _show(player); - viewers.add(player); - } - - public void hide(Player player) { - if (!viewers.contains(player)) return; - _hide(player); - viewers.remove(player); - } - - public boolean isShown(Player player) { - return viewers.contains(player); - } - - private void _show(Player player) { + @Override + protected void _show(Player player) { entity.spawn(player); } - private void _hide(Player player) { + @Override + protected void _hide(Player player) { entity.despawn(player); } - private void _hideAll() { - for (Player viewer : viewers) _hide(viewer); - } - - private void _showAll() { - for (Player viewer : viewers) _show(viewer); + private void _refreshMeta() { + for (Player viewer : viewers) entity.refreshMeta(viewer); } @SuppressWarnings("unchecked") - public T getProperty(NPCProperty key) { + public T getProperty(EntityProperty key) { return hasProperty(key) ? (T) propertyMap.get(key) : key.getDefaultValue(); } - public boolean hasProperty(NPCProperty key) { + public boolean hasProperty(EntityProperty key) { return propertyMap.containsKey(key); } - public void setProperty(NPCProperty key, T value) { + public void setProperty(EntityProperty key, T value) { if (value.equals(key.getDefaultValue())) removeProperty(key); else { propertyMap.put(key, value); - respawn(); + _refreshMeta(); } } - public void removeProperty(NPCProperty key) { + public void removeProperty(EntityProperty key) { propertyMap.remove(key); - respawn(); + _refreshMeta(); } public Collection getActions() { diff --git a/src/main/java/lol/pyr/znpcsplus/npc/NPCProperty.java b/src/main/java/lol/pyr/znpcsplus/npc/NPCProperty.java deleted file mode 100644 index 6236194..0000000 --- a/src/main/java/lol/pyr/znpcsplus/npc/NPCProperty.java +++ /dev/null @@ -1,42 +0,0 @@ -package lol.pyr.znpcsplus.npc; - -import lol.pyr.znpcsplus.skin.SkinDescriptor; -import net.kyori.adventure.text.format.NamedTextColor; - -import java.util.HashMap; -import java.util.Map; - -public class NPCProperty { - private final String name; - private final T defaultValue; - - public NPCProperty(String name) { - this(name, null); - } - - public NPCProperty(String name, T defaultValue) { - this.name = name.toUpperCase(); - this.defaultValue = defaultValue; - BY_NAME.put(this.name, this); - } - - public String name() { - return name; - } - - protected T getDefaultValue() { - return defaultValue; - } - - private final static Map> BY_NAME = new HashMap<>(); - - public static NPCProperty getByName(String name) { - return BY_NAME.get(name.toUpperCase()); - } - - public static NPCProperty SKIN_LAYERS = new NPCProperty<>("skin_layers", true); - public static NPCProperty SKIN = new NPCProperty<>("skin"); - public static NPCProperty GLOW = new NPCProperty<>("glow"); - public static NPCProperty FIRE = new NPCProperty<>("fire", false); - public static NPCProperty INVISIBLE = new NPCProperty<>("invisible", false); -} \ No newline at end of file diff --git a/src/main/java/lol/pyr/znpcsplus/npc/NPCType.java b/src/main/java/lol/pyr/znpcsplus/npc/NPCType.java index 463b8d5..8fcaa86 100644 --- a/src/main/java/lol/pyr/znpcsplus/npc/NPCType.java +++ b/src/main/java/lol/pyr/znpcsplus/npc/NPCType.java @@ -4,6 +4,7 @@ import com.github.retrooper.packetevents.PacketEvents; import com.github.retrooper.packetevents.manager.server.ServerVersion; import com.github.retrooper.packetevents.protocol.entity.type.EntityType; import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes; +import lol.pyr.znpcsplus.entity.EntityProperty; import java.util.*; @@ -19,10 +20,10 @@ public class NPCType { } private final EntityType type; - private final Set> allowedProperties; + private final Set> allowedProperties; private final String name; - private NPCType(String name, EntityType type, Set> allowedProperties) { + private NPCType(String name, EntityType type, Set> allowedProperties) { this.name = name.toUpperCase(); this.type = type; this.allowedProperties = allowedProperties; @@ -36,7 +37,7 @@ public class NPCType { return type; } - public Set> getAllowedProperties() { + public Set> getAllowedProperties() { return allowedProperties; } @@ -51,7 +52,7 @@ public class NPCType { static { register(new Builder("player", EntityTypes.PLAYER) - .addProperties(NPCProperty.SKIN, NPCProperty.SKIN_LAYERS)); + .addProperties(EntityProperty.SKIN, EntityProperty.SKIN_LAYERS)); register(new Builder("creeper", EntityTypes.CREEPER)); register(new Builder("zombie", EntityTypes.ZOMBIE)); register(new Builder("skeleton", EntityTypes.SKELETON)); @@ -60,7 +61,7 @@ public class NPCType { private static final class Builder { private final String name; private final EntityType type; - private final List> allowedProperties = new ArrayList<>(); + private final List> allowedProperties = new ArrayList<>(); private boolean globalProperties = true; private Builder(String name, EntityType type) { @@ -68,7 +69,7 @@ public class NPCType { this.type = type; } - public Builder addProperties(NPCProperty... properties) { + public Builder addProperties(EntityProperty... properties) { allowedProperties.addAll(List.of(properties)); return this; } @@ -80,10 +81,11 @@ public class NPCType { public NPCType build() { if (globalProperties) { - allowedProperties.add(NPCProperty.FIRE); - allowedProperties.add(NPCProperty.INVISIBLE); + allowedProperties.add(EntityProperty.FIRE); + allowedProperties.add(EntityProperty.INVISIBLE); + allowedProperties.add(EntityProperty.SILENT); if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) - allowedProperties.add(NPCProperty.GLOW); + allowedProperties.add(EntityProperty.GLOW); } return new NPCType(name, type, Set.copyOf(allowedProperties)); } diff --git a/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java b/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java index 9cdaf43..fc151fa 100644 --- a/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java +++ b/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java @@ -4,24 +4,26 @@ import com.github.retrooper.packetevents.PacketEvents; import com.github.retrooper.packetevents.manager.server.ServerVersion; import com.github.retrooper.packetevents.protocol.entity.data.EntityData; import lol.pyr.znpcsplus.entity.PacketEntity; +import lol.pyr.znpcsplus.entity.PropertyHolder; import lol.pyr.znpcsplus.util.LazyLoader; import org.bukkit.entity.Player; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; public interface PacketFactory { - void spawnPlayer(Player player, PacketEntity entity); - void spawnEntity(Player player, PacketEntity entity); - void destroyEntity(Player player, PacketEntity entity); + void spawnPlayer(Player player, PacketEntity entity, PropertyHolder properties); + void spawnEntity(Player player, PacketEntity entity, PropertyHolder properties); + void destroyEntity(Player player, PacketEntity entity, PropertyHolder properties); void teleportEntity(Player player, PacketEntity entity); - CompletableFuture addTabPlayer(Player player, PacketEntity entity); + CompletableFuture addTabPlayer(Player player, PacketEntity entity, PropertyHolder properties); void removeTabPlayer(Player player, PacketEntity entity); - void createTeam(Player player, PacketEntity entity); + void createTeam(Player player, PacketEntity entity, PropertyHolder properties); void removeTeam(Player player, PacketEntity entity); - void sendAllMetadata(Player player, PacketEntity entity); - void sendMetadata(Player player, PacketEntity entity, EntityData... data); + void sendAllMetadata(Player player, PacketEntity entity, PropertyHolder properties); + void sendMetadata(Player player, PacketEntity entity, List data); PacketFactory factory = get(); diff --git a/src/main/java/lol/pyr/znpcsplus/packets/V1_14Factory.java b/src/main/java/lol/pyr/znpcsplus/packets/V1_14Factory.java index 560f948..fdbad60 100644 --- a/src/main/java/lol/pyr/znpcsplus/packets/V1_14Factory.java +++ b/src/main/java/lol/pyr/znpcsplus/packets/V1_14Factory.java @@ -3,18 +3,19 @@ package lol.pyr.znpcsplus.packets; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSpawnEntity; import lol.pyr.znpcsplus.entity.PacketEntity; import lol.pyr.znpcsplus.entity.PacketLocation; -import lol.pyr.znpcsplus.npc.NPCProperty; +import lol.pyr.znpcsplus.entity.EntityProperty; +import lol.pyr.znpcsplus.entity.PropertyHolder; import org.bukkit.entity.Player; import java.util.Optional; public class V1_14Factory extends V1_9Factory { @Override - public void spawnEntity(Player player, PacketEntity entity) { + public void spawnEntity(Player player, PacketEntity entity, PropertyHolder properties) { PacketLocation location = entity.getLocation(); sendPacket(player, new WrapperPlayServerSpawnEntity(entity.getEntityId(), Optional.of(entity.getUuid()), entity.getType(), location.toVector3d(), location.getPitch(), location.getYaw(), location.getYaw(), 0, Optional.empty())); - if (entity.getOwner().hasProperty(NPCProperty.GLOW)) createTeam(player, entity); - sendAllMetadata(player, entity); + if (properties.hasProperty(EntityProperty.GLOW)) createTeam(player, entity, properties); + sendAllMetadata(player, entity, properties); } } diff --git a/src/main/java/lol/pyr/znpcsplus/packets/V1_19Factory.java b/src/main/java/lol/pyr/znpcsplus/packets/V1_19Factory.java index ad0b12c..9d6522c 100644 --- a/src/main/java/lol/pyr/znpcsplus/packets/V1_19Factory.java +++ b/src/main/java/lol/pyr/znpcsplus/packets/V1_19Factory.java @@ -6,6 +6,7 @@ import com.github.retrooper.packetevents.protocol.player.UserProfile; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerPlayerInfoRemove; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerPlayerInfoUpdate; import lol.pyr.znpcsplus.entity.PacketEntity; +import lol.pyr.znpcsplus.entity.PropertyHolder; import net.kyori.adventure.text.Component; import org.bukkit.entity.Player; @@ -14,10 +15,10 @@ import java.util.concurrent.CompletableFuture; public class V1_19Factory extends V1_14Factory { @Override - public CompletableFuture addTabPlayer(Player player, PacketEntity entity) { + public CompletableFuture addTabPlayer(Player player, PacketEntity entity, PropertyHolder properties) { if (entity.getType() != EntityTypes.PLAYER) return CompletableFuture.completedFuture(null); CompletableFuture future = new CompletableFuture<>(); - skinned(player, entity, new UserProfile(entity.getUuid(), Integer.toString(entity.getEntityId()))).thenAccept(profile -> { + skinned(player, properties, new UserProfile(entity.getUuid(), Integer.toString(entity.getEntityId()))).thenAccept(profile -> { WrapperPlayServerPlayerInfoUpdate.PlayerInfo info = new WrapperPlayServerPlayerInfoUpdate.PlayerInfo( profile, false, 1, GameMode.CREATIVE, Component.empty(), null); sendPacket(player, new WrapperPlayServerPlayerInfoUpdate(EnumSet.of(WrapperPlayServerPlayerInfoUpdate.Action.ADD_PLAYER, diff --git a/src/main/java/lol/pyr/znpcsplus/packets/V1_8Factory.java b/src/main/java/lol/pyr/znpcsplus/packets/V1_8Factory.java index ebeda9f..122fd88 100644 --- a/src/main/java/lol/pyr/znpcsplus/packets/V1_8Factory.java +++ b/src/main/java/lol/pyr/znpcsplus/packets/V1_8Factory.java @@ -14,32 +14,33 @@ import lol.pyr.znpcsplus.ZNPCsPlus; import lol.pyr.znpcsplus.entity.PacketEntity; import lol.pyr.znpcsplus.entity.PacketLocation; import lol.pyr.znpcsplus.metadata.MetadataFactory; -import lol.pyr.znpcsplus.npc.NPC; -import lol.pyr.znpcsplus.npc.NPCProperty; +import lol.pyr.znpcsplus.entity.EntityProperty; +import lol.pyr.znpcsplus.entity.PropertyHolder; import lol.pyr.znpcsplus.skin.SkinDescriptor; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.entity.Player; +import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; public class V1_8Factory implements PacketFactory { @Override - public void spawnPlayer(Player player, PacketEntity entity) { - addTabPlayer(player, entity).thenAccept(ignored -> { - createTeam(player, entity); + public void spawnPlayer(Player player, PacketEntity entity, PropertyHolder properties) { + addTabPlayer(player, entity, properties).thenAccept(ignored -> { + createTeam(player, entity, properties); PacketLocation location = entity.getLocation(); sendPacket(player, new WrapperPlayServerSpawnPlayer(entity.getEntityId(), entity.getUuid(), location.toVector3d(), location.getYaw(), location.getPitch(), List.of())); - sendAllMetadata(player, entity); + sendAllMetadata(player, entity, properties); ZNPCsPlus.SCHEDULER.runTaskLaterSync(() -> removeTabPlayer(player, entity), 60); }); } @Override - public void spawnEntity(Player player, PacketEntity entity) { + public void spawnEntity(Player player, PacketEntity entity, PropertyHolder properties) { PacketLocation location = entity.getLocation(); EntityType type = entity.getType(); ClientVersion clientVersion = PacketEvents.getAPI().getServerManager().getVersion().toClientVersion(); @@ -48,11 +49,11 @@ public class V1_8Factory implements PacketFactory { location.getYaw(), location.getPitch(), location.getPitch(), new Vector3d(), List.of()) : new WrapperPlayServerSpawnEntity(entity.getEntityId(), Optional.of(entity.getUuid()), entity.getType(), location.toVector3d(), location.getPitch(), location.getYaw(), location.getYaw(), 0, Optional.empty())); - sendAllMetadata(player, entity); + sendAllMetadata(player, entity, properties); } @Override - public void destroyEntity(Player player, PacketEntity entity) { + public void destroyEntity(Player player, PacketEntity entity, PropertyHolder properties) { sendPacket(player, new WrapperPlayServerDestroyEntities(entity.getEntityId())); if (entity.getType() == EntityTypes.PLAYER) removeTeam(player, entity); } @@ -65,10 +66,10 @@ public class V1_8Factory implements PacketFactory { } @Override - public CompletableFuture addTabPlayer(Player player, PacketEntity entity) { + public CompletableFuture addTabPlayer(Player player, PacketEntity entity, PropertyHolder properties) { if (entity.getType() != EntityTypes.PLAYER) return CompletableFuture.completedFuture(null); CompletableFuture future = new CompletableFuture<>(); - skinned(player, entity, new UserProfile(entity.getUuid(), Integer.toString(entity.getEntityId()))).thenAccept(profile -> { + skinned(player, properties, new UserProfile(entity.getUuid(), Integer.toString(entity.getEntityId()))).thenAccept(profile -> { sendPacket(player, new WrapperPlayServerPlayerInfo( WrapperPlayServerPlayerInfo.Action.ADD_PLAYER, new WrapperPlayServerPlayerInfo.PlayerData(Component.text(""), profile, GameMode.CREATIVE, 1))); @@ -86,13 +87,12 @@ public class V1_8Factory implements PacketFactory { } @Override - public void createTeam(Player player, PacketEntity entity) { - NPC owner = entity.getOwner(); + public void createTeam(Player player, PacketEntity entity, PropertyHolder properties) { sendPacket(player, new WrapperPlayServerTeams("npc_team_" + entity.getEntityId(), WrapperPlayServerTeams.TeamMode.CREATE, new WrapperPlayServerTeams.ScoreBoardTeamInfo( Component.empty(), Component.empty(), Component.empty(), WrapperPlayServerTeams.NameTagVisibility.NEVER, WrapperPlayServerTeams.CollisionRule.NEVER, - owner.hasProperty(NPCProperty.GLOW) ? owner.getProperty(NPCProperty.GLOW) : NamedTextColor.WHITE, + properties.hasProperty(EntityProperty.GLOW) ? properties.getProperty(EntityProperty.GLOW) : NamedTextColor.WHITE, WrapperPlayServerTeams.OptionData.NONE ))); sendPacket(player, new WrapperPlayServerTeams("npc_team_" + entity.getEntityId(), WrapperPlayServerTeams.TeamMode.ADD_ENTITIES, (WrapperPlayServerTeams.ScoreBoardTeamInfo) null, @@ -105,27 +105,29 @@ public class V1_8Factory implements PacketFactory { } @Override - public void sendAllMetadata(Player player, PacketEntity entity) { - NPC owner = entity.getOwner(); - if (entity.getType() == EntityTypes.PLAYER && owner.getProperty(NPCProperty.SKIN_LAYERS)) sendMetadata(player, entity, MetadataFactory.get().skinLayers()); - boolean fire = owner.getProperty(NPCProperty.FIRE); - boolean invisible = owner.getProperty(NPCProperty.INVISIBLE); - if (fire || invisible) sendMetadata(player, entity, MetadataFactory.get().effects(fire, false, invisible)); + public void sendAllMetadata(Player player, PacketEntity entity, PropertyHolder properties) { + ArrayList data = new ArrayList<>(); + if (entity.getType() == EntityTypes.PLAYER && properties.getProperty(EntityProperty.SKIN_LAYERS)) data.add(MetadataFactory.get().skinLayers()); + boolean fire = properties.getProperty(EntityProperty.FIRE); + boolean invisible = properties.getProperty(EntityProperty.INVISIBLE); + if (fire || invisible) data.add(MetadataFactory.get().effects(fire, false, invisible)); + if (properties.getProperty(EntityProperty.SILENT)) data.add(MetadataFactory.get().silent()); + if (properties.hasProperty(EntityProperty.NAME)) data.addAll(MetadataFactory.get().name(properties.getProperty(EntityProperty.NAME))); + sendMetadata(player, entity, data); } @Override - public void sendMetadata(Player player, PacketEntity entity, EntityData... data) { - PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerEntityMetadata(entity.getEntityId(), List.of(data))); + public void sendMetadata(Player player, PacketEntity entity, List data) { + PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerEntityMetadata(entity.getEntityId(), data)); } protected void sendPacket(Player player, PacketWrapper packet) { PacketEvents.getAPI().getPlayerManager().sendPacket(player, packet); } - protected CompletableFuture skinned(Player player, PacketEntity entity, UserProfile profile) { - NPC owner = entity.getOwner(); - if (!owner.hasProperty(NPCProperty.SKIN)) return CompletableFuture.completedFuture(profile); - SkinDescriptor descriptor = owner.getProperty(NPCProperty.SKIN); + protected CompletableFuture skinned(Player player, PropertyHolder properties, UserProfile profile) { + if (!properties.hasProperty(EntityProperty.SKIN)) return CompletableFuture.completedFuture(profile); + SkinDescriptor descriptor = properties.getProperty(EntityProperty.SKIN); if (descriptor.supportsInstant(player)) { descriptor.fetchInstant(player).apply(profile); return CompletableFuture.completedFuture(profile); diff --git a/src/main/java/lol/pyr/znpcsplus/packets/V1_9Factory.java b/src/main/java/lol/pyr/znpcsplus/packets/V1_9Factory.java index 0a1eaeb..009d66c 100644 --- a/src/main/java/lol/pyr/znpcsplus/packets/V1_9Factory.java +++ b/src/main/java/lol/pyr/znpcsplus/packets/V1_9Factory.java @@ -1,32 +1,38 @@ package lol.pyr.znpcsplus.packets; +import com.github.retrooper.packetevents.protocol.entity.data.EntityData; import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes; import lol.pyr.znpcsplus.entity.PacketEntity; import lol.pyr.znpcsplus.metadata.MetadataFactory; -import lol.pyr.znpcsplus.npc.NPC; -import lol.pyr.znpcsplus.npc.NPCProperty; +import lol.pyr.znpcsplus.entity.EntityProperty; +import lol.pyr.znpcsplus.entity.PropertyHolder; import org.bukkit.entity.Player; +import java.util.ArrayList; + public class V1_9Factory extends V1_8Factory { @Override - public void sendAllMetadata(Player player, PacketEntity entity) { - NPC owner = entity.getOwner(); - if (entity.getType() == EntityTypes.PLAYER && owner.getProperty(NPCProperty.SKIN_LAYERS)) sendMetadata(player, entity, MetadataFactory.get().skinLayers()); - boolean glow = owner.hasProperty(NPCProperty.GLOW); - boolean fire = owner.getProperty(NPCProperty.FIRE); - boolean invisible = owner.getProperty(NPCProperty.INVISIBLE); - if (glow || fire) sendMetadata(player, entity, MetadataFactory.get().effects(fire, glow, invisible)); + public void sendAllMetadata(Player player, PacketEntity entity, PropertyHolder properties) { + ArrayList data = new ArrayList<>(); + if (entity.getType() == EntityTypes.PLAYER && properties.getProperty(EntityProperty.SKIN_LAYERS)) data.add(MetadataFactory.get().skinLayers()); + boolean glow = properties.hasProperty(EntityProperty.GLOW); + boolean fire = properties.getProperty(EntityProperty.FIRE); + boolean invisible = properties.getProperty(EntityProperty.INVISIBLE); + if (glow || fire || invisible) data.add(MetadataFactory.get().effects(fire, glow, invisible)); + if (properties.getProperty(EntityProperty.SILENT)) data.add(MetadataFactory.get().silent()); + if (properties.hasProperty(EntityProperty.NAME)) data.addAll(MetadataFactory.get().name(properties.getProperty(EntityProperty.NAME))); + sendMetadata(player, entity, data); } @Override - public void spawnEntity(Player player, PacketEntity entity) { - super.spawnEntity(player, entity); - if (entity.getOwner().hasProperty(NPCProperty.GLOW)) createTeam(player, entity); + public void spawnEntity(Player player, PacketEntity entity, PropertyHolder properties) { + super.spawnEntity(player, entity, properties); + if (properties.hasProperty(EntityProperty.GLOW)) createTeam(player, entity, properties); } @Override - public void destroyEntity(Player player, PacketEntity entity) { - super.destroyEntity(player, entity); - if (entity.getType() != EntityTypes.PLAYER && entity.getOwner().hasProperty(NPCProperty.GLOW)) removeTeam(player, entity); + public void destroyEntity(Player player, PacketEntity entity, PropertyHolder properties) { + super.destroyEntity(player, entity, properties); + if (entity.getType() != EntityTypes.PLAYER && properties.hasProperty(EntityProperty.GLOW)) removeTeam(player, entity); } } diff --git a/src/main/java/lol/pyr/znpcsplus/util/Viewable.java b/src/main/java/lol/pyr/znpcsplus/util/Viewable.java new file mode 100644 index 0000000..60b39f3 --- /dev/null +++ b/src/main/java/lol/pyr/znpcsplus/util/Viewable.java @@ -0,0 +1,59 @@ +package lol.pyr.znpcsplus.util; + +import org.bukkit.entity.Player; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +public abstract class Viewable { + private final Set viewers = new HashSet<>(); + + public void delete() { + UNSAFE_hideAll(); + viewers.clear(); + } + + public void respawn() { + UNSAFE_hideAll(); + UNSAFE_showAll(); + } + + public void respawn(Player player) { + if (!viewers.contains(player)) return; + _hide(player); + _show(player); + } + + public void show(Player player) { + if (viewers.contains(player)) return; + _show(player); + viewers.add(player); + } + + public void hide(Player player) { + if (!viewers.contains(player)) return; + _hide(player); + viewers.remove(player); + } + + public boolean isShown(Player player) { + return viewers.contains(player); + } + + protected void UNSAFE_hideAll() { + for (Player viewer : viewers) _hide(viewer); + } + + protected void UNSAFE_showAll() { + for (Player viewer : viewers) _show(viewer); + } + + public Set getViewers() { + return Collections.unmodifiableSet(viewers); + } + + protected abstract void _show(Player player); + + protected abstract void _hide(Player player); +}