Search in sources :

Example 1 with PlayerBedEnterEvent

use of org.bukkit.event.player.PlayerBedEnterEvent 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.getInstance().callEvent(new PlayerBedEnterEvent(this, head)).isCancelled()) {
        return;
    }
    // Occupy the bed
    BlockBed.setOccupied(head, foot, true);
    bed = head;
    sleeping = true;
    setRawLocation(head.getLocation(), false);
// TODO: Set bed metadata (LivingEntity)
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) PlayerBedEnterEvent(org.bukkit.event.player.PlayerBedEnterEvent)

Aggregations

GlowBlock (net.glowstone.block.GlowBlock)1 PlayerBedEnterEvent (org.bukkit.event.player.PlayerBedEnterEvent)1