Solved How to put configurable option "Config.yml"

Discussion in 'Plugin Development' started by Texgabs, Nov 17, 2015.

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

    Texgabs

    I 'm working on a plugin and this sounds when the player join the server.
    This is my code:
    Spoiler (open)
    Code:
      @EventHandler
      public void onPlayerJoin(PlayerJoinEvent e)
      {
        if (e.getPlayer().hasPermission("mdjoinLevelup.true")) {
          for (Player p : Bukkit.getOnlinePlayers()) {
            p.playSound(p.getLocation(), Sound.LEVEL_UP, 1.0F, 0.0F);

    This works fine but I need the sound configurable in the " config.yml "
    I tried this:
    SPOILER (open)
    Code:
      @EventHandler
      public void onPlayerJoin(PlayerJoinEvent e)
      {
        if (e.getPlayer().hasPermission("mdjoinLevelup.true")) {
          for (Player p : Bukkit.getOnlinePlayers()) {
            p.playSound(p.getLocation(), Sound.getConfig().getString("Sound"), 1.0F, 0.0F);
    But no work's , you can helpme please?
    Sorry for my english , not is my native language.
     
  2. Offline

    Xerox262

    Use something like Sound.valueOf(getConfig().getString("Sound")); but you need to handle your errors correctly and create a backup sound incase they enter a sound that is invalid.

    Should throw a EnumConstantNotPresentException if they enter an invalid name. Also I believe the enum names are case sensitive so you should do String#toUpperCase() when checking.
     
  3. Offline

    Texgabs

    Thanks, works fantastic. :D
     
  4. Offline

    Scimiguy

    Don't throw any exception, just handle it and either replace it with a default sound or stop the rest of the code from happening
     
  5. Offline

    Xerox262

    What? Trying to get the enum with an incorrect name throws the exception... Did you not read what I said?
     
  6. Offline

    Scimiguy

    I'm aware of what it does, i thought you mean he should throw an exception manually

    My mistake
     
Thread Status:
Not open for further replies.

Share This Page