Exemple #1
0
  @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);
        }
      }
    }
  }
Exemple #2
0
  @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();
          }
        }
      }
    }
  }