Beispiel #1
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);
      }
    }
  }
Beispiel #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);
      }
    }
  }
Beispiel #3
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;
  }
Beispiel #4
0
  private void handleItemHook(Hook hook, IPlayer player, RunsafeMeta item) {
    IWorld hookWorld = hook.getWorld();
    if (hookWorld.isWorld(player.getWorld())) {
      LuaTable table = new LuaTable();
      table.set("player", player.getName());
      table.set("itemID", item.getItemId());
      table.set("itemName", item.hasDisplayName() ? item.getDisplayName() : item.getNormalName());

      hook.execute(table);
    }
  }
Beispiel #5
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);
        }
      }
    }
  }
Beispiel #6
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);
        }
      }
    }
  }