001 package org.bukkit.plugin;
002
003 import org.bukkit.event.*;
004
005 /**
006 * Stores relevant information for plugin listeners
007 */
008 public class RegisteredListener {
009 private final Listener listener;
010 private final EventPriority priority;
011 private final Plugin plugin;
012 private final EventExecutor executor;
013 private final boolean ignoreCancelled;
014
015 public RegisteredListener(final Listener listener, final EventExecutor executor, final EventPriority priority, final Plugin plugin, final boolean ignoreCancelled) {
016 this.listener = listener;
017 this.priority = priority;
018 this.plugin = plugin;
019 this.executor = executor;
020 this.ignoreCancelled = ignoreCancelled;
021 }
022
023 /**
024 * Gets the listener for this registration
025 *
026 * @return Registered Listener
027 */
028 public Listener getListener() {
029 return listener;
030 }
031
032 /**
033 * Gets the plugin for this registration
034 *
035 * @return Registered Plugin
036 */
037 public Plugin getPlugin() {
038 return plugin;
039 }
040
041 /**
042 * Gets the priority for this registration
043 *
044 * @return Registered Priority
045 */
046 public EventPriority getPriority() {
047 return priority;
048 }
049
050 /**
051 * Calls the event executor
052 *
053 * @param event The event
054 * @throws EventException If an event handler throws an exception.
055 */
056 public void callEvent(final Event event) throws EventException {
057 if (event instanceof Cancellable){
058 if (((Cancellable) event).isCancelled() && isIgnoringCancelled()){
059 return;
060 }
061 }
062 executor.execute(listener, event);
063 }
064
065 /**
066 * Whether this listener accepts cancelled events
067 *
068 * @return True when ignoring cancelled events
069 */
070 public boolean isIgnoringCancelled() {
071 return ignoreCancelled;
072 }
073 }