}
int toDrop = amount;
for (final String slotName : Constants.CARRYING_SLOTS) {
final RPSlot slot = getSlot(slotName);
Iterator<RPObject> objectsIterator = slot.iterator();
while (objectsIterator.hasNext()) {
final RPObject object = objectsIterator.next();
if (!(object instanceof Item)) {
continue;
}
final Item item = (Item) object;
if (!item.getName().equals(name)) {
continue;
}
if (item instanceof StackableItem) {
// The item is stackable, we try to remove
// multiple ones.
final int quantity = item.getQuantity();
if (toDrop >= quantity) {
new ItemLogger().destroy(this, slot, item);
slot.remove(item.getID());
toDrop -= quantity;
// Recreate the iterator to prevent
// ConcurrentModificationExceptions.
// This inefficient, but simple.
objectsIterator = slot.iterator();
} else {
((StackableItem) item).setQuantity(quantity - toDrop);
new ItemLogger().splitOff(this, item, toDrop);
toDrop = 0;
}
} else {
// The item is not stackable, so we only remove a
// single one.
slot.remove(item.getID());
new ItemLogger().destroy(this, slot, item);
toDrop--;
// recreate the iterator to prevent
// ConcurrentModificationExceptions.
objectsIterator = slot.iterator();
}
if (toDrop == 0) {
updateItemAtkDef();
notifyWorldAboutChanges();