Solved Dynamic Class Loading

Discussion in 'Plugin Development' started by thebiologist13, Feb 15, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    thebiologist13

    Hello All!

    One of my plugins uses NMS and CraftBukkit code in it, so the package names change each update. This is troublesome for me because it makes the plugin not work on versions of Bukkit other than the one I built it for (for example, net.minecraft.server.v1_4_5 changed to net.minecraft.server.v1_4_R1).

    Is there a way I can dynamically load the classes I need across versions of Bukkit even when the package name changes? Or is this against the plugin submission rules?

    Thanks in advance!
    ~thebiologist13
     
  2. Offline

    Comphenix

    There's a limit to what kind of crazy scheme you can employ to circumvent the package versioning safeguard, which would certainly include dynamic meta-programming.

    I'm assuming you're referring to your CustomSpawners plugin.

    In any case, what you CAN do, is either:
    • Use Maven modules to compile multiple packages of the classes that use native NMS, each with support for a particular version. Then you select the correct package at runtime.
    • You could also use reflection throughout, but it's a lot of work and it may cost you a bit in terms of performance.
    • Use a third-party plugin that already supports multiple versions of CraftBukkit. For instance, if you need a NBT library, you can use ProtocolLib's NBT wrappers and use reflection for everything else.
    • Lobby the Bukkit team to create an official API for whatever you're using NMS to accomplish. Remember, they will never expose raw NBT as it's considered an internal implementation detail of Minecraft and not suited for the API. You'll have to make a case (or submit as a PR) for a proper API that allows you to set or get the settings/information you need in a series of Java beans/standard patterns.
     
  3. Offline

    thebiologist13

    Thanks so much for the reply! It was very helpful. I am considering submitting a PR, but I've never submitted one before. What would be involved in submitting one? Also, by Java beans/standard patterns, do you mean reliable methods/classes to get and set the information?

    Thanks! :D
    ~thebiologist13
     
  4. Offline

    Comphenix

    Well, you certainly have to prove there's a use case for it, and submit a single clean commit that is consistent with the coding style and patterns of the CraftBukkit project.

    Essentially, yes. Think of ItemMeta - it was introduced to replace the old method of modifying the NBT data in memory, and instead provides simple get- and set-methods for each property (like item name and lore). It really depends on the specifics.

    Also, I'd recommend asking anyone associated with the team before you start writing the PR. It's better for your proposal to be rejected now than after you've put many hours into writing it. You can find them on the IRC channel.
     
  5. Offline

    thebiologist13

    Alright, thanks a ton for your reply! It helped a bunch :)

    ~thebiologist13
     
Thread Status:
Not open for further replies.

Share This Page