From b3da5944ea2b2167add0ad5d9dae1cf854344713 Mon Sep 17 00:00:00 2001 From: Cat Core <34719527+thecatcore@users.noreply.github.com> Date: Fri, 6 Dec 2024 23:02:58 +0100 Subject: [PATCH] Reduce code duplication in command-api-v2 (sponge) by introducing a common sub-module and fix some formatting issues (#181) * Update Lomm * First round of command classes * Second round of shared classes * Mixins clean up * Bump modules version * Fix some formatting issues * Fix more formatting issues * Fix style --- build.gradle | 2 +- gradle.properties | 4 +- .../v2/lib/sponge/args/CommandFlags.java | 2 +- .../args/PatternMatchingCommandElement.java | 151 -------- .../v2/lib/sponge/args/parsing/SingleArg.java | 109 ------ .../impl/command/MinecraftClientAccessor.java | 24 -- .../sponge/args/OptionalCommandElement.java | 103 ------ .../sponge/args/PermissionCommandElement.java | 101 ----- .../lib/sponge/args/PlayerCommandElement.java | 2 +- .../mixin/command/MinecraftClientMixin.java | 38 -- .../mixin/command/MinecraftServerMixin.java | 36 -- .../1.12.2/src/main/resources/fabric.mod.json | 4 +- ...y-fabric-sponge-command-api-v2.mixins.json | 14 - .../fabric/api/command/v2/StringType.java | 36 -- .../v2/lib/sponge/CommandException.java | 92 ----- .../lib/sponge/CommandMessageFormatting.java | 63 ---- .../lib/sponge/CommandNotFoundException.java | 70 ---- .../sponge/CommandPermissionException.java | 63 ---- .../sponge/InvocationCommandException.java | 46 --- .../v2/lib/sponge/TextMessageException.java | 98 ----- .../sponge/args/ArgumentParseException.java | 159 -------- .../args/ChildCommandElementExecutor.java | 4 +- .../v2/lib/sponge/args/CommandArgs.java | 348 ------------------ .../v2/lib/sponge/args/CommandContext.java | 337 ----------------- .../v2/lib/sponge/args/CommandElement.java | 133 ------- .../v2/lib/sponge/args/CommandFlags.java | 2 +- .../v2/lib/sponge/args/KeyElement.java | 48 --- .../sponge/args/parsing/InputTokenizer.java | 81 ---- .../args/parsing/QuotedStringTokenizer.java | 172 --------- .../args/parsing/RawStringInputTokenizer.java | 41 --- .../v2/lib/sponge/args/parsing/SingleArg.java | 108 ------ .../parsing/SpaceSplitInputTokenizer.java | 65 ---- .../sponge/args/parsing/TokenizerState.java | 75 ---- .../v2/lib/sponge/spec/CommandSpec.java | 2 +- .../impl/command/CommandManagerImpl.java | 2 +- .../fabric/impl/command/CommandWrapper.java | 2 +- .../lib/sponge/args/AllOfCommandElement.java | 92 ----- .../lib/sponge/args/BigDecimalElement.java | 56 --- .../lib/sponge/args/BigIntegerElement.java | 56 --- .../sponge/args/ChoicesCommandElement.java | 99 ----- .../lib/sponge/args/DateTimeElement.java | 103 ------ .../lib/sponge/args/DurationElement.java | 75 ---- .../lib/sponge/args/EntityCommandElement.java | 4 +- .../lib/sponge/args/EnumValueElement.java | 68 ---- .../args/FilteredSuggestionsElement.java | 61 --- .../args/FirstParsingCommandElement.java | 110 ------ .../sponge/args/LiteralCommandElement.java | 94 ----- .../sponge/args/MarkTrueCommandElement.java | 59 --- .../lib/sponge/args/ModCommandElement.java | 56 --- .../lib/sponge/args/NumericElement.java | 71 ---- .../sponge/args/OnlyOneCommandElement.java | 74 ---- .../sponge/args/PermissionCommandElement.java | 101 ----- .../lib/sponge/args/PlayerCommandElement.java | 5 +- .../RemainingJoinedStringsCommandElement.java | 71 ---- .../sponge/args/RepeatedCommandElement.java | 82 ----- .../sponge/args/SequenceCommandElement.java | 134 ------- .../lib/sponge/args/StringCommandElement.java | 53 --- .../lib/sponge/args/StringElement.java | 44 --- .../command/lib/sponge/args/UrlElement.java | 67 ---- .../command/lib/sponge/args/UuidElement.java | 54 --- .../sponge/args/WithSuggestionsElement.java | 69 ---- .../1.7.10/src/main/resources/fabric.mod.json | 4 +- ...y-fabric-sponge-command-api-v2.mixins.json | 11 - .../fabric/api/command/v2/StringType.java | 36 -- .../v2/lib/sponge/CommandException.java | 92 ----- .../lib/sponge/CommandMessageFormatting.java | 63 ---- .../lib/sponge/CommandNotFoundException.java | 70 ---- .../sponge/CommandPermissionException.java | 63 ---- .../sponge/InvocationCommandException.java | 46 --- .../v2/lib/sponge/TextMessageException.java | 98 ----- .../sponge/args/ArgumentParseException.java | 159 -------- .../v2/lib/sponge/args/CommandArgs.java | 348 ------------------ .../v2/lib/sponge/args/CommandContext.java | 337 ----------------- .../v2/lib/sponge/args/CommandElement.java | 133 ------- .../v2/lib/sponge/args/CommandFlags.java | 2 +- .../v2/lib/sponge/args/KeyElement.java | 48 --- .../args/PatternMatchingCommandElement.java | 151 -------- .../sponge/args/parsing/InputTokenizer.java | 81 ---- .../args/parsing/QuotedStringTokenizer.java | 172 --------- .../args/parsing/RawStringInputTokenizer.java | 41 --- .../parsing/SpaceSplitInputTokenizer.java | 65 ---- .../sponge/args/parsing/TokenizerState.java | 75 ---- .../lib/sponge/args/AllOfCommandElement.java | 92 ----- .../lib/sponge/args/BigDecimalElement.java | 56 --- .../lib/sponge/args/BigIntegerElement.java | 56 --- .../sponge/args/ChoicesCommandElement.java | 99 ----- .../lib/sponge/args/DateTimeElement.java | 103 ------ .../lib/sponge/args/DurationElement.java | 75 ---- .../lib/sponge/args/EntityCommandElement.java | 4 +- .../lib/sponge/args/EnumValueElement.java | 68 ---- .../args/FilteredSuggestionsElement.java | 61 --- .../args/FirstParsingCommandElement.java | 110 ------ .../sponge/args/LiteralCommandElement.java | 94 ----- .../sponge/args/MarkTrueCommandElement.java | 59 --- .../lib/sponge/args/ModCommandElement.java | 56 --- .../lib/sponge/args/NumericElement.java | 71 ---- .../sponge/args/OnlyOneCommandElement.java | 74 ---- .../sponge/args/OptionalCommandElement.java | 103 ------ .../lib/sponge/args/PlayerCommandElement.java | 4 +- .../RemainingJoinedStringsCommandElement.java | 71 ---- .../sponge/args/RepeatedCommandElement.java | 82 ----- .../sponge/args/SequenceCommandElement.java | 134 ------- .../lib/sponge/args/StringCommandElement.java | 53 --- .../lib/sponge/args/StringElement.java | 44 --- .../command/lib/sponge/args/UrlElement.java | 67 ---- .../command/lib/sponge/args/UuidElement.java | 54 --- .../sponge/args/WithSuggestionsElement.java | 69 ---- .../mixin/command/MinecraftServerMixin.java | 36 -- .../1.8.9/src/main/resources/fabric.mod.json | 4 +- ...y-fabric-sponge-command-api-v2.mixins.json | 11 - .../common/build.gradle | 0 .../common/gradle.properties | 2 + .../fabric/api/command/v2/StringType.java | 0 .../v2/lib/sponge/CommandException.java | 0 .../lib/sponge/CommandMessageFormatting.java | 0 .../lib/sponge/CommandNotFoundException.java | 0 .../sponge/CommandPermissionException.java | 0 .../sponge/InvocationCommandException.java | 0 .../v2/lib/sponge/TextMessageException.java | 0 .../sponge/args/ArgumentParseException.java | 0 .../v2/lib/sponge/args/CommandArgs.java | 0 .../v2/lib/sponge/args/CommandContext.java | 3 +- .../v2/lib/sponge/args/CommandElement.java | 21 +- .../v2/lib/sponge/args/KeyElement.java | 0 .../args/PatternMatchingCommandElement.java | 2 +- .../sponge/args/parsing/InputTokenizer.java | 0 .../args/parsing/QuotedStringTokenizer.java | 0 .../args/parsing/RawStringInputTokenizer.java | 0 .../v2/lib/sponge/args/parsing/SingleArg.java | 4 +- .../parsing/SpaceSplitInputTokenizer.java | 0 .../sponge/args/parsing/TokenizerState.java | 0 .../fabric/impl/command/GuavaUtils.java | 173 +++++++++ .../lib/sponge/args/AllOfCommandElement.java | 0 .../lib/sponge/args/BigDecimalElement.java | 0 .../lib/sponge/args/BigIntegerElement.java | 0 .../sponge/args/ChoicesCommandElement.java | 0 .../lib/sponge/args/DateTimeElement.java | 0 .../lib/sponge/args/DurationElement.java | 0 .../lib/sponge/args/EnumValueElement.java | 0 .../args/FilteredSuggestionsElement.java | 0 .../args/FirstParsingCommandElement.java | 0 .../sponge/args/LiteralCommandElement.java | 0 .../sponge/args/MarkTrueCommandElement.java | 0 .../lib/sponge/args/ModCommandElement.java | 0 .../lib/sponge/args/NumericElement.java | 0 .../sponge/args/OnlyOneCommandElement.java | 2 +- .../sponge/args/OptionalCommandElement.java | 2 +- .../sponge/args/PermissionCommandElement.java | 4 +- .../RemainingJoinedStringsCommandElement.java | 0 .../sponge/args/RepeatedCommandElement.java | 0 .../sponge/args/SequenceCommandElement.java | 0 .../lib/sponge/args/StringCommandElement.java | 0 .../lib/sponge/args/StringElement.java | 0 .../command/lib/sponge/args/UrlElement.java | 0 .../command/lib/sponge/args/UuidElement.java | 0 .../sponge/args/WithSuggestionsElement.java | 0 .../common/src/main/resources/fabric.mod.json | 38 ++ .../permission}/MinecraftServerMixin.java | 6 +- ...bric-permissions-api-v1-common.mixins.json | 1 + 159 files changed, 259 insertions(+), 8299 deletions(-) delete mode 100644 legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/PatternMatchingCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SingleArg.java delete mode 100644 legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/MinecraftClientAccessor.java delete mode 100644 legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OptionalCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/PermissionCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/command/MinecraftClientMixin.java delete mode 100644 legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/command/MinecraftServerMixin.java delete mode 100644 legacy-fabric-command-api-v2/1.12.2/src/main/resources/legacy-fabric-sponge-command-api-v2.mixins.json delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/StringType.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandException.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandMessageFormatting.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandNotFoundException.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandPermissionException.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/InvocationCommandException.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/TextMessageException.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/ArgumentParseException.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandArgs.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandContext.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/KeyElement.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/InputTokenizer.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/QuotedStringTokenizer.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/RawStringInputTokenizer.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SingleArg.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SpaceSplitInputTokenizer.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/TokenizerState.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/AllOfCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/BigDecimalElement.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/BigIntegerElement.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/ChoicesCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/DateTimeElement.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/DurationElement.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/EnumValueElement.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/FilteredSuggestionsElement.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/FirstParsingCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/LiteralCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/MarkTrueCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/ModCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/NumericElement.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OnlyOneCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/PermissionCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/RemainingJoinedStringsCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/RepeatedCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/SequenceCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/StringCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/StringElement.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/UrlElement.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/UuidElement.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/WithSuggestionsElement.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/resources/legacy-fabric-sponge-command-api-v2.mixins.json delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/StringType.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandException.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandMessageFormatting.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandNotFoundException.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandPermissionException.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/InvocationCommandException.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/TextMessageException.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/ArgumentParseException.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandArgs.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandContext.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/KeyElement.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/PatternMatchingCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/InputTokenizer.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/QuotedStringTokenizer.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/RawStringInputTokenizer.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SpaceSplitInputTokenizer.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/TokenizerState.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/AllOfCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/BigDecimalElement.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/BigIntegerElement.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/ChoicesCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/DateTimeElement.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/DurationElement.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/EnumValueElement.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/FilteredSuggestionsElement.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/FirstParsingCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/LiteralCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/MarkTrueCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/ModCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/NumericElement.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OnlyOneCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OptionalCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/RemainingJoinedStringsCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/RepeatedCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/SequenceCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/StringCommandElement.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/StringElement.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/UrlElement.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/UuidElement.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/WithSuggestionsElement.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/command/MinecraftServerMixin.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/resources/legacy-fabric-sponge-command-api-v2.mixins.json create mode 100644 legacy-fabric-command-api-v2/common/build.gradle create mode 100644 legacy-fabric-command-api-v2/common/gradle.properties rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/api/command/v2/StringType.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandException.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandMessageFormatting.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandNotFoundException.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandPermissionException.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/InvocationCommandException.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/TextMessageException.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/ArgumentParseException.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandArgs.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandContext.java (98%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandElement.java (91%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/KeyElement.java (100%) rename legacy-fabric-command-api-v2/{1.7.10 => common}/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/PatternMatchingCommandElement.java (99%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/InputTokenizer.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/QuotedStringTokenizer.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/RawStringInputTokenizer.java (100%) rename legacy-fabric-command-api-v2/{1.8.9 => common}/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SingleArg.java (96%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SpaceSplitInputTokenizer.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/TokenizerState.java (100%) create mode 100644 legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/GuavaUtils.java rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/AllOfCommandElement.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/BigDecimalElement.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/BigIntegerElement.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/ChoicesCommandElement.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/DateTimeElement.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/DurationElement.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/EnumValueElement.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/FilteredSuggestionsElement.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/FirstParsingCommandElement.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/LiteralCommandElement.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/MarkTrueCommandElement.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/ModCommandElement.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/NumericElement.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OnlyOneCommandElement.java (97%) rename legacy-fabric-command-api-v2/{1.7.10 => common}/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OptionalCommandElement.java (97%) rename legacy-fabric-command-api-v2/{1.8.9 => common}/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/PermissionCommandElement.java (95%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/RemainingJoinedStringsCommandElement.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/RepeatedCommandElement.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/SequenceCommandElement.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/StringCommandElement.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/StringElement.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/UrlElement.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/UuidElement.java (100%) rename legacy-fabric-command-api-v2/{1.12.2 => common}/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/WithSuggestionsElement.java (100%) create mode 100644 legacy-fabric-command-api-v2/common/src/main/resources/fabric.mod.json rename {legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/command => legacy-fabric-permissions-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/permission}/MinecraftServerMixin.java (87%) diff --git a/build.gradle b/build.gradle index d68563dbc..f678fe7ca 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { id "eclipse" id "idea" id "maven-publish" - id "fabric-loom" version "1.8.11" apply false + id "fabric-loom" version "1.8.13" apply false id "legacy-looming" version "1.8.2" apply false id "com.diffplug.spotless" version "6.20.0" id "org.ajoberstar.grgit" version "5.2.2" diff --git a/gradle.properties b/gradle.properties index ab1434761..46a95ac05 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ yarn_mappings_build = 530 ## Module versions legacy-fabric-api-base.version = 1.1.0 legacy-fabric-command-api-v1.version = 1.0.1 -legacy-fabric-command-api-v2.version = 1.0.2 +legacy-fabric-command-api-v2.version = 1.1.0 legacy-fabric-crash-report-info-v1.version = 1.0.0 legacy-fabric-entity-events-v1.version = 1.0.0 legacy-fabric-gamerule-api-v1.version = 1.0.0 @@ -17,7 +17,7 @@ legacy-fabric-keybindings-api-v1.version = 1.1.1 legacy-fabric-lifecycle-events-v1.version = 1.1.0 legacy-fabric-logger-api-v1.version = 1.0.4 legacy-fabric-networking-api-v1.version = 2.0.2 -legacy-fabric-permissions-api-v1.version = 1.1.0 +legacy-fabric-permissions-api-v1.version = 1.1.1 legacy-fabric-registry-sync-api-v1.version = 2.2.0 legacy-fabric-rendering-api-v1.version = 1.0.0 legacy-fabric-resource-loader-v1.version = 2.2.2 diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandFlags.java b/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandFlags.java index 9e1a5ea4c..c0927bf6a 100644 --- a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandFlags.java +++ b/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandFlags.java @@ -183,7 +183,7 @@ public Text getUsage(PermissibleCommandSource src) { if (usage.asUnformattedString().trim().length() > 0) { builder.add(" "); - builder.add(usage); + builder.add(usage.asUnformattedString()); } builder.add("]"); diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/PatternMatchingCommandElement.java b/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/PatternMatchingCommandElement.java deleted file mode 100644 index efa95b171..000000000 --- a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/PatternMatchingCommandElement.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge.args; - -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.regex.Pattern; -import java.util.stream.Collectors; -import java.util.stream.StreamSupport; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -/** - * Abstract command element that matches values based on a regex pattern. - */ -public abstract class PatternMatchingCommandElement extends CommandElement { - private static final Text nullKeyArg = new LiteralText("argument"); - final boolean useRegex; - - /** - * @param yesIWantRegex Specify if you want to allow regex for users of - * the command element. Note that this will open up for DoS attacks. - */ - protected PatternMatchingCommandElement(@Nullable Text key, boolean yesIWantRegex) { - super(key); - this.useRegex = yesIWantRegex; - } - - protected PatternMatchingCommandElement(@Nullable Text key) { - this(key, false); - } - - @Nullable - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - Iterable choices = this.getChoices(source); - Iterable ret; - String arg = args.next(); - - // Check to see if we have an exact match first - Optional exactMatch = this.getExactMatch(choices, arg); - - if (exactMatch.isPresent()) { - // Return this as a collection as this can get transformed by the subclass. - return Collections.singleton(exactMatch.get()); - } - - if (this.useRegex) { - Pattern pattern = this.getFormattedPattern(arg); - ret = StreamSupport.stream(choices.spliterator(), false).filter(element -> pattern.matcher(element).find()).collect(Collectors.toList()).stream().map(this::getValue).collect(Collectors.toList()); - } else { - Iterable startsWith = StreamSupport.stream(choices.spliterator(), false).filter(element -> element.regionMatches(true, 0, arg, 0, arg.length())).collect(Collectors.toList()); - ret = StreamSupport.stream(startsWith.spliterator(), false).map(this::getValue).collect(Collectors.toList()); - } - - if (!ret.iterator().hasNext()) { - throw args.createError(new LiteralText(String.format("No values matching pattern '%s' present for %s!", arg, this.getKey() == null - ? nullKeyArg : this.getKey()))); - } - - return ret; - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - Iterable choices = this.getChoices(src); - final Optional nextArg = args.nextIfPresent(); - - if (nextArg.isPresent()) { - if (this.useRegex) { - choices = StreamSupport.stream(choices.spliterator(), false).filter(input -> this.getFormattedPattern(nextArg.get()).matcher(input).find()).collect(Collectors.toList()); - } else { - String arg = nextArg.get(); - choices = StreamSupport.stream(choices.spliterator(), false).filter(input -> input.regionMatches(true, 0, arg, 0, arg.length())).collect(Collectors.toList()); - } - } - - return ImmutableList.copyOf(choices); - } - - Pattern getFormattedPattern(String input) { - if (!input.startsWith("^")) { // Anchor matches to the beginning -- this lets us use find() - input = "^" + input; - } - - return Pattern.compile(input, Pattern.CASE_INSENSITIVE); - } - - /** - * Tests a string against a set of valid choices to see if it is a - * case-insensitive match. - * - * @param choices The choices available to match against - * @param potentialChoice The potential choice - * @return If matched, an {@link Optional} containing the matched value - */ - protected Optional getExactMatch(final Iterable choices, final String potentialChoice) { - return Optional.ofNullable(Iterables.tryFind(choices, potentialChoice::equalsIgnoreCase).orNull()).map(this::getValue); - } - - /** - * Gets the available choices for this command source. - * - * @param source The source requesting choices - * @return the possible choices - */ - protected abstract Iterable getChoices(PermissibleCommandSource source); - - /** - * Gets the value for a given choice. For any result in - * {@link #getChoices(PermissibleCommandSource)}, this must return a non-null value. - * Otherwise, an {@link IllegalArgumentException} may be throw. - * - * @param choice The specified choice - * @return the choice's value - * @throws IllegalArgumentException if the input string is not any return - * value of {@link #getChoices(PermissibleCommandSource)} - */ - protected abstract Object getValue(String choice) throws IllegalArgumentException; -} diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SingleArg.java b/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SingleArg.java deleted file mode 100644 index 2f80950fe..000000000 --- a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SingleArg.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge.args.parsing; - -import com.google.common.base.MoreObjects; -import com.google.common.base.Objects; - -/** - * This represents a single argument with its start and end indexes - * in the associated raw input string. - */ -public class SingleArg { - private final String value; - private final int startIdx; - private final int endIdx; - - /** - * Create a new argument. - * - * @param value The argument string - * @param startIdx The starting index of {@code value} in an input string - * @param endIdx The ending index of {@code value} in an input string - */ - public SingleArg(String value, int startIdx, int endIdx) { - this.value = value; - this.startIdx = startIdx; - this.endIdx = endIdx; - } - - /** - * Gets the string used. - * - * @return The string used - */ - public String getValue() { - return this.value; - } - - /** - * Gets the starting index. - * - * @return The starting index - */ - public int getStartIdx() { - return this.startIdx; - } - - /** - * Gets the ending index. - * - * @return The ending index - */ - public int getEndIdx() { - return this.endIdx; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - - if (!(o instanceof SingleArg)) { - return false; - } - - SingleArg singleArg = (SingleArg) o; - return this.startIdx == singleArg.startIdx - && this.endIdx == singleArg.endIdx - && Objects.equal(this.value, singleArg.value); - } - - @Override - public int hashCode() { - return Objects.hashCode(this.value, this.startIdx, this.endIdx); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("value", this.value) - .add("startIdx", this.startIdx) - .add("endIdx", this.endIdx) - .toString(); - } -} diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/MinecraftClientAccessor.java b/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/MinecraftClientAccessor.java deleted file mode 100644 index baf176236..000000000 --- a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/MinecraftClientAccessor.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.impl.command; - -import net.minecraft.server.MinecraftServer; - -public interface MinecraftClientAccessor { - MinecraftServer getMinecraftServer(); -} diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OptionalCommandElement.java b/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OptionalCommandElement.java deleted file mode 100644 index 8abf3f5be..000000000 --- a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OptionalCommandElement.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.List; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandContext; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class OptionalCommandElement extends CommandElement { - private final CommandElement element; - @Nullable - private final Object value; - private final boolean considerInvalidFormatEmpty; - - public OptionalCommandElement(CommandElement element, @Nullable Object value, boolean considerInvalidFormatEmpty) { - super(null); - this.element = element; - this.value = value; - this.considerInvalidFormatEmpty = considerInvalidFormatEmpty; - } - - @Override - public void parse(PermissibleCommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException { - if (!args.hasNext()) { - Text key = this.element.getKey(); - - if (key != null && this.value != null) { - context.putArg(key.computeValue(), this.value); - } - - return; - } - - CommandArgs.Snapshot startState = args.getSnapshot(); - - try { - this.element.parse(source, args, context); - } catch (ArgumentParseException ex) { - if (this.considerInvalidFormatEmpty || args.hasNext()) { // If there are more args, suppress. Otherwise, throw the error - args.applySnapshot(startState); - - if (this.element.getKey() != null && this.value != null) { - context.putArg(this.element.getUntranslatedKey(), this.value); - } - } else { - throw ex; - } - } - } - - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - return args.hasNext() ? null : this.element.parseValue(source, args); - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - return this.element.complete(src, args, context); - } - - @Override - public Text getUsage(PermissibleCommandSource src) { - final Text containingUsage = this.element.getUsage(src); - - if (containingUsage.asUnformattedString().isEmpty()) { - return new LiteralText(""); - } - - return new LiteralText("[" + this.element.getUsage(src) + "]"); - } -} diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/PermissionCommandElement.java b/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/PermissionCommandElement.java deleted file mode 100644 index 151c83ab8..000000000 --- a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/PermissionCommandElement.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.List; - -import com.google.common.collect.ImmutableList; -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandContext; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class PermissionCommandElement extends CommandElement { - private final CommandElement element; - private final String permission; - private final boolean isOptional; - - public PermissionCommandElement(CommandElement element, String permission, boolean isOptional) { - super(element.getKey()); - this.element = element; - this.permission = permission; - this.isOptional = isOptional; - } - - @Nullable - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - if (this.checkPermission(source, args)) { - return this.element.parseValue(source, args); - } - - return null; - } - - private boolean checkPermission(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - boolean hasPermission = source.hasPermission(this.permission); - - if (!hasPermission && !this.isOptional) { - Text key = this.getKey(); - throw args.createError(new LiteralText(String.format("You do not have permission to use the %s argument", key != null ? key : "unknown"))); - } - - return hasPermission; - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - boolean flag = /*src.hasPermission(this.permission)*/ true; - - if (!flag) { - return ImmutableList.of(); - } - - return this.element.complete(src, args, context); - } - - @Override - public void parse(PermissibleCommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException { - if (this.checkPermission(source, args)) { - this.element.parse(source, args, context); - } - } - - @Override - public Text getUsage(PermissibleCommandSource src) { - if (this.isOptional && !src.hasPermission(this.permission)) { - return new LiteralText(""); - } - - return this.element.getUsage(src); - } -} diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/PlayerCommandElement.java b/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/PlayerCommandElement.java index af467fb40..65405c484 100644 --- a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/PlayerCommandElement.java +++ b/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/PlayerCommandElement.java @@ -95,6 +95,6 @@ private PlayerEntity tryReturnSource(PermissibleCommandSource source, CommandArg @Override public Text getUsage(PermissibleCommandSource src) { - return src != null && this.returnSource ? new LiteralText("[" + super.getUsage(src) + "]") : super.getUsage(src); + return src != null && this.returnSource ? new LiteralText("[" + super.getUsage(src).asUnformattedString() + "]") : super.getUsage(src); } } diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/command/MinecraftClientMixin.java b/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/command/MinecraftClientMixin.java deleted file mode 100644 index 131b5c306..000000000 --- a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/command/MinecraftClientMixin.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.command; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.integrated.IntegratedServer; - -import net.legacyfabric.fabric.impl.command.MinecraftClientAccessor; - -@Mixin(MinecraftClient.class) -public abstract class MinecraftClientMixin implements MinecraftClientAccessor { - @Shadow - public abstract IntegratedServer getServer(); - - @Override - public MinecraftServer getMinecraftServer() { - return this.getServer(); - } -} diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/command/MinecraftServerMixin.java b/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/command/MinecraftServerMixin.java deleted file mode 100644 index 397b46b4c..000000000 --- a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/command/MinecraftServerMixin.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.command; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -import net.minecraft.server.MinecraftServer; - -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -@Mixin(MinecraftServer.class) -public abstract class MinecraftServerMixin implements PermissibleCommandSource { - @Shadow - public abstract boolean isDedicated(); - - @Override - public boolean hasPermission(String perm) { - return true; - } -} diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/resources/fabric.mod.json b/legacy-fabric-command-api-v2/1.12.2/src/main/resources/fabric.mod.json index 5ff821a2a..83dca385f 100644 --- a/legacy-fabric-command-api-v2/1.12.2/src/main/resources/fabric.mod.json +++ b/legacy-fabric-command-api-v2/1.12.2/src/main/resources/fabric.mod.json @@ -28,9 +28,7 @@ ] }, "description": "Powerful Command API that uses SpongeAPI's command api", - "mixins": [ - "legacy-fabric-sponge-command-api-v2.mixins.json" - ], + "mixins": [], "custom": { "modmenu": { "badges": [ "library" ], diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/resources/legacy-fabric-sponge-command-api-v2.mixins.json b/legacy-fabric-command-api-v2/1.12.2/src/main/resources/legacy-fabric-sponge-command-api-v2.mixins.json deleted file mode 100644 index 5ac1b89f3..000000000 --- a/legacy-fabric-command-api-v2/1.12.2/src/main/resources/legacy-fabric-sponge-command-api-v2.mixins.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "required": true, - "package": "net.legacyfabric.fabric.mixin.command", - "compatibilityLevel": "JAVA_8", - "mixins": [ - "MinecraftServerMixin" - ], - "client": [ - "MinecraftClientMixin" - ], - "injectors": { - "defaultRequire": 1 - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/StringType.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/StringType.java deleted file mode 100644 index f294fb603..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/StringType.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.api.command.v2; - -/** - * Specifies a method to parse {@link String}s in a command. - */ -public enum StringType { - SINGLE_WORD(false), - GREEDY_PHRASE(true); - - private final boolean all; - - StringType(boolean all) { - this.all = all; - } - - public boolean isAll() { - return this.all; - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandException.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandException.java deleted file mode 100644 index 6d65de8be..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandException.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge; - -import net.minecraft.text.Text; - -/** - * Thrown when an executed command raises an error or when execution of - * the command failed. - */ -public class CommandException extends TextMessageException { - private static final long serialVersionUID = 4626722485860074825L; - - private final boolean includeUsage; - - /** - * Constructs a new {@link CommandException} with the given message. - * - * @param message The detail message - */ - public CommandException(Text message) { - this(message, false); - } - - /** - * Constructs a new {@link CommandException} with the given message and - * the given cause. - * - * @param message The detail message - * @param cause The cause - */ - public CommandException(Text message, Throwable cause) { - this(message, cause, false); - } - - /** - * Constructs a new {@link CommandException} with the given message. - * - * @param message The detail message - * @param includeUsage Whether to include usage in the exception - */ - public CommandException(Text message, boolean includeUsage) { - super(message); - this.includeUsage = includeUsage; - } - - /** - * Constructs a new {@link CommandException} with the given message and - * the given cause. - * - * @param message The detail message - * @param cause The cause - * @param includeUsage Whether to include the usage in the exception - */ - public CommandException(Text message, Throwable cause, boolean includeUsage) { - super(message, cause); - this.includeUsage = includeUsage; - } - - /** - * Gets whether the exception should include usage in - * the presentation of the exception/stack-trace. - * - * @return Whether to include usage in the exception - */ - public boolean shouldIncludeUsage() { - return this.includeUsage; - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandMessageFormatting.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandMessageFormatting.java deleted file mode 100644 index f6ca1bf02..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandMessageFormatting.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; - -public class CommandMessageFormatting { - private CommandMessageFormatting() { - } - - public static final Text PIPE_TEXT = new LiteralText("|"); - public static final Text SPACE_TEXT = new LiteralText(" "); - public static final Text STAR_TEXT = new LiteralText("*"); - public static final Text LT_TEXT = new LiteralText("<"); - public static final Text GT_TEXT = new LiteralText(">"); - public static final Text ELLIPSIS_TEXT = new LiteralText("…"); - - /** - * Format text to be output as an error directly to a sender. Not necessary - * when creating an exception to be thrown - * - * @param error The error message - * @return The formatted error message. - */ - public static Text error(Text error) { - return error.setStyle(error.getStyle().setFormatting(Formatting.RED)); - } - - /** - * Format text to be output as a debug message directly to a sender. - * - * @param debug The debug message - * @return The formatted debug message. - */ - public static Text debug(Text debug) { - return debug.setStyle(debug.getStyle().setFormatting(Formatting.GRAY)); - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandNotFoundException.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandNotFoundException.java deleted file mode 100644 index 23d2b1455..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandNotFoundException.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge; - -import com.google.common.base.Preconditions; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -/** - * This exception is thrown when a sender tries to execute a command that does - * not exist. - */ -public class CommandNotFoundException extends CommandException { - private static final long serialVersionUID = -7714518367616848051L; - - private final String command; - - /** - * Create an exception with the default message. - * - * @param command The command that was queried for - */ - public CommandNotFoundException(String command) { - this(new LiteralText("No such command"), command); - } - - /** - * Create an exception with a custom message. - * - * @param message The message - * @param command The command that was queried for - */ - public CommandNotFoundException(Text message, String command) { - super(message); - this.command = Preconditions.checkNotNull(command, "command"); - } - - /** - * Returns the command that was queried for. - * - * @return The command - */ - public String getCommand() { - return this.command; - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandPermissionException.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandPermissionException.java deleted file mode 100644 index 0711108f2..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandPermissionException.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -/** - * This exception is thrown when a subject does not have permission to execute - * a command. - */ -public class CommandPermissionException extends CommandException { - private static final long serialVersionUID = -6057386975881181213L; - - /** - * Create an exception with the default message. - */ - public CommandPermissionException() { - this(new LiteralText("You do not have permission to use this command!")); - } - - /** - * Create a permissions exception with a custom message. - * - * @param message The message - */ - public CommandPermissionException(Text message) { - super(message); - } - - /** - * Create a permissions exception with a custom message and cause. - * - * @param message the message - * @param cause the cause - */ - public CommandPermissionException(Text message, Throwable cause) { - super(message, cause); - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/InvocationCommandException.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/InvocationCommandException.java deleted file mode 100644 index 5501a12ab..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/InvocationCommandException.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge; - -import net.minecraft.text.Text; - -/** - * Thrown when invocation of a command fails, wrapping the exception that - * is thrown. - */ -public class InvocationCommandException extends CommandException { - private static final long serialVersionUID = 2123904283741023948L; - - /** - * Constructs a new exception with the given message and the given cause. - * - * @param message The detail message - * @param cause The cause - */ - public InvocationCommandException(Text message, Throwable cause) { - super(message, cause); - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/TextMessageException.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/TextMessageException.java deleted file mode 100644 index 44a7a58d1..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/TextMessageException.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge; - -import net.minecraft.text.Text; - -/** - * A subclass of Exception that contains a rich message that is an instance of - * {@link Text} rather than a String. This allows formatted and localized - * exception messages. - */ -public class TextMessageException extends Exception { - private static final long serialVersionUID = -5281221645176698853L; - - private final Text message; - - /** - * Constructs a new {@link TextMessageException}. - */ - public TextMessageException() { - this.message = null; - } - - /** - * Constructs a new {@link TextMessageException} with the given message. - * - * @param message The detail message - */ - public TextMessageException(Text message) { - this.message = message; - } - - /** - * Constructs a new {@link TextMessageException} with the given message and - * cause. - * - * @param message The detail message - * @param throwable The cause - */ - public TextMessageException(Text message, Throwable throwable) { - super(throwable); - this.message = message; - } - - /** - * Constructs a new {@link TextMessageException} with the given cause. - * - * @param throwable The cause - */ - public TextMessageException(Throwable throwable) { - super(throwable); - this.message = null; - } - - @Override - public String getMessage() { - Text message = this.getText(); - return message == null ? null : message.computeValue(); - } - - /** - * Returns the text message for this exception, or null if nothing is - * present. - * - * @return The text for this message - */ - public Text getText() { - return this.message; - } - - @Override - public String getLocalizedMessage() { - return this.getMessage(); - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/ArgumentParseException.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/ArgumentParseException.java deleted file mode 100644 index f099c1e43..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/ArgumentParseException.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge.args; - -import com.google.common.base.Strings; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.CommandException; - -/** - * Exception thrown when an error occurs while parsing arguments. - */ -public class ArgumentParseException extends CommandException { - private static final long serialVersionUID = -8555316116315990226L; - - private final String source; - private final int position; - - /** - * Return a new {@link ArgumentParseException} with the given message, source and position. - * - * @param message The message to use for this exception - * @param source The source string being parsed - * @param position The current position in the source string - */ - public ArgumentParseException(Text message, String source, int position) { - super(message, true); - this.source = source; - this.position = position; - } - - /** - * Return a new {@link ArgumentParseException} with the given message, cause, source and position. - * - * @param message The message to use for this exception - * @param cause The cause for this exception - * @param source The source string being parsed - * @param position The current position in the source string - */ - public ArgumentParseException(Text message, Throwable cause, String source, int position) { - super(message, cause, true); - this.source = source; - this.position = position; - } - - @Override - public Text getText() { - Text superText = super.getText(); - - if (this.source == null || this.source.isEmpty()) { - return super.getText(); - } else if (superText == null) { - return new LiteralText(this.getAnnotatedPosition()); - } else { - return new LiteralText(superText.asUnformattedString() + "\n" + this.getAnnotatedPosition()); - } - } - - private Text getSuperText() { - return super.getText(); - } - - /** - * Return a string pointing to the position of the arguments when this - * exception occurs. - * - * @return The appropriate position string - */ - public String getAnnotatedPosition() { - String source = this.source; - int position = this.position; - - if (source.length() > 80) { - if (position >= 37) { - int startPos = position - 37; - int endPos = Math.min(source.length(), position + 37); - - if (endPos < source.length()) { - source = "..." + source.substring(startPos, endPos) + "..."; - } else { - source = "..." + source.substring(startPos, endPos); - } - - position -= 40; - } else { - source = source.substring(0, 77) + "..."; - } - } - - return source + "\n" + Strings.repeat(" ", position) + "^"; - } - - /** - * Gets the position of the last fetched argument in the provided source - * string. - * - * @return The source string to get position for - */ - public int getPosition() { - return this.position; - } - - /** - * Returns the source string arguments are being parsed from. - * - * @return The source string - */ - public String getSourceString() { - return this.source; - } - - /** - * An {@link ArgumentParseException} where the usage is already specified. - */ - public static class WithUsage extends ArgumentParseException { - private static final long serialVersionUID = -786214501012293475L; - - private final Text usage; - - public WithUsage(ArgumentParseException wrapped, Text usage) { - super(wrapped.getSuperText(), wrapped.getCause(), wrapped.getSourceString(), wrapped.getPosition()); - this.usage = usage; - } - - /** - * Gets the usage associated with this exception. - * - * @return The usage - */ - public Text getUsage() { - return this.usage; - } - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/ChildCommandElementExecutor.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/ChildCommandElementExecutor.java index 9bb6d68fd..a6af47f05 100644 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/ChildCommandElementExecutor.java +++ b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/ChildCommandElementExecutor.java @@ -221,10 +221,10 @@ public void parse(PermissibleCommandSource source, CommandArgs args, CommandCont if (ex instanceof ArgumentParseException.WithUsage) { // This indicates a previous child failed, so we just prepend our child - throw new ArgumentParseException.WithUsage(ex, new LiteralText(key + " " + ((ArgumentParseException.WithUsage) ex).getUsage())); + throw new ArgumentParseException.WithUsage(ex, new LiteralText(key + " " + ((ArgumentParseException.WithUsage) ex).getUsage().asUnformattedString())); } - throw new ArgumentParseException.WithUsage(ex, new LiteralText(key + " " + mapping.getCallable().getUsage(source))); + throw new ArgumentParseException.WithUsage(ex, new LiteralText(key + " " + mapping.getCallable().getUsage(source).asUnformattedString())); } } else { // Not a child, so let's continue with the fallback. diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandArgs.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandArgs.java deleted file mode 100644 index 8858be838..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandArgs.java +++ /dev/null @@ -1,348 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge.args; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Collectors; - -import com.google.common.collect.ImmutableList; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.parsing.SingleArg; - -/** - * Holder for command arguments. - */ -public final class CommandArgs { - private final String rawInput; - private final List args; - private int index = -1; - - /** - * Create a new CommandArgs instance with the given raw input and arguments. - * - * @param rawInput Raw input - * @param args Arguments extracted from the raw input - */ - public CommandArgs(String rawInput, List args) { - this.rawInput = rawInput; - this.args = new ArrayList<>(args); - } - - /** - * Return whether more arguments remain to be read. - * - * @return Whether more arguments remain - */ - public boolean hasNext() { - return this.index + 1 < this.args.size(); - } - - /** - * Returns true if: - * - *
    - *
  • The next element returned by {@link #next()} is the last
  • - *
  • {@link #hasNext()} is false
  • - *
- * Else returns false. - * - * @return True if a completion can occur - */ - public boolean canComplete() { - return this.index + 2 >= this.args.size(); - } - - /** - * Try to read the next argument without advancing the current index. - * - * @return The next argument - * @throws ArgumentParseException if not enough arguments are present - */ - public String peek() throws ArgumentParseException { - if (!this.hasNext()) { - throw this.createError(new LiteralText("Not enough arguments")); - } - - return this.args.get(this.index + 1).getValue(); - } - - /** - * Try to read the next argument, advancing the current index if successful. - * - * @return The next argument - * @throws ArgumentParseException if not enough arguments are present - */ - public String next() throws ArgumentParseException { - if (!this.hasNext()) { - throw this.createError(new LiteralText("Not enough arguments!")); - } - - return this.args.get(++this.index).getValue(); - } - - /** - * Try to read the next argument, advancing the current index if successful - * or returning an absent optional if not. - * - * @return The optional next argument. - */ - public Optional nextIfPresent() { - return this.hasNext() ? Optional.of(this.args.get(++this.index).getValue()) : Optional.empty(); - } - - /** - * Create a parse exception with the provided message which has the position - * of the last parsed argument attached. The returned exception must be - * thrown at the target - * - * @param message The message for the exception - * @return the newly created, but unthrown exception - */ - public ArgumentParseException createError(Text message) { - return new ArgumentParseException(message, this.rawInput, this.index < 0 ? 0 : this.args.get(this.index).getStartIdx()); - } - - /** - * Gets a list of all arguments as a string. The returned list is immutable. - * - * @return all arguments - */ - public List getAll() { - return Collections.unmodifiableList(this.args.stream().map(SingleArg::getValue).collect(Collectors.toList())); - } - - List getArgs() { - return this.args; - } - - /** - * Return this arguments object's current state. Can be used to reset with - * the {@link #setState(Object)} method. - * - * @return The current state - * @deprecated Use {@link #getSnapshot()} and - * {@link #applySnapshot(Snapshot)} instead - */ - @Deprecated - public Object getState() { - return this.getSnapshot(); - } - - /** - * Restore the arguments object's state to a state previously used. - * - * @param state the previous state - * @deprecated Use {@link #getSnapshot()} and - * {@link #applySnapshot(Snapshot)} instead - */ - @Deprecated - public void setState(Object state) { - if (!(state instanceof Snapshot)) { - throw new IllegalArgumentException("Provided state was not of appropriate format returned by getState!"); - } - - this.applySnapshot((Snapshot) state, false); // keep parity with before - } - - /** - * Return the raw string used to provide input to this arguments object. - * - * @return The raw input - */ - public String getRaw() { - return this.rawInput; - } - - /** - * Get an arg at the specified position. - * - * @param index index of the element to return - */ - public String get(int index) { - return this.args.get(index).getValue(); - } - - /** - * Insert an arg as the next arg to be returned by {@link #next()}. - * - * @param value The argument to insert - */ - public void insertArg(String value) { - int index = this.index < 0 ? 0 : this.args.get(this.index).getEndIdx(); - this.args.add(this.index + 1, new SingleArg(value, index, index)); - } - - /** - * Remove the arguments parsed between startState and endState. - * - * @param startState The starting state - * @param endState The ending state - * @deprecated Use with {@link #getSnapshot()} instead of - * {@link #getState()} with {@link #removeArgs(Snapshot, Snapshot)} - */ - @Deprecated - public void removeArgs(Object startState, Object endState) { - if (!(startState instanceof Integer) || !(endState instanceof Integer)) { - throw new IllegalArgumentException("One of the states provided was not of the correct type!"); - } - - this.removeArgs((int) startState, (int) endState); - } - - /** - * Remove the arguments parsed between two snapshots. - * - * @param startSnapshot The starting state - * @param endSnapshot The ending state - */ - public void removeArgs(Snapshot startSnapshot, Snapshot endSnapshot) { - this.removeArgs(startSnapshot.index, endSnapshot.index); - } - - private void removeArgs(int startIdx, int endIdx) { - if (this.index >= startIdx) { - if (this.index < endIdx) { - this.index = startIdx - 1; - } else { - this.index -= (endIdx - startIdx) + 1; - } - } - - for (int i = startIdx; i <= endIdx; ++i) { - this.args.remove(startIdx); - } - } - - /** - * Returns the number of arguments. - * - * @return the number of arguments - */ - public int size() { - return this.args.size(); - } - - /** - * Go back to the previous argument. - */ - void previous() { - if (this.index > -1) { - --this.index; - } - } - - /** - * Gets the current position in raw input. - * - * @return the raw position - */ - public int getRawPosition() { - return this.index < 0 ? 0 : this.args.get(this.index).getStartIdx(); - } - - /** - * Gets a snapshot of the data inside this context to allow it to be - * restored later. - * - * @return The {@link Snapshot} containing the current state of the - * {@link CommandArgs} - */ - public Snapshot getSnapshot() { - return new Snapshot(this.index, this.args); - } - - /** - * Resets a {@link CommandArgs} to a previous state using a previously - * created {@link Snapshot}. - * - * @param snapshot The {@link Snapshot} to restore this context - * with - */ - public void applySnapshot(Snapshot snapshot) { - this.applySnapshot(snapshot, true); - } - - /** - * Resets a {@link CommandArgs} to a previous state using a previously - * created {@link Snapshot}. - * - *

If resetArgs is set to false, this snapshot will not reset the - * argument list to its previous state, only the index.

- * - * @param snapshot The {@link Snapshot} to restore this context - * with - * @param resetArgs Whether to restore the argument list - */ - public void applySnapshot(Snapshot snapshot, boolean resetArgs) { - this.index = snapshot.index; - - if (resetArgs) { - this.args.clear(); - this.args.addAll(snapshot.args); - } - } - - /** - * A snapshot of a {@link CommandArgs}. This object does not contain any - * public API methods, a snapshot should be considered a black box. - */ - public final class Snapshot { - final int index; - final ImmutableList args; - - Snapshot(int index, List args) { - this.index = index; - this.args = ImmutableList.copyOf(args); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - - if (o == null || this.getClass() != o.getClass()) { - return false; - } - - Snapshot snapshot = (Snapshot) o; - return this.index == snapshot.index - && Objects.equals(this.args, snapshot.args); - } - - @Override - public int hashCode() { - return Objects.hash(this.index, this.args); - } - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandContext.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandContext.java deleted file mode 100644 index 1907dfecb..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandContext.java +++ /dev/null @@ -1,337 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge.args; - -import java.util.Collection; -import java.util.Collections; -import java.util.NoSuchElementException; -import java.util.Optional; -import java.util.Set; - -import com.google.common.base.Preconditions; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; -import com.google.common.collect.Sets; -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; -import net.minecraft.text.TranslatableText; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.CommandException; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; -import net.legacyfabric.fabric.api.util.Location; - -/** - * Context that a command is executed in. - * This object stores parsed arguments from other commands - */ -public final class CommandContext { - /** - * The argument key for a target block position that may be present - * during tab completion, of type {@link Location Location<World>}. - */ - public static final String TARGET_BLOCK_ARG = "targetblock-pos048658"; // Random junk afterwards so we don't accidentally conflict with other args - - /** - * The argument key to indicate that a tab completion is taking place. - */ - public static final String TAB_COMPLETION = "tab-complete-50456"; // Random junk afterwards so we don't accidentally conflict with other args - - private final Multimap parsedArgs; - private final Set definedFlags; - - /** - * Create a new empty CommandContext. - */ - public CommandContext() { - this.parsedArgs = ArrayListMultimap.create(); - this.definedFlags = Sets.newHashSet(); - } - - /** - * Gets all values for the given argument. May return an empty list if no - * values are present. - * - * @param key The key to get values for - * @param the type of value to get - * @return the collection of all values - */ - @SuppressWarnings("unchecked") - public Collection getAll(String key) { - return Collections.unmodifiableCollection((Collection) this.parsedArgs.get(key)); - } - - /** - * Gets all values for the given argument. May return an empty list if no - * values are present. - * - * @param key The key to get values for - * @param the type of value to get - * @return the collection of all values - */ - public Collection getAll(Text key) { - return this.getAll(CommandContext.textToArgKey(key)); - } - - /** - * Gets the value for the given key if the key has only one value. - * - *

An empty {@link Optional} indicates that there are either zero or more - * than one values for the given key. Use {@link #hasAny(Text)} to verify - * which.

- * - * @param key the key to get - * @param the expected type of the argument - * @return the argument - */ - @SuppressWarnings("unchecked") - public Optional getOne(String key) { - Collection values = this.parsedArgs.get(key); - - if (values.size() != 1) { - return Optional.empty(); - } - - return Optional.ofNullable((T) values.iterator().next()); - } - - /** - * Gets the value for the given key if the key has only one value. - * - *

An empty {@link Optional} indicates that there are either zero or more - * than one values for the given key. Use {@link #hasAny(Text)} to verify - * which.

- * - * @param key the key to get - * @param the expected type of the argument - * @return the argument - */ - public Optional getOne(Text key) { - return this.getOne(CommandContext.textToArgKey(key)); - } - - /** - * Gets the value for the given key if the key has only one value, throws an - * exception otherwise. - * - * @param key the key to get - * @param the expected type of the argument - * @return the argument - * @throws NoSuchElementException if there is no element with the - * associated key - * @throws IllegalArgumentException if there are more than one element - * associated with the key (thus, the argument is illegal in this - * context) - * @throws ClassCastException if the element type is not what is expected - * by the caller - */ - @SuppressWarnings("unchecked") - public T requireOne(String key) throws NoSuchElementException, IllegalArgumentException, ClassCastException { - Collection values = this.parsedArgs.get(key); - - if (values.size() == 1) { - return (T) values.iterator().next(); - } else if (values.isEmpty()) { - throw new NoSuchElementException(); - } - - throw new IllegalArgumentException(); - } - - /** - * Gets the value for the given key if the key has only one value, throws an - * exception otherwise. - * - * @param key the key to get - * @param the expected type of the argument - * @return the argument - * @throws NoSuchElementException if there is no element with the - * associated key - * @throws IllegalArgumentException if there are more than one element - * associated with the key (thus, the argument is illegal in this - * context) - * @throws ClassCastException if the element type is not what is expected - */ - public T requireOne(Text key) - throws NoSuchElementException, IllegalArgumentException, ClassCastException { - return this.requireOne(CommandContext.textToArgKey(key)); - } - - /** - * Insert an argument into this context. - * - * @param key the key to store the arg under - * @param value the value for this argument - */ - public void putArg(String key, Object value) { - Preconditions.checkNotNull(value, "value"); - this.parsedArgs.put(key, value); - } - - /** - * Insert an argument into this context. - * - * @param key the key to store the arg under - * @param value the value for this argument - */ - public void putArg(Text key, Object value) { - this.putArg(CommandContext.textToArgKey(key), value); - } - - /** - * Defines the flag as being present when parsing this context. - * - * @param key the key for the flag defined - */ - public void addFlag(String key) { - this.definedFlags.add(key); - } - - /** - * Defines the flag as being present when parsing this context. - * - * @param key the key for the flag defined - */ - public void addFlag(Text key) { - this.addFlag(CommandContext.textToArgKey(key)); - } - - /** - * Perform a permissions check, throwing an exception if the required - * permissions are not present. - * - * @param commander the source to check against - * @param permission The permission to check - * @throws CommandException if the source does not have permission - */ - public void checkPermission(PermissibleCommandSource commander, String permission) throws CommandException { - if (!commander.hasPermission(permission)) { - throw new CommandException(new LiteralText("You do not have permission to use this command!")); - } - } - - /** - * Returns whether this context has any value for the given argument key. - * - * @param key The key to look up - * @return whether there are any values present - */ - public boolean hasAny(String key) { - return this.parsedArgs.containsKey(key); - } - - /** - * Returns whether this context has any value for the given argument key. - * - * @param key The key to look up - * @return whether there are any values present - */ - public boolean hasAny(Text key) { - return this.hasAny(CommandContext.textToArgKey(key)); - } - - /** - * Returns whether the given flag has been defined in this context. - * - * @param key The key to look up - * @return whether the flag is defined - */ - public boolean hasFlag(String key) { - return this.definedFlags.contains(key); - } - - /** - * Returns whether the given flag has been defined in this context. - * - * @param key The key to look up - * @return whether the flag is defined - */ - public boolean hasFlag(Text key) { - return this.hasFlag(CommandContext.textToArgKey(key)); - } - - /** - * Gets a snapshot of the data inside this context to allow it to be - * restored later. - * - *

This is only guaranteed to create a shallow copy of the - * backing store. If any value is mutable, any changes to that value - * will be reflected in this snapshot. It is therefore not recommended - * that you keep this snapshot around for longer than is necessary.

- * - * @return The {@link Snapshot} containing the current state of the - * {@link CommandContext} - */ - public Snapshot createSnapshot() { - return new Snapshot(this.parsedArgs, this.definedFlags); - } - - /** - * Resets a {@link CommandContext} to a previous state using a previously - * created {@link Snapshot}. - * - * @param snapshot The {@link Snapshot} to restore this context with - */ - public void applySnapshot(Snapshot snapshot) { - this.parsedArgs.clear(); - this.parsedArgs.putAll(snapshot.args); - this.definedFlags.clear(); - this.definedFlags.addAll(snapshot.flags); - } - - /** - * A snapshot of a {@link CommandContext}. This object does not contain any - * public API methods, a snapshot should be considered a black box. - */ - public static final class Snapshot { - final Multimap args; - final Set flags; - - Snapshot(Multimap args, Set flags) { - this.args = ArrayListMultimap.create(args); - this.flags = Sets.newHashSet(flags); - } - } - - /** - * Converts a {@link Text} into a String key. - * - * @param key the text to be converted into a string key - * @return the string key. if {@code key} is a {@link TranslatableText}, the translation key. - */ - public static String textToArgKey(@Nullable Text key) { - if (key == null) { - return null; - } - - if (key instanceof TranslatableText) { // Use translation key - return ((TranslatableText) key).getKey(); - } - - return key.computeValue(); - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandElement.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandElement.java deleted file mode 100644 index 215187dbf..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandElement.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge.args; - -import java.util.List; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; -import net.minecraft.text.TranslatableText; - -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -/** - * Represents a command argument element. - */ -public abstract class CommandElement { - @Nullable - private final Text key; - - protected CommandElement(@Nullable Text key) { - this.key = key; - } - - /** - * Return the key to be used for this object. - * - * @return the user-facing representation of the key - */ - @Nullable - public Text getKey() { - return this.key; - } - - /** - * Return the plain key, to be used when looking up this command element in - * a {@link CommandContext}. If the key is a {@link TranslatableText}, this - * is the translation's id. Otherwise, this is the result of - * {@link Text#asString()} ()} ()}. - * - * @return the raw key - */ - @Nullable - public String getUntranslatedKey() { - return CommandContext.textToArgKey(this.key); - } - - /** - * Attempt to extract a value for this element from the given arguments and - * put it in the given context. This method normally delegates to - * {@link #parseValue(PermissibleCommandSource, CommandArgs)} for getting the values. - * This method is expected to have no side-effects for the source, meaning - * that executing it will not change the state of the {@link PermissibleCommandSource} - * in any way. - * - * @param source The source to parse for - * @param args The args to extract from - * @param context The context to supply to - * @throws ArgumentParseException if unable to extract a value - */ - public void parse(PermissibleCommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException { - Object val = this.parseValue(source, args); - String key = this.getUntranslatedKey(); - - if (key != null && val != null) { - if (val instanceof Iterable) { - for (Object ent : ((Iterable) val)) { - context.putArg(key, ent); - } - } else { - context.putArg(key, val); - } - } - } - - /** - * Attempt to extract a value for this element from the given arguments. - * This method is expected to have no side-effects for the source, meaning - * that executing it will not change the state of the {@link PermissibleCommandSource} - * in any way. - * - * @param source The source to parse for - * @param args the arguments - * @return The extracted value - * @throws ArgumentParseException if unable to extract a value - */ - @Nullable - public abstract Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException; - - /** - * Fetch completions for command arguments. - * - * @param src The source requesting tab completions - * @param args The arguments currently provided - * @param context The context to store state in - * @return Any relevant completions - */ - public abstract List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context); - - /** - * Return a usage message for this specific argument. - * - * @param src The source requesting usage - * @return The formatted usage - */ - public Text getUsage(PermissibleCommandSource src) { - return this.getKey() == null ? new LiteralText("") : new LiteralText("<" + this.getKey() + ">"); - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandFlags.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandFlags.java index 9e1a5ea4c..c0927bf6a 100644 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandFlags.java +++ b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandFlags.java @@ -183,7 +183,7 @@ public Text getUsage(PermissibleCommandSource src) { if (usage.asUnformattedString().trim().length() > 0) { builder.add(" "); - builder.add(usage); + builder.add(usage.asUnformattedString()); } builder.add("]"); diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/KeyElement.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/KeyElement.java deleted file mode 100644 index 1fc48c36b..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/KeyElement.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge.args; - -import java.util.Collections; -import java.util.List; - -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -/** - * Parent class that specifies elements as having no tab completions. - * Useful for inputs with a very large domain, like strings and integers. - */ -public abstract class KeyElement extends CommandElement { - protected KeyElement(Text key) { - super(key); - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - return Collections.emptyList(); - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/InputTokenizer.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/InputTokenizer.java deleted file mode 100644 index 7b838414a..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/InputTokenizer.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge.args.parsing; - -import java.util.List; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; - -public interface InputTokenizer { - /** - * Use an input string tokenizer that supports quoted arguments and - * character escapes. - * - *

Forcing lenient to true makes the following apply:

- * - *
    - *
  • Unclosed quotations are treated as a single string from the - * opening quotation to the end of the arguments rather than throwing - * an exception
  • - *
- * - * @param forceLenient Whether the tokenizer is forced into lenient mode - * @return the appropriate tokenizer - */ - static InputTokenizer quotedStrings(boolean forceLenient) { - return new QuotedStringTokenizer(true, forceLenient, false); - } - - /** - * Returns an input tokenizer that takes input strings and splits them by - * space. - * - * @return The appropriate tokenizer - */ - static InputTokenizer spaceSplitString() { - return SpaceSplitInputTokenizer.INSTANCE; - } - - /** - * Returns an input tokenizer that returns the input string as a single - * argument. - * - * @return The appropriate tokenizer - */ - static InputTokenizer rawInput() { - return RawStringInputTokenizer.INSTANCE; - } - - /** - * Take the input string and split it as appropriate into argument tokens. - * - * @param arguments The provided arguments - * @param lenient Whether to parse leniently - * @return The tokenized strings. Empty list if error occurs - * @throws ArgumentParseException if an invalid input is provided - */ - List tokenize(String arguments, boolean lenient) throws ArgumentParseException; -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/QuotedStringTokenizer.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/QuotedStringTokenizer.java deleted file mode 100644 index 256287791..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/QuotedStringTokenizer.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge.args.parsing; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import net.minecraft.text.LiteralText; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; - -/** - * Parser for converting a quoted string into a list of arguments. - * - *

Grammar is roughly (yeah, this is not really a proper grammar but it gives - * you an idea of what's happening:

- * - *
 WHITESPACE = Character.isWhiteSpace(codePoint)
- * CHAR := (all unicode)
- * ESCAPE := '\' CHAR
- * QUOTE = ' | "
- * UNQUOTED_ARG := (CHAR | ESCAPE)+ WHITESPACE
- * QUOTED_ARG := QUOTE (CHAR | ESCAPE)+ QUOTE
- * ARGS := ((UNQUOTED_ARG | QUOTED_ARG) WHITESPACE+)+
- */ -class QuotedStringTokenizer implements InputTokenizer { - private static final int CHAR_BACKSLASH = '\\'; - private static final int CHAR_SINGLE_QUOTE = '\''; - private static final int CHAR_DOUBLE_QUOTE = '"'; - private final boolean handleQuotedStrings; - private final boolean forceLenient; - private final boolean trimTrailingSpace; - - QuotedStringTokenizer(boolean handleQuotedStrings, boolean forceLenient, boolean trimTrailingSpace) { - this.handleQuotedStrings = handleQuotedStrings; - this.forceLenient = forceLenient; - this.trimTrailingSpace = trimTrailingSpace; - } - - @Override - public List tokenize(String arguments, boolean lenient) throws ArgumentParseException { - if (arguments.length() == 0) { - return Collections.emptyList(); - } - - final TokenizerState state = new TokenizerState(arguments, lenient); - List returnedArgs = new ArrayList<>(arguments.length() / 4); - - if (this.trimTrailingSpace) { - this.skipWhiteSpace(state); - } - - while (state.hasMore()) { - if (!this.trimTrailingSpace) { - this.skipWhiteSpace(state); - } - - int startIdx = state.getIndex() + 1; - String arg = this.nextArg(state); - returnedArgs.add(new SingleArg(arg, startIdx, state.getIndex())); - - if (this.trimTrailingSpace) { - this.skipWhiteSpace(state); - } - } - - return returnedArgs; - } - - // Parsing methods - - private void skipWhiteSpace(TokenizerState state) throws ArgumentParseException { - if (!state.hasMore()) { - return; - } - - while (state.hasMore() && Character.isWhitespace(state.peek())) { - state.next(); - } - } - - private String nextArg(TokenizerState state) throws ArgumentParseException { - StringBuilder argBuilder = new StringBuilder(); - - if (state.hasMore()) { - int codePoint = state.peek(); - - if (this.handleQuotedStrings && (codePoint == CHAR_DOUBLE_QUOTE || codePoint == CHAR_SINGLE_QUOTE)) { - // quoted string - this.parseQuotedString(state, codePoint, argBuilder); - } else { - this.parseUnquotedString(state, argBuilder); - } - } - - return argBuilder.toString(); - } - - private void parseQuotedString(TokenizerState state, int startQuotation, StringBuilder builder) throws ArgumentParseException { - // Consume the start quotation character - int nextCodePoint = state.next(); - - if (nextCodePoint != startQuotation) { - throw state.createException(new LiteralText(String.format("Actual next character '%c' did not match expected quotation character '%c'", - nextCodePoint, startQuotation))); - } - - while (true) { - if (!state.hasMore()) { - if (state.isLenient() || this.forceLenient) { - return; - } - - throw state.createException(new LiteralText("Unterminated quoted string found")); - } - - nextCodePoint = state.peek(); - - if (nextCodePoint == startQuotation) { - state.next(); - return; - } else if (nextCodePoint == CHAR_BACKSLASH) { - this.parseEscape(state, builder); - } else { - builder.appendCodePoint(state.next()); - } - } - } - - private void parseUnquotedString(TokenizerState state, StringBuilder builder) throws ArgumentParseException { - while (state.hasMore()) { - int nextCodePoint = state.peek(); - - if (Character.isWhitespace(nextCodePoint)) { - return; - } else if (nextCodePoint == CHAR_BACKSLASH) { - this.parseEscape(state, builder); - } else { - builder.appendCodePoint(state.next()); - } - } - } - - private void parseEscape(TokenizerState state, StringBuilder builder) throws ArgumentParseException { - state.next(); // Consume \ - builder.appendCodePoint(state.next()); // TODO: Unicode character escapes (\u00A7 type thing)? - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/RawStringInputTokenizer.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/RawStringInputTokenizer.java deleted file mode 100644 index fe46931e3..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/RawStringInputTokenizer.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge.args.parsing; - -import java.util.Collections; -import java.util.List; - -class RawStringInputTokenizer implements InputTokenizer { - static final RawStringInputTokenizer INSTANCE = new RawStringInputTokenizer(); - - private RawStringInputTokenizer() { - } - - @Override - public List tokenize(String arguments, boolean lenient) { - return Collections.singletonList(new SingleArg(arguments, 0, arguments.length())); - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SingleArg.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SingleArg.java deleted file mode 100644 index cf5ae6c7d..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SingleArg.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge.args.parsing; - -import com.google.common.base.Objects; - -/** - * This represents a single argument with its start and end indexes - * in the associated raw input string. - */ -public class SingleArg { - private final String value; - private final int startIdx; - private final int endIdx; - - /** - * Create a new argument. - * - * @param value The argument string - * @param startIdx The starting index of {@code value} in an input string - * @param endIdx The ending index of {@code value} in an input string - */ - public SingleArg(String value, int startIdx, int endIdx) { - this.value = value; - this.startIdx = startIdx; - this.endIdx = endIdx; - } - - /** - * Gets the string used. - * - * @return The string used - */ - public String getValue() { - return this.value; - } - - /** - * Gets the starting index. - * - * @return The starting index - */ - public int getStartIdx() { - return this.startIdx; - } - - /** - * Gets the ending index. - * - * @return The ending index - */ - public int getEndIdx() { - return this.endIdx; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - - if (!(o instanceof SingleArg)) { - return false; - } - - SingleArg singleArg = (SingleArg) o; - return this.startIdx == singleArg.startIdx - && this.endIdx == singleArg.endIdx - && Objects.equal(this.value, singleArg.value); - } - - @Override - public int hashCode() { - return Objects.hashCode(this.value, this.startIdx, this.endIdx); - } - - @Override - public String toString() { - return Objects.toStringHelper(this) - .add("value", this.value) - .add("startIdx", this.startIdx) - .add("endIdx", this.endIdx) - .toString(); - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SpaceSplitInputTokenizer.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SpaceSplitInputTokenizer.java deleted file mode 100644 index 3caa7d81d..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SpaceSplitInputTokenizer.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge.args.parsing; - -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Pattern; - -import com.google.common.collect.ImmutableList; - -class SpaceSplitInputTokenizer implements InputTokenizer { - public static final SpaceSplitInputTokenizer INSTANCE = new SpaceSplitInputTokenizer(); - private static final Pattern SPACE_REGEX = Pattern.compile("^[ ]*$"); - - private SpaceSplitInputTokenizer() { - } - - @Override - public List tokenize(String arguments, boolean lenient) { - if (SPACE_REGEX.matcher(arguments).matches()) { - return ImmutableList.of(); - } - - List ret = new ArrayList<>(); - int lastIndex = 0; - int spaceIndex; - - while ((spaceIndex = arguments.indexOf(" ")) != -1) { - if (spaceIndex != 0) { - ret.add(new SingleArg(arguments.substring(0, spaceIndex), lastIndex, lastIndex + spaceIndex)); - arguments = arguments.substring(spaceIndex); - } else { - arguments = arguments.substring(1); - } - - lastIndex += spaceIndex + 1; - } - - ret.add(new SingleArg(arguments, lastIndex, lastIndex + arguments.length())); - return ret; - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/TokenizerState.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/TokenizerState.java deleted file mode 100644 index a93a0515b..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/TokenizerState.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge.args.parsing; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; - -class TokenizerState { - private final boolean lenient; - private final String buffer; - private int index = -1; - - TokenizerState(String buffer, boolean lenient) { - this.buffer = buffer; - this.lenient = lenient; - } - - // Utility methods - public boolean hasMore() { - return this.index + 1 < this.buffer.length(); - } - - public int peek() throws ArgumentParseException { - if (!this.hasMore()) { - throw this.createException(new LiteralText("Buffer overrun while parsing args")); - } - - return this.buffer.codePointAt(this.index + 1); - } - - public int next() throws ArgumentParseException { - if (!this.hasMore()) { - throw this.createException(new LiteralText("Buffer overrun while parsing args")); - } - - return this.buffer.codePointAt(++this.index); - } - - public ArgumentParseException createException(Text message) { - return new ArgumentParseException(message, this.buffer, this.index); - } - - public boolean isLenient() { - return this.lenient; - } - - public int getIndex() { - return this.index; - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/spec/CommandSpec.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/spec/CommandSpec.java index 14bd7f71a..67110cd10 100644 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/spec/CommandSpec.java +++ b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/spec/CommandSpec.java @@ -457,7 +457,7 @@ public Optional getHelp(PermissibleCommandSource source) { Preconditions.checkNotNull(source, "source"); StringBuilder builder = new StringBuilder(); this.getShortDescription(source).ifPresent((a) -> builder.append(a.asUnformattedString()).append("\n")); - builder.append(this.getUsage(source)); + builder.append(this.getUsage(source).asUnformattedString()); this.getExtendedDescription(source).ifPresent((a) -> builder.append(a.asUnformattedString()).append("\n")); return Optional.of(new LiteralText(builder.toString())); } diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/CommandManagerImpl.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/CommandManagerImpl.java index 049ad1aa8..f15f2ff7a 100644 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/CommandManagerImpl.java +++ b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/CommandManagerImpl.java @@ -132,7 +132,7 @@ public CommandResult process(PermissibleCommandSource source, String command) { usage = mapping.get().getCallable().getUsage(source); } - source.sendMessage(CommandMessageFormatting.error(new LiteralText(String.format("Usage: /%s %s", argSplit[0], usage)))); + source.sendMessage(CommandMessageFormatting.error(new LiteralText(String.format("Usage: /%s %s", argSplit[0], usage.asUnformattedString())))); } } } diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/CommandWrapper.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/CommandWrapper.java index 974d43b86..8b3ad6cd6 100644 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/CommandWrapper.java +++ b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/CommandWrapper.java @@ -90,7 +90,7 @@ public void execute(CommandSource source, String[] args) { usage = this.mapping.getCallable().getUsage((PermissibleCommandSource) source); } - source.sendMessage(CommandMessageFormatting.error(new LiteralText(String.format("Usage: /%s %s", this.getCommandName(), usage)))); + source.sendMessage(CommandMessageFormatting.error(new LiteralText(String.format("Usage: /%s %s", this.getCommandName(), usage.asUnformattedString())))); } } } catch (Throwable t) { diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/AllOfCommandElement.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/AllOfCommandElement.java deleted file mode 100644 index 72e55d551..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/AllOfCommandElement.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.Collections; -import java.util.List; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.CommandMessageFormatting; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandContext; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class AllOfCommandElement extends CommandElement { - private final CommandElement element; - - public AllOfCommandElement(CommandElement element) { - super(null); - this.element = element; - } - - @Override - public void parse(PermissibleCommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException { - while (args.hasNext()) { - this.element.parse(source, args, context); - } - } - - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - return null; - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - CommandArgs.Snapshot startState = null; - - try { - while (args.hasNext()) { - startState = args.getSnapshot(); - this.element.parse(src, args, context); - } - } catch (ArgumentParseException e) { - // ignored - } - - // The final element, if an exception was not thrown, might have more completions available to it. - // Therefore, we reapply the last snapshot and complete from it. - if (startState != null) { - args.applySnapshot(startState); - } - - if (args.canComplete()) { - return this.element.complete(src, args, context); - } - - // If we have more elements, do not complete. - return Collections.emptyList(); - } - - @Override - public Text getUsage(PermissibleCommandSource context) { - return new LiteralText(this.element.getUsage(context).asUnformattedString() + CommandMessageFormatting.STAR_TEXT.computeValue()); - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/BigDecimalElement.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/BigDecimalElement.java deleted file mode 100644 index 3d762821c..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/BigDecimalElement.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.math.BigDecimal; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.KeyElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class BigDecimalElement extends KeyElement { - public BigDecimalElement(Text key) { - super(key); - } - - @Nullable - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - String next = args.next(); - - try { - return new BigDecimal(next); - } catch (NumberFormatException ex) { - throw args.createError(new LiteralText("Expected a number, but input " + next + " was not")); - } - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/BigIntegerElement.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/BigIntegerElement.java deleted file mode 100644 index 99368f2ee..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/BigIntegerElement.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.math.BigInteger; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.KeyElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class BigIntegerElement extends KeyElement { - public BigIntegerElement(Text key) { - super(key); - } - - @Nullable - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - String integerString = args.next(); - - try { - return new BigInteger(integerString); - } catch (NumberFormatException ex) { - throw args.createError(new LiteralText("Expected an integer, but input " + integerString + " was not")); - } - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/ChoicesCommandElement.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/ChoicesCommandElement.java deleted file mode 100644 index c8dd91a8a..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/ChoicesCommandElement.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.function.Function; -import java.util.function.Supplier; -import java.util.stream.Collectors; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.CommandMessageFormatting; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandContext; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; -import net.legacyfabric.fabric.api.util.TriState; - -public class ChoicesCommandElement extends CommandElement { - public static final int CUTOFF = 5; - private final Supplier> keySupplier; - private final Function valueSupplier; - private final TriState choicesInUsage; - - public ChoicesCommandElement(Text key, Supplier> keySupplier, Function valueSupplier, TriState choicesInUsage) { - super(key); - this.keySupplier = keySupplier; - this.valueSupplier = valueSupplier; - this.choicesInUsage = choicesInUsage; - } - - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - Object value = this.valueSupplier.apply(args.next()); - - if (value == null) { - throw args.createError(new LiteralText(String.format("Argument was not a valid choice. Valid choices: %s", this.keySupplier.get().toString()))); - } - - return value; - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - final String prefix = args.nextIfPresent().orElse(""); - return Collections.unmodifiableList(this.keySupplier.get().stream().filter((input) -> input.startsWith(prefix)).collect(Collectors.toList())); - } - - @Override - public Text getUsage(PermissibleCommandSource commander) { - Collection keys = this.keySupplier.get(); - - if (this.choicesInUsage == TriState.TRUE || (this.choicesInUsage == TriState.DEFAULT && keys.size() <= CUTOFF)) { - final Text build = new LiteralText(""); - build.append(CommandMessageFormatting.LT_TEXT); - - for (Iterator it = keys.iterator(); it.hasNext(); ) { - build.append(new LiteralText(it.next())); - - if (it.hasNext()) { - build.append(CommandMessageFormatting.PIPE_TEXT); - } - } - - build.append(CommandMessageFormatting.GT_TEXT); - return new LiteralText(build.asUnformattedString()); - } - - return super.getUsage(commander); - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/DateTimeElement.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/DateTimeElement.java deleted file mode 100644 index 93e19c7ba..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/DateTimeElement.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.format.DateTimeParseException; -import java.util.List; - -import com.google.common.collect.ImmutableList; -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandContext; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class DateTimeElement extends CommandElement { - private final boolean returnNow; - - public DateTimeElement(Text key, boolean returnNow) { - super(key); - this.returnNow = returnNow; - } - - @Nullable - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - if (!args.hasNext() && this.returnNow) { - return LocalDateTime.now(); - } - - CommandArgs.Snapshot state = args.getSnapshot(); - String date = args.next(); - - try { - return LocalDateTime.parse(date); - } catch (DateTimeParseException ex) { - try { - return LocalDateTime.of(LocalDate.now(), LocalTime.parse(date)); - } catch (DateTimeParseException ex2) { - try { - return LocalDateTime.of(LocalDate.parse(date), LocalTime.MIDNIGHT); - } catch (DateTimeParseException ex3) { - if (this.returnNow) { - args.applySnapshot(state); - return LocalDateTime.now(); - } - - throw args.createError(new LiteralText("Invalid date-time!")); - } - } - } - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - String date = LocalDateTime.now().withNano(0).toString(); - - if (date.startsWith(args.nextIfPresent().orElse(""))) { - return ImmutableList.of(date); - } else { - return ImmutableList.of(); - } - } - - @Override - public Text getUsage(PermissibleCommandSource src) { - if (!this.returnNow) { - return super.getUsage(src); - } else { - return new LiteralText("[" + this.getKey().asUnformattedString() + "]"); - } - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/DurationElement.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/DurationElement.java deleted file mode 100644 index ef161bb88..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/DurationElement.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.time.Duration; -import java.time.format.DateTimeParseException; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.KeyElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class DurationElement extends KeyElement { - public DurationElement(Text key) { - super(key); - } - - @Nullable - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - String s = args.next().toUpperCase(); - - if (!s.contains("T")) { - if (s.contains("D")) { - if (s.contains("H") || s.contains("M") || s.contains("S")) { - s = s.replace("D", "DT"); - } - } else { - if (s.startsWith("P")) { - s = "PT" + s.substring(1); - } else { - s = "T" + s; - } - } - } - - if (!s.startsWith("P")) { - s = "P" + s; - } - - try { - return Duration.parse(s); - } catch (DateTimeParseException ex) { - throw args.createError(new LiteralText("Invalid duration!")); - } - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/EntityCommandElement.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/EntityCommandElement.java index 10b9aad84..29054eaaa 100644 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/EntityCommandElement.java +++ b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/EntityCommandElement.java @@ -119,11 +119,11 @@ protected Object getValue(String choice) throws IllegalArgumentException { uuid = UUID.fromString(choice); } catch (IllegalArgumentException ignored) { // Player could be a name - return Optional.ofNullable(MinecraftServer.getServer().getPlayerManager().getPlayer(choice)).orElseThrow(() -> new IllegalArgumentException("Input value " + choice + " does not represent a valid entity")); + return Optional.ofNullable(this.getServer().getPlayerManager().getPlayer(choice)).orElseThrow(() -> new IllegalArgumentException("Input value " + choice + " does not represent a valid entity")); } boolean found = false; - Optional ret = Optional.ofNullable((Entity) MinecraftServer.getServer().getWorld().entities.stream() + Optional ret = Optional.ofNullable((Entity) this.getServer().getWorld().entities.stream() .filter(o -> ((Entity) o).getUuid().equals(uuid)).findFirst().orElse(null)); if (ret.isPresent()) { diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/EnumValueElement.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/EnumValueElement.java deleted file mode 100644 index a9e260670..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/EnumValueElement.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.Arrays; -import java.util.Map; -import java.util.function.Function; -import java.util.stream.Collectors; - -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.PatternMatchingCommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class EnumValueElement> extends PatternMatchingCommandElement { - private final Class type; - private final Map values; - - public EnumValueElement(Text key, Class type) { - super(key); - this.type = type; - this.values = Arrays.stream(type.getEnumConstants()) - .collect(Collectors.toMap(value -> value.name().toLowerCase(), - Function.identity(), (value, value2) -> { - throw new UnsupportedOperationException(type.getCanonicalName() + " contains more than one enum constant " + "with the same name, only differing by capitalization, which is unsupported."); - } - )); - } - - @Override - protected Iterable getChoices(PermissibleCommandSource source) { - return this.values.keySet(); - } - - @Override - protected Object getValue(String choice) throws IllegalArgumentException { - T value = this.values.get(choice.toLowerCase()); - - if (value == null) { - throw new IllegalArgumentException("No enum constant " + this.type.getCanonicalName() + "." + choice); - } - - return value; - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/FilteredSuggestionsElement.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/FilteredSuggestionsElement.java deleted file mode 100644 index 01d7c3883..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/FilteredSuggestionsElement.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.Collections; -import java.util.List; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -import org.jetbrains.annotations.Nullable; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandContext; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class FilteredSuggestionsElement extends CommandElement { - private final CommandElement wrapped; - private final Predicate predicate; - - public FilteredSuggestionsElement(CommandElement wrapped, Predicate predicate) { - super(wrapped.getKey()); - this.wrapped = wrapped; - this.predicate = predicate; - } - - @Nullable - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - return this.wrapped.parseValue(source, args); - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - return Collections.unmodifiableList(this.wrapped.complete(src, args, context).stream().filter(this.predicate).collect(Collectors.toList())); - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/FirstParsingCommandElement.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/FirstParsingCommandElement.java deleted file mode 100644 index 597d41de0..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/FirstParsingCommandElement.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.Iterator; -import java.util.List; -import java.util.stream.Collectors; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.CommandMessageFormatting; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandContext; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class FirstParsingCommandElement extends CommandElement { - private final List elements; - - public FirstParsingCommandElement(List elements) { - super(null); - this.elements = elements; - } - - @Override - public void parse(PermissibleCommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException { - ArgumentParseException lastException = null; - - for (CommandElement element : this.elements) { - CommandArgs.Snapshot startState = args.getSnapshot(); - CommandContext.Snapshot contextSnapshot = context.createSnapshot(); - - try { - element.parse(source, args, context); - return; - } catch (ArgumentParseException ex) { - lastException = ex; - args.applySnapshot(startState); - context.applySnapshot(contextSnapshot); - } - } - - if (lastException != null) { - throw lastException; - } - } - - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - return null; - } - - @Override - public List complete(final PermissibleCommandSource src, final CommandArgs args, final CommandContext context) { - return Lists.newLinkedList(Iterables.concat(this.elements.stream().map(element -> { - if (element == null) { - return ImmutableList.of(); - } else { - CommandArgs.Snapshot snapshot = args.getSnapshot(); - List ret = element.complete(src, args, context); - args.applySnapshot(snapshot); - return ret; - } - }).collect(Collectors.toSet()))); - } - - @Override - public Text getUsage(PermissibleCommandSource commander) { - final Text ret = new LiteralText(""); - - for (Iterator it = this.elements.iterator(); it.hasNext(); ) { - ret.append(it.next().getUsage(commander)); - - if (it.hasNext()) { - ret.append(CommandMessageFormatting.PIPE_TEXT); - } - } - - return new LiteralText(ret.asUnformattedString()); - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/LiteralCommandElement.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/LiteralCommandElement.java deleted file mode 100644 index 8544e38a4..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/LiteralCommandElement.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.List; -import java.util.Optional; - -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableList; -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandContext; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class LiteralCommandElement extends CommandElement { - private final List expectedArgs; - @Nullable - private final Object putValue; - - public LiteralCommandElement(@Nullable Text key, List expectedArgs, @Nullable Object putValue) { - super(key); - this.expectedArgs = ImmutableList.copyOf(expectedArgs); - this.putValue = putValue; - } - - @Nullable - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - for (String arg : this.expectedArgs) { - String current; - - if (!(current = args.next()).equalsIgnoreCase(arg)) { - throw args.createError(new LiteralText(String.format("Argument %s did not match expected next argument %s", current, arg))); - } - } - - return this.putValue; - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - for (String arg : this.expectedArgs) { - final Optional next = args.nextIfPresent(); - - if (!next.isPresent()) { - break; - } else if (args.hasNext()) { - if (!next.get().equalsIgnoreCase(arg)) { - break; - } - } else { - if (arg.toLowerCase().startsWith(next.get().toLowerCase())) { // Case-insensitive compare - return ImmutableList.of(arg); // TODO: Possibly complete all remaining args? Does that even work - } - } - } - - return ImmutableList.of(); - } - - @Override - public Text getUsage(PermissibleCommandSource src) { - return new LiteralText(Joiner.on(' ').join(this.expectedArgs)); - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/MarkTrueCommandElement.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/MarkTrueCommandElement.java deleted file mode 100644 index ac862d943..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/MarkTrueCommandElement.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.Collections; -import java.util.List; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandContext; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class MarkTrueCommandElement extends CommandElement { - public MarkTrueCommandElement(Text key) { - super(key); - } - - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - return true; - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - return Collections.emptyList(); - } - - @Override - public Text getUsage(PermissibleCommandSource src) { - return new LiteralText(""); - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/ModCommandElement.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/ModCommandElement.java deleted file mode 100644 index 250f0586e..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/ModCommandElement.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.Optional; -import java.util.stream.Collectors; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.Text; - -import net.fabricmc.loader.api.FabricLoader; -import net.fabricmc.loader.api.ModContainer; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.PatternMatchingCommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class ModCommandElement extends PatternMatchingCommandElement { - public ModCommandElement(@Nullable Text key) { - super(key); - } - - @Override - protected Iterable getChoices(PermissibleCommandSource source) { - return FabricLoader.getInstance().getAllMods().stream().map(container -> container.getMetadata().getId()).collect(Collectors.toSet()); - } - - @Override - protected Object getValue(String choice) throws IllegalArgumentException { - Optional plugin = FabricLoader.getInstance().getModContainer(choice); - return plugin.orElseThrow(() -> new IllegalArgumentException("Mod " + choice + " was not found")); - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/NumericElement.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/NumericElement.java deleted file mode 100644 index 0eb493945..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/NumericElement.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.function.BiFunction; -import java.util.function.Function; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.KeyElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class NumericElement extends KeyElement { - private final Function parseFunc; - @Nullable - private final BiFunction parseRadixFunction; - private final Function errorSupplier; - - public NumericElement(Text key, Function parseFunc, @Nullable BiFunction parseRadixFunction, Function errorSupplier) { - super(key); - this.parseFunc = parseFunc; - this.parseRadixFunction = parseRadixFunction; - this.errorSupplier = errorSupplier; - } - - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - final String input = args.next(); - - try { - if (this.parseRadixFunction != null) { - if (input.startsWith("0x")) { - return this.parseRadixFunction.apply(input.substring(2), 16); - } else if (input.startsWith("0b")) { - return this.parseRadixFunction.apply(input.substring(2), 2); - } - } - - return this.parseFunc.apply(input); - } catch (NumberFormatException ex) { - throw args.createError(this.errorSupplier.apply(input)); - } - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OnlyOneCommandElement.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OnlyOneCommandElement.java deleted file mode 100644 index ba0173c43..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OnlyOneCommandElement.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.List; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandContext; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class OnlyOneCommandElement extends CommandElement { - private final CommandElement element; - - public OnlyOneCommandElement(CommandElement element) { - super(element.getKey()); - this.element = element; - } - - @Override - public void parse(PermissibleCommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException { - this.element.parse(source, args, context); - - if (context.getAll(this.element.getUntranslatedKey()).size() > 1) { - Text key = this.element.getKey(); - throw args.createError(new LiteralText(String.format("Argument %s may have only one value!", key != null ? key : "unknown"))); - } - } - - @Override - public Text getUsage(PermissibleCommandSource src) { - return this.element.getUsage(src); - } - - @Nullable - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - return this.element.parseValue(source, args); - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - return this.element.complete(src, args, context); - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/PermissionCommandElement.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/PermissionCommandElement.java deleted file mode 100644 index 151c83ab8..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/PermissionCommandElement.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.List; - -import com.google.common.collect.ImmutableList; -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandContext; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class PermissionCommandElement extends CommandElement { - private final CommandElement element; - private final String permission; - private final boolean isOptional; - - public PermissionCommandElement(CommandElement element, String permission, boolean isOptional) { - super(element.getKey()); - this.element = element; - this.permission = permission; - this.isOptional = isOptional; - } - - @Nullable - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - if (this.checkPermission(source, args)) { - return this.element.parseValue(source, args); - } - - return null; - } - - private boolean checkPermission(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - boolean hasPermission = source.hasPermission(this.permission); - - if (!hasPermission && !this.isOptional) { - Text key = this.getKey(); - throw args.createError(new LiteralText(String.format("You do not have permission to use the %s argument", key != null ? key : "unknown"))); - } - - return hasPermission; - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - boolean flag = /*src.hasPermission(this.permission)*/ true; - - if (!flag) { - return ImmutableList.of(); - } - - return this.element.complete(src, args, context); - } - - @Override - public void parse(PermissibleCommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException { - if (this.checkPermission(source, args)) { - this.element.parse(source, args, context); - } - } - - @Override - public Text getUsage(PermissibleCommandSource src) { - if (this.isOptional && !src.hasPermission(this.permission)) { - return new LiteralText(""); - } - - return this.element.getUsage(src); - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/PlayerCommandElement.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/PlayerCommandElement.java index a3993e4e4..ad3d1212d 100644 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/PlayerCommandElement.java +++ b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/PlayerCommandElement.java @@ -26,7 +26,6 @@ package net.legacyfabric.fabric.impl.command.lib.sponge.args; import java.util.Optional; -import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.StreamSupport; @@ -77,7 +76,7 @@ protected Iterable getChoices(PermissibleCommandSource source) { @Override protected Object getValue(String choice) throws IllegalArgumentException { - Optional ret = MinecraftServer.getServer().getPlayerManager().players.stream().findFirst().map(Function.identity()); + Optional ret = this.getServer().getPlayerManager().players.stream().findFirst(); if (!ret.isPresent()) { throw new IllegalArgumentException("Input value " + choice + " was not a player"); @@ -96,6 +95,6 @@ private PlayerEntity tryReturnSource(PermissibleCommandSource source, CommandArg @Override public Text getUsage(PermissibleCommandSource src) { - return src != null && this.returnSource ? new LiteralText("[" + super.getUsage(src) + "]") : super.getUsage(src); + return src != null && this.returnSource ? new LiteralText("[" + super.getUsage(src).asUnformattedString() + "]") : super.getUsage(src); } } diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/RemainingJoinedStringsCommandElement.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/RemainingJoinedStringsCommandElement.java deleted file mode 100644 index a145ca7d1..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/RemainingJoinedStringsCommandElement.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.CommandMessageFormatting; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.KeyElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class RemainingJoinedStringsCommandElement extends KeyElement { - private final boolean raw; - - public RemainingJoinedStringsCommandElement(Text key, boolean raw) { - super(key); - this.raw = raw; - } - - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - if (this.raw) { - args.next(); - String ret = args.getRaw().substring(args.getRawPosition()); - - while (args.hasNext()) { // Consume remaining args - args.next(); - } - - return ret; - } - - final StringBuilder ret = new StringBuilder(args.next()); - - while (args.hasNext()) { - ret.append(' ').append(args.next()); - } - - return ret.toString(); - } - - @Override - public Text getUsage(PermissibleCommandSource src) { - return new LiteralText("").append(CommandMessageFormatting.LT_TEXT.asUnformattedString()).append(this.getKey()).append(CommandMessageFormatting.ELLIPSIS_TEXT).append(CommandMessageFormatting.GT_TEXT); - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/RepeatedCommandElement.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/RepeatedCommandElement.java deleted file mode 100644 index 4128da783..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/RepeatedCommandElement.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.Collections; -import java.util.List; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandContext; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class RepeatedCommandElement extends CommandElement { - private final CommandElement element; - private final int times; - - public RepeatedCommandElement(CommandElement element, int times) { - super(null); - this.element = element; - this.times = times; - } - - @Override - public void parse(PermissibleCommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException { - for (int i = 0; i < this.times; ++i) { - this.element.parse(source, args, context); - } - } - - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - return null; - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - for (int i = 0; i < this.times; ++i) { - CommandArgs.Snapshot startState = args.getSnapshot(); - - try { - this.element.parse(src, args, context); - } catch (ArgumentParseException e) { - args.applySnapshot(startState); - return this.element.complete(src, args, context); - } - } - - return Collections.emptyList(); - } - - @Override - public Text getUsage(PermissibleCommandSource src) { - return new LiteralText(this.times + '*' + this.element.getUsage(src).asUnformattedString()); - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/SequenceCommandElement.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/SequenceCommandElement.java deleted file mode 100644 index f08c2b2fc..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/SequenceCommandElement.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.CommandMessageFormatting; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandContext; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class SequenceCommandElement extends CommandElement { - private final List elements; - - public SequenceCommandElement(List elements) { - super(null); - this.elements = elements; - } - - @Override - public void parse(PermissibleCommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException { - for (CommandElement element : this.elements) { - element.parse(source, args, context); - } - } - - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - return null; - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - Set completions = Sets.newHashSet(); - - for (CommandElement element : this.elements) { - CommandArgs.Snapshot state = args.getSnapshot(); - CommandContext.Snapshot contextSnapshot = context.createSnapshot(); - - try { - element.parse(src, args, context); - - // If we get here, the parse occurred successfully. - // However, if nothing was consumed, then we should consider - // what could have been. - CommandContext.Snapshot afterSnapshot = context.createSnapshot(); - - if (state.equals(args.getSnapshot())) { - context.applySnapshot(contextSnapshot); - completions.addAll(element.complete(src, args, context)); - args.applySnapshot(state); - context.applySnapshot(afterSnapshot); - } else if (args.hasNext()) { - completions.clear(); - } else { - // What we might also have - we have no args left to parse so - // while the parse itself was successful, there could be other - // valid entries to add... - context.applySnapshot(contextSnapshot); - args.applySnapshot(state); - completions.addAll(element.complete(src, args, context)); - - if (!(element instanceof OptionalCommandElement)) { - break; - } - - // The last element was optional, so we go back to before this - // element would have been parsed, and assume it never existed... - context.applySnapshot(contextSnapshot); - args.applySnapshot(state); - } - } catch (ArgumentParseException ignored) { - args.applySnapshot(state); - context.applySnapshot(contextSnapshot); - completions.addAll(element.complete(src, args, context)); - break; - } - } - - return Lists.newArrayList(completions); - } - - @Override - public Text getUsage(PermissibleCommandSource commander) { - final Text build = new LiteralText(""); - - for (Iterator it = this.elements.iterator(); it.hasNext(); ) { - Text usage = it.next().getUsage(commander); - - if (!usage.asUnformattedString().isEmpty()) { - build.append(usage); - - if (it.hasNext()) { - build.append(CommandMessageFormatting.SPACE_TEXT); - } - } - } - - return new LiteralText(build.asUnformattedString()); - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/StringCommandElement.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/StringCommandElement.java deleted file mode 100644 index bd4ef8e26..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/StringCommandElement.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.StringType; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.KeyElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class StringCommandElement extends KeyElement { - private final StringType stringType; - private final RemainingJoinedStringsCommandElement joinedElement; - - public StringCommandElement(Text key, StringType type) { - super(key); - this.stringType = type; - this.joinedElement = type.isAll() ? new RemainingJoinedStringsCommandElement(key, false) : null; - } - - @Nullable - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - return this.stringType.isAll() ? (String) this.joinedElement.parseValue(source, args) : args.next(); - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/StringElement.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/StringElement.java deleted file mode 100644 index 649e4a077..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/StringElement.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.KeyElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class StringElement extends KeyElement { - public StringElement(Text key) { - super(key); - } - - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - return args.next(); - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/UrlElement.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/UrlElement.java deleted file mode 100644 index 14f0f856f..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/UrlElement.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.net.MalformedURLException; -import java.net.URISyntaxException; -import java.net.URL; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.KeyElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class UrlElement extends KeyElement { - public UrlElement(Text key) { - super(key); - } - - @Nullable - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - String str = args.next(); - URL url; - - try { - url = new URL(str); - } catch (MalformedURLException ex) { - throw new ArgumentParseException(new LiteralText("Invalid URL!"), ex, str, 0); - } - - try { - url.toURI(); - } catch (URISyntaxException ex) { - throw new ArgumentParseException(new LiteralText("Invalid URL!"), ex, str, 0); - } - - return url; - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/UuidElement.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/UuidElement.java deleted file mode 100644 index 16db686da..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/UuidElement.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.UUID; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.KeyElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class UuidElement extends KeyElement { - public UuidElement(Text key) { - super(key); - } - - @Nullable - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - try { - return UUID.fromString(args.next()); - } catch (IllegalArgumentException ex) { - throw args.createError(new LiteralText("Invalid UUID!")); - } - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/WithSuggestionsElement.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/WithSuggestionsElement.java deleted file mode 100644 index 389e75583..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/WithSuggestionsElement.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.List; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.StreamSupport; - -import com.google.common.collect.ImmutableList; -import org.jetbrains.annotations.Nullable; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandContext; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class WithSuggestionsElement extends CommandElement { - private final CommandElement wrapped; - private final Function> suggestions; - private final boolean requireBegin; - - public WithSuggestionsElement(CommandElement wrapped, Function> suggestions, boolean requireBegin) { - super(wrapped.getKey()); - this.wrapped = wrapped; - this.suggestions = suggestions; - this.requireBegin = requireBegin; - } - - @Nullable - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - return this.wrapped.parseValue(source, args); - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - if (this.requireBegin) { - String arg = args.nextIfPresent().orElse(""); - return ImmutableList.copyOf(StreamSupport.stream(this.suggestions.apply(src).spliterator(), false).filter(f -> f.startsWith(arg)).collect(Collectors.toList())); - } else { - return ImmutableList.copyOf(this.suggestions.apply(src)); - } - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/resources/fabric.mod.json b/legacy-fabric-command-api-v2/1.7.10/src/main/resources/fabric.mod.json index 5ff821a2a..83dca385f 100644 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/resources/fabric.mod.json +++ b/legacy-fabric-command-api-v2/1.7.10/src/main/resources/fabric.mod.json @@ -28,9 +28,7 @@ ] }, "description": "Powerful Command API that uses SpongeAPI's command api", - "mixins": [ - "legacy-fabric-sponge-command-api-v2.mixins.json" - ], + "mixins": [], "custom": { "modmenu": { "badges": [ "library" ], diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/resources/legacy-fabric-sponge-command-api-v2.mixins.json b/legacy-fabric-command-api-v2/1.7.10/src/main/resources/legacy-fabric-sponge-command-api-v2.mixins.json deleted file mode 100644 index bc49c8a20..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/resources/legacy-fabric-sponge-command-api-v2.mixins.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "required": true, - "package": "net.legacyfabric.fabric.mixin.command", - "compatibilityLevel": "JAVA_8", - "mixins": [ - "MinecraftServerMixin" - ], - "injectors": { - "defaultRequire": 1 - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/StringType.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/StringType.java deleted file mode 100644 index f294fb603..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/StringType.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.api.command.v2; - -/** - * Specifies a method to parse {@link String}s in a command. - */ -public enum StringType { - SINGLE_WORD(false), - GREEDY_PHRASE(true); - - private final boolean all; - - StringType(boolean all) { - this.all = all; - } - - public boolean isAll() { - return this.all; - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandException.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandException.java deleted file mode 100644 index 6d65de8be..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandException.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge; - -import net.minecraft.text.Text; - -/** - * Thrown when an executed command raises an error or when execution of - * the command failed. - */ -public class CommandException extends TextMessageException { - private static final long serialVersionUID = 4626722485860074825L; - - private final boolean includeUsage; - - /** - * Constructs a new {@link CommandException} with the given message. - * - * @param message The detail message - */ - public CommandException(Text message) { - this(message, false); - } - - /** - * Constructs a new {@link CommandException} with the given message and - * the given cause. - * - * @param message The detail message - * @param cause The cause - */ - public CommandException(Text message, Throwable cause) { - this(message, cause, false); - } - - /** - * Constructs a new {@link CommandException} with the given message. - * - * @param message The detail message - * @param includeUsage Whether to include usage in the exception - */ - public CommandException(Text message, boolean includeUsage) { - super(message); - this.includeUsage = includeUsage; - } - - /** - * Constructs a new {@link CommandException} with the given message and - * the given cause. - * - * @param message The detail message - * @param cause The cause - * @param includeUsage Whether to include the usage in the exception - */ - public CommandException(Text message, Throwable cause, boolean includeUsage) { - super(message, cause); - this.includeUsage = includeUsage; - } - - /** - * Gets whether the exception should include usage in - * the presentation of the exception/stack-trace. - * - * @return Whether to include usage in the exception - */ - public boolean shouldIncludeUsage() { - return this.includeUsage; - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandMessageFormatting.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandMessageFormatting.java deleted file mode 100644 index f6ca1bf02..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandMessageFormatting.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; - -public class CommandMessageFormatting { - private CommandMessageFormatting() { - } - - public static final Text PIPE_TEXT = new LiteralText("|"); - public static final Text SPACE_TEXT = new LiteralText(" "); - public static final Text STAR_TEXT = new LiteralText("*"); - public static final Text LT_TEXT = new LiteralText("<"); - public static final Text GT_TEXT = new LiteralText(">"); - public static final Text ELLIPSIS_TEXT = new LiteralText("…"); - - /** - * Format text to be output as an error directly to a sender. Not necessary - * when creating an exception to be thrown - * - * @param error The error message - * @return The formatted error message. - */ - public static Text error(Text error) { - return error.setStyle(error.getStyle().setFormatting(Formatting.RED)); - } - - /** - * Format text to be output as a debug message directly to a sender. - * - * @param debug The debug message - * @return The formatted debug message. - */ - public static Text debug(Text debug) { - return debug.setStyle(debug.getStyle().setFormatting(Formatting.GRAY)); - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandNotFoundException.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandNotFoundException.java deleted file mode 100644 index 23d2b1455..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandNotFoundException.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge; - -import com.google.common.base.Preconditions; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -/** - * This exception is thrown when a sender tries to execute a command that does - * not exist. - */ -public class CommandNotFoundException extends CommandException { - private static final long serialVersionUID = -7714518367616848051L; - - private final String command; - - /** - * Create an exception with the default message. - * - * @param command The command that was queried for - */ - public CommandNotFoundException(String command) { - this(new LiteralText("No such command"), command); - } - - /** - * Create an exception with a custom message. - * - * @param message The message - * @param command The command that was queried for - */ - public CommandNotFoundException(Text message, String command) { - super(message); - this.command = Preconditions.checkNotNull(command, "command"); - } - - /** - * Returns the command that was queried for. - * - * @return The command - */ - public String getCommand() { - return this.command; - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandPermissionException.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandPermissionException.java deleted file mode 100644 index 0711108f2..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandPermissionException.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -/** - * This exception is thrown when a subject does not have permission to execute - * a command. - */ -public class CommandPermissionException extends CommandException { - private static final long serialVersionUID = -6057386975881181213L; - - /** - * Create an exception with the default message. - */ - public CommandPermissionException() { - this(new LiteralText("You do not have permission to use this command!")); - } - - /** - * Create a permissions exception with a custom message. - * - * @param message The message - */ - public CommandPermissionException(Text message) { - super(message); - } - - /** - * Create a permissions exception with a custom message and cause. - * - * @param message the message - * @param cause the cause - */ - public CommandPermissionException(Text message, Throwable cause) { - super(message, cause); - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/InvocationCommandException.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/InvocationCommandException.java deleted file mode 100644 index 5501a12ab..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/InvocationCommandException.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge; - -import net.minecraft.text.Text; - -/** - * Thrown when invocation of a command fails, wrapping the exception that - * is thrown. - */ -public class InvocationCommandException extends CommandException { - private static final long serialVersionUID = 2123904283741023948L; - - /** - * Constructs a new exception with the given message and the given cause. - * - * @param message The detail message - * @param cause The cause - */ - public InvocationCommandException(Text message, Throwable cause) { - super(message, cause); - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/TextMessageException.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/TextMessageException.java deleted file mode 100644 index 44a7a58d1..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/TextMessageException.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge; - -import net.minecraft.text.Text; - -/** - * A subclass of Exception that contains a rich message that is an instance of - * {@link Text} rather than a String. This allows formatted and localized - * exception messages. - */ -public class TextMessageException extends Exception { - private static final long serialVersionUID = -5281221645176698853L; - - private final Text message; - - /** - * Constructs a new {@link TextMessageException}. - */ - public TextMessageException() { - this.message = null; - } - - /** - * Constructs a new {@link TextMessageException} with the given message. - * - * @param message The detail message - */ - public TextMessageException(Text message) { - this.message = message; - } - - /** - * Constructs a new {@link TextMessageException} with the given message and - * cause. - * - * @param message The detail message - * @param throwable The cause - */ - public TextMessageException(Text message, Throwable throwable) { - super(throwable); - this.message = message; - } - - /** - * Constructs a new {@link TextMessageException} with the given cause. - * - * @param throwable The cause - */ - public TextMessageException(Throwable throwable) { - super(throwable); - this.message = null; - } - - @Override - public String getMessage() { - Text message = this.getText(); - return message == null ? null : message.computeValue(); - } - - /** - * Returns the text message for this exception, or null if nothing is - * present. - * - * @return The text for this message - */ - public Text getText() { - return this.message; - } - - @Override - public String getLocalizedMessage() { - return this.getMessage(); - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/ArgumentParseException.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/ArgumentParseException.java deleted file mode 100644 index f099c1e43..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/ArgumentParseException.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge.args; - -import com.google.common.base.Strings; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.CommandException; - -/** - * Exception thrown when an error occurs while parsing arguments. - */ -public class ArgumentParseException extends CommandException { - private static final long serialVersionUID = -8555316116315990226L; - - private final String source; - private final int position; - - /** - * Return a new {@link ArgumentParseException} with the given message, source and position. - * - * @param message The message to use for this exception - * @param source The source string being parsed - * @param position The current position in the source string - */ - public ArgumentParseException(Text message, String source, int position) { - super(message, true); - this.source = source; - this.position = position; - } - - /** - * Return a new {@link ArgumentParseException} with the given message, cause, source and position. - * - * @param message The message to use for this exception - * @param cause The cause for this exception - * @param source The source string being parsed - * @param position The current position in the source string - */ - public ArgumentParseException(Text message, Throwable cause, String source, int position) { - super(message, cause, true); - this.source = source; - this.position = position; - } - - @Override - public Text getText() { - Text superText = super.getText(); - - if (this.source == null || this.source.isEmpty()) { - return super.getText(); - } else if (superText == null) { - return new LiteralText(this.getAnnotatedPosition()); - } else { - return new LiteralText(superText.asUnformattedString() + "\n" + this.getAnnotatedPosition()); - } - } - - private Text getSuperText() { - return super.getText(); - } - - /** - * Return a string pointing to the position of the arguments when this - * exception occurs. - * - * @return The appropriate position string - */ - public String getAnnotatedPosition() { - String source = this.source; - int position = this.position; - - if (source.length() > 80) { - if (position >= 37) { - int startPos = position - 37; - int endPos = Math.min(source.length(), position + 37); - - if (endPos < source.length()) { - source = "..." + source.substring(startPos, endPos) + "..."; - } else { - source = "..." + source.substring(startPos, endPos); - } - - position -= 40; - } else { - source = source.substring(0, 77) + "..."; - } - } - - return source + "\n" + Strings.repeat(" ", position) + "^"; - } - - /** - * Gets the position of the last fetched argument in the provided source - * string. - * - * @return The source string to get position for - */ - public int getPosition() { - return this.position; - } - - /** - * Returns the source string arguments are being parsed from. - * - * @return The source string - */ - public String getSourceString() { - return this.source; - } - - /** - * An {@link ArgumentParseException} where the usage is already specified. - */ - public static class WithUsage extends ArgumentParseException { - private static final long serialVersionUID = -786214501012293475L; - - private final Text usage; - - public WithUsage(ArgumentParseException wrapped, Text usage) { - super(wrapped.getSuperText(), wrapped.getCause(), wrapped.getSourceString(), wrapped.getPosition()); - this.usage = usage; - } - - /** - * Gets the usage associated with this exception. - * - * @return The usage - */ - public Text getUsage() { - return this.usage; - } - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandArgs.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandArgs.java deleted file mode 100644 index 3da0f488c..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandArgs.java +++ /dev/null @@ -1,348 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge.args; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Collectors; - -import com.google.common.collect.ImmutableList; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.parsing.SingleArg; - -/** - * Holder for command arguments. - */ -public final class CommandArgs { - private final String rawInput; - private final List args; - private int index = -1; - - /** - * Create a new CommandArgs instance with the given raw input and arguments. - * - * @param rawInput Raw input - * @param args Arguments extracted from the raw input - */ - public CommandArgs(String rawInput, List args) { - this.rawInput = rawInput; - this.args = new ArrayList<>(args); - } - - /** - * Return whether more arguments remain to be read. - * - * @return Whether more arguments remain - */ - public boolean hasNext() { - return this.index + 1 < this.args.size(); - } - - /** - * Returns true if: - * - *
    - *
  • The next element returned by {@link #next()} is the last
  • - *
  • {@link #hasNext()} is false
  • - *
- * Else returns false. - * - * @return True if a completion can occur - */ - public boolean canComplete() { - return this.index + 2 >= this.args.size(); - } - - /** - * Try to read the next argument without advancing the current index. - * - * @return The next argument - * @throws ArgumentParseException if not enough arguments are present - */ - public String peek() throws ArgumentParseException { - if (!this.hasNext()) { - throw this.createError(new LiteralText("Not enough arguments!")); - } - - return this.args.get(this.index + 1).getValue(); - } - - /** - * Try to read the next argument, advancing the current index if successful. - * - * @return The next argument - * @throws ArgumentParseException if not enough arguments are present - */ - public String next() throws ArgumentParseException { - if (!this.hasNext()) { - throw this.createError(new LiteralText("Not enough arguments!")); - } - - return this.args.get(++this.index).getValue(); - } - - /** - * Try to read the next argument, advancing the current index if successful - * or returning an absent optional if not. - * - * @return The optional next argument. - */ - public Optional nextIfPresent() { - return this.hasNext() ? Optional.of(this.args.get(++this.index).getValue()) : Optional.empty(); - } - - /** - * Create a parse exception with the provided message which has the position - * of the last parsed argument attached. The returned exception must be - * thrown at the target - * - * @param message The message for the exception - * @return the newly created, but unthrown exception - */ - public ArgumentParseException createError(Text message) { - return new ArgumentParseException(message, this.rawInput, this.index < 0 ? 0 : this.args.get(this.index).getStartIdx()); - } - - /** - * Gets a list of all arguments as a string. The returned list is immutable. - * - * @return all arguments - */ - public List getAll() { - return Collections.unmodifiableList(this.args.stream().map(SingleArg::getValue).collect(Collectors.toList())); - } - - List getArgs() { - return this.args; - } - - /** - * Return this arguments object's current state. Can be used to reset with - * the {@link #setState(Object)} method. - * - * @return The current state - * @deprecated Use {@link #getSnapshot()} and - * {@link #applySnapshot(Snapshot)} instead - */ - @Deprecated - public Object getState() { - return this.getSnapshot(); - } - - /** - * Restore the arguments object's state to a state previously used. - * - * @param state the previous state - * @deprecated Use {@link #getSnapshot()} and - * {@link #applySnapshot(Snapshot)} instead - */ - @Deprecated - public void setState(Object state) { - if (!(state instanceof Snapshot)) { - throw new IllegalArgumentException("Provided state was not of appropriate format returned by getState!"); - } - - this.applySnapshot((Snapshot) state, false); // keep parity with before - } - - /** - * Return the raw string used to provide input to this arguments object. - * - * @return The raw input - */ - public String getRaw() { - return this.rawInput; - } - - /** - * Get an arg at the specified position. - * - * @param index index of the element to return - */ - public String get(int index) { - return this.args.get(index).getValue(); - } - - /** - * Insert an arg as the next arg to be returned by {@link #next()}. - * - * @param value The argument to insert - */ - public void insertArg(String value) { - int index = this.index < 0 ? 0 : this.args.get(this.index).getEndIdx(); - this.args.add(this.index + 1, new SingleArg(value, index, index)); - } - - /** - * Remove the arguments parsed between startState and endState. - * - * @param startState The starting state - * @param endState The ending state - * @deprecated Use with {@link #getSnapshot()} instead of - * {@link #getState()} with {@link #removeArgs(Snapshot, Snapshot)} - */ - @Deprecated - public void removeArgs(Object startState, Object endState) { - if (!(startState instanceof Integer) || !(endState instanceof Integer)) { - throw new IllegalArgumentException("One of the states provided was not of the correct type!"); - } - - this.removeArgs((int) startState, (int) endState); - } - - /** - * Remove the arguments parsed between two snapshots. - * - * @param startSnapshot The starting state - * @param endSnapshot The ending state - */ - public void removeArgs(Snapshot startSnapshot, Snapshot endSnapshot) { - this.removeArgs(startSnapshot.index, endSnapshot.index); - } - - private void removeArgs(int startIdx, int endIdx) { - if (this.index >= startIdx) { - if (this.index < endIdx) { - this.index = startIdx - 1; - } else { - this.index -= (endIdx - startIdx) + 1; - } - } - - for (int i = startIdx; i <= endIdx; ++i) { - this.args.remove(startIdx); - } - } - - /** - * Returns the number of arguments. - * - * @return the number of arguments - */ - public int size() { - return this.args.size(); - } - - /** - * Go back to the previous argument. - */ - void previous() { - if (this.index > -1) { - --this.index; - } - } - - /** - * Gets the current position in raw input. - * - * @return the raw position - */ - public int getRawPosition() { - return this.index < 0 ? 0 : this.args.get(this.index).getStartIdx(); - } - - /** - * Gets a snapshot of the data inside this context to allow it to be - * restored later. - * - * @return The {@link Snapshot} containing the current state of the - * {@link CommandArgs} - */ - public Snapshot getSnapshot() { - return new Snapshot(this.index, this.args); - } - - /** - * Resets a {@link CommandArgs} to a previous state using a previously - * created {@link Snapshot}. - * - * @param snapshot The {@link Snapshot} to restore this context - * with - */ - public void applySnapshot(Snapshot snapshot) { - this.applySnapshot(snapshot, true); - } - - /** - * Resets a {@link CommandArgs} to a previous state using a previously - * created {@link Snapshot}. - * - *

If resetArgs is set to false, this snapshot will not reset the - * argument list to its previous state, only the index.

- * - * @param snapshot The {@link Snapshot} to restore this context - * with - * @param resetArgs Whether to restore the argument list - */ - public void applySnapshot(Snapshot snapshot, boolean resetArgs) { - this.index = snapshot.index; - - if (resetArgs) { - this.args.clear(); - this.args.addAll(snapshot.args); - } - } - - /** - * A snapshot of a {@link CommandArgs}. This object does not contain any - * public API methods, a snapshot should be considered a black box. - */ - public final class Snapshot { - final int index; - final ImmutableList args; - - Snapshot(int index, List args) { - this.index = index; - this.args = ImmutableList.copyOf(args); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - - if (o == null || this.getClass() != o.getClass()) { - return false; - } - - Snapshot snapshot = (Snapshot) o; - return this.index == snapshot.index - && Objects.equals(this.args, snapshot.args); - } - - @Override - public int hashCode() { - return Objects.hash(this.index, this.args); - } - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandContext.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandContext.java deleted file mode 100644 index 1907dfecb..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandContext.java +++ /dev/null @@ -1,337 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge.args; - -import java.util.Collection; -import java.util.Collections; -import java.util.NoSuchElementException; -import java.util.Optional; -import java.util.Set; - -import com.google.common.base.Preconditions; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; -import com.google.common.collect.Sets; -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; -import net.minecraft.text.TranslatableText; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.CommandException; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; -import net.legacyfabric.fabric.api.util.Location; - -/** - * Context that a command is executed in. - * This object stores parsed arguments from other commands - */ -public final class CommandContext { - /** - * The argument key for a target block position that may be present - * during tab completion, of type {@link Location Location<World>}. - */ - public static final String TARGET_BLOCK_ARG = "targetblock-pos048658"; // Random junk afterwards so we don't accidentally conflict with other args - - /** - * The argument key to indicate that a tab completion is taking place. - */ - public static final String TAB_COMPLETION = "tab-complete-50456"; // Random junk afterwards so we don't accidentally conflict with other args - - private final Multimap parsedArgs; - private final Set definedFlags; - - /** - * Create a new empty CommandContext. - */ - public CommandContext() { - this.parsedArgs = ArrayListMultimap.create(); - this.definedFlags = Sets.newHashSet(); - } - - /** - * Gets all values for the given argument. May return an empty list if no - * values are present. - * - * @param key The key to get values for - * @param the type of value to get - * @return the collection of all values - */ - @SuppressWarnings("unchecked") - public Collection getAll(String key) { - return Collections.unmodifiableCollection((Collection) this.parsedArgs.get(key)); - } - - /** - * Gets all values for the given argument. May return an empty list if no - * values are present. - * - * @param key The key to get values for - * @param the type of value to get - * @return the collection of all values - */ - public Collection getAll(Text key) { - return this.getAll(CommandContext.textToArgKey(key)); - } - - /** - * Gets the value for the given key if the key has only one value. - * - *

An empty {@link Optional} indicates that there are either zero or more - * than one values for the given key. Use {@link #hasAny(Text)} to verify - * which.

- * - * @param key the key to get - * @param the expected type of the argument - * @return the argument - */ - @SuppressWarnings("unchecked") - public Optional getOne(String key) { - Collection values = this.parsedArgs.get(key); - - if (values.size() != 1) { - return Optional.empty(); - } - - return Optional.ofNullable((T) values.iterator().next()); - } - - /** - * Gets the value for the given key if the key has only one value. - * - *

An empty {@link Optional} indicates that there are either zero or more - * than one values for the given key. Use {@link #hasAny(Text)} to verify - * which.

- * - * @param key the key to get - * @param the expected type of the argument - * @return the argument - */ - public Optional getOne(Text key) { - return this.getOne(CommandContext.textToArgKey(key)); - } - - /** - * Gets the value for the given key if the key has only one value, throws an - * exception otherwise. - * - * @param key the key to get - * @param the expected type of the argument - * @return the argument - * @throws NoSuchElementException if there is no element with the - * associated key - * @throws IllegalArgumentException if there are more than one element - * associated with the key (thus, the argument is illegal in this - * context) - * @throws ClassCastException if the element type is not what is expected - * by the caller - */ - @SuppressWarnings("unchecked") - public T requireOne(String key) throws NoSuchElementException, IllegalArgumentException, ClassCastException { - Collection values = this.parsedArgs.get(key); - - if (values.size() == 1) { - return (T) values.iterator().next(); - } else if (values.isEmpty()) { - throw new NoSuchElementException(); - } - - throw new IllegalArgumentException(); - } - - /** - * Gets the value for the given key if the key has only one value, throws an - * exception otherwise. - * - * @param key the key to get - * @param the expected type of the argument - * @return the argument - * @throws NoSuchElementException if there is no element with the - * associated key - * @throws IllegalArgumentException if there are more than one element - * associated with the key (thus, the argument is illegal in this - * context) - * @throws ClassCastException if the element type is not what is expected - */ - public T requireOne(Text key) - throws NoSuchElementException, IllegalArgumentException, ClassCastException { - return this.requireOne(CommandContext.textToArgKey(key)); - } - - /** - * Insert an argument into this context. - * - * @param key the key to store the arg under - * @param value the value for this argument - */ - public void putArg(String key, Object value) { - Preconditions.checkNotNull(value, "value"); - this.parsedArgs.put(key, value); - } - - /** - * Insert an argument into this context. - * - * @param key the key to store the arg under - * @param value the value for this argument - */ - public void putArg(Text key, Object value) { - this.putArg(CommandContext.textToArgKey(key), value); - } - - /** - * Defines the flag as being present when parsing this context. - * - * @param key the key for the flag defined - */ - public void addFlag(String key) { - this.definedFlags.add(key); - } - - /** - * Defines the flag as being present when parsing this context. - * - * @param key the key for the flag defined - */ - public void addFlag(Text key) { - this.addFlag(CommandContext.textToArgKey(key)); - } - - /** - * Perform a permissions check, throwing an exception if the required - * permissions are not present. - * - * @param commander the source to check against - * @param permission The permission to check - * @throws CommandException if the source does not have permission - */ - public void checkPermission(PermissibleCommandSource commander, String permission) throws CommandException { - if (!commander.hasPermission(permission)) { - throw new CommandException(new LiteralText("You do not have permission to use this command!")); - } - } - - /** - * Returns whether this context has any value for the given argument key. - * - * @param key The key to look up - * @return whether there are any values present - */ - public boolean hasAny(String key) { - return this.parsedArgs.containsKey(key); - } - - /** - * Returns whether this context has any value for the given argument key. - * - * @param key The key to look up - * @return whether there are any values present - */ - public boolean hasAny(Text key) { - return this.hasAny(CommandContext.textToArgKey(key)); - } - - /** - * Returns whether the given flag has been defined in this context. - * - * @param key The key to look up - * @return whether the flag is defined - */ - public boolean hasFlag(String key) { - return this.definedFlags.contains(key); - } - - /** - * Returns whether the given flag has been defined in this context. - * - * @param key The key to look up - * @return whether the flag is defined - */ - public boolean hasFlag(Text key) { - return this.hasFlag(CommandContext.textToArgKey(key)); - } - - /** - * Gets a snapshot of the data inside this context to allow it to be - * restored later. - * - *

This is only guaranteed to create a shallow copy of the - * backing store. If any value is mutable, any changes to that value - * will be reflected in this snapshot. It is therefore not recommended - * that you keep this snapshot around for longer than is necessary.

- * - * @return The {@link Snapshot} containing the current state of the - * {@link CommandContext} - */ - public Snapshot createSnapshot() { - return new Snapshot(this.parsedArgs, this.definedFlags); - } - - /** - * Resets a {@link CommandContext} to a previous state using a previously - * created {@link Snapshot}. - * - * @param snapshot The {@link Snapshot} to restore this context with - */ - public void applySnapshot(Snapshot snapshot) { - this.parsedArgs.clear(); - this.parsedArgs.putAll(snapshot.args); - this.definedFlags.clear(); - this.definedFlags.addAll(snapshot.flags); - } - - /** - * A snapshot of a {@link CommandContext}. This object does not contain any - * public API methods, a snapshot should be considered a black box. - */ - public static final class Snapshot { - final Multimap args; - final Set flags; - - Snapshot(Multimap args, Set flags) { - this.args = ArrayListMultimap.create(args); - this.flags = Sets.newHashSet(flags); - } - } - - /** - * Converts a {@link Text} into a String key. - * - * @param key the text to be converted into a string key - * @return the string key. if {@code key} is a {@link TranslatableText}, the translation key. - */ - public static String textToArgKey(@Nullable Text key) { - if (key == null) { - return null; - } - - if (key instanceof TranslatableText) { // Use translation key - return ((TranslatableText) key).getKey(); - } - - return key.computeValue(); - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandElement.java deleted file mode 100644 index 67aebbb40..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandElement.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge.args; - -import java.util.List; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; -import net.minecraft.text.TranslatableText; - -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -/** - * Represents a command argument element. - */ -public abstract class CommandElement { - @Nullable - private final Text key; - - protected CommandElement(@Nullable Text key) { - this.key = key; - } - - /** - * Return the key to be used for this object. - * - * @return the user-facing representation of the key - */ - @Nullable - public Text getKey() { - return this.key; - } - - /** - * Return the plain key, to be used when looking up this command element in - * a {@link CommandContext}. If the key is a {@link TranslatableText}, this - * is the translation's id. Otherwise, this is the result of - * {@link Text#asString()} ()} ()}. - * - * @return the raw key - */ - @Nullable - public String getUntranslatedKey() { - return CommandContext.textToArgKey(this.key); - } - - /** - * Attempt to extract a value for this element from the given arguments and - * put it in the given context. This method normally delegates to - * {@link #parseValue(PermissibleCommandSource, CommandArgs)} for getting the values. - * This method is expected to have no side-effects for the source, meaning - * that executing it will not change the state of the {@link PermissibleCommandSource} - * in any way. - * - * @param source The source to parse for - * @param args The args to extract from - * @param context The context to supply to - * @throws ArgumentParseException if unable to extract a value - */ - public void parse(PermissibleCommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException { - Object val = this.parseValue(source, args); - String key = this.getUntranslatedKey(); - - if (key != null && val != null) { - if (val instanceof Iterable) { - for (Object ent : ((Iterable) val)) { - context.putArg(key, ent); - } - } else { - context.putArg(key, val); - } - } - } - - /** - * Attempt to extract a value for this element from the given arguments. - * This method is expected to have no side-effects for the source, meaning - * that executing it will not change the state of the {@link PermissibleCommandSource} - * in any way. - * - * @param source The source to parse for - * @param args the arguments - * @return The extracted value - * @throws ArgumentParseException if unable to extract a value - */ - @Nullable - public abstract Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException; - - /** - * Fetch completions for command arguments. - * - * @param src The source requesting tab completions - * @param args The arguments currently provided - * @param context The context to store state in - * @return Any relevant completions - */ - public abstract List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context); - - /** - * Return a usage message for this specific argument. - * - * @param src The source requesting usage - * @return The formatted usage - */ - public Text getUsage(PermissibleCommandSource src) { - return this.getKey() == null ? new LiteralText("") : new LiteralText("<" + this.getKey().asUnformattedString() + ">"); - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandFlags.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandFlags.java index 9e1a5ea4c..c0927bf6a 100644 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandFlags.java +++ b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandFlags.java @@ -183,7 +183,7 @@ public Text getUsage(PermissibleCommandSource src) { if (usage.asUnformattedString().trim().length() > 0) { builder.add(" "); - builder.add(usage); + builder.add(usage.asUnformattedString()); } builder.add("]"); diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/KeyElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/KeyElement.java deleted file mode 100644 index 1fc48c36b..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/KeyElement.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge.args; - -import java.util.Collections; -import java.util.List; - -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -/** - * Parent class that specifies elements as having no tab completions. - * Useful for inputs with a very large domain, like strings and integers. - */ -public abstract class KeyElement extends CommandElement { - protected KeyElement(Text key) { - super(key); - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - return Collections.emptyList(); - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/PatternMatchingCommandElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/PatternMatchingCommandElement.java deleted file mode 100644 index efa95b171..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/PatternMatchingCommandElement.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge.args; - -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.regex.Pattern; -import java.util.stream.Collectors; -import java.util.stream.StreamSupport; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -/** - * Abstract command element that matches values based on a regex pattern. - */ -public abstract class PatternMatchingCommandElement extends CommandElement { - private static final Text nullKeyArg = new LiteralText("argument"); - final boolean useRegex; - - /** - * @param yesIWantRegex Specify if you want to allow regex for users of - * the command element. Note that this will open up for DoS attacks. - */ - protected PatternMatchingCommandElement(@Nullable Text key, boolean yesIWantRegex) { - super(key); - this.useRegex = yesIWantRegex; - } - - protected PatternMatchingCommandElement(@Nullable Text key) { - this(key, false); - } - - @Nullable - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - Iterable choices = this.getChoices(source); - Iterable ret; - String arg = args.next(); - - // Check to see if we have an exact match first - Optional exactMatch = this.getExactMatch(choices, arg); - - if (exactMatch.isPresent()) { - // Return this as a collection as this can get transformed by the subclass. - return Collections.singleton(exactMatch.get()); - } - - if (this.useRegex) { - Pattern pattern = this.getFormattedPattern(arg); - ret = StreamSupport.stream(choices.spliterator(), false).filter(element -> pattern.matcher(element).find()).collect(Collectors.toList()).stream().map(this::getValue).collect(Collectors.toList()); - } else { - Iterable startsWith = StreamSupport.stream(choices.spliterator(), false).filter(element -> element.regionMatches(true, 0, arg, 0, arg.length())).collect(Collectors.toList()); - ret = StreamSupport.stream(startsWith.spliterator(), false).map(this::getValue).collect(Collectors.toList()); - } - - if (!ret.iterator().hasNext()) { - throw args.createError(new LiteralText(String.format("No values matching pattern '%s' present for %s!", arg, this.getKey() == null - ? nullKeyArg : this.getKey()))); - } - - return ret; - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - Iterable choices = this.getChoices(src); - final Optional nextArg = args.nextIfPresent(); - - if (nextArg.isPresent()) { - if (this.useRegex) { - choices = StreamSupport.stream(choices.spliterator(), false).filter(input -> this.getFormattedPattern(nextArg.get()).matcher(input).find()).collect(Collectors.toList()); - } else { - String arg = nextArg.get(); - choices = StreamSupport.stream(choices.spliterator(), false).filter(input -> input.regionMatches(true, 0, arg, 0, arg.length())).collect(Collectors.toList()); - } - } - - return ImmutableList.copyOf(choices); - } - - Pattern getFormattedPattern(String input) { - if (!input.startsWith("^")) { // Anchor matches to the beginning -- this lets us use find() - input = "^" + input; - } - - return Pattern.compile(input, Pattern.CASE_INSENSITIVE); - } - - /** - * Tests a string against a set of valid choices to see if it is a - * case-insensitive match. - * - * @param choices The choices available to match against - * @param potentialChoice The potential choice - * @return If matched, an {@link Optional} containing the matched value - */ - protected Optional getExactMatch(final Iterable choices, final String potentialChoice) { - return Optional.ofNullable(Iterables.tryFind(choices, potentialChoice::equalsIgnoreCase).orNull()).map(this::getValue); - } - - /** - * Gets the available choices for this command source. - * - * @param source The source requesting choices - * @return the possible choices - */ - protected abstract Iterable getChoices(PermissibleCommandSource source); - - /** - * Gets the value for a given choice. For any result in - * {@link #getChoices(PermissibleCommandSource)}, this must return a non-null value. - * Otherwise, an {@link IllegalArgumentException} may be throw. - * - * @param choice The specified choice - * @return the choice's value - * @throws IllegalArgumentException if the input string is not any return - * value of {@link #getChoices(PermissibleCommandSource)} - */ - protected abstract Object getValue(String choice) throws IllegalArgumentException; -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/InputTokenizer.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/InputTokenizer.java deleted file mode 100644 index 7b838414a..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/InputTokenizer.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge.args.parsing; - -import java.util.List; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; - -public interface InputTokenizer { - /** - * Use an input string tokenizer that supports quoted arguments and - * character escapes. - * - *

Forcing lenient to true makes the following apply:

- * - *
    - *
  • Unclosed quotations are treated as a single string from the - * opening quotation to the end of the arguments rather than throwing - * an exception
  • - *
- * - * @param forceLenient Whether the tokenizer is forced into lenient mode - * @return the appropriate tokenizer - */ - static InputTokenizer quotedStrings(boolean forceLenient) { - return new QuotedStringTokenizer(true, forceLenient, false); - } - - /** - * Returns an input tokenizer that takes input strings and splits them by - * space. - * - * @return The appropriate tokenizer - */ - static InputTokenizer spaceSplitString() { - return SpaceSplitInputTokenizer.INSTANCE; - } - - /** - * Returns an input tokenizer that returns the input string as a single - * argument. - * - * @return The appropriate tokenizer - */ - static InputTokenizer rawInput() { - return RawStringInputTokenizer.INSTANCE; - } - - /** - * Take the input string and split it as appropriate into argument tokens. - * - * @param arguments The provided arguments - * @param lenient Whether to parse leniently - * @return The tokenized strings. Empty list if error occurs - * @throws ArgumentParseException if an invalid input is provided - */ - List tokenize(String arguments, boolean lenient) throws ArgumentParseException; -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/QuotedStringTokenizer.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/QuotedStringTokenizer.java deleted file mode 100644 index 256287791..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/QuotedStringTokenizer.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge.args.parsing; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import net.minecraft.text.LiteralText; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; - -/** - * Parser for converting a quoted string into a list of arguments. - * - *

Grammar is roughly (yeah, this is not really a proper grammar but it gives - * you an idea of what's happening:

- * - *
 WHITESPACE = Character.isWhiteSpace(codePoint)
- * CHAR := (all unicode)
- * ESCAPE := '\' CHAR
- * QUOTE = ' | "
- * UNQUOTED_ARG := (CHAR | ESCAPE)+ WHITESPACE
- * QUOTED_ARG := QUOTE (CHAR | ESCAPE)+ QUOTE
- * ARGS := ((UNQUOTED_ARG | QUOTED_ARG) WHITESPACE+)+
- */ -class QuotedStringTokenizer implements InputTokenizer { - private static final int CHAR_BACKSLASH = '\\'; - private static final int CHAR_SINGLE_QUOTE = '\''; - private static final int CHAR_DOUBLE_QUOTE = '"'; - private final boolean handleQuotedStrings; - private final boolean forceLenient; - private final boolean trimTrailingSpace; - - QuotedStringTokenizer(boolean handleQuotedStrings, boolean forceLenient, boolean trimTrailingSpace) { - this.handleQuotedStrings = handleQuotedStrings; - this.forceLenient = forceLenient; - this.trimTrailingSpace = trimTrailingSpace; - } - - @Override - public List tokenize(String arguments, boolean lenient) throws ArgumentParseException { - if (arguments.length() == 0) { - return Collections.emptyList(); - } - - final TokenizerState state = new TokenizerState(arguments, lenient); - List returnedArgs = new ArrayList<>(arguments.length() / 4); - - if (this.trimTrailingSpace) { - this.skipWhiteSpace(state); - } - - while (state.hasMore()) { - if (!this.trimTrailingSpace) { - this.skipWhiteSpace(state); - } - - int startIdx = state.getIndex() + 1; - String arg = this.nextArg(state); - returnedArgs.add(new SingleArg(arg, startIdx, state.getIndex())); - - if (this.trimTrailingSpace) { - this.skipWhiteSpace(state); - } - } - - return returnedArgs; - } - - // Parsing methods - - private void skipWhiteSpace(TokenizerState state) throws ArgumentParseException { - if (!state.hasMore()) { - return; - } - - while (state.hasMore() && Character.isWhitespace(state.peek())) { - state.next(); - } - } - - private String nextArg(TokenizerState state) throws ArgumentParseException { - StringBuilder argBuilder = new StringBuilder(); - - if (state.hasMore()) { - int codePoint = state.peek(); - - if (this.handleQuotedStrings && (codePoint == CHAR_DOUBLE_QUOTE || codePoint == CHAR_SINGLE_QUOTE)) { - // quoted string - this.parseQuotedString(state, codePoint, argBuilder); - } else { - this.parseUnquotedString(state, argBuilder); - } - } - - return argBuilder.toString(); - } - - private void parseQuotedString(TokenizerState state, int startQuotation, StringBuilder builder) throws ArgumentParseException { - // Consume the start quotation character - int nextCodePoint = state.next(); - - if (nextCodePoint != startQuotation) { - throw state.createException(new LiteralText(String.format("Actual next character '%c' did not match expected quotation character '%c'", - nextCodePoint, startQuotation))); - } - - while (true) { - if (!state.hasMore()) { - if (state.isLenient() || this.forceLenient) { - return; - } - - throw state.createException(new LiteralText("Unterminated quoted string found")); - } - - nextCodePoint = state.peek(); - - if (nextCodePoint == startQuotation) { - state.next(); - return; - } else if (nextCodePoint == CHAR_BACKSLASH) { - this.parseEscape(state, builder); - } else { - builder.appendCodePoint(state.next()); - } - } - } - - private void parseUnquotedString(TokenizerState state, StringBuilder builder) throws ArgumentParseException { - while (state.hasMore()) { - int nextCodePoint = state.peek(); - - if (Character.isWhitespace(nextCodePoint)) { - return; - } else if (nextCodePoint == CHAR_BACKSLASH) { - this.parseEscape(state, builder); - } else { - builder.appendCodePoint(state.next()); - } - } - } - - private void parseEscape(TokenizerState state, StringBuilder builder) throws ArgumentParseException { - state.next(); // Consume \ - builder.appendCodePoint(state.next()); // TODO: Unicode character escapes (\u00A7 type thing)? - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/RawStringInputTokenizer.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/RawStringInputTokenizer.java deleted file mode 100644 index fe46931e3..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/RawStringInputTokenizer.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge.args.parsing; - -import java.util.Collections; -import java.util.List; - -class RawStringInputTokenizer implements InputTokenizer { - static final RawStringInputTokenizer INSTANCE = new RawStringInputTokenizer(); - - private RawStringInputTokenizer() { - } - - @Override - public List tokenize(String arguments, boolean lenient) { - return Collections.singletonList(new SingleArg(arguments, 0, arguments.length())); - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SpaceSplitInputTokenizer.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SpaceSplitInputTokenizer.java deleted file mode 100644 index 3caa7d81d..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SpaceSplitInputTokenizer.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge.args.parsing; - -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Pattern; - -import com.google.common.collect.ImmutableList; - -class SpaceSplitInputTokenizer implements InputTokenizer { - public static final SpaceSplitInputTokenizer INSTANCE = new SpaceSplitInputTokenizer(); - private static final Pattern SPACE_REGEX = Pattern.compile("^[ ]*$"); - - private SpaceSplitInputTokenizer() { - } - - @Override - public List tokenize(String arguments, boolean lenient) { - if (SPACE_REGEX.matcher(arguments).matches()) { - return ImmutableList.of(); - } - - List ret = new ArrayList<>(); - int lastIndex = 0; - int spaceIndex; - - while ((spaceIndex = arguments.indexOf(" ")) != -1) { - if (spaceIndex != 0) { - ret.add(new SingleArg(arguments.substring(0, spaceIndex), lastIndex, lastIndex + spaceIndex)); - arguments = arguments.substring(spaceIndex); - } else { - arguments = arguments.substring(1); - } - - lastIndex += spaceIndex + 1; - } - - ret.add(new SingleArg(arguments, lastIndex, lastIndex + arguments.length())); - return ret; - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/TokenizerState.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/TokenizerState.java deleted file mode 100644 index a93a0515b..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/TokenizerState.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.api.command.v2.lib.sponge.args.parsing; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; - -class TokenizerState { - private final boolean lenient; - private final String buffer; - private int index = -1; - - TokenizerState(String buffer, boolean lenient) { - this.buffer = buffer; - this.lenient = lenient; - } - - // Utility methods - public boolean hasMore() { - return this.index + 1 < this.buffer.length(); - } - - public int peek() throws ArgumentParseException { - if (!this.hasMore()) { - throw this.createException(new LiteralText("Buffer overrun while parsing args")); - } - - return this.buffer.codePointAt(this.index + 1); - } - - public int next() throws ArgumentParseException { - if (!this.hasMore()) { - throw this.createException(new LiteralText("Buffer overrun while parsing args")); - } - - return this.buffer.codePointAt(++this.index); - } - - public ArgumentParseException createException(Text message) { - return new ArgumentParseException(message, this.buffer, this.index); - } - - public boolean isLenient() { - return this.lenient; - } - - public int getIndex() { - return this.index; - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/AllOfCommandElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/AllOfCommandElement.java deleted file mode 100644 index 72e55d551..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/AllOfCommandElement.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.Collections; -import java.util.List; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.CommandMessageFormatting; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandContext; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class AllOfCommandElement extends CommandElement { - private final CommandElement element; - - public AllOfCommandElement(CommandElement element) { - super(null); - this.element = element; - } - - @Override - public void parse(PermissibleCommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException { - while (args.hasNext()) { - this.element.parse(source, args, context); - } - } - - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - return null; - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - CommandArgs.Snapshot startState = null; - - try { - while (args.hasNext()) { - startState = args.getSnapshot(); - this.element.parse(src, args, context); - } - } catch (ArgumentParseException e) { - // ignored - } - - // The final element, if an exception was not thrown, might have more completions available to it. - // Therefore, we reapply the last snapshot and complete from it. - if (startState != null) { - args.applySnapshot(startState); - } - - if (args.canComplete()) { - return this.element.complete(src, args, context); - } - - // If we have more elements, do not complete. - return Collections.emptyList(); - } - - @Override - public Text getUsage(PermissibleCommandSource context) { - return new LiteralText(this.element.getUsage(context).asUnformattedString() + CommandMessageFormatting.STAR_TEXT.computeValue()); - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/BigDecimalElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/BigDecimalElement.java deleted file mode 100644 index 3d762821c..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/BigDecimalElement.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.math.BigDecimal; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.KeyElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class BigDecimalElement extends KeyElement { - public BigDecimalElement(Text key) { - super(key); - } - - @Nullable - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - String next = args.next(); - - try { - return new BigDecimal(next); - } catch (NumberFormatException ex) { - throw args.createError(new LiteralText("Expected a number, but input " + next + " was not")); - } - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/BigIntegerElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/BigIntegerElement.java deleted file mode 100644 index 99368f2ee..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/BigIntegerElement.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.math.BigInteger; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.KeyElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class BigIntegerElement extends KeyElement { - public BigIntegerElement(Text key) { - super(key); - } - - @Nullable - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - String integerString = args.next(); - - try { - return new BigInteger(integerString); - } catch (NumberFormatException ex) { - throw args.createError(new LiteralText("Expected an integer, but input " + integerString + " was not")); - } - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/ChoicesCommandElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/ChoicesCommandElement.java deleted file mode 100644 index c8dd91a8a..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/ChoicesCommandElement.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.function.Function; -import java.util.function.Supplier; -import java.util.stream.Collectors; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.CommandMessageFormatting; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandContext; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; -import net.legacyfabric.fabric.api.util.TriState; - -public class ChoicesCommandElement extends CommandElement { - public static final int CUTOFF = 5; - private final Supplier> keySupplier; - private final Function valueSupplier; - private final TriState choicesInUsage; - - public ChoicesCommandElement(Text key, Supplier> keySupplier, Function valueSupplier, TriState choicesInUsage) { - super(key); - this.keySupplier = keySupplier; - this.valueSupplier = valueSupplier; - this.choicesInUsage = choicesInUsage; - } - - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - Object value = this.valueSupplier.apply(args.next()); - - if (value == null) { - throw args.createError(new LiteralText(String.format("Argument was not a valid choice. Valid choices: %s", this.keySupplier.get().toString()))); - } - - return value; - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - final String prefix = args.nextIfPresent().orElse(""); - return Collections.unmodifiableList(this.keySupplier.get().stream().filter((input) -> input.startsWith(prefix)).collect(Collectors.toList())); - } - - @Override - public Text getUsage(PermissibleCommandSource commander) { - Collection keys = this.keySupplier.get(); - - if (this.choicesInUsage == TriState.TRUE || (this.choicesInUsage == TriState.DEFAULT && keys.size() <= CUTOFF)) { - final Text build = new LiteralText(""); - build.append(CommandMessageFormatting.LT_TEXT); - - for (Iterator it = keys.iterator(); it.hasNext(); ) { - build.append(new LiteralText(it.next())); - - if (it.hasNext()) { - build.append(CommandMessageFormatting.PIPE_TEXT); - } - } - - build.append(CommandMessageFormatting.GT_TEXT); - return new LiteralText(build.asUnformattedString()); - } - - return super.getUsage(commander); - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/DateTimeElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/DateTimeElement.java deleted file mode 100644 index 93e19c7ba..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/DateTimeElement.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.format.DateTimeParseException; -import java.util.List; - -import com.google.common.collect.ImmutableList; -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandContext; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class DateTimeElement extends CommandElement { - private final boolean returnNow; - - public DateTimeElement(Text key, boolean returnNow) { - super(key); - this.returnNow = returnNow; - } - - @Nullable - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - if (!args.hasNext() && this.returnNow) { - return LocalDateTime.now(); - } - - CommandArgs.Snapshot state = args.getSnapshot(); - String date = args.next(); - - try { - return LocalDateTime.parse(date); - } catch (DateTimeParseException ex) { - try { - return LocalDateTime.of(LocalDate.now(), LocalTime.parse(date)); - } catch (DateTimeParseException ex2) { - try { - return LocalDateTime.of(LocalDate.parse(date), LocalTime.MIDNIGHT); - } catch (DateTimeParseException ex3) { - if (this.returnNow) { - args.applySnapshot(state); - return LocalDateTime.now(); - } - - throw args.createError(new LiteralText("Invalid date-time!")); - } - } - } - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - String date = LocalDateTime.now().withNano(0).toString(); - - if (date.startsWith(args.nextIfPresent().orElse(""))) { - return ImmutableList.of(date); - } else { - return ImmutableList.of(); - } - } - - @Override - public Text getUsage(PermissibleCommandSource src) { - if (!this.returnNow) { - return super.getUsage(src); - } else { - return new LiteralText("[" + this.getKey().asUnformattedString() + "]"); - } - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/DurationElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/DurationElement.java deleted file mode 100644 index ef161bb88..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/DurationElement.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.time.Duration; -import java.time.format.DateTimeParseException; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.KeyElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class DurationElement extends KeyElement { - public DurationElement(Text key) { - super(key); - } - - @Nullable - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - String s = args.next().toUpperCase(); - - if (!s.contains("T")) { - if (s.contains("D")) { - if (s.contains("H") || s.contains("M") || s.contains("S")) { - s = s.replace("D", "DT"); - } - } else { - if (s.startsWith("P")) { - s = "PT" + s.substring(1); - } else { - s = "T" + s; - } - } - } - - if (!s.startsWith("P")) { - s = "P" + s; - } - - try { - return Duration.parse(s); - } catch (DateTimeParseException ex) { - throw args.createError(new LiteralText("Invalid duration!")); - } - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/EntityCommandElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/EntityCommandElement.java index 1bffd8838..bd018bc5d 100644 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/EntityCommandElement.java +++ b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/EntityCommandElement.java @@ -119,11 +119,11 @@ protected Object getValue(String choice) throws IllegalArgumentException { uuid = UUID.fromString(choice); } catch (IllegalArgumentException ignored) { // Player could be a name - return Optional.ofNullable(MinecraftServer.getServer().getPlayerManager().getPlayer(choice)).orElseThrow(() -> new IllegalArgumentException("Input value " + choice + " does not represent a valid entity")); + return Optional.ofNullable(this.getServer().getPlayerManager().getPlayer(choice)).orElseThrow(() -> new IllegalArgumentException("Input value " + choice + " does not represent a valid entity")); } boolean found = false; - Optional ret = Optional.ofNullable(MinecraftServer.getServer().getEntity(uuid)); + Optional ret = Optional.ofNullable(this.getServer().getEntity(uuid)); if (ret.isPresent()) { Entity entity = ret.get(); diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/EnumValueElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/EnumValueElement.java deleted file mode 100644 index a9e260670..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/EnumValueElement.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.Arrays; -import java.util.Map; -import java.util.function.Function; -import java.util.stream.Collectors; - -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.PatternMatchingCommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class EnumValueElement> extends PatternMatchingCommandElement { - private final Class type; - private final Map values; - - public EnumValueElement(Text key, Class type) { - super(key); - this.type = type; - this.values = Arrays.stream(type.getEnumConstants()) - .collect(Collectors.toMap(value -> value.name().toLowerCase(), - Function.identity(), (value, value2) -> { - throw new UnsupportedOperationException(type.getCanonicalName() + " contains more than one enum constant " + "with the same name, only differing by capitalization, which is unsupported."); - } - )); - } - - @Override - protected Iterable getChoices(PermissibleCommandSource source) { - return this.values.keySet(); - } - - @Override - protected Object getValue(String choice) throws IllegalArgumentException { - T value = this.values.get(choice.toLowerCase()); - - if (value == null) { - throw new IllegalArgumentException("No enum constant " + this.type.getCanonicalName() + "." + choice); - } - - return value; - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/FilteredSuggestionsElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/FilteredSuggestionsElement.java deleted file mode 100644 index 01d7c3883..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/FilteredSuggestionsElement.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.Collections; -import java.util.List; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -import org.jetbrains.annotations.Nullable; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandContext; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class FilteredSuggestionsElement extends CommandElement { - private final CommandElement wrapped; - private final Predicate predicate; - - public FilteredSuggestionsElement(CommandElement wrapped, Predicate predicate) { - super(wrapped.getKey()); - this.wrapped = wrapped; - this.predicate = predicate; - } - - @Nullable - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - return this.wrapped.parseValue(source, args); - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - return Collections.unmodifiableList(this.wrapped.complete(src, args, context).stream().filter(this.predicate).collect(Collectors.toList())); - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/FirstParsingCommandElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/FirstParsingCommandElement.java deleted file mode 100644 index 597d41de0..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/FirstParsingCommandElement.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.Iterator; -import java.util.List; -import java.util.stream.Collectors; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.CommandMessageFormatting; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandContext; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class FirstParsingCommandElement extends CommandElement { - private final List elements; - - public FirstParsingCommandElement(List elements) { - super(null); - this.elements = elements; - } - - @Override - public void parse(PermissibleCommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException { - ArgumentParseException lastException = null; - - for (CommandElement element : this.elements) { - CommandArgs.Snapshot startState = args.getSnapshot(); - CommandContext.Snapshot contextSnapshot = context.createSnapshot(); - - try { - element.parse(source, args, context); - return; - } catch (ArgumentParseException ex) { - lastException = ex; - args.applySnapshot(startState); - context.applySnapshot(contextSnapshot); - } - } - - if (lastException != null) { - throw lastException; - } - } - - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - return null; - } - - @Override - public List complete(final PermissibleCommandSource src, final CommandArgs args, final CommandContext context) { - return Lists.newLinkedList(Iterables.concat(this.elements.stream().map(element -> { - if (element == null) { - return ImmutableList.of(); - } else { - CommandArgs.Snapshot snapshot = args.getSnapshot(); - List ret = element.complete(src, args, context); - args.applySnapshot(snapshot); - return ret; - } - }).collect(Collectors.toSet()))); - } - - @Override - public Text getUsage(PermissibleCommandSource commander) { - final Text ret = new LiteralText(""); - - for (Iterator it = this.elements.iterator(); it.hasNext(); ) { - ret.append(it.next().getUsage(commander)); - - if (it.hasNext()) { - ret.append(CommandMessageFormatting.PIPE_TEXT); - } - } - - return new LiteralText(ret.asUnformattedString()); - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/LiteralCommandElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/LiteralCommandElement.java deleted file mode 100644 index 8544e38a4..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/LiteralCommandElement.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.List; -import java.util.Optional; - -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableList; -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandContext; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class LiteralCommandElement extends CommandElement { - private final List expectedArgs; - @Nullable - private final Object putValue; - - public LiteralCommandElement(@Nullable Text key, List expectedArgs, @Nullable Object putValue) { - super(key); - this.expectedArgs = ImmutableList.copyOf(expectedArgs); - this.putValue = putValue; - } - - @Nullable - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - for (String arg : this.expectedArgs) { - String current; - - if (!(current = args.next()).equalsIgnoreCase(arg)) { - throw args.createError(new LiteralText(String.format("Argument %s did not match expected next argument %s", current, arg))); - } - } - - return this.putValue; - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - for (String arg : this.expectedArgs) { - final Optional next = args.nextIfPresent(); - - if (!next.isPresent()) { - break; - } else if (args.hasNext()) { - if (!next.get().equalsIgnoreCase(arg)) { - break; - } - } else { - if (arg.toLowerCase().startsWith(next.get().toLowerCase())) { // Case-insensitive compare - return ImmutableList.of(arg); // TODO: Possibly complete all remaining args? Does that even work - } - } - } - - return ImmutableList.of(); - } - - @Override - public Text getUsage(PermissibleCommandSource src) { - return new LiteralText(Joiner.on(' ').join(this.expectedArgs)); - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/MarkTrueCommandElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/MarkTrueCommandElement.java deleted file mode 100644 index ac862d943..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/MarkTrueCommandElement.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.Collections; -import java.util.List; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandContext; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class MarkTrueCommandElement extends CommandElement { - public MarkTrueCommandElement(Text key) { - super(key); - } - - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - return true; - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - return Collections.emptyList(); - } - - @Override - public Text getUsage(PermissibleCommandSource src) { - return new LiteralText(""); - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/ModCommandElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/ModCommandElement.java deleted file mode 100644 index 250f0586e..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/ModCommandElement.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.Optional; -import java.util.stream.Collectors; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.Text; - -import net.fabricmc.loader.api.FabricLoader; -import net.fabricmc.loader.api.ModContainer; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.PatternMatchingCommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class ModCommandElement extends PatternMatchingCommandElement { - public ModCommandElement(@Nullable Text key) { - super(key); - } - - @Override - protected Iterable getChoices(PermissibleCommandSource source) { - return FabricLoader.getInstance().getAllMods().stream().map(container -> container.getMetadata().getId()).collect(Collectors.toSet()); - } - - @Override - protected Object getValue(String choice) throws IllegalArgumentException { - Optional plugin = FabricLoader.getInstance().getModContainer(choice); - return plugin.orElseThrow(() -> new IllegalArgumentException("Mod " + choice + " was not found")); - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/NumericElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/NumericElement.java deleted file mode 100644 index 0eb493945..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/NumericElement.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.function.BiFunction; -import java.util.function.Function; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.KeyElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class NumericElement extends KeyElement { - private final Function parseFunc; - @Nullable - private final BiFunction parseRadixFunction; - private final Function errorSupplier; - - public NumericElement(Text key, Function parseFunc, @Nullable BiFunction parseRadixFunction, Function errorSupplier) { - super(key); - this.parseFunc = parseFunc; - this.parseRadixFunction = parseRadixFunction; - this.errorSupplier = errorSupplier; - } - - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - final String input = args.next(); - - try { - if (this.parseRadixFunction != null) { - if (input.startsWith("0x")) { - return this.parseRadixFunction.apply(input.substring(2), 16); - } else if (input.startsWith("0b")) { - return this.parseRadixFunction.apply(input.substring(2), 2); - } - } - - return this.parseFunc.apply(input); - } catch (NumberFormatException ex) { - throw args.createError(this.errorSupplier.apply(input)); - } - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OnlyOneCommandElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OnlyOneCommandElement.java deleted file mode 100644 index ba0173c43..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OnlyOneCommandElement.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.List; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandContext; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class OnlyOneCommandElement extends CommandElement { - private final CommandElement element; - - public OnlyOneCommandElement(CommandElement element) { - super(element.getKey()); - this.element = element; - } - - @Override - public void parse(PermissibleCommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException { - this.element.parse(source, args, context); - - if (context.getAll(this.element.getUntranslatedKey()).size() > 1) { - Text key = this.element.getKey(); - throw args.createError(new LiteralText(String.format("Argument %s may have only one value!", key != null ? key : "unknown"))); - } - } - - @Override - public Text getUsage(PermissibleCommandSource src) { - return this.element.getUsage(src); - } - - @Nullable - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - return this.element.parseValue(source, args); - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - return this.element.complete(src, args, context); - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OptionalCommandElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OptionalCommandElement.java deleted file mode 100644 index 8abf3f5be..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OptionalCommandElement.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.List; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandContext; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class OptionalCommandElement extends CommandElement { - private final CommandElement element; - @Nullable - private final Object value; - private final boolean considerInvalidFormatEmpty; - - public OptionalCommandElement(CommandElement element, @Nullable Object value, boolean considerInvalidFormatEmpty) { - super(null); - this.element = element; - this.value = value; - this.considerInvalidFormatEmpty = considerInvalidFormatEmpty; - } - - @Override - public void parse(PermissibleCommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException { - if (!args.hasNext()) { - Text key = this.element.getKey(); - - if (key != null && this.value != null) { - context.putArg(key.computeValue(), this.value); - } - - return; - } - - CommandArgs.Snapshot startState = args.getSnapshot(); - - try { - this.element.parse(source, args, context); - } catch (ArgumentParseException ex) { - if (this.considerInvalidFormatEmpty || args.hasNext()) { // If there are more args, suppress. Otherwise, throw the error - args.applySnapshot(startState); - - if (this.element.getKey() != null && this.value != null) { - context.putArg(this.element.getUntranslatedKey(), this.value); - } - } else { - throw ex; - } - } - } - - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - return args.hasNext() ? null : this.element.parseValue(source, args); - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - return this.element.complete(src, args, context); - } - - @Override - public Text getUsage(PermissibleCommandSource src) { - final Text containingUsage = this.element.getUsage(src); - - if (containingUsage.asUnformattedString().isEmpty()) { - return new LiteralText(""); - } - - return new LiteralText("[" + this.element.getUsage(src) + "]"); - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/PlayerCommandElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/PlayerCommandElement.java index 62276338d..f67b1ffd7 100644 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/PlayerCommandElement.java +++ b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/PlayerCommandElement.java @@ -77,7 +77,7 @@ protected Iterable getChoices(PermissibleCommandSource source) { @Override protected Object getValue(String choice) throws IllegalArgumentException { - Optional ret = MinecraftServer.getServer().getPlayerManager().getPlayers().stream().findFirst().map(Function.identity()); + Optional ret = this.getServer().getPlayerManager().getPlayers().stream().findFirst().map(Function.identity()); if (!ret.isPresent()) { throw new IllegalArgumentException("Input value " + choice + " was not a player"); @@ -96,6 +96,6 @@ private PlayerEntity tryReturnSource(PermissibleCommandSource source, CommandArg @Override public Text getUsage(PermissibleCommandSource src) { - return src != null && this.returnSource ? new LiteralText("[" + super.getUsage(src) + "]") : super.getUsage(src); + return src != null && this.returnSource ? new LiteralText("[" + super.getUsage(src).asUnformattedString() + "]") : super.getUsage(src); } } diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/RemainingJoinedStringsCommandElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/RemainingJoinedStringsCommandElement.java deleted file mode 100644 index a145ca7d1..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/RemainingJoinedStringsCommandElement.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.CommandMessageFormatting; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.KeyElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class RemainingJoinedStringsCommandElement extends KeyElement { - private final boolean raw; - - public RemainingJoinedStringsCommandElement(Text key, boolean raw) { - super(key); - this.raw = raw; - } - - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - if (this.raw) { - args.next(); - String ret = args.getRaw().substring(args.getRawPosition()); - - while (args.hasNext()) { // Consume remaining args - args.next(); - } - - return ret; - } - - final StringBuilder ret = new StringBuilder(args.next()); - - while (args.hasNext()) { - ret.append(' ').append(args.next()); - } - - return ret.toString(); - } - - @Override - public Text getUsage(PermissibleCommandSource src) { - return new LiteralText("").append(CommandMessageFormatting.LT_TEXT.asUnformattedString()).append(this.getKey()).append(CommandMessageFormatting.ELLIPSIS_TEXT).append(CommandMessageFormatting.GT_TEXT); - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/RepeatedCommandElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/RepeatedCommandElement.java deleted file mode 100644 index 4128da783..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/RepeatedCommandElement.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.Collections; -import java.util.List; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandContext; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class RepeatedCommandElement extends CommandElement { - private final CommandElement element; - private final int times; - - public RepeatedCommandElement(CommandElement element, int times) { - super(null); - this.element = element; - this.times = times; - } - - @Override - public void parse(PermissibleCommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException { - for (int i = 0; i < this.times; ++i) { - this.element.parse(source, args, context); - } - } - - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - return null; - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - for (int i = 0; i < this.times; ++i) { - CommandArgs.Snapshot startState = args.getSnapshot(); - - try { - this.element.parse(src, args, context); - } catch (ArgumentParseException e) { - args.applySnapshot(startState); - return this.element.complete(src, args, context); - } - } - - return Collections.emptyList(); - } - - @Override - public Text getUsage(PermissibleCommandSource src) { - return new LiteralText(this.times + '*' + this.element.getUsage(src).asUnformattedString()); - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/SequenceCommandElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/SequenceCommandElement.java deleted file mode 100644 index f08c2b2fc..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/SequenceCommandElement.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.CommandMessageFormatting; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandContext; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class SequenceCommandElement extends CommandElement { - private final List elements; - - public SequenceCommandElement(List elements) { - super(null); - this.elements = elements; - } - - @Override - public void parse(PermissibleCommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException { - for (CommandElement element : this.elements) { - element.parse(source, args, context); - } - } - - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - return null; - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - Set completions = Sets.newHashSet(); - - for (CommandElement element : this.elements) { - CommandArgs.Snapshot state = args.getSnapshot(); - CommandContext.Snapshot contextSnapshot = context.createSnapshot(); - - try { - element.parse(src, args, context); - - // If we get here, the parse occurred successfully. - // However, if nothing was consumed, then we should consider - // what could have been. - CommandContext.Snapshot afterSnapshot = context.createSnapshot(); - - if (state.equals(args.getSnapshot())) { - context.applySnapshot(contextSnapshot); - completions.addAll(element.complete(src, args, context)); - args.applySnapshot(state); - context.applySnapshot(afterSnapshot); - } else if (args.hasNext()) { - completions.clear(); - } else { - // What we might also have - we have no args left to parse so - // while the parse itself was successful, there could be other - // valid entries to add... - context.applySnapshot(contextSnapshot); - args.applySnapshot(state); - completions.addAll(element.complete(src, args, context)); - - if (!(element instanceof OptionalCommandElement)) { - break; - } - - // The last element was optional, so we go back to before this - // element would have been parsed, and assume it never existed... - context.applySnapshot(contextSnapshot); - args.applySnapshot(state); - } - } catch (ArgumentParseException ignored) { - args.applySnapshot(state); - context.applySnapshot(contextSnapshot); - completions.addAll(element.complete(src, args, context)); - break; - } - } - - return Lists.newArrayList(completions); - } - - @Override - public Text getUsage(PermissibleCommandSource commander) { - final Text build = new LiteralText(""); - - for (Iterator it = this.elements.iterator(); it.hasNext(); ) { - Text usage = it.next().getUsage(commander); - - if (!usage.asUnformattedString().isEmpty()) { - build.append(usage); - - if (it.hasNext()) { - build.append(CommandMessageFormatting.SPACE_TEXT); - } - } - } - - return new LiteralText(build.asUnformattedString()); - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/StringCommandElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/StringCommandElement.java deleted file mode 100644 index bd4ef8e26..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/StringCommandElement.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.StringType; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.KeyElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class StringCommandElement extends KeyElement { - private final StringType stringType; - private final RemainingJoinedStringsCommandElement joinedElement; - - public StringCommandElement(Text key, StringType type) { - super(key); - this.stringType = type; - this.joinedElement = type.isAll() ? new RemainingJoinedStringsCommandElement(key, false) : null; - } - - @Nullable - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - return this.stringType.isAll() ? (String) this.joinedElement.parseValue(source, args) : args.next(); - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/StringElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/StringElement.java deleted file mode 100644 index 649e4a077..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/StringElement.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.KeyElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class StringElement extends KeyElement { - public StringElement(Text key) { - super(key); - } - - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - return args.next(); - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/UrlElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/UrlElement.java deleted file mode 100644 index 14f0f856f..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/UrlElement.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.net.MalformedURLException; -import java.net.URISyntaxException; -import java.net.URL; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.KeyElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class UrlElement extends KeyElement { - public UrlElement(Text key) { - super(key); - } - - @Nullable - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - String str = args.next(); - URL url; - - try { - url = new URL(str); - } catch (MalformedURLException ex) { - throw new ArgumentParseException(new LiteralText("Invalid URL!"), ex, str, 0); - } - - try { - url.toURI(); - } catch (URISyntaxException ex) { - throw new ArgumentParseException(new LiteralText("Invalid URL!"), ex, str, 0); - } - - return url; - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/UuidElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/UuidElement.java deleted file mode 100644 index 16db686da..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/UuidElement.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.UUID; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.KeyElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class UuidElement extends KeyElement { - public UuidElement(Text key) { - super(key); - } - - @Nullable - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - try { - return UUID.fromString(args.next()); - } catch (IllegalArgumentException ex) { - throw args.createError(new LiteralText("Invalid UUID!")); - } - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/WithSuggestionsElement.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/WithSuggestionsElement.java deleted file mode 100644 index 389e75583..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/WithSuggestionsElement.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * This file is part of SpongeAPI, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.legacyfabric.fabric.impl.command.lib.sponge.args; - -import java.util.List; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.StreamSupport; - -import com.google.common.collect.ImmutableList; -import org.jetbrains.annotations.Nullable; - -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.ArgumentParseException; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandArgs; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandContext; -import net.legacyfabric.fabric.api.command.v2.lib.sponge.args.CommandElement; -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -public class WithSuggestionsElement extends CommandElement { - private final CommandElement wrapped; - private final Function> suggestions; - private final boolean requireBegin; - - public WithSuggestionsElement(CommandElement wrapped, Function> suggestions, boolean requireBegin) { - super(wrapped.getKey()); - this.wrapped = wrapped; - this.suggestions = suggestions; - this.requireBegin = requireBegin; - } - - @Nullable - @Override - public Object parseValue(PermissibleCommandSource source, CommandArgs args) throws ArgumentParseException { - return this.wrapped.parseValue(source, args); - } - - @Override - public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - if (this.requireBegin) { - String arg = args.nextIfPresent().orElse(""); - return ImmutableList.copyOf(StreamSupport.stream(this.suggestions.apply(src).spliterator(), false).filter(f -> f.startsWith(arg)).collect(Collectors.toList())); - } else { - return ImmutableList.copyOf(this.suggestions.apply(src)); - } - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/command/MinecraftServerMixin.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/command/MinecraftServerMixin.java deleted file mode 100644 index 397b46b4c..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/command/MinecraftServerMixin.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.legacyfabric.fabric.mixin.command; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -import net.minecraft.server.MinecraftServer; - -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -@Mixin(MinecraftServer.class) -public abstract class MinecraftServerMixin implements PermissibleCommandSource { - @Shadow - public abstract boolean isDedicated(); - - @Override - public boolean hasPermission(String perm) { - return true; - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/resources/fabric.mod.json b/legacy-fabric-command-api-v2/1.8.9/src/main/resources/fabric.mod.json index 5ff821a2a..83dca385f 100644 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/resources/fabric.mod.json +++ b/legacy-fabric-command-api-v2/1.8.9/src/main/resources/fabric.mod.json @@ -28,9 +28,7 @@ ] }, "description": "Powerful Command API that uses SpongeAPI's command api", - "mixins": [ - "legacy-fabric-sponge-command-api-v2.mixins.json" - ], + "mixins": [], "custom": { "modmenu": { "badges": [ "library" ], diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/resources/legacy-fabric-sponge-command-api-v2.mixins.json b/legacy-fabric-command-api-v2/1.8.9/src/main/resources/legacy-fabric-sponge-command-api-v2.mixins.json deleted file mode 100644 index bc49c8a20..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/resources/legacy-fabric-sponge-command-api-v2.mixins.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "required": true, - "package": "net.legacyfabric.fabric.mixin.command", - "compatibilityLevel": "JAVA_8", - "mixins": [ - "MinecraftServerMixin" - ], - "injectors": { - "defaultRequire": 1 - } -} diff --git a/legacy-fabric-command-api-v2/common/build.gradle b/legacy-fabric-command-api-v2/common/build.gradle new file mode 100644 index 000000000..e69de29bb diff --git a/legacy-fabric-command-api-v2/common/gradle.properties b/legacy-fabric-command-api-v2/common/gradle.properties new file mode 100644 index 000000000..503076051 --- /dev/null +++ b/legacy-fabric-command-api-v2/common/gradle.properties @@ -0,0 +1,2 @@ +minVersionIncluded=1.7.10 +maxVersionIncluded=1.12.2 diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/StringType.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/StringType.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/StringType.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/StringType.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandException.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandException.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandException.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandException.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandMessageFormatting.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandMessageFormatting.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandMessageFormatting.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandMessageFormatting.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandNotFoundException.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandNotFoundException.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandNotFoundException.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandNotFoundException.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandPermissionException.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandPermissionException.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandPermissionException.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/CommandPermissionException.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/InvocationCommandException.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/InvocationCommandException.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/InvocationCommandException.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/InvocationCommandException.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/TextMessageException.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/TextMessageException.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/TextMessageException.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/TextMessageException.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/ArgumentParseException.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/ArgumentParseException.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/ArgumentParseException.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/ArgumentParseException.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandArgs.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandArgs.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandArgs.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandArgs.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandContext.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandContext.java similarity index 98% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandContext.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandContext.java index 1907dfecb..e2c0047ea 100644 --- a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandContext.java +++ b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandContext.java @@ -43,7 +43,6 @@ import net.legacyfabric.fabric.api.command.v2.lib.sponge.CommandException; import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; -import net.legacyfabric.fabric.api.util.Location; /** * Context that a command is executed in. @@ -52,7 +51,7 @@ public final class CommandContext { /** * The argument key for a target block position that may be present - * during tab completion, of type {@link Location Location<World>}. + * during tab completion, of type {@link net.legacyfabric.fabric.api.util.Location Location<World>}. */ public static final String TARGET_BLOCK_ARG = "targetblock-pos048658"; // Random junk afterwards so we don't accidentally conflict with other args diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandElement.java similarity index 91% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandElement.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandElement.java index 7dd95dfa6..d582ace40 100644 --- a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandElement.java +++ b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandElement.java @@ -38,7 +38,6 @@ import net.fabricmc.loader.api.FabricLoader; import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; -import net.legacyfabric.fabric.impl.command.MinecraftClientAccessor; /** * Represents a command argument element. @@ -65,7 +64,7 @@ public Text getKey() { * Return the plain key, to be used when looking up this command element in * a {@link CommandContext}. If the key is a {@link TranslatableText}, this * is the translation's id. Otherwise, this is the result of - * {@link Text#asString()} ()} ()}. + * {@link Text#computeValue()}. * * @return the raw key */ @@ -139,13 +138,17 @@ public Text getUsage(PermissibleCommandSource src) { public MinecraftServer getServer() { MinecraftServer minecraftServer = null; - if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER) { - minecraftServer = (MinecraftServer) FabricLoader.getInstance().getGameInstance(); - } else { - try { - minecraftServer = ((MinecraftClientAccessor) net.minecraft.client.MinecraftClient.getInstance()).getMinecraftServer(); - } catch (RuntimeException e) { - e.printStackTrace(); + try { + minecraftServer = MinecraftServer.getServer(); + } catch (RuntimeException e1) { + if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER) { + minecraftServer = (MinecraftServer) FabricLoader.getInstance().getGameInstance(); + } else { + try { + minecraftServer = net.minecraft.client.MinecraftClient.getInstance().getServer(); + } catch (RuntimeException e2) { + e2.printStackTrace(); + } } } diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/KeyElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/KeyElement.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/KeyElement.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/KeyElement.java diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/PatternMatchingCommandElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/PatternMatchingCommandElement.java similarity index 99% rename from legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/PatternMatchingCommandElement.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/PatternMatchingCommandElement.java index efa95b171..765daedfe 100644 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/PatternMatchingCommandElement.java +++ b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/PatternMatchingCommandElement.java @@ -86,7 +86,7 @@ public Object parseValue(PermissibleCommandSource source, CommandArgs args) thro if (!ret.iterator().hasNext()) { throw args.createError(new LiteralText(String.format("No values matching pattern '%s' present for %s!", arg, this.getKey() == null - ? nullKeyArg : this.getKey()))); + ? nullKeyArg : this.getKey().asUnformattedString()))); } return ret; diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/InputTokenizer.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/InputTokenizer.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/InputTokenizer.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/InputTokenizer.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/QuotedStringTokenizer.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/QuotedStringTokenizer.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/QuotedStringTokenizer.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/QuotedStringTokenizer.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/RawStringInputTokenizer.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/RawStringInputTokenizer.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/RawStringInputTokenizer.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/RawStringInputTokenizer.java diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SingleArg.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SingleArg.java similarity index 96% rename from legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SingleArg.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SingleArg.java index cf5ae6c7d..5b0e34ae2 100644 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SingleArg.java +++ b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SingleArg.java @@ -27,6 +27,8 @@ import com.google.common.base.Objects; +import net.legacyfabric.fabric.impl.command.GuavaUtils; + /** * This represents a single argument with its start and end indexes * in the associated raw input string. @@ -99,7 +101,7 @@ public int hashCode() { @Override public String toString() { - return Objects.toStringHelper(this) + return GuavaUtils.toStringHelper(this) .add("value", this.value) .add("startIdx", this.startIdx) .add("endIdx", this.endIdx) diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SpaceSplitInputTokenizer.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SpaceSplitInputTokenizer.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SpaceSplitInputTokenizer.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/SpaceSplitInputTokenizer.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/TokenizerState.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/TokenizerState.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/TokenizerState.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/parsing/TokenizerState.java diff --git a/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/GuavaUtils.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/GuavaUtils.java new file mode 100644 index 000000000..da5fd2b6a --- /dev/null +++ b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/GuavaUtils.java @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.fabric.impl.command; + +import java.util.Arrays; + +import com.google.common.base.Preconditions; +import org.jetbrains.annotations.Nullable; + +/** + * Guava's ToStringHelper class which isn't located at the same place depending on guava versions. + * This ensures it is available in all targeted versions. + */ +public class GuavaUtils { + public static ToStringHelper toStringHelper(Object self) { + return new ToStringHelper(self.getClass().getSimpleName()); + } + + public static ToStringHelper toStringHelper(Class clazz) { + return new ToStringHelper(clazz.getSimpleName()); + } + + public static ToStringHelper toStringHelper(String className) { + return new ToStringHelper(className); + } + + public static final class ToStringHelper { + private final String className; + private final ValueHolder holderHead; + private ValueHolder holderTail; + private boolean omitNullValues; + + private ToStringHelper(String className) { + this.holderHead = new ValueHolder(); + this.holderTail = this.holderHead; + this.omitNullValues = false; + this.className = (String) Preconditions.checkNotNull(className); + } + + public ToStringHelper omitNullValues() { + this.omitNullValues = true; + return this; + } + + public ToStringHelper add(String name, @Nullable Object value) { + return this.addHolder(name, value); + } + + public ToStringHelper add(String name, boolean value) { + return this.addHolder(name, String.valueOf(value)); + } + + public ToStringHelper add(String name, char value) { + return this.addHolder(name, String.valueOf(value)); + } + + public ToStringHelper add(String name, double value) { + return this.addHolder(name, String.valueOf(value)); + } + + public ToStringHelper add(String name, float value) { + return this.addHolder(name, String.valueOf(value)); + } + + public ToStringHelper add(String name, int value) { + return this.addHolder(name, String.valueOf(value)); + } + + public ToStringHelper add(String name, long value) { + return this.addHolder(name, String.valueOf(value)); + } + + public ToStringHelper addValue(@Nullable Object value) { + return this.addHolder(value); + } + + public ToStringHelper addValue(boolean value) { + return this.addHolder(String.valueOf(value)); + } + + public ToStringHelper addValue(char value) { + return this.addHolder(String.valueOf(value)); + } + + public ToStringHelper addValue(double value) { + return this.addHolder(String.valueOf(value)); + } + + public ToStringHelper addValue(float value) { + return this.addHolder(String.valueOf(value)); + } + + public ToStringHelper addValue(int value) { + return this.addHolder(String.valueOf(value)); + } + + public ToStringHelper addValue(long value) { + return this.addHolder(String.valueOf(value)); + } + + public String toString() { + boolean omitNullValuesSnapshot = this.omitNullValues; + String nextSeparator = ""; + StringBuilder builder = (new StringBuilder(32)).append(this.className).append('{'); + + for (ValueHolder valueHolder = this.holderHead.next; valueHolder != null; valueHolder = valueHolder.next) { + Object value = valueHolder.value; + + if (!omitNullValuesSnapshot || value != null) { + builder.append(nextSeparator); + nextSeparator = ", "; + + if (valueHolder.name != null) { + builder.append(valueHolder.name).append('='); + } + + if (value != null && value.getClass().isArray()) { + Object[] objectArray = new Object[]{value}; + String arrayString = Arrays.deepToString(objectArray); + builder.append(arrayString, 1, arrayString.length() - 1); + } else { + builder.append(value); + } + } + } + + return builder.append('}').toString(); + } + + private ValueHolder addHolder() { + ValueHolder valueHolder = new ValueHolder(); + this.holderTail = this.holderTail.next = valueHolder; + return valueHolder; + } + + private ToStringHelper addHolder(@Nullable Object value) { + ValueHolder valueHolder = this.addHolder(); + valueHolder.value = value; + return this; + } + + private ToStringHelper addHolder(String name, @Nullable Object value) { + ValueHolder valueHolder = this.addHolder(); + valueHolder.value = value; + valueHolder.name = (String) Preconditions.checkNotNull(name); + return this; + } + + private static final class ValueHolder { + String name; + Object value; + ValueHolder next; + + private ValueHolder() { + } + } + } +} diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/AllOfCommandElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/AllOfCommandElement.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/AllOfCommandElement.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/AllOfCommandElement.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/BigDecimalElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/BigDecimalElement.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/BigDecimalElement.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/BigDecimalElement.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/BigIntegerElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/BigIntegerElement.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/BigIntegerElement.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/BigIntegerElement.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/ChoicesCommandElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/ChoicesCommandElement.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/ChoicesCommandElement.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/ChoicesCommandElement.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/DateTimeElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/DateTimeElement.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/DateTimeElement.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/DateTimeElement.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/DurationElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/DurationElement.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/DurationElement.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/DurationElement.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/EnumValueElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/EnumValueElement.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/EnumValueElement.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/EnumValueElement.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/FilteredSuggestionsElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/FilteredSuggestionsElement.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/FilteredSuggestionsElement.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/FilteredSuggestionsElement.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/FirstParsingCommandElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/FirstParsingCommandElement.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/FirstParsingCommandElement.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/FirstParsingCommandElement.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/LiteralCommandElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/LiteralCommandElement.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/LiteralCommandElement.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/LiteralCommandElement.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/MarkTrueCommandElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/MarkTrueCommandElement.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/MarkTrueCommandElement.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/MarkTrueCommandElement.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/ModCommandElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/ModCommandElement.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/ModCommandElement.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/ModCommandElement.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/NumericElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/NumericElement.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/NumericElement.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/NumericElement.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OnlyOneCommandElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OnlyOneCommandElement.java similarity index 97% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OnlyOneCommandElement.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OnlyOneCommandElement.java index ba0173c43..6a3146371 100644 --- a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OnlyOneCommandElement.java +++ b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OnlyOneCommandElement.java @@ -52,7 +52,7 @@ public void parse(PermissibleCommandSource source, CommandArgs args, CommandCont if (context.getAll(this.element.getUntranslatedKey()).size() > 1) { Text key = this.element.getKey(); - throw args.createError(new LiteralText(String.format("Argument %s may have only one value!", key != null ? key : "unknown"))); + throw args.createError(new LiteralText(String.format("Argument %s may have only one value!", key != null ? key.asUnformattedString() : "unknown"))); } } diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OptionalCommandElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OptionalCommandElement.java similarity index 97% rename from legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OptionalCommandElement.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OptionalCommandElement.java index 8abf3f5be..14559ce88 100644 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OptionalCommandElement.java +++ b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/OptionalCommandElement.java @@ -98,6 +98,6 @@ public Text getUsage(PermissibleCommandSource src) { return new LiteralText(""); } - return new LiteralText("[" + this.element.getUsage(src) + "]"); + return new LiteralText("[" + this.element.getUsage(src).asUnformattedString() + "]"); } } diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/PermissionCommandElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/PermissionCommandElement.java similarity index 95% rename from legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/PermissionCommandElement.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/PermissionCommandElement.java index 151c83ab8..20bc2cd32 100644 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/PermissionCommandElement.java +++ b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/PermissionCommandElement.java @@ -66,7 +66,7 @@ private boolean checkPermission(PermissibleCommandSource source, CommandArgs arg if (!hasPermission && !this.isOptional) { Text key = this.getKey(); - throw args.createError(new LiteralText(String.format("You do not have permission to use the %s argument", key != null ? key : "unknown"))); + throw args.createError(new LiteralText(String.format("You do not have permission to use the %s argument", key != null ? key.asUnformattedString() : "unknown"))); } return hasPermission; @@ -74,7 +74,7 @@ private boolean checkPermission(PermissibleCommandSource source, CommandArgs arg @Override public List complete(PermissibleCommandSource src, CommandArgs args, CommandContext context) { - boolean flag = /*src.hasPermission(this.permission)*/ true; + boolean flag = src.hasPermission(this.permission); if (!flag) { return ImmutableList.of(); diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/RemainingJoinedStringsCommandElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/RemainingJoinedStringsCommandElement.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/RemainingJoinedStringsCommandElement.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/RemainingJoinedStringsCommandElement.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/RepeatedCommandElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/RepeatedCommandElement.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/RepeatedCommandElement.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/RepeatedCommandElement.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/SequenceCommandElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/SequenceCommandElement.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/SequenceCommandElement.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/SequenceCommandElement.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/StringCommandElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/StringCommandElement.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/StringCommandElement.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/StringCommandElement.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/StringElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/StringElement.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/StringElement.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/StringElement.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/UrlElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/UrlElement.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/UrlElement.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/UrlElement.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/UuidElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/UuidElement.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/UuidElement.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/UuidElement.java diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/WithSuggestionsElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/WithSuggestionsElement.java similarity index 100% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/WithSuggestionsElement.java rename to legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/lib/sponge/args/WithSuggestionsElement.java diff --git a/legacy-fabric-command-api-v2/common/src/main/resources/fabric.mod.json b/legacy-fabric-command-api-v2/common/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..c0620c084 --- /dev/null +++ b/legacy-fabric-command-api-v2/common/src/main/resources/fabric.mod.json @@ -0,0 +1,38 @@ +{ + "schemaVersion": 1, + "id": "legacy-fabric-command-api-v2-common", + "name": "Legacy Fabric Command API (v2) Common", + "version": "${version}", + "environment": "*", + "license": "Apache-2.0", + "icon": "assets/legacy-fabric-sponge-command-api-v2/icon.png", + "contact": { + "homepage": "https://legacyfabric.net", + "irc": "irc://irc.esper.net:6667/legacyfabric", + "issues": "https://github.com/Legacy-Fabric/fabric/issues", + "sources": "https://github.com/Legacy-Fabric/fabric" + }, + "authors": [ + "Legacy-Fabric" + ], + "depends": { + "fabricloader": ">=0.4.0", + "minecraft": "${minecraft_version}" + }, + "entrypoints": { + }, + "description": "Powerful Command API that uses SpongeAPI's command api", + "mixins": [], + "custom": { + "modmenu": { + "badges": [ "library" ], + "parent": { + "id": "legacy-fabric-api", + "name": "Legacy Fabric API", + "badges": [ "library" ], + "description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", + "icon": "assets/legacy-fabric-sponge-command-api-v2/icon.png" + } + } + } +} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/command/MinecraftServerMixin.java b/legacy-fabric-permissions-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/permission/MinecraftServerMixin.java similarity index 87% rename from legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/command/MinecraftServerMixin.java rename to legacy-fabric-permissions-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/permission/MinecraftServerMixin.java index 397b46b4c..f277a46b7 100644 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/command/MinecraftServerMixin.java +++ b/legacy-fabric-permissions-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/permission/MinecraftServerMixin.java @@ -15,10 +15,9 @@ * limitations under the License. */ -package net.legacyfabric.fabric.mixin.command; +package net.legacyfabric.fabric.mixin.permission; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import net.minecraft.server.MinecraftServer; @@ -26,9 +25,6 @@ @Mixin(MinecraftServer.class) public abstract class MinecraftServerMixin implements PermissibleCommandSource { - @Shadow - public abstract boolean isDedicated(); - @Override public boolean hasPermission(String perm) { return true; diff --git a/legacy-fabric-permissions-api-v1/common/src/main/resources/legacy-fabric-permissions-api-v1-common.mixins.json b/legacy-fabric-permissions-api-v1/common/src/main/resources/legacy-fabric-permissions-api-v1-common.mixins.json index a982b0f48..fd8c4ce74 100644 --- a/legacy-fabric-permissions-api-v1/common/src/main/resources/legacy-fabric-permissions-api-v1-common.mixins.json +++ b/legacy-fabric-permissions-api-v1/common/src/main/resources/legacy-fabric-permissions-api-v1-common.mixins.json @@ -5,6 +5,7 @@ "mixins": [ "ConsoleMixin", "EntityMixin", + "MinecraftServerMixin", "ServerPlayerEntityMixin" ], "injectors": {