p.hasPlayedBefore() not functioning

Discussion in 'Plugin Development' started by siriusx96, Apr 9, 2012.

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

    siriusx96

    Hi, I was making a very simple plugin.

    I have no clue what's causing the issue, but whenever I sign on (regardless of playing before or not), it says "Welcome, ...!". Here is my code:

    Code:
    package suirisx;
     
    import java.util.ArrayList;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Server;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.Plugin;
     
    public class playerJoinListener implements Listener {
     
    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
    Player p = event.getPlayer();
    if (p.hasPlayedBefore() == true) {
    p.getServer().broadcastMessage(ChatColor.LIGHT_PURPLE + "Welcome back, " + event.getPlayer().getName() + ChatColor.LIGHT_PURPLE + "!");
    } else {
    p.getServer().broadcastMessage(ChatColor.LIGHT_PURPLE + "Welcome, " + event.getPlayer().getName() + ChatColor.LIGHT_PURPLE + "!");
    }
     
     
    public playerJoinListener(Plugin plugin) {
     
    }
     
    }
    
    If you could please help identify the problem, it would be fantastic.
    Thanks.
     
  2. Offline

    jamietech

    Just try
    Code:
    if (p.hasPlayedBefore()) { //code }
    instead of using == true
     
  3. Offline

    siriusx96

    I actually had it that way earlier, and talked to a friend who had been making Bukkit plugins before. He said to try that. I didn't change it back.

    I'll try again

    Nothing.

    Also, just realized I'm missing a brace.

    It still doesn't work.
     
  4. Offline

    CorrieKay

    just to clarify, has played before will check if theyve played on the -map- before.
     
  5. Offline

    AmberK

    This worked for me:
    Code:java
    1. public void onPlayerJoin(PlayerJoinEvent event) {
    2. Player p = event.getPlayer();
    3. if (p.hasPlayedBefore()) {
    4. p.sendMessage("§dWelcome back, " + p.getName() + "!"); }
    5. else {
    6. p.sendMessage("§dWelcome, " + p.getName() + "!");
    7. }
    8. }
     
  6. Offline

    siriusx96

    I've only got 1 map loaded, and it still doesn't work.

    I plugged that code into the plugin, and it still says Welcome rather then Welcome back.

    Here's WelcomePlugin.java
    Code:
    package suirisx;
     
    import java.util.logging.Logger;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.event.Listener;
     
    public class WelcomePlugin extends JavaPlugin implements Listener {
     
    Logger log;
    public final playerJoinListener pjl = new playerJoinListener(this);
     
     
    public void onEnable() {
    PluginManager pm = getServer().getPluginManager();
    pm.registerEvents(pjl, this);
     
    }
     
    public void onDisable() {
    }
    }
    
    playerJoinListener.java:
    Code:
    package suirisx;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.Plugin;
    public class playerJoinListener implements Listener {
     
    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
            Player p = event.getPlayer();
            if (p.hasPlayedBefore()) {
                p.sendMessage("§dWelcome back, " + p.getName() + "!"); }
            else {
                p.sendMessage("§dWelcome, " + p.getName() + "!");
            }
        }
     
     
    public playerJoinListener(Plugin plugin) {
     
    }
    }
    
    Thanks :3
     
  7. Offline

    dillyg10

    hmm, you might want to try doing the opisite
    Code:java
    1.  
    2. if(!p.hasPlayedBefore() {
    3. p.sendMessage("Welcome");
    4. else {
    5. p.sendMessage("Welcome back!");
    6. }
     
  8. Offline

    siriusx96

    I tried that. There's no avail.

    Thanks for your help, everybody. I've still yet to get this to work.
     
  9. Offline

    siriusx96

    Bump? Still no progress.

    Anyone else think this is a Bukkit issue?
     
  10. Offline

    damospiderman

    Try using p.getLastPlayed() will return 0 if they have never played before
     
  11. Offline

    siriusx96

    I'll try that.

    No luck. :I
     
  12. Offline

    dumb0t

    server is saved?after log out?dont know if thats the problem...try saving it
     
  13. Offline

    siriusx96

    Alright. I'll try that, although sometimes I'll just sign in then out, and then back in again. It should work? I'll post back later if that seems to fix it.
     
Thread Status:
Not open for further replies.

Share This Page