Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
Remove remaining deprecated APIs
Dieser Commit ist enthalten in:
Ursprung
a1eebc6502
Commit
d8d469af0b
@ -62,33 +62,6 @@ public interface CommandManager {
|
|||||||
*/
|
*/
|
||||||
void unregister(String alias);
|
void unregister(String alias);
|
||||||
|
|
||||||
/**
|
|
||||||
* Attempts to execute a command from the given {@code cmdLine} in
|
|
||||||
* a blocking fashion.
|
|
||||||
*
|
|
||||||
* @param source the source to execute the command for
|
|
||||||
* @param cmdLine the command to run
|
|
||||||
* @return {@code true} if the command was found and executed
|
|
||||||
* @deprecated this method blocks the current thread during the event call and
|
|
||||||
* the command execution. Prefer {@link #executeAsync(CommandSource, String)}
|
|
||||||
* instead.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
boolean execute(CommandSource source, String cmdLine);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attempts to execute a command from the given {@code cmdLine} without
|
|
||||||
* firing a {@link CommandExecuteEvent} in a blocking fashion.
|
|
||||||
*
|
|
||||||
* @param source the source to execute the command for
|
|
||||||
* @param cmdLine the command to run
|
|
||||||
* @return {@code true} if the command was found and executed
|
|
||||||
* @deprecated this methods blocks the current thread during the command execution.
|
|
||||||
* Prefer {@link #executeImmediatelyAsync(CommandSource, String)} instead.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
boolean executeImmediately(CommandSource source, String cmdLine);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to asynchronously execute a command from the given {@code cmdLine}.
|
* Attempts to asynchronously execute a command from the given {@code cmdLine}.
|
||||||
*
|
*
|
||||||
@ -97,7 +70,7 @@ public interface CommandManager {
|
|||||||
* @return a future that may be completed with the result of the command execution.
|
* @return a future that may be completed with the result of the command execution.
|
||||||
* Can be completed exceptionally if an exception is thrown during execution.
|
* Can be completed exceptionally if an exception is thrown during execution.
|
||||||
*/
|
*/
|
||||||
CompletableFuture<Boolean> executeAsync(CommandSource source, String cmdLine);
|
CompletableFuture<Boolean> execute(CommandSource source, String cmdLine);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to asynchronously execute a command from the given {@code cmdLine}
|
* Attempts to asynchronously execute a command from the given {@code cmdLine}
|
||||||
@ -108,7 +81,7 @@ public interface CommandManager {
|
|||||||
* @return a future that may be completed with the result of the command execution.
|
* @return a future that may be completed with the result of the command execution.
|
||||||
* Can be completed exceptionally if an exception is thrown during execution.
|
* Can be completed exceptionally if an exception is thrown during execution.
|
||||||
*/
|
*/
|
||||||
CompletableFuture<Boolean> executeImmediatelyAsync(CommandSource source, String cmdLine);
|
CompletableFuture<Boolean> executeImmediately(CommandSource source, String cmdLine);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the given alias is registered on this manager.
|
* Returns whether the given alias is registered on this manager.
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
package com.velocitypowered.api.event.connection;
|
package com.velocitypowered.api.event.connection;
|
||||||
|
|
||||||
import static com.velocitypowered.api.event.connection.DisconnectEvent.LoginStatus.CANCELLED_BY_PROXY;
|
|
||||||
import static com.velocitypowered.api.event.connection.DisconnectEvent.LoginStatus.CONFLICTING_LOGIN;
|
|
||||||
import static com.velocitypowered.api.event.connection.DisconnectEvent.LoginStatus.SUCCESSFUL_LOGIN;
|
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
|
||||||
@ -16,17 +12,6 @@ public final class DisconnectEvent {
|
|||||||
private final Player player;
|
private final Player player;
|
||||||
private final LoginStatus loginStatus;
|
private final LoginStatus loginStatus;
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public DisconnectEvent(Player player) {
|
|
||||||
this(player, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public DisconnectEvent(Player player,
|
|
||||||
boolean disconnectedDuringLogin) {
|
|
||||||
this(player, disconnectedDuringLogin ? CANCELLED_BY_PROXY : SUCCESSFUL_LOGIN);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DisconnectEvent(Player player, LoginStatus loginStatus) {
|
public DisconnectEvent(Player player, LoginStatus loginStatus) {
|
||||||
this.player = Preconditions.checkNotNull(player, "player");
|
this.player = Preconditions.checkNotNull(player, "player");
|
||||||
this.loginStatus = Preconditions.checkNotNull(loginStatus, "loginStatus");
|
this.loginStatus = Preconditions.checkNotNull(loginStatus, "loginStatus");
|
||||||
@ -36,11 +21,6 @@ public final class DisconnectEvent {
|
|||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public boolean disconnectedDuringLogin() {
|
|
||||||
return this.loginStatus == CANCELLED_BY_PROXY || this.loginStatus == CONFLICTING_LOGIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LoginStatus getLoginStatus() {
|
public LoginStatus getLoginStatus() {
|
||||||
return loginStatus;
|
return loginStatus;
|
||||||
}
|
}
|
||||||
|
@ -29,11 +29,6 @@ public final class ServerConnectedEvent {
|
|||||||
this.previousServer = previousServer;
|
this.previousServer = previousServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public ServerConnectedEvent(Player player, RegisteredServer server) {
|
|
||||||
this(player, server, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
@ -120,13 +120,7 @@ public class VelocityCommandManager implements CommandManager {
|
|||||||
return eventManager.fire(new CommandExecuteEvent(source, cmdLine));
|
return eventManager.fire(new CommandExecuteEvent(source, cmdLine));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private boolean executeImmediately0(final CommandSource source, final String cmdLine) {
|
||||||
public boolean execute(final CommandSource source, final String cmdLine) {
|
|
||||||
return executeAsync(source, cmdLine).join();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean executeImmediately(final CommandSource source, final String cmdLine) {
|
|
||||||
Preconditions.checkNotNull(source, "source");
|
Preconditions.checkNotNull(source, "source");
|
||||||
Preconditions.checkNotNull(cmdLine, "cmdLine");
|
Preconditions.checkNotNull(cmdLine, "cmdLine");
|
||||||
|
|
||||||
@ -150,27 +144,27 @@ public class VelocityCommandManager implements CommandManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> executeAsync(final CommandSource source, final String cmdLine) {
|
public CompletableFuture<Boolean> execute(final CommandSource source, final String cmdLine) {
|
||||||
Preconditions.checkNotNull(source, "source");
|
Preconditions.checkNotNull(source, "source");
|
||||||
Preconditions.checkNotNull(cmdLine, "cmdLine");
|
Preconditions.checkNotNull(cmdLine, "cmdLine");
|
||||||
|
|
||||||
return callCommandEvent(source, cmdLine).thenApply(event -> {
|
return callCommandEvent(source, cmdLine).thenApplyAsync(event -> {
|
||||||
CommandResult commandResult = event.getResult();
|
CommandResult commandResult = event.getResult();
|
||||||
if (commandResult.isForwardToServer() || !commandResult.isAllowed()) {
|
if (commandResult.isForwardToServer() || !commandResult.isAllowed()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return executeImmediately(source, commandResult.getCommand().orElse(event.getCommand()));
|
return executeImmediately0(source, commandResult.getCommand().orElse(event.getCommand()));
|
||||||
});
|
}, eventManager.getService());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> executeImmediatelyAsync(
|
public CompletableFuture<Boolean> executeImmediately(
|
||||||
final CommandSource source, final String cmdLine) {
|
final CommandSource source, final String cmdLine) {
|
||||||
Preconditions.checkNotNull(source, "source");
|
Preconditions.checkNotNull(source, "source");
|
||||||
Preconditions.checkNotNull(cmdLine, "cmdLine");
|
Preconditions.checkNotNull(cmdLine, "cmdLine");
|
||||||
|
|
||||||
return CompletableFuture.supplyAsync(
|
return CompletableFuture.supplyAsync(
|
||||||
() -> executeImmediately(source, cmdLine), eventManager.getService());
|
() -> executeImmediately0(source, cmdLine), eventManager.getService());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -505,7 +505,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
return CompletableFuture.runAsync(() -> smc.write(Chat.createServerbound("/"
|
return CompletableFuture.runAsync(() -> smc.write(Chat.createServerbound("/"
|
||||||
+ commandToRun)), smc.eventLoop());
|
+ commandToRun)), smc.eventLoop());
|
||||||
} else {
|
} else {
|
||||||
return server.getCommandManager().executeImmediatelyAsync(player, commandToRun)
|
return server.getCommandManager().executeImmediately(player, commandToRun)
|
||||||
.thenAcceptAsync(hasRun -> {
|
.thenAcceptAsync(hasRun -> {
|
||||||
if (!hasRun) {
|
if (!hasRun) {
|
||||||
smc.write(Chat.createServerbound("/" + commandToRun));
|
smc.write(Chat.createServerbound("/" + commandToRun));
|
||||||
|
@ -87,7 +87,7 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons
|
|||||||
@Override
|
@Override
|
||||||
protected void runCommand(String command) {
|
protected void runCommand(String command) {
|
||||||
try {
|
try {
|
||||||
if (!this.server.getCommandManager().execute(this, command)) {
|
if (!this.server.getCommandManager().execute(this, command).join()) {
|
||||||
sendMessage(Component.text("Command not found.", NamedTextColor.RED));
|
sendMessage(Component.text("Command not found.", NamedTextColor.RED));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -17,7 +17,6 @@ import com.mojang.brigadier.tree.ArgumentCommandNode;
|
|||||||
import com.mojang.brigadier.tree.CommandNode;
|
import com.mojang.brigadier.tree.CommandNode;
|
||||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
import com.velocitypowered.api.command.BrigadierCommand;
|
import com.velocitypowered.api.command.BrigadierCommand;
|
||||||
import com.velocitypowered.api.command.Command;
|
|
||||||
import com.velocitypowered.api.command.CommandMeta;
|
import com.velocitypowered.api.command.CommandMeta;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
import com.velocitypowered.api.command.RawCommand;
|
import com.velocitypowered.api.command.RawCommand;
|
||||||
@ -27,7 +26,6 @@ import com.velocitypowered.proxy.plugin.VelocityEventManager;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class CommandManagerTests {
|
public class CommandManagerTests {
|
||||||
@ -53,8 +51,8 @@ public class CommandManagerTests {
|
|||||||
VelocityCommandManager manager = createManager();
|
VelocityCommandManager manager = createManager();
|
||||||
assertFalse(manager.hasCommand("foo"));
|
assertFalse(manager.hasCommand("foo"));
|
||||||
assertTrue(manager.getDispatcher().getRoot().getChildren().isEmpty());
|
assertTrue(manager.getDispatcher().getRoot().getChildren().isEmpty());
|
||||||
assertFalse(manager.execute(MockCommandSource.INSTANCE, "foo"));
|
assertFalse(manager.execute(MockCommandSource.INSTANCE, "foo").join());
|
||||||
assertFalse(manager.executeImmediately(MockCommandSource.INSTANCE, "bar"));
|
assertFalse(manager.executeImmediately(MockCommandSource.INSTANCE, "bar").join());
|
||||||
assertTrue(manager.offerSuggestions(MockCommandSource.INSTANCE, "").join().isEmpty());
|
assertTrue(manager.offerSuggestions(MockCommandSource.INSTANCE, "").join().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,14 +160,15 @@ public class CommandManagerTests {
|
|||||||
node.addChild(quantityNode);
|
node.addChild(quantityNode);
|
||||||
manager.register(new BrigadierCommand(node));
|
manager.register(new BrigadierCommand(node));
|
||||||
|
|
||||||
assertTrue(manager.executeAsync(MockCommandSource.INSTANCE, "buy ").join());
|
assertTrue(manager.execute(MockCommandSource.INSTANCE, "buy ").join());
|
||||||
assertTrue(executed.compareAndSet(true, false), "was executed");
|
assertTrue(executed.compareAndSet(true, false), "was executed");
|
||||||
assertTrue(manager.executeImmediatelyAsync(MockCommandSource.INSTANCE, "buy 14").join());
|
assertTrue(manager.executeImmediately(MockCommandSource.INSTANCE, "buy 14").join());
|
||||||
assertTrue(checkedRequires.compareAndSet(true, false));
|
assertTrue(checkedRequires.compareAndSet(true, false));
|
||||||
assertTrue(executed.get());
|
assertTrue(executed.get());
|
||||||
assertFalse(manager.execute(MockCommandSource.INSTANCE, "buy 9"),
|
assertFalse(manager.execute(MockCommandSource.INSTANCE, "buy 9").join(),
|
||||||
"Invalid arg returns false");
|
"Invalid arg returns false");
|
||||||
assertFalse(manager.executeImmediately(MockCommandSource.INSTANCE, "buy 12 bananas"));
|
assertFalse(manager.executeImmediately(MockCommandSource.INSTANCE, "buy 12 bananas")
|
||||||
|
.join());
|
||||||
assertTrue(checkedRequires.get());
|
assertTrue(checkedRequires.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,7 +183,7 @@ public class CommandManagerTests {
|
|||||||
};
|
};
|
||||||
manager.register("foo", command);
|
manager.register("foo", command);
|
||||||
|
|
||||||
assertTrue(manager.executeAsync(MockCommandSource.INSTANCE, "foo bar 254").join());
|
assertTrue(manager.execute(MockCommandSource.INSTANCE, "foo bar 254").join());
|
||||||
assertTrue(executed.get());
|
assertTrue(executed.get());
|
||||||
|
|
||||||
SimpleCommand noPermsCommand = new SimpleCommand() {
|
SimpleCommand noPermsCommand = new SimpleCommand() {
|
||||||
@ -200,8 +199,9 @@ public class CommandManagerTests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
manager.register("dangerous", noPermsCommand, "veryDangerous");
|
manager.register("dangerous", noPermsCommand, "veryDangerous");
|
||||||
assertFalse(manager.execute(MockCommandSource.INSTANCE, "dangerous"));
|
assertFalse(manager.execute(MockCommandSource.INSTANCE, "dangerous").join());
|
||||||
assertFalse(manager.executeImmediately(MockCommandSource.INSTANCE, "verydangerous 123"));
|
assertFalse(manager.executeImmediately(MockCommandSource.INSTANCE, "verydangerous 123")
|
||||||
|
.join());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -218,7 +218,8 @@ public class CommandManagerTests {
|
|||||||
};
|
};
|
||||||
manager.register("sendMe", command);
|
manager.register("sendMe", command);
|
||||||
|
|
||||||
assertTrue(manager.executeImmediately(MockCommandSource.INSTANCE, "sendMe lobby 23"));
|
assertTrue(manager.executeImmediately(MockCommandSource.INSTANCE, "sendMe lobby 23")
|
||||||
|
.join());
|
||||||
assertTrue(executed.compareAndSet(true, false));
|
assertTrue(executed.compareAndSet(true, false));
|
||||||
|
|
||||||
RawCommand noArgsCommand = new RawCommand() {
|
RawCommand noArgsCommand = new RawCommand() {
|
||||||
@ -230,9 +231,9 @@ public class CommandManagerTests {
|
|||||||
};
|
};
|
||||||
manager.register("noargs", noArgsCommand);
|
manager.register("noargs", noArgsCommand);
|
||||||
|
|
||||||
assertTrue(manager.executeImmediately(MockCommandSource.INSTANCE, "noargs"));
|
assertTrue(manager.executeImmediately(MockCommandSource.INSTANCE, "noargs").join());
|
||||||
assertTrue(executed.get());
|
assertTrue(executed.get());
|
||||||
assertTrue(manager.executeImmediately(MockCommandSource.INSTANCE, "noargs "));
|
assertTrue(manager.executeImmediately(MockCommandSource.INSTANCE, "noargs ").join());
|
||||||
|
|
||||||
RawCommand noPermsCommand = new RawCommand() {
|
RawCommand noPermsCommand = new RawCommand() {
|
||||||
@Override
|
@Override
|
||||||
@ -247,7 +248,8 @@ public class CommandManagerTests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
manager.register("sendThem", noPermsCommand);
|
manager.register("sendThem", noPermsCommand);
|
||||||
assertFalse(manager.executeImmediately(MockCommandSource.INSTANCE, "sendThem foo"));
|
assertFalse(manager.executeImmediately(MockCommandSource.INSTANCE, "sendThem foo")
|
||||||
|
.join());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -410,16 +412,16 @@ public class CommandManagerTests {
|
|||||||
manager.register(meta, command);
|
manager.register(meta, command);
|
||||||
|
|
||||||
expectedArgs.set("notBarOrBaz");
|
expectedArgs.set("notBarOrBaz");
|
||||||
assertTrue(manager.execute(MockCommandSource.INSTANCE, "foo notBarOrBaz"));
|
assertTrue(manager.execute(MockCommandSource.INSTANCE, "foo notBarOrBaz").join());
|
||||||
assertTrue(executed.compareAndSet(true, false));
|
assertTrue(executed.compareAndSet(true, false));
|
||||||
expectedArgs.set("anotherArg 123");
|
expectedArgs.set("anotherArg 123");
|
||||||
assertTrue(manager.execute(MockCommandSource.INSTANCE, "Foo2 anotherArg 123"));
|
assertTrue(manager.execute(MockCommandSource.INSTANCE, "Foo2 anotherArg 123").join());
|
||||||
assertTrue(executed.compareAndSet(true, false));
|
assertTrue(executed.compareAndSet(true, false));
|
||||||
expectedArgs.set("bar");
|
expectedArgs.set("bar");
|
||||||
assertTrue(manager.execute(MockCommandSource.INSTANCE, "foo bar"));
|
assertTrue(manager.execute(MockCommandSource.INSTANCE, "foo bar").join());
|
||||||
assertTrue(executed.compareAndSet(true, false));
|
assertTrue(executed.compareAndSet(true, false));
|
||||||
expectedArgs.set("bar 123");
|
expectedArgs.set("bar 123");
|
||||||
assertTrue(manager.execute(MockCommandSource.INSTANCE, "foo2 bar 123"));
|
assertTrue(manager.execute(MockCommandSource.INSTANCE, "foo2 bar 123").join());
|
||||||
assertTrue(executed.compareAndSet(true, false));
|
assertTrue(executed.compareAndSet(true, false));
|
||||||
|
|
||||||
assertEquals(ImmutableList.of("bar", "baz", "raw"),
|
assertEquals(ImmutableList.of("bar", "baz", "raw"),
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren