net.minecraft.server version

Discussion in 'Plugin Development' started by Skionz, Aug 29, 2014.

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

    Skionz

    So I found this snippet on google that displays the version of bukkit the server is running and I am trying to make it so my particles don't break every time I update so I tried this hoping it would work (obviously didn't).
    Code:
    String name = Bukkit.getServer().getClass().getPackage().getName();
    String version = name.substring(name.lastIndexOf('.') + 1);
     
    ((org.bukkit.craftbukkit.version.entity.CraftPlayer) player).getHandle().playerConnection
    .sendPacket(new net.minecraft.server.version.PacketPlayOutWorldParticles(
    type, x, y, z, xOff, yOff, zOff, data, amount));
    Basically version is "v1_7_R4" or whichever version of craftbukkit the server is running.
     
  2. Offline

    fireblast709

    Skionz this method requires you to use reflection one way or another. One idea is that you acquire Class objects through using Class.forName(className), where className is the full package + class name with the correct version.

    Another is that you create a package per version (i.e. net.darkseraphim.pluginname.v_1_7_R4 in my case), in which you have classes that are created for that specific version. Then you can create an instance of such classes using reflection like above, but inside such an instance you will have flat out written NMS package which include a static (note: not referring to Java static, static as in not dynamic) version.

    Examples for both should be available in the resources section, in case you are looking for examples.
     
  3. Offline

    NathanWolf


    You've got the right idea with how to parse out the version- but from there you'd need to use Reflection, which can be a complex subject if you're new to it. It's also generally "frowned upon" around here, when used as a means to bypass Craftbukkit's intentional namespace versioning.

    You could try using something like EffectLib or ParticleLib instead?

    If you use Maven, it's easy to shade it into your plugin so you won't have any external plugin dependencies.
     
Thread Status:
Not open for further replies.

Share This Page