Package be.seeseemelk.mockbukkit.plugin
Class PluginManagerMock
java.lang.Object
be.seeseemelk.mockbukkit.PermissionManagerMock
be.seeseemelk.mockbukkit.plugin.PluginManagerMock
- All Implemented Interfaces:
PermissionManager
,PluginManager
Mock implementation of a
PluginManager
.-
Constructor Summary
ConstructorsConstructorDescriptionPluginManagerMock
(@NotNull ServerMock server) Constructs a newPluginManagerMock
for the providedServerMock
. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addCommandsFrom
(@NotNull Plugin plugin) Add commands from a certain plugin to the internal list of commands.void
addPermission
(@NotNull Permission perm) void
assertEventFired
(@NotNull Class<? extends Event> eventClass) Asserts that a specific event or one of it's sub-events has been fired at least once.<T extends Event>
voidassertEventFired
(@NotNull Class<T> eventClass, @NotNull Predicate<T> predicate) Asserts that there is at least one event of a certain class for which the predicate is true.void
assertEventFired
(@NotNull Predicate<Event> predicate) Asserts that at least one event conforms to the given predicate.<T extends Event>
voidassertEventFired
(@Nullable String message, @NotNull Class<T> eventClass, @NotNull Predicate<T> predicate) Asserts that there is at least one event of a certain class for which the predicate is true.void
assertEventFired
(@Nullable String message, @NotNull Predicate<Event> predicate) Asserts that at least one event conforms to the given predicate.void
assertEventNotFired
(@NotNull Class<? extends Event> eventClass) Asserts that a specific event or one of it's sub-event has not been fired.void
assertEventNotFired
(@NotNull Class<? extends Event> eventClass, @Nullable String message) Asserts that a specific event or one of it's sub-event has not been fired.void
void
callEventAsynchronously
(@NotNull Event event) <T extends Event>
voidcallEventAsynchronously
(T event, @Nullable Consumer<T> func) void
This method clears the history ofevents
.void
@NotNull File
createTemporaryDirectory
(@NotNull String name) Tries to create a temporary directory.@NotNull File
createTemporaryPluginFile
(@NotNull String name) Tries to create a temporary plugin file.void
disablePlugin
(@NotNull Plugin plugin) void
void
enablePlugin
(@NotNull Plugin plugin) @NotNull Collection<PluginCommand>
Get a collection of all available commands.@NotNull Set<Permission>
getDefaultPermissions
(boolean op) @NotNull Set<Permissible>
getDefaultPermSubscriptions
(boolean op) @NotNull File
Creates a new unique temporary directory.getPermission
(@NotNull String name) @NotNull Set<Permission>
@NotNull Set<Permissible>
getPermissionSubscriptions
(@NotNull String permission) Plugin @NotNull []
boolean
isPluginEnabled
(@NotNull String name) boolean
isPluginEnabled
(@Nullable Plugin plugin) boolean
isTransitiveDependency
(PluginMeta pluginMeta, PluginMeta dependencyConfig) loadPlugin
(@NotNull File file) @NotNull JavaPlugin
loadPlugin
(@NotNull Class<? extends JavaPlugin> class1, @NotNull PluginDescriptionFile description, @NotNull Object @NotNull [] parameters) Load a plugin from a class.@NotNull JavaPlugin
loadPlugin
(@NotNull Class<? extends JavaPlugin> class1, Object @NotNull [] parameters) Load a plugin from a class.Plugin[]
loadPlugins
(@NotNull File directory) void
overridePermissionManager
(@NotNull Plugin plugin, @Nullable PermissionManager permissionManager) void
recalculatePermissionDefaults
(@NotNull Permission perm) void
registerEvent
(@NotNull Class<? extends Event> event, @NotNull Listener listener, @NotNull EventPriority priority, @NotNull EventExecutor executor, @NotNull Plugin plugin) void
registerEvent
(@NotNull Class<? extends Event> event, @NotNull Listener listener, @NotNull EventPriority priority, @NotNull EventExecutor executor, @NotNull Plugin plugin, boolean ignoreCancelled) void
registerEvents
(@NotNull Listener listener, @NotNull Plugin plugin) void
registerInterface
(@NotNull Class<? extends PluginLoader> loader) void
registerLoadedPlugin
(@NotNull Plugin plugin) Registers a plugin that has already been loaded.void
removePermission
(@NotNull String name) void
removePermission
(@NotNull Permission perm) void
subscribeToDefaultPerms
(boolean op, @NotNull Permissible permissible) void
subscribeToPermission
(@NotNull String permission, @NotNull Permissible permissible) void
unload()
Should be called when the plugin manager is not used anymore.void
unregisterPluginEvents
(@NotNull Plugin plugin) Unregisters all listeners for a plugin.void
unsubscribeFromDefaultPerms
(boolean op, @NotNull Permissible permissible) void
unsubscribeFromPermission
(@NotNull String permission, @NotNull Permissible permissible) boolean
Timings are used for event timings on a live server - they serve no purpose during a artificial test environ.Methods inherited from class be.seeseemelk.mockbukkit.PermissionManagerMock
addPermissions, clearPermissions
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.papermc.paper.plugin.PermissionManager
addPermissions, clearPermissions
-
Constructor Details
-
PluginManagerMock
Constructs a newPluginManagerMock
for the providedServerMock
.- Parameters:
server
- The server this is for.
-
-
Method Details
-
unload
public void unload()Should be called when the plugin manager is not used anymore. -
assertEventFired
public void assertEventFired(@Nullable @Nullable String message, @NotNull @NotNull Predicate<Event> predicate) Asserts that at least one event conforms to the given predicate.- Parameters:
message
- The message to display when no event conforms.predicate
- The predicate to test against.
-
assertEventFired
Asserts that at least one event conforms to the given predicate.- Parameters:
predicate
- The predicate to test against.
-
assertEventFired
public <T extends Event> void assertEventFired(@Nullable @Nullable String message, @NotNull @NotNull Class<T> eventClass, @NotNull @NotNull Predicate<T> predicate) Asserts that there is at least one event of a certain class for which the predicate is true.- Type Parameters:
T
- The type of event that is expected.- Parameters:
message
- The message to display if no event is found.eventClass
- The class type that the event should be an instance of.predicate
- The predicate to test the event against.
-
assertEventFired
public <T extends Event> void assertEventFired(@NotNull @NotNull Class<T> eventClass, @NotNull @NotNull Predicate<T> predicate) Asserts that there is at least one event of a certain class for which the predicate is true.- Type Parameters:
T
- The type of event that is expected.- Parameters:
eventClass
- The class type that the event should be an instance of.predicate
- The predicate to test the event against.
-
assertEventFired
Asserts that a specific event or one of it's sub-events has been fired at least once.- Parameters:
eventClass
- The class of the event to check for.
-
assertEventNotFired
Asserts that a specific event or one of it's sub-event has not been fired.- Parameters:
eventClass
- The class of the event to check for.
-
assertEventNotFired
public void assertEventNotFired(@NotNull @NotNull Class<? extends Event> eventClass, @Nullable @Nullable String message) Asserts that a specific event or one of it's sub-event has not been fired.- Parameters:
eventClass
- The class of the event to check for.message
- The message to print when failed.
-
getPlugin
- Specified by:
getPlugin
in interfacePluginManager
-
getPlugins
- Specified by:
getPlugins
in interfacePluginManager
-
getCommands
Get a collection of all available commands.- Returns:
- A collection of all available commands.
-
getParentTemporaryDirectory
Creates a new unique temporary directory.- Returns:
- The directory.
- Throws:
IOException
- If an IO error occurs.
-
createTemporaryDirectory
@NotNull public @NotNull File createTemporaryDirectory(@NotNull @NotNull String name) throws IOException Tries to create a temporary directory.- Parameters:
name
- The name of the directory to create.- Returns:
- The created temporary directory.
- Throws:
IOException
- when the directory could not be created.
-
createTemporaryPluginFile
@NotNull public @NotNull File createTemporaryPluginFile(@NotNull @NotNull String name) throws IOException Tries to create a temporary plugin file.- Parameters:
name
- The name of the plugin.- Returns:
- The created temporary file.
- Throws:
IOException
- when the file could not be created.
-
registerLoadedPlugin
Registers a plugin that has already been loaded. This is necessary to register plugins loaded from external jars.- Parameters:
plugin
- The plugin that has been loaded.
-
loadPlugin
@NotNull public @NotNull JavaPlugin loadPlugin(@NotNull @NotNull Class<? extends JavaPlugin> class1, @NotNull @NotNull PluginDescriptionFile description, @NotNull @NotNull Object @NotNull [] parameters) Load a plugin from a class. It will use the system resourceplugin.yml
as the resource file.- Parameters:
description
- ThePluginDescriptionFile
that contains information about the plugin.class1
- The plugin to load.parameters
- Extra parameters to pass on to the plugin constructor. Must not benull
.- Returns:
- The loaded plugin.
-
loadPlugin
@NotNull public @NotNull JavaPlugin loadPlugin(@NotNull @NotNull Class<? extends JavaPlugin> class1, Object @NotNull [] parameters) Load a plugin from a class. It will use the system resourceplugin.yml
as the resource file.- Parameters:
class1
- The plugin to load.parameters
- Extra parameters to pass on to the plugin constructor.- Returns:
- The loaded plugin.
-
callEvent
- Specified by:
callEvent
in interfacePluginManager
-
callEventAsynchronously
- Parameters:
event
- The asynchronousEvent
to call.
-
callEventAsynchronously
public <T extends Event> void callEventAsynchronously(@NotNull T event, @Nullable @Nullable Consumer<T> func) - Type Parameters:
T
- The event type.- Parameters:
event
- The asynchronousEvent
to call.func
- A function to invoke after the event has been called.
-
enablePlugin
- Specified by:
enablePlugin
in interfacePluginManager
-
addCommandsFrom
Add commands from a certain plugin to the internal list of commands.- Parameters:
plugin
- The plugin from which to read commands.
-
registerInterface
public void registerInterface(@NotNull @NotNull Class<? extends PluginLoader> loader) throws IllegalArgumentException - Specified by:
registerInterface
in interfacePluginManager
- Throws:
IllegalArgumentException
-
isPluginEnabled
- Specified by:
isPluginEnabled
in interfacePluginManager
-
isPluginEnabled
- Specified by:
isPluginEnabled
in interfacePluginManager
-
loadPlugin
- Specified by:
loadPlugin
in interfacePluginManager
- Throws:
UnknownDependencyException
-
loadPlugins
- Specified by:
loadPlugins
in interfacePluginManager
-
disablePlugins
public void disablePlugins()- Specified by:
disablePlugins
in interfacePluginManager
-
clearPlugins
public void clearPlugins()- Specified by:
clearPlugins
in interfacePluginManager
-
clearEvents
public void clearEvents()This method clears the history ofevents
. Doing that can be very useful if you want to assert fresh events usingassertEventFired(Class)
or similar. -
registerEvents
- Specified by:
registerEvents
in interfacePluginManager
-
unregisterPluginEvents
Unregisters all listeners for a plugin.- Parameters:
plugin
- The plugin.
-
registerEvent
public void registerEvent(@NotNull @NotNull Class<? extends Event> event, @NotNull @NotNull Listener listener, @NotNull @NotNull EventPriority priority, @NotNull @NotNull EventExecutor executor, @NotNull @NotNull Plugin plugin) - Specified by:
registerEvent
in interfacePluginManager
-
registerEvent
public void registerEvent(@NotNull @NotNull Class<? extends Event> event, @NotNull @NotNull Listener listener, @NotNull @NotNull EventPriority priority, @NotNull @NotNull EventExecutor executor, @NotNull @NotNull Plugin plugin, boolean ignoreCancelled) - Specified by:
registerEvent
in interfacePluginManager
-
disablePlugin
- Specified by:
disablePlugin
in interfacePluginManager
-
getPermission
- Specified by:
getPermission
in interfacePermissionManager
- Specified by:
getPermission
in interfacePluginManager
- Overrides:
getPermission
in classPermissionManagerMock
-
addPermission
- Specified by:
addPermission
in interfacePermissionManager
- Specified by:
addPermission
in interfacePluginManager
- Overrides:
addPermission
in classPermissionManagerMock
-
removePermission
- Specified by:
removePermission
in interfacePermissionManager
- Specified by:
removePermission
in interfacePluginManager
- Overrides:
removePermission
in classPermissionManagerMock
-
removePermission
- Specified by:
removePermission
in interfacePermissionManager
- Specified by:
removePermission
in interfacePluginManager
- Overrides:
removePermission
in classPermissionManagerMock
-
getDefaultPermissions
- Specified by:
getDefaultPermissions
in interfacePermissionManager
- Specified by:
getDefaultPermissions
in interfacePluginManager
- Overrides:
getDefaultPermissions
in classPermissionManagerMock
-
recalculatePermissionDefaults
- Specified by:
recalculatePermissionDefaults
in interfacePermissionManager
- Specified by:
recalculatePermissionDefaults
in interfacePluginManager
- Overrides:
recalculatePermissionDefaults
in classPermissionManagerMock
-
subscribeToPermission
public void subscribeToPermission(@NotNull @NotNull String permission, @NotNull @NotNull Permissible permissible) - Specified by:
subscribeToPermission
in interfacePermissionManager
- Specified by:
subscribeToPermission
in interfacePluginManager
- Overrides:
subscribeToPermission
in classPermissionManagerMock
-
unsubscribeFromPermission
public void unsubscribeFromPermission(@NotNull @NotNull String permission, @NotNull @NotNull Permissible permissible) - Specified by:
unsubscribeFromPermission
in interfacePermissionManager
- Specified by:
unsubscribeFromPermission
in interfacePluginManager
- Overrides:
unsubscribeFromPermission
in classPermissionManagerMock
-
getPermissionSubscriptions
@NotNull public @NotNull Set<Permissible> getPermissionSubscriptions(@NotNull @NotNull String permission) - Specified by:
getPermissionSubscriptions
in interfacePermissionManager
- Specified by:
getPermissionSubscriptions
in interfacePluginManager
- Overrides:
getPermissionSubscriptions
in classPermissionManagerMock
-
subscribeToDefaultPerms
- Specified by:
subscribeToDefaultPerms
in interfacePermissionManager
- Specified by:
subscribeToDefaultPerms
in interfacePluginManager
- Overrides:
subscribeToDefaultPerms
in classPermissionManagerMock
-
unsubscribeFromDefaultPerms
- Specified by:
unsubscribeFromDefaultPerms
in interfacePermissionManager
- Specified by:
unsubscribeFromDefaultPerms
in interfacePluginManager
- Overrides:
unsubscribeFromDefaultPerms
in classPermissionManagerMock
-
getDefaultPermSubscriptions
- Specified by:
getDefaultPermSubscriptions
in interfacePermissionManager
- Specified by:
getDefaultPermSubscriptions
in interfacePluginManager
- Overrides:
getDefaultPermSubscriptions
in classPermissionManagerMock
-
getPermissions
- Specified by:
getPermissions
in interfacePermissionManager
- Specified by:
getPermissions
in interfacePluginManager
- Overrides:
getPermissions
in classPermissionManagerMock
-
useTimings
public boolean useTimings()Timings are used for event timings on a live server - they serve no purpose during a artificial test environ.- Specified by:
useTimings
in interfacePluginManager
- Returns:
- boolean.false
-
isTransitiveDependency
- Specified by:
isTransitiveDependency
in interfacePluginManager
-
overridePermissionManager
public void overridePermissionManager(@NotNull @NotNull Plugin plugin, @Nullable @Nullable PermissionManager permissionManager) - Specified by:
overridePermissionManager
in interfacePluginManager
-