org.bukkit.plugin.EventExecutor Java Examples

The following examples show how to use org.bukkit.plugin.EventExecutor. 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: SpringEventExecutor.java    From mcspring-boot with MIT License 5 votes vote down vote up
public EventExecutor create(Method method) {
    val eventType = method.getParameters()[0].getType();
    return (listener, event) -> {
        if (!eventType.isInstance(event)) return;
        context.runWithSender(EventUtil.getSender(event), () -> {
            triggerEvent(method, listener, event);
        });
    };
}
 
Example #2
Source File: ObservableTest.java    From mcspring-boot with MIT License 5 votes vote down vote up
@Test
public void shouldEmitEventsToTheObservable() throws EventException {
    TestObserver<TestEvent> testObserver = testEventObservable.test();
    verify(server.getPluginManager()).registerEvent(eq(TestEvent.class), any(), any(), eventExecutorCaptor.capture(), eq(plugin), anyBoolean());
    EventExecutor executor = eventExecutorCaptor.getValue();

    TestEvent event = new TestEvent(player);
    executor.execute(null, event);
    executor.execute(null, event);

    testObserver
            .assertValuesOnly(event, event)
            .assertNotTerminated();
}
 
Example #3
Source File: BlockTransformListener.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
public void registerEvents() {
  // Find all the @EventWrapper methods in this class and register them at EVERY priority level.
  Stream.of(getClass().getMethods())
      .filter(method -> method.getAnnotation(EventWrapper.class) != null)
      .forEach(
          method -> {
            final Class<? extends Event> eventClass =
                method.getParameterTypes()[0].asSubclass(Event.class);

            for (final EventPriority priority : EventPriority.values()) {
              EventExecutor executor =
                  new EventExecutor() {
                    @Override
                    public void execute(Listener listener, Event event) throws EventException {
                      // REMOVED: Ignore the event if it was fron a non-Match world
                      // if (event instanceof Physical
                      //    && PGM.get().getMatchManager().getMatch(((Physical) event).getWorld())
                      // ==
                      // null)
                      //  return;

                      if (!Events.isCancelled(event)) {
                        // At the first priority level, call the event handler method.
                        // If it decides to generate a BlockTransformEvent, it will be stored in
                        // currentEvents.
                        if (priority == EventPriority.LOWEST) {
                          if (eventClass.isInstance(event)) {
                            try {
                              method.invoke(listener, event);
                            } catch (InvocationTargetException ex) {
                              throw new EventException(ex.getCause(), event);
                            } catch (Throwable t) {
                              throw new EventException(t, event);
                            }
                          }
                        }
                      }

                      // Check for cached events and dispatch them at the current priority level
                      // only.
                      // The BTE needs to be dispatched even after it's cancelled, because we DO
                      // have
                      // listeners that depend on receiving cancelled events e.g. WoolMatchModule.
                      for (BlockTransformEvent bte : currentEvents.get(event)) {
                        Events.callEvent(bte, priority);
                      }

                      // After dispatching the last priority level, clean up the cached events and
                      // do
                      // post-event stuff.
                      // This needs to happen even if the event is cancelled.
                      if (priority == EventPriority.MONITOR) {
                        finishCauseEvent(event);
                      }
                    }
                  };

              pm.registerEvent(eventClass, this, priority, executor, plugin, false);
            }
          });
}
 
Example #4
Source File: LoggedPluginManager.java    From VoxelGamesLibv2 with MIT License 4 votes vote down vote up
@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));
}
 
Example #5
Source File: LoggedPluginManager.java    From VoxelGamesLibv2 with MIT License 4 votes vote down vote up
@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));
}
 
Example #6
Source File: PlayerChatEventHandler.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
public 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);
}
 
Example #7
Source File: LoggedPluginManager.java    From NovaGuilds with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority, EventExecutor executor, Plugin plugin) {

	delegate.registerEvent(event, listener, priority, getWrappedExecutor(executor), plugin);
}
 
Example #8
Source File: LoggedPluginManager.java    From NovaGuilds with GNU General Public License v3.0 4 votes vote down vote up
@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);
}