diff options
| author | Aaron <51387595+AzureAaron@users.noreply.github.com> | 2024-09-26 17:52:49 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-26 17:52:49 -0400 |
| commit | 9bccc63d33fc07aa735832ef289ae82af012acde (patch) | |
| tree | 4812db342a961eb063932b8fa50d230ee9e4d52a /src/main/java | |
| parent | f4714fb07798b9900ead21fa6f657a7ab0ec53fc (diff) | |
| parent | c1292243286f61aac88fa1421456408b2f1aeebe (diff) | |
| download | Skyblocker-9bccc63d33fc07aa735832ef289ae82af012acde.tar.gz Skyblocker-9bccc63d33fc07aa735832ef289ae82af012acde.tar.bz2 Skyblocker-9bccc63d33fc07aa735832ef289ae82af012acde.zip | |
Merge pull request #1006 from kevinthegreat1/random-fixes
Random fixes
Diffstat (limited to 'src/main/java')
14 files changed, 236 insertions, 234 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/PetCache.java b/src/main/java/de/hysky/skyblocker/skyblock/PetCache.java index 39516dc2..01c7fada 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/PetCache.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/PetCache.java @@ -7,6 +7,7 @@ import com.mojang.serialization.JsonOps; import com.mojang.serialization.codecs.RecordCodecBuilder; import de.hysky.skyblocker.SkyblockerMod; import de.hysky.skyblocker.annotations.Init; +import de.hysky.skyblocker.skyblock.item.SkyblockItemRarity; import de.hysky.skyblocker.utils.ItemUtils; import de.hysky.skyblocker.utils.Utils; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; @@ -137,9 +138,6 @@ public class PetCache { } public record PetInfo(String type, double exp, String tier, Optional<String> uuid, Optional<String> item, Optional<String> skin) { - // TODO: Combine with SkyblockItemRarity - private static final String[] TIER_INDEX = {"COMMON", "UNCOMMON", "RARE", "EPIC", "LEGENDARY", "MYTHIC"}; - public static final Codec<PetInfo> CODEC = RecordCodecBuilder.create(instance -> instance.group( Codec.STRING.fieldOf("type").forGetter(PetInfo::type), Codec.DOUBLE.fieldOf("exp").forGetter(PetInfo::exp), @@ -153,7 +151,7 @@ public class PetCache { ).xmap(Object2ObjectOpenHashMap::new, Object2ObjectOpenHashMap::new); public int tierIndex() { - return ArrayUtils.indexOf(TIER_INDEX, tier); + return SkyblockItemRarity.valueOf(tier).ordinal(); } } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/StatusBarTracker.java b/src/main/java/de/hysky/skyblocker/skyblock/StatusBarTracker.java index 5938f76e..c589438c 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/StatusBarTracker.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/StatusBarTracker.java @@ -2,10 +2,11 @@ package de.hysky.skyblocker.skyblock; import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.utils.Location; +import de.hysky.skyblocker.utils.RegexUtils; import de.hysky.skyblocker.utils.Utils; +import de.hysky.skyblocker.utils.scheduler.Scheduler; import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.text.Text; @@ -13,143 +14,142 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; public class StatusBarTracker { - private static final Pattern STATUS_HEALTH = Pattern.compile("§[6c](\\d+(,\\d\\d\\d)*)/(\\d+(,\\d\\d\\d)*)❤(?:(\\+§c(\\d+(,\\d\\d\\d)*). *)| *)"); - private static final Pattern DEFENSE_STATUS = Pattern.compile("§a(\\d+(,\\d\\d\\d)*)§a❈ Defense *"); - private static final Pattern MANA_USE = Pattern.compile("§b-(\\d+(,\\d\\d\\d)*) Mana \\(§\\S+(?:\\s\\S+)* *"); - private static final Pattern MANA_STATUS = Pattern.compile("§b(\\d+(,\\d\\d\\d)*)/(\\d+(,\\d\\d\\d)*)✎ (?:Mana|§3(\\d+(,\\d\\d\\d)*)ʬ) *"); - - private Resource health = new Resource(100, 100, 0); - private Resource mana = new Resource(100, 100, 0); - private Resource speed = new Resource(100, 400, 0); - private int defense = 0; - - public void init() { - ClientReceiveMessageEvents.ALLOW_GAME.register(this::allowOverlayMessage); - ClientReceiveMessageEvents.MODIFY_GAME.register(this::onOverlayMessage); - } - - public Resource getHealth() { - return this.health; - } - - public Resource getMana() { - return this.mana; - } - - public int getDefense() { - return this.defense; - } - - public Resource getSpeed() { - updateSpeed(); - return this.speed; - } - - private int parseInt(Matcher m, int group) { - return Integer.parseInt(m.group(group).replace(",", "")); - } - - private void updateMana(Matcher m) { - int value = parseInt(m, 1); - int max = parseInt(m, 3); - int overflow = m.group(5) == null ? 0 : parseInt(m, 5); - this.mana = new Resource(value, max, overflow); - } - - private void updateSpeed() { - // Black cat and racing helm are untested - I don't have the money to test atm, but no reason why they shouldn't work - var player = MinecraftClient.getInstance().player; - int value = (int) (player.isSprinting() ? (player.getMovementSpeed() / 1.3f) * 1000 : player.getMovementSpeed() * 1000); - int max = 400; // hardcoded limit (except for with cactus knife, black cat, snail, racing helm, young drag) - if (player.getMainHandStack().getName().getString().contains("Cactus Knife") && Utils.getLocation() == Location.GARDEN) { - max = 500; - } - Iterable<ItemStack> armor = player.getArmorItems(); - int youngDragCount = 0; - for (ItemStack armorPiece : armor) { - if (armorPiece.getName().getString().contains("Racing Helmet")) { - max = 500; - } else if (armorPiece.getName().getString().contains("Young Dragon")) { - youngDragCount++; - } - } - if (youngDragCount == 4) { - max = 500; - } - - PetCache.PetInfo pet = PetCache.getCurrentPet(); - if (pet != null) { - if (pet.type().contains("BLACK_CAT")) { - max = 500; - } else if (pet.type().contains("SNAIL")) { - max = 100; - } - } - this.speed = new Resource(value, max, 0); - } - - private void updateHealth(Matcher m) { - int value = parseInt(m, 1); - int max = parseInt(m, 3); - int overflow = Math.max(0, value - max); - if (MinecraftClient.getInstance() != null && MinecraftClient.getInstance().player != null) { - ClientPlayerEntity player = MinecraftClient.getInstance().player; - value = (int) (player.getHealth() * max / player.getMaxHealth()); - overflow = (int) (player.getAbsorptionAmount() * max / player.getMaxHealth()); - } - this.health = new Resource(Math.min(value, max), max, Math.min(overflow, max)); - } - - private String reset(String str, Matcher m) { - str = str.substring(m.end()); - m.reset(str); - return str; - } - - private boolean allowOverlayMessage(Text text, boolean overlay) { - onOverlayMessage(text, overlay); - return true; - } - - private Text onOverlayMessage(Text text, boolean overlay) { - if (!overlay || !Utils.isOnSkyblock() || !SkyblockerConfigManager.get().uiAndVisuals.bars.enableBars || Utils.isInTheRift()) { - return text; - } - return Text.of(update(text.getString(), SkyblockerConfigManager.get().chat.hideMana)); - } - - public String update(String actionBar, boolean filterManaUse) { - var sb = new StringBuilder(); - Matcher matcher = STATUS_HEALTH.matcher(actionBar); - if (!matcher.lookingAt()) - return actionBar; - updateHealth(matcher); - if (matcher.group(5) != null) { - sb.append("§c❤"); - sb.append(matcher.group(5)); - } - actionBar = reset(actionBar, matcher); - if (matcher.usePattern(MANA_STATUS).lookingAt()) { - defense = 0; - updateMana(matcher); - actionBar = reset(actionBar, matcher); - } else { - if (matcher.usePattern(DEFENSE_STATUS).lookingAt()) { - defense = parseInt(matcher, 1); - actionBar = reset(actionBar, matcher); - } else if (filterManaUse && matcher.usePattern(MANA_USE).lookingAt()) { - actionBar = reset(actionBar, matcher); - } - if (matcher.usePattern(MANA_STATUS).find()) { - updateMana(matcher); - matcher.appendReplacement(sb, ""); - } - } - matcher.appendTail(sb); - String res = sb.toString().trim(); - return res.isEmpty() ? null : res; - } - - public record Resource(int value, int max, int overflow) { - } + private static final Pattern STATUS_HEALTH = Pattern.compile("§[6c](?<health>[\\d,]+)/(?<max>[\\d,]+)❤ *(?<healing>\\+§c([\\d,]+). *)?"); + private static final Pattern DEFENSE_STATUS = Pattern.compile("§a(?<defense>[\\d,]+)§a❈ Defense *"); + private static final Pattern MANA_USE = Pattern.compile("§b-([\\d,]+) Mana \\(§.*?\\) *"); + private static final Pattern MANA_STATUS = Pattern.compile("§b(?<mana>[\\d,]+)/(?<max>[\\d,]+)✎ (?:Mana|§3(?<overflow>[\\d,]+)ʬ) *"); + + private final MinecraftClient client = MinecraftClient.getInstance(); + private Resource health = new Resource(100, 100, 0); + private Resource mana = new Resource(100, 100, 0); + private Resource speed = new Resource(100, 400, 0); + private int defense = 0; + + public void init() { + ClientReceiveMessageEvents.ALLOW_GAME.register(this::allowOverlayMessage); + ClientReceiveMessageEvents.MODIFY_GAME.register(this::onOverlayMessage); + Scheduler.INSTANCE.scheduleCyclic(this::tick, 1); + } + + public Resource getHealth() { + return this.health; + } + + public Resource getMana() { + return this.mana; + } + + public int getDefense() { + return this.defense; + } + + public Resource getSpeed() { + return this.speed; + } + + private void tick() { + if (client == null || client.player == null) return; + updateHealth(health.value, health.max, health.overflow); + updateSpeed(); + } + + private boolean allowOverlayMessage(Text text, boolean overlay) { + onOverlayMessage(text, overlay); + return true; + } + + private Text onOverlayMessage(Text text, boolean overlay) { + if (!overlay || !Utils.isOnSkyblock() || !SkyblockerConfigManager.get().uiAndVisuals.bars.enableBars || Utils.isInTheRift()) { + return text; + } + return Text.of(update(text.getString(), SkyblockerConfigManager.get().chat.hideMana)); + } + + public String update(String actionBar, boolean filterManaUse) { + var sb = new StringBuilder(); + + // Match health and don't add it to the string builder + // Append healing to the string builder if there is any healing + Matcher matcher = STATUS_HEALTH.matcher(actionBar); + if (!matcher.find()) return actionBar; + updateHealth(matcher); + if (matcher.group("healing") != null) { + sb.append("§c❤"); + } + matcher.appendReplacement(sb, "$3"); + + // Match defense or mana use and don't add it to the string builder + if (matcher.usePattern(DEFENSE_STATUS).find()) { + defense = RegexUtils.parseIntFromMatcher(matcher, "defense"); + matcher.appendReplacement(sb, ""); + } else if (filterManaUse && matcher.usePattern(MANA_USE).find()) { + matcher.appendReplacement(sb, ""); + } + + // Match mana and don't add it to the string builder + if (matcher.usePattern(MANA_STATUS).find()) { + updateMana(matcher); + matcher.appendReplacement(sb, ""); + } + + // Append the rest of the message to the string builder + matcher.appendTail(sb); + String res = sb.toString().trim(); + return res.isEmpty() ? null : res; + } + + private void updateHealth(Matcher matcher) { + int health = RegexUtils.parseIntFromMatcher(matcher, "health"); + int max = RegexUtils.parseIntFromMatcher(matcher, "max"); + updateHealth(health, max, Math.max(0, health - max)); + } + + private void updateHealth(int value, int max, int overflow) { + if (client != null && client.player != null) { + value = (int) (client.player.getHealth() * max / client.player.getMaxHealth()); + overflow = (int) (client.player.getAbsorptionAmount() * max / client.player.getMaxHealth()); + } + health = new Resource(Math.min(value, max), max, Math.min(overflow, max)); + } + + private void updateMana(Matcher m) { + int mana = RegexUtils.parseIntFromMatcher(m, "mana"); + int max = RegexUtils.parseIntFromMatcher(m, "max"); + int overflow = m.group("overflow") == null ? 0 : RegexUtils.parseIntFromMatcher(m, "overflow"); + this.mana = new Resource(mana, max, overflow); + } + + private void updateSpeed() { + // Black cat and racing helm are untested - I don't have the money to test atm, but no reason why they shouldn't work + assert client.player != null; + int value = (int) (client.player.isSprinting() ? (client.player.getMovementSpeed() / 1.3f) * 1000 : client.player.getMovementSpeed() * 1000); + int max = 400; // hardcoded limit (except for with cactus knife, black cat, snail, racing helm, young drag) + if (client.player.getMainHandStack().getName().getString().contains("Cactus Knife") && Utils.getLocation() == Location.GARDEN) { + max = 500; + } + Iterable<ItemStack> armor = client.player.getArmorItems(); + int youngDragCount = 0; + for (ItemStack armorPiece : armor) { + if (armorPiece.getName().getString().contains("Racing Helmet")) { + max = 500; + } else if (armorPiece.getName().getString().contains("Young Dragon")) { + youngDragCount++; + } + } + if (youngDragCount == 4) { + max = 500; + } + + PetCache.PetInfo pet = PetCache.getCurrentPet(); + if (pet != null) { + if (pet.type().contains("BLACK_CAT")) { + max = 500; + } else if (pet.type().contains("SNAIL")) { + max = 100; + } + } + this.speed = new Resource(value, max, 0); + } + + public record Resource(int value, int max, int overflow) {} } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/ChocolateFactorySolver.java b/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/ChocolateFactorySolver.java index 087d1663..9bc45670 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/ChocolateFactorySolver.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/ChocolateFactorySolver.java @@ -6,6 +6,7 @@ import de.hysky.skyblocker.skyblock.item.tooltip.adders.LineSmoothener; import de.hysky.skyblocker.utils.ItemUtils; import de.hysky.skyblocker.utils.RegexUtils; import de.hysky.skyblocker.utils.RomanNumerals; +import de.hysky.skyblocker.utils.SkyblockTime; import de.hysky.skyblocker.utils.container.SimpleContainerSolver; import de.hysky.skyblocker.utils.container.SlotTextAdder; import de.hysky.skyblocker.utils.container.TooltipAdder; @@ -144,19 +145,19 @@ public class ChocolateFactorySolver extends SimpleContainerSolver implements Too getCoach(slots.get(COACH_SLOT)).ifPresent(cpsIncreaseFactors::add); //The clickable chocolate is in slot 13, holds the total chocolate - RegexUtils.getLongFromMatcher(CHOCOLATE_PATTERN.matcher(slots.get(CHOCOLATE_SLOT).getName().getString())).ifPresent(l -> totalChocolate = l); + RegexUtils.findLongFromMatcher(CHOCOLATE_PATTERN.matcher(slots.get(CHOCOLATE_SLOT).getName().getString())).ifPresent(l -> totalChocolate = l); //Cps item (cocoa bean) is in slot 45 String cpsItemLore = ItemUtils.getConcatenatedLore(slots.get(CPS_SLOT)); Matcher cpsMatcher = CPS_PATTERN.matcher(cpsItemLore); - RegexUtils.getDoubleFromMatcher(cpsMatcher).ifPresent(d -> totalCps = d); + RegexUtils.findDoubleFromMatcher(cpsMatcher).ifPresent(d -> totalCps = d); Matcher multiplierMatcher = TOTAL_MULTIPLIER_PATTERN.matcher(cpsItemLore); - RegexUtils.getDoubleFromMatcher(multiplierMatcher, cpsMatcher.hasMatch() ? cpsMatcher.end() : 0).ifPresent(d -> totalCpsMultiplier = d); + RegexUtils.findDoubleFromMatcher(multiplierMatcher, cpsMatcher.hasMatch() ? cpsMatcher.end() : 0).ifPresent(d -> totalCpsMultiplier = d); //Prestige item is in slot 28 String prestigeLore = ItemUtils.getConcatenatedLore(slots.get(PRESTIGE_SLOT)); Matcher prestigeMatcher = PRESTIGE_REQUIREMENT_PATTERN.matcher(prestigeLore); - OptionalLong currentChocolate = RegexUtils.getLongFromMatcher(prestigeMatcher); + OptionalLong currentChocolate = RegexUtils.findLongFromMatcher(prestigeMatcher); if (currentChocolate.isPresent()) { String requirement = prestigeMatcher.group(2); //If the first one matched, we can assume the 2nd one is also matched since it's one whole regex //Since the last character is either M or B we can just try to replace both characters. Only the correct one will actually replace anything. @@ -177,7 +178,7 @@ public class ChocolateFactorySolver extends SimpleContainerSolver implements Too isTimeTowerMaxed = StringUtils.substringAfterLast(slots.get(TIME_TOWER_SLOT).getName().getString(), ' ').equals("XV"); String timeTowerLore = ItemUtils.getConcatenatedLore(slots.get(TIME_TOWER_SLOT)); Matcher timeTowerMultiplierMatcher = TIME_TOWER_MULTIPLIER_PATTERN.matcher(timeTowerLore); - RegexUtils.getDoubleFromMatcher(timeTowerMultiplierMatcher).ifPresent(d -> timeTowerMultiplier = d); + RegexUtils.findDoubleFromMatcher(timeTowerMultiplierMatcher).ifPresent(d -> timeTowerMultiplier = d); Matcher timeTowerStatusMatcher = TIME_TOWER_STATUS_PATTERN.matcher(timeTowerLore); if (timeTowerStatusMatcher.find(timeTowerMultiplierMatcher.hasMatch() ? timeTowerMultiplierMatcher.end() : 0)) { isTimeTowerActive = timeTowerStatusMatcher.group(1).equals("ACTIVE"); @@ -198,10 +199,10 @@ public class ChocolateFactorySolver extends SimpleContainerSolver implements Too if (totalCps < 0 || totalCpsMultiplier < 0) return Optional.empty(); //We need these 2 to calculate the increase in cps. Matcher multiplierIncreaseMatcher = MULTIPLIER_INCREASE_PATTERN.matcher(coachLore); - OptionalDouble currentCpsMultiplier = RegexUtils.getDoubleFromMatcher(multiplierIncreaseMatcher); + OptionalDouble currentCpsMultiplier = RegexUtils.findDoubleFromMatcher(multiplierIncreaseMatcher); if (currentCpsMultiplier.isEmpty()) return Optional.empty(); - OptionalDouble nextCpsMultiplier = RegexUtils.getDoubleFromMatcher(multiplierIncreaseMatcher); + OptionalDouble nextCpsMultiplier = RegexUtils.findDoubleFromMatcher(multiplierIncreaseMatcher); if (nextCpsMultiplier.isEmpty()) { //This means that the coach isn't hired yet. nextCpsMultiplier = currentCpsMultiplier; //So the first instance of the multiplier is actually the amount we'll get upon upgrading. currentCpsMultiplier = OptionalDouble.of(0.0); //And so, we can re-assign values to the variables to make the calculation more readable. @@ -209,7 +210,7 @@ public class ChocolateFactorySolver extends SimpleContainerSolver implements Too Matcher costMatcher = COST_PATTERN.matcher(coachLore); Matcher levelMatcher = COACH_LEVEL_PATTERN.matcher(coachItem.getName().getString()); - OptionalLong cost = RegexUtils.getLongFromMatcher(costMatcher, multiplierIncreaseMatcher.hasMatch() ? multiplierIncreaseMatcher.end() : 0); //Cost comes after the multiplier line + OptionalLong cost = RegexUtils.findLongFromMatcher(costMatcher, multiplierIncreaseMatcher.hasMatch() ? multiplierIncreaseMatcher.end() : 0); //Cost comes after the multiplier line int level = -1; if (levelMatcher.find()) { level = RomanNumerals.romanToDecimal(levelMatcher.group(1)); @@ -221,18 +222,18 @@ public class ChocolateFactorySolver extends SimpleContainerSolver implements Too private Optional<Rabbit> getRabbit(ItemStack item, int slot) { String lore = ItemUtils.getConcatenatedLore(item); Matcher cpsMatcher = CPS_INCREASE_PATTERN.matcher(lore); - OptionalInt currentCps = RegexUtils.getIntFromMatcher(cpsMatcher); + OptionalInt currentCps = RegexUtils.findIntFromMatcher(cpsMatcher); if (currentCps.isEmpty()) return Optional.empty(); - OptionalInt nextCps = RegexUtils.getIntFromMatcher(cpsMatcher); + OptionalInt nextCps = RegexUtils.findIntFromMatcher(cpsMatcher); if (nextCps.isEmpty()) { nextCps = currentCps; //This means that the rabbit isn't hired yet. currentCps = OptionalInt.of(0); //So the first instance of the cps is actually the amount we'll get upon hiring. } Matcher costMatcher = COST_PATTERN.matcher(lore); - OptionalLong cost = RegexUtils.getLongFromMatcher(costMatcher, cpsMatcher.hasMatch() ? cpsMatcher.end() : 0); //Cost comes after the cps line + OptionalLong cost = RegexUtils.findLongFromMatcher(costMatcher, cpsMatcher.hasMatch() ? cpsMatcher.end() : 0); //Cost comes after the cps line Matcher levelMatcher = LEVEL_PATTERN.matcher(lore); - int level = RegexUtils.getIntFromMatcher(levelMatcher).orElse(0) - 1; + int level = RegexUtils.findIntFromMatcher(levelMatcher).orElse(0) - 1; if (cost.isEmpty()) return Optional.empty(); return Optional.of(new Rabbit((nextCps.getAsInt() - currentCps.getAsInt()) * (totalCpsMultiplier < 0 ? 1 : totalCpsMultiplier), cost.getAsLong(), slot, level)); } @@ -271,7 +272,7 @@ public class ChocolateFactorySolver extends SimpleContainerSolver implements Too String lore = ItemUtils.concatenateLore(lines); Matcher costMatcher = COST_PATTERN.matcher(lore); - OptionalLong cost = RegexUtils.getLongFromMatcher(costMatcher); + OptionalLong cost = RegexUtils.findLongFromMatcher(costMatcher); //Available on all items with a chocolate cost if (cost.isPresent()) shouldAddLine |= addUpgradeTimerToLore(lines, cost.getAsLong()); @@ -364,26 +365,7 @@ public class ChocolateFactorySolver extends SimpleContainerSolver implements Too } private MutableText formatTime(double seconds) { - seconds = Math.ceil(seconds); - if (seconds <= 0) return Text.literal("Now").formatted(Formatting.GREEN); - - StringBuilder builder = new StringBuilder(); - if (seconds >= 86400) { - builder.append((int) (seconds / 86400)).append("d "); - seconds %= 86400; - } - if (seconds >= 3600) { - builder.append((int) (seconds / 3600)).append("h "); - seconds %= 3600; - } - if (seconds >= 60) { - builder.append((int) (seconds / 60)).append("m "); - seconds %= 60; - } - if (seconds >= 1) { - builder.append((int) seconds).append("s"); - } - return Text.literal(builder.toString()).formatted(Formatting.GOLD); + return SkyblockTime.formatTime(seconds).formatted(Formatting.GOLD); } @Override diff --git a/src/main/java/de/hysky/skyblocker/skyblock/events/EventToast.java b/src/main/java/de/hysky/skyblocker/skyblock/events/EventToast.java index 48ea05c4..16bd5272 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/events/EventToast.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/events/EventToast.java @@ -1,7 +1,7 @@ package de.hysky.skyblocker.skyblock.events; import de.hysky.skyblocker.SkyblockerMod; -import de.hysky.skyblocker.utils.Utils; +import de.hysky.skyblocker.utils.SkyblockTime; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; @@ -71,7 +71,7 @@ public class EventToast implements Toast { started = timeTillEvent < 0; if (started) return; - Text time = Utils.getDurationText(timeTillEvent); + Text time = SkyblockTime.formatTime(timeTillEvent); TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer; context.drawText(textRenderer, time, x, y, Colors.LIGHT_YELLOW, false); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/SkyblockItemRarity.java b/src/main/java/de/hysky/skyblocker/skyblock/item/SkyblockItemRarity.java index 60bda976..b21b5878 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/SkyblockItemRarity.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/SkyblockItemRarity.java @@ -3,17 +3,17 @@ package de.hysky.skyblocker.skyblock.item; import net.minecraft.util.Formatting; public enum SkyblockItemRarity { - ADMIN(Formatting.DARK_RED), - ULTIMATE(Formatting.DARK_RED), - VERY_SPECIAL(Formatting.RED), - SPECIAL(Formatting.RED), - DIVINE(Formatting.AQUA), - MYTHIC(Formatting.LIGHT_PURPLE), - LEGENDARY(Formatting.GOLD), - EPIC(Formatting.DARK_PURPLE), - RARE(Formatting.BLUE), + COMMON(Formatting.WHITE), UNCOMMON(Formatting.GREEN), - COMMON(Formatting.WHITE); + RARE(Formatting.BLUE), + EPIC(Formatting.DARK_PURPLE), + LEGENDARY(Formatting.GOLD), + MYTHIC(Formatting.LIGHT_PURPLE), + DIVINE(Formatting.AQUA), + SPECIAL(Formatting.RED), + VERY_SPECIAL(Formatting.RED), + ULTIMATE(Formatting.DARK_RED), + ADMIN(Formatting.DARK_RED); public final int color; public final float r; diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/BazaarPriceTooltip.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/BazaarPriceTooltip.java index 6d7d26c5..4e1c0dc3 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/BazaarPriceTooltip.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/BazaarPriceTooltip.java @@ -23,26 +23,26 @@ public class BazaarPriceTooltip extends SimpleTooltipAdder { String skyblockApiId = stack.getSkyblockApiId(); if (TooltipInfoType.BAZAAR.hasOrNullWarning(skyblockApiId)) { - int amount; - if (lines.get(1).getString().endsWith("Sack")) { - //The amount is in the 2nd sibling of the 3rd line of the lore. here V + int count; + if (lines.size() >= 4 && lines.get(3).getSiblings().size() >= 2 && lines.get(1).getString().endsWith("Sack")) { + //The count is in the 2nd sibling of the 3rd line of the lore. here V //Example line: empty[style={color=dark_purple,!italic}, siblings=[literal{Stored: }[style={color=gray}], literal{0}[style={color=dark_gray}], literal{/20k}[style={color=gray}]] String line = lines.get(3).getSiblings().get(1).getString().replace(",", ""); - amount = NumberUtils.isParsable(line) && !line.equals("0") ? Integer.parseInt(line) : stack.getCount(); + count = NumberUtils.isParsable(line) && !line.equals("0") ? Integer.parseInt(line) : stack.getCount(); } else { - amount = stack.getCount(); + count = stack.getCount(); } BazaarProduct product = TooltipInfoType.BAZAAR.getData().get(skyblockApiId); lines.add(Text.literal(String.format("%-18s", "Bazaar buy Price:")) .formatted(Formatting.GOLD) .append(product.buyPrice().isEmpty() ? Text.literal("No data").formatted(Formatting.RED) - : ItemTooltip.getCoinsMessage(product.buyPrice().getAsDouble(), amount))); + : ItemTooltip.getCoinsMessage(product.buyPrice().getAsDouble(), count))); lines.add(Text.literal(String.format("%-19s", "Bazaar sell Price:")) .formatted(Formatting.GOLD) .append(product.sellPrice().isEmpty() ? Text.literal("No data").formatted(Formatting.RED) - : ItemTooltip.getCoinsMessage(product.sellPrice().getAsDouble(), amount))); + : ItemTooltip.getCoinsMessage(product.sellPrice().getAsDouble(), count))); } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/EssenceShopPrice.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/EssenceShopPrice.java index 240a30ed..e4a85ec1 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/EssenceShopPrice.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/EssenceShopPrice.java @@ -50,7 +50,7 @@ public class EssenceShopPrice extends SimpleTooltipAdder { public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List<Text> lines) { String lore = ItemUtils.concatenateLore(lines); Matcher essenceMatcher = ESSENCE_PATTERN.matcher(lore); - OptionalLong cost = RegexUtils.getLongFromMatcher(essenceMatcher); + OptionalLong cost = RegexUtils.findLongFromMatcher(essenceMatcher); if (cost.isEmpty()) return; String type = essenceMatcher.group("type"); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/itemlist/UpcomingEventsTab.java b/src/main/java/de/hysky/skyblocker/skyblock/itemlist/UpcomingEventsTab.java index 9552ae87..5b46f568 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/itemlist/UpcomingEventsTab.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/itemlist/UpcomingEventsTab.java @@ -3,7 +3,7 @@ package de.hysky.skyblocker.skyblock.itemlist; import de.hysky.skyblocker.mixins.accessors.DrawContextInvoker; import de.hysky.skyblocker.skyblock.events.EventNotifications; import de.hysky.skyblocker.skyblock.tabhud.widget.JacobsContestWidget; -import de.hysky.skyblocker.utils.Utils; +import de.hysky.skyblocker.utils.SkyblockTime; import de.hysky.skyblocker.utils.scheduler.MessageScheduler; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; @@ -105,10 +105,10 @@ public class UpcomingEventsTab extends ItemListWidget.TabContainerWidget { if (events.isEmpty()) { context.drawText(textRenderer, Text.literal(" ").append(Text.translatable("skyblocker.events.tab.noMore")), x, y + textRenderer.fontHeight, Colors.GRAY, false); } else if (events.peekFirst().start() > time) { - MutableText formatted = Text.literal(" ").append(Text.translatable("skyblocker.events.tab.startsIn", Utils.getDurationText((int) (events.peekFirst().start() - time)))).formatted(Formatting.YELLOW); + MutableText formatted = Text.literal(" ").append(Text.translatable("skyblocker.events.tab.startsIn", SkyblockTime.formatTime((int) (events.peekFirst().start() - time)))).formatted(Formatting.YELLOW); context.drawText(textRenderer, formatted, x, y + textRenderer.fontHeight, -1, true); } else { - MutableText formatted = Text.literal(" ").append(Text.translatable( "skyblocker.events.tab.endsIn", Utils.getDurationText((int) (events.peekFirst().start() + events.peekFirst().duration() - time)))).formatted(Formatting.GREEN); + MutableText formatted = Text.literal(" ").append(Text.translatable( "skyblocker.events.tab.endsIn", SkyblockTime.formatTime((int) (events.peekFirst().start() + events.peekFirst().duration() - time)))).formatted(Formatting.GREEN); context.drawText(textRenderer, formatted, x, y + textRenderer.fontHeight, -1, true); } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/quicknav/QuickNavButton.java b/src/main/java/de/hysky/skyblocker/skyblock/quicknav/QuickNavButton.java index 1873111b..3f38bf74 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/quicknav/QuickNavButton.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/quicknav/QuickNavButton.java @@ -5,6 +5,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.serialization.JsonOps; import de.hysky.skyblocker.SkyblockerMod; import de.hysky.skyblocker.mixins.accessors.HandledScreenAccessor; +import de.hysky.skyblocker.utils.Constants; import de.hysky.skyblocker.utils.scheduler.MessageScheduler; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -18,6 +19,7 @@ import net.minecraft.client.gui.widget.ClickableWidget; import net.minecraft.item.ItemStack; import net.minecraft.text.Text; import net.minecraft.text.TextCodecs; +import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; import java.time.Duration; @@ -98,8 +100,11 @@ public class QuickNavButton extends ClickableWidget { if (!this.temporaryToggled) { this.temporaryToggled = true; this.toggleTime = System.currentTimeMillis(); - MessageScheduler.INSTANCE.sendMessageAfterCooldown(command); - // TODO : add null check with log error + if (command == null || command.isEmpty()) { + MinecraftClient.getInstance().player.sendMessage(Constants.PREFIX.get().append(Text.literal("Quick Nav button index " + (index + 1) + " has no command!").formatted(Formatting.RED)), false); + } else { + MessageScheduler.INSTANCE.sendMessageAfterCooldown(command); + } this.alpha = 0.5f; } } diff --git a/src/main/java/de/hysky/skyblocker/utils/RegexUtils.java b/src/main/java/de/hysky/skyblocker/utils/RegexUtils.java index 5b91a80b..3d6b8842 100644 --- a/src/main/java/de/hysky/skyblocker/utils/RegexUtils.java +++ b/src/main/java/de/hysky/skyblocker/utils/RegexUtils.java @@ -9,14 +9,14 @@ public class RegexUtils { /** * @return An OptionalLong of the first group in the matcher, or an empty OptionalLong if the matcher doesn't find anything. */ - public static OptionalLong getLongFromMatcher(Matcher matcher) { - return getLongFromMatcher(matcher, matcher.hasMatch() ? matcher.end() : 0); + public static OptionalLong findLongFromMatcher(Matcher matcher) { + return findLongFromMatcher(matcher, matcher.hasMatch() ? matcher.end() : 0); } /** * @return An OptionalLong of the first group in the matcher, or an empty OptionalLong if the matcher doesn't find anything. */ - public static OptionalLong getLongFromMatcher(Matcher matcher, int startingIndex) { + public static OptionalLong findLongFromMatcher(Matcher matcher, int startingIndex) { if (!matcher.find(startingIndex)) return OptionalLong.empty(); ret |
