Solved Error with player names

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

  1. Offline


    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
    case "go":                   
    if(hasIsland(player) == true) {
                                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

    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


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


    Thanks now it works perfectly. I'll follow your suggestion of UUIDs

Share This Page