Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-12-24 15:20:35 +01:00
Convert all Velocity commands to use adventure text components
Dieser Commit ist enthalten in:
Ursprung
bcab3be2e2
Commit
ff99b2b248
@ -9,8 +9,8 @@ import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import net.kyori.text.TextComponent;
|
||||
import net.kyori.text.format.TextColor;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class GlistCommand implements Command {
|
||||
@ -26,9 +26,9 @@ public class GlistCommand implements Command {
|
||||
if (args.length == 0) {
|
||||
sendTotalProxyCount(source);
|
||||
source.sendMessage(
|
||||
TextComponent.builder("To view all players on servers, use ", TextColor.YELLOW)
|
||||
.append("/glist all", TextColor.DARK_AQUA)
|
||||
.append(".", TextColor.YELLOW)
|
||||
TextComponent.builder("To view all players on servers, use ", NamedTextColor.YELLOW)
|
||||
.append("/glist all", NamedTextColor.DARK_AQUA)
|
||||
.append(".", NamedTextColor.YELLOW)
|
||||
.build());
|
||||
} else if (args.length == 1) {
|
||||
String arg = args[0];
|
||||
@ -41,20 +41,20 @@ public class GlistCommand implements Command {
|
||||
Optional<RegisteredServer> registeredServer = server.getServer(arg);
|
||||
if (!registeredServer.isPresent()) {
|
||||
source.sendMessage(
|
||||
TextComponent.of("Server " + arg + " doesn't exist.", TextColor.RED));
|
||||
TextComponent.of("Server " + arg + " doesn't exist.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
sendServerPlayers(source, registeredServer.get(), false);
|
||||
}
|
||||
} else {
|
||||
source.sendMessage(TextComponent.of("Too many arguments.", TextColor.RED));
|
||||
source.sendMessage(TextComponent.of("Too many arguments.", NamedTextColor.RED));
|
||||
}
|
||||
}
|
||||
|
||||
private void sendTotalProxyCount(CommandSource target) {
|
||||
target.sendMessage(TextComponent.builder("There are ", TextColor.YELLOW)
|
||||
.append(Integer.toString(server.getAllPlayers().size()), TextColor.GREEN)
|
||||
.append(" player(s) online.", TextColor.YELLOW)
|
||||
target.sendMessage(TextComponent.builder("There are ", NamedTextColor.YELLOW)
|
||||
.append(Integer.toString(server.getAllPlayers().size()), NamedTextColor.GREEN)
|
||||
.append(" player(s) online.", NamedTextColor.YELLOW)
|
||||
.build());
|
||||
}
|
||||
|
||||
@ -66,8 +66,8 @@ public class GlistCommand implements Command {
|
||||
|
||||
TextComponent.Builder builder = TextComponent.builder()
|
||||
.append(TextComponent.of("[" + server.getServerInfo().getName() + "] ",
|
||||
TextColor.DARK_AQUA))
|
||||
.append("(" + onServer.size() + ")", TextColor.GRAY)
|
||||
NamedTextColor.DARK_AQUA))
|
||||
.append("(" + onServer.size() + ")", NamedTextColor.GRAY)
|
||||
.append(": ")
|
||||
.resetStyle();
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.velocitypowered.proxy.command;
|
||||
|
||||
import static net.kyori.text.TextComponent.of;
|
||||
import static net.kyori.text.event.HoverEvent.showText;
|
||||
import static net.kyori.adventure.text.event.HoverEvent.showText;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.velocitypowered.api.command.Command;
|
||||
@ -16,9 +15,9 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import net.kyori.text.TextComponent;
|
||||
import net.kyori.text.event.ClickEvent;
|
||||
import net.kyori.text.format.TextColor;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class ServerCommand implements Command {
|
||||
@ -33,7 +32,8 @@ public class ServerCommand implements Command {
|
||||
@Override
|
||||
public void execute(CommandSource source, String @NonNull [] args) {
|
||||
if (!(source instanceof Player)) {
|
||||
source.sendMessage(of("Only players may run this command.", TextColor.RED));
|
||||
source.sendMessage(TextComponent.of("Only players may run this command.",
|
||||
NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ public class ServerCommand implements Command {
|
||||
Optional<RegisteredServer> toConnect = server.getServer(serverName);
|
||||
if (!toConnect.isPresent()) {
|
||||
player.sendMessage(
|
||||
of("Server " + serverName + " doesn't exist.", TextColor.RED));
|
||||
TextComponent.of("Server " + serverName + " doesn't exist.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -57,24 +57,24 @@ public class ServerCommand implements Command {
|
||||
private void outputServerInformation(Player executor) {
|
||||
String currentServer = executor.getCurrentServer().map(ServerConnection::getServerInfo)
|
||||
.map(ServerInfo::getName).orElse("<unknown>");
|
||||
executor.sendMessage(of("You are currently connected to " + currentServer + ".",
|
||||
TextColor.YELLOW));
|
||||
executor.sendMessage(TextComponent.of("You are currently connected to " + currentServer + ".",
|
||||
NamedTextColor.YELLOW));
|
||||
|
||||
List<RegisteredServer> servers = BuiltinCommandUtil.sortedServerList(server);
|
||||
if (servers.size() > MAX_SERVERS_TO_LIST) {
|
||||
executor.sendMessage(of("Too many servers to list. Tab-complete to show all servers.",
|
||||
TextColor.RED));
|
||||
executor.sendMessage(TextComponent.of(
|
||||
"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: ")
|
||||
.color(TextColor.YELLOW);
|
||||
.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(of(", ", TextColor.GRAY));
|
||||
serverListBuilder.append(TextComponent.of(", ", NamedTextColor.GRAY));
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,16 +83,20 @@ public class ServerCommand implements Command {
|
||||
|
||||
private TextComponent formatServerComponent(String currentPlayerServer, RegisteredServer server) {
|
||||
ServerInfo serverInfo = server.getServerInfo();
|
||||
TextComponent serverTextComponent = of(serverInfo.getName());
|
||||
TextComponent serverTextComponent = TextComponent.of(serverInfo.getName());
|
||||
|
||||
String playersText = server.getPlayersConnected().size() + " player(s) online";
|
||||
if (serverInfo.getName().equals(currentPlayerServer)) {
|
||||
serverTextComponent = serverTextComponent.color(TextColor.GREEN)
|
||||
.hoverEvent(showText(of("Currently connected to this server\n" + playersText)));
|
||||
serverTextComponent = serverTextComponent.color(NamedTextColor.GREEN)
|
||||
.hoverEvent(
|
||||
showText(TextComponent.of("Currently connected to this server\n" + playersText))
|
||||
);
|
||||
} else {
|
||||
serverTextComponent = serverTextComponent.color(TextColor.GRAY)
|
||||
serverTextComponent = serverTextComponent.color(NamedTextColor.GRAY)
|
||||
.clickEvent(ClickEvent.runCommand("/server " + serverInfo.getName()))
|
||||
.hoverEvent(showText(of("Click to connect to this server\n" + playersText)));
|
||||
.hoverEvent(
|
||||
showText(TextComponent.of("Click to connect to this server\n" + playersText))
|
||||
);
|
||||
}
|
||||
return serverTextComponent;
|
||||
}
|
||||
|
@ -16,11 +16,11 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import net.kyori.text.TextComponent;
|
||||
import net.kyori.text.event.ClickEvent;
|
||||
import net.kyori.text.event.HoverEvent;
|
||||
import net.kyori.text.format.TextColor;
|
||||
import net.kyori.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
@ -47,7 +47,7 @@ public class VelocityCommand implements Command {
|
||||
.map(Map.Entry::getKey)
|
||||
.collect(Collectors.joining("|"));
|
||||
String commandText = "/velocity <" + availableCommands + ">";
|
||||
source.sendMessage(TextComponent.of(commandText, TextColor.RED));
|
||||
source.sendMessage(TextComponent.of(commandText, NamedTextColor.RED));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -121,17 +121,17 @@ public class VelocityCommand implements Command {
|
||||
public void execute(CommandSource source, String @NonNull [] args) {
|
||||
try {
|
||||
if (server.reloadConfiguration()) {
|
||||
source.sendMessage(TextComponent.of("Configuration reloaded.", TextColor.GREEN));
|
||||
source.sendMessage(TextComponent.of("Configuration reloaded.", NamedTextColor.GREEN));
|
||||
} else {
|
||||
source.sendMessage(TextComponent.of(
|
||||
"Unable to reload your configuration. Check the console for more details.",
|
||||
TextColor.RED));
|
||||
NamedTextColor.RED));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("Unable to reload configuration", e);
|
||||
source.sendMessage(TextComponent.of(
|
||||
"Unable to reload your configuration. Check the console for more details.",
|
||||
TextColor.RED));
|
||||
NamedTextColor.RED));
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,7 +152,7 @@ public class VelocityCommand implements Command {
|
||||
@Override
|
||||
public void execute(CommandSource source, String @NonNull [] args) {
|
||||
if (args.length != 0) {
|
||||
source.sendMessage(TextComponent.of("/velocity version", TextColor.RED));
|
||||
source.sendMessage(TextComponent.of("/velocity version", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -160,7 +160,7 @@ public class VelocityCommand implements Command {
|
||||
|
||||
TextComponent velocity = TextComponent.builder(version.getName() + " ")
|
||||
.decoration(TextDecoration.BOLD, true)
|
||||
.color(TextColor.DARK_AQUA)
|
||||
.color(NamedTextColor.DARK_AQUA)
|
||||
.append(TextComponent.of(version.getVersion()).decoration(TextDecoration.BOLD, false))
|
||||
.build();
|
||||
TextComponent copyright = TextComponent
|
||||
@ -173,13 +173,13 @@ public class VelocityCommand implements Command {
|
||||
TextComponent velocityWebsite = TextComponent.builder()
|
||||
.content("Visit the ")
|
||||
.append(TextComponent.builder("Velocity website")
|
||||
.color(TextColor.GREEN)
|
||||
.color(NamedTextColor.GREEN)
|
||||
.clickEvent(
|
||||
ClickEvent.openUrl("https://www.velocitypowered.com"))
|
||||
.build())
|
||||
.append(TextComponent.of(" or the "))
|
||||
.append(TextComponent.builder("Velocity GitHub")
|
||||
.color(TextColor.GREEN)
|
||||
.color(NamedTextColor.GREEN)
|
||||
.clickEvent(ClickEvent.openUrl(
|
||||
"https://github.com/VelocityPowered/Velocity"))
|
||||
.build())
|
||||
@ -205,7 +205,7 @@ public class VelocityCommand implements Command {
|
||||
@Override
|
||||
public void execute(CommandSource source, String @NonNull [] args) {
|
||||
if (args.length != 0) {
|
||||
source.sendMessage(TextComponent.of("/velocity plugins", TextColor.RED));
|
||||
source.sendMessage(TextComponent.of("/velocity plugins", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -213,12 +213,12 @@ public class VelocityCommand implements Command {
|
||||
int pluginCount = plugins.size();
|
||||
|
||||
if (pluginCount == 0) {
|
||||
source.sendMessage(TextComponent.of("No plugins installed.", TextColor.YELLOW));
|
||||
source.sendMessage(TextComponent.of("No plugins installed.", NamedTextColor.YELLOW));
|
||||
return;
|
||||
}
|
||||
|
||||
TextComponent.Builder output = TextComponent.builder("Plugins: ")
|
||||
.color(TextColor.YELLOW);
|
||||
.color(NamedTextColor.YELLOW);
|
||||
for (int i = 0; i < pluginCount; i++) {
|
||||
PluginContainer plugin = plugins.get(i);
|
||||
output.append(componentForPlugin(plugin.getDescription()));
|
||||
@ -255,7 +255,7 @@ public class VelocityCommand implements Command {
|
||||
hoverText.append(TextComponent.of(pdesc));
|
||||
});
|
||||
|
||||
return TextComponent.of(description.getId(), TextColor.GRAY)
|
||||
return TextComponent.of(description.getId(), NamedTextColor.GRAY)
|
||||
.hoverEvent(HoverEvent.showText(hoverText.build()));
|
||||
}
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren