diff --git a/build.gradle b/build.gradle index 7de2ff7..11bac75 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,7 @@ if (!isJitpack) { } group "de.randombyte" -version "2.2.3" +version "2.2.4" repositories { jcenter() diff --git a/src/main/kotlin/de/randombyte/commandutils/CommandUtils.kt b/src/main/kotlin/de/randombyte/commandutils/CommandUtils.kt index 48b7617..28b4c21 100644 --- a/src/main/kotlin/de/randombyte/commandutils/CommandUtils.kt +++ b/src/main/kotlin/de/randombyte/commandutils/CommandUtils.kt @@ -20,7 +20,6 @@ import de.randombyte.commandutils.executeonserverstartup.ServerStartupListener import de.randombyte.commandutils.service.CommandUtilsService import de.randombyte.commandutils.service.CommandUtilsServiceImpl import de.randombyte.kosp.extensions.toText -import org.bstats.sponge.Metrics import org.slf4j.Logger import org.spongepowered.api.Sponge import org.spongepowered.api.command.args.GenericArguments.* @@ -42,13 +41,13 @@ import java.nio.file.Path dependencies = [(Dependency(id = PLACEHOLDER_API_ID, optional = true))]) class CommandUtils @Inject constructor( val logger: Logger, - @ConfigDir(sharedRoot = false) configPath: Path, - val bStats: Metrics + @ConfigDir(sharedRoot = false) configPath: Path + //val bStats: Metrics ) { companion object { const val ID = "command-utils" const val NAME = "CommandUtils" - const val VERSION = "2.2.3" + const val VERSION = "2.2.4" const val AUTHOR = "RandomByte" const val PLACEHOLDER_API_ID = "placeholderapi" diff --git a/src/main/kotlin/de/randombyte/commandutils/alias/CommandListener.kt b/src/main/kotlin/de/randombyte/commandutils/alias/CommandListener.kt index 9902eeb..2eb67fa 100644 --- a/src/main/kotlin/de/randombyte/commandutils/alias/CommandListener.kt +++ b/src/main/kotlin/de/randombyte/commandutils/alias/CommandListener.kt @@ -58,7 +58,7 @@ class CommandListener { configAccessor.lastAliasExecutions.save(newLastExecutionsConfig) } - aliasConfig.commands.forEach { command -> + aliasConfig.commands.forEachIndexed { index, command -> val replacements = if (commandSource is Player) { // adding the legacy '$p' arguments + Pair("\$p", commandSource.name) @@ -67,7 +67,8 @@ class CommandListener { executeCommand( command = command, commandSource = commandSource, - replacements = replacements + replacements = replacements, + commandIndex = index ) } } diff --git a/src/main/kotlin/de/randombyte/commandutils/execute/delay/DelayCommand.kt b/src/main/kotlin/de/randombyte/commandutils/execute/delay/DelayCommand.kt index 6512c3f..8bd263c 100644 --- a/src/main/kotlin/de/randombyte/commandutils/execute/delay/DelayCommand.kt +++ b/src/main/kotlin/de/randombyte/commandutils/execute/delay/DelayCommand.kt @@ -30,7 +30,8 @@ class DelayCommand : CommandExecutor { .delay(delayMilliseconds, TimeUnit.MILLISECONDS) .execute { -> executeCommand( command = command, - commandSource = src + commandSource = src, + commandIndex = 0 ) } .submit(CommandUtils.INSTANCE) diff --git a/src/main/kotlin/de/randombyte/commandutils/execute/ifcondition/IfCommand.kt b/src/main/kotlin/de/randombyte/commandutils/execute/ifcondition/IfCommand.kt index 6a9dbb2..b4ab64f 100644 --- a/src/main/kotlin/de/randombyte/commandutils/execute/ifcondition/IfCommand.kt +++ b/src/main/kotlin/de/randombyte/commandutils/execute/ifcondition/IfCommand.kt @@ -15,7 +15,8 @@ class IfCommand(val inverted: Boolean) : CommandExecutor { executeCommand( command = conditionCommand, - commandSource = src + commandSource = src, + commandIndex = 0 ) { commandResult -> // workaround for https://github.com/SpongePowered/SpongeCommon/issues/1922 var truthy = commandResult.isTruthy() @@ -24,7 +25,8 @@ class IfCommand(val inverted: Boolean) : CommandExecutor { if (truthy) { commands.forEach { executeCommand( command = it, - commandSource = src + commandSource = src, + commandIndex = 0 ) } } } diff --git a/src/main/kotlin/de/randombyte/commandutils/execute/parse/ParseCommand.kt b/src/main/kotlin/de/randombyte/commandutils/execute/parse/ParseCommand.kt index 6b49f4f..355a602 100644 --- a/src/main/kotlin/de/randombyte/commandutils/execute/parse/ParseCommand.kt +++ b/src/main/kotlin/de/randombyte/commandutils/execute/parse/ParseCommand.kt @@ -19,7 +19,8 @@ class ParseCommand : CommandExecutor { executeCommand( command = command, commandSource = src, - target = target + target = target, + commandIndex = 0 ) return CommandResult.success() diff --git a/src/main/kotlin/de/randombyte/commandutils/execute/whenonline/PlayerJoinListener.kt b/src/main/kotlin/de/randombyte/commandutils/execute/whenonline/PlayerJoinListener.kt index aa011a4..da5442b 100644 --- a/src/main/kotlin/de/randombyte/commandutils/execute/whenonline/PlayerJoinListener.kt +++ b/src/main/kotlin/de/randombyte/commandutils/execute/whenonline/PlayerJoinListener.kt @@ -24,11 +24,12 @@ class PlayerJoinListener { val currentConfig = commandUtils.configAccessor.executeWhenOnline.get() - currentConfig.commands[playerUuid]?.forEach { command -> + currentConfig.commands[playerUuid]?.forEachIndexed { index, command -> executeCommand( command = command, commandSource = player, - replacements = mapOf("\$p" to player.name) + replacements = mapOf("\$p" to player.name), + commandIndex = index ) } diff --git a/src/main/kotlin/de/randombyte/commandutils/executeonserverstartup/ServerStartupListener.kt b/src/main/kotlin/de/randombyte/commandutils/executeonserverstartup/ServerStartupListener.kt index e46e469..de51df2 100644 --- a/src/main/kotlin/de/randombyte/commandutils/executeonserverstartup/ServerStartupListener.kt +++ b/src/main/kotlin/de/randombyte/commandutils/executeonserverstartup/ServerStartupListener.kt @@ -14,9 +14,10 @@ class ServerStartupListener { .delayTicks(1) .execute { -> CommandUtils.INSTANCE.configAccessor.executeOnServerStartup.get().commands - .forEach { executeCommand( - command = it, - commandSource = Sponge.getServer().console + .forEachIndexed { index, command -> executeCommand( + command = command, + commandSource = Sponge.getServer().console, + commandIndex = index ) } } .submit(CommandUtils.INSTANCE) diff --git a/src/main/kotlin/de/randombyte/commandutils/service/CommandUtilsServiceImpl.kt b/src/main/kotlin/de/randombyte/commandutils/service/CommandUtilsServiceImpl.kt index 9676a22..962d4ed 100644 --- a/src/main/kotlin/de/randombyte/commandutils/service/CommandUtilsServiceImpl.kt +++ b/src/main/kotlin/de/randombyte/commandutils/service/CommandUtilsServiceImpl.kt @@ -13,7 +13,8 @@ class CommandUtilsServiceImpl(val configAccessor: ConfigAccessor) : CommandUtils executeCommand( command = newCommand, commandSource = player, - replacements = mapOf("\$p" to player.name) + replacements = mapOf("\$p" to player.name), + commandIndex = 0 ) return } diff --git a/src/main/kotlin/de/randombyte/commandutils/utils.kt b/src/main/kotlin/de/randombyte/commandutils/utils.kt index 737ee98..59fab0d 100644 --- a/src/main/kotlin/de/randombyte/commandutils/utils.kt +++ b/src/main/kotlin/de/randombyte/commandutils/utils.kt @@ -10,12 +10,19 @@ import org.spongepowered.api.scheduler.Task private const val EXECUTE_AS_CONSOLE_PREFIX = "*" +/** + * When working around https://github.com/SpongePowered/SpongeCommon/issues/1922 you have to keep + * the order of execution in mind. [commandIndex] must be incremented for each command that should + * keep its order. + */ fun executeCommand( command: String, commandSource: CommandSource, replacements: Map = emptyMap(), target: Any = commandSource, - commandResultCallback: (CommandResult) -> Unit = { }) { + commandIndex: Int, + commandResultCallback: (CommandResult) -> Unit = { } +) { val unprefixedCommand = command.removePrefix(EXECUTE_AS_CONSOLE_PREFIX) val executeAsConsole = command.startsWith(EXECUTE_AS_CONSOLE_PREFIX) @@ -43,6 +50,6 @@ fun executeCommand( val commandResult = finalCommandSource.executeCommand(processedCommand) commandResultCallback(commandResult) } - .delayTicks(1) + .delayTicks(commandIndex.toLong()) .submit(CommandUtils.INSTANCE) } \ No newline at end of file