Created
November 19, 2019 03:32
-
-
Save Daomephsta/0a699ad3037f2985facd1ea4e7301ddd to your computer and use it in GitHub Desktop.
DelegatingArgumentType
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class DelegatingArgumentType implements ArgumentType<String> | |
| { | |
| private final ArgumentType<?> delegate; | |
| private DelegatingArgumentType(ArgumentType<?> delegate) | |
| { | |
| this.delegate = delegate; | |
| } | |
| public static DelegatingArgumentType delegate(ArgumentType<?> delegate) | |
| { | |
| return new DelegatingArgumentType(delegate); | |
| } | |
| @Override | |
| public String parse(StringReader reader) throws CommandSyntaxException | |
| { | |
| int cursor = reader.getCursor(); | |
| String stringForm = reader.readStringUntil(' '); | |
| reader.setCursor(cursor); | |
| //Throw any errors, but ignore the result | |
| delegate.parse(reader); | |
| return stringForm; | |
| } | |
| @Override | |
| public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) | |
| { | |
| return delegate.listSuggestions(context, builder); | |
| } | |
| @Override | |
| public Collection<String> getExamples() | |
| { | |
| return delegate.getExamples(); | |
| } | |
| public static class Serialiser implements ArgumentSerializer<DelegatingArgumentType> | |
| { | |
| @Override | |
| public void toPacket(DelegatingArgumentType argumentType, PacketByteBuf buf) | |
| { | |
| ArgumentTypes.toPacket(buf, argumentType.delegate); | |
| } | |
| @Override | |
| public DelegatingArgumentType fromPacket(PacketByteBuf buf) | |
| { | |
| return new DelegatingArgumentType(ArgumentTypes.fromPacket(buf)); | |
| } | |
| @Override | |
| public void toJson(DelegatingArgumentType argumentType, JsonObject json) | |
| { | |
| ArgumentTypesAccessors.invokeToJson(json, argumentType.delegate); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment