Error with hasPLayedBefore

Discussion in 'Plugin Development' started by Coobro_FTW, Jul 3, 2014.

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

    Coobro_FTW

    So I am using this code below and when I run it I get an onCommand error and and it points to the line

    target.hasPlayedBefore.

    Here is the code. All help is appreciated :)

    Code:
    if(args[0].equalsIgnoreCase("promote")) {
       User user = new User(p);
       Player target = Bukkit.getPlayer(args[1]);
       if(target.hasPlayedBefore()) {
       user.sendM("&cyolo");
     
       } else {
       user.sendM("&c"+target.getName()+" has not played on this server before.");
       }
     
       }
     
  2. Offline

    bob7

    You need to get the OfflinePlayer object i believe.. Player instances are only created when a user is currently connected to the server.
     
  3. Offline

    unrealdesign

    Nope.

    Coobro_FTW You never checked if the plaer was null or not. You could have entered an invalid name.
     
  4. Offline

    Coobro_FTW

    Yeah I did check whether it was null or not but then I had an error on the null part.

    unrealdesign
     
  5. Offline

    unrealdesign

    Well in the code you provided, you never checked
    Code:java
    1. if(player != null)

    So you could be doing null.hasPlayedBefore() which doesn't work. Also, if you posted the error, I bet you'd see a NullPointerException
     
Thread Status:
Not open for further replies.

Share This Page

OSZAR »