cn.nukkit.event.Listener Java Examples

The following examples show how to use cn.nukkit.event.Listener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Timings.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public static Timing getPluginEventTiming(Class<? extends Event> event, Listener listener, EventExecutor executor, Plugin plugin) {
    Timing group = TimingsManager.getTiming(plugin.getName(), "Combined Total", pluginEventTimer);

    return TimingsManager.getTiming(plugin.getName(), "Event: " + listener.getClass().getName() + "."
            + (executor instanceof MethodEventExecutor ? ((MethodEventExecutor) executor).getMethod().getName() : "???")
            + " (" + event.getSimpleName() + ")", group);
}
 
Example #2
Source File: RegisteredListener.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public RegisteredListener(Listener listener, EventExecutor executor, EventPriority priority, Plugin plugin, boolean ignoreCancelled, Timing timing) {
    this.listener = listener;
    this.priority = priority;
    this.plugin = plugin;
    this.executor = executor;
    this.ignoreCancelled = ignoreCancelled;
    this.timing = timing;
}
 
Example #3
Source File: PluginManager.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority, EventExecutor executor, Plugin plugin, boolean ignoreCancelled) throws PluginException {
    if (!plugin.isEnabled()) {
        throw new PluginException("Plugin attempted to register " + event + " while not enabled");
    }

    try {
        Timing timing = Timings.getPluginEventTiming(event, listener, executor, plugin);
        this.getEventListeners(event).register(new RegisteredListener(listener, executor, priority, plugin, ignoreCancelled, timing));
    } catch (IllegalAccessException e) {
        Server.getInstance().getLogger().logException(e);
    }
}
 
Example #4
Source File: Timings.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public static Timing getPluginEventTiming(Class<? extends Event> event, Listener listener, EventExecutor executor, Plugin plugin) {
    Timing group = TimingsManager.getTiming(plugin.getName(), "Combined Total", pluginEventTimer);

    return TimingsManager.getTiming(plugin.getName(), "Event: " + listener.getClass().getName() + "."
            + (executor instanceof MethodEventExecutor ? ((MethodEventExecutor) executor).getMethod().getName() : "???")
            + " (" + event.getSimpleName() + ")", group);
}
 
Example #5
Source File: RegisteredListener.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public RegisteredListener(Listener listener, EventExecutor executor, EventPriority priority, Plugin plugin, boolean ignoreCancelled, Timing timing) {
    this.listener = listener;
    this.priority = priority;
    this.plugin = plugin;
    this.executor = executor;
    this.ignoreCancelled = ignoreCancelled;
    this.timing = timing;
}
 
Example #6
Source File: NukkitPlugin.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void registerListener(Listener... listeners) {
    for (Listener listener : listeners) {
        if (listener == null) {
            logger.warn("Attempted to register a null listener!");
            continue;
        }
        getServer().getPluginManager().registerEvents(listener, this);
    }
}
 
Example #7
Source File: Timings.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public static Timing getPluginEventTiming(Class<? extends Event> event, Listener listener, EventExecutor executor, Plugin plugin) {
    Timing group = TimingsManager.getTiming(plugin.getName(), "Combined Total", pluginEventTimer);

    return TimingsManager.getTiming(plugin.getName(), "Event: " + listener.getClass().getName() + "."
            + (executor instanceof MethodEventExecutor ? ((MethodEventExecutor) executor).getMethod().getName() : "???")
            + " (" + event.getSimpleName() + ")", group);
}
 
Example #8
Source File: RegisteredListener.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public RegisteredListener(Listener listener, EventExecutor executor, EventPriority priority, Plugin plugin, boolean ignoreCancelled, Timing timing) {
    this.listener = listener;
    this.priority = priority;
    this.plugin = plugin;
    this.executor = executor;
    this.ignoreCancelled = ignoreCancelled;
    this.timing = timing;
}
 
Example #9
Source File: RegisteredListener.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public Listener getListener() {
    return listener;
}
 
Example #10
Source File: PluginManager.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public void registerEvents(Listener listener, Plugin plugin) {
    if (!plugin.isEnabled()) {
        throw new PluginException("Plugin attempted to register " + listener.getClass().getName() + " while not enabled");
    }

    Set<Method> methods;
    try {
        Method[] publicMethods = listener.getClass().getMethods();
        Method[] privateMethods = listener.getClass().getDeclaredMethods();
        methods = new HashSet<>(publicMethods.length + privateMethods.length, 1.0f);
        Collections.addAll(methods, publicMethods);
        Collections.addAll(methods, privateMethods);
    } catch (NoClassDefFoundError e) {
        plugin.getLogger().error("Plugin " + plugin.getDescription().getFullName() + " has failed to register events for " + listener.getClass() + " because " + e.getMessage() + " does not exist.");
        return;
    }

    for (final Method method : methods) {
        final EventHandler eh = method.getAnnotation(EventHandler.class);
        if (eh == null) continue;
        if (method.isBridge() || method.isSynthetic()) {
            continue;
        }
        final Class<?> checkClass;

        if (method.getParameterTypes().length != 1 || !Event.class.isAssignableFrom(checkClass = method.getParameterTypes()[0])) {
            plugin.getLogger().error(plugin.getDescription().getFullName() + " attempted to register an invalid EventHandler method signature \"" + method.toGenericString() + "\" in " + listener.getClass());
            continue;
        }

        final Class<? extends Event> eventClass = checkClass.asSubclass(Event.class);
        method.setAccessible(true);

        for (Class<?> clazz = eventClass; Event.class.isAssignableFrom(clazz); clazz = clazz.getSuperclass()) {
            // This loop checks for extending deprecated events
            if (clazz.getAnnotation(Deprecated.class) != null) {
                if (Boolean.valueOf(String.valueOf(this.server.getConfig("settings.deprecated-verbpse", true)))) {
                    this.server.getLogger().warning(this.server.getLanguage().translateString("nukkit.plugin.deprecatedEvent", plugin.getName(), clazz.getName(), listener.getClass().getName() + "." + method.getName() + "()"));
                }
                break;
            }
        }
        this.registerEvent(eventClass, listener, eh.priority(), new MethodEventExecutor(method), plugin, eh.ignoreCancelled());
    }
}
 
Example #11
Source File: PluginManager.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority, EventExecutor executor, Plugin plugin) throws PluginException {
    this.registerEvent(event, listener, priority, executor, plugin, false);
}
 
Example #12
Source File: RegisteredListener.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public Listener getListener() {
    return listener;
}
 
Example #13
Source File: RegisteredListener.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public Listener getListener() {
    return listener;
}
 
Example #14
Source File: EventExecutor.java    From Jupiter with GNU General Public License v3.0 votes vote down vote up
void execute(Listener listener, Event event) throws EventException; 
Example #15
Source File: EventExecutor.java    From Nukkit with GNU General Public License v3.0 votes vote down vote up
void execute(Listener listener, Event event) throws EventException; 
Example #16
Source File: EventExecutor.java    From Nukkit with GNU General Public License v3.0 votes vote down vote up
void execute(Listener listener, Event event) throws EventException;