From ff5287258aee4e39b6ab0ba92ab17afde2de07d9 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Wed, 1 May 2024 08:56:07 +0200 Subject: [PATCH] Feature: Chocolate change leaderboard (#1602) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Co-authored-by: Cal --- .../ChocolateFactoryConfig.java | 9 +++++ .../storage/ProfileSpecificStorage.java | 14 +++++++ .../chocolatefactory/ChocolateFactoryAPI.kt | 1 + .../chocolatefactory/ChocolateFactoryStats.kt | 11 +++-- .../ChocolatePositionChange.kt | 40 +++++++++++++++++++ 5 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolatePositionChange.kt diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java index 96386bf76644..773fe7fcfcc2 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java @@ -129,6 +129,15 @@ public class ChocolateFactoryConfig { @ConfigLink(owner = ChocolateFactoryConfig.class, field = "hoppityCollectionStats") public Position hoppityStatsPosition = new Position(163, 160, false, true); + @Expose + @ConfigOption(name = "Leaderboard Change", + desc = "Show the change of your chocolate leaderboard over time in chat. " + + "This updates every time you first open the /cf menu on a new server." + ) + @ConfigEditorBoolean + @FeatureToggle + public boolean leaderboardChange = false; + @Expose @ConfigOption(name = "Hoppity Menu Shortcut", desc = "Add a Chocolate Factory button in the SkyBlock Menu that runs /chocolatefactory on click.") @ConfigEditorBoolean diff --git a/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java b/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java index 472f1e8af1cb..ba60712e9570 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java +++ b/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java @@ -94,6 +94,20 @@ public static class ChocolateFactoryStorage { @Expose public long lastDataSave = 0; + + @Expose + public PositionChange positionChange = new PositionChange(); + + public static class PositionChange { + @Expose + public Long lastTime = null; + + @Expose + public int lastPosition = -1; + + @Expose + public String lastLeaderboard = null; + } } @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryAPI.kt index 37ddb9a8e926..5780b4d24880 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryAPI.kt @@ -36,6 +36,7 @@ import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object ChocolateFactoryAPI { + val config: ChocolateFactoryConfig get() = SkyHanniMod.feature.inventory.chocolateFactory val profileStorage: ChocolateFactoryStorage? get() = ProfileStorageData.profileSpecific?.chocolateFactory diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryStats.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryStats.kt index cbf38db46de9..a30848d43492 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryStats.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryStats.kt @@ -41,8 +41,13 @@ object ChocolateFactoryStats { val perMinute = perSecond * 60 val perHour = perMinute * 60 val perDay = perHour * 24 - val position = ChocolateFactoryAPI.leaderboardPosition?.addSeparators() ?: "???" + + val position = ChocolateFactoryAPI.leaderboardPosition + val positionText = position?.addSeparators() ?: "???" val percentile = ChocolateFactoryAPI.leaderboardPercentile?.let { "§7Top §a$it%" } ?: "" + val leaderboard = "#$positionText $percentile" + ChocolatePositionChange.update(position, leaderboard) + val timeTowerInfo = if (ChocolateFactoryTimeTowerManager.timeTowerActive()) { "§d§lActive" } else { @@ -66,7 +71,7 @@ object ChocolateFactoryStats { put(ChocolateFactoryStat.MULTIPLIER, "§eChocolate Multiplier: §6${profileStorage.chocolateMultiplier}") put(ChocolateFactoryStat.BARN, "§eBarn: §6${ChocolateFactoryBarnManager.barnStatus()}") - put(ChocolateFactoryStat.LEADERBOARD_POS, "§ePosition: §7#§b$position $percentile") + put(ChocolateFactoryStat.LEADERBOARD_POS, "§ePosition: §b$leaderboard") put(ChocolateFactoryStat.EMPTY, "") put(ChocolateFactoryStat.EMPTY_2, "") @@ -120,7 +125,7 @@ object ChocolateFactoryStats { PER_DAY("§ePer Day: §6326,654,208"), MULTIPLIER("§eChocolate Multiplier: §61.77"), BARN("§eBarn: §6171/190 Rabbits"), - LEADERBOARD_POS("§ePosition: §7#§b103 §7Top §a0.87%"), + LEADERBOARD_POS("§ePosition: §b#103 §7Top §a0.87%"), EMPTY(""), EMPTY_2(""), EMPTY_3(""), diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolatePositionChange.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolatePositionChange.kt new file mode 100644 index 000000000000..0868f5bd29c0 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolatePositionChange.kt @@ -0,0 +1,40 @@ +package at.hannibal2.skyhanni.features.inventory.chocolatefactory + +import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.TimeUtils.format + +object ChocolatePositionChange { + + private val config get() = ChocolateFactoryAPI.config + private val storage get() = ChocolateFactoryAPI.profileStorage?.positionChange + + fun update(position: Int?, leaderboard: String) { + position ?: return + val storage = storage ?: return + val lastTime = storage.lastTime?.let { SimpleTimeMark(it) } + val lastPosition = storage.lastPosition + val lastLeaderboard = storage.lastLeaderboard + + if (lastLeaderboard == leaderboard) return + + lastLeaderboard?.let { lastLb -> + var message = "$lastLb §c-> $leaderboard" + val change = lastPosition - position + val color = if (change > 0) "§a+" else "§c" + message += "\n §7Changed by $color${change.addSeparators()} spots" + + lastTime?.let { + message += " §7in §b${it.passedSince().format(maxUnits = 2)}" + } + if (config.leaderboardChange && lastPosition != -1) { + ChatUtils.chat(" \n §6Chocolate Leaderboard Change: §7(SkyHanni)\n $message\n ", prefix = false) + } + } + + storage.lastTime = SimpleTimeMark.now().toMillis() + storage.lastLeaderboard = leaderboard + storage.lastPosition = position + } +}