mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-04 08:39:27 +00:00
Remove duplicate code in NpcActionVerificationHandler.
This commit is contained in:
@@ -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<NpcActionEvent> {
|
||||
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, NpcActionEvent event) {
|
||||
if (event.getIndex() < 0 || event.getIndex() >= WorldConstants.MAXIMUM_NPCS) {
|
||||
MobRepository<Npc> 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;
|
||||
|
||||
Reference in New Issue
Block a user