✨ fix-commodore (#27)
This commit is contained in:
parent
8f8f98b189
commit
c3469706ab
14 changed files with 435 additions and 11 deletions
|
|
@ -0,0 +1,37 @@
|
|||
//
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2020 Alexander Söderberg & 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 cloud.commandframework.annotations.specifier;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Annotation used to make {@link cloud.commandframework.arguments.standard.StringArgument string arguments} greedy
|
||||
*/
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Greedy {
|
||||
}
|
||||
|
|
@ -55,6 +55,10 @@ public final class StandardParameters {
|
|||
* The command should be hidden from help menus, etc
|
||||
*/
|
||||
public static final ParserParameter<Boolean> HIDDEN = create("hidden", TypeToken.get(Boolean.class));
|
||||
/**
|
||||
* Indicates that a string argument should be greedy
|
||||
*/
|
||||
public static final ParserParameter<Boolean> GREEDY = create("greedy", TypeToken.get(Boolean.class));
|
||||
|
||||
private StandardParameters() {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
//
|
||||
package cloud.commandframework.arguments.parser;
|
||||
|
||||
import cloud.commandframework.annotations.specifier.Greedy;
|
||||
import cloud.commandframework.arguments.standard.UUIDArgument;
|
||||
import cloud.commandframework.annotations.specifier.Completions;
|
||||
import cloud.commandframework.annotations.specifier.Range;
|
||||
|
|
@ -101,9 +102,15 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
|
|||
(double) options.get(StandardParameters.RANGE_MAX, Double.MAX_VALUE)));
|
||||
this.registerParserSupplier(TypeToken.get(Character.class), options -> new CharArgument.CharacterParser<C>());
|
||||
/* Make this one less awful */
|
||||
this.registerParserSupplier(TypeToken.get(String.class), options -> new StringArgument.StringParser<C>(
|
||||
StringArgument.StringMode.SINGLE, (context, s) ->
|
||||
Arrays.asList(options.get(StandardParameters.COMPLETIONS, new String[0]))));
|
||||
this.registerParserSupplier(TypeToken.get(String.class), options -> {
|
||||
final boolean greedy = options.get(StandardParameters.GREEDY, false);
|
||||
final StringArgument.StringMode stringMode = greedy
|
||||
? StringArgument.StringMode.GREEDY
|
||||
: StringArgument.StringMode.SINGLE;
|
||||
return new StringArgument.StringParser<C>(
|
||||
stringMode,
|
||||
(context, s) -> Arrays.asList(options.get(StandardParameters.COMPLETIONS, new String[0])));
|
||||
});
|
||||
/* Add options to this */
|
||||
this.registerParserSupplier(TypeToken.get(Boolean.class), options -> new BooleanArgument.BooleanParser<>(false));
|
||||
this.registerParserSupplier(TypeToken.get(UUID.class), options -> new UUIDArgument.UUIDParser<>());
|
||||
|
|
@ -276,4 +283,15 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
|
|||
|
||||
}
|
||||
|
||||
|
||||
private static final class GreedyMapper implements BiFunction<@NonNull Greedy, @NonNull TypeToken<?>,
|
||||
@NonNull ParserParameters> {
|
||||
|
||||
@Override
|
||||
public @NonNull ParserParameters apply(@NonNull final Greedy greedy, @NonNull final TypeToken<?> typeToken) {
|
||||
return ParserParameters.single(StandardParameters.GREEDY, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue