if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
if (event.getClickedBlock() == null || !chairBlocks.contains(new ItemInfo(event.getClickedBlock())))
return;
LocalPlayer lplayer = CraftBookPlugin.inst().wrapPlayer(event.getPlayer());
if (lplayer.isSneaking()) return;
Player player = event.getPlayer();
// Now everything looks good, continue;
if (chairAllowHeldBlock || !lplayer.isHoldingBlock() && lplayer.getHeldItemInfo().getType() != Material.SIGN || lplayer.getHeldItemInfo().getType() == Material.AIR) {
if (chairRequireSign && !hasSign(event.getClickedBlock(), new ArrayList<Location>(), event.getClickedBlock()))
return;
if (!lplayer.hasPermission("craftbook.mech.chair.use")) {
if(CraftBookPlugin.inst().getConfiguration().showPermissionMessages)
lplayer.printError("mech.use-permission");
return;
}
if(!ProtectionUtil.canUse(event.getPlayer(), event.getClickedBlock().getLocation(), event.getBlockFace(), event.getAction())) {
if(CraftBookPlugin.inst().getConfiguration().showPermissionMessages)
lplayer.printError("area.use-permissions");
return;
}
if(event.getPlayer().getLocation().distanceSquared(event.getClickedBlock().getLocation().add(0.5, 0.5, 0.5)) > Math.pow(chairMaxClickRadius, 2)) {
lplayer.printError("mech.chairs.too-far");
return;
}
if (hasChair(player.getPlayer())) { // Stand
removeChair(player.getPlayer());
} else { // Sit
if (hasChair(event.getClickedBlock())) {
lplayer.print("mech.chairs.in-use");
return;
}
if (BlockType.canPassThrough(event.getClickedBlock().getRelative(0, -1, 0).getTypeId())) {
lplayer.printError("mech.chairs.floating");
return;
} else if(!BlockType.canPassThrough(event.getClickedBlock().getRelative(0, 1, 0).getTypeId())) {
lplayer.printError("mech.chairs.obstructed");
return;
}
Location chairLoc = event.getClickedBlock().getLocation().add(0.5,0,0.5);