Ejemplo n.º 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);
        }
      }
    }
  }
Ejemplo n.º 2
0
  @SuppressWarnings("unchecked")
  @Override
  public void OnPlayerCustomEvent(RunsafeCustomEvent event) {
    HookType type = null;
    String eventType = event.getEvent();

    if (eventType.equals("region.enter")) type = HookType.REGION_ENTER;
    else if (eventType.equals("region.leave")) type = HookType.REGION_LEAVE;

    if (type != null) {
      List<Hook> hooks = HookHandler.getHooks(type);

      if (hooks != null) {
        for (final Hook hook : hooks) {
          Map<String, String> data = (Map<String, String>) event.getData();
          if (((String) hook.getData())
              .equalsIgnoreCase(String.format("%s-%s", data.get("world"), data.get("region")))) {
            final LuaTable table = new LuaTable();
            table.set("player", LuaValue.valueOf(event.getPlayer().getName()));

            scheduler.runNow(
                new Runnable() {
                  @Override
                  public void run() {
                    hook.execute(table);
                  }
                });
          }
        }
      }
    }
  }