Add a DiscordRPC.kt feature
This commit is contained in:
		
							parent
							
								
									6f5817389d
								
							
						
					
					
						commit
						6552adbf70
					
				| @ -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 { | ||||
|  | ||||
| @ -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) | ||||
|     } | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user