Class ReflectionUtils
Caches the packet related methods and is asynchronous.
This class does not handle null checks as most of the requests are from the other utility classes that already handle null checks.
Clientbound Packets are considered fake updates to the client without changing the actual data. Since all the data is handled by the server.
A useful resource used to compare mappings is Mini's Mapping Viewer
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Class<?> The class for the NMS CraftPlayer.static final StringMojang remapped their NMS in 1.17: Spigot Threadstatic final Class<?> The class for the NMS EntityPlayer.static final MethodHandleResponsible for getting the NMS handlerEntityPlayerobject for the player.static final intThe raw minor version number.static final Stringstatic final StringWe use reflection mainly to avoid writing a new class for version barrier.static final intThe raw patch version number. -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable Class<?> getCraftClass(String name) Get a CraftBukkit (org.bukkit.craftbukkit) class.static ObjectgetEntityPlayer(Object craftPlayer) static @Nullable Class<?> getNMSClass(String name) Get a NMS (net.minecraft.server) class.static @Nullable Class<?> getNMSClass(String newPackage, String name) Get a NMS (net.minecraft.server) class which accepts a package for 1.17 compatibility.static StringGets the full version information of the server.static voidsendPacketSync(org.bukkit.entity.Player player, Object... packets) Sends a packet to the player synchronously if they're online.static booleanstatic <T> ReflectionUtils.VersionHandler<T> v(int minor, int patch, T handle) This method is purely for readability.static <T> ReflectionUtils.VersionHandler<T> v(int version, T handle) This method is purely for readability.
-
Field Details
-
NMS_VERSION
We use reflection mainly to avoid writing a new class for version barrier. The version barrier is for NMS that uses the Minecraft version as the main package name.E.g. EntityPlayer in 1.15 is in the class
net.minecraft.server.v1_15_R1but in 1.14 it's innet.minecraft.server.v1_14_R1In order to maintain cross-version compatibility we cannot import these classes.Performance is not a concern for these specific statically initialized values.
-
MINOR_NUMBER
public static final int MINOR_NUMBERThe raw minor version number. E.g.v1_17_R1to17- Since:
- 4.0.0
- See Also:
-
PATCH_NUMBER
public static final int PATCH_NUMBERThe raw patch version number. E.g.v1_17_R1to1I'd not recommend developers to support individual patches at all. You should always support the latest patch. For example, between v1.14.0, v1.14.1, v1.14.2, v1.14.3 and v1.14.4 you should only support v1.14.4
This can be used to warn server owners when your plugin will break on older patches.
- Since:
- 7.0.0
-
CRAFTBUKKIT_PACKAGE
Mojang remapped their NMS in 1.17: Spigot Thread -
NMS_PACKAGE
-
GET_HANDLE
Responsible for getting the NMS handlerEntityPlayerobject for the player.CraftPlayeris simply a wrapper forEntityPlayer. Used mainly for handling packet related operations.This is also where the famous player
pingfield comes from! -
CRAFT_PLAYER
The class for the NMS CraftPlayer. -
ENTITY_PLAYER
The class for the NMS EntityPlayer.
-
-
Method Details
-
getVersionInformation
Gets the full version information of the server. Useful for including in errors.- Since:
- 7.0.0
-
supportsMC1202
public static boolean supportsMC1202() -
v
This method is purely for readability. No performance is gained.- Since:
- 3.3.0
-
v
This method is purely for readability. No performance is gained.- Since:
- 5.0.0
-
getNMSClass
Get a NMS (net.minecraft.server) class which accepts a package for 1.17 compatibility.- Parameters:
newPackage- the 1.17 package name.name- the name of the class.- Returns:
- the NMS class or null if not found.
- Since:
- 4.0.0
-
getNMSClass
Get a NMS (net.minecraft.server) class.- Parameters:
name- the name of the class.- Returns:
- the NMS class or null if not found.
- Since:
- 1.0.0
-
getEntityPlayer
- Throws:
Throwable
-
sendPacketSync
public static void sendPacketSync(org.bukkit.entity.Player player, Object... packets) throws Throwable Sends a packet to the player synchronously if they're online.- Parameters:
player- the player to send the packet to.packets- the packets to send.- Throws:
Throwable- Since:
- 2.0.0
-
getCraftClass
Get a CraftBukkit (org.bukkit.craftbukkit) class.- Parameters:
name- the name of the class to load.- Returns:
- the CraftBukkit class or null if not found.
- Since:
- 1.0.0
-