org.bukkit.event.EventException Java Examples
The following examples show how to use
org.bukkit.event.EventException.
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: TimedRegisteredListener.java From Kettle with GNU General Public License v3.0 | 6 votes |
@Override public void callEvent(Event event) throws EventException { if (event.isAsynchronous()) { super.callEvent(event); return; } count++; Class<? extends Event> newEventClass = event.getClass(); if (this.eventClass == null) { this.eventClass = newEventClass; } else if (!this.eventClass.equals(newEventClass)) { multiple = true; this.eventClass = getCommonSuperclass(newEventClass, this.eventClass).asSubclass(Event.class); } long start = System.nanoTime(); super.callEvent(event); totalTime += System.nanoTime() - start; }
Example #2
Source File: MatchTabManager.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerTeamChange(PlayerChangePartyEvent event) throws EventException { event.yield(); invalidate(event.getPlayer()); if(event.getOldParty() instanceof Team) { this.getTeamEntry((Team) event.getOldParty()).invalidate(); } if(event.getNewParty() instanceof Team) { this.getTeamEntry((Team) event.getNewParty()).invalidate(); } if(event.getOldParty() instanceof Tribute || event.getNewParty() instanceof Tribute) { this.getFreeForAllEntry(event.getMatch()).invalidate(); } }
Example #3
Source File: BossBarMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onJoinLeave(PlayerChangePartyEvent event) throws EventException { final Player viewer = event.getPlayer().getBukkit(); if(event.isLeavingMatch()) { Optional.ofNullable(views.rowMap().remove(viewer)) .ifPresent(row -> row.values().forEach(View::destroy)); } event.yield(); if(event.isJoiningMatch()) { for(BossBarSource source : globalSources) { views.put(viewer, source, new View(source, viewer)); } } }
Example #4
Source File: CountdownContext.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler void suspend(ServerSuspendEvent event) throws EventException { try { event.yield(); } finally { runners().forEach(Runner::resume); } }
Example #5
Source File: EvtMoveOn.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("null") @Override public void execute(final @Nullable Listener l, final @Nullable Event event) throws EventException { if (event == null) return; final PlayerMoveEvent e = (PlayerMoveEvent) event; final Location from = e.getFrom(), to = e.getTo(); if (!itemTypeTriggers.isEmpty()) { final Block block = getOnBlock(to); if (block == null || block.getType() == Material.AIR) return; final Material id = block.getType(); final List<Trigger> ts = itemTypeTriggers.get(id); if (ts == null) return; final int y = getBlockY(to.getY(), id); if (to.getWorld().equals(from.getWorld()) && to.getBlockX() == from.getBlockX() && to.getBlockZ() == from.getBlockZ() && y == getBlockY(from.getY(), getOnBlock(from).getType()) && getOnBlock(from).getType() == id) return; SkriptEventHandler.logEventStart(e); triggersLoop: for (final Trigger t : ts) { final EvtMoveOn se = (EvtMoveOn) t.getEvent(); for (final ItemType i : se.types) { if (i.isOfType(block)) { SkriptEventHandler.logTriggerStart(t); t.execute(e); SkriptEventHandler.logTriggerEnd(t); continue triggersLoop; } } } SkriptEventHandler.logEventEnd(); } }
Example #6
Source File: JoinMessageAnnouncer.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onQuit(PlayerQuitEvent event) throws EventException { event.setQuitMessage(null); final User user = userStore.getUser(event.getPlayer()); final SessionChange change = pendingQuits.getIfPresent(user); event.yield(); if(change != null) { pendingQuits.invalidate(user); announce(change); } }
Example #7
Source File: ReadyListener.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onPlayerLeave(PlayerChangePartyEvent event) throws EventException { if(event.getNewParty() != null) return; event.yield(); ReadyManager readyManager = readyManagerProvider.get().orElse(null); if (readyManager == null) return; Tournament tournament = tournamentProvider.get(); Party party = event.getOldParty(); if (party != null && party.isParticipatingType() && party.getPlayers().size() < tournament.min_players_per_match()) { readyManager.markNotReady(party); } }
Example #8
Source File: TeamListener.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void addPlayersToRegisteredTeam(EntrantRegisterEvent event) throws EventException { event.yield(); Match match = event.getTeam().getMatch(); TeamMatchModule tmm = match.needMatchModule(TeamMatchModule.class); for(MatchPlayer player : match.getPlayers()) { if(event.getEntrant().members().contains(player.getPlayerId())) { tourney.getLogger().info("Adding player '" + player.getDisplayName() + "' to team '" + event.getTeam().getName() + "'"); tmm.forceJoin(player, event.getTeam()); } } }
Example #9
Source File: SuspendListener.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@Inject SuspendListener(Set<Suspendable> suspendables) { ThrowingConsumer<ServerSuspendEvent, EventException> yielder = Event::yield; for(Suspendable suspendable : suspendables) { ThrowingConsumer<ServerSuspendEvent, EventException> next = yielder; yielder = event -> suspendable.suspend(() -> next.acceptThrows(event)); } this.yielder = yielder; }
Example #10
Source File: FilterMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onPartyChange(PlayerChangePartyEvent event) throws EventException { if(event.newParty().isPresent()) { invalidate(event.getPlayer()); } else { // Before a player leaves, force all filters false that are not already false. // So, all dynamic player filters are effectively wrapped in "___ and online", // and listeners don't need to do any cleanup as long as they don't hold on to // players that don't match the filter. listeners.columnMap().forEach((scope, column) -> { if(scope.isInstance(event.getPlayer())) { // For each filter in this scope column.forEach((filter, filterListeners) -> { // If player joined very recently, they may not have a cached response yet final Boolean response = lastResponses.get(filter, event.getPlayer()); if(response != null && response) { filterListeners.fall.forEach(listener -> dispatch((FilterListener<? super MatchPlayer>) listener, filter, event.getPlayer(), false)); } }); } }); event.yield(); // Wait until after the event to remove them, in case they get invalidated during the event. dirtySet.remove(event.getPlayer()); lastResponses.columnKeySet().remove(event.getPlayer()); } }
Example #11
Source File: ObservableTest.java From mcspring-boot with MIT License | 5 votes |
@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 #12
Source File: SpawnMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onPartyChange(final PlayerChangePartyEvent event) throws EventException { final MatchPlayer player = event.getPlayer(); if(event.getOldParty() == null) { // Join match event.yield(); if(event.getNewParty().isParticipating()) { enterState(player, new Joining(player)); } else { enterState(player, new Observing(player, true, true)); } } else if(event.getNewParty() == null) { // Leave match leaveState(player); } else { // Party change during match withState(player, state -> { state.onEvent(event); if(hasQueuedTransitions(player)) { // If the party change caused a state transition, leave the old // state before the change, and enter the new state afterward. // The potential danger here is that the player has no spawn state // during the party change, while other events are firing. The // danger is minimized by listening at MONITOR priority. leaveState(player); event.yield(); processQueuedTransitions(player); } }); } }
Example #13
Source File: MethodHandleEventExecutor.java From Kettle with GNU General Public License v3.0 | 5 votes |
@Override public void execute(Listener listener, Event event) throws EventException { if (!eventClass.isInstance(event)) { return; } try { handle.invoke(listener, event); } catch (Throwable t) { throw new EventException(t); } }
Example #14
Source File: StaticMethodHandleEventExecutor.java From Kettle with GNU General Public License v3.0 | 5 votes |
@Override public void execute(Listener listener, Event event) throws EventException { if (!eventClass.isInstance(event)) { return; } try { handle.invoke(event); } catch (Throwable t) { throw new EventException(t); } }
Example #15
Source File: EventExecutor1.java From Kettle with GNU General Public License v3.0 | 5 votes |
@Override public void execute(Listener listener, Event event) throws EventException { try { if (!this.eventClass.isAssignableFrom(event.getClass())) { return; } this.method.invoke(listener, event); } catch (InvocationTargetException ex) { throw new EventException(ex.getCause()); } catch (Throwable t) { throw new EventException(t); } }
Example #16
Source File: BlockTransformListener.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
@Override public void enable() { // Find all the @EventWrapper methods in this class and register them at EVERY priority level. for(final Method method : Methods.annotatedMethods(getClass(), EventWrapper.class)) { final Class<? extends Event> eventClass = method.getParameterTypes()[0].asSubclass(Event.class); for(final EventPriority priority : EventPriority.values()) { Event.register(eventRegistry.bindHandler(new EventHandlerMeta<>(eventClass, priority, false), this, (listener, event) -> { // Ignore events from non-match worlds if(matchFinder.getMatch(event) == null) return; if(!BukkitEvents.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)) { eventBus.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); } })); } } }
Example #17
Source File: SuspendListener.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler void onSuspend(ServerSuspendEvent event) throws EventException { yielder.acceptThrows(event); checkState(!event.canYield(), "Suspendable didn't yield"); }
Example #18
Source File: BlockTransformListener.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
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 #19
Source File: MatchImpl.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
@Override public void execute(Listener other, Event event) throws EventException { if (((MatchEvent) event).getMatch() == MatchImpl.this) { listener.callEvent(event); } }
Example #20
Source File: EventExecutor.java From Kettle with GNU General Public License v3.0 | votes |
public void execute(Listener listener, Event event) throws EventException;