SPIGOT-439: Add player locale related APIs.

This commit is contained in:
MiniDigger 2017-05-26 23:37:06 +02:00 committed by md_5
parent a479029a85
commit 274304b8ca
2 changed files with 49 additions and 35 deletions

View File

@ -1,6 +1,6 @@
--- a/net/minecraft/server/EntityPlayer.java --- a/net/minecraft/server/EntityPlayer.java
+++ b/net/minecraft/server/EntityPlayer.java +++ b/net/minecraft/server/EntityPlayer.java
@@ -12,6 +12,22 @@ @@ -12,10 +12,27 @@
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -16,6 +16,7 @@
+import org.bukkit.event.inventory.InventoryType; +import org.bukkit.event.inventory.InventoryType;
+import org.bukkit.event.player.PlayerChangedMainHandEvent; +import org.bukkit.event.player.PlayerChangedMainHandEvent;
+import org.bukkit.event.player.PlayerGameModeChangeEvent; +import org.bukkit.event.player.PlayerGameModeChangeEvent;
+import org.bukkit.event.player.PlayerLocaleChangeEvent;
+import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
+import org.bukkit.inventory.MainHand; +import org.bukkit.inventory.MainHand;
+// CraftBukkit end +// CraftBukkit end
@ -23,7 +24,12 @@
public class EntityPlayer extends EntityHuman implements ICrafting { public class EntityPlayer extends EntityHuman implements ICrafting {
private static final Logger bV = LogManager.getLogger(); private static final Logger bV = LogManager.getLogger();
@@ -51,6 +67,19 @@ - private String locale = "en_US";
+ public String locale = "en_us"; // PAIL: private -> public
public PlayerConnection playerConnection;
public final MinecraftServer server;
public final PlayerInteractManager playerInteractManager;
@@ -51,6 +68,19 @@
public int ping; public int ping;
public boolean viewingCredits; public boolean viewingCredits;
@ -43,7 +49,7 @@
public EntityPlayer(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile, PlayerInteractManager playerinteractmanager) { public EntityPlayer(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile, PlayerInteractManager playerinteractmanager) {
super(worldserver, gameprofile); super(worldserver, gameprofile);
playerinteractmanager.player = this; playerinteractmanager.player = this;
@@ -82,6 +111,11 @@ @@ -82,6 +112,11 @@
this.setPosition(this.locX, this.locY + 1.0D, this.locZ); this.setPosition(this.locX, this.locY + 1.0D, this.locZ);
} }
@ -55,7 +61,7 @@
} }
public void a(NBTTagCompound nbttagcompound) { public void a(NBTTagCompound nbttagcompound) {
@@ -104,6 +138,7 @@ @@ -104,6 +139,7 @@
if (nbttagcompound.hasKeyOfType("recipeBook", 10)) { if (nbttagcompound.hasKeyOfType("recipeBook", 10)) {
this.cr.a(nbttagcompound.getCompound("recipeBook")); this.cr.a(nbttagcompound.getCompound("recipeBook"));
} }
@ -63,7 +69,7 @@
} }
@@ -150,8 +185,34 @@ @@ -150,8 +186,34 @@
} }
nbttagcompound.set("recipeBook", this.cr.e()); nbttagcompound.set("recipeBook", this.cr.e());
@ -98,7 +104,7 @@
public void levelDown(int i) { public void levelDown(int i) {
super.levelDown(i); super.levelDown(i);
this.lastSentExp = -1; this.lastSentExp = -1;
@@ -185,6 +246,11 @@ @@ -185,6 +247,11 @@
} }
public void B_() { public void B_() {
@ -110,7 +116,7 @@
this.playerInteractManager.a(); this.playerInteractManager.a();
--this.invulnerableTicks; --this.invulnerableTicks;
if (this.noDamageTicks > 0) { if (this.noDamageTicks > 0) {
@@ -250,7 +316,7 @@ @@ -250,7 +317,7 @@
} }
if (this.getHealth() != this.lastHealthSent || this.ch != this.foodData.getFoodLevel() || this.foodData.getSaturationLevel() == 0.0F != this.ci) { if (this.getHealth() != this.lastHealthSent || this.ch != this.foodData.getFoodLevel() || this.foodData.getSaturationLevel() == 0.0F != this.ci) {
@ -119,7 +125,7 @@
this.lastHealthSent = this.getHealth(); this.lastHealthSent = this.getHealth();
this.ch = this.foodData.getFoodLevel(); this.ch = this.foodData.getFoodLevel();
this.ci = this.foodData.getSaturationLevel() == 0.0F; this.ci = this.foodData.getSaturationLevel() == 0.0F;
@@ -271,6 +337,12 @@ @@ -271,6 +338,12 @@
this.a(IScoreboardCriteria.i, MathHelper.f((float) this.cc)); this.a(IScoreboardCriteria.i, MathHelper.f((float) this.cc));
} }
@ -132,7 +138,7 @@
if (this.getArmorStrength() != this.cd) { if (this.getArmorStrength() != this.cd) {
this.cd = this.getArmorStrength(); this.cd = this.getArmorStrength();
this.a(IScoreboardCriteria.j, MathHelper.f((float) this.cd)); this.a(IScoreboardCriteria.j, MathHelper.f((float) this.cd));
@@ -295,6 +367,16 @@ @@ -295,6 +368,16 @@
CriterionTriggers.o.a(this); CriterionTriggers.o.a(this);
} }
@ -149,7 +155,7 @@
} catch (Throwable throwable) { } catch (Throwable throwable) {
CrashReport crashreport = CrashReport.a(throwable, "Ticking player"); CrashReport crashreport = CrashReport.a(throwable, "Ticking player");
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Player being ticked"); CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Player being ticked");
@@ -305,12 +387,11 @@ @@ -305,12 +388,11 @@
} }
private void a(IScoreboardCriteria iscoreboardcriteria, int i) { private void a(IScoreboardCriteria iscoreboardcriteria, int i) {
@ -164,7 +170,7 @@
scoreboardscore.setScore(i); scoreboardscore.setScore(i);
} }
@@ -321,32 +402,62 @@ @@ -321,32 +403,62 @@
boolean flag = this.world.getGameRules().getBoolean("showDeathMessages"); boolean flag = this.world.getGameRules().getBoolean("showDeathMessages");
this.playerConnection.sendPacket(new PacketPlayOutCombatEvent(this.getCombatTracker(), PacketPlayOutCombatEvent.EnumCombatEventType.ENTITY_DIED, flag)); this.playerConnection.sendPacket(new PacketPlayOutCombatEvent(this.getCombatTracker(), PacketPlayOutCombatEvent.EnumCombatEventType.ENTITY_DIED, flag));
@ -241,7 +247,7 @@
scoreboardscore.incrementScore(); scoreboardscore.incrementScore();
} }
@@ -374,29 +485,36 @@ @@ -374,29 +486,36 @@
if (entity != this) { if (entity != this) {
super.a(entity, i, damagesource); super.a(entity, i, damagesource);
this.addScore(i); this.addScore(i);
@ -284,7 +290,7 @@
String s = entity instanceof EntityHuman ? entity.getName() : entity.bl(); String s = entity instanceof EntityHuman ? entity.getName() : entity.bl();
ScoreboardTeam scoreboardteam = this.getScoreboard().getPlayerTeam(this.getName()); ScoreboardTeam scoreboardteam = this.getScoreboard().getPlayerTeam(this.getName());
@@ -421,7 +539,10 @@ @@ -421,7 +540,10 @@
int j = scoreboardteam1.m().b(); int j = scoreboardteam1.m().b();
if (j >= 0 && j < IScoreboardCriteria.m.length) { if (j >= 0 && j < IScoreboardCriteria.m.length) {
@ -296,7 +302,7 @@
} }
} }
@@ -463,12 +584,14 @@ @@ -463,12 +585,14 @@
} }
private boolean canPvP() { private boolean canPvP() {
@ -313,7 +319,7 @@
if (this.dimension == 0 && i == -1) { if (this.dimension == 0 && i == -1) {
this.cv = new Vec3D(this.locX, this.locY, this.locZ); this.cv = new Vec3D(this.locX, this.locY, this.locZ);
} else if (this.dimension != -1 && i != 0) { } else if (this.dimension != -1 && i != 0) {
@@ -476,6 +599,7 @@ @@ -476,6 +600,7 @@
} }
if (this.dimension == 1 && i == 1) { if (this.dimension == 1 && i == 1) {
@ -321,7 +327,7 @@
this.world.kill(this); this.world.kill(this);
if (!this.viewingCredits) { if (!this.viewingCredits) {
this.viewingCredits = true; this.viewingCredits = true;
@@ -489,7 +613,10 @@ @@ -489,7 +614,10 @@
i = 1; i = 1;
} }
@ -333,7 +339,7 @@
this.playerConnection.sendPacket(new PacketPlayOutWorldEvent(1032, BlockPosition.ZERO, 0, false)); this.playerConnection.sendPacket(new PacketPlayOutWorldEvent(1032, BlockPosition.ZERO, 0, false));
this.lastSentExp = -1; this.lastSentExp = -1;
this.lastHealthSent = -1.0F; this.lastHealthSent = -1.0F;
@@ -535,6 +662,7 @@ @@ -535,6 +663,7 @@
} }
public void a(boolean flag, boolean flag1, boolean flag2) { public void a(boolean flag, boolean flag1, boolean flag2) {
@ -341,7 +347,7 @@
if (this.isSleeping()) { if (this.isSleeping()) {
this.x().getTracker().sendPacketToEntity(this, new PacketPlayOutAnimation(this, 2)); this.x().getTracker().sendPacketToEntity(this, new PacketPlayOutAnimation(this, 2));
} }
@@ -613,23 +741,55 @@ @@ -613,23 +742,55 @@
this.playerConnection.sendPacket(new PacketPlayOutOpenSignEditor(tileentitysign.getPosition())); this.playerConnection.sendPacket(new PacketPlayOutOpenSignEditor(tileentitysign.getPosition()));
} }
@ -400,7 +406,7 @@
if (iinventory instanceof ILootable && ((ILootable) iinventory).b() != null && this.isSpectator()) { if (iinventory instanceof ILootable && ((ILootable) iinventory).b() != null && this.isSpectator()) {
this.a((new ChatMessage("container.spectatorCantOpen", new Object[0])).setChatModifier((new ChatModifier()).setColor(EnumChatFormat.RED)), true); this.a((new ChatMessage("container.spectatorCantOpen", new Object[0])).setChatModifier((new ChatModifier()).setColor(EnumChatFormat.RED)), true);
} else { } else {
@@ -643,18 +803,21 @@ @@ -643,18 +804,21 @@
if (itileinventory.isLocked() && !this.a(itileinventory.getLock()) && !this.isSpectator()) { if (itileinventory.isLocked() && !this.a(itileinventory.getLock()) && !this.isSpectator()) {
this.playerConnection.sendPacket(new PacketPlayOutChat(new ChatMessage("container.isLocked", new Object[] { iinventory.getScoreboardDisplayName()}), ChatMessageType.GAME_INFO)); this.playerConnection.sendPacket(new PacketPlayOutChat(new ChatMessage("container.isLocked", new Object[] { iinventory.getScoreboardDisplayName()}), ChatMessageType.GAME_INFO));
this.playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(SoundEffects.ab, SoundCategory.BLOCKS, this.locX, this.locY, this.locZ, 1.0F, 1.0F)); this.playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(SoundEffects.ab, SoundCategory.BLOCKS, this.locX, this.locY, this.locZ, 1.0F, 1.0F));
@ -424,7 +430,7 @@
this.activeContainer.windowId = this.containerCounter; this.activeContainer.windowId = this.containerCounter;
this.activeContainer.addSlotListener(this); this.activeContainer.addSlotListener(this);
@@ -662,8 +825,14 @@ @@ -662,8 +826,14 @@
} }
public void openTrade(IMerchant imerchant) { public void openTrade(IMerchant imerchant) {
@ -440,7 +446,7 @@
this.activeContainer.windowId = this.containerCounter; this.activeContainer.windowId = this.containerCounter;
this.activeContainer.addSlotListener(this); this.activeContainer.addSlotListener(this);
InventoryMerchant inventorymerchant = ((ContainerMerchant) this.activeContainer).e(); InventoryMerchant inventorymerchant = ((ContainerMerchant) this.activeContainer).e();
@@ -683,13 +852,20 @@ @@ -683,13 +853,20 @@
} }
public void openHorseInventory(EntityHorseAbstract entityhorseabstract, IInventory iinventory) { public void openHorseInventory(EntityHorseAbstract entityhorseabstract, IInventory iinventory) {
@ -462,7 +468,7 @@
this.activeContainer.windowId = this.containerCounter; this.activeContainer.windowId = this.containerCounter;
this.activeContainer.addSlotListener(this); this.activeContainer.addSlotListener(this);
} }
@@ -730,6 +906,11 @@ @@ -730,6 +907,11 @@
public void a(Container container, NonNullList<ItemStack> nonnulllist) { public void a(Container container, NonNullList<ItemStack> nonnulllist) {
this.playerConnection.sendPacket(new PacketPlayOutWindowItems(container.windowId, nonnulllist)); this.playerConnection.sendPacket(new PacketPlayOutWindowItems(container.windowId, nonnulllist));
this.playerConnection.sendPacket(new PacketPlayOutSetSlot(-1, -1, this.inventory.getCarried())); this.playerConnection.sendPacket(new PacketPlayOutSetSlot(-1, -1, this.inventory.getCarried()));
@ -474,7 +480,7 @@
} }
public void setContainerData(Container container, int i, int j) { public void setContainerData(Container container, int i, int j) {
@@ -744,6 +925,7 @@ @@ -744,6 +926,7 @@
} }
public void closeInventory() { public void closeInventory() {
@ -482,7 +488,7 @@
this.playerConnection.sendPacket(new PacketPlayOutCloseWindow(this.activeContainer.windowId)); this.playerConnection.sendPacket(new PacketPlayOutCloseWindow(this.activeContainer.windowId));
this.r(); this.r();
} }
@@ -818,7 +1000,7 @@ @@ -818,7 +1001,7 @@
arraylist.add(CraftingManager.a(minecraftkey)); arraylist.add(CraftingManager.a(minecraftkey));
} }
@ -491,7 +497,7 @@
} }
public void b(List<IRecipe> list) { public void b(List<IRecipe> list) {
@@ -840,7 +1022,16 @@ @@ -840,7 +1023,16 @@
public void triggerHealthUpdate() { public void triggerHealthUpdate() {
this.lastHealthSent = -1.0E8F; this.lastHealthSent = -1.0E8F;
@ -508,7 +514,7 @@
public void a(IChatBaseComponent ichatbasecomponent, boolean flag) { public void a(IChatBaseComponent ichatbasecomponent, boolean flag) {
this.playerConnection.sendPacket(new PacketPlayOutChat(ichatbasecomponent, flag ? ChatMessageType.GAME_INFO : ChatMessageType.CHAT)); this.playerConnection.sendPacket(new PacketPlayOutChat(ichatbasecomponent, flag ? ChatMessageType.GAME_INFO : ChatMessageType.CHAT));
@@ -880,7 +1071,7 @@ @@ -880,7 +1072,7 @@
this.lastSentExp = -1; this.lastSentExp = -1;
this.lastHealthSent = -1.0F; this.lastHealthSent = -1.0F;
this.ch = -1; this.ch = -1;
@ -517,7 +523,7 @@
this.removeQueue.addAll(entityplayer.removeQueue); this.removeQueue.addAll(entityplayer.removeQueue);
this.cq = entityplayer.cq; this.cq = entityplayer.cq;
this.cv = entityplayer.cv; this.cv = entityplayer.cv;
@@ -939,6 +1130,18 @@ @@ -939,6 +1131,18 @@
} }
public void a(EnumGamemode enumgamemode) { public void a(EnumGamemode enumgamemode) {
@ -536,7 +542,7 @@
this.playerInteractManager.setGameMode(enumgamemode); this.playerInteractManager.setGameMode(enumgamemode);
this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(3, (float) enumgamemode.getId())); this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(3, (float) enumgamemode.getId()));
if (enumgamemode == EnumGamemode.SPECTATOR) { if (enumgamemode == EnumGamemode.SPECTATOR) {
@@ -965,6 +1168,7 @@ @@ -965,6 +1169,7 @@
} }
public boolean a(int i, String s) { public boolean a(int i, String s) {
@ -544,7 +550,7 @@
if ("seed".equals(s) && !this.server.aa()) { if ("seed".equals(s) && !this.server.aa()) {
return true; return true;
} else if (!"tell".equals(s) && !"help".equals(s) && !"me".equals(s) && !"trigger".equals(s)) { } else if (!"tell".equals(s) && !"help".equals(s) && !"me".equals(s) && !"trigger".equals(s)) {
@@ -978,6 +1182,15 @@ @@ -978,6 +1183,15 @@
} else { } else {
return true; return true;
} }
@ -560,7 +566,7 @@
} }
public String A() { public String A() {
@@ -989,6 +1202,12 @@ @@ -989,6 +1203,16 @@
} }
public void a(PacketPlayInSettings packetplayinsettings) { public void a(PacketPlayInSettings packetplayinsettings) {
@ -569,11 +575,15 @@
+ PlayerChangedMainHandEvent event = new PlayerChangedMainHandEvent(getBukkitEntity(), getMainHand() == EnumMainHand.LEFT ? MainHand.LEFT : MainHand.RIGHT); + PlayerChangedMainHandEvent event = new PlayerChangedMainHandEvent(getBukkitEntity(), getMainHand() == EnumMainHand.LEFT ? MainHand.LEFT : MainHand.RIGHT);
+ this.server.server.getPluginManager().callEvent(event); + this.server.server.getPluginManager().callEvent(event);
+ } + }
+ if (!this.locale.equals(packetplayinsettings.a())) {
+ PlayerLocaleChangeEvent event = new PlayerLocaleChangeEvent(getBukkitEntity(), packetplayinsettings.a());
+ this.server.server.getPluginManager().callEvent(event);
+ }
+ // CraftBukkit end + // CraftBukkit end
this.locale = packetplayinsettings.a(); this.locale = packetplayinsettings.a();
this.cl = packetplayinsettings.c(); this.cl = packetplayinsettings.c();
this.cm = packetplayinsettings.d(); this.cm = packetplayinsettings.d();
@@ -1054,7 +1273,7 @@ @@ -1054,7 +1278,7 @@
this.co = (Entity) (entity == null ? this : entity); this.co = (Entity) (entity == null ? this : entity);
if (entity1 != this.co) { if (entity1 != this.co) {
this.playerConnection.sendPacket(new PacketPlayOutCamera(this.co)); this.playerConnection.sendPacket(new PacketPlayOutCamera(this.co));
@ -582,7 +592,7 @@
} }
} }
@@ -1081,7 +1300,7 @@ @@ -1081,7 +1305,7 @@
@Nullable @Nullable
public IChatBaseComponent getPlayerListName() { public IChatBaseComponent getPlayerListName() {
@ -591,7 +601,7 @@
} }
public void a(EnumHand enumhand) { public void a(EnumHand enumhand) {
@@ -1098,12 +1317,17 @@ @@ -1098,12 +1322,17 @@
} }
public void N() { public void N() {
@ -609,7 +619,7 @@
} }
public AdvancementDataPlayer getAdvancementData() { public AdvancementDataPlayer getAdvancementData() {
@@ -1114,4 +1338,139 @@ @@ -1114,4 +1343,139 @@
public Vec3D Q() { public Vec3D Q() {
return this.cv; return this.cv;
} }

View File

@ -15,7 +15,6 @@ import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@ -1446,4 +1445,9 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
return new CraftAdvancementProgress(craft, data, progress); return new CraftAdvancementProgress(craft, data, progress);
} }
@Override
public String getLocale() {
return getHandle().locale;
}
} }