Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
Remove deprecated Velocity 1.0.0 Command API.
Dieser Commit ist enthalten in:
Ursprung
9dfe44b125
Commit
a1eebc6502
@ -25,66 +25,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
* to Velocity.
|
* to Velocity.
|
||||||
*
|
*
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
|
||||||
* <p>For this reason, the legacy {@code execute}, {@code suggest} and
|
|
||||||
* {@code hasPermission} methods are deprecated and will be removed
|
|
||||||
* in Velocity 2.0.0. We suggest implementing one of the more specific
|
|
||||||
* subinterfaces instead.
|
|
||||||
* The legacy methods are executed by a {@link CommandManager} if and only if
|
|
||||||
* the given command <b>directly</b> implements this interface.
|
|
||||||
*/
|
*/
|
||||||
public interface Command {
|
public interface Command {
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes the command for the specified source.
|
|
||||||
*
|
|
||||||
* @param source the source to execute the command for
|
|
||||||
* @param args the arguments for the command
|
|
||||||
* @deprecated see {@link Command}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
default void execute(final CommandSource source, final String @NonNull [] args) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides tab complete suggestions for the specified source.
|
|
||||||
*
|
|
||||||
* @param source the source to execute the command for
|
|
||||||
* @param currentArgs the partial arguments for the command
|
|
||||||
* @return the tab complete suggestions
|
|
||||||
* @deprecated see {@link Command}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
default List<String> suggest(final CommandSource source, final String @NonNull [] currentArgs) {
|
|
||||||
return ImmutableList.of();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides tab complete suggestions for the specified source.
|
|
||||||
*
|
|
||||||
* @param source the source to execute the command for
|
|
||||||
* @param currentArgs the partial arguments for the command
|
|
||||||
* @return the tab complete suggestions
|
|
||||||
* @deprecated see {@link Command}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
default CompletableFuture<List<String>> suggestAsync(final CommandSource source,
|
|
||||||
String @NonNull [] currentArgs) {
|
|
||||||
return CompletableFuture.completedFuture(suggest(source, currentArgs));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests to check if the source has permission to perform the command with
|
|
||||||
* the provided arguments.
|
|
||||||
*
|
|
||||||
* @param source the source to execute the command for
|
|
||||||
* @param args the arguments for the command
|
|
||||||
* @return {@code true} if the source has permission
|
|
||||||
* @deprecated see {@link Command}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
default boolean hasPermission(final CommandSource source, final String @NonNull [] args) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -26,19 +26,6 @@ public interface CommandManager {
|
|||||||
*/
|
*/
|
||||||
CommandMeta.Builder metaBuilder(BrigadierCommand command);
|
CommandMeta.Builder metaBuilder(BrigadierCommand command);
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers the specified command with the specified aliases.
|
|
||||||
*
|
|
||||||
* @param command the command to register
|
|
||||||
* @param aliases the command aliases
|
|
||||||
*
|
|
||||||
* @throws IllegalArgumentException if one of the given aliases is already registered
|
|
||||||
* @deprecated This method requires at least one alias, but this is only enforced at runtime.
|
|
||||||
* Prefer {@link #register(String, Command, String...)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
void register(Command command, String... aliases);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers the specified command with the specified aliases.
|
* Registers the specified command with the specified aliases.
|
||||||
*
|
*
|
||||||
@ -46,10 +33,10 @@ public interface CommandManager {
|
|||||||
* @param command the command to register
|
* @param command the command to register
|
||||||
* @param otherAliases additional aliases
|
* @param otherAliases additional aliases
|
||||||
* @throws IllegalArgumentException if one of the given aliases is already registered
|
* @throws IllegalArgumentException if one of the given aliases is already registered
|
||||||
* @deprecated Prefer {@link #register(CommandMeta, Command)} instead.
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
default void register(String alias, Command command, String... otherAliases) {
|
||||||
void register(String alias, Command command, String... otherAliases);
|
register(metaBuilder(alias).aliases(otherAliases).build(), command);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers the specified Brigadier command.
|
* Registers the specified Brigadier command.
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
package com.velocitypowered.api.command;
|
package com.velocitypowered.api.command;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A specialized sub-interface of {@code Command} which indicates the proxy should pass
|
* A specialized sub-interface of {@code Command} which indicates the proxy should pass
|
||||||
* the command and its arguments directly without further processing.
|
* the command and its arguments directly without further processing.
|
||||||
@ -11,77 +7,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
*/
|
*/
|
||||||
public interface RawCommand extends InvocableCommand<RawCommand.Invocation> {
|
public interface RawCommand extends InvocableCommand<RawCommand.Invocation> {
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes the command for the specified source.
|
|
||||||
*
|
|
||||||
* @param source the source to execute the command for
|
|
||||||
* @param cmdLine the arguments for the command
|
|
||||||
* @deprecated see {@link Command}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
default void execute(final CommandSource source, final String cmdLine) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
default void execute(final CommandSource source, final String @NonNull [] args) {
|
|
||||||
execute(source, String.join(" ", args));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
default void execute(Invocation invocation) {
|
|
||||||
// Guarantees ABI compatibility
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides tab complete suggestions for the specified source.
|
|
||||||
*
|
|
||||||
* @param source the source to execute the command for
|
|
||||||
* @param currentArgs the partial arguments for the command
|
|
||||||
* @return the tab complete suggestions
|
|
||||||
* @deprecated see {@link Command}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
default CompletableFuture<List<String>> suggest(final CommandSource source,
|
|
||||||
final String currentArgs) {
|
|
||||||
// This method even has an inconsistent return type
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
default List<String> suggest(final CommandSource source, final String @NonNull [] currentArgs) {
|
|
||||||
return suggestAsync(source, currentArgs).join();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
default CompletableFuture<List<String>> suggestAsync(final CommandSource source,
|
|
||||||
final String @NonNull [] currentArgs) {
|
|
||||||
return suggest(source, String.join(" ", currentArgs));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests to check if the source has permission to perform the command with
|
|
||||||
* the provided arguments.
|
|
||||||
*
|
|
||||||
* @param source the source to execute the command for
|
|
||||||
* @param cmdLine the arguments for the command
|
|
||||||
* @return {@code true} if the source has permission
|
|
||||||
* @deprecated see {@link Command}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
default boolean hasPermission(final CommandSource source, final String cmdLine) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
default boolean hasPermission(final CommandSource source, final String @NonNull [] args) {
|
|
||||||
return hasPermission(source, String.join(" ", args));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains the invocation data for a raw command.
|
* Contains the invocation data for a raw command.
|
||||||
*/
|
*/
|
||||||
|
@ -32,29 +32,6 @@ public interface CommandNodeFactory<T extends Command> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
CommandNodeFactory<Command> FALLBACK = (alias, command) ->
|
|
||||||
BrigadierUtils.buildRawArgumentsLiteral(alias,
|
|
||||||
context -> {
|
|
||||||
CommandSource source = context.getSource();
|
|
||||||
String[] args = BrigadierUtils.getSplitArguments(context);
|
|
||||||
|
|
||||||
if (!command.hasPermission(source, args)) {
|
|
||||||
return BrigadierCommand.FORWARD;
|
|
||||||
}
|
|
||||||
command.execute(source, args);
|
|
||||||
return 1;
|
|
||||||
},
|
|
||||||
(context, builder) -> {
|
|
||||||
String[] args = BrigadierUtils.getSplitArguments(context);
|
|
||||||
return command.suggestAsync(context.getSource(), args).thenApply(values -> {
|
|
||||||
for (String value : values) {
|
|
||||||
builder.suggest(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder.build();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a Brigadier node for the execution of the given command.
|
* Returns a Brigadier node for the execution of the given command.
|
||||||
*
|
*
|
||||||
|
@ -19,14 +19,12 @@ import com.velocitypowered.api.event.command.CommandExecuteEvent;
|
|||||||
import com.velocitypowered.api.event.command.CommandExecuteEvent.CommandResult;
|
import com.velocitypowered.api.event.command.CommandExecuteEvent.CommandResult;
|
||||||
import com.velocitypowered.proxy.plugin.VelocityEventManager;
|
import com.velocitypowered.proxy.plugin.VelocityEventManager;
|
||||||
import com.velocitypowered.proxy.util.BrigadierUtils;
|
import com.velocitypowered.proxy.util.BrigadierUtils;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import net.kyori.adventure.identity.Identity;
|
import net.kyori.adventure.identity.Identity;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.TextComponent;
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
|
||||||
public class VelocityCommandManager implements CommandManager {
|
public class VelocityCommandManager implements CommandManager {
|
||||||
@ -51,20 +49,6 @@ public class VelocityCommandManager implements CommandManager {
|
|||||||
return new VelocityCommandMeta.Builder(command.getNode().getName());
|
return new VelocityCommandMeta.Builder(command.getNode().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void register(final Command command, final String... aliases) {
|
|
||||||
Preconditions.checkArgument(aliases.length > 0, "no aliases provided");
|
|
||||||
register(aliases[0], command, Arrays.copyOfRange(aliases, 1, aliases.length));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void register(final String alias, final Command command, final String... otherAliases) {
|
|
||||||
Preconditions.checkNotNull(alias, "alias");
|
|
||||||
Preconditions.checkNotNull(command, "command");
|
|
||||||
Preconditions.checkNotNull(otherAliases, "otherAliases");
|
|
||||||
register(metaBuilder(alias).aliases(otherAliases).build(), command);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void register(final BrigadierCommand command) {
|
public void register(final BrigadierCommand command) {
|
||||||
Preconditions.checkNotNull(command, "command");
|
Preconditions.checkNotNull(command, "command");
|
||||||
@ -85,20 +69,10 @@ public class VelocityCommandManager implements CommandManager {
|
|||||||
} else if (command instanceof SimpleCommand) {
|
} else if (command instanceof SimpleCommand) {
|
||||||
node = CommandNodeFactory.SIMPLE.create(primaryAlias, (SimpleCommand) command);
|
node = CommandNodeFactory.SIMPLE.create(primaryAlias, (SimpleCommand) command);
|
||||||
} else if (command instanceof RawCommand) {
|
} else if (command instanceof RawCommand) {
|
||||||
// This ugly hack will be removed in Velocity 2.0. Most if not all plugins
|
node = CommandNodeFactory.RAW.create(primaryAlias, (RawCommand) command);
|
||||||
// have side-effect free #suggest methods. We rely on the newer RawCommand
|
} else {
|
||||||
// throwing UOE.
|
throw new IllegalArgumentException("Unknown command implementation for "
|
||||||
RawCommand asRaw = (RawCommand) command;
|
+ command.getClass().getName());
|
||||||
try {
|
|
||||||
asRaw.suggest(null, new String[0]);
|
|
||||||
} catch (final UnsupportedOperationException e) {
|
|
||||||
node = CommandNodeFactory.RAW.create(primaryAlias, asRaw);
|
|
||||||
} catch (final Exception ignored) {
|
|
||||||
// The implementation probably relies on a non-null source
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (node == null) {
|
|
||||||
node = CommandNodeFactory.FALLBACK.create(primaryAlias, command);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(command instanceof BrigadierCommand)) {
|
if (!(command instanceof BrigadierCommand)) {
|
||||||
|
@ -105,28 +105,15 @@ public class CommandManagerTests {
|
|||||||
VelocityCommandManager manager = createManager();
|
VelocityCommandManager manager = createManager();
|
||||||
RawCommand command = new NoopRawCommand();
|
RawCommand command = new NoopRawCommand();
|
||||||
|
|
||||||
assertThrows(IllegalArgumentException.class, () -> manager.register(command),
|
manager.register("foO", command, "BAR");
|
||||||
"no aliases throws");
|
|
||||||
manager.register(command, "foO", "BAR");
|
|
||||||
assertTrue(manager.hasCommand("fOo"));
|
assertTrue(manager.hasCommand("fOo"));
|
||||||
assertTrue(manager.hasCommand("bar"));
|
assertTrue(manager.hasCommand("bar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void testDeprecatedRegister() {
|
|
||||||
VelocityCommandManager manager = createManager();
|
|
||||||
Command command = new NoopDeprecatedCommand();
|
|
||||||
|
|
||||||
manager.register("foo", command);
|
|
||||||
assertTrue(manager.hasCommand("foO"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testAlreadyRegisteredThrows() {
|
void testAlreadyRegisteredThrows() {
|
||||||
VelocityCommandManager manager = createManager();
|
VelocityCommandManager manager = createManager();
|
||||||
manager.register("bar", new NoopDeprecatedCommand());
|
manager.register("BAR", new NoopSimpleCommand());
|
||||||
assertThrows(IllegalArgumentException.class, () ->
|
|
||||||
manager.register("BAR", new NoopSimpleCommand()));
|
|
||||||
assertThrows(IllegalArgumentException.class, () -> {
|
assertThrows(IllegalArgumentException.class, () -> {
|
||||||
CommandMeta meta = manager.metaBuilder("baz")
|
CommandMeta meta = manager.metaBuilder("baz")
|
||||||
.aliases("BAr")
|
.aliases("BAr")
|
||||||
@ -263,35 +250,6 @@ public class CommandManagerTests {
|
|||||||
assertFalse(manager.executeImmediately(MockCommandSource.INSTANCE, "sendThem foo"));
|
assertFalse(manager.executeImmediately(MockCommandSource.INSTANCE, "sendThem foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void testDeprecatedExecute() {
|
|
||||||
VelocityCommandManager manager = createManager();
|
|
||||||
AtomicBoolean executed = new AtomicBoolean(false);
|
|
||||||
Command command = new Command() {
|
|
||||||
@Override
|
|
||||||
public void execute(final CommandSource source, final String @NonNull [] args) {
|
|
||||||
assertEquals(MockCommandSource.INSTANCE, source);
|
|
||||||
assertArrayEquals(new String[] { "boo", "123" }, args);
|
|
||||||
executed.set(true);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
manager.register("foo", command);
|
|
||||||
|
|
||||||
assertTrue(manager.execute(MockCommandSource.INSTANCE, "foo boo 123"));
|
|
||||||
assertTrue(executed.get());
|
|
||||||
|
|
||||||
Command noPermsCommand = new Command() {
|
|
||||||
@Override
|
|
||||||
public boolean hasPermission(final CommandSource source, final String @NonNull [] args) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
manager.register("oof", noPermsCommand, "veryOof");
|
|
||||||
assertFalse(manager.execute(MockCommandSource.INSTANCE, "veryOOF"));
|
|
||||||
assertFalse(manager.executeImmediately(MockCommandSource.INSTANCE, "ooF boo 54321"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testSuggestions() {
|
void testSuggestions() {
|
||||||
VelocityCommandManager manager = createManager();
|
VelocityCommandManager manager = createManager();
|
||||||
@ -352,24 +310,8 @@ public class CommandManagerTests {
|
|||||||
};
|
};
|
||||||
manager.register("raw", rawCommand);
|
manager.register("raw", rawCommand);
|
||||||
|
|
||||||
Command deprecatedCommand = new Command() {
|
|
||||||
@Override
|
|
||||||
public List<String> suggest(
|
|
||||||
final CommandSource source, final String @NonNull [] currentArgs) {
|
|
||||||
switch (currentArgs.length) {
|
|
||||||
case 0:
|
|
||||||
return ImmutableList.of("boo", "scary");
|
|
||||||
case 1:
|
|
||||||
return ImmutableList.of("123", "456");
|
|
||||||
default:
|
|
||||||
return ImmutableList.of();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
manager.register("deprecated", deprecatedCommand);
|
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
ImmutableList.of("brigadier", "deprecated", "raw", "simple"),
|
ImmutableList.of("brigadier", "raw", "simple"),
|
||||||
manager.offerSuggestions(MockCommandSource.INSTANCE, "").join(),
|
manager.offerSuggestions(MockCommandSource.INSTANCE, "").join(),
|
||||||
"literals are in alphabetical order");
|
"literals are in alphabetical order");
|
||||||
assertEquals(
|
assertEquals(
|
||||||
@ -403,16 +345,6 @@ public class CommandManagerTests {
|
|||||||
assertEquals(
|
assertEquals(
|
||||||
ImmutableList.of("11", "13", "17"),
|
ImmutableList.of("11", "13", "17"),
|
||||||
manager.offerSuggestions(MockCommandSource.INSTANCE, "rAW bar ").join());
|
manager.offerSuggestions(MockCommandSource.INSTANCE, "rAW bar ").join());
|
||||||
assertEquals(
|
|
||||||
ImmutableList.of("boo", "scary"),
|
|
||||||
manager.offerSuggestions(MockCommandSource.INSTANCE, "deprecated ").join());
|
|
||||||
assertTrue(manager.offerSuggestions(MockCommandSource.INSTANCE, "deprecated")
|
|
||||||
.join().isEmpty());
|
|
||||||
assertEquals(
|
|
||||||
ImmutableList.of("123", "456"),
|
|
||||||
manager.offerSuggestions(MockCommandSource.INSTANCE, "deprEcated foo ").join());
|
|
||||||
assertTrue(manager.offerSuggestions(MockCommandSource.INSTANCE, "deprecated foo 789 ")
|
|
||||||
.join().isEmpty());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -513,11 +445,4 @@ public class CommandManagerTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class NoopDeprecatedCommand implements Command {
|
|
||||||
@Override
|
|
||||||
public void execute(final CommandSource source, final String @NonNull [] args) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren