Solved Error with player names

Discussion in 'Plugin Development' started by Ago19, Jan 4, 2021.

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

    Ago19

    I was trying to create a SkyBlock Plugin for my server. When a player types /is go the program checks if the sender has an island. All the islands are stored in a set called islSet. Here's some code
    Code:
    case "go":                   
    if(hasIsland(player) == true) {
                            try{
                                player.teleport(getPlayerIsland(player).mainBlock);
                                player.sendMessage(prefix + "Teleporting to your island");
                            } catch (NullPointerException ex) {
                                player.sendMessage(prefix + "Error teleporting to the island (NullPointerException), talk to a staffer!");
                                System.out.println(prefix + "Error teleporting " + player.getName() + " to the island, [Error] NullPointerException");
                            }
                        } else {
                            player.sendMessage(prefix + "You have no island so you can't be teleported");
                        }
    
    Here i'll post the hasIsland method

    Code:
    public static boolean hasIsland (Player player) {
            String pName = player.getName();
            for(Island is : islSet) {
                if(is.owner == pName) {
                    return true;
                }
            }
            return false;
        }
    
    When the hasIsland method is called, it returns false even when the player owns an island.
    The code was originally in Italian but i changed the words to allow everyone to understand. In case I forgot somethings :
    proprietario = owner
    teletrasportando = teleporting
    isola = island
    Errore = Error
     
  2. Offline

    CraftCreeper6

    @Ago19
    Don't compare strings with == use .equals instead. You should be using UUID's instead of player names anyway.
     
  3. Offline

    Ago19

    Thanks now it works perfectly. I'll follow your suggestion of UUIDs
     
Thread Status:
Not open for further replies.

Share This Page