Skip to content
Merged
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
17 changes: 17 additions & 0 deletions api/src/main/java/com/velocitypowered/api/proxy/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.velocitypowered.api.util.GameProfile;
import com.velocitypowered.api.util.ModInfo;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.UUID;
import java.util.function.UnaryOperator;
Expand All @@ -45,6 +46,22 @@ public interface Player extends CommandSource, Identified, InboundConnection,
*/
String getUsername();

/**
* Returns the locale the proxy will use to send messages translated via the Adventure global translator.
* By default, the value of {@link PlayerSettings#getLocale()} is used.
*
* <p>This can be {@code null} when the client has not yet connected to any server.</p>
*
* @return the locale.
*/
@Nullable Locale getEffectiveLocale();

/**
* Change the locale the proxy will be translating its messages to.
*
* @param locale the locale to translate to
*/
void setEffectiveLocale(Locale locale);

/**
* Returns the player's UUID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import com.velocitypowered.api.util.GameProfile;
import com.velocitypowered.api.util.ModInfo;
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;
Expand Down Expand Up @@ -79,7 +78,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Optional;
import java.util.Queue;
import java.util.UUID;
Expand All @@ -97,8 +95,6 @@
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
import net.kyori.adventure.title.Title;
import net.kyori.adventure.title.Title.Times;
import net.kyori.adventure.translation.GlobalTranslator;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -149,6 +145,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
.withStatic(PermissionChecker.POINTER, getPermissionChecker())
.build();
private @Nullable String clientBrand;
private @Nullable Locale effectiveLocale;

ConnectedPlayer(VelocityServer server, GameProfile profile, MinecraftConnection connection,
@Nullable InetSocketAddress virtualHost, boolean onlineMode) {
Expand Down Expand Up @@ -178,6 +175,19 @@ public String getUsername() {
return profile.getName();
}

@Override
public Locale getEffectiveLocale() {
if (effectiveLocale == null && settings != null) {
return settings.getLocale();
}
return effectiveLocale;
}

@Override
public void setEffectiveLocale(Locale locale) {
effectiveLocale = locale;
}

@Override
public UUID getUniqueId() {
return profile.getId();
Expand Down Expand Up @@ -276,7 +286,7 @@ public ProtocolVersion getProtocolVersion() {
*/
public Component translateMessage(Component message) {
Locale locale = ClosestLocaleMatcher.INSTANCE
.lookupClosest(this.settings == null ? Locale.getDefault() : this.settings.getLocale());
.lookupClosest(getEffectiveLocale() == null ? Locale.getDefault() : getEffectiveLocale());
return GlobalTranslator.render(message, locale);
}

Expand Down