From a5861de2da48bfc5544d21302f4fe4b4f871728b Mon Sep 17 00:00:00 2001 From: mfnalex Date: Thu, 15 Feb 2024 18:27:55 +0100 Subject: [PATCH 1/7] removed command alias (shall be configurable) --- .../spigotbasics/core/permission/CorePermissions.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/src/main/kotlin/com/github/spigotbasics/core/permission/CorePermissions.kt b/core/src/main/kotlin/com/github/spigotbasics/core/permission/CorePermissions.kt index 64d664eb..d2fc54d8 100644 --- a/core/src/main/kotlin/com/github/spigotbasics/core/permission/CorePermissions.kt +++ b/core/src/main/kotlin/com/github/spigotbasics/core/permission/CorePermissions.kt @@ -1,8 +1,12 @@ package com.github.spigotbasics.core.permission -class CorePermissions(private val permissionManager: BasicsPermissionManager) { +import com.github.spigotbasics.core.logger.BasicsLoggerFactory + +object CorePermissions { + private val pm = BasicsPermissionManager(BasicsLoggerFactory.getCoreLogger(CorePermissions::class)) + val useSelectors = - permissionManager.createSimplePermission( + pm.createSimplePermission( "basics.selectors", "Allows using selectors (@p, etc)", ) From 8335938a395a85b9861c59e54db878f631b534ae Mon Sep 17 00:00:00 2001 From: mfnalex Date: Thu, 15 Feb 2024 18:28:13 +0100 Subject: [PATCH 2/7] removed command alias (shall be configurable) --- .../modules/basicsworkbench/BasicsWorkbenchModule.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/basics-workbench/src/main/kotlin/com/github/spigotbasics/modules/basicsworkbench/BasicsWorkbenchModule.kt b/modules/basics-workbench/src/main/kotlin/com/github/spigotbasics/modules/basicsworkbench/BasicsWorkbenchModule.kt index 1c417270..ca30d663 100644 --- a/modules/basics-workbench/src/main/kotlin/com/github/spigotbasics/modules/basicsworkbench/BasicsWorkbenchModule.kt +++ b/modules/basics-workbench/src/main/kotlin/com/github/spigotbasics/modules/basicsworkbench/BasicsWorkbenchModule.kt @@ -54,7 +54,7 @@ class BasicsWorkbenchModule(context: ModuleInstantiationContext) : AbstractBasic override fun onEnable() { commandFactory.rawCommandBuilder("craftingtable", permissionCraftingTable) .description("Opens a crafting table") - .aliases(listOf("workbench")) +// .aliases(listOf("workbench")) .executor(WorkbenchExecutor()) .register() From 04becaef2184681d28a377a190fe8bddbd5cfc35 Mon Sep 17 00:00:00 2001 From: mfnalex Date: Thu, 15 Feb 2024 18:32:39 +0100 Subject: [PATCH 3/7] Auto stash before rebase of "refs/heads/main" --- .../spigotbasics/core/command/parsed/arguments/PlayersArg.kt | 3 ++- .../kotlin/com/github/spigotbasics/plugin/BasicsPluginImpl.kt | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/arguments/PlayersArg.kt b/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/arguments/PlayersArg.kt index c3278a38..508d872e 100644 --- a/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/arguments/PlayersArg.kt +++ b/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/arguments/PlayersArg.kt @@ -5,6 +5,7 @@ import com.github.spigotbasics.common.leftOrNull import com.github.spigotbasics.core.Basics import com.github.spigotbasics.core.extensions.partialMatches import com.github.spigotbasics.core.messages.Message +import com.github.spigotbasics.core.permission.CorePermissions import org.bukkit.Bukkit import org.bukkit.command.CommandSender import org.bukkit.entity.Player @@ -16,7 +17,7 @@ class PlayersArg(name: String) : CommandArgument>(name) { SELECTOR_INCUDES_ENTITIES, } - private val selectorPermission = Basics.permissions.useSelectors + private val selectorPermission = CorePermissions.useSelectors override fun parse( sender: CommandSender, diff --git a/plugin/src/main/kotlin/com/github/spigotbasics/plugin/BasicsPluginImpl.kt b/plugin/src/main/kotlin/com/github/spigotbasics/plugin/BasicsPluginImpl.kt index f9f98d4c..c1aad393 100644 --- a/plugin/src/main/kotlin/com/github/spigotbasics/plugin/BasicsPluginImpl.kt +++ b/plugin/src/main/kotlin/com/github/spigotbasics/plugin/BasicsPluginImpl.kt @@ -18,7 +18,6 @@ import com.github.spigotbasics.core.messages.CoreMessages import com.github.spigotbasics.core.messages.MessageFactory import com.github.spigotbasics.core.messages.tags.TagResolverFactory import com.github.spigotbasics.core.module.manager.ModuleManager -import com.github.spigotbasics.core.permission.BasicsPermissionManager import com.github.spigotbasics.core.permission.CorePermissions import com.github.spigotbasics.core.playerdata.CorePlayerData import com.github.spigotbasics.core.playerdata.CorePlayerDataListener @@ -50,7 +49,7 @@ class BasicsPluginImpl : JavaPlugin(), BasicsPlugin { private val logger = BasicsLoggerFactory.getCoreLogger(this::class) - override val permissions = CorePermissions(BasicsPermissionManager(logger)) + override val permissions = CorePermissions override val moduleFolder = File(dataFolder, "modules") override val moduleManager = ModuleManager(this, server, moduleFolder) override val tagResolverFactory: TagResolverFactory = TagResolverFactory(facade) From 69d238f72d06aa104ec0ea0e6c718abacbc85a80 Mon Sep 17 00:00:00 2001 From: mfnalex Date: Thu, 15 Feb 2024 18:51:09 +0100 Subject: [PATCH 4/7] fixed typo in PlayersArg.ErrorType.SELECTOR_INCLUDES_ENTITIES --- .../core/command/parsed/arguments/PlayersArg.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/arguments/PlayersArg.kt b/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/arguments/PlayersArg.kt index 508d872e..404a78bb 100644 --- a/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/arguments/PlayersArg.kt +++ b/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/arguments/PlayersArg.kt @@ -14,7 +14,7 @@ class PlayersArg(name: String) : CommandArgument>(name) { private enum class ErrorType { NOT_FOUND, NO_PERMISSION_SELECTORS, - SELECTOR_INCUDES_ENTITIES, + SELECTOR_INCLUDES_ENTITIES, } private val selectorPermission = CorePermissions.useSelectors @@ -59,7 +59,7 @@ class PlayersArg(name: String) : CommandArgument>(name) { val selected = Bukkit.selectEntities(sender, value) val players = selected.filterIsInstance() if (selected.size != players.size) { - return Either.Left(ErrorType.SELECTOR_INCUDES_ENTITIES) + return Either.Left(ErrorType.SELECTOR_INCLUDES_ENTITIES) } if (players.isEmpty()) { return Either.Left(ErrorType.NOT_FOUND) @@ -74,7 +74,7 @@ class PlayersArg(name: String) : CommandArgument>(name) { return when (get(sender, value).leftOrNull()) { ErrorType.NOT_FOUND -> Basics.messages.playerNotFound(value) ErrorType.NO_PERMISSION_SELECTORS -> Basics.messages.noPermission(selectorPermission) - ErrorType.SELECTOR_INCUDES_ENTITIES -> Basics.messages.selectorIncludesEntities(value) + ErrorType.SELECTOR_INCLUDES_ENTITIES -> Basics.messages.selectorIncludesEntities(value) else -> super.errorMessage(sender, value) } } From a2c7b7760b9f30a3903b6bd10f5ef1086c3598a0 Mon Sep 17 00:00:00 2001 From: mfnalex Date: Thu, 15 Feb 2024 19:29:14 +0100 Subject: [PATCH 5/7] Adds CommandContextExecutors for each ArgumentPath --- .../core/command/parsed/ArgumentPath.kt | 1 + .../command/parsed/ParsedCommandExecutor.kt | 7 ++++-- .../ArgumentPathBuilder.kt | 4 +++ .../GenericArgumentPathBuilder.kt | 2 ++ .../MapArgumentPathBuilder.kt | 4 ++- .../commandbuilder/ParsedCommandBuilder.kt | 2 +- .../modules/basicscore/BasicsCoreModule.kt | 25 +++++++++++++++++-- .../basicscore/DebugFallbackExecutor.kt | 11 ++++++++ .../basicscore/PrintPermissionsCommand.kt | 13 ++++++++++ .../spigotbasics/plugin/BasicsPluginImpl.kt | 2 +- plugin/src/main/resources/plugin.yml | 8 +++--- 11 files changed, 68 insertions(+), 11 deletions(-) create mode 100644 modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/DebugFallbackExecutor.kt create mode 100644 modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/PrintPermissionsCommand.kt diff --git a/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/ArgumentPath.kt b/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/ArgumentPath.kt index 14ff9c80..5de8b2ed 100644 --- a/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/ArgumentPath.kt +++ b/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/ArgumentPath.kt @@ -16,6 +16,7 @@ class ArgumentPath( val arguments: List>>, val permission: List = emptyList(), private val contextBuilder: (Map) -> T, + val ownExecutor: CommandContextExecutor? = null, ) { companion object { val logger = BasicsLoggerFactory.getCoreLogger(ArgumentPath::class) diff --git a/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/ParsedCommandExecutor.kt b/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/ParsedCommandExecutor.kt index 43d6bbe5..a0ebb3a9 100644 --- a/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/ParsedCommandExecutor.kt +++ b/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/ParsedCommandExecutor.kt @@ -9,7 +9,7 @@ import org.bukkit.command.CommandSender import org.bukkit.permissions.Permission class ParsedCommandExecutor( - private val executor: CommandContextExecutor, + private val executor: CommandContextExecutor?, private val paths: List>, ) { companion object { @@ -78,7 +78,10 @@ class ParsedCommandExecutor( when (val result = path.parse(sender, input)) { is ParseResult.Success -> { logger.debug(10, "Path.parse == ParseResult.Success: $result") - executor.execute(sender, result.context) + + val actualExecutor = path.ownExecutor ?: executor ?: error("No executor found for path: $path") + + actualExecutor.execute(sender, result.context) // logger.debug(10,"Command executed successfully.") logger.debug(10, "Command executed successfully.") return Either.Left(CommandResult.SUCCESS) diff --git a/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/dsl/argumentpathbuilder/ArgumentPathBuilder.kt b/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/dsl/argumentpathbuilder/ArgumentPathBuilder.kt index 78c16f97..5fb97a8b 100644 --- a/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/dsl/argumentpathbuilder/ArgumentPathBuilder.kt +++ b/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/dsl/argumentpathbuilder/ArgumentPathBuilder.kt @@ -2,6 +2,7 @@ package com.github.spigotbasics.core.command.parsed.dsl.argumentpathbuilder import com.github.spigotbasics.core.command.parsed.AnySender import com.github.spigotbasics.core.command.parsed.ArgumentPath +import com.github.spigotbasics.core.command.parsed.CommandContextExecutor import com.github.spigotbasics.core.command.parsed.PlayerSender import com.github.spigotbasics.core.command.parsed.SenderType import com.github.spigotbasics.core.command.parsed.arguments.CommandArgument @@ -13,6 +14,7 @@ abstract class ArgumentPathBuilder { protected var senderType: SenderType<*> = AnySender protected var arguments = emptyList>>() protected var permissions = emptyList() + protected var pathExecutor: CommandContextExecutor? = null private fun senderType(senderType: SenderType<*>) = apply { this.senderType = senderType } @@ -29,5 +31,7 @@ abstract class ArgumentPathBuilder { this.arguments = argumentBuilder.build() } + fun executor(pathExecutor: CommandContextExecutor) = apply { this.pathExecutor = pathExecutor } + abstract fun build(): ArgumentPath } diff --git a/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/dsl/argumentpathbuilder/GenericArgumentPathBuilder.kt b/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/dsl/argumentpathbuilder/GenericArgumentPathBuilder.kt index b41aad8a..b72c6edb 100644 --- a/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/dsl/argumentpathbuilder/GenericArgumentPathBuilder.kt +++ b/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/dsl/argumentpathbuilder/GenericArgumentPathBuilder.kt @@ -1,6 +1,7 @@ package com.github.spigotbasics.core.command.parsed.dsl.argumentpathbuilder import com.github.spigotbasics.core.command.parsed.ArgumentPath +import com.github.spigotbasics.core.command.parsed.CommandContextExecutor import com.github.spigotbasics.core.command.parsed.context.CommandContext class GenericArgumentPathBuilder : ArgumentPathBuilder() { @@ -14,5 +15,6 @@ class GenericArgumentPathBuilder : ArgumentPathBuilder() arguments, permissions, contextBuilder ?: error("Context builder not set"), + pathExecutor ) } diff --git a/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/dsl/argumentpathbuilder/MapArgumentPathBuilder.kt b/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/dsl/argumentpathbuilder/MapArgumentPathBuilder.kt index 21cfd756..81a071eb 100644 --- a/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/dsl/argumentpathbuilder/MapArgumentPathBuilder.kt +++ b/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/dsl/argumentpathbuilder/MapArgumentPathBuilder.kt @@ -9,5 +9,7 @@ class MapArgumentPathBuilder : ArgumentPathBuilder() { senderType, arguments, permissions, - ) { args -> MapContext(args) } + { args -> MapContext(args) }, + pathExecutor, + ) } diff --git a/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/dsl/commandbuilder/ParsedCommandBuilder.kt b/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/dsl/commandbuilder/ParsedCommandBuilder.kt index 6f4482a2..dd47d9bb 100644 --- a/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/dsl/commandbuilder/ParsedCommandBuilder.kt +++ b/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/dsl/commandbuilder/ParsedCommandBuilder.kt @@ -87,7 +87,7 @@ open class ParsedCommandBuilder( fun build(): BasicsCommand { val command = ParsedCommandExecutor( - parsedExecutor ?: error("parsedExecutor must be set"), + parsedExecutor, // ?: error("parsedExecutor must be set"), argumentPaths, ) val actualExecutor = createActualExecutor(command) diff --git a/modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/BasicsCoreModule.kt b/modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/BasicsCoreModule.kt index 556ed944..fa3adc3c 100644 --- a/modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/BasicsCoreModule.kt +++ b/modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/BasicsCoreModule.kt @@ -5,15 +5,22 @@ import com.github.spigotbasics.core.module.loader.ModuleInstantiationContext import org.bukkit.permissions.PermissionDefault class BasicsCoreModule(context: ModuleInstantiationContext) : AbstractBasicsModule(context) { - val permission = + val modulePermission = permissionManager.createSimplePermission( "basics.admin.module", "Allows managing Basics modules", PermissionDefault.OP, ) + val debugPermission = + permissionManager.createSimplePermission( + "basics.admin.debug", + "Allows debugging Basics", + PermissionDefault.OP, + ) + override fun onEnable() { - commandFactory.parsedCommandBuilder("module", permission) + commandFactory.parsedCommandBuilder("module", modulePermission) .mapContext { usage = " [module]" @@ -92,5 +99,19 @@ class BasicsCoreModule(context: ModuleInstantiationContext) : AbstractBasicsModu } .executor(ModuleCommand(this)) .register() + + commandFactory.parsedCommandBuilder("basicsdebug", debugPermission) + .mapContext { + usage = "" + + path { + arguments { + sub("printpermissions") + } + executor(PrintPermissionsCommand()) + } + } + //.executor(DebugFallbackExecutor()) + .register() } } diff --git a/modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/DebugFallbackExecutor.kt b/modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/DebugFallbackExecutor.kt new file mode 100644 index 00000000..8d2cc962 --- /dev/null +++ b/modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/DebugFallbackExecutor.kt @@ -0,0 +1,11 @@ +package com.github.spigotbasics.modules.basicscore + +import com.github.spigotbasics.core.command.parsed.CommandContextExecutor +import com.github.spigotbasics.core.command.parsed.context.MapContext +import org.bukkit.command.CommandSender + +class DebugFallbackExecutor : CommandContextExecutor { + override fun execute(sender: CommandSender, context: MapContext) { + throw IllegalStateException("This command should never be executed") + } +} \ No newline at end of file diff --git a/modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/PrintPermissionsCommand.kt b/modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/PrintPermissionsCommand.kt new file mode 100644 index 00000000..e7ea08f9 --- /dev/null +++ b/modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/PrintPermissionsCommand.kt @@ -0,0 +1,13 @@ +package com.github.spigotbasics.modules.basicscore + +import com.github.spigotbasics.core.command.parsed.CommandContextExecutor +import com.github.spigotbasics.core.command.parsed.context.MapContext +import org.bukkit.command.CommandSender + +class PrintPermissionsCommand : CommandContextExecutor { + override fun execute(sender: CommandSender, context: MapContext) { + for(permission in sender.server.pluginManager.permissions.filter { it.name.startsWith("basics.") }.sortedBy { it.name }) { + sender.sendMessage(permission.name + " - " + permission.description + " - " + permission.default.toString()) + } + } +} \ No newline at end of file diff --git a/plugin/src/main/kotlin/com/github/spigotbasics/plugin/BasicsPluginImpl.kt b/plugin/src/main/kotlin/com/github/spigotbasics/plugin/BasicsPluginImpl.kt index c1aad393..4397a4e5 100644 --- a/plugin/src/main/kotlin/com/github/spigotbasics/plugin/BasicsPluginImpl.kt +++ b/plugin/src/main/kotlin/com/github/spigotbasics/plugin/BasicsPluginImpl.kt @@ -137,7 +137,7 @@ class BasicsPluginImpl : JavaPlugin(), BasicsPlugin { server.pluginManager.registerEvents(modulePlayerDataLoader, this) server.pluginManager.registerEvents(PlayerCommandListSendListener(facade.getCommandMap(server.pluginManager)), this) - getCommand("basicsdebug")?.setExecutor(BasicsDebugCommand(this)) + //getCommand("basicsdebug")?.setExecutor(BasicsDebugCommand(this)) } private fun initializeHeavyClasses() { diff --git a/plugin/src/main/resources/plugin.yml b/plugin/src/main/resources/plugin.yml index ce620227..5fb9835b 100644 --- a/plugin/src/main/resources/plugin.yml +++ b/plugin/src/main/resources/plugin.yml @@ -4,7 +4,7 @@ main: com.github.spigotbasics.plugin.BasicsPluginImpl api-version: "1.13" authors: [ "https://github.com/SpigotBasics/basics/graphs/contributors" ] commands: - basicsdebug: - description: "Debugging commands for Basics" - permission: basics.debug - usage: "/ [start |stop]" \ No newline at end of file +# basicsdebug: +# description: "Debugging commands for Basics" +# permission: basics.debug +# usage: "/ [start |stop]" \ No newline at end of file From fea6c342519e1c5376bbca0d4701dc3d355705c2 Mon Sep 17 00:00:00 2001 From: mfnalex Date: Thu, 15 Feb 2024 19:57:48 +0100 Subject: [PATCH 6/7] Added /basicsdebug command Fixed IntArgs showing incorrect error message --- .../core/command/parsed/ParsedCommandExecutor.kt | 10 ++++++++++ .../core/command/parsed/arguments/IntArg.kt | 9 +++++++++ .../core/command/parsed/arguments/IntRangeArg.kt | 3 ++- .../GenericArgumentPathBuilder.kt | 3 +-- .../dsl/commandbuilder/ParsedCommandBuilder.kt | 2 +- .../spigotbasics/core/messages/CoreMessages.kt | 15 ++++++++++++--- core/src/main/resources/messages.yml | 1 + .../modules/basicscore/BasicsCoreModule.kt | 12 +++++++++++- .../{ => commands}/DebugFallbackExecutor.kt | 9 ++++++--- .../{ => commands}/PrintPermissionsCommand.kt | 11 +++++++---- .../commands/SetDebugLogLevelCommand.kt | 16 ++++++++++++++++ .../spigotbasics/plugin/BasicsPluginImpl.kt | 2 +- 12 files changed, 77 insertions(+), 16 deletions(-) rename modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/{ => commands}/DebugFallbackExecutor.kt (68%) rename modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/{ => commands}/PrintPermissionsCommand.kt (57%) create mode 100644 modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/commands/SetDebugLogLevelCommand.kt diff --git a/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/ParsedCommandExecutor.kt b/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/ParsedCommandExecutor.kt index a0ebb3a9..e6a17c11 100644 --- a/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/ParsedCommandExecutor.kt +++ b/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/ParsedCommandExecutor.kt @@ -17,6 +17,16 @@ class ParsedCommandExecutor( } init { + + for (path in paths) { + if (path.ownExecutor == null && executor == null) { + throw IllegalArgumentException( + "Attempting to create a ParsedCommandExecutor with a path that has no executor and no default " + + "executor was provided. Path: $path", + ) + } + } + logger.debug(10, "ParsedCommandExecutor created with paths: ${paths.size}") } diff --git a/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/arguments/IntArg.kt b/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/arguments/IntArg.kt index 60c51f8d..36f8e28a 100644 --- a/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/arguments/IntArg.kt +++ b/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/arguments/IntArg.kt @@ -1,5 +1,7 @@ package com.github.spigotbasics.core.command.parsed.arguments +import com.github.spigotbasics.core.Basics +import com.github.spigotbasics.core.messages.Message import org.bukkit.command.CommandSender open class IntArg(name: String) : CommandArgument(name) { @@ -7,4 +9,11 @@ open class IntArg(name: String) : CommandArgument(name) { sender: CommandSender, value: String, ): Int? = value.toIntOrNull() + + override fun errorMessage( + sender: CommandSender, + value: String, + ): Message { + return Basics.messages.invalidValueForArgumentMustBeInteger(name, value) + } } diff --git a/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/arguments/IntRangeArg.kt b/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/arguments/IntRangeArg.kt index 72d11c4f..5ed00b48 100644 --- a/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/arguments/IntRangeArg.kt +++ b/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/arguments/IntRangeArg.kt @@ -21,6 +21,7 @@ class IntRangeArg(name: String, private val min: () -> Int, private val max: () sender: CommandSender, value: String, ): Message { - return Basics.messages.invalidValueForArgumentNumberNotInRange(name, value.toIntOrNull() ?: 0, min(), max()) + val given = value.toIntOrNull() ?: return Basics.messages.invalidValueForArgumentMustBeInteger(name, value) + return Basics.messages.invalidValueForArgumentNumberNotInRange(name, given, min(), max()) } } diff --git a/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/dsl/argumentpathbuilder/GenericArgumentPathBuilder.kt b/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/dsl/argumentpathbuilder/GenericArgumentPathBuilder.kt index b72c6edb..d1955dbf 100644 --- a/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/dsl/argumentpathbuilder/GenericArgumentPathBuilder.kt +++ b/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/dsl/argumentpathbuilder/GenericArgumentPathBuilder.kt @@ -1,7 +1,6 @@ package com.github.spigotbasics.core.command.parsed.dsl.argumentpathbuilder import com.github.spigotbasics.core.command.parsed.ArgumentPath -import com.github.spigotbasics.core.command.parsed.CommandContextExecutor import com.github.spigotbasics.core.command.parsed.context.CommandContext class GenericArgumentPathBuilder : ArgumentPathBuilder() { @@ -15,6 +14,6 @@ class GenericArgumentPathBuilder : ArgumentPathBuilder() arguments, permissions, contextBuilder ?: error("Context builder not set"), - pathExecutor + pathExecutor, ) } diff --git a/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/dsl/commandbuilder/ParsedCommandBuilder.kt b/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/dsl/commandbuilder/ParsedCommandBuilder.kt index dd47d9bb..d9f9b058 100644 --- a/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/dsl/commandbuilder/ParsedCommandBuilder.kt +++ b/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/dsl/commandbuilder/ParsedCommandBuilder.kt @@ -87,7 +87,7 @@ open class ParsedCommandBuilder( fun build(): BasicsCommand { val command = ParsedCommandExecutor( - parsedExecutor, // ?: error("parsedExecutor must be set"), + parsedExecutor, argumentPaths, ) val actualExecutor = createActualExecutor(command) diff --git a/core/src/main/kotlin/com/github/spigotbasics/core/messages/CoreMessages.kt b/core/src/main/kotlin/com/github/spigotbasics/core/messages/CoreMessages.kt index 13a37fed..912304fe 100644 --- a/core/src/main/kotlin/com/github/spigotbasics/core/messages/CoreMessages.kt +++ b/core/src/main/kotlin/com/github/spigotbasics/core/messages/CoreMessages.kt @@ -58,6 +58,15 @@ class CoreMessages(context: ConfigInstantiationContext) : SavedConfig(context) { .tagUnparsed("value", givenValue) } + fun invalidValueForArgumentMustBeInteger( + argumentName: String, + givenValue: String, + ): Message { + return getMessage("invalid-value-for-argument-must-be-integer") + .tagUnparsed("argument", argumentName) + .tagUnparsed("value", givenValue) + } + fun invalidValueForArgumentNumberNotInRange( argumentName: String, givenValue: Int, @@ -66,9 +75,9 @@ class CoreMessages(context: ConfigInstantiationContext) : SavedConfig(context) { ): Message { return getMessage("invalid-value-for-argument-number-not-in-range") .tagUnparsed("argument", argumentName) - .tagParsed("value", givenValue.toString()) - .tagParsed("min", min.toString()) - .tagParsed("max", max.toString()) + .tagUnparsed("value", givenValue.toString()) + .tagUnparsed("min", min.toString()) + .tagUnparsed("max", max.toString()) } fun missingArgument(name: String) = getMessage("missing-value-for-argument").tagParsed("argument", name) diff --git a/core/src/main/resources/messages.yml b/core/src/main/resources/messages.yml index b807263e..f0d10635 100644 --- a/core/src/main/resources/messages.yml +++ b/core/src/main/resources/messages.yml @@ -9,6 +9,7 @@ unknown-option: "Unknown option: <#option> <#value> invalid-value-for-argument: "Invalid value for <#argument>: <#value>" +invalid-value-for-argument-must-be-integer: "Invalid value for <#argument>: Must be an integer, was <#value>!" # Tags: <#argument> <#value> <#min> <#max> invalid-value-for-argument-number-not-in-range: "Invalid value for <#argument>: Must be between <#min> and <#max>, was <#value>!" diff --git a/modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/BasicsCoreModule.kt b/modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/BasicsCoreModule.kt index fa3adc3c..c66ce15f 100644 --- a/modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/BasicsCoreModule.kt +++ b/modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/BasicsCoreModule.kt @@ -1,7 +1,10 @@ package com.github.spigotbasics.modules.basicscore +import com.github.spigotbasics.core.command.parsed.arguments.IntRangeArg import com.github.spigotbasics.core.module.AbstractBasicsModule import com.github.spigotbasics.core.module.loader.ModuleInstantiationContext +import com.github.spigotbasics.modules.basicscore.commands.PrintPermissionsCommand +import com.github.spigotbasics.modules.basicscore.commands.SetDebugLogLevelCommand import org.bukkit.permissions.PermissionDefault class BasicsCoreModule(context: ModuleInstantiationContext) : AbstractBasicsModule(context) { @@ -110,8 +113,15 @@ class BasicsCoreModule(context: ModuleInstantiationContext) : AbstractBasicsModu } executor(PrintPermissionsCommand()) } + + path { + arguments { + sub("setdebugloglevel") + named("level", IntRangeArg("Log Level", { 0 }, { 999_999_999 })) + } + executor(SetDebugLogLevelCommand()) + } } - //.executor(DebugFallbackExecutor()) .register() } } diff --git a/modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/DebugFallbackExecutor.kt b/modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/commands/DebugFallbackExecutor.kt similarity index 68% rename from modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/DebugFallbackExecutor.kt rename to modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/commands/DebugFallbackExecutor.kt index 8d2cc962..e569bcd7 100644 --- a/modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/DebugFallbackExecutor.kt +++ b/modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/commands/DebugFallbackExecutor.kt @@ -1,11 +1,14 @@ -package com.github.spigotbasics.modules.basicscore +package com.github.spigotbasics.modules.basicscore.commands import com.github.spigotbasics.core.command.parsed.CommandContextExecutor import com.github.spigotbasics.core.command.parsed.context.MapContext import org.bukkit.command.CommandSender class DebugFallbackExecutor : CommandContextExecutor { - override fun execute(sender: CommandSender, context: MapContext) { + override fun execute( + sender: CommandSender, + context: MapContext, + ) { throw IllegalStateException("This command should never be executed") } -} \ No newline at end of file +} diff --git a/modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/PrintPermissionsCommand.kt b/modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/commands/PrintPermissionsCommand.kt similarity index 57% rename from modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/PrintPermissionsCommand.kt rename to modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/commands/PrintPermissionsCommand.kt index e7ea08f9..ac9621c7 100644 --- a/modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/PrintPermissionsCommand.kt +++ b/modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/commands/PrintPermissionsCommand.kt @@ -1,13 +1,16 @@ -package com.github.spigotbasics.modules.basicscore +package com.github.spigotbasics.modules.basicscore.commands import com.github.spigotbasics.core.command.parsed.CommandContextExecutor import com.github.spigotbasics.core.command.parsed.context.MapContext import org.bukkit.command.CommandSender class PrintPermissionsCommand : CommandContextExecutor { - override fun execute(sender: CommandSender, context: MapContext) { - for(permission in sender.server.pluginManager.permissions.filter { it.name.startsWith("basics.") }.sortedBy { it.name }) { + override fun execute( + sender: CommandSender, + context: MapContext, + ) { + for (permission in sender.server.pluginManager.permissions.filter { it.name.startsWith("basics.") }.sortedBy { it.name }) { sender.sendMessage(permission.name + " - " + permission.description + " - " + permission.default.toString()) } } -} \ No newline at end of file +} diff --git a/modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/commands/SetDebugLogLevelCommand.kt b/modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/commands/SetDebugLogLevelCommand.kt new file mode 100644 index 00000000..65938424 --- /dev/null +++ b/modules/basics-core/src/main/kotlin/com/github/spigotbasics/modules/basicscore/commands/SetDebugLogLevelCommand.kt @@ -0,0 +1,16 @@ +package com.github.spigotbasics.modules.basicscore.commands + +import com.github.spigotbasics.core.command.parsed.CommandContextExecutor +import com.github.spigotbasics.core.command.parsed.context.MapContext +import com.github.spigotbasics.core.logger.BasicsLogger +import org.bukkit.command.CommandSender + +class SetDebugLogLevelCommand : CommandContextExecutor { + override fun execute( + sender: CommandSender, + context: MapContext, + ) { + BasicsLogger.debugLogLevel = context["level"] as Int + sender.sendMessage("Debug log level set to ${context["level"]}") + } +} diff --git a/plugin/src/main/kotlin/com/github/spigotbasics/plugin/BasicsPluginImpl.kt b/plugin/src/main/kotlin/com/github/spigotbasics/plugin/BasicsPluginImpl.kt index 4397a4e5..cd46cc92 100644 --- a/plugin/src/main/kotlin/com/github/spigotbasics/plugin/BasicsPluginImpl.kt +++ b/plugin/src/main/kotlin/com/github/spigotbasics/plugin/BasicsPluginImpl.kt @@ -137,7 +137,7 @@ class BasicsPluginImpl : JavaPlugin(), BasicsPlugin { server.pluginManager.registerEvents(modulePlayerDataLoader, this) server.pluginManager.registerEvents(PlayerCommandListSendListener(facade.getCommandMap(server.pluginManager)), this) - //getCommand("basicsdebug")?.setExecutor(BasicsDebugCommand(this)) + // getCommand("basicsdebug")?.setExecutor(BasicsDebugCommand(this)) } private fun initializeHeavyClasses() { From a72c48123e16d8fd03b18472e7121ea1fcd4abc1 Mon Sep 17 00:00:00 2001 From: mfnalex Date: Thu, 15 Feb 2024 19:58:57 +0100 Subject: [PATCH 7/7] Updated README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b276d17b..c1e029e5 100644 --- a/README.md +++ b/README.md @@ -64,4 +64,6 @@ Debug output can be enabled by setting the `BASICS_DEBUG_LEVEL` environment vari ```shell BASICS_DEBUG_LEVEL=99 java -jar spigot.jar -``` \ No newline at end of file +``` + +You can also change the debug level on the fly using `/basicsdebug setdebugloglevel `. \ No newline at end of file