Class PluginManagerMock

java.lang.Object
be.seeseemelk.mockbukkit.PermissionManagerMock
be.seeseemelk.mockbukkit.plugin.PluginManagerMock
All Implemented Interfaces:
io.papermc.paper.plugin.PermissionManager, org.bukkit.plugin.PluginManager

public class PluginManagerMock extends PermissionManagerMock implements org.bukkit.plugin.PluginManager
Mock implementation of a PluginManager.
  • Constructor Details

    • PluginManagerMock

      @Internal public PluginManagerMock(@NotNull @NotNull ServerMock server)
      Constructs a new PluginManagerMock for the provided ServerMock.
      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<org.bukkit.event.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

      public void assertEventFired(@NotNull @NotNull Predicate<org.bukkit.event.Event> predicate)
      Asserts that at least one event conforms to the given predicate.
      Parameters:
      predicate - The predicate to test against.
    • assertEventFired

      public <T extends org.bukkit.event.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 org.bukkit.event.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

      public void assertEventFired(@NotNull @NotNull Class<? extends org.bukkit.event.Event> eventClass)
      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

      public void assertEventNotFired(@NotNull @NotNull Class<? extends org.bukkit.event.Event> eventClass)
      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 org.bukkit.event.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

      public org.bukkit.plugin.Plugin getPlugin(@NotNull @NotNull String name)
      Specified by:
      getPlugin in interface org.bukkit.plugin.PluginManager
    • getPlugins

      public org.bukkit.plugin.Plugin @NotNull [] getPlugins()
      Specified by:
      getPlugins in interface org.bukkit.plugin.PluginManager
    • getCommands

      @NotNull public @NotNull Collection<org.bukkit.command.PluginCommand> getCommands()
      Get a collection of all available commands.
      Returns:
      A collection of all available commands.
    • getParentTemporaryDirectory

      @NotNull public @NotNull File getParentTemporaryDirectory() throws IOException
      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

      public void registerLoadedPlugin(@NotNull @NotNull org.bukkit.plugin.Plugin plugin)
      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 org.bukkit.plugin.java.JavaPlugin loadPlugin(@NotNull @NotNull Class<? extends org.bukkit.plugin.java.JavaPlugin> class1, @NotNull @NotNull org.bukkit.plugin.PluginDescriptionFile description, @NotNull @NotNull Object @NotNull [] parameters)
      Load a plugin from a class. It will use the system resource plugin.yml as the resource file.
      Parameters:
      class1 - The plugin to load.
      description - The PluginDescriptionFile that contains information about the plugin.
      parameters - Extra parameters to pass on to the plugin constructor. Must not be null.
      Returns:
      The loaded plugin.
    • loadPlugin

      @NotNull public @NotNull org.bukkit.plugin.java.JavaPlugin loadPlugin(@NotNull @NotNull Class<? extends org.bukkit.plugin.java.JavaPlugin> class1, Object @NotNull [] parameters)
      Load a plugin from a class. It will use the system resource plugin.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

      public void callEvent(@NotNull @NotNull org.bukkit.event.Event event)
      Specified by:
      callEvent in interface org.bukkit.plugin.PluginManager
    • callEventAsynchronously

      public void callEventAsynchronously(@NotNull @NotNull org.bukkit.event.Event event)
      This method invokes callEvent(Event) from a different Thread using the BukkitSchedulerMock.
      Parameters:
      event - The asynchronous Event to call.
    • callEventAsynchronously

      public <T extends org.bukkit.event.Event> void callEventAsynchronously(@NotNull T event, @Nullable @Nullable Consumer<T> func)
      This method invokes callEvent(Event) from a different Thread using the BukkitSchedulerMock.
      Type Parameters:
      T - The event type.
      Parameters:
      event - The asynchronous Event to call.
      func - A function to invoke after the event has been called.
    • enablePlugin

      public void enablePlugin(@NotNull @NotNull org.bukkit.plugin.Plugin plugin)
      Specified by:
      enablePlugin in interface org.bukkit.plugin.PluginManager
    • addCommandsFrom

      protected void addCommandsFrom(@NotNull @NotNull org.bukkit.plugin.Plugin plugin)
      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 org.bukkit.plugin.PluginLoader> loader) throws IllegalArgumentException
      Specified by:
      registerInterface in interface org.bukkit.plugin.PluginManager
      Throws:
      IllegalArgumentException
    • isPluginEnabled

      public boolean isPluginEnabled(@NotNull @NotNull String name)
      Specified by:
      isPluginEnabled in interface org.bukkit.plugin.PluginManager
    • isPluginEnabled

      public boolean isPluginEnabled(@Nullable @Nullable org.bukkit.plugin.Plugin plugin)
      Specified by:
      isPluginEnabled in interface org.bukkit.plugin.PluginManager
    • loadPlugin

      public org.bukkit.plugin.Plugin loadPlugin(@NotNull @NotNull File file) throws org.bukkit.plugin.UnknownDependencyException
      Specified by:
      loadPlugin in interface org.bukkit.plugin.PluginManager
      Throws:
      org.bukkit.plugin.UnknownDependencyException
    • loadPlugins

      public org.bukkit.plugin.Plugin[] loadPlugins(@NotNull @NotNull File directory)
      Specified by:
      loadPlugins in interface org.bukkit.plugin.PluginManager
    • loadPlugins

      @NotNull public @NotNull org.bukkit.plugin.Plugin[] loadPlugins(@NotNull @NotNull File[] files)
      Specified by:
      loadPlugins in interface org.bukkit.plugin.PluginManager
    • disablePlugins

      public void disablePlugins()
      Specified by:
      disablePlugins in interface org.bukkit.plugin.PluginManager
    • clearPlugins

      public void clearPlugins()
      Specified by:
      clearPlugins in interface org.bukkit.plugin.PluginManager
    • clearEvents

      public void clearEvents()
      This method clears the history of events. Doing that can be very useful if you want to assert fresh events using assertEventFired(Class) or similar.
    • registerEvents

      public void registerEvents(@NotNull @NotNull org.bukkit.event.Listener listener, @NotNull @NotNull org.bukkit.plugin.Plugin plugin)
      Specified by:
      registerEvents in interface org.bukkit.plugin.PluginManager
    • unregisterPluginEvents

      public void unregisterPluginEvents(@NotNull @NotNull org.bukkit.plugin.Plugin plugin)
      Unregisters all listeners for a plugin.
      Parameters:
      plugin - The plugin.
    • registerEvent

      public void registerEvent(@NotNull @NotNull Class<? extends org.bukkit.event.Event> event, @NotNull @NotNull org.bukkit.event.Listener listener, @NotNull @NotNull org.bukkit.event.EventPriority priority, @NotNull @NotNull org.bukkit.plugin.EventExecutor executor, @NotNull @NotNull org.bukkit.plugin.Plugin plugin)
      Specified by:
      registerEvent in interface org.bukkit.plugin.PluginManager
    • registerEvent

      public void registerEvent(@NotNull @NotNull Class<? extends org.bukkit.event.Event> event, @NotNull @NotNull org.bukkit.event.Listener listener, @NotNull @NotNull org.bukkit.event.EventPriority priority, @NotNull @NotNull org.bukkit.plugin.EventExecutor executor, @NotNull @NotNull org.bukkit.plugin.Plugin plugin, boolean ignoreCancelled)
      Specified by:
      registerEvent in interface org.bukkit.plugin.PluginManager
    • disablePlugin

      public void disablePlugin(@NotNull @NotNull org.bukkit.plugin.Plugin plugin)
      Specified by:
      disablePlugin in interface org.bukkit.plugin.PluginManager
    • 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 interface org.bukkit.plugin.PluginManager
      Returns:
      boolean.false
    • isTransitiveDependency

      public boolean isTransitiveDependency(io.papermc.paper.plugin.configuration.PluginMeta pluginMeta, io.papermc.paper.plugin.configuration.PluginMeta dependencyConfig)
      Specified by:
      isTransitiveDependency in interface org.bukkit.plugin.PluginManager
    • overridePermissionManager

      public void overridePermissionManager(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @Nullable @Nullable io.papermc.paper.plugin.PermissionManager permissionManager)
      Specified by:
      overridePermissionManager in interface org.bukkit.plugin.PluginManager