diff --git a/src/main/kotlin/com/lambda/client/LambdaMod.kt b/src/main/kotlin/com/lambda/client/LambdaMod.kt index 3db31a672..46da0bbb8 100644 --- a/src/main/kotlin/com/lambda/client/LambdaMod.kt +++ b/src/main/kotlin/com/lambda/client/LambdaMod.kt @@ -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 diff --git a/src/main/kotlin/com/lambda/client/command/commands/LicenseCommand.kt b/src/main/kotlin/com/lambda/client/command/commands/LicenseCommand.kt index f54dfcbd0..a84736199 100644 --- a/src/main/kotlin/com/lambda/client/command/commands/LicenseCommand.kt +++ b/src/main/kotlin/com/lambda/client/command/commands/LicenseCommand.kt @@ -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") } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/command/commands/OpenFolderCommand.kt b/src/main/kotlin/com/lambda/client/command/commands/OpenFolderCommand.kt new file mode 100644 index 000000000..030b71f35 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/command/commands/OpenFolderCommand.kt @@ -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) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/command/commands/PluginCommand.kt b/src/main/kotlin/com/lambda/client/command/commands/PluginCommand.kt index cde713170..1745606fe 100644 --- a/src/main/kotlin/com/lambda/client/command/commands/PluginCommand.kt +++ b/src/main/kotlin/com/lambda/client/command/commands/PluginCommand.kt @@ -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 @@ -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!") diff --git a/src/main/kotlin/com/lambda/client/command/commands/SearchCommand.kt b/src/main/kotlin/com/lambda/client/command/commands/SearchCommand.kt index 0061b6664..dcde86644 100644 --- a/src/main/kotlin/com/lambda/client/command/commands/SearchCommand.kt +++ b/src/main/kotlin/com/lambda/client/command/commands/SearchCommand.kt @@ -20,7 +20,6 @@ object SearchCommand : ClientCommand( val blockName = blockArg.value.registryName.toString() addBlock(blockName) } - } execute("Add a block to search list") { diff --git a/src/main/kotlin/com/lambda/client/gui/clickgui/LambdaClickGui.kt b/src/main/kotlin/com/lambda/client/gui/clickgui/LambdaClickGui.kt index 9a9ef07a4..89b576ffb 100644 --- a/src/main/kotlin/com/lambda/client/gui/clickgui/LambdaClickGui.kt +++ b/src/main/kotlin/com/lambda/client/gui/clickgui/LambdaClickGui.kt @@ -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 @@ -233,7 +234,7 @@ object LambdaClickGui : AbstractLambdaGui() 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 ) } diff --git a/src/main/kotlin/com/lambda/client/gui/clickgui/component/ImportPluginButton.kt b/src/main/kotlin/com/lambda/client/gui/clickgui/component/ImportPluginButton.kt index c5aaf0919..b9cf57517 100644 --- a/src/main/kotlin/com/lambda/client/gui/clickgui/component/ImportPluginButton.kt +++ b/src/main/kotlin/com/lambda/client/gui/clickgui/component/ImportPluginButton.kt @@ -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) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/NoteBot.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/NoteBot.kt index 07f14f552..1e68c176d 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/NoteBot.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/NoteBot.kt @@ -1,6 +1,5 @@ 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 @@ -8,6 +7,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 @@ -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 { diff --git a/src/main/kotlin/com/lambda/client/module/modules/player/PacketLogger.kt b/src/main/kotlin/com/lambda/client/module/modules/player/PacketLogger.kt index 39b34de70..ff4e58052 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/player/PacketLogger.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/player/PacketLogger.kt @@ -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 @@ -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}") } } @@ -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) { diff --git a/src/main/kotlin/com/lambda/client/plugin/PluginManager.kt b/src/main/kotlin/com/lambda/client/plugin/PluginManager.kt index 444452582..14a305adf 100644 --- a/src/main/kotlin/com/lambda/client/plugin/PluginManager.kt +++ b/src/main/kotlin/com/lambda/client/plugin/PluginManager.kt @@ -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 @@ -28,7 +29,7 @@ internal object PluginManager : AsyncLoader> { } fun getLoaders(): List { - val dir = File(LambdaMod.PLUGIN_PATH) + val dir = File(FolderUtils.pluginFolder) if (!dir.exists()) dir.mkdir() val files = dir.listFiles() ?: return emptyList() diff --git a/src/main/kotlin/com/lambda/client/util/ConfigUtils.kt b/src/main/kotlin/com/lambda/client/util/ConfigUtils.kt index 392088d39..4af2a25ef 100644 --- a/src/main/kotlin/com/lambda/client/util/ConfigUtils.kt +++ b/src/main/kotlin/com/lambda/client/util/ConfigUtils.kt @@ -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) diff --git a/src/main/kotlin/com/lambda/client/util/filesystem/FolderUtils.kt b/src/main/kotlin/com/lambda/client/util/FolderUtils.kt similarity index 53% rename from src/main/kotlin/com/lambda/client/util/filesystem/FolderUtils.kt rename to src/main/kotlin/com/lambda/client/util/FolderUtils.kt index 9460cd039..3cbea595e 100644 --- a/src/main/kotlin/com/lambda/client/util/filesystem/FolderUtils.kt +++ b/src/main/kotlin/com/lambda/client/util/FolderUtils.kt @@ -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}" @@ -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() } @@ -62,7 +86,7 @@ object FolderUtils { } } - private enum class OperatingSystem { + enum class OperatingSystem { UNIX, OSX, WINDOWS } } \ No newline at end of file