/**
  * Transforms the RPObjects in the spells slots to the real spell objects
  *
  * @param player
  */
 private void loadSpellsIntoSlots(Player player) {
   // load spells
   // use list of slot names to make code easily extendable in case spell can be put into
   // different slots
   final List<String> slotsSpells = Arrays.asList("spells");
   for (String slotName : slotsSpells) {
     RPSlot slot = player.getSlot(slotName);
     List<RPObject> objects = new LinkedList<RPObject>();
     // collect objects from slot before clearing and transforming
     for (final RPObject objectInSlot : slot) {
       objects.add(objectInSlot);
     }
     // clear the slot
     slot.clear();
     SpellTransformer transformer = new SpellTransformer();
     // transform rpobjects in slot to spell
     for (RPObject o : objects) {
       Spell s = (Spell) transformer.transform(o);
       // only add to slot if transforming was successful
       if (s != null) {
         slot.add(s);
       }
     }
   }
 }
  /**
   * Loads the items into the slots of the player on login.
   *
   * @param player Player
   * @param slot original slot
   * @param newSlot new Stendhal specific slot
   */
  private void loadSlotContent(final Player player, final RPSlot slot, final PlayerSlot newSlot) {
    final List<RPObject> objects = new LinkedList<RPObject>();
    for (final RPObject objectInSlot : slot) {
      objects.add(objectInSlot);
    }
    slot.clear();
    player.removeSlot(slot.getName());
    player.addSlot(newSlot);

    ItemTransformer transformer = new ItemTransformer();
    for (final RPObject rpobject : objects) {
      try {
        // remove admin items the player does not deserve
        if (ITEMS_FOR_ADMINS.contains(rpobject.get("name"))
            && (!player.has("adminlevel") || player.getInt("adminlevel") < 1000)) {
          logger.warn(
              "removed admin item " + rpobject.get("name") + " from player " + player.getName());
          new ItemLogger().destroyOnLogin(player, slot, rpobject);

          continue;
        }

        Item item = transformer.transform(rpobject);

        // log removed items
        if (item == null) {
          int quantity = 1;
          if (rpobject.has("quantity")) {
            quantity = rpobject.getInt("quantity");
          }

          logger.warn(
              "Cannot restore "
                  + quantity
                  + " "
                  + rpobject.get("name")
                  + " on login of "
                  + player.getName()
                  + " because this item"
                  + " was removed from items.xml");
          new ItemLogger().destroyOnLogin(player, slot, rpobject);

          continue;
        }

        boundOldItemsToPlayer(player, item);

        newSlot.add(item);
      } catch (final Exception e) {
        logger.error("Error adding " + rpobject + " to player slot" + slot, e);
      }
    }
  }
  /**
   * Returns the single object of a "keyed slot".
   *
   * @param slotOwner the object owning the slot
   * @param name name of key slot
   * @return object or <code>null</code> it does not exist
   */
  public static RPObject getKeyedSlotObject(final SlotOwner slotOwner, final String name) {
    if (!slotOwner.hasSlot(name)) {
      logger.error("Expected to find " + name + " slot in " + slotOwner, new Throwable());
      return null;
    }

    final RPSlot slot = slotOwner.getSlot(name);

    if (slot.size() == 0) {
      logger.error("Found empty " + name + " slot" + slotOwner, new Throwable());
      return null;
    }

    return slot.iterator().next();
  }
Exemple #4
0
 /**
  * Checks if the corpse is empty or not
  *
  * @return true if the corpse is empty
  */
 public boolean isEmpty() {
   // size() is a method from RPSlot which counts the number of objects in the slot
   return content.size() == 0;
 }