SPIGOT-943: InventoryCloseEvent called on death regardless of open inventory

This commit is contained in:
md_5 2018-12-27 11:36:53 +11:00
parent 0afed59271
commit b4a4f15dbf

View file

@ -51,7 +51,7 @@
public EntityPlayer(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile, PlayerInteractManager playerinteractmanager) {
super((World) worldserver, gameprofile);
playerinteractmanager.player = this;
@@ -61,8 +93,50 @@
@@ -61,7 +93,49 @@
this.cf = minecraftserver.getPlayerList().h(this);
this.Q = 1.0F;
this.a(worldserver);
@ -60,8 +60,8 @@
+ this.displayName = this.getName();
+ this.canPickUpLoot = true;
+ this.maxHealthCache = this.getMaxHealth();
}
+ }
+
+ // Yes, this doesn't match Vanilla, but it's the best we can do for now.
+ // If this is an issue, PRs are welcome
+ public final BlockPosition getSpawnPoint(WorldServer worldserver) {
@ -96,12 +96,11 @@
+ }
+
+ return blockposition;
+ }
}
+ // CraftBukkit end
+
private void a(WorldServer worldserver) {
BlockPosition blockposition = worldserver.getSpawn();
@@ -129,6 +203,7 @@
if (nbttagcompound.hasKeyOfType("recipeBook", 10)) {
this.recipeBook.a(nbttagcompound.getCompound("recipeBook"));
@ -132,13 +131,13 @@
NBTTagCompound nbttagcompound2 = new NBTTagCompound();
NBTTagCompound nbttagcompound3 = new NBTTagCompound();
@@ -159,8 +247,34 @@
@@ -159,7 +247,33 @@
}
nbttagcompound.set("recipeBook", this.recipeBook.e());
+ this.getBukkitEntity().setExtraData(nbttagcompound); // CraftBukkit
}
+ }
+
+ // CraftBukkit start - World fallback code, either respawn location or global spawn
+ public void spawnIn(World world) {
+ super.spawnIn(world);
@ -161,12 +160,11 @@
+ }
+ this.dimension = ((WorldServer) this.world).dimension;
+ this.playerInteractManager.a((WorldServer) world);
+ }
}
+ // CraftBukkit end
+
public void a(int i) {
float f = (float) this.getExpToLevel();
float f1 = (f - 1.0F) / f;
@@ -207,6 +321,11 @@
}
@ -218,7 +216,7 @@
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.a(throwable, "Ticking player");
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Player being ticked");
@@ -327,16 +462,43 @@
@@ -327,16 +462,48 @@
}
private void a(IScoreboardCriteria iscoreboardcriteria, int i) {
@ -253,6 +251,11 @@
+ String deathmessage = defaultMessage.getString();
+ org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, deathmessage, keepInventory);
+
+ // SPIGOT-943 - only call if they have an inventory open
+ if (this.activeContainer != this.defaultContainer) {
+ this.closeInventory();
+ }
+
+ String deathMessage = event.getDeathMessage();
+
+ if (deathMessage != null && deathMessage.length() > 0 && flag) { // TODO: allow plugins to override?
@ -265,29 +268,29 @@
this.playerConnection.a((Packet) (new PacketPlayOutCombatEvent(this.getCombatTracker(), PacketPlayOutCombatEvent.EnumCombatEventType.ENTITY_DIED, ichatbasecomponent)), (future) -> {
if (!future.isSuccess()) {
@@ -367,12 +529,17 @@
@@ -367,12 +534,16 @@
}
this.releaseShoulderEntities();
- if (!this.world.getGameRules().getBoolean("keepInventory") && !this.isSpectator()) {
- this.removeCursedItems();
- this.inventory.dropContents();
- }
+ // we clean the player's inventory after the EntityDeathEvent is called so plugins can get the exact state of the inventory.
+ if (!event.getKeepInventory()) {
+ this.inventory.clear();
}
- this.getScoreboard().getObjectivesForCriteria(IScoreboardCriteria.DEATH_COUNT, this.getName(), ScoreboardScore::incrementScore);
+ this.closeInventory();
+ }
+
+ this.setSpectatorTarget(this); // Remove spectated target
+ // CraftBukkit end
+
- this.getScoreboard().getObjectivesForCriteria(IScoreboardCriteria.DEATH_COUNT, this.getName(), ScoreboardScore::incrementScore);
+ // CraftBukkit - Get our scores instead
+ this.world.getServer().getScoreboardManager().getScoreboardScores(IScoreboardCriteria.DEATH_COUNT, this.getName(), ScoreboardScore::incrementScore);
EntityLiving entityliving = this.cv();
if (entityliving != null) {
@@ -395,10 +562,12 @@
@@ -395,10 +566,12 @@
String s = this.getName();
String s1 = entity.getName();
@ -302,7 +305,7 @@
} else {
this.a(StatisticList.MOB_KILLS);
}
@@ -416,7 +585,8 @@
@@ -416,7 +589,8 @@
int i = scoreboardteam.getColor().b();
if (i >= 0 && i < aiscoreboardcriteria.length) {
@ -312,7 +315,7 @@
}
}
@@ -458,12 +628,14 @@
@@ -458,12 +632,14 @@
}
private boolean canPvP() {
@ -329,7 +332,7 @@
if (this.dimension == DimensionManager.OVERWORLD && dimensionmanager == DimensionManager.NETHER) {
this.cC = new Vec3D(this.locX, this.locY, this.locZ);
} else if (this.dimension != DimensionManager.NETHER && dimensionmanager != DimensionManager.OVERWORLD) {
@@ -471,6 +643,7 @@
@@ -471,6 +647,7 @@
}
if (this.dimension == DimensionManager.THE_END && dimensionmanager == DimensionManager.THE_END) {
@ -337,7 +340,7 @@
this.world.kill(this);
if (!this.viewingCredits) {
this.viewingCredits = true;
@@ -484,7 +657,10 @@
@@ -484,7 +661,10 @@
dimensionmanager = DimensionManager.THE_END;
}
@ -349,7 +352,7 @@
this.playerConnection.sendPacket(new PacketPlayOutWorldEvent(1032, BlockPosition.ZERO, 0, false));
this.lastSentExp = -1;
this.lastHealthSent = -1.0F;
@@ -530,6 +706,7 @@
@@ -530,6 +710,7 @@
}
public void a(boolean flag, boolean flag1, boolean flag2) {
@ -357,7 +360,7 @@
if (this.isSleeping()) {
this.getWorldServer().getTracker().sendPacketToEntity(this, new PacketPlayOutAnimation(this, 2));
}
@@ -608,23 +785,55 @@
@@ -608,23 +789,55 @@
this.playerConnection.sendPacket(new PacketPlayOutOpenSignEditor(tileentitysign.getPosition()));
}
@ -416,7 +419,7 @@
if (iinventory instanceof ILootable && ((ILootable) iinventory).getLootTable() != null && this.isSpectator()) {
this.a((new ChatMessage("container.spectatorCantOpen", new Object[0])).a(EnumChatFormat.RED), true);
} else {
@@ -638,18 +847,21 @@
@@ -638,18 +851,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.BLOCK_CHEST_LOCKED, SoundCategory.BLOCKS, this.locX, this.locY, this.locZ, 1.0F, 1.0F));
@ -440,7 +443,7 @@
this.activeContainer.windowId = this.containerCounter;
this.activeContainer.addSlotListener(this);
@@ -657,8 +869,14 @@
@@ -657,8 +873,14 @@
}
public void openTrade(IMerchant imerchant) {
@ -456,7 +459,7 @@
this.activeContainer.windowId = this.containerCounter;
this.activeContainer.addSlotListener(this);
InventoryMerchant inventorymerchant = ((ContainerMerchant) this.activeContainer).d();
@@ -678,13 +896,20 @@
@@ -678,13 +900,20 @@
}
public void openHorseInventory(EntityHorseAbstract entityhorseabstract, IInventory iinventory) {
@ -478,7 +481,7 @@
this.activeContainer.windowId = this.containerCounter;
this.activeContainer.addSlotListener(this);
}
@@ -725,6 +950,11 @@
@@ -725,6 +954,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()));
@ -490,7 +493,7 @@
}
public void setContainerData(Container container, int i, int j) {
@@ -739,6 +969,7 @@
@@ -739,6 +973,7 @@
}
public void closeInventory() {
@ -498,7 +501,7 @@
this.playerConnection.sendPacket(new PacketPlayOutCloseWindow(this.activeContainer.windowId));
this.m();
}
@@ -772,14 +1003,14 @@
@@ -772,14 +1007,14 @@
public void a(Statistic<?> statistic, int i) {
this.cg.b(this, statistic, i);
@ -515,7 +518,7 @@
}
public int discoverRecipes(Collection<IRecipe> collection) {
@@ -827,8 +1058,17 @@
@@ -827,8 +1062,17 @@
public void triggerHealthUpdate() {
this.lastHealthSent = -1.0E8F;
@ -533,7 +536,7 @@
public void a(IChatBaseComponent ichatbasecomponent, boolean flag) {
this.playerConnection.sendPacket(new PacketPlayOutChat(ichatbasecomponent, flag ? ChatMessageType.GAME_INFO : ChatMessageType.CHAT));
}
@@ -879,7 +1119,7 @@
@@ -879,7 +1123,7 @@
this.lastSentExp = -1;
this.lastHealthSent = -1.0F;
this.lastFoodSent = -1;
@ -542,7 +545,7 @@
this.removeQueue.addAll(entityplayer.removeQueue);
this.cx = entityplayer.cx;
this.cC = entityplayer.cC;
@@ -938,6 +1178,18 @@
@@ -938,6 +1182,18 @@
}
public void a(EnumGamemode enumgamemode) {
@ -561,7 +564,7 @@
this.playerInteractManager.setGameMode(enumgamemode);
this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(3, (float) enumgamemode.getId()));
if (enumgamemode == EnumGamemode.SPECTATOR) {
@@ -985,6 +1237,17 @@
@@ -985,6 +1241,17 @@
}
public void a(PacketPlayInSettings packetplayinsettings) {
@ -579,7 +582,7 @@
this.locale = packetplayinsettings.b();
this.cs = packetplayinsettings.d();
this.ct = packetplayinsettings.e();
@@ -1020,13 +1283,13 @@
@@ -1020,13 +1287,13 @@
if (entity instanceof EntityHuman) {
this.playerConnection.sendPacket(new PacketPlayOutEntityDestroy(new int[] { entity.getId()}));
} else {
@ -595,7 +598,7 @@
}
protected void C() {
@@ -1050,7 +1313,7 @@
@@ -1050,7 +1317,7 @@
this.spectatedEntity = (Entity) (entity == null ? this : entity);
if (entity1 != this.spectatedEntity) {
this.playerConnection.sendPacket(new PacketPlayOutCamera(this.spectatedEntity));
@ -604,7 +607,7 @@
}
}
@@ -1077,7 +1340,7 @@
@@ -1077,7 +1344,7 @@
@Nullable
public IChatBaseComponent getPlayerListName() {
@ -613,7 +616,7 @@
}
public void a(EnumHand enumhand) {
@@ -1094,12 +1357,17 @@
@@ -1094,12 +1361,17 @@
}
public void J() {
@ -631,7 +634,7 @@
}
public AdvancementDataPlayer getAdvancementData() {
@@ -1111,9 +1379,16 @@
@@ -1111,9 +1383,16 @@
return this.cC;
}
@ -648,7 +651,7 @@
if (worldserver == this.world) {
this.playerConnection.a(d0, d1, d2, f, f1);
} else {
@@ -1138,6 +1413,149 @@
@@ -1138,6 +1417,149 @@
this.server.getPlayerList().b(this, worldserver);
this.server.getPlayerList().updateClient(this);
}