com.mojang.brigadier.suggestion.SuggestionProvider Java Examples
The following examples show how to use
com.mojang.brigadier.suggestion.SuggestionProvider.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ForgeSparkPlugin.java From spark with GNU General Public License v3.0 | 7 votes |
public static <T> void registerCommands(CommandDispatcher<T> dispatcher, Command<T> executor, SuggestionProvider<T> suggestor, String... aliases) { if (aliases.length == 0) { return; } String mainName = aliases[0]; LiteralArgumentBuilder<T> command = LiteralArgumentBuilder.<T>literal(mainName) .executes(executor) .then(RequiredArgumentBuilder.<T, String>argument("args", StringArgumentType.greedyString()) .suggests(suggestor) .executes(executor) ); LiteralCommandNode<T> node = dispatcher.register(command); for (int i = 1; i < aliases.length; i++) { dispatcher.register(LiteralArgumentBuilder.<T>literal(aliases[i]).redirect(node)); } }
Example #2
Source File: FabricSparkPlugin.java From spark with GNU General Public License v3.0 | 6 votes |
public static <T> void registerCommands(CommandDispatcher<T> dispatcher, Command<T> executor, SuggestionProvider<T> suggestor, String... aliases) { if (aliases.length == 0) { return; } String mainName = aliases[0]; LiteralArgumentBuilder<T> command = LiteralArgumentBuilder.<T>literal(mainName) .executes(executor) .then(RequiredArgumentBuilder.<T, String>argument("args", StringArgumentType.greedyString()) .suggests(suggestor) .executes(executor) ); LiteralCommandNode<T> node = dispatcher.register(command); for (int i = 1; i < aliases.length; i++) { dispatcher.register(LiteralArgumentBuilder.<T>literal(aliases[i]).redirect(node)); } }
Example #3
Source File: SpigotMapper.java From Chimera with MIT License | 6 votes |
@Override protected @Nullable SuggestionProvider<CommandListenerWrapper> suggestions(ArgumentCommandNode<CommandSender, ?> command) { var type = command.getType(); var suggestor = command.getCustomSuggestions(); if (!(type instanceof Type<?>) && suggestor == null) { return null; } else if (suggestor == null) { return reparse((Type<?>) type); } var client = CLIENT_SIDE.get(suggestor); if (client != null) { return client; } else { return reparse(suggestor); } }
Example #4
Source File: SpigotMapper.java From Chimera with MIT License | 5 votes |
SuggestionProvider<CommandListenerWrapper> reparse(Type<?> type) { return (context, suggestions) -> { var sender = context.getSource().getBukkitSender(); var reparsed = dispatcher.parse(context.getInput(), sender).getContext().build(context.getInput()); return type.listSuggestions(reparsed, suggestions); }; }
Example #5
Source File: VariableResolver.java From Chimera with MIT License | 5 votes |
public VariableResolver(Environment environment) { super(environment); command = specialize(Command.class, sender); argumentType = types.erasure(elements.getTypeElement(ArgumentType.class.getName()).asType()); requirement = specialize(Predicate.class, sender); suggestions = specialize(SuggestionProvider.class, sender); }
Example #6
Source File: SpigotMapper.java From Chimera with MIT License | 5 votes |
SuggestionProvider<CommandListenerWrapper> reparse(SuggestionProvider<CommandSender> suggestor) { return (context, suggestions) -> { var sender = context.getSource().getBukkitSender(); var reparsed = dispatcher.parse(context.getInput(), sender).getContext().build(context.getInput()); return suggestor.getSuggestions(reparsed, suggestions); }; }
Example #7
Source File: NMS_1_14_3.java From 1.13-Command-API with Apache License 2.0 | 5 votes |
@Override public SuggestionProvider getSuggestionProvider(SuggestionProviders provider) { switch (provider) { case FUNCTION: return (context, builder) -> { CustomFunctionData functionData = getCLW(context).getServer().getFunctionData(); ICompletionProvider.a(functionData.h().a(), builder, "#"); return ICompletionProvider.a(functionData.c().keySet(), builder); }; case RECIPES: return CompletionProviders.b; case SOUNDS: return CompletionProviders.c; case ADVANCEMENTS: return (cmdCtx, builder) -> { Collection<Advancement> advancements = ((CommandListenerWrapper) cmdCtx.getSource()).getServer().getAdvancementData().a(); return ICompletionProvider.a(advancements.stream().map(Advancement::getName), builder); }; case LOOT_TABLES: return (context, builder) -> { LootTableRegistry lootTables = getCLW(context).getServer().getLootTableRegistry(); return ICompletionProvider.a(lootTables.a(), builder); }; case ENTITIES: return CompletionProviders.d; case BIOMES: default: return (context, builder) -> Suggestions.empty(); } }
Example #8
Source File: NMS_1_14_4.java From 1.13-Command-API with Apache License 2.0 | 5 votes |
@Override public SuggestionProvider getSuggestionProvider(SuggestionProviders provider) { switch (provider) { case FUNCTION: return (context, builder) -> { CustomFunctionData functionData = getCLW(context).getServer().getFunctionData(); ICompletionProvider.a(functionData.h().a(), builder, "#"); return ICompletionProvider.a(functionData.c().keySet(), builder); }; case RECIPES: return CompletionProviders.b; case SOUNDS: return CompletionProviders.c; case ADVANCEMENTS: return (cmdCtx, builder) -> { Collection<Advancement> advancements = ((CommandListenerWrapper) cmdCtx.getSource()).getServer().getAdvancementData().a(); return ICompletionProvider.a(advancements.stream().map(Advancement::getName), builder); }; case LOOT_TABLES: return (context, builder) -> { LootTableRegistry lootTables = getCLW(context).getServer().getLootTableRegistry(); return ICompletionProvider.a(lootTables.a(), builder); }; case ENTITIES: return CompletionProviders.d; case BIOMES: default: return (context, builder) -> Suggestions.empty(); } }
Example #9
Source File: NMS_1_15.java From 1.13-Command-API with Apache License 2.0 | 5 votes |
@Override public SuggestionProvider getSuggestionProvider(SuggestionProviders provider) { switch (provider) { case FUNCTION: return (context, builder) -> { CustomFunctionData functionData = getCLW(context).getServer().getFunctionData(); ICompletionProvider.a(functionData.h().a(), builder, "#"); return ICompletionProvider.a(functionData.c().keySet(), builder); }; case RECIPES: return CompletionProviders.b; case SOUNDS: return CompletionProviders.c; case ADVANCEMENTS: return (cmdCtx, builder) -> { Collection<Advancement> advancements = ((CommandListenerWrapper) cmdCtx.getSource()).getServer() .getAdvancementData().getAdvancements(); return ICompletionProvider.a(advancements.stream().map(Advancement::getName), builder); }; case LOOT_TABLES: return (context, builder) -> { LootTableRegistry lootTables = getCLW(context).getServer().getLootTableRegistry(); return ICompletionProvider.a(lootTables.a(), builder); }; case ENTITIES: return CompletionProviders.d; case BIOMES: default: return (context, builder) -> Suggestions.empty(); } }
Example #10
Source File: NMS_1_14.java From 1.13-Command-API with Apache License 2.0 | 5 votes |
@Override public SuggestionProvider getSuggestionProvider(SuggestionProviders provider) { switch (provider) { case FUNCTION: return (context, builder) -> { CustomFunctionData functionData = getCLW(context).getServer().getFunctionData(); ICompletionProvider.a(functionData.g().a(), builder, "#"); return ICompletionProvider.a(functionData.c().keySet(), builder); }; case RECIPES: return CompletionProviders.b; case SOUNDS: return CompletionProviders.c; case ADVANCEMENTS: return (cmdCtx, builder) -> { Collection<Advancement> advancements = ((CommandListenerWrapper) cmdCtx.getSource()).getServer() .getAdvancementData().b(); return ICompletionProvider.a(advancements.stream().map(Advancement::getName), builder); }; case LOOT_TABLES: return (context, builder) -> { LootTableRegistry lootTables = getCLW(context).getServer().getLootTableRegistry(); return ICompletionProvider.a(lootTables.a(), builder); }; case ENTITIES: return CompletionProviders.d; case BIOMES: default: return (context, builder) -> Suggestions.empty(); } }
Example #11
Source File: NMS_1_16_R1.java From 1.13-Command-API with Apache License 2.0 | 5 votes |
@Override public SuggestionProvider getSuggestionProvider(SuggestionProviders provider) { switch (provider) { case FUNCTION: return (context, builder) -> { CustomFunctionData functionData = getCLW(context).getServer().getFunctionData(); ICompletionProvider.a(functionData.g(), builder, "#"); return ICompletionProvider.a(functionData.f(), builder); }; case RECIPES: return CompletionProviders.b; case SOUNDS: return CompletionProviders.c; case ADVANCEMENTS: return (cmdCtx, builder) -> { Collection<Advancement> advancements = ((CommandListenerWrapper) cmdCtx.getSource()).getServer() .getAdvancementData().getAdvancements(); return ICompletionProvider.a(advancements.stream().map(Advancement::getName), builder); }; case LOOT_TABLES: return (context, builder) -> { LootTableRegistry lootTables = getCLW(context).getServer().getLootTableRegistry(); return ICompletionProvider.a(lootTables.a(), builder); }; case BIOMES: return CompletionProviders.d; case ENTITIES: return CompletionProviders.e; default: return (context, builder) -> Suggestions.empty(); } }
Example #12
Source File: AvailableCommands.java From Velocity with MIT License | 4 votes |
private static void serializeNode(CommandNode<Object> node, ByteBuf buf, Object2IntMap<CommandNode<Object>> idMappings) { byte flags = 0; if (node.getRedirect() != null) { flags |= FLAG_IS_REDIRECT; } if (node.getCommand() != null) { flags |= FLAG_EXECUTABLE; } if (node instanceof RootCommandNode<?>) { flags |= NODE_TYPE_ROOT; } else if (node instanceof LiteralCommandNode<?>) { flags |= NODE_TYPE_LITERAL; } else if (node instanceof ArgumentCommandNode<?, ?>) { flags |= NODE_TYPE_ARGUMENT; if (((ArgumentCommandNode) node).getCustomSuggestions() != null) { flags |= FLAG_HAS_SUGGESTIONS; } } else { throw new IllegalArgumentException("Unknown node type " + node.getClass().getName()); } buf.writeByte(flags); ProtocolUtils.writeVarInt(buf, node.getChildren().size()); for (CommandNode<Object> child : node.getChildren()) { ProtocolUtils.writeVarInt(buf, idMappings.getInt(child)); } if (node.getRedirect() != null) { ProtocolUtils.writeVarInt(buf, idMappings.getInt(node.getRedirect())); } if (node instanceof ArgumentCommandNode<?, ?>) { ProtocolUtils.writeString(buf, node.getName()); ArgumentPropertyRegistry.serialize(buf, ((ArgumentCommandNode) node).getType()); if (((ArgumentCommandNode) node).getCustomSuggestions() != null) { // The unchecked cast is required, but it is not particularly relevant because we check for // a more specific type later. (Even then, we only pull out one field.) @SuppressWarnings("unchecked") SuggestionProvider<Object> provider = ((ArgumentCommandNode) node).getCustomSuggestions(); if (!(provider instanceof ProtocolSuggestionProvider)) { throw new IllegalArgumentException("Suggestion provider " + provider.getClass().getName() + " is not valid."); } ProtocolUtils.writeString(buf, ((ProtocolSuggestionProvider) provider).name); } } else if (node instanceof LiteralCommandNode<?>) { ProtocolUtils.writeString(buf, node.getName()); } }
Example #13
Source File: CommandAPIHandler.java From 1.13-Command-API with Apache License 2.0 | 4 votes |
private <T> RequiredArgumentBuilder<?, T> getRequiredArgumentBuilderWithProvider(String argumentName, ArgumentType<T> type, CommandPermission permission, SuggestionProvider provider) { return RequiredArgumentBuilder.argument(argumentName, type) .requires(clw -> permissionCheck(nms.getCommandSenderForCLW(clw), permission)).suggests(provider); }
Example #14
Source File: Argument.java From Chimera with MIT License | 4 votes |
public Argument(String name, ArgumentType<V> type, Command<T> command, Predicate<T> requirement, SuggestionProvider<T> suggestions) { this(name, type, command, requirement, null, null, false, suggestions); }
Example #15
Source File: Argument.java From Chimera with MIT License | 4 votes |
public Argument(String name, ArgumentType<V> type, Execution<T> execution, Predicate<T> requirement, SuggestionProvider<T> suggestions) { this(name, type, execution, requirement, null, null, false, suggestions); }
Example #16
Source File: Argument.java From Chimera with MIT License | 4 votes |
public Argument(String name, ArgumentType<V> type, Command<T> command, Predicate<T> requirement, @Nullable CommandNode<T> destination, RedirectModifier<T> modifier, boolean fork, SuggestionProvider<T> suggestions) { super(name, type, command, requirement, destination, modifier, fork, suggestions); this.destination = destination; this.addition = super::addChild; }
Example #17
Source File: Argument.java From Chimera with MIT License | 4 votes |
public Builder<T, V> suggests(SuggestionProvider<T> suggestions) { this.suggestions = suggestions; return getThis(); }
Example #18
Source File: Mapper.java From Chimera with MIT License | 4 votes |
@VisibleForOverride protected @Nullable SuggestionProvider<R> suggestions(ArgumentCommandNode<T, ?> command) { return null; }
Example #19
Source File: ArgumentCommandNode.java From brigadier with MIT License | 4 votes |
public ArgumentCommandNode(final String name, final ArgumentType<T> type, final Command<S> command, final Predicate<S> requirement, final CommandNode<S> redirect, final RedirectModifier<S> modifier, final boolean forks, final SuggestionProvider<S> customSuggestions) { super(command, requirement, redirect, modifier, forks); this.name = name; this.type = type; this.customSuggestions = customSuggestions; }
Example #20
Source File: ArgumentCommandNode.java From brigadier with MIT License | 3 votes |
public SuggestionProvider<S> getCustomSuggestions() { return customSuggestions; }
Example #21
Source File: RequiredArgumentBuilder.java From brigadier with MIT License | 3 votes |
public RequiredArgumentBuilder<S, T> suggests(final SuggestionProvider<S> provider) { this.suggestionsProvider = provider; return getThis(); }
Example #22
Source File: RequiredArgumentBuilder.java From brigadier with MIT License | 3 votes |
public SuggestionProvider<S> getSuggestionsProvider() { return suggestionsProvider; }
Example #23
Source File: NMS.java From 1.13-Command-API with Apache License 2.0 | 1 votes |
/** * Retrieve a specific NMS implemented SuggestionProvider * @param provider The SuggestionProvider type to retrieve * @return A SuggestionProvider that matches the SuggestionProviders input */ SuggestionProvider<?> getSuggestionProvider(SuggestionProviders provider);