From b2263f1637c99f942079361594b4182a1e15eab7 Mon Sep 17 00:00:00 2001 From: Major- Date: Tue, 22 Jul 2014 00:32:18 +0100 Subject: [PATCH] Remove duplicate code in NpcActionVerificationHandler. --- .../handler/impl/NpcActionVerificationHandler.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/org/apollo/game/event/handler/impl/NpcActionVerificationHandler.java b/src/org/apollo/game/event/handler/impl/NpcActionVerificationHandler.java index a5d65ede..4653399b 100644 --- a/src/org/apollo/game/event/handler/impl/NpcActionVerificationHandler.java +++ b/src/org/apollo/game/event/handler/impl/NpcActionVerificationHandler.java @@ -4,32 +4,35 @@ import org.apollo.game.event.handler.EventHandler; import org.apollo.game.event.handler.EventHandlerContext; import org.apollo.game.event.impl.NpcActionEvent; import org.apollo.game.model.World; -import org.apollo.game.model.WorldConstants; import org.apollo.game.model.entity.Npc; import org.apollo.game.model.entity.Player; +import org.apollo.util.MobRepository; /** * A verification {@link EventHandler} for the {@link NpcActionEvent}. * * @author Stuart + * @author Major */ public final class NpcActionVerificationHandler extends EventHandler { @Override public void handle(EventHandlerContext ctx, Player player, NpcActionEvent event) { - if (event.getIndex() < 0 || event.getIndex() >= WorldConstants.MAXIMUM_NPCS) { + MobRepository repository = World.getWorld().getNpcRepository(); + int index = event.getIndex(); + + if (index < 0 || index >= repository.capacity()) { ctx.breakHandlerChain(); return; } - Npc npc = World.getWorld().getNpcRepository().get(event.getIndex()); + Npc npc = repository.get(index); if (npc == null || !player.getPosition().isWithinDistance(npc.getPosition(), 15)) { ctx.breakHandlerChain(); return; } - // TODO is this right? if (event.getOption() >= npc.getDefinition().getInteractions().length) { ctx.breakHandlerChain(); return;