How to compare an argument to a value in the config

Discussion in 'Plugin Development' started by Ethan, Jul 13, 2013.

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

    Ethan

    So in a plugin that stores a value in someones name in a config such has

    Playername:
    Requested By: Red

    So if the command was /accept player red how would I check if the value 'red' in the command equals the value in the config? Since when I try

    Code:java
    1. if(getConfig().getString(player.getName() + ".requested by") == player.getServer().getPlayer(args[1]))


    it gives the error that a string cannot be converted to the value player.
     
  2. Offline

    SnipsRevival

    Add .getName() to the right side.
     
  3. Offline

    Ethan

    Do you want me to just make it getName()? Because it won't let me use getName() along with getPlayer(), player, or getServer()
     
  4. Offline

    xTrollxDudex

    Ethan
    getName() goes after getPlayer(args[0]) and before you end the if with )
     
  5. Offline

    LinearLogic

    == compares references to an object in the String pool; .equals(...) or .equalsIgnoreCase(...) is what you want. Additionally, ensure that the Player with the name matching args[1] isn't null:
    Code:
    Player requested = getServer().getPlayer(args[1]);
    if (requested != null) {
        if(getConfig().getString(player.getName() + ".requested by").equalsIgnoreCase(requested.getName())) {
            // Your code here...
        }
    }
     
  6. Offline

    Ethan

    Thanks guys ^.^

    It works
     
Thread Status:
Not open for further replies.

Share This Page