Package com.comphenix.protocol.utility
Class MinecraftReflection
java.lang.Object
com.comphenix.protocol.utility.MinecraftReflection
Methods and constants specifically used in conjuction with reflecting Minecraft object.
- Author:
- Kristian
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic StringDeprecated.static ReportTypestatic ReportTypestatic ReportType -
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?>getArrayClass(Class<?> componentType)Retrieve the array class of a given component type.static Class<?>static Class<?>Retrieve the attribute modifier class.static Class<?>Retrieve the attribute snapshot class.static Class<?>Retrieve the Block (NMS) class.static Class<?>Retrieves the BlockPosition class.static ObjectgetBukkitEntity(Object nmsObject)Dynamically retrieve the Bukkit entity from a given entity.static org.bukkit.inventory.ItemStackgetBukkitItemStack(Object generic)Retrieves the Bukkit equivalent of a NMS ItemStack.static Class<?>static Class<?>Retrieve the NMS chat component text class.static Class<?>static Class<?>Attempt to find the ChatSerializer class.static Class<?>Retrieve the ChunkCoordinates class.static Class<?>Retrieve the ChunkCoordIntPair class.static Class<?>Retrieves the ChunkPosition class.static Class<?>static Class<?>getCraftBukkitClass(String className)Retrieve the class object of a specific CraftBukkit class.static StringRetrieve the name of the root CraftBukkit package.static Class<?>Retrieve the CraftChatMessage in Minecraft 1.7.2.static Class<?>Retrieve the CraftEntity class.static Class<?>Retrieve the CraftItemStack class.static Class<?>Retrieve the CraftChatMessage introduced in 1.7.2static Class<?>Retrieve the CraftPlayer class.static Class<?>static Class<?>Retrieve the CraftWorld class.static Class<?>Retrieve the DataWatcher class.static Class<?>Retrieve the DataWatcher Item class.static Class<?>static Class<?>static Class<?>static Class<?>static Class<?>Retrieve the entity (NMS) class.static Class<?>Retrieve the EntityHuman class.static Class<?>Retrieve the EntityPlayer (NMS) class.static Class<?>Retrieve the EntityTracker (NMS) class.static Class<?>static MethodAccessorGet a method accessor to get the actual use action out of the wrapping EnumEntityUseAction in 1.17.static Class<?>Retrieves the entity use action class in 1.17.static Class<?>Retrieve the EnumProtocol class in 1.7.2.static Class<?>getFastUtilClass(String className)static Class<?>static Class<?>Retrieve the GameProfile class in 1.7.2 and later.static Class<?>Retrieve the PacketPlayOutGameStateChange.a class, aka GameState in 1.16static FieldAccessorgetHandEntityUseActionEnumFieldAccessor(Object enumEntityUseAction)Get a field accessor for the hand in the wrapping EnumEntityUseAction in 1.17.static Class<?>Retrieve the IBlockData class in 1.8.static Class<?>static Class<?>Retrieve the IChatBaseComponent class.static Class<?>static Class<?>static Class<?>Retrieve the IntHashMap class.static Class<?>static Class<?>static Class<?>Retrieve the ItemStack[] class.static Class<?>Retrieve the NMS ItemStack class.static Class<?>static Class<?>getMinecraftClass(String className)Retrieve the class object of a specific Minecraft class.static Class<?>getMinecraftClass(String className, String... aliases)Retrieve the first class that matches a specified Minecraft name.static Class<?>Retrieve the Gson class used by Minecraft.static ObjectgetMinecraftItemStack(org.bukkit.inventory.ItemStack specific)Retrieves the NMS equivalent of a Bukkit ItemStack.static Class<?>static Class<?>getMinecraftLibraryClass(String className)Retrieve the class object of a specific Minecraft library class.static AbstractFuzzyMatcher<Class<?>>Retrieve a abstract fuzzy class matcher for Minecraft objects.static StringRetrieve a regular expression that can match Minecraft package objects.static StringRetrieve the name of the Minecraft server package.static Class<?>Retrieve the MinecraftServer class.static Class<?>Retrieve the net.minecraft.server.MobEffect class.static Class<?>static Class<?>Retrieve the MultiBlockChangeInfo array class in 1.8.static Class<?>Retrieve the MultiBlockChangeInfo class in 1.8.static Class<?>Retrieve the NBT base class.static Class<?>Retrieve the NBT Compound class.static Class<?>Retrieve the NBTCompressedStreamTools class.static Class<?>Retrieve the NBT read limiter class.static Class<?>static Class<?>Retrieve the NetHandler class (or Connection)static Class<?>Retrieve the NetLoginHandler class (or PendingConnection)static StringDynamically retrieve the name of the current NetLoginHandler.static Class<?>Retrieve the NetworkManager class or its interface.static StringDynamically retrieve the NetworkManager name.static Class<?>Retrieve the World (NMS) class.static Class<?>static MethodAccessorstatic Class<?>getNullableNMS(String className, String... aliases)static StringRetrieve the package version of the underlying CraftBukkit server.static Class<?>Retrieve the packet class.static ObjectgetPacketDataSerializer(Object buffer)Retrieve an instance of the packet data serializer wrapper.static Class<?>Retrieve the packet data serializer class that overrides ByteBuf.static Class<?>static Class<?>static Class<?>static Class<?>Retrieve the PlayerConnection class (or NetServerHandler)static Class<?>Retrieve the PlayerInfoData class in 1.8.static Class<?>Retrieve the player list class (or ServerConfigurationManager),static Class<?>static Class<?>static Class<?>static Class<?>Retrieve the ServerConnection abstract class.static Class<?>Retrieve the ServerPing class in Minecraft 1.7.2.static Class<?>Retrieve the ServerPingPlayerSample class in Minecraft 1.7.2.static Class<?>Retrieve the ServerPingServerData class in Minecraft 1.7.2.static Class<?>static Class<?>Retrieve the NMS statistics class.static Class<?>Retrieve the NMS statistic list class.static Class<?>Retrieve the NMS tile entity class.static Class<?>Retrieves the Vec3D class.static FieldAccessorgetVec3EntityUseActionEnumFieldAccessor(Object enumEntityUseAction)Get a field accessor for the vec3d in the wrapping EnumEntityUseAction in 1.17.static Class<?>Retrieve the WatchableObject class.static Class<?>Retrieve the WorldServer (NMS) class.static Class<?>Retrieve the WorldType class.static booleanEquivalent tois(Class, Object)but we don't call getClass againstatic booleanDetermine if a given Object is compatible with a given Class.static booleanisBlockPosition(Object obj)Determine if a given object is a BlockPosition.static booleanisChunkCoordinates(Object obj)Determine if a given object is a ChunkCoordinate.static booleanisChunkCoordIntPair(Object obj)Determine if the given object is an NMS ChunkCoordIntPar.static booleanisChunkPosition(Object obj)Determine if a given object is a ChunkPosition.static booleanisCraftItemStack(Object obj)Determine if the given object is a CraftItemStack instancey.static booleanisCraftPlayer(Object value)Determine if the given object is a CraftPlayer class.static booleanisDataWatcher(Object obj)Determine if the given object is a data watcher object.static booleanisIntHashMap(Object obj)Determine if the given object is an IntHashMap object.static booleanisItemStack(Object value)Determine if the given object is a NMS ItemStack.static booleanisLoginHandler(Object obj)Determine if the given object is a NetLoginHandler (PendingConnection)static booleanisMinecraftClass(Class<?> clazz)Determine if the given class is found within the package net.minecraft.server, or any equivalent package.static booleanisMinecraftEntity(Object obj)Determine if the given object is actually a Minecraft packet.static booleanisMinecraftObject(Object obj)Determine if a given object can be found within the package net.minecraft.server.static booleanisMinecraftObject(Object obj, String className)Determine if a given object is found in net.minecraft.server, and has the given name.static booleanisMinecraftPlayer(Object obj)Determine if the given object is a Minecraft player entity.static booleanisPacketClass(Object obj)Determine if the given object is actually a Minecraft packet.static booleanisPlayerInfoData(Object obj)Determine if the given object is a PlayerInfoData.static booleanisServerHandler(Object obj)Determine if the given object is assignable to a NetServerHandler (PlayerConnection)static booleanDetermine if this Minecraft version is using Netty.static booleanisWatchableObject(Object obj)Determine if the given object is a watchable object.static voidsetMinecraftPackage(String minecraftPackage, String craftBukkitPackage)Used during debugging and testing.static booleanstatic boolean
-
Field Details
-
REPORT_CANNOT_FIND_MCPC_REMAPPER
-
REPORT_CANNOT_LOAD_CPC_REMAPPER
-
REPORT_NON_CRAFTBUKKIT_LIBRARY_PACKAGE
-
MINECRAFT_OBJECT
Deprecated.Regular expression that matches a Minecraft object.Replaced by the method
getMinecraftObjectRegex().- See Also:
- Constant Field Values
-
-
Method Details
-
getMinecraftObjectRegex
Retrieve a regular expression that can match Minecraft package objects.- Returns:
- Minecraft package matcher.
-
getMinecraftObjectMatcher
Retrieve a abstract fuzzy class matcher for Minecraft objects.- Returns:
- A matcher for Minecraft objects.
-
getMinecraftPackage
Retrieve the name of the Minecraft server package.- Returns:
- Full canonical name of the Minecraft server package.
-
getPackageVersion
Retrieve the package version of the underlying CraftBukkit server.- Returns:
- The package version, or NULL if not applicable (before 1.4.6).
-
setMinecraftPackage
Used during debugging and testing.- Parameters:
minecraftPackage- - the current Minecraft package.craftBukkitPackage- - the current CraftBukkit package.
-
getCraftBukkitPackage
Retrieve the name of the root CraftBukkit package.- Returns:
- Full canonical name of the root CraftBukkit package.
-
getBukkitEntity
Dynamically retrieve the Bukkit entity from a given entity.- Parameters:
nmsObject- - the NMS entity.- Returns:
- A bukkit entity.
- Throws:
RuntimeException- If we were unable to retrieve the Bukkit entity.
-
isMinecraftObject
Determine if a given object can be found within the package net.minecraft.server.- Parameters:
obj- - the object to test.- Returns:
- TRUE if it can, FALSE otherwise.
-
isMinecraftClass
Determine if the given class is found within the package net.minecraft.server, or any equivalent package.- Parameters:
clazz- - the class to test.- Returns:
- TRUE if it can, FALSE otherwise.
-
isMinecraftObject
Determine if a given object is found in net.minecraft.server, and has the given name.- Parameters:
obj- - the object to test.className- - the class name to test.- Returns:
- TRUE if it can, FALSE otherwise.
-
is
Determine if a given Object is compatible with a given Class. That is, whether or not the Object is an instance of that Class or one of its subclasses. If either is null, false is returned.- Parameters:
clazz- Class to test for, may be nullobject- the Object to test, may be null- Returns:
- True if it is, false if not
- See Also:
Class.isAssignableFrom(Class)
-
is
Equivalent tois(Class, Object)but we don't call getClass again -
isChunkPosition
Determine if a given object is a ChunkPosition.- Parameters:
obj- - the object to test.- Returns:
- TRUE if it can, FALSE otherwise.
-
isBlockPosition
Determine if a given object is a BlockPosition.- Parameters:
obj- - the object to test.- Returns:
- TRUE if it can, FALSE otherwise.
-
isChunkCoordIntPair
Determine if the given object is an NMS ChunkCoordIntPar.- Parameters:
obj- - the object.- Returns:
- TRUE if it can, FALSE otherwise.
-
isChunkCoordinates
Determine if a given object is a ChunkCoordinate.- Parameters:
obj- - the object to test.- Returns:
- TRUE if it can, FALSE otherwise.
-
isPacketClass
Determine if the given object is actually a Minecraft packet.- Parameters:
obj- - the given object.- Returns:
- TRUE if it is, FALSE otherwise.
-
isLoginHandler
Determine if the given object is a NetLoginHandler (PendingConnection)- Parameters:
obj- - the given object.- Returns:
- TRUE if it is, FALSE otherwise.
-
isServerHandler
Determine if the given object is assignable to a NetServerHandler (PlayerConnection)- Parameters:
obj- - the given object.- Returns:
- TRUE if it is, FALSE otherwise.
-
isMinecraftEntity
Determine if the given object is actually a Minecraft packet.- Parameters:
obj- - the given object.- Returns:
- TRUE if it is, FALSE otherwise.
-
isItemStack
Determine if the given object is a NMS ItemStack.- Parameters:
value- - the given object.- Returns:
- TRUE if it is, FALSE otherwise.
-
isCraftPlayer
Determine if the given object is a CraftPlayer class.- Parameters:
value- - the given object.- Returns:
- TRUE if it is, FALSE otherwise.
-
isMinecraftPlayer
Determine if the given object is a Minecraft player entity.- Parameters:
obj- - the given object.- Returns:
- TRUE if it is, FALSE otherwise.
-
isWatchableObject
Determine if the given object is a watchable object.- Parameters:
obj- - the given object.- Returns:
- TRUE if it is, FALSE otherwise.
-
isDataWatcher
Determine if the given object is a data watcher object.- Parameters:
obj- - the given object.- Returns:
- TRUE if it is, FALSE otherwise.
-
isIntHashMap
Determine if the given object is an IntHashMap object.- Parameters:
obj- - the given object.- Returns:
- TRUE if it is, FALSE otherwise.
-
isCraftItemStack
Determine if the given object is a CraftItemStack instancey.- Parameters:
obj- - the given object.- Returns:
- TRUE if it is, FALSE otherwise.
-
getEntityPlayerClass
Retrieve the EntityPlayer (NMS) class.- Returns:
- The entity class.
-
getEntityHumanClass
Retrieve the EntityHuman class.- Returns:
- The entity human class.
-
getGameProfileClass
Retrieve the GameProfile class in 1.7.2 and later.- Returns:
- The game profile class.
- Throws:
IllegalStateException- If we are running 1.6.4 or earlier.
-
getEntityClass
Retrieve the entity (NMS) class.- Returns:
- The entity class.
-
getCraftChatMessage
Retrieve the CraftChatMessage in Minecraft 1.7.2.- Returns:
- The CraftChatMessage class.
-
getWorldServerClass
Retrieve the WorldServer (NMS) class.- Returns:
- The WorldServer class.
-
getNmsWorldClass
Retrieve the World (NMS) class.- Returns:
- The world class.
-
getPacketClass
Retrieve the packet class.- Returns:
- The packet class.
-
getByteBufClass
-
getEnumProtocolClass
Retrieve the EnumProtocol class in 1.7.2.- Returns:
- The Enum protocol class.
-
getIChatBaseComponentClass
Retrieve the IChatBaseComponent class.- Returns:
- The IChatBaseComponent.
-
getIChatBaseComponentArrayClass
-
getChatComponentTextClass
Retrieve the NMS chat component text class.- Returns:
- The chat component class.
-
getChatSerializerClass
Attempt to find the ChatSerializer class.- Returns:
- The serializer class.
- Throws:
IllegalStateException- If the class could not be found or deduced.
-
getServerPingClass
Retrieve the ServerPing class in Minecraft 1.7.2.- Returns:
- The ServerPing class.
-
getServerPingServerDataClass
Retrieve the ServerPingServerData class in Minecraft 1.7.2.- Returns:
- The ServerPingServerData class.
-
getServerPingPlayerSampleClass
Retrieve the ServerPingPlayerSample class in Minecraft 1.7.2.- Returns:
- The ServerPingPlayerSample class.
-
isUsingNetty
public static boolean isUsingNetty()Determine if this Minecraft version is using Netty.Spigot is ignored in this consideration.
- Returns:
- TRUE if it does, FALSE otherwise.
-
getMinecraftServerClass
Retrieve the MinecraftServer class.- Returns:
- MinecraftServer class.
-
getStatisticClass
Retrieve the NMS statistics class.- Returns:
- The statistics class.
-
getStatisticListClass
Retrieve the NMS statistic list class.- Returns:
- The statistic list class.
-
getPlayerListClass
Retrieve the player list class (or ServerConfigurationManager),- Returns:
- The player list class.
-
getNetLoginHandlerClass
Retrieve the NetLoginHandler class (or PendingConnection)- Returns:
- The NetLoginHandler class.
-
getPlayerConnectionClass
Retrieve the PlayerConnection class (or NetServerHandler)- Returns:
- The PlayerConnection class.
-
getNetworkManagerClass
Retrieve the NetworkManager class or its interface.- Returns:
- The NetworkManager class or its interface.
-
getNetHandlerClass
Retrieve the NetHandler class (or Connection)- Returns:
- The NetHandler class.
-
getItemStackClass
Retrieve the NMS ItemStack class.- Returns:
- The ItemStack class.
-
getBlockClass
Retrieve the Block (NMS) class.- Returns:
- Block (NMS) class.
-
getItemClass
-
getFluidTypeClass
-
getParticleTypeClass
-
getWorldTypeClass
Retrieve the WorldType class.- Returns:
- The WorldType class.
-
getDataWatcherClass
Retrieve the DataWatcher class.- Returns:
- The DataWatcher class.
-
getChunkPositionClass
Retrieves the ChunkPosition class.- Returns:
- The ChunkPosition class.
-
getBlockPositionClass
Retrieves the BlockPosition class.- Returns:
- The BlockPosition class.
-
getVec3DClass
Retrieves the Vec3D class.- Returns:
- The Vec3D class.
-
getChunkCoordinatesClass
Retrieve the ChunkCoordinates class.- Returns:
- The ChunkPosition class.
-
getChunkCoordIntPair
Retrieve the ChunkCoordIntPair class.- Returns:
- The ChunkCoordIntPair class.
-
getWatchableObjectClass
Retrieve the WatchableObject class. Replaced bygetDataWatcherItemClass()- Returns:
- The WatchableObject class.
-
getDataWatcherItemClass
Retrieve the DataWatcher Item class.- Returns:
- The class
-
getDataWatcherObjectClass
-
watcherObjectExists
public static boolean watcherObjectExists() -
getDataWatcherSerializerClass
-
getDataWatcherRegistryClass
-
getMinecraftKeyClass
-
getMobEffectListClass
-
getSoundEffectClass
-
getServerConnectionClass
Retrieve the ServerConnection abstract class.- Returns:
- The ServerConnection class.
-
getNBTBaseClass
Retrieve the NBT base class.- Returns:
- The NBT base class.
-
getNBTReadLimiterClass
Retrieve the NBT read limiter class.This is only supported in 1.7.8 (released 2014) and higher.
- Returns:
- The NBT read limiter.
-
getNBTCompoundClass
Retrieve the NBT Compound class.- Returns:
- The NBT Compond class.
-
getEntityTrackerClass
Retrieve the EntityTracker (NMS) class.- Returns:
- EntityTracker class.
-
getAttributeSnapshotClass
Retrieve the attribute snapshot class.This stores the final value of an attribute, along with all the associated computational steps.
- Returns:
- The attribute snapshot class.
-
getIntHashMapClass
Retrieve the IntHashMap class.- Returns:
- IntHashMap class.
-
getAttributeModifierClass
Retrieve the attribute modifier class.- Returns:
- Attribute modifier class.
-
getMobEffectClass
Retrieve the net.minecraft.server.MobEffect class.- Returns:
- The mob effect class.
-
getPacketDataSerializerClass
Retrieve the packet data serializer class that overrides ByteBuf.- Returns:
- The data serializer class.
-
getNbtCompressedStreamToolsClass
Retrieve the NBTCompressedStreamTools class.- Returns:
- The NBTCompressedStreamTools class.
-
getTileEntityClass
Retrieve the NMS tile entity class.- Returns:
- The tile entity class.
-
getMinecraftGsonClass
Retrieve the Gson class used by Minecraft.- Returns:
- The Gson class.
-
getItemStackArrayClass
Retrieve the ItemStack[] class.- Returns:
- The ItemStack[] class.
-
getArrayClass
Retrieve the array class of a given component type.- Parameters:
componentType- - type of each element in the array.- Returns:
- The class of the array.
-
getCraftItemStackClass
Retrieve the CraftItemStack class.- Returns:
- The CraftItemStack class.
-
getCraftPlayerClass
Retrieve the CraftPlayer class.- Returns:
- CraftPlayer class.
-
getCraftWorldClass
Retrieve the CraftWorld class.- Returns:
- The CraftWorld class.
-
getCraftEntityClass
Retrieve the CraftEntity class.- Returns:
- CraftEntity class.
-
getCraftMessageClass
Retrieve the CraftChatMessage introduced in 1.7.2- Returns:
- The CraftChatMessage class.
-
getPlayerInfoDataClass
Retrieve the PlayerInfoData class in 1.8.- Returns:
- The PlayerInfoData class
-
getEnumEntityUseActionClass
Retrieves the entity use action class in 1.17.- Returns:
- The EntityUseAction class
-
getEntityUseActionEnumMethodAccessor
Get a method accessor to get the actual use action out of the wrapping EnumEntityUseAction in 1.17.- Returns:
- a method accessor to get the actual use action
-
getHandEntityUseActionEnumFieldAccessor
Get a field accessor for the hand in the wrapping EnumEntityUseAction in 1.17.- Parameters:
enumEntityUseAction- the object instance of the action, the field is not present in attack.- Returns:
- a field accessor for the hand in the wrapping EnumEntityUseAction
-
getVec3EntityUseActionEnumFieldAccessor
Get a field accessor for the vec3d in the wrapping EnumEntityUseAction in 1.17.- Parameters:
enumEntityUseAction- the object instance of the action, the field is not present in attack.- Returns:
- a field accessor for the hand in the wrapping EnumEntityUseAction
-
isPlayerInfoData
Determine if the given object is a PlayerInfoData.- Parameters:
obj- - the given object.- Returns:
- TRUE if it is, FALSE otherwise.
-
getIBlockDataClass
Retrieve the IBlockData class in 1.8.- Returns:
- The IBlockData class
-
getMultiBlockChangeInfoClass
Retrieve the MultiBlockChangeInfo class in 1.8.- Returns:
- The MultiBlockChangeInfo class
-
getMultiBlockChangeInfoArrayClass
Retrieve the MultiBlockChangeInfo array class in 1.8.- Returns:
- The MultiBlockChangeInfo array class
-
getGameStateClass
Retrieve the PacketPlayOutGameStateChange.a class, aka GameState in 1.16- Returns:
- The GameState class
-
signUpdateExists
public static boolean signUpdateExists() -
getNonNullListClass
-
getNonNullListCreateAccessor
-
getCraftSoundClass
-
getSectionPositionClass
-
getBukkitItemStack
Retrieves the Bukkit equivalent of a NMS ItemStack. This method should preserve NBT data and will never return null when supplied with a valid ItemStack. Empty ItemStacks are treated as AIR.- Parameters:
generic- NMS ItemStack- Returns:
- The Bukkit equivalent
-
getMinecraftItemStack
Retrieves the NMS equivalent of a Bukkit ItemStack. This method will never return null and should preserve NBT data. Null inputs are treated as empty (AIR) ItemStacks.- Parameters:
specific- Bukkit ItemStack- Returns:
- The NMS equivalent
-
getCraftBukkitClass
Retrieve the class object of a specific CraftBukkit class.- Parameters:
className- - the specific CraftBukkit class.- Returns:
- Class object.
- Throws:
RuntimeException- If we are unable to find the given class.
-
getMinecraftClass
Retrieve the class object of a specific Minecraft class.- Parameters:
className- - the specific Minecraft class.- Returns:
- Class object.
- Throws:
RuntimeException- If we are unable to find the given class.
-
getNullableNMS
-
getMinecraftClass
Retrieve the first class that matches a specified Minecraft name.- Parameters:
className- - the specific Minecraft class.aliases- - alternative names for this Minecraft class.- Returns:
- Class object.
- Throws:
RuntimeException- If we are unable to find any of the given classes.
-
getMinecraftLibraryClass
Retrieve the class object of a specific Minecraft library class.- Parameters:
className- - the specific library Minecraft class.- Returns:
- Class object.
- Throws:
RuntimeException- If we are unable to find the given class.
-
getNetworkManagerName
Dynamically retrieve the NetworkManager name.- Returns:
- Name of the NetworkManager class.
-
getNetLoginHandlerName
Dynamically retrieve the name of the current NetLoginHandler.- Returns:
- Name of the NetLoginHandler class.
-
getPacketDataSerializer
Retrieve an instance of the packet data serializer wrapper.- Parameters:
buffer- - the buffer.- Returns:
- The instance.
-
getNbtTagTypes
-
getChatDeserializer
-
getDimensionManager
-
getMerchantRecipeList
-
getResourceKey
-
getEntityTypes
-
getParticleParam
-
getSectionPosition
-
getChunkProviderServer
-
getPlayerChunkMap
-
getIRegistry
-
getAttributeBase
-
getFastUtilClass
-
getInt2ObjectMapClass
-
getIntArrayListClass
-