Solved Total players played on server

Discussion in 'Plugin Development' started by Ty Cleere, Oct 5, 2013.

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

    Ty Cleere

    Ok so im making something where i get the total players played on the server ever. I got it but when i reload the server it restarts. So what i was thinking was to use like a int or string in the config but how would i add 1 to a string in the config every time a new player joins. I dont know how i would make it so that it keeps adding 1 when a new player. Thanks guys!
     
  2. Offline

    MrSparkzz


    I'm not really sure, but I think you could just get the online players and the offline players, then add up the length of them.

    Well if you want to do that, you'd have to setup a onJoinEvent that checks player.hasPlayedBefore; if not, add one to your int, then save your config

    Code:java
    1.  
    2. @EventHandler
    3. public void onJoin(PlayerJoinEvent event) {
    4. Player player = e.getPlayer();
    5.  
    6. if (!player.hasPlayedBefore()) {
    7. int i = getConfig().getInt("players");
    8.  
    9. i++;
    10.  
    11. saveConfig();
    12. }
    13. }
    14.  

    note: this was not created in an IDE, so there may be errors about.
     
  3. Offline

    Goblom

    Code:java
    1. new File("world/players/").list().length;


    That will count all the files in the world/players folder.... Essentially every time a user logs on a .dat folder is created in the main worlds players folder. This is just counting how many of those files are there... Basically if a user has logged in there would be a file there with their name.
     
  4. Offline

    MrSparkzz

    But isn't there already a method in Bukkit that allows you to get the total players that have played? I'm pretty sure there was, but things have changed.
     
  5. Offline

    Goblom

    MrSparkzz
    Code:java
    1. int totalPlayer = Bukkit.getOfflinePlayers().length + Bukkit.getOnlinePlayers().length;
     
    MrSparkzz likes this.
  6. Offline

    MrSparkzz

    Only one problem... You're adding the amount of offline players to the amount of offline players. Instead of the amount of offline to online.
     
  7. Offline

    Goblom

    (facepalm)

    Edit: fixed
     
  8. Offline

    Ty Cleere

Thread Status:
Not open for further replies.

Share This Page