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.

By: blablubbabc <lukas@wirsindwir.de>
This commit is contained in:
CraftBukkit/Spigot
2019-03-13 04:48:19 +01:00
parent 6f19c56acd
commit 7a7e9aa31e
3 changed files with 50 additions and 32 deletions

View File

@@ -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);