[SOLVED] Error On If Statement

Discussion in 'Plugin Development' started by WildN00b, May 1, 2011.

Thread Status:
Not open for further replies.
  1. Hi, I'm writing a whitelist plugin, it checks if the user is on the list and if it's not on the list it's disallows the request to join with a fake message.
    When i (WildN00b) connects, the if statement "fails" and goes to the else.

    Heres my code:

    Code:
    public void onPlayerPreLogin(PlayerPreLoginEvent event) {
            String name = event.getName();
    
            if (name == "WildN00b") {
                event.allow();
            } else {
                plugin.getServer().broadcastMessage("[PreKick] " + name + " From IP " + event.getAddress().getHostAddress() + " Was Kicked");
                System.out.println("[PreKick] " + name + " From IP " + event.getAddress().getHostAddress() + " Was Kicked");
    
                event.disallow(Result.KICK_OTHER, "The Server Is Down For Maintenance!");
            }
        }
    Can anyone help me?

    //WildN00b
     
  2. Offline

    sam holder

    To do string comparisons in java we have to use the equals method.

    Code:
    if (name.equals("WildN00b")) {
     
    WildN00b likes this.
  3. Offline

    Acrobot

    You don't compare strings by "==" in Java.
    It would be:
    Code:
    if (name.equals("WildN00b") {
    //rest of your code
    
    EDIT: Ninja'd
     
    WildN00b likes this.
  4. Offline

    sam holder

    Hehe ;)
    I make this mistake very often after using other languages such as php, actionscript, etc.
     
Thread Status:
Not open for further replies.

Share This Page