13
0
geforkt von Mirrors/Velocity

Merge pull request #367 from VelocityPowered/adventure-1

Update for Adventure changes
Dieser Commit ist enthalten in:
Andrew Steinborn 2020-09-28 12:54:58 -04:00 committet von GitHub
Commit 65cab85b50
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
11 geänderte Dateien mit 81 neuen und 73 gelöschten Zeilen

Datei anzeigen

@ -344,14 +344,14 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
player.createConnectionRequest(next.get()).connectWithIndication()
.whenComplete((success, ex) -> {
if (ex != null || success == null || !success) {
player.disconnect(TextComponent.of("Your server has been changed, but we could "
player.disconnect(Component.text("Your server has been changed, but we could "
+ "not move you to any fallback servers."));
}
latch.countDown();
});
} else {
latch.countDown();
player.disconnect(TextComponent.of("Your server has been changed, but we could "
player.disconnect(Component.text("Your server has been changed, but we could "
+ "not move you to any fallback servers."));
}
}
@ -466,7 +466,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
* @param explicitExit whether the user explicitly shut down the proxy
*/
public void shutdown(boolean explicitExit) {
shutdown(explicitExit, TextComponent.of("Proxy shutting down."));
shutdown(explicitExit, Component.text("Proxy shutting down."));
}
@Override
@ -520,7 +520,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
} else {
ConnectedPlayer existing = connectionsByUuid.get(connection.getUniqueId());
if (existing != null) {
existing.disconnect(TranslatableComponent.of("multiplayer.disconnect.duplicate_login"));
existing.disconnect(Component.translatable("multiplayer.disconnect.duplicate_login"));
}
// We can now replace the entries as needed.

Datei anzeigen

@ -24,6 +24,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.CompletableFuture;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;
@ -161,7 +162,7 @@ public class VelocityCommandManager implements CommandManager {
boolean isSyntaxError = !e.getType().equals(
CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownCommand());
if (isSyntaxError) {
source.sendMessage(TextComponent.of(e.getMessage(), NamedTextColor.RED));
source.sendMessage(Component.text(e.getMessage(), NamedTextColor.RED));
// This is, of course, a lie, but the API will need to change...
return true;
} else {

Datei anzeigen

@ -17,6 +17,7 @@ import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import java.util.List;
import java.util.Optional;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;
@ -59,9 +60,10 @@ public class GlistCommand {
final CommandSource source = context.getSource();
sendTotalProxyCount(source);
source.sendMessage(
TextComponent.builder("To view all players on servers, use ", NamedTextColor.YELLOW)
.append("/glist all", NamedTextColor.DARK_AQUA)
.append(".", NamedTextColor.YELLOW)
Component.text().content("To view all players on servers, use ")
.color(NamedTextColor.YELLOW)
.append(Component.text("/glist all", NamedTextColor.DARK_AQUA))
.append(Component.text(".", NamedTextColor.YELLOW))
.build());
return 1;
}
@ -78,7 +80,7 @@ public class GlistCommand {
Optional<RegisteredServer> registeredServer = server.getServer(serverName);
if (!registeredServer.isPresent()) {
source.sendMessage(
TextComponent.of("Server " + serverName + " doesn't exist.", NamedTextColor.RED));
Component.text("Server " + serverName + " doesn't exist.", NamedTextColor.RED));
return -1;
}
sendServerPlayers(source, registeredServer.get(), false);
@ -87,9 +89,9 @@ public class GlistCommand {
}
private void sendTotalProxyCount(CommandSource target) {
target.sendMessage(TextComponent.builder("There are ", NamedTextColor.YELLOW)
.append(Integer.toString(server.getAllPlayers().size()), NamedTextColor.GREEN)
.append(" player(s) online.", NamedTextColor.YELLOW)
target.sendMessage(Component.text().content("There are ").color(NamedTextColor.YELLOW)
.append(Component.text(server.getAllPlayers().size(), NamedTextColor.GREEN))
.append(Component.text(" player(s) online.", NamedTextColor.YELLOW))
.build());
}
@ -99,11 +101,11 @@ public class GlistCommand {
return;
}
TextComponent.Builder builder = TextComponent.builder()
TextComponent.Builder builder = Component.text()
.append(TextComponent.of("[" + server.getServerInfo().getName() + "] ",
NamedTextColor.DARK_AQUA))
.append("(" + onServer.size() + ")", NamedTextColor.GRAY)
.append(": ")
.append(Component.text("(" + onServer.size() + ")", NamedTextColor.GRAY))
.append(Component.text(": "))
.resetStyle();
for (int i = 0; i < onServer.size(); i++) {
@ -111,7 +113,7 @@ public class GlistCommand {
builder.append(player.getUsername());
if (i + 1 < onServer.size()) {
builder.append(", ");
builder.append(Component.text(", "));
}
}

Datei anzeigen

@ -15,6 +15,7 @@ import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.format.NamedTextColor;
@ -34,7 +35,7 @@ public class ServerCommand implements SimpleCommand {
final String[] args = invocation.arguments();
if (!(source instanceof Player)) {
source.sendMessage(TextComponent.of("Only players may run this command.",
source.sendMessage(Component.text("Only players may run this command.",
NamedTextColor.RED));
return;
}
@ -46,7 +47,7 @@ public class ServerCommand implements SimpleCommand {
Optional<RegisteredServer> toConnect = server.getServer(serverName);
if (!toConnect.isPresent()) {
player.sendMessage(
TextComponent.of("Server " + serverName + " doesn't exist.", NamedTextColor.RED));
Component.text("Server " + serverName + " doesn't exist.", NamedTextColor.RED));
return;
}
@ -59,24 +60,24 @@ public class ServerCommand implements SimpleCommand {
private void outputServerInformation(Player executor) {
String currentServer = executor.getCurrentServer().map(ServerConnection::getServerInfo)
.map(ServerInfo::getName).orElse("<unknown>");
executor.sendMessage(TextComponent.of("You are currently connected to " + currentServer + ".",
executor.sendMessage(Component.text("You are currently connected to " + currentServer + ".",
NamedTextColor.YELLOW));
List<RegisteredServer> servers = BuiltinCommandUtil.sortedServerList(server);
if (servers.size() > MAX_SERVERS_TO_LIST) {
executor.sendMessage(TextComponent.of(
executor.sendMessage(Component.text(
"Too many servers to list. Tab-complete to show all servers.", NamedTextColor.RED));
return;
}
// Assemble the list of servers as components
TextComponent.Builder serverListBuilder = TextComponent.builder("Available servers: ")
TextComponent.Builder serverListBuilder = Component.text().content("Available servers: ")
.color(NamedTextColor.YELLOW);
for (int i = 0; i < servers.size(); i++) {
RegisteredServer rs = servers.get(i);
serverListBuilder.append(formatServerComponent(currentServer, rs));
if (i != servers.size() - 1) {
serverListBuilder.append(TextComponent.of(", ", NamedTextColor.GRAY));
serverListBuilder.append(Component.text(", ", NamedTextColor.GRAY));
}
}
@ -85,19 +86,19 @@ public class ServerCommand implements SimpleCommand {
private TextComponent formatServerComponent(String currentPlayerServer, RegisteredServer server) {
ServerInfo serverInfo = server.getServerInfo();
TextComponent serverTextComponent = TextComponent.of(serverInfo.getName());
TextComponent serverTextComponent = Component.text(serverInfo.getName());
String playersText = server.getPlayersConnected().size() + " player(s) online";
if (serverInfo.getName().equals(currentPlayerServer)) {
serverTextComponent = serverTextComponent.color(NamedTextColor.GREEN)
.hoverEvent(
showText(TextComponent.of("Currently connected to this server\n" + playersText))
showText(Component.text("Currently connected to this server\n" + playersText))
);
} else {
serverTextComponent = serverTextComponent.color(NamedTextColor.GRAY)
.clickEvent(ClickEvent.runCommand("/server " + serverInfo.getName()))
.hoverEvent(
showText(TextComponent.of("Click to connect to this server\n" + playersText))
showText(Component.text("Click to connect to this server\n" + playersText))
);
}
return serverTextComponent;

Datei anzeigen

@ -16,6 +16,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent;
@ -59,7 +60,7 @@ public class VelocityCommand implements SimpleCommand {
.map(Map.Entry::getKey)
.collect(Collectors.joining("|"));
String commandText = "/velocity <" + availableCommands + ">";
source.sendMessage(TextComponent.of(commandText, NamedTextColor.RED));
source.sendMessage(Component.text(commandText, NamedTextColor.RED));
}
@Override
@ -142,15 +143,15 @@ public class VelocityCommand implements SimpleCommand {
public void execute(CommandSource source, String @NonNull [] args) {
try {
if (server.reloadConfiguration()) {
source.sendMessage(TextComponent.of("Configuration reloaded.", NamedTextColor.GREEN));
source.sendMessage(Component.text("Configuration reloaded.", NamedTextColor.GREEN));
} else {
source.sendMessage(TextComponent.of(
source.sendMessage(Component.text(
"Unable to reload your configuration. Check the console for more details.",
NamedTextColor.RED));
}
} catch (Exception e) {
logger.error("Unable to reload configuration", e);
source.sendMessage(TextComponent.of(
source.sendMessage(Component.text(
"Unable to reload your configuration. Check the console for more details.",
NamedTextColor.RED));
}
@ -173,16 +174,16 @@ public class VelocityCommand implements SimpleCommand {
@Override
public void execute(CommandSource source, String @NonNull [] args) {
if (args.length != 0) {
source.sendMessage(TextComponent.of("/velocity version", NamedTextColor.RED));
source.sendMessage(Component.text("/velocity version", NamedTextColor.RED));
return;
}
ProxyVersion version = server.getVersion();
TextComponent velocity = TextComponent.builder(version.getName() + " ")
TextComponent velocity = Component.text().content(version.getName() + " ")
.decoration(TextDecoration.BOLD, true)
.color(NamedTextColor.DARK_AQUA)
.append(TextComponent.of(version.getVersion()).decoration(TextDecoration.BOLD, false))
.append(Component.text(version.getVersion()).decoration(TextDecoration.BOLD, false))
.build();
TextComponent copyright = TextComponent
.of("Copyright 2018-2020 " + version.getVendor() + ". " + version.getName()
@ -191,15 +192,15 @@ public class VelocityCommand implements SimpleCommand {
source.sendMessage(copyright);
if (version.getName().equals("Velocity")) {
TextComponent velocityWebsite = TextComponent.builder()
TextComponent velocityWebsite = Component.text()
.content("Visit the ")
.append(TextComponent.builder("Velocity website")
.append(Component.text().content("Velocity website")
.color(NamedTextColor.GREEN)
.clickEvent(
ClickEvent.openUrl("https://www.velocitypowered.com"))
.build())
.append(TextComponent.of(" or the "))
.append(TextComponent.builder("Velocity GitHub")
.append(Component.text(" or the "))
.append(Component.text().content("Velocity GitHub")
.color(NamedTextColor.GREEN)
.clickEvent(ClickEvent.openUrl(
"https://github.com/VelocityPowered/Velocity"))
@ -226,7 +227,7 @@ public class VelocityCommand implements SimpleCommand {
@Override
public void execute(CommandSource source, String @NonNull [] args) {
if (args.length != 0) {
source.sendMessage(TextComponent.of("/velocity plugins", NamedTextColor.RED));
source.sendMessage(Component.text("/velocity plugins", NamedTextColor.RED));
return;
}
@ -234,17 +235,17 @@ public class VelocityCommand implements SimpleCommand {
int pluginCount = plugins.size();
if (pluginCount == 0) {
source.sendMessage(TextComponent.of("No plugins installed.", NamedTextColor.YELLOW));
source.sendMessage(Component.text("No plugins installed.", NamedTextColor.YELLOW));
return;
}
TextComponent.Builder output = TextComponent.builder("Plugins: ")
TextComponent.Builder output = Component.text().content("Plugins: ")
.color(NamedTextColor.YELLOW);
for (int i = 0; i < pluginCount; i++) {
PluginContainer plugin = plugins.get(i);
output.append(componentForPlugin(plugin.getDescription()));
if (i + 1 < pluginCount) {
output.append(TextComponent.of(", "));
output.append(Component.text(", "));
}
}
@ -255,28 +256,28 @@ public class VelocityCommand implements SimpleCommand {
String pluginInfo = description.getName().orElse(description.getId())
+ description.getVersion().map(v -> " " + v).orElse("");
TextComponent.Builder hoverText = TextComponent.builder(pluginInfo);
TextComponent.Builder hoverText = Component.text().content(pluginInfo);
description.getUrl().ifPresent(url -> {
hoverText.append(TextComponent.newline());
hoverText.append(TextComponent.of("Website: " + url));
hoverText.append(Component.newline());
hoverText.append(Component.text("Website: " + url));
});
if (!description.getAuthors().isEmpty()) {
hoverText.append(TextComponent.newline());
hoverText.append(Component.newline());
if (description.getAuthors().size() == 1) {
hoverText.append(TextComponent.of("Author: " + description.getAuthors().get(0)));
hoverText.append(Component.text("Author: " + description.getAuthors().get(0)));
} else {
hoverText.append(TextComponent.of("Authors: " + Joiner.on(", ")
hoverText.append(Component.text("Authors: " + Joiner.on(", ")
.join(description.getAuthors())));
}
}
description.getDescription().ifPresent(pdesc -> {
hoverText.append(TextComponent.newline());
hoverText.append(TextComponent.newline());
hoverText.append(TextComponent.of(pdesc));
hoverText.append(Component.newline());
hoverText.append(Component.newline());
hoverText.append(Component.text(pdesc));
});
return TextComponent.of(description.getId(), NamedTextColor.GRAY)
return Component.text(description.getId(), NamedTextColor.GRAY)
.hoverEvent(HoverEvent.showText(hoverText.build()));
}

Datei anzeigen

@ -26,12 +26,13 @@ import java.util.concurrent.CompletableFuture;
import javax.crypto.Mac;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
public class LoginSessionHandler implements MinecraftSessionHandler {
private static final TextComponent MODERN_IP_FORWARDING_FAILURE = TextComponent
.of("Your server did not send a forwarding request to the proxy. Is it set up correctly?");
private static final TextComponent MODERN_IP_FORWARDING_FAILURE = Component
.text("Your server did not send a forwarding request to the proxy. Is it set up correctly?");
private final VelocityServer server;
private final VelocityServerConnection serverConn;

Datei anzeigen

@ -43,7 +43,7 @@ import java.util.Optional;
import java.util.Queue;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -138,7 +138,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
logger.info("Exception occurred while running command for {}",
player.getUsername(), e);
player.sendMessage(
TextComponent.of("An error occurred while running this command.",
Component.text("An error occurred while running this command.",
NamedTextColor.RED));
return null;
});

Datei anzeigen

@ -504,7 +504,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
userMessage = "Unable to connect to " + server.getServerInfo().getName() + ". Try again "
+ "later.";
}
handleConnectionException(server, null, TextComponent.of(userMessage,
handleConnectionException(server, null, Component.text(userMessage,
NamedTextColor.RED), safe);
}
@ -527,7 +527,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
if (connectedServer != null && connectedServer.getServerInfo().equals(server.getServerInfo())) {
logger.error("{}: kicked from server {}: {}", this, server.getServerInfo().getName(),
plainTextReason);
handleConnectionException(server, disconnectReason, TextComponent.builder()
handleConnectionException(server, disconnectReason, Component.text()
.append(messages.getKickPrefix(server.getServerInfo().getName()))
.color(NamedTextColor.RED)
.append(disconnectReason)
@ -535,7 +535,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
} else {
logger.error("{}: disconnected while connecting to {}: {}", this,
server.getServerInfo().getName(), plainTextReason);
handleConnectionException(server, disconnectReason, TextComponent.builder()
handleConnectionException(server, disconnectReason, Component.text()
.append(messages.getDisconnectPrefix(server.getServerInfo().getName()))
.color(NamedTextColor.RED)
.append(disconnectReason)

Datei anzeigen

@ -22,6 +22,7 @@ import io.netty.buffer.ByteBuf;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.Optional;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.TranslatableComponent;
import net.kyori.adventure.text.format.NamedTextColor;
@ -54,7 +55,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
@Override
public boolean handle(LegacyHandshake packet) {
connection.closeWith(LegacyDisconnect
.from(TextComponent.of("Your client is old, please upgrade!", NamedTextColor.RED)));
.from(Component.text("Your client is old, please upgrade!", NamedTextColor.RED)));
return true;
}
@ -100,13 +101,13 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
private void handleLogin(Handshake handshake, InitialInboundConnection ic) {
if (!ProtocolVersion.isSupported(handshake.getProtocolVersion())) {
ic.disconnectQuietly(TranslatableComponent.of("multiplayer.disconnect.outdated_client"));
ic.disconnectQuietly(Component.translatable("multiplayer.disconnect.outdated_client"));
return;
}
InetAddress address = ((InetSocketAddress) connection.getRemoteAddress()).getAddress();
if (!server.getIpAttemptLimiter().attempt(address)) {
ic.disconnectQuietly(TextComponent.of("You are logging in too fast, try again later."));
ic.disconnectQuietly(Component.text("You are logging in too fast, try again later."));
return;
}
@ -116,7 +117,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
// and lower, otherwise IP information will never get forwarded.
if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN
&& handshake.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_13) < 0) {
ic.disconnectQuietly(TextComponent.of("This server is only compatible with 1.13 and above."));
ic.disconnectQuietly(Component.text("This server is only compatible with 1.13 and above."));
return;
}

Datei anzeigen

@ -1,16 +1,17 @@
package com.velocitypowered.proxy.connection.util;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;
public class ConnectionMessages {
public static final TextComponent ALREADY_CONNECTED = TextComponent
.of("You are already connected to this server!", NamedTextColor.RED);
public static final TextComponent IN_PROGRESS = TextComponent
.of("You are already connecting to a server!", NamedTextColor.RED);
public static final TextComponent INTERNAL_SERVER_CONNECTION_ERROR = TextComponent
.of("An internal server connection error occurred.", NamedTextColor.RED);
public static final TextComponent ALREADY_CONNECTED = Component
.text("You are already connected to this server!", NamedTextColor.RED);
public static final TextComponent IN_PROGRESS = Component
.text("You are already connecting to a server!", NamedTextColor.RED);
public static final TextComponent INTERNAL_SERVER_CONNECTION_ERROR = Component
.text("An internal server connection error occurred.", NamedTextColor.RED);
private ConnectionMessages() {
throw new AssertionError();

Datei anzeigen

@ -31,7 +31,7 @@ public class VelocityLegacyHoverEventSerializer implements LegacyHoverEventSeria
}
private static Key legacyIdToFakeKey(byte id) {
return Key.of("velocity", "legacy_hover/id_" + id);
return Key.key("velocity", "legacy_hover/id_" + id);
}
@Override
@ -45,7 +45,7 @@ public class VelocityLegacyHoverEventSerializer implements LegacyHoverEventSeria
if (idIfString.isEmpty()) {
key = legacyIdToFakeKey(item.getByte("id"));
} else {
key = Key.of(idIfString);
key = Key.key(idIfString);
}
byte count = item.getByte("Count", (byte) 1);
@ -62,10 +62,10 @@ public class VelocityLegacyHoverEventSerializer implements LegacyHoverEventSeria
try {
name = componentDecoder.decode(item.getString("name"));
} catch (Exception e) {
name = TextComponent.of(item.getString("name"));
name = Component.text(item.getString("name"));
}
return ShowEntity.of(Key.of(item.getString("type")),
return ShowEntity.of(Key.key(item.getString("type")),
UUID.fromString(item.getString("id")),
name);
}
@ -89,7 +89,7 @@ public class VelocityLegacyHoverEventSerializer implements LegacyHoverEventSeria
builder.put("tag", TagStringIO.get().asCompound(nbt.string()));
}
return TextComponent.of(TagStringIO.get().asString(builder.build()));
return Component.text(TagStringIO.get().asString(builder.build()));
}
@Override
@ -102,6 +102,6 @@ public class VelocityLegacyHoverEventSerializer implements LegacyHoverEventSeria
if (name != null) {
tag.putString("name", componentEncoder.encode(name));
}
return TextComponent.of(TagStringIO.get().asString(tag.build()));
return Component.text(TagStringIO.get().asString(tag.build()));
}
}