diff options
author | ThatGravyBoat <ThatGravyBoat@users.noreply.github.com> | 2021-07-15 04:07:36 +0000 |
---|---|---|
committer | GitHub Action <actions@github.com> | 2021-07-15 04:07:36 +0000 |
commit | 4e4058da31c3575b69c69d2d7bb3c9af29e248dc (patch) | |
tree | d46d48754f080386e23bb86e884580fed0f555f3 /src/main/java/com/thatgravyboat/skyblockhud/tracker | |
parent | 718740e85f48b57bf712a62f811cd4d34dd98450 (diff) | |
download | SkyblockHud-Death-Defied-4e4058da31c3575b69c69d2d7bb3c9af29e248dc.tar.gz SkyblockHud-Death-Defied-4e4058da31c3575b69c69d2d7bb3c9af29e248dc.tar.bz2 SkyblockHud-Death-Defied-4e4058da31c3575b69c69d2d7bb3c9af29e248dc.zip |
Prettified Code!
Diffstat (limited to 'src/main/java/com/thatgravyboat/skyblockhud/tracker')
3 files changed, 46 insertions, 41 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) {} diff --git a/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerHandler.java index 9832c4b..50dd04c 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerHandler.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerHandler.java @@ -21,7 +21,7 @@ public class TrackerHandler extends Gui { public static Set<TrackerObject> trackerObjects = new HashSet<>(); public static Map<Locations, Map<String, TrackerObject>> trackers = new HashMap<>(); - public static <K,V> Map<K, V> sortTrackers(Map<K, V> map, Comparator<? super Map.Entry<K, V>> comparator) { + public static <K, V> Map<K, V> sortTrackers(Map<K, V> map, Comparator<? super Map.Entry<K, V>> comparator) { List<Map.Entry<K, V>> list = new ArrayList<>(map.entrySet()); list.sort(comparator); @@ -46,7 +46,6 @@ public class TrackerHandler extends Gui { object.increaseCount(amount); trackers.put(LocationHandler.getCurrentLocation(), sortTrackers(trackerMap, (entry1, entry2) -> Integer.compare(entry2.getValue().getCount(), entry1.getValue().getCount()))); } - } } @@ -61,12 +60,12 @@ public class TrackerHandler extends Gui { } @SubscribeEvent - public void onSbEntityDeath(SkyBlockEntityKilled event){ + public void onSbEntityDeath(SkyBlockEntityKilled event) { System.out.println(event.id); if (SkyblockHud.hasSkyblockScoreboard() && trackers.containsKey(LocationHandler.getCurrentLocation())) { Map<String, TrackerObject> trackerMap = trackers.get(LocationHandler.getCurrentLocation()); - if (trackerMap.containsKey("ENTITY:"+event.id)){ - TrackerObject object = trackerMap.get("ENTITY:"+event.id); + if (trackerMap.containsKey("ENTITY:" + event.id)) { + TrackerObject object = trackerMap.get("ENTITY:" + event.id); object.increaseCount(); trackers.put(LocationHandler.getCurrentLocation(), sortTrackers(trackerMap, (entry1, entry2) -> Integer.compare(entry2.getValue().getCount(), entry1.getValue().getCount()))); } @@ -75,7 +74,7 @@ public class TrackerHandler extends Gui { @SubscribeEvent public void renderOverlay(RenderGameOverlayEvent.Post event) { - if (Utils.overlayShouldRender(event.type, SkyblockHud.hasSkyblockScoreboard(), trackers.containsKey(LocationHandler.getCurrentLocation()),!SkyblockHud.config.trackers.hideTracker)) { + if (Utils.overlayShouldRender(event.type, SkyblockHud.hasSkyblockScoreboard(), trackers.containsKey(LocationHandler.getCurrentLocation()), !SkyblockHud.config.trackers.hideTracker)) { Map<String, TrackerObject> tracker = trackers.get(LocationHandler.getCurrentLocation()); Minecraft mc = Minecraft.getMinecraft(); @@ -87,7 +86,7 @@ public class TrackerHandler extends Gui { Gui.drawRect(startPos, y, startPos + 130, y + 10, -1072689136); mc.fontRendererObj.drawString("Tracker", startPos + 4, y + 1, 0xffffff, false); y += 10; - Gui.drawRect(startPos, y, startPos + (tracker.size() >= 6 ? 130 : (tracker.size() * 20)+10), (int) (y + (Math.ceil(tracker.size() / 5d) * 20)), 1610612736); + Gui.drawRect(startPos, y, startPos + (tracker.size() >= 6 ? 130 : (tracker.size() * 20) + 10), (int) (y + (Math.ceil(tracker.size() / 5d) * 20)), 1610612736); int x = startPos + 5; for (TrackerObject object : tracker.values()) { String s = Utils.formattedNumber(object.getCount(), 1000); diff --git a/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerObject.java b/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerObject.java index 58034d5..6013b09 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerObject.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerObject.java @@ -19,14 +19,14 @@ public class TrackerObject { private final boolean isEntity; private int count; - public TrackerObject(JsonObject jsonObject, EnumSet<Locations> locations){ + public TrackerObject(JsonObject jsonObject, EnumSet<Locations> locations) { this.stack = decodeToItemStack(jsonObject); this.internalId = jsonObject.get("id").getAsString(); this.isEntity = jsonObject.get("id").getAsString().contains("entity:"); this.locations = locations; } - public static ItemStack decodeToItemStack(JsonObject jsonObject){ + public static ItemStack decodeToItemStack(JsonObject jsonObject) { jsonObject = jsonObject.getAsJsonObject("displayItem"); int meta = jsonObject.get("meta").getAsInt(); ResourceLocation itemid = new ResourceLocation(jsonObject.get("item").getAsString()); @@ -59,7 +59,7 @@ public class TrackerObject { } public void increaseCount(int amount) { - count+=amount; + count += amount; } public void increaseCount() { @@ -89,6 +89,4 @@ public class TrackerObject { public boolean isEntity() { return isEntity; } - - } |