Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-12-24 15:20:35 +01:00
Introduce ConsoleCommandSource. See #155
Dieser Commit ist enthalten in:
Ursprung
773d9f0470
Commit
a9ae53e527
@ -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 {
|
||||||
|
}
|
@ -99,7 +99,7 @@ public interface ProxyServer {
|
|||||||
*
|
*
|
||||||
* @return the console command invoker
|
* @return the console command invoker
|
||||||
*/
|
*/
|
||||||
CommandSource getConsoleCommandSource();
|
ConsoleCommandSource getConsoleCommandSource();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the {@link PluginManager} instance.
|
* Gets the {@link PluginManager} instance.
|
||||||
|
@ -68,21 +68,29 @@ public class VelocityCommandManager implements CommandManager {
|
|||||||
return commands.containsKey(command);
|
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) {
|
public List<String> offerSuggestions(CommandSource source, String cmdLine) {
|
||||||
Preconditions.checkNotNull(source, "source");
|
Preconditions.checkNotNull(source, "source");
|
||||||
Preconditions.checkNotNull(cmdLine, "cmdLine");
|
Preconditions.checkNotNull(cmdLine, "cmdLine");
|
||||||
|
|
||||||
String[] split = cmdLine.split(" ", -1);
|
String[] split = cmdLine.split(" ", -1);
|
||||||
if (split.length == 0) {
|
if (split.length == 0) {
|
||||||
|
// No command available.
|
||||||
return ImmutableList.of();
|
return ImmutableList.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
String alias = split[0];
|
String alias = split[0];
|
||||||
if (split.length == 1) {
|
if (split.length == 1) {
|
||||||
|
// Offer to fill in commands.
|
||||||
List<String> availableCommands = new ArrayList<>();
|
List<String> availableCommands = new ArrayList<>();
|
||||||
for (Map.Entry<String, Command> entry : commands.entrySet()) {
|
for (Map.Entry<String, Command> entry : commands.entrySet()) {
|
||||||
if (entry.getKey().regionMatches(true, 0, alias, 0, alias.length()) &&
|
if (entry.getKey().regionMatches(true, 0, alias, 0, alias.length())
|
||||||
entry.getValue().hasPermission(source, new String[0])) {
|
&& entry.getValue().hasPermission(source, new String[0])) {
|
||||||
availableCommands.add("/" + entry.getKey());
|
availableCommands.add("/" + entry.getKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,6 +101,7 @@ public class VelocityCommandManager implements CommandManager {
|
|||||||
String[] actualArgs = Arrays.copyOfRange(split, 1, split.length);
|
String[] actualArgs = Arrays.copyOfRange(split, 1, split.length);
|
||||||
Command command = commands.get(alias.toLowerCase(Locale.ENGLISH));
|
Command command = commands.get(alias.toLowerCase(Locale.ENGLISH));
|
||||||
if (command == null) {
|
if (command == null) {
|
||||||
|
// No such command, so we can't offer any tab complete suggestions.
|
||||||
return ImmutableList.of();
|
return ImmutableList.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package com.velocitypowered.proxy.console;
|
package com.velocitypowered.proxy.console;
|
||||||
|
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
|
||||||
import com.velocitypowered.api.event.permission.PermissionsSetupEvent;
|
import com.velocitypowered.api.event.permission.PermissionsSetupEvent;
|
||||||
import com.velocitypowered.api.permission.PermissionFunction;
|
import com.velocitypowered.api.permission.PermissionFunction;
|
||||||
import com.velocitypowered.api.permission.Tristate;
|
import com.velocitypowered.api.permission.Tristate;
|
||||||
|
import com.velocitypowered.api.proxy.ConsoleCommandSource;
|
||||||
import com.velocitypowered.proxy.VelocityServer;
|
import com.velocitypowered.proxy.VelocityServer;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.kyori.text.Component;
|
import net.kyori.text.Component;
|
||||||
@ -18,7 +18,7 @@ import org.jline.reader.Candidate;
|
|||||||
import org.jline.reader.LineReader;
|
import org.jline.reader.LineReader;
|
||||||
import org.jline.reader.LineReaderBuilder;
|
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);
|
private static final Logger logger = LogManager.getLogger(VelocityConsole.class);
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren