Skip to content

Commit

Permalink
Backend: Move some commands to their own classes (#3309)
Browse files Browse the repository at this point in the history
  • Loading branch information
CalMWolfs authored Jan 25, 2025
1 parent 86a3090 commit 2818165
Show file tree
Hide file tree
Showing 42 changed files with 451 additions and 318 deletions.
256 changes: 0 additions & 256 deletions src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.config.commands.CommandCategory
import at.hannibal2.skyhanni.config.commands.CommandRegistrationEvent
import at.hannibal2.skyhanni.events.MessageSendToServerEvent
import at.hannibal2.skyhanni.events.chat.SkyHanniChatEvent
import at.hannibal2.skyhanni.events.minecraft.packet.PacketSentEvent
Expand Down Expand Up @@ -172,7 +174,7 @@ object ChatManager {
}
}

fun openChatFilterGUI(args: Array<String>) {
private fun openChatFilterGUI(args: Array<String>) {
SkyHanniMod.screenToOpen = if (args.isEmpty()) {
ChatFilterGui(getRecentMessageHistory())
} else {
Expand Down Expand Up @@ -206,4 +208,13 @@ object ChatManager {
history.actionKind = ActionKind.RETRACTED
history.actionReason = reason.uppercase()
}

@HandleEvent
fun onCommandRegistration(event: CommandRegistrationEvent) {
event.register("shchathistory") {
description = "Show the unfiltered chat history"
category = CommandCategory.DEVELOPER_TEST
callback { openChatFilterGUI(it) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package at.hannibal2.skyhanni.data
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.config.ConfigManager
import at.hannibal2.skyhanni.config.commands.CommandCategory
import at.hannibal2.skyhanni.config.commands.CommandRegistrationEvent
import at.hannibal2.skyhanni.data.jsonobjects.repo.GardenJson
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.features.garden.CropType
Expand Down Expand Up @@ -111,7 +113,7 @@ object GardenCropMilestonesCommunityFix {
* differences are getting replaced, and the result gets put into the clipboard.
* The clipboard context can be used to update the repo content.
*/
fun readDataFromClipboard() {
private fun readDataFromClipboard() {
SkyHanniMod.coroutineScope.launch {
OSUtils.readFromClipboard()?.let {
handleInput(it)
Expand Down Expand Up @@ -160,4 +162,13 @@ object GardenCropMilestonesCommunityFix {
this[tier] = amount
}
}

@HandleEvent
fun onCommandRegistration(event: CommandRegistrationEvent) {
event.register("shreadcropmilestonefromclipboard") {
description = "Read crop milestone from clipboard. This helps fixing wrong crop milestone data"
category = CommandCategory.DEVELOPER_TEST
callback { readDataFromClipboard() }
}
}
}
13 changes: 12 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/data/PartyApi.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.config.commands.CommandCategory
import at.hannibal2.skyhanni.config.commands.CommandRegistrationEvent
import at.hannibal2.skyhanni.data.hypixel.chat.event.PartyChatEvent
import at.hannibal2.skyhanni.events.chat.SkyHanniChatEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
Expand Down Expand Up @@ -142,7 +144,7 @@ object PartyApi {
var partyLeader: String? = null
var prevPartyLeader: String? = null

fun listMembers() {
private fun listMembers() {
val size = partyMembers.size
if (size == 0) {
ChatUtils.chat("No tracked party members!")
Expand Down Expand Up @@ -278,4 +280,13 @@ object PartyApi {
partyLeader = null
prevPartyLeader = null
}

@HandleEvent
fun onCommandRegistration(event: CommandRegistrationEvent) {
event.register("shpartydebug") {
description = "List persons into the chat SkyHanni thinks are in your party."
category = CommandCategory.DEVELOPER_TEST
callback { listMembers() }
}
}
}
13 changes: 12 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/data/TitleManager.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.config.commands.CommandCategory
import at.hannibal2.skyhanni.config.commands.CommandRegistrationEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.ProfileJoinEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
Expand Down Expand Up @@ -42,7 +44,7 @@ object TitleManager {
}
}

fun command(args: Array<String>) {
private fun command(args: Array<String>) {
if (args.size < 4) {
ChatUtils.userError("Usage: /shsendtitle <duration> <height> <fontSize> <text ..>")
return
Expand Down Expand Up @@ -82,4 +84,13 @@ object TitleManager {
TextRenderUtils.drawStringCenteredScaledMaxWidth(display, renderer, 0f, 0f, true, 75, 0)
GlStateManager.popMatrix()
}

@HandleEvent
fun onCommandRegistration(event: CommandRegistrationEvent) {
event.register("shsendtitle") {
description = "Display a title on the screen with the specified settings."
category = CommandCategory.DEVELOPER_TEST
callback { command(it) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package at.hannibal2.skyhanni.features.bingo.card
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.config.commands.CommandCategory
import at.hannibal2.skyhanni.config.commands.CommandRegistrationEvent
import at.hannibal2.skyhanni.events.ConfigLoadEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.SecondPassedEvent
Expand Down Expand Up @@ -49,7 +51,7 @@ object BingoCardDisplay {
BingoApi.bingoGoals.clear()
}

fun toggleCommand() {
private fun toggleCommand() {
if (!LorenzUtils.isBingoProfile) {
ChatUtils.userError("This command only works on a bingo profile!")
return
Expand Down Expand Up @@ -267,4 +269,13 @@ object BingoCardDisplay {
fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
event.move(2, "bingo", "event.bingo")
}

@HandleEvent
fun onCommandRegistration(event: CommandRegistrationEvent) {
event.register("shbingotoggle") {
description = "Toggle the bingo card display mode"
category = CommandCategory.USERS_ACTIVE
callback { toggleCommand() }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.SkyHanniMod.coroutineScope
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.config.commands.CommandCategory
import at.hannibal2.skyhanni.config.commands.CommandRegistrationEvent
import at.hannibal2.skyhanni.events.ConfigLoadEvent
import at.hannibal2.skyhanni.events.chat.SkyHanniChatEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
Expand Down Expand Up @@ -138,7 +140,7 @@ object Translator {
return arrayOf(messageToSend, language)
}

fun toNativeLanguage(args: Array<String>) {
private fun toNativeLanguage(args: Array<String>) {
val message = args.joinToString(" ").removeColor()

coroutineScope.launch {
Expand All @@ -158,7 +160,7 @@ object Translator {
}
}

fun fromNativeLanguage(args: Array<String>) {
private fun fromNativeLanguage(args: Array<String>) {
if (args.size < 2) {
ChatUtils.userError("Usage: /shcopytranslation <language code (found at the end of a translation)> <message>")
return
Expand All @@ -176,7 +178,27 @@ object Translator {
}
}

fun translateAdvancedCommand(args: Array<String>) {
@HandleEvent
fun onCommandRegistration(event: CommandRegistrationEvent) {
event.register("shtranslateadvanced") {
description = "Translates a message in an inputted language to another inputted language."
category = CommandCategory.DEVELOPER_TEST
callback { translateAdvancedCommand(it) }
}
event.register("shcopytranslation") {
description = "Copy the translation of a message in another language to your clipboard.\n" +
"Uses a 2 letter language code that can be found at the end of a translation message."
category = CommandCategory.USERS_ACTIVE
callback { fromNativeLanguage(it) }
}
event.register("shtranslate") {
description = "Translate a message in another language your language."
category = CommandCategory.USERS_ACTIVE
callback { toNativeLanguage(it) }
}
}

private fun translateAdvancedCommand(args: Array<String>) {
if (args.size < 3) {
ChatUtils.userError("Usage: /shtranslateadvanced <source lang code> <target lang code> <message>")
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package at.hannibal2.skyhanni.features.combat.endernodetracker
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.config.commands.CommandCategory
import at.hannibal2.skyhanni.config.commands.CommandRegistrationEvent
import at.hannibal2.skyhanni.config.features.combat.EnderNodeConfig.EnderNodeDisplayEntry
import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.data.ProfileStorageData
Expand Down Expand Up @@ -283,7 +285,12 @@ object EnderNodeTracker {
return newList
}

fun resetCommand() {
tracker.resetCommand()
@HandleEvent
fun onCommandRegistration(event: CommandRegistrationEvent) {
event.register("shresetendernodetracker") {
description = "Resets the Ender Node Tracker"
category = CommandCategory.USERS_RESET
callback { tracker.resetCommand() }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package at.hannibal2.skyhanni.features.event.diana

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.config.commands.CommandCategory
import at.hannibal2.skyhanni.config.commands.CommandRegistrationEvent
import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.events.diana.BurrowDetectEvent
import at.hannibal2.skyhanni.events.minecraft.SkyHanniRenderWorldEvent
Expand Down Expand Up @@ -45,13 +47,13 @@ object AllBurrowsList {
.take(25).toList()
}

fun copyToClipboard() {
private fun copyToClipboard() {
val list = burrowLocations.map { it.printWithAccuracy(0, ":") }
OSUtils.copyToClipboard(list.joinToString(";"))
ChatUtils.chat("Saved all ${list.size} burrow locations to clipboard.")
}

fun addFromClipboard() {
private fun addFromClipboard() {
SkyHanniMod.coroutineScope.launch {
val text = OSUtils.readFromClipboard() ?: return@launch

Expand Down Expand Up @@ -85,5 +87,19 @@ object AllBurrowsList {
}
}

@HandleEvent
fun onCommandRegistration(event: CommandRegistrationEvent) {
event.register("shaddfoundburrowlocationsfromclipboard") {
description = "Add all ever found burrow locations from clipboard"
category = CommandCategory.DEVELOPER_TEST
callback { addFromClipboard() }
}
event.register("shcopyfoundburrowlocations") {
description = "Copy all ever found burrow locations to clipboard"
category = CommandCategory.DEVELOPER_DEBUG
callback { copyToClipboard() }
}
}

fun isEnabled() = DianaApi.isDoingDiana() && config.save
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package at.hannibal2.skyhanni.features.event.diana
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.config.commands.CommandCategory
import at.hannibal2.skyhanni.config.commands.CommandRegistrationEvent
import at.hannibal2.skyhanni.data.ElectionApi.getElectionYear
import at.hannibal2.skyhanni.data.ItemAddManager
import at.hannibal2.skyhanni.data.jsonobjects.repo.DianaDropsJson
Expand Down Expand Up @@ -178,8 +180,13 @@ object DianaProfitTracker {
allowedDrops = event.getConstant<DianaDropsJson>("DianaDrops").dianaDrops
}

fun resetCommand() {
tracker.resetCommand()
@HandleEvent
fun onCommandRegistration(event: CommandRegistrationEvent) {
event.register("shresetdianaprofittracker") {
description = "Resets the Diana Profit Tracker"
category = CommandCategory.USERS_RESET
callback { tracker.resetCommand() }
}
}

private val migrationMapping by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package at.hannibal2.skyhanni.features.event.diana
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.config.commands.CommandCategory
import at.hannibal2.skyhanni.config.commands.CommandRegistrationEvent
import at.hannibal2.skyhanni.data.ElectionCandidate
import at.hannibal2.skyhanni.data.EntityMovementData
import at.hannibal2.skyhanni.data.IslandType
Expand Down Expand Up @@ -394,7 +396,7 @@ object GriffinBurrowHelper {

private fun isEnabled() = DianaApi.isDoingDiana()

fun setTestBurrow(strings: Array<String>) {
private fun setTestBurrow(strings: Array<String>) {
if (!IslandType.HUB.isInIsland()) {
ChatUtils.userError("You can only create test burrows on the hub island!")
return
Expand Down Expand Up @@ -439,4 +441,13 @@ object GriffinBurrowHelper {
particleBurrows = particleBurrows.editCopy { this[location] = type }
update()
}

@HandleEvent
fun onCommandRegistration(event: CommandRegistrationEvent) {
event.register("shtestburrow") {
description = "Sets a test burrow waypoint at your location"
category = CommandCategory.DEVELOPER_TEST
callback { setTestBurrow(it) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package at.hannibal2.skyhanni.features.event.diana

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.config.commands.CommandCategory
import at.hannibal2.skyhanni.config.commands.CommandRegistrationEvent
import at.hannibal2.skyhanni.data.ElectionApi.getElectionYear
import at.hannibal2.skyhanni.events.ConfigLoadEvent
import at.hannibal2.skyhanni.events.chat.SkyHanniChatEvent
Expand Down Expand Up @@ -149,8 +151,12 @@ object MythologicalCreatureTracker {
)
}

fun resetCommand() {
tracker.resetCommand()
@HandleEvent
fun onCommandRegistration(event: CommandRegistrationEvent) {
event.register("shresetmythologicalcreaturetracker") {
description = "Resets the Mythological Creature Tracker"
category = CommandCategory.USERS_RESET
callback { tracker.resetCommand() }
}
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package at.hannibal2.skyhanni.features.event.hoppity

import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.config.commands.CommandCategory
import at.hannibal2.skyhanni.config.commands.CommandRegistrationEvent
import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.data.jsonobjects.repo.HoppityEggLocationsJson
import at.hannibal2.skyhanni.events.NeuProfileDataLoadedEvent
Expand Down Expand Up @@ -123,7 +125,7 @@ object HoppityEggLocations {
// to be removed - in case there are any issues with missing locations
private var legacyEggLocations: Map<IslandType, Set<LorenzVec>> = mapOf()

fun toggleDebug() {
private fun toggleDebug() {
showEggLocationsDebug = !showEggLocationsDebug
val enabledDisabled = if (showEggLocationsDebug) "§aEnabled" else "§cDisabled"
ChatUtils.chat("$enabledDisabled hoppity egg location debug viewer.")
Expand All @@ -148,4 +150,13 @@ object HoppityEggLocations {
}
}
}

@HandleEvent
fun onCommandRegistration(event: CommandRegistrationEvent) {
event.register("shtoggleegglocationdebug") {
description = "Shows Hoppity egg locations with their internal API names and status."
category = CommandCategory.DEVELOPER_TEST
callback { toggleDebug() }
}
}
}
Loading

0 comments on commit 2818165

Please sign in to comment.