summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorErik Broes <erikbroes@grum.nl>2012-01-19 08:13:49 +0100
committerErik Broes <erikbroes@grum.nl>2012-01-19 08:13:49 +0100
commit257e35d51c78e1d15e696769e98c37ef46c25678 (patch)
tree3e331ef879bc657ea6f5337434e6c62f530a5ffa /src
parent81dc1c0a520d53f92a8198bcec62e26700109d91 (diff)
downloadbukkit-257e35d51c78e1d15e696769e98c37ef46c25678.tar
bukkit-257e35d51c78e1d15e696769e98c37ef46c25678.tar.gz
bukkit-257e35d51c78e1d15e696769e98c37ef46c25678.tar.lz
bukkit-257e35d51c78e1d15e696769e98c37ef46c25678.tar.xz
bukkit-257e35d51c78e1d15e696769e98c37ef46c25678.zip
Use the type of the eventhandler method's parameter as type rather than specificing it. Thanks zml2008.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/bukkit/event/CustomEventListener.java2
-rw-r--r--src/main/java/org/bukkit/event/EventHandler.java9
-rw-r--r--src/main/java/org/bukkit/plugin/PluginLoader.java1
-rw-r--r--src/main/java/org/bukkit/plugin/PluginManager.java2
-rw-r--r--src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java9
5 files changed, 16 insertions, 7 deletions
diff --git a/src/main/java/org/bukkit/event/CustomEventListener.java b/src/main/java/org/bukkit/event/CustomEventListener.java
index afdf924a..26d2dbda 100644
--- a/src/main/java/org/bukkit/event/CustomEventListener.java
+++ b/src/main/java/org/bukkit/event/CustomEventListener.java
@@ -1,7 +1,5 @@
package org.bukkit.event;
-import org.bukkit.event.Listener;
-
/**
* Handles all custom events
*/
diff --git a/src/main/java/org/bukkit/event/EventHandler.java b/src/main/java/org/bukkit/event/EventHandler.java
index 42c00368..34c70adb 100644
--- a/src/main/java/org/bukkit/event/EventHandler.java
+++ b/src/main/java/org/bukkit/event/EventHandler.java
@@ -1,15 +1,22 @@
package org.bukkit.event;
+import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
/**
* An annotation to mark methods as being event handler methods
*/
+@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface EventHandler {
- Class<? extends Event> event();
+ /**
+ * This field is now fetched from the event handler method's parameter
+ * @return
+ */
+ @Deprecated Class<? extends Event> event() default Event.class;
EventPriority priority() default EventPriority.NORMAL;
}
diff --git a/src/main/java/org/bukkit/plugin/PluginLoader.java b/src/main/java/org/bukkit/plugin/PluginLoader.java
index bc4e849f..2a9dc10f 100644
--- a/src/main/java/org/bukkit/plugin/PluginLoader.java
+++ b/src/main/java/org/bukkit/plugin/PluginLoader.java
@@ -52,6 +52,7 @@ public interface PluginLoader {
* @param type Type of the event executor to create
* @param listener the object that will handle the eventual call back
* @return The new executor
+ * @deprecated see PluginLoader#createRegisteredListeners
*/
@Deprecated
public EventExecutor createExecutor(Event.Type type, Listener listener);
diff --git a/src/main/java/org/bukkit/plugin/PluginManager.java b/src/main/java/org/bukkit/plugin/PluginManager.java
index ea59dcde..c2930e28 100644
--- a/src/main/java/org/bukkit/plugin/PluginManager.java
+++ b/src/main/java/org/bukkit/plugin/PluginManager.java
@@ -103,6 +103,7 @@ public interface PluginManager {
* @param listener Listener to register
* @param priority Priority of this event
* @param plugin Plugin to register
+ * @deprecated see PluginManager#registerEvents
*/
@Deprecated
public void registerEvent(Event.Type type, Listener listener, Priority priority, Plugin plugin);
@@ -115,6 +116,7 @@ public interface PluginManager {
* @param executor EventExecutor to register
* @param priority Priority of this event
* @param plugin Plugin to register
+ * @deprecated see PluginManager#registerEvent(Class, Listener, EventPriority, EventExecutor, Plugin)
*/
@Deprecated
public void registerEvent(Event.Type type, Listener listener, EventExecutor executor, Priority priority, Plugin plugin);
diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
index 46fe3340..cfa41c6c 100644
--- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
+++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
@@ -987,20 +987,21 @@ public class JavaPluginLoader implements PluginLoader {
final EventHandler eh = method.getAnnotation(EventHandler.class);
if (eh == null) continue;
final Class<?> checkClass = method.getParameterTypes()[0];
- if (!checkClass.isAssignableFrom(eh.event()) || method.getParameterTypes().length != 1) {
+ if (!Event.class.isAssignableFrom(checkClass) || method.getParameterTypes().length != 1) {
plugin.getServer().getLogger().severe("Wrong method arguments used for event type registered");
continue;
}
+ final Class<? extends Event> eventClass = checkClass.asSubclass(Event.class);
method.setAccessible(true);
- Set<RegisteredListener> eventSet = ret.get(eh.event());
+ Set<RegisteredListener> eventSet = ret.get(eventClass);
if (eventSet == null) {
eventSet = new HashSet<RegisteredListener>();
- ret.put(eh.event(), eventSet);
+ ret.put(eventClass, eventSet);
}
eventSet.add(new RegisteredListener(listener, new EventExecutor() {
public void execute(Listener listener, Event event) throws EventException {
try {
- if (!checkClass.isAssignableFrom(event.getClass())) {
+ if (!eventClass.isAssignableFrom(event.getClass())) {
throw new EventException("Wrong event type passed to registered method");
}
method.invoke(listener, event);