@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); } } }
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 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); } } } }
@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); } } } }