58 private static Set<GameRecord> GLOBAL_RECORDS =
new HashSet<>();
60 public static void display(Player player, ActivityType activity) {
61 List<GameRecord> list = getActivities(activity);
62 player.gameRecord.showActivities(activity);
64 for (
int index = 0, count = 0; index < 25; index++) {
65 if (index >= list.size())
67 GameRecord record = list.get(index);
69 String prefix = index == 1 ?
"<clan=6>" : (count == 6 ?
"<clan=5>" : (count == 11 ?
"<clan=4>" : (count / 5) + 1 +
")"));
70 player.send(
new SendString(prefix, 32401 + count));
72 player.send(
new SendString(record.name, 32401 + count));
74 player.send(
new SendString(Utility.getTime(record.time), 32401 + count));
76 player.send(
new SendString(record.date, 32401 + count));
80 player.send(
new SendScrollbar(32400, 696));
81 player.interfaceManager.open(32300);
84 public static void add(Player player, GameRecord tracker) {
85 GameRecord record = getTracker(player.getName(), tracker.activityType);
87 GLOBAL_RECORDS.add(tracker);
90 if (tracker.time > record.time) {
91 GLOBAL_RECORDS.remove(record);
92 GLOBAL_RECORDS.add(tracker);
96 private static GameRecord getTracker(String name, ActivityType activity) {
97 Set<GameRecord>
set = getGlobalRecords(name);
99 if (
set ==
null ||
set.isEmpty()) {
103 for (GameRecord t :
set) {
104 if (t.activityType == activity)
110 static GameRecord getTopRecord(ActivityType activity) {
111 List<GameRecord> records = getActivities(activity);
112 return records.isEmpty() ? null : records.get(0);
115 private static Set<GameRecord> getGlobalRecords(String name) {
116 Set<GameRecord>
set =
new HashSet<>();
117 if (GLOBAL_RECORDS ==
null || GLOBAL_RECORDS.isEmpty()) {
121 for (GameRecord tracker : GLOBAL_RECORDS) {
122 if (!tracker.name.equalsIgnoreCase(name))
129 private static List<GameRecord> getActivities(ActivityType activity) {
130 List<GameRecord>
set =
new ArrayList<>();
131 for (GameRecord tracker : GLOBAL_RECORDS) {
132 if (tracker.activityType != activity)
136 set.sort(Comparator.comparingLong(record -> record.time));
140 public static void load() {
141 Type type =
new TypeToken<Set<GameRecord>>() {
143 Path path = Paths.get(
"data",
"/content/game/game_records.json");
144 try (FileReader reader =
new FileReader(path.toFile())) {
145 JsonParser parser =
new JsonParser();
146 GLOBAL_RECORDS =
new GsonBuilder().create().fromJson(parser.parse(reader), type);
147 }
catch (Exception e) {
152 public static void save() {
154 try (FileWriter fw =
new FileWriter(
"./data/content/game/game_records.json")) {
155 fw.write(GsonUtils.JSON_PRETTY_NO_NULLS.toJson(GLOBAL_RECORDS));
156 }
catch (
final Exception e) {