@@ -3,7 +3,6 @@ package com.mairwunnx.projectessentials.core.impl.commands
33import com.mairwunnx.projectessentials.core.api.v1.MESSAGE_CORE_PREFIX
44import com.mairwunnx.projectessentials.core.api.v1.commands.CommandAPI
55import com.mairwunnx.projectessentials.core.api.v1.commands.CommandBase
6- import com.mairwunnx.projectessentials.core.api.v1.commands.arguments.StringArrayArgument
76import com.mairwunnx.projectessentials.core.api.v1.configuration.ConfigurationAPI
87import com.mairwunnx.projectessentials.core.api.v1.extensions.getPlayer
98import com.mairwunnx.projectessentials.core.api.v1.extensions.isPlayerSender
@@ -13,7 +12,6 @@ import com.mairwunnx.projectessentials.core.api.v1.messaging.ServerMessagingAPI
1312import com.mairwunnx.projectessentials.core.api.v1.permissions.hasPermission
1413import com.mairwunnx.projectessentials.core.impl.commands.ConfigureEssentialsCommandAPI.requiredServerRestart
1514import com.mairwunnx.projectessentials.core.impl.configurations.GeneralConfiguration
16- import com.mojang.brigadier.CommandDispatcher
1715import com.mojang.brigadier.context.CommandContext
1816import net.minecraft.command.CommandSource
1917import org.apache.logging.log4j.LogManager
@@ -55,28 +53,32 @@ object ConfigureEssentialsCommandAPI {
5553 fun getRequired () = requiredServerRestart.toList()
5654}
5755
58- internal object ConfigureEssentialsCommand : CommandBase(
59- takeConfigureEssentialsLiteral() , false
56+ object ConfigureEssentialsCommand : CommandBase(
57+ configureEssentialsLiteral , false
6058) {
6159 private val generalConfiguration by lazy {
6260 ConfigurationAPI .getConfigurationByName<GeneralConfiguration >(" general" )
6361 }
6462
6563 override val name = " configure-essentials"
6664
67- /*
68- This is a correction of the problem in order to get the list
69- of settings in the configuration several times, because for
70- the first time it is empty.
71- */
72- override fun register (dispatcher : CommandDispatcher <CommandSource >) {
73- this .literal = takeConfigureEssentialsLiteral()
74- super .register(dispatcher)
75- }
76-
7765 override fun process (context : CommandContext <CommandSource >): Int {
78- val setting = StringArrayArgument .getValue (context, " setting" )
66+ val setting = CommandAPI .getString (context, " setting" )
7967 val value = CommandAPI .getString(context, " value" )
68+
69+ if (! validateArguments(setting, value)) {
70+ if (context.isPlayerSender()) {
71+ MessagingAPI .sendMessage(
72+ context.getPlayer()!! ,
73+ " $MESSAGE_CORE_PREFIX .configure.not_found" ,
74+ args = * arrayOf(name)
75+ )
76+ } else {
77+ ServerMessagingAPI .response { " Setting with name $name not exist or value has incorrect format." }
78+ }
79+ return 0
80+ }
81+
8082 val oldValue = generalConfiguration.take().getValue(setting).toString()
8183
8284 if (context.isPlayerSender()) {
@@ -124,4 +126,8 @@ internal object ConfigureEssentialsCommand : CommandBase(
124126 }
125127 return 0
126128 }
129+
130+ private fun validateArguments (setting : String , value : String ) =
131+ generalConfiguration.take().keys.filter { it as String == setting }.count() > 1 &&
132+ value.isNotBlank() && ! Regex (" [=|:@$^*]" ).containsMatchIn(value)
127133}
0 commit comments