use of net.glowstone.net.message.play.player.UseBedMessage in project Glowstone by GlowstoneMC.
the class GlowPlayer method enterBed.
/**
* This player enters the specified bed and is marked as sleeping.
*
* @param block the bed
*/
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.callEvent(new PlayerBedEnterEvent(this, head)).isCancelled()) {
return;
}
// Occupy the bed
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));
}
use of net.glowstone.net.message.play.player.UseBedMessage in project Glowstone by GlowstoneMC.
the class UseBedCodec method decode.
@Override
public UseBedMessage decode(ByteBuf buf) throws IOException {
int id = ByteBufUtils.readVarInt(buf);
BlockVector pos = GlowBufUtils.readBlockPosition(buf);
return new UseBedMessage(id, pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
}
Aggregations