-
Notifications
You must be signed in to change notification settings - Fork 5
Plugins
TuubesCore provides a foundation for game servers, it does not implement the game components. Those are provided and extended by plugins.
We might support more languages in the future, but for now only Scala is officialy supported (theoretically it's possible to write plugins in Java or another compatible JVM language).
Creating a Scala plugin is extremely simple: all you have to do is to create a class that extends our Plugin trait.
import org.tuubes.core.engine.World
import org.tuubes.core.plugins.{Plugin, PluginDescription}
/**
* An example of plugin class.
* Note: the override modifiers aren't mandatory here, but I've let them
* to show that the methods and values come from the parent trait.
*/
class PluginExample extends Plugin {
override val description = PluginExample
override def onLoad() = {
logger.info("Plugin loaded!")
}
override def onUnload() = {
logger.info("Plugin unloaded!")
}
override def onEnable(world: World) = {
logger.info(s"Plugin enabled in world $world")
}
override def onDisable(world: World) = {
logger.info(s"Plugin disabled in world $world")
}
}
/**
* The companion object extends PluginDescription.
* The PluginDescription is needed to load the plugin.
*/
object PluginExample extends PluginDescription {
override val name = "ElectronWill's Example"
override val version = "1.0.0"
override val optionalDeps = Seq("PluginA", "PluginB") // 2 optional dependencies
override val requiredDeps = Nil // No required dependencies
}Notice how we've used the companion object to provide the description of the plugin. You have to use the companion object, otherwise Tuubes cannot initialize the description before the plugin, and the plugin won't load.
- Tuubes inspects the plugin file and finds its description and main class.
- Tuubes loads the plugin and its dependencies (if any), that is, it creates an instance of the plugin class. The plugin's state is INIT.
- Tuubes calls
onLoad(). The plugin's state is now LOADED. - Then, it enables the plugin in some worlds (possibly none), calling
onEnable(World). - The plugin happily lives in the server, reacting to events and doing stuff.
- Sometimes, the plugin is enabled in more worlds and disabled in others.
onEnable(World)andonDisable(World)are called as needed. - All good things come to an end. Tuubes disables the plugin, calling
onDisable(World)for each world where the plugin is enabled, and thenonUnload(). The plugin's state is now TERMINATED, forever. Goodbye, little plugin!
TL;DR:
- Plugin file inspection
- Plugin instance created, state = INIT
-
onLoad(), state = LOADED -
onEnable(World)with zero or more worlds - doing stuff
-
onDisable(World)for each world -
onUnload(), state = TERMINATED definitively
Tuubes, The Ultimate Universal Block Engine Server, is a free (libre) project started by TheElectronWill