diff options
author | ThatGravyBoat <thatgravyboat@gmail.com> | 2021-07-06 19:09:11 -0230 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-06 19:09:11 -0230 |
commit | 93248d28d6b314b42f6b0d82164975343b214ece (patch) | |
tree | e3e06c24454080f059355133d633e5a076d85ad3 /src/main/java/com/thatgravyboat/skyblockhud/tracker | |
parent | 91464c8f433e8bf323932ac956678971207b607e (diff) | |
parent | 804767ebfc26e2a1252bc327def02389b35dfc6e (diff) | |
download | SkyblockHud-Death-Defied-93248d28d6b314b42f6b0d82164975343b214ece.tar.gz SkyblockHud-Death-Defied-93248d28d6b314b42f6b0d82164975343b214ece.tar.bz2 SkyblockHud-Death-Defied-93248d28d6b314b42f6b0d82164975343b214ece.zip |
Merge pull request #2 from ThatGravyBoat/prettier
Add prettier settings and format code
Diffstat (limited to 'src/main/java/com/thatgravyboat/skyblockhud/tracker')
3 files changed, 84 insertions, 105 deletions
diff --git a/src/main/java/com/thatgravyboat/skyblockhud/tracker/KillTrackerHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/tracker/KillTrackerHandler.java index 6734283..5d5615f 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/tracker/KillTrackerHandler.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/tracker/KillTrackerHandler.java @@ -1,5 +1,8 @@ package com.thatgravyboat.skyblockhud.tracker; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; import net.minecraft.client.Minecraft; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.DamageSource; @@ -8,24 +11,19 @@ import net.minecraftforge.event.entity.living.LivingDeathEvent; import net.minecraftforge.event.entity.player.AttackEntityEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; - public class KillTrackerHandler { public static final Set<UUID> attackedEntities = new HashSet<>(); @SubscribeEvent - public void onAttack(AttackEntityEvent event){ + public void onAttack(AttackEntityEvent event) { if (event.target != null) { attackedEntities.add(event.target.getUniqueID()); } } @SubscribeEvent - public void onDeath(LivingDeathEvent event){ - + public void onDeath(LivingDeathEvent event) { if (false) { //Used for testing System.out.println("----------------------------------------------------------------------------------------------------------------"); @@ -41,32 +39,12 @@ public class KillTrackerHandler { attackedEntities.remove(event.entity.getUniqueID()); } - public static String getDamageSourceString(DamageSource source){ - return "{ " + - source.getDamageType() + - ", " + - source.isDamageAbsolute() + - ", " + - source.isDifficultyScaled() + - ", " + - source.isFireDamage() + - ", " + - source.isProjectile() + - ", " + - source.isUnblockable() + - ", " + - source.isExplosion() + - ", " + - source.isMagicDamage() + - ", " + - source.isCreativePlayer() + - ", " + - source.getSourceOfDamage() + - " }"; + public static String getDamageSourceString(DamageSource source) { + return ("{ " + source.getDamageType() + ", " + source.isDamageAbsolute() + ", " + source.isDifficultyScaled() + ", " + source.isFireDamage() + ", " + source.isProjectile() + ", " + source.isUnblockable() + ", " + source.isExplosion() + ", " + source.isMagicDamage() + ", " + source.isCreativePlayer() + ", " + source.getSourceOfDamage() + " }"); } @SubscribeEvent - public void onWorldChange(EntityJoinWorldEvent event){ + public void onWorldChange(EntityJoinWorldEvent event) { if (event.entity != null) { if (event.entity.getUniqueID().equals(Minecraft.getMinecraft().thePlayer.getUniqueID())) { attackedEntities.clear(); diff --git a/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerFileLoader.java b/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerFileLoader.java index d7f7512..624ca60 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerFileLoader.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerFileLoader.java @@ -2,6 +2,12 @@ package com.thatgravyboat.skyblockhud.tracker; import com.google.gson.*; import com.thatgravyboat.skyblockhud.location.Locations; +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import net.minecraft.client.Minecraft; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -10,30 +16,23 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.ResourceLocation; -import java.io.*; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - public class TrackerFileLoader { private static final Gson gson = new GsonBuilder().create(); - public static ItemStack getDisplayItem(JsonObject jsonObject){ + public static ItemStack getDisplayItem(JsonObject jsonObject) { int meta = jsonObject.get("meta").getAsInt(); String displayItemId = jsonObject.get("item").getAsString(); Item item = Item.itemRegistry.getObject(new ResourceLocation(displayItemId)); ItemStack stack = new ItemStack(item, 0, meta); - if (jsonObject.has("skullData") && displayItemId.equals("minecraft:skull") && meta == 3){ - stack.setTagInfo("SkullOwner",getSkullTag(jsonObject.getAsJsonObject("skullData"))); + if (jsonObject.has("skullData") && displayItemId.equals("minecraft:skull") && meta == 3) { + stack.setTagInfo("SkullOwner", getSkullTag(jsonObject.getAsJsonObject("skullData"))); } if (jsonObject.has("enchanted") && jsonObject.get("enchanted").getAsBoolean()) stack.setTagInfo("ench", new NBTTagList()); return stack; } - public static NBTBase getSkullTag(JsonObject skullObject){ + public static NBTBase getSkullTag(JsonObject skullObject) { NBTTagCompound skullOwner = new NBTTagCompound(); NBTTagCompound properties = new NBTTagCompound(); NBTTagList textures = new NBTTagList(); @@ -44,22 +43,21 @@ public class TrackerFileLoader { value.setString("Value", skullObject.get("texture").getAsString()); textures.appendTag(value); - properties.setTag("textures",textures); + properties.setTag("textures", textures); skullOwner.setTag("Properties", properties); return skullOwner; } - private static void loadTrackers(JsonObject object){ + private static void loadTrackers(JsonObject object) { for (JsonElement element : object.get("trackers").getAsJsonArray()) { JsonObject tracker = element.getAsJsonObject(); StringBuilder builder = new StringBuilder(); tracker.get("location").getAsJsonArray().forEach(loc -> builder.append(loc.getAsString())); String location = builder.toString(); - Map<String, ItemStack> stacks = new HashMap<>(); - for (JsonElement drop :tracker.get("drops").getAsJsonArray()) { + for (JsonElement drop : tracker.get("drops").getAsJsonArray()) { JsonObject dropObject = drop.getAsJsonObject(); //Display Item Creation @@ -74,9 +72,9 @@ public class TrackerFileLoader { Map<String, Map<String, ItemStack>> events = new HashMap<>(); events.put(event, stacks); - if (TrackerHandler.trackers.containsKey(location)){ + if (TrackerHandler.trackers.containsKey(location)) { TrackerHandler.trackers.get(location).dropTrackers.put(event, stacks); - }else { + } else { TrackerHandler.trackers.putIfAbsent(location, new TrackerHandler.TrackerData(events)); } @@ -84,28 +82,30 @@ public class TrackerFileLoader { } } - private static JsonElement getTrackerFile(){ + private static JsonElement getTrackerFile() { List<JsonObject> trackerStats = new ArrayList<>(); - TrackerHandler.trackers.forEach((locations, trackerData) -> - trackerData.dropTrackers.forEach((event, drops) -> { - JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty("location", locations); - - if (event == null) jsonObject.add("event", new JsonNull()); - else jsonObject.addProperty("event", event); - - JsonObject dropsData = new JsonObject(); - drops.forEach((s, stack) -> dropsData.addProperty(s, stack.stackSize)); - jsonObject.add("drops", dropsData); - trackerStats.add(jsonObject); - } - )); + TrackerHandler.trackers.forEach( + (locations, trackerData) -> + trackerData.dropTrackers.forEach( + (event, drops) -> { + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("location", locations); + + if (event == null) jsonObject.add("event", new JsonNull()); else jsonObject.addProperty("event", event); + + JsonObject dropsData = new JsonObject(); + drops.forEach((s, stack) -> dropsData.addProperty(s, stack.stackSize)); + jsonObject.add("drops", dropsData); + trackerStats.add(jsonObject); + } + ) + ); JsonArray stats = new JsonArray(); trackerStats.forEach(stats::add); return stats; } - public static void loadTrackersFile(){ + public static void loadTrackersFile() { try { ResourceLocation trackers = new ResourceLocation("skyblockhud:data/trackers.json"); InputStream is = Minecraft.getMinecraft().getResourceManager().getResource(trackers).getInputStream(); @@ -113,59 +113,62 @@ public class TrackerFileLoader { try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) { loadTrackers(gson.fromJson(reader, JsonObject.class)); } - }catch (Exception ignored){} + } catch (Exception ignored) {} } - public static boolean loadTrackerStatsFile(File configDirectory){ + public static boolean loadTrackerStatsFile(File configDirectory) { File configFile = new File(configDirectory, "sbh-trackers-stats.json"); try { - if (configFile.createNewFile()){ + if (configFile.createNewFile()) { return true; } 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 -> { - if (element.isJsonObject()){ - JsonObject object = element.getAsJsonObject(); - String location = object.get("location").getAsString(); - Map<String, Map<String, ItemStack>> trackers = TrackerHandler.trackers.get(location).dropTrackers; - - JsonElement event = object.get("event"); - String eventString = event == null || event.isJsonNull() ? null : event.getAsString(); - Map<String, ItemStack> drops = trackers.get(eventString); - - if (drops != null) { - for (Map.Entry <String ,JsonElement> drop :object.getAsJsonObject("drops").entrySet()) { - if (drops.containsKey(drop.getKey())) { - drops.get(drop.getKey()).stackSize = drop.getValue().getAsInt(); + if (json.has("trackerStats")) { + json + .getAsJsonArray("trackerStats") + .forEach( + element -> { + if (element.isJsonObject()) { + JsonObject object = element.getAsJsonObject(); + String location = object.get("location").getAsString(); + Map<String, Map<String, ItemStack>> trackers = TrackerHandler.trackers.get(location).dropTrackers; + + JsonElement event = object.get("event"); + String eventString = event == null || event.isJsonNull() ? null : event.getAsString(); + Map<String, ItemStack> drops = trackers.get(eventString); + + if (drops != null) { + for (Map.Entry<String, JsonElement> drop : object.getAsJsonObject("drops").entrySet()) { + if (drops.containsKey(drop.getKey())) { + drops.get(drop.getKey()).stackSize = drop.getValue().getAsInt(); + } + } + drops = TrackerHandler.sortTrackers(drops); + trackers.put(eventString, drops); } } - drops = TrackerHandler.sortTrackers(drops); - trackers.put(eventString, drops); } - } - }); + ); } } - } catch(Exception ignored) {} + } catch (Exception ignored) {} return false; } - public static void saveTrackerStatsFile(File configDirectory){ + public static void saveTrackerStatsFile(File configDirectory) { File configFile = new File(configDirectory, "sbh-trackers-stats.json"); try { configFile.createNewFile(); - try(BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(configFile), StandardCharsets.UTF_8))) { + try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(configFile), StandardCharsets.UTF_8))) { JsonObject json = new JsonObject(); json.add("trackerStats", getTrackerFile()); writer.write(gson.toJson(json)); } - } catch(IOException ignored) {} + } catch (IOException ignored) {} } - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerHandler.java index 9d8261b..fa2bacf 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerHandler.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerHandler.java @@ -6,6 +6,7 @@ import com.thatgravyboat.skyblockhud.core.config.Position; import com.thatgravyboat.skyblockhud.location.LocationHandler; import com.thatgravyboat.skyblockhud.location.Locations; import com.thatgravyboat.skyblockhud.seasons.SeasonDateHandler; +import java.util.*; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.GlStateManager; @@ -15,29 +16,28 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import java.util.*; - public class TrackerHandler { public static class TrackerData { - public Map<String, Map<String,ItemStack>> dropTrackers; - public TrackerData(Map<String, Map<String,ItemStack>> trackers) { + public Map<String, Map<String, ItemStack>> dropTrackers; + + public TrackerData(Map<String, Map<String, ItemStack>> trackers) { this.dropTrackers = trackers; } - public String getDropId(String event){ + public String getDropId(String event) { if (event == null || event.isEmpty() || !eventGoing() || !dropTrackers.containsKey(event.toLowerCase().trim())) return null; return event.toLowerCase().trim(); } - private boolean eventGoing(){ + private boolean eventGoing() { return SeasonDateHandler.getCurrentEventTime().trim().toLowerCase().contains("ends in"); } } public static Map<String, TrackerData> trackers = new HashMap<>(); - public static Map<Locations,String> trackerIds = new HashMap<>(); + public static Map<Locations, String> trackerIds = new HashMap<>(); public static Map<String, ItemStack> sortTrackers(Map<String, ItemStack> map) { List<Map.Entry<String, ItemStack>> list = new ArrayList<>(map.entrySet()); @@ -51,18 +51,18 @@ public class TrackerHandler { return result; } - public static void onItemAdded(String id, int amount, String enchant, int level){ - if (SkyblockHud.hasSkyblockScoreboard() && trackerIds.containsKey(LocationHandler.getCurrentLocation())){ + public static void onItemAdded(String id, int amount, String enchant, int level) { + if (SkyblockHud.hasSkyblockScoreboard() && trackerIds.containsKey(LocationHandler.getCurrentLocation())) { String trackerId = trackerIds.get(LocationHandler.getCurrentLocation()); TrackerData tracked = trackers.get(trackerId); String dropTrackerId = tracked.getDropId(SeasonDateHandler.getCurrentEvent()); - Map<String,ItemStack> tracker = tracked.dropTrackers.get(dropTrackerId); + Map<String, ItemStack> tracker = tracked.dropTrackers.get(dropTrackerId); String dropId = id; - if (enchant != null){ + if (enchant != null) { dropId = enchant.toUpperCase() + ";" + level; } - if (tracker != null && tracker.containsKey(dropId)){ + if (tracker != null && tracker.containsKey(dropId)) { ItemStack stack = tracker.get(dropId); stack.stackSize += amount; tracked.dropTrackers.put(dropTrackerId, sortTrackers(tracker)); @@ -71,7 +71,7 @@ public class TrackerHandler { } public static void drawItemStack(ItemStack stack, int x, int y) { - if(stack == null)return; + if (stack == null) return; RenderItem itemRender = Minecraft.getMinecraft().getRenderItem(); RenderHelper.enableGUIStandardItemLighting(); itemRender.zLevel = -145; @@ -119,6 +119,4 @@ public class TrackerHandler { } } } - - } |