Class NPCList

java.lang.Object
games.stendhal.server.entity.npc.NPCList
All Implemented Interfaces:
Iterable<SpeakerNPC>

public class NPCList extends Object implements Iterable<SpeakerNPC>
This Singleton should contain all NPCs in the Stendhal world that are unique.
  • Constructor Details

    • NPCList

      protected NPCList()
  • Method Details

    • get

      public static NPCList get()
      Returns the Singleton instance.
      Returns:
      The instance
    • get

      public SpeakerNPC get(String name)
      Returns the NPC with the given name.
      Parameters:
      name - The NPC's name
      Returns:
      The NPC, or null if there is no NPC with this name
    • has

      public boolean has(String name)
      Checks whether an NPC with the given name exists.
      Parameters:
      name - The NPC's name
      Returns:
      true iff an NPC with the given name exists
    • add

      public void add(SpeakerNPC npc)
      Adds an NPC to the NPCList. Does nothing if an NPC with the same name already exists. This makes sure that each NPC can be uniquely identified by his/her name.
      Parameters:
      npc - The NPC that should be added
    • remove

      public SpeakerNPC remove(String name)
      Removes an NPC from the NPCList. Does nothing if no NPC with the given name exists.
      Parameters:
      name - The name of the NPC that should be removed
      Returns:
      SpeakerNPC or null in case it was not in the list
    • getNPCs

      public Set<String> getNPCs()
      Returns a list of all NPCs.
      Returns:
      list of npcs
    • clear

      public void clear()
      Removes all NPCs from this list.
    • iterator

      public Iterator<SpeakerNPC> iterator()
      Specified by:
      iterator in interface Iterable<SpeakerNPC>
      Returns:
      the interator over the SpeakerNPC objects.