Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
org.bukkit.event.HandlerList Class Reference

Public Member Functions

 HandlerList ()
 
synchronized void register (RegisteredListener listener)
 
void registerAll (Collection< RegisteredListener > listeners)
 
synchronized void unregister (RegisteredListener listener)
 
synchronized void unregister (Plugin plugin)
 
synchronized void unregister (Listener listener)
 
synchronized void bake ()
 
RegisteredListener[] getRegisteredListeners ()
 

Static Public Member Functions

static void bakeAll ()
 
static void unregisterAll ()
 
static void unregisterAll (Plugin plugin)
 
static void unregisterAll (Listener listener)
 
static ArrayList< RegisteredListenergetRegisteredListeners (Plugin plugin)
 
static ArrayList< HandlerListgetHandlerLists ()
 

Detailed Description

A list of event handlers, stored per-event. Based on lahwran's fevents.

Definition at line 12 of file HandlerList.java.

Constructor & Destructor Documentation

org.bukkit.event.HandlerList.HandlerList ( )

Create a new handler list and initialize using EventPriority.

The HandlerList is then added to meta-list for use in bakeAll()

Definition at line 92 of file HandlerList.java.

92  {
93  handlerslots = new EnumMap<EventPriority, ArrayList<RegisteredListener>>(EventPriority.class);
94  for (EventPriority o : EventPriority.values()) {
95  handlerslots.put(o, new ArrayList<RegisteredListener>());
96  }
97  synchronized (allLists) {
98  allLists.add(this);
99  }
100  }

Member Function Documentation

synchronized void org.bukkit.event.HandlerList.bake ( )

Bake HashMap and ArrayLists to 2d array - does nothing if not necessary

Definition at line 175 of file HandlerList.java.

Referenced by org.bukkit.event.HandlerList.getRegisteredListeners().

175  {
176  if (handlers != null) return; // don't re-bake when still valid
177  List<RegisteredListener> entries = new ArrayList<RegisteredListener>();
178  for (Entry<EventPriority, ArrayList<RegisteredListener>> entry : handlerslots.entrySet()) {
179  entries.addAll(entry.getValue());
180  }
181  handlers = entries.toArray(new RegisteredListener[entries.size()]);
182  }
static void org.bukkit.event.HandlerList.bakeAll ( )
static

Bake all handler lists. Best used just after all normal event registration is complete, ie just after all plugins are loaded if you're using fevents in a plugin system.

Definition at line 37 of file HandlerList.java.

37  {
38  synchronized (allLists) {
39  for (HandlerList h : allLists) {
40  h.bake();
41  }
42  }
43  }
static ArrayList<HandlerList> org.bukkit.event.HandlerList.getHandlerLists ( )
static

Get a list of all handler lists for every event type

Returns
the list of all handler lists

Definition at line 226 of file HandlerList.java.

226  {
227  synchronized (allLists) {
228  return (ArrayList<HandlerList>) allLists.clone();
229  }
230  }
RegisteredListener [] org.bukkit.event.HandlerList.getRegisteredListeners ( )

Get the baked registered listeners associated with this handler list

Returns
the array of registered listeners

Definition at line 189 of file HandlerList.java.

References org.bukkit.event.HandlerList.bake().

189  {
190  RegisteredListener[] handlers;
191  while ((handlers = this.handlers) == null) bake(); // This prevents fringe cases of returning null
192  return handlers;
193  }
synchronized void bake()
static ArrayList<RegisteredListener> org.bukkit.event.HandlerList.getRegisteredListeners ( Plugin  plugin)
static

Get a specific plugin's registered listeners associated with this handler list

Parameters
pluginthe plugin to get the listeners of
Returns
the list of registered listeners

Definition at line 202 of file HandlerList.java.

202  {
203  ArrayList<RegisteredListener> listeners = new ArrayList<RegisteredListener>();
204  synchronized (allLists) {
205  for (HandlerList h : allLists) {
206  synchronized (h) {
207  for (List<RegisteredListener> list : h.handlerslots.values()) {
208  for (RegisteredListener listener : list) {
209  if (listener.getPlugin().equals(plugin)) {
210  listeners.add(listener);
211  }
212  }
213  }
214  }
215  }
216  }
217  return listeners;
218  }
synchronized void org.bukkit.event.HandlerList.register ( RegisteredListener  listener)

Register a new listener in this handler list

Parameters
listenerlistener to register

Definition at line 107 of file HandlerList.java.

Referenced by org.bukkit.plugin.SimplePluginManager.registerEvent().

107  {
108  if (handlerslots.get(listener.getPriority()).contains(listener))
109  throw new IllegalStateException("This listener is already registered to priority " + listener.getPriority().toString());
110  handlers = null;
111  handlerslots.get(listener.getPriority()).add(listener);
112  }
void org.bukkit.event.HandlerList.registerAll ( Collection< RegisteredListener listeners)

Register a collection of new listeners in this handler list

Parameters
listenerslisteners to register

Definition at line 119 of file HandlerList.java.

Referenced by org.bukkit.plugin.SimplePluginManager.registerEvents().

119  {
120  for (RegisteredListener listener : listeners) {
121  register(listener);
122  }
123  }
synchronized void org.bukkit.event.HandlerList.unregister ( RegisteredListener  listener)

Remove a listener from a specific order slot

Parameters
listenerlistener to remove

Definition at line 130 of file HandlerList.java.

References org.bukkit.plugin.RegisteredListener.getPriority().

130  {
131  if (handlerslots.get(listener.getPriority()).remove(listener)) {
132  handlers = null;
133  }
134  }
synchronized void org.bukkit.event.HandlerList.unregister ( Plugin  plugin)

Remove a specific plugin's listeners from this handler

Parameters
pluginplugin to remove

Definition at line 141 of file HandlerList.java.

141  {
142  boolean changed = false;
143  for (List<RegisteredListener> list : handlerslots.values()) {
144  for (ListIterator<RegisteredListener> i = list.listIterator(); i.hasNext();) {
145  if (i.next().getPlugin().equals(plugin)) {
146  i.remove();
147  changed = true;
148  }
149  }
150  }
151  if (changed) handlers = null;
152  }
synchronized void org.bukkit.event.HandlerList.unregister ( Listener  listener)

Remove a specific listener from this handler

Parameters
listenerlistener to remove

Definition at line 159 of file HandlerList.java.

159  {
160  boolean changed = false;
161  for (List<RegisteredListener> list : handlerslots.values()) {
162  for (ListIterator<RegisteredListener> i = list.listIterator(); i.hasNext();) {
163  if (i.next().getListener().equals(listener)) {
164  i.remove();
165  changed = true;
166  }
167  }
168  }
169  if (changed) handlers = null;
170  }
static void org.bukkit.event.HandlerList.unregisterAll ( )
static

Unregister all listeners from all handler lists.

Definition at line 48 of file HandlerList.java.

Referenced by org.bukkit.plugin.SimplePluginManager.clearPlugins().

48  {
49  synchronized (allLists) {
50  for (HandlerList h : allLists) {
51  synchronized (h) {
52  for (List<RegisteredListener> list : h.handlerslots.values()) {
53  list.clear();
54  }
55  h.handlers = null;
56  }
57  }
58  }
59  }
static void org.bukkit.event.HandlerList.unregisterAll ( Plugin  plugin)
static

Unregister a specific plugin's listeners from all handler lists.

Parameters
pluginplugin to unregister

Definition at line 66 of file HandlerList.java.

66  {
67  synchronized (allLists) {
68  for (HandlerList h : allLists) {
69  h.unregister(plugin);
70  }
71  }
72  }
static void org.bukkit.event.HandlerList.unregisterAll ( Listener  listener)
static

Unregister a specific listener from all handler lists.

Parameters
listenerlistener to unregister

Definition at line 79 of file HandlerList.java.

79  {
80  synchronized (allLists) {
81  for (HandlerList h : allLists) {
82  h.unregister(listener);
83  }
84  }
85  }

The documentation for this class was generated from the following file: