Skip to content

Commit

Permalink
Improvement: Custom Scoreboard Refactor (hannibal002#2162)
Browse files Browse the repository at this point in the history
Co-authored-by: CalMWolfs <[email protected]>
Co-authored-by: J10a1n15 <[email protected]>
Co-authored-by: Empa <[email protected]>
Co-authored-by: Cal <[email protected]>
Co-authored-by: hannibal2 <[email protected]>
Co-authored-by: ItsEmpa <[email protected]>
  • Loading branch information
6 people authored Oct 18, 2024
1 parent ead1f9e commit 83efbb3
Show file tree
Hide file tree
Showing 94 changed files with 2,403 additions and 1,883 deletions.
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import at.hannibal2.skyhanni.utils.NumberUtil.formatDouble
import at.hannibal2.skyhanni.utils.NumberUtil.formatLong
import at.hannibal2.skyhanni.utils.NumberUtil.formatLongOrUserError
import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.TabListData
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.google.gson.JsonPrimitive
object ConfigUpdaterMigrator {

val logger = LorenzLogger("ConfigMigration")
const val CONFIG_VERSION = 62
const val CONFIG_VERSION = 63
fun JsonElement.at(chain: List<String>, init: Boolean): JsonElement? {
if (chain.isEmpty()) return this
if (this !is JsonObject) return null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package at.hannibal2.skyhanni.config.features.gui.customscoreboard;

import at.hannibal2.skyhanni.features.gui.customscoreboard.ChunkedStat;
import at.hannibal2.skyhanni.features.gui.customscoreboard.ChunkedStatsLine;
import com.google.gson.annotations.Expose;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDraggableList;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorSlider;
Expand All @@ -17,7 +17,7 @@ public class ChunkedStatsConfig {
desc = "Select the stats you want to display chunked on the scoreboard."
)
@ConfigEditorDraggableList
public List<ChunkedStat> chunkedStats = new ArrayList<>(ChunkedStat.getEntries());
public List<ChunkedStatsLine> chunkedStats = new ArrayList<>(ChunkedStatsLine.getEntries());

@Expose
@ConfigOption(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import at.hannibal2.skyhanni.config.FeatureToggle;
import at.hannibal2.skyhanni.config.core.config.Position;
import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardElement;
import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboard;
import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardConfigElement;
import com.google.gson.annotations.Expose;
import io.github.notenoughupdates.moulconfig.annotations.Accordion;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
Expand All @@ -28,17 +29,14 @@ public class CustomScoreboardConfig {
@Expose
@ConfigOption(
name = "Appearance",
desc = "Drag text to change the appearance of the advanced scoreboard." // supporting both custom & advanced search
desc = "Drag text to change the appearance of the advanced scoreboard."
)
@ConfigEditorDraggableList()
public List<ScoreboardElement> scoreboardEntries = new ArrayList<>(ScoreboardElement.defaultOption);
@ConfigEditorDraggableList
public Property<List<ScoreboardConfigElement>> scoreboardEntries = Property.of(new ArrayList<>(ScoreboardConfigElement.defaultOptions));

@ConfigOption(name = "Reset Appearance", desc = "Reset the appearance of the advanced scoreboard.")
@ConfigEditorButton(buttonText = "Reset")
public Runnable reset = () -> {
scoreboardEntries.clear();
scoreboardEntries.addAll(ScoreboardElement.defaultOption);
};
public Runnable reset = CustomScoreboard::resetAppearance;

@Expose
@ConfigOption(name = "Display Options", desc = "")
Expand All @@ -56,7 +54,11 @@ public class CustomScoreboardConfig {
public InformationFilteringConfig informationFiltering = new InformationFilteringConfig();

@Expose
@ConfigOption(name = "Unknown Lines warning", desc = "Give a chat warning when unknown lines are found in the scoreboard.")
@ConfigOption(
name = "Unknown Lines warning",
desc = "Give a chat warning when unknown lines are found in the scoreboard." +
"\n§cReporting these in the Discord Server are very important, so we can know what lines are missing."
)
@ConfigEditorBoolean
public boolean unknownLinesWarning = true;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.config.features.gui.customscoreboard;

import at.hannibal2.skyhanni.config.FeatureToggle;
import at.hannibal2.skyhanni.utils.RenderUtils;
import com.google.gson.annotations.Expose;
import io.github.notenoughupdates.moulconfig.annotations.Accordion;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
Expand Down Expand Up @@ -51,7 +52,6 @@ public class DisplayConfig {
@Accordion
public TitleAndFooterConfig titleAndFooter = new TitleAndFooterConfig();


@Expose
@ConfigOption(name = "Hide Vanilla Scoreboard", desc = "Hide the vanilla scoreboard.\n" +
"§cMods that add their own scoreboard will not be affected by this setting!")
Expand Down Expand Up @@ -145,8 +145,16 @@ public String toString() {
public int lineSpacing = 10;

@Expose
@ConfigOption(name = "Cache Scoreboard on Island Switch",
desc = "Will stop the Scoreboard from updating while switching islands.\nRemoves the shaking when loading data.")
@ConfigOption(name = "Text Alignment", desc = "Will align the text to the left, center or right, while not overriding certain lines, like title or footer.")
@ConfigEditorDropdown
public RenderUtils.HorizontalAlignment textAlignment = RenderUtils.HorizontalAlignment.LEFT;

@Expose
@ConfigOption(
name = "Cache Scoreboard on Island Switch",
desc = "Will stop the Scoreboard from updating while switching islands.\n" +
"Removes the shaking when loading data."
)
@ConfigEditorBoolean
public boolean cacheScoreboardOnIslandSwitch = false;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package at.hannibal2.skyhanni.config.features.gui.customscoreboard;

import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardEvent;
import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardConfigEventElement;
import com.google.gson.annotations.Expose;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorButton;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDraggableList;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;
import io.github.notenoughupdates.moulconfig.observer.Property;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -18,13 +19,15 @@ public class EventsConfig {
desc = "Drag your list to select the priority of each event."
)
@ConfigEditorDraggableList()
public List<ScoreboardEvent> eventEntries = new ArrayList<>(ScoreboardEvent.defaultOption);
public Property<List<ScoreboardConfigEventElement>> eventEntries = Property.of(new ArrayList<>(ScoreboardConfigEventElement.defaultOption));

@ConfigOption(name = "Reset Events Priority", desc = "Reset the priority of all events.")
@ConfigEditorButton(buttonText = "Reset")
// TODO move into kotlin
public Runnable reset = () -> {
eventEntries.clear();
eventEntries.addAll(ScoreboardEvent.defaultOption);
eventEntries.get().clear();
eventEntries.get().addAll(ScoreboardConfigEventElement.defaultOption);
eventEntries.notifyObservers();
};

@Expose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class PartyConfig {
@ConfigOption(name = "Max Party List", desc = "Max number of party members to show in the party list (you are not included).")
@ConfigEditorSlider(
minValue = 1,
maxValue = 25, // why do I even set it so high
maxValue = 25,
minStep = 1
)
public Property<Integer> maxPartyList = Property.of(4);
Expand All @@ -21,4 +21,9 @@ public class PartyConfig {
"If disabled, it will only show in Dungeon Hub, Crimson Isle & Kuudra.")
@ConfigEditorBoolean
public boolean showPartyEverywhere = false;

@Expose
@ConfigOption(name = "Show Party Leader", desc = "Show the party leader in the party list.")
@ConfigEditorBoolean
public boolean showPartyLeader = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDropdown;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorText;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;
import io.github.notenoughupdates.moulconfig.observer.Property;

public class TitleAndFooterConfig {
@Expose
@ConfigOption(name = "Title and Footer Alignment", desc = "Align the title and footer in the scoreboard.")
@ConfigOption(name = "Title Alignment", desc = "Align the title in the scoreboard.")
@ConfigEditorDropdown
// TODO rename to "horizontalAlignment" or "alignment"
public RenderUtils.HorizontalAlignment alignTitleAndFooter = RenderUtils.HorizontalAlignment.CENTER;
public RenderUtils.HorizontalAlignment alignTitle = RenderUtils.HorizontalAlignment.CENTER;

@Expose
@ConfigOption(name = "Custom Title", desc = "What should be displayed as the title of the scoreboard." +
"\nUse & for colors." +
"\nUse && for colors." +
"\nUse \"\\n\" for new line.")
@ConfigEditorText
public Property<String> customTitle = Property.of("&6&lSKYBLOCK");
public String customTitle = "&&6&&lSKYBLOCK";

@Expose
@ConfigOption(name = "Use Custom Title", desc = "Use a custom title instead of the default Hypixel title.")
Expand All @@ -32,10 +30,22 @@ public class TitleAndFooterConfig {
@ConfigEditorBoolean
public boolean useCustomTitleOutsideSkyBlock = false;

@Expose
@ConfigOption(name = "Footer Alignment", desc = "Align the footer in the scoreboard.")
@ConfigEditorDropdown
public RenderUtils.HorizontalAlignment alignFooter = RenderUtils.HorizontalAlignment.LEFT;

@Expose
@ConfigOption(name = "Custom Footer", desc = "What should be displayed as the footer of the scoreboard." +
"\nUse & for colors." +
"\nUse && for colors." +
"\nUse \"\\n\" for new line.")
@ConfigEditorText
public String customFooter = "&&ewww.hypixel.net";

@Expose
@ConfigOption(name = "Custom Alpha Footer", desc = "What should be displayed as the footer of the scoreboard when on the Alpha Server." +
"\nUse && for colors." +
"\nUse \"\\n\" for new line.")
@ConfigEditorText
public Property<String> customFooter = Property.of("&ewww.hypixel.net");
public String customAlphaFooter = "&&ealpha.hypixel.net";
}
18 changes: 10 additions & 8 deletions src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -485,32 +485,34 @@ object HypixelData {
}

private fun checkIsland(event: WidgetUpdateEvent) {
val islandType: IslandType
val newIsland: IslandType
val foundIsland: String
if (event.isClear()) {

TabListData.fullyLoaded = false
islandType = IslandType.NONE
newIsland = IslandType.NONE
foundIsland = ""

} else {
TabListData.fullyLoaded = true
// Can not use color coding, because of the color effect (§f§lSKYB§6§lL§e§lOCK§A§L GUEST)
val guesting = guestPattern.matches(ScoreboardData.objectiveTitle.removeColor())
foundIsland = TabWidget.AREA.matchMatcherFirstLine { group("island").removeColor() } ?: ""
islandType = getIslandType(foundIsland, guesting)
newIsland = getIslandType(foundIsland, guesting)
}

// TODO don't send events when one of the arguments is none, at least when not on sb anymore
if (skyBlockIsland != islandType) {
IslandChangeEvent(islandType, skyBlockIsland).postAndCatch()
if (islandType == IslandType.UNKNOWN) {
if (skyBlockIsland != newIsland) {
val oldIsland = skyBlockIsland
skyBlockIsland = newIsland
IslandChangeEvent(newIsland, oldIsland).postAndCatch()

if (newIsland == IslandType.UNKNOWN) {
ChatUtils.debug("Unknown island detected: '$foundIsland'")
loggerIslandChange.log("Unknown: '$foundIsland'")
} else {
loggerIslandChange.log(islandType.name)
loggerIslandChange.log(newIsland.name)
}
skyBlockIsland = islandType
if (TabListData.fullyLoaded) {
TabWidget.reSendEvents()
}
Expand Down
15 changes: 6 additions & 9 deletions src/main/java/at/hannibal2/skyhanni/data/MaxwellAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.features.dungeon.DungeonAPI
import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboard
import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardElement
import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardConfigElement
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.ChatUtils
Expand Down Expand Up @@ -135,14 +135,11 @@ object MaxwellAPI {

chatPowerPattern.tryReadPower(message)
chatPowerUnlockedPattern.tryReadPower(message)
tuningAutoAssignedPattern.matchMatcher(event.message) {
if (tunings.isNullOrEmpty()) return
val tuningsInScoreboard = ScoreboardElement.TUNING in CustomScoreboard.config.scoreboardEntries
if (tuningsInScoreboard) {
ChatUtils.chat(
"Talk to Maxwell and open the Tuning Page again to update the tuning data in scoreboard.",
)
}
if (!tuningAutoAssignedPattern.matches(event.message)) return
if (tunings.isNullOrEmpty()) return
with(CustomScoreboard.config) {
if (!enabled.get() || ScoreboardConfigElement.TUNING !in scoreboardEntries.get()) return
ChatUtils.chat("Talk to Maxwell and open the Tuning Page again to update the tuning data in scoreboard.")
}
}

Expand Down
17 changes: 14 additions & 3 deletions src/main/java/at/hannibal2/skyhanni/data/MiningAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import at.hannibal2.skyhanni.events.ServerBlockChangeEvent
import at.hannibal2.skyhanni.events.mining.OreMinedEvent
import at.hannibal2.skyhanni.events.player.PlayerDeathEvent
import at.hannibal2.skyhanni.events.skyblock.ScoreboardAreaChangeEvent
import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardPattern
import at.hannibal2.skyhanni.features.mining.OreBlock
import at.hannibal2.skyhanni.features.mining.isTitanium
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
Expand Down Expand Up @@ -46,12 +45,20 @@ object MiningAPI {
private val glaciteAreaPattern by group.pattern("area.glacite", "Glacite Tunnels|Great Glacite Lake")
private val dwarvenBaseCampPattern by group.pattern("area.basecamp", "Dwarven Base Camp")

// TODO add regex test
// TODO add regex tests
private val coldResetPattern by group.pattern(
"cold.reset",
"§6The warmth of the campfire reduced your §r§b❄ Cold §r§6to §r§a0§r§6!|§c ☠ §r§7You froze to death§r§7\\.",
)

/**
* REGEX-TEST: Cold: §b-1❄
*/
val coldPattern by group.pattern(
"cold",
"(?:§.)*Cold: §.(?<cold>-?\\d+)❄",
)

private val pickbobulusGroup = group.group("pickobulus")

/**
Expand Down Expand Up @@ -150,11 +157,15 @@ object MiningAPI {
IslandType.SPIDER_DEN,
)

fun inAdvancedMiningIsland() = inAnyIsland(IslandType.DWARVEN_MINES, IslandType.CRYSTAL_HOLLOWS, IslandType.MINESHAFT)

fun inMiningIsland() = inAdvancedMiningIsland() || inAnyIsland(IslandType.GOLD_MINES, IslandType.DEEP_CAVERNS)

fun inColdIsland() = inAnyIsland(IslandType.DWARVEN_MINES, IslandType.MINESHAFT)

@SubscribeEvent
fun onScoreboardChange(event: ScoreboardUpdateEvent) {
val newCold = ScoreboardPattern.coldPattern.firstMatcher(event.scoreboard) {
val newCold = coldPattern.firstMatcher(event.scoreboard) {
group("cold").toInt().absoluteValue
} ?: return

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/data/WinterAPI.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
import at.hannibal2.skyhanni.utils.TimeUtils
import java.time.Month

object WinterAPI {

fun inWorkshop() = IslandType.WINTER.isInIsland()

fun isDecember() = TimeUtils.getCurrentLocalDate().month == Month.DECEMBER
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ enum class TabWidget(
),
EVENT(
// language=RegExp
"(?:§.)*Event: (?:§.)*(?<event>.*)",
"(?:§.)*Event: (?<color>(?:§.)*)(?<event>.*)",
),
SKILLS(
// language=RegExp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
package at.hannibal2.skyhanni.features.combat

import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.data.ScoreboardData
import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardPattern
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
import at.hannibal2.skyhanni.utils.RegexUtils.anyMatches
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern

@SkyHanniModule
object SpidersDenAPI {
fun isAtTopOfNest(): Boolean = ScoreboardData.sidebarLinesFormatted.any { ScoreboardPattern.broodmotherPattern.matches(it) }

private val repoGroup = RepoPattern.group("combat.spidersden")

/**
* REGEX-TEST: §4Broodmother§7: §6Soon
*/
val broodmotherPattern by repoGroup.pattern(
"broodmother",
"§4Broodmother§7: §[e64](?:Slain|Dormant|Soon|Awakening|Imminent|Alive!)",
)

fun inSpidersDen() = IslandType.SPIDER_DEN.isInIsland()

fun isAtTopOfNest() = inSpidersDen() && broodmotherPattern.anyMatches(ScoreboardData.sidebarLinesFormatted)
}
Loading

0 comments on commit 83efbb3

Please sign in to comment.