Logging player online time?

Discussion in 'Plugin Development' started by niber, Aug 27, 2013.

?

Do you think this plugin will work out?

  1. Yes

    1 vote(s)
    25.0%
  2. No

    3 vote(s)
    75.0%
Thread Status:
Not open for further replies.
  1. Offline

    niber

    I have an idea for an administration plugin that helps owners and staff managers with promotions.
    How can I log the time that people play who have certain nodes. So in other words if Steve has the node "promotion.log" then it logs the time they play and if the have "promotion.log.staff" is logs it in another command. If anyone is willing to help me get this plugin coded and launched or is good with graphics I am willing to pay a bit. And I am looking for a development team! I have a bukkitdev page set up but not much stuff is on it. http://dev.bukkit.org/bukkit-plugins/plugin-promotion/
     
  2. Offline

    NoLiver92

    is this asking for help or asking someone to code for you?
     
    hintss likes this.
  3. Offline

    niber

    Asking for help
     
  4. Offline

    acburdine

    I possibly could help with that. It sounds like a good idea.
     
  5. Offline

    metalhedd


    Which is why it's already been done... many, many times...
     
  6. This is actually a good topic. Feel like it's be a good idea for the plugin I'm working on. Just don't know how to do it :(
     
  7. Offline

    metalhedd


    I just posted a link to about a dozen plugins that do it. surely a few of them have source code available.
     
  8. Offline

    niber

    This is not the main part of the plugin, It is a promotion manager that logs the online time to a file and can be viewed ingame as a bonus. But the main idea is for it to handle what a staff manager would.
     
  9. Offline

    KingNyuels

    Hmm In RegionKing, I use this:
    Code:java
    1. public class LastOnline extends BukkitRunnable {
    2.  
    3. public LastOnline(JavaPlugin plugin) {
    4. }
    5.  
    6. public void run() {
    7. Player players[] = RegionKing.main.getServer().getOnlinePlayers();
    8. OfflinePlayer offplayers[] = RegionKing.main.getServer()
    9. .getOfflinePlayers();
    10. if (players.length >= 1) {
    11. for (int i = 0; i == (players.length - 1); i++) {
    12. String d = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
    13. .format(new Date(System.currentTimeMillis()));
    14. RegionKingConfig.getConfig(ConfigFile.LASTONLINE).set(
    15. players[i].getName() + ".Last", d);
    16. if (!isSet(players[i])) {
    17. RegionKingConfig.getConfig(ConfigFile.LASTONLINE).set(
    18. players[i].getName() + ".First", d);
    19. }
    20. if (TimeUtil.isNextDay(System.currentTimeMillis())) {
    21. double average = TimeUtil.getAverageTime(players[i]);
    22. double toDay = TimeUtil.getTodayOnline(players[i]);
    23. double days = TimeUtil.getDaysOnline(players[i]);
    24. RegionKingConfig.getConfig(ConfigFile.LASTONLINE).set(
    25. players[i].getName() + ".ToDay", 0);
    26. TimeUtil.setAverage(players[i], (average + toDay) / days);
    27.  
    28. if (offplayers.length >= 1) {
    29. for (int j = 0; j == (offplayers.length - 1); j++) {
    30.  
    31. double offaverage = TimeUtil
    32. .getAverageTime(offplayers[j]);
    33. double offdays = TimeUtil
    34. .getDaysOnline(offplayers[j]);
    35. double offtoDay = TimeUtil
    36. .getTodayOnline(offplayers[j]);
    37.  
    38. RegionKingConfig.getConfig(ConfigFile.LASTONLINE)
    39. .set(offplayers[i].getName() + ".ToDay", 0);
    40.  
    41. TimeUtil.setAverage(players[j],
    42. (offaverage + offtoDay) / offdays);
    43.  
    44. RegionKingConfig.saveConfig(ConfigFile.LASTONLINE);
    45.  
    46. }
    47. }
    48. } else {
    49. TimeUtil.IncreaseTodayOnline(players[i]);
    50. }
    51. RegionKingConfig.getConfig(ConfigFile.LASTONLINE).set(
    52. players[i].getName() + ".Time",
    53. onlineTime(players[i]) + 5);
    54.  
    55. RegionKingConfig.saveConfig(ConfigFile.LASTONLINE);
    56.  
    57. }
    58. }
    59.  
    60. RegionKingConfig.saveConfig(ConfigFile.LASTONLINE);
    61. }
    62.  
    63. public static String getDate(OfflinePlayer p) {
    64. return RegionKingConfig.getConfig(ConfigFile.LASTONLINE).getString(
    65. p.getName() + ".Last");
    66. }
    67.  
    68. public static boolean isSet(OfflinePlayer offlinePlayer) {
    69. boolean returnment = false;
    70. try {
    71. if (RegionKingConfig.getConfig(ConfigFile.LASTONLINE).get(
    72. offlinePlayer.getName() + ".First") == ""
    73. || RegionKingConfig.getConfig(ConfigFile.LASTONLINE).get(
    74. offlinePlayer.getName() + ".First") == null) {
    75. returnment = false;
    76. } else {
    77. returnment = true;
    78. }
    79. } catch (Exception e) {
    80. returnment = false;
    81. }
    82.  
    83. return returnment;
    84.  
    85. }
    86.  
    87. public static String getFirst(OfflinePlayer offlinePlayer) {
    88. if (isSet(offlinePlayer)) {
    89. return DateUtil.StringToDate(
    90. RegionKingConfig.getConfig(ConfigFile.LASTONLINE)
    91. .getString(offlinePlayer.getName() + ".First"))
    92. .toString();
    93. } else {
    94.  
    95. return ChatColor.RED + "You are not registered in the System!";
    96.  
    97.  
    98. }
    99.  
    100. }
    101.  
    102. public static int onlineTime(OfflinePlayer offlinePlayer) {
    103. return RegionKingConfig.getConfig(ConfigFile.LASTONLINE).getInt(
    104. offlinePlayer.getName() + ".Time");
    105. }
    106.  
    107. }[/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i]

    Code:java
    1. public class DateUtil {
    2.  
    3. public static int DateToDays(Date d) {
    4. Date now = new Date(System.currentTimeMillis());
    5. int diffInDays = (int) ((now.getTime() - d.getTime()) / 86400000);
    6. return diffInDays;
    7. }
    8.  
    9. public static Date StringToDate(String s) {
    10. Date date = null;
    11. try {
    12. date = new SimpleDateFormat("dd-MM-yyyy'T'HH:mm:ss", Locale.GERMAN)
    13. .parse(s);
    14. } catch (ParseException e) {
    15. e.printStackTrace();
    16. }
    17. return date;
    18. }
    19.  
    20. }
    21.  

    Code:java
    1. public class TimeUtil {
    2. public static String parseTime(int time) {
    3. if (Locale.getLocale() == "en_US" || Locale.getLocale() == "en_GB") {
    4. return time / 24 / 60 + " days " + time / 60 % 24 + " hours "
    5. + time % 60 + " minutes";
    6. } else if (Locale.getLocale() == "de") {
    7. return time / 24 / 60 + " Tage " + time / 60 % 24 + " Stunden "
    8. + time % 60 + " Minuten";
    9. } else {
    10. return "FEHLER";
    11. }
    12.  
    13. }
    14.  
    15. public static double getAverageTime(OfflinePlayer offlinePlayer) {
    16. return RegionKingConfig.getConfig(ConfigFile.LASTONLINE).getDouble(
    17. offlinePlayer.getName() + ".Average");
    18. }
    19.  
    20. public static void setAverage(Player p, double d) {
    21. RegionKingConfig.getConfig(ConfigFile.LASTONLINE).set(
    22. p.getName() + ".Average", d);
    23. RegionKingConfig.saveConfig(ConfigFile.LASTONLINE);
    24. }
    25.  
    26. public static int getTodayOnline(OfflinePlayer offplayers) {
    27. return RegionKingConfig.getConfig(ConfigFile.LASTONLINE).getInt(
    28. offplayers.getName() + ".ToDay");
    29. }
    30.  
    31. public static int getDaysOnline(OfflinePlayer p) {
    32. return RegionKingConfig.getConfig(ConfigFile.LASTONLINE).getInt(
    33. p.getName() + ".TotalDays");
    34. }
    35.  
    36. public static void IncreaseTodayOnline(Player p) {
    37. RegionKingConfig.getConfig(ConfigFile.LASTONLINE).set(
    38. p.getName() + ".ToDay", getTodayOnline(p) + 5);
    39. RegionKingConfig.saveConfig(ConfigFile.LASTONLINE);
    40. }
    41.  
    42. public static boolean isNextDay(long time) {
    43. if ((time - 86400000) <= 300000) {
    44. return true;
    45. } else {
    46. return false;
    47. }
    48. }
    49.  
    50. public static void increaseTotalDaysOnline(OfflinePlayer p) {
    51. RegionKingConfig.getConfig(ConfigFile.LASTONLINE).set(
    52. p.getName() + ".TotalDays", getDaysOnline(p) + 1);
    53. RegionKingConfig.saveConfig(ConfigFile.LASTONLINE);
    54. }
    55. }

    Would that be something?
     
  10. Offline

    niber

    I will take a look at it. :D Thanks!

    You misunderstood the point of the plugin. It is a promotion manager.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  11. Offline

    metalhedd


    Did I misunderstand it? or was your question completely unclear? You never said that anywhere in your post.. you only said: "I have an idea for an administration plugin that helps owners and staff managers with promotions."

    you then went on to ask about how to track players online time, the answer to your question is to either use, or look at the source code of one of the existing plugins I linked. You can probably STILL do this and integrate it with you 'promotion manager', Just have it check the database created by the other plugin, or directly hook the other plugin to query online time.
     
  12. Offline

    niber

    Ok thanks! :)
     
Thread Status:
Not open for further replies.

Share This Page