public void enterBed(GlowBlock block) {
checkNotNull(block, "Bed block cannot be null");
Preconditions.checkState(bed == null, "Player already in bed");
GlowBlock head = BlockBed.getHead(block);
GlowBlock foot = BlockBed.getFoot(block);
if (EventFactory.getInstance()
.callEvent(new PlayerBedEnterEvent(this, head)).isCancelled()) {
return;
}
BlockBed.setOccupied(head, foot, true);
bed = head;
sleeping = true;
setRawLocation(head.getLocation(), false);
getSession().send(new UseBedMessage(SELF_ID, head.getX(), head.getY(), head.getZ()));
UseBedMessage msg = new UseBedMessage(getEntityId(), head.getX(), head.getY(), head.getZ());
world.getRawPlayers().stream().filter(p -> p != this && p.canSeeEntity(this))
.forEach(p -> p.getSession().send(msg));
}