Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-06 00:00:47 +01:00
Enforce at least one parameter in CommandManager#register()
The old register method has been deprecated.
Dieser Commit ist enthalten in:
Ursprung
ed8209cfd1
Commit
81840abc86
@ -10,9 +10,22 @@ public interface CommandManager {
|
|||||||
*
|
*
|
||||||
* @param command the command to register
|
* @param command the command to register
|
||||||
* @param aliases the alias to use
|
* @param aliases the alias to use
|
||||||
|
*
|
||||||
|
* @deprecated This method requires at least one alias, but this is only enforced at runtime.
|
||||||
|
* Prefer {@link #register(String, Command, String...)} instead.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
void register(Command command, String... aliases);
|
void register(Command command, String... aliases);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers the specified command with the manager with the specified aliases.
|
||||||
|
*
|
||||||
|
* @param alias the first alias to register
|
||||||
|
* @param command the command to register
|
||||||
|
* @param otherAliases the other aliases to use
|
||||||
|
*/
|
||||||
|
void register(String alias, Command command, String... otherAliases);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregisters a command.
|
* Unregisters a command.
|
||||||
*
|
*
|
||||||
|
@ -167,10 +167,10 @@ public class VelocityServer implements ProxyServer {
|
|||||||
cm.logChannelInformation();
|
cm.logChannelInformation();
|
||||||
|
|
||||||
// Initialize commands first
|
// Initialize commands first
|
||||||
commandManager.register(new VelocityCommand(this), "velocity");
|
commandManager.register("velocity", new VelocityCommand(this));
|
||||||
commandManager.register(new ServerCommand(this), "server");
|
commandManager.register("server", new ServerCommand(this));
|
||||||
commandManager.register(new ShutdownCommand(this), "shutdown", "end");
|
commandManager.register("shutdown", new ShutdownCommand(this),"end");
|
||||||
commandManager.register(new GlistCommand(this), "glist");
|
commandManager.register("glist", new GlistCommand(this));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Path configPath = Paths.get("velocity.toml");
|
Path configPath = Paths.get("velocity.toml");
|
||||||
|
@ -7,27 +7,35 @@ import com.velocitypowered.api.command.Command;
|
|||||||
import com.velocitypowered.api.command.CommandManager;
|
import com.velocitypowered.api.command.CommandManager;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
import com.velocitypowered.api.command.RawCommand;
|
import com.velocitypowered.api.command.RawCommand;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
||||||
|
|
||||||
public class VelocityCommandManager implements CommandManager {
|
public class VelocityCommandManager implements CommandManager {
|
||||||
|
|
||||||
private final Map<String, Command> commands = new HashMap<>();
|
private final Map<String, Command> commands = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public void register(final Command command, final String... aliases) {
|
public void register(final Command command, final String... aliases) {
|
||||||
Preconditions.checkNotNull(aliases, "aliases");
|
Preconditions.checkArgument(aliases.length > 0, "no aliases provided");
|
||||||
|
register(aliases[0], command, Arrays.copyOfRange(aliases, 1, aliases.length));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void register(String alias, Command command, String... otherAliases) {
|
||||||
|
Preconditions.checkNotNull(alias, "alias");
|
||||||
|
Preconditions.checkNotNull(otherAliases, "otherAliases");
|
||||||
Preconditions.checkNotNull(command, "executor");
|
Preconditions.checkNotNull(command, "executor");
|
||||||
for (int i = 0, length = aliases.length; i < length; i++) {
|
this.commands.put(alias.toLowerCase(Locale.ENGLISH), command);
|
||||||
final String alias = aliases[i];
|
|
||||||
Preconditions.checkNotNull(alias, "alias at index %s", i);
|
for (int i = 0, length = otherAliases.length; i < length; i++) {
|
||||||
this.commands.put(alias.toLowerCase(Locale.ENGLISH), command);
|
final String alias1 = otherAliases[i];
|
||||||
|
Preconditions.checkNotNull(alias1, "alias at index %s", i + 1);
|
||||||
|
this.commands.put(alias1.toLowerCase(Locale.ENGLISH), command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren