Begginer question

Discussion in 'Plugin Development' started by jumika, Mar 7, 2011.

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

    jumika

    Hi all!
    First of all i want to say that i'm new to java, and maybe my question is more likely to be a java issue than bukkit.
    So i use Player.getName() to get the player name, and every time i try to compare it to a String in a LinkedList it just doesnt work.
    Here is an exemple of what isn't working:
    Code:
    if(curr.name == playerName) {
                    player.sendMessage(ChatColor.BLUE+" Your places:");
                    for(String[] place : curr.places) {
                        player.sendMessage(ChatColor.AQUA+place[0]+" - X: "+place[1]+", Y: "+place[2]+", Z: "+place[3]);
                    }
                }
    And this works:
    Code:
    if(curr.name.replace(playerName, "").length() == 0) {
                    player.sendMessage(ChatColor.BLUE+" Your places:");
                    for(String[] place : curr.places) {
                        player.sendMessage(ChatColor.AQUA+place[0]+" - X: "+place[1]+", Y: "+place[2]+", Z: "+place[3]);
                    }
                }
    Do anybody have a suggesion for me?
     
  2. Offline

    Whalum

    If curr.name and playerName are both strings, you might want to try the equals or equalsIgnoreCase methods.
     
  3. Offline

    Dinnerbone Bukkit Team Member

    Java equals isn't like you'd expect. You have to .equals(xxx), not ==
     
  4. Offline

    jumika

    Thanks, this works.
    This means that if(string1 == string2) is not a proper way to compare to strings in java?
    Anyway now i have problems with teleportTo method. :D
    I'm experimenting with a teleport plugin, where you can save multiple places.
    These are stored in String arrays where [0] is the name of the place, and the rest are the coordinates.
    here is my code for the teleport:
    The coordinates are right i checked it trough the server console.
    Than what is the problem?
    Code:
    public void goPlace(Player player, String placeName) {
            for (jWorldUser curr : users ) {
                if(curr.name.equals(player.getName())) {
                    for(String[] place : curr.places) {
                        System.out.println(place[0]);
                        System.out.println(Double.valueOf(place[1]).doubleValue());
                        System.out.println(Double.valueOf(place[2]).doubleValue());
                        System.out.println(Double.valueOf(place[3]).doubleValue());
                        if(place[0].equals(placeName))
                            player.teleportTo(new Location(player.getWorld(), Double.valueOf(place[1]).doubleValue(), Double.valueOf(place[2]).doubleValue(), Double.valueOf(place[3]).doubleValue()));
                            player.sendMessage(ChatColor.BLUE+" Now you are at: "+placeName);
                            break;
                        }
                    break;
                }
            }
        }
    I found the problem. Some Bracket was missing near the if
     
  5. Offline

    andret

Thread Status:
Not open for further replies.

Share This Page