Example #1
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);
                  }
                });
          }
        }
      }
    }
  }
Example #2
0
  @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);
      }
    }
  }
Example #3
0
  @Override
  public void OnPlayerDamage(IPlayer player, RunsafeEntityDamageEvent event) {
    List<Hook> hooks = HookHandler.getHooks(HookType.PLAYER_DAMAGE);

    if (hooks != null) {
      IWorld damageWorld = player.getWorld();

      LuaString playerName = LuaValue.valueOf(player.getName());
      LuaString damageCause = LuaValue.valueOf(event.getCause().name());
      LuaValue damage = LuaValue.valueOf(event.getDamage());

      for (Hook hook : hooks) {
        IWorld world = hook.getWorld();
        if (world == null || !world.isWorld(damageWorld)) return;

        LuaTable table = new LuaTable();
        table.set("player", playerName);
        table.set("playerHealth", player.getHealth());
        table.set("playerMaxHealth", player.getMaxHealth());
        table.set("damage", damage);
        table.set("cause", damageCause);

        hook.execute(table);
      }
    }
  }
Example #4
0
  @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;
  }
Example #5
0
  private void playerLogEvent(IPlayer player, HookType type) {
    List<Hook> hooks = HookHandler.getHooks(type);

    if (hooks != null)
      for (Hook hook : hooks)
        if (hook.getPlayerName().equalsIgnoreCase(player.getName())) hook.execute();
  }
Example #6
0
  @Override
  public void OnPlayerPickupItemEvent(RunsafePlayerPickupItemEvent event) {
    List<Hook> hooks = HookHandler.getHooks(HookType.PLAYER_ITEM_PICKUP);

    if (hooks != null)
      for (Hook hook : hooks)
        handleItemHook(hook, event.getPlayer(), event.getItem().getItemStack());
  }
Example #7
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);
        }
      }
    }
  }
Example #8
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();
          }
        }
      }
    }
  }
Example #9
0
  @Override
  public void OnPlayerDeathEvent(RunsafePlayerDeathEvent event) {
    List<Hook> hooks = HookHandler.getHooks(HookType.PLAYER_DEATH);

    if (hooks != null) {
      IPlayer player = event.getEntity();

      for (Hook hook : hooks) {
        IWorld hookWorld = hook.getWorld();
        if (hookWorld.isWorld(player.getWorld())) {
          LuaTable table = new LuaTable();
          table.set("player", LuaValue.valueOf(player.getName()));

          hook.execute(table);
        }
      }
    }
  }
Example #10
0
  @Override
  public void OnPlayerChatEvent(RunsafePlayerChatEvent event) {
    List<Hook> hooks = HookHandler.getHooks(HookType.CHAT_MESSAGE);

    if (hooks != null) {
      IPlayer player = event.getPlayer();
      IWorld playerWorld = player.getWorld();

      if (playerWorld == null) return;

      for (Hook hook : hooks) {
        if (hook.getWorld().isWorld(player.getWorld())) {
          LuaTable table = new LuaTable();
          table.set("player", LuaValue.valueOf(player.getName()));
          table.set("message", LuaValue.valueOf(event.getMessage()));

          hook.execute(table);
        }
      }
    }
  }