SPIGOT-227: Add entity persistent flag

Non-persistent entities won't get saved when the chunk saves the entities.
Entities that are passengers of a non-persistent entity won't get saved.
Players won't save their vehicle, if the player is directly or
indirectly riding a non-persistent entity.

By: blablubbabc <lukas@wirsindwir.de>
This commit is contained in:
CraftBukkit/Spigot
2018-06-14 19:59:21 +02:00
parent 888b0dc31b
commit 94950beea7
3 changed files with 109 additions and 67 deletions

View File

@@ -51,7 +51,7 @@
public EntityPlayer(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile, PlayerInteractManager playerinteractmanager) {
super((World) worldserver, gameprofile);
playerinteractmanager.player = this;
@@ -65,7 +96,49 @@
@@ -65,8 +96,50 @@
this.cg = 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,11 +96,12 @@
+ }
+
+ return blockposition;
}
+ }
+ // CraftBukkit end
+
private void a(WorldServer worldserver) {
BlockPosition blockposition = worldserver.getSpawn();
@@ -133,6 +206,7 @@
if (nbttagcompound.hasKeyOfType("recipeBook", 10)) {
this.cz.a(nbttagcompound.getCompound("recipeBook"));
@@ -109,7 +110,29 @@
}
@@ -163,8 +237,34 @@
@@ -152,7 +226,20 @@
Entity entity = this.getRootVehicle();
Entity entity1 = this.getVehicle();
- if (entity1 != null && entity != this && entity.bR()) {
+ // CraftBukkit start - handle non-persistent vehicles
+ boolean persistVehicle = true;
+ if (entity1 != null) {
+ Entity vehicle;
+ for (vehicle = entity1; vehicle != null; vehicle = vehicle.getVehicle()) {
+ if (!vehicle.persist) {
+ persistVehicle = false;
+ break;
+ }
+ }
+ }
+
+ if (persistVehicle && entity1 != null && entity != this && entity.bR()) {
+ // CraftBukkit end
NBTTagCompound nbttagcompound2 = new NBTTagCompound();
NBTTagCompound nbttagcompound3 = new NBTTagCompound();
@@ -163,8 +250,34 @@
}
nbttagcompound.set("recipeBook", this.cz.e());
@@ -144,7 +167,7 @@
public void a(int i) {
float f = (float) this.getExpToLevel();
float f1 = (f - 1.0F) / f;
@@ -211,6 +311,11 @@
@@ -211,6 +324,11 @@
}
public void tick() {
@@ -156,7 +179,7 @@
this.playerInteractManager.a();
--this.invulnerableTicks;
if (this.noDamageTicks > 0) {
@@ -276,7 +381,7 @@
@@ -276,7 +394,7 @@
}
if (this.getHealth() != this.lastHealthSent || this.cp != this.foodData.getFoodLevel() || this.foodData.getSaturationLevel() == 0.0F != this.cq) {
@@ -165,7 +188,7 @@
this.lastHealthSent = this.getHealth();
this.cp = this.foodData.getFoodLevel();
this.cq = this.foodData.getSaturationLevel() == 0.0F;
@@ -307,6 +412,12 @@
@@ -307,6 +425,12 @@
this.a(IScoreboardCriteria.k, MathHelper.f((float) this.cn));
}
@@ -178,7 +201,7 @@
if (this.expLevel != this.cm) {
this.cm = this.expLevel;
this.a(IScoreboardCriteria.l, MathHelper.f((float) this.cm));
@@ -321,6 +432,16 @@
@@ -321,6 +445,16 @@
CriterionTriggers.p.a(this);
}
@@ -195,7 +218,7 @@
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.a(throwable, "Ticking player");
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Player being ticked");
@@ -331,7 +452,8 @@
@@ -331,7 +465,8 @@
}
private void a(IScoreboardCriteria iscoreboardcriteria, int i) {
@@ -205,7 +228,7 @@
scoreboardscore.setScore(i);
});
}
@@ -340,27 +462,59 @@
@@ -340,27 +475,59 @@
boolean flag = this.world.getGameRules().getBoolean("showDeathMessages");
this.playerConnection.sendPacket(new PacketPlayOutCombatEvent(this.getCombatTracker(), PacketPlayOutCombatEvent.EnumCombatEventType.ENTITY_DIED, flag));
@@ -225,17 +248,17 @@
+ }
+ }
+ }
+
+ IChatBaseComponent chatmessage = this.getCombatTracker().getDeathMessage();
+
+ String deathmessage = chatmessage.getString();
+ org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, deathmessage, keepInventory);
- if (scoreboardteambase != null && scoreboardteambase.getDeathMessageVisibility() != ScoreboardTeamBase.EnumNameTagVisibility.ALWAYS) {
- if (scoreboardteambase.getDeathMessageVisibility() == ScoreboardTeamBase.EnumNameTagVisibility.HIDE_FOR_OTHER_TEAMS) {
- this.server.getPlayerList().a((EntityHuman) this, this.getCombatTracker().getDeathMessage());
- } else if (scoreboardteambase.getDeathMessageVisibility() == ScoreboardTeamBase.EnumNameTagVisibility.HIDE_FOR_OWN_TEAM) {
- this.server.getPlayerList().b((EntityHuman) this, this.getCombatTracker().getDeathMessage());
+ IChatBaseComponent chatmessage = this.getCombatTracker().getDeathMessage();
+
+ String deathmessage = chatmessage.getString();
+ org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, deathmessage, keepInventory);
+
+ String deathMessage = event.getDeathMessage();
+
+ if (deathMessage != null && deathMessage.length() > 0 && flag) { // TODO: allow plugins to override?
@@ -277,7 +300,7 @@
EntityLiving entityliving = this.cv();
if (entityliving != null) {
@@ -383,10 +537,12 @@
@@ -383,10 +550,12 @@
String s = this.getName();
String s1 = entity.getName();
@@ -292,7 +315,7 @@
} else {
this.a(StatisticList.MOB_KILLS);
}
@@ -404,7 +560,8 @@
@@ -404,7 +573,8 @@
int i = scoreboardteam.getColor().b();
if (i >= 0 && i < aiscoreboardcriteria.length) {
@@ -302,7 +325,7 @@
}
}
@@ -445,12 +602,14 @@
@@ -445,12 +615,14 @@
}
private boolean canPvP() {
@@ -319,7 +342,7 @@
if (this.dimension == 0 && i == -1) {
this.cD = new Vec3D(this.locX, this.locY, this.locZ);
} else if (this.dimension != -1 && i != 0) {
@@ -458,6 +617,7 @@
@@ -458,6 +630,7 @@
}
if (this.dimension == 1 && i == 1) {
@@ -327,7 +350,7 @@
this.world.kill(this);
if (!this.viewingCredits) {
this.viewingCredits = true;
@@ -471,7 +631,10 @@
@@ -471,7 +644,10 @@
i = 1;
}
@@ -339,7 +362,7 @@
this.playerConnection.sendPacket(new PacketPlayOutWorldEvent(1032, BlockPosition.ZERO, 0, false));
this.lastSentExp = -1;
this.lastHealthSent = -1.0F;
@@ -517,6 +680,7 @@
@@ -517,6 +693,7 @@
}
public void a(boolean flag, boolean flag1, boolean flag2) {
@@ -347,7 +370,7 @@
if (this.isSleeping()) {
this.getWorldServer().getTracker().sendPacketToEntity(this, new PacketPlayOutAnimation(this, 2));
}
@@ -595,23 +759,55 @@
@@ -595,23 +772,55 @@
this.playerConnection.sendPacket(new PacketPlayOutOpenSignEditor(tileentitysign.getPosition()));
}
@@ -406,7 +429,7 @@
if (iinventory instanceof ILootable && ((ILootable) iinventory).Q_() != null && this.isSpectator()) {
this.a((new ChatMessage("container.spectatorCantOpen", new Object[0])).a(EnumChatFormat.RED), true);
} else {
@@ -625,18 +821,21 @@
@@ -625,18 +834,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));
@@ -430,7 +453,7 @@
this.activeContainer.windowId = this.containerCounter;
this.activeContainer.addSlotListener(this);
@@ -644,8 +843,14 @@
@@ -644,8 +856,14 @@
}
public void openTrade(IMerchant imerchant) {
@@ -446,7 +469,7 @@
this.activeContainer.windowId = this.containerCounter;
this.activeContainer.addSlotListener(this);
InventoryMerchant inventorymerchant = ((ContainerMerchant) this.activeContainer).d();
@@ -665,13 +870,20 @@
@@ -665,13 +883,20 @@
}
public void openHorseInventory(EntityHorseAbstract entityhorseabstract, IInventory iinventory) {
@@ -468,7 +491,7 @@
this.activeContainer.windowId = this.containerCounter;
this.activeContainer.addSlotListener(this);
}
@@ -712,6 +924,11 @@
@@ -712,6 +937,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()));
@@ -480,7 +503,7 @@
}
public void setContainerData(Container container, int i, int j) {
@@ -726,6 +943,7 @@
@@ -726,6 +956,7 @@
}
public void closeInventory() {
@@ -488,7 +511,7 @@
this.playerConnection.sendPacket(new PacketPlayOutCloseWindow(this.activeContainer.windowId));
this.m();
}
@@ -759,14 +977,14 @@
@@ -759,14 +990,14 @@
public void a(Statistic<?> statistic, int i) {
this.ch.b(this, statistic, i);
@@ -505,7 +528,7 @@
}
public int a(Collection<IRecipe> collection) {
@@ -814,8 +1032,17 @@
@@ -814,8 +1045,17 @@
public void triggerHealthUpdate() {
this.lastHealthSent = -1.0E8F;
@@ -523,7 +546,7 @@
public void a(IChatBaseComponent ichatbasecomponent, boolean flag) {
this.playerConnection.sendPacket(new PacketPlayOutChat(ichatbasecomponent, flag ? ChatMessageType.GAME_INFO : ChatMessageType.CHAT));
}
@@ -866,7 +1093,7 @@
@@ -866,7 +1106,7 @@
this.lastSentExp = -1;
this.lastHealthSent = -1.0F;
this.cp = -1;
@@ -532,7 +555,7 @@
this.removeQueue.addAll(entityplayer.removeQueue);
this.cy = entityplayer.cy;
this.cD = entityplayer.cD;
@@ -925,6 +1152,18 @@
@@ -925,6 +1165,18 @@
}
public void a(EnumGamemode enumgamemode) {
@@ -551,7 +574,7 @@
this.playerInteractManager.setGameMode(enumgamemode);
this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(3, (float) enumgamemode.getId()));
if (enumgamemode == EnumGamemode.SPECTATOR) {
@@ -968,6 +1207,16 @@
@@ -968,6 +1220,16 @@
}
public void a(PacketPlayInSettings packetplayinsettings) {
@@ -568,7 +591,7 @@
this.locale = packetplayinsettings.b();
this.ct = packetplayinsettings.d();
this.cu = packetplayinsettings.e();
@@ -1033,7 +1282,7 @@
@@ -1033,7 +1295,7 @@
this.cw = (Entity) (entity == null ? this : entity);
if (entity1 != this.cw) {
this.playerConnection.sendPacket(new PacketPlayOutCamera(this.cw));
@@ -577,7 +600,7 @@
}
}
@@ -1060,7 +1309,7 @@
@@ -1060,7 +1322,7 @@
@Nullable
public IChatBaseComponent getPlayerListName() {
@@ -586,7 +609,7 @@
}
public void a(EnumHand enumhand) {
@@ -1077,12 +1326,17 @@
@@ -1077,12 +1339,17 @@
}
public void J() {
@@ -604,7 +627,7 @@
}
public AdvancementDataPlayer getAdvancementData() {
@@ -1094,9 +1348,16 @@
@@ -1094,9 +1361,16 @@
return this.cD;
}
@@ -621,7 +644,7 @@
if (worldserver == this.world) {
this.playerConnection.a(d0, d1, d2, f, f1);
} else {
@@ -1121,6 +1382,149 @@
@@ -1121,6 +1395,149 @@
this.server.getPlayerList().b(this, worldserver);
this.server.getPlayerList().updateClient(this);
}