Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
Event.java
1 package org.bukkit.event;
2 
4 
5 /**
6  * Represents an event.
7  *
8  * @see PluginManager#callEvent(Event)
9  * @see PluginManager#registerEvents(Listener,Plugin)
10  */
11 public abstract class Event {
12  private String name;
13  private final boolean async;
14 
15  /**
16  * The default constructor is defined for cleaner code. This constructor
17  * assumes the event is synchronous.
18  */
19  public Event() {
20  this(false);
21  }
22 
23  /**
24  * This constructor is used to explicitly declare an event as synchronous
25  * or asynchronous.
26  *
27  * @param isAsync true indicates the event will fire asynchronously, false
28  * by default from default constructor
29  */
30  public Event(boolean isAsync) {
31  this.async = isAsync;
32  }
33 
34  /**
35  * Convenience method for providing a user-friendly identifier. By
36  * default, it is the event's class's {@linkplain Class#getSimpleName()
37  * simple name}.
38  *
39  * @return name of this event
40  */
41  public String getEventName() {
42  if (name == null) {
43  name = getClass().getSimpleName();
44  }
45  return name;
46  }
47 
48  public abstract HandlerList getHandlers();
49 
50  /**
51  * Any custom event that should not by synchronized with other events must
52  * use the specific constructor. These are the caveats of using an
53  * asynchronous event:
54  * <ul>
55  * <li>The event is never fired from inside code triggered by a
56  * synchronous event. Attempting to do so results in an {@link
57  * java.lang.IllegalStateException}.
58  * <li>However, asynchronous event handlers may fire synchronous or
59  * asynchronous events
60  * <li>The event may be fired multiple times simultaneously and in any
61  * order.
62  * <li>Any newly registered or unregistered handler is ignored after an
63  * event starts execution.
64  * <li>The handlers for this event may block for any length of time.
65  * <li>Some implementations may selectively declare a specific event use
66  * as asynchronous. This behavior should be clearly defined.
67  * <li>Asynchronous calls are not calculated in the plugin timing system.
68  * </ul>
69  *
70  * @return false by default, true if the event fires asynchronously
71  */
72  public final boolean isAsynchronous() {
73  return async;
74  }
75 
76  public enum Result {
77 
78  /**
79  * Deny the event. Depending on the event, the action indicated by the
80  * event will either not take place or will be reverted. Some actions
81  * may not be denied.
82  */
84  /**
85  * Neither deny nor allow the event. The server will proceed with its
86  * normal handling.
87  */
89  /**
90  * Allow / Force the event. The action indicated by the event will
91  * take place if possible, even if the server would not normally allow
92  * the action. Some actions may not be allowed.
93  */
95  }
96 }
String getEventName()
Definition: Event.java:41
Event(boolean isAsync)
Definition: Event.java:30
final boolean isAsynchronous()
Definition: Event.java:72