Making certain things work for a certain spigot version

Discussion in 'Spigot Plugin Development' started by TimeVisualSales, May 9, 2015.

  1. Hi there as said in the title, I want to know how I can make something work in a version such as spigot 1.8 R1 but not in any other version. How will I do this?
  2. Check the server's version. If they aren't using 1.8 don't continue a specific task, or disable the plugin.
  3. So like
    Code (Text):
    What would I put after .getVersion() ?
  4. If you still dont understand what I mean, I've created a plugin where the mob follows the player but since I'm using Spigot 1.8 R1, it wont work for version such as Spigot 1.8 R2. Therefore, I have added spigot 1.8 R1 and R2 to my libary and created seperate classes for the following and I want it so that if your in Spigot 1.8 R1 (net.minecraft.server.v1_8_R1) the player following will only work in that version and not try to work for spigot 1.8 R2 when your in the Spigot 1.8 R1 version.
  5. So you want to use one class with 1.8, and a separate class for 1.8.3? You can parse the version and use that version to get the specific class with reflection. Then you would create a new instance of that class and cast it to its super interface, or super (abstract) class.
  6. I have the reflection class but what do I do next?
  7. Create either an interface, or an abstract class with all of your method headers and have each of your classes either extend, or implement it and handle each method appropriately.
  8. Ok thanks.
  9. clip


  10. The reflection I am talking about would just be used to get the specific class. IMO, it would be a lot cleaner even though it is fairly slow.
    Code (Text):
    Class.forName("com.skionz.myplugin.AbstractClass" + version);
    This way the right class will be used depending on the version. Then you can just get the constructor, create a new instance, and declare it as its super class/interface. It is pretty much the same thing you did, but replaces your if/else statements.
  11. clip


    I guess either way would suffice.