Exemple #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);
      }
    }
  }
Exemple #2
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;
  }
Exemple #3
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();
  }
Exemple #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);
    }
  }
 @Override
 public String OnExecute(ICommandExecutor executor, IArgumentList parameters) {
   IPlayer player = parameters.getValue("player");
   if (player == null) return null;
   this.history.save(player);
   player.getInventory().clear();
   player.updateInventory();
   if (executor instanceof IPlayer && executor.getName().equals(player.getName()))
     return "&2Your inventory has been cleared.";
   return "&2Inventory for " + player.getPrettyName() + " &2cleared.";
 }
Exemple #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);
        }
      }
    }
  }
Exemple #7
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);
        }
      }
    }
  }
 public void registerCatch(IPlayer player) {
   String playerName = player.getName();
   int newProgress = progress.containsKey(playerName) ? progress.get(playerName) + 1 : 1;
   if (newProgress == config.getFishToWin()) concludeEvent(player);
   else progress.put(playerName, newProgress);
 }