Skip to content

Commit

Permalink
Feature: Chocolate change leaderboard (#1602)
Browse files Browse the repository at this point in the history
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Co-authored-by: Cal <cwolfson58@gmail.com>
  • Loading branch information
3 people authored May 1, 2024
1 parent dad2c5b commit ff52872
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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, "")
Expand Down Expand Up @@ -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(""),
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit ff52872

Please sign in to comment.