Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
16 changes: 16 additions & 0 deletions paper-api/src/main/java/org/bukkit/entity/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -3275,6 +3275,22 @@ default boolean hasResourcePack() {
*/
java.util.Locale locale();
// Paper end

/**
* Returns the locale the server will use to send messages translated via the Adventure global translator.
* By default, the value of {@link Player#locale()} is used.
*
* @return the locale.
*/
java.util.Locale getEffectiveLocale();

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

/**
* Gets the player's estimated ping in milliseconds.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
--- a/net/minecraft/server/level/ServerPlayer.java
+++ b/net/minecraft/server/level/ServerPlayer.java
@@ -235,7 +_,8 @@
@@ -235,7 +_,9 @@
private int levitationStartTime;
private boolean disconnected;
private int requestedViewDistance = 2;
- public String language = "en_us";
+ public String language = null; // Paper - default to null
+ public java.util.Locale adventure$locale = java.util.Locale.US; // Paper
+ public java.util.Locale effectiveLocale = null; // Paper
@Nullable
private Vec3 startingToFallPosition;
@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
@Override
public void handleClientInformation(ServerboundClientInformationPacket packet) {
this.clientInformation = packet.information();
+ this.connection.channel.attr(io.papermc.paper.adventure.PaperAdventure.LOCALE_ATTRIBUTE).set(net.kyori.adventure.translation.Translator.parseLocale(packet.information().language())); // Paper
+ this.connection.channel.attr(io.papermc.paper.adventure.PaperAdventure.LOCALE_ATTRIBUTE).set(player.effectiveLocale != null ? player.effectiveLocale : net.kyori.adventure.translation.Translator.parseLocale(packet.information().language())); // Paper
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2513,7 +2513,7 @@
+ // Paper end - do not accept invalid information
boolean isModelPartShown = this.player.isModelPartShown(PlayerModelPart.HAT);
this.player.updateOptions(packet.information());
+ this.connection.channel.attr(io.papermc.paper.adventure.PaperAdventure.LOCALE_ATTRIBUTE).set(net.kyori.adventure.translation.Translator.parseLocale(packet.information().language())); // Paper
+ this.connection.channel.attr(io.papermc.paper.adventure.PaperAdventure.LOCALE_ATTRIBUTE).set(player.effectiveLocale != null ? player.effectiveLocale : net.kyori.adventure.translation.Translator.parseLocale(packet.information().language())); // Paper
if (this.player.isModelPartShown(PlayerModelPart.HAT) != isModelPartShown) {
this.server.getPlayerList().broadcastAll(new ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_HAT, this.player));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2996,6 +2996,25 @@ public java.util.Locale locale() {
return getHandle().adventure$locale;
}
// Paper end


@Override
public java.util.Locale getEffectiveLocale() {
if (getHandle().effectiveLocale == null) {
return locale();
}
return getHandle().effectiveLocale;
}

@Override
public void setEffectiveLocale(final java.util.Locale locale) {
getHandle().effectiveLocale = locale;

if (getHandle().connection != null) {
getHandle().connection.connection.channel.attr(io.papermc.paper.adventure.PaperAdventure.LOCALE_ATTRIBUTE).set(getEffectiveLocale());
}
}

@Override
public int getPing() {
return this.getHandle().connection.latency();
Expand Down
Loading