Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.KeyPair;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -105,8 +104,8 @@
import net.kyori.adventure.audience.ForwardingAudience;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.translation.MiniMessageTranslationStore;
import net.kyori.adventure.translation.GlobalTranslator;
import net.kyori.adventure.translation.TranslationStore;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bstats.MetricsBase;
Expand Down Expand Up @@ -242,8 +241,6 @@ void start() {
console.setupStreams();
pluginManager.registerPlugin(this.createVirtualPlugin());

registerTranslations();

// Yes, you're reading that correctly. We're generating a 1024-bit RSA keypair. Sounds
// dangerous, right? We're well within the realm of factoring such a key...
//
Expand Down Expand Up @@ -292,6 +289,8 @@ void start() {

this.doStartupConfigLoad();

registerTranslations();

for (ServerInfo cliServer : options.getServers()) {
servers.register(cliServer);
}
Expand Down Expand Up @@ -342,8 +341,8 @@ void start() {
}

private void registerTranslations() {
final TranslationStore.StringBased<MessageFormat> translationRegistry =
TranslationStore.messageFormat(Key.key("velocity", "translations"));
final MiniMessageTranslationStore translationRegistry =
MiniMessageTranslationStore.create(Key.key("velocity", "translations"));
translationRegistry.defaultLocale(Locale.US);
try {
ResourceUtils.visitResources(VelocityServer.class, path -> {
Expand Down Expand Up @@ -835,7 +834,7 @@ public VelocityScheduler getScheduler() {
public VelocityChannelRegistrar getChannelRegistrar() {
return channelRegistrar;
}

@Override
public boolean isShuttingDown() {
return shutdownInProgress.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.TranslatableComponent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.translation.Argument;

/**
* Implements the Velocity default {@code /glist} command.
Expand Down Expand Up @@ -111,7 +112,7 @@ private int serverCount(final CommandContext<CommandSource> context) {
if (registeredServer.isEmpty()) {
source.sendMessage(
CommandMessages.SERVER_DOES_NOT_EXIST
.arguments(Component.text(serverName)));
.arguments(Argument.string("server", serverName)));
return -1;
}
sendServerPlayers(source, registeredServer.get(), false);
Expand All @@ -126,7 +127,8 @@ private void sendTotalProxyCount(CommandSource target) {
? "velocity.command.glist-player-singular"
: "velocity.command.glist-player-plural"
).color(NamedTextColor.YELLOW)
.arguments(Component.text(Integer.toString(online), NamedTextColor.GREEN));
.arguments(Argument.component(
"players", Component.text(Integer.toString(online), NamedTextColor.GREEN)));
target.sendMessage(msg.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.Optional;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.translation.Argument;

/**
* Implements the Velocity default {@code /send} command.
Expand Down Expand Up @@ -121,7 +122,7 @@ private int send(final CommandContext<CommandSource> context) {

if (maybeServer.isEmpty()) {
context.getSource().sendMessage(
CommandMessages.SERVER_DOES_NOT_EXIST.arguments(Component.text(serverName))
CommandMessages.SERVER_DOES_NOT_EXIST.arguments(Argument.string("server", serverName))
);
return 0;
}
Expand All @@ -133,7 +134,7 @@ private int send(final CommandContext<CommandSource> context) {
&& !Objects.equals(player, "all")
&& !Objects.equals(player, "current")) {
context.getSource().sendMessage(
CommandMessages.PLAYER_NOT_FOUND.arguments(Component.text(player))
CommandMessages.PLAYER_NOT_FOUND.arguments(Argument.string("player", player))
);
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import net.kyori.adventure.text.TranslatableComponent;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.translation.Argument;

/**
* Implements Velocity's {@code /server} command.
Expand Down Expand Up @@ -76,7 +77,7 @@ public static BrigadierCommand create(final ProxyServer server) {
final Optional<RegisteredServer> toConnect = server.getServer(serverName);
if (toConnect.isEmpty()) {
player.sendMessage(CommandMessages.SERVER_DOES_NOT_EXIST
.arguments(Component.text(serverName)));
.arguments(Argument.string("server", serverName)));
return -1;
}

Expand Down Expand Up @@ -135,7 +136,7 @@ private static TextComponent formatServerComponent(final String currentPlayerSer
} else {
playersTextComponent.key("velocity.command.server-tooltip-players-online");
}
playersTextComponent.arguments(Component.text(connectedPlayers));
playersTextComponent.arguments(Argument.component("players", Component.text(connectedPlayers)));
if (serverInfo.getName().equals(currentPlayerServer)) {
serverTextComponent.color(NamedTextColor.GREEN)
.hoverEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.minimessage.translation.Argument;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -165,9 +166,9 @@ public int run(final CommandContext<CommandSource> context) {
.build();
final Component copyright = Component
.translatable("velocity.command.version-copyright",
Component.text(version.getVendor()),
Component.text(version.getName()),
Component.text(LocalDate.now().getYear()));
Argument.string("vendor", version.getVendor()),
Argument.string("name", version.getName()),
Argument.component("year", Component.text(LocalDate.now().getYear())));
source.sendMessage(velocity);
source.sendMessage(copyright);

Expand Down Expand Up @@ -220,7 +221,7 @@ public int run(final CommandContext<CommandSource> context) {
final TranslatableComponent output = Component.translatable()
.key("velocity.command.plugins-list")
.color(NamedTextColor.YELLOW)
.arguments(listBuilder.build())
.arguments(Argument.component("plugins", listBuilder.build()))
.build();
source.sendMessage(output);
return Command.SINGLE_SUCCESS;
Expand All @@ -236,7 +237,7 @@ private TextComponent componentForPlugin(PluginDescription description) {
hoverText.append(Component.newline());
hoverText.append(Component.translatable(
"velocity.command.plugin-tooltip-website",
Component.text(url)));
Argument.component("url", Component.text(url))));
});
if (!description.getAuthors().isEmpty()) {
hoverText.append(Component.newline());
Expand All @@ -246,7 +247,7 @@ private TextComponent componentForPlugin(PluginDescription description) {
} else {
hoverText.append(
Component.translatable("velocity.command.plugin-tooltip-author",
Component.text(String.join(", ", description.getAuthors()))
Argument.string("authors", String.join(", ", description.getAuthors()))
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.velocitypowered.proxy.config.migration.ConfigurationMigration;
import com.velocitypowered.proxy.config.migration.ForwardingMigration;
import com.velocitypowered.proxy.config.migration.KeyAuthenticationMigration;
import com.velocitypowered.proxy.config.migration.MiniMessageTranslationsMigration;
import com.velocitypowered.proxy.config.migration.MotdMigration;
import com.velocitypowered.proxy.config.migration.TransferIntegrationMigration;
import com.velocitypowered.proxy.util.AddressUtil;
Expand Down Expand Up @@ -504,6 +505,7 @@ public static VelocityConfiguration read(Path path) throws IOException {
new ForwardingMigration(),
new KeyAuthenticationMigration(),
new MotdMigration(),
new MiniMessageTranslationsMigration(),
new TransferIntegrationMigration()
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public sealed interface ConfigurationMigration
permits ForwardingMigration,
KeyAuthenticationMigration,
MotdMigration,
MiniMessageTranslationsMigration,
TransferIntegrationMigration {
boolean shouldMigrate(CommentedFileConfig config);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (C) 2024 Velocity Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.velocitypowered.proxy.config.migration;

import com.electronwill.nightconfig.core.file.CommentedFileConfig;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.regex.Pattern;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.apache.logging.log4j.Logger;

/**
* Migration from old to modern language argument format with MiniMessage.
* Also migrates possible use of legacy colors to MiniMessage format.
*/
public final class MiniMessageTranslationsMigration implements ConfigurationMigration {
@Override
public boolean shouldMigrate(final CommentedFileConfig config) {
// Checking whether translations should be migrated would be just as costly as attempting to migrate them directly.
return true;
}

@Override
public void migrate(final CommentedFileConfig config, final Logger logger) throws IOException {
final Path langFolder = Path.of("lang");
if (Files.notExists(langFolder)) {
return;
}
final Pattern oldPlaceholderPattern = Pattern.compile("\\{(\\d+)}");
try (final DirectoryStream<Path> stream
= Files.newDirectoryStream(langFolder, Files::isRegularFile)) {
for (final Path path : stream) {
String content = Files.readString(path, StandardCharsets.UTF_8);
if (content.indexOf('{') == -1) {
continue;
}
// Migrate old arguments
content = oldPlaceholderPattern.matcher(content).replaceAll("<arg:$1>");
// Some setups use legacy color codes, this format is migrated to MiniMessage
content = MiniMessage.miniMessage().serialize(
LegacyComponentSerializer.legacySection().deserialize(content));
Files.writeString(path, content, StandardCharsets.UTF_8);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
import net.kyori.adventure.text.minimessage.translation.Argument;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import net.kyori.adventure.title.Title.Times;
Expand Down Expand Up @@ -713,12 +714,12 @@ public void handleConnectionException(RegisteredServer server, Throwable throwab
Component friendlyError;
if (connectedServer != null && connectedServer.getServerInfo().equals(server.getServerInfo())) {
friendlyError = Component.translatable("velocity.error.connected-server-error",
Component.text(server.getServerInfo().getName()));
Argument.string("server", server.getServerInfo().getName()));
} else {
logger.error("{}: unable to connect to server {}", this, server.getServerInfo().getName(),
wrapped);
friendlyError = Component.translatable("velocity.error.connecting-server-error",
Component.text(server.getServerInfo().getName()));
Argument.string("server", server.getServerInfo().getName()));
}
handleConnectionException(server, null, friendlyError.color(NamedTextColor.RED), safe);
}
Expand Down Expand Up @@ -746,7 +747,7 @@ public void handleConnectionException(RegisteredServer server, DisconnectPacket
}
handleConnectionException(server, disconnectReason,
Component.translatable("velocity.error.moved-to-new-server", NamedTextColor.RED,
Component.text(server.getServerInfo().getName()),
Argument.string("server", server.getServerInfo().getName()),
disconnectReason), safe);
} else {
if (this.server.getConfiguration().isLogPlayerConnections()) {
Expand All @@ -755,7 +756,7 @@ public void handleConnectionException(RegisteredServer server, DisconnectPacket
}
handleConnectionException(server, disconnectReason,
Component.translatable("velocity.error.cant-connect", NamedTextColor.RED,
Component.text(server.getServerInfo().getName()),
Argument.string("server", server.getServerInfo().getName()),
disconnectReason), safe);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.util.Optional;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.translation.Argument;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.Nullable;
Expand Down Expand Up @@ -129,7 +130,7 @@ private void handleLogin(HandshakePacket handshake, InitialInboundConnection ic)
connection.setState(StateRegistry.LOGIN);
ic.disconnectQuietly(Component.translatable()
.key("multiplayer.disconnect.outdated_client")
.arguments(Component.text(ProtocolVersion.SUPPORTED_VERSION_STRING))
.arguments(Argument.string("versions", ProtocolVersion.SUPPORTED_VERSION_STRING))
.build());
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,42 @@
velocity.error.already-connected=You are already connected to this server!
velocity.error.already-connected-proxy=You are already connected to this proxy!
velocity.error.already-connecting=You are already trying to connect to a server!
velocity.error.cant-connect=Unable to connect to {0}: {1}
velocity.error.connecting-server-error=Unable to connect you to {0}. Please try again later.
velocity.error.connected-server-error=Your connection to {0} encountered a problem.
velocity.error.cant-connect=Unable to connect to <arg:0>: <arg:1>
velocity.error.connecting-server-error=Unable to connect you to <arg:0>. Please try again later.
velocity.error.connected-server-error=Your connection to <arg:0> encountered a problem.
velocity.error.internal-server-connection-error=An internal server connection error occurred.
velocity.error.logging-in-too-fast=You are logging in too fast, try again later.
velocity.error.online-mode-only=You are not logged into your Minecraft account. If you are logged into your Minecraft account, try restarting your Minecraft client.
velocity.error.player-connection-error=An internal error occurred in your connection.
velocity.error.modern-forwarding-needs-new-client=This server is only compatible with Minecraft 1.13 and above.
velocity.error.modern-forwarding-failed=Your server did not send a forwarding request to the proxy. Make sure the server is configured for Velocity forwarding.
velocity.error.moved-to-new-server=You were kicked from {0}: {1}
velocity.error.moved-to-new-server=You were kicked from <arg:0>: <arg:1>
velocity.error.no-available-servers=There are no available servers to connect you to. Try again later or contact an admin.
velocity.error.illegal-chat-characters=Illegal characters in chat
# Commands
velocity.command.generic-error=An error occurred while running this command.
velocity.command.command-does-not-exist=This command does not exist.
velocity.command.players-only=Only players can run this command.
velocity.command.server-does-not-exist=The specified server {0} does not exist.
velocity.command.player-not-found=The specified player {0} does not exist.
velocity.command.server-current-server=You are currently connected to {0}.
velocity.command.server-does-not-exist=The specified server <arg:0> does not exist.
velocity.command.player-not-found=The specified player <arg:0> does not exist.
velocity.command.server-current-server=You are currently connected to <arg:0>.
velocity.command.server-too-many=There are too many servers set up. Use tab completion to view all servers available.
velocity.command.server-available=Available servers:
velocity.command.server-tooltip-player-online={0} player online
velocity.command.server-tooltip-players-online={0} players online
velocity.command.server-tooltip-player-online=<arg:0> player online
velocity.command.server-tooltip-players-online=<arg:0> players online
velocity.command.server-tooltip-current-server=Currently connected to this server
velocity.command.server-tooltip-offer-connect-server=Click to connect to this server
velocity.command.glist-player-singular={0} player is currently connected to the proxy.
velocity.command.glist-player-plural={0} players are currently connected to the proxy.
velocity.command.glist-player-singular=<arg:0> player is currently connected to the proxy.
velocity.command.glist-player-plural=<arg:0> players are currently connected to the proxy.
velocity.command.glist-view-all=To view all players on servers, use /glist all.
velocity.command.reload-success=Velocity configuration successfully reloaded.
velocity.command.reload-failure=Unable to reload your Velocity configuration. Check the console for more details.
velocity.command.version-copyright=Copyright 2018-{2} {0}. {1} is licensed under the terms of the GNU General Public License v3.
velocity.command.version-copyright=Copyright 2018-<arg:2> <arg:0>. <arg:1> is licensed under the terms of the GNU General Public License v3.
velocity.command.no-plugins=There are no plugins currently installed.
velocity.command.plugins-list=Plugins: {0}
velocity.command.plugin-tooltip-website=Website: {0}
velocity.command.plugin-tooltip-author=Author: {0}
velocity.command.plugin-tooltip-authors=Authors: {0}
velocity.command.plugins-list=Plugins: <arg:0>
velocity.command.plugin-tooltip-website=Website: <arg:0>
velocity.command.plugin-tooltip-author=Author: <arg:0>
velocity.command.plugin-tooltip-authors=Authors: <arg:0>
velocity.command.dump-uploading=Uploading gathered information...
velocity.command.dump-send-error=An error occurred while communicating with the Velocity servers. The servers may be temporarily unavailable or there is an issue with your network settings. You can find more information in the log or console of your Velocity server.
velocity.command.dump-success=Created an anonymised report containing useful information about this proxy. If a developer requested it, you may share the following link with them:
Expand Down
Loading