跨實施版本訪問 NMS

// gets the Class objects from the net.mminecraft.server package with the given name
public Class<?> getNmsClass(String name) throws ClassNotFoundException {
    // explode the Server interface implementation's package name into its components
    String[] packageArray = Bukkit.getServer().getClass().getPackage().getName().split("\\.");

    // pick out the component representing the package version if it's present
    String packageVersion = array.length == 4 ? array[3] + "." : "";

    // construct the qualified class name from the obtained package version
    String qualName = "net.minecraft.server." + packageVersion + name;

    // simple call to get the Class object
    return Class.forName(qualName);
}