Skip to content

Commit

Permalink
LEGACY: KillAura, Auto/LocalSettings, StaffDetector, Velocity Updates (
Browse files Browse the repository at this point in the history
…CCBlueX#3029)

- Fixed Killaura Switch mode, for temporary fixes, it will skip new target if the target is not hittable. (Closes CCBlueX#2811)
- Fixed Killaura SwitchDelay, now should be working.
- Fixed Velocity SmoothReverse (Speed stuck).
- Optimized StaffDetector retrieving staff list, and now it should run on start.
- Optimized AutoSettings & LocalSettings Command, now should load online config slightly faster & optimize.
- Optimized ClickGui Online Config Loading, using async.
- Tweaked LocalSettings Command to save `all` by default.
- Added LocalSettings TABComplete for saving local config, which is `all`, `values`, `binds`, and `states`. (default = all)
- Improved Killaura onDestroyBlock & onScaffold Checks, properly handle checks of f*cker & scaffold module.
  • Loading branch information
EclipsesDev authored May 16, 2024
1 parent f425062 commit 4af25fd
Show file tree
Hide file tree
Showing 8 changed files with 344 additions and 285 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package net.ccbluex.liquidbounce.features.command.commands

import kotlinx.coroutines.*
import net.ccbluex.liquidbounce.LiquidBounce
import net.ccbluex.liquidbounce.api.ClientApi
import net.ccbluex.liquidbounce.api.Status
Expand All @@ -19,9 +20,9 @@ import net.ccbluex.liquidbounce.utils.misc.HttpUtils.get
import net.ccbluex.liquidbounce.utils.misc.StringUtils
import java.awt.Toolkit
import java.awt.datatransfer.StringSelection
import kotlin.concurrent.thread

object AutoSettingsCommand : Command("autosettings", "autosetting", "settings", "setting", "config") {

/**
* Execute commands with provided [args]
*/
Expand All @@ -30,119 +31,122 @@ object AutoSettingsCommand : Command("autosettings", "autosetting", "settings",

if (args.size <= 1) {
chatSyntax("$usedAlias <load/list/upload/report>")

return
}

when (args[1].lowercase()) {
// Load subcommand
"load" -> {
if (args.size < 3) {
chatSyntax("$usedAlias load <name/url>")
return
}

thread {
runCatching {
chat("Loading settings...")

// Load settings and apply them
val settings = if (args[2].startsWith("http")) {
val (text, code) = get(args[2])
if (code != 200) {
error(text)
}
GlobalScope.launch {
when (args[1].lowercase()) {
"load" -> loadSettings(args)
"report" -> reportSettings(args)
"upload" -> uploadSettings(args)
"list" -> listSettings()
else -> chatSyntax("$usedAlias <load/list/upload/report>")
}
}
}

text
} else {
ClientApi.requestSettingsScript(args[2])
}
// Load subcommand
private suspend fun loadSettings(args: Array<String>) {
withContext(Dispatchers.IO) {
if (args.size < 3) {
chatSyntax("${args[0].lowercase()} load <name/url>")
return@withContext
}

chat("Applying settings...")
SettingsUtils.applyScript(settings)
}.onSuccess {
chat("§6Settings applied successfully")
addNotification(Notification("Updated Settings"))
playEdit()
}.onFailure {
LOGGER.error("Failed to load settings", it)
chat("Failed to load settings: ${it.message}")
try {
val settings = if (args[2].startsWith("http")) {
val (text, code) = get(args[2])
if (code != 200) {
error(text)
}
}
}

// Report subcommand
"report" -> {
if (args.size < 3) {
chatSyntax("$usedAlias report <name>")
return
text
} else {
ClientApi.requestSettingsScript(args[2])
}

thread {
runCatching {
val response = ClientApi.reportSettings(args[2])
chat("Applying settings...")
SettingsUtils.applyScript(settings)
chat("§6Settings applied successfully")
addNotification(Notification("Updated Settings"))
playEdit()
} catch (e: Exception) {
LOGGER.error("Failed to load settings", e)
chat("Failed to load settings: ${e.message}")
}
}
}

when (response.status) {
Status.SUCCESS -> chat("§6${response.message}")
Status.ERROR -> chat("§c${response.message}")
}
}.onFailure {
LOGGER.error("Failed to report settings", it)
chat("Failed to report settings: ${it.message}")
}
}
// Report subcommand
private suspend fun reportSettings(args: Array<String>) {
withContext(Dispatchers.IO) {
if (args.size < 3) {
chatSyntax("${args[0].lowercase()} report <name>")
return@withContext
}

// Report subcommand
"upload" -> {
val option = if (args.size > 3) StringUtils.toCompleteString(args, 3).lowercase() else "values"
val all = "all" in option
val values = all || "values" in option
val binds = all || "binds" in option
val states = all || "states" in option

if (!values && !binds && !states) {
chatSyntax("$usedAlias upload [all/values/binds/states]...")
return
try {
val response = ClientApi.reportSettings(args[2])
when (response.status) {
Status.SUCCESS -> chat("§6${response.message}")
Status.ERROR -> chat("§c${response.message}")
}
} catch (e: Exception) {
LOGGER.error("Failed to report settings", e)
chat("Failed to report settings: ${e.message}")
}
}
}

// Upload subcommand
private suspend fun uploadSettings(args: Array<String>) {
withContext(Dispatchers.IO) {
val option = if (args.size > 3) StringUtils.toCompleteString(args, 3).lowercase() else "all"
val all = "all" in option
val values = all || "values" in option
val binds = all || "binds" in option
val states = all || "states" in option

if (!values && !binds && !states) {
chatSyntax("${args[0].lowercase()} upload [all/values/binds/states]...")
return@withContext
}

thread {
runCatching {
chat("§9Creating settings...")
val settingsScript = SettingsUtils.generateScript(values, binds, states)
chat("§9Uploading settings...")
try {
chat("§9Creating settings...")
val settingsScript = SettingsUtils.generateScript(values, binds, states)
chat("§9Uploading settings...")

val serverData = mc.currentServerData ?: error("You need to be on a server to upload settings.")
val serverData = mc.currentServerData ?: error("You need to be on a server to upload settings.")

val name = "${LiquidBounce.clientCommit}-${serverData.serverIP.replace(".", "_")}"
val response = ClientApi.uploadSettings(name, mc.session.username, settingsScript)
val name = "${LiquidBounce.clientCommit}-${serverData.serverIP.replace(".", "_")}"
val response = ClientApi.uploadSettings(name, mc.session.username, settingsScript)

when (response.status) {
Status.SUCCESS -> {
chat("§6${response.message}")
chat("§9Token: §6${response.token}")
when (response.status) {
Status.SUCCESS -> {
chat("§6${response.message}")
chat("§9Token: §6${response.token}")

// Store token in clipboard
val stringSelection = StringSelection(response.token)
Toolkit.getDefaultToolkit().systemClipboard.setContents(stringSelection, stringSelection)
}
Status.ERROR -> chat("§c${response.message}")
}
}.onFailure {
LOGGER.error("Failed to upload settings", it)
chat("Failed to upload settings: ${it.message}")
// Store token in clipboard
val stringSelection = StringSelection(response.token)
Toolkit.getDefaultToolkit().systemClipboard.setContents(stringSelection, stringSelection)
}
Status.ERROR -> chat("§c${response.message}")
}
} catch (e: Exception) {
LOGGER.error("Failed to upload settings", e)
chat("Failed to upload settings: ${e.message}")
}
}
}

// List subcommand
"list" -> {
chat("Loading settings...")

loadSettings(false) {
for (setting in it) {
chat("> ${setting.settingId} (Last updated: ${setting.date}, Status: ${setting.statusType.displayName})")
}
// List subcommand
private suspend fun listSettings() {
withContext(Dispatchers.IO) {
chat("Loading settings...")
loadSettings(false) {
for (setting in it) {
chat("> ${setting.settingId} (Last updated: ${setting.date}, Status: ${setting.statusType.displayName})")
}
}
}
Expand All @@ -156,16 +160,20 @@ object AutoSettingsCommand : Command("autosettings", "autosetting", "settings",
return when (args.size) {
1 -> listOf("list", "load", "upload", "report").filter { it.startsWith(args[0], true) }
2 -> {
if (args[0].equals("load", true) || args[0].equals("report", true)) {
if (autoSettingsList == null) {
loadSettings(true, 500) {}
}
when (args[0].lowercase()) {
"load", "report" -> {
if (autoSettingsList == null) {
loadSettings(true, 500) {}
}

if (autoSettingsList != null) {
return autoSettingsList!!.filter { it.settingId.startsWith(args[1], true) }.map { it.settingId }
return autoSettingsList?.filter { it.settingId.startsWith(args[1], true) }?.map { it.settingId }
?: emptyList()
}
"upload" -> {
return listOf("all", "values", "binds", "states").filter { it.startsWith(args[1], true) }
}
else -> emptyList()
}
return emptyList()
}
else -> emptyList()
}
Expand Down
Loading

0 comments on commit 4af25fd

Please sign in to comment.