Class ScalaPlugin

java.lang.Object
xyz.janboerman.scalaloader.plugin.ScalaPlugin
All Implemented Interfaces:
CommandExecutor, TabCompleter, TabExecutor, Plugin, IScalaPlugin

public abstract class ScalaPlugin extends Object implements IScalaPlugin

A ScalaPlugin!
This is what your main class (can be an object singleton) usually extends in your Scala plugin project.
Example:

 
 import xyz.janboerman.scalaloader.plugin.ScalaPlugin
 import xyz.janboerman.scalaloader.plugin.description.*

 @Scala(ScalaVersion.v3_1_1)
 object MyPlugin extends ScalaPlugin:
     override def onEnable(): Unit =
         getLogger().info("Hello, World!")
 
 
Optionally you can pass a ScalaPluginDescription to the ScalaPlugin constructor which allows you to not have to provide a plugin.yml plugin description file.

For ScalaLoader's Event api, see EventBus, Event and Cancellable.

  • Constructor Details

    • ScalaPlugin

      protected ScalaPlugin(ScalaPluginDescription pluginDescription)
      This constructor should be used when your class is loaded by a ScalaPluginClassLoader - which is always the case in a server environment.
      Parameters:
      pluginDescription - the plugin's configuration
    • ScalaPlugin

      protected ScalaPlugin()
      This constructor can be used if you use a plugin.yml to define your plugin description.
    • ScalaPlugin

      protected ScalaPlugin(ScalaPluginDescription pluginDescription, Server server, File file)
      An initializing constructor. For (unit) testing purposes only. Many fields will remain uninitialised and most methods will give unexpected results.
      Parameters:
      pluginDescription - the description
      server - the server
      file - the plugin's jar file
  • Method Details

    • getClassLoader

      @Deprecated public ScalaPluginClassLoader getClassLoader()
      Deprecated.
      This method *WILL NOT EXIST* at runtime when running your plugin on Paper. Use classLoader() instead.
      Can only be used when the ScalaPlugin is loaded by the ScalaPluginLoader. Otherwise use scalaPlugin.getClass().getClassLoader().
      Returns:
      the ScalaPluginClassLoader that loaded classes from this plugin
    • classLoader

      public final ScalaPluginClassLoader classLoader()
      Can only be used when the ScalaPlugin is loaded by the ScalaPluginLoader. Otherwise use scalaPlugin.getClass().getClassLoader().
      Specified by:
      classLoader in interface IScalaPlugin
      Returns:
      the ScalaPluginClassLoader that loaded classes from this plugin
    • getEventBus

      public final EventBus getEventBus()
      Get the ScalaLoader's EventBus! This event bus allows you to call Events, which will allow you to write less boilerplate.
      Specified by:
      getEventBus in interface IScalaPlugin
      Returns:
      the event bus
    • getScalaVersion

      public final String getScalaVersion()
      Get the version of Scala this plugin.
      Specified by:
      getScalaVersion in interface IScalaPlugin
      Returns:
      the version of Scala, as per the ScalaPluginClassLoader used for this plugin
    • getScalaRelease

      public final ScalaRelease getScalaRelease()
      Get the compatibility-release version of Scala used by this plugin.
      Specified by:
      getScalaRelease in interface IScalaPlugin
      Returns:
      the compatibility release
    • getDeclaredScalaVersion

      public final String getDeclaredScalaVersion()
      Get the version of Scala that this plugin depends on. At runtime a newer compatible version of Scala could be used instead.
      Specified by:
      getDeclaredScalaVersion in interface IScalaPlugin
      Returns:
      the defined scala version
    • getDeclaredApiVersion

      public final String getDeclaredApiVersion()
      Get the api-version that was declared by this plugin.
      Returns:
      the bukkit api version
    • getName

      public String getName()
      Get the name of the plugin.
      Specified by:
      getName in interface IScalaPlugin
      Specified by:
      getName in interface Plugin
      Returns:
      the plugin's name
    • getDataFolder

      public File getDataFolder()
      Get the data folder for of this ScalaPlugin
      Specified by:
      getDataFolder in interface Plugin
      Returns:
      the data folder
    • getPrefix

      public String getPrefix()
      Get the log prefix of this ScalaPlugin.
      Specified by:
      getPrefix in interface IScalaPlugin
      Returns:
      the prefix
    • getDescription

      public PluginDescriptionFile getDescription()
      Get the description of this ScalaPlugin.
      Specified by:
      getDescription in interface Plugin
      Returns:
      the description
    • getConfig

      public FileConfiguration getConfig()
      Get the configurations for this plugin.
      Specified by:
      getConfig in interface Plugin
      Returns:
      the configurations
    • getResource

      public InputStream getResource(String filename)
      Get a resource from the ScalaPlugin's jar file.
      Specified by:
      getResource in interface Plugin
      Parameters:
      filename - the file inside the jar file
      Returns:
      an InputStream providing the contents of the resource, or null if the resource wasn't found
    • getConfigFile

      public File getConfigFile()
      Get the default configuration file used for this plugin.
      Specified by:
      getConfigFile in interface IScalaPlugin
      Returns:
      the configuration file
    • saveConfig

      public void saveConfig()
      Saves the configuration to the configuration file.
      Specified by:
      saveConfig in interface Plugin
    • saveDefaultConfig

      public void saveDefaultConfig()
      Save the default configuration file to the plugin's data folder.
      Specified by:
      saveDefaultConfig in interface Plugin
    • saveResource

      public void saveResource(String resourcePath, boolean replace)
      Save a resource in the plugin's jar file to the plugin's data folder.
      Specified by:
      saveResource in interface Plugin
      Parameters:
      resourcePath - the file inside the jar
      replace - whether to replace the file in the data folder if one exists already
    • reloadConfig

      public void reloadConfig()
      Reads the configuration from the configuration file.
      Specified by:
      reloadConfig in interface Plugin
    • getPluginLoader

      @Deprecated public ScalaPluginLoader getPluginLoader()
      Deprecated.
      use pluginLoader() instead.
      Gets the plugin loader.
      Specified by:
      getPluginLoader in interface Plugin
      Returns:
      a ScalaPluginLoader
    • pluginLoader

      public ScalaPluginLoader pluginLoader()
      Get the plugin loader.
      Specified by:
      pluginLoader in interface IScalaPlugin
      Returns:
      a ScalaPluginLoader
    • getServer

      public Server getServer()
      Get the server this plugin runs on
      Specified by:
      getServer in interface Plugin
      Returns:
      the server
    • isEnabled

      public boolean isEnabled()
      Get whether this plugin is enabled.
      Specified by:
      isEnabled in interface Plugin
      Returns:
      true if the plugin is enabled, otherwise false
    • onDisable

      public void onDisable()
      Callback that is invoked when the plugin is disabled by the ScalaPluginLoader. This method can be overridden by subclasses.
      Specified by:
      onDisable in interface Plugin
    • onLoad

      public void onLoad()
      Callback that is invoked when the plugin is loaded by the ScalaPluginLoader. This method can be overridden by subclasses.
      Specified by:
      onLoad in interface Plugin
    • onEnable

      public void onEnable()
      Callback that is invoked when the plugin is enabled by the ScalaPluginLoader. This method can be overridden by subclasses.
      Specified by:
      onEnable in interface Plugin
    • isNaggable

      public boolean isNaggable()
      Get whether you shouldn't use this plugin's logger.
      Specified by:
      isNaggable in interface Plugin
      Returns:
      true if you can use the logger without problems, otherwise false
    • setNaggable

      public void setNaggable(boolean canNag)
      Set whether the plugin can be nagged.
      Specified by:
      setNaggable in interface Plugin
      Parameters:
      canNag - true if the plugin must be able to be nagged, otherwise false.
    • getDefaultWorldGenerator

      public ChunkGenerator getDefaultWorldGenerator(String worldName, String id)
      Gets a ChunkGenerator for use in a default world, as specified in the server configuration.
      Specified by:
      getDefaultWorldGenerator in interface Plugin
      Parameters:
      worldName - the name of the world that the generator will be applied to
      id - Unique ID, if any, that was specified to indicate which generated was requested
      Returns:
      a chunk generator if present, or null when this plugin doesn't provide a chunk generator
    • getDefaultBiomeProvider

      public BiomeProvider getDefaultBiomeProvider(String worldName, String id)
      Gets a BiomeProvider for use in a default world, as specified in the server configuration.
      Specified by:
      getDefaultBiomeProvider in interface Plugin
      Parameters:
      worldName - the name of the world that the biome provider will be applied to
      id - Unique ID, if any, that was specified to indicate which biome provider was requested
      Returns:
      a biome provider if present, or null when this plugin doesn't provide a biome provider
    • getLogger

      public Logger getLogger()
      Gets this plugin's logger.
      Specified by:
      getLogger in interface Plugin
      Returns:
      the logger
    • getCommand

      protected final PluginCommand getCommand(String name)
      Get a command defined in the plugin.yml file or in the ScalaPluginDescription.
      Parameters:
      name - the name of the command
      Returns:
      the command if one with a corresponding name was found, otherwise null
    • onCommand

      public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
      Specified by:
      onCommand in interface CommandExecutor
    • onTabComplete

      public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args)
      Specified by:
      onTabComplete in interface TabCompleter
    • equals

      public boolean equals(Object other)
      Checks whether this plugin is equal to another plugin. In practice this only happens when this plugin is compared to itself.
      Overrides:
      equals in class Object
      Parameters:
      other - the other plugin
      Returns:
      true if the plugins are equal, otherwise false
    • hashCode

      public int hashCode()
      Get the hash code of this plugin.
      Overrides:
      hashCode in class Object
      Returns:
      the hash code
    • toString

      public String toString()
      Get a string representation of this plugin.
      Overrides:
      toString in class Object
      Returns:
      the string representation.
    • getPlugin

      protected static <P extends ScalaPlugin> P getPlugin(Class<P> pluginClass)
      Get the ScalaPlugin's instance given its class.
      Type Parameters:
      P - the type of the plugin
      Parameters:
      pluginClass - the class of the ScalaPlugin
      Returns:
      the ScalaPlugin
      Throws:
      IllegalArgumentException - if the class is not a subtype of ScalaPlugin
      ClassCastException - if the plugin's instance is not of type pluginClass
      IllegalStateException - when called from a plugin's constructor or initializer