Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3
Events rehaul#16
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
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Events rehaul #16
Changes from all commits
80a4731b67f31c969ad0324080293524629fceb00b902996f92715724894dde2c98a1cddc17e62448a5ee681fd05880019405274ec9041f2f05586379629642ae3316bbce33555a45378d3a8d4dc9e582e3ab81a3ede5a0eceafc1ce85a9000525ce3ef5d799311f8cfd51bb8a5b8f8355f40b51c6bbbdb7e18eb3774d6d0b03213File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -52,6 +52,9 @@ dependencies { | ||
| testImplementation("org.junit.jupiter:junit-jupiter:5.12.2") | ||
| testImplementation("org.mockbukkit.mockbukkit:mockbukkit-v1.21:4.45.1") | ||
| testImplementation("org.mockito.kotlin:mockito-kotlin:5.4.0") | ||
| // TODO check if needed | ||
| implementation("com.google.guava:guava:32.0.1-jre") | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @blockarchitech said not to use guava, he should also comment here | ||
| } | ||
| val targetJavaVersion = 21 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -17,6 +17,7 @@ package dev.znci.rocket.commands | ||
| import dev.znci.rocket.i18n.LocaleManager | ||
| import dev.znci.rocket.scripting.ScriptManager | ||
| import dev.znci.rocket.scripting.ScriptManager.disableFile | ||
| import dev.znci.rocket.scripting.ScriptManager.scriptsFolder | ||
| import org.bukkit.command.Command | ||
| import org.bukkit.command.CommandSender | ||
| @@ -32,7 +33,8 @@ class RocketCommand(private val plugin: JavaPlugin) : TabExecutor { | ||
| } | ||
| val action = args[0].lowercase() | ||
| val scriptName = if (!args[1].endsWith(".lua")) "${args[1]}.lua" else args[1] | ||
| val scriptName = args[1] | ||
| val rawScriptName = if (!scriptName.endsWith(".lua")) "${scriptName}.lua" else scriptName | ||
| if (!scriptsFolder.exists() || !scriptsFolder.isDirectory) { | ||
| sender.sendMessage(LocaleManager.getMessageAsComponent("rocket_command.scripts_folder_not_found")) | ||
| @@ -41,7 +43,7 @@ class RocketCommand(private val plugin: JavaPlugin) : TabExecutor { | ||
| when (action) { | ||
| "reload" -> { | ||
| if (scriptName.lowercase() == "config.lua") { | ||
| if (scriptName.lowercase() == "config") { | ||
| plugin.reloadConfig() | ||
| val defaultLocale = plugin.config.getString("locale", "en_GB").toString() | ||
| @@ -51,36 +53,49 @@ class RocketCommand(private val plugin: JavaPlugin) : TabExecutor { | ||
| sender.sendMessage(LocaleManager.getMessageAsComponent("rocket_command.config_reloaded")) | ||
| return true | ||
| } else if (scriptName.lowercase() == "all") { | ||
| val results = ScriptManager.loadAll() | ||
| if (results.isNotEmpty()) { | ||
| results.forEach { error -> | ||
| sender.sendMessage(LocaleManager.getMessageAsComponent("generic_error", error ?: "Unknown error")) | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zNotChill - we need better error handling 🙂 Want to open a ticket for that? Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
On my new branch (not yet published), I have already mostly done this. Anywhere you use a RocketError will now work, whereas before it would not, and it would just produce a | ||
| } | ||
| } | ||
| return true | ||
| } | ||
| val scriptFile = File(scriptsFolder, scriptName) | ||
| val scriptFile = File(scriptsFolder, rawScriptName) | ||
| if (!scriptFile.exists()) { | ||
| sender.sendMessage(LocaleManager.getMessageAsComponent("rocket_command.script_not_found", scriptName)) | ||
| sender.sendMessage(LocaleManager.getMessageAsComponent("rocket_command.script_not_found", rawScriptName)) | ||
| return true | ||
| } | ||
| val content = scriptFile.readText() | ||
| val result = ScriptManager.runScript(content) | ||
| val result = ScriptManager.loadScript(scriptFile) | ||
| if (result !== "") { | ||
| sender.sendMessage(LocaleManager.getMessageAsComponent("generic_error", result ?: "Unknown error")) | ||
| } else { | ||
| sender.sendMessage( | ||
| LocaleManager.getMessageAsComponent( | ||
| "rocket_command.script_reloaded", | ||
| scriptName | ||
| rawScriptName | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
| "disable" -> { | ||
| val scriptFile = File(scriptsFolder, scriptName) | ||
| val scriptFile = File(scriptsFolder, rawScriptName) | ||
| if (!scriptFile.exists()) { | ||
| sender.sendMessage(LocaleManager.getMessageAsComponent("rocket_command.script_not_found", scriptName)) | ||
| sender.sendMessage(LocaleManager.getMessageAsComponent("rocket_command.script_not_found", rawScriptName)) | ||
| return true | ||
| } | ||
| sender.sendMessage(LocaleManager.getMessageAsComponent("rocket_command.script_disabled", scriptName)) | ||
| // TODO: Add disabling of file (with '-') | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you open a ticket for this? | ||
| // For another PR though | ||
| disableFile(scriptFile) | ||
| sender.sendMessage(LocaleManager.getMessageAsComponent("rocket_command.script_disabled", rawScriptName)) | ||
| } | ||
| else -> { | ||
| sender.sendMessage(LocaleManager.getMessageAsComponent("rocket_command.usage")) | ||
| @@ -99,9 +114,11 @@ class RocketCommand(private val plugin: JavaPlugin) : TabExecutor { | ||
| if (args.size == 1) { | ||
| return mutableListOf("reload", "disable") | ||
| } else if (args.size == 2) { | ||
| return if (args[0] == "reload") ScriptManager.getAllScripts().toMutableList() | ||
| else if (args[0] == "disable") ScriptManager.getAllScripts(false).toMutableList() | ||
| else null | ||
| val list: MutableList<String>? = | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There has to be a better way of doing commands. I really don't like this class. Could we use some sort of command library? Being said, this is scope creep 🙂 | ||
| if (args[0] == "reload") ScriptManager.getAllScripts().toMutableList().also { it.add("config") } | ||
| else if (args[0] == "disable") ScriptManager.getAllScripts(false).toMutableList().also { it.add("config") } | ||
| else null | ||
| return list | ||
| } | ||
| return null | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think guava is a welcome addition but I see not usages of it here.