RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
FameHandler.java
1package com.osroyale.content.famehall;
2
3import com.google.gson.Gson;
4import com.google.gson.GsonBuilder;
5import com.google.gson.JsonParser;
6import com.google.gson.reflect.TypeToken;
7import com.osroyale.game.world.entity.mob.player.Player;
8import com.osroyale.game.world.entity.mob.player.PlayerRight;
9import com.osroyale.game.world.World;
10import com.osroyale.game.world.items.Item;
11import com.osroyale.net.packet.out.*;
12import com.osroyale.util.Utility;
13
14import java.io.FileReader;
15import java.io.FileWriter;
16import java.lang.reflect.Type;
17import java.nio.file.Path;
18import java.nio.file.Paths;
19import java.util.HashMap;
20import java.util.List;
21import java.util.Map;
22import java.util.Map.Entry;
23
61
62* This class handles the fame system.
63 *
64 * @author Daniel
65 */
66public class FameHandler {
67
69 public static Map<FameEntry, Fame> HALL_OF_FAME = new HashMap<>();
70
79 public static void activate(Player player, FameEntry fameEntry) {
80 if (!HALL_OF_FAME.containsKey(fameEntry)) {
81 HALL_OF_FAME.put(fameEntry, new Fame(fameEntry.getType(), PlayerRight.getCrown(player) + " " + player.getName(), Utility.getDate()));
82 player.send(new SendMessage("Congratulations, you have left your mark on the hall of fame!"));
83 World.sendBroadcast(1, player.getName() + " is now on the hall of fame for " + fameEntry.getEntry(), false);
84 save();
85 }
86 }
87
94 public static void remove(FameEntry fameEntry) {
95 if (HALL_OF_FAME.containsKey(fameEntry))
96 HALL_OF_FAME.remove(fameEntry);
97 }
98
106 public static Map<FameEntry, Fame> getEntries(FameType type) {
107 Map<FameEntry, Fame> hall = new HashMap<>();
108 for (Entry<FameEntry, Fame> entries : HALL_OF_FAME.entrySet()) {
109 if (entries.getKey().getType() == type)
110 hall.put(entries.getKey(), entries.getValue());
111 }
112 return hall;
113 }
114
122 private static Fame getEntry(FameEntry entry) {
123 Fame result = null;
124 for (Entry<FameEntry, Fame> fame : getEntries(entry.getType()).entrySet()) {
125 if (fame.getKey().name().equalsIgnoreCase(entry.name())) {
126 result = fame.getValue();
127 break;
128 }
129 }
130 return result;
131 }
132
141 public static void open(Player player, FameType type) {
142 int string = 58533;
143 List<FameEntry> entry_list = FameEntry.getEntries(type);
144 Item[] items = new Item[entry_list.size()];
145
146 for (int index = 0; index < entry_list.size(); index++) {
147 FameEntry display = entry_list.get(index);
148 Fame fame = getEntry(display);
149
150 items[index] = new Item(display.getDisplay());
151 player.send(new SendString(display == null ? "" : display.getEntry(), string));
152 string++;
153 player.send(new SendString(fame == null ? "---" : fame.getName(), string));
154 string++;
155 player.send(new SendString(fame == null ? "---" : fame.getAccomplished(), string));
156 string++;
157 string++;
158 }
159
160 player.send(new SendConfig(1150, type.ordinal()));
161 player.send(new SendString(HALL_OF_FAME.size() + "/" + FameEntry.values().length + " Remaining", 58523));
162 player.send(new SendString("<col=" + (type.ordinal() == 0 ? "ffffff" : "ff9933") + ">Player Killing", 58515));
163 player.send(new SendString("<col=" + (type.ordinal() == 1 ? "ffffff" : "ff9933") + ">Monster Killing", 58516));
164 player.send(new SendString("<col=" + (type.ordinal() == 2 ? "ffffff" : "ff9933") + ">Skilling", 58517));
165 player.send(new SendString("<col=" + (type.ordinal() == 3 ? "ffffff" : "ff9933") + ">Miscellaneous", 58518));
166 player.send(new SendItemOnInterface(58531, items));
167 player.send(new SendScrollbar(58530, (entry_list.size() * 34)));
168 player.interfaceManager.open(58500);
169 }
170
179 public static void search(Player player, String context) {
180 int index = 0;
181 for (Entry<FameEntry, Fame> entries : HALL_OF_FAME.entrySet()) {
182 if (entries.getValue().getName().equalsIgnoreCase(context)) {
183 index++;
184 }
185 }
186
187 String message = index == 0 ? Utility.formatName(context) + " was not found in the hall of fame." : index + " entries were found in the hall of fame for " + Utility.formatName(context) + ".";
188 player.send(new SendMessage(message));
189 }
190
194 public static void load() {
195 Type type = new TypeToken<Map<FameEntry, Fame>>() {
196 }.getType();
197
198 Path path = Paths.get("data", "/content/fame/hall_of_fame_list.json");
199 try (FileReader reader = new FileReader(path.toFile())) {
200 JsonParser parser = new JsonParser();
201 HALL_OF_FAME = new GsonBuilder().create().fromJson(parser.parse(reader), type);
202 } catch (Exception e) {
203 e.printStackTrace();
204 }
205 }
206
210 public static void save() {
211 Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
212 try (FileWriter fw = new FileWriter("./data/content/fame/hall_of_fame_list.json")) {
213 fw.write(gson.toJson(HALL_OF_FAME));
214 } catch (final Exception e) {
215 e.printStackTrace();
216 }
217 }
218}
static void open(Player player, FameType type)
static void activate(Player player, FameEntry fameEntry)
static Map< FameEntry, Fame > HALL_OF_FAME
static Map< FameEntry, Fame > getEntries(FameType type)
static void search(Player player, String context)
static void sendBroadcast(int time, String message, boolean countdown)
Definition World.java:455
static String getDate()
Definition Utility.java:163
static List< FameEntry > getEntries(FameType type)
String getEntry()
int getDisplay()
FameType getType()