001 package org.bukkit.plugin;
002
003 import java.io.File;
004 import java.util.Set;
005
006 import org.bukkit.event.Event;
007 import org.bukkit.event.EventPriority;
008 import org.bukkit.event.Listener;
009 import org.bukkit.permissions.Permissible;
010 import org.bukkit.permissions.Permission;
011
012 /**
013 * Handles all plugin management from the Server
014 */
015 public interface PluginManager {
016
017 /**
018 * Registers the specified plugin loader
019 *
020 * @param loader Class name of the PluginLoader to register
021 * @throws IllegalArgumentException Thrown when the given Class is not a
022 * valid PluginLoader
023 */
024 public void registerInterface(Class<? extends PluginLoader> loader) throws IllegalArgumentException;
025
026 /**
027 * Checks if the given plugin is loaded and returns it when applicable
028 * <p>
029 * Please note that the name of the plugin is case-sensitive
030 *
031 * @param name Name of the plugin to check
032 * @return Plugin if it exists, otherwise null
033 */
034 public Plugin getPlugin(String name);
035
036 /**
037 * Gets a list of all currently loaded plugins
038 *
039 * @return Array of Plugins
040 */
041 public Plugin[] getPlugins();
042
043 /**
044 * Checks if the given plugin is enabled or not
045 * <p>
046 * Please note that the name of the plugin is case-sensitive.
047 *
048 * @param name Name of the plugin to check
049 * @return true if the plugin is enabled, otherwise false
050 */
051 public boolean isPluginEnabled(String name);
052
053 /**
054 * Checks if the given plugin is enabled or not
055 *
056 * @param plugin Plugin to check
057 * @return true if the plugin is enabled, otherwise false
058 */
059 public boolean isPluginEnabled(Plugin plugin);
060
061 /**
062 * Loads the plugin in the specified file
063 * <p>
064 * File must be valid according to the current enabled Plugin interfaces
065 *
066 * @param file File containing the plugin to load
067 * @return The Plugin loaded, or null if it was invalid
068 * @throws InvalidPluginException Thrown when the specified file is not a
069 * valid plugin
070 * @throws InvalidDescriptionException Thrown when the specified file
071 * contains an invalid description
072 * @throws UnknownDependencyException If a required dependency could not
073 * be resolved
074 */
075 public Plugin loadPlugin(File file) throws InvalidPluginException, InvalidDescriptionException, UnknownDependencyException;
076
077 /**
078 * Loads the plugins contained within the specified directory
079 *
080 * @param directory Directory to check for plugins
081 * @return A list of all plugins loaded
082 */
083 public Plugin[] loadPlugins(File directory);
084
085 /**
086 * Disables all the loaded plugins
087 */
088 public void disablePlugins();
089
090 /**
091 * Disables and removes all plugins
092 */
093 public void clearPlugins();
094
095 /**
096 * Calls an event with the given details
097 *
098 * @param event Event details
099 * @throws IllegalStateException Thrown when an asynchronous event is
100 * fired from synchronous code.
101 * <p>
102 * <i>Note: This is best-effort basis, and should not be used to test
103 * synchronized state. This is an indicator for flawed flow logic.</i>
104 */
105 public void callEvent(Event event) throws IllegalStateException;
106
107 /**
108 * Registers all the events in the given listener class
109 *
110 * @param listener Listener to register
111 * @param plugin Plugin to register
112 */
113 public void registerEvents(Listener listener, Plugin plugin);
114
115 /**
116 * Registers the specified executor to the given event class
117 *
118 * @param event Event type to register
119 * @param listener Listener to register
120 * @param priority Priority to register this event at
121 * @param executor EventExecutor to register
122 * @param plugin Plugin to register
123 */
124 public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority, EventExecutor executor, Plugin plugin);
125
126 /**
127 * Registers the specified executor to the given event class
128 *
129 * @param event Event type to register
130 * @param listener Listener to register
131 * @param priority Priority to register this event at
132 * @param executor EventExecutor to register
133 * @param plugin Plugin to register
134 * @param ignoreCancelled Whether to pass cancelled events or not
135 */
136 public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority, EventExecutor executor, Plugin plugin, boolean ignoreCancelled);
137
138 /**
139 * Enables the specified plugin
140 * <p>
141 * Attempting to enable a plugin that is already enabled will have no
142 * effect
143 *
144 * @param plugin Plugin to enable
145 */
146 public void enablePlugin(Plugin plugin);
147
148 /**
149 * Disables the specified plugin
150 * <p>
151 * Attempting to disable a plugin that is not enabled will have no effect
152 *
153 * @param plugin Plugin to disable
154 */
155 public void disablePlugin(Plugin plugin);
156
157 /**
158 * Gets a {@link Permission} from its fully qualified name
159 *
160 * @param name Name of the permission
161 * @return Permission, or null if none
162 */
163 public Permission getPermission(String name);
164
165 /**
166 * Adds a {@link Permission} to this plugin manager.
167 * <p>
168 * If a permission is already defined with the given name of the new
169 * permission, an exception will be thrown.
170 *
171 * @param perm Permission to add
172 * @throws IllegalArgumentException Thrown when a permission with the same
173 * name already exists
174 */
175 public void addPermission(Permission perm);
176
177 /**
178 * Removes a {@link Permission} registration from this plugin manager.
179 * <p>
180 * If the specified permission does not exist in this plugin manager,
181 * nothing will happen.
182 * <p>
183 * Removing a permission registration will <b>not</b> remove the
184 * permission from any {@link Permissible}s that have it.
185 *
186 * @param perm Permission to remove
187 */
188 public void removePermission(Permission perm);
189
190 /**
191 * Removes a {@link Permission} registration from this plugin manager.
192 * <p>
193 * If the specified permission does not exist in this plugin manager,
194 * nothing will happen.
195 * <p>
196 * Removing a permission registration will <b>not</b> remove the
197 * permission from any {@link Permissible}s that have it.
198 *
199 * @param name Permission to remove
200 */
201 public void removePermission(String name);
202
203 /**
204 * Gets the default permissions for the given op status
205 *
206 * @param op Which set of default permissions to get
207 * @return The default permissions
208 */
209 public Set<Permission> getDefaultPermissions(boolean op);
210
211 /**
212 * Recalculates the defaults for the given {@link Permission}.
213 * <p>
214 * This will have no effect if the specified permission is not registered
215 * here.
216 *
217 * @param perm Permission to recalculate
218 */
219 public void recalculatePermissionDefaults(Permission perm);
220
221 /**
222 * Subscribes the given Permissible for information about the requested
223 * Permission, by name.
224 * <p>
225 * If the specified Permission changes in any form, the Permissible will
226 * be asked to recalculate.
227 *
228 * @param permission Permission to subscribe to
229 * @param permissible Permissible subscribing
230 */
231 public void subscribeToPermission(String permission, Permissible permissible);
232
233 /**
234 * Unsubscribes the given Permissible for information about the requested
235 * Permission, by name.
236 *
237 * @param permission Permission to unsubscribe from
238 * @param permissible Permissible subscribing
239 */
240 public void unsubscribeFromPermission(String permission, Permissible permissible);
241
242 /**
243 * Gets a set containing all subscribed {@link Permissible}s to the given
244 * permission, by name
245 *
246 * @param permission Permission to query for
247 * @return Set containing all subscribed permissions
248 */
249 public Set<Permissible> getPermissionSubscriptions(String permission);
250
251 /**
252 * Subscribes to the given Default permissions by operator status
253 * <p>
254 * If the specified defaults change in any form, the Permissible will be
255 * asked to recalculate.
256 *
257 * @param op Default list to subscribe to
258 * @param permissible Permissible subscribing
259 */
260 public void subscribeToDefaultPerms(boolean op, Permissible permissible);
261
262 /**
263 * Unsubscribes from the given Default permissions by operator status
264 *
265 * @param op Default list to unsubscribe from
266 * @param permissible Permissible subscribing
267 */
268 public void unsubscribeFromDefaultPerms(boolean op, Permissible permissible);
269
270 /**
271 * Gets a set containing all subscribed {@link Permissible}s to the given
272 * default list, by op status
273 *
274 * @param op Default list to query for
275 * @return Set containing all subscribed permissions
276 */
277 public Set<Permissible> getDefaultPermSubscriptions(boolean op);
278
279 /**
280 * Gets a set of all registered permissions.
281 * <p>
282 * This set is a copy and will not be modified live.
283 *
284 * @return Set containing all current registered permissions
285 */
286 public Set<Permission> getPermissions();
287
288 /**
289 * Returns whether or not timing code should be used for event calls
290 *
291 * @return True if event timings are to be used
292 */
293 public boolean useTimings();
294 }