-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the cloud command framework instead of creating the commands by t…
…hemselves
- Loading branch information
1 parent
2e35dfa
commit d8e3be3
Showing
2 changed files
with
84 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
186 changes: 76 additions & 110 deletions
186
src/main/kotlin/de/derniklaas/buildbugs/BuildBugsCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,124 +1,90 @@ | ||
package de.derniklaas.buildbugs | ||
|
||
import com.mojang.brigadier.Command | ||
import com.mojang.brigadier.CommandDispatcher | ||
import com.mojang.brigadier.arguments.BoolArgumentType | ||
import com.mojang.brigadier.arguments.StringArgumentType | ||
import com.mojang.brigadier.builder.LiteralArgumentBuilder.literal | ||
import de.derniklaas.buildbugs.utils.Utils | ||
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument | ||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource | ||
import net.minecraft.command.CommandRegistryAccess | ||
import org.incendo.cloud.annotations.Argument | ||
import org.incendo.cloud.annotations.Command | ||
import org.incendo.cloud.annotations.suggestion.Suggestions | ||
import org.incendo.cloud.context.CommandContext | ||
import org.incendo.cloud.suggestion.Suggestion | ||
|
||
object BuildBugsCommand { | ||
fun register(dispatcher: CommandDispatcher<FabricClientCommandSource>, registryAccess: CommandRegistryAccess) { | ||
dispatcher.register(literal<FabricClientCommandSource>("buildbug").then( | ||
literal<FabricClientCommandSource>("config").then( | ||
literal<FabricClientCommandSource>("clipboard").then(argument( | ||
"value", BoolArgumentType.bool() | ||
).executes { | ||
val value = BoolArgumentType.getBool(it, "value") | ||
BuildBugsClientEntrypoint.config.setCopy(value) | ||
if (BuildBugsClientEntrypoint.config.copyToClipboard) { | ||
Utils.sendMiniMessage("<green>Enabled</green> automatic copying to clipboard.") | ||
} else { | ||
Utils.sendMiniMessage("<red>Disabled</red> automatic copying to clipboard.") | ||
} | ||
return@executes Command.SINGLE_SUCCESS | ||
}) | ||
).then( | ||
literal<FabricClientCommandSource>("debug").then(argument( | ||
"value", BoolArgumentType.bool() | ||
).executes { | ||
val value = BoolArgumentType.getBool(it, "value") | ||
BuildBugsClientEntrypoint.config.setDebug(value) | ||
class BuildBugsCommand { | ||
|
||
if (BuildBugsClientEntrypoint.config.debugMode) { | ||
Utils.sendMiniMessage("<green>Enabled</green> Debug mode.") | ||
BugCreator.printCurrentGameState() | ||
} else { | ||
Utils.sendMiniMessage("<red>Disabled</red> Debug mode.") | ||
} | ||
@Command("buildbug config clipboard <value>") | ||
fun config_clipboard(context: CommandContext<*>, @Argument("value") value: Boolean) { | ||
BuildBugsClientEntrypoint.config.setCopy(value) | ||
if (BuildBugsClientEntrypoint.config.copyToClipboard) { | ||
Utils.sendMiniMessage("<green>Enabled</green> automatic copying to clipboard.") | ||
} else { | ||
Utils.sendMiniMessage("<red>Disabled</red> automatic copying to clipboard.") | ||
} | ||
} | ||
|
||
@Command("buildbug config debug <value>") | ||
fun config_debug(context: CommandContext<*>, @Argument("value") value: Boolean) { | ||
BuildBugsClientEntrypoint.config.setDebug(value) | ||
if (BuildBugsClientEntrypoint.config.debugMode) { | ||
Utils.sendMiniMessage("<green>Enabled</green> Debug mode.") | ||
BugCreator.printCurrentGameState() | ||
} else { | ||
Utils.sendMiniMessage("<red>Disabled</red> Debug mode.") | ||
} | ||
} | ||
|
||
return@executes Command.SINGLE_SUCCESS | ||
}) | ||
).then( | ||
literal<FabricClientCommandSource?>("log_incoming_packets").then(argument( | ||
"value", | ||
BoolArgumentType.bool() | ||
).executes { | ||
val value = BoolArgumentType.getBool(it, "value") | ||
BuildBugsClientEntrypoint.config.setLoggingForIncomingPackets(value) | ||
@Command("buildbug config eventip <address>") | ||
fun config_ip(context: CommandContext<*>, @Argument("address") address: String) { | ||
BuildBugsClientEntrypoint.config.setEventAddress(address) | ||
Utils.sendSuccessMessage("Set event IP to <gold>$address</gold>.") | ||
|
||
if (BuildBugsClientEntrypoint.config.logIncomingPackets) { | ||
Utils.sendMiniMessage("<green>Enabled</green> logging of incoming packets.") | ||
} else { | ||
Utils.sendMiniMessage("<red>Disabled</red> logging of incoming packets.") | ||
} | ||
} | ||
|
||
return@executes Command.SINGLE_SUCCESS | ||
}) | ||
).then( | ||
literal<FabricClientCommandSource?>("log_outgoing_packets").then(argument( | ||
"value", | ||
BoolArgumentType.bool() | ||
).executes { | ||
val value = BoolArgumentType.getBool(it, "value") | ||
BuildBugsClientEntrypoint.config.setLoggingForOutgoingPackets(value) | ||
@Command("buildbug version") | ||
fun version(context: CommandContext<*>) { | ||
Utils.sendSuccessMessage("Running BuildBugs ${BuildBugsClientEntrypoint.version}!") | ||
} | ||
|
||
if (BuildBugsClientEntrypoint.config.logOutgoingPackets) { | ||
Utils.sendMiniMessage("<green>Enabled</green> logging of outgoing packets.") | ||
} else { | ||
Utils.sendMiniMessage("<red>Disabled</red> logging of outgoing packets.") | ||
} | ||
@Command("buildbug reset_state") | ||
fun reset_state(context: CommandContext<*>) { | ||
if (BuildBugsClientEntrypoint.config.debugMode) { | ||
BugCreator.resetGameState() | ||
} else { | ||
Utils.sendErrorMessage("You can only reset the game state in debug mode.") | ||
} | ||
} | ||
|
||
return@executes Command.SINGLE_SUCCESS | ||
}) | ||
).then( | ||
literal<FabricClientCommandSource?>("eventip").then(argument( | ||
"value", StringArgumentType.string() | ||
).executes { | ||
val value = StringArgumentType.getString(it, "value") | ||
BuildBugsClientEntrypoint.config.setEventAddress(value) | ||
@Command("buildbug force_state <game> <type> <map>") | ||
fun force_state_full( | ||
context: CommandContext<*>, | ||
@Argument("game", suggestions = "gameSuggestions") game: String, | ||
@Argument("type") type: String, | ||
@Argument("map") map: String | ||
) { | ||
if (!BuildBugsClientEntrypoint.config.debugMode) { | ||
Utils.sendErrorMessage("You can only force the game state in debug mode.") | ||
return | ||
} | ||
BugCreator.forceGameState(game, type, map) | ||
} | ||
|
||
@Command("buildbug force_state <game> <type>") | ||
fun force_state_full( | ||
context: CommandContext<*>, | ||
@Argument("game", suggestions = "gameSuggestions") game: String, | ||
@Argument("type") type: String | ||
) { | ||
if (!BuildBugsClientEntrypoint.config.debugMode) { | ||
Utils.sendErrorMessage("You can only force the game state in debug mode.") | ||
return | ||
} | ||
BugCreator.forceGameState(game, type, Constants.UNKNOWN) | ||
} | ||
|
||
fun report(context: CommandContext<*>) { | ||
BugCreator.report() | ||
} | ||
|
||
Utils.sendSuccessMessage("Set event IP to <gold>$value</gold>.") | ||
|
||
return@executes Command.SINGLE_SUCCESS | ||
}) | ||
) | ||
).then(literal<FabricClientCommandSource>("version").executes { | ||
Utils.sendSuccessMessage("Running BuildBugs ${BuildBugsClientEntrypoint.version}!") | ||
return@executes Command.SINGLE_SUCCESS | ||
}).then(literal<FabricClientCommandSource>("reset_state").executes { | ||
if (BuildBugsClientEntrypoint.config.debugMode) { | ||
BugCreator.resetGameState() | ||
} else { | ||
Utils.sendErrorMessage("You can only reset the game state in debug mode.") | ||
} | ||
return@executes Command.SINGLE_SUCCESS | ||
}).then( | ||
literal<FabricClientCommandSource>("force_state").then( | ||
argument( | ||
"type", StringArgumentType.string() | ||
).then( | ||
argument("subtype", StringArgumentType.string()).then(argument( | ||
"map", StringArgumentType.string() | ||
).executes { | ||
if (!BuildBugsClientEntrypoint.config.debugMode) { | ||
Utils.sendErrorMessage("You can only force the game state in debug mode.") | ||
return@executes Command.SINGLE_SUCCESS | ||
} | ||
val type = StringArgumentType.getString(it, "type") | ||
val subType = StringArgumentType.getString(it, "subtype") | ||
val map = StringArgumentType.getString(it, "map") | ||
BugCreator.forceGameState(type, subType, map) | ||
return@executes Command.SINGLE_SUCCESS | ||
}) | ||
) | ||
) | ||
).executes { | ||
BugCreator.report() | ||
return@executes Command.SINGLE_SUCCESS | ||
}) | ||
@Suggestions("gameSuggestions") | ||
fun gameSuggestions(commandContext: CommandContext<*>, input: String): List<Suggestion> { | ||
return Constants.ALL_TYPES.map { Suggestion.suggestion(it) } | ||
} | ||
} |