-
-
Notifications
You must be signed in to change notification settings - Fork 1
pyplugins framework
The same as Java-like minimum requirements:
- Main class have to be extended from PythonPlugin class. (You don't have to import it, because it is auto imported on startup of loader plugin).
- Your main class must have onEnable() and onDisable() methods.
Handlers are available to easily create your Python plugin:
-
PythonCommandExecutor class (CommandAPI)
You can inherit your own
PluginNameCommandExecutorclass fromPythonCommandExecutorto make handlers for "executeCommand" and "onTabComplete" actions (the command must be declared inplugin.yml). Just create methods for these actions and make thecommandsattribute of yourPluginNameCommandExecutorclass with instances ofPyCommandclass (with command and methods names). -
PythonListener class (EventAPI)
Similar to CommandsAPI, but with
PythonListenerclass as parent, thelistenersattribute (for save your handlers) of class with instances ofPyEventHandler(requires name of method to execute, Bukkit event object and (optional) Bukkit ptiority object). -
Add Default Configuration Commands (uses CommandAPI)
NOTE: Secured by permissions - can use only Operators or Console.
The framework provides to add basic commands for plugin configuration. Just use
self.add_configuration()inonEnable()method of your plugin main class and addconfig.ymlto your plugin. Now you can use<PluginPrefix/PluginName>-config reloadto reload your plugin configuration.You can make options from config be available to set and see (
setandparamssub-commands of<PluginPrefix/PluginName>-configcommand). It works in-game or in console. Just add attributeavailable_optionsas['x']for string option or[('x', int)]for integer option. (DONT FORGET ADD THIS OPTIONS TO DEFAULT CONFIG) -
Add bStats to your plugin
Just use
self.add_bstats(pluginId)inonEnable()method of your plugin main class.
File: /plugin.yml
name: SamplePlugin
main: SamplePluginMainClass
version: 0.1-dev
commands:
sample:
description: send a sample message
usage: /<command>
NOTE: If you want to customize Configuration Commands please add plugin prefix.
File: /config.yml
NOTE: Required for Configuration Commands API, uses as Default config.
# Header (optional)
x: 1
z: 200File: /plugin.py
# COMMAND API
class SampleCommands(PythonCommandExecutor):
commands = [
PyCommand('sample', 'sampleCommand', 'sampleOnTabComplete')
]
def sampleCommand(self, sender, command, label, args):
# Print to console
self.plugin.logger.info('aaaa')
# Print message to command sender
sender.sendMessage(command.getName())
# For `/sample test` send "TEST"
if args and args[0] == "test":
sender.sendMessage("TEST")
return True
def sampleOnTabComplete(self, sender, command, alias, args):
return ['test']
# EVENT API
from org.bukkit.event import SampleEvent
class SampleListener(PythonListener):
listeners = [
PyEventHandler('onSampleEvent', SampleEvent)
]
def onSampleEvent(self, event):
# Get spawn location
world = Bukkit.getServer().getWorlds().get(0)
world_spawn_location = world.getSpawnLocation()
# Print to console spawn point Y
self.plugin.logger.info(world_spawn_location.getBlockY())
# MAIN PLUGIN CLASS
class SamplePluginMainClass(PythonPlugin):
def onEnable(self):
# Add commands
self.apply_command_executor(SampleCommands)
# Add events
pm = self.getServer().getPluginManager()
pm.registerEvents(SampleListener(self), self)
# Add configuration
self.add_configuration(available_options=[
('x', int), ('z', int)
])
# Add bStats metrics
self.add_bstats(0000)
self.logger.info("plugin enabled!")
def onDisable(self):
self.logger.info("plugin disabled!")