@Override public void OnPlayerLeftClick(RunsafePlayerClickEvent event) { List<Hook> hooks = HookHandler.getHooks(HookType.LEFT_CLICK_BLOCK); if (hooks != null) { IBlock block = event.getBlock(); Item material = block.getMaterial(); ILocation blockLocation = block.getLocation(); String blockWorldName = blockLocation.getWorld().getName(); String playerName = event.getPlayer().getName(); for (Hook hook : hooks) { IWorld world = hook.getWorld(); if (world != null && !blockWorldName.equals(world.getName())) return; LuaTable table = new LuaTable(); table.set("player", LuaValue.valueOf(playerName)); table.set("world", LuaValue.valueOf(blockWorldName)); table.set("x", LuaValue.valueOf(blockLocation.getBlockX())); table.set("y", LuaValue.valueOf(blockLocation.getBlockY())); table.set("z", LuaValue.valueOf(blockLocation.getBlockZ())); table.set("blockID", LuaValue.valueOf(material.getItemID())); table.set("blockData", LuaValue.valueOf(material.getData())); hook.execute(table); } } }
@Override public boolean OnBlockBreak(IPlayer player, IBlock block) { List<Hook> hooks = HookHandler.getHooks(HookType.BLOCK_BREAK); if (hooks != null) { ILocation blockLocation = block.getLocation(); String blockWorld = blockLocation.getWorld().getName(); for (Hook hook : hooks) { IWorld world = hook.getWorld(); if (world != null && !blockWorld.equals(world.getName())) return true; LuaTable table = new LuaTable(); if (player != null) table.set("player", LuaValue.valueOf(player.getName())); table.set("world", LuaValue.valueOf(blockWorld)); table.set("x", LuaValue.valueOf(blockLocation.getBlockX())); table.set("y", LuaValue.valueOf(blockLocation.getBlockY())); table.set("z", LuaValue.valueOf(blockLocation.getBlockZ())); table.set("blockID", LuaValue.valueOf(block.getMaterial().getItemID())); table.set("blockData", LuaValue.valueOf(((RunsafeBlock) block).getData())); hook.execute(table); } } return true; }
@Override public void OnBlockRedstoneEvent(RunsafeBlockRedstoneEvent event) { if (event.getNewCurrent() > 0 && event.getOldCurrent() == 0) { List<Hook> hooks = HookHandler.getHooks(HookType.BLOCK_GAINS_CURRENT); if (hooks != null) { for (Hook hook : hooks) { IBlock block = event.getBlock(); if (block != null) { ILocation location = block.getLocation(); if (location.getWorld().getName().equals(hook.getLocation().getWorld().getName())) if (location.distance(hook.getLocation()) < 1) hook.execute(); } } } } }
@Override public void OnPlayerInteractEvent(RunsafePlayerInteractEvent event) { debug.debugFine("Interact event detected"); List<Hook> hooks = HookHandler.getHooks(HookType.INTERACT); if (hooks != null) { debug.debugFine("Hooks not null"); for (Hook hook : hooks) { debug.debugFine("Processing hook..."); IBlock block = event.getBlock(); if (hook.getData() != null) if (block == null || block.getMaterial().getItemID() != (Integer) hook.getData()) continue; debug.debugFine("Block is not null"); IWorld hookWorld = hook.getWorld(); ILocation location = block.getLocation(); if (hookWorld == null) { debug.debugFine("Hook world is null, using location"); if (location.getWorld().getName().equals(hook.getLocation().getWorld().getName())) { debug.debugFine("Correct world!"); if (location.distance(hook.getLocation()) < 1) { debug.debugFine("Distance is less than 1"); LuaTable table = new LuaTable(); if (event.getPlayer() != null) table.set("player", LuaValue.valueOf(event.getPlayer().getName())); table.set("x", LuaValue.valueOf(location.getBlockX())); table.set("y", LuaValue.valueOf(location.getBlockY())); table.set("z", LuaValue.valueOf(location.getBlockZ())); table.set("blockID", LuaValue.valueOf(block.getMaterial().getItemID())); table.set("blockData", LuaValue.valueOf((block).getData())); hook.execute(table); } } } else if (hookWorld.getName().equals(block.getWorld().getName())) { debug.debugFine("Hook world is null, sending location data"); LuaTable table = new LuaTable(); if (event.getPlayer() != null) table.set("player", LuaValue.valueOf(event.getPlayer().getName())); table.set("x", LuaValue.valueOf(location.getBlockX())); table.set("y", LuaValue.valueOf(location.getBlockY())); table.set("z", LuaValue.valueOf(location.getBlockZ())); table.set("blockID", LuaValue.valueOf(block.getMaterial().getItemID())); table.set("blockData", LuaValue.valueOf((block).getData())); hook.execute(table); } } } }