diff options
Diffstat (limited to 'src/main/java/at/hannibal2')
5 files changed, 35 insertions, 8 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 771f5bdd2..3cc1dc11a 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -255,7 +255,7 @@ class SkyHanniMod { loadModule(AshfangMinisNametagHider()) loadModule(GardenTeleportPadInventoryNumber()) loadModule(ComposterOverlay()) - loadModule(DiscordRPCManager()) + loadModule(DiscordRPCManager) loadModule(GardenCropMilestoneFix()) loadModule(GardenBurrowingSporesNotifier()) loadModule(WildStrawberryDyeNotification()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt index 23e478ade..b36d04121 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -17,6 +17,7 @@ import at.hannibal2.skyhanni.features.garden.farming.CropSpeedMeter import at.hannibal2.skyhanni.features.minion.MinionFeatures import at.hannibal2.skyhanni.features.misc.CollectionCounter import at.hannibal2.skyhanni.features.misc.MarkedPlayerManager +import at.hannibal2.skyhanni.features.misc.discordrpc.DiscordRPCManager import at.hannibal2.skyhanni.test.PacketTest import at.hannibal2.skyhanni.test.SkyHanniTestCommand import at.hannibal2.skyhanni.test.TestBingo @@ -52,6 +53,7 @@ object Commands { registerCommand("shcropspeedmeter") { CropSpeedMeter.toggle() } registerCommand("shcroptime") { GardenCropTimeCommand.onCommand(it) } registerCommand("shshareinquis") { InquisitorWaypointShare.sendInquisitor() } + registerCommand("shrpcstart") { DiscordRPCManager.startCommand() } // for users - fix bugs registerCommand("shupdaterepo") { SkyHanniMod.repo.updateRepo() } diff --git a/src/main/java/at/hannibal2/skyhanni/data/ActionBarStatsData.kt b/src/main/java/at/hannibal2/skyhanni/data/ActionBarStatsData.kt index 5130e7080..7e6c7f21e 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ActionBarStatsData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ActionBarStatsData.kt @@ -7,7 +7,7 @@ import java.util.regex.Pattern class ActionBarStatsData { private val pattern = - Pattern.compile("..((?:\\d|,)*)\\/(?:\\d|,)*(.) *..((?:\\d|,)*)..(. \\w*) *..((?:\\d|,)*)\\/(?:\\d|,)*(.*)") + Pattern.compile("..((?:\\d|,)*)\\/(?:\\d|,)*(.) *..((?:\\d|,)*)..(. \\w*) *..((?:\\d|,)*)\\/(?:\\d|,)*(✎).*") // Sample input: §c2,817/2,817❤ §a703§a❈ Defense §b3,479/3,479✎ Mana // Returns the following groups: 1 = 2,817; 2 = ❤; 3 = 703; 4 = ❈ Defense; 5 = 3,479; 6 = ✎ Mana diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordRPCManager.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordRPCManager.kt index 21539451f..6717f861b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordRPCManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordRPCManager.kt @@ -22,7 +22,7 @@ import java.util.concurrent.Executors import java.util.concurrent.ScheduledExecutorService import java.util.concurrent.TimeUnit -class DiscordRPCManager : IPCListener { +object DiscordRPCManager : IPCListener { private val applicationID = 653443797182578707L private val updatePeriod = 4200L @@ -39,7 +39,7 @@ class DiscordRPCManager : IPCListener { private val DiscordLocationKey = DiscordLocationKey() - private fun start() { + fun start(fromCommand: Boolean = false) { coroutineScope.launch { try { if (isActive()) { @@ -55,9 +55,13 @@ class DiscordRPCManager : IPCListener { try { client?.connect() + if (fromCommand) LorenzUtils.chat("§a[SkyHanni] Successfully started Rich Presence!") // confirm that /shrpcstart worked } catch (ex: Exception) { consoleLog("Warn: Failed to connect to RPC!") consoleLog(ex.toString()) + LorenzUtils.clickableChat("§e[SkyHanni] Discord Rich Presence was unable to start! " + + "This usually happens when you join SkyBlock when Discord is not started. " + + "Please run /shrpcstart to retry once you have launched Discord.", "shrpcstart") } } catch (ex: Throwable) { consoleLog("Warn: Discord RPC has thrown an unexpected error while trying to start...") @@ -121,7 +125,7 @@ class DiscordRPCManager : IPCListener { }, 0, updatePeriod) } - override fun onClose(client: IPCClient, json: JsonObject) { + override fun onClose(client: IPCClient, json: JsonObject?) { consoleLog("Discord RPC closed.") this.client = null connected = false @@ -173,4 +177,23 @@ class DiscordRPCManager : IPCListener { fun onDisconnect(event: FMLNetworkEvent.ClientDisconnectionFromServerEvent) { stop() } + + fun startCommand() { + if (!config.enabled.get()) { + LorenzUtils.chat("§c[SkyHanni] Discord Rich Presence is disabled. Enable it in the config §e/sh discord") + return + } + + if (isActive()) { + LorenzUtils.chat("§e[SkyHanni] Discord Rich Presence is already active!") + return + } + + LorenzUtils.chat("§e[SkyHanni] Attempting to start Discord Rich Presence...") + try { + start(true) + } catch (e: Exception) { + LorenzUtils.chat("§c[SkyHanni] Unable to start Discord Rich Presence! Please report this on Discord and ping NetheriteMiner#6267.") + } + } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt index f76ea9dc4..fae6b5104 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt @@ -14,6 +14,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.colorCodeToRarity import at.hannibal2.skyhanni.utils.StringUtils.firstLetterUppercase import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import io.github.moulberry.notenoughupdates.miscfeatures.PetInfoOverlay.getCurrentPet import io.github.moulberry.notenoughupdates.util.SkyBlockTime import java.util.function.Supplier import java.util.regex.Pattern @@ -76,7 +77,7 @@ enum class DiscordStatus(private val displayMessageSupplier: Supplier<String>?) when (groups[item]) { "❤" -> statString = "❤${groups[item - 1]} " "❈ Defense" -> statString = "$statString❈${groups[item - 1]} " - "✎ Mana" -> statString = "$statString✎${groups[item - 1]} " + "✎" -> statString = "$statString✎${groups[item - 1]} " } } statString @@ -176,8 +177,9 @@ enum class DiscordStatus(private val displayMessageSupplier: Supplier<String>?) val pet = SkyHanniMod.feature.hidden.currentPet val colorCode = pet.substring(1..2).first() val petName = pet.substring(2) + val petLevel = getCurrentPet().petLevel.currentLevel - "${colorCodeToRarity(colorCode)} $petName" + "[Lvl $petLevel] ${colorCodeToRarity(colorCode)} $petName" }) ; @@ -187,4 +189,4 @@ enum class DiscordStatus(private val displayMessageSupplier: Supplier<String>?) } return "" } -}
\ No newline at end of file +} |