RuneHive-Game
Loading...
Searching...
No Matches
PlayerRecord.java
Go to the documentation of this file.
1package com.runehive.content.activity.record;
2
3import com.runehive.content.activity.ActivityType;
4import com.runehive.game.world.entity.mob.player.Player;
5import com.runehive.game.world.entity.mob.player.PlayerRight;
6import com.runehive.net.packet.out.*;
7import com.runehive.util.Utility;
8
9import java.util.*;
10
11public class PlayerRecord {
12
13 private final Player player;
14 public long time;
15 public boolean global;
16 private Map<ActivityType, TreeSet<GameRecord>> personalRecord = new HashMap<>();
17
19 this.player = player;
20 }
21
22 public void start() {
23 time = System.currentTimeMillis();
24 }
25
26 public long end(ActivityType activity) {
27 return end(activity, true);
28 }
29
30 public long end(ActivityType activity, boolean track) {
31 long record = System.currentTimeMillis() - time;
32
33 /* Don't add if time is longer than 30 minutes */
34 if (record > 1_800_000) {
35 return 0;
36 }
37
38 if (track && !PlayerRight.isAdministrator(player)) {
40 // GlobalRecords.add(player, tracker);
41 add(tracker);
42 }
43
44 time = -1;
45 return record;
46 }
47
48 public void add(GameRecord tracker) {
50 TreeSet<GameRecord> personal = personalRecord.computeIfAbsent(activity, act -> new TreeSet<>(Comparator.comparingLong(record -> record.time)));
51 if (personal.size() < 10) {
52 personal.add(tracker);
53 } else if (tracker.time < personal.first().time) {
54 personal.pollLast();
55 personal.add(tracker);
56 }
57 }
58
59 void clean(int size) {
60 int string = 32401;
61 for (int count = 0; count < (size < 25 ? 25 : size); count++) {
62 player.send(new SendString("", ++string));
63 player.send(new SendString("", ++string));
64 player.send(new SendString("", ++string));
65 player.send(new SendString("", ++string));
66 string++;
67 }
68 player.send(new SendScrollbar(32400, (size < 10 ? 10 : size) * 28));
69 }
70
72 int count = 0;
73 String[] marquee = new String[5];
74 List<ActivityType> activities = ActivityType.getRecordable();
75 for (ActivityType activity : activities) {
76 String name = Utility.formatEnum(activity.name());
77 player.send(new SendString((viewing == activity ? "<col=ffffff>" : "</col>") + name, 32352 + count));
78 player.send(new SendTooltip("Display " + name + " records", 32352 + count));
79 count +=2;
80 }
81 for (int index = 0; index < marquee.length; index++) {
82 ActivityType type = Utility.randomElement(activities);
83 // GameRecord top = GlobalRecords.getTopRecord(type);
84 activities.remove(type);
85 // String details = top == null ? "None" : top.name + "(" + Utility.getTime(top.time) + ")";
86 // marquee[index] = Utility.formatEnum(type.name()) + ": " + details;
87 }
88 int size = ActivityType.values().length < 12 ? 12 : ActivityType.values().length;
89 player.send(new SendScrollbar(32350 , size * 23));
90 player.send(new SendMarquee(32306, marquee));
91 }
92
96
97 public void display(boolean global, ActivityType activity) {
98 this.global = global;
99 player.send(new SendConfig(325, global ? 1 : 0));
100
101 /* if (global) {
102 GlobalRecords.display(player, activity);
103 return;
104 }*/
105
106 clean(0);
108 TreeSet<GameRecord> records = personalRecord.getOrDefault(activity, new TreeSet<>());
109
110 int idx = 0;
111 for (GameRecord personal : records) {
112 player.send(new SendString((idx / 5 + 1) + ")", (idx + 1) + 32401));
113 player.send(new SendString(Utility.formatName(personal.name), (idx + 2) + 32401));
114 player.send(new SendString(personal.time == 0 ? "None!" : Utility.getTime(personal.time), (idx + 3) + 32401));
115 player.send(new SendString(personal.date, (idx + 4) + 32401));
116 idx += 5;
117 }
118 player.send(new SendScrollbar(32400, (records.size() < 9 ? 9 : records.size()) * 28));
119 player.interfaceManager.open(32300);
120 }
121}
long end(ActivityType activity, boolean track)
void display(boolean global, ActivityType activity)
Map< ActivityType, TreeSet< GameRecord > > personalRecord
This class represents a character controlled by a player.
Definition Player.java:125
The OutgoingPacket responsible for changing settings on a client.
The OutgoingPacket that sends a string to a Players itemcontainer in the client.
Handles miscellaneous methods.
Definition Utility.java:27
static String formatName(final String input)
Definition Utility.java:645
static< T > T randomElement(Collection< T > collection)
Picks a random element out of any array type.
Definition Utility.java:248
static String getTime()
Gets the current server time and formats it.
Definition Utility.java:141
static String formatEnum(final String string)
Formats name of enum.
Definition Utility.java:89
Holds all activity types that are timed.
static List< ActivityType > getRecordable()
static boolean isAdministrator(Player player)
Checks if the player is a privileged member.