Discussion in 'Programming' started by Rocologo, Mar 12, 2016.

  1. Hi,

    When I updated my plugin MobHunting to Minecraft 1.9 I had a build error on this line:

    player.getWorld().playSound(player.getLocation(), Sound.LEVEL_UP, 1.0f,1.0f);

    so I changed it to

    player.getWorld().playSound(player.getLocation(), Sound.ENTITY_FIREWORK_TWINKLE, 1.0f,1.0f);

    but the I lost backwards compatibility! Sound.LEVEL_UP does not exist in MC 1.9 and Sound.ENTITY_FIREWORD_TWINKLE does not exist in MC1.8.8 how do I solve this issue?
  2. Use Sound.valueOf("LEVEL_UP") and catch the error. If it throws an error, play the sound using the new playSound(Player player, String s, .....) method.
    • Friendly Friendly x 1
  3. Thank you very much! That helped!

    This is how I did it:

    Code (Text):

            try {
                //Minecraft 1.9
                player.getWorld().playSound(player.getLocation(),Sound.valueOf("ENTITY_PLAYER_LEVELUP"), 1.0f, 1.0f);
            } catch (Exception e) {
                //Minecraft 1.8.8
                player.getWorld().playSound(player.getLocation(),Sound.valueOf("LEVEL_UP"), 1.0f, 1.0f);

  4. just for let you know if you want to check what sounds you can do use this website: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Sound.html
    Every sound you want to do is registered there so you can find out the name of the sound using this website every update
    • Informative Informative x 1
  5. Thank you. I found that site myself, when I was searching for the solution, but I just didn't know how to use the playSound method so I could build the plugin for both MC1.8 and MC1.9.
  6. Ok if you need any help contact me :)