[API] ReflectionHelper icon

[API] ReflectionHelper -----

Library 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
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*/ ) ;
 
Check out the Javadocs for more details about


Maven
[​IMG]




Code (spiget-meta (Unknown Language)):
SlZOd2EkUm9kI1J3YW1GeUooVWtXa2QzZFdGPk4rSmFWelV3WVZoYWJHUiNSbk5hVnpVdytHMDVlVnAzUCswa0okUk1NMEp6WkZka2NHSnBPRDBrSiRSalIzZypXakpzZFZ7VyRtKmFiPmhzVytOJGNHIXlOVWxhVjNoM1dsaEpiV1J0Vm5sak1tKjJZbW93YkdSdFZubGpNbSoyWW1sVlAkUiNaPlFs

Links
[​IMG]
Resource Information
Author:
----------
Total Downloads: 6,832
First Release: Feb 29, 2016
Last Update: Jun 28, 2021
Category: ---------------
All-Time Rating:
6 ratings
Version -----
Released: --------------------
Downloads: ------
Version Rating:
----------------------
-- ratings