[API] ReflectionHelper
1.18.4-SNAPSHOTLibrary to easily access Classes, Fields & Methods using reflection
This 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
I enjoy making all of my plugins for free, but I need your help to keep them for free.
SlZOd2EkUm9kI1J3YW1GeUooVWtXa2QzZFdGPk4rSmFWelV3WVZoYWJHUiNSbk5hVnpVdytHMDVlVnAzUCswa0okUk1NMEp6WkZka2NHSnBPRDBrSiRSalIzZypXakpzZFZ7VyRtKmFiPmhzVytOJGNHIXlOVWxhVjNoM1dsaEpiV1J0Vm5sak1tKjJZbW93YkdSdFZubGpNbSoyWW1sVlAkUiNaPlFs
Links
Similar projects
Plugin →Let Me Despawn
Improves performance by tweaking mob despawn rules. Say bye to pesky unintentional persistent mobs.
26.2MSueta
JourneyMap
Real-time map used for mapping in-game or your browser as you explore.
15.6MSueta
Emotecraft
Create your own emotes in Minecraft.
7.9MSueta
Simple Tpa
A simple tpa plugin which sends requests
5.4MSueta
Common Network
Forge and Fabric Unified Networking Solution
4.7MSueta
Set Home
A lightweight plugin for players to set their homes.
3.8MSueta