diff options
author | ThatGravyBoat <ThatGravyBoat@users.noreply.github.com> | 2021-07-27 07:09:21 +0000 |
---|---|---|
committer | GitHub Action <actions@github.com> | 2021-07-27 07:09:21 +0000 |
commit | 8f14ae49e5cfd329a70895e74ebb22bc7559f32e (patch) | |
tree | a9b6e44d5b404fba4ff1f14462bb592bdbfa16bb /src/main | |
parent | 7809a1362c9644c9bfb69d8563a13e3f1ed3354a (diff) | |
download | SkyblockHud-Death-Defied-8f14ae49e5cfd329a70895e74ebb22bc7559f32e.tar.gz SkyblockHud-Death-Defied-8f14ae49e5cfd329a70895e74ebb22bc7559f32e.tar.bz2 SkyblockHud-Death-Defied-8f14ae49e5cfd329a70895e74ebb22bc7559f32e.zip |
Prettified Code!
Diffstat (limited to 'src/main')
9 files changed, 71 insertions, 58 deletions
diff --git a/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java b/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java index 9b3da58..99f04e9 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java @@ -97,7 +97,9 @@ public class SkyblockHud { ((IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager()).registerReloadListener(new Textures()); configDirectory = new File(event.getModConfigurationDirectory(), "skyblockhud"); - try { configDirectory.mkdir(); } catch (Exception ignored){} + try { + configDirectory.mkdir(); + } catch (Exception ignored) {} configFile = new File(configDirectory, "sbh-config.json"); @@ -194,7 +196,7 @@ public class SkyblockHud { String stripped = message.replace("your profile was changed to:", "").replace("(co-op)", "").trim(); MinecraftForge.EVENT_BUS.post(new ProfileSwitchedEvent(stripped)); } - if (message.startsWith("you are playing on profile:")){ + if (message.startsWith("you are playing on profile:")) { String stripped = message.replace("you are playing on profile:", "").replace("(co-op)", "").trim(); MinecraftForge.EVENT_BUS.post(new ProfileJoinedEvent(stripped)); } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/api/events/ProfileJoinedEvent.java b/src/main/java/com/thatgravyboat/skyblockhud/api/events/ProfileJoinedEvent.java index ba24a5d..f1d4d38 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/api/events/ProfileJoinedEvent.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/api/events/ProfileJoinedEvent.java @@ -6,7 +6,7 @@ public class ProfileJoinedEvent extends Event { public String profile; - public ProfileJoinedEvent(String profile){ + public ProfileJoinedEvent(String profile) { this.profile = profile; } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/api/events/ProfileSwitchedEvent.java b/src/main/java/com/thatgravyboat/skyblockhud/api/events/ProfileSwitchedEvent.java index e8561c6..408ac8a 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/api/events/ProfileSwitchedEvent.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/api/events/ProfileSwitchedEvent.java @@ -6,8 +6,7 @@ public class ProfileSwitchedEvent extends Event { public String profile; - public ProfileSwitchedEvent(String profile){ + public ProfileSwitchedEvent(String profile) { this.profile = profile; } - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/api/item/IAbility.java b/src/main/java/com/thatgravyboat/skyblockhud/api/item/IAbility.java index bd7e81f..4f330d9 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/api/item/IAbility.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/api/item/IAbility.java @@ -1,7 +1,6 @@ package com.thatgravyboat.skyblockhud.api.item; public interface IAbility { - String getAbility(); int getAbilityTime(); diff --git a/src/main/java/com/thatgravyboat/skyblockhud/commands/Commands.java b/src/main/java/com/thatgravyboat/skyblockhud/commands/Commands.java index 90333b5..e8ac1d3 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/commands/Commands.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/commands/Commands.java @@ -54,9 +54,9 @@ public class Commands { break; case "copySkin": Entity entity = Minecraft.getMinecraft().objectMouseOver.entityHit; - if (entity instanceof AbstractClientPlayer){ - clipboard = new StringSelection("http://textures.minecraft.net/texture/"+((AbstractClientPlayer) entity).getLocationSkin().getResourcePath().replace("skins/", "")); - }else { + if (entity instanceof AbstractClientPlayer) { + clipboard = new StringSelection("http://textures.minecraft.net/texture/" + ((AbstractClientPlayer) entity).getLocationSkin().getResourcePath().replace("skins/", "")); + } else { sendSBHMessage(sender, "Not a player!"); } break; diff --git a/src/main/java/com/thatgravyboat/skyblockhud/handlers/CooldownHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/handlers/CooldownHandler.java index d7d3a41..e53e937 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/handlers/CooldownHandler.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/handlers/CooldownHandler.java @@ -22,9 +22,9 @@ public class CooldownHandler { private static final Map<String, Cooldown> COOLDOWNS = new HashMap<>(); public static Matcher getAbility(NBTTagCompound nbt) { - if (nbt != null && nbt.hasKey("ExtraAttributes") && nbt.getCompoundTag("ExtraAttributes").hasKey("uuid") && nbt.hasKey("display")){ + if (nbt != null && nbt.hasKey("ExtraAttributes") && nbt.getCompoundTag("ExtraAttributes").hasKey("uuid") && nbt.hasKey("display")) { NBTTagCompound display = nbt.getCompoundTag("display"); - if (display != null && display.hasKey("Lore")){ + if (display != null && display.hasKey("Lore")) { NBTTagList lore = display.getTagList("Lore", 8); List<String> loreList = new ArrayList<>(); for (int i = 0; i < lore.tagCount(); i++) { @@ -32,7 +32,7 @@ public class CooldownHandler { if (!loreLine.isEmpty()) loreList.add(loreLine); } Matcher abilityMatcher = ABILITY_REGEX.matcher(String.join(" ", loreList)); - if (abilityMatcher.find()){ + if (abilityMatcher.find()) { return abilityMatcher; } } @@ -41,11 +41,11 @@ public class CooldownHandler { } private static void addCooldown(IAbility ability) { - COOLDOWNS.putIfAbsent(ability.getAbility(), new Cooldown(ability.getAbilityTime()*20)); + COOLDOWNS.putIfAbsent(ability.getAbility(), new Cooldown(ability.getAbilityTime() * 20)); } @SubscribeEvent - public void tick(TickEvent.ClientTickEvent event){ + public void tick(TickEvent.ClientTickEvent event) { if (SkyblockHud.config.misc.hideItemCooldowns) return; if (event.phase.equals(TickEvent.Phase.END)) { COOLDOWNS.values().forEach(Cooldown::tick); @@ -56,9 +56,9 @@ public class CooldownHandler { @SubscribeEvent public void onPlayerInteract(PlayerInteractEvent event) { if (SkyblockHud.config.misc.hideItemCooldowns) return; - if (event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_AIR) || event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK)){ + if (event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_AIR) || event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK)) { if (event.entityPlayer.getHeldItem() != null) { - IAbility ability = (IAbility)((Object) event.entityPlayer.getHeldItem()); + IAbility ability = (IAbility) ((Object) event.entityPlayer.getHeldItem()); if (ability.getAbility() != null) { addCooldown(ability); } @@ -66,8 +66,8 @@ public class CooldownHandler { } } - public static float getAbilityTime(ItemStack stack){ - IAbility ability = (IAbility)((Object) stack); + public static float getAbilityTime(ItemStack stack) { + IAbility ability = (IAbility) ((Object) stack); if (ability.getAbility() != null) { return COOLDOWNS.containsKey(ability.getAbility()) ? COOLDOWNS.get(ability.getAbility()).getTime() : -1f; } @@ -75,10 +75,11 @@ public class CooldownHandler { } private static class Cooldown { + public int current; public final int end; - Cooldown(int end){ + Cooldown(int end) { this.end = end; } @@ -91,8 +92,7 @@ public class CooldownHandler { } public float getTime() { - return current/(float)end; + return current / (float) end; } } - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/handlers/WarpHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/handlers/WarpHandler.java index 71079b6..9eaa421 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/handlers/WarpHandler.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/handlers/WarpHandler.java @@ -34,16 +34,16 @@ public class WarpHandler { } @SubscribeEvent - public void profileChange(ProfileSwitchedEvent event){ - if (profile != null && !profile.equals(event.profile)){ + public void profileChange(ProfileSwitchedEvent event) { + if (profile != null && !profile.equals(event.profile)) { load(); } profile = event.profile; } @SubscribeEvent - public void profileJoined(ProfileJoinedEvent event){ - if (profile != null && !profile.equals(event.profile)){ + public void profileJoined(ProfileJoinedEvent event) { + if (profile != null && !profile.equals(event.profile)) { load(); } profile = event.profile; @@ -53,24 +53,24 @@ public class WarpHandler { public void onGuiClosed(GuiOpenEvent event) { boolean changed = false; GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen; - if (currentScreen instanceof GuiChest){ + if (currentScreen instanceof GuiChest) { GuiChestAccessor accessor = (GuiChestAccessor) currentScreen; - if (accessor.getLowerChestInventory().getDisplayName().getUnformattedText().contains("Fast Travel")){ + if (accessor.getLowerChestInventory().getDisplayName().getUnformattedText().contains("Fast Travel")) { for (int i = 9; i < Math.min(36, accessor.getLowerChestInventory().getSizeInventory()); i++) { ItemStack stack = accessor.getLowerChestInventory().getStackInSlot(i); - if (stack != null && stack.getItem().equals(Items.skull) && stack.getTagCompound().hasKey("display")){ + if (stack != null && stack.getItem().equals(Items.skull) && stack.getTagCompound().hasKey("display")) { NBTTagList lore = stack.getTagCompound().getCompoundTag("display").getTagList("Lore", 8); String warpLine = Utils.removeColor(lore.getStringTagAt(0)).trim(); if (warpLine.equals("Unknown island!")) continue; - String disabledLine = Utils.removeColor(lore.getStringTagAt(lore.tagCount()-1)).trim(); + String disabledLine = Utils.removeColor(lore.getStringTagAt(lore.tagCount() - 1)).trim(); Warp warp = Warp.fromId(warpLine.replace("/warp", "").trim()); if (warp != null && !disabledLine.equals("Warp not unlocked!")) { - if (PLAYER_WARPS.put(profile, warp)){ + if (PLAYER_WARPS.put(profile, warp)) { changed = true; } } @@ -84,14 +84,18 @@ public class WarpHandler { public static void save() { JsonObject json = new JsonObject(); JsonArray array = new JsonArray(); - PLAYER_WARPS.asMap().forEach((profile, warps) -> { - JsonObject profileObject = new JsonObject(); - profileObject.addProperty("profile", profile); - JsonArray warpArray = new JsonArray(); - warps.forEach(warp -> warpArray.add(new JsonPrimitive(warp.name()))); - profileObject.add("warps", warpArray); - array.add(profileObject); - }); + PLAYER_WARPS + .asMap() + .forEach( + (profile, warps) -> { + JsonObject profileObject = new JsonObject(); + profileObject.addProperty("profile", profile); + JsonArray warpArray = new JsonArray(); + warps.forEach(warp -> warpArray.add(new JsonPrimitive(warp.name()))); + profileObject.add("warps", warpArray); + array.add(profileObject); + } + ); json.add("profileWarps", array); warpConfig = new File(SkyblockHud.configDirectory, "sbh-warps.json"); @@ -111,15 +115,25 @@ public class WarpHandler { if (warpConfig.createNewFile()) return true; try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(warpConfig), StandardCharsets.UTF_8))) { JsonObject json = GSON.fromJson(reader, JsonObject.class); - json.get("profileWarps").getAsJsonArray().forEach(jsonElement -> { - JsonObject profileObject = jsonElement.getAsJsonObject(); - List<Warp> warps = new ArrayList<>(); - profileObject.get("warps").getAsJsonArray().forEach(warpId -> { - Warp warp = Warp.safeValueOf(warpId.getAsString()); - if (warp != null) warps.add(warp); - }); - PLAYER_WARPS.putAll(profileObject.get("profile").getAsString(), warps); - }); + json + .get("profileWarps") + .getAsJsonArray() + .forEach( + jsonElement -> { + JsonObject profileObject = jsonElement.getAsJsonObject(); + List<Warp> warps = new ArrayList<>(); + profileObject + .get("warps") + .getAsJsonArray() + .forEach( + warpId -> { + Warp warp = Warp.safeValueOf(warpId.getAsString()); + if (warp != null) warps.add(warp); + } + ); + PLAYER_WARPS.putAll(profileObject.get("profile").getAsString(), warps); + } + ); } } catch (Exception ignored) {} return false; @@ -149,24 +163,23 @@ public class WarpHandler { public String warpId; - Warp(String warpId){ + Warp(String warpId) { this.warpId = warpId; } - public static Warp fromId(String id){ + public static Warp fromId(String id) { for (Warp value : Warp.values()) { if (value.warpId.equals(id)) return value; } return null; } - public static Warp safeValueOf(String value){ + public static Warp safeValueOf(String value) { try { return Warp.valueOf(value); - }catch (Exception e) { + } catch (Exception e) { return null; } } } - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/mixins/GuiChestAccessor.java b/src/main/java/com/thatgravyboat/skyblockhud/mixins/GuiChestAccessor.java index a300f9e..0a1fb75 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/mixins/GuiChestAccessor.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/mixins/GuiChestAccessor.java @@ -7,7 +7,6 @@ import org.spongepowered.asm.mixin.gen.Accessor; @Mixin(GuiChest.class) public interface GuiChestAccessor { - @Accessor IInventory getLowerChestInventory(); } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinRenderItem.java b/src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinRenderItem.java index 08f9314..269920f 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinRenderItem.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinRenderItem.java @@ -16,14 +16,15 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(RenderItem.class) public abstract class MixinRenderItem { - @Shadow protected abstract void draw(WorldRenderer renderer, int x, int y, int width, int height, int red, int green, int blue, int alpha); + @Shadow + protected abstract void draw(WorldRenderer renderer, int x, int y, int width, int height, int red, int green, int blue, int alpha); - @Inject(method="renderItemOverlayIntoGUI", at=@At("RETURN")) + @Inject(method = "renderItemOverlayIntoGUI", at = @At("RETURN")) public void renderItemOverlayIntoGUI(FontRenderer fr, ItemStack stack, int xPosition, int yPosition, String text, CallbackInfo ci) { - if(stack == null) return; + if (stack == null) return; float cooldown = CooldownHandler.getAbilityTime(stack); - if (cooldown > -1){ + if (cooldown > -1) { GlStateManager.disableLighting(); GlStateManager.disableDepth(); GlStateManager.disableTexture2D(); @@ -31,7 +32,7 @@ public abstract class MixinRenderItem { GlStateManager.disableBlend(); WorldRenderer worldrenderer = Tessellator.getInstance().getWorldRenderer(); this.draw(worldrenderer, xPosition + 2, yPosition + 13, 13, 2, 0, 0, 0, 255); - this.draw(worldrenderer, xPosition + 2, yPosition + 13, Math.round(cooldown * 13f), 1, 102, 102, 255, 255); + this.draw(worldrenderer, xPosition + 2, yPosition + 13, Math.round(cooldown * 13f), 1, 102, 102, 255, 255); GlStateManager.enableAlpha(); GlStateManager.enableTexture2D(); GlStateManager.enableLighting(); |