fix most if not all reflection cache misses, renamed the "cache" to a more sane name

This commit is contained in:
Pyrbu 2023-04-20 20:34:58 +01:00
parent 5225410814
commit 8506aa99bc
21 changed files with 1057 additions and 1062 deletions

@ -1,682 +0,0 @@
package io.github.znetworkw.znpcservers.cache;
import com.mojang.authlib.GameProfile;
import io.github.znetworkw.znpcservers.utility.Utils;
import io.netty.channel.Channel;
import org.bukkit.inventory.ItemStack;
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;
public final class CacheRegistry {
public static final Class<?> PACKET_PLAY_IN_USE_ENTITY_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName("PacketPlayInUseEntity"))).load();
public static final Class<?> ENUM_PLAYER_INFO_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName("PacketPlayOutPlayerInfo$EnumPlayerInfoAction")
.withClassName("ClientboundPlayerInfoUpdatePacket$a"))).load();
public static final Class<?> PACKET_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PROTOCOL)
.withClassName("Packet"))).load();
public static final Class<?> ENTITY_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withClassName("Entity"))).load();
public static final Class<?> ENTITY_LIVING = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withClassName("EntityLiving"))).load();
public static final Class<?> ENTITY_PLAYER_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.SERVER_LEVEL)
.withClassName("EntityPlayer"))).load();
public static final Class<?> ENTITY_ARMOR_STAND_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("decoration")
.withClassName("EntityArmorStand"))).load();
public static final Class<?> ENTITY_BAT_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("ambient")
.withClassName("EntityBat"))).load();
public static final Class<?> ENTITY_BLAZE_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("monster")
.withClassName("EntityBlaze"))).load();
public static final Class<?> ENTITY_CAVE_SPIDER_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("monster")
.withClassName("EntityCaveSpider"))).load();
public static final Class<?> ENTITY_CHICKEN_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityChicken"))).load();
public static final Class<?> ENTITY_COW_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityCow"))).load();
public static final Class<?> ENTITY_CREEPER_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("monster")
.withClassName("EntityCreeper"))).load();
public static final Class<?> ENTITY_ENDER_DRAGON_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("boss.enderdragon")
.withClassName("EntityEnderDragon"))).load();
public static final Class<?> ENTITY_ENDERMAN_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("monster")
.withClassName("EntityEnderman"))).load();
public static final Class<?> ENTITY_HUMAN_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("player")
.withClassName("EntityHuman"))).load();
public static final Class<?> ENTITY_ENDERMITE_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("monster")
.withClassName("EntityEndermite"))).load();
public static final Class<?> ENTITY_GHAST_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("monster")
.withClassName("EntityGhast"))).load();
public static final Class<?> ENTITY_IRON_GOLEM_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityIronGolem"))).load();
public static final Class<?> ENTITY_GIANT_ZOMBIE_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("monster")
.withClassName("EntityGiantZombie"))).load();
public static final Class<?> ENTITY_GUARDIAN_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("monster")
.withClassName("EntityGuardian"))).load();
public static final Class<?> ENTITY_HORSE_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("animal.horse")
.withClassName("EntityHorse"))).load();
public static final Class<?> ENTITY_LLAMA_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("animal.horse")
.withClassName("EntityLlama"))).load();
public static final Class<?> ENTITY_MAGMA_CUBE_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("monster")
.withClassName("EntityMagmaCube"))).load();
public static final Class<?> ENTITY_MUSHROOM_COW_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityMushroomCow"))).load();
public static final Class<?> ENTITY_OCELOT_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityOcelot"))).load();
public static final Class<?> ENTITY_TURTLE = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityTurtle"))).load();
public static final Class<?> ENTITY_WARDEN = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("monster.warden")
.withClassName("EntityWarden")
.withClassName("Warden"))).load();
public static final Class<?> ENTITY_BEE_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityBee"))).load();
public static final Class<?> ENTITY_PARROT_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityParrot"))).load();
public static final Class<?> ENTITY_PIG_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityPig"))).load();
public static final Class<?> ENTITY_RABBIT_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityRabbit"))).load();
public static final Class<?> ENTITY_POLAR_BEAR_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityPolarBear"))).load();
public static final Class<?> ENTITY_PANDA_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityPanda"))).load();
public static final Class<?> ENTITY_SHEEP_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("animal")
.withClassName("EntitySheep"))).load();
public static final Class<?> ENTITY_SNOWMAN_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("animal")
.withClassName("EntitySnowman"))).load();
public static final Class<?> ENTITY_SHULKER_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("monster")
.withClassName("EntityShulker"))).load();
public static final Class<?> ENTITY_SILVERFISH_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("monster")
.withClassName("EntitySilverfish"))).load();
public static final Class<?> ENTITY_SKELETON_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("monster")
.withClassName("EntitySkeleton"))).load();
public static final Class<?> ENTITY_SLIME_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("monster")
.withClassName("EntitySlime"))).load();
public static final Class<?> ENTITY_SPIDER_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("monster")
.withClassName("EntitySpider"))).load();
public static final Class<?> ENTITY_SQUID_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("animal")
.withClassName("EntitySquid"))).load();
public static final Class<?> ENTITY_VILLAGER_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("npc")
.withClassName("EntityVillager"))).load();
public static final Class<?> ENTITY_WITCH_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("monster")
.withClassName("EntityWitch"))).load();
public static final Class<?> ENTITY_WITHER_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("boss.wither")
.withClassName("EntityWither"))).load();
public static final Class<?> ENTITY_ZOMBIE_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("monster")
.withClassName("EntityZombie"))).load();
public static final Class<?> ENTITY_WOLF_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityWolf"))).load();
public static final Class<?> ENTITY_AXOLOTL_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("animal.axolotl")
.withClassName("Axolotl"))).load();
public static final Class<?> ENTITY_GOAT_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("animal.goat")
.withClassName("Goat"))).load();
public static final Class<?> ENTITY_FOX_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityFox"))).load();
public static final Class<?> ENTITY_TYPES_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withClassName("EntityTypes"))).load();
public static final Class<?> ENUM_CHAT_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withClassName("EnumChatFormat"))).load();
public static final Class<?> ENUM_ITEM_SLOT = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withClassName("EnumItemSlot"))).load();
public static final Class<?> I_CHAT_BASE_COMPONENT = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.CHAT)
.withClassName("IChatBaseComponent"))).load();
public static final Class<?> ITEM_STACK_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ITEM)
.withClassName("ItemStack"))).load();
public static final Class<?> DATA_WATCHER_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.SYNCHER)
.withClassName("DataWatcher"))).load();
public static final Class<?> DATA_WATCHER_OBJECT = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.SYNCHER)
.withClassName("DataWatcherObject"))).load();
public static final Class<?> DATA_WATCHER_REGISTRY = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.SYNCHER)
.withClassName("DataWatcherRegistry"))).load();
public static final Class<?> DATA_WATCHER_SERIALIZER = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.SYNCHER)
.withClassName("DataWatcherSerializer"))).load();
public static final Class<?> WORLD_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.WORLD_LEVEL)
.withClassName("World"))).load();
public static final Class<?> CRAFT_ITEM_STACK_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.CRAFT_BUKKIT))
.withClassName("inventory.CraftItemStack"))).load();
public static final Class<?> WORLD_SERVER_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.SERVER_LEVEL)
.withClassName("WorldServer"))).load();
public static final Class<?> MINECRAFT_SERVER_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.SERVER)
.withClassName("MinecraftServer"))).load();
public static final Class<?> PLAYER_INTERACT_MANAGER_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.SERVER_LEVEL)
.withClassName("PlayerInteractManager"))).load();
public static final Class<?> PLAYER_CONNECTION_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.SERVER_NETWORK)
.withClassName("PlayerConnection"))).load();
public static final Class<?> NETWORK_MANAGER_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.NETWORK)
.withClassName("NetworkManager"))).load();
public static final Class<?> PACKET_PLAY_OUT_PLAYER_INFO_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName("PacketPlayOutPlayerInfo")
.withClassName("ClientboundPlayerInfoUpdatePacket")))
.load();
public static final Class<?> PACKET_PLAY_OUT_PLAYER_INFO_REMOVE_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName("ClientboundPlayerInfoRemovePacket")))
.load();
public static final Class<?> PACKET_PLAY_OUT_SCOREBOARD_TEAM_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName("PacketPlayOutScoreboardTeam"))).load();
public static final Class<?> PACKET_PLAY_OUT_ENTITY_DESTROY_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName("PacketPlayOutEntityDestroy"))).load();
public static final Class<?> SCOREBOARD_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.WORLD_SCORES)
.withClassName("Scoreboard"))).load();
public static final Class<?> SCOREBOARD_TEAM_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.WORLD_SCORES)
.withClassName("ScoreboardTeam"))).load();
public static final Class<?> ENUM_TAG_VISIBILITY = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.WORLD_SCORES)
.withClassName("ScoreboardTeamBase$EnumNameTagVisibility"))).load();
public static final Class<?> CRAFT_CHAT_MESSAGE_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.CRAFT_BUKKIT))
.withClassName("util.CraftChatMessage"))).load();
public static final Class<?> PROFILE_PUBLIC_KEY_CLASS = (new TypeCache.BaseCache.ClazzLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.WORLD_ENTITY_PLAYER)
.withClassName("ProfilePublicKey"))).load();
public static final TypeCache.BaseCache<Constructor<?>> SCOREBOARD_TEAM_CONSTRUCTOR = new TypeCache.BaseCache.ConstructorLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(SCOREBOARD_TEAM_CLASS)
.withParameterTypes(SCOREBOARD_CLASS, String.class));
public static final TypeCache.BaseCache<Constructor<?>> PLAYER_CONSTRUCTOR_OLD = new TypeCache.BaseCache.ConstructorLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(ENTITY_PLAYER_CLASS)
.withParameterTypes(MINECRAFT_SERVER_CLASS, WORLD_SERVER_CLASS, GameProfile.class, PLAYER_INTERACT_MANAGER_CLASS));
public static final TypeCache.BaseCache<Constructor<?>> PLAYER_CONSTRUCTOR_NEW = new TypeCache.BaseCache.ConstructorLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(ENTITY_PLAYER_CLASS)
.withParameterTypes(MINECRAFT_SERVER_CLASS, WORLD_SERVER_CLASS, GameProfile.class));
public static final TypeCache.BaseCache<Constructor<?>> PLAYER_CONSTRUCTOR_NEW_1 = new TypeCache.BaseCache.ConstructorLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(ENTITY_PLAYER_CLASS)
.withParameterTypes(MINECRAFT_SERVER_CLASS, WORLD_SERVER_CLASS, GameProfile.class, PROFILE_PUBLIC_KEY_CLASS));
public static final TypeCache.BaseCache<Constructor<?>> PLAYER_CONSTRUCTOR_NEW_2 = new TypeCache.BaseCache.ConstructorLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(ENTITY_PLAYER_CLASS)
.withParameterTypes(MINECRAFT_SERVER_CLASS, WORLD_SERVER_CLASS, GameProfile.class));
public static final TypeCache.BaseCache<Constructor<?>> PACKET_PLAY_OUT_PLAYER_INFO_CONSTRUCTOR = new TypeCache.BaseCache.ConstructorLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.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 TypeCache.BaseCache<Constructor<?>> PACKET_PLAY_OUT_PLAYER_INFO_REMOVE_CONSTRUCTOR = new TypeCache.BaseCache.ConstructorLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(PACKET_PLAY_OUT_PLAYER_INFO_REMOVE_CLASS)
.withParameterTypes(List.class));
public static final TypeCache.BaseCache<Constructor<?>> PACKET_PLAY_OUT_ENTITY_LOOK_CONSTRUCTOR = new TypeCache.BaseCache.ConstructorLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName("PacketPlayOutEntity$PacketPlayOutEntityLook")
.withParameterTypes(int.class, byte.class, byte.class, boolean.class));
public static final TypeCache.BaseCache<Constructor<?>> PACKET_PLAY_OUT_ENTITY_HEAD_ROTATION_CONSTRUCTOR = new TypeCache.BaseCache.ConstructorLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName("PacketPlayOutEntityHeadRotation")
.withParameterTypes(ENTITY_CLASS, byte.class));
public static final TypeCache.BaseCache<Constructor<?>> PACKET_PLAY_OUT_ENTITY_TELEPORT_CONSTRUCTOR = new TypeCache.BaseCache.ConstructorLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName("PacketPlayOutEntityTeleport")
.withParameterTypes(ENTITY_CLASS));
public static final TypeCache.BaseCache<Constructor<?>> PACKET_PLAY_OUT_ENTITY_META_DATA_CONSTRUCTOR = new TypeCache.BaseCache.ConstructorLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName("PacketPlayOutEntityMetadata")
.withParameterTypes(int.class, DATA_WATCHER_CLASS, boolean.class));
public static final TypeCache.BaseCache<Constructor<?>> PACKET_PLAY_OUT_ENTITY_META_DATA_CONSTRUCTOR_V1 = new TypeCache.BaseCache.ConstructorLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName("PacketPlayOutEntityMetadata")
.withParameterTypes(int.class, List.class));
public static final TypeCache.BaseCache<Constructor<?>> PACKET_PLAY_OUT_NAMED_ENTITY_CONSTRUCTOR = new TypeCache.BaseCache.ConstructorLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName("PacketPlayOutNamedEntitySpawn")
.withParameterTypes(ENTITY_HUMAN_CLASS));
public static final TypeCache.BaseCache<Constructor<?>> PACKET_PLAY_OUT_ENTITY_DESTROY_CONSTRUCTOR = new TypeCache.BaseCache.ConstructorLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(PACKET_PLAY_OUT_ENTITY_DESTROY_CLASS)
.withParameterTypes(int.class).withParameterTypes(int[].class));
public static final TypeCache.BaseCache<Constructor<?>> PACKET_PLAY_OUT_SPAWN_ENTITY_CONSTRUCTOR = new TypeCache.BaseCache.ConstructorLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName("PacketPlayOutSpawnEntity")
.withClassName("PacketPlayOutSpawnEntityLiving")
.withParameterTypes(ENTITY_LIVING).withParameterTypes(ENTITY_CLASS));
public static final TypeCache.BaseCache<Constructor<?>> PLAYER_INTERACT_MANAGER_OLD_CONSTRUCTOR = new TypeCache.BaseCache.ConstructorLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName("PlayerInteractManager")
.withParameterTypes(WORLD_CLASS));
public static final TypeCache.BaseCache<Constructor<?>> PLAYER_INTERACT_MANAGER_NEW_CONSTRUCTOR = new TypeCache.BaseCache.ConstructorLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName("PlayerInteractManager")
.withParameterTypes(WORLD_SERVER_CLASS));
public static final TypeCache.BaseCache<Constructor<?>> PACKET_PLAY_OUT_SCOREBOARD_TEAM_CONSTRUCTOR_OLD = new TypeCache.BaseCache.ConstructorLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(PACKET_PLAY_OUT_SCOREBOARD_TEAM_CLASS));
public static final TypeCache.BaseCache<Constructor<?>> PACKET_PLAY_OUT_ENTITY_EQUIPMENT_CONSTRUCTOR_OLD = new TypeCache.BaseCache.ConstructorLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName("PacketPlayOutEntityEquipment")
.withParameterTypes(int.class, int.class, ITEM_STACK_CLASS));
public static final TypeCache.BaseCache<Constructor<?>> PACKET_PLAY_OUT_ENTITY_EQUIPMENT_CONSTRUCTOR_NEWEST_OLD = new TypeCache.BaseCache.ConstructorLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName("PacketPlayOutEntityEquipment")
.withParameterTypes(int.class, ENUM_ITEM_SLOT, ITEM_STACK_CLASS));
public static final TypeCache.BaseCache<Constructor<?>> PACKET_PLAY_OUT_ENTITY_EQUIPMENT_CONSTRUCTOR_V1 = new TypeCache.BaseCache.ConstructorLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName("PacketPlayOutEntityEquipment")
.withParameterTypes(int.class, List.class));
public static final TypeCache.BaseCache<Constructor<?>> I_CHAT_BASE_COMPONENT_A_CONSTRUCTOR = new TypeCache.BaseCache.ConstructorLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.CHAT)
.withClassName("ChatComponentText")
.withParameterTypes(String.class));
public static final TypeCache.BaseCache<Constructor<?>> ENTITY_CONSTRUCTOR = new TypeCache.BaseCache.ConstructorLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(ENTITY_ARMOR_STAND_CLASS)
.withParameterTypes(WORLD_CLASS, double.class, double.class, double.class));
public static final TypeCache.BaseCache<Constructor<?>> DATA_WATCHER_OBJECT_CONSTRUCTOR = new TypeCache.BaseCache.ConstructorLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(DATA_WATCHER_OBJECT)
.withParameterTypes(int.class, DATA_WATCHER_SERIALIZER));
public static final TypeCache.BaseCache<Method> AS_NMS_COPY_METHOD = new TypeCache.BaseCache.MethodLoader((new TypeCache.CacheBuilder(CachePackage.CRAFT_BUKKIT))
.withClassName("inventory.CraftItemStack")
.withMethodName("asNMSCopy")
.withParameterTypes(ItemStack.class));
public static final TypeCache.BaseCache<Method> GET_PROFILE_METHOD = new TypeCache.BaseCache.MethodLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withClassName(ENTITY_HUMAN_CLASS)
.withExpectResult(GameProfile.class));
public static final TypeCache.BaseCache<Method> GET_ENTITY_ID = new TypeCache.BaseCache.MethodLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(ENTITY_CLASS)
.withMethodName("getId")
.withMethodName("ae")
.withMethodName("ah")
.withMethodName("af")
.withExpectResult(int.class));
public static final TypeCache.BaseCache<Method> GET_HANDLE_PLAYER_METHOD = new TypeCache.BaseCache.MethodLoader((new TypeCache.CacheBuilder(CachePackage.CRAFT_BUKKIT))
.withClassName("entity.CraftPlayer").withClassName("entity.CraftHumanEntity")
.withMethodName("getHandle"));
public static final TypeCache.BaseCache<Method> GET_HANDLE_WORLD_METHOD = new TypeCache.BaseCache.MethodLoader((new TypeCache.CacheBuilder(CachePackage.CRAFT_BUKKIT))
.withClassName("CraftWorld")
.withMethodName("getHandle"));
public static final TypeCache.BaseCache<Method> GET_SERVER_METHOD = new TypeCache.BaseCache.MethodLoader((new TypeCache.CacheBuilder(CachePackage.CRAFT_BUKKIT))
.withClassName("CraftServer")
.withMethodName("getServer"));
public static final TypeCache.BaseCache<Method> SEND_PACKET_METHOD = new TypeCache.BaseCache.MethodLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(PLAYER_CONNECTION_CLASS)
.withMethodName("sendPacket").withMethodName("a")
.withParameterTypes(PACKET_CLASS));
public static final TypeCache.BaseCache<Method> SET_CUSTOM_NAME_OLD_METHOD = new TypeCache.BaseCache.MethodLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(ENTITY_CLASS)
.withMethodName("setCustomName")
.withParameterTypes(String.class));
public static final TypeCache.BaseCache<Method> SET_CUSTOM_NAME_NEW_METHOD = new TypeCache.BaseCache.MethodLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(ENTITY_CLASS)
.withMethodName("setCustomName")
.withMethodName("a")
.withMethodName("b")
.withParameterTypes(I_CHAT_BASE_COMPONENT).withExpectResult(void.class));
public static final TypeCache.BaseCache<Method> SET_CUSTOM_NAME_VISIBLE_METHOD = new TypeCache.BaseCache.MethodLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(ENTITY_CLASS)
.withMethodName("setCustomNameVisible")
.withMethodName("n")
.withParameterTypes(boolean.class));
public static final TypeCache.BaseCache<Method> SET_INVISIBLE_METHOD = new TypeCache.BaseCache.MethodLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(ENTITY_ARMOR_STAND_CLASS)
.withMethodName("setInvisible").withMethodName("j")
.withParameterTypes(boolean.class));
public static final TypeCache.BaseCache<Method> SET_LOCATION_METHOD = new TypeCache.BaseCache.MethodLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(ENTITY_CLASS)
.withMethodName("setPositionRotation")
.withMethodName("a")
.withParameterTypes(double.class, double.class, double.class, float.class, float.class));
public static final TypeCache.BaseCache<Method> SET_DATA_WATCHER_METHOD = new TypeCache.BaseCache.MethodLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(DATA_WATCHER_CLASS)
.withMethodName("set").withMethodName("b")
.withParameterTypes(DATA_WATCHER_OBJECT, Object.class));
public static final TypeCache.BaseCache<Method> WATCH_DATA_WATCHER_METHOD = new TypeCache.BaseCache.MethodLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(DATA_WATCHER_CLASS)
.withMethodName("watch")
.withParameterTypes(int.class, Object.class));
public static final TypeCache.BaseCache<Method> GET_DATA_WATCHER_METHOD = new TypeCache.BaseCache.MethodLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(ENTITY_CLASS)
.withMethodName("getDataWatcher")
.withMethodName("ai")
.withMethodName("al")
.withMethodName("aj")
.withExpectResult(DATA_WATCHER_CLASS));
public static final TypeCache.BaseCache<Method> GET_BUKKIT_ENTITY_METHOD = new TypeCache.BaseCache.MethodLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(ENTITY_CLASS)
.withMethodName("getBukkitEntity"));
public static final TypeCache.BaseCache<Method> GET_ENUM_CHAT_ID_METHOD = new TypeCache.BaseCache.MethodLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(ENUM_CHAT_CLASS)
.withMethodName("b"));
public static final TypeCache.BaseCache<Method> ENUM_CHAT_TO_STRING_METHOD = new TypeCache.BaseCache.MethodLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(ENUM_CHAT_CLASS)
.withExpectResult(String.class)
.withMethodName("toString"));
public static final TypeCache.BaseCache<Method> ENTITY_TYPES_A_METHOD = new TypeCache.BaseCache.MethodLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.ENTITY)
.withClassName(ENTITY_TYPES_CLASS)
.withMethodName("a")
.withParameterTypes(String.class));
public static final TypeCache.BaseCache<Method> PACKET_PLAY_OUT_SCOREBOARD_TEAM_CREATE_V1 = new TypeCache.BaseCache.MethodLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(PACKET_PLAY_OUT_SCOREBOARD_TEAM_CLASS)
.withMethodName("a")
.withParameterTypes(SCOREBOARD_TEAM_CLASS));
public static final TypeCache.BaseCache<Method> PACKET_PLAY_OUT_SCOREBOARD_TEAM_CREATE = new TypeCache.BaseCache.MethodLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(PACKET_PLAY_OUT_SCOREBOARD_TEAM_CLASS)
.withMethodName("a")
.withParameterTypes(SCOREBOARD_TEAM_CLASS, boolean.class));
public static final TypeCache.BaseCache<Method> SCOREBOARD_PLAYER_LIST = new TypeCache.BaseCache.MethodLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(SCOREBOARD_TEAM_CLASS)
.withMethodName("getPlayerNameSet").withMethodName("g"));
public static final TypeCache.BaseCache<Method> ENUM_CHAT_FORMAT_FIND = new TypeCache.BaseCache.MethodLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withClassName(ENUM_CHAT_CLASS)
.withParameterTypes(String.class).withExpectResult(ENUM_CHAT_CLASS));
public static final TypeCache.BaseCache<Method> CRAFT_CHAT_MESSAGE_METHOD = new TypeCache.BaseCache.MethodLoader((new TypeCache.CacheBuilder(CachePackage.CRAFT_BUKKIT))
.withClassName(CRAFT_CHAT_MESSAGE_CLASS)
.withMethodName("fromStringOrNull")
.withParameterTypes(String.class));
public static final TypeCache.BaseCache<Method> GET_UNIQUE_ID_METHOD = new TypeCache.BaseCache.MethodLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withClassName(ENTITY_CLASS)
.withExpectResult(UUID.class));
public static final TypeCache.BaseCache<Method> GET_DATAWATCHER_B_LIST = new TypeCache.BaseCache.MethodLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withMethodName("c")
.withClassName(DATA_WATCHER_CLASS));
public static final TypeCache.BaseCache<Field> PLAYER_CONNECTION_FIELD = new TypeCache.BaseCache.FieldLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.SERVER_LEVEL)
.withClassName(ENTITY_PLAYER_CLASS)
.withFieldName((Utils.BUKKIT_VERSION > 16) ? "b" : "playerConnection"));
public static final TypeCache.BaseCache<Field> NETWORK_MANAGER_FIELD = new TypeCache.BaseCache.FieldLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(PLAYER_CONNECTION_CLASS)
.withFieldName((Utils.BUKKIT_VERSION > 16) ? "a" : "networkManager")
.withExpectResult(NETWORK_MANAGER_CLASS));
public static final TypeCache.BaseCache<Field> CHANNEL_FIELD = new TypeCache.BaseCache.FieldLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.SERVER_NETWORK)
.withClassName(NETWORK_MANAGER_CLASS)
.withExpectResult(Channel.class));
public static final TypeCache.BaseCache<Field> PACKET_IN_USE_ENTITY_ID_FIELD = new TypeCache.BaseCache.FieldLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName("PacketPlayInUseEntity")
.withFieldName("a"));
public static final TypeCache.BaseCache<Field> BUKKIT_COMMAND_MAP = new TypeCache.BaseCache.FieldLoader((new TypeCache.CacheBuilder(CachePackage.CRAFT_BUKKIT))
.withClassName("CraftServer")
.withFieldName("commandMap"));
public static final TypeCache.BaseCache<Object> ADD_PLAYER_FIELD = (new TypeCache.BaseCache.FieldLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName("PacketPlayOutPlayerInfo$EnumPlayerInfoAction")
.withClassName("ClientboundPlayerInfoUpdatePacket$a")
.withFieldName((Utils.BUKKIT_VERSION > 16) ? "a" : "ADD_PLAYER"))).asValueField();
public static final TypeCache.BaseCache<Object> UPDATE_LISTED_FIELD = (new TypeCache.BaseCache.FieldLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName("ClientboundPlayerInfoUpdatePacket$a")
.withFieldName("d"))).asValueField();
public static final TypeCache.BaseCache<Object> REMOVE_PLAYER_FIELD = (new TypeCache.BaseCache.FieldLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName("PacketPlayOutPlayerInfo$EnumPlayerInfoAction")
.withClassName("ClientboundPlayerInfoUpdatePacket$a")
.withFieldName((Utils.BUKKIT_VERSION > 16) ? "e" : "REMOVE_PLAYER"))).asValueField();
public static final TypeCache.BaseCache<Object> DATA_WATCHER_REGISTER_FIELD = (new TypeCache.BaseCache.FieldLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(DATA_WATCHER_REGISTRY)
.withFieldName("a"))).asValueField();
public static final TypeCache.BaseCache<Object> ENUM_TAG_VISIBILITY_NEVER_FIELD = (new TypeCache.BaseCache.FieldLoader((new TypeCache.CacheBuilder(CachePackage.MINECRAFT_SERVER))
.withCategory(CacheCategory.PACKET)
.withClassName(ENUM_TAG_VISIBILITY)
.withFieldName("b"))).asValueField();
}

@ -1,272 +0,0 @@
package io.github.znetworkw.znpcservers.cache;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import lol.pyr.znpcsplus.ZNPCsPlus;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
public interface TypeCache {
class ClassCache {
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);
}
}
}
class CacheBuilder {
private final CachePackage cachePackage;
private final CacheCategory cacheCategory;
private final String fieldName;
private final List<String> className;
private final List<String> methods;
private final String additionalData;
private final ImmutableList<Class<?>[]> parameterTypes;
private final Class<?> expectType;
public CacheBuilder(CachePackage cachePackage) {
this(cachePackage, CacheCategory.DEFAULT, new ArrayList<>(), "", new ArrayList<>(), "", ImmutableList.of(), null);
}
protected CacheBuilder(CachePackage cachePackage, CacheCategory cacheCategory, List<String> className, String fieldName, List<String> methods, String additionalData, ImmutableList<Class<?>[]> parameterTypes, Class<?> expectType) {
this.cachePackage = cachePackage;
this.cacheCategory = cacheCategory;
this.className = className;
this.methods = methods;
this.fieldName = fieldName;
this.additionalData = additionalData;
this.parameterTypes = parameterTypes;
this.expectType = expectType;
}
public CacheBuilder withCategory(CacheCategory cacheCategory) {
return new CacheBuilder(this.cachePackage, cacheCategory, this.className, this.fieldName, this.methods, this.additionalData, this.parameterTypes, this.expectType);
}
public CacheBuilder withClassName(String className) {
return new CacheBuilder(this.cachePackage, this.cacheCategory, new ImmutableList.Builder<String>().addAll(this.className).add(formatClass(className)).build(), this.fieldName, this.methods, this.additionalData, this.parameterTypes, this.expectType);
}
public CacheBuilder withClassName(Class<?> clazz) {
return new CacheBuilder(this.cachePackage, this.cacheCategory, new ImmutableList.Builder<String>().addAll(this.className).add((clazz == null) ? "" : clazz.getName()).build(), this.fieldName, this.methods, this.additionalData, this.parameterTypes, this.expectType);
}
public CacheBuilder withMethodName(String methodName) {
return new CacheBuilder(this.cachePackage, this.cacheCategory, this.className, this.fieldName, new ImmutableList.Builder<String>().addAll(this.methods).add(methodName).build(), this.additionalData, this.parameterTypes, this.expectType);
}
public CacheBuilder withFieldName(String fieldName) {
return new CacheBuilder(this.cachePackage, this.cacheCategory, this.className, fieldName, this.methods, this.additionalData, this.parameterTypes, this.expectType);
}
public CacheBuilder withAdditionalData(String additionalData) {
return new CacheBuilder(this.cachePackage, this.cacheCategory, this.className, this.fieldName, this.methods, additionalData, this.parameterTypes, this.expectType);
}
public CacheBuilder withParameterTypes(Class<?>... types) {
return new CacheBuilder(this.cachePackage, this.cacheCategory, this.className, this.fieldName, this.methods, this.additionalData, ImmutableList.copyOf(Iterables.concat(this.parameterTypes, ImmutableList.of(types))), this.expectType);
}
public CacheBuilder withExpectResult(Class<?> expectType) {
return new CacheBuilder(this.cachePackage, this.cacheCategory, this.className, this.fieldName, this.methods, this.additionalData, this.parameterTypes, expectType);
}
protected String formatClass(String className) {
return switch (this.cachePackage) {
case MINECRAFT_SERVER, CRAFT_BUKKIT -> String.format(((this.cachePackage == CachePackage.CRAFT_BUKKIT) ? this.cachePackage.getFixedPackageName() : this.cachePackage.getForCategory(this.cacheCategory, this.additionalData)) + ".%s", className);
case DEFAULT -> className;
};
}
}
abstract class BaseCache<T> {
protected final TypeCache.CacheBuilder cacheBuilder;
protected Class<?> BUILDER_CLASS;
private T cached;
private boolean loaded = false;
protected BaseCache(TypeCache.CacheBuilder cacheBuilder) {
this.cacheBuilder = cacheBuilder;
for (String classes : cacheBuilder.className) {
try {
this.BUILDER_CLASS = Class.forName(classes);
} catch (ClassNotFoundException ignored) {
}
}
}
public T load() {
return load(false);
}
public T load(boolean missAllowed) {
if (this.loaded) return this.cached;
try {
if (this.BUILDER_CLASS == null) throw new ClassNotFoundException("No class found: " + this.cacheBuilder.className.toString());
T eval = (this.cached != null) ? this.cached : (this.cached = onLoad());
if (eval == null) throw new NullPointerException();
} catch (Throwable throwable) {
if (!missAllowed) {
log("Cache load failed!");
log("Class Names: " + this.cacheBuilder.className.toString());
log("Loader Type: " + getClass().getCanonicalName());
log("Exception:");
throwable.printStackTrace();
}
}
this.loaded = true;
return this.cached;
}
private void log(String message) {
ZNPCsPlus.LOGGER.warning("[BaseCache] " + message);
}
protected abstract T onLoad() throws Exception;
public static class ClazzLoader extends BaseCache<Class<?>> {
public ClazzLoader(TypeCache.CacheBuilder cacheBuilder) {
super(cacheBuilder);
}
protected Class<?> onLoad() {
return this.BUILDER_CLASS;
}
}
public static class MethodLoader extends BaseCache<Method> {
public MethodLoader(TypeCache.CacheBuilder builder) {
super(builder);
}
protected Method onLoad() {
Method methodThis = null;
List<String> methods = this.cacheBuilder.methods;
boolean hasExpectedType = (this.cacheBuilder.expectType != null);
if (methods.isEmpty() && hasExpectedType) for (Method method : this.BUILDER_CLASS.getDeclaredMethods()) {
if (method.getReturnType() == this.cacheBuilder.expectType) return method;
}
for (String methodName : this.cacheBuilder.methods) try {
Method maybeGet;
if (!Iterables.isEmpty(this.cacheBuilder.parameterTypes))
maybeGet = this.BUILDER_CLASS.getDeclaredMethod(methodName, Iterables.get(this.cacheBuilder.parameterTypes, 0));
else maybeGet = this.BUILDER_CLASS.getDeclaredMethod(methodName);
if (this.cacheBuilder.expectType != null && this.cacheBuilder.expectType != maybeGet.getReturnType()) continue;
maybeGet.setAccessible(true);
methodThis = maybeGet;
} catch (NoSuchMethodException ignored) {}
return methodThis;
}
}
public static class FieldLoader extends BaseCache<Field> {
public FieldLoader(TypeCache.CacheBuilder cacheBuilder) {
super(cacheBuilder);
}
protected Field onLoad() throws NoSuchFieldException {
if (this.cacheBuilder.expectType != null)
for (Field field1 : this.BUILDER_CLASS.getDeclaredFields()) {
if (field1.getType() == this.cacheBuilder.expectType) {
field1.setAccessible(true);
return field1;
}
}
Field field = this.BUILDER_CLASS.getDeclaredField(this.cacheBuilder.fieldName);
field.setAccessible(true);
return field;
}
public AsValueField asValueField() {
return new AsValueField(this);
}
private static class AsValueField extends TypeCache.BaseCache<Object> {
private final TypeCache.BaseCache.FieldLoader fieldLoader;
public AsValueField(TypeCache.BaseCache.FieldLoader fieldLoader) {
super(fieldLoader.cacheBuilder);
this.fieldLoader = fieldLoader;
}
protected Object onLoad() throws IllegalAccessException, NoSuchFieldException {
Field field = this.fieldLoader.onLoad();
return field.get(null);
}
}
}
public static class ConstructorLoader extends BaseCache<Constructor<?>> {
public ConstructorLoader(TypeCache.CacheBuilder cacheBuilder) {
super(cacheBuilder);
}
protected Constructor<?> onLoad() throws NoSuchMethodException {
Constructor<?> constructor = null;
if (Iterables.size(this.cacheBuilder.parameterTypes) > 1) {
for (Class<?>[] keyParameters : this.cacheBuilder.parameterTypes) try {
constructor = this.BUILDER_CLASS.getDeclaredConstructor(keyParameters);
} catch (NoSuchMethodException ignored) {}
} else constructor = (Iterables.size(this.cacheBuilder.parameterTypes) > 0) ? this.BUILDER_CLASS.getDeclaredConstructor(Iterables.get(this.cacheBuilder.parameterTypes, 0)) : this.BUILDER_CLASS.getDeclaredConstructor();
if (constructor != null) constructor.setAccessible(true);
return constructor;
}
}
public static class EnumLoader extends BaseCache<Enum<?>[]> {
public EnumLoader(TypeCache.CacheBuilder cacheBuilder) {
super(cacheBuilder);
}
protected Enum<?>[] onLoad() {
Enum<?>[] arrayOfEnum = (Enum<?>[]) this.BUILDER_CLASS.getEnumConstants();
for (Enum<?> enumConstant : arrayOfEnum) TypeCache.ClassCache.register(enumConstant.name(), enumConstant, this.BUILDER_CLASS);
return arrayOfEnum;
}
}
}
}

@ -1,7 +1,7 @@
package io.github.znetworkw.znpcservers.commands; package io.github.znetworkw.znpcservers.commands;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import io.github.znetworkw.znpcservers.cache.CacheRegistry; import io.github.znetworkw.znpcservers.reflection.ReflectionCache;
import io.github.znetworkw.znpcservers.commands.exception.CommandException; import io.github.znetworkw.znpcservers.commands.exception.CommandException;
import io.github.znetworkw.znpcservers.commands.exception.CommandExecuteException; import io.github.znetworkw.znpcservers.commands.exception.CommandExecuteException;
import io.github.znetworkw.znpcservers.commands.exception.CommandPermissionException; import io.github.znetworkw.znpcservers.commands.exception.CommandPermissionException;
@ -20,7 +20,7 @@ public class Command extends BukkitCommand {
static { static {
try { try {
COMMAND_MAP = (CommandMap) CacheRegistry.BUKKIT_COMMAND_MAP.load().get(Bukkit.getServer()); COMMAND_MAP = (CommandMap) ReflectionCache.BUKKIT_COMMAND_MAP.load().get(Bukkit.getServer());
} catch (IllegalAccessException exception) { } catch (IllegalAccessException exception) {
throw new IllegalStateException("Unable to register Bukkit command map."); throw new IllegalStateException("Unable to register Bukkit command map.");
} }

@ -1,8 +1,8 @@
package io.github.znetworkw.znpcservers.npc; package io.github.znetworkw.znpcservers.npc;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import io.github.znetworkw.znpcservers.cache.CachePackage; import io.github.znetworkw.znpcservers.reflection.ReflectionBasePackage;
import io.github.znetworkw.znpcservers.cache.TypeCache; import io.github.znetworkw.znpcservers.reflection.TypeCache;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
@ -32,7 +32,7 @@ public class CustomizationLoader {
for (Class<?> parameter : method.getParameterTypes()) { for (Class<?> parameter : method.getParameterTypes()) {
TypeProperty typeProperty = TypeProperty.forType(parameter); TypeProperty typeProperty = TypeProperty.forType(parameter);
if (typeProperty == null && parameter.isEnum()) if (typeProperty == null && parameter.isEnum())
(new TypeCache.BaseCache.EnumLoader((new TypeCache.CacheBuilder(CachePackage.DEFAULT)) (new TypeCache.BaseReflection.EnumReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.DEFAULT))
.withClassName(parameter.getTypeName()))).load(); .withClassName(parameter.getTypeName()))).load();
} }
builder.put(method.getName(), method); builder.put(method.getName(), method);

@ -5,7 +5,7 @@ import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.Property;
import com.mojang.authlib.properties.PropertyMap; import com.mojang.authlib.properties.PropertyMap;
import io.github.znetworkw.znpcservers.UnexpectedCallException; import io.github.znetworkw.znpcservers.UnexpectedCallException;
import io.github.znetworkw.znpcservers.cache.CacheRegistry; import io.github.znetworkw.znpcservers.reflection.ReflectionCache;
import io.github.znetworkw.znpcservers.npc.conversation.ConversationModel; import io.github.znetworkw.znpcservers.npc.conversation.ConversationModel;
import io.github.znetworkw.znpcservers.npc.hologram.Hologram; import io.github.znetworkw.znpcservers.npc.hologram.Hologram;
import io.github.znetworkw.znpcservers.npc.packet.PacketCache; import io.github.znetworkw.znpcservers.npc.packet.PacketCache;
@ -137,8 +137,8 @@ public class NPC {
if (updateTime) this.lastMove = System.nanoTime(); if (updateTime) this.lastMove = System.nanoTime();
this.npcPojo.setLocation(new ZLocation(location = new Location(location.getWorld(), location.getBlockX() + 0.5D, location.getY(), location.getBlockZ() + 0.5D, location.getYaw(), location.getPitch()))); this.npcPojo.setLocation(new ZLocation(location = new Location(location.getWorld(), location.getBlockX() + 0.5D, location.getY(), location.getBlockZ() + 0.5D, location.getYaw(), location.getPitch())));
} }
CacheRegistry.SET_LOCATION_METHOD.load().invoke(this.nmsEntity, location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); ReflectionCache.SET_LOCATION_METHOD.load().invoke(this.nmsEntity, location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
Object npcTeleportPacket = CacheRegistry.PACKET_PLAY_OUT_ENTITY_TELEPORT_CONSTRUCTOR.load().newInstance(this.nmsEntity); Object npcTeleportPacket = ReflectionCache.PACKET_PLAY_OUT_ENTITY_TELEPORT_CONSTRUCTOR.load().newInstance(this.nmsEntity);
this.viewers.forEach(player -> Utils.sendPackets(player, npcTeleportPacket)); this.viewers.forEach(player -> Utils.sendPackets(player, npcTeleportPacket));
this.hologram.setLocation(location, this.npcPojo.getNpcType().getHoloHeight()); this.hologram.setLocation(location, this.npcPojo.getNpcType().getHoloHeight());
} catch (ReflectiveOperationException operationException) { } catch (ReflectiveOperationException operationException) {
@ -157,13 +157,13 @@ public class NPC {
public void setSecondLayerSkin() { public void setSecondLayerSkin() {
try { try {
Object dataWatcherObject = CacheRegistry.GET_DATA_WATCHER_METHOD.load().invoke(this.nmsEntity); Object dataWatcherObject = ReflectionCache.GET_DATA_WATCHER_METHOD.load().invoke(this.nmsEntity);
if (Utils.versionNewer(9)) { if (Utils.versionNewer(9)) {
CacheRegistry.SET_DATA_WATCHER_METHOD.load().invoke(dataWatcherObject, ReflectionCache.SET_DATA_WATCHER_METHOD.load().invoke(dataWatcherObject,
CacheRegistry.DATA_WATCHER_OBJECT_CONSTRUCTOR.load() ReflectionCache.DATA_WATCHER_OBJECT_CONSTRUCTOR.load()
.newInstance(this.npcSkin.getLayerIndex(), CacheRegistry.DATA_WATCHER_REGISTER_FIELD.load()), (byte) 127); .newInstance(this.npcSkin.getLayerIndex(), ReflectionCache.DATA_WATCHER_REGISTER_FIELD.load()), (byte) 127);
} else { } else {
CacheRegistry.WATCH_DATA_WATCHER_METHOD.load().invoke(dataWatcherObject, 10, (byte) 127); ReflectionCache.WATCH_DATA_WATCHER_METHOD.load().invoke(dataWatcherObject, 10, (byte) 127);
} }
} catch (ReflectiveOperationException operationException) { } catch (ReflectiveOperationException operationException) {
throw new UnexpectedCallException(operationException); throw new UnexpectedCallException(operationException);
@ -173,24 +173,24 @@ public class NPC {
public synchronized void changeType(NPCType npcType) { public synchronized void changeType(NPCType npcType) {
deleteViewers(); deleteViewers();
try { try {
Object nmsWorld = CacheRegistry.GET_HANDLE_WORLD_METHOD.load().invoke(getLocation().getWorld()); Object nmsWorld = ReflectionCache.GET_HANDLE_WORLD_METHOD.load().invoke(getLocation().getWorld());
boolean isPlayer = (npcType == NPCType.PLAYER); boolean isPlayer = (npcType == NPCType.PLAYER);
this.nmsEntity = isPlayer ? this.packets.getProxyInstance().getPlayerPacket(nmsWorld, this.gameProfile) : (Utils.versionNewer(14) ? npcType.getConstructor().newInstance(npcType.getNmsEntityType(), nmsWorld) : npcType.getConstructor().newInstance(nmsWorld)); this.nmsEntity = isPlayer ? this.packets.getProxyInstance().getPlayerPacket(nmsWorld, this.gameProfile) : (Utils.versionNewer(14) ? npcType.getConstructor().newInstance(npcType.getNmsEntityType(), nmsWorld) : npcType.getConstructor().newInstance(nmsWorld));
this.bukkitEntity = CacheRegistry.GET_BUKKIT_ENTITY_METHOD.load().invoke(this.nmsEntity); this.bukkitEntity = ReflectionCache.GET_BUKKIT_ENTITY_METHOD.load().invoke(this.nmsEntity);
this.uuid = (UUID) CacheRegistry.GET_UNIQUE_ID_METHOD.load().invoke(this.nmsEntity, new Object[0]); this.uuid = (UUID) ReflectionCache.GET_UNIQUE_ID_METHOD.load().invoke(this.nmsEntity, new Object[0]);
if (isPlayer) { if (isPlayer) {
try { try {
this.tabConstructor = CacheRegistry.PACKET_PLAY_OUT_PLAYER_INFO_CONSTRUCTOR.load().newInstance(CacheRegistry.ADD_PLAYER_FIELD.load(), Collections.singletonList(this.nmsEntity)); this.tabConstructor = ReflectionCache.PACKET_PLAY_OUT_PLAYER_INFO_CONSTRUCTOR.load().newInstance(ReflectionCache.ADD_PLAYER_FIELD.load(), Collections.singletonList(this.nmsEntity));
} catch (Throwable e) { } catch (Throwable e) {
this.tabConstructor = CacheRegistry.PACKET_PLAY_OUT_PLAYER_INFO_CONSTRUCTOR.load().newInstance(CacheRegistry.ADD_PLAYER_FIELD.load(), this.nmsEntity); this.tabConstructor = ReflectionCache.PACKET_PLAY_OUT_PLAYER_INFO_CONSTRUCTOR.load().newInstance(ReflectionCache.ADD_PLAYER_FIELD.load(), this.nmsEntity);
this.updateTabConstructor = CacheRegistry.PACKET_PLAY_OUT_PLAYER_INFO_CONSTRUCTOR.load().newInstance(CacheRegistry.UPDATE_LISTED_FIELD.load(), this.nmsEntity); this.updateTabConstructor = ReflectionCache.PACKET_PLAY_OUT_PLAYER_INFO_CONSTRUCTOR.load().newInstance(ReflectionCache.UPDATE_LISTED_FIELD.load(), this.nmsEntity);
} }
setSecondLayerSkin(); setSecondLayerSkin();
} }
this.npcPojo.setNpcType(npcType); this.npcPojo.setNpcType(npcType);
setLocation(getLocation(), false); setLocation(getLocation(), false);
this.packets.flushCache("spawnPacket", "removeTab"); this.packets.flushCache("spawnPacket", "removeTab");
this.entityID = (Integer) CacheRegistry.GET_ENTITY_ID.load().invoke(this.nmsEntity, new Object[0]); this.entityID = (Integer) ReflectionCache.GET_ENTITY_ID.load().invoke(this.nmsEntity, new Object[0]);
FunctionFactory.findFunctionsForNpc(this).forEach(function -> function.resolve(this)); FunctionFactory.findFunctionsForNpc(this).forEach(function -> function.resolve(this));
getPackets().getProxyInstance().update(this.packets); getPackets().getProxyInstance().update(this.packets);
this.hologram.createHologram(); this.hologram.createHologram();
@ -248,8 +248,8 @@ public class NPC {
if (this.lastMove > 1L && lastMoveNanos < 1000000000L) return; if (this.lastMove > 1L && lastMoveNanos < 1000000000L) return;
Location direction = rotation ? location : this.npcPojo.getLocation().bukkitLocation().clone().setDirection(location.clone().subtract(this.npcPojo.getLocation().bukkitLocation().clone()).toVector()); Location direction = rotation ? location : this.npcPojo.getLocation().bukkitLocation().clone().setDirection(location.clone().subtract(this.npcPojo.getLocation().bukkitLocation().clone()).toVector());
try { try {
Object lookPacket = CacheRegistry.PACKET_PLAY_OUT_ENTITY_LOOK_CONSTRUCTOR.load().newInstance(this.entityID, (byte) (int) (direction.getYaw() * 256.0F / 360.0F), (byte) (int) (direction.getPitch() * 256.0F / 360.0F), true); Object lookPacket = ReflectionCache.PACKET_PLAY_OUT_ENTITY_LOOK_CONSTRUCTOR.load().newInstance(this.entityID, (byte) (int) (direction.getYaw() * 256.0F / 360.0F), (byte) (int) (direction.getPitch() * 256.0F / 360.0F), true);
Object headRotationPacket = CacheRegistry.PACKET_PLAY_OUT_ENTITY_HEAD_ROTATION_CONSTRUCTOR.load().newInstance(this.nmsEntity, (byte) (int) (direction.getYaw() * 256.0F / 360.0F)); Object headRotationPacket = ReflectionCache.PACKET_PLAY_OUT_ENTITY_HEAD_ROTATION_CONSTRUCTOR.load().newInstance(this.nmsEntity, (byte) (int) (direction.getYaw() * 256.0F / 360.0F));
if (player != null) Utils.sendPackets(player, lookPacket, headRotationPacket); if (player != null) Utils.sendPackets(player, lookPacket, headRotationPacket);
else this.viewers.forEach(players -> Utils.sendPackets(players, headRotationPacket)); else this.viewers.forEach(players -> Utils.sendPackets(players, headRotationPacket));
} catch (ReflectiveOperationException operationException) { } catch (ReflectiveOperationException operationException) {
@ -275,7 +275,7 @@ public class NPC {
public void updateProfile(PropertyMap propertyMap) { public void updateProfile(PropertyMap propertyMap) {
if (this.npcPojo.getNpcType() != NPCType.PLAYER) return; if (this.npcPojo.getNpcType() != NPCType.PLAYER) return;
try { try {
Object gameProfileObj = CacheRegistry.GET_PROFILE_METHOD.load().invoke(this.nmsEntity); Object gameProfileObj = ReflectionCache.GET_PROFILE_METHOD.load().invoke(this.nmsEntity);
Utils.setValue(gameProfileObj, "name", this.gameProfile.getName()); Utils.setValue(gameProfileObj, "name", this.gameProfile.getName());
Utils.setValue(gameProfileObj, "id", this.gameProfile.getId()); Utils.setValue(gameProfileObj, "id", this.gameProfile.getId());
Utils.setValue(gameProfileObj, "properties", propertyMap); Utils.setValue(gameProfileObj, "properties", propertyMap);

@ -1,7 +1,7 @@
package io.github.znetworkw.znpcservers.npc; package io.github.znetworkw.znpcservers.npc;
import io.github.znetworkw.znpcservers.UnexpectedCallException; import io.github.znetworkw.znpcservers.UnexpectedCallException;
import io.github.znetworkw.znpcservers.cache.TypeCache; import io.github.znetworkw.znpcservers.reflection.TypeCache;
import io.github.znetworkw.znpcservers.utility.Utils; import io.github.znetworkw.znpcservers.utility.Utils;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
@ -11,7 +11,7 @@ import java.lang.reflect.Method;
import java.util.Arrays; import java.util.Arrays;
import java.util.Optional; import java.util.Optional;
import static io.github.znetworkw.znpcservers.cache.CacheRegistry.*; import static io.github.znetworkw.znpcservers.reflection.ReflectionCache.*;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public enum NPCType { public enum NPCType {

@ -1,6 +1,6 @@
package io.github.znetworkw.znpcservers.npc.function; package io.github.znetworkw.znpcservers.npc.function;
import io.github.znetworkw.znpcservers.cache.CacheRegistry; import io.github.znetworkw.znpcservers.reflection.ReflectionCache;
import io.github.znetworkw.znpcservers.npc.FunctionContext; import io.github.znetworkw.znpcservers.npc.FunctionContext;
import io.github.znetworkw.znpcservers.npc.FunctionFactory; import io.github.znetworkw.znpcservers.npc.FunctionFactory;
import io.github.znetworkw.znpcservers.npc.NPC; import io.github.znetworkw.znpcservers.npc.NPC;
@ -16,15 +16,15 @@ public class GlowFunction extends NPCFunction {
throw new IllegalStateException("invalid context type, " + functionContext.getClass().getSimpleName() + ", expected ContextWithValue."); throw new IllegalStateException("invalid context type, " + functionContext.getClass().getSimpleName() + ", expected ContextWithValue.");
String glowColorName = ((FunctionContext.ContextWithValue) functionContext).getValue(); String glowColorName = ((FunctionContext.ContextWithValue) functionContext).getValue();
try { try {
Object glowColor = CacheRegistry.ENUM_CHAT_FORMAT_FIND.load().invoke(null, ( Object glowColor = ReflectionCache.ENUM_CHAT_FORMAT_FIND.load().invoke(null, (
glowColorName == null || glowColorName.length() == 0) ? "WHITE" : glowColorName); glowColorName == null || glowColorName.length() == 0) ? "WHITE" : glowColorName);
if (glowColor == null) if (glowColor == null)
return NPCFunction.ResultType.FAIL; return NPCFunction.ResultType.FAIL;
npc.getNpcPojo().setGlowName(glowColorName); npc.getNpcPojo().setGlowName(glowColorName);
npc.setGlowColor(glowColor); npc.setGlowColor(glowColor);
CacheRegistry.SET_DATA_WATCHER_METHOD.load().invoke(CacheRegistry.GET_DATA_WATCHER_METHOD ReflectionCache.SET_DATA_WATCHER_METHOD.load().invoke(ReflectionCache.GET_DATA_WATCHER_METHOD
.load().invoke(npc.getNmsEntity()), CacheRegistry.DATA_WATCHER_OBJECT_CONSTRUCTOR .load().invoke(npc.getNmsEntity()), ReflectionCache.DATA_WATCHER_OBJECT_CONSTRUCTOR
.load().newInstance(0, CacheRegistry.DATA_WATCHER_REGISTER_FIELD .load().newInstance(0, ReflectionCache.DATA_WATCHER_REGISTER_FIELD
.load()), (byte) (!FunctionFactory.isTrue(npc, this) ? 64 : 0)); .load()), (byte) (!FunctionFactory.isTrue(npc, this) ? 64 : 0));
npc.getPackets().getProxyInstance().update(npc.getPackets()); npc.getPackets().getProxyInstance().update(npc.getPackets());
npc.deleteViewers(); npc.deleteViewers();

@ -1,7 +1,7 @@
package io.github.znetworkw.znpcservers.npc.hologram; package io.github.znetworkw.znpcservers.npc.hologram;
import io.github.znetworkw.znpcservers.UnexpectedCallException; import io.github.znetworkw.znpcservers.UnexpectedCallException;
import io.github.znetworkw.znpcservers.cache.CacheRegistry; import io.github.znetworkw.znpcservers.reflection.ReflectionCache;
import io.github.znetworkw.znpcservers.configuration.Configuration; import io.github.znetworkw.znpcservers.configuration.Configuration;
import io.github.znetworkw.znpcservers.configuration.ConfigurationConstants; import io.github.znetworkw.znpcservers.configuration.ConfigurationConstants;
import io.github.znetworkw.znpcservers.configuration.ConfigurationValue; import io.github.znetworkw.znpcservers.configuration.ConfigurationValue;
@ -37,14 +37,14 @@ public class Hologram {
Location location = this.npc.getLocation(); Location location = this.npc.getLocation();
for (String line : this.npc.getNpcPojo().getHologramLines()) { for (String line : this.npc.getNpcPojo().getHologramLines()) {
boolean visible = !line.equalsIgnoreCase("%space%"); boolean visible = !line.equalsIgnoreCase("%space%");
Object armorStand = CacheRegistry.ENTITY_CONSTRUCTOR.load().newInstance(CacheRegistry.GET_HANDLE_WORLD_METHOD.load().invoke(location.getWorld()), Object armorStand = ReflectionCache.ENTITY_CONSTRUCTOR.load().newInstance(ReflectionCache.GET_HANDLE_WORLD_METHOD.load().invoke(location.getWorld()),
location.getX(), location.getY() - 0.15D + y, location.getZ()); location.getX(), location.getY() - 0.15D + y, location.getZ());
if (visible) { if (visible) {
CacheRegistry.SET_CUSTOM_NAME_VISIBLE_METHOD.load().invoke(armorStand, true); ReflectionCache.SET_CUSTOM_NAME_VISIBLE_METHOD.load().invoke(armorStand, true);
updateLine(line, armorStand, null); updateLine(line, armorStand, null);
} }
CacheRegistry.SET_INVISIBLE_METHOD.load().invoke(armorStand, true); ReflectionCache.SET_INVISIBLE_METHOD.load().invoke(armorStand, true);
this.hologramLines.add(new HologramLine(line.replace(ConfigurationConstants.SPACE_SYMBOL, " "), armorStand, (Integer) CacheRegistry.GET_ENTITY_ID this.hologramLines.add(new HologramLine(line.replace(ConfigurationConstants.SPACE_SYMBOL, " "), armorStand, (Integer) ReflectionCache.GET_ENTITY_ID
.load().invoke(armorStand))); .load().invoke(armorStand)));
y += LINE_SPACING; y += LINE_SPACING;
} }
@ -92,7 +92,7 @@ public class Hologram {
public void updateLocation() { public void updateLocation() {
this.hologramLines.forEach(hologramLine -> { this.hologramLines.forEach(hologramLine -> {
try { try {
Object packet = CacheRegistry.PACKET_PLAY_OUT_ENTITY_TELEPORT_CONSTRUCTOR.load().newInstance(hologramLine.armorStand); Object packet = ReflectionCache.PACKET_PLAY_OUT_ENTITY_TELEPORT_CONSTRUCTOR.load().newInstance(hologramLine.armorStand);
this.npc.getViewers().forEach(player -> Utils.sendPackets(player, packet)); this.npc.getViewers().forEach(player -> Utils.sendPackets(player, packet));
} }
catch (ReflectiveOperationException operationException) { catch (ReflectiveOperationException operationException) {
@ -106,7 +106,7 @@ public class Hologram {
try { try {
double y = this.npc.getNpcPojo().getHologramHeight(); double y = this.npc.getNpcPojo().getHologramHeight();
for (HologramLine hologramLine : this.hologramLines) { for (HologramLine hologramLine : this.hologramLines) {
CacheRegistry.SET_LOCATION_METHOD.load().invoke(hologramLine.armorStand, location.getX(), location.getY() - 0.15 + y, location.getZ(), location.getYaw(), location.getPitch()); ReflectionCache.SET_LOCATION_METHOD.load().invoke(hologramLine.armorStand, location.getX(), location.getY() - 0.15 + y, location.getZ(), location.getYaw(), location.getPitch());
y += LINE_SPACING; y += LINE_SPACING;
} }
this.updateLocation(); this.updateLocation();
@ -118,9 +118,9 @@ public class Hologram {
private void updateLine(String line, Object armorStand, @Nullable ZUser user) throws InvocationTargetException, IllegalAccessException { private void updateLine(String line, Object armorStand, @Nullable ZUser user) throws InvocationTargetException, IllegalAccessException {
if (NEW_METHOD) { if (NEW_METHOD) {
CacheRegistry.SET_CUSTOM_NAME_NEW_METHOD.load().invoke(armorStand, CacheRegistry.CRAFT_CHAT_MESSAGE_METHOD.load().invoke(null, LineReplacer.makeAll(user, line))); ReflectionCache.SET_CUSTOM_NAME_NEW_METHOD.load().invoke(armorStand, ReflectionCache.CRAFT_CHAT_MESSAGE_METHOD.load().invoke(null, LineReplacer.makeAll(user, line)));
} else { } else {
CacheRegistry.SET_CUSTOM_NAME_OLD_METHOD.load().invoke(armorStand, LineReplacer.makeAll(user, line)); ReflectionCache.SET_CUSTOM_NAME_OLD_METHOD.load().invoke(armorStand, LineReplacer.makeAll(user, line));
} }
} }

@ -2,7 +2,7 @@ package io.github.znetworkw.znpcservers.npc.packet;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import io.github.znetworkw.znpcservers.cache.CacheRegistry; import io.github.znetworkw.znpcservers.reflection.ReflectionCache;
import io.github.znetworkw.znpcservers.npc.FunctionFactory; import io.github.znetworkw.znpcservers.npc.FunctionFactory;
import io.github.znetworkw.znpcservers.npc.ItemSlot; import io.github.znetworkw.znpcservers.npc.ItemSlot;
import io.github.znetworkw.znpcservers.npc.NPC; import io.github.znetworkw.znpcservers.npc.NPC;
@ -35,22 +35,22 @@ public interface Packet {
@SuppressWarnings("SuspiciousTernaryOperatorInVarargsCall") @SuppressWarnings("SuspiciousTernaryOperatorInVarargsCall")
@PacketValue(keyName = "destroyPacket", valueType = ValueType.ARGUMENTS) @PacketValue(keyName = "destroyPacket", valueType = ValueType.ARGUMENTS)
default Object getDestroyPacket(int entityId) throws ReflectiveOperationException { default Object getDestroyPacket(int entityId) throws ReflectiveOperationException {
return CacheRegistry.PACKET_PLAY_OUT_ENTITY_DESTROY_CONSTRUCTOR.load().newInstance(CacheRegistry.PACKET_PLAY_OUT_ENTITY_DESTROY_CONSTRUCTOR.load().getParameterTypes()[0].isArray() ? new int[] {entityId} : entityId); return ReflectionCache.PACKET_PLAY_OUT_ENTITY_DESTROY_CONSTRUCTOR.load().newInstance(ReflectionCache.PACKET_PLAY_OUT_ENTITY_DESTROY_CONSTRUCTOR.load().getParameterTypes()[0].isArray() ? new int[] {entityId} : entityId);
} }
@PacketValue(keyName = "enumSlot", valueType = ValueType.ARGUMENTS) @PacketValue(keyName = "enumSlot", valueType = ValueType.ARGUMENTS)
default Object getItemSlot(int slot) { default Object getItemSlot(int slot) {
return CacheRegistry.ENUM_ITEM_SLOT.getEnumConstants()[slot]; return ReflectionCache.ENUM_ITEM_SLOT.getEnumConstants()[slot];
} }
@PacketValue(keyName = "removeTab") @PacketValue(keyName = "removeTab")
default Object getTabRemovePacket(Object nmsEntity) throws ReflectiveOperationException { default Object getTabRemovePacket(Object nmsEntity) throws ReflectiveOperationException {
try { try {
return CacheRegistry.PACKET_PLAY_OUT_PLAYER_INFO_CONSTRUCTOR.load().newInstance(CacheRegistry.REMOVE_PLAYER_FIELD.load(), Collections.singletonList(nmsEntity)); return ReflectionCache.PACKET_PLAY_OUT_PLAYER_INFO_CONSTRUCTOR.load().newInstance(ReflectionCache.REMOVE_PLAYER_FIELD.load(), Collections.singletonList(nmsEntity));
} catch (Throwable throwable) { } catch (Throwable throwable) {
boolean useOldMethod = (CacheRegistry.PACKET_PLAY_OUT_PLAYER_INFO_REMOVE_CLASS != null); boolean useOldMethod = (ReflectionCache.PACKET_PLAY_OUT_PLAYER_INFO_REMOVE_CLASS != null);
if (useOldMethod) return CacheRegistry.PACKET_PLAY_OUT_PLAYER_INFO_REMOVE_CONSTRUCTOR.load().newInstance(Collections.singletonList(CacheRegistry.GET_UNIQUE_ID_METHOD.load().invoke(nmsEntity))); if (useOldMethod) return ReflectionCache.PACKET_PLAY_OUT_PLAYER_INFO_REMOVE_CONSTRUCTOR.load().newInstance(Collections.singletonList(ReflectionCache.GET_UNIQUE_ID_METHOD.load().invoke(nmsEntity)));
return CacheRegistry.PACKET_PLAY_OUT_PLAYER_INFO_CONSTRUCTOR.load().newInstance(CacheRegistry.REMOVE_PLAYER_FIELD.load(), nmsEntity); return ReflectionCache.PACKET_PLAY_OUT_PLAYER_INFO_CONSTRUCTOR.load().newInstance(ReflectionCache.REMOVE_PLAYER_FIELD.load(), nmsEntity);
} }
} }
@ -63,29 +63,29 @@ public interface Packet {
ImmutableList.Builder<Object> builder = ImmutableList.builder(); ImmutableList.Builder<Object> builder = ImmutableList.builder();
boolean isVersion17 = (Utils.BUKKIT_VERSION > 16); boolean isVersion17 = (Utils.BUKKIT_VERSION > 16);
boolean isVersion9 = (Utils.BUKKIT_VERSION > 8); boolean isVersion9 = (Utils.BUKKIT_VERSION > 8);
Object scoreboardTeamPacket = isVersion17 ? CacheRegistry.SCOREBOARD_TEAM_CONSTRUCTOR.load().newInstance(null, npc.getGameProfile().getName()) : CacheRegistry.PACKET_PLAY_OUT_SCOREBOARD_TEAM_CONSTRUCTOR_OLD.load().newInstance(); Object scoreboardTeamPacket = isVersion17 ? ReflectionCache.SCOREBOARD_TEAM_CONSTRUCTOR.load().newInstance(null, npc.getGameProfile().getName()) : ReflectionCache.PACKET_PLAY_OUT_SCOREBOARD_TEAM_CONSTRUCTOR_OLD.load().newInstance();
if (!isVersion17) { if (!isVersion17) {
Utils.setValue(scoreboardTeamPacket, "a", npc.getGameProfile().getName()); Utils.setValue(scoreboardTeamPacket, "a", npc.getGameProfile().getName());
Utils.setValue(scoreboardTeamPacket, isVersion9 ? "i" : "h", 1); Utils.setValue(scoreboardTeamPacket, isVersion9 ? "i" : "h", 1);
} }
builder.add(isVersion17 ? CacheRegistry.PACKET_PLAY_OUT_SCOREBOARD_TEAM_CREATE_V1.load().invoke(null, scoreboardTeamPacket) : scoreboardTeamPacket); builder.add(isVersion17 ? ReflectionCache.PACKET_PLAY_OUT_SCOREBOARD_TEAM_CREATE_V1.load().invoke(null, scoreboardTeamPacket) : scoreboardTeamPacket);
if (isVersion17) { if (isVersion17) {
scoreboardTeamPacket = CacheRegistry.SCOREBOARD_TEAM_CONSTRUCTOR.load().newInstance(null, npc.getGameProfile().getName()); scoreboardTeamPacket = ReflectionCache.SCOREBOARD_TEAM_CONSTRUCTOR.load().newInstance(null, npc.getGameProfile().getName());
if (Utils.BUKKIT_VERSION > 17) { if (Utils.BUKKIT_VERSION > 17) {
Utils.setValue(scoreboardTeamPacket, "d", npc.getGameProfile().getName()); Utils.setValue(scoreboardTeamPacket, "d", npc.getGameProfile().getName());
ReflectionUtils.findFieldForClassAndSet(scoreboardTeamPacket, CacheRegistry.ENUM_TAG_VISIBILITY, CacheRegistry.ENUM_TAG_VISIBILITY_NEVER_FIELD.load()); ReflectionUtils.findFieldForClassAndSet(scoreboardTeamPacket, ReflectionCache.ENUM_TAG_VISIBILITY, ReflectionCache.ENUM_TAG_VISIBILITY_NEVER_FIELD.load());
Utils.setValue(scoreboardTeamPacket, "m", CacheRegistry.ENUM_CHAT_FORMAT_FIND.load().invoke(null, "DARK_GRAY")); Utils.setValue(scoreboardTeamPacket, "m", ReflectionCache.ENUM_CHAT_FORMAT_FIND.load().invoke(null, "DARK_GRAY"));
} else { } else {
Utils.setValue(scoreboardTeamPacket, "e", npc.getGameProfile().getName()); Utils.setValue(scoreboardTeamPacket, "e", npc.getGameProfile().getName());
Utils.setValue(scoreboardTeamPacket, "l", CacheRegistry.ENUM_TAG_VISIBILITY_NEVER_FIELD.load()); Utils.setValue(scoreboardTeamPacket, "l", ReflectionCache.ENUM_TAG_VISIBILITY_NEVER_FIELD.load());
} }
} else { } else {
scoreboardTeamPacket = CacheRegistry.PACKET_PLAY_OUT_SCOREBOARD_TEAM_CONSTRUCTOR_OLD.load().newInstance(); scoreboardTeamPacket = ReflectionCache.PACKET_PLAY_OUT_SCOREBOARD_TEAM_CONSTRUCTOR_OLD.load().newInstance();
Utils.setValue(scoreboardTeamPacket, "a", npc.getGameProfile().getName()); Utils.setValue(scoreboardTeamPacket, "a", npc.getGameProfile().getName());
Utils.setValue(scoreboardTeamPacket, "e", "never"); Utils.setValue(scoreboardTeamPacket, "e", "never");
Utils.setValue(scoreboardTeamPacket, isVersion9 ? "i" : "h", 0); Utils.setValue(scoreboardTeamPacket, isVersion9 ? "i" : "h", 0);
} }
Collection<String> collection = isVersion17 ? (Collection<String>) CacheRegistry.SCOREBOARD_PLAYER_LIST.load().invoke(scoreboardTeamPacket) : (Collection<String>) Utils.getValue(scoreboardTeamPacket, isVersion9 ? "h" : "g"); Collection<String> collection = isVersion17 ? (Collection<String>) ReflectionCache.SCOREBOARD_PLAYER_LIST.load().invoke(scoreboardTeamPacket) : (Collection<String>) Utils.getValue(scoreboardTeamPacket, isVersion9 ? "h" : "g");
if (npc.getNpcPojo().getNpcType() == NPCType.PLAYER) { if (npc.getNpcPojo().getNpcType() == NPCType.PLAYER) {
collection.add(npc.getGameProfile().getName()); collection.add(npc.getGameProfile().getName());
} else { } else {
@ -93,7 +93,7 @@ public interface Packet {
} }
if (allowGlowColor() && FunctionFactory.isTrue(npc, "glow")) if (allowGlowColor() && FunctionFactory.isTrue(npc, "glow"))
updateGlowPacket(npc, scoreboardTeamPacket); updateGlowPacket(npc, scoreboardTeamPacket);
builder.add(isVersion17 ? CacheRegistry.PACKET_PLAY_OUT_SCOREBOARD_TEAM_CREATE.load().invoke(null, scoreboardTeamPacket, Boolean.TRUE) : scoreboardTeamPacket); builder.add(isVersion17 ? ReflectionCache.PACKET_PLAY_OUT_SCOREBOARD_TEAM_CREATE.load().invoke(null, scoreboardTeamPacket, Boolean.TRUE) : scoreboardTeamPacket);
return builder.build(); return builder.build();
} }

@ -3,7 +3,7 @@ package io.github.znetworkw.znpcservers.npc.packet;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.mojang.datafixers.util.Pair; import com.mojang.datafixers.util.Pair;
import io.github.znetworkw.znpcservers.cache.CacheRegistry; import io.github.znetworkw.znpcservers.reflection.ReflectionCache;
import io.github.znetworkw.znpcservers.npc.ItemSlot; import io.github.znetworkw.znpcservers.npc.ItemSlot;
import io.github.znetworkw.znpcservers.npc.NPC; import io.github.znetworkw.znpcservers.npc.NPC;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -22,6 +22,6 @@ public class PacketV16 extends PacketV9 {
pairs.add(new Pair<>(getItemSlot(entry pairs.add(new Pair<>(getItemSlot(entry
.getKey().getSlot()), .getKey().getSlot()),
convertItemStack(npc.getEntityID(), entry.getKey(), entry.getValue()))); convertItemStack(npc.getEntityID(), entry.getKey(), entry.getValue())));
return ImmutableList.of(CacheRegistry.PACKET_PLAY_OUT_ENTITY_EQUIPMENT_CONSTRUCTOR_V1.load().newInstance(npc.getEntityID(), pairs)); return ImmutableList.of(ReflectionCache.PACKET_PLAY_OUT_ENTITY_EQUIPMENT_CONSTRUCTOR_V1.load().newInstance(npc.getEntityID(), pairs));
} }
} }

@ -1,7 +1,7 @@
package io.github.znetworkw.znpcservers.npc.packet; package io.github.znetworkw.znpcservers.npc.packet;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import io.github.znetworkw.znpcservers.cache.CacheRegistry; import io.github.znetworkw.znpcservers.reflection.ReflectionCache;
import io.github.znetworkw.znpcservers.npc.NPC; import io.github.znetworkw.znpcservers.npc.NPC;
import io.github.znetworkw.znpcservers.utility.Utils; import io.github.znetworkw.znpcservers.utility.Utils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -12,11 +12,11 @@ public class PacketV17 extends PacketV16 {
} }
public Object getPlayerPacket(Object nmsWorld, GameProfile gameProfile) throws ReflectiveOperationException { public Object getPlayerPacket(Object nmsWorld, GameProfile gameProfile) throws ReflectiveOperationException {
return CacheRegistry.PLAYER_CONSTRUCTOR_NEW.load().newInstance(CacheRegistry.GET_SERVER_METHOD.load().invoke(Bukkit.getServer()), nmsWorld, gameProfile); return ReflectionCache.PLAYER_CONSTRUCTOR_NEW.load().newInstance(ReflectionCache.GET_SERVER_METHOD.load().invoke(Bukkit.getServer()), nmsWorld, gameProfile);
} }
public void updateGlowPacket(NPC npc, Object packet) throws ReflectiveOperationException { public void updateGlowPacket(NPC npc, Object packet) throws ReflectiveOperationException {
Utils.setValue(packet, "n", CacheRegistry.ENUM_CHAT_FORMAT_FIND.load().invoke(null, npc.getNpcPojo().getGlowName())); Utils.setValue(packet, "n", ReflectionCache.ENUM_CHAT_FORMAT_FIND.load().invoke(null, npc.getNpcPojo().getGlowName()));
} }
public Object getClickType(Object interactPacket) { public Object getClickType(Object interactPacket) {

@ -1,6 +1,6 @@
package io.github.znetworkw.znpcservers.npc.packet; package io.github.znetworkw.znpcservers.npc.packet;
import io.github.znetworkw.znpcservers.cache.CacheRegistry; import io.github.znetworkw.znpcservers.reflection.ReflectionCache;
import io.github.znetworkw.znpcservers.npc.NPC; import io.github.znetworkw.znpcservers.npc.NPC;
import io.github.znetworkw.znpcservers.utility.Utils; import io.github.znetworkw.znpcservers.utility.Utils;
@ -10,6 +10,6 @@ public class PacketV18 extends PacketV17 {
} }
public void updateGlowPacket(NPC npc, Object packet) throws ReflectiveOperationException { public void updateGlowPacket(NPC npc, Object packet) throws ReflectiveOperationException {
Utils.setValue(packet, "m", CacheRegistry.ENUM_CHAT_FORMAT_FIND.load().invoke(null, npc.getNpcPojo().getGlowName())); Utils.setValue(packet, "m", ReflectionCache.ENUM_CHAT_FORMAT_FIND.load().invoke(null, npc.getNpcPojo().getGlowName()));
} }
} }

@ -1,7 +1,7 @@
package io.github.znetworkw.znpcservers.npc.packet; package io.github.znetworkw.znpcservers.npc.packet;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import io.github.znetworkw.znpcservers.cache.CacheRegistry; import io.github.znetworkw.znpcservers.reflection.ReflectionCache;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
public class PacketV19 extends PacketV18 { public class PacketV19 extends PacketV18 {
@ -11,9 +11,9 @@ public class PacketV19 extends PacketV18 {
public Object getPlayerPacket(Object nmsWorld, GameProfile gameProfile) throws ReflectiveOperationException { public Object getPlayerPacket(Object nmsWorld, GameProfile gameProfile) throws ReflectiveOperationException {
try { try {
return CacheRegistry.PLAYER_CONSTRUCTOR_NEW_1.load(true).newInstance(CacheRegistry.GET_SERVER_METHOD.load().invoke(Bukkit.getServer()), nmsWorld, gameProfile, null); return ReflectionCache.PLAYER_CONSTRUCTOR_NEW_1.load(true).newInstance(ReflectionCache.GET_SERVER_METHOD.load().invoke(Bukkit.getServer()), nmsWorld, gameProfile, null);
} catch (Throwable e) { } catch (Throwable e) {
return CacheRegistry.PLAYER_CONSTRUCTOR_NEW_2.load().newInstance(CacheRegistry.GET_SERVER_METHOD.load().invoke(Bukkit.getServer()), nmsWorld, gameProfile); return ReflectionCache.PLAYER_CONSTRUCTOR_NEW_2.load().newInstance(ReflectionCache.GET_SERVER_METHOD.load().invoke(Bukkit.getServer()), nmsWorld, gameProfile);
} }
} }
} }

@ -2,7 +2,7 @@ package io.github.znetworkw.znpcservers.npc.packet;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import io.github.znetworkw.znpcservers.cache.CacheRegistry; import io.github.znetworkw.znpcservers.reflection.ReflectionCache;
import io.github.znetworkw.znpcservers.npc.ItemSlot; import io.github.znetworkw.znpcservers.npc.ItemSlot;
import io.github.znetworkw.znpcservers.npc.NPC; import io.github.znetworkw.znpcservers.npc.NPC;
import io.github.znetworkw.znpcservers.utility.Utils; import io.github.znetworkw.znpcservers.utility.Utils;
@ -18,18 +18,18 @@ public class PacketV8 implements Packet {
} }
public Object getPlayerPacket(Object nmsWorld, GameProfile gameProfile) throws ReflectiveOperationException { public Object getPlayerPacket(Object nmsWorld, GameProfile gameProfile) throws ReflectiveOperationException {
Constructor<?> constructor = (Utils.BUKKIT_VERSION > 13) ? CacheRegistry.PLAYER_INTERACT_MANAGER_NEW_CONSTRUCTOR.load() : CacheRegistry.PLAYER_INTERACT_MANAGER_OLD_CONSTRUCTOR.load(); Constructor<?> constructor = (Utils.BUKKIT_VERSION > 13) ? ReflectionCache.PLAYER_INTERACT_MANAGER_NEW_CONSTRUCTOR.load() : ReflectionCache.PLAYER_INTERACT_MANAGER_OLD_CONSTRUCTOR.load();
return CacheRegistry.PLAYER_CONSTRUCTOR_OLD.load().newInstance(CacheRegistry.GET_SERVER_METHOD return ReflectionCache.PLAYER_CONSTRUCTOR_OLD.load().newInstance(ReflectionCache.GET_SERVER_METHOD
.load().invoke(Bukkit.getServer()), nmsWorld, gameProfile, constructor.newInstance(nmsWorld)); .load().invoke(Bukkit.getServer()), nmsWorld, gameProfile, constructor.newInstance(nmsWorld));
} }
public Object getSpawnPacket(Object nmsEntity, boolean isPlayer) throws ReflectiveOperationException { public Object getSpawnPacket(Object nmsEntity, boolean isPlayer) throws ReflectiveOperationException {
return isPlayer ? CacheRegistry.PACKET_PLAY_OUT_NAMED_ENTITY_CONSTRUCTOR.load().newInstance(nmsEntity) : CacheRegistry.PACKET_PLAY_OUT_SPAWN_ENTITY_CONSTRUCTOR.load().newInstance(nmsEntity); return isPlayer ? ReflectionCache.PACKET_PLAY_OUT_NAMED_ENTITY_CONSTRUCTOR.load().newInstance(nmsEntity) : ReflectionCache.PACKET_PLAY_OUT_SPAWN_ENTITY_CONSTRUCTOR.load().newInstance(nmsEntity);
} }
public Object convertItemStack(int entityId, ItemSlot itemSlot, ItemStack itemStack) throws ReflectiveOperationException { public Object convertItemStack(int entityId, ItemSlot itemSlot, ItemStack itemStack) throws ReflectiveOperationException {
return CacheRegistry.PACKET_PLAY_OUT_ENTITY_EQUIPMENT_CONSTRUCTOR_OLD.load().newInstance(entityId, return ReflectionCache.PACKET_PLAY_OUT_ENTITY_EQUIPMENT_CONSTRUCTOR_OLD.load().newInstance(entityId,
itemSlot.getSlotOld(), CacheRegistry.AS_NMS_COPY_METHOD.load().invoke(CacheRegistry.CRAFT_ITEM_STACK_CLASS, itemStack)); itemSlot.getSlotOld(), ReflectionCache.AS_NMS_COPY_METHOD.load().invoke(ReflectionCache.CRAFT_ITEM_STACK_CLASS, itemStack));
} }
public Object getClickType(Object interactPacket) throws ReflectiveOperationException { public Object getClickType(Object interactPacket) throws ReflectiveOperationException {
@ -37,22 +37,22 @@ public class PacketV8 implements Packet {
} }
public Object getMetadataPacket(int entityId, Object nmsEntity) throws ReflectiveOperationException { public Object getMetadataPacket(int entityId, Object nmsEntity) throws ReflectiveOperationException {
Object dataWatcher = CacheRegistry.GET_DATA_WATCHER_METHOD.load().invoke(nmsEntity); Object dataWatcher = ReflectionCache.GET_DATA_WATCHER_METHOD.load().invoke(nmsEntity);
try { try {
return CacheRegistry.PACKET_PLAY_OUT_ENTITY_META_DATA_CONSTRUCTOR.load(true).newInstance(entityId, dataWatcher, true); return ReflectionCache.PACKET_PLAY_OUT_ENTITY_META_DATA_CONSTRUCTOR.load(true).newInstance(entityId, dataWatcher, true);
} catch (Exception e2) { } catch (Exception e2) {
return CacheRegistry.PACKET_PLAY_OUT_ENTITY_META_DATA_CONSTRUCTOR_V1.load().newInstance(entityId, CacheRegistry.GET_DATAWATCHER_B_LIST.load().invoke(dataWatcher)); return ReflectionCache.PACKET_PLAY_OUT_ENTITY_META_DATA_CONSTRUCTOR_V1.load().newInstance(entityId, ReflectionCache.GET_DATAWATCHER_B_LIST.load().invoke(dataWatcher));
} }
} }
public Object getHologramSpawnPacket(Object armorStand) throws ReflectiveOperationException { public Object getHologramSpawnPacket(Object armorStand) throws ReflectiveOperationException {
return CacheRegistry.PACKET_PLAY_OUT_SPAWN_ENTITY_CONSTRUCTOR.load().newInstance(armorStand); return ReflectionCache.PACKET_PLAY_OUT_SPAWN_ENTITY_CONSTRUCTOR.load().newInstance(armorStand);
} }
public ImmutableList<Object> getEquipPackets(NPC npc) throws ReflectiveOperationException { public ImmutableList<Object> getEquipPackets(NPC npc) throws ReflectiveOperationException {
ImmutableList.Builder<Object> builder = ImmutableList.builder(); ImmutableList.Builder<Object> builder = ImmutableList.builder();
for (Map.Entry<ItemSlot, ItemStack> stackEntry : npc.getNpcPojo().getNpcEquip().entrySet()) { for (Map.Entry<ItemSlot, ItemStack> stackEntry : npc.getNpcPojo().getNpcEquip().entrySet()) {
builder.add(CacheRegistry.PACKET_PLAY_OUT_ENTITY_EQUIPMENT_CONSTRUCTOR_OLD.load().newInstance(npc.getEntityID(), stackEntry.getKey().getSlotOld(), builder.add(ReflectionCache.PACKET_PLAY_OUT_ENTITY_EQUIPMENT_CONSTRUCTOR_OLD.load().newInstance(npc.getEntityID(), stackEntry.getKey().getSlotOld(),
convertItemStack(npc.getEntityID(), stackEntry.getKey(), stackEntry.getValue()))); convertItemStack(npc.getEntityID(), stackEntry.getKey(), stackEntry.getValue())));
} }
return builder.build(); return builder.build();

@ -1,7 +1,7 @@
package io.github.znetworkw.znpcservers.npc.packet; package io.github.znetworkw.znpcservers.npc.packet;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import io.github.znetworkw.znpcservers.cache.CacheRegistry; import io.github.znetworkw.znpcservers.reflection.ReflectionCache;
import io.github.znetworkw.znpcservers.npc.ItemSlot; import io.github.znetworkw.znpcservers.npc.ItemSlot;
import io.github.znetworkw.znpcservers.npc.NPC; import io.github.znetworkw.znpcservers.npc.NPC;
import io.github.znetworkw.znpcservers.utility.Utils; import io.github.znetworkw.znpcservers.utility.Utils;
@ -15,13 +15,13 @@ public class PacketV9 extends PacketV8 {
} }
public Object convertItemStack(int entityId, ItemSlot itemSlot, ItemStack itemStack) throws ReflectiveOperationException { public Object convertItemStack(int entityId, ItemSlot itemSlot, ItemStack itemStack) throws ReflectiveOperationException {
return CacheRegistry.AS_NMS_COPY_METHOD.load().invoke(CacheRegistry.CRAFT_ITEM_STACK_CLASS, itemStack); return ReflectionCache.AS_NMS_COPY_METHOD.load().invoke(ReflectionCache.CRAFT_ITEM_STACK_CLASS, itemStack);
} }
public ImmutableList<Object> getEquipPackets(NPC npc) throws ReflectiveOperationException { public ImmutableList<Object> getEquipPackets(NPC npc) throws ReflectiveOperationException {
ImmutableList.Builder<Object> builder = ImmutableList.builder(); ImmutableList.Builder<Object> builder = ImmutableList.builder();
for (Map.Entry<ItemSlot, ItemStack> stackEntry : npc.getNpcPojo().getNpcEquip().entrySet()) { for (Map.Entry<ItemSlot, ItemStack> stackEntry : npc.getNpcPojo().getNpcEquip().entrySet()) {
builder.add(CacheRegistry.PACKET_PLAY_OUT_ENTITY_EQUIPMENT_CONSTRUCTOR_NEWEST_OLD.load().newInstance(npc.getEntityID(), builder.add(ReflectionCache.PACKET_PLAY_OUT_ENTITY_EQUIPMENT_CONSTRUCTOR_NEWEST_OLD.load().newInstance(npc.getEntityID(),
getItemSlot(stackEntry.getKey().getSlot()), getItemSlot(stackEntry.getKey().getSlot()),
convertItemStack(npc.getEntityID(), stackEntry.getKey(), stackEntry.getValue()))); convertItemStack(npc.getEntityID(), stackEntry.getKey(), stackEntry.getValue())));
} }
@ -29,12 +29,12 @@ public class PacketV9 extends PacketV8 {
} }
public void updateGlowPacket(NPC npc, Object packet) throws ReflectiveOperationException { public void updateGlowPacket(NPC npc, Object packet) throws ReflectiveOperationException {
Object enumChatString = CacheRegistry.ENUM_CHAT_TO_STRING_METHOD.load().invoke(npc.getGlowColor()); Object enumChatString = ReflectionCache.ENUM_CHAT_TO_STRING_METHOD.load().invoke(npc.getGlowColor());
if (Utils.BUKKIT_VERSION > 12) { if (Utils.BUKKIT_VERSION > 12) {
Utils.setValue(packet, npc.getGlowColor(), CacheRegistry.ENUM_CHAT_CLASS); Utils.setValue(packet, npc.getGlowColor(), ReflectionCache.ENUM_CHAT_CLASS);
Utils.setValue(packet, "c", CacheRegistry.I_CHAT_BASE_COMPONENT_A_CONSTRUCTOR.load().newInstance(enumChatString)); Utils.setValue(packet, "c", ReflectionCache.I_CHAT_BASE_COMPONENT_A_CONSTRUCTOR.load().newInstance(enumChatString));
} else { } else {
Utils.setValue(packet, "g", CacheRegistry.GET_ENUM_CHAT_ID_METHOD.load().invoke(npc.getGlowColor())); Utils.setValue(packet, "g", ReflectionCache.GET_ENUM_CHAT_ID_METHOD.load().invoke(npc.getGlowColor()));
Utils.setValue(packet, "c", enumChatString); Utils.setValue(packet, "c", enumChatString);
} }
} }

@ -1,23 +1,23 @@
package io.github.znetworkw.znpcservers.cache; package io.github.znetworkw.znpcservers.reflection;
import io.github.znetworkw.znpcservers.utility.Utils; import io.github.znetworkw.znpcservers.utility.Utils;
public enum CachePackage { public enum ReflectionBasePackage {
DEFAULT, DEFAULT,
CRAFT_BUKKIT("org.bukkit.craftbukkit." + Utils.getBukkitPackage()), CRAFT_BUKKIT("org.bukkit.craftbukkit." + Utils.getBukkitPackage()),
MINECRAFT_SERVER("net.minecraft"); MINECRAFT_SERVER("net.minecraft");
private final String fixedPackageName; private final String fixedPackageName;
CachePackage(String packageName) { ReflectionBasePackage(String packageName) {
this.fixedPackageName = Utils.versionNewer(17) ? packageName : (packageName + (packageName.contains("minecraft") ? (".server." + Utils.getBukkitPackage()) : "")); this.fixedPackageName = Utils.versionNewer(17) ? packageName : (packageName + (packageName.contains("minecraft") ? (".server." + Utils.getBukkitPackage()) : ""));
} }
CachePackage() { ReflectionBasePackage() {
this.fixedPackageName = ""; this.fixedPackageName = "";
} }
public String getForCategory(CacheCategory packetCategory, String extra) { public String getForCategory(ReflectionTopPackage packetCategory, String extra) {
return Utils.versionNewer(17) ? (packetCategory return Utils.versionNewer(17) ? (packetCategory
.getPackageName() + ((extra.length() > 0) ? ("." + extra) : "")) : .getPackageName() + ((extra.length() > 0) ? ("." + extra) : "")) :
this.fixedPackageName; this.fixedPackageName;

@ -0,0 +1,682 @@
package io.github.znetworkw.znpcservers.reflection;
import com.mojang.authlib.GameProfile;
import io.github.znetworkw.znpcservers.utility.Utils;
import io.netty.channel.Channel;
import org.bukkit.inventory.ItemStack;
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;
public final class ReflectionCache {
public static final Class<?> PACKET_PLAY_IN_USE_ENTITY_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName("PacketPlayInUseEntity"))).load();
public static final Class<?> ENUM_PLAYER_INFO_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName("PacketPlayOutPlayerInfo$EnumPlayerInfoAction")
.withClassName("ClientboundPlayerInfoUpdatePacket$a"))).load();
public static final Class<?> PACKET_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PROTOCOL)
.withClassName("Packet"))).load();
public static final Class<?> ENTITY_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withClassName("Entity"))).load();
public static final Class<?> ENTITY_LIVING = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withClassName("EntityLiving"))).load();
public static final Class<?> ENTITY_PLAYER_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.SERVER_LEVEL)
.withClassName("EntityPlayer"))).load();
public static final Class<?> ENTITY_ARMOR_STAND_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("decoration")
.withClassName("EntityArmorStand"))).load();
public static final Class<?> ENTITY_BAT_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("ambient")
.withClassName("EntityBat"))).load();
public static final Class<?> ENTITY_BLAZE_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("monster")
.withClassName("EntityBlaze"))).load();
public static final Class<?> ENTITY_CAVE_SPIDER_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("monster")
.withClassName("EntityCaveSpider"))).load();
public static final Class<?> ENTITY_CHICKEN_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityChicken"))).load();
public static final Class<?> ENTITY_COW_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityCow"))).load();
public static final Class<?> ENTITY_CREEPER_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("monster")
.withClassName("EntityCreeper"))).load();
public static final Class<?> ENTITY_ENDER_DRAGON_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("boss.enderdragon")
.withClassName("EntityEnderDragon"))).load();
public static final Class<?> ENTITY_ENDERMAN_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("monster")
.withClassName("EntityEnderman"))).load();
public static final Class<?> ENTITY_HUMAN_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("player")
.withClassName("EntityHuman"))).load();
public static final Class<?> ENTITY_ENDERMITE_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("monster")
.withClassName("EntityEndermite"))).load();
public static final Class<?> ENTITY_GHAST_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("monster")
.withClassName("EntityGhast"))).load();
public static final Class<?> ENTITY_IRON_GOLEM_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityIronGolem"))).load();
public static final Class<?> ENTITY_GIANT_ZOMBIE_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("monster")
.withClassName("EntityGiantZombie"))).load();
public static final Class<?> ENTITY_GUARDIAN_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("monster")
.withClassName("EntityGuardian"))).load();
public static final Class<?> ENTITY_HORSE_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("animal.horse")
.withClassName("EntityHorse"))).load();
public static final Class<?> ENTITY_LLAMA_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("animal.horse")
.withClassName("EntityLlama"))).load(!Utils.versionNewer(11));
public static final Class<?> ENTITY_MAGMA_CUBE_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("monster")
.withClassName("EntityMagmaCube"))).load();
public static final Class<?> ENTITY_MUSHROOM_COW_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityMushroomCow"))).load();
public static final Class<?> ENTITY_OCELOT_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityOcelot"))).load();
public static final Class<?> ENTITY_TURTLE = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityTurtle"))).load(!Utils.versionNewer(13));
public static final Class<?> ENTITY_WARDEN = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("monster.warden")
.withClassName("EntityWarden")
.withClassName("Warden"))).load(!Utils.versionNewer(19));
public static final Class<?> ENTITY_BEE_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityBee"))).load(!Utils.versionNewer(15));
public static final Class<?> ENTITY_PARROT_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityParrot"))).load(!Utils.versionNewer(12));
public static final Class<?> ENTITY_PIG_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityPig"))).load();
public static final Class<?> ENTITY_RABBIT_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityRabbit"))).load();
public static final Class<?> ENTITY_POLAR_BEAR_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityPolarBear"))).load(!Utils.versionNewer(10));
public static final Class<?> ENTITY_PANDA_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityPanda"))).load(!Utils.versionNewer(14));
public static final Class<?> ENTITY_SHEEP_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("animal")
.withClassName("EntitySheep"))).load();
public static final Class<?> ENTITY_SNOWMAN_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("animal")
.withClassName("EntitySnowman"))).load();
public static final Class<?> ENTITY_SHULKER_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("monster")
.withClassName("EntityShulker"))).load(!Utils.versionNewer(9));
public static final Class<?> ENTITY_SILVERFISH_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("monster")
.withClassName("EntitySilverfish"))).load();
public static final Class<?> ENTITY_SKELETON_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("monster")
.withClassName("EntitySkeleton"))).load();
public static final Class<?> ENTITY_SLIME_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("monster")
.withClassName("EntitySlime"))).load();
public static final Class<?> ENTITY_SPIDER_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("monster")
.withClassName("EntitySpider"))).load();
public static final Class<?> ENTITY_SQUID_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("animal")
.withClassName("EntitySquid"))).load();
public static final Class<?> ENTITY_VILLAGER_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("npc")
.withClassName("EntityVillager"))).load();
public static final Class<?> ENTITY_WITCH_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("monster")
.withClassName("EntityWitch"))).load();
public static final Class<?> ENTITY_WITHER_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("boss.wither")
.withClassName("EntityWither"))).load();
public static final Class<?> ENTITY_ZOMBIE_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("monster")
.withClassName("EntityZombie"))).load();
public static final Class<?> ENTITY_WOLF_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityWolf"))).load();
public static final Class<?> ENTITY_AXOLOTL_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("animal.axolotl")
.withClassName("Axolotl"))).load(!Utils.versionNewer(17));
public static final Class<?> ENTITY_GOAT_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("animal.goat")
.withClassName("Goat"))).load(!Utils.versionNewer(17));
public static final Class<?> ENTITY_FOX_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withAdditionalData("animal")
.withClassName("EntityFox"))).load(!Utils.versionNewer(14));
public static final Class<?> ENTITY_TYPES_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withClassName("EntityTypes"))).load();
public static final Class<?> ENUM_CHAT_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withClassName("EnumChatFormat"))).load();
public static final Class<?> ENUM_ITEM_SLOT = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withClassName("EnumItemSlot"))).load(!Utils.versionNewer(9));
public static final Class<?> I_CHAT_BASE_COMPONENT = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.CHAT)
.withClassName("IChatBaseComponent"))).load();
public static final Class<?> ITEM_STACK_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ITEM)
.withClassName("ItemStack"))).load();
public static final Class<?> DATA_WATCHER_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.SYNCHER)
.withClassName("DataWatcher"))).load(!Utils.versionNewer(9));
public static final Class<?> DATA_WATCHER_OBJECT = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.SYNCHER)
.withClassName("DataWatcherObject"))).load(!Utils.versionNewer(9));
public static final Class<?> DATA_WATCHER_REGISTRY = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.SYNCHER)
.withClassName("DataWatcherRegistry"))).load(!Utils.versionNewer(9));
public static final Class<?> DATA_WATCHER_SERIALIZER = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.SYNCHER)
.withClassName("DataWatcherSerializer"))).load(!Utils.versionNewer(9));
public static final Class<?> WORLD_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.WORLD_LEVEL)
.withClassName("World"))).load();
public static final Class<?> CRAFT_ITEM_STACK_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.CRAFT_BUKKIT))
.withClassName("inventory.CraftItemStack"))).load();
public static final Class<?> WORLD_SERVER_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.SERVER_LEVEL)
.withClassName("WorldServer"))).load();
public static final Class<?> MINECRAFT_SERVER_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.SERVER)
.withClassName("MinecraftServer"))).load();
public static final Class<?> PLAYER_INTERACT_MANAGER_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.SERVER_LEVEL)
.withClassName("PlayerInteractManager"))).load();
public static final Class<?> PLAYER_CONNECTION_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.SERVER_NETWORK)
.withClassName("PlayerConnection"))).load();
public static final Class<?> NETWORK_MANAGER_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.NETWORK)
.withClassName("NetworkManager"))).load();
public static final Class<?> PACKET_PLAY_OUT_PLAYER_INFO_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName("PacketPlayOutPlayerInfo")
.withClassName("ClientboundPlayerInfoUpdatePacket")))
.load();
public static final Class<?> PACKET_PLAY_OUT_PLAYER_INFO_REMOVE_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName("ClientboundPlayerInfoRemovePacket")))
.load(true);
public static final Class<?> PACKET_PLAY_OUT_SCOREBOARD_TEAM_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName("PacketPlayOutScoreboardTeam"))).load();
public static final Class<?> PACKET_PLAY_OUT_ENTITY_DESTROY_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName("PacketPlayOutEntityDestroy"))).load();
public static final Class<?> SCOREBOARD_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.WORLD_SCORES)
.withClassName("Scoreboard"))).load();
public static final Class<?> SCOREBOARD_TEAM_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.WORLD_SCORES)
.withClassName("ScoreboardTeam"))).load();
public static final Class<?> ENUM_TAG_VISIBILITY = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.WORLD_SCORES)
.withClassName("ScoreboardTeamBase$EnumNameTagVisibility"))).load();
public static final Class<?> CRAFT_CHAT_MESSAGE_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.CRAFT_BUKKIT))
.withClassName("util.CraftChatMessage"))).load();
public static final Class<?> PROFILE_PUBLIC_KEY_CLASS = (new TypeCache.BaseReflection.ClassReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.WORLD_ENTITY_PLAYER)
.withClassName("ProfilePublicKey"))).load(!Utils.versionNewer(19));
public static final TypeCache.BaseReflection<Constructor<?>> SCOREBOARD_TEAM_CONSTRUCTOR = new TypeCache.BaseReflection.ConstructorReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(SCOREBOARD_TEAM_CLASS)
.withParameterTypes(SCOREBOARD_CLASS, String.class));
public static final TypeCache.BaseReflection<Constructor<?>> PLAYER_CONSTRUCTOR_OLD = new TypeCache.BaseReflection.ConstructorReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(ENTITY_PLAYER_CLASS)
.withParameterTypes(MINECRAFT_SERVER_CLASS, WORLD_SERVER_CLASS, GameProfile.class, PLAYER_INTERACT_MANAGER_CLASS));
public static final TypeCache.BaseReflection<Constructor<?>> PLAYER_CONSTRUCTOR_NEW = new TypeCache.BaseReflection.ConstructorReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(ENTITY_PLAYER_CLASS)
.withParameterTypes(MINECRAFT_SERVER_CLASS, WORLD_SERVER_CLASS, GameProfile.class));
public static final TypeCache.BaseReflection<Constructor<?>> PLAYER_CONSTRUCTOR_NEW_1 = new TypeCache.BaseReflection.ConstructorReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(ENTITY_PLAYER_CLASS)
.withParameterTypes(MINECRAFT_SERVER_CLASS, WORLD_SERVER_CLASS, GameProfile.class, PROFILE_PUBLIC_KEY_CLASS));
public static final TypeCache.BaseReflection<Constructor<?>> PLAYER_CONSTRUCTOR_NEW_2 = new TypeCache.BaseReflection.ConstructorReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(ENTITY_PLAYER_CLASS)
.withParameterTypes(MINECRAFT_SERVER_CLASS, WORLD_SERVER_CLASS, GameProfile.class));
public static final TypeCache.BaseReflection<Constructor<?>> PACKET_PLAY_OUT_PLAYER_INFO_CONSTRUCTOR = new TypeCache.BaseReflection.ConstructorReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.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 TypeCache.BaseReflection<Constructor<?>> PACKET_PLAY_OUT_PLAYER_INFO_REMOVE_CONSTRUCTOR = new TypeCache.BaseReflection.ConstructorReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(PACKET_PLAY_OUT_PLAYER_INFO_REMOVE_CLASS)
.withParameterTypes(List.class));
public static final TypeCache.BaseReflection<Constructor<?>> PACKET_PLAY_OUT_ENTITY_LOOK_CONSTRUCTOR = new TypeCache.BaseReflection.ConstructorReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName("PacketPlayOutEntity$PacketPlayOutEntityLook")
.withParameterTypes(int.class, byte.class, byte.class, boolean.class));
public static final TypeCache.BaseReflection<Constructor<?>> PACKET_PLAY_OUT_ENTITY_HEAD_ROTATION_CONSTRUCTOR = new TypeCache.BaseReflection.ConstructorReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName("PacketPlayOutEntityHeadRotation")
.withParameterTypes(ENTITY_CLASS, byte.class));
public static final TypeCache.BaseReflection<Constructor<?>> PACKET_PLAY_OUT_ENTITY_TELEPORT_CONSTRUCTOR = new TypeCache.BaseReflection.ConstructorReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName("PacketPlayOutEntityTeleport")
.withParameterTypes(ENTITY_CLASS));
public static final TypeCache.BaseReflection<Constructor<?>> PACKET_PLAY_OUT_ENTITY_META_DATA_CONSTRUCTOR = new TypeCache.BaseReflection.ConstructorReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName("PacketPlayOutEntityMetadata")
.withParameterTypes(int.class, DATA_WATCHER_CLASS, boolean.class));
public static final TypeCache.BaseReflection<Constructor<?>> PACKET_PLAY_OUT_ENTITY_META_DATA_CONSTRUCTOR_V1 = new TypeCache.BaseReflection.ConstructorReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName("PacketPlayOutEntityMetadata")
.withParameterTypes(int.class, List.class));
public static final TypeCache.BaseReflection<Constructor<?>> PACKET_PLAY_OUT_NAMED_ENTITY_CONSTRUCTOR = new TypeCache.BaseReflection.ConstructorReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName("PacketPlayOutNamedEntitySpawn")
.withParameterTypes(ENTITY_HUMAN_CLASS));
public static final TypeCache.BaseReflection<Constructor<?>> PACKET_PLAY_OUT_ENTITY_DESTROY_CONSTRUCTOR = new TypeCache.BaseReflection.ConstructorReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(PACKET_PLAY_OUT_ENTITY_DESTROY_CLASS)
.withParameterTypes(int.class).withParameterTypes(int[].class));
public static final TypeCache.BaseReflection<Constructor<?>> PACKET_PLAY_OUT_SPAWN_ENTITY_CONSTRUCTOR = new TypeCache.BaseReflection.ConstructorReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName("PacketPlayOutSpawnEntity")
.withClassName("PacketPlayOutSpawnEntityLiving")
.withParameterTypes(ENTITY_LIVING).withParameterTypes(ENTITY_CLASS));
public static final TypeCache.BaseReflection<Constructor<?>> PLAYER_INTERACT_MANAGER_OLD_CONSTRUCTOR = new TypeCache.BaseReflection.ConstructorReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName("PlayerInteractManager")
.withParameterTypes(WORLD_CLASS));
public static final TypeCache.BaseReflection<Constructor<?>> PLAYER_INTERACT_MANAGER_NEW_CONSTRUCTOR = new TypeCache.BaseReflection.ConstructorReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName("PlayerInteractManager")
.withParameterTypes(WORLD_SERVER_CLASS));
public static final TypeCache.BaseReflection<Constructor<?>> PACKET_PLAY_OUT_SCOREBOARD_TEAM_CONSTRUCTOR_OLD = new TypeCache.BaseReflection.ConstructorReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(PACKET_PLAY_OUT_SCOREBOARD_TEAM_CLASS));
public static final TypeCache.BaseReflection<Constructor<?>> PACKET_PLAY_OUT_ENTITY_EQUIPMENT_CONSTRUCTOR_OLD = new TypeCache.BaseReflection.ConstructorReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName("PacketPlayOutEntityEquipment")
.withParameterTypes(int.class, int.class, ITEM_STACK_CLASS));
public static final TypeCache.BaseReflection<Constructor<?>> PACKET_PLAY_OUT_ENTITY_EQUIPMENT_CONSTRUCTOR_NEWEST_OLD = new TypeCache.BaseReflection.ConstructorReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName("PacketPlayOutEntityEquipment")
.withParameterTypes(int.class, ENUM_ITEM_SLOT, ITEM_STACK_CLASS));
public static final TypeCache.BaseReflection<Constructor<?>> PACKET_PLAY_OUT_ENTITY_EQUIPMENT_CONSTRUCTOR_V1 = new TypeCache.BaseReflection.ConstructorReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName("PacketPlayOutEntityEquipment")
.withParameterTypes(int.class, List.class));
public static final TypeCache.BaseReflection<Constructor<?>> I_CHAT_BASE_COMPONENT_A_CONSTRUCTOR = new TypeCache.BaseReflection.ConstructorReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.CHAT)
.withClassName("ChatComponentText")
.withParameterTypes(String.class));
public static final TypeCache.BaseReflection<Constructor<?>> ENTITY_CONSTRUCTOR = new TypeCache.BaseReflection.ConstructorReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(ENTITY_ARMOR_STAND_CLASS)
.withParameterTypes(WORLD_CLASS, double.class, double.class, double.class));
public static final TypeCache.BaseReflection<Constructor<?>> DATA_WATCHER_OBJECT_CONSTRUCTOR = new TypeCache.BaseReflection.ConstructorReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(DATA_WATCHER_OBJECT)
.withParameterTypes(int.class, DATA_WATCHER_SERIALIZER));
public static final TypeCache.BaseReflection<Method> AS_NMS_COPY_METHOD = new TypeCache.BaseReflection.MethodReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.CRAFT_BUKKIT))
.withClassName("inventory.CraftItemStack")
.withMethodName("asNMSCopy")
.withParameterTypes(ItemStack.class));
public static final TypeCache.BaseReflection<Method> GET_PROFILE_METHOD = new TypeCache.BaseReflection.MethodReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withClassName(ENTITY_HUMAN_CLASS)
.withExpectResult(GameProfile.class));
public static final TypeCache.BaseReflection<Method> GET_ENTITY_ID = new TypeCache.BaseReflection.MethodReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(ENTITY_CLASS)
.withMethodName("getId")
.withMethodName("ae")
.withMethodName("ah")
.withMethodName("af")
.withExpectResult(int.class));
public static final TypeCache.BaseReflection<Method> GET_HANDLE_PLAYER_METHOD = new TypeCache.BaseReflection.MethodReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.CRAFT_BUKKIT))
.withClassName("entity.CraftPlayer").withClassName("entity.CraftHumanEntity")
.withMethodName("getHandle"));
public static final TypeCache.BaseReflection<Method> GET_HANDLE_WORLD_METHOD = new TypeCache.BaseReflection.MethodReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.CRAFT_BUKKIT))
.withClassName("CraftWorld")
.withMethodName("getHandle"));
public static final TypeCache.BaseReflection<Method> GET_SERVER_METHOD = new TypeCache.BaseReflection.MethodReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.CRAFT_BUKKIT))
.withClassName("CraftServer")
.withMethodName("getServer"));
public static final TypeCache.BaseReflection<Method> SEND_PACKET_METHOD = new TypeCache.BaseReflection.MethodReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(PLAYER_CONNECTION_CLASS)
.withMethodName("sendPacket").withMethodName("a")
.withParameterTypes(PACKET_CLASS));
public static final TypeCache.BaseReflection<Method> SET_CUSTOM_NAME_OLD_METHOD = new TypeCache.BaseReflection.MethodReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(ENTITY_CLASS)
.withMethodName("setCustomName")
.withParameterTypes(String.class));
public static final TypeCache.BaseReflection<Method> SET_CUSTOM_NAME_NEW_METHOD = new TypeCache.BaseReflection.MethodReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(ENTITY_CLASS)
.withMethodName("setCustomName")
.withMethodName("a")
.withMethodName("b")
.withParameterTypes(I_CHAT_BASE_COMPONENT).withExpectResult(void.class));
public static final TypeCache.BaseReflection<Method> SET_CUSTOM_NAME_VISIBLE_METHOD = new TypeCache.BaseReflection.MethodReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(ENTITY_CLASS)
.withMethodName("setCustomNameVisible")
.withMethodName("n")
.withParameterTypes(boolean.class));
public static final TypeCache.BaseReflection<Method> SET_INVISIBLE_METHOD = new TypeCache.BaseReflection.MethodReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(ENTITY_ARMOR_STAND_CLASS)
.withMethodName("setInvisible").withMethodName("j")
.withParameterTypes(boolean.class));
public static final TypeCache.BaseReflection<Method> SET_LOCATION_METHOD = new TypeCache.BaseReflection.MethodReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(ENTITY_CLASS)
.withMethodName("setPositionRotation")
.withMethodName("a")
.withParameterTypes(double.class, double.class, double.class, float.class, float.class));
public static final TypeCache.BaseReflection<Method> SET_DATA_WATCHER_METHOD = new TypeCache.BaseReflection.MethodReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(DATA_WATCHER_CLASS)
.withMethodName("set").withMethodName("b")
.withParameterTypes(DATA_WATCHER_OBJECT, Object.class));
public static final TypeCache.BaseReflection<Method> WATCH_DATA_WATCHER_METHOD = new TypeCache.BaseReflection.MethodReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(DATA_WATCHER_CLASS)
.withMethodName("watch")
.withParameterTypes(int.class, Object.class));
public static final TypeCache.BaseReflection<Method> GET_DATA_WATCHER_METHOD = new TypeCache.BaseReflection.MethodReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(ENTITY_CLASS)
.withMethodName("getDataWatcher")
.withMethodName("ai")
.withMethodName("al")
.withMethodName("aj")
.withExpectResult(DATA_WATCHER_CLASS));
public static final TypeCache.BaseReflection<Method> GET_BUKKIT_ENTITY_METHOD = new TypeCache.BaseReflection.MethodReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(ENTITY_CLASS)
.withMethodName("getBukkitEntity"));
public static final TypeCache.BaseReflection<Method> GET_ENUM_CHAT_ID_METHOD = new TypeCache.BaseReflection.MethodReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(ENUM_CHAT_CLASS)
.withMethodName("b"));
public static final TypeCache.BaseReflection<Method> ENUM_CHAT_TO_STRING_METHOD = new TypeCache.BaseReflection.MethodReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(ENUM_CHAT_CLASS)
.withExpectResult(String.class)
.withMethodName("toString"));
public static final TypeCache.BaseReflection<Method> ENTITY_TYPES_A_METHOD = new TypeCache.BaseReflection.MethodReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.ENTITY)
.withClassName(ENTITY_TYPES_CLASS)
.withMethodName("a")
.withParameterTypes(String.class));
public static final TypeCache.BaseReflection<Method> PACKET_PLAY_OUT_SCOREBOARD_TEAM_CREATE_V1 = new TypeCache.BaseReflection.MethodReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(PACKET_PLAY_OUT_SCOREBOARD_TEAM_CLASS)
.withMethodName("a")
.withParameterTypes(SCOREBOARD_TEAM_CLASS));
public static final TypeCache.BaseReflection<Method> PACKET_PLAY_OUT_SCOREBOARD_TEAM_CREATE = new TypeCache.BaseReflection.MethodReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(PACKET_PLAY_OUT_SCOREBOARD_TEAM_CLASS)
.withMethodName("a")
.withParameterTypes(SCOREBOARD_TEAM_CLASS, boolean.class));
public static final TypeCache.BaseReflection<Method> SCOREBOARD_PLAYER_LIST = new TypeCache.BaseReflection.MethodReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(SCOREBOARD_TEAM_CLASS)
.withMethodName("getPlayerNameSet").withMethodName("g"));
public static final TypeCache.BaseReflection<Method> ENUM_CHAT_FORMAT_FIND = new TypeCache.BaseReflection.MethodReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withClassName(ENUM_CHAT_CLASS)
.withParameterTypes(String.class).withExpectResult(ENUM_CHAT_CLASS));
public static final TypeCache.BaseReflection<Method> CRAFT_CHAT_MESSAGE_METHOD = new TypeCache.BaseReflection.MethodReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.CRAFT_BUKKIT))
.withClassName(CRAFT_CHAT_MESSAGE_CLASS)
.withMethodName("fromStringOrNull")
.withParameterTypes(String.class));
public static final TypeCache.BaseReflection<Method> GET_UNIQUE_ID_METHOD = new TypeCache.BaseReflection.MethodReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withClassName(ENTITY_CLASS)
.withExpectResult(UUID.class));
public static final TypeCache.BaseReflection<Method> GET_DATAWATCHER_B_LIST = new TypeCache.BaseReflection.MethodReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withMethodName("c")
.withClassName(DATA_WATCHER_CLASS));
public static final TypeCache.BaseReflection<Field> PLAYER_CONNECTION_FIELD = new TypeCache.BaseReflection.FieldReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.SERVER_LEVEL)
.withClassName(ENTITY_PLAYER_CLASS)
.withFieldName((Utils.BUKKIT_VERSION > 16) ? "b" : "playerConnection"));
public static final TypeCache.BaseReflection<Field> NETWORK_MANAGER_FIELD = new TypeCache.BaseReflection.FieldReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(PLAYER_CONNECTION_CLASS)
.withFieldName((Utils.BUKKIT_VERSION > 16) ? "a" : "networkManager")
.withExpectResult(NETWORK_MANAGER_CLASS));
public static final TypeCache.BaseReflection<Field> CHANNEL_FIELD = new TypeCache.BaseReflection.FieldReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.SERVER_NETWORK)
.withClassName(NETWORK_MANAGER_CLASS)
.withExpectResult(Channel.class));
public static final TypeCache.BaseReflection<Field> PACKET_IN_USE_ENTITY_ID_FIELD = new TypeCache.BaseReflection.FieldReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName("PacketPlayInUseEntity")
.withFieldName("a"));
public static final TypeCache.BaseReflection<Field> BUKKIT_COMMAND_MAP = new TypeCache.BaseReflection.FieldReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.CRAFT_BUKKIT))
.withClassName("CraftServer")
.withFieldName("commandMap"));
public static final TypeCache.BaseReflection<Object> ADD_PLAYER_FIELD = (new TypeCache.BaseReflection.FieldReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName("PacketPlayOutPlayerInfo$EnumPlayerInfoAction")
.withClassName("ClientboundPlayerInfoUpdatePacket$a")
.withFieldName((Utils.BUKKIT_VERSION > 16) ? "a" : "ADD_PLAYER"))).asValueField();
public static final TypeCache.BaseReflection<Object> UPDATE_LISTED_FIELD = (new TypeCache.BaseReflection.FieldReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName("ClientboundPlayerInfoUpdatePacket$a")
.withFieldName("d"))).asValueField();
public static final TypeCache.BaseReflection<Object> REMOVE_PLAYER_FIELD = (new TypeCache.BaseReflection.FieldReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName("PacketPlayOutPlayerInfo$EnumPlayerInfoAction")
.withClassName("ClientboundPlayerInfoUpdatePacket$a")
.withFieldName((Utils.BUKKIT_VERSION > 16) ? "e" : "REMOVE_PLAYER"))).asValueField();
public static final TypeCache.BaseReflection<Object> DATA_WATCHER_REGISTER_FIELD = (new TypeCache.BaseReflection.FieldReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(DATA_WATCHER_REGISTRY)
.withFieldName("a"))).asValueField();
public static final TypeCache.BaseReflection<Object> ENUM_TAG_VISIBILITY_NEVER_FIELD = (new TypeCache.BaseReflection.FieldReflection((new TypeCache.ReflectionBuilder(ReflectionBasePackage.MINECRAFT_SERVER))
.withCategory(ReflectionTopPackage.PACKET)
.withClassName(ENUM_TAG_VISIBILITY)
.withFieldName("b"))).asValueField();
}

@ -1,6 +1,6 @@
package io.github.znetworkw.znpcservers.cache; package io.github.znetworkw.znpcservers.reflection;
public enum CacheCategory { public enum ReflectionTopPackage {
DEFAULT(""), DEFAULT(""),
NETWORK("network"), NETWORK("network"),
PROTOCOL("network.protocol"), PROTOCOL("network.protocol"),
@ -16,13 +16,10 @@ public enum CacheCategory {
SERVER_NETWORK("server.network"), SERVER_NETWORK("server.network"),
SERVER("server"); SERVER("server");
private final String subPackageName;
private final String packageName; private final String packageName;
CacheCategory(String subPackageName) { ReflectionTopPackage(String subPackageName) {
this.subPackageName = subPackageName; StringBuilder stringBuilder = new StringBuilder(ReflectionBasePackage.MINECRAFT_SERVER.getFixedPackageName());
StringBuilder stringBuilder = new StringBuilder(CachePackage.MINECRAFT_SERVER.getFixedPackageName());
if (subPackageName.length() > 0) { if (subPackageName.length() > 0) {
stringBuilder.append("."); stringBuilder.append(".");
stringBuilder.append(subPackageName); stringBuilder.append(subPackageName);
@ -30,10 +27,6 @@ public enum CacheCategory {
this.packageName = stringBuilder.toString(); this.packageName = stringBuilder.toString();
} }
public String getSubPackageName() {
return this.subPackageName;
}
public String getPackageName() { public String getPackageName() {
return this.packageName; return this.packageName;
} }

@ -0,0 +1,274 @@
package io.github.znetworkw.znpcservers.reflection;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import io.github.znetworkw.znpcservers.utility.Utils;
import lol.pyr.znpcsplus.ZNPCsPlus;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
public interface TypeCache {
class ClassCache {
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);
}
}
}
class ReflectionBuilder {
private final ReflectionBasePackage reflectionBasePackage;
private final ReflectionTopPackage reflectionTopPackage;
private final String fieldName;
private final List<String> className;
private final List<String> methods;
private final String additionalData;
private final ImmutableList<Class<?>[]> parameterTypes;
private final Class<?> expectType;
public ReflectionBuilder(ReflectionBasePackage reflectionBasePackage) {
this(reflectionBasePackage, ReflectionTopPackage.DEFAULT, new ArrayList<>(), "", new ArrayList<>(), "", ImmutableList.of(), null);
}
protected ReflectionBuilder(ReflectionBasePackage reflectionBasePackage, ReflectionTopPackage reflectionTopPackage, List<String> className, String fieldName, List<String> methods, String additionalData, ImmutableList<Class<?>[]> parameterTypes, Class<?> expectType) {
this.reflectionBasePackage = reflectionBasePackage;
this.reflectionTopPackage = reflectionTopPackage;
this.className = className;
this.methods = methods;
this.fieldName = fieldName;
this.additionalData = additionalData;
this.parameterTypes = parameterTypes;
this.expectType = expectType;
}
public ReflectionBuilder withCategory(ReflectionTopPackage reflectionTopPackage) {
return new ReflectionBuilder(this.reflectionBasePackage, reflectionTopPackage, this.className, this.fieldName, this.methods, this.additionalData, this.parameterTypes, this.expectType);
}
public ReflectionBuilder withClassName(String className) {
return new ReflectionBuilder(this.reflectionBasePackage, this.reflectionTopPackage, new ImmutableList.Builder<String>().addAll(this.className).add(formatClass(className)).build(), this.fieldName, this.methods, this.additionalData, this.parameterTypes, this.expectType);
}
public ReflectionBuilder withClassName(Class<?> clazz) {
return new ReflectionBuilder(this.reflectionBasePackage, this.reflectionTopPackage, new ImmutableList.Builder<String>().addAll(this.className).add((clazz == null) ? "" : clazz.getName()).build(), this.fieldName, this.methods, this.additionalData, this.parameterTypes, this.expectType);
}
public ReflectionBuilder withMethodName(String methodName) {
return new ReflectionBuilder(this.reflectionBasePackage, this.reflectionTopPackage, this.className, this.fieldName, new ImmutableList.Builder<String>().addAll(this.methods).add(methodName).build(), this.additionalData, this.parameterTypes, this.expectType);
}
public ReflectionBuilder withFieldName(String fieldName) {
return new ReflectionBuilder(this.reflectionBasePackage, this.reflectionTopPackage, this.className, fieldName, this.methods, this.additionalData, this.parameterTypes, this.expectType);
}
public ReflectionBuilder withAdditionalData(String additionalData) {
return new ReflectionBuilder(this.reflectionBasePackage, this.reflectionTopPackage, this.className, this.fieldName, this.methods, additionalData, this.parameterTypes, this.expectType);
}
public ReflectionBuilder withParameterTypes(Class<?>... types) {
return new ReflectionBuilder(this.reflectionBasePackage, this.reflectionTopPackage, this.className, this.fieldName, this.methods, this.additionalData, ImmutableList.copyOf(Iterables.concat(this.parameterTypes, ImmutableList.of(types))), this.expectType);
}
public ReflectionBuilder withExpectResult(Class<?> expectType) {
return new ReflectionBuilder(this.reflectionBasePackage, this.reflectionTopPackage, this.className, this.fieldName, this.methods, this.additionalData, this.parameterTypes, expectType);
}
protected String formatClass(String className) {
return switch (this.reflectionBasePackage) {
case MINECRAFT_SERVER, CRAFT_BUKKIT -> String.format(((this.reflectionBasePackage == ReflectionBasePackage.CRAFT_BUKKIT) ? this.reflectionBasePackage.getFixedPackageName() : this.reflectionBasePackage.getForCategory(this.reflectionTopPackage, this.additionalData)) + ".%s", className);
case DEFAULT -> className;
};
}
}
abstract class BaseReflection<T> {
protected final ReflectionBuilder reflectionBuilder;
protected Class<?> BUILDER_CLASS;
private T cached;
private boolean loaded = false;
protected BaseReflection(ReflectionBuilder reflectionBuilder) {
this.reflectionBuilder = reflectionBuilder;
for (String classes : reflectionBuilder.className) {
try {
this.BUILDER_CLASS = Class.forName(classes);
} catch (ClassNotFoundException ignored) {
}
}
}
public T load() {
return load(false);
}
public T load(boolean missAllowed) {
if (this.loaded) return this.cached;
try {
if (this.BUILDER_CLASS == null) throw new ClassNotFoundException("No class found: " + this.reflectionBuilder.className.toString());
T eval = (this.cached != null) ? this.cached : (this.cached = onLoad());
if (eval == null) throw new NullPointerException();
} catch (Throwable throwable) {
if (!missAllowed) {
log("Cache load failed!");
log("Class Names: " + this.reflectionBuilder.className.toString());
log("Loader Type: " + getClass().getCanonicalName());
log("Bukkit Version: " + Utils.BUKKIT_VERSION + " (" + Utils.getBukkitPackage() + ")");
log("Exception:");
throwable.printStackTrace();
}
}
this.loaded = true;
return this.cached;
}
private void log(String message) {
ZNPCsPlus.LOGGER.warning("[ReflectionCache] " + message);
}
protected abstract T onLoad() throws Exception;
public static class ClassReflection extends BaseReflection<Class<?>> {
public ClassReflection(ReflectionBuilder reflectionBuilder) {
super(reflectionBuilder);
}
protected Class<?> onLoad() {
return this.BUILDER_CLASS;
}
}
public static class MethodReflection extends BaseReflection<Method> {
public MethodReflection(ReflectionBuilder builder) {
super(builder);
}
protected Method onLoad() {
Method methodThis = null;
List<String> methods = this.reflectionBuilder.methods;
boolean hasExpectedType = (this.reflectionBuilder.expectType != null);
if (methods.isEmpty() && hasExpectedType) for (Method method : this.BUILDER_CLASS.getDeclaredMethods()) {
if (method.getReturnType() == this.reflectionBuilder.expectType) return method;
}
for (String methodName : this.reflectionBuilder.methods) try {
Method maybeGet;
if (!Iterables.isEmpty(this.reflectionBuilder.parameterTypes))
maybeGet = this.BUILDER_CLASS.getDeclaredMethod(methodName, Iterables.get(this.reflectionBuilder.parameterTypes, 0));
else maybeGet = this.BUILDER_CLASS.getDeclaredMethod(methodName);
if (this.reflectionBuilder.expectType != null && this.reflectionBuilder.expectType != maybeGet.getReturnType()) continue;
maybeGet.setAccessible(true);
methodThis = maybeGet;
} catch (NoSuchMethodException ignored) {}
return methodThis;
}
}
public static class FieldReflection extends BaseReflection<Field> {
public FieldReflection(ReflectionBuilder reflectionBuilder) {
super(reflectionBuilder);
}
protected Field onLoad() throws NoSuchFieldException {
if (this.reflectionBuilder.expectType != null)
for (Field field1 : this.BUILDER_CLASS.getDeclaredFields()) {
if (field1.getType() == this.reflectionBuilder.expectType) {
field1.setAccessible(true);
return field1;
}
}
Field field = this.BUILDER_CLASS.getDeclaredField(this.reflectionBuilder.fieldName);
field.setAccessible(true);
return field;
}
public AsValueField asValueField() {
return new AsValueField(this);
}
private static class AsValueField extends BaseReflection<Object> {
private final FieldReflection fieldReflection;
public AsValueField(FieldReflection fieldReflection) {
super(fieldReflection.reflectionBuilder);
this.fieldReflection = fieldReflection;
}
protected Object onLoad() throws IllegalAccessException, NoSuchFieldException {
Field field = this.fieldReflection.onLoad();
return field.get(null);
}
}
}
public static class ConstructorReflection extends BaseReflection<Constructor<?>> {
public ConstructorReflection(ReflectionBuilder reflectionBuilder) {
super(reflectionBuilder);
}
protected Constructor<?> onLoad() throws NoSuchMethodException {
Constructor<?> constructor = null;
if (Iterables.size(this.reflectionBuilder.parameterTypes) > 1) {
for (Class<?>[] keyParameters : this.reflectionBuilder.parameterTypes) try {
constructor = this.BUILDER_CLASS.getDeclaredConstructor(keyParameters);
} catch (NoSuchMethodException ignored) {}
} else constructor = (Iterables.size(this.reflectionBuilder.parameterTypes) > 0) ? this.BUILDER_CLASS.getDeclaredConstructor(Iterables.get(this.reflectionBuilder.parameterTypes, 0)) : this.BUILDER_CLASS.getDeclaredConstructor();
if (constructor != null) constructor.setAccessible(true);
return constructor;
}
}
public static class EnumReflection extends BaseReflection<Enum<?>[]> {
public EnumReflection(ReflectionBuilder reflectionBuilder) {
super(reflectionBuilder);
}
protected Enum<?>[] onLoad() {
Enum<?>[] arrayOfEnum = (Enum<?>[]) this.BUILDER_CLASS.getEnumConstants();
for (Enum<?> enumConstant : arrayOfEnum) TypeCache.ClassCache.register(enumConstant.name(), enumConstant, this.BUILDER_CLASS);
return arrayOfEnum;
}
}
}
}

@ -1,7 +1,7 @@
package io.github.znetworkw.znpcservers.user; package io.github.znetworkw.znpcservers.user;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import io.github.znetworkw.znpcservers.cache.CacheRegistry; import io.github.znetworkw.znpcservers.reflection.ReflectionCache;
import io.github.znetworkw.znpcservers.npc.NPC; import io.github.znetworkw.znpcservers.npc.NPC;
import io.github.znetworkw.znpcservers.npc.NPCAction; import io.github.znetworkw.znpcservers.npc.NPCAction;
import io.github.znetworkw.znpcservers.npc.event.ClickType; import io.github.znetworkw.znpcservers.npc.event.ClickType;
@ -41,9 +41,9 @@ public class ZUser {
this.lastClicked = new HashMap<>(); this.lastClicked = new HashMap<>();
this.eventServices = new ArrayList<>(); this.eventServices = new ArrayList<>();
try { try {
Object playerHandle = CacheRegistry.GET_HANDLE_PLAYER_METHOD.load().invoke(toPlayer()); Object playerHandle = ReflectionCache.GET_HANDLE_PLAYER_METHOD.load().invoke(toPlayer());
this.gameProfile = (GameProfile) CacheRegistry.GET_PROFILE_METHOD.load().invoke(playerHandle, new Object[0]); this.gameProfile = (GameProfile) ReflectionCache.GET_PROFILE_METHOD.load().invoke(playerHandle, new Object[0]);
this.playerConnection = CacheRegistry.PLAYER_CONNECTION_FIELD.load().get(playerHandle); this.playerConnection = ReflectionCache.PLAYER_CONNECTION_FIELD.load().get(playerHandle);
} catch (IllegalAccessException | InvocationTargetException e) { } catch (IllegalAccessException | InvocationTargetException e) {
throw new IllegalStateException("can't create user for player " + uuid.toString(), e.getCause()); throw new IllegalStateException("can't create user for player " + uuid.toString(), e.getCause());
} }
@ -77,7 +77,7 @@ public class ZUser {
private boolean tryRegisterChannel() { private boolean tryRegisterChannel() {
try { try {
Channel channel = (Channel) CacheRegistry.CHANNEL_FIELD.load().get(CacheRegistry.NETWORK_MANAGER_FIELD.load().get(this.playerConnection)); Channel channel = (Channel) ReflectionCache.CHANNEL_FIELD.load().get(ReflectionCache.NETWORK_MANAGER_FIELD.load().get(this.playerConnection));
if (channel.pipeline().names().contains("npc_interact")) channel.pipeline().remove("npc_interact"); if (channel.pipeline().names().contains("npc_interact")) channel.pipeline().remove("npc_interact");
channel.pipeline().addAfter("decoder", "npc_interact", new ZNPCSocketDecoder()); channel.pipeline().addAfter("decoder", "npc_interact", new ZNPCSocketDecoder());
return true; return true;
@ -137,11 +137,11 @@ public class ZUser {
class ZNPCSocketDecoder extends MessageToMessageDecoder<Object> { class ZNPCSocketDecoder extends MessageToMessageDecoder<Object> {
protected void decode(ChannelHandlerContext channelHandlerContext, Object packet, List<Object> out) throws Exception { protected void decode(ChannelHandlerContext channelHandlerContext, Object packet, List<Object> out) throws Exception {
out.add(packet); out.add(packet);
if (packet.getClass() == CacheRegistry.PACKET_PLAY_IN_USE_ENTITY_CLASS) { if (packet.getClass() == ReflectionCache.PACKET_PLAY_IN_USE_ENTITY_CLASS) {
long lastInteractNanos = System.nanoTime() - ZUser.this.lastInteract; long lastInteractNanos = System.nanoTime() - ZUser.this.lastInteract;
if (ZUser.this.lastInteract != 0L && lastInteractNanos < 1000000000L) if (ZUser.this.lastInteract != 0L && lastInteractNanos < 1000000000L)
return; return;
int entityId = CacheRegistry.PACKET_IN_USE_ENTITY_ID_FIELD.load().getInt(packet); int entityId = ReflectionCache.PACKET_IN_USE_ENTITY_ID_FIELD.load().getInt(packet);
NPC npc = NPC.all().stream().filter(npc1 -> (npc1.getEntityID() == entityId)).findFirst().orElse(null); NPC npc = NPC.all().stream().filter(npc1 -> (npc1.getEntityID() == entityId)).findFirst().orElse(null);
if (npc == null) if (npc == null)
return; return;

@ -1,6 +1,6 @@
package io.github.znetworkw.znpcservers.utility; package io.github.znetworkw.znpcservers.utility;
import io.github.znetworkw.znpcservers.cache.CacheRegistry; import io.github.znetworkw.znpcservers.reflection.ReflectionCache;
import io.github.znetworkw.znpcservers.configuration.ConfigurationConstants; import io.github.znetworkw.znpcservers.configuration.ConfigurationConstants;
import io.github.znetworkw.znpcservers.user.ZUser; import io.github.znetworkw.znpcservers.user.ZUser;
import me.clip.placeholderapi.PlaceholderAPI; import me.clip.placeholderapi.PlaceholderAPI;
@ -76,7 +76,7 @@ public final class Utils {
try { try {
for (Object packet : packets) { for (Object packet : packets) {
if (packet != null) if (packet != null)
CacheRegistry.SEND_PACKET_METHOD.load().invoke(user.getPlayerConnection(), packet); ReflectionCache.SEND_PACKET_METHOD.load().invoke(user.getPlayerConnection(), packet);
} }
} catch (IllegalAccessException | java.lang.reflect.InvocationTargetException e) { } catch (IllegalAccessException | java.lang.reflect.InvocationTargetException e) {
e.printStackTrace(); e.printStackTrace();