Different code for different versions.

Discussion in 'Spigot Discussion' started by masecla22, Aug 1, 2018.

  1. So I am making a plugin, and I want it to work in as many versions as possible and I was wondering how can I have some methods for a version and some methods for another.
    What I am talking about is
    In 1.12.2 this is how you set an owner to a skull head:
    Code (Text):
    meta.setOwningPlayer(opp1);
    And in 1.8 this is how you do it:
    Code (Text):
    meta.setOwner(opp1);
    How can I add different methods based on the version this is compiling on?
     
  2. Choco

    Moderator

    Let me preface with "It's recommended that you compile against the latest version of the API, Spigot 1.13". This is SpigotMC's recommendation and it forces servers to use more up-to-date versions as any versions that are not the latest are unsupported.

    With that being said, you're looking for version abstractions. See this guide. Do consider using Minecraft 1.13 though.
     
  3. I am no expert here but wouldnt everything in the latest version or whatever version you are going up to work? Have you tested that 1.12 method in a 1.8 server?
     
  4. So I simply have to use
    Code (Text):

     version = Bukkit.getServer().getClass().getPackage().getName().replace(".",  ",").split(",")[3];
     
    And call different methods based on what I need, right?