Development Assistance Multiple versions for a plugin

Discussion in 'Plugin Help/Development/Requests' started by Tomass, Jun 24, 2015.

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

    Tomass

    Hello!

    How can I make my plugin accessable for 1.8.1-1.8.7 versions? Yes, I know there are tons of tutorials, but I still confused and I'm trying to do it without any success. I have read http://bukkit.org/threads/support-multiple-minecraft-versions-with-abstraction-maven.115810/ topic where user @mbaxter demonstrate the tutorial which helps us to make plugin accessable for diffrent versions. This is my first experiance working with Maven and I still don't understand how it works with plugins.

    Kindly ask you to help me or even create a simple example (without other processes) for me which allows plugin to work in 1.8.1 and 1.8.3 versions. I will look at the code and learn how to do it.

    I spent 2 days to find a way without any success, so please don't condemn me :)

    I'm making plugins on Eclipse.


    Thank you guys!
     
  2. Offline

    Zombie_Striker

    @Tomass
    If your code's import starts with 1.8.7, 1.7.9R2, 1.8.3, thenn its not accessable to all versions, only the version of those imports.
     
  3. If you only use the bukkit API itself (no craftbukkit or nms classes), you should already be fine. If you also use the craftbukkit and nms stuff, it's best to use reflection as much as you can. If there are things that extends nms or craftbukkit classes, then you need to create multiple copies of that class, each with the imports for another mc version, and check which version the server is, and then when creating an instance use the class for that version (for example use a interface class for all the methods that you want to acces, and make that the variable type and then making the other classes implements that interface). If all the nms and craftbukkit stuff is just having variables and that sort of stuff, you should be able to do reflection, and to get the package you can use:
    Code:
    private static String getVersion() {
            String[] array = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",");
            if (array.length == 4) return array[3] + ".";
            return "";
        }
    
    I hope that this wasn't too much for you, if so, try to take a small bit, do that and then go to another bit. If it's still too much you can ask me to explain a part better. Maybe it's good to make a backup of your project before making changes, in case it totally failes.
     
  4. Offline

    Tomass

    Yes, I know. But for example I have similar situation:

    I need to use this import:
    Code:
    import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
    And this line broke my plugin if I'm using higher 1.8 version (for example 1.8.3).
     
  5. Offline

    timtower Administrator Administrator Moderator

    Moved to Bukkit alternatives
     
  6. @Bram0101 You're hinting at the correct way to do this, yet giving the answer to the wrong way to do it. Bypassing the version package names by using reflection is simply wrong, it's there for a reason.
     
  7. Offline

    Zombie_Striker

    @Tomass
    Then work around it. Don't import craftplayer and just use Player#getHandle to get craftplayer.
     
  8. Offline

    Tomass

    Yes, I did as you said. But how to import library for diffrent version?

    Yes, I heard that reflections are wrong way to make multiple versions. As far as I know the best way is using Maven.
     
    Last edited by a moderator: Jun 26, 2015
  9. Offline

    Zombie_Striker

    @Tomass
    The only problem you have is that you imported this:
    Just use the work around to no have to have the import. Then it will work on all versions. You don't need to cast/create an instance of the craftplayer.
     
  10. Offline

    Tomass

    I just said an example. I have to use such imports! (NMS, packets).
     
  11. If you use a library as in another plugin, then that plugin needs to be for multiple versions, or you import the same plugin but for different minecraft versions.
    I know that reflection isn't the good way to go, but it's a possible way, and I was just giving possible ways that I could come up with on the spot.
     
  12. Offline

    Tomass

    Hm, I prefer using Maven. Maybe someone could give me a pure and simple example?
     
  13. I can't help you then, I don't use maven, because I find it unnecessary and a bit too much work.
     
  14. Offline

    Tomass

    Sadly :(
     
  15. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    This is the most support I'll give to something that isn't Bukkit:

    My example is very pure and simple.
     
  16. Offline

    xTrollxDudex

  17. Offline

    Tomass

    Regarding code I fully understand, but how can I add repositories to get diffrent bukkit versions for one plugin. (For each version class I need to use new imports from other bukkit docs)?

    Yes, I understand your example, but how you add diffrent versions into plugin to get certain version's imports?

    Should I install something to use Maven? Because I can't find it in Window > Preferences > Maven

    I really confused.
     
    Last edited by a moderator: Jun 26, 2015
  18. Offline

    xTrollxDudex

    You'd add the different version of the jar to the dependencies of each submodule
     
    Last edited by a moderator: Jun 25, 2015
  19. Maybe, but I like it the way it is, and I don't really like to learn stuff or use stuff that I totally do not need.
     
  20. Offline

    xTrollxDudex

    You don't need maven, but once you learn how to use it, it makes your life so much easier. Your call though.
     
    Quantum64 and nverdier like this.
  21. Offline

    nverdier

    There is no such method. There is a CraftPlayer#getHandle() which returns an EntityPlayer, but there is no #getHandle() method in the Player interface.
     
Thread Status:
Not open for further replies.

Share This Page