Add a DiscordRPC.kt feature

This commit is contained in:
Username404 2021-05-27 20:00:35 +02:00
parent 6f5817389d
commit 6552adbf70
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
2 changed files with 30 additions and 2 deletions

View File

@ -52,8 +52,9 @@ subprojects {
"$kotlinX:kotlinx-datetime:0.2.1",
"com.typesafe:config:1.4.1",
"io.github.config4k:config4k:0.4.2",
"org.jetbrains:annotations:20.1.0"
).forEach { implementation(it); shadowC(it) { isTransitive = false; } }
"org.jetbrains:annotations:20.1.0",
"com.github.Vatuu:discord-rpc:1.6.2"
).forEach { implementation(it); shadowC(it) { isTransitive = false; exclude("com.sun.jna") } }
"minecraft"("com.mojang:minecraft:${rootProject.property("minecraft")}")
"mappings"(mappingsDep)
}
@ -73,6 +74,7 @@ subprojects {
relocate("com.typesafe.config", "${rootProject.group}.typesafe.config")
relocate("io.github.config4k", "${rootProject.group}.config4k")
relocate("net.arikia.dev.drpc", "${rootProject.group}.drpc")
exclude("com/sun/jna/**/*") // The shadowed JNA from discord-rpc isn't needed since it is already available at runtime
exclude("**/*.kotlin_metadata")
exclude("**/*.kotlin_builtins")
exclude("META-INF/maven/**/*")
@ -99,6 +101,9 @@ subprojects {
adaptclassstrings()
"$group.**".also { dontnote(it); dontwarn(it) }
// Required for discord-rpc
keep("class $group.drpc.** { public * ; }")
dontwarn("kotlinx.serialization.**")
doFirst {

View File

@ -0,0 +1,23 @@
package fr.username404.snowygui.gui.feature
import net.arikia.dev.drpc.DiscordRichPresence
import net.minecraft.client.Minecraft
import fr.username404.snowygui.gui.feature.ButtonInfo.Companion.Type
import net.arikia.dev.drpc.DiscordEventHandlers
import net.arikia.dev.drpc.DiscordRPC as discord_rpc
@ButtonInfo(Category.MISC, kind = Type.TOGGLE)
object DiscordRPC: ButtonImpl() {
private val RPCHandlers: DiscordEventHandlers = DiscordEventHandlers.Builder().build()
private val RichPresence: DiscordRichPresence.Builder = DiscordRichPresence
.Builder("Playing Minecraft ${Minecraft.getInstance().game.version.name} (${Minecraft.getInstance().launchedVersion})")
.setBigImage("icon", "SnowyGUI")
override fun execAction() {
if (toggled) discord_rpc.discordUpdatePresence(RichPresence.build())
else discord_rpc.discordClearPresence()
}
init {
Runtime.getRuntime().addShutdownHook(Thread { discord_rpc.discordShutdown() })
discord_rpc.discordInitialize("839058922102849538", RPCHandlers, true)
}
}