RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
GlobalRecords.java
1/*
2package com.osroyale.content.activity.record;
3
4import com.google.common.reflect.TypeToken;
5import com.google.gson.Gson;
6import com.google.gson.GsonBuilder;
7import com.google.gson.JsonParser;
8import com.osroyale.content.activity.ActivityType;
9import com.osroyale.game.world.entity.mob.player.Player;
10import com.osroyale.net.packet.out.SendScrollbar;
11import com.osroyale.net.packet.out.SendString;
12import com.osroyale.util.GsonUtils;
13import com.osroyale.util.Utility;
14
15import java.io.FileReader;
16import java.io.FileWriter;
17import java.lang.reflect.Type;
18import java.nio.file.Path;
19import java.nio.file.Paths;
20import java.util.*;
21
22*//*
26
55
56public class GlobalRecords {
57
58 private static Set<GameRecord> GLOBAL_RECORDS = new HashSet<>();
59
60 public static void display(Player player, ActivityType activity) {
61 List<GameRecord> list = getActivities(activity);
62 player.gameRecord.showActivities(activity);
63
64 for (int index = 0, count = 0; index < 25; index++) {
65 if (index >= list.size())
66 continue;
67 GameRecord record = list.get(index);
68 count++;
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));
71 count++;
72 player.send(new SendString(record.name, 32401 + count));
73 count++;
74 player.send(new SendString(Utility.getTime(record.time), 32401 + count));
75 count++;
76 player.send(new SendString(record.date, 32401 + count));
77 count++;
78 }
79
80 player.send(new SendScrollbar(32400, 696));
81 player.interfaceManager.open(32300);
82 }
83
84 public static void add(Player player, GameRecord tracker) {
85 GameRecord record = getTracker(player.getName(), tracker.activityType);
86 if (record == null) {
87 GLOBAL_RECORDS.add(tracker);
88 return;
89 }
90 if (tracker.time > record.time) {
91 GLOBAL_RECORDS.remove(record);
92 GLOBAL_RECORDS.add(tracker);
93 }
94 }
95
96 private static GameRecord getTracker(String name, ActivityType activity) {
97 Set<GameRecord> set = getGlobalRecords(name);
98
99 if (set == null || set.isEmpty()) {
100 return null;
101 }
102
103 for (GameRecord t : set) {
104 if (t.activityType == activity)
105 return t;
106 }
107 return null;
108 }
109
110 static GameRecord getTopRecord(ActivityType activity) {
111 List<GameRecord> records = getActivities(activity);
112 return records.isEmpty() ? null : records.get(0);
113 }
114
115 private static Set<GameRecord> getGlobalRecords(String name) {
116 Set<GameRecord> set = new HashSet<>();
117 if (GLOBAL_RECORDS == null || GLOBAL_RECORDS.isEmpty()) {
118 return set;
119 }
120
121 for (GameRecord tracker : GLOBAL_RECORDS) {
122 if (!tracker.name.equalsIgnoreCase(name))
123 continue;
124 set.add(tracker);
125 }
126 return set;
127 }
128
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)
133 continue;
134 set.add(tracker);
135 }
136 set.sort(Comparator.comparingLong(record -> record.time));
137 return set;
138 }
139
140 public static void load() {
141 Type type = new TypeToken<Set<GameRecord>>() {
142 }.getType();
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) {
148 e.printStackTrace();
149 }
150 }
151
152 public static void save() {
153 new Thread(() -> {
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) {
157 e.printStackTrace();
158 }
159 }).start();
160 }
161}
162*/