From 6e1a86bc1fe07a90cba5e6a6a2070b46474e5597 Mon Sep 17 00:00:00 2001 From: ILikePlayingGames <22475143+ILikePlayingGames@users.noreply.github.com> Date: Wed, 31 Aug 2022 01:43:45 -0400 Subject: [PATCH 1/2] Add toggle for showing number separators and fix a bunch of small warnings --- .../skyblockaddons/SkyblockAddons.java | 9 +++-- .../skyblockaddons/config/ConfigValues.java | 1 - .../biscuit/skyblockaddons/core/Feature.java | 6 ++- .../skyblockaddons/core/SkyblockDate.java | 3 +- .../core/dungeons/DungeonManager.java | 4 +- .../features/discordrpc/DiscordStatus.java | 10 ++--- .../dungeonmap/DungeonMapManager.java | 10 ++--- .../fishParticles/FishParticleManager.java | 12 +++--- .../listeners/RenderListener.java | 37 +++++++++++-------- .../skyblockaddons/shader/ShaderHelper.java | 2 +- .../shader/chroma/Chroma3DShader.java | 4 +- .../shader/chroma/ChromaScreenShader.java | 4 +- .../chroma/ChromaScreenTexturedShader.java | 4 +- .../skyblockaddons/utils/DrawUtils.java | 10 ++--- .../skyblockaddons/utils/ItemUtils.java | 2 - .../skyblockaddons/utils/TextUtils.java | 28 ++++++++++---- .../biscuit/skyblockaddons/utils/Utils.java | 8 ---- src/main/resources/lang/en_US.json | 3 +- 18 files changed, 84 insertions(+), 73 deletions(-) diff --git a/src/main/java/codes/biscuit/skyblockaddons/SkyblockAddons.java b/src/main/java/codes/biscuit/skyblockaddons/SkyblockAddons.java index aab7639860..73f50596b1 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/SkyblockAddons.java +++ b/src/main/java/codes/biscuit/skyblockaddons/SkyblockAddons.java @@ -23,10 +23,7 @@ import codes.biscuit.skyblockaddons.misc.scheduler.Scheduler; import codes.biscuit.skyblockaddons.misc.scheduler.SkyblockRunnable; import codes.biscuit.skyblockaddons.newgui.GuiManager; -import codes.biscuit.skyblockaddons.utils.EnumUtils; -import codes.biscuit.skyblockaddons.utils.InventoryUtils; -import codes.biscuit.skyblockaddons.utils.SkyblockAddonsMessageFactory; -import codes.biscuit.skyblockaddons.utils.Utils; +import codes.biscuit.skyblockaddons.utils.*; import codes.biscuit.skyblockaddons.utils.data.DataUtils; import codes.biscuit.skyblockaddons.utils.gson.GsonInitializableTypeAdapter; import codes.biscuit.skyblockaddons.utils.gson.PatternAdapter; @@ -192,6 +189,10 @@ public void init(FMLInitializationEvent e) { usingLabymod = utils.isModLoaded("labymod"); usingOofModv1 = utils.isModLoaded("refractionoof", "1.0"); usingPatcher = utils.isModLoaded("patcher"); + + if (!this.configValues.isEnabled(Feature.NUMBER_SEPARATORS)) { + TextUtils.NUMBER_FORMAT.setGroupingUsed(false); + } } @Mod.EventHandler diff --git a/src/main/java/codes/biscuit/skyblockaddons/config/ConfigValues.java b/src/main/java/codes/biscuit/skyblockaddons/config/ConfigValues.java index 14d2fd9ed4..23f0d82e30 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/config/ConfigValues.java +++ b/src/main/java/codes/biscuit/skyblockaddons/config/ConfigValues.java @@ -519,7 +519,6 @@ private , F extends Enum> void deserializeEnumEnumMapFromID } } - @SuppressWarnings("unchecked") private , N extends Number> void deserializeEnumNumberMapFromID(Map map, String path, Class keyClass, Class numberClass) { deserializeEnumNumberMapFromID(loadedConfig, map, path, keyClass, numberClass); } diff --git a/src/main/java/codes/biscuit/skyblockaddons/core/Feature.java b/src/main/java/codes/biscuit/skyblockaddons/core/Feature.java index aa3190eec4..23ef34233a 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/core/Feature.java +++ b/src/main/java/codes/biscuit/skyblockaddons/core/Feature.java @@ -216,6 +216,8 @@ public enum Feature { SHOW_SKYBLOCK_ITEM_ID(213, "settings.showSkyblockItemId", null, true), RESET_SALVAGED_ESSENCES_AFTER_LEAVING_MENU(214, "settings.resetSalvagedEssencesAfterLeavingMenu", null, false), CHANGE_DUNGEON_MAP_ZOOM_WITH_KEYBOARD(215, "settings.changeDungeonMapZoomWithKeyboard", null, false), + // Release 1.7 + NUMBER_SEPARATORS(216, "settings.numberSeparators", null, false), WARNING_TIME(-1, "settings.warningDuration", null, false), WARP_ADVANCED_MODE(-1, "settings.advancedMode", null, true), @@ -282,7 +284,7 @@ public enum Feature { */ @Getter private static final Set generalTabFeatures = new LinkedHashSet<>(Arrays.asList(TEXT_STYLE, WARNING_TIME, CHROMA_SPEED, CHROMA_MODE, - CHROMA_SIZE, TURN_ALL_FEATURES_CHROMA, CHROMA_SATURATION, CHROMA_BRIGHTNESS, USE_NEW_CHROMA_EFFECT, DEVELOPER_MODE)); + CHROMA_SIZE, TURN_ALL_FEATURES_CHROMA, CHROMA_SATURATION, CHROMA_BRIGHTNESS, USE_NEW_CHROMA_EFFECT, NUMBER_SEPARATORS, DEVELOPER_MODE)); private static final int ID_AT_PREVIOUS_UPDATE = 199; @@ -312,7 +314,7 @@ public enum Feature { } /** - * Called when a features enable state is changed. + * Called right after a feature's enable state is changed. */ public void onToggle() { if (this.id == DEVELOPER_MODE.id) { diff --git a/src/main/java/codes/biscuit/skyblockaddons/core/SkyblockDate.java b/src/main/java/codes/biscuit/skyblockaddons/core/SkyblockDate.java index 36a2b6b46d..5ba9b84549 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/core/SkyblockDate.java +++ b/src/main/java/codes/biscuit/skyblockaddons/core/SkyblockDate.java @@ -2,7 +2,6 @@ import codes.biscuit.skyblockaddons.utils.TextUtils; -import java.text.DecimalFormat; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -120,7 +119,7 @@ public String toString() { monthName, DAY + TextUtils.getOrdinalSuffix(DAY), HOUR, - TextUtils.NUMBER_FORMAT.format(MINUTE), + TextUtils.formatNumber(MINUTE), PERIOD); } } diff --git a/src/main/java/codes/biscuit/skyblockaddons/core/dungeons/DungeonManager.java b/src/main/java/codes/biscuit/skyblockaddons/core/dungeons/DungeonManager.java index 91df723fe1..0d67647883 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/core/dungeons/DungeonManager.java +++ b/src/main/java/codes/biscuit/skyblockaddons/core/dungeons/DungeonManager.java @@ -23,7 +23,7 @@ */ public class DungeonManager { - private static final Pattern PATTERN_MILESTONE = Pattern.compile("^.+?(Healer|Tank|Mage|Archer|Berserk) Milestone .+?([❶-❿]).+?§r§.(\\d+)§.§7 .+?"); + private static final Pattern PATTERN_MILESTONE = Pattern.compile("^.+?(Healer|Tank|Mage|Archer|Berserk) Milestone .+?([❶-❿]).+?§r§.([\\d,.]+)§.§7 .+?"); private static final Pattern PATTERN_COLLECTED_ESSENCES = Pattern.compile("§.+?(\\d+) (Wither|Spider|Undead|Dragon|Gold|Diamond|Ice) Essence"); private static final Pattern PATTERN_BONUS_ESSENCE = Pattern.compile("^§.+?[^You] .+?found a .+?(Wither|Spider|Undead|Dragon|Gold|Diamond|Ice) Essence.+?"); private static final Pattern PATTERN_SALVAGE_ESSENCES = Pattern.compile("\\+(?[0-9]+) (?Wither|Spider|Undead|Dragon|Gold|Diamond|Ice) Essence!"); @@ -42,7 +42,7 @@ public class DungeonManager { /** * Represents the number of essences from salvaged items by the player. - * + *

* It's in a separate map to avoid conflict with the collected map. */ @Getter private final Map salvagedEssences = new EnumMap<>(EssenceType.class); diff --git a/src/main/java/codes/biscuit/skyblockaddons/features/discordrpc/DiscordStatus.java b/src/main/java/codes/biscuit/skyblockaddons/features/discordrpc/DiscordStatus.java index fb9071d3f4..d5d5082108 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/features/discordrpc/DiscordStatus.java +++ b/src/main/java/codes/biscuit/skyblockaddons/features/discordrpc/DiscordStatus.java @@ -12,7 +12,7 @@ /** * Statuses that are shown on the Discord RPC feature - * + *

* This file has LF line endings because ForgeGradle is weird and will throw a NullPointerException if it's CRLF. */ public enum DiscordStatus implements ButtonSelect.SelectItem { @@ -36,9 +36,9 @@ public enum DiscordStatus implements ButtonSelect.SelectItem { String coinString = " Coin"; if (coins == 1) { - return TextUtils.formatDouble(coins) + coinString; + return TextUtils.formatNumber(coins) + coinString; } else { - return TextUtils.formatDouble(coins) + coinString + 's'; + return TextUtils.formatNumber(coins) + coinString + 's'; } }), @@ -48,9 +48,9 @@ public enum DiscordStatus implements ButtonSelect.SelectItem { String bitString = " Bit"; if (bits == 1) { - return TextUtils.formatDouble(bits) + bitString; + return TextUtils.formatNumber(bits) + bitString; } else { - return TextUtils.formatDouble(bits) + bitString + 's'; + return TextUtils.formatNumber(bits) + bitString + 's'; } }), diff --git a/src/main/java/codes/biscuit/skyblockaddons/features/dungeonmap/DungeonMapManager.java b/src/main/java/codes/biscuit/skyblockaddons/features/dungeonmap/DungeonMapManager.java index d903afd474..cbff10933a 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/features/dungeonmap/DungeonMapManager.java +++ b/src/main/java/codes/biscuit/skyblockaddons/features/dungeonmap/DungeonMapManager.java @@ -57,9 +57,9 @@ public class DungeonMapManager { /** The factor the player's coordinates are multiplied by to calculate their map marker coordinates */ private static final float COORDINATE_FACTOR = 1.33F; - /** {@link EntityPlayerSP#lastReportedPosX} */ + /** {@code EntityPlayerSP#lastReportedPosX} */ static final Field lastReportedPosX; - /** {@link EntityPlayerSP#lastReportedPosZ} */ + /** {@code EntityPlayerSP#lastReportedPosZ} */ static final Field lastReportedPosZ; private static MapData mapData; @@ -505,16 +505,16 @@ public static void decreaseZoomByStep() { } /** - * Returns the map zoom factor from {@link codes.biscuit.skyblockaddons.config.ConfigValues#mapZoom}. + * Returns the map zoom factor from {@code codes.biscuit.skyblockaddons.config.ConfigValues#mapZoom}. * - * @return the map zoom factor from {@link codes.biscuit.skyblockaddons.config.ConfigValues#mapZoom} + * @return the map zoom factor from {@code codes.biscuit.skyblockaddons.config.ConfigValues#mapZoom} */ public static float getMapZoom() { return main.getConfigValues().getMapZoom().getValue(); } /** - * Sets the map zoom factor in {@link codes.biscuit.skyblockaddons.config.ConfigValues#mapZoom}. + * Sets the map zoom factor in {@code codes.biscuit.skyblockaddons.config.ConfigValues#mapZoom}. * The new value must be between 0.5f and 5f inclusive. * * @param value the new map zoom factor diff --git a/src/main/java/codes/biscuit/skyblockaddons/features/fishParticles/FishParticleManager.java b/src/main/java/codes/biscuit/skyblockaddons/features/fishParticles/FishParticleManager.java index defe28efc7..70b435b5da 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/features/fishParticles/FishParticleManager.java +++ b/src/main/java/codes/biscuit/skyblockaddons/features/fishParticles/FishParticleManager.java @@ -12,7 +12,7 @@ * * This class allows us to approximate the trail of fish particles made by a fish converging to the player's bobber. * To do this, we use a variant on the Bellman Ford algorithm, as well as the exponentiation-by-squaring algorithm - * + *

* In general, we wish to identify those splash particles that belong to a fish converging on the player's bobber. * Notice several identifying features of these converging particles: * 1) Particles spawn at a radial distance from the cast hook. @@ -25,15 +25,15 @@ * 3 standard distributions (12 degrees) * 3) Sequential particles approaching the hook generally come in every tick, but we can allow for 2 or 3 ticks * 4) Particles will not spawn farther than 8 blocks away from the cast hook - * + *

* (These are mostly discoverable in the EntityFishHook.java file. Hopefully, my making this algorithm won't cause servers to go ballistic...) - * + *

* Consideration of time complexity is a huge part of the algorithm. * It is an O(n^2) algorithm, which for a large number of particles is unsustainable. * Each tick only gives us 50 milliseconds to compute stuff, so we're using bitwise operations. * Unfortunately, the longest primitive is 64 bits, so we're limited to tracking 64 particles at the moment. * This means when 10+ fishers are in the same spot, we may not be able to link the particles before we overwrite with new ones. - * + *

* Processing the per-particle step takes <.025 milliseconds and the per-tick step generally takes <.050 milliseconds * So we are well below any critical thresholds for computation time. * @@ -187,7 +187,7 @@ else if (hook != null) { * Find a few (i.e. a "trail" of) particles that each meet the criteria for the subsequent particle in the trail * E.g. we find a trail 1 -> 5 -> 6 -> 10 (particle 1 meets the criteria for 5, 5 meets the criteria for 6, and so on) * Finding the trail of length n is found by computing M^n, where M is the pairwise matchings for each particle combination - * + *

* Given the particle trail, spawn a distinct particle (lava drip) at the most recently spawned particle in the particle trail. */ private static void calculateTrails() { @@ -249,7 +249,7 @@ public static void clearParticleCache() { /** * Performs a bitwise square of a matrix - * + *

* Saves the resulting matrix to result in row form * @param result saved result of the matrix squaring * @param rows input 64 x 64 bit matrix diff --git a/src/main/java/codes/biscuit/skyblockaddons/listeners/RenderListener.java b/src/main/java/codes/biscuit/skyblockaddons/listeners/RenderListener.java index 19f52c498d..d002d8742b 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/listeners/RenderListener.java +++ b/src/main/java/codes/biscuit/skyblockaddons/listeners/RenderListener.java @@ -67,7 +67,7 @@ import java.awt.*; import java.math.BigDecimal; import java.math.RoundingMode; -import java.text.DecimalFormat; +import java.text.ParseException; import java.util.List; import java.util.*; @@ -327,7 +327,7 @@ private void renderWarnings(ScaledResolution scaledResolution) { break; case NO_ARROWS_LEFT_ALERT: if (arrowsLeft != -1) { - Translations.getMessage("messages.noArrowsLeft", TextUtils.NUMBER_FORMAT.format(arrowsLeft)); + Translations.getMessage("messages.noArrowsLeft", TextUtils.formatNumber(arrowsLeft)); } break; } @@ -671,11 +671,11 @@ public void drawText(Feature feature, float scale, Minecraft mc, ButtonLocation String text; int color = main.getConfigValues().getColor(feature); if (feature == Feature.MANA_TEXT) { - text = NUMBER_FORMAT.format(getAttribute(Attribute.MANA)) + "/" + NUMBER_FORMAT.format(getAttribute(Attribute.MAX_MANA)); + text = TextUtils.formatNumber(getAttribute(Attribute.MANA)) + "/" + TextUtils.formatNumber(getAttribute(Attribute.MAX_MANA)); } else if (feature == Feature.OVERFLOW_MANA) { if (getAttribute(Attribute.OVERFLOW_MANA) != 0 || buttonLocation != null) { - text = getAttribute(Attribute.OVERFLOW_MANA) + "ʬ"; + text = TextUtils.formatNumber(getAttribute(Attribute.OVERFLOW_MANA)) + "ʬ"; } else { return; } @@ -683,10 +683,10 @@ public void drawText(Feature feature, float scale, Minecraft mc, ButtonLocation if (mc.thePlayer.isPotionActive(22/* Absorption */)) { color = ColorUtils.getDummySkyblockColor(ColorCode.GOLD.getColor(), main.getConfigValues().getChromaFeatures().contains(feature)).getColor(); } - text = NUMBER_FORMAT.format(getAttribute(Attribute.HEALTH)) + "/" + NUMBER_FORMAT.format(getAttribute(Attribute.MAX_HEALTH)); + text = TextUtils.formatNumber(getAttribute(Attribute.HEALTH)) + "/" + TextUtils.formatNumber(getAttribute(Attribute.MAX_HEALTH)); } else if (feature == Feature.DEFENCE_TEXT) { - text = NUMBER_FORMAT.format(getAttribute(Attribute.DEFENCE)); + text = TextUtils.formatNumber(getAttribute(Attribute.DEFENCE)); } else if (feature == Feature.OTHER_DEFENCE_STATS) { text = main.getPlayerListener().getActionBarParser().getOtherDefense(); @@ -698,7 +698,7 @@ public void drawText(Feature feature, float scale, Minecraft mc, ButtonLocation } } else if (feature == Feature.EFFECTIVE_HEALTH_TEXT) { - text = NUMBER_FORMAT.format(Math.round(getAttribute(Attribute.HEALTH) * (1 + getAttribute(Attribute.DEFENCE) / 100F))); + text = TextUtils.formatNumber(Math.round(getAttribute(Attribute.HEALTH) * (1 + getAttribute(Attribute.DEFENCE) / 100F))); } else if (feature == Feature.DRILL_FUEL_TEXT) { if (!ItemUtils.isDrill(mc.thePlayer.getHeldItem())) { @@ -712,7 +712,7 @@ public void drawText(Feature feature, float scale, Minecraft mc, ButtonLocation text = bigDecimal + "%"; } else if (feature == Feature.SPEED_PERCENTAGE) { - String walkSpeed = NUMBER_FORMAT.format(Minecraft.getMinecraft().thePlayer.capabilities.getWalkSpeed() * 1000); + String walkSpeed = TextUtils.formatNumber(Minecraft.getMinecraft().thePlayer.capabilities.getWalkSpeed() * 1000); text = walkSpeed.substring(0, Math.min(walkSpeed.length(), 3)); if (text.endsWith(".")) text = text.substring(0, text.indexOf('.')); //remove trailing periods @@ -724,7 +724,7 @@ public void drawText(Feature feature, float scale, Minecraft mc, ButtonLocation if (buttonLocation == null) { if (healthUpdate != null) { color = healthUpdate > 0 ? ColorCode.GREEN.getColor() : ColorCode.RED.getColor(); - text = (healthUpdate > 0 ? "+" : "-") + Math.abs(healthUpdate); + text = (healthUpdate > 0 ? "+" : "-") + TextUtils.formatNumber(Math.abs(healthUpdate)); } else { return; } @@ -1259,10 +1259,15 @@ public void drawText(Feature feature, float scale, Minecraft mc, ButtonLocation renderItem(dungeonMilestone.getDungeonClass().getItem(), x, y); FontRendererHook.setupFeatureFont(feature); DrawUtils.drawText(text, x + 18, y, color); - double amount = Double.parseDouble(dungeonMilestone.getValue()); - DecimalFormat formatter = new DecimalFormat("#,###"); - DrawUtils.drawText(formatter.format(amount), x + 18 + mc.fontRendererObj.getStringWidth(text) / 2F - - mc.fontRendererObj.getStringWidth(formatter.format(amount)) / 2F, y + 9, color); + Number amount; + try { + amount = NUMBER_FORMAT.parse(dungeonMilestone.getValue()); + } catch (ParseException e) { + amount = -1; + } + String formattedAmount = TextUtils.formatNumber(amount); + DrawUtils.drawText(formattedAmount, x + 18 + mc.fontRendererObj.getStringWidth(text) / 2F + - mc.fontRendererObj.getStringWidth(formattedAmount) / 2F, y + 9, color); FontRendererHook.endFeatureFont(); } else if (feature == Feature.DUNGEONS_COLLECTED_ESSENCES_DISPLAY) { @@ -2272,18 +2277,18 @@ private void drawDetailedPowerOrbStatus(Minecraft mc, float scale, ButtonLocatio double healIncrease = powerOrb.getHealIncrease() * 100; List display = new LinkedList<>(); - display.add(String.format("§c+%s ❤/s", TextUtils.formatDouble(healthRegen))); + display.add(String.format("§c+%s ❤/s", TextUtils.formatNumber(healthRegen))); if (powerOrb.getManaRegen() > 0) { float maxMana = main.getUtils().getAttributes().get(Attribute.MAX_MANA).getValue(); float manaRegen = (float) Math.floor(maxMana / 50); manaRegen = (float) (manaRegen + manaRegen * powerOrb.getManaRegen()); - display.add(String.format("§b+%s ✎/s", TextUtils.formatDouble(manaRegen))); + display.add(String.format("§b+%s ✎/s", TextUtils.formatNumber(manaRegen))); } if (powerOrb.getStrength() > 0) { display.add(String.format("§4+%d ❁", powerOrb.getStrength())); } if (healIncrease > 0) { - display.add(String.format("§2+%s%% Healing", TextUtils.formatDouble(healIncrease))); + display.add(String.format("§2+%s%% Healing", TextUtils.formatNumber(healIncrease))); } Optional longestLine = display.stream().max(Comparator.comparingInt(String::length)); diff --git a/src/main/java/codes/biscuit/skyblockaddons/shader/ShaderHelper.java b/src/main/java/codes/biscuit/skyblockaddons/shader/ShaderHelper.java index 13f2824054..2e6ef074b1 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/shader/ShaderHelper.java +++ b/src/main/java/codes/biscuit/skyblockaddons/shader/ShaderHelper.java @@ -10,7 +10,7 @@ /** * This class provides methods to check what opengl capabilities are supported. - * + *

* Please use the provided methods instead of calling opengl methods directly to avoid crashes! */ public class ShaderHelper { diff --git a/src/main/java/codes/biscuit/skyblockaddons/shader/chroma/Chroma3DShader.java b/src/main/java/codes/biscuit/skyblockaddons/shader/chroma/Chroma3DShader.java index f7f0f0fac9..aacc30823d 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/shader/chroma/Chroma3DShader.java +++ b/src/main/java/codes/biscuit/skyblockaddons/shader/chroma/Chroma3DShader.java @@ -8,10 +8,10 @@ /** * This shader shows a chroma color on a pixel depending on its position in the world - * + *

* This shader does: * - Take in account its position in 3-dimensional space - * + *

* This shader does not: * - Preserve the brightness and saturation of the original color * - Work with textures diff --git a/src/main/java/codes/biscuit/skyblockaddons/shader/chroma/ChromaScreenShader.java b/src/main/java/codes/biscuit/skyblockaddons/shader/chroma/ChromaScreenShader.java index 4cf4812948..9ad5532907 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/shader/chroma/ChromaScreenShader.java +++ b/src/main/java/codes/biscuit/skyblockaddons/shader/chroma/ChromaScreenShader.java @@ -2,10 +2,10 @@ /** * This shader shows a chroma color on a pixel depending on its position on the screen. - * + *

* This shader does: * - Preserve the brightness and saturation of the original color (for text shadows) - * + *

* This shader does not: * - Take in account world position, scale, etc. * - Work with textures (see {@link ChromaScreenTexturedShader} for a textured version). diff --git a/src/main/java/codes/biscuit/skyblockaddons/shader/chroma/ChromaScreenTexturedShader.java b/src/main/java/codes/biscuit/skyblockaddons/shader/chroma/ChromaScreenTexturedShader.java index 2c123cb0b2..8b5fd36827 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/shader/chroma/ChromaScreenTexturedShader.java +++ b/src/main/java/codes/biscuit/skyblockaddons/shader/chroma/ChromaScreenTexturedShader.java @@ -2,11 +2,11 @@ /** * This shader shows a chroma color on a pixel depending on its position on the screen. - * + *

* This shader does: * - Work with textures (see {@link ChromaScreenShader} for a non-textured version). * - Preserve the brightness and saturation of the original color (for text shadows) - * + *

* This shader does not: * - Take in account world position, scale, etc. */ diff --git a/src/main/java/codes/biscuit/skyblockaddons/utils/DrawUtils.java b/src/main/java/codes/biscuit/skyblockaddons/utils/DrawUtils.java index 8a826b17f9..6ad3a85fd1 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/utils/DrawUtils.java +++ b/src/main/java/codes/biscuit/skyblockaddons/utils/DrawUtils.java @@ -186,7 +186,7 @@ public static void drawModalRectWithCustomSizedTexture(float x, float y, float u /** * Draws a rectangle using absolute coordinates & a color. - * + *

* See {@link DrawUtils#drawRect(double, double, double, double, int)} to use width/height instead. */ public static void drawRectAbsolute(double left, double top, double right, double bottom, int color) { @@ -195,7 +195,7 @@ public static void drawRectAbsolute(double left, double top, double right, doubl /** * Draws a rectangle using absolute coordinates & a color. - * + *

* See {@link DrawUtils#drawRect(double, double, double, double, int, boolean)} to use width/height instead. */ public static void drawRectAbsolute(double left, double top, double right, double bottom, int color, boolean chroma) { @@ -214,7 +214,7 @@ public static void drawRectAbsolute(double left, double top, double right, doubl /** * Draws a rectangle using absolute a starting position and a width/height. - * + *

* See {@link DrawUtils#drawRectAbsolute(double, double, double, double, int)} to use absolute coordinates instead. */ public static void drawRect(double x, double y, double w, double h, SkyblockColor color, int rounding) { @@ -223,7 +223,7 @@ public static void drawRect(double x, double y, double w, double h, SkyblockColo /** * Draws a rectangle using absolute a starting position and a width/height. - * + *

* See {@link DrawUtils#drawRectAbsolute(double, double, double, double, int)} to use absolute coordinates instead. */ public static void drawRect(double x, double y, double w, double h, int color) { @@ -232,7 +232,7 @@ public static void drawRect(double x, double y, double w, double h, int color) { /** * Draws a rectangle using absolute a starting position and a width/height. - * + *

* See {@link DrawUtils#drawRectAbsolute(double, double, double, double, int, boolean)} to use absolute coordinates instead. */ public static void drawRect(double x, double y, double w, double h, int color, boolean chroma) { diff --git a/src/main/java/codes/biscuit/skyblockaddons/utils/ItemUtils.java b/src/main/java/codes/biscuit/skyblockaddons/utils/ItemUtils.java index 5d517a3162..8878ad0b1f 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/utils/ItemUtils.java +++ b/src/main/java/codes/biscuit/skyblockaddons/utils/ItemUtils.java @@ -42,9 +42,7 @@ public class ItemUtils { * This expression matches the line with a Skyblock item's rarity and item type that's at the end of its lore. */ private static final Pattern ITEM_TYPE_AND_RARITY_PATTERN = Pattern.compile("§l(?[A-Z]+) ?(?[A-Z ]+)?(?:§[0-9a-f]§l§ka)?$"); - @SuppressWarnings({"FieldMayBeFinal", "MismatchedQueryAndUpdateOfCollection"}) @Setter private static Map compactorItems; - @SuppressWarnings({"FieldMayBeFinal", "MismatchedQueryAndUpdateOfCollection"}) @Setter private static Map containers; diff --git a/src/main/java/codes/biscuit/skyblockaddons/utils/TextUtils.java b/src/main/java/codes/biscuit/skyblockaddons/utils/TextUtils.java index 3c37de79ea..c8dc4695ac 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/utils/TextUtils.java +++ b/src/main/java/codes/biscuit/skyblockaddons/utils/TextUtils.java @@ -1,6 +1,7 @@ package codes.biscuit.skyblockaddons.utils; import codes.biscuit.skyblockaddons.SkyblockAddons; +import codes.biscuit.skyblockaddons.core.Feature; import com.google.gson.JsonObject; import java.nio.charset.StandardCharsets; @@ -18,7 +19,11 @@ public class TextUtils { * Hypixel uses US number format. */ public static final NumberFormat NUMBER_FORMAT = NumberFormat.getInstance(Locale.US); - + /** + * Number format with thousands separators disabled, used for displaying numbers in Hypixel's old (no separators) + * style + */ + public static final NumberFormat NUMBER_FORMAT_NO_GROUPING = NumberFormat.getInstance(Locale.US); private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)§[0-9A-FK-ORZ]"); private static final Pattern REPEATED_COLOR_PATTERN = Pattern.compile("(?i)(§[0-9A-FK-ORZ])+"); private static final Pattern NUMBERS_SLASHES = Pattern.compile("[^0-9 /]"); @@ -31,22 +36,31 @@ public class TextUtils { private static final Pattern MAGNITUDE_PATTERN = Pattern.compile("(\\d[\\d,.]*\\d*)+([kKmMbBtT])"); private static final NavigableMap suffixes = new TreeMap<>(); + static { suffixes.put(1_000, "k"); suffixes.put(1_000_000, "M"); suffixes.put(1_000_000_000, "B"); + NUMBER_FORMAT.setMaximumFractionDigits(2); + NUMBER_FORMAT_NO_GROUPING.setMaximumFractionDigits(2); + NUMBER_FORMAT_NO_GROUPING.setGroupingUsed(false); } /** - * Formats a double number to look better with commas every 3 digits and up to two decimal places. + * Formats a number to look better with commas every 3 digits (if the {@code NUMBER_SEPARATORS} mod feature is enabled) + * and up to two decimal places. * For example: {@code 1,006,789.5} * * @param number Number to format * @return Formatted string */ - public static String formatDouble(double number) { - return NUMBER_FORMAT.format(number); + public static String formatNumber(Number number) { + if (SkyblockAddons.getInstance().getConfigValues().isEnabled(Feature.NUMBER_SEPARATORS)) { + return NUMBER_FORMAT.format(number); + } else { + return NUMBER_FORMAT_NO_GROUPING.format(number); + } } /** @@ -112,7 +126,7 @@ public static String getNumbersOnly(String text) { /** * Converts all numbers with magnitudes in a given string, e.g. "10k" -> "10000" and "10M" -> "10000000." Magnitudes * are not case-sensitive. - * + *

* Supported magnitudes: *

k - thousand

*

m - million

@@ -150,7 +164,7 @@ public static String convertMagnitudes(String text) throws ParseException { parsedDouble *= 1_000_000_000_000L; } - matcher.appendReplacement(sb, NUMBER_FORMAT.format(parsedDouble)); + matcher.appendReplacement(sb, TextUtils.formatNumber(parsedDouble)); } matcher.appendTail(sb); @@ -218,7 +232,7 @@ public static String getOrdinalSuffix(final int n) { } /** - * @param textureURL The texture ID/hash that is in the texture URL (not including http://textures.minecraft.net/texture/) + * @param textureURL The texture ID/hash that is in the texture URL (not including {@code http://textures.minecraft.net/texture/}) * @return A json string including the texture URL as a skin texture (used in NBT) */ public static String encodeSkinTextureURL(String textureURL) { diff --git a/src/main/java/codes/biscuit/skyblockaddons/utils/Utils.java b/src/main/java/codes/biscuit/skyblockaddons/utils/Utils.java index d8cc7649b4..a24aa7b462 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/utils/Utils.java +++ b/src/main/java/codes/biscuit/skyblockaddons/utils/Utils.java @@ -283,7 +283,6 @@ public void parseSidebar() { String strippedScoreboardLine = ScoreboardManager.getStrippedScoreboardLines().get(lineNumber); Matcher matcher; - //noinspection RedundantSuppression switch (lineNumber) { case 0: // Server ID @@ -505,9 +504,6 @@ private void parseSlayerProgress(String line) { } } - private void onCoinsChange(double coinsChange) { - } - public int getDefaultColor(float alphaFloat) { int alpha = (int) alphaFloat; return new Color(150, 236, 255, alpha).getRGB(); @@ -883,10 +879,6 @@ private void parseCoins(String strippedScoreboardLine) { try { double oldCoins = purse; purse = TextUtils.NUMBER_FORMAT.parse(matcher.group("coins")).doubleValue(); - - if (oldCoins != purse) { - onCoinsChange(purse - oldCoins); - } } catch (NumberFormatException | ParseException e) { purse = 0; } diff --git a/src/main/resources/lang/en_US.json b/src/main/resources/lang/en_US.json index d967eef171..234145b119 100644 --- a/src/main/resources/lang/en_US.json +++ b/src/main/resources/lang/en_US.json @@ -219,7 +219,8 @@ "showSkyblockItemId": "Show Skyblock Item ID on Hover", "showFeatureNamesOnHover": "Show Feature Names on Hover", "resetSalvagedEssencesAfterLeavingMenu": "Reset Salvaged Essence Counter After Closing Menu", - "changeDungeonMapZoomWithKeyboard": "Adjust zoom with +/- keys" + "changeDungeonMapZoomWithKeyboard": "Adjust zoom with +/- keys", + "numberSeparators": "Show Number Separators" }, "messages": { "enchants": "Enchants", From 4765b595c0503e36901bbe44116e38649a76a3bf Mon Sep 17 00:00:00 2001 From: ILikePlayingGames <22475143+ILikePlayingGames@users.noreply.github.com> Date: Wed, 31 Aug 2022 03:39:02 -0400 Subject: [PATCH 2/2] Fix broken test --- .../java/codes/biscuit/skyblockaddons/utils/TextUtils.java | 5 ++++- .../java/codes/biscuit/skyblockaddons/TextUtilsTests.java | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/codes/biscuit/skyblockaddons/utils/TextUtils.java b/src/main/java/codes/biscuit/skyblockaddons/utils/TextUtils.java index c8dc4695ac..8e51212ce4 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/utils/TextUtils.java +++ b/src/main/java/codes/biscuit/skyblockaddons/utils/TextUtils.java @@ -1,6 +1,7 @@ package codes.biscuit.skyblockaddons.utils; import codes.biscuit.skyblockaddons.SkyblockAddons; +import codes.biscuit.skyblockaddons.config.ConfigValues; import codes.biscuit.skyblockaddons.core.Feature; import com.google.gson.JsonObject; @@ -56,7 +57,9 @@ public class TextUtils { * @return Formatted string */ public static String formatNumber(Number number) { - if (SkyblockAddons.getInstance().getConfigValues().isEnabled(Feature.NUMBER_SEPARATORS)) { + // This null check is here for TextUtilsTests + if (SkyblockAddons.getInstance() == null || + SkyblockAddons.getInstance().getConfigValues().isEnabled(Feature.NUMBER_SEPARATORS)) { return NUMBER_FORMAT.format(number); } else { return NUMBER_FORMAT_NO_GROUPING.format(number); diff --git a/src/test/java/codes/biscuit/skyblockaddons/TextUtilsTests.java b/src/test/java/codes/biscuit/skyblockaddons/TextUtilsTests.java index 3cd308e7f7..e1d8e3c80b 100644 --- a/src/test/java/codes/biscuit/skyblockaddons/TextUtilsTests.java +++ b/src/test/java/codes/biscuit/skyblockaddons/TextUtilsTests.java @@ -18,7 +18,7 @@ public class TextUtilsTests { @DisplayName("Action Bar Magnitude Conversion Tests") @ParameterizedTest() @CsvFileSource(resources = "/convert-magnitudes.csv", numLinesToSkip = 1) - void testActionBarMagnitudeConversionS(String inputString, String expectedOutput) { + void testActionBarMagnitudeConversions(String inputString, String expectedOutput) { try { assertEquals(expectedOutput, TextUtils.convertMagnitudes(inputString)); } catch (ParseException e) {