Paper/Spigot-Server-Patches/0095-Implement-PlayerLocaleChangeEvent.patch
2019-05-13 21:20:58 -05:00

71 lines
3.3 KiB
Diff

From 7bb6986156e4f55149c222aa7d9ddc563635d5e9 Mon Sep 17 00:00:00 2001
From: Isaac Moore <rmsy@me.com>
Date: Tue, 19 Apr 2016 14:09:31 -0500
Subject: [PATCH] Implement PlayerLocaleChangeEvent
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
index 6725b62a9..42b5b3f40 100644
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
@@ -37,7 +37,7 @@ import org.bukkit.inventory.MainHand;
public class EntityPlayer extends EntityHuman implements ICrafting {
private static final Logger LOGGER = LogManager.getLogger();
- public String locale = "en_us"; // CraftBukkit - lowercase
+ public String locale = null; // CraftBukkit - lowercase // Paper - default to null
public PlayerConnection playerConnection;
public final MinecraftServer server;
public final PlayerInteractManager playerInteractManager;
@@ -1444,13 +1444,20 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
PlayerChangedMainHandEvent event = new PlayerChangedMainHandEvent(getBukkitEntity(), getMainHand() == EnumMainHand.LEFT ? MainHand.LEFT : MainHand.RIGHT);
this.server.server.getPluginManager().callEvent(event);
}
- if (!this.locale.equals(packetplayinsettings.b())) {
+ if (this.locale == null || !this.locale.equals(packetplayinsettings.b())) { // Paper - check for null
PlayerLocaleChangeEvent event = new PlayerLocaleChangeEvent(getBukkitEntity(), packetplayinsettings.b());
this.server.server.getPluginManager().callEvent(event);
}
this.clientViewDistance = packetplayinsettings.viewDistance;
// CraftBukkit end
+ // Paper start - add PlayerLocaleChangeEvent
+ // Since the field is initialized to null, this event should always fire the first time the packet is received
+ String oldLocale = this.locale;
this.locale = packetplayinsettings.b();
+ if (!this.locale.equals(oldLocale)) {
+ new com.destroystokyo.paper.event.player.PlayerLocaleChangeEvent(this.getBukkitEntity(), oldLocale, this.locale).callEvent();
+ }
+ // Paper end
this.ck = packetplayinsettings.d();
this.cl = packetplayinsettings.e();
this.getDataWatcher().set(EntityPlayer.bt, (byte) packetplayinsettings.f());
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 3d37f78c6..eca8c0ded 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -1748,8 +1748,10 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@Override
public String getLocale() {
- return getHandle().locale;
-
+ // Paper start - Locale change event
+ final String locale = getHandle().locale;
+ return locale != null ? locale : "en_us";
+ // Paper end
}
// Paper start
@@ -1828,7 +1830,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@Override
public String getLocale()
{
- return getHandle().locale;
+ return CraftPlayer.this.getLocale(); // Paper
}
@Override
--
2.21.0