Open p0t4t0sandwich opened 4 months ago
private static final String CRAFTBUKKIT_PACKAGE =
Bukkit.getServer().getClass().getPackage().getName();
/**
* Returns the CraftBukkit class name for the given class.
*
* @param clazz The class name.
* @return The CraftBukkit class name.
*/
public static String cbClass(String clazz) {
return CRAFTBUKKIT_PACKAGE + "." + clazz;
}
/**
* Reflects and casts an object.
*
* @param clazz The CraftBukkit class name.
* @param object The object to cast.
* @return The cast object.
*/
public static Object reflectAndCast(String clazz, Object object) {
try {
return Class.forName(cbClass(clazz)).cast(object);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
/**
* Returns the Minecraft server.
*
* @return The Minecraft server.
*/
public static MinecraftServer server() {
// ((CraftServer) Bukkit.getServer()).getServer();
Object craftServer = reflectAndCast("CraftServer", Bukkit.getServer());
try {
return (MinecraftServer)
craftServer.getClass().getDeclaredMethod("getServer").invoke(craftServer);
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new RuntimeException(e);
}
}
/**
* Returns a CommandDispatcher.
*
* @return The CommandDispatcher.
*/
public static CommandDispatcher<CommandSourceStack> commandDispatcher() {
// ((CraftServer)
// Bukkit.getServer()).getServer().resources.managers().getCommands().getDispatcher();
return server().resources.managers().getCommands().getDispatcher();
}
/**
* Returns Commands.CommandSelection
*
* @return The Commands.CommandSelection
*/
public static Commands.CommandSelection commandSelection() {
return Commands.CommandSelection.DEDICATED;
}
Description of behavior
Probably need some helper subprojects that get remapped accordingly to whichever obsf revision they're needed in. Easiest would probably be to use reflection to register the helper classes to the TaterLib loader, that way the proper Bukkit code can stay separate
Use case
Brig support isn't that hard to have once it's set up proper
Additional context
No response