Skip to content

Commit bd5a073

Browse files
Added workaround for SpongePowered/Sponge#1922
1 parent df56748 commit bd5a073

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/main/kotlin/de/randombyte/commandutils/execute/ifcondition/IfCommand.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ class IfCommand(val inverted: Boolean) : CommandExecutor {
1212
val conditionCommand = args.getOne<String>(CommandUtils.CONDITION_COMMAND_ARG).get()
1313
val commands = args.getAll<String>(CommandUtils.COMMAND_ARG)
1414

15-
val commandResult = executeCommand(conditionCommand, src)
16-
var truthy = commandResult.successCount.isPresent // CommandResult.EMPTY.successCount is absent
15+
executeCommand(conditionCommand, src) { commandResult -> // workaround for https://github.com/SpongePowered/SpongeCommon/issues/1922
16+
var truthy = commandResult.successCount.isPresent // CommandResult.EMPTY.successCount is absent
1717

18-
if (inverted) truthy = !truthy
18+
if (inverted) truthy = !truthy
1919

20-
if (truthy) {
21-
commands.forEach { executeCommand(it, src) }
20+
if (truthy) {
21+
commands.forEach { executeCommand(it, src) }
22+
}
2223
}
2324

2425
return CommandResult.success()

src/main/kotlin/de/randombyte/commandutils/utils.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import me.rojo8399.placeholderapi.PlaceholderService
66
import org.spongepowered.api.Sponge
77
import org.spongepowered.api.command.CommandResult
88
import org.spongepowered.api.command.CommandSource
9+
import org.spongepowered.api.scheduler.Task
910
import org.spongepowered.api.text.Text
1011
import org.spongepowered.api.text.serializer.TextSerializers
1112

@@ -15,7 +16,8 @@ fun executeCommand(
1516
command: String,
1617
commandSource: CommandSource,
1718
replacements: Map<String, String> = emptyMap(),
18-
doPlaceholderProcessing: Boolean = true): CommandResult {
19+
doPlaceholderProcessing: Boolean = true,
20+
commandResultCallback: (CommandResult) -> Unit = { }) {
1921

2022
val unprefixedCommand = command.removePrefix(EXECUTE_AS_CONSOLE_PREFIX)
2123
val executeAsConsole = command.startsWith(EXECUTE_AS_CONSOLE_PREFIX)
@@ -28,7 +30,14 @@ fun executeCommand(
2830
val replacedCommand = processedCommand.replace(replacements)
2931

3032
val finalCommandSource = if (executeAsConsole) Sponge.getServer().console else commandSource
31-
return finalCommandSource.executeCommand(replacedCommand)
33+
34+
Task.builder()
35+
.execute { ->
36+
val commandResult = finalCommandSource.executeCommand(replacedCommand)
37+
commandResultCallback(commandResult)
38+
}
39+
.delayTicks(1)
40+
.submit(CommandUtils.INSTANCE)
3241
}
3342

3443
/**

0 commit comments

Comments
 (0)