mirror of
https://github.com/PaperMC/Velocity.git
synced 2026-02-17 14:37:43 +01:00
[Breaking] Many renamings in the API
The get prefix has been dropped from getters where it is unambiguous what is being referred to. Other getters have also received renames to clarify their purpose. The main exception is the ProxyConfig API, but it's one of my personal sore spots in the API, so it'll be replaced instead.
This commit is contained in:
@@ -103,17 +103,17 @@ public class Metrics {
|
||||
Metrics metrics = new Metrics(logger, 4752, metricsConfig.isEnabled());
|
||||
|
||||
metrics.addCustomChart(
|
||||
new SingleLineChart("players", server::getPlayerCount)
|
||||
new SingleLineChart("players", server::countConnectedPlayers)
|
||||
);
|
||||
metrics.addCustomChart(
|
||||
new SingleLineChart("managed_servers", () -> server.getAllServers().size())
|
||||
new SingleLineChart("managed_servers", () -> server.registeredServers().size())
|
||||
);
|
||||
metrics.addCustomChart(
|
||||
new SimplePie("online_mode",
|
||||
() -> server.getConfiguration().isOnlineMode() ? "online" : "offline")
|
||||
() -> server.configuration().isOnlineMode() ? "online" : "offline")
|
||||
);
|
||||
metrics.addCustomChart(new SimplePie("velocity_version",
|
||||
() -> server.getVersion().getVersion()));
|
||||
() -> server.version().getVersion()));
|
||||
|
||||
metrics.addCustomChart(new DrilldownPie("java_version", () -> {
|
||||
Map<String, Map<String, Integer>> map = new HashMap<>();
|
||||
|
||||
@@ -84,7 +84,7 @@ public class Velocity {
|
||||
|
||||
double bootTime = (System.currentTimeMillis() - startTime) / 1000d;
|
||||
logger.info("Done ({}s)!", new DecimalFormat("#.##").format(bootTime));
|
||||
server.getConsoleCommandSource().start();
|
||||
server.consoleCommandSource().start();
|
||||
|
||||
// If we don't have a console available (because SimpleTerminalConsole returned), then we still
|
||||
// need to wait, otherwise the JVM will reap us as no non-daemon threads will be active once the
|
||||
|
||||
@@ -155,12 +155,12 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
|
||||
}
|
||||
|
||||
@Override
|
||||
public VelocityConfiguration getConfiguration() {
|
||||
public VelocityConfiguration configuration() {
|
||||
return this.configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProxyVersion getVersion() {
|
||||
public ProxyVersion version() {
|
||||
Package pkg = VelocityServer.class.getPackage();
|
||||
String implName;
|
||||
String implVersion;
|
||||
@@ -179,7 +179,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
|
||||
}
|
||||
|
||||
@Override
|
||||
public VelocityCommandManager getCommandManager() {
|
||||
public VelocityCommandManager commandManager() {
|
||||
return commandManager;
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
|
||||
@EnsuresNonNull({"serverKeyPair", "servers", "pluginManager", "eventManager", "scheduler",
|
||||
"console", "cm", "configuration"})
|
||||
void start() {
|
||||
logger.info("Booting up {} {}...", getVersion().getName(), getVersion().getVersion());
|
||||
logger.info("Booting up {} {}...", version().getName(), version().getVersion());
|
||||
console.setupStreams();
|
||||
|
||||
serverKeyPair = EncryptionUtils.createRsaKeyPair(1024);
|
||||
@@ -278,13 +278,13 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
|
||||
|
||||
// Register the plugin main classes so that we can fire the proxy initialize event
|
||||
for (PluginContainer plugin : pluginManager.getPlugins()) {
|
||||
Optional<?> instance = plugin.getInstance();
|
||||
Optional<?> instance = plugin.instance();
|
||||
if (instance.isPresent()) {
|
||||
try {
|
||||
eventManager.register(instance.get(), instance.get());
|
||||
} catch (Exception e) {
|
||||
logger.error("Unable to register plugin listener for {}",
|
||||
plugin.getDescription().getName().orElse(plugin.getDescription().getId()), e);
|
||||
plugin.description().name().orElse(plugin.description().id()), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -327,15 +327,15 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
|
||||
Optional<RegisteredServer> rs = servers.getServer(entry.getKey());
|
||||
if (!rs.isPresent()) {
|
||||
servers.register(newInfo);
|
||||
} else if (!rs.get().getServerInfo().equals(newInfo)) {
|
||||
for (Player player : rs.get().getPlayersConnected()) {
|
||||
} else if (!rs.get().serverInfo().equals(newInfo)) {
|
||||
for (Player player : rs.get().connectedPlayers()) {
|
||||
if (!(player instanceof ConnectedPlayer)) {
|
||||
throw new IllegalStateException("ConnectedPlayer not found for player " + player
|
||||
+ " in server " + rs.get().getServerInfo().getName());
|
||||
+ " in server " + rs.get().serverInfo().name());
|
||||
}
|
||||
evacuate.add((ConnectedPlayer) player);
|
||||
}
|
||||
servers.unregister(rs.get().getServerInfo());
|
||||
servers.unregister(rs.get().serverInfo());
|
||||
servers.register(newInfo);
|
||||
}
|
||||
}
|
||||
@@ -518,9 +518,9 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
|
||||
if (configuration.isOnlineMode() && configuration.isOnlineModeKickExistingPlayers()) {
|
||||
return true;
|
||||
}
|
||||
String lowerName = connection.getUsername().toLowerCase(Locale.US);
|
||||
String lowerName = connection.username().toLowerCase(Locale.US);
|
||||
return !(connectionsByName.containsKey(lowerName)
|
||||
|| connectionsByUuid.containsKey(connection.getUniqueId()));
|
||||
|| connectionsByUuid.containsKey(connection.id()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -529,25 +529,25 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
|
||||
* @return {@code true} if we registered the connection, {@code false} if not
|
||||
*/
|
||||
public boolean registerConnection(ConnectedPlayer connection) {
|
||||
String lowerName = connection.getUsername().toLowerCase(Locale.US);
|
||||
String lowerName = connection.username().toLowerCase(Locale.US);
|
||||
|
||||
if (!this.configuration.isOnlineModeKickExistingPlayers()) {
|
||||
if (connectionsByName.putIfAbsent(lowerName, connection) != null) {
|
||||
return false;
|
||||
}
|
||||
if (connectionsByUuid.putIfAbsent(connection.getUniqueId(), connection) != null) {
|
||||
if (connectionsByUuid.putIfAbsent(connection.id(), connection) != null) {
|
||||
connectionsByName.remove(lowerName, connection);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
ConnectedPlayer existing = connectionsByUuid.get(connection.getUniqueId());
|
||||
ConnectedPlayer existing = connectionsByUuid.get(connection.id());
|
||||
if (existing != null) {
|
||||
existing.disconnect(Component.translatable("multiplayer.disconnect.duplicate_login"));
|
||||
}
|
||||
|
||||
// We can now replace the entries as needed.
|
||||
connectionsByName.put(lowerName, connection);
|
||||
connectionsByUuid.put(connection.getUniqueId(), connection);
|
||||
connectionsByUuid.put(connection.id(), connection);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -558,8 +558,8 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
|
||||
* @param connection the connection to unregister
|
||||
*/
|
||||
public void unregisterConnection(ConnectedPlayer connection) {
|
||||
connectionsByName.remove(connection.getUsername().toLowerCase(Locale.US), connection);
|
||||
connectionsByUuid.remove(connection.getUniqueId(), connection);
|
||||
connectionsByName.remove(connection.username().toLowerCase(Locale.US), connection);
|
||||
connectionsByUuid.remove(connection.id(), connection);
|
||||
bossBarManager.onDisconnect(connection);
|
||||
}
|
||||
|
||||
@@ -579,7 +579,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
|
||||
public Collection<Player> matchPlayer(String partialName) {
|
||||
Objects.requireNonNull(partialName);
|
||||
|
||||
return getAllPlayers().stream().filter(p -> p.getUsername()
|
||||
return connectedPlayers().stream().filter(p -> p.username()
|
||||
.regionMatches(true, 0, partialName, 0, partialName.length()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
@@ -588,28 +588,28 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
|
||||
public Collection<RegisteredServer> matchServer(String partialName) {
|
||||
Objects.requireNonNull(partialName);
|
||||
|
||||
return getAllServers().stream().filter(s -> s.getServerInfo().getName()
|
||||
return registeredServers().stream().filter(s -> s.serverInfo().name()
|
||||
.regionMatches(true, 0, partialName, 0, partialName.length()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Player> getAllPlayers() {
|
||||
public Collection<Player> connectedPlayers() {
|
||||
return ImmutableList.copyOf(connectionsByUuid.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPlayerCount() {
|
||||
public int countConnectedPlayers() {
|
||||
return connectionsByUuid.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<RegisteredServer> getServer(String name) {
|
||||
public Optional<RegisteredServer> server(String name) {
|
||||
return servers.getServer(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<RegisteredServer> getAllServers() {
|
||||
public Collection<RegisteredServer> registeredServers() {
|
||||
return servers.getAllServers();
|
||||
}
|
||||
|
||||
@@ -624,44 +624,35 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
|
||||
}
|
||||
|
||||
@Override
|
||||
public VelocityConsole getConsoleCommandSource() {
|
||||
public VelocityConsole consoleCommandSource() {
|
||||
return console;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginManager getPluginManager() {
|
||||
public PluginManager pluginManager() {
|
||||
return pluginManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventManager getEventManager() {
|
||||
public EventManager eventManager() {
|
||||
return eventManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VelocityScheduler getScheduler() {
|
||||
public VelocityScheduler scheduler() {
|
||||
return scheduler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VelocityChannelRegistrar getChannelRegistrar() {
|
||||
public VelocityChannelRegistrar channelRegistrar() {
|
||||
return channelRegistrar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketAddress getBoundAddress() {
|
||||
if (configuration == null) {
|
||||
throw new IllegalStateException(
|
||||
"No configuration"); // even though you'll never get the chance... heh, heh
|
||||
}
|
||||
return configuration.getBind();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Iterable<? extends Audience> audiences() {
|
||||
Collection<Audience> audiences = new ArrayList<>(this.getPlayerCount() + 1);
|
||||
Collection<Audience> audiences = new ArrayList<>(this.countConnectedPlayers() + 1);
|
||||
audiences.add(this.console);
|
||||
audiences.addAll(this.getAllPlayers());
|
||||
audiences.addAll(this.connectedPlayers());
|
||||
return audiences;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ public class VelocityCommandManager implements CommandManager {
|
||||
Preconditions.checkNotNull(meta, "meta");
|
||||
Preconditions.checkNotNull(command, "command");
|
||||
|
||||
Iterator<String> aliasIterator = meta.getAliases().iterator();
|
||||
Iterator<String> aliasIterator = meta.aliases().iterator();
|
||||
String primaryAlias = aliasIterator.next();
|
||||
|
||||
LiteralCommandNode<CommandSource> node = null;
|
||||
@@ -94,7 +94,7 @@ public class VelocityCommandManager implements CommandManager {
|
||||
}
|
||||
|
||||
if (!(command instanceof BrigadierCommand)) {
|
||||
for (CommandNode<CommandSource> hint : meta.getHints()) {
|
||||
for (CommandNode<CommandSource> hint : meta.hints()) {
|
||||
node.addChild(BrigadierUtils.wrapForHinting(hint, node.getCommand()));
|
||||
}
|
||||
}
|
||||
@@ -160,11 +160,11 @@ public class VelocityCommandManager implements CommandManager {
|
||||
Preconditions.checkNotNull(cmdLine, "cmdLine");
|
||||
|
||||
return callCommandEvent(source, cmdLine).thenApplyAsync(event -> {
|
||||
CommandResult commandResult = event.getResult();
|
||||
CommandResult commandResult = event.result();
|
||||
if (commandResult.isForwardToServer() || !commandResult.isAllowed()) {
|
||||
return false;
|
||||
}
|
||||
return executeImmediately0(source, commandResult.getCommand().orElse(event.getCommand()));
|
||||
return executeImmediately0(source, commandResult.modifiedCommand().orElse(event.rawCommand()));
|
||||
}, eventManager.getAsyncExecutor());
|
||||
}
|
||||
|
||||
|
||||
@@ -76,12 +76,12 @@ final class VelocityCommandMeta implements CommandMeta {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getAliases() {
|
||||
public Collection<String> aliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<CommandNode<CommandSource>> getHints() {
|
||||
public Collection<CommandNode<CommandSource>> hints() {
|
||||
return hints;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ class BuiltinCommandUtil {
|
||||
}
|
||||
|
||||
static List<RegisteredServer> sortedServerList(ProxyServer proxy) {
|
||||
List<RegisteredServer> servers = new ArrayList<>(proxy.getAllServers());
|
||||
servers.sort(Comparator.comparing(RegisteredServer::getServerInfo));
|
||||
List<RegisteredServer> servers = new ArrayList<>(proxy.registeredServers());
|
||||
servers.sort(Comparator.comparing(RegisteredServer::serverInfo));
|
||||
return Collections.unmodifiableList(servers);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,14 +56,14 @@ public class GlistCommand {
|
||||
LiteralCommandNode<CommandSource> totalNode = LiteralArgumentBuilder
|
||||
.<CommandSource>literal("glist")
|
||||
.requires(source ->
|
||||
source.getPermissionValue("velocity.command.glist") == Tristate.TRUE)
|
||||
source.evaluatePermission("velocity.command.glist") == Tristate.TRUE)
|
||||
.executes(this::totalCount)
|
||||
.build();
|
||||
ArgumentCommandNode<CommandSource, String> serverNode = RequiredArgumentBuilder
|
||||
.<CommandSource, String>argument(SERVER_ARG, StringArgumentType.string())
|
||||
.suggests((context, builder) -> {
|
||||
for (RegisteredServer server : server.getAllServers()) {
|
||||
builder.suggest(server.getServerInfo().getName());
|
||||
for (RegisteredServer server : server.registeredServers()) {
|
||||
builder.suggest(server.serverInfo().name());
|
||||
}
|
||||
builder.suggest("all");
|
||||
return builder.buildFuture();
|
||||
@@ -71,7 +71,7 @@ public class GlistCommand {
|
||||
.executes(this::serverCount)
|
||||
.build();
|
||||
totalNode.addChild(serverNode);
|
||||
server.getCommandManager().register(new BrigadierCommand(totalNode));
|
||||
server.commandManager().register(new BrigadierCommand(totalNode));
|
||||
}
|
||||
|
||||
private int totalCount(final CommandContext<CommandSource> context) {
|
||||
@@ -95,7 +95,7 @@ public class GlistCommand {
|
||||
}
|
||||
sendTotalProxyCount(source);
|
||||
} else {
|
||||
Optional<RegisteredServer> registeredServer = server.getServer(serverName);
|
||||
Optional<RegisteredServer> registeredServer = server.server(serverName);
|
||||
if (!registeredServer.isPresent()) {
|
||||
source.sendMessage(Identity.nil(),
|
||||
Component.text("Server " + serverName + " doesn't exist.", NamedTextColor.RED));
|
||||
@@ -109,19 +109,19 @@ public class GlistCommand {
|
||||
private void sendTotalProxyCount(CommandSource target) {
|
||||
target.sendMessage(Identity.nil(), Component.text()
|
||||
.content("There are ").color(NamedTextColor.YELLOW)
|
||||
.append(Component.text(server.getAllPlayers().size(), NamedTextColor.GREEN))
|
||||
.append(Component.text(server.connectedPlayers().size(), NamedTextColor.GREEN))
|
||||
.append(Component.text(" player(s) online.", NamedTextColor.YELLOW))
|
||||
.build());
|
||||
}
|
||||
|
||||
private void sendServerPlayers(CommandSource target, RegisteredServer server, boolean fromAll) {
|
||||
List<Player> onServer = ImmutableList.copyOf(server.getPlayersConnected());
|
||||
List<Player> onServer = ImmutableList.copyOf(server.connectedPlayers());
|
||||
if (onServer.isEmpty() && fromAll) {
|
||||
return;
|
||||
}
|
||||
|
||||
TextComponent.Builder builder = Component.text()
|
||||
.append(Component.text("[" + server.getServerInfo().getName() + "] ",
|
||||
.append(Component.text("[" + server.serverInfo().name() + "] ",
|
||||
NamedTextColor.DARK_AQUA))
|
||||
.append(Component.text("(" + onServer.size() + ")", NamedTextColor.GRAY))
|
||||
.append(Component.text(": "))
|
||||
@@ -129,7 +129,7 @@ public class GlistCommand {
|
||||
|
||||
for (int i = 0; i < onServer.size(); i++) {
|
||||
Player player = onServer.get(i);
|
||||
builder.append(Component.text(player.getUsername()));
|
||||
builder.append(Component.text(player.username()));
|
||||
|
||||
if (i + 1 < onServer.size()) {
|
||||
builder.append(Component.text(", "));
|
||||
|
||||
@@ -62,7 +62,7 @@ public class ServerCommand implements SimpleCommand {
|
||||
if (args.length == 1) {
|
||||
// Trying to connect to a server.
|
||||
String serverName = args[0];
|
||||
Optional<RegisteredServer> toConnect = server.getServer(serverName);
|
||||
Optional<RegisteredServer> toConnect = server.server(serverName);
|
||||
if (!toConnect.isPresent()) {
|
||||
player.sendMessage(Identity.nil(),
|
||||
Component.text("Server " + serverName + " doesn't exist.", NamedTextColor.RED));
|
||||
@@ -76,8 +76,8 @@ public class ServerCommand implements SimpleCommand {
|
||||
}
|
||||
|
||||
private void outputServerInformation(Player executor) {
|
||||
String currentServer = executor.getCurrentServer().map(ServerConnection::getServerInfo)
|
||||
.map(ServerInfo::getName).orElse("<unknown>");
|
||||
String currentServer = executor.connectedServer().map(ServerConnection::serverInfo)
|
||||
.map(ServerInfo::name).orElse("<unknown>");
|
||||
executor.sendMessage(Identity.nil(), Component.text(
|
||||
"You are currently connected to " + currentServer + ".", NamedTextColor.YELLOW));
|
||||
|
||||
@@ -103,18 +103,18 @@ public class ServerCommand implements SimpleCommand {
|
||||
}
|
||||
|
||||
private TextComponent formatServerComponent(String currentPlayerServer, RegisteredServer server) {
|
||||
ServerInfo serverInfo = server.getServerInfo();
|
||||
TextComponent serverTextComponent = Component.text(serverInfo.getName());
|
||||
ServerInfo serverInfo = server.serverInfo();
|
||||
TextComponent serverTextComponent = Component.text(serverInfo.name());
|
||||
|
||||
String playersText = server.getPlayersConnected().size() + " player(s) online";
|
||||
if (serverInfo.getName().equals(currentPlayerServer)) {
|
||||
String playersText = server.connectedPlayers().size() + " player(s) online";
|
||||
if (serverInfo.name().equals(currentPlayerServer)) {
|
||||
serverTextComponent = serverTextComponent.color(NamedTextColor.GREEN)
|
||||
.hoverEvent(
|
||||
showText(Component.text("Currently connected to this server\n" + playersText))
|
||||
);
|
||||
} else {
|
||||
serverTextComponent = serverTextComponent.color(NamedTextColor.GRAY)
|
||||
.clickEvent(ClickEvent.runCommand("/server " + serverInfo.getName()))
|
||||
.clickEvent(ClickEvent.runCommand("/server " + serverInfo.name()))
|
||||
.hoverEvent(
|
||||
showText(Component.text("Click to connect to this server\n" + playersText))
|
||||
);
|
||||
@@ -125,8 +125,8 @@ public class ServerCommand implements SimpleCommand {
|
||||
@Override
|
||||
public List<String> suggest(final SimpleCommand.Invocation invocation) {
|
||||
final String[] currentArgs = invocation.arguments();
|
||||
Stream<String> possibilities = server.getAllServers().stream()
|
||||
.map(rs -> rs.getServerInfo().getName());
|
||||
Stream<String> possibilities = server.registeredServers().stream()
|
||||
.map(rs -> rs.serverInfo().name());
|
||||
|
||||
if (currentArgs.length == 0) {
|
||||
return possibilities.collect(Collectors.toList());
|
||||
@@ -141,6 +141,6 @@ public class ServerCommand implements SimpleCommand {
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final SimpleCommand.Invocation invocation) {
|
||||
return invocation.source().getPermissionValue("velocity.command.server") != Tristate.FALSE;
|
||||
return invocation.source().evaluatePermission("velocity.command.server") != Tristate.FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,6 @@ public class ShutdownCommand implements RawCommand {
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final Invocation invocation) {
|
||||
return invocation.source() == server.getConsoleCommandSource();
|
||||
return invocation.source() == server.consoleCommandSource();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ public class VelocityCommand implements SimpleCommand {
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final CommandSource source, final String @NonNull [] args) {
|
||||
return source.getPermissionValue("velocity.command.reload") == Tristate.TRUE;
|
||||
return source.evaluatePermission("velocity.command.reload") == Tristate.TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ public class VelocityCommand implements SimpleCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
ProxyVersion version = server.getVersion();
|
||||
ProxyVersion version = server.version();
|
||||
|
||||
TextComponent velocity = Component.text().content(version.getName() + " ")
|
||||
.decoration(TextDecoration.BOLD, true)
|
||||
@@ -251,7 +251,7 @@ public class VelocityCommand implements SimpleCommand {
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final CommandSource source, final String @NonNull [] args) {
|
||||
return source.getPermissionValue("velocity.command.info") != Tristate.FALSE;
|
||||
return source.evaluatePermission("velocity.command.info") != Tristate.FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ public class VelocityCommand implements SimpleCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
List<PluginContainer> plugins = ImmutableList.copyOf(server.getPluginManager().getPlugins());
|
||||
List<PluginContainer> plugins = ImmutableList.copyOf(server.pluginManager().getPlugins());
|
||||
int pluginCount = plugins.size();
|
||||
|
||||
if (pluginCount == 0) {
|
||||
@@ -283,7 +283,7 @@ public class VelocityCommand implements SimpleCommand {
|
||||
.color(NamedTextColor.YELLOW);
|
||||
for (int i = 0; i < pluginCount; i++) {
|
||||
PluginContainer plugin = plugins.get(i);
|
||||
output.append(componentForPlugin(plugin.getDescription()));
|
||||
output.append(componentForPlugin(plugin.description()));
|
||||
if (i + 1 < pluginCount) {
|
||||
output.append(Component.text(", "));
|
||||
}
|
||||
@@ -293,37 +293,37 @@ public class VelocityCommand implements SimpleCommand {
|
||||
}
|
||||
|
||||
private TextComponent componentForPlugin(PluginDescription description) {
|
||||
String pluginInfo = description.getName().orElse(description.getId())
|
||||
+ description.getVersion().map(v -> " " + v).orElse("");
|
||||
String pluginInfo = description.name().orElse(description.id())
|
||||
+ description.version().map(v -> " " + v).orElse("");
|
||||
|
||||
TextComponent.Builder hoverText = Component.text().content(pluginInfo);
|
||||
|
||||
description.getUrl().ifPresent(url -> {
|
||||
description.url().ifPresent(url -> {
|
||||
hoverText.append(Component.newline());
|
||||
hoverText.append(Component.text("Website: " + url));
|
||||
});
|
||||
if (!description.getAuthors().isEmpty()) {
|
||||
if (!description.authors().isEmpty()) {
|
||||
hoverText.append(Component.newline());
|
||||
if (description.getAuthors().size() == 1) {
|
||||
hoverText.append(Component.text("Author: " + description.getAuthors().get(0)));
|
||||
if (description.authors().size() == 1) {
|
||||
hoverText.append(Component.text("Author: " + description.authors().get(0)));
|
||||
} else {
|
||||
hoverText.append(Component.text("Authors: " + Joiner.on(", ")
|
||||
.join(description.getAuthors())));
|
||||
.join(description.authors())));
|
||||
}
|
||||
}
|
||||
description.getDescription().ifPresent(pdesc -> {
|
||||
description.description().ifPresent(pdesc -> {
|
||||
hoverText.append(Component.newline());
|
||||
hoverText.append(Component.newline());
|
||||
hoverText.append(Component.text(pdesc));
|
||||
});
|
||||
|
||||
return Component.text(description.getId(), NamedTextColor.GRAY)
|
||||
return Component.text(description.id(), NamedTextColor.GRAY)
|
||||
.hoverEvent(HoverEvent.showText(hoverText.build()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final CommandSource source, final String @NonNull [] args) {
|
||||
return source.getPermissionValue("velocity.command.plugins") == Tristate.TRUE;
|
||||
return source.evaluatePermission("velocity.command.plugins") == Tristate.TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,27 +343,27 @@ public class VelocityCommand implements SimpleCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
Collection<RegisteredServer> allServers = ImmutableSet.copyOf(server.getAllServers());
|
||||
Collection<RegisteredServer> allServers = ImmutableSet.copyOf(server.registeredServers());
|
||||
JsonObject servers = new JsonObject();
|
||||
for (RegisteredServer iter : allServers) {
|
||||
servers.add(iter.getServerInfo().getName(),
|
||||
servers.add(iter.serverInfo().name(),
|
||||
InformationUtils.collectServerInfo(iter));
|
||||
}
|
||||
JsonArray connectOrder = new JsonArray();
|
||||
List<String> attemptedConnectionOrder = ImmutableList.copyOf(
|
||||
server.getConfiguration().getAttemptConnectionOrder());
|
||||
server.configuration().getAttemptConnectionOrder());
|
||||
for (int i = 0; i < attemptedConnectionOrder.size(); i++) {
|
||||
connectOrder.add(attemptedConnectionOrder.get(i));
|
||||
}
|
||||
|
||||
JsonObject proxyConfig = InformationUtils.collectProxyConfig(server.getConfiguration());
|
||||
JsonObject proxyConfig = InformationUtils.collectProxyConfig(server.configuration());
|
||||
proxyConfig.add("servers", servers);
|
||||
proxyConfig.add("connectOrder", connectOrder);
|
||||
proxyConfig.add("forcedHosts",
|
||||
InformationUtils.collectForcedHosts(server.getConfiguration()));
|
||||
InformationUtils.collectForcedHosts(server.configuration()));
|
||||
|
||||
JsonObject dump = new JsonObject();
|
||||
dump.add("versionInfo", InformationUtils.collectProxyInfo(server.getVersion()));
|
||||
dump.add("versionInfo", InformationUtils.collectProxyInfo(server.version()));
|
||||
dump.add("platform", InformationUtils.collectEnvironmentInfo());
|
||||
dump.add("config", proxyConfig);
|
||||
dump.add("plugins", InformationUtils.collectPluginInfo(server));
|
||||
@@ -374,8 +374,8 @@ public class VelocityCommand implements SimpleCommand {
|
||||
BoundRequestBuilder request =
|
||||
httpClient.preparePost("https://dump.velocitypowered.com/documents");
|
||||
request.setHeader("Content-Type", "text/plain");
|
||||
request.addHeader("User-Agent", server.getVersion().getName() + "/"
|
||||
+ server.getVersion().getVersion());
|
||||
request.addHeader("User-Agent", server.version().getName() + "/"
|
||||
+ server.version().getVersion());
|
||||
request.setBody(
|
||||
InformationUtils.toHumanReadableString(dump).getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
@@ -459,7 +459,7 @@ public class VelocityCommand implements SimpleCommand {
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final CommandSource source, final String @NonNull [] args) {
|
||||
return source.getPermissionValue("velocity.command.plugins") == Tristate.TRUE;
|
||||
return source.evaluatePermission("velocity.command.plugins") == Tristate.TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -414,7 +414,7 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
|
||||
decoder.setThreshold(threshold);
|
||||
encoder.setThreshold(threshold);
|
||||
} else {
|
||||
int level = server.getConfiguration().getCompressionLevel();
|
||||
int level = server.configuration().getCompressionLevel();
|
||||
VelocityCompressor compressor = Natives.compress.get().create(level);
|
||||
|
||||
encoder = new MinecraftCompressEncoder(threshold, compressor);
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.mojang.brigadier.tree.RootCommandNode;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.event.command.PlayerAvailableCommandsEventImpl;
|
||||
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||
import com.velocitypowered.api.event.connection.PluginMessageEventImpl;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
@@ -68,7 +69,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
||||
BackendPlaySessionHandler(VelocityServer server, VelocityServerConnection serverConn) {
|
||||
this.server = server;
|
||||
this.serverConn = serverConn;
|
||||
this.playerConnection = serverConn.getPlayer().getConnection();
|
||||
this.playerConnection = serverConn.player().getConnection();
|
||||
|
||||
MinecraftSessionHandler psh = playerConnection.getSessionHandler();
|
||||
if (!(psh instanceof ClientPlaySessionHandler)) {
|
||||
@@ -78,14 +79,14 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
||||
this.playerSessionHandler = (ClientPlaySessionHandler) psh;
|
||||
|
||||
this.bungeecordMessageResponder = new BungeeCordMessageResponder(server,
|
||||
serverConn.getPlayer());
|
||||
serverConn.player());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activated() {
|
||||
serverConn.getServer().addPlayer(serverConn.getPlayer());
|
||||
serverConn.target().addPlayer(serverConn.player());
|
||||
|
||||
if (server.getConfiguration().isBungeePluginChannelEnabled()) {
|
||||
if (server.configuration().isBungeePluginChannelEnabled()) {
|
||||
MinecraftConnection serverMc = serverConn.ensureConnected();
|
||||
serverMc.write(PluginMessageUtil.constructChannelsPacket(serverMc.getProtocolVersion(),
|
||||
ImmutableList.of(getBungeeCordChannel(serverMc.getProtocolVersion())),
|
||||
@@ -112,7 +113,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
||||
@Override
|
||||
public boolean handle(ClientboundDisconnectPacket packet) {
|
||||
serverConn.disconnect();
|
||||
serverConn.getPlayer().handleConnectionException(serverConn.getServer(), packet, true);
|
||||
serverConn.player().handleConnectionException(serverConn.target(), packet, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -132,7 +133,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!serverConn.getPlayer().canForwardPluginMessage(serverConn.ensureConnected()
|
||||
if (!serverConn.player().canForwardPluginMessage(serverConn.ensureConnected()
|
||||
.getProtocolVersion(), packet)) {
|
||||
return true;
|
||||
}
|
||||
@@ -140,36 +141,36 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
||||
// We need to specially handle REGISTER and UNREGISTER packets. Later on, we'll write them to
|
||||
// the client.
|
||||
if (PluginMessageUtil.isRegister(packet)) {
|
||||
serverConn.getPlayer().getKnownChannels().addAll(PluginMessageUtil.getChannels(packet));
|
||||
serverConn.player().getKnownChannels().addAll(PluginMessageUtil.getChannels(packet));
|
||||
return false;
|
||||
} else if (PluginMessageUtil.isUnregister(packet)) {
|
||||
serverConn.getPlayer().getKnownChannels().removeAll(PluginMessageUtil.getChannels(packet));
|
||||
serverConn.player().getKnownChannels().removeAll(PluginMessageUtil.getChannels(packet));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (PluginMessageUtil.isMcBrand(packet)) {
|
||||
AbstractPluginMessagePacket<?> rewritten = PluginMessageUtil.rewriteMinecraftBrand(packet,
|
||||
server.getVersion(), playerConnection.getProtocolVersion(), ClientboundPluginMessagePacket.FACTORY);
|
||||
server.version(), playerConnection.getProtocolVersion(), ClientboundPluginMessagePacket.FACTORY);
|
||||
playerConnection.write(rewritten);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (serverConn.getPhase().handle(serverConn, serverConn.getPlayer(), packet)) {
|
||||
if (serverConn.getPhase().handle(serverConn, serverConn.player(), packet)) {
|
||||
// Handled.
|
||||
return true;
|
||||
}
|
||||
|
||||
ChannelIdentifier id = server.getChannelRegistrar().getFromId(packet.getChannel());
|
||||
ChannelIdentifier id = server.channelRegistrar().getFromId(packet.getChannel());
|
||||
if (id == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
byte[] copy = ByteBufUtil.getBytes(packet.content());
|
||||
PluginMessageEvent event = new PluginMessageEvent(serverConn, serverConn.getPlayer(), id,
|
||||
PluginMessageEvent event = new PluginMessageEventImpl(serverConn, serverConn.player(), id,
|
||||
copy);
|
||||
server.getEventManager().fire(event)
|
||||
server.eventManager().fire(event)
|
||||
.thenAcceptAsync(pme -> {
|
||||
if (pme.getResult().isAllowed() && !playerConnection.isClosed()) {
|
||||
if (pme.result().isAllowed() && !playerConnection.isClosed()) {
|
||||
ClientboundPluginMessagePacket copied = new ClientboundPluginMessagePacket(packet.getChannel(),
|
||||
Unpooled.wrappedBuffer(copy));
|
||||
playerConnection.write(copied);
|
||||
@@ -190,18 +191,18 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
||||
|
||||
@Override
|
||||
public boolean handle(ClientboundPlayerListItemPacket packet) {
|
||||
serverConn.getPlayer().getTabList().processBackendPacket(packet);
|
||||
serverConn.player().tabList().processBackendPacket(packet);
|
||||
return false; //Forward packet to player
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(ClientboundAvailableCommandsPacket commands) {
|
||||
RootCommandNode<CommandSource> rootNode = commands.getRootNode();
|
||||
if (server.getConfiguration().isAnnounceProxyCommands()) {
|
||||
if (server.configuration().isAnnounceProxyCommands()) {
|
||||
// Inject commands from the proxy.
|
||||
RootCommandNode<CommandSource> dispatcherRootNode =
|
||||
(RootCommandNode<CommandSource>)
|
||||
filterNode(server.getCommandManager().getDispatcher().getRoot());
|
||||
filterNode(server.commandManager().getDispatcher().getRoot());
|
||||
assert dispatcherRootNode != null : "Filtering root node returned null.";
|
||||
Collection<CommandNode<CommandSource>> proxyNodes = dispatcherRootNode.getChildren();
|
||||
for (CommandNode<CommandSource> node : proxyNodes) {
|
||||
@@ -213,8 +214,8 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
server.getEventManager().fire(
|
||||
new PlayerAvailableCommandsEventImpl(serverConn.getPlayer(), rootNode))
|
||||
server.eventManager().fire(
|
||||
new PlayerAvailableCommandsEventImpl(serverConn.player(), rootNode))
|
||||
.thenAcceptAsync(event -> playerConnection.write(commands), playerConnection.eventLoop())
|
||||
.exceptionally((ex) -> {
|
||||
logger.error("Exception while handling available commands for {}", playerConnection, ex);
|
||||
@@ -237,7 +238,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
||||
} else {
|
||||
if (source.getRequirement() != null) {
|
||||
try {
|
||||
if (!source.getRequirement().test(serverConn.getPlayer())) {
|
||||
if (!source.getRequirement().test(serverConn.player())) {
|
||||
return null;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
@@ -288,7 +289,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
||||
@Override
|
||||
public void exception(Throwable throwable) {
|
||||
exceptionTriggered = true;
|
||||
serverConn.getPlayer().handleConnectionException(serverConn.getServer(), throwable,
|
||||
serverConn.player().handleConnectionException(serverConn.target(), throwable,
|
||||
!(throwable instanceof ReadTimeoutException));
|
||||
}
|
||||
|
||||
@@ -298,14 +299,14 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
||||
|
||||
@Override
|
||||
public void disconnected() {
|
||||
serverConn.getServer().removePlayer(serverConn.getPlayer());
|
||||
serverConn.target().removePlayer(serverConn.player());
|
||||
if (!serverConn.isGracefulDisconnect() && !exceptionTriggered) {
|
||||
if (server.getConfiguration().isFailoverOnUnexpectedServerDisconnect()) {
|
||||
serverConn.getPlayer().handleConnectionException(serverConn.getServer(),
|
||||
if (server.configuration().isFailoverOnUnexpectedServerDisconnect()) {
|
||||
serverConn.player().handleConnectionException(serverConn.target(),
|
||||
ClientboundDisconnectPacket.create(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR,
|
||||
ProtocolVersion.MINECRAFT_1_16), true);
|
||||
} else {
|
||||
serverConn.getPlayer().disconnect(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR);
|
||||
serverConn.player().disconnect(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,13 +64,13 @@ public class BungeeCordMessageResponder {
|
||||
}
|
||||
|
||||
public static boolean isBungeeCordMessage(AbstractPluginMessagePacket<?> message) {
|
||||
return MODERN_CHANNEL.getId().equals(message.getChannel()) || LEGACY_CHANNEL.getId()
|
||||
return MODERN_CHANNEL.id().equals(message.getChannel()) || LEGACY_CHANNEL.id()
|
||||
.equals(message.getChannel());
|
||||
}
|
||||
|
||||
private void processConnect(ByteBufDataInput in) {
|
||||
String serverName = in.readUTF();
|
||||
proxy.getServer(serverName).ifPresent(server -> player.createConnectionRequest(server)
|
||||
proxy.server(serverName).ifPresent(server -> player.createConnectionRequest(server)
|
||||
.fireAndForget());
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public class BungeeCordMessageResponder {
|
||||
String serverName = in.readUTF();
|
||||
|
||||
Optional<Player> referencedPlayer = proxy.getPlayer(playerName);
|
||||
Optional<RegisteredServer> referencedServer = proxy.getServer(serverName);
|
||||
Optional<RegisteredServer> referencedServer = proxy.server(serverName);
|
||||
if (referencedPlayer.isPresent() && referencedServer.isPresent()) {
|
||||
referencedPlayer.get().createConnectionRequest(referencedServer.get()).fireAndForget();
|
||||
}
|
||||
@@ -90,7 +90,7 @@ public class BungeeCordMessageResponder {
|
||||
ByteBufDataOutput out = new ByteBufDataOutput(buf);
|
||||
out.writeUTF("IP");
|
||||
|
||||
SocketAddress address = player.getRemoteAddress();
|
||||
SocketAddress address = player.remoteAddress();
|
||||
if (address instanceof InetSocketAddress) {
|
||||
InetSocketAddress serverInetAddr = (InetSocketAddress) address;
|
||||
out.writeUTF(serverInetAddr.getHostString());
|
||||
@@ -110,12 +110,12 @@ public class BungeeCordMessageResponder {
|
||||
if (target.equals("ALL")) {
|
||||
out.writeUTF("PlayerCount");
|
||||
out.writeUTF("ALL");
|
||||
out.writeInt(proxy.getPlayerCount());
|
||||
out.writeInt(proxy.countConnectedPlayers());
|
||||
} else {
|
||||
proxy.getServer(target).ifPresent(rs -> {
|
||||
int playersOnServer = rs.getPlayersConnected().size();
|
||||
proxy.server(target).ifPresent(rs -> {
|
||||
int playersOnServer = rs.connectedPlayers().size();
|
||||
out.writeUTF("PlayerCount");
|
||||
out.writeUTF(rs.getServerInfo().getName());
|
||||
out.writeUTF(rs.serverInfo().name());
|
||||
out.writeInt(playersOnServer);
|
||||
});
|
||||
}
|
||||
@@ -137,18 +137,18 @@ public class BungeeCordMessageResponder {
|
||||
out.writeUTF("ALL");
|
||||
|
||||
StringJoiner joiner = new StringJoiner(", ");
|
||||
for (Player online : proxy.getAllPlayers()) {
|
||||
joiner.add(online.getUsername());
|
||||
for (Player online : proxy.connectedPlayers()) {
|
||||
joiner.add(online.username());
|
||||
}
|
||||
out.writeUTF(joiner.toString());
|
||||
} else {
|
||||
proxy.getServer(target).ifPresent(info -> {
|
||||
proxy.server(target).ifPresent(info -> {
|
||||
out.writeUTF("PlayerList");
|
||||
out.writeUTF(info.getServerInfo().getName());
|
||||
out.writeUTF(info.serverInfo().name());
|
||||
|
||||
StringJoiner joiner = new StringJoiner(", ");
|
||||
for (Player online : info.getPlayersConnected()) {
|
||||
joiner.add(online.getUsername());
|
||||
for (Player online : info.connectedPlayers()) {
|
||||
joiner.add(online.username());
|
||||
}
|
||||
out.writeUTF(joiner.toString());
|
||||
});
|
||||
@@ -163,8 +163,8 @@ public class BungeeCordMessageResponder {
|
||||
|
||||
private void processGetServers() {
|
||||
StringJoiner joiner = new StringJoiner(", ");
|
||||
for (RegisteredServer server : proxy.getAllServers()) {
|
||||
joiner.add(server.getServerInfo().getName());
|
||||
for (RegisteredServer server : proxy.registeredServers()) {
|
||||
joiner.add(server.serverInfo().name());
|
||||
}
|
||||
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
@@ -202,7 +202,7 @@ public class BungeeCordMessageResponder {
|
||||
ByteBufDataOutput out = new ByteBufDataOutput(buf);
|
||||
|
||||
out.writeUTF("GetServer");
|
||||
out.writeUTF(player.ensureAndGetCurrentServer().getServerInfo().getName());
|
||||
out.writeUTF(player.ensureAndGetCurrentServer().serverInfo().name());
|
||||
|
||||
sendResponseOnConnection(buf);
|
||||
}
|
||||
@@ -212,7 +212,7 @@ public class BungeeCordMessageResponder {
|
||||
ByteBufDataOutput out = new ByteBufDataOutput(buf);
|
||||
|
||||
out.writeUTF("UUID");
|
||||
out.writeUTF(UuidUtils.toUndashed(player.getUniqueId()));
|
||||
out.writeUTF(UuidUtils.toUndashed(player.id()));
|
||||
|
||||
sendResponseOnConnection(buf);
|
||||
}
|
||||
@@ -223,8 +223,8 @@ public class BungeeCordMessageResponder {
|
||||
ByteBufDataOutput out = new ByteBufDataOutput(buf);
|
||||
|
||||
out.writeUTF("UUIDOther");
|
||||
out.writeUTF(player.getUsername());
|
||||
out.writeUTF(UuidUtils.toUndashed(player.getUniqueId()));
|
||||
out.writeUTF(player.username());
|
||||
out.writeUTF(UuidUtils.toUndashed(player.id()));
|
||||
|
||||
sendResponseOnConnection(buf);
|
||||
});
|
||||
@@ -236,8 +236,8 @@ public class BungeeCordMessageResponder {
|
||||
ByteBufDataOutput out = new ByteBufDataOutput(buf);
|
||||
|
||||
out.writeUTF("IPOther");
|
||||
out.writeUTF(player.getUsername());
|
||||
SocketAddress address = player.getRemoteAddress();
|
||||
out.writeUTF(player.username());
|
||||
SocketAddress address = player.remoteAddress();
|
||||
if (address instanceof InetSocketAddress) {
|
||||
InetSocketAddress serverInetAddr = (InetSocketAddress) address;
|
||||
out.writeUTF(serverInetAddr.getHostString());
|
||||
@@ -252,13 +252,13 @@ public class BungeeCordMessageResponder {
|
||||
}
|
||||
|
||||
private void processServerIp(ByteBufDataInput in) {
|
||||
proxy.getServer(in.readUTF()).ifPresent(info -> {
|
||||
proxy.server(in.readUTF()).ifPresent(info -> {
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
ByteBufDataOutput out = new ByteBufDataOutput(buf);
|
||||
|
||||
out.writeUTF("ServerIP");
|
||||
out.writeUTF(info.getServerInfo().getName());
|
||||
SocketAddress address = info.getServerInfo().getAddress();
|
||||
out.writeUTF(info.serverInfo().name());
|
||||
SocketAddress address = info.serverInfo().address();
|
||||
if (address instanceof InetSocketAddress) {
|
||||
InetSocketAddress serverInetAddr = (InetSocketAddress) address;
|
||||
out.writeUTF(serverInetAddr.getHostString());
|
||||
@@ -292,7 +292,7 @@ public class BungeeCordMessageResponder {
|
||||
ByteBuf toForward = in.unwrap().copy();
|
||||
if (target.equals("ALL")) {
|
||||
try {
|
||||
for (RegisteredServer rs : proxy.getAllServers()) {
|
||||
for (RegisteredServer rs : proxy.registeredServers()) {
|
||||
((VelocityRegisteredServer) rs).sendPluginMessage(LEGACY_CHANNEL,
|
||||
toForward.retainedSlice());
|
||||
}
|
||||
@@ -300,7 +300,7 @@ public class BungeeCordMessageResponder {
|
||||
toForward.release();
|
||||
}
|
||||
} else {
|
||||
Optional<RegisteredServer> server = proxy.getServer(target);
|
||||
Optional<RegisteredServer> server = proxy.server(target);
|
||||
if (server.isPresent()) {
|
||||
((VelocityRegisteredServer) server.get()).sendPluginMessage(LEGACY_CHANNEL, toForward);
|
||||
} else {
|
||||
@@ -310,8 +310,8 @@ public class BungeeCordMessageResponder {
|
||||
}
|
||||
|
||||
static String getBungeeCordChannel(ProtocolVersion version) {
|
||||
return version.gte(ProtocolVersion.MINECRAFT_1_13) ? MODERN_CHANNEL.getId()
|
||||
: LEGACY_CHANNEL.getId();
|
||||
return version.gte(ProtocolVersion.MINECRAFT_1_13) ? MODERN_CHANNEL.id()
|
||||
: LEGACY_CHANNEL.id();
|
||||
}
|
||||
|
||||
// Note: this method will always release the buffer!
|
||||
@@ -328,7 +328,7 @@ public class BungeeCordMessageResponder {
|
||||
}
|
||||
|
||||
boolean process(AbstractPluginMessagePacket<?> message) {
|
||||
if (!proxy.getConfiguration().isBungeePluginChannelEnabled()) {
|
||||
if (!proxy.configuration().isBungeePluginChannelEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,12 +73,12 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
@Override
|
||||
public boolean handle(ClientboundLoginPluginMessagePacket packet) {
|
||||
MinecraftConnection mc = serverConn.ensureConnected();
|
||||
VelocityConfiguration configuration = server.getConfiguration();
|
||||
VelocityConfiguration configuration = server.configuration();
|
||||
if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN && packet
|
||||
.getChannel().equals(VelocityConstants.VELOCITY_IP_FORWARDING_CHANNEL)) {
|
||||
ByteBuf forwardingData = createForwardingData(configuration.getForwardingSecret(),
|
||||
cleanRemoteAddress(serverConn.getPlayer().getRemoteAddress()),
|
||||
serverConn.getPlayer().getGameProfile());
|
||||
cleanRemoteAddress(serverConn.player().remoteAddress()),
|
||||
serverConn.player().gameProfile());
|
||||
ServerboundLoginPluginResponsePacket response = new ServerboundLoginPluginResponsePacket(
|
||||
packet.getId(), true, forwardingData);
|
||||
mc.write(response);
|
||||
@@ -93,7 +93,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
|
||||
@Override
|
||||
public boolean handle(ClientboundDisconnectPacket packet) {
|
||||
resultFuture.complete(ConnectionRequestResults.forDisconnect(packet, serverConn.getServer()));
|
||||
resultFuture.complete(ConnectionRequestResults.forDisconnect(packet, serverConn.target()));
|
||||
serverConn.disconnect();
|
||||
return true;
|
||||
}
|
||||
@@ -106,10 +106,10 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
|
||||
@Override
|
||||
public boolean handle(ClientboundServerLoginSuccessPacket packet) {
|
||||
if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN
|
||||
if (server.configuration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN
|
||||
&& !informationForwarded) {
|
||||
resultFuture.complete(ConnectionRequestResults.forDisconnect(MODERN_IP_FORWARDING_FAILURE,
|
||||
serverConn.getServer()));
|
||||
serverConn.target()));
|
||||
serverConn.disconnect();
|
||||
return true;
|
||||
}
|
||||
@@ -133,7 +133,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
|
||||
@Override
|
||||
public void disconnected() {
|
||||
if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.LEGACY) {
|
||||
if (server.configuration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.LEGACY) {
|
||||
resultFuture.completeExceptionally(
|
||||
new QuietRuntimeException("The connection to the remote server was unexpectedly closed.\n"
|
||||
+ "This is usually because the remote server does not have BungeeCord IP forwarding "
|
||||
|
||||
@@ -85,9 +85,9 @@ public class TransitionSessionHandler implements MinecraftSessionHandler {
|
||||
@Override
|
||||
public boolean handle(ClientboundJoinGamePacket packet) {
|
||||
MinecraftConnection smc = serverConn.ensureConnected();
|
||||
VelocityServerConnection existingConnection = serverConn.getPlayer().getConnectedServer();
|
||||
VelocityServerConnection existingConnection = serverConn.player().getConnectedServer();
|
||||
|
||||
final ConnectedPlayer player = serverConn.getPlayer();
|
||||
final ConnectedPlayer player = serverConn.player();
|
||||
|
||||
if (existingConnection != null) {
|
||||
// Shut down the existing server connection.
|
||||
@@ -100,9 +100,9 @@ public class TransitionSessionHandler implements MinecraftSessionHandler {
|
||||
|
||||
// The goods are in hand! We got JoinGame. Let's transition completely to the new state.
|
||||
smc.setAutoReading(false);
|
||||
server.getEventManager()
|
||||
.fire(new ServerConnectedEventImpl(player, serverConn.getServer(),
|
||||
existingConnection != null ? existingConnection.getServer() : null))
|
||||
server.eventManager()
|
||||
.fire(new ServerConnectedEventImpl(player, serverConn.target(),
|
||||
existingConnection != null ? existingConnection.target() : null))
|
||||
.thenRunAsync(() -> {
|
||||
// Make sure we can still transition (player might have disconnected here).
|
||||
if (!serverConn.isActive()) {
|
||||
@@ -129,17 +129,17 @@ public class TransitionSessionHandler implements MinecraftSessionHandler {
|
||||
smc.setAutoReading(true);
|
||||
|
||||
// Now set the connected server.
|
||||
serverConn.getPlayer().setConnectedServer(serverConn);
|
||||
serverConn.player().setConnectedServer(serverConn);
|
||||
|
||||
// We're done! :)
|
||||
server.getEventManager().fireAndForget(new ServerPostConnectEventImpl(player,
|
||||
existingConnection == null ? null : existingConnection.getServer()));
|
||||
resultFuture.complete(ConnectionRequestResults.successful(serverConn.getServer()));
|
||||
server.eventManager().fireAndForget(new ServerPostConnectEventImpl(player,
|
||||
existingConnection == null ? null : existingConnection.target()));
|
||||
resultFuture.complete(ConnectionRequestResults.successful(serverConn.target()));
|
||||
}, smc.eventLoop())
|
||||
.exceptionally(exc -> {
|
||||
logger.error("Unable to switch to new server {} for {}",
|
||||
serverConn.getServerInfo().getName(),
|
||||
player.getUsername(), exc);
|
||||
serverConn.serverInfo().name(),
|
||||
player.username(), exc);
|
||||
player.disconnect(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR);
|
||||
resultFuture.completeExceptionally(exc);
|
||||
return null;
|
||||
@@ -158,9 +158,9 @@ public class TransitionSessionHandler implements MinecraftSessionHandler {
|
||||
if (connection.getType() == ConnectionTypes.LEGACY_FORGE
|
||||
&& !serverConn.getPhase().consideredComplete()) {
|
||||
resultFuture.complete(ConnectionRequestResults.forUnsafeDisconnect(packet,
|
||||
serverConn.getServer()));
|
||||
serverConn.target()));
|
||||
} else {
|
||||
resultFuture.complete(ConnectionRequestResults.forDisconnect(packet, serverConn.getServer()));
|
||||
resultFuture.complete(ConnectionRequestResults.forDisconnect(packet, serverConn.target()));
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -168,35 +168,35 @@ public class TransitionSessionHandler implements MinecraftSessionHandler {
|
||||
|
||||
@Override
|
||||
public boolean handle(ClientboundPluginMessagePacket packet) {
|
||||
if (!serverConn.getPlayer().canForwardPluginMessage(serverConn.ensureConnected()
|
||||
if (!serverConn.player().canForwardPluginMessage(serverConn.ensureConnected()
|
||||
.getProtocolVersion(), packet)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (PluginMessageUtil.isRegister(packet)) {
|
||||
serverConn.getPlayer().getKnownChannels().addAll(PluginMessageUtil.getChannels(packet));
|
||||
serverConn.player().getKnownChannels().addAll(PluginMessageUtil.getChannels(packet));
|
||||
} else if (PluginMessageUtil.isUnregister(packet)) {
|
||||
serverConn.getPlayer().getKnownChannels().removeAll(PluginMessageUtil.getChannels(packet));
|
||||
serverConn.player().getKnownChannels().removeAll(PluginMessageUtil.getChannels(packet));
|
||||
}
|
||||
|
||||
// We always need to handle plugin messages, for Forge compatibility.
|
||||
if (serverConn.getPhase().handle(serverConn, serverConn.getPlayer(), packet)) {
|
||||
if (serverConn.getPhase().handle(serverConn, serverConn.player(), packet)) {
|
||||
// Handled, but check the server connection phase.
|
||||
if (serverConn.getPhase() == HELLO) {
|
||||
VelocityServerConnection existingConnection = serverConn.getPlayer().getConnectedServer();
|
||||
VelocityServerConnection existingConnection = serverConn.player().getConnectedServer();
|
||||
if (existingConnection != null && existingConnection.getPhase() != IN_TRANSITION) {
|
||||
// Indicate that this connection is "in transition"
|
||||
existingConnection.setConnectionPhase(IN_TRANSITION);
|
||||
|
||||
// Tell the player that we're leaving and we just aren't coming back.
|
||||
existingConnection.getPhase().onDepartForNewServer(existingConnection,
|
||||
serverConn.getPlayer());
|
||||
serverConn.player());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
serverConn.getPlayer().getConnection().write(packet.retain());
|
||||
serverConn.player().getConnection().write(packet.retain());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
||||
CompletableFuture<Impl> result = new CompletableFuture<>();
|
||||
// Note: we use the event loop for the connection the player is on. This reduces context
|
||||
// switches.
|
||||
SocketAddress destinationAddress = registeredServer.getServerInfo().getAddress();
|
||||
SocketAddress destinationAddress = registeredServer.serverInfo().address();
|
||||
server.createBootstrap(proxyPlayer.getConnection().eventLoop(), destinationAddress)
|
||||
.handler(server.getBackendChannelInitializer())
|
||||
.connect(destinationAddress)
|
||||
@@ -118,26 +118,26 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
||||
}
|
||||
|
||||
private String getHandshakeRemoteAddress() {
|
||||
return proxyPlayer.getVirtualHost().map(InetSocketAddress::getHostString).orElse("");
|
||||
return proxyPlayer.connectedHost().map(InetSocketAddress::getHostString).orElse("");
|
||||
}
|
||||
|
||||
private String createLegacyForwardingAddress(UnaryOperator<List<Property>> propertiesTransform) {
|
||||
// BungeeCord IP forwarding is simply a special injection after the "address" in the handshake,
|
||||
// separated by \0 (the null byte). In order, you send the original host, the player's IP, their
|
||||
// UUID (undashed), and if you are in online-mode, their login properties (from Mojang).
|
||||
SocketAddress playerRemoteAddress = proxyPlayer.getRemoteAddress();
|
||||
SocketAddress playerRemoteAddress = proxyPlayer.remoteAddress();
|
||||
if (!(playerRemoteAddress instanceof InetSocketAddress)) {
|
||||
return getHandshakeRemoteAddress();
|
||||
}
|
||||
StringBuilder data = new StringBuilder()
|
||||
.append(getHandshakeRemoteAddress())
|
||||
.append('\0')
|
||||
.append(((InetSocketAddress) proxyPlayer.getRemoteAddress()).getHostString())
|
||||
.append(((InetSocketAddress) proxyPlayer.remoteAddress()).getHostString())
|
||||
.append('\0')
|
||||
.append(proxyPlayer.getGameProfile().getUndashedId())
|
||||
.append(proxyPlayer.gameProfile().getUndashedId())
|
||||
.append('\0');
|
||||
GENERAL_GSON
|
||||
.toJson(propertiesTransform.apply(proxyPlayer.getGameProfile().getProperties()), data);
|
||||
.toJson(propertiesTransform.apply(proxyPlayer.gameProfile().getProperties()), data);
|
||||
return data.toString();
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
||||
|
||||
private void startHandshake() {
|
||||
final MinecraftConnection mc = ensureConnected();
|
||||
PlayerInfoForwarding forwardingMode = server.getConfiguration().getPlayerInfoForwardingMode();
|
||||
PlayerInfoForwarding forwardingMode = server.configuration().getPlayerInfoForwardingMode();
|
||||
|
||||
// Initiate the handshake.
|
||||
ProtocolVersion protocolVersion = proxyPlayer.getConnection().getProtocolVersion();
|
||||
@@ -167,7 +167,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
||||
if (forwardingMode == PlayerInfoForwarding.LEGACY) {
|
||||
handshake.setServerAddress(createLegacyForwardingAddress());
|
||||
} else if (forwardingMode == PlayerInfoForwarding.BUNGEEGUARD) {
|
||||
byte[] secret = server.getConfiguration().getForwardingSecret();
|
||||
byte[] secret = server.configuration().getForwardingSecret();
|
||||
handshake.setServerAddress(createBungeeGuardForwardingAddress(secret));
|
||||
} else if (proxyPlayer.getConnection().getType() == ConnectionTypes.LEGACY_FORGE) {
|
||||
handshake.setServerAddress(getHandshakeRemoteAddress() + HANDSHAKE_HOSTNAME_TOKEN);
|
||||
@@ -175,7 +175,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
||||
handshake.setServerAddress(getHandshakeRemoteAddress());
|
||||
}
|
||||
|
||||
SocketAddress destinationAddr = registeredServer.getServerInfo().getAddress();
|
||||
SocketAddress destinationAddr = registeredServer.serverInfo().address();
|
||||
if (destinationAddr instanceof InetSocketAddress) {
|
||||
handshake.setPort(((InetSocketAddress) destinationAddr).getPort());
|
||||
}
|
||||
@@ -183,7 +183,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
||||
|
||||
mc.setProtocolVersion(protocolVersion);
|
||||
mc.setState(StateRegistry.LOGIN);
|
||||
mc.delayedWrite(new ServerboundServerLoginPacket(proxyPlayer.getUsername()));
|
||||
mc.delayedWrite(new ServerboundServerLoginPacket(proxyPlayer.username()));
|
||||
mc.flush();
|
||||
}
|
||||
|
||||
@@ -204,17 +204,17 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
||||
}
|
||||
|
||||
@Override
|
||||
public VelocityRegisteredServer getServer() {
|
||||
public VelocityRegisteredServer target() {
|
||||
return registeredServer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerInfo getServerInfo() {
|
||||
return registeredServer.getServerInfo();
|
||||
public ServerInfo serverInfo() {
|
||||
return registeredServer.serverInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConnectedPlayer getPlayer() {
|
||||
public ConnectedPlayer player() {
|
||||
return proxyPlayer;
|
||||
}
|
||||
|
||||
@@ -231,8 +231,8 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[server connection] " + proxyPlayer.getGameProfile().getName() + " -> "
|
||||
+ registeredServer.getServerInfo().getName();
|
||||
return "[server connection] " + proxyPlayer.gameProfile().getName() + " -> "
|
||||
+ registeredServer.serverInfo().name();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -252,7 +252,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
||||
|
||||
MinecraftConnection mc = ensureConnected();
|
||||
|
||||
ServerboundPluginMessagePacket message = new ServerboundPluginMessagePacket(identifier.getId(), data);
|
||||
ServerboundPluginMessagePacket message = new ServerboundPluginMessagePacket(identifier.id(), data);
|
||||
mc.write(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import static com.velocitypowered.proxy.network.PluginMessageUtil.constructChann
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.velocitypowered.api.event.command.CommandExecuteEvent.CommandResult;
|
||||
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||
import com.velocitypowered.api.event.connection.PluginMessageEventImpl;
|
||||
import com.velocitypowered.api.event.player.PlayerChannelRegisterEventImpl;
|
||||
import com.velocitypowered.api.event.player.PlayerChatEvent;
|
||||
import com.velocitypowered.api.event.player.PlayerChatEventImpl;
|
||||
@@ -104,10 +105,10 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
|
||||
@Override
|
||||
public void activated() {
|
||||
Collection<String> channels = server.getChannelRegistrar().getChannelsForProtocol(player
|
||||
.getProtocolVersion());
|
||||
Collection<String> channels = server.channelRegistrar().getChannelsForProtocol(player
|
||||
.protocolVersion());
|
||||
if (!channels.isEmpty()) {
|
||||
AbstractPluginMessagePacket<?> register = constructChannelsPacket(player.getProtocolVersion(),
|
||||
AbstractPluginMessagePacket<?> register = constructChannelsPacket(player.protocolVersion(),
|
||||
channels, ClientboundPluginMessagePacket.FACTORY);
|
||||
player.getConnection().write(register);
|
||||
player.getKnownChannels().addAll(channels);
|
||||
@@ -157,17 +158,17 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
String msg = packet.getMessage();
|
||||
if (msg.startsWith("/")) {
|
||||
String originalCommand = msg.substring(1);
|
||||
server.getCommandManager().callCommandEvent(player, msg.substring(1))
|
||||
server.commandManager().callCommandEvent(player, msg.substring(1))
|
||||
.thenComposeAsync(event -> processCommandExecuteResult(originalCommand,
|
||||
event.getResult()))
|
||||
event.result()))
|
||||
.whenComplete((ignored, throwable) -> {
|
||||
if (server.getConfiguration().isLogCommandExecutions()) {
|
||||
if (server.configuration().isLogCommandExecutions()) {
|
||||
logger.info("{} -> executed command /{}", player, originalCommand);
|
||||
}
|
||||
})
|
||||
.exceptionally(e -> {
|
||||
logger.info("Exception occurred while running command for {}",
|
||||
player.getUsername(), e);
|
||||
player.username(), e);
|
||||
player.sendMessage(Identity.nil(),
|
||||
Component.text("An error occurred while running this command.",
|
||||
NamedTextColor.RED));
|
||||
@@ -175,11 +176,11 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
});
|
||||
} else {
|
||||
PlayerChatEvent event = new PlayerChatEventImpl(player, msg);
|
||||
server.getEventManager().fire(event)
|
||||
server.eventManager().fire(event)
|
||||
.thenAcceptAsync(pme -> {
|
||||
PlayerChatEventImpl.ChatResult chatResult = pme.getResult();
|
||||
PlayerChatEventImpl.ChatResult chatResult = pme.result();
|
||||
if (chatResult.isAllowed()) {
|
||||
Optional<String> eventMsg = pme.getResult().getMessage();
|
||||
Optional<String> eventMsg = pme.result().modifiedMessage();
|
||||
if (eventMsg.isPresent()) {
|
||||
smc.write(new ServerboundChatPacket(eventMsg.get()));
|
||||
} else {
|
||||
@@ -225,7 +226,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
channelIdentifiers.add(new LegacyChannelIdentifier(channel));
|
||||
}
|
||||
}
|
||||
server.getEventManager().fireAndForget(new PlayerChannelRegisterEventImpl(player,
|
||||
server.eventManager().fireAndForget(new PlayerChannelRegisterEventImpl(player,
|
||||
ImmutableList.copyOf(channelIdentifiers)));
|
||||
backendConn.write(packet.retain());
|
||||
} else if (PluginMessageUtil.isUnregister(packet)) {
|
||||
@@ -233,7 +234,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
backendConn.write(packet.retain());
|
||||
} else if (PluginMessageUtil.isMcBrand(packet)) {
|
||||
backendConn.write(PluginMessageUtil
|
||||
.rewriteMinecraftBrand(packet, server.getVersion(), player.getProtocolVersion(), ServerboundPluginMessagePacket.FACTORY));
|
||||
.rewriteMinecraftBrand(packet, server.version(), player.protocolVersion(), ServerboundPluginMessagePacket.FACTORY));
|
||||
} else if (BungeeCordMessageResponder.isBungeeCordMessage(packet)) {
|
||||
return true;
|
||||
} else {
|
||||
@@ -258,14 +259,14 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
// appropriately.
|
||||
loginPluginMessages.add(packet.retain());
|
||||
} else {
|
||||
ChannelIdentifier id = server.getChannelRegistrar().getFromId(packet.getChannel());
|
||||
ChannelIdentifier id = server.channelRegistrar().getFromId(packet.getChannel());
|
||||
if (id == null) {
|
||||
backendConn.write(packet.retain());
|
||||
} else {
|
||||
byte[] copy = ByteBufUtil.getBytes(packet.content());
|
||||
PluginMessageEvent event = new PluginMessageEvent(player, serverConn, id, copy);
|
||||
server.getEventManager().fire(event).thenAcceptAsync(pme -> {
|
||||
if (pme.getResult().isAllowed()) {
|
||||
PluginMessageEvent event = new PluginMessageEventImpl(player, serverConn, id, copy);
|
||||
server.eventManager().fire(event).thenAcceptAsync(pme -> {
|
||||
if (pme.result().isAllowed()) {
|
||||
ServerboundPluginMessagePacket message = new ServerboundPluginMessagePacket(packet.getChannel(),
|
||||
Unpooled.wrappedBuffer(copy));
|
||||
backendConn.write(message);
|
||||
@@ -287,7 +288,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
|
||||
@Override
|
||||
public boolean handle(ServerboundResourcePackResponsePacket packet) {
|
||||
server.getEventManager().fireAndForget(new PlayerResourcePackStatusEventImpl(player,
|
||||
server.eventManager().fireAndForget(new PlayerResourcePackStatusEventImpl(player,
|
||||
packet.getStatus()));
|
||||
return false;
|
||||
}
|
||||
@@ -330,7 +331,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
|
||||
@Override
|
||||
public void exception(Throwable throwable) {
|
||||
player.disconnect(server.getConfiguration().getMessages().getGenericConnectionError());
|
||||
player.disconnect(server.configuration().getMessages().getGenericConnectionError());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -371,7 +372,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
player.getPhase().onFirstJoin(player);
|
||||
} else {
|
||||
// Clear tab list to avoid duplicate entries
|
||||
player.getTabList().clearAll();
|
||||
player.tabList().clearAll();
|
||||
if (player.getConnection().getType() == ConnectionTypes.LEGACY_FORGE) {
|
||||
this.doSafeClientServerSwitch(joinGame);
|
||||
} else {
|
||||
@@ -403,9 +404,9 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
}
|
||||
|
||||
// Clear any title from the previous server.
|
||||
if (player.getProtocolVersion().gte(MINECRAFT_1_8)) {
|
||||
if (player.protocolVersion().gte(MINECRAFT_1_8)) {
|
||||
player.getConnection()
|
||||
.delayedWrite(ClientboundTitlePacket.reset(player.getProtocolVersion()));
|
||||
.delayedWrite(ClientboundTitlePacket.reset(player.protocolVersion()));
|
||||
}
|
||||
|
||||
// Flush everything
|
||||
@@ -424,7 +425,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
// to perform entity ID rewrites, eliminating potential issues from rewriting packets and
|
||||
// improving compatibility with mods.
|
||||
int sentOldDim = joinGame.getDimension();
|
||||
if (player.getProtocolVersion().lt(MINECRAFT_1_16)) {
|
||||
if (player.protocolVersion().lt(MINECRAFT_1_16)) {
|
||||
// Before Minecraft 1.16, we could not switch to the same dimension without sending an
|
||||
// additional respawn. On older versions of Minecraft this forces the client to perform
|
||||
// garbage collection which adds additional latency.
|
||||
@@ -476,8 +477,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
}
|
||||
|
||||
String commandLabel = command.substring(0, commandEndPosition);
|
||||
if (!server.getCommandManager().hasCommand(commandLabel)) {
|
||||
if (player.getProtocolVersion().lt(MINECRAFT_1_13)) {
|
||||
if (!server.commandManager().hasCommand(commandLabel)) {
|
||||
if (player.protocolVersion().lt(MINECRAFT_1_13)) {
|
||||
// Outstanding tab completes are recorded for use with 1.12 clients and below to provide
|
||||
// additional tab completion support.
|
||||
outstandingTabComplete = packet;
|
||||
@@ -485,7 +486,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
server.getCommandManager().offerSuggestions(player, command)
|
||||
server.commandManager().offerSuggestions(player, command)
|
||||
.thenAcceptAsync(suggestions -> {
|
||||
if (suggestions.isEmpty()) {
|
||||
return;
|
||||
@@ -514,7 +515,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
}
|
||||
|
||||
private boolean handleRegularTabComplete(ServerboundTabCompleteRequestPacket packet) {
|
||||
if (player.getProtocolVersion().lt(MINECRAFT_1_13)) {
|
||||
if (player.protocolVersion().lt(MINECRAFT_1_13)) {
|
||||
// Outstanding tab completes are recorded for use with 1.12 clients and below to provide
|
||||
// additional tab completion support.
|
||||
outstandingTabComplete = packet;
|
||||
@@ -544,9 +545,9 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
private void finishCommandTabComplete(ServerboundTabCompleteRequestPacket request,
|
||||
ClientboundTabCompleteResponsePacket response) {
|
||||
String command = request.getCommand().substring(1);
|
||||
server.getCommandManager().offerSuggestions(player, command)
|
||||
server.commandManager().offerSuggestions(player, command)
|
||||
.thenAcceptAsync(offers -> {
|
||||
boolean legacy = player.getProtocolVersion().lt(MINECRAFT_1_13);
|
||||
boolean legacy = player.protocolVersion().lt(MINECRAFT_1_13);
|
||||
try {
|
||||
for (String offer : offers) {
|
||||
offer = legacy && !offer.startsWith("/") ? "/" + offer : offer;
|
||||
@@ -559,7 +560,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
player.getConnection().write(response);
|
||||
} catch (Exception e) {
|
||||
logger.error("Unable to provide tab list completions for {} for command '{}'",
|
||||
player.getUsername(),
|
||||
player.username(),
|
||||
command, e);
|
||||
}
|
||||
}, player.getConnection().eventLoop())
|
||||
@@ -577,10 +578,10 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
for (Offer offer : response.getOffers()) {
|
||||
offers.add(offer.getText());
|
||||
}
|
||||
server.getEventManager().fire(new TabCompleteEventImpl(player, request.getCommand(), offers))
|
||||
server.eventManager().fire(new TabCompleteEventImpl(player, request.getCommand(), offers))
|
||||
.thenAcceptAsync(e -> {
|
||||
response.getOffers().clear();
|
||||
for (String s : e.getSuggestions()) {
|
||||
for (String s : e.suggestions()) {
|
||||
response.getOffers().add(new Offer(s));
|
||||
}
|
||||
player.getConnection().write(response);
|
||||
@@ -600,12 +601,12 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
}
|
||||
|
||||
MinecraftConnection smc = player.ensureAndGetCurrentServer().ensureConnected();
|
||||
String commandToRun = result.getCommand().orElse(originalCommand);
|
||||
String commandToRun = result.modifiedCommand().orElse(originalCommand);
|
||||
if (result.isForwardToServer()) {
|
||||
return CompletableFuture.runAsync(() -> smc.write(new ServerboundChatPacket("/"
|
||||
+ commandToRun)), smc.eventLoop());
|
||||
} else {
|
||||
return server.getCommandManager().executeImmediately(player, commandToRun)
|
||||
return server.commandManager().executeImmediately(player, commandToRun)
|
||||
.thenAcceptAsync(hasRun -> {
|
||||
if (!hasRun) {
|
||||
smc.write(new ServerboundChatPacket("/" + commandToRun));
|
||||
|
||||
@@ -17,15 +17,15 @@
|
||||
|
||||
package com.velocitypowered.proxy.connection.client;
|
||||
|
||||
import com.velocitypowered.api.proxy.player.PlayerSettings;
|
||||
import com.velocitypowered.api.proxy.player.ClientSettings;
|
||||
import com.velocitypowered.api.proxy.player.SkinParts;
|
||||
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundClientSettingsPacket;
|
||||
import java.util.Locale;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class ClientSettingsWrapper implements PlayerSettings {
|
||||
public class ClientSettingsWrapper implements ClientSettings {
|
||||
|
||||
static final PlayerSettings DEFAULT = new ClientSettingsWrapper(
|
||||
static final ClientSettings DEFAULT = new ClientSettingsWrapper(
|
||||
new ServerboundClientSettingsPacket("en_US", (byte) 10, 0, true, (short) 127, 1));
|
||||
|
||||
private final ServerboundClientSettingsPacket settings;
|
||||
|
||||
@@ -32,8 +32,8 @@ import com.velocitypowered.api.event.player.KickedFromServerEvent.Notify;
|
||||
import com.velocitypowered.api.event.player.KickedFromServerEvent.RedirectPlayer;
|
||||
import com.velocitypowered.api.event.player.KickedFromServerEvent.ServerKickResult;
|
||||
import com.velocitypowered.api.event.player.KickedFromServerEventImpl;
|
||||
import com.velocitypowered.api.event.player.PlayerClientSettingsChangedEventImpl;
|
||||
import com.velocitypowered.api.event.player.PlayerModInfoEventImpl;
|
||||
import com.velocitypowered.api.event.player.PlayerSettingsChangedEventImpl;
|
||||
import com.velocitypowered.api.event.player.ServerPreConnectEvent;
|
||||
import com.velocitypowered.api.event.player.ServerPreConnectEventImpl;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
@@ -43,8 +43,8 @@ import com.velocitypowered.api.permission.Tristate;
|
||||
import com.velocitypowered.api.proxy.connection.Player;
|
||||
import com.velocitypowered.api.proxy.connection.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||
import com.velocitypowered.api.proxy.player.ClientSettings;
|
||||
import com.velocitypowered.api.proxy.player.ConnectionRequestBuilder;
|
||||
import com.velocitypowered.api.proxy.player.PlayerSettings;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.api.util.ModInfo;
|
||||
@@ -122,7 +122,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
private final boolean onlineMode;
|
||||
private @Nullable VelocityServerConnection connectedServer;
|
||||
private @Nullable VelocityServerConnection connectionInFlight;
|
||||
private @Nullable PlayerSettings settings;
|
||||
private @Nullable ClientSettings settings;
|
||||
private @Nullable ModInfo modInfo;
|
||||
private Component playerListHeader = Component.empty();
|
||||
private Component playerListFooter = Component.empty();
|
||||
@@ -157,17 +157,17 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
public String username() {
|
||||
return profile.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUniqueId() {
|
||||
public UUID id() {
|
||||
return profile.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ServerConnection> getCurrentServer() {
|
||||
public Optional<ServerConnection> connectedServer() {
|
||||
return Optional.ofNullable(connectedServer);
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameProfile getGameProfile() {
|
||||
public GameProfile gameProfile() {
|
||||
return profile;
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPing() {
|
||||
public long ping() {
|
||||
return this.ping;
|
||||
}
|
||||
|
||||
@@ -202,38 +202,38 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnlineMode() {
|
||||
public boolean onlineMode() {
|
||||
return onlineMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerSettings getPlayerSettings() {
|
||||
public ClientSettings clientSettings() {
|
||||
return settings == null ? ClientSettingsWrapper.DEFAULT : this.settings;
|
||||
}
|
||||
|
||||
void setPlayerSettings(ServerboundClientSettingsPacket settings) {
|
||||
ClientSettingsWrapper cs = new ClientSettingsWrapper(settings);
|
||||
this.settings = cs;
|
||||
server.getEventManager().fireAndForget(new PlayerSettingsChangedEventImpl(this, cs));
|
||||
server.eventManager().fireAndForget(new PlayerClientSettingsChangedEventImpl(this, cs));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ModInfo> getModInfo() {
|
||||
public Optional<ModInfo> modInfo() {
|
||||
return Optional.ofNullable(modInfo);
|
||||
}
|
||||
|
||||
public void setModInfo(ModInfo modInfo) {
|
||||
this.modInfo = modInfo;
|
||||
server.getEventManager().fireAndForget(new PlayerModInfoEventImpl(this, modInfo));
|
||||
server.eventManager().fireAndForget(new PlayerModInfoEventImpl(this, modInfo));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketAddress getRemoteAddress() {
|
||||
public SocketAddress remoteAddress() {
|
||||
return connection.getRemoteAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<InetSocketAddress> getVirtualHost() {
|
||||
public Optional<InetSocketAddress> connectedHost() {
|
||||
return Optional.ofNullable(virtualHost);
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolVersion getProtocolVersion() {
|
||||
public ProtocolVersion protocolVersion() {
|
||||
return connection.getProtocolVersion();
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
Preconditions.checkNotNull(type, "type");
|
||||
|
||||
connection.write(new ClientboundChatPacket(
|
||||
ProtocolUtils.getJsonChatSerializer(this.getProtocolVersion()).serialize(message),
|
||||
ProtocolUtils.getJsonChatSerializer(this.protocolVersion()).serialize(message),
|
||||
type == MessageType.CHAT
|
||||
? ClientboundChatPacket.CHAT_TYPE
|
||||
: ClientboundChatPacket.SYSTEM_TYPE,
|
||||
@@ -268,7 +268,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
|
||||
@Override
|
||||
public void sendActionBar(net.kyori.adventure.text.@NonNull Component message) {
|
||||
ProtocolVersion playerVersion = getProtocolVersion();
|
||||
ProtocolVersion playerVersion = protocolVersion();
|
||||
if (playerVersion.gte(ProtocolVersion.MINECRAFT_1_11)) {
|
||||
// Use the title packet instead.
|
||||
connection.write(new ClientboundTitlePacket(
|
||||
@@ -307,9 +307,9 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
|
||||
@Override
|
||||
public void showTitle(net.kyori.adventure.title.@NonNull Title title) {
|
||||
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
|
||||
if (this.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
|
||||
GsonComponentSerializer serializer = ProtocolUtils.getJsonChatSerializer(this
|
||||
.getProtocolVersion());
|
||||
.protocolVersion());
|
||||
|
||||
connection.delayedWrite(new ClientboundTitlePacket(
|
||||
ClientboundTitlePacket.SET_TITLE,
|
||||
@@ -323,7 +323,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
|
||||
net.kyori.adventure.title.Title.Times times = title.times();
|
||||
if (times != null) {
|
||||
connection.delayedWrite(ClientboundTitlePacket.times(this.getProtocolVersion(), times));
|
||||
connection.delayedWrite(ClientboundTitlePacket.times(this.protocolVersion(), times));
|
||||
}
|
||||
|
||||
connection.flush();
|
||||
@@ -332,28 +332,28 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
|
||||
@Override
|
||||
public void clearTitle() {
|
||||
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
|
||||
connection.write(ClientboundTitlePacket.hide(this.getProtocolVersion()));
|
||||
if (this.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
|
||||
connection.write(ClientboundTitlePacket.hide(this.protocolVersion()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetTitle() {
|
||||
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
|
||||
connection.write(ClientboundTitlePacket.reset(this.getProtocolVersion()));
|
||||
if (this.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
|
||||
connection.write(ClientboundTitlePacket.reset(this.protocolVersion()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideBossBar(@NonNull BossBar bar) {
|
||||
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) {
|
||||
if (this.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) {
|
||||
this.server.getBossBarManager().removeBossBar(this, bar);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showBossBar(@NonNull BossBar bar) {
|
||||
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) {
|
||||
if (this.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) {
|
||||
this.server.getBossBarManager().addBossBar(this, bar);
|
||||
}
|
||||
}
|
||||
@@ -369,7 +369,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
}
|
||||
|
||||
@Override
|
||||
public VelocityTabList getTabList() {
|
||||
public VelocityTabList tabList() {
|
||||
return tabList;
|
||||
}
|
||||
|
||||
@@ -390,7 +390,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
public void disconnect0(Component reason, boolean duringLogin) {
|
||||
logger.info("{} has disconnected: {}", this,
|
||||
LegacyComponentSerializer.legacySection().serialize(reason));
|
||||
connection.closeWith(ClientboundDisconnectPacket.create(reason, this.getProtocolVersion()));
|
||||
connection.closeWith(ClientboundDisconnectPacket.create(reason, this.protocolVersion()));
|
||||
}
|
||||
|
||||
public @Nullable VelocityServerConnection getConnectedServer() {
|
||||
@@ -430,13 +430,13 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
}
|
||||
}
|
||||
String userMessage;
|
||||
if (connectedServer != null && connectedServer.getServerInfo().equals(server.getServerInfo())) {
|
||||
userMessage = "Your connection to " + server.getServerInfo().getName() + " encountered an "
|
||||
if (connectedServer != null && connectedServer.serverInfo().equals(server.serverInfo())) {
|
||||
userMessage = "Your connection to " + server.serverInfo().name() + " encountered an "
|
||||
+ "error.";
|
||||
} else {
|
||||
logger.error("{}: unable to connect to server {}", this, server.getServerInfo().getName(),
|
||||
logger.error("{}: unable to connect to server {}", this, server.serverInfo().name(),
|
||||
wrapped);
|
||||
userMessage = "Unable to connect to " + server.getServerInfo().getName() + ". Try again "
|
||||
userMessage = "Unable to connect to " + server.serverInfo().name() + ". Try again "
|
||||
+ "later.";
|
||||
}
|
||||
handleConnectionException(server, null, Component.text(userMessage,
|
||||
@@ -456,23 +456,23 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
return;
|
||||
}
|
||||
|
||||
VelocityConfiguration.Messages messages = this.server.getConfiguration().getMessages();
|
||||
VelocityConfiguration.Messages messages = this.server.configuration().getMessages();
|
||||
Component disconnectReason = GsonComponentSerializer.gson().deserialize(disconnect.getReason());
|
||||
String plainTextReason = PASS_THRU_TRANSLATE.serialize(disconnectReason);
|
||||
if (connectedServer != null && connectedServer.getServerInfo().equals(server.getServerInfo())) {
|
||||
logger.error("{}: kicked from server {}: {}", this, server.getServerInfo().getName(),
|
||||
if (connectedServer != null && connectedServer.serverInfo().equals(server.serverInfo())) {
|
||||
logger.error("{}: kicked from server {}: {}", this, server.serverInfo().name(),
|
||||
plainTextReason);
|
||||
handleConnectionException(server, disconnectReason, Component.text()
|
||||
.append(messages.getKickPrefix(server.getServerInfo().getName())
|
||||
.append(messages.getKickPrefix(server.serverInfo().name())
|
||||
.colorIfAbsent(NamedTextColor.RED))
|
||||
.color(NamedTextColor.RED)
|
||||
.append(disconnectReason)
|
||||
.build(), safe);
|
||||
} else {
|
||||
logger.error("{}: disconnected while connecting to {}: {}", this,
|
||||
server.getServerInfo().getName(), plainTextReason);
|
||||
server.serverInfo().name(), plainTextReason);
|
||||
handleConnectionException(server, disconnectReason, Component.text()
|
||||
.append(messages.getDisconnectPrefix(server.getServerInfo().getName())
|
||||
.append(messages.getDisconnectPrefix(server.serverInfo().name())
|
||||
.colorIfAbsent(NamedTextColor.RED))
|
||||
.append(disconnectReason)
|
||||
.build(), safe);
|
||||
@@ -494,7 +494,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean kickedFromCurrent = connectedServer == null || connectedServer.getServer().equals(rs);
|
||||
boolean kickedFromCurrent = connectedServer == null || connectedServer.target().equals(rs);
|
||||
ServerKickResult result;
|
||||
if (kickedFromCurrent) {
|
||||
Optional<RegisteredServer> next = getNextServerToTry(rs);
|
||||
@@ -502,7 +502,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
.orElseGet(() -> DisconnectPlayer.create(friendlyReason));
|
||||
} else {
|
||||
// If we were kicked by going to another server, the connection should not be in flight
|
||||
if (connectionInFlight != null && connectionInFlight.getServer().equals(rs)) {
|
||||
if (connectionInFlight != null && connectionInFlight.target().equals(rs)) {
|
||||
resetInFlightConnection();
|
||||
}
|
||||
result = Notify.create(friendlyReason);
|
||||
@@ -514,7 +514,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
|
||||
private void handleKickEvent(KickedFromServerEvent originalEvent, Component friendlyReason,
|
||||
boolean kickedFromCurrent) {
|
||||
server.getEventManager().fire(originalEvent)
|
||||
server.eventManager().fire(originalEvent)
|
||||
.thenAcceptAsync(event -> {
|
||||
// There can't be any connection in flight now.
|
||||
connectionInFlight = null;
|
||||
@@ -530,36 +530,36 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getResult() instanceof DisconnectPlayer) {
|
||||
DisconnectPlayer res = (DisconnectPlayer) event.getResult();
|
||||
disconnect(res.getReason());
|
||||
} else if (event.getResult() instanceof RedirectPlayer) {
|
||||
RedirectPlayer res = (RedirectPlayer) event.getResult();
|
||||
if (event.result() instanceof DisconnectPlayer) {
|
||||
DisconnectPlayer res = (DisconnectPlayer) event.result();
|
||||
disconnect(res.message());
|
||||
} else if (event.result() instanceof RedirectPlayer) {
|
||||
RedirectPlayer res = (RedirectPlayer) event.result();
|
||||
createConnectionRequest(res.getServer())
|
||||
.connect()
|
||||
.whenCompleteAsync((status, throwable) -> {
|
||||
if (throwable != null) {
|
||||
handleConnectionException(status != null ? status.getAttemptedConnection()
|
||||
handleConnectionException(status != null ? status.finalTarget()
|
||||
: res.getServer(), throwable, true);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (status.getStatus()) {
|
||||
switch (status.status()) {
|
||||
// Impossible/nonsensical cases
|
||||
case ALREADY_CONNECTED:
|
||||
case CONNECTION_IN_PROGRESS:
|
||||
// Fatal case
|
||||
case CONNECTION_CANCELLED:
|
||||
disconnect(status.getReason().orElse(res.getMessage()));
|
||||
disconnect(status.failureReason().orElse(res.message()));
|
||||
break;
|
||||
case SERVER_DISCONNECTED:
|
||||
Component reason = status.getReason()
|
||||
Component reason = status.failureReason()
|
||||
.orElse(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR);
|
||||
handleConnectionException(res.getServer(), ClientboundDisconnectPacket.create(reason,
|
||||
getProtocolVersion()), ((Impl) status).isSafe());
|
||||
protocolVersion()), ((Impl) status).isSafe());
|
||||
break;
|
||||
case SUCCESS:
|
||||
sendMessage(Identity.nil(), server.getConfiguration().getMessages()
|
||||
sendMessage(Identity.nil(), server.configuration().getMessages()
|
||||
.getMovedToNewServerPrefix().append(friendlyReason));
|
||||
break;
|
||||
default:
|
||||
@@ -567,12 +567,12 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
break;
|
||||
}
|
||||
}, connection.eventLoop());
|
||||
} else if (event.getResult() instanceof Notify) {
|
||||
Notify res = (Notify) event.getResult();
|
||||
} else if (event.result() instanceof Notify) {
|
||||
Notify res = (Notify) event.result();
|
||||
if (event.kickedDuringServerConnect() && previouslyConnected) {
|
||||
sendMessage(Identity.nil(), res.getMessage());
|
||||
sendMessage(Identity.nil(), res.message());
|
||||
} else {
|
||||
disconnect(res.getMessage());
|
||||
disconnect(res.message());
|
||||
}
|
||||
} else {
|
||||
// In case someone gets creative, assume we want to disconnect the player.
|
||||
@@ -601,31 +601,31 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
*/
|
||||
private Optional<RegisteredServer> getNextServerToTry(@Nullable RegisteredServer current) {
|
||||
if (serversToTry == null) {
|
||||
String virtualHostStr = getVirtualHost().map(InetSocketAddress::getHostString).orElse("");
|
||||
serversToTry = server.getConfiguration().getForcedHosts().getOrDefault(virtualHostStr,
|
||||
String virtualHostStr = connectedHost().map(InetSocketAddress::getHostString).orElse("");
|
||||
serversToTry = server.configuration().getForcedHosts().getOrDefault(virtualHostStr,
|
||||
Collections.emptyList());
|
||||
}
|
||||
|
||||
if (serversToTry.isEmpty()) {
|
||||
serversToTry = server.getConfiguration().getAttemptConnectionOrder();
|
||||
serversToTry = server.configuration().getAttemptConnectionOrder();
|
||||
}
|
||||
|
||||
for (int i = tryIndex; i < serversToTry.size(); i++) {
|
||||
String toTryName = serversToTry.get(i);
|
||||
if ((connectedServer != null && hasSameName(connectedServer.getServer(), toTryName))
|
||||
|| (connectionInFlight != null && hasSameName(connectionInFlight.getServer(), toTryName))
|
||||
if ((connectedServer != null && hasSameName(connectedServer.target(), toTryName))
|
||||
|| (connectionInFlight != null && hasSameName(connectionInFlight.target(), toTryName))
|
||||
|| (current != null && hasSameName(current, toTryName))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
tryIndex = i;
|
||||
return server.getServer(toTryName);
|
||||
return server.server(toTryName);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private static boolean hasSameName(RegisteredServer server, String name) {
|
||||
return server.getServerInfo().getName().equalsIgnoreCase(name);
|
||||
return server.serverInfo().name().equalsIgnoreCase(name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -668,12 +668,12 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
connectedServer.disconnect();
|
||||
}
|
||||
|
||||
Optional<Player> connectedPlayer = server.getPlayer(this.getUniqueId());
|
||||
Optional<Player> connectedPlayer = server.getPlayer(this.id());
|
||||
server.unregisterConnection(this);
|
||||
|
||||
DisconnectEventImpl.LoginStatus status;
|
||||
if (connectedPlayer.isPresent()) {
|
||||
if (!connectedPlayer.get().getCurrentServer().isPresent()) {
|
||||
if (!connectedPlayer.get().connectedServer().isPresent()) {
|
||||
status = LoginStatus.PRE_SERVER_JOIN;
|
||||
} else {
|
||||
status = connectedPlayer.get() == this ? LoginStatus.SUCCESSFUL_LOGIN
|
||||
@@ -685,7 +685,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
}
|
||||
|
||||
DisconnectEvent event = new DisconnectEventImpl(this, status);
|
||||
server.getEventManager().fire(event).whenComplete((val, ex) -> {
|
||||
server.eventManager().fire(event).whenComplete((val, ex) -> {
|
||||
if (ex == null) {
|
||||
this.teardownFuture.complete(null);
|
||||
} else {
|
||||
@@ -700,19 +700,19 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[connected player] " + profile.getName() + " (" + getRemoteAddress() + ")";
|
||||
return "[connected player] " + profile.getName() + " (" + remoteAddress() + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tristate getPermissionValue(String permission) {
|
||||
return permissionFunction.getPermissionValue(permission);
|
||||
public Tristate evaluatePermission(String permission) {
|
||||
return permissionFunction.evaluatePermission(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendPluginMessage(ChannelIdentifier identifier, byte[] data) {
|
||||
Preconditions.checkNotNull(identifier, "identifier");
|
||||
Preconditions.checkNotNull(data, "data");
|
||||
ClientboundPluginMessagePacket message = new ClientboundPluginMessagePacket(identifier.getId(),
|
||||
ClientboundPluginMessagePacket message = new ClientboundPluginMessagePacket(identifier.id(),
|
||||
Unpooled.wrappedBuffer(data));
|
||||
connection.write(message);
|
||||
return true;
|
||||
@@ -730,7 +730,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
public void sendResourcePack(String url) {
|
||||
Preconditions.checkNotNull(url, "url");
|
||||
|
||||
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
|
||||
if (this.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
|
||||
connection.write(new ClientboundResourcePackRequestPacket(url, ""));
|
||||
}
|
||||
}
|
||||
@@ -741,7 +741,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
Preconditions.checkNotNull(hash, "hash");
|
||||
Preconditions.checkArgument(hash.length == 20, "Hash length is not 20");
|
||||
|
||||
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
|
||||
if (this.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
|
||||
connection.write(new ClientboundResourcePackRequestPacket(url, ByteBufUtil.hexDump(hash)));
|
||||
}
|
||||
}
|
||||
@@ -813,7 +813,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
private class IdentityImpl implements Identity {
|
||||
@Override
|
||||
public @NonNull UUID uuid() {
|
||||
return ConnectedPlayer.this.getUniqueId();
|
||||
return ConnectedPlayer.this.id();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -826,7 +826,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegisteredServer getServer() {
|
||||
public RegisteredServer target() {
|
||||
return toConnect;
|
||||
}
|
||||
|
||||
@@ -837,7 +837,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
&& !connectedServer.hasCompletedJoin())) {
|
||||
return Optional.of(ConnectionRequestBuilder.Status.CONNECTION_IN_PROGRESS);
|
||||
}
|
||||
if (connectedServer != null && connectedServer.getServer().equals(server)) {
|
||||
if (connectedServer != null && connectedServer.target().equals(server)) {
|
||||
return Optional.of(ALREADY_CONNECTED);
|
||||
}
|
||||
return Optional.empty();
|
||||
@@ -856,9 +856,9 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
|
||||
ServerPreConnectEvent event = new ServerPreConnectEventImpl(ConnectedPlayer.this,
|
||||
toConnect);
|
||||
return server.getEventManager().fire(event)
|
||||
return server.eventManager().fire(event)
|
||||
.thenComposeAsync(newEvent -> {
|
||||
Optional<RegisteredServer> newDest = newEvent.getResult().getServer();
|
||||
Optional<RegisteredServer> newDest = newEvent.result().target();
|
||||
if (!newDest.isPresent()) {
|
||||
return completedFuture(
|
||||
plainResult(ConnectionRequestBuilder.Status.CONNECTION_CANCELLED, toConnect)
|
||||
@@ -895,7 +895,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
.whenCompleteAsync((status, throwable) -> {
|
||||
if (status != null && !status.isSuccessful()) {
|
||||
if (!status.isSafe()) {
|
||||
handleConnectionException(status.getAttemptedConnection(), throwable, false);
|
||||
handleConnectionException(status.finalTarget(), throwable, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -912,12 +912,12 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
.whenCompleteAsync((status, throwable) -> {
|
||||
if (throwable != null) {
|
||||
// TODO: The exception handling from this is not very good. Find a better way.
|
||||
handleConnectionException(status != null ? status.getAttemptedConnection()
|
||||
handleConnectionException(status != null ? status.finalTarget()
|
||||
: toConnect, throwable, true);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (status.getStatus()) {
|
||||
switch (status.status()) {
|
||||
case ALREADY_CONNECTED:
|
||||
sendMessage(Identity.nil(), ConnectionMessages.ALREADY_CONNECTED);
|
||||
break;
|
||||
@@ -928,10 +928,10 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
// Ignored; the plugin probably already handled this.
|
||||
break;
|
||||
case SERVER_DISCONNECTED:
|
||||
Component reason = status.getReason()
|
||||
Component reason = status.failureReason()
|
||||
.orElse(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR);
|
||||
handleConnectionException(toConnect, ClientboundDisconnectPacket.create(reason,
|
||||
getProtocolVersion()), status.isSafe());
|
||||
protocolVersion()), status.isSafe());
|
||||
break;
|
||||
default:
|
||||
// The only remaining value is successful (no need to do anything!)
|
||||
|
||||
@@ -130,13 +130,13 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
|
||||
|
||||
// If the proxy is configured for modern forwarding, we must deny connections from 1.12.2
|
||||
// and lower, otherwise IP information will never get forwarded.
|
||||
if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN
|
||||
if (server.configuration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN
|
||||
&& handshake.getProtocolVersion().lt(ProtocolVersion.MINECRAFT_1_13)) {
|
||||
ic.disconnectQuietly(Component.text("This server is only compatible with 1.13 and above."));
|
||||
return;
|
||||
}
|
||||
|
||||
server.getEventManager().fireAndForget(new ConnectionHandshakeEventImpl(ic));
|
||||
server.eventManager().fireAndForget(new ConnectionHandshakeEventImpl(ic));
|
||||
connection.setSessionHandler(new LoginSessionHandler(server, connection, ic));
|
||||
}
|
||||
|
||||
@@ -204,12 +204,12 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getRemoteAddress() {
|
||||
public InetSocketAddress remoteAddress() {
|
||||
return (InetSocketAddress) connection.getRemoteAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<InetSocketAddress> getVirtualHost() {
|
||||
public Optional<InetSocketAddress> connectedHost() {
|
||||
return Optional.ofNullable(ping.getVhost());
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolVersion getProtocolVersion() {
|
||||
public ProtocolVersion protocolVersion() {
|
||||
return ProtocolVersion.LEGACY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,12 +47,12 @@ public final class InitialInboundConnection implements InboundConnection,
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getRemoteAddress() {
|
||||
public InetSocketAddress remoteAddress() {
|
||||
return (InetSocketAddress) connection.getRemoteAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<InetSocketAddress> getVirtualHost() {
|
||||
public Optional<InetSocketAddress> connectedHost() {
|
||||
return Optional.of(InetSocketAddress.createUnresolved(cleanedAddress, handshake.getPort()));
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public final class InitialInboundConnection implements InboundConnection,
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolVersion getProtocolVersion() {
|
||||
public ProtocolVersion protocolVersion() {
|
||||
return connection.getProtocolVersion();
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ public final class InitialInboundConnection implements InboundConnection,
|
||||
public void disconnect(Component reason) {
|
||||
logger.info("{} has disconnected: {}", this,
|
||||
LegacyComponentSerializer.legacySection().serialize(reason));
|
||||
connection.closeWith(ClientboundDisconnectPacket.create(reason, getProtocolVersion()));
|
||||
connection.closeWith(ClientboundDisconnectPacket.create(reason, protocolVersion()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,6 +86,6 @@ public final class InitialInboundConnection implements InboundConnection,
|
||||
* @param reason the reason for disconnecting
|
||||
*/
|
||||
public void disconnectQuietly(Component reason) {
|
||||
connection.closeWith(ClientboundDisconnectPacket.create(reason, getProtocolVersion()));
|
||||
connection.closeWith(ClientboundDisconnectPacket.create(reason, protocolVersion()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
String url = String.format(MOJANG_HASJOINED_URL,
|
||||
urlFormParameterEscaper().escape(login.getUsername()), serverId);
|
||||
|
||||
if (server.getConfiguration().shouldPreventClientProxyConnections()) {
|
||||
if (server.configuration().shouldPreventClientProxyConnections()) {
|
||||
url += "&ip=" + urlFormParameterEscaper().escape(playerIp);
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
GameProfile.class), true);
|
||||
} else if (profileResponse.getStatusCode() == 204) {
|
||||
// Apparently an offline-mode user logged onto this online-mode proxy.
|
||||
inbound.disconnect(server.getConfiguration().getMessages().getOnlineModeOnly());
|
||||
inbound.disconnect(server.configuration().getMessages().getOnlineModeOnly());
|
||||
} else {
|
||||
// Something else went wrong
|
||||
logger.error(
|
||||
@@ -180,23 +180,23 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
throw new IllegalStateException("No ServerLogin packet received yet.");
|
||||
}
|
||||
PreLoginEvent event = new PreLoginEventImpl(inbound, login.getUsername());
|
||||
server.getEventManager().fire(event)
|
||||
server.eventManager().fire(event)
|
||||
.thenRunAsync(() -> {
|
||||
if (mcConnection.isClosed()) {
|
||||
// The player was disconnected
|
||||
return;
|
||||
}
|
||||
|
||||
PreLoginComponentResult result = event.getResult();
|
||||
Optional<Component> disconnectReason = result.getReason();
|
||||
PreLoginComponentResult result = event.result();
|
||||
Optional<Component> disconnectReason = result.denialReason();
|
||||
if (disconnectReason.isPresent()) {
|
||||
// The component is guaranteed to be provided if the connection was denied.
|
||||
mcConnection.closeWith(ClientboundDisconnectPacket.create(disconnectReason.get(),
|
||||
inbound.getProtocolVersion()));
|
||||
inbound.protocolVersion()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!result.isForceOfflineMode() && (server.getConfiguration().isOnlineMode() || result
|
||||
if (!result.isForceOfflineMode() && (server.configuration().isOnlineMode() || result
|
||||
.isOnlineModeAllowed())) {
|
||||
// Request encryption.
|
||||
ClientboundEncryptionRequestPacket request = generateEncryptionRequest();
|
||||
@@ -225,29 +225,29 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
private void initializePlayer(GameProfile profile, boolean onlineMode) {
|
||||
// Some connection types may need to alter the game profile.
|
||||
profile = mcConnection.getType().addGameProfileTokensIfRequired(profile,
|
||||
server.getConfiguration().getPlayerInfoForwardingMode());
|
||||
server.configuration().getPlayerInfoForwardingMode());
|
||||
GameProfileRequestEvent profileRequestEvent = new GameProfileRequestEventImpl(inbound, profile,
|
||||
onlineMode);
|
||||
final GameProfile finalProfile = profile;
|
||||
|
||||
server.getEventManager().fire(profileRequestEvent).thenComposeAsync(profileEvent -> {
|
||||
server.eventManager().fire(profileRequestEvent).thenComposeAsync(profileEvent -> {
|
||||
if (mcConnection.isClosed()) {
|
||||
// The player disconnected after we authenticated them.
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
// Initiate a regular connection and move over to it.
|
||||
ConnectedPlayer player = new ConnectedPlayer(server, profileEvent.getGameProfile(),
|
||||
mcConnection, inbound.getVirtualHost().orElse(null), onlineMode);
|
||||
ConnectedPlayer player = new ConnectedPlayer(server, profileEvent.gameProfile(),
|
||||
mcConnection, inbound.connectedHost().orElse(null), onlineMode);
|
||||
this.connectedPlayer = player;
|
||||
if (!server.canRegisterConnection(player)) {
|
||||
player.disconnect0(server.getConfiguration().getMessages().getAlreadyConnected(), true);
|
||||
player.disconnect0(server.configuration().getMessages().getAlreadyConnected(), true);
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
logger.info("{} has connected", player);
|
||||
|
||||
return server.getEventManager()
|
||||
return server.eventManager()
|
||||
.fire(new PermissionsSetupEventImpl(player, ConnectedPlayer.DEFAULT_PERMISSIONS))
|
||||
.thenAcceptAsync(event -> {
|
||||
if (!mcConnection.isClosed()) {
|
||||
@@ -258,8 +258,8 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
"A plugin permission provider {} provided an invalid permission function"
|
||||
+ " for player {}. This is a bug in the plugin, not in Velocity. Falling"
|
||||
+ " back to the default permission function.",
|
||||
event.getProvider().getClass().getName(),
|
||||
player.getUsername());
|
||||
event.provider().getClass().getName(),
|
||||
player.username());
|
||||
} else {
|
||||
player.setPermissionFunction(function);
|
||||
}
|
||||
@@ -273,42 +273,42 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
}
|
||||
|
||||
private void completeLoginProtocolPhaseAndInitialize(ConnectedPlayer player) {
|
||||
int threshold = server.getConfiguration().getCompressionThreshold();
|
||||
int threshold = server.configuration().getCompressionThreshold();
|
||||
if (threshold >= 0 && mcConnection.getProtocolVersion().gte(MINECRAFT_1_8)) {
|
||||
mcConnection.write(new ClientboundSetCompressionPacket(threshold));
|
||||
mcConnection.setCompressionThreshold(threshold);
|
||||
}
|
||||
VelocityConfiguration configuration = server.getConfiguration();
|
||||
UUID playerUniqueId = player.getUniqueId();
|
||||
VelocityConfiguration configuration = server.configuration();
|
||||
UUID playerUniqueId = player.id();
|
||||
if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.NONE) {
|
||||
playerUniqueId = UuidUtils.generateOfflinePlayerUuid(player.getUsername());
|
||||
playerUniqueId = UuidUtils.generateOfflinePlayerUuid(player.username());
|
||||
}
|
||||
mcConnection.write(new ClientboundServerLoginSuccessPacket(playerUniqueId, player.getUsername()));
|
||||
mcConnection.write(new ClientboundServerLoginSuccessPacket(playerUniqueId, player.username()));
|
||||
|
||||
mcConnection.setAssociation(player);
|
||||
mcConnection.setState(StateRegistry.PLAY);
|
||||
|
||||
server.getEventManager().fire(new LoginEventImpl(player))
|
||||
server.eventManager().fire(new LoginEventImpl(player))
|
||||
.thenAcceptAsync(event -> {
|
||||
if (mcConnection.isClosed()) {
|
||||
// The player was disconnected
|
||||
server.getEventManager().fireAndForget(new DisconnectEventImpl(player,
|
||||
server.eventManager().fireAndForget(new DisconnectEventImpl(player,
|
||||
LoginStatus.CANCELLED_BY_USER_BEFORE_COMPLETE));
|
||||
return;
|
||||
}
|
||||
|
||||
Optional<Component> reason = event.getResult().getReason();
|
||||
Optional<Component> reason = event.result().reason();
|
||||
if (reason.isPresent()) {
|
||||
player.disconnect0(reason.get(), true);
|
||||
} else {
|
||||
if (!server.registerConnection(player)) {
|
||||
player.disconnect0(server.getConfiguration().getMessages()
|
||||
player.disconnect0(server.configuration().getMessages()
|
||||
.getAlreadyConnected(), true);
|
||||
return;
|
||||
}
|
||||
|
||||
mcConnection.setSessionHandler(new InitialConnectSessionHandler(player));
|
||||
server.getEventManager().fire(new PostLoginEventImpl(player))
|
||||
server.eventManager().fire(new PostLoginEventImpl(player))
|
||||
.thenCompose((ignored) -> connectToInitialServer(player))
|
||||
.exceptionally((ex) -> {
|
||||
logger.error("Exception while connecting {} to initial server", player, ex);
|
||||
@@ -327,11 +327,11 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
PlayerChooseInitialServerEvent event = new PlayerChooseInitialServerEventImpl(player,
|
||||
initialFromConfig.orElse(null));
|
||||
|
||||
return server.getEventManager().fire(event)
|
||||
return server.eventManager().fire(event)
|
||||
.thenRunAsync(() -> {
|
||||
Optional<RegisteredServer> toTry = event.getInitialServer();
|
||||
Optional<RegisteredServer> toTry = event.initialServer();
|
||||
if (!toTry.isPresent()) {
|
||||
player.disconnect0(server.getConfiguration().getMessages()
|
||||
player.disconnect0(server.configuration().getMessages()
|
||||
.getNoAvailableServers(), true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -67,18 +67,18 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
|
||||
|
||||
@Override
|
||||
public void activated() {
|
||||
if (server.getConfiguration().isShowPingRequests()) {
|
||||
if (server.configuration().isShowPingRequests()) {
|
||||
logger.info("{} is pinging the server with version {}", this.inbound,
|
||||
this.connection.getProtocolVersion());
|
||||
}
|
||||
}
|
||||
|
||||
private ServerPing constructLocalPing(ProtocolVersion version) {
|
||||
VelocityConfiguration configuration = server.getConfiguration();
|
||||
VelocityConfiguration configuration = server.configuration();
|
||||
return new ServerPing(
|
||||
new ServerPing.Version(version.getProtocol(),
|
||||
new ServerPing.Version(version.protocol(),
|
||||
"Velocity " + ProtocolVersion.SUPPORTED_VERSION_STRING),
|
||||
new ServerPing.Players(server.getPlayerCount(), configuration.getShowMaxPlayers(),
|
||||
new ServerPing.Players(server.countConnectedPlayers(), configuration.getShowMaxPlayers(),
|
||||
ImmutableList.of()),
|
||||
configuration.getMotd(),
|
||||
configuration.getFavicon().orElse(null),
|
||||
@@ -91,7 +91,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
|
||||
ServerPing fallback = constructLocalPing(pingingVersion);
|
||||
List<CompletableFuture<ServerPing>> pings = new ArrayList<>();
|
||||
for (String s : servers) {
|
||||
Optional<RegisteredServer> rs = server.getServer(s);
|
||||
Optional<RegisteredServer> rs = server.server(s);
|
||||
if (!rs.isPresent()) {
|
||||
continue;
|
||||
}
|
||||
@@ -123,7 +123,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
|
||||
if (response == fallback) {
|
||||
continue;
|
||||
}
|
||||
Optional<ModInfo> modInfo = response.getModinfo();
|
||||
Optional<ModInfo> modInfo = response.modInfo();
|
||||
if (modInfo.isPresent()) {
|
||||
return fallback.asBuilder().mods(modInfo.get()).build();
|
||||
}
|
||||
@@ -138,16 +138,16 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (response.getDescription() == null) {
|
||||
if (response.description() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return new ServerPing(
|
||||
fallback.getVersion(),
|
||||
fallback.getPlayers().orElse(null),
|
||||
response.getDescription(),
|
||||
fallback.getFavicon().orElse(null),
|
||||
response.getModinfo().orElse(null)
|
||||
fallback.version(),
|
||||
fallback.players().orElse(null),
|
||||
response.description(),
|
||||
fallback.favicon().orElse(null),
|
||||
response.modInfo().orElse(null)
|
||||
);
|
||||
}
|
||||
return fallback;
|
||||
@@ -159,7 +159,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
|
||||
}
|
||||
|
||||
private CompletableFuture<ServerPing> getInitialPing() {
|
||||
VelocityConfiguration configuration = server.getConfiguration();
|
||||
VelocityConfiguration configuration = server.configuration();
|
||||
ProtocolVersion shownVersion = ProtocolVersion.isSupported(connection.getProtocolVersion())
|
||||
? connection.getProtocolVersion() : ProtocolVersion.MAXIMUM_VERSION;
|
||||
PingPassthroughMode passthrough = configuration.getPingPassthrough();
|
||||
@@ -167,10 +167,10 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
|
||||
if (passthrough == PingPassthroughMode.DISABLED) {
|
||||
return CompletableFuture.completedFuture(constructLocalPing(shownVersion));
|
||||
} else {
|
||||
String virtualHostStr = inbound.getVirtualHost().map(InetSocketAddress::getHostString)
|
||||
String virtualHostStr = inbound.connectedHost().map(InetSocketAddress::getHostString)
|
||||
.orElse("");
|
||||
List<String> serversToTry = server.getConfiguration().getForcedHosts().getOrDefault(
|
||||
virtualHostStr, server.getConfiguration().getAttemptConnectionOrder());
|
||||
List<String> serversToTry = server.configuration().getForcedHosts().getOrDefault(
|
||||
virtualHostStr, server.configuration().getAttemptConnectionOrder());
|
||||
return attemptPingPassthrough(configuration.getPingPassthrough(), serversToTry, shownVersion);
|
||||
}
|
||||
}
|
||||
@@ -182,9 +182,9 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
|
||||
}
|
||||
this.pingReceived = true;
|
||||
getInitialPing()
|
||||
.thenCompose(ping -> server.getEventManager().fire(new ProxyPingEventImpl(inbound, ping)))
|
||||
.thenCompose(ping -> server.eventManager().fire(new ProxyPingEventImpl(inbound, ping)))
|
||||
.thenAcceptAsync(event -> connection.closeWith(
|
||||
LegacyDisconnectPacket.fromServerPing(event.getPing(), packet.getVersion())),
|
||||
LegacyDisconnectPacket.fromServerPing(event.ping(), packet.getVersion())),
|
||||
connection.eventLoop())
|
||||
.exceptionally((ex) -> {
|
||||
logger.error("Exception while handling legacy ping {}", packet, ex);
|
||||
@@ -207,12 +207,12 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
|
||||
this.pingReceived = true;
|
||||
|
||||
getInitialPing()
|
||||
.thenCompose(ping -> server.getEventManager().fire(new ProxyPingEventImpl(inbound, ping)))
|
||||
.thenCompose(ping -> server.eventManager().fire(new ProxyPingEventImpl(inbound, ping)))
|
||||
.thenAcceptAsync(
|
||||
(event) -> {
|
||||
StringBuilder json = new StringBuilder();
|
||||
VelocityServer.getPingGsonInstance(connection.getProtocolVersion())
|
||||
.toJson(event.getPing(), json);
|
||||
.toJson(event.ping(), json);
|
||||
connection.write(new ClientboundStatusResponsePacket(json));
|
||||
},
|
||||
connection.eventLoop())
|
||||
|
||||
@@ -60,7 +60,7 @@ public enum LegacyForgeHandshakeBackendPhase implements BackendConnectionPhase {
|
||||
if (mc != null) {
|
||||
mc.setType(ConnectionTypes.LEGACY_FORGE);
|
||||
}
|
||||
connection.getPlayer().sendLegacyForgeHandshakeResetPacket();
|
||||
connection.player().sendLegacyForgeHandshakeResetPacket();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ public enum LegacyForgeHandshakeClientPhase implements ClientConnectionPhase {
|
||||
AbstractPluginMessagePacket<?> message,
|
||||
MinecraftConnection backendConn) {
|
||||
// Read the mod list if we haven't already.
|
||||
if (!player.getModInfo().isPresent()) {
|
||||
if (!player.modInfo().isPresent()) {
|
||||
List<ModInfo.Mod> mods = LegacyForgeUtil.readModList(message);
|
||||
if (!mods.isEmpty()) {
|
||||
player.setModInfo(new ModInfo("FML", mods));
|
||||
|
||||
@@ -84,17 +84,17 @@ public class ConnectionRequestResults {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Status getStatus() {
|
||||
public Status status() {
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Component> getReason() {
|
||||
public Optional<Component> failureReason() {
|
||||
return Optional.ofNullable(component);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegisteredServer getAttemptedConnection() {
|
||||
public RegisteredServer finalTarget() {
|
||||
return attemptedConnection;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,8 +57,8 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Tristate getPermissionValue(@NonNull String permission) {
|
||||
return this.permissionFunction.getPermissionValue(permission);
|
||||
public @NonNull Tristate evaluatePermission(@NonNull String permission) {
|
||||
return this.permissionFunction.evaluatePermission(permission);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,13 +75,13 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons
|
||||
public void setupPermissions() {
|
||||
PermissionsSetupEvent event = new PermissionsSetupEventImpl(this, s -> ALWAYS_TRUE);
|
||||
// we can safely block here, this is before any listeners fire
|
||||
this.permissionFunction = this.server.getEventManager().fire(event).join().createFunction(this);
|
||||
this.permissionFunction = this.server.eventManager().fire(event).join().createFunction(this);
|
||||
if (this.permissionFunction == null) {
|
||||
logger.error(
|
||||
"A plugin permission provider {} provided an invalid permission function"
|
||||
+ " for the console. This is a bug in the plugin, not in Velocity. Falling"
|
||||
+ " back to the default permission function.",
|
||||
event.getProvider().getClass().getName());
|
||||
event.provider().getClass().getName());
|
||||
this.permissionFunction = ALWAYS_TRUE;
|
||||
}
|
||||
}
|
||||
@@ -92,7 +92,7 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons
|
||||
.appName("Velocity")
|
||||
.completer((reader, parsedLine, list) -> {
|
||||
try {
|
||||
List<String> offers = this.server.getCommandManager()
|
||||
List<String> offers = this.server.commandManager()
|
||||
.offerSuggestions(this, parsedLine.line())
|
||||
.join(); // Console doesn't get harmed much by this...
|
||||
for (String offer : offers) {
|
||||
@@ -113,7 +113,7 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons
|
||||
@Override
|
||||
protected void runCommand(String command) {
|
||||
try {
|
||||
if (!this.server.getCommandManager().execute(this, command).join()) {
|
||||
if (!this.server.commandManager().execute(this, command).join()) {
|
||||
sendMessage(Component.text("Command not found.", NamedTextColor.RED));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -595,7 +595,7 @@ public class VelocityEventManager implements EventManager {
|
||||
private static void logHandlerException(
|
||||
final HandlerRegistration registration, final Throwable t) {
|
||||
logger.error("Couldn't pass {} to {}", registration.eventType.getSimpleName(),
|
||||
registration.plugin.getDescription().getId(), t);
|
||||
registration.plugin.description().id(), t);
|
||||
}
|
||||
|
||||
public boolean shutdown() throws InterruptedException {
|
||||
|
||||
@@ -50,7 +50,7 @@ public class BackendChannelInitializer extends ChannelInitializer<Channel> {
|
||||
ch.pipeline()
|
||||
.addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder())
|
||||
.addLast(READ_TIMEOUT,
|
||||
new ReadTimeoutHandler(server.getConfiguration().getReadTimeout(),
|
||||
new ReadTimeoutHandler(server.configuration().getReadTimeout(),
|
||||
TimeUnit.MILLISECONDS))
|
||||
.addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE)
|
||||
.addLast(MINECRAFT_DECODER,
|
||||
|
||||
@@ -87,7 +87,7 @@ public final class ConnectionManager {
|
||||
this.resolver = new SeparatePoolInetNameResolver(GlobalEventExecutor.INSTANCE);
|
||||
this.httpClient = asyncHttpClient(config()
|
||||
.setEventLoopGroup(this.workerGroup)
|
||||
.setUserAgent(server.getVersion().getName() + "/" + server.getVersion().getVersion())
|
||||
.setUserAgent(server.version().getName() + "/" + server.version().getVersion())
|
||||
.addRequestFilter(new RequestFilter() {
|
||||
@Override
|
||||
public <T> FilterContext<T> filter(FilterContext<T> ctx) {
|
||||
@@ -122,7 +122,7 @@ public final class ConnectionManager {
|
||||
if (address instanceof InetSocketAddress) {
|
||||
bootstrap.childOption(ChannelOption.TCP_NODELAY, true)
|
||||
.childOption(ChannelOption.IP_TOS, 0x18);
|
||||
if (transportType == TransportType.EPOLL && server.getConfiguration().useTcpFastOpen()) {
|
||||
if (transportType == TransportType.EPOLL && server.configuration().useTcpFastOpen()) {
|
||||
bootstrap.option(EpollChannelOption.TCP_FASTOPEN, 3);
|
||||
}
|
||||
}
|
||||
@@ -135,7 +135,7 @@ public final class ConnectionManager {
|
||||
LOGGER.info("Listening on {}", channel.localAddress());
|
||||
|
||||
// Fire the proxy bound event after the socket is bound
|
||||
server.getEventManager().fireAndForget(
|
||||
server.eventManager().fireAndForget(
|
||||
new ListenerBoundEventImpl(address, ListenerType.MINECRAFT));
|
||||
} else {
|
||||
LOGGER.error("Can't bind to {}", address, future.cause());
|
||||
@@ -164,7 +164,7 @@ public final class ConnectionManager {
|
||||
LOGGER.info("Listening for GS4 query on {}", channel.localAddress());
|
||||
|
||||
// Fire the proxy bound event after the socket is bound
|
||||
server.getEventManager().fireAndForget(
|
||||
server.eventManager().fireAndForget(
|
||||
new ListenerBoundEventImpl(address, ListenerType.QUERY));
|
||||
} else {
|
||||
LOGGER.error("Can't bind to {}", bootstrap.config().localAddress(), future.cause());
|
||||
@@ -184,10 +184,10 @@ public final class ConnectionManager {
|
||||
.channelFactory(this.transportType.getClientChannelFactory(target))
|
||||
.option(ChannelOption.TCP_NODELAY, true)
|
||||
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS,
|
||||
this.server.getConfiguration().getConnectTimeout())
|
||||
this.server.configuration().getConnectTimeout())
|
||||
.group(group == null ? this.workerGroup : group)
|
||||
.resolver(this.resolver.asGroup());
|
||||
if (transportType == TransportType.EPOLL && server.getConfiguration().useTcpFastOpen()) {
|
||||
if (transportType == TransportType.EPOLL && server.configuration().useTcpFastOpen()) {
|
||||
bootstrap.option(EpollChannelOption.TCP_FASTOPEN_CONNECT, true);
|
||||
}
|
||||
return bootstrap;
|
||||
@@ -203,7 +203,7 @@ public final class ConnectionManager {
|
||||
|
||||
// Fire proxy close event to notify plugins of socket close. We block since plugins
|
||||
// should have a chance to be notified before the server stops accepting connections.
|
||||
server.getEventManager().fire(new ListenerClosedEventImpl(oldBind, endpoint.getType())).join();
|
||||
server.eventManager().fire(new ListenerClosedEventImpl(oldBind, endpoint.getType())).join();
|
||||
|
||||
Channel serverChannel = endpoint.getChannel();
|
||||
|
||||
@@ -222,7 +222,7 @@ public final class ConnectionManager {
|
||||
|
||||
// Fire proxy close event to notify plugins of socket close. We block since plugins
|
||||
// should have a chance to be notified before the server stops accepting connections.
|
||||
server.getEventManager().fire(new ListenerClosedEventImpl(address, endpoint.getType())).join();
|
||||
server.eventManager().fire(new ListenerClosedEventImpl(address, endpoint.getType())).join();
|
||||
|
||||
try {
|
||||
LOGGER.info("Closing endpoint {}", address);
|
||||
|
||||
@@ -56,7 +56,7 @@ public class ServerChannelInitializer extends ChannelInitializer<Channel> {
|
||||
.addLast(LEGACY_PING_DECODER, new LegacyPingDecoder())
|
||||
.addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder())
|
||||
.addLast(READ_TIMEOUT,
|
||||
new ReadTimeoutHandler(this.server.getConfiguration().getReadTimeout(),
|
||||
new ReadTimeoutHandler(this.server.configuration().getReadTimeout(),
|
||||
TimeUnit.MILLISECONDS))
|
||||
.addLast(LEGACY_PING_ENCODER, LegacyPingEncoder.INSTANCE)
|
||||
.addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE)
|
||||
@@ -67,7 +67,7 @@ public class ServerChannelInitializer extends ChannelInitializer<Channel> {
|
||||
connection.setSessionHandler(new HandshakeSessionHandler(connection, this.server));
|
||||
ch.pipeline().addLast(HandlerNames.HANDLER, connection);
|
||||
|
||||
if (this.server.getConfiguration().isProxyProtocol()) {
|
||||
if (this.server.configuration().isProxyProtocol()) {
|
||||
ch.pipeline().addFirst(new HAProxyMessageDecoder());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,12 +205,12 @@ public class ClientboundPlayerListItemPacket implements Packet {
|
||||
}
|
||||
|
||||
public static Item from(TabListEntry entry) {
|
||||
return new Item(entry.getProfile().getId())
|
||||
.setName(entry.getProfile().getName())
|
||||
.setProperties(entry.getProfile().getProperties())
|
||||
.setLatency(entry.getLatency())
|
||||
.setGameMode(entry.getGameMode())
|
||||
.setDisplayName(entry.getDisplayName().orElse(null));
|
||||
return new Item(entry.gameProfile().getId())
|
||||
.setName(entry.gameProfile().getName())
|
||||
.setProperties(entry.gameProfile().getProperties())
|
||||
.setLatency(entry.ping())
|
||||
.setGameMode(entry.gameMode())
|
||||
.setDisplayName(entry.displayName().orElse(null));
|
||||
}
|
||||
|
||||
public @Nullable UUID getUuid() {
|
||||
|
||||
@@ -45,7 +45,7 @@ public class LegacyDisconnectPacket implements LegacyPacket {
|
||||
*/
|
||||
public static LegacyDisconnectPacket fromServerPing(ServerPing response,
|
||||
LegacyMinecraftPingVersion version) {
|
||||
Players players = response.getPlayers().orElse(FAKE_PLAYERS);
|
||||
Players players = response.players().orElse(FAKE_PLAYERS);
|
||||
|
||||
switch (version) {
|
||||
case MINECRAFT_1_3:
|
||||
@@ -54,20 +54,20 @@ public class LegacyDisconnectPacket implements LegacyPacket {
|
||||
// MOTD.
|
||||
return new LegacyDisconnectPacket(String.join(LEGACY_COLOR_CODE,
|
||||
cleanSectionSymbol(getFirstLine(PlainComponentSerializer.plain().serialize(
|
||||
response.getDescription()))),
|
||||
Integer.toString(players.getOnline()),
|
||||
Integer.toString(players.getMax())));
|
||||
response.description()))),
|
||||
Integer.toString(players.online()),
|
||||
Integer.toString(players.maximum())));
|
||||
case MINECRAFT_1_4:
|
||||
case MINECRAFT_1_6:
|
||||
// Minecraft 1.4-1.6 provide support for more fields, and additionally support color codes.
|
||||
return new LegacyDisconnectPacket(String.join("\0",
|
||||
LEGACY_COLOR_CODE + "1",
|
||||
Integer.toString(response.getVersion().getProtocol()),
|
||||
response.getVersion().getName(),
|
||||
Integer.toString(response.version().protocol()),
|
||||
response.version().name(),
|
||||
getFirstLine(LegacyComponentSerializer.legacySection().serialize(response
|
||||
.getDescription())),
|
||||
Integer.toString(players.getOnline()),
|
||||
Integer.toString(players.getMax())
|
||||
.description())),
|
||||
Integer.toString(players.online()),
|
||||
Integer.toString(players.maximum())
|
||||
));
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown version " + version);
|
||||
|
||||
@@ -29,7 +29,7 @@ import io.netty.buffer.ByteBuf;
|
||||
public class ServerboundHandshakePacket implements Packet {
|
||||
public static final PacketReader<ServerboundHandshakePacket> DECODER = (buf, version) -> {
|
||||
int realProtocolVersion = ProtocolUtils.readVarInt(buf);
|
||||
final ProtocolVersion protocolVersion = ProtocolVersion.getProtocolVersion(realProtocolVersion);
|
||||
final ProtocolVersion protocolVersion = ProtocolVersion.byMinecraftProtocolVersion(realProtocolVersion);
|
||||
final String hostname = ProtocolUtils.readString(buf);
|
||||
final int port = buf.readUnsignedShort();
|
||||
final int nextStatus = ProtocolUtils.readVarInt(buf);
|
||||
@@ -54,7 +54,7 @@ public class ServerboundHandshakePacket implements Packet {
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolVersion ignored) {
|
||||
ProtocolUtils.writeVarInt(buf, this.protocolVersion.getProtocol());
|
||||
ProtocolUtils.writeVarInt(buf, this.protocolVersion.protocol());
|
||||
ProtocolUtils.writeString(buf, this.serverAddress);
|
||||
buf.writeShort(this.port);
|
||||
ProtocolUtils.writeVarInt(buf, this.nextStatus);
|
||||
|
||||
@@ -84,18 +84,18 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
|
||||
|
||||
private QueryResponse createInitialResponse() {
|
||||
return QueryResponse.builder()
|
||||
.hostname(PlainComponentSerializer.plain().serialize(server.getConfiguration().getMotd()))
|
||||
.hostname(PlainComponentSerializer.plain().serialize(server.configuration().getMotd()))
|
||||
.gameVersion(ProtocolVersion.SUPPORTED_VERSION_STRING)
|
||||
.map(server.getConfiguration().getQueryMap())
|
||||
.currentPlayers(server.getPlayerCount())
|
||||
.maxPlayers(server.getConfiguration().getShowMaxPlayers())
|
||||
.proxyPort(((InetSocketAddress) server.getConfiguration().getBind()).getPort())
|
||||
.proxyHost(((InetSocketAddress) server.getConfiguration().getBind()).getHostString())
|
||||
.players(server.getAllPlayers().stream().map(Player::getUsername)
|
||||
.map(server.configuration().getQueryMap())
|
||||
.onlinePlayers(server.countConnectedPlayers())
|
||||
.maxPlayers(server.configuration().getShowMaxPlayers())
|
||||
.proxyPort(((InetSocketAddress) server.configuration().getBind()).getPort())
|
||||
.proxyHost(((InetSocketAddress) server.configuration().getBind()).getHostString())
|
||||
.players(server.connectedPlayers().stream().map(Player::username)
|
||||
.collect(Collectors.toList()))
|
||||
.proxyVersion("Velocity")
|
||||
.plugins(
|
||||
server.getConfiguration().shouldQueryShowPlugins() ? getRealPluginInformation()
|
||||
server.configuration().shouldQueryShowPlugins() ? getRealPluginInformation()
|
||||
: Collections.emptyList())
|
||||
.build();
|
||||
}
|
||||
@@ -150,7 +150,7 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
|
||||
boolean isBasic = !queryMessage.isReadable();
|
||||
|
||||
// Call event and write response
|
||||
server.getEventManager()
|
||||
server.eventManager()
|
||||
.fire(new ProxyQueryEventImpl(isBasic ? BASIC : FULL, senderAddress, response))
|
||||
.whenCompleteAsync((event, exc) -> {
|
||||
// Packet header
|
||||
@@ -160,22 +160,22 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
|
||||
|
||||
// Start writing the response
|
||||
ResponseWriter responseWriter = new ResponseWriter(queryResponse, isBasic);
|
||||
responseWriter.write("hostname", event.getResponse().getHostname());
|
||||
responseWriter.write("hostname", event.response().hostname());
|
||||
responseWriter.write("gametype", "SMP");
|
||||
|
||||
responseWriter.write("game_id", "MINECRAFT");
|
||||
responseWriter.write("version", event.getResponse().getGameVersion());
|
||||
responseWriter.writePlugins(event.getResponse().getProxyVersion(),
|
||||
event.getResponse().getPlugins());
|
||||
responseWriter.write("version", event.response().gameVersion());
|
||||
responseWriter.writePlugins(event.response().proxyVersion(),
|
||||
event.response().plugins());
|
||||
|
||||
responseWriter.write("map", event.getResponse().getMap());
|
||||
responseWriter.write("numplayers", event.getResponse().getCurrentPlayers());
|
||||
responseWriter.write("maxplayers", event.getResponse().getMaxPlayers());
|
||||
responseWriter.write("hostport", event.getResponse().getProxyPort());
|
||||
responseWriter.write("hostip", event.getResponse().getProxyHost());
|
||||
responseWriter.write("map", event.response().mapName());
|
||||
responseWriter.write("numplayers", event.response().onlinePlayers());
|
||||
responseWriter.write("maxplayers", event.response().maxPlayers());
|
||||
responseWriter.write("hostport", event.response().proxyPort());
|
||||
responseWriter.write("hostip", event.response().proxyHost());
|
||||
|
||||
if (!responseWriter.isBasic) {
|
||||
responseWriter.writePlayers(event.getResponse().getPlayers());
|
||||
responseWriter.writePlayers(event.response().players());
|
||||
}
|
||||
|
||||
// Send the response
|
||||
@@ -201,10 +201,10 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
|
||||
|
||||
private List<QueryResponse.PluginInformation> getRealPluginInformation() {
|
||||
List<QueryResponse.PluginInformation> result = new ArrayList<>();
|
||||
for (PluginContainer plugin : server.getPluginManager().getPlugins()) {
|
||||
PluginDescription description = plugin.getDescription();
|
||||
result.add(QueryResponse.PluginInformation.of(description.getName()
|
||||
.orElse(description.getId()), description.getVersion().orElse(null)));
|
||||
for (PluginContainer plugin : server.pluginManager().getPlugins()) {
|
||||
PluginDescription description = plugin.description();
|
||||
result.add(QueryResponse.PluginInformation.of(description.name()
|
||||
.orElse(description.id()), description.version().orElse(null)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,6 @@ import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -67,8 +66,8 @@ public class VelocityPluginManager implements PluginManager {
|
||||
}
|
||||
|
||||
private void registerPlugin(PluginContainer plugin) {
|
||||
plugins.put(plugin.getDescription().getId(), plugin);
|
||||
Optional<?> instance = plugin.getInstance();
|
||||
plugins.put(plugin.description().id(), plugin);
|
||||
Optional<?> instance = plugin.instance();
|
||||
instance.ifPresent(o -> pluginInstances.put(o, plugin));
|
||||
}
|
||||
|
||||
@@ -110,9 +109,9 @@ public class VelocityPluginManager implements PluginManager {
|
||||
pluginLoad:
|
||||
for (PluginDescription candidate : sortedPlugins) {
|
||||
// Verify dependencies
|
||||
for (PluginDependency dependency : candidate.getDependencies()) {
|
||||
for (PluginDependency dependency : candidate.dependencies()) {
|
||||
if (!dependency.isOptional() && !loadedPluginsById.contains(dependency.getId())) {
|
||||
logger.error("Can't load plugin {} due to missing dependency {}", candidate.getId(),
|
||||
logger.error("Can't load plugin {} due to missing dependency {}", candidate.id(),
|
||||
dependency.getId());
|
||||
continue pluginLoad;
|
||||
}
|
||||
@@ -122,9 +121,9 @@ public class VelocityPluginManager implements PluginManager {
|
||||
PluginDescription realPlugin = loader.loadPlugin(candidate);
|
||||
VelocityPluginContainer container = new VelocityPluginContainer(realPlugin);
|
||||
pluginContainers.put(container, loader.createModule(container));
|
||||
loadedPluginsById.add(realPlugin.getId());
|
||||
loadedPluginsById.add(realPlugin.id());
|
||||
} catch (Exception e) {
|
||||
logger.error("Can't create module for plugin {}", candidate.getId(), e);
|
||||
logger.error("Can't create module for plugin {}", candidate.id(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,12 +132,12 @@ public class VelocityPluginManager implements PluginManager {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(ProxyServer.class).toInstance(server);
|
||||
bind(PluginManager.class).toInstance(server.getPluginManager());
|
||||
bind(EventManager.class).toInstance(server.getEventManager());
|
||||
bind(CommandManager.class).toInstance(server.getCommandManager());
|
||||
bind(PluginManager.class).toInstance(server.pluginManager());
|
||||
bind(EventManager.class).toInstance(server.eventManager());
|
||||
bind(CommandManager.class).toInstance(server.commandManager());
|
||||
for (PluginContainer container : pluginContainers.keySet()) {
|
||||
bind(PluginContainer.class)
|
||||
.annotatedWith(Names.named(container.getDescription().getId()))
|
||||
.annotatedWith(Names.named(container.description().id()))
|
||||
.toInstance(container);
|
||||
}
|
||||
}
|
||||
@@ -146,17 +145,17 @@ public class VelocityPluginManager implements PluginManager {
|
||||
|
||||
for (Map.Entry<PluginContainer, Module> plugin : pluginContainers.entrySet()) {
|
||||
PluginContainer container = plugin.getKey();
|
||||
PluginDescription description = container.getDescription();
|
||||
PluginDescription description = container.description();
|
||||
|
||||
try {
|
||||
loader.createPlugin(container, plugin.getValue(), commonModule);
|
||||
} catch (Exception e) {
|
||||
logger.error("Can't create plugin {}", description.getId(), e);
|
||||
logger.error("Can't create plugin {}", description.id(), e);
|
||||
continue;
|
||||
}
|
||||
|
||||
logger.info("Loaded plugin {} {} by {}", description.getId(), description.getVersion()
|
||||
.orElse("<UNKNOWN>"), Joiner.on(", ").join(description.getAuthors()));
|
||||
logger.info("Loaded plugin {} {} by {}", description.id(), description.version()
|
||||
.orElse("<UNKNOWN>"), Joiner.on(", ").join(description.authors()));
|
||||
registerPlugin(container);
|
||||
}
|
||||
}
|
||||
@@ -194,7 +193,7 @@ public class VelocityPluginManager implements PluginManager {
|
||||
checkNotNull(path, "path");
|
||||
Optional<PluginContainer> optContainer = fromInstance(plugin);
|
||||
checkArgument(optContainer.isPresent(), "plugin is not loaded");
|
||||
Optional<?> optInstance = optContainer.get().getInstance();
|
||||
Optional<?> optInstance = optContainer.get().instance();
|
||||
checkArgument(optInstance.isPresent(), "plugin has no instance");
|
||||
|
||||
ClassLoader pluginClassloader = optInstance.get().getClass().getClassLoader();
|
||||
|
||||
@@ -31,12 +31,12 @@ public class VelocityPluginContainer implements PluginContainer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginDescription getDescription() {
|
||||
public PluginDescription description() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<?> getInstance() {
|
||||
public Optional<?> instance() {
|
||||
return Optional.ofNullable(instance);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,37 +67,37 @@ public class VelocityPluginDescription implements PluginDescription {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
public String id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getName() {
|
||||
public Optional<String> name() {
|
||||
return Optional.ofNullable(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getVersion() {
|
||||
public Optional<String> version() {
|
||||
return Optional.ofNullable(version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getDescription() {
|
||||
public Optional<String> description() {
|
||||
return Optional.ofNullable(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getUrl() {
|
||||
public Optional<String> url() {
|
||||
return Optional.ofNullable(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAuthors() {
|
||||
public List<String> authors() {
|
||||
return authors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PluginDependency> getDependencies() {
|
||||
public Collection<PluginDependency> dependencies() {
|
||||
return dependencies.values();
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public class VelocityPluginDescription implements PluginDescription {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Path> getSource() {
|
||||
public Optional<Path> file() {
|
||||
return Optional.ofNullable(source);
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ public class JavaPluginLoader implements PluginLoader {
|
||||
throw new IllegalArgumentException("Description provided isn't of the Java plugin loader");
|
||||
}
|
||||
|
||||
URL pluginJarUrl = source.getSource().get().toUri().toURL();
|
||||
URL pluginJarUrl = source.file().get().toUri().toURL();
|
||||
PluginClassLoader loader = AccessController.doPrivileged(
|
||||
(PrivilegedAction<PluginClassLoader>) () -> new PluginClassLoader(new URL[]{pluginJarUrl}));
|
||||
loader.addToClassloaders();
|
||||
@@ -91,13 +91,13 @@ public class JavaPluginLoader implements PluginLoader {
|
||||
|
||||
@Override
|
||||
public Module createModule(PluginContainer container) throws Exception {
|
||||
PluginDescription description = container.getDescription();
|
||||
PluginDescription description = container.description();
|
||||
if (!(description instanceof JavaVelocityPluginDescription)) {
|
||||
throw new IllegalArgumentException("Description provided isn't of the Java plugin loader");
|
||||
}
|
||||
|
||||
JavaVelocityPluginDescription javaDescription = (JavaVelocityPluginDescription) description;
|
||||
Optional<Path> source = javaDescription.getSource();
|
||||
Optional<Path> source = javaDescription.file();
|
||||
|
||||
if (!source.isPresent()) {
|
||||
throw new IllegalArgumentException("No path in plugin description");
|
||||
@@ -111,7 +111,7 @@ public class JavaPluginLoader implements PluginLoader {
|
||||
if (!(container instanceof VelocityPluginContainer)) {
|
||||
throw new IllegalArgumentException("Container provided isn't of the Java plugin loader");
|
||||
}
|
||||
PluginDescription description = container.getDescription();
|
||||
PluginDescription description = container.description();
|
||||
if (!(description instanceof JavaVelocityPluginDescription)) {
|
||||
throw new IllegalArgumentException("Description provided isn't of the Java plugin loader");
|
||||
}
|
||||
@@ -122,7 +122,7 @@ public class JavaPluginLoader implements PluginLoader {
|
||||
|
||||
if (instance == null) {
|
||||
throw new IllegalStateException(
|
||||
"Got nothing from injector for plugin " + description.getId());
|
||||
"Got nothing from injector for plugin " + description.id());
|
||||
}
|
||||
|
||||
((VelocityPluginContainer) container).setInstance(instance);
|
||||
@@ -183,14 +183,14 @@ public class JavaPluginLoader implements PluginLoader {
|
||||
JavaVelocityPluginDescriptionCandidate description,
|
||||
Class mainClass) {
|
||||
return new JavaVelocityPluginDescription(
|
||||
description.getId(),
|
||||
description.getName().orElse(null),
|
||||
description.getVersion().orElse(null),
|
||||
description.getDescription().orElse(null),
|
||||
description.getUrl().orElse(null),
|
||||
description.getAuthors(),
|
||||
description.getDependencies(),
|
||||
description.getSource().orElse(null),
|
||||
description.id(),
|
||||
description.name().orElse(null),
|
||||
description.version().orElse(null),
|
||||
description.description().orElse(null),
|
||||
description.url().orElse(null),
|
||||
description.authors(),
|
||||
description.dependencies(),
|
||||
description.file().orElse(null),
|
||||
mainClass
|
||||
);
|
||||
}
|
||||
|
||||
@@ -47,9 +47,9 @@ class VelocityPluginModule implements Module {
|
||||
public void configure(Binder binder) {
|
||||
binder.bind(description.getMainClass()).in(Scopes.SINGLETON);
|
||||
|
||||
binder.bind(Logger.class).toInstance(LoggerFactory.getLogger(description.getId()));
|
||||
binder.bind(Logger.class).toInstance(LoggerFactory.getLogger(description.id()));
|
||||
binder.bind(Path.class).annotatedWith(DataDirectory.class)
|
||||
.toInstance(basePluginPath.resolve(description.getId()));
|
||||
.toInstance(basePluginPath.resolve(description.id()));
|
||||
binder.bind(PluginDescription.class).toInstance(description);
|
||||
binder.bind(PluginContainer.class).toInstance(pluginContainer);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class PluginDependencyUtils {
|
||||
*/
|
||||
public static List<PluginDescription> sortCandidates(List<PluginDescription> candidates) {
|
||||
List<PluginDescription> sortedCandidates = new ArrayList<>(candidates);
|
||||
sortedCandidates.sort(Comparator.comparing(PluginDescription::getId));
|
||||
sortedCandidates.sort(Comparator.comparing(PluginDescription::id));
|
||||
|
||||
// Create a graph and populate it with plugin dependencies. Specifically, each graph has plugin
|
||||
// nodes, and edges that represent the dependencies that plugin relies on. Non-existent plugins
|
||||
@@ -57,12 +57,12 @@ public class PluginDependencyUtils {
|
||||
.expectedNodeCount(sortedCandidates.size())
|
||||
.build();
|
||||
Map<String, PluginDescription> candidateMap = Maps.uniqueIndex(sortedCandidates,
|
||||
PluginDescription::getId);
|
||||
PluginDescription::id);
|
||||
|
||||
for (PluginDescription description : sortedCandidates) {
|
||||
graph.addNode(description);
|
||||
|
||||
for (PluginDependency dependency : description.getDependencies()) {
|
||||
for (PluginDependency dependency : description.dependencies()) {
|
||||
PluginDescription in = candidateMap.get(dependency.getId());
|
||||
|
||||
if (in != null) {
|
||||
@@ -93,7 +93,7 @@ public class PluginDependencyUtils {
|
||||
currentIteration.addLast(node);
|
||||
StringBuilder loopGraph = new StringBuilder();
|
||||
for (PluginDescription description : currentIteration) {
|
||||
loopGraph.append(description.getId());
|
||||
loopGraph.append(description.id());
|
||||
loopGraph.append(" -> ");
|
||||
}
|
||||
loopGraph.setLength(loopGraph.length() - 4);
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Multimaps;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import com.velocitypowered.api.plugin.PluginContainer;
|
||||
import com.velocitypowered.api.plugin.PluginManager;
|
||||
import com.velocitypowered.api.scheduler.ScheduledTask;
|
||||
import com.velocitypowered.api.scheduler.Scheduler;
|
||||
@@ -207,8 +206,8 @@ public class VelocityScheduler implements Scheduler {
|
||||
Thread.currentThread().interrupt();
|
||||
} else {
|
||||
String friendlyPluginName = pluginManager.fromInstance(plugin)
|
||||
.map(container -> container.getDescription().getName()
|
||||
.orElse(container.getDescription().getId()))
|
||||
.map(container -> container.description().name()
|
||||
.orElse(container.description().id()))
|
||||
.orElse("UNKNOWN");
|
||||
Log.logger.error("Exception in task {} by plugin {}", runnable, friendlyPluginName,
|
||||
e);
|
||||
|
||||
@@ -53,7 +53,7 @@ public class PingSessionHandler implements MinecraftSessionHandler {
|
||||
ServerboundHandshakePacket handshake = new ServerboundHandshakePacket();
|
||||
handshake.setNextStatus(StateRegistry.STATUS_ID);
|
||||
|
||||
SocketAddress address = server.getServerInfo().getAddress();
|
||||
SocketAddress address = server.serverInfo().address();
|
||||
if (address instanceof InetSocketAddress) {
|
||||
InetSocketAddress socketAddr = (InetSocketAddress) address;
|
||||
handshake.setServerAddress(socketAddr.getHostString());
|
||||
|
||||
@@ -62,13 +62,13 @@ public class ServerMap {
|
||||
*/
|
||||
public RegisteredServer register(ServerInfo serverInfo) {
|
||||
Preconditions.checkNotNull(serverInfo, "serverInfo");
|
||||
String lowerName = serverInfo.getName().toLowerCase(Locale.US);
|
||||
String lowerName = serverInfo.name().toLowerCase(Locale.US);
|
||||
VelocityRegisteredServer rs = new VelocityRegisteredServer(server, serverInfo);
|
||||
|
||||
RegisteredServer existing = servers.putIfAbsent(lowerName, rs);
|
||||
if (existing != null && !existing.getServerInfo().equals(serverInfo)) {
|
||||
if (existing != null && !existing.serverInfo().equals(serverInfo)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Server with name " + serverInfo.getName() + " already registered");
|
||||
"Server with name " + serverInfo.name() + " already registered");
|
||||
} else if (existing == null) {
|
||||
return rs;
|
||||
} else {
|
||||
@@ -83,15 +83,15 @@ public class ServerMap {
|
||||
*/
|
||||
public void unregister(ServerInfo serverInfo) {
|
||||
Preconditions.checkNotNull(serverInfo, "serverInfo");
|
||||
String lowerName = serverInfo.getName().toLowerCase(Locale.US);
|
||||
String lowerName = serverInfo.name().toLowerCase(Locale.US);
|
||||
RegisteredServer rs = servers.get(lowerName);
|
||||
if (rs == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Server with name " + serverInfo.getName() + " is not registered!");
|
||||
"Server with name " + serverInfo.name() + " is not registered!");
|
||||
}
|
||||
Preconditions.checkArgument(rs.getServerInfo().equals(serverInfo),
|
||||
"Trying to remove server %s with differing information", serverInfo.getName());
|
||||
Preconditions.checkArgument(rs.serverInfo().equals(serverInfo),
|
||||
"Trying to remove server %s with differing information", serverInfo.name());
|
||||
Preconditions.checkState(servers.remove(lowerName, rs),
|
||||
"Server with name %s replaced whilst unregistering", serverInfo.getName());
|
||||
"Server with name %s replaced whilst unregistering", serverInfo.name());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,12 +71,12 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerInfo getServerInfo() {
|
||||
public ServerInfo serverInfo() {
|
||||
return serverInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Player> getPlayersConnected() {
|
||||
public Collection<Player> connectedPlayers() {
|
||||
return ImmutableList.copyOf(players.values());
|
||||
}
|
||||
|
||||
@@ -97,14 +97,14 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud
|
||||
throw new IllegalStateException("No Velocity proxy instance available");
|
||||
}
|
||||
CompletableFuture<ServerPing> pingFuture = new CompletableFuture<>();
|
||||
server.createBootstrap(loop, serverInfo.getAddress())
|
||||
server.createBootstrap(loop, serverInfo.address())
|
||||
.handler(new ChannelInitializer<Channel>() {
|
||||
@Override
|
||||
protected void initChannel(Channel ch) throws Exception {
|
||||
ch.pipeline()
|
||||
.addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder())
|
||||
.addLast(READ_TIMEOUT,
|
||||
new ReadTimeoutHandler(server.getConfiguration().getReadTimeout(),
|
||||
new ReadTimeoutHandler(server.configuration().getReadTimeout(),
|
||||
TimeUnit.MILLISECONDS))
|
||||
.addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE)
|
||||
.addLast(MINECRAFT_DECODER,
|
||||
@@ -115,7 +115,7 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud
|
||||
ch.pipeline().addLast(HANDLER, new MinecraftConnection(ch, server));
|
||||
}
|
||||
})
|
||||
.connect(serverInfo.getAddress())
|
||||
.connect(serverInfo.address())
|
||||
.addListener((ChannelFutureListener) future -> {
|
||||
if (future.isSuccess()) {
|
||||
MinecraftConnection conn = future.channel().pipeline().get(MinecraftConnection.class);
|
||||
@@ -129,11 +129,11 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud
|
||||
}
|
||||
|
||||
public void addPlayer(ConnectedPlayer player) {
|
||||
players.put(player.getUniqueId(), player);
|
||||
players.put(player.id(), player);
|
||||
}
|
||||
|
||||
public void removePlayer(ConnectedPlayer player) {
|
||||
players.remove(player.getUniqueId(), player);
|
||||
players.remove(player.id(), player);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -152,7 +152,7 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud
|
||||
public boolean sendPluginMessage(ChannelIdentifier identifier, ByteBuf data) {
|
||||
for (ConnectedPlayer player : players.values()) {
|
||||
VelocityServerConnection connection = player.getConnectedServer();
|
||||
if (connection != null && connection.getServer() == this) {
|
||||
if (connection != null && connection.target() == this) {
|
||||
return connection.sendPluginMessage(identifier, data);
|
||||
}
|
||||
}
|
||||
@@ -168,6 +168,6 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud
|
||||
|
||||
@Override
|
||||
public @NonNull Iterable<? extends Audience> audiences() {
|
||||
return this.getPlayersConnected();
|
||||
return this.connectedPlayers();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,16 +69,16 @@ public class VelocityTabList implements TabList {
|
||||
@Override
|
||||
public void addEntry(TabListEntry entry) {
|
||||
Preconditions.checkNotNull(entry, "entry");
|
||||
Preconditions.checkArgument(entry.getTabList().equals(this),
|
||||
Preconditions.checkArgument(entry.parent().equals(this),
|
||||
"The provided entry was not created by this tab list");
|
||||
Preconditions.checkArgument(!entries.containsKey(entry.getProfile().getId()),
|
||||
Preconditions.checkArgument(!entries.containsKey(entry.gameProfile().getId()),
|
||||
"this TabList already contains an entry with the same uuid");
|
||||
Preconditions.checkArgument(entry instanceof VelocityTabListEntry,
|
||||
"Not a Velocity tab list entry");
|
||||
|
||||
connection.write(new ClientboundPlayerListItemPacket(ClientboundPlayerListItemPacket.ADD_PLAYER,
|
||||
Collections.singletonList(ClientboundPlayerListItemPacket.Item.from(entry))));
|
||||
entries.put(entry.getProfile().getId(), (VelocityTabListEntry) entry);
|
||||
entries.put(entry.gameProfile().getId(), (VelocityTabListEntry) entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -122,7 +122,7 @@ public class VelocityTabList implements TabList {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<TabListEntry> getEntries() {
|
||||
public Collection<TabListEntry> entries() {
|
||||
return Collections.unmodifiableCollection(this.entries.values());
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ public class VelocityTabList implements TabList {
|
||||
}
|
||||
|
||||
void updateEntry(int action, TabListEntry entry) {
|
||||
if (entries.containsKey(entry.getProfile().getId())) {
|
||||
if (entries.containsKey(entry.gameProfile().getId())) {
|
||||
connection.write(new ClientboundPlayerListItemPacket(action,
|
||||
Collections.singletonList(ClientboundPlayerListItemPacket.Item.from(entry))));
|
||||
}
|
||||
|
||||
@@ -43,17 +43,17 @@ public class VelocityTabListEntry implements TabListEntry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TabList getTabList() {
|
||||
public TabList parent() {
|
||||
return tabList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameProfile getProfile() {
|
||||
public GameProfile gameProfile() {
|
||||
return profile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Component> getDisplayName() {
|
||||
public Optional<Component> displayName() {
|
||||
return Optional.ofNullable(displayName);
|
||||
}
|
||||
|
||||
@@ -69,12 +69,12 @@ public class VelocityTabListEntry implements TabListEntry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLatency() {
|
||||
public int ping() {
|
||||
return latency;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TabListEntry setLatency(int latency) {
|
||||
public TabListEntry setPing(int latency) {
|
||||
this.latency = latency;
|
||||
tabList.updateEntry(ClientboundPlayerListItemPacket.UPDATE_LATENCY, this);
|
||||
return this;
|
||||
@@ -85,7 +85,7 @@ public class VelocityTabListEntry implements TabListEntry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGameMode() {
|
||||
public int gameMode() {
|
||||
return gameMode;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public class VelocityTabListEntryLegacy extends VelocityTabListEntry {
|
||||
|
||||
@Override
|
||||
public TabListEntry setDisplayName(@Nullable Component displayName) {
|
||||
getTabList().removeEntry(getProfile().getId()); // We have to remove first if updating
|
||||
parent().removeEntry(gameProfile().getId()); // We have to remove first if updating
|
||||
return super.setDisplayName(displayName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,13 +50,13 @@ public class VelocityTabListLegacy extends VelocityTabList {
|
||||
@Override
|
||||
public void addEntry(TabListEntry entry) {
|
||||
super.addEntry(entry);
|
||||
nameMapping.put(entry.getProfile().getName(), entry.getProfile().getId());
|
||||
nameMapping.put(entry.gameProfile().getName(), entry.gameProfile().getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<TabListEntry> removeEntry(UUID uuid) {
|
||||
Optional<TabListEntry> entry = super.removeEntry(uuid);
|
||||
entry.map(TabListEntry::getProfile).map(GameProfile::getName).ifPresent(nameMapping::remove);
|
||||
entry.map(TabListEntry::gameProfile).map(GameProfile::getName).ifPresent(nameMapping::remove);
|
||||
return entry;
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ public class VelocityTabListLegacy extends VelocityTabList {
|
||||
|
||||
@Override
|
||||
void updateEntry(int action, TabListEntry entry) {
|
||||
if (entries.containsKey(entry.getProfile().getId())) {
|
||||
if (entries.containsKey(entry.gameProfile().getId())) {
|
||||
switch (action) {
|
||||
case ClientboundPlayerListItemPacket.UPDATE_LATENCY:
|
||||
case ClientboundPlayerListItemPacket.UPDATE_DISPLAY_NAME: // Add here because we
|
||||
|
||||
@@ -53,35 +53,35 @@ public enum InformationUtils {
|
||||
*/
|
||||
public static JsonArray collectPluginInfo(ProxyServer proxy) {
|
||||
List<PluginContainer> allPlugins = ImmutableList.copyOf(
|
||||
proxy.getPluginManager().getPlugins());
|
||||
proxy.pluginManager().getPlugins());
|
||||
JsonArray plugins = new JsonArray();
|
||||
|
||||
for (PluginContainer plugin : allPlugins) {
|
||||
PluginDescription desc = plugin.getDescription();
|
||||
PluginDescription desc = plugin.description();
|
||||
JsonObject current = new JsonObject();
|
||||
current.addProperty("id", desc.getId());
|
||||
if (desc.getName().isPresent()) {
|
||||
current.addProperty("name", desc.getName().get());
|
||||
current.addProperty("id", desc.id());
|
||||
if (desc.name().isPresent()) {
|
||||
current.addProperty("name", desc.name().get());
|
||||
}
|
||||
if (desc.getVersion().isPresent()) {
|
||||
current.addProperty("version", desc.getVersion().get());
|
||||
if (desc.version().isPresent()) {
|
||||
current.addProperty("version", desc.version().get());
|
||||
}
|
||||
if (!desc.getAuthors().isEmpty()) {
|
||||
if (!desc.authors().isEmpty()) {
|
||||
JsonArray authorsArray = new JsonArray();
|
||||
for (String author : desc.getAuthors()) {
|
||||
for (String author : desc.authors()) {
|
||||
authorsArray.add(author);
|
||||
}
|
||||
current.add("authors", authorsArray);
|
||||
}
|
||||
if (desc.getDescription().isPresent()) {
|
||||
current.addProperty("description", desc.getDescription().get());
|
||||
if (desc.description().isPresent()) {
|
||||
current.addProperty("description", desc.description().get());
|
||||
}
|
||||
if (desc.getUrl().isPresent()) {
|
||||
current.addProperty("url", desc.getUrl().get());
|
||||
if (desc.url().isPresent()) {
|
||||
current.addProperty("url", desc.url().get());
|
||||
}
|
||||
if (!desc.getDependencies().isEmpty()) {
|
||||
if (!desc.dependencies().isEmpty()) {
|
||||
JsonArray dependencies = new JsonArray();
|
||||
for (PluginDependency dependency : desc.getDependencies()) {
|
||||
for (PluginDependency dependency : desc.dependencies()) {
|
||||
dependencies.add(dependency.getId());
|
||||
}
|
||||
current.add("dependencies", dependencies);
|
||||
@@ -185,8 +185,8 @@ public enum InformationUtils {
|
||||
*/
|
||||
public static JsonObject collectServerInfo(RegisteredServer server) {
|
||||
JsonObject info = new JsonObject();
|
||||
info.addProperty("currentPlayers", server.getPlayersConnected().size());
|
||||
SocketAddress address = server.getServerInfo().getAddress();
|
||||
info.addProperty("currentPlayers", server.connectedPlayers().size());
|
||||
SocketAddress address = server.serverInfo().address();
|
||||
if (address instanceof InetSocketAddress) {
|
||||
InetSocketAddress iaddr = (InetSocketAddress) address;
|
||||
if (iaddr.isUnresolved()) {
|
||||
|
||||
@@ -43,10 +43,10 @@ public class VelocityChannelRegistrar implements ChannelRegistrar {
|
||||
|
||||
for (ChannelIdentifier identifier : identifiers) {
|
||||
if (identifier instanceof MinecraftChannelIdentifier) {
|
||||
identifierMap.put(identifier.getId(), identifier);
|
||||
identifierMap.put(identifier.id(), identifier);
|
||||
} else {
|
||||
String rewritten = PluginMessageUtil.transformLegacyToModernChannel(identifier.getId());
|
||||
identifierMap.put(identifier.getId(), identifier);
|
||||
String rewritten = PluginMessageUtil.transformLegacyToModernChannel(identifier.id());
|
||||
identifierMap.put(identifier.id(), identifier);
|
||||
identifierMap.put(rewritten, identifier);
|
||||
}
|
||||
}
|
||||
@@ -62,10 +62,10 @@ public class VelocityChannelRegistrar implements ChannelRegistrar {
|
||||
|
||||
for (ChannelIdentifier identifier : identifiers) {
|
||||
if (identifier instanceof MinecraftChannelIdentifier) {
|
||||
identifierMap.remove(identifier.getId());
|
||||
identifierMap.remove(identifier.id());
|
||||
} else {
|
||||
String rewritten = PluginMessageUtil.transformLegacyToModernChannel(identifier.getId());
|
||||
identifierMap.remove(identifier.getId());
|
||||
String rewritten = PluginMessageUtil.transformLegacyToModernChannel(identifier.id());
|
||||
identifierMap.remove(identifier.id());
|
||||
identifierMap.remove(rewritten);
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ public class VelocityChannelRegistrar implements ChannelRegistrar {
|
||||
public Collection<String> getLegacyChannelIds() {
|
||||
Collection<String> ids = new HashSet<>();
|
||||
for (ChannelIdentifier value : identifierMap.values()) {
|
||||
ids.add(value.getId());
|
||||
ids.add(value.id());
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
@@ -93,9 +93,9 @@ public class VelocityChannelRegistrar implements ChannelRegistrar {
|
||||
Collection<String> ids = new HashSet<>();
|
||||
for (ChannelIdentifier value : identifierMap.values()) {
|
||||
if (value instanceof MinecraftChannelIdentifier) {
|
||||
ids.add(value.getId());
|
||||
ids.add(value.id());
|
||||
} else {
|
||||
ids.add(PluginMessageUtil.transformLegacyToModernChannel(value.getId()));
|
||||
ids.add(PluginMessageUtil.transformLegacyToModernChannel(value.id()));
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
|
||||
@@ -101,7 +101,7 @@ public class AdventureBossBarManager implements BossBar.Listener {
|
||||
public void addBossBar(ConnectedPlayer player, BossBar bar) {
|
||||
BossBarHolder holder = this.getOrCreateHandler(bar);
|
||||
if (holder.subscribers.add(player)) {
|
||||
player.getConnection().write(holder.createAddPacket(player.getProtocolVersion()));
|
||||
player.getConnection().write(holder.createAddPacket(player.protocolVersion()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ public class AdventureBossBarManager implements BossBar.Listener {
|
||||
ClientboundBossBarPacket rgbPacket = holder.createTitleUpdate(
|
||||
newName, ProtocolVersion.MINECRAFT_1_16);
|
||||
for (ConnectedPlayer player : holder.subscribers) {
|
||||
if (player.getProtocolVersion().gte(ProtocolVersion.MINECRAFT_1_16)) {
|
||||
if (player.protocolVersion().gte(ProtocolVersion.MINECRAFT_1_16)) {
|
||||
player.getConnection().write(rgbPacket);
|
||||
} else {
|
||||
player.getConnection().write(pre116Packet);
|
||||
|
||||
@@ -94,8 +94,8 @@ public class CommandManagerTests {
|
||||
.aliases("baZ")
|
||||
.build();
|
||||
|
||||
assertEquals(ImmutableSet.of("bar", "baz"), meta.getAliases());
|
||||
assertTrue(meta.getHints().isEmpty());
|
||||
assertEquals(ImmutableSet.of("bar", "baz"), meta.aliases());
|
||||
assertTrue(meta.hints().isEmpty());
|
||||
manager.register(meta, aliasesCommand);
|
||||
assertTrue(manager.hasCommand("bAr"));
|
||||
assertTrue(manager.hasCommand("Baz"));
|
||||
|
||||
@@ -25,7 +25,7 @@ public class MockCommandSource implements CommandSource {
|
||||
public static final CommandSource INSTANCE = new MockCommandSource();
|
||||
|
||||
@Override
|
||||
public Tristate getPermissionValue(final String permission) {
|
||||
public Tristate evaluatePermission(final String permission) {
|
||||
return Tristate.UNDEFINED;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,12 +83,12 @@ public class FakePluginManager implements PluginManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull PluginDescription getDescription() {
|
||||
public @NonNull PluginDescription description() {
|
||||
return () -> id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<?> getInstance() {
|
||||
public Optional<?> instance() {
|
||||
return Optional.of(instance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,9 +45,9 @@ class VelocityChannelRegistrarTest {
|
||||
|
||||
// Two channels cover the modern channel (velocity:test) and the legacy-mapped channel
|
||||
// (legacy:velocitytest). Make sure they're what we expect.
|
||||
assertEquals(ImmutableSet.of(MODERN.getId(), SIMPLE_LEGACY_REMAPPED), registrar
|
||||
assertEquals(ImmutableSet.of(MODERN.id(), SIMPLE_LEGACY_REMAPPED), registrar
|
||||
.getModernChannelIds());
|
||||
assertEquals(ImmutableSet.of(SIMPLE_LEGACY.getId(), MODERN.getId()), registrar
|
||||
assertEquals(ImmutableSet.of(SIMPLE_LEGACY.id(), MODERN.id()), registrar
|
||||
.getLegacyChannelIds());
|
||||
}
|
||||
|
||||
@@ -57,8 +57,8 @@ class VelocityChannelRegistrarTest {
|
||||
registrar.register(SPECIAL_REMAP_LEGACY, MODERN_SPECIAL_REMAP);
|
||||
|
||||
// This one, just one channel for the modern case.
|
||||
assertEquals(ImmutableSet.of(MODERN_SPECIAL_REMAP.getId()), registrar.getModernChannelIds());
|
||||
assertEquals(ImmutableSet.of(MODERN_SPECIAL_REMAP.getId(), SPECIAL_REMAP_LEGACY.getId()),
|
||||
assertEquals(ImmutableSet.of(MODERN_SPECIAL_REMAP.id()), registrar.getModernChannelIds());
|
||||
assertEquals(ImmutableSet.of(MODERN_SPECIAL_REMAP.id(), SPECIAL_REMAP_LEGACY.id()),
|
||||
registrar.getLegacyChannelIds());
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ class VelocityChannelRegistrarTest {
|
||||
registrar.register(MODERN, SIMPLE_LEGACY);
|
||||
registrar.unregister(SIMPLE_LEGACY);
|
||||
|
||||
assertEquals(ImmutableSet.of(MODERN.getId()), registrar.getModernChannelIds());
|
||||
assertEquals(ImmutableSet.of(MODERN.getId()), registrar.getLegacyChannelIds());
|
||||
assertEquals(ImmutableSet.of(MODERN.id()), registrar.getModernChannelIds());
|
||||
assertEquals(ImmutableSet.of(MODERN.id()), registrar.getLegacyChannelIds());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user