Java 类org.bukkit.plugin.EventExecutor 实例源码

项目:EscapeLag    文件:EventExecutorInjector.java   
/**
 * 
 * @author jiongjionger,Vlvxingze
 */

// 将监听器原本的EventExecutor替换成带性能统计的版本
public static void inject(Plugin plg) {
    if (plg != null) {
        for (RegisteredListener listener : HandlerList.getRegisteredListeners(plg)) {
            try {
                FieldAccessor<EventExecutor> field = Reflection.getField(RegisteredListener.class, "executor", EventExecutor.class);
                EventExecutor fieldEventExecutor = field.get(listener);
                field.set(listener, new EventExecutorInjector(plg, fieldEventExecutor));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
项目:ExilePearl    文件:TestPluginManager.java   
@Override
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority, EventExecutor executor, Plugin plugin, boolean ignoreCancelled) {
       Validate.notNull(listener, "Listener cannot be null");
       Validate.notNull(priority, "Priority cannot be null");
       Validate.notNull(executor, "Executor cannot be null");
       Validate.notNull(plugin, "Plugin cannot be null");

       if (!plugin.isEnabled()) {
           throw new IllegalPluginAccessException("Plugin attempted to register " + event + " while not enabled");
       }

       if (useTimings) {
           getEventListeners(event).register(new TimedRegisteredListener(listener, executor, priority, plugin, ignoreCancelled));
       } else {
           getEventListeners(event).register(new RegisteredListener(listener, executor, priority, plugin, ignoreCancelled));
       }
}
项目:ReUtil    文件:EventManager.java   
private static void tryRegisterEvent(Listener listener, Method method, AutoEventHandler eventHandler, Plugin plugin) {
    final Annotation[][] parameterAnnotations = method.getParameterAnnotations();
    final Class<?>[] parameterTypes = method.getParameterTypes();
    if(parameterTypes.length == 0 || !Event.class.isAssignableFrom(parameterTypes[0])) {
        Bukkit.getLogger().severe(plugin.getDescription().getFullName() + " attempted to register an invalid AutoEventHandler method signature \"" + method.toGenericString() + "\" in " + listener.getClass());
        return;
    } else if(parameterTypes.length == 1) {
        Bukkit.getLogger().warning(plugin.getDescription().getFullName() + " attempted to register an EventHandler method signature \"" + method.toGenericString() + "\" as AutoEventHandler in " + listener.getClass());
    }

    final Class<? extends Event> eventType = parameterTypes[0].asSubclass(Event.class);

    final MethodHandle mainHandle;
    try {
        mainHandle = MethodHandles.lookup().unreflect(method);
    } catch (IllegalAccessException e) {
        return;
    }

    final MethodHandle[] handles = getParameterHandles(listener, method, plugin, parameterAnnotations, parameterTypes, eventType);
    if (handles == null) return;

    EventExecutor executor = createEventExecutor(parameterTypes, eventType, mainHandle, handles);
    Bukkit.getPluginManager().registerEvent(eventType, listener, eventHandler.priority(), executor, plugin, eventHandler.ignoreCancelled());
}
项目:EscapeLag    文件:MonitorUtils.java   
public static Map<String, MonitorRecord> getEventTimingsByPlugin(Plugin plg) {
    Map<String, MonitorRecord> record = new HashMap<>();
    if (plg == null) {
        return record;
    }
    for (RegisteredListener listener : HandlerList.getRegisteredListeners(plg)) {
        try {
            FieldAccessor<EventExecutor> field = Reflection.getField(RegisteredListener.class, "executor",
                    EventExecutor.class);
            EventExecutor executor = field.get(listener);
            if (executor instanceof EventExecutorInjector) {
                EventExecutorInjector eventExecutorInjector = (EventExecutorInjector) executor;
                String eventName = eventExecutorInjector.getEventName();
                if (eventName != null) {
                    MonitorRecord monitorRecord = getMonitorRecord(eventName, eventExecutorInjector.getTotalTime(),
                            eventExecutorInjector.getTotalCount(), eventExecutorInjector.getMaxExecuteTime());
                    if (record.containsKey(eventName)) {
                        MonitorRecord otherMonitorRecord = record.get(eventName);
                        record.put(eventName, otherMonitorRecord.merge(monitorRecord));
                    } else {
                        record.put(eventName, monitorRecord);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return record;
}
项目:EscapeLag    文件:EventExecutorInjector.java   
public static void uninject(Plugin plg) {
    if (plg != null) {
        for (RegisteredListener listener : HandlerList.getRegisteredListeners(plg)) {
            try {
                FieldAccessor<EventExecutor> field = Reflection.getField(RegisteredListener.class, "executor", EventExecutor.class);
                EventExecutor executor = field.get(listener);
                if (executor instanceof EventExecutorInjector) {
                    field.set(listener, ((EventExecutorInjector) executor).getEventExecutor());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
项目:MockBukkit    文件:PluginManagerMock.java   
@Override
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority,
        EventExecutor executor, Plugin plugin)
{
    // TODO Auto-generated method stub
    throw new UnimplementedOperationException();
}
项目:MockBukkit    文件:PluginManagerMock.java   
@Override
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority,
        EventExecutor executor, Plugin plugin, boolean ignoreCancelled)
{
    // TODO Auto-generated method stub
    throw new UnimplementedOperationException();
}
项目:NeverLag    文件:MonitorUtils.java   
public static Map<String, MonitorRecord> getEventTimingsByPlugin(Plugin plg) {
    Map<String, MonitorRecord> record = new HashMap<>();
    if (plg == null) {
        return record;
    }
    for (RegisteredListener listener : HandlerList.getRegisteredListeners(plg)) {
        try {
            FieldAccessor<EventExecutor> field = Reflection.getField(RegisteredListener.class, "executor", EventExecutor.class);
            EventExecutor executor = field.get(listener);
            if (executor instanceof EventExecutorInjector) {
                EventExecutorInjector eventExecutorInjector = (EventExecutorInjector) executor;
                String eventName = eventExecutorInjector.getEventName();
                if (eventName != null) {
                    MonitorRecord monitorRecord = getMonitorRecord(eventName, eventExecutorInjector.getTotalTime(), eventExecutorInjector.getTotalCount(),
                        eventExecutorInjector.getMaxExecuteTime());
                    if (record.containsKey(eventName)) {
                        MonitorRecord otherMonitorRecord = record.get(eventName);
                        record.put(eventName, otherMonitorRecord.merge(monitorRecord));
                    } else {
                        record.put(eventName, monitorRecord);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return record;
}
项目:NeverLag    文件:EventExecutorInjector.java   
public static void inject(Plugin plg) {
    if (plg != null) {
        for (RegisteredListener listener : HandlerList.getRegisteredListeners(plg)) {
            try {
                FieldAccessor<EventExecutor> field = Reflection.getField(RegisteredListener.class, "executor", EventExecutor.class);
                EventExecutor fieldEventExecutor = field.get(listener);
                field.set(listener, new EventExecutorInjector(plg, fieldEventExecutor));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
项目:NeverLag    文件:EventExecutorInjector.java   
public static void uninject(Plugin plg) {
    if (plg != null) {
        for (RegisteredListener listener : HandlerList.getRegisteredListeners(plg)) {
            try {
                FieldAccessor<EventExecutor> field = Reflection.getField(RegisteredListener.class, "executor", EventExecutor.class);
                EventExecutor executor = field.get(listener);
                if (executor instanceof EventExecutorInjector) {
                    field.set(listener, ((EventExecutorInjector) executor).getEventExecutor());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
项目:Ourtown    文件:EventListener.java   
public EventListener(OurTown pl) {
    this.plugin = pl;
    pl.getServer().getPluginManager().registerEvents(this, pl);
    if (plugin.config.handle_player_respawn) {
        plugin.getServer().getPluginManager().registerEvent(PlayerRespawnEvent.class, this,
                plugin.config.respawn_listener_priority, new EventExecutor() {
                    @Override
                    public void execute(Listener listener, Event event) throws EventException {
                        ((EventListener) listener).onPlayerRespawn((PlayerRespawnEvent) event);
                    }
                }, plugin, true);
    }
}
项目:LagMonitor    文件:ListenerInjector.java   
public static void inject(Plugin plugin) {
    List<RegisteredListener> listeners = HandlerList.getRegisteredListeners(plugin);
    for (RegisteredListener listener : listeners) {
        HandlerList.unregisterAll(listener.getListener());
        FieldAccessor<EventExecutor> executorField = Reflection
                .getField(RegisteredListener.class, "executor", EventExecutor.class);

        EventExecutor originalExecutor = executorField.get(listener);
        ListenerInjector listenerInjector = new ListenerInjector(originalExecutor);

        executorField.set(listener, listenerInjector);
    }
}
项目:LagMonitor    文件:ListenerInjector.java   
public static void uninject(Plugin plugin) {
    List<RegisteredListener> listeners = HandlerList.getRegisteredListeners(plugin);
    for (RegisteredListener listener : listeners) {
        HandlerList.unregisterAll(listener.getListener());
        FieldAccessor<EventExecutor> executorField = Reflection
                .getField(RegisteredListener.class, "executor", EventExecutor.class);

        EventExecutor executor = executorField.get(listener);
        if (executor instanceof ListenerInjector) {
            executorField.set(listener, ((ListenerInjector) executor).originalExecutor);
        }
    }
}
项目:LagMonitor    文件:ListenerInjector.java   
public static void inject(Plugin plugin) {
    List<RegisteredListener> listeners = HandlerList.getRegisteredListeners(plugin);
    for (RegisteredListener listener : listeners) {
        HandlerList.unregisterAll(listener.getListener());
        FieldAccessor<EventExecutor> executorField = Reflection
                .getField(RegisteredListener.class, "executor", EventExecutor.class);

        EventExecutor originalExecutor = executorField.get(listener);
        ListenerInjector listenerInjector = new ListenerInjector(originalExecutor);

        executorField.set(listener, listenerInjector);
    }
}
项目:LagMonitor    文件:ListenerInjector.java   
public static void uninject(Plugin plugin) {
    List<RegisteredListener> listeners = HandlerList.getRegisteredListeners(plugin);
    for (RegisteredListener listener : listeners) {
        HandlerList.unregisterAll(listener.getListener());
        FieldAccessor<EventExecutor> executorField = Reflection
                .getField(RegisteredListener.class, "executor", EventExecutor.class);

        EventExecutor executor = executorField.get(listener);
        if (executor instanceof ListenerInjector) {
            executorField.set(listener, ((ListenerInjector) executor).originalExecutor);
        }
    }
}
项目:EscapeLag    文件:EventExecutorInjector.java   
public EventExecutorInjector(Plugin plugin, EventExecutor eventExecutor) {
    super(plugin);
    this.eventExecutor = eventExecutor;
}
项目:EscapeLag    文件:EventExecutorInjector.java   
public EventExecutor getEventExecutor() {
    return this.eventExecutor;
}
项目:NeverLag    文件:EventExecutorInjector.java   
public EventExecutorInjector(Plugin plugin, EventExecutor eventExecutor) {
    super(plugin);
    this.eventExecutor = eventExecutor;
}
项目:NeverLag    文件:EventExecutorInjector.java   
public EventExecutor getEventExecutor() {
    return this.eventExecutor;
}
项目:VoxelGamesLibv2    文件:LoggedPluginManager.java   
@Override
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority,
                          EventExecutor executor, Plugin plugin) {
    catchError(plugin, () -> delegate
            .registerEvent(event, listener, priority, getWrappedExecutor(executor), plugin));
}
项目:VoxelGamesLibv2    文件:LoggedPluginManager.java   
@Override
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority,
                          EventExecutor executor, Plugin plugin, boolean ignoreCancel) {
    catchError(plugin, () -> delegate
            .registerEvent(event, listener, priority, getWrappedExecutor(executor), plugin));
}
项目:Skript    文件:PlayerChatEventHandler.java   
public final static void registerChatEvent(final EventPriority priority, final EventExecutor executor, final boolean ignoreCancelled) {
    if (Skript.classExists("org.bukkit.event.player.AsyncPlayerChatEvent"))
        Bukkit.getPluginManager().registerEvent(AsyncPlayerChatEvent.class, new Listener() {}, priority, executor, Skript.getInstance(), ignoreCancelled);
    else
        Bukkit.getPluginManager().registerEvent(PlayerChatEvent.class, new Listener() {}, priority, executor, Skript.getInstance(), ignoreCancelled);
}
项目:MinigameManager    文件:MinigamePluginManagerWrapper.java   
@Override
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority, EventExecutor executor, Plugin plugin) {
    pm.registerEvent(event, listener, priority, executor, plugin);
}
项目:MinigameManager    文件:MinigamePluginManagerWrapper.java   
@Override
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority, EventExecutor executor, Plugin plugin, boolean ignoreCancelled) {
    pm.registerEvent(event, listener, priority, executor, plugin, ignoreCancelled);
}
项目:ExilePearl    文件:TestPluginManager.java   
@Override
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority, EventExecutor executor, Plugin plugin) {
       registerEvent(event, listener, priority, executor, plugin, false);
}
项目:LagMonitor    文件:ListenerInjector.java   
public ListenerInjector(EventExecutor originalExecutor) {
    this.originalExecutor = originalExecutor;
}
项目:LagMonitor    文件:ListenerInjector.java   
public EventExecutor getOriginalExecutor() {
    return originalExecutor;
}
项目:Pokkit    文件:BukkitEventManager.java   
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority,
        EventExecutor executor, Plugin plugin) {
    registerEvent(event, listener, priority, executor, plugin, false);
}
项目:Pokkit    文件:PokkitPluginManager.java   
@Override
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority,
        EventExecutor executor, Plugin plugin) {
    eventManager.registerEvent(event, listener, priority, executor, plugin);
}
项目:Pokkit    文件:PokkitPluginManager.java   
@Override
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority,
        EventExecutor executor, Plugin plugin, boolean ignoreCancelled) {
    eventManager.registerEvent(event, listener, priority, executor, plugin, ignoreCancelled);
}
项目:LagMonitor    文件:ListenerInjector.java   
public ListenerInjector(EventExecutor originalExecutor) {
    this.originalExecutor = originalExecutor;
}
项目:LagMonitor    文件:ListenerInjector.java   
public EventExecutor getOriginalExecutor() {
    return originalExecutor;
}
项目:NovaGuilds    文件:LoggedPluginManager.java   
@Override
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority, EventExecutor executor, Plugin plugin) {

    delegate.registerEvent(event, listener, priority, getWrappedExecutor(executor), plugin);
}
项目:NovaGuilds    文件:LoggedPluginManager.java   
@Override
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority, EventExecutor executor, Plugin plugin, boolean ignoreCancel) {

    delegate.registerEvent(event, listener, priority, getWrappedExecutor(executor), plugin);
}
项目:BedrockAPI    文件:RegisteredListener.java   
public RegisteredListener(Listener listener, EventExecutor executor, EventPriority priority, Plugin plugin, boolean ignoreCancelled) {
}
项目:BedrockAPI    文件:TimedRegisteredListener.java   
public TimedRegisteredListener(Listener pluginListener, EventExecutor eventExecutor, EventPriority eventPriority, Plugin registeredPlugin, boolean listenCancelled) {
       super(pluginListener, eventExecutor, eventPriority, registeredPlugin, listenCancelled);
}
项目:BedrockAPI    文件:SimplePluginManager.java   
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority, EventExecutor executor, Plugin plugin) {
}
项目:BedrockAPI    文件:SimplePluginManager.java   
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority, EventExecutor executor, Plugin plugin, boolean ignoreCancelled) {
}
项目:Pokkit    文件:BukkitEventManager.java   
/**
 * Registers the given event to the specified listener using a directly
 * passed EventExecutor
 *
 * @param event
 *            Event class to register
 * @param listener
 *            PlayerListener to register
 * @param priority
 *            Priority of this event
 * @param executor
 *            EventExecutor to register
 * @param plugin
 *            Plugin to register
 * @param ignoreCancelled
 *            Do not call executor if event was already cancelled
 */
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority,
        EventExecutor executor, Plugin plugin, boolean ignoreCancelled) {
    Validate.notNull(listener, "Listener cannot be null");
    Validate.notNull(priority, "Priority cannot be null");
    Validate.notNull(executor, "Executor cannot be null");
    Validate.notNull(plugin, "Plugin cannot be null");

    if (!plugin.isEnabled()) {
        throw new IllegalPluginAccessException("Plugin attempted to register " + event + " while not enabled");
    }

    getEventListeners(event)
            .register(new RegisteredListener(listener, executor, priority, plugin, ignoreCancelled));
}
项目:NerdLag    文件:MaxTimedRegisteredListener.java   
/**
 * Constructor.
 *
 * A MaxTimedRegisteredListener is constructed from an original
 * TimedRegisteredListener that it replaces.
 *
 * @param original the RegisteredListener this instance will replace.
 * @param report if true, event handler invocations exceeding
 *        reportThresholdNanos.
 * @param reportThresholdNanos the event handler duration in nanoseconds,
 *        above which the event will be reported to
 *        {@link NerdLag#report(MaxTimedRegisteredListener, long)}.
 * @param handler receives callbacks about event executions whose durations
 *        exceed the reporting threshold.
 *
 * @throws SecurityException
 * @throws NoSuchFieldException
 * @throws IllegalAccessException
 * @throws IllegalArgumentException
 */
public MaxTimedRegisteredListener(RegisteredListener original, boolean report, long reportThresholdNanos, EventDurationHandler handler)
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    super(original.getListener(), null, original.getPriority(), original.getPlugin(), original.isIgnoringCancelled());
    this.report = report;
    this.reportThresholdNanos = reportThresholdNanos;
    this.handler = handler;

    // Copy the executor field from the original TimedRegisteredListener.
    Class<RegisteredListener> rlClass = RegisteredListener.class;
    Field executorField = rlClass.getDeclaredField("executor");
    executorField.setAccessible(true);
    executor = (EventExecutor) executorField.get(original);
    executorField.set(this, executor);
}