Allow Disabling of Command TabComplete

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot 2013-06-21 18:05:54 +10:00
parent 0eed728812
commit cabf908e4c
3 changed files with 49 additions and 17 deletions

View file

@ -35,13 +35,12 @@
this.dispatcher.setConsumer(ExecutionCommandSource.resultConsumer()); this.dispatcher.setConsumer(ExecutionCommandSource.resultConsumer());
} }
@@ -262,30 +276,77 @@ @@ -260,32 +274,79 @@
return new ParseResults(commandcontextbuilder1, parseResults.getReader(), parseResults.getExceptions()); CommandContextBuilder<S> commandcontextbuilder1 = commandcontextbuilder.withSource(sourceMapper.apply(commandcontextbuilder.getSource()));
}
- public void performPrefixedCommand(CommandSourceStack source, String command) { return new ParseResults(commandcontextbuilder1, parseResults.getReader(), parseResults.getExceptions());
- command = command.startsWith("/") ? command.substring(1) : command; + }
- this.performCommand(this.dispatcher.parse(command, source), command); +
+ // CraftBukkit start + // CraftBukkit start
+ public void dispatchServerCommand(CommandSourceStack sender, String command) { + public void dispatchServerCommand(CommandSourceStack sender, String command) {
+ Joiner joiner = Joiner.on(" "); + Joiner joiner = Joiner.on(" ");
@ -79,11 +78,13 @@
} }
+ // CraftBukkit end + // CraftBukkit end
+ public void performPrefixedCommand(CommandSourceStack source, String command) { public void performPrefixedCommand(CommandSourceStack source, String command) {
- command = command.startsWith("/") ? command.substring(1) : command;
- this.performCommand(this.dispatcher.parse(command, source), command);
+ // CraftBukkit start + // CraftBukkit start
+ this.performPrefixedCommand(source, command, command); + this.performPrefixedCommand(source, command, command);
+ } }
+
+ public void performPrefixedCommand(CommandSourceStack commandlistenerwrapper, String s, String label) { + public void performPrefixedCommand(CommandSourceStack commandlistenerwrapper, String s, String label) {
+ s = s.startsWith("/") ? s.substring(1) : s; + s = s.startsWith("/") ? s.substring(1) : s;
+ this.performCommand(this.dispatcher.parse(s, commandlistenerwrapper), s, label); + this.performCommand(this.dispatcher.parse(s, commandlistenerwrapper), s, label);
@ -94,12 +95,13 @@
- CommandSourceStack commandlistenerwrapper = (CommandSourceStack) parseResults.getContext().getSource(); - CommandSourceStack commandlistenerwrapper = (CommandSourceStack) parseResults.getContext().getSource();
+ this.performCommand(parseResults, command, command); + this.performCommand(parseResults, command, command);
+ } + }
+
- Profiler.get().push(() -> {
- return "/" + command;
+ public void performCommand(ParseResults<CommandSourceStack> parseresults, String s, String label) { // CraftBukkit + public void performCommand(ParseResults<CommandSourceStack> parseresults, String s, String label) { // CraftBukkit
+ CommandSourceStack commandlistenerwrapper = (CommandSourceStack) parseresults.getContext().getSource(); + CommandSourceStack commandlistenerwrapper = (CommandSourceStack) parseresults.getContext().getSource();
+
Profiler.get().push(() -> { + Profiler.get().push(() -> {
- return "/" + command;
+ return "/" + s; + return "/" + s;
}); });
- ContextChain<CommandSourceStack> contextchain = Commands.finishParsing(parseResults, command, commandlistenerwrapper); - ContextChain<CommandSourceStack> contextchain = Commands.finishParsing(parseResults, command, commandlistenerwrapper);
@ -173,11 +175,12 @@
} }
} else { } else {
callback.accept(executioncontext); callback.accept(executioncontext);
@@ -377,11 +438,36 @@ @@ -377,11 +438,37 @@
} }
public void sendCommands(ServerPlayer player) { public void sendCommands(ServerPlayer player) {
- Map<CommandNode<CommandSourceStack>, CommandNode<SharedSuggestionProvider>> map = Maps.newHashMap(); - Map<CommandNode<CommandSourceStack>, CommandNode<SharedSuggestionProvider>> map = Maps.newHashMap();
+ if ( org.spigotmc.SpigotConfig.tabComplete < 0 ) return; // Spigot
+ // CraftBukkit start + // CraftBukkit start
+ // Register Vanilla commands into builtRoot as before + // Register Vanilla commands into builtRoot as before
+ Map<CommandNode<CommandSourceStack>, CommandNode<SharedSuggestionProvider>> map = Maps.newIdentityHashMap(); // Use identity to prevent aliasing issues + Map<CommandNode<CommandSourceStack>, CommandNode<SharedSuggestionProvider>> map = Maps.newIdentityHashMap(); // Use identity to prevent aliasing issues
@ -211,8 +214,11 @@
player.connection.send(new ClientboundCommandsPacket(rootcommandnode)); player.connection.send(new ClientboundCommandsPacket(rootcommandnode));
} }
@@ -392,7 +478,7 @@ @@ -390,9 +477,10 @@
while (iterator.hasNext()) {
CommandNode<CommandSourceStack> commandnode2 = (CommandNode) iterator.next(); CommandNode<CommandSourceStack> commandnode2 = (CommandNode) iterator.next();
+ if ( !org.spigotmc.SpigotConfig.sendNamespaced && commandnode2.getName().contains( ":" ) ) continue; // Spigot
if (commandnode2.canUse(source)) { if (commandnode2.canUse(source)) {
- ArgumentBuilder<SharedSuggestionProvider, ?> argumentbuilder = commandnode2.createBuilder(); - ArgumentBuilder<SharedSuggestionProvider, ?> argumentbuilder = commandnode2.createBuilder();
@ -220,7 +226,7 @@
argumentbuilder.requires((icompletionprovider) -> { argumentbuilder.requires((icompletionprovider) -> {
return true; return true;
@@ -415,7 +501,7 @@ @@ -415,7 +503,7 @@
argumentbuilder.redirect((CommandNode) resultNodes.get(argumentbuilder.getRedirect())); argumentbuilder.redirect((CommandNode) resultNodes.get(argumentbuilder.getRedirect()));
} }
@ -229,7 +235,7 @@
resultNodes.put(commandnode2, commandnode3); resultNodes.put(commandnode2, commandnode3);
result.addChild(commandnode3); result.addChild(commandnode3);
@@ -481,7 +567,7 @@ @@ -481,7 +569,7 @@
} }
private <T> HolderLookup.RegistryLookup.Delegate<T> createLookup(final HolderLookup.RegistryLookup<T> original) { private <T> HolderLookup.RegistryLookup.Delegate<T> createLookup(final HolderLookup.RegistryLookup<T> original) {

View file

@ -2182,6 +2182,13 @@ public final class CraftServer implements Server {
} }
public List<String> tabCompleteCommand(Player player, String message, ServerLevel world, Vec3 pos) { public List<String> tabCompleteCommand(Player player, String message, ServerLevel world, Vec3 pos) {
// Spigot Start
if ( (org.spigotmc.SpigotConfig.tabComplete < 0 || message.length() <= org.spigotmc.SpigotConfig.tabComplete) && !message.contains( " " ) )
{
return ImmutableList.of();
}
// Spigot End
List<String> completions = null; List<String> completions = null;
try { try {
if (message.startsWith("/")) { if (message.startsWith("/")) {

View file

@ -156,4 +156,23 @@ public class SpigotConfig
{ {
SpigotConfig.logCommands = SpigotConfig.getBoolean( "commands.log", true ); SpigotConfig.logCommands = SpigotConfig.getBoolean( "commands.log", true );
} }
public static int tabComplete;
public static boolean sendNamespaced;
private static void tabComplete()
{
if ( SpigotConfig.version < 6 )
{
boolean oldValue = SpigotConfig.getBoolean( "commands.tab-complete", true );
if ( oldValue )
{
SpigotConfig.set( "commands.tab-complete", 0 );
} else
{
SpigotConfig.set( "commands.tab-complete", -1 );
}
}
SpigotConfig.tabComplete = SpigotConfig.getInt( "commands.tab-complete", 0 );
SpigotConfig.sendNamespaced = SpigotConfig.getBoolean( "commands.send-namespaced", true );
}
} }