Package games.stendhal.server.entity.npc
Class NPCList
java.lang.Object
games.stendhal.server.entity.npc.NPCList
- All Implemented Interfaces:
Iterable<SpeakerNPC>
This Singleton should contain all NPCs in the Stendhal world that are unique.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(SpeakerNPC npc) Adds an NPC to the NPCList.voidclear()Removes all NPCs from this list.static NPCListget()Returns the Singleton instance.Returns the NPC with the given name.getNPCs()Returns a list of all NPCs.booleanChecks whether an NPC with the given name exists.iterator()Removes an NPC from the NPCList.voidCall when dynamically created NPC with reserved name is removed from world.voidCall when an NPC with reserved name is created dynamically.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
NPCList
protected NPCList()
-
-
Method Details
-
get
Returns the Singleton instance.- Returns:
- The instance
-
get
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
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
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
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
Returns a list of all NPCs.- Returns:
- list of npcs
-
clear
public void clear()Removes all NPCs from this list. -
iterator
- Specified by:
iteratorin interfaceIterable<SpeakerNPC>- Returns:
- the interator over the SpeakerNPC objects.
-
reserve
Call when dynamically created NPC with reserved name is removed from world. -
unreserve
Call when an NPC with reserved name is created dynamically.
-