13
0
geforkt von Mirrors/Velocity

Add configurable messages for disconnect and kick prefix

Dieser Commit ist enthalten in:
Frank van der Heijden 2020-08-18 23:52:13 +02:00
Ursprung 26f3cb43c7
Commit 9e27dac557
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 26DA56488D314D11
3 geänderte Dateien mit 53 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -22,6 +22,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.Random;
import java.util.UUID;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.legacytext3.LegacyText3ComponentSerializer;
@ -49,22 +50,24 @@ public class VelocityConfiguration implements ProxyConfig {
private final Advanced advanced;
private final Query query;
private final Metrics metrics;
private final Messages messages;
private net.kyori.adventure.text.@MonotonicNonNull Component motdAsComponent;
private @Nullable Favicon favicon;
private VelocityConfiguration(Servers servers, ForcedHosts forcedHosts, Advanced advanced,
Query query, Metrics metrics) {
Query query, Metrics metrics, Messages messages) {
this.servers = servers;
this.forcedHosts = forcedHosts;
this.advanced = advanced;
this.query = query;
this.metrics = metrics;
this.messages = messages;
}
private VelocityConfiguration(String bind, String motd, int showMaxPlayers, boolean onlineMode,
boolean announceForge, PlayerInfoForwarding playerInfoForwardingMode, byte[] forwardingSecret,
boolean onlineModeKickExistingPlayers, PingPassthroughMode pingPassthrough, Servers servers,
ForcedHosts forcedHosts, Advanced advanced, Query query, Metrics metrics) {
ForcedHosts forcedHosts, Advanced advanced, Query query, Metrics metrics, Messages messages) {
this.bind = bind;
this.motd = motd;
this.showMaxPlayers = showMaxPlayers;
@ -79,6 +82,7 @@ public class VelocityConfiguration implements ProxyConfig {
this.advanced = advanced;
this.query = query;
this.metrics = metrics;
this.messages = messages;
}
/**
@ -359,6 +363,10 @@ public class VelocityConfiguration implements ProxyConfig {
return advanced.isLogCommandExecutions();
}
public Messages getMessages() {
return messages;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
@ -418,6 +426,7 @@ public class VelocityConfiguration implements ProxyConfig {
CommentedConfig advancedConfig = config.get("advanced");
CommentedConfig queryConfig = config.get("query");
CommentedConfig metricsConfig = config.get("metrics");
CommentedConfig messagesConfig = config.get("messages");
PlayerInfoForwarding forwardingMode = config.getEnumOrElse("player-info-forwarding-mode",
PlayerInfoForwarding.NONE);
PingPassthroughMode pingPassthroughMode = config.getEnumOrElse("ping-passthrough",
@ -444,7 +453,8 @@ public class VelocityConfiguration implements ProxyConfig {
new ForcedHosts(forcedHostsConfig),
new Advanced(advancedConfig),
new Query(queryConfig),
new Metrics(metricsConfig)
new Metrics(metricsConfig),
new Messages(messagesConfig)
);
}
@ -781,4 +791,31 @@ public class VelocityConfiguration implements ProxyConfig {
return fromConfig;
}
}
public static class Messages {
private String kickPrefix = "&cKicked from %s: ";
private String disconnectPrefix = "&cCan't connect to %s: ";
private Messages(CommentedConfig toml) {
if (toml != null) {
this.kickPrefix = toml.getOrElse("kick-prefix", kickPrefix);
this.disconnectPrefix = toml.getOrElse("disconnect-prefix", disconnectPrefix);
}
}
public Component getKickPrefix(String server) {
return serialize(String.format(kickPrefix, server));
}
public Component getDisconnectPrefix(String server) {
return serialize(String.format(disconnectPrefix, server));
}
private Component serialize(String str) {
if (str.startsWith("{")) {
return GsonComponentSerializer.gson().deserialize(str);
}
return LegacyComponentSerializer.legacyAmpersand().deserialize(str);
}
}
}

Datei anzeigen

@ -32,6 +32,7 @@ import com.velocitypowered.api.util.title.TextTitle;
import com.velocitypowered.api.util.title.Title;
import com.velocitypowered.api.util.title.Titles;
import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.config.VelocityConfiguration;
import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.MinecraftConnectionAssociation;
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
@ -517,13 +518,14 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
return;
}
VelocityConfiguration.Messages messages = this.server.getConfiguration().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(),
plainTextReason);
handleConnectionException(server, disconnectReason, TextComponent.builder()
.content("Kicked from " + server.getServerInfo().getName() + ": ")
.append(messages.getKickPrefix(server.getServerInfo().getName()))
.color(NamedTextColor.RED)
.append(disconnectReason)
.build(), safe);
@ -531,7 +533,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
logger.error("{}: disconnected while connecting to {}: {}", this,
server.getServerInfo().getName(), plainTextReason);
handleConnectionException(server, disconnectReason, TextComponent.builder()
.content("Can't connect to server " + server.getServerInfo().getName() + ": ")
.append(messages.getDisconnectPrefix(server.getServerInfo().getName()))
.color(NamedTextColor.RED)
.append(disconnectReason)
.build(), safe);

Datei anzeigen

@ -158,3 +158,12 @@ id = ""
log-failure = false
# Legacy color codes and JSON are accepted in all messages.
[messages]
# Prefix when the player gets kicked from a server.
# First argument '%s': the server name
kick-prefix = "&cKicked from %s: "
# Prefix when the player is disconnected from a server.
# First argument '%s': the server name
disconnect-prefix = "&cCan't connect to %s: "