|
@@ -49,11 +49,11 @@ public class ModCommandManager extends Commands {
|
|
|
this.perms = perms;
|
|
|
this.events = events;
|
|
|
this.scripts = scripts;
|
|
|
-
|
|
|
+
|
|
|
// forge command which fails ...
|
|
|
- ignoredCommands.add("config");
|
|
|
+ ignoredCommands.add("config");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public void clearCustomNodes() {
|
|
|
customNodes.clear();
|
|
|
}
|
|
@@ -65,10 +65,10 @@ public class ModCommandManager extends Commands {
|
|
|
public void clearIgnoredCommands() {
|
|
|
ignoredCommands.clear();
|
|
|
// forge command which fails ...
|
|
|
- ignoredCommands.add("config");
|
|
|
+ ignoredCommands.add("config");
|
|
|
}
|
|
|
|
|
|
- public void addCustomNodes(CommandNode node) {
|
|
|
+ public void addCustomNode(CommandNode node) {
|
|
|
customNodes.add(node);
|
|
|
}
|
|
|
|
|
@@ -187,15 +187,14 @@ public class ModCommandManager extends Commands {
|
|
|
@Override
|
|
|
public void send(ServerPlayerEntity player) {
|
|
|
Map<CommandNode<CommandSource>, CommandNode<ISuggestionProvider>> map = Maps.newHashMap();
|
|
|
- RootCommandNode<ISuggestionProvider> rootcommandnode = new RootCommandNode<>();
|
|
|
- map.put(getDispatcher().getRoot(), rootcommandnode);
|
|
|
- this.commandSourceNodesToSuggestionNodes(true, getDispatcher().getRoot(), rootcommandnode, player.getCommandSource(), map);
|
|
|
-
|
|
|
+ RootCommandNode<ISuggestionProvider> rootNode = new RootCommandNode<>();
|
|
|
+ map.put(getDispatcher().getRoot(), rootNode);
|
|
|
+ CommandSource cs = player.getCommandSource();
|
|
|
+ commandSourceNodesToSuggestionNodes(true, getDispatcher().getRoot(), rootNode, cs, map);
|
|
|
for(CommandNode node : customNodes) {
|
|
|
- rootcommandnode.addChild(node);
|
|
|
+ commandSourceNodesToSuggestionNodes(node, rootNode, cs, map);
|
|
|
}
|
|
|
-
|
|
|
- player.connection.sendPacket(new SCommandListPacket(rootcommandnode));
|
|
|
+ player.connection.sendPacket(new SCommandListPacket(rootNode));
|
|
|
}
|
|
|
|
|
|
private void commandSourceNodesToSuggestionNodes(boolean first,
|
|
@@ -203,35 +202,65 @@ public class ModCommandManager extends Commands {
|
|
|
CommandNode<ISuggestionProvider> suggestion,
|
|
|
CommandSource source,
|
|
|
Map<CommandNode<CommandSource>, CommandNode<ISuggestionProvider>> map) {
|
|
|
- for(CommandNode<CommandSource> commandnode : node.getChildren()) {
|
|
|
- if(first && ignoredCommands.contains(commandnode.getName())) {
|
|
|
+ for(CommandNode<CommandSource> childNode : node.getChildren()) {
|
|
|
+ if(first && ignoredCommands.contains(childNode.getName())) {
|
|
|
continue;
|
|
|
}
|
|
|
- if((first && perms.has(source, commandnode.getName()) || (!first && commandnode.canUse(source)))) {
|
|
|
- ArgumentBuilder<ISuggestionProvider, ?> argumentbuilder = (ArgumentBuilder) commandnode.createBuilder();
|
|
|
- argumentbuilder.requires(a -> true);
|
|
|
- if(argumentbuilder.getCommand() != null) {
|
|
|
- argumentbuilder.executes(a -> 0);
|
|
|
+ if((first && perms.has(source, childNode.getName()) || (!first && childNode.canUse(source)))) {
|
|
|
+ ArgumentBuilder<ISuggestionProvider, ?> arg = (ArgumentBuilder) childNode.createBuilder();
|
|
|
+ arg.requires(a -> true);
|
|
|
+ if(arg.getCommand() != null) {
|
|
|
+ arg.executes(a -> 0);
|
|
|
}
|
|
|
|
|
|
- if(argumentbuilder instanceof RequiredArgumentBuilder) {
|
|
|
- RequiredArgumentBuilder<ISuggestionProvider, ?> requiredargumentbuilder = (RequiredArgumentBuilder) argumentbuilder;
|
|
|
- if(requiredargumentbuilder.getSuggestionsProvider() != null) {
|
|
|
- requiredargumentbuilder.suggests(SuggestionProviders.ensureKnown(requiredargumentbuilder.getSuggestionsProvider()));
|
|
|
+ if(arg instanceof RequiredArgumentBuilder) {
|
|
|
+ RequiredArgumentBuilder<ISuggestionProvider, ?> required = (RequiredArgumentBuilder) arg;
|
|
|
+ if(required.getSuggestionsProvider() != null) {
|
|
|
+ required.suggests(SuggestionProviders.ensureKnown(required.getSuggestionsProvider()));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if(argumentbuilder.getRedirect() != null) {
|
|
|
- argumentbuilder.redirect(map.get(argumentbuilder.getRedirect()));
|
|
|
+ if(arg.getRedirect() != null) {
|
|
|
+ arg.redirect(map.get(arg.getRedirect()));
|
|
|
}
|
|
|
|
|
|
- CommandNode<ISuggestionProvider> commandNode = argumentbuilder.build();
|
|
|
- map.put(commandnode, commandNode);
|
|
|
+ CommandNode<ISuggestionProvider> commandNode = arg.build();
|
|
|
+ map.put(childNode, commandNode);
|
|
|
suggestion.addChild(commandNode);
|
|
|
- if(!commandnode.getChildren().isEmpty()) {
|
|
|
- this.commandSourceNodesToSuggestionNodes(false, commandnode, commandNode, source, map);
|
|
|
+ if(!childNode.getChildren().isEmpty()) {
|
|
|
+ this.commandSourceNodesToSuggestionNodes(false, childNode, commandNode, source, map);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private void commandSourceNodesToSuggestionNodes(
|
|
|
+ CommandNode<CommandSource> node,
|
|
|
+ CommandNode<ISuggestionProvider> parentNode,
|
|
|
+ CommandSource cs,
|
|
|
+ Map<CommandNode<CommandSource>, CommandNode<ISuggestionProvider>> map) {
|
|
|
+ if(!node.canUse(cs)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ArgumentBuilder<ISuggestionProvider, ?> arg = (ArgumentBuilder) node.createBuilder();
|
|
|
+ arg.requires(a -> true);
|
|
|
+ if(arg.getCommand() != null) {
|
|
|
+ arg.executes(a -> 0);
|
|
|
+ }
|
|
|
+ if(arg instanceof RequiredArgumentBuilder) {
|
|
|
+ RequiredArgumentBuilder<ISuggestionProvider, ?> required = (RequiredArgumentBuilder) arg;
|
|
|
+ if(required.getSuggestionsProvider() != null) {
|
|
|
+ required.suggests(SuggestionProviders.ensureKnown(required.getSuggestionsProvider()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(arg.getRedirect() != null) {
|
|
|
+ arg.redirect(map.get(arg.getRedirect()));
|
|
|
+ }
|
|
|
+ CommandNode<ISuggestionProvider> commandNode = arg.build();
|
|
|
+ map.put(node, commandNode);
|
|
|
+ parentNode.addChild(commandNode);
|
|
|
+ for(CommandNode<CommandSource> childNode : node.getChildren()) {
|
|
|
+ commandSourceNodesToSuggestionNodes(childNode, commandNode, cs, map);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|