SPIGOT-4875: PlayerChangedWorldEvent does not fire on teleporting via portals

This commit is contained in:
md_5 2019-05-06 08:38:29 +10:00
parent 5f89a0e3c1
commit 40484a5fa0

View File

@ -1,6 +1,6 @@
--- a/net/minecraft/server/EntityPlayer.java
+++ b/net/minecraft/server/EntityPlayer.java
@@ -13,10 +13,30 @@
@@ -13,10 +13,31 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -16,6 +16,7 @@
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.inventory.InventoryType;
+import org.bukkit.event.player.PlayerChangedMainHandEvent;
+import org.bukkit.event.player.PlayerChangedWorldEvent;
+import org.bukkit.event.player.PlayerGameModeChangeEvent;
+import org.bukkit.event.player.PlayerLocaleChangeEvent;
+import org.bukkit.event.player.PlayerPortalEvent;
@ -32,7 +33,7 @@
public PlayerConnection playerConnection;
public final MinecraftServer server;
public final PlayerInteractManager playerInteractManager;
@@ -52,6 +72,20 @@
@@ -52,6 +73,20 @@
public int ping;
public boolean viewingCredits;
@ -53,7 +54,7 @@
public EntityPlayer(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile, PlayerInteractManager playerinteractmanager) {
super((World) worldserver, gameprofile);
playerinteractmanager.player = this;
@@ -62,8 +96,50 @@
@@ -62,8 +97,50 @@
this.advancementDataPlayer = minecraftserver.getPlayerList().f(this);
this.K = 1.0F;
this.a(worldserver);
@ -104,7 +105,7 @@
private void a(WorldServer worldserver) {
BlockPosition blockposition = worldserver.getSpawn();
@@ -131,6 +207,7 @@
@@ -131,6 +208,7 @@
if (nbttagcompound.hasKeyOfType("recipeBook", 10)) {
this.recipeBook.a(nbttagcompound.getCompound("recipeBook"));
}
@ -112,7 +113,7 @@
if (this.isSleeping()) {
this.dy();
@@ -155,7 +232,20 @@
@@ -155,7 +233,20 @@
Entity entity = this.getRootVehicle();
Entity entity1 = this.getVehicle();
@ -134,7 +135,7 @@
NBTTagCompound nbttagcompound2 = new NBTTagCompound();
NBTTagCompound nbttagcompound3 = new NBTTagCompound();
@@ -166,7 +256,33 @@
@@ -166,7 +257,33 @@
}
nbttagcompound.set("recipeBook", this.recipeBook.save());
@ -168,7 +169,7 @@
public void a(int i) {
float f = (float) this.getExpToLevel();
@@ -221,6 +337,11 @@
@@ -221,6 +338,11 @@
@Override
public void tick() {
@ -180,7 +181,7 @@
this.playerInteractManager.a();
--this.invulnerableTicks;
if (this.noDamageTicks > 0) {
@@ -288,7 +409,7 @@
@@ -288,7 +410,7 @@
}
if (this.getHealth() != this.lastHealthSent || this.lastFoodSent != this.foodData.getFoodLevel() || this.foodData.getSaturationLevel() == 0.0F != this.lastSentSaturationZero) {
@ -189,7 +190,7 @@
this.lastHealthSent = this.getHealth();
this.lastFoodSent = this.foodData.getFoodLevel();
this.lastSentSaturationZero = this.foodData.getSaturationLevel() == 0.0F;
@@ -319,6 +440,12 @@
@@ -319,6 +441,12 @@
this.a(IScoreboardCriteria.XP, MathHelper.f((float) this.lastExpTotalScored));
}
@ -202,7 +203,7 @@
if (this.expLevel != this.lastExpLevelScored) {
this.lastExpLevelScored = this.expLevel;
this.a(IScoreboardCriteria.LEVEL, MathHelper.f((float) this.lastExpLevelScored));
@@ -333,6 +460,16 @@
@@ -333,6 +461,16 @@
CriterionTriggers.p.a(this);
}
@ -219,7 +220,7 @@
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.a(throwable, "Ticking player");
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Player being ticked");
@@ -343,7 +480,8 @@
@@ -343,7 +481,8 @@
}
private void a(IScoreboardCriteria iscoreboardcriteria, int i) {
@ -229,7 +230,7 @@
scoreboardscore.setScore(i);
});
}
@@ -351,9 +489,40 @@
@@ -351,9 +490,40 @@
@Override
public void die(DamageSource damagesource) {
boolean flag = this.world.getGameRules().getBoolean("showDeathMessages");
@ -272,7 +273,7 @@
this.playerConnection.a((Packet) (new PacketPlayOutCombatEvent(this.getCombatTracker(), PacketPlayOutCombatEvent.EnumCombatEventType.ENTITY_DIED, ichatbasecomponent)), (future) -> {
if (!future.isSuccess()) {
@@ -384,11 +553,16 @@
@@ -384,11 +554,16 @@
}
this.releaseShoulderEntities();
@ -292,7 +293,7 @@
EntityLiving entityliving = this.getKillingEntity();
if (entityliving != null) {
@@ -431,10 +605,12 @@
@@ -431,10 +606,12 @@
String s = this.getName();
String s1 = entity.getName();
@ -307,7 +308,7 @@
} else {
this.a(StatisticList.MOB_KILLS);
}
@@ -452,7 +628,8 @@
@@ -452,7 +629,8 @@
int i = scoreboardteam.getColor().b();
if (i >= 0 && i < aiscoreboardcriteria.length) {
@ -317,7 +318,7 @@
}
}
@@ -496,16 +673,26 @@
@@ -496,16 +674,26 @@
}
private boolean canPvP() {
@ -346,7 +347,7 @@
this.decouple();
this.getWorldServer().removePlayer(this);
if (!this.viewingCredits) {
@@ -518,10 +705,16 @@
@@ -518,10 +706,16 @@
} else {
WorldServer worldserver = this.server.getWorldServer(dimensionmanager1);
@ -364,7 +365,7 @@
this.playerConnection.sendPacket(new PacketPlayOutRespawn(dimensionmanager, worlddata.getType(), this.playerInteractManager.getGameMode()));
this.playerConnection.sendPacket(new PacketPlayOutServerDifficulty(worlddata.getDifficulty(), worlddata.isDifficultyLocked()));
PlayerList playerlist = this.server.getPlayerList();
@@ -529,6 +722,8 @@
@@ -529,6 +723,8 @@
playerlist.d(this);
worldserver.removePlayer(this);
this.dead = false;
@ -373,7 +374,7 @@
double d0 = this.locX;
double d1 = this.locY;
double d2 = this.locZ;
@@ -555,6 +750,52 @@
@@ -555,6 +751,52 @@
f = 0.0F;
}
@ -426,7 +427,7 @@
this.setPositionRotation(d0, d1, d2, f1, f);
worldserver.getMethodProfiler().exit();
worldserver.getMethodProfiler().enter("placing");
@@ -572,6 +813,7 @@
@@ -572,6 +814,7 @@
int k = MathHelper.floor(this.locZ);
boolean flag = true;
boolean flag1 = false;
@ -434,7 +435,7 @@
for (int l = -2; l <= 2; ++l) {
for (int i1 = -2; i1 <= 2; ++i1) {
@@ -581,11 +823,20 @@
@@ -581,11 +824,20 @@
int i2 = k + i1 * 0 - l * 1;
boolean flag2 = j1 < 0;
@ -456,7 +457,16 @@
this.setPositionRotation((double) i, (double) j, (double) k, f1, 0.0F);
this.setMot(Vec3D.a);
} else if (!worldserver1.getTravelAgent().a(this, f2)) {
@@ -618,7 +869,7 @@
@@ -614,11 +866,16 @@
this.lastSentExp = -1;
this.lastHealthSent = -1.0F;
this.lastFoodSent = -1;
+
+ // CraftBukkit start
+ PlayerChangedWorldEvent changeEvent = new PlayerChangedWorldEvent(this.getBukkitEntity(), worldserver.getWorld());
+ this.world.getServer().getPluginManager().callEvent(changeEvent);
+ // CraftBukkit end
return this;
}
}
@ -465,7 +475,7 @@
DimensionManager dimensionmanager = worldserver.worldProvider.getDimensionManager();
DimensionManager dimensionmanager1 = this.world.worldProvider.getDimensionManager();
@@ -655,9 +906,16 @@
@@ -655,9 +912,16 @@
this.activeContainer.c();
}
@ -484,7 +494,7 @@
this.a(StatisticList.SLEEP_IN_BED);
CriterionTriggers.q.a(this);
});
@@ -665,6 +923,7 @@
@@ -665,6 +929,7 @@
@Override
public void wakeup(boolean flag, boolean flag1, boolean flag2) {
@ -492,7 +502,7 @@
if (this.isSleeping()) {
this.getWorldServer().getChunkProvider().broadcastIncludingSelf(this, new PacketPlayOutAnimation(this, 2));
}
@@ -752,8 +1011,9 @@
@@ -752,8 +1017,9 @@
this.playerConnection.sendPacket(new PacketPlayOutOpenSignEditor(tileentitysign.getPosition()));
}
@ -503,7 +513,7 @@
}
@Override
@@ -768,6 +1028,17 @@
@@ -768,6 +1034,17 @@
this.nextContainerCounter();
Container container = itileinventory.createMenu(this.containerCounter, this.inventory, this);
@ -521,7 +531,7 @@
if (container == null) {
if (this.isSpectator()) {
this.a((new ChatMessage("container.spectatorCantOpen", new Object[0])).a(EnumChatFormat.RED), true);
@@ -775,9 +1046,11 @@
@@ -775,9 +1052,11 @@
return OptionalInt.empty();
} else {
@ -535,7 +545,7 @@
return OptionalInt.of(this.containerCounter);
}
}
@@ -790,13 +1063,21 @@
@@ -790,13 +1069,21 @@
@Override
public void openHorseInventory(EntityHorseAbstract entityhorseabstract, IInventory iinventory) {
@ -559,7 +569,7 @@
this.activeContainer.addSlotListener(this);
}
@@ -841,6 +1122,11 @@
@@ -841,6 +1128,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()));
@ -571,7 +581,7 @@
}
@Override
@@ -850,6 +1136,7 @@
@@ -850,6 +1142,7 @@
@Override
public void closeInventory() {
@ -579,7 +589,7 @@
this.playerConnection.sendPacket(new PacketPlayOutCloseWindow(this.activeContainer.windowId));
this.m();
}
@@ -884,7 +1171,7 @@
@@ -884,7 +1177,7 @@
@Override
public void a(Statistic<?> statistic, int i) {
this.serverStatisticManager.b(this, statistic, i);
@ -588,7 +598,7 @@
scoreboardscore.addScore(i);
});
}
@@ -892,7 +1179,7 @@
@@ -892,7 +1185,7 @@
@Override
public void a(Statistic<?> statistic) {
this.serverStatisticManager.setStatistic(this, statistic, 0);
@ -597,25 +607,24 @@
}
@Override
@@ -941,8 +1228,17 @@
@@ -941,7 +1234,16 @@
public void triggerHealthUpdate() {
this.lastHealthSent = -1.0E8F;
+ this.lastSentExp = -1; // CraftBukkit - Added to reset
}
+ }
+
+ // CraftBukkit start - Support multi-line messages
+ public void sendMessage(IChatBaseComponent[] ichatbasecomponent) {
+ for (IChatBaseComponent component : ichatbasecomponent) {
+ this.sendMessage(component);
+ }
+ }
}
+ // CraftBukkit end
+
@Override
public void a(IChatBaseComponent ichatbasecomponent, boolean flag) {
this.playerConnection.sendPacket(new PacketPlayOutChat(ichatbasecomponent, flag ? ChatMessageType.GAME_INFO : ChatMessageType.CHAT));
@@ -996,12 +1292,14 @@
@@ -996,12 +1298,14 @@
this.lastSentExp = -1;
this.lastHealthSent = -1.0F;
this.lastFoodSent = -1;
@ -631,7 +640,7 @@
}
@Override
@@ -1063,6 +1361,18 @@
@@ -1063,6 +1367,18 @@
@Override
public void a(EnumGamemode enumgamemode) {
@ -650,7 +659,7 @@
this.playerInteractManager.setGameMode(enumgamemode);
this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(3, (float) enumgamemode.getId()));
if (enumgamemode == EnumGamemode.SPECTATOR) {
@@ -1113,6 +1423,17 @@
@@ -1113,6 +1429,17 @@
}
public void a(PacketPlayInSettings packetplayinsettings) {
@ -668,7 +677,7 @@
this.locale = packetplayinsettings.b();
this.ck = packetplayinsettings.d();
this.cl = packetplayinsettings.e();
@@ -1149,13 +1470,13 @@
@@ -1149,13 +1476,13 @@
if (entity instanceof EntityHuman) {
this.playerConnection.sendPacket(new PacketPlayOutEntityDestroy(new int[] { entity.getId()}));
} else {
@ -684,7 +693,7 @@
}
@Override
@@ -1179,7 +1500,7 @@
@@ -1179,7 +1506,7 @@
this.spectatedEntity = (Entity) (entity == null ? this : entity);
if (entity1 != this.spectatedEntity) {
this.playerConnection.sendPacket(new PacketPlayOutCamera(this.spectatedEntity));
@ -693,7 +702,7 @@
}
}
@@ -1208,7 +1529,7 @@
@@ -1208,7 +1535,7 @@
@Nullable
public IChatBaseComponent getPlayerListName() {
@ -702,7 +711,7 @@
}
@Override
@@ -1226,21 +1547,33 @@
@@ -1226,21 +1553,33 @@
}
public void J() {
@ -736,7 +745,7 @@
if (worldserver == this.world) {
this.playerConnection.a(d0, d1, d2, f, f1);
} else {
@@ -1263,6 +1596,9 @@
@@ -1263,6 +1602,9 @@
this.server.getPlayerList().a(this, worldserver);
this.server.getPlayerList().updateClient(this);
}
@ -746,7 +755,7 @@
}
@@ -1314,4 +1650,144 @@
@@ -1314,4 +1656,144 @@
return entityitem;
}
}