/**
   * Get a keyed string value on a named slot.
   *
   * @param slotOwner the object owning the slot
   * @param name The slot name.
   * @param key The value key.
   * @return The keyed value of the slot, or <code>null</code> if not set.
   */
  public static String getKeyedSlot(
      final SlotOwner slotOwner, final String name, final String key) {
    final RPObject object = KeyedSlotUtil.getKeyedSlotObject(slotOwner, name);
    if (object == null) {
      return null;
    }

    return object.get(key);
  }
Beispiel #2
0
 /** Tests for onAdded. */
 @Test
 public void testOnAdded() {
   player.onAdded(new StendhalRPZone("playertest"));
   RPObject object = KeyedSlotUtil.getKeyedSlotObject(player, "!visited");
   if (object == null) {
     fail("slot not found");
   }
   assertTrue(object.has("playertest"));
   assertThat(player.get("visibility"), is("100"));
   player.onAdded(new StendhalRPZone(PlayerDieer.DEFAULT_DEAD_AREA));
   object = KeyedSlotUtil.getKeyedSlotObject(player, "!visited");
   if (object == null) {
     fail("slot not found");
   }
   assertTrue(object.has(PlayerDieer.DEFAULT_DEAD_AREA));
   assertThat(player.get("visibility"), is("50"));
   player.onRemoved(new StendhalRPZone(PlayerDieer.DEFAULT_DEAD_AREA));
   assertThat(player.get("visibility"), is("100"));
 }
  /**
   * Set a keyed string value on a named slot.
   *
   * @param slotOwner the object owning the slot
   * @param name The slot name.
   * @param key The value key.
   * @param value The value to assign (or remove if <code>null</code>).
   * @return <code>true</code> if value changed, <code>false</code> if there was a problem.
   */
  public static boolean setKeyedSlot(
      final SlotOwner slotOwner, final String name, final String key, final String value) {
    final RPObject object = KeyedSlotUtil.getKeyedSlotObject(slotOwner, name);
    if (object == null) {
      return false;
    }

    if (value != null) {
      object.put(key, value);
    } else if (object.has(key)) {
      object.remove(key);
    }

    return true;
  }