3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-12-23 23:00:35 +01:00

Introduce ConsoleCommandSource. See #155

Dieser Commit ist enthalten in:
Andrew Steinborn 2018-12-01 17:08:34 -05:00
Ursprung 773d9f0470
Commit a9ae53e527
4 geänderte Dateien mit 23 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,9 @@
package com.velocitypowered.api.proxy;
import com.velocitypowered.api.command.CommandSource;
/**
* Indicates that the executor of the command is the console.
*/
public interface ConsoleCommandSource extends CommandSource {
}

Datei anzeigen

@ -99,7 +99,7 @@ public interface ProxyServer {
*
* @return the console command invoker
*/
CommandSource getConsoleCommandSource();
ConsoleCommandSource getConsoleCommandSource();
/**
* Gets the {@link PluginManager} instance.

Datei anzeigen

@ -68,21 +68,29 @@ public class VelocityCommandManager implements CommandManager {
return commands.containsKey(command);
}
/**
* Offer suggestions to fill in the command.
* @param source the source for the command
* @param cmdLine the partially completed command
* @return a {@link List}, possibly empty
*/
public List<String> offerSuggestions(CommandSource source, String cmdLine) {
Preconditions.checkNotNull(source, "source");
Preconditions.checkNotNull(cmdLine, "cmdLine");
String[] split = cmdLine.split(" ", -1);
if (split.length == 0) {
// No command available.
return ImmutableList.of();
}
String alias = split[0];
if (split.length == 1) {
// Offer to fill in commands.
List<String> availableCommands = new ArrayList<>();
for (Map.Entry<String, Command> entry : commands.entrySet()) {
if (entry.getKey().regionMatches(true, 0, alias, 0, alias.length()) &&
entry.getValue().hasPermission(source, new String[0])) {
if (entry.getKey().regionMatches(true, 0, alias, 0, alias.length())
&& entry.getValue().hasPermission(source, new String[0])) {
availableCommands.add("/" + entry.getKey());
}
}
@ -93,6 +101,7 @@ public class VelocityCommandManager implements CommandManager {
String[] actualArgs = Arrays.copyOfRange(split, 1, split.length);
Command command = commands.get(alias.toLowerCase(Locale.ENGLISH));
if (command == null) {
// No such command, so we can't offer any tab complete suggestions.
return ImmutableList.of();
}

Datei anzeigen

@ -1,9 +1,9 @@
package com.velocitypowered.proxy.console;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.event.permission.PermissionsSetupEvent;
import com.velocitypowered.api.permission.PermissionFunction;
import com.velocitypowered.api.permission.Tristate;
import com.velocitypowered.api.proxy.ConsoleCommandSource;
import com.velocitypowered.proxy.VelocityServer;
import java.util.List;
import net.kyori.text.Component;
@ -18,7 +18,7 @@ import org.jline.reader.Candidate;
import org.jline.reader.LineReader;
import org.jline.reader.LineReaderBuilder;
public final class VelocityConsole extends SimpleTerminalConsole implements CommandSource {
public final class VelocityConsole extends SimpleTerminalConsole implements ConsoleCommandSource {
private static final Logger logger = LogManager.getLogger(VelocityConsole.class);