mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 16:51:37 +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>
|
<handler>org.apollo.game.event.handler.impl.BankEventHandler</handler>
|
||||||
</chain>
|
</chain>
|
||||||
</event>
|
</event>
|
||||||
|
<event>
|
||||||
|
<type>org.apollo.game.event.impl.ItemOnObjectEvent</type>
|
||||||
|
<chain>
|
||||||
|
<handler>org.apollo.game.event.handler.impl.ItemOnObjectVerificationHandler</handler>
|
||||||
|
</chain>
|
||||||
|
</event>
|
||||||
<event>
|
<event>
|
||||||
<type>org.apollo.game.event.impl.ClosedInterfaceEvent</type>
|
<type>org.apollo.game.event.impl.ClosedInterfaceEvent</type>
|
||||||
<chain>
|
<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;
|
package org.apollo.game.event.impl;
|
||||||
|
|
||||||
import org.apollo.game.event.Event;
|
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.
|
* 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;
|
private final int objectId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The x coordinate of the object.
|
* The position of the object.
|
||||||
*/
|
*/
|
||||||
private final int x;
|
private final Position position;
|
||||||
|
|
||||||
/**
|
|
||||||
* The y coordinate of the object.
|
|
||||||
*/
|
|
||||||
private final int y;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an item on object event.
|
* 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) {
|
public ItemOnObjectEvent(int interfaceId, int id, int slot, int objectId, int x, int y) {
|
||||||
super(0, interfaceId, id, slot);
|
super(0, interfaceId, id, slot);
|
||||||
this.objectId = objectId;
|
this.objectId = objectId;
|
||||||
this.x = x;
|
this.position = new Position(x, y);
|
||||||
this.y = 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() {
|
public Position getPosition() {
|
||||||
return x;
|
return position;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the y coordinate of the object.
|
|
||||||
*
|
|
||||||
* @return The y coordinate.
|
|
||||||
*/
|
|
||||||
public int getY() {
|
|
||||||
return y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user