Package com.cryptomorin.xseries
Class ReflectionUtils
- java.lang.Object
-
- com.cryptomorin.xseries.ReflectionUtils
-
public final class ReflectionUtils extends Object
ReflectionUtils - Reflection handler for NMS and CraftBukkit.
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
- Version:
- 4.0.0
- Author:
- Crypto Morin
-
-
Field Summary
Fields Modifier and Type Field Description static String
CRAFTBUKKIT
Mojang remapped their NMS in 1.17 https://www.spigotmc.org/threads/spigot-bungeecord-1-17.510208/#post-4184317static String
NMS
Mojang remapped their NMS in 1.17 https://www.spigotmc.org/threads/spigot-bungeecord-1-17.510208/#post-4184317static int
VER
The raw minor version number.static String
VERSION
We use reflection mainly to avoid writing a new class for version barrier.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Class<?>
getArrayClass(String clazz, boolean nms)
static Object
getConnection(org.bukkit.entity.Player player)
static Class<?>
getCraftClass(String name)
Get a CraftBukkit (org.bukkit.craftbukkit) class.static Object
getHandle(org.bukkit.entity.Player player)
static Class<?>
getNMSClass(String name)
Get a NMS (net.minecraft.server) class.static Class<?>
getNMSClass(String newPackage, String name)
Get a NMS (net.minecraft.server) class which accepts a package for 1.17 compatibility.static CompletableFuture<Void>
sendPacket(org.bukkit.entity.Player player, Object... packets)
Sends a packet to the player asynchronously if they're online.static void
sendPacketSync(org.bukkit.entity.Player player, Object... packets)
Sends a packet to the player synchronously if they're online.static boolean
supports(int version)
Checks whether the server version is equal or greater than the given version.static Class<?>
toArrayClass(Class<?> clazz)
-
-
-
Field Detail
-
VERSION
public static final String 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_R1
but in 1.14 it's innet.minecraft.server.v1_14_R1
In order to maintain cross-version compatibility we cannot import these classes.Performance is not a concern for these specific statically initialized values.
-
VER
public static final int VER
The raw minor version number. E.g.v1_17_R1
to17
- Since:
- 4.0.0
-
CRAFTBUKKIT
public static final String CRAFTBUKKIT
Mojang remapped their NMS in 1.17 https://www.spigotmc.org/threads/spigot-bungeecord-1-17.510208/#post-4184317
-
NMS
public static final String NMS
Mojang remapped their NMS in 1.17 https://www.spigotmc.org/threads/spigot-bungeecord-1-17.510208/#post-4184317
-
-
Method Detail
-
supports
public static boolean supports(int version)
Checks whether the server version is equal or greater than the given version.- Parameters:
version
- the version to compare the server version with.- Returns:
- true if the version is equal or newer, otherwise false.
- Since:
- 4.0.0
-
getNMSClass
@Nullable public static Class<?> getNMSClass(@Nonnull String newPackage, @Nonnull String name)
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
@Nullable public static Class<?> getNMSClass(@Nonnull String name)
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
-
sendPacket
@Nonnull public static CompletableFuture<Void> sendPacket(@Nonnull org.bukkit.entity.Player player, @Nonnull Object... packets)
Sends a packet to the player asynchronously if they're online. Packets are thread-safe.- Parameters:
player
- the player to send the packet to.packets
- the packets to send.- Returns:
- the async thread handling the packet.
- Since:
- 1.0.0
- See Also:
sendPacketSync(Player, Object...)
-
sendPacketSync
public static void sendPacketSync(@Nonnull org.bukkit.entity.Player player, @Nonnull Object... packets)
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.- Since:
- 2.0.0
- See Also:
sendPacket(Player, Object...)
-
getConnection
@Nullable public static Object getConnection(@Nonnull org.bukkit.entity.Player player)
-
getCraftClass
@Nullable public static Class<?> getCraftClass(@Nonnull String name)
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
-
-