public void onCommonClick(PlayerInteractEvent event) {
if (!EventUtil.passesFilter(event))
return;
LocalPlayer localPlayer = CraftBookPlugin.inst().wrapPlayer(event.getPlayer());
Block trigger = null;
if (SignUtil.isSign(event.getClickedBlock())) {
ChangedSign s = BukkitUtil.toChangedSign(event.getClickedBlock());
if (!s.getLine(1).equals("[Teleporter]")) return;
String[] pos = RegexUtil.COLON_PATTERN.split(s.getLine(2));
if (pos.length <= 2) {
localPlayer.printError("mech.teleport.invalidcoords");
return;
}
trigger = event.getClickedBlock();
} else if (event.getClickedBlock().getType() == Material.STONE_BUTTON || event.getClickedBlock().getType() == Material.WOOD_BUTTON) {
Button b = (Button) event.getClickedBlock().getState().getData();
if(b == null || b.getAttachedFace() == null) return;
Block sign = event.getClickedBlock().getRelative(b.getAttachedFace(), 2);
if (SignUtil.isSign(sign)) {
ChangedSign s = BukkitUtil.toChangedSign(sign);
if (!s.getLine(1).equals("[Teleporter]")) return;
String[] pos = RegexUtil.COLON_PATTERN.split(s.getLine(2));
if (pos.length <= 2) {
localPlayer.printError("mech.teleport.invalidcoords");
return;
}
trigger = sign;
}
} else
return;
if(trigger == null) return;
if (!localPlayer.hasPermission("craftbook.mech.teleporter.use")) {
if(CraftBookPlugin.inst().getConfiguration().showPermissionMessages)
localPlayer.printError("mech.use-permission");
return;
}
if(!ProtectionUtil.canUse(event.getPlayer(), event.getClickedBlock().getLocation(), event.getBlockFace(), event.getAction())) {
if(CraftBookPlugin.inst().getConfiguration().showPermissionMessages)
localPlayer.printError("area.use-permissions");
return;
}
makeItSo(localPlayer, trigger);