mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 16:51:37 +00:00
Add tests around ItemOnObjectVerificationHandler
Add various tests around ItemOnObject messages to verify that a valid object needs to be given as well as a valid item in order for the message to be passed down the MessageHandlerChain.
This commit is contained in:
@@ -1,13 +1,20 @@
|
||||
package org.apollo.game.message.handler;
|
||||
|
||||
import org.apollo.cache.def.ObjectDefinition;
|
||||
import org.apollo.game.message.impl.ItemOnObjectMessage;
|
||||
import org.apollo.game.model.Item;
|
||||
import org.apollo.game.model.Position;
|
||||
import org.apollo.game.model.World;
|
||||
import org.apollo.game.model.area.Region;
|
||||
import org.apollo.game.model.entity.EntityType;
|
||||
import org.apollo.game.model.entity.Player;
|
||||
import org.apollo.game.model.entity.obj.GameObject;
|
||||
import org.apollo.game.model.inter.bank.BankConstants;
|
||||
import org.apollo.game.model.inv.Inventory;
|
||||
import org.apollo.game.model.inv.SynchronizationInventoryListener;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A {@link MessageHandler} that verifies {@link ItemOnObjectMessage}s.
|
||||
*
|
||||
@@ -44,6 +51,21 @@ public final class ItemOnObjectVerificationHandler extends MessageHandler<ItemOn
|
||||
message.terminate();
|
||||
return;
|
||||
}
|
||||
|
||||
int objectId = message.getObjectId();
|
||||
if (objectId < 0 || objectId >= ObjectDefinition.count()) {
|
||||
message.terminate();
|
||||
return;
|
||||
}
|
||||
|
||||
Position position = message.getPosition();
|
||||
Region region = world.getRegionRepository().fromPosition(position);
|
||||
Set<GameObject> objects = region.getEntities(position, EntityType.STATIC_OBJECT, EntityType.DYNAMIC_OBJECT);
|
||||
|
||||
if (!player.getPosition().isWithinDistance(position, 15) || !ObjectActionVerificationHandler.containsObject(objectId, objects)) {
|
||||
message.terminate();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public final class ObjectActionVerificationHandler extends MessageHandler<Object
|
||||
* @param objects The list of objects.
|
||||
* @return {@code true} if the list does contain the object with the specified id, otherwise {@code false}.
|
||||
*/
|
||||
private static boolean containsObject(int id, Set<GameObject> objects) {
|
||||
public static boolean containsObject(int id, Set<GameObject> objects) {
|
||||
return objects.stream().anyMatch(object -> object.getId() == id);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user