Class ScalaPlugin
java.lang.Object
xyz.janboerman.scalaloader.plugin.ScalaPlugin
- All Implemented Interfaces:
CommandExecutor
,TabCompleter
,TabExecutor
,Plugin
,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 Summary
ConstructorsModifierConstructorDescriptionprotected
This constructor can be used if you use a plugin.yml to define your plugin description.protected
ScalaPlugin
(ScalaPluginDescription pluginDescription) This constructor should be used when your class is loaded by aScalaPluginClassLoader
- which is always the case in a server environment.protected
ScalaPlugin
(ScalaPluginDescription pluginDescription, Server server, File file) An initializing constructor. -
Method Summary
Modifier and TypeMethodDescriptionfinal ScalaPluginClassLoader
Can only be used when the ScalaPlugin is loaded by the ScalaPluginLoader.boolean
Checks whether this plugin is equal to another plugin.Deprecated.This method *WILL NOT EXIST* at runtime when running your plugin on Paper.protected final PluginCommand
getCommand
(String name) Get a command defined in the plugin.yml file or in theScalaPluginDescription
.Get the configurations for this plugin.Get the default configuration file used for this plugin.Get the data folder for of this ScalaPluginfinal String
Get the api-version that was declared by this plugin.final String
Get the version of Scala that this plugin depends on.getDefaultBiomeProvider
(String worldName, String id) Gets a BiomeProvider for use in a default world, as specified in the server configuration.getDefaultWorldGenerator
(String worldName, String id) Gets a ChunkGenerator for use in a default world, as specified in the server configuration.Get the description of this ScalaPlugin.final EventBus
Get the ScalaLoader's EventBus! This event bus allows you to callEvent
s, which will allow you to write less boilerplate.Gets this plugin's logger.getName()
Get the name of the plugin.protected static <P extends ScalaPlugin>
PGet the ScalaPlugin's instance given its class.Deprecated.usepluginLoader()
instead.Get the log prefix of this ScalaPlugin.getResource
(String filename) Get a resource from the ScalaPlugin's jar file.final ScalaRelease
Get the compatibility-release version of Scala used by this plugin.final String
Get the version of Scala this plugin.Get the server this plugin runs onint
hashCode()
Get the hash code of this plugin.boolean
Get whether this plugin is enabled.boolean
Get whether you shouldn't use this plugin's logger.boolean
onCommand
(CommandSender sender, Command command, String label, String[] args) void
Callback that is invoked when the plugin is disabled by theScalaPluginLoader
.void
onEnable()
Callback that is invoked when the plugin is enabled by theScalaPluginLoader
.void
onLoad()
Callback that is invoked when the plugin is loaded by theScalaPluginLoader
.onTabComplete
(CommandSender sender, Command command, String alias, String[] args) Get the plugin loader.void
Reads the configuration from the configuration file.void
Saves the configuration to the configuration file.void
Save the default configuration file to the plugin's data folder.void
saveResource
(String resourcePath, boolean replace) Save a resource in the plugin's jar file to the plugin's data folder.void
setNaggable
(boolean canNag) Set whether the plugin can be nagged.toString()
Get a string representation of this plugin.
-
Constructor Details
-
ScalaPlugin
This constructor should be used when your class is loaded by aScalaPluginClassLoader
- 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
An initializing constructor. For (unit) testing purposes only. Many fields will remain uninitialised and most methods will give unexpected results.- Parameters:
pluginDescription
- the descriptionserver
- the serverfile
- the plugin's jar file
-
-
Method Details
-
getClassLoader
Deprecated.This method *WILL NOT EXIST* at runtime when running your plugin on Paper. UseclassLoader()
instead.Can only be used when the ScalaPlugin is loaded by the ScalaPluginLoader. Otherwise usescalaPlugin.getClass().getClassLoader()
.- Returns:
- the ScalaPluginClassLoader that loaded classes from this plugin
-
classLoader
Can only be used when the ScalaPlugin is loaded by the ScalaPluginLoader. Otherwise usescalaPlugin.getClass().getClassLoader()
.- Specified by:
classLoader
in interfaceIScalaPlugin
- Returns:
- the ScalaPluginClassLoader that loaded classes from this plugin
-
getEventBus
Get the ScalaLoader's EventBus! This event bus allows you to callEvent
s, which will allow you to write less boilerplate.- Specified by:
getEventBus
in interfaceIScalaPlugin
- Returns:
- the event bus
-
getScalaVersion
Get the version of Scala this plugin.- Specified by:
getScalaVersion
in interfaceIScalaPlugin
- Returns:
- the version of Scala, as per the
ScalaPluginClassLoader
used for this plugin
-
getScalaRelease
Get the compatibility-release version of Scala used by this plugin.- Specified by:
getScalaRelease
in interfaceIScalaPlugin
- Returns:
- the compatibility release
-
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 interfaceIScalaPlugin
- Returns:
- the defined scala version
-
getDeclaredApiVersion
Get the api-version that was declared by this plugin.- Returns:
- the bukkit api version
-
getName
Get the name of the plugin.- Specified by:
getName
in interfaceIScalaPlugin
- Specified by:
getName
in interfacePlugin
- Returns:
- the plugin's name
-
getDataFolder
Get the data folder for of this ScalaPlugin- Specified by:
getDataFolder
in interfacePlugin
- Returns:
- the data folder
-
getPrefix
Get the log prefix of this ScalaPlugin.- Specified by:
getPrefix
in interfaceIScalaPlugin
- Returns:
- the prefix
-
getDescription
Get the description of this ScalaPlugin.- Specified by:
getDescription
in interfacePlugin
- Returns:
- the description
-
getConfig
Get the configurations for this plugin. -
getResource
Get a resource from the ScalaPlugin's jar file.- Specified by:
getResource
in interfacePlugin
- 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
Get the default configuration file used for this plugin.- Specified by:
getConfigFile
in interfaceIScalaPlugin
- Returns:
- the configuration file
-
saveConfig
public void saveConfig()Saves the configuration to the configuration file.- Specified by:
saveConfig
in interfacePlugin
-
saveDefaultConfig
public void saveDefaultConfig()Save the default configuration file to the plugin's data folder.- Specified by:
saveDefaultConfig
in interfacePlugin
-
saveResource
Save a resource in the plugin's jar file to the plugin's data folder.- Specified by:
saveResource
in interfacePlugin
- Parameters:
resourcePath
- the file inside the jarreplace
- 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 interfacePlugin
-
getPluginLoader
Deprecated.usepluginLoader()
instead.Gets the plugin loader.- Specified by:
getPluginLoader
in interfacePlugin
- Returns:
- a
ScalaPluginLoader
-
pluginLoader
Get the plugin loader.- Specified by:
pluginLoader
in interfaceIScalaPlugin
- Returns:
- a
ScalaPluginLoader
-
getServer
Get the server this plugin runs on -
isEnabled
public boolean isEnabled()Get whether this plugin is enabled. -
onDisable
public void onDisable()Callback that is invoked when the plugin is disabled by theScalaPluginLoader
. This method can be overridden by subclasses. -
onLoad
public void onLoad()Callback that is invoked when the plugin is loaded by theScalaPluginLoader
. This method can be overridden by subclasses. -
onEnable
public void onEnable()Callback that is invoked when the plugin is enabled by theScalaPluginLoader
. This method can be overridden by subclasses. -
isNaggable
public boolean isNaggable()Get whether you shouldn't use this plugin's logger.- Specified by:
isNaggable
in interfacePlugin
- 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 interfacePlugin
- Parameters:
canNag
- true if the plugin must be able to be nagged, otherwise false.
-
getDefaultWorldGenerator
Gets a ChunkGenerator for use in a default world, as specified in the server configuration.- Specified by:
getDefaultWorldGenerator
in interfacePlugin
- Parameters:
worldName
- the name of the world that the generator will be applied toid
- 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
Gets a BiomeProvider for use in a default world, as specified in the server configuration.- Specified by:
getDefaultBiomeProvider
in interfacePlugin
- Parameters:
worldName
- the name of the world that the biome provider will be applied toid
- 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
Gets this plugin's logger. -
getCommand
Get a command defined in the plugin.yml file or in theScalaPluginDescription
.- Parameters:
name
- the name of the command- Returns:
- the command if one with a corresponding name was found, otherwise null
-
onCommand
- Specified by:
onCommand
in interfaceCommandExecutor
-
onTabComplete
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) - Specified by:
onTabComplete
in interfaceTabCompleter
-
equals
Checks whether this plugin is equal to another plugin. In practice this only happens when this plugin is compared to itself. -
hashCode
public int hashCode()Get the hash code of this plugin. -
toString
Get a string representation of this plugin. -
getPlugin
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 ofScalaPlugin
ClassCastException
- if the plugin's instance is not of type pluginClassIllegalStateException
- when called from a plugin's constructor or initializer
-