Need Help fixing this... I cant tell whats gone wrong

Discussion in 'Plugin Development' started by Wristz, Oct 10, 2016.

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

    Wristz

    Basically I'm trying to make it to where the if the player is not online it sends the "sender" a message and returns true; However I keep getting errors.

    My code...

    http://pastebin.com/CjHkggkp
     
  2. Offline

    Zombie_Striker

    Code:
    if(Bukkit.getPlayer(args[0]) != null) //<----- If player is online...
                            {
                            Player target = Bukkit.getPlayer(args[0]);
    Do tell me, if the only way for target to be created is if the player is null, what did you expect the exact the same player to return?

    If the targets name is args[0], why not use args[0]?
     
  3. Offline

    blue1

    One problem you have is thinking that the player is null if he isn't online. Try using
    Code:
    if(p.isOnline())
    instead.
    And to see if a player has been on the server before, use
    Code:
    for(OfflinePlayer each:Bukkit.getOfflinePlayers()){
        if(each.getName() == args[0]){
            //The player has played before
        }
    }
     
  4. @blue1
    Actually, he's right and you're wrong, as Bukkit.getPlayer() returns null if the player isn't online. The reason that Player has the "isOnline" method is because it's actually in the OfflinePlayer interface (which Player implements).

    @Wristz
    As for the actual problem, it's probably encapsulation, because if you don't put curly brackets, only the line directly under the else statement will get executed.

    This should however not give you any errors, so I suspect the error is somewhere else in the class. Post the error, aswell as show us which all the lines mentioned in the stacktrace are.
     
    Last edited: Oct 10, 2016
    Firestar311 likes this.
Thread Status:
Not open for further replies.

Share This Page