Add PlayerBedFailEnterEvent

This commit is contained in:
Jake Potrebic 2020-12-24 12:27:41 -08:00
parent 80878ac918
commit 472880fdde

View File

@ -10,7 +10,7 @@
world.removeBlock(pos, false);
BlockPos blockposition1 = pos.relative(((Direction) state.getValue(BedBlock.FACING)).getOpposite());
@@ -114,7 +115,16 @@
@@ -114,19 +115,59 @@
return InteractionResult.SUCCESS_SERVER;
} else {
@ -19,18 +19,31 @@
+ BlockPos finalblockposition = pos;
+ // CraftBukkit end
player.startSleepInBed(pos).ifLeft((entityhuman_enumbedresult) -> {
+ // Paper start - PlayerBedFailEnterEvent
+ if (entityhuman_enumbedresult != null) {
+ io.papermc.paper.event.player.PlayerBedFailEnterEvent event = new io.papermc.paper.event.player.PlayerBedFailEnterEvent((org.bukkit.entity.Player) player.getBukkitEntity(), io.papermc.paper.event.player.PlayerBedFailEnterEvent.FailReason.values()[entityhuman_enumbedresult.ordinal()], org.bukkit.craftbukkit.block.CraftBlock.at(world, finalblockposition), !world.dimensionType().bedWorks(), io.papermc.paper.adventure.PaperAdventure.asAdventure(entityhuman_enumbedresult.getMessage()));
+ if (!event.callEvent()) {
+ return;
+ }
+ // Paper end - PlayerBedFailEnterEvent
+ // CraftBukkit start - handling bed explosion from below here
+ if (!world.dimensionType().bedWorks()) {
+ if (event.getWillExplode()) { // Paper - PlayerBedFailEnterEvent
+ this.explodeBed(finaliblockdata, world, finalblockposition);
+ } else
+ // CraftBukkit end
if (entityhuman_enumbedresult.getMessage() != null) {
player.displayClientMessage(entityhuman_enumbedresult.getMessage(), true);
- player.displayClientMessage(entityhuman_enumbedresult.getMessage(), true);
+ final net.kyori.adventure.text.Component message = event.getMessage(); // Paper - PlayerBedFailEnterEvent
+ if (message != null) player.displayClientMessage(io.papermc.paper.adventure.PaperAdventure.asVanilla(message), true); // Paper - PlayerBedFailEnterEvent
}
@@ -125,8 +135,30 @@
}
}
+ } // Paper - PlayerBedFailEnterEvent
});
return InteractionResult.SUCCESS_SERVER;
+ }
+ }
+ }
+
+ // CraftBukkit start
+ private InteractionResult explodeBed(BlockState iblockdata, Level world, BlockPos blockposition) {
+ {
@ -47,11 +60,11 @@
+
+ world.explode((Entity) null, world.damageSources().badRespawnPointExplosion(vec3d, blockState), (ExplosionDamageCalculator) null, vec3d, 5.0F, true, Level.ExplosionInteraction.BLOCK); // CraftBukkit - add state
+ return InteractionResult.SUCCESS;
+ }
+ }
+ }
}
}
}
+ // CraftBukkit end
+
public static boolean canSetSpawn(Level world) {
- return world.dimensionType().bedWorks();
+ // CraftBukkit - moved world and biome check into EntityHuman
@ -59,7 +72,7 @@
}
private boolean kickVillagerOutOfBed(Level world, BlockPos pos) {
@@ -320,6 +352,11 @@
@@ -320,6 +361,11 @@
BlockPos blockposition1 = pos.relative((Direction) state.getValue(BedBlock.FACING));
world.setBlock(blockposition1, (BlockState) state.setValue(BedBlock.PART, BedPart.HEAD), 3);