offline players?

Discussion in 'Plugin Development' started by madcap, Feb 17, 2011.

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

    madcap

    org.bukkit.Server.getPlayer says it may return null for offline players. Is there a way to get info on offline players without manually looking in the world file and the player.dat files?

    Specifically I'm trying to determine if a player exists with a certain name who may be offline. I could check if the name.dat file exists, but I'm hoping there is an easier way.
     
  2. Offline

    Edward Hand

    Why do you need an easier way?

    Code:
    boolean playerExists(String name)
    {
       try
       {
          FileInputStream test = new FileInputStream("world/players/"+name+".dat);
       }
       catch (FileNotFoundException e)
       {
          //no player.dat file so return false
          return false;
       }
      //if code got this far then file must exist: return true
      return true;
    }
    should work I think (though not actually tested)
     
  3. Offline

    Plague

    Why o to a fileystem level if maybe bukkit has it in memory.
     
  4. Offline

    Edward Hand

    How about this then as a slight improvement?

    Code:
    boolean playerExists(String name)
    {
      if(referenceToServer.getPlayer(name) != null)
         return true;
    
       try
       {
          FileInputStream test = new FileInputStream("world/players/"+name+".dat);
       }
       catch (FileNotFoundException e)
       {
          return false;
       }
      return true;
    }
     
  5. Offline

    Plague

    Yes that's the best way I can think of, but what I was getting at is that he wanted to know if there is something like getOfflinePlayers() or something and that is WHY he wanted to know a better way than filesystem :)

    Offtopic: Edward from your posts I can see that it's a real shame you live in England, otherwise I'd like to employ you :D
     
  6. Offline

    madcap

    I will be using this approach to check for offline players. But the functionality to access offline players may be useful for a variety of reasons beyond just checking for existence so I was curious if the functionality existed. Apparently it does not. Thanks for the replies.
     
Thread Status:
Not open for further replies.

Share This Page