mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Use position in item on object event; add verification handler.
This commit is contained in:
@@ -59,6 +59,12 @@
|
||||
<handler>org.apollo.game.event.handler.impl.BankEventHandler</handler>
|
||||
</chain>
|
||||
</event>
|
||||
<event>
|
||||
<type>org.apollo.game.event.impl.ItemOnObjectEvent</type>
|
||||
<chain>
|
||||
<handler>org.apollo.game.event.handler.impl.ItemOnObjectVerificationHandler</handler>
|
||||
</chain>
|
||||
</event>
|
||||
<event>
|
||||
<type>org.apollo.game.event.impl.ClosedInterfaceEvent</type>
|
||||
<chain>
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package org.apollo.game.event.handler.impl;
|
||||
|
||||
import org.apollo.game.event.handler.EventHandler;
|
||||
import org.apollo.game.event.handler.EventHandlerContext;
|
||||
import org.apollo.game.event.impl.ItemOnObjectEvent;
|
||||
import org.apollo.game.model.Inventory;
|
||||
import org.apollo.game.model.Item;
|
||||
import org.apollo.game.model.Player;
|
||||
import org.apollo.game.model.inter.bank.BankConstants;
|
||||
import org.apollo.game.model.inv.SynchronizationInventoryListener;
|
||||
|
||||
/**
|
||||
* An {@link EventHandler} that verifies {@link ItemObObjectEvent}s.
|
||||
*
|
||||
* @author Major
|
||||
*/
|
||||
public final class ItemOnObjectVerificationHandler extends EventHandler<ItemOnObjectEvent> {
|
||||
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, ItemOnObjectEvent event) {
|
||||
if (event.getInterfaceId() != SynchronizationInventoryListener.INVENTORY_ID
|
||||
|| event.getInterfaceId() != BankConstants.SIDEBAR_INVENTORY_ID) {
|
||||
ctx.breakHandlerChain();
|
||||
return;
|
||||
}
|
||||
|
||||
Inventory inventory = player.getInventory();
|
||||
|
||||
int slot = event.getSlot();
|
||||
if (slot < 0 || slot >= inventory.capacity()) {
|
||||
ctx.breakHandlerChain();
|
||||
return;
|
||||
}
|
||||
|
||||
Item item = inventory.get(slot);
|
||||
if (item == null || item.getId() != event.getId()) {
|
||||
ctx.breakHandlerChain();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.apollo.game.event.impl;
|
||||
|
||||
import org.apollo.game.event.Event;
|
||||
import org.apollo.game.model.Position;
|
||||
|
||||
/**
|
||||
* An {@link Event} sent by the client when an item is used on an object.
|
||||
@@ -15,14 +16,9 @@ public final class ItemOnObjectEvent extends InventoryItemEvent {
|
||||
private final int objectId;
|
||||
|
||||
/**
|
||||
* The x coordinate of the object.
|
||||
* The position of the object.
|
||||
*/
|
||||
private final int x;
|
||||
|
||||
/**
|
||||
* The y coordinate of the object.
|
||||
*/
|
||||
private final int y;
|
||||
private final Position position;
|
||||
|
||||
/**
|
||||
* Creates an item on object event.
|
||||
@@ -37,8 +33,7 @@ public final class ItemOnObjectEvent extends InventoryItemEvent {
|
||||
public ItemOnObjectEvent(int interfaceId, int id, int slot, int objectId, int x, int y) {
|
||||
super(0, interfaceId, id, slot);
|
||||
this.objectId = objectId;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.position = new Position(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,21 +46,12 @@ public final class ItemOnObjectEvent extends InventoryItemEvent {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the x coordinate of the object.
|
||||
* Gets the position of the object.
|
||||
*
|
||||
* @return The x coordinate.
|
||||
* @return The position.
|
||||
*/
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the y coordinate of the object.
|
||||
*
|
||||
* @return The y coordinate.
|
||||
*/
|
||||
public int getY() {
|
||||
return y;
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user