diff options
Diffstat (limited to 'src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerFileLoader.java')
-rw-r--r-- | src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerFileLoader.java | 66 |
1 files changed, 37 insertions, 29 deletions
diff --git a/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerFileLoader.java b/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerFileLoader.java index 804ac60..81e8ed1 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerFileLoader.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerFileLoader.java @@ -18,12 +18,17 @@ public class TrackerFileLoader { for (JsonElement element : object.get("trackers").getAsJsonArray()) { JsonObject tracker = element.getAsJsonObject(); EnumSet<Locations> locations = EnumSet.noneOf(Locations.class); - tracker.get("location").getAsJsonArray().forEach(l -> { - Locations location = Locations.get(l.getAsString().toUpperCase(Locale.ENGLISH)); - if (location != Locations.DEFAULT){ - locations.add(location); - } - }); + tracker + .get("location") + .getAsJsonArray() + .forEach( + l -> { + Locations location = Locations.get(l.getAsString().toUpperCase(Locale.ENGLISH)); + if (location != Locations.DEFAULT) { + locations.add(location); + } + } + ); if (tracker.has("drops")) { for (JsonElement drop : tracker.get("drops").getAsJsonArray()) { TrackerHandler.trackerObjects.add(new TrackerObject(drop.getAsJsonObject(), locations)); @@ -38,16 +43,15 @@ public class TrackerFileLoader { for (TrackerObject trackerObject : TrackerHandler.trackerObjects) { for (Locations location : trackerObject.getLocations()) { - if (TrackerHandler.trackers.containsKey(location)){ + if (TrackerHandler.trackers.containsKey(location)) { TrackerHandler.trackers.get(location).put(trackerObject.getInternalId(), trackerObject); - }else { + } else { HashMap<String, TrackerObject> value = new HashMap<>(); value.put(trackerObject.getInternalId(), trackerObject); TrackerHandler.trackers.put(location, value); } } } - } public static void loadTrackersFile() { @@ -65,17 +69,19 @@ public class TrackerFileLoader { private static JsonElement getTrackerFile() { JsonArray stats = new JsonArray(); - TrackerHandler.trackerObjects.forEach((trackerObject) ->{ - if (trackerObject.getCount() > 0) { - JsonObject jsonObject = new JsonObject(); - JsonArray locations = new JsonArray(); - trackerObject.getLocations().forEach(l -> locations.add(new JsonPrimitive(l.toString().toUpperCase(Locale.ENGLISH)))); - jsonObject.add("id", new JsonPrimitive(trackerObject.getInternalId())); - jsonObject.add("locations", locations); - jsonObject.add("count", new JsonPrimitive(trackerObject.getCount())); - stats.add(jsonObject); + TrackerHandler.trackerObjects.forEach( + trackerObject -> { + if (trackerObject.getCount() > 0) { + JsonObject jsonObject = new JsonObject(); + JsonArray locations = new JsonArray(); + trackerObject.getLocations().forEach(l -> locations.add(new JsonPrimitive(l.toString().toUpperCase(Locale.ENGLISH)))); + jsonObject.add("id", new JsonPrimitive(trackerObject.getInternalId())); + jsonObject.add("locations", locations); + jsonObject.add("count", new JsonPrimitive(trackerObject.getCount())); + stats.add(jsonObject); + } } - }); + ); return stats; } @@ -90,7 +96,10 @@ public class TrackerFileLoader { try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8))) { JsonObject json = gson.fromJson(reader, JsonObject.class); if (json.has("trackerStats")) { - json.getAsJsonArray("trackerStats").forEach(element -> { + json + .getAsJsonArray("trackerStats") + .forEach( + element -> { if (element.isJsonObject()) { JsonObject object = element.getAsJsonObject(); JsonArray locations = object.get("locations").getAsJsonArray(); @@ -100,19 +109,18 @@ public class TrackerFileLoader { if (!firstLocation.equals(Locations.DEFAULT)) break; } - if (firstLocation != null && !firstLocation.equals(Locations.DEFAULT)){ + if (firstLocation != null && !firstLocation.equals(Locations.DEFAULT)) { TrackerHandler.trackers.get(firstLocation).get(object.get("id").getAsString()).setCount(object.get("count").getAsInt()); } } - }); - - TrackerHandler.trackers.forEach((location, map) -> { - TrackerHandler.trackers.put(location, - TrackerHandler.sortTrackers(map, - (entry1, entry2) -> Integer.compare(entry2.getValue().getCount(), entry1.getValue().getCount()) - ) + } ); - }); + + TrackerHandler.trackers.forEach( + (location, map) -> { + TrackerHandler.trackers.put(location, TrackerHandler.sortTrackers(map, (entry1, entry2) -> Integer.compare(entry2.getValue().getCount(), entry1.getValue().getCount()))); + } + ); } } } catch (Exception ignored) {} |