use of org.bukkit.event.player.PlayerBedLeaveEvent in project Glowstone by GlowstoneMC.
the class GlowPlayer method leaveBed.
/**
* This player leaves their bed causing them to quit sleeping.
*
* @param setSpawn Whether to set the bed spawn of the player
*/
public void leaveBed(boolean setSpawn) {
Preconditions.checkState(bed != null, "Player is not in bed");
GlowBlock head = BlockBed.getHead(bed);
GlowBlock foot = BlockBed.getFoot(bed);
// Determine exit location
Block exitBlock = BlockBed.getExitLocation(head, foot);
if (exitBlock == null) {
// If no empty blocks were found fallback to block above bed
exitBlock = head.getRelative(BlockFace.UP);
}
// Set their spawn (normally omitted if their bed gets destroyed instead of them leaving it)
if (setSpawn) {
setBedSpawnLocation(head.getLocation());
}
// Empty the bed
BlockBed.setOccupied(head, foot, false);
bed = null;
sleeping = false;
// And eject the player
// Use center of block
Location exitLocation = exitBlock.getLocation().add(0.5, 0.1, 0.5);
setRawLocation(exitLocation, false);
teleported = true;
// Call event
EventFactory.getInstance().callEvent(new PlayerBedLeaveEvent(this, head, setSpawn));
playAnimationToSelf(EntityAnimation.LEAVE_BED);
playAnimation(EntityAnimation.LEAVE_BED);
// TODO: Set bed metadata (LivingEntity)
}
Aggregations