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
ConstructorsModifierConstructorDescriptionprotectedThis constructor can be used if you use a plugin.yml to define your plugin description.protectedScalaPlugin(ScalaPluginDescription pluginDescription) This constructor should be used when your class is loaded by aScalaPluginClassLoader- which is always the case in a server environment.protectedScalaPlugin(ScalaPluginDescription pluginDescription, Server server, File file) An initializing constructor. -
Method Summary
Modifier and TypeMethodDescriptionfinal ScalaPluginClassLoaderCan only be used when the ScalaPlugin is loaded by the ScalaPluginLoader.booleanChecks whether this plugin is equal to another plugin.Deprecated.This method *WILL NOT EXIST* at runtime when running your plugin on Paper.protected final PluginCommandgetCommand(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 StringGet the api-version that was declared by this plugin.final StringGet 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 EventBusGet the ScalaLoader's EventBus! This event bus allows you to callEvents, 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 ScalaReleaseGet the compatibility-release version of Scala used by this plugin.final StringGet the version of Scala this plugin.Get the server this plugin runs oninthashCode()Get the hash code of this plugin.booleanGet whether this plugin is enabled.booleanGet whether you shouldn't use this plugin's logger.booleanonCommand(CommandSender sender, Command command, String label, String[] args) voidCallback that is invoked when the plugin is disabled by theScalaPluginLoader.voidonEnable()Callback that is invoked when the plugin is enabled by theScalaPluginLoader.voidonLoad()Callback that is invoked when the plugin is loaded by theScalaPluginLoader.onTabComplete(CommandSender sender, Command command, String alias, String[] args) Get the plugin loader.voidReads the configuration from the configuration file.voidSaves the configuration to the configuration file.voidSave the default configuration file to the plugin's data folder.voidsaveResource(String resourcePath, boolean replace) Save a resource in the plugin's jar file to the plugin's data folder.voidsetNaggable(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:
classLoaderin interfaceIScalaPlugin- Returns:
- the ScalaPluginClassLoader that loaded classes from this plugin
-
getEventBus
Get the ScalaLoader's EventBus! This event bus allows you to callEvents, which will allow you to write less boilerplate.- Specified by:
getEventBusin interfaceIScalaPlugin- Returns:
- the event bus
-
getScalaVersion
Get the version of Scala this plugin.- Specified by:
getScalaVersionin interfaceIScalaPlugin- Returns:
- the version of Scala, as per the
ScalaPluginClassLoaderused for this plugin
-
getScalaRelease
Get the compatibility-release version of Scala used by this plugin.- Specified by:
getScalaReleasein 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:
getDeclaredScalaVersionin 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:
getNamein interfaceIScalaPlugin- Specified by:
getNamein interfacePlugin- Returns:
- the plugin's name
-
getDataFolder
Get the data folder for of this ScalaPlugin- Specified by:
getDataFolderin interfacePlugin- Returns:
- the data folder
-
getPrefix
Get the log prefix of this ScalaPlugin.- Specified by:
getPrefixin interfaceIScalaPlugin- Returns:
- the prefix
-
getDescription
Get the description of this ScalaPlugin.- Specified by:
getDescriptionin interfacePlugin- Returns:
- the description
-
getConfig
Get the configurations for this plugin. -
getResource
Get a resource from the ScalaPlugin's jar file.- Specified by:
getResourcein 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:
getConfigFilein interfaceIScalaPlugin- Returns:
- the configuration file
-
saveConfig
public void saveConfig()Saves the configuration to the configuration file.- Specified by:
saveConfigin interfacePlugin
-
saveDefaultConfig
public void saveDefaultConfig()Save the default configuration file to the plugin's data folder.- Specified by:
saveDefaultConfigin interfacePlugin
-
saveResource
Save a resource in the plugin's jar file to the plugin's data folder.- Specified by:
saveResourcein 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:
reloadConfigin interfacePlugin
-
getPluginLoader
Deprecated.usepluginLoader()instead.Gets the plugin loader.- Specified by:
getPluginLoaderin interfacePlugin- Returns:
- a
ScalaPluginLoader
-
pluginLoader
Get the plugin loader.- Specified by:
pluginLoaderin 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:
isNaggablein 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:
setNaggablein 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:
getDefaultWorldGeneratorin 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:
getDefaultBiomeProviderin 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:
onCommandin interfaceCommandExecutor
-
onTabComplete
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) - Specified by:
onTabCompletein 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 ofScalaPluginClassCastException- if the plugin's instance is not of type pluginClassIllegalStateException- when called from a plugin's constructor or initializer
-