Search in sources :

Example 1 with HandlerList

use of org.bukkit.event.HandlerList in project MassiveCore by MassiveCraft.

the class EventUtil method callEventAt.

public static void callEventAt(Event event, EventPriority priority) {
    HandlerList handlers = event.getHandlers();
    RegisteredListener[] listeners = handlers.getRegisteredListeners().clone();
    for (RegisteredListener registration : listeners) {
        try {
            EventPriority thisPriority = (EventPriority) fieldRegisteredListenerDotPriority.get(registration);
            if (thisPriority != priority)
                continue;
        } catch (Exception e) {
            e.printStackTrace();
            continue;
        }
        fireEventRegistration(event, registration);
    }
}
Also used : HandlerList(org.bukkit.event.HandlerList) RegisteredListener(org.bukkit.plugin.RegisteredListener) AuthorNagException(org.bukkit.plugin.AuthorNagException) EventPriority(org.bukkit.event.EventPriority)

Example 2 with HandlerList

use of org.bukkit.event.HandlerList in project MassiveCore by MassiveCraft.

the class EventUtil method callEventAfter.

public static void callEventAfter(Event event, Listener listener, EventPriority priority) {
    HandlerList handlers = event.getHandlers();
    RegisteredListener[] listeners = handlers.getRegisteredListeners().clone();
    boolean run = false;
    for (RegisteredListener registration : listeners) {
        if (run) {
            fireEventRegistration(event, registration);
        } else {
            try {
                EventPriority thisPriority = (EventPriority) fieldRegisteredListenerDotPriority.get(registration);
                Listener thisListener = (Listener) fieldRegisteredListenerDotListener.get(registration);
                if (thisListener == listener && thisPriority == priority)
                    run = true;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : HandlerList(org.bukkit.event.HandlerList) RegisteredListener(org.bukkit.plugin.RegisteredListener) Listener(org.bukkit.event.Listener) RegisteredListener(org.bukkit.plugin.RegisteredListener) AuthorNagException(org.bukkit.plugin.AuthorNagException) EventPriority(org.bukkit.event.EventPriority)

Example 3 with HandlerList

use of org.bukkit.event.HandlerList in project VoxelGamesLibv2 by VoxelGamesLib.

the class LoggedPluginManager method getEventListeners.

private HandlerList getEventListeners(Class<? extends Event> type) {
    try {
        Method method = getRegistrationClass(type).getDeclaredMethod("getHandlerList");
        method.setAccessible(true);
        return (HandlerList) method.invoke(null);
    } catch (Exception e) {
        throw new IllegalPluginAccessException(e.toString());
    }
}
Also used : HandlerList(org.bukkit.event.HandlerList) IllegalPluginAccessException(org.bukkit.plugin.IllegalPluginAccessException) Method(java.lang.reflect.Method) UnknownDependencyException(org.bukkit.plugin.UnknownDependencyException) InvalidDescriptionException(org.bukkit.plugin.InvalidDescriptionException) EventException(org.bukkit.event.EventException) IllegalPluginAccessException(org.bukkit.plugin.IllegalPluginAccessException) AuthorNagException(org.bukkit.plugin.AuthorNagException) InvalidPluginException(org.bukkit.plugin.InvalidPluginException)

Example 4 with HandlerList

use of org.bukkit.event.HandlerList in project Denizen-For-Bukkit by DenizenScript.

the class ServerTagBase method getHandlerPluginList.

public static ListTag getHandlerPluginList(Class eventClass) {
    if (Event.class.isAssignableFrom(eventClass)) {
        HandlerList handlers = BukkitScriptEvent.getEventListeners(eventClass);
        if (handlers != null) {
            ListTag result = new ListTag();
            HashSet<String> deduplicationSet = new HashSet<>();
            for (RegisteredListener listener : handlers.getRegisteredListeners()) {
                if (deduplicationSet.add(listener.getPlugin().getName())) {
                    result.addObject(new PluginTag(listener.getPlugin()));
                }
            }
            return result;
        }
    }
    return null;
}
Also used : HandlerList(org.bukkit.event.HandlerList) RegisteredListener(org.bukkit.plugin.RegisteredListener)

Example 5 with HandlerList

use of org.bukkit.event.HandlerList in project Dragonet-Legacy by DragonetMC.

the class MixedPluginManager method getEventListeners.

private HandlerList getEventListeners(Class<? extends Event> type) {
    try {
        Method method = getRegistrationClass(type).getDeclaredMethod("getHandlerList");
        method.setAccessible(true);
        return (HandlerList) method.invoke(null);
    } catch (Exception e) {
        throw new IllegalPluginAccessException(e.toString());
    }
}
Also used : HandlerList(org.bukkit.event.HandlerList) IllegalPluginAccessException(org.bukkit.plugin.IllegalPluginAccessException) Method(java.lang.reflect.Method) UnknownDependencyException(org.bukkit.plugin.UnknownDependencyException) InvalidDescriptionException(org.bukkit.plugin.InvalidDescriptionException) MalformedURLException(java.net.MalformedURLException) IllegalPluginAccessException(org.bukkit.plugin.IllegalPluginAccessException) AuthorNagException(org.bukkit.plugin.AuthorNagException) InvalidPluginException(org.bukkit.plugin.InvalidPluginException)

Aggregations

HandlerList (org.bukkit.event.HandlerList)11 RegisteredListener (org.bukkit.plugin.RegisteredListener)7 AuthorNagException (org.bukkit.plugin.AuthorNagException)5 EventPriority (org.bukkit.event.EventPriority)4 Method (java.lang.reflect.Method)3 MalformedURLException (java.net.MalformedURLException)2 EventException (org.bukkit.event.EventException)2 Listener (org.bukkit.event.Listener)2 IllegalPluginAccessException (org.bukkit.plugin.IllegalPluginAccessException)2 InvalidDescriptionException (org.bukkit.plugin.InvalidDescriptionException)2 InvalidPluginException (org.bukkit.plugin.InvalidPluginException)2 TimedRegisteredListener (org.bukkit.plugin.TimedRegisteredListener)2 UnknownDependencyException (org.bukkit.plugin.UnknownDependencyException)2 BHandlerList (com.bergerkiller.reflection.org.bukkit.BHandlerList)1 ReflectionUtils (com.laytonsmith.PureUtilities.Common.ReflectionUtils)1 EventIdentifier (com.laytonsmith.annotations.EventIdentifier)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Event (org.bukkit.event.Event)1 EventHandler (org.bukkit.event.EventHandler)1 PlayerCommandPreprocessEvent (org.bukkit.event.player.PlayerCommandPreprocessEvent)1