*/
private static SourceObject createSource(RPAction action, final Player player) {
List<String> path = action.getList(EquipActionConsts.SOURCE_PATH);
Iterator<String> it = path.iterator();
// The ultimate parent object
Entity parent = EquipUtil.getEntityFromId(player, MathHelper.parseInt(it.next()));
if (parent == null) {
return invalidSource;
}
// Walk the slot path
Entity entity = parent;
String slotName = null;
while (it.hasNext()) {
slotName = it.next();
if (!entity.hasSlot(slotName)) {
player.sendPrivateText("Source " + slotName + " does not exist");
logger.error(player.getName() + " tried to use non existing slot " + slotName + " of " + entity
+ " as source. player zone: " + player.getZone() + " object zone: " + parent.getZone());
}
final RPSlot slot = ((EntitySlot) entity.getSlot(slotName)).getWriteableSlot();
if (!isValidBaseSlot(player, slot)) {
return invalidSource;
}
if (!it.hasNext()) {
logger.error("Missing item id");
return invalidSource;
}
final RPObject.ID itemId = new RPObject.ID(MathHelper.parseInt(it.next()), "");
if (!slot.has(itemId)) {
logger.debug("Base item(" + entity + ") doesn't contain item(" + itemId + ") on given slot(" + slotName
+ ")");
return invalidSource;
}
entity = (Entity) slot.get(itemId);
if (!(entity instanceof Item)) {
player.sendPrivateText("Oh, that " + entity.getDescriptionName(true)
+ " is not an item and therefore cannot be equipped");
return invalidSource;
}
}
// wipe parent, if the item is not contained