3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 20:40:07 +01:00

SPIGOT-4666: Force parameter in HumanEntity#sleep

Also moved the application of the force parameter inside EntityHuman, to
no longer allow bypassing of very essential checks.
Dieser Commit ist enthalten in:
blablubbabc 2019-03-13 04:48:19 +01:00 committet von md_5
Ursprung 8b1588e2f1
Commit 8d8475fc46
3 geänderte Dateien mit 50 neuen und 32 gelöschten Zeilen

Datei anzeigen

@ -330,7 +330,7 @@
return EntityHuman.EnumBedResult.NOT_POSSIBLE_HERE;
}
@@ -1140,6 +1267,30 @@
@@ -1140,6 +1267,34 @@
}
}
}
@ -344,12 +344,16 @@
+
+ public EntityHuman.EnumBedResult a(BlockPosition blockposition, boolean force) {
+ EnumDirection enumdirection = (EnumDirection) this.world.getType(blockposition).get(BlockFacingHorizontal.FACING);
+ EntityHuman.EnumBedResult bedResult = force ? EnumBedResult.OK : this.getBedResult(blockposition, enumdirection);
+ EntityHuman.EnumBedResult bedResult = this.getBedResult(blockposition, enumdirection);
+
+ if (bedResult == EntityHuman.EnumBedResult.OTHER_PROBLEM) {
+ return bedResult; // return immediately if the result is not bypassable by plugins
+ }
+
+ if (force) {
+ bedResult = EnumBedResult.OK;
+ }
+
+ if (this.getBukkitEntity() instanceof Player) {
+ bedResult = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerBedEnterEvent(this, blockposition, bedResult);
+
@ -361,7 +365,7 @@
if (this.isPassenger()) {
this.stopRiding();
@@ -1206,6 +1357,24 @@
@@ -1206,6 +1361,24 @@
this.world.everyoneSleeping();
}
@ -386,7 +390,7 @@
this.sleepTicks = flag ? 0 : 100;
if (flag2) {
this.setRespawnPosition(this.bedPosition, false);
@@ -1257,9 +1426,11 @@
@@ -1257,9 +1430,11 @@
if (blockposition != null) {
this.e = blockposition;
this.f = flag;
@ -398,7 +402,7 @@
}
}
@@ -1325,7 +1496,11 @@
@@ -1325,7 +1500,11 @@
this.motY = d3 * 0.6D;
this.aU = f3;
this.fallDistance = 0.0F;
@ -411,7 +415,7 @@
} else {
super.a(f, f1, f2);
}
@@ -1625,13 +1800,17 @@
@@ -1625,13 +1804,17 @@
}
protected void releaseShoulderEntities() {
@ -434,7 +438,7 @@
if (!this.world.isClientSide && !nbttagcompound.isEmpty()) {
Entity entity = EntityTypes.a(nbttagcompound, this.world);
@@ -1640,9 +1819,10 @@
@@ -1640,9 +1823,10 @@
}
entity.setPosition(this.locX, this.locY + 0.699999988079071D, this.locZ);

Datei anzeigen

@ -132,13 +132,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 +161,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 @@
}
@ -354,7 +353,22 @@
this.playerConnection.sendPacket(new PacketPlayOutWorldEvent(1032, BlockPosition.ZERO, 0, false));
this.lastSentExp = -1;
this.lastHealthSent = -1.0F;
@@ -530,6 +710,7 @@
@@ -514,7 +694,13 @@
}
public EntityHuman.EnumBedResult a(BlockPosition blockposition) {
- EntityHuman.EnumBedResult entityhuman_enumbedresult = super.a(blockposition);
+ // CraftBukkit start - add force parameter
+ return this.a(blockposition, false);
+ }
+
+ public EntityHuman.EnumBedResult a(BlockPosition blockposition, boolean force) {
+ EntityHuman.EnumBedResult entityhuman_enumbedresult = super.a(blockposition, force);
+ // CraftBukkit end
if (entityhuman_enumbedresult == EntityHuman.EnumBedResult.OK) {
this.a(StatisticList.SLEEP_IN_BED);
@@ -530,6 +716,7 @@
}
public void a(boolean flag, boolean flag1, boolean flag2) {
@ -362,7 +376,7 @@
if (this.isSleeping()) {
this.getWorldServer().getTracker().sendPacketToEntity(this, new PacketPlayOutAnimation(this, 2));
}
@@ -608,23 +789,55 @@
@@ -608,23 +795,55 @@
this.playerConnection.sendPacket(new PacketPlayOutOpenSignEditor(tileentitysign.getPosition()));
}
@ -421,7 +435,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 +851,21 @@
@@ -638,18 +857,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));
@ -445,7 +459,7 @@
this.activeContainer.windowId = this.containerCounter;
this.activeContainer.addSlotListener(this);
@@ -657,14 +873,27 @@
@@ -657,14 +879,27 @@
}
public void openTrade(IMerchant imerchant) {
@ -476,7 +490,7 @@
MerchantRecipeList merchantrecipelist = imerchant.getOffers(this);
if (merchantrecipelist != null) {
@@ -678,13 +907,20 @@
@@ -678,13 +913,20 @@
}
public void openHorseInventory(EntityHorseAbstract entityhorseabstract, IInventory iinventory) {
@ -498,7 +512,7 @@
this.activeContainer.windowId = this.containerCounter;
this.activeContainer.addSlotListener(this);
}
@@ -725,6 +961,11 @@
@@ -725,6 +967,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()));
@ -510,7 +524,7 @@
}
public void setContainerData(Container container, int i, int j) {
@@ -739,6 +980,7 @@
@@ -739,6 +986,7 @@
}
public void closeInventory() {
@ -518,7 +532,7 @@
this.playerConnection.sendPacket(new PacketPlayOutCloseWindow(this.activeContainer.windowId));
this.m();
}
@@ -772,14 +1014,14 @@
@@ -772,14 +1020,14 @@
public void a(Statistic<?> statistic, int i) {
this.cg.b(this, statistic, i);
@ -535,7 +549,7 @@
}
public int discoverRecipes(Collection<IRecipe> collection) {
@@ -827,8 +1069,17 @@
@@ -827,8 +1075,17 @@
public void triggerHealthUpdate() {
this.lastHealthSent = -1.0E8F;
@ -553,7 +567,7 @@
public void a(IChatBaseComponent ichatbasecomponent, boolean flag) {
this.playerConnection.sendPacket(new PacketPlayOutChat(ichatbasecomponent, flag ? ChatMessageType.GAME_INFO : ChatMessageType.CHAT));
}
@@ -879,7 +1130,7 @@
@@ -879,7 +1136,7 @@
this.lastSentExp = -1;
this.lastHealthSent = -1.0F;
this.lastFoodSent = -1;
@ -562,7 +576,7 @@
this.removeQueue.addAll(entityplayer.removeQueue);
this.cx = entityplayer.cx;
this.cC = entityplayer.cC;
@@ -938,6 +1189,18 @@
@@ -938,6 +1195,18 @@
}
public void a(EnumGamemode enumgamemode) {
@ -581,7 +595,7 @@
this.playerInteractManager.setGameMode(enumgamemode);
this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(3, (float) enumgamemode.getId()));
if (enumgamemode == EnumGamemode.SPECTATOR) {
@@ -985,6 +1248,17 @@
@@ -985,6 +1254,17 @@
}
public void a(PacketPlayInSettings packetplayinsettings) {
@ -599,7 +613,7 @@
this.locale = packetplayinsettings.b();
this.cs = packetplayinsettings.d();
this.ct = packetplayinsettings.e();
@@ -1020,13 +1294,13 @@
@@ -1020,13 +1300,13 @@
if (entity instanceof EntityHuman) {
this.playerConnection.sendPacket(new PacketPlayOutEntityDestroy(new int[] { entity.getId()}));
} else {
@ -615,7 +629,7 @@
}
protected void C() {
@@ -1050,7 +1324,7 @@
@@ -1050,7 +1330,7 @@
this.spectatedEntity = (Entity) (entity == null ? this : entity);
if (entity1 != this.spectatedEntity) {
this.playerConnection.sendPacket(new PacketPlayOutCamera(this.spectatedEntity));
@ -624,7 +638,7 @@
}
}
@@ -1077,7 +1351,7 @@
@@ -1077,7 +1357,7 @@
@Nullable
public IChatBaseComponent getPlayerListName() {
@ -633,7 +647,7 @@
}
public void a(EnumHand enumhand) {
@@ -1094,12 +1368,17 @@
@@ -1094,12 +1374,17 @@
}
public void J() {
@ -651,7 +665,7 @@
}
public AdvancementDataPlayer getAdvancementData() {
@@ -1111,9 +1390,16 @@
@@ -1111,9 +1396,16 @@
return this.cC;
}
@ -668,7 +682,7 @@
if (worldserver == this.world) {
this.playerConnection.a(d0, d1, d2, f, f1);
} else {
@@ -1138,6 +1424,149 @@
@@ -1138,6 +1430,149 @@
this.server.getPlayerList().b(this, worldserver);
this.server.getPlayerList().updateClient(this);
}

Datei anzeigen

@ -168,7 +168,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
return false;
}
if (getHandle().a(blockposition) != EntityHuman.EnumBedResult.OK) {
if (getHandle().a(blockposition, force) != EntityHuman.EnumBedResult.OK) {
return false;
}