if (!(entity instanceof Player) || type != Action.RIGHT_CLICK) {
return;
}
final Player player = (Player) entity;
Sleep sleep = player.get(Sleep.class);
if (sleep == null) {
return;
}
final Block head = getCorrectHalf(block, true);
final World world = player.getWorld();
final Sky sky = world.get(Sky.class);
for (Entity e : world.getNearbyEntities(player, NEARBY_MONSTER_RANGE)) {
if (e.get(Living.class) instanceof Hostile) {
player.sendMessage(NEARBY_MONSTER_MESSAGE);
return;
}
}
if (sky != null && sky.getTime() < Time.DUSK.getTime()) {
player.sendMessage(NOT_NIGHT_MESSAGE);
return;
}
if (isOccupied(head)) {
player.sendMessage(OCCUPIED_MESSAGE);
return;
}
sleep.sleep(head);
}