Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ;openfolder command #233

Merged
merged 5 commits into from
Feb 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/main/kotlin/com/lambda/client/LambdaMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ class LambdaMod {

const val LAMBDA = "λ"

const val PLUGIN_PATH = "${DIRECTORY}plugins/"
const val PACKET_LOG_PATH = "${DIRECTORY}packet-logs/"
const val SONGS_PATH = "${DIRECTORY}songs/"

val LOG: Logger = LogManager.getLogger(NAME)

var ready: Boolean = false; private set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object LicenseCommand : ClientCommand(
) {
init {
execute {
MessageSendHelper.sendChatMessage("You can view Lambda's &7client&f License (LGPLv3) at &9https://lambda-client.org/license")
MessageSendHelper.sendChatMessage("You can view Lambda's &7client&f License (LGPLv3) at &9https://github.com/lambda-client/lambda/blob/master/LICENSE.md")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.lambda.client.command.commands

import com.lambda.client.command.ClientCommand
import com.lambda.client.util.FolderUtils

object OpenFolderCommand : ClientCommand(
name = "openfolder",
alias = arrayOf("of", "open"),
description = "Open any Lambda folder"
) {
init {
literal("lambda") {
execute {
FolderUtils.openFolder(FolderUtils.lambdaFolder)
}
}

literal("plugins") {
execute {
FolderUtils.openFolder(FolderUtils.pluginFolder)
}
}

literal("packetLogs") {
execute {
FolderUtils.openFolder(FolderUtils.packetLogFolder)
}
}

literal("songs") {
execute {
FolderUtils.openFolder(FolderUtils.songFolder)
}
}

literal("screenshots") {
execute {
FolderUtils.openFolder(FolderUtils.screenshotFolder)
}
}

literal("logs") {
execute {
FolderUtils.openFolder(FolderUtils.logFolder)
}
}

execute {
FolderUtils.openFolder(FolderUtils.lambdaFolder)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.lambda.client.command.commands

import com.lambda.client.LambdaMod
import com.lambda.client.command.ClientCommand
import com.lambda.client.plugin.PluginLoader
import com.lambda.client.plugin.PluginManager
import com.lambda.client.plugin.api.Plugin
import com.lambda.client.util.ConfigUtils
import com.lambda.client.util.FolderUtils
import com.lambda.client.util.text.MessageSendHelper
import com.lambda.client.util.text.formatValue
import java.io.File
Expand All @@ -19,7 +19,7 @@ object PluginCommand : ClientCommand(
string("jar name") { nameArg ->
execute {
val name = "${nameArg.value.removeSuffix(".jar")}.jar"
val file = File("${LambdaMod.PLUGIN_PATH}$name")
val file = File("${FolderUtils.pluginFolder}$name")

if (!file.exists()) {
MessageSendHelper.sendErrorMessage("${formatValue(name)} is not a valid jar file name!")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ object SearchCommand : ClientCommand(
val blockName = blockArg.value.registryName.toString()
addBlock(blockName)
}

}

execute("Add a block to search list") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.lambda.client.module.ModuleManager
import com.lambda.client.module.modules.client.ClickGUI
import com.lambda.client.plugin.PluginManager
import com.lambda.client.setting.ConfigManager
import com.lambda.client.util.FolderUtils
import com.lambda.client.util.math.Vec2f
import com.lambda.client.util.text.MessageSendHelper
import com.lambda.client.util.threads.defaultScope
Expand Down Expand Up @@ -233,7 +234,7 @@ object LambdaClickGui : AbstractLambdaGui<ModuleSettingWindow, AbstractModule>()
URL(remotePluginButton.downloadUrl).openStream().use { inputStream ->
Files.copy(
inputStream,
Paths.get("${LambdaMod.PLUGIN_PATH}/${remotePluginButton.fileName}"),
Paths.get("${FolderUtils.pluginFolder}/${remotePluginButton.fileName}"),
StandardCopyOption.REPLACE_EXISTING
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package com.lambda.client.gui.clickgui.component

import com.lambda.client.LambdaMod
import com.lambda.client.gui.rgui.component.BooleanSlider
import com.lambda.client.util.filesystem.FolderUtils
import com.lambda.client.util.FolderUtils
import com.lambda.client.util.math.Vec2f

object ImportPluginButton : BooleanSlider("Import...", 0.0, "Import plugins to Lambda") {
override fun onClick(mousePos: Vec2f, buttonId: Int) {
super.onClick(mousePos, buttonId)
if (buttonId == 0) FolderUtils.openFolder(LambdaMod.PLUGIN_PATH)
if (buttonId == 0) FolderUtils.openFolder(FolderUtils.pluginFolder)
}

override fun onRelease(mousePos: Vec2f, buttonId: Int) {
super.onRelease(mousePos, buttonId)
if (buttonId == 1) FolderUtils.openFolder(LambdaMod.PLUGIN_PATH)
if (buttonId == 1) FolderUtils.openFolder(FolderUtils.pluginFolder)
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.lambda.client.module.modules.misc

import com.lambda.client.LambdaMod
import com.lambda.client.event.SafeClientEvent
import com.lambda.client.event.events.PacketEvent
import com.lambda.client.event.events.RenderWorldEvent
import com.lambda.client.module.Category
import com.lambda.client.module.Module
import com.lambda.client.util.TickTimer
import com.lambda.client.util.TimeUnit
import com.lambda.client.util.FolderUtils
import com.lambda.client.util.text.MessageSendHelper
import com.lambda.client.util.threads.defaultScope
import com.lambda.client.util.threads.runSafe
Expand Down Expand Up @@ -106,7 +106,7 @@ object NoteBot : Module(

private fun loadSong() {
defaultScope.launch(Dispatchers.IO) {
val path = "${LambdaMod.SONGS_PATH}$songName"
val path = "${FolderUtils.songFolder}$songName"

try {
parse(path).let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.lambda.client.module.Category
import com.lambda.client.module.Module
import com.lambda.client.util.TickTimer
import com.lambda.client.util.TimeUnit
import com.lambda.client.util.FolderUtils
import com.lambda.client.util.text.MessageSendHelper
import com.lambda.client.util.threads.defaultScope
import com.lambda.client.util.threads.runSafe
Expand Down Expand Up @@ -76,7 +77,7 @@ object PacketLogger : Module(
write()

runSafe {
MessageSendHelper.sendChatMessage("$chatName Log saved at ${TextFormatting.GREEN}${LambdaMod.PACKET_LOG_PATH}${filename}")
MessageSendHelper.sendChatMessage("$chatName Log saved at ${TextFormatting.GREEN}${FolderUtils.packetLogFolder}${filename}")
}
}

Expand Down Expand Up @@ -735,11 +736,11 @@ object PacketLogger : Module(

defaultScope.launch(Dispatchers.IO) {
try {
with(File(LambdaMod.PACKET_LOG_PATH)) {
with(File(FolderUtils.packetLogFolder)) {
if (!exists()) mkdir()
}

FileWriter("${LambdaMod.PACKET_LOG_PATH}${filename}", true).buffered().use {
FileWriter("${FolderUtils.packetLogFolder}${filename}", true).buffered().use {
for (line in lines) it.write(line)
}
} catch (e: Exception) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/com/lambda/client/plugin/PluginManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.lambda.client.LambdaMod
import com.lambda.client.gui.clickgui.LambdaClickGui
import com.lambda.client.gui.clickgui.component.PluginButton
import com.lambda.client.plugin.api.Plugin
import com.lambda.client.util.FolderUtils
import com.lambda.client.util.text.MessageSendHelper
import com.lambda.commons.collections.NameableSet
import kotlinx.coroutines.Deferred
Expand All @@ -28,7 +29,7 @@ internal object PluginManager : AsyncLoader<List<PluginLoader>> {
}

fun getLoaders(): List<PluginLoader> {
val dir = File(LambdaMod.PLUGIN_PATH)
val dir = File(FolderUtils.pluginFolder)
if (!dir.exists()) dir.mkdir()

val files = dir.listFiles() ?: return emptyList()
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/lambda/client/util/ConfigUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ object ConfigUtils {
}
}

// TODO: Introduce a version helper for LambdaMod.BUILD_NUMBER for version-specific configs. This should be theoritically fine for now
// TODO: Introduce a version helper for LambdaMod.BUILD_NUMBER for version-specific configs. This should be theoretically fine for now
fun moveAllLegacyConfigs() {
moveLegacyConfig("lambda/generic.json", "lambda/generic.bak", GenericConfig)
moveLegacyConfig("lambda/modules/default.json", "lambda/modules/default.bak", ModuleConfig)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.lambda.client.util.filesystem
package com.lambda.client.util

import com.lambda.client.LambdaMod
import java.awt.Desktop
import java.io.File
import java.net.URL

object FolderUtils {
@JvmStatic
val minecraftFolder: String
get() = "${File("").absolutePath}${File.separator}"

@JvmStatic
val versionsFolder
get() = "${minecraftFolder}versions${File.separator}"
Expand All @@ -13,23 +18,42 @@ object FolderUtils {
val modsFolder
get() = "${minecraftFolder}mods${File.separator}"

/**
* The Minecraft folder specific to the current operating system
*/
private val minecraftFolder: String
get() = when (getOS()) {
OperatingSystem.UNIX -> System.getProperty("user.home") + "/.minecraft/"
OperatingSystem.OSX -> System.getProperty("user.home") + "/Library/Application Support/minecraft/"
OperatingSystem.WINDOWS -> System.getenv("APPDATA") + File.separator + ".minecraft" + File.separator
}
@JvmStatic
val logFolder
get() = "${minecraftFolder}logs${File.separator}"

@JvmStatic
val screenshotFolder
get() = "${minecraftFolder}screenshots${File.separator}"

@JvmStatic
val lambdaFolder
get() = "$minecraftFolder${LambdaMod.DIRECTORY}${File.separator}"

@JvmStatic
val pluginFolder
get() = "${lambdaFolder}plugins${File.separator}"

@JvmStatic
val packetLogFolder
get() = "${lambdaFolder}packet-logs${File.separator}"

@JvmStatic
val songFolder
get() = "${lambdaFolder}songs${File.separator}"

/**
* Opens the given folder using the right library based on OS
* Opens the given path using the right library based on OS
*/
fun openFolder(path: String) {
Thread {
if (getOS() == OperatingSystem.WINDOWS) Desktop.getDesktop().open(File(path))
else Runtime.getRuntime().exec(getURLOpenCommand(File(path).toURI().toURL()))
val file = File(path)
if (!file.exists()) file.mkdir()
if (getOS() == OperatingSystem.WINDOWS) {
Desktop.getDesktop().open(file)
} else {
Runtime.getRuntime().exec(getURLOpenCommand(file.toURI().toURL()))
}
}.start()
}

Expand Down Expand Up @@ -62,7 +86,7 @@ object FolderUtils {
}
}

private enum class OperatingSystem {
enum class OperatingSystem {
UNIX, OSX, WINDOWS
}
}