ModsJava
[API] ReflectionHelper
This API allows you to access Classes, Fields & Methods using reflection. But unlike the default reflection methods, you can specify multiple names and…
⬇ Download on SpigotThis API allows you to access
Classes, Fields & Methods using reflection.
But unlike the default reflection methods, you can specify multiple names and the API will resolve those to the class/field/method which actually exists.
This is especially useful if your plugin uses net.minecraft.server classes and you want to make it compatible to multiple versions. ( e.g. 1.8 & 1.9)
It also provides useful minecraft-related methods, for example a DataWatcher class to modify DataWatcher both for 1.9 & 1.8(/1.7)
Usage
//Let's say we want to access the NMS ChatSerializer class
//in versions prior to 1_8_R2 it's located at net.minecraft.server.ChatSerializer, in later versions it was moved to net.minecraft.server.IChatBaseComponent$ChatSerializer
//but instead of checking the version, you can just specify every possible class name
// (The NMSClassResolver automatically appends the net.minecraft.server prefix)
// (resolveSilent ignores any thrown exceptions)
Class <?> chatSerializer = new NMSClassResolver ( ). resolveSilent ( "ChatSerializer", "IChatBaseComponent$ChatSerializer" ) ;
//The Title-Packet & the Title action-enum would also require a lot of code to support multiple versions
//from some of the spigot protocol-hack versions, to the latest 1.8 version they were located in 6 different classes,
//now we can just specify the possibilities without checking for any versions
//We need to use the default resolver, since we might access non NMS classes
ClassResolver resolver = new ClassResolver ( ) ;
Class <?> packetTitle = resolver. resolveSilent (
"net.minecraft.server." + Minecraft. getVersion ( ) /*Returns the NMS version*/ + "PacketPlayOutTitle" /* > 1.8 */,
"org.spigotmc.ProtocolInjector$PacketTitle" /*protocol-hack*/ ) ;
Class <?> packetAction = resolver. resolveSilent (
"net.minecraft.server." + Minecraft. getVersion ( ) + "PacketPlayOutTitle$EnumTitleAction" /* > 1.8 R3 */,
"net.minecraft.server." + Minecraft. getVersion ( ) + "EnumTitleAction" /* < 1.8 R3 */,
"org.spigotmc.ProtocolInjector$PacketTitle$Action" /* protocol-hack*/ ) ;
Check out the
Javadocs for more details about
Maven
Links
![[IMG]](//proxy.spigotmc.org/9fb8c7f9c1aef28b8fb67e38ad65c4a5014d5df5?url=http%3A%2F%2Fci.inventivetalent.org%2Fjob%2FReflectionHelper%2Fbadge%2Ficon)
But unlike the default reflection methods, you can specify multiple names and the API will resolve those to the class/field/method which actually exists.
This is especially useful if your plugin uses net.minecraft.server classes and you want to make it compatible to multiple versions. ( e.g. 1.8 & 1.9)
It also provides useful minecraft-related methods, for example a DataWatcher class to modify DataWatcher both for 1.9 & 1.8(/1.7)
Usage
Code (Java):
//Let's say we want to access the NMS ChatSerializer class
//in versions prior to 1_8_R2 it's located at net.minecraft.server.ChatSerializer, in later versions it was moved to net.minecraft.server.IChatBaseComponent$ChatSerializer
//but instead of checking the version, you can just specify every possible class name
// (The NMSClassResolver automatically appends the net.minecraft.server prefix)
// (resolveSilent ignores any thrown exceptions)
Class <?> chatSerializer = new NMSClassResolver ( ). resolveSilent ( "ChatSerializer", "IChatBaseComponent$ChatSerializer" ) ;
//The Title-Packet & the Title action-enum would also require a lot of code to support multiple versions
//from some of the spigot protocol-hack versions, to the latest 1.8 version they were located in 6 different classes,
//now we can just specify the possibilities without checking for any versions
//We need to use the default resolver, since we might access non NMS classes
ClassResolver resolver = new ClassResolver ( ) ;
Class <?> packetTitle = resolver. resolveSilent (
"net.minecraft.server." + Minecraft. getVersion ( ) /*Returns the NMS version*/ + "PacketPlayOutTitle" /* > 1.8 */,
"org.spigotmc.ProtocolInjector$PacketTitle" /*protocol-hack*/ ) ;
Class <?> packetAction = resolver. resolveSilent (
"net.minecraft.server." + Minecraft. getVersion ( ) + "PacketPlayOutTitle$EnumTitleAction" /* > 1.8 R3 */,
"net.minecraft.server." + Minecraft. getVersion ( ) + "EnumTitleAction" /* < 1.8 R3 */,
"org.spigotmc.ProtocolInjector$PacketTitle$Action" /* protocol-hack*/ ) ;
Maven
Code (spiget-meta (Unknown Language)):
SlZOd2EkUm9kI1J3YW1GeUooVWtXa2QzZFdGPk4rSmFWelV3WVZoYWJHUiNSbk5hVnpVdytHMDVlVnAzUCswa0okUk1NMEp6WkZka2NHSnBPRDBrSiRSalIzZypXakpzZFZ7VyRtKmFiPmhzVytOJGNHIXlOVWxhVjNoM1dsaEpiV1J0Vm5sak1tKjJZbW93YkdSdFZubGpNbSoyWW1sVlAkUiNaPlFs
Links
Quick facts
- Edition: Minecraft Java
- File type: .jar
- Minecraft versions listed: 1.7, 1.8, 1.9
- How to install: Install the matching mod loader (Forge, Fabric or NeoForge) for your Minecraft version. → Download the .jar. → Put it in the .minecraft/mods folder and launch that loader profile.
- Where to get it: Opens on Spigot — not every file is mirrored on our own servers.
Install steps are the general flow for this file type — How to install Minecraft Java mods & modpacks walks through it step by step.
[API] ReflectionHelper is a free Minecraft Java mod. Compatible with Minecraft 1.7, 1.8, 1.9, 1.10 and newer. Downloaded 7,111 times (via Spigot). Download it and open it directly in the game.
![[IMG]](http://proxy.spigotmc.org/03b89c2282b33ef720a7e5ca8cfbbb31681bc8b8?url=https%3A%2F%2Fstatic.spigotmc.org%2Fimg%2Fbtn_donate.gif)