mirror of
https://github.com/PaperMC/Waterfall.git
synced 2024-11-28 13:15:31 +01:00
Re-add the feature to let the console to tab complete commands
Fixes #16
This commit is contained in:
parent
06af55a425
commit
d4938e82fe
@ -0,0 +1,99 @@
|
|||||||
|
From 4880a16aabd7bc71227ca550109d9b86397119a7 Mon Sep 17 00:00:00 2001
|
||||||
|
From: DoctorDark <doctordark11@gmail.com>
|
||||||
|
Date: Sun, 14 Feb 2016 15:54:40 +0000
|
||||||
|
Subject: [PATCH] Allow the console to tab complete commands
|
||||||
|
|
||||||
|
|
||||||
|
diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java
|
||||||
|
index d0739c1..fc5ca3a 100644
|
||||||
|
--- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java
|
||||||
|
+++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java
|
||||||
|
@@ -205,6 +205,7 @@ public class BungeeCord extends ProxyServer
|
||||||
|
AnsiConsole.systemInstall();
|
||||||
|
consoleReader = new ConsoleReader();
|
||||||
|
consoleReader.setExpandEvents( false );
|
||||||
|
+ consoleReader.addCompleter( new ConsoleCommandCompleter( this ) );
|
||||||
|
|
||||||
|
logger = new BungeeLogger( this );
|
||||||
|
System.setErr( new PrintStream( new LoggingOutputStream( logger, Level.SEVERE ), true ) );
|
||||||
|
diff --git a/proxy/src/main/java/net/md_5/bungee/ConsoleCommandCompleter.java b/proxy/src/main/java/net/md_5/bungee/ConsoleCommandCompleter.java
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000..455b078
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/proxy/src/main/java/net/md_5/bungee/ConsoleCommandCompleter.java
|
||||||
|
@@ -0,0 +1,72 @@
|
||||||
|
+package net.md_5.bungee;
|
||||||
|
+
|
||||||
|
+import com.google.common.collect.Iterables;
|
||||||
|
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||||
|
+import jline.console.completer.Completer;
|
||||||
|
+import net.md_5.bungee.api.ProxyServer;
|
||||||
|
+
|
||||||
|
+import java.util.ArrayList;
|
||||||
|
+import java.util.List;
|
||||||
|
+import java.util.concurrent.Callable;
|
||||||
|
+import java.util.concurrent.ExecutionException;
|
||||||
|
+import java.util.concurrent.ExecutorService;
|
||||||
|
+import java.util.concurrent.Executors;
|
||||||
|
+import java.util.concurrent.Future;
|
||||||
|
+import java.util.logging.Level;
|
||||||
|
+
|
||||||
|
+public class ConsoleCommandCompleter implements Completer
|
||||||
|
+{
|
||||||
|
+
|
||||||
|
+ private final ExecutorService executor = Executors.newSingleThreadExecutor(
|
||||||
|
+ new ThreadFactoryBuilder().setNameFormat( "Console Command Completer Thread - %1$d" ).build() );
|
||||||
|
+
|
||||||
|
+ private final ProxyServer proxy;
|
||||||
|
+
|
||||||
|
+ public ConsoleCommandCompleter( ProxyServer proxy )
|
||||||
|
+ {
|
||||||
|
+ this.proxy = proxy;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ public int complete( String buffer, int cursor, List<CharSequence> candidates )
|
||||||
|
+ {
|
||||||
|
+ Future<Iterable<String>> future = executor.submit( new Callable<Iterable<String>>()
|
||||||
|
+ {
|
||||||
|
+ @Override
|
||||||
|
+ public Iterable<String> call() throws Exception
|
||||||
|
+ {
|
||||||
|
+ List<String> results = new ArrayList<>();
|
||||||
|
+ proxy.getPluginManager().dispatchCommand( proxy.getConsole(), buffer, results );
|
||||||
|
+ return results;
|
||||||
|
+ }
|
||||||
|
+ } );
|
||||||
|
+
|
||||||
|
+ try
|
||||||
|
+ {
|
||||||
|
+ Iterable<String> offers = future.get();
|
||||||
|
+ if ( offers == null )
|
||||||
|
+ {
|
||||||
|
+ return cursor;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ Iterables.addAll( candidates, offers );
|
||||||
|
+
|
||||||
|
+ final int lastSpace = buffer.lastIndexOf( ' ' );
|
||||||
|
+ if ( lastSpace == -1 )
|
||||||
|
+ {
|
||||||
|
+ return cursor - buffer.length();
|
||||||
|
+ } else
|
||||||
|
+ {
|
||||||
|
+ return cursor - ( buffer.length() - lastSpace - 1 );
|
||||||
|
+ }
|
||||||
|
+ } catch ( ExecutionException ex )
|
||||||
|
+ {
|
||||||
|
+ proxy.getLogger().log( Level.WARNING, "Unhandled exception when tab completing", ex );
|
||||||
|
+ } catch ( InterruptedException ex )
|
||||||
|
+ {
|
||||||
|
+ Thread.currentThread().interrupt();
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return cursor;
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
--
|
||||||
|
2.8.3
|
||||||
|
|
Loading…
Reference in New Issue
Block a user