Skip to content
Closed
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
18 changes: 18 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 @@ -7,6 +7,7 @@
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -3275,6 +3276,23 @@ 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.
*/
Locale getEffectiveLocale();

/**
* Change the locale the server will be translating its messages to.
* If set, the effective locale overrides the client locale for server-side translations.
*
* @param locale the locale to translate to
*/
void setEffectiveLocale(@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,14 @@
--- a/net/minecraft/server/level/ServerPlayer.java
+++ b/net/minecraft/server/level/ServerPlayer.java
@@ -235,7 +_,8 @@
@@ -235,7 +_,10 @@
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
+ @Nullable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try put this in the same line because the comment only apply to the field and not this.

+ 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