holograms woo

This commit is contained in:
Pyrbu 2023-04-26 00:31:49 +01:00
parent 0e9fab6e7a
commit 7a4899b2b5
29 changed files with 396 additions and 1077 deletions

@ -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<ConfigurationValue, Object> 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<Configuration> SAVE_CONFIGURATIONS = ImmutableList.of(CONVERSATIONS, DATA);
protected Configuration(String name) {
this(name, ZNPCsPlus.PLUGIN_FOLDER.toPath().resolve(name + ".json"));

@ -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) {
}
}

@ -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<CacheKey, Object> 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);
}
}
}

@ -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) {

@ -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<Constructor<?>> SCOREBOARD_TEAM_CONSTRUCTOR = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
.withClassName(SCOREBOARD_TEAM_CLASS)
.withParameterTypes(SCOREBOARD_CLASS, String.class));
public static final ReflectionLazyLoader<Constructor<?>> 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<Constructor<?>> 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<Constructor<?>> 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<Constructor<?>> 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<Constructor<?>> 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<Constructor<?>> 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<Constructor<?>> PACKET_PLAY_OUT_ENTITY_HEAD_ROTATION_CONSTRUCTOR = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
.withClassName("PacketPlayOutEntityHeadRotation")
.withParameterTypes(ENTITY_CLASS, byte.class));
public static final ReflectionLazyLoader<Constructor<?>> PACKET_PLAY_OUT_ENTITY_TELEPORT_CONSTRUCTOR = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
.withClassName("PacketPlayOutEntityTeleport")
.withParameterTypes(ENTITY_CLASS));
public static final ReflectionLazyLoader<Constructor<?>> 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<Constructor<?>> 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<Constructor<?>> 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<Constructor<?>> PLAYER_INTERACT_MANAGER_OLD_CONSTRUCTOR = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
.withClassName("PlayerInteractManager")
.withParameterTypes(WORLD_CLASS));
public static final ReflectionLazyLoader<Constructor<?>> PLAYER_INTERACT_MANAGER_NEW_CONSTRUCTOR = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
.withClassName("PlayerInteractManager")
.withParameterTypes(WORLD_SERVER_CLASS));
public static final ReflectionLazyLoader<Constructor<?>> PACKET_PLAY_OUT_SCOREBOARD_TEAM_CONSTRUCTOR_OLD = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
.withClassName(PACKET_PLAY_OUT_SCOREBOARD_TEAM_CLASS));
public static final ReflectionLazyLoader<Constructor<?>> I_CHAT_BASE_COMPONENT_A_CONSTRUCTOR = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.CHAT)
.withClassName("ChatComponentText")
.withParameterTypes(String.class));
public static final ReflectionLazyLoader<Constructor<?>> 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<Constructor<?>> DATA_WATCHER_OBJECT_CONSTRUCTOR = new ConstructorReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
.withClassName(DATA_WATCHER_OBJECT)
.withParameterTypes(int.class, DATA_WATCHER_SERIALIZER));
public static final ReflectionLazyLoader<Method> GET_PROFILE_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withClassName(ENTITY_HUMAN_CLASS)
.withExpectResult(GameProfile.class));
public static final ReflectionLazyLoader<Method> 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<Method> GET_HANDLE_PLAYER_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.BUKKIT)
.withClassName("entity.CraftPlayer").withClassName("entity.CraftHumanEntity")
.withMethodName("getHandle"));
public static final ReflectionLazyLoader<Method> GET_HANDLE_WORLD_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.BUKKIT)
.withClassName("CraftWorld")
.withMethodName("getHandle"));
public static final ReflectionLazyLoader<Method> GET_SERVER_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.BUKKIT)
.withClassName("CraftServer")
.withMethodName("getServer"));
public static final ReflectionLazyLoader<Method> SEND_PACKET_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
.withClassName(PLAYER_CONNECTION_CLASS)
.withMethodName("sendPacket").withMethodName("a")
.withParameterTypes(PACKET_CLASS));
public static final ReflectionLazyLoader<Method> SET_CUSTOM_NAME_OLD_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
.withClassName(ENTITY_CLASS)
.withMethodName("setCustomName")
.withParameterTypes(String.class));
public static final ReflectionLazyLoader<Method> 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<Method> 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<Method> 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<Method> 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<Method> 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<Method> 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<Method> 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<Method> GET_BUKKIT_ENTITY_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
.withClassName(ENTITY_CLASS)
.withMethodName("getBukkitEntity"));
public static final ReflectionLazyLoader<Method> GET_ENUM_CHAT_ID_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
.withClassName(ENUM_CHAT_CLASS)
.withMethodName("b"));
public static final ReflectionLazyLoader<Method> ENUM_CHAT_TO_STRING_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
.withClassName(ENUM_CHAT_CLASS)
.withExpectResult(String.class)
.withMethodName("toString"));
public static final ReflectionLazyLoader<Method> ENTITY_TYPES_A_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withClassName(ENTITY_TYPES_CLASS)
.withMethodName("a")
.withParameterTypes(String.class));
public static final ReflectionLazyLoader<Method> 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<Method> 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<Method> SCOREBOARD_PLAYER_LIST = new MethodReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
.withClassName(SCOREBOARD_TEAM_CLASS)
.withMethodName("getPlayerNameSet").withMethodName("g"));
public static final ReflectionLazyLoader<Method> 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<Method> CRAFT_CHAT_MESSAGE_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.BUKKIT)
.withClassName(CRAFT_CHAT_MESSAGE_CLASS)
.withMethodName("fromStringOrNull")
.withParameterTypes(String.class));
public static final ReflectionLazyLoader<Method> GET_UNIQUE_ID_METHOD = new MethodReflection(new ReflectionBuilder(ReflectionPackage.MINECRAFT)
.withClassName(ENTITY_CLASS)
.withExpectResult(UUID.class));
public static final ReflectionLazyLoader<Method> GET_DATAWATCHER_B_LIST = new MethodReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
.withMethodName("c")
.withClassName(DATA_WATCHER_CLASS));
public static final ReflectionLazyLoader<Field> 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<Object> 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<Object> UPDATE_LISTED_FIELD = new FieldReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
.withClassName("ClientboundPlayerInfoUpdatePacket$a")
.withFieldName("d")).staticValueLoader();
public static final ReflectionLazyLoader<Object> DATA_WATCHER_REGISTER_FIELD = new FieldReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
.withClassName(DATA_WATCHER_REGISTRY)
.withFieldName("a")).staticValueLoader();
public static final ReflectionLazyLoader<Object> ENUM_TAG_VISIBILITY_NEVER_FIELD = new FieldReflection(new ReflectionBuilder(ReflectionPackage.PACKET)
.withClassName(ENUM_TAG_VISIBILITY)
.withFieldName("b")).staticValueLoader();
public static final ReflectionLazyLoader<CommandMap> COMMAND_MAP_FIELD = new FieldReflection(new ReflectionBuilder(ReflectionPackage.BUKKIT)
.withClassName("CraftServer")
.withFieldName("commandMap")).valueLoader(Bukkit.getServer(), CommandMap.class);
public static final FieldReflection.ValueModifier<Integer> ENTITY_ID_MODIFIER = new FieldReflection(new ReflectionBuilder(ReflectionPackage.ENTITY)
.withClassName(ENTITY_CLASS)
.withFieldName("entityCount")

@ -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<Constructor<?>> {
private final ImmutableList<Class<?>[]> 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<String> logger) {
logger.accept("Possible Parameter Type Combinations:");
for (Class<?>[] possible : parameterTypes) logger.accept(Arrays.toString(possible));
}
}

@ -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<Enum<?>[]> {
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;
}
}

@ -17,7 +17,7 @@ public class FieldReflection extends ReflectionLazyLoader<Field> {
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;

@ -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();
}
}
}

@ -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;
}
}

@ -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<T> {
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<String, EntityProperty<?>> BY_NAME = new HashMap<>();
public static EntityProperty<?> getByName(String name) {
return BY_NAME.get(name.toUpperCase());
}
public static EntityProperty<Boolean> SKIN_LAYERS = new EntityProperty<>("skin_layers", true);
public static EntityProperty<SkinDescriptor> SKIN = new EntityProperty<>("skin");
public static EntityProperty<NamedTextColor> GLOW = new EntityProperty<>("glow");
public static EntityProperty<Boolean> FIRE = new EntityProperty<>("fire", false);
public static EntityProperty<Boolean> INVISIBLE = new EntityProperty<>("invisible", false);
public static EntityProperty<Boolean> SILENT = new EntityProperty<>("silent", false);
public static EntityProperty<Component> NAME = new EntityProperty<>("name");
}

@ -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<Player> viewers) {
public void setLocation(PacketLocation location, Collection<Player> 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() {

@ -0,0 +1,18 @@
package lol.pyr.znpcsplus.entity;
public interface PropertyHolder {
<T> T getProperty(EntityProperty<T> key);
boolean hasProperty(EntityProperty<?> key);
PropertyHolder EMPTY = new PropertyHolder() {
@Override
public <T> T getProperty(EntityProperty<T> key) {
return null;
}
@Override
public boolean hasProperty(EntityProperty<?> key) {
return false;
}
};
}

@ -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<HologramLine> 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);
}
}

@ -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<Player> viewers) {
armorStand.setLocation(location, viewers);
}
@SuppressWarnings("unchecked")
@Override
public <T> T getProperty(EntityProperty<T> 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;
}
}

@ -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<EntityData> name(Component name);
EntityData silent();
MetadataFactory factory = get();

@ -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<EntityData> name(Component name) {
return List.of(
new EntityData(2, EntityDataTypes.OPTIONAL_COMPONENT, AdventureSerializer.getGsonSerializer().serialize(name)),
new EntityData(3, EntityDataTypes.BOOLEAN, true)
);
}
}

@ -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);

@ -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<EntityData> 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);
}

@ -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<EntityData> 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);
}
}

@ -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<NPC> _ALL_NPCS = new HashSet<>();
private final Set<Player> viewers = new HashSet<>();
@ -18,7 +21,7 @@ public class NPC {
private PacketLocation location;
private NPCType type;
private final Map<NPCProperty<?>, Object> propertyMap = new HashMap<>();
private final Map<EntityProperty<?>, Object> propertyMap = new HashMap<>();
private final Set<NPCAction> 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> T getProperty(NPCProperty<T> key) {
public <T> T getProperty(EntityProperty<T> 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 <T> void setProperty(NPCProperty<T> key, T value) {
public <T> void setProperty(EntityProperty<T> 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<NPCAction> getActions() {

@ -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<T> {
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<String, NPCProperty<?>> BY_NAME = new HashMap<>();
public static NPCProperty<?> getByName(String name) {
return BY_NAME.get(name.toUpperCase());
}
public static NPCProperty<Boolean> SKIN_LAYERS = new NPCProperty<>("skin_layers", true);
public static NPCProperty<SkinDescriptor> SKIN = new NPCProperty<>("skin");
public static NPCProperty<NamedTextColor> GLOW = new NPCProperty<>("glow");
public static NPCProperty<Boolean> FIRE = new NPCProperty<>("fire", false);
public static NPCProperty<Boolean> INVISIBLE = new NPCProperty<>("invisible", false);
}

@ -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<NPCProperty<?>> allowedProperties;
private final Set<EntityProperty<?>> allowedProperties;
private final String name;
private NPCType(String name, EntityType type, Set<NPCProperty<?>> allowedProperties) {
private NPCType(String name, EntityType type, Set<EntityProperty<?>> allowedProperties) {
this.name = name.toUpperCase();
this.type = type;
this.allowedProperties = allowedProperties;
@ -36,7 +37,7 @@ public class NPCType {
return type;
}
public Set<NPCProperty<?>> getAllowedProperties() {
public Set<EntityProperty<?>> 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<NPCProperty<?>> allowedProperties = new ArrayList<>();
private final List<EntityProperty<?>> 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));
}

@ -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<Void> addTabPlayer(Player player, PacketEntity entity);
CompletableFuture<Void> 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<EntityData> data);
PacketFactory factory = get();

@ -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);
}
}

@ -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<Void> addTabPlayer(Player player, PacketEntity entity) {
public CompletableFuture<Void> addTabPlayer(Player player, PacketEntity entity, PropertyHolder properties) {
if (entity.getType() != EntityTypes.PLAYER) return CompletableFuture.completedFuture(null);
CompletableFuture<Void> 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,

@ -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<Void> addTabPlayer(Player player, PacketEntity entity) {
public CompletableFuture<Void> addTabPlayer(Player player, PacketEntity entity, PropertyHolder properties) {
if (entity.getType() != EntityTypes.PLAYER) return CompletableFuture.completedFuture(null);
CompletableFuture<Void> 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<EntityData> 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<EntityData> 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<UserProfile> 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<UserProfile> 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);

@ -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<EntityData> 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);
}
}

@ -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<Player> 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<Player> getViewers() {
return Collections.unmodifiableSet(viewers);
}
protected abstract void _show(Player player);
protected abstract void _hide(Player player);
}