Skip to content
This repository has been archived by the owner on Dec 24, 2023. It is now read-only.

Commit

Permalink
1.0.0
Browse files Browse the repository at this point in the history
update README to add more info
more features honestly i dont remember anymore lol
  • Loading branch information
Wyvest committed Aug 30, 2021
1 parent 65d07e4 commit a12009e
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 76 deletions.
Binary file added .github/img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/img_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/img_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/img_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
# SimpleRPC
### A simple Discord Rich Presence mod for Minecraft 1.8.9.

Made by W-OVERFLOW

#### Previews
![img.png](.github/img.png)
![img_2.png](.github/img_1.png)
![img_3.png](.github/img_3.png)
![img_2.png](.github/img_2.png)
11 changes: 9 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
id "org.jetbrains.kotlin.jvm" version "1.5.30"
}

version = "0.2.0"
version = "1.0.0"
group = "net.wyvest"
archivesBaseName = "SimpleRPC"

Expand Down Expand Up @@ -41,7 +41,7 @@ dependencies {
implementation ('xyz.matthewtgm:RequisiteLaunchwrapper:1.1')
implementation ('gg.essential:loader-launchwrapper:1.1.0')
provided 'gg.essential:essential-1.8.9-forge:1300'
include ('com.github.cbyrneee:KDiscordIPC:d589e4235b') {
include ('com.github.Wyvest:KDiscordIPC:1afa380307') {
transitive = false
}
include('com.google.code.gson:gson:2.8.8')
Expand Down Expand Up @@ -126,3 +126,10 @@ compileTestKotlin {
freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
}
}

sourceSets {
dummy
main {
compileClasspath += dummy.output
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.github.dediamondpro.hycord.options;

public class Settings {
public static boolean enableRP;
}
159 changes: 123 additions & 36 deletions src/main/kotlin/net/wyvest/simplerpc/SimpleRPC.kt
Original file line number Diff line number Diff line change
@@ -1,47 +1,92 @@
package net.wyvest.simplerpc

import dev.cbyrne.kdiscordipc.DiscordIPC
import dev.cbyrne.kdiscordipc.event.DiscordEvent
import dev.cbyrne.kdiscordipc.listener.IPCListener
import dev.cbyrne.kdiscordipc.presence.presence
import gg.essential.api.EssentialAPI
import gg.essential.api.utils.Multithreading
import io.github.dediamondpro.hycord.options.Settings
import net.minecraft.client.Minecraft
import net.minecraft.util.EnumChatFormatting
import net.minecraftforge.common.MinecraftForge.EVENT_BUS
import net.minecraftforge.fml.common.Mod
import net.minecraftforge.fml.common.event.FMLInitializationEvent
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent
import net.minecraftforge.fml.common.network.FMLNetworkEvent
import net.wyvest.simplerpc.commands.SimpleRPCCommand
import net.wyvest.simplerpc.config.RPCConfig
import net.wyvest.simplerpc.config.SimpleConfig
import net.wyvest.simplerpc.utils.Updater
import xyz.matthewtgm.requisite.util.ChatHelper
import xyz.matthewtgm.requisite.util.ForgeHelper
import java.awt.event.ActionListener
import java.io.File
import javax.swing.Timer
import kotlin.math.floor


@Mod(name = SimpleRPC.NAME, modid = SimpleRPC.ID, version = SimpleRPC.VERSION, modLanguageAdapter = "gg.essential.api.utils.KotlinAdapter")
@Mod(
name = SimpleRPC.NAME,
modid = SimpleRPC.ID,
version = SimpleRPC.VERSION,
modLanguageAdapter = "gg.essential.api.utils.KotlinAdapter"
)
object SimpleRPC {
private var disconnectedHypixel = false
const val NAME = "SimpleRPC"
const val VERSION = "0.2.0"
const val VERSION = "1.0.0"
const val ID = "simplerpc"
val mc: Minecraft
get() = Minecraft.getMinecraft()

fun sendMessage(message: String?) {
ChatHelper.sendMessage(EnumChatFormatting.DARK_PURPLE.toString() + "[$NAME] ", message)
}

lateinit var jarFile: File
val modDir = File(File(File(mc.mcDataDir, "config"), "Wyvest"), NAME)
private val ipc = DiscordIPC("862536466793103411")
private val regex = Regex("§[a-z0-9]")
val ipc = DiscordIPC("862536466793103411")
private var secondsPassed = 0
private var timerTask = ActionListener {
secondsPassed += 1
ipc.presence = presence {
state = "Playing Minecraft 1.8.9"
details = calculateTime()
if (SimpleConfig.showImage) {
details = if (RPCConfig.showDetails) {
val newDetails = when (RPCConfig.details) {
0 -> calculateTime()
1 -> if (mc.currentServerData == null) {
null
} else {
"Playing on ${mc.currentServerData.serverIP}"
}
2 -> if (mc.thePlayer == null) {
null
} else {
"Playing as ${mc.thePlayer.name}"
}
3 -> "Holding ${getCurrentItem()}"
4 -> if (mc.netHandler == null) {
null
} else {
"Fighting ${
if (mc.netHandler.playerInfoMap.isEmpty()) {
0
} else {
mc.netHandler.playerInfoMap.size - 1
}
} other players."
}
else -> null
}
if ((newDetails == null) || (newDetails.length >= 128)) {
null
} else {
newDetails
}
} else {
null
}
if (RPCConfig.showImage) {
largeImageKey = "grass_side"
largeImageText = "Powered by SimpleRPC!"
} else {
Expand All @@ -51,6 +96,7 @@ object SimpleRPC {
}
}
private var timer = Timer(1000, timerTask)
private var hycordDetected = false

@Mod.EventHandler
private fun onFMLPreInitialization(event: FMLPreInitializationEvent) {
Expand All @@ -60,50 +106,91 @@ object SimpleRPC {

@Mod.EventHandler
fun onFMLInitialization(event: FMLInitializationEvent) {
SimpleConfig.initialize()
//AdvancedConfig.initialize()
RPCConfig.initialize()
RPCConfig.preload()
SimpleRPCCommand.register()
Updater.update()
Multithreading.runAsync {
if (RPCConfig.toggled) {
ipc.presence = presence {
state = "Playing Minecraft 1.8.9"
details = "00:00:00 elapsed."
if (SimpleConfig.showImage) {
largeImageKey = "grass_side"
largeImageText = "Powered by SimpleRPC!"
} else {
largeImageKey = null
largeImageText = null
}
}

ipc.listener = object : IPCListener {
override fun onReadyEvent(event: DiscordEvent.Ready) {
println("${event.user} connecting...")
}
EVENT_BUS.register(this)
hycordDetected = ForgeHelper.isModLoaded("hycord")
if (RPCConfig.toggled) {
ipc.presence = presence {
state = "Playing Minecraft 1.8.9"
details = "00:00:00 elapsed."
if (RPCConfig.showImage) {
largeImageKey = "grass_side"
largeImageText = "Powered by SimpleRPC!"
} else {
largeImageKey = null
largeImageText = null
}

ipc.connect()
timer.start()
}

ipc.connect()
timer.start()
}
EssentialAPI.getShutdownHookUtil().register {
//we don't need to disconnect because somehow the IPC already disconnects
println("Shutting down timer task...")
println("Shutting down IPC and timer task...")
try {
ipc.disconnect()
} catch (_: Exception) {
println("The Discord IPC failed to shut down, this is likely due to the IPC already being stopped.")
}
try {
timer.stop()
} catch (e : Exception) {
} catch (_: Exception) {
println("The timer failed to shut down, this is likely due to the timer already being stopped.")
}
}
}

@SubscribeEvent
fun onServerJoin(e: TickEvent.ClientTickEvent) {
if (e.phase == TickEvent.Phase.START) {
if (EssentialAPI.getMinecraftUtil().isHypixel() && hycordDetected) {
if (Settings.enableRP && !disconnectedHypixel) {
try {
ipc.disconnect()
disconnectedHypixel = true
} catch (e: Exception) {
EssentialAPI.getNotifications().push("SimpleRPC", "There was a problem trying to disable SimpleRPC IPC.")
}
}
}
}
}

@SubscribeEvent
fun onServerLeave(e: FMLNetworkEvent.ClientDisconnectionFromServerEvent) {
if (disconnectedHypixel && hycordDetected) {
try {
ipc.connect()
disconnectedHypixel = false
} catch (e: Exception) {
EssentialAPI.getNotifications().push("SimpleRPC", "There was a problem trying to enable SimpleRPC IPC.")
}
}
}

private fun getCurrentItem(): String {
if (mc.thePlayer != null) {
if (mc.thePlayer.currentEquippedItem != null) {
if (mc.thePlayer.currentEquippedItem.displayName.replace(regex, "").trim().isNotEmpty()) {
return mc.thePlayer.currentEquippedItem.displayName.replace(regex, "")
}
}
}
return "nothing"
}

private fun calculateTime(): String {
val hours = floor((secondsPassed / 3600).toFloat()).toInt()
val minutes = floor(((secondsPassed - hours * 3600) / 60).toFloat()).toInt()
val seconds = secondsPassed - hours * 3600 - minutes * 60
return "${String.format("%02d", hours)}:${String.format("%02d", minutes)}:${String.format("%02d", seconds)} elapsed."
return "${String.format("%02d", hours)}:${String.format("%02d", minutes)}:${
String.format(
"%02d",
seconds
)
} elapsed"
}
}
4 changes: 0 additions & 4 deletions src/main/kotlin/net/wyvest/simplerpc/config/AdvancedConfig.kt

This file was deleted.

63 changes: 48 additions & 15 deletions src/main/kotlin/net/wyvest/simplerpc/config/RPCConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,49 @@ import net.wyvest.simplerpc.gui.DownloadConfirmGui
import net.wyvest.simplerpc.utils.Updater
import java.io.File

@Suppress("unused")
object RPCConfig : Vigilant(File(SimpleRPC.modDir, "${SimpleRPC.ID}.toml"), NAME) {

@Property(
type = PropertyType.SWITCH,
name = "Toggle Mod",
description = "Toggle the mod.\nRequires a restart of Minecraft.",
description = "Toggle the mod.\nCan be buggy and sometimes needs a restart to take effect.",
category = "General"
)
var toggled = true

@Property(
type = PropertyType.SWITCH,
name = "Automatically Turn Off Mod When HyCord",
description = "Automatically turn off SimpleRPC when HyCord is detected.",
category = "General"
)
var hycordDetect = true

@Property(
type = PropertyType.SWITCH,
name = "Show Details",
description = "Show the details of the RPC.",
category = "General"
)
var showDetails = true

@Property(
type = PropertyType.SELECTOR,
name = "RPC Mode",
description = "Choose the mode of the RPC.",
name = "Select Details",
description = "Select the type of detail for the RPC.",
category = "General",
options = ["Simple", "Advanced"]
options = ["Time Elapsed", "Current Server", "Current User", "Current Item Held", "Current Amount of Players"]
)
var mode = 0
var details = 0

@Property(
type = PropertyType.BUTTON,
name = "Access Options",
description = "Click the button to access the settings.",
type = PropertyType.SWITCH,
name = "Show Image",
description = "Show the image for the RPC.",
category = "General"
)
fun access() {
if (mode == 0) {
EssentialAPI.getGuiUtil().openScreen(SimpleConfig.gui())
} else {
EssentialAPI.getNotifications().push("SimpleRPC", "Advanced has not been implemented yet :(")
}
}
var showImage = true

@Property(
type = PropertyType.SWITCH,
Expand All @@ -63,4 +74,26 @@ object RPCConfig : Vigilant(File(SimpleRPC.modDir, "${SimpleRPC.ID}.toml"), NAME
.openScreen(DownloadConfirmGui(mc.currentScreen)) else EssentialAPI.getNotifications()
.push(NAME, "No update had been detected at startup, and thus the update GUI has not been shown.")
}

init {
initialize()
registerListener("toggled") {
isToggled: Boolean ->
run {
if (isToggled) {
try {
SimpleRPC.ipc.connect()
} catch (e: Exception) {
EssentialAPI.getNotifications().push("SimpleRPC", "There was an error trying to reconnect to the IPC. Please restart your game for your changes to take effect.")
}
} else {
try {
SimpleRPC.ipc.disconnect()
} catch (e: Exception) {
EssentialAPI.getNotifications().push("SimpleRPC", "There was an error trying to disconnect to the IPC. Please restart your game for your changes to take effect.")
}
}
}
}
}
}
19 changes: 0 additions & 19 deletions src/main/kotlin/net/wyvest/simplerpc/config/SimpleConfig.kt

This file was deleted.

0 comments on commit a12009e

Please sign in to comment.