SPIGOT-439: Add player locale related APIs.

Dieser Commit ist enthalten in:
MiniDigger 2017-05-26 23:37:06 +02:00 committet von md_5
Ursprung a479029a85
Commit 274304b8ca
2 geänderte Dateien mit 49 neuen und 35 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

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