How to write a backwards-compatible code block?

Discussion in 'Plugin Development' started by Zhro, Apr 18, 2014.

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

    Zhro

    This is kind of a double question.

    before 1.7.9, player data was stored here:

    worldName + "/player/" + p.getName() + ".dat"

    Now it is stored here:

    worldName + "/playerdata/" + p.getUniqueId() + ".dat"

    A plugin I help to maintain broke from this update for two reasons. The "player" folder was changed to "playerdata" and the file name was changed from the player's name to the new UUID string.

    My first question is whether there is a way to get the "player/playerdata" path in such a way that is not hard-coded as it is here.

    My second question is how to write an expression which allows me to say, "if the version of bukkit is older than 1.7.9, execute this block, else, execute this other block".

    Thanks.
     
  2. Offline

    RawCode

    two separate handlers and switch, i hope you will find self method to get bukkit version.
     
  3. Offline

    Plo124

    Zhro

    Try this, its untested though
    Code:java
    1. public File getPlayerDatFile(Player p){
    2. String s = Bukkit.getVersion();
    3. s = s.replaceAll(".","");
    4. if (Integer.parseInt(s) >= 179){
    5. return new File("path/to/file/"+p.getUniqueId()+".dat");
    6. } else {
    7. return new File("old/minecraft/path/to/file/"+p.getUniqueId()+".dat");
    8. }
    9. }
     
Thread Status:
Not open for further replies.

Share This Page