mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Add consistency to events and handlers.
This commit is contained in:
@@ -83,10 +83,8 @@ public final class BankEventHandler extends EventHandler<ItemActionEvent> {
|
||||
if (amount == -1) {
|
||||
player.getInterfaceSet().openEnterAmountDialog(
|
||||
new BankWithdrawEnterAmountListener(player, event.getSlot(), event.getId()));
|
||||
} else {
|
||||
if (!BankUtils.withdraw(player, event.getSlot(), event.getId(), amount)) {
|
||||
ctx.breakHandlerChain();
|
||||
}
|
||||
} else if (!BankUtils.withdraw(player, event.getSlot(), event.getId(), amount)) {
|
||||
ctx.breakHandlerChain();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,15 +26,15 @@ public final class EquipEventHandler extends EventHandler<ItemOptionEvent> {
|
||||
int inventorySlot = event.getSlot();
|
||||
Item equipping = player.getInventory().get(inventorySlot);
|
||||
int equippingId = equipping.getId();
|
||||
EquipmentDefinition equippingDefinition = EquipmentDefinition.lookup(equippingId);
|
||||
EquipmentDefinition definition = EquipmentDefinition.lookup(equippingId);
|
||||
|
||||
if (equippingDefinition == null) {
|
||||
if (definition == null) {
|
||||
ctx.breakHandlerChain();
|
||||
return;
|
||||
}
|
||||
|
||||
for (int id = 0; id < 5; id++) {
|
||||
int requirement = equippingDefinition.getLevel(id);
|
||||
int requirement = definition.getLevel(id);
|
||||
|
||||
if (player.getSkillSet().getSkill(id).getMaximumLevel() < requirement) {
|
||||
String skillName = Skill.getName(id);
|
||||
@@ -50,12 +50,12 @@ public final class EquipEventHandler extends EventHandler<ItemOptionEvent> {
|
||||
Inventory inventory = player.getInventory();
|
||||
Inventory equipment = player.getEquipment();
|
||||
|
||||
int equipmentSlot = equippingDefinition.getSlot();
|
||||
int equipmentSlot = definition.getSlot();
|
||||
Item currentlyEquipped = equipment.get(equipmentSlot);
|
||||
|
||||
if (equipping.getDefinition().isStackable()
|
||||
&& (currentlyEquipped == null || currentlyEquipped.getId() == equippingId)) {
|
||||
equipment.set(equippingDefinition.getSlot(), equipping);
|
||||
equipment.set(definition.getSlot(), equipping);
|
||||
inventory.reset(inventorySlot);
|
||||
ctx.breakHandlerChain();
|
||||
return;
|
||||
@@ -64,7 +64,7 @@ public final class EquipEventHandler extends EventHandler<ItemOptionEvent> {
|
||||
Item weapon = equipment.get(EquipmentConstants.WEAPON);
|
||||
Item shield = equipment.get(EquipmentConstants.SHIELD);
|
||||
|
||||
if (equippingDefinition.isTwoHanded()) {
|
||||
if (definition.isTwoHanded()) {
|
||||
int slotsRequired = weapon != null ? shield != null ? 1 : 0 : 0;
|
||||
if (inventory.freeSlots() < slotsRequired) {
|
||||
ctx.breakHandlerChain();
|
||||
@@ -82,7 +82,7 @@ public final class EquipEventHandler extends EventHandler<ItemOptionEvent> {
|
||||
inventory.add(weapon);
|
||||
}
|
||||
return;
|
||||
} else if (equippingDefinition.getSlot() == EquipmentConstants.SHIELD && weapon != null
|
||||
} else if (definition.getSlot() == EquipmentConstants.SHIELD && weapon != null
|
||||
&& EquipmentDefinition.lookup(weapon.getId()).isTwoHanded()) {
|
||||
equipment.set(EquipmentConstants.SHIELD, inventory.reset(inventorySlot));
|
||||
inventory.add(equipment.reset(EquipmentConstants.WEAPON));
|
||||
@@ -90,13 +90,11 @@ public final class EquipEventHandler extends EventHandler<ItemOptionEvent> {
|
||||
}
|
||||
|
||||
Item previous = equipment.reset(equipmentSlot);
|
||||
inventory.remove(equipping); // no need for fancy stuff here as we
|
||||
// know the item isn't stackable.
|
||||
inventory.remove(equipping); // no need for fancy stuff here as we know the item isn't stackable.
|
||||
equipment.set(equipmentSlot, equipping);
|
||||
if (previous != null) {
|
||||
inventory.add(previous);
|
||||
}
|
||||
|
||||
ctx.breakHandlerChain();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,13 +29,10 @@ public final class ItemVerificationHandler extends EventHandler<InventoryItemEve
|
||||
case SynchronizationInventoryListener.INVENTORY_ID:
|
||||
case BankConstants.SIDEBAR_INVENTORY_ID:
|
||||
return player.getInventory();
|
||||
|
||||
case SynchronizationInventoryListener.EQUIPMENT_ID:
|
||||
return player.getEquipment();
|
||||
|
||||
case BankConstants.BANK_INVENTORY_ID:
|
||||
return player.getBank();
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("unknown interface id: " + interfaceId);
|
||||
}
|
||||
|
||||
@@ -41,9 +41,8 @@ public final class PlayerDesignVerificationHandler extends EventHandler<PlayerDe
|
||||
return validMaleStyle(appearance);
|
||||
} else if (gender == Gender.FEMALE) {
|
||||
return validFemaleStyle(appearance);
|
||||
} else {
|
||||
throw new IllegalArgumentException("player can only be either male or female");
|
||||
}
|
||||
throw new IllegalArgumentException("player can only be either male or female");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,7 +19,6 @@ public final class RemoveEventHandler extends EventHandler<ItemActionEvent> {
|
||||
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, ItemActionEvent event) {
|
||||
|
||||
if (event.getOption() == 1 && event.getInterfaceId() == SynchronizationInventoryListener.EQUIPMENT_ID) {
|
||||
Inventory inventory = player.getInventory();
|
||||
Inventory equipment = player.getEquipment();
|
||||
|
||||
@@ -5,7 +5,7 @@ package org.apollo.game.event.impl;
|
||||
*
|
||||
* @author Major
|
||||
*/
|
||||
public class FirstNpcActionEvent extends NpcActionEvent {
|
||||
public final class FirstNpcActionEvent extends NpcActionEvent {
|
||||
|
||||
/**
|
||||
* Creates a new first npc action event.
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.apollo.game.event.Event;
|
||||
*
|
||||
* @author Major
|
||||
*/
|
||||
public class NpcActionEvent extends Event {
|
||||
public abstract class NpcActionEvent extends Event {
|
||||
|
||||
/**
|
||||
* The action number .
|
||||
|
||||
@@ -5,7 +5,7 @@ package org.apollo.game.event.impl;
|
||||
*
|
||||
* @author Major
|
||||
*/
|
||||
public class SecondNpcActionEvent extends NpcActionEvent {
|
||||
public final class SecondNpcActionEvent extends NpcActionEvent {
|
||||
|
||||
/**
|
||||
* Creates a new second npc action event.
|
||||
|
||||
@@ -5,7 +5,7 @@ package org.apollo.game.event.impl;
|
||||
*
|
||||
* @author Major
|
||||
*/
|
||||
public class ThirdNpcActionEvent extends NpcActionEvent {
|
||||
public final class ThirdNpcActionEvent extends NpcActionEvent {
|
||||
|
||||
/**
|
||||
* Creates a new third npc action event.
|
||||
|
||||
Reference in New Issue
Block a user