mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-07 16:49:12 +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.handler.EventHandlerContext;
|
||||||
import org.apollo.game.event.impl.NpcActionEvent;
|
import org.apollo.game.event.impl.NpcActionEvent;
|
||||||
import org.apollo.game.model.World;
|
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.Npc;
|
||||||
import org.apollo.game.model.entity.Player;
|
import org.apollo.game.model.entity.Player;
|
||||||
|
import org.apollo.util.MobRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A verification {@link EventHandler} for the {@link NpcActionEvent}.
|
* A verification {@link EventHandler} for the {@link NpcActionEvent}.
|
||||||
*
|
*
|
||||||
* @author Stuart
|
* @author Stuart
|
||||||
|
* @author Major
|
||||||
*/
|
*/
|
||||||
public final class NpcActionVerificationHandler extends EventHandler<NpcActionEvent> {
|
public final class NpcActionVerificationHandler extends EventHandler<NpcActionEvent> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(EventHandlerContext ctx, Player player, NpcActionEvent event) {
|
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();
|
ctx.breakHandlerChain();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Npc npc = World.getWorld().getNpcRepository().get(event.getIndex());
|
Npc npc = repository.get(index);
|
||||||
|
|
||||||
if (npc == null || !player.getPosition().isWithinDistance(npc.getPosition(), 15)) {
|
if (npc == null || !player.getPosition().isWithinDistance(npc.getPosition(), 15)) {
|
||||||
ctx.breakHandlerChain();
|
ctx.breakHandlerChain();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO is this right?
|
|
||||||
if (event.getOption() >= npc.getDefinition().getInteractions().length) {
|
if (event.getOption() >= npc.getDefinition().getInteractions().length) {
|
||||||
ctx.breakHandlerChain();
|
ctx.breakHandlerChain();
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user