PyPlugins - Python Plugin Loader
PyPlugins - is a plugins loader for Bukkit/Spigot (PaperMC) to load plugins are written on Python 2.7 (via Jython 2.7.2).
The creation of the plugin was inspired by Macuyiko/minecraft-python, masteroftime/Python-Plugin-Loader and cyberlis/pploader.
Installation
PyPlugins (loader)
Available two versions of the loader plugin:
- with included Jython (recommended to use);
- without Jython (requires inclusion of
jython.jar
in the folderserver/lib/
)
Steps:
- Put
PyPlugins-with[out]-Jython-*.*.*.jar
(download link) in yourserver/plugins/
directory - Run server
Python plugins install
- Put the
<PluginName>.pyplugin
sources (directory or zip file) in yourserver/plugins/
directory - Run server
Create plugin on Python
The PyPlugins contains a few way to create plugin for Spigot on Python.
It's can be:
- Clear Java-like approach (just write the code as a Java plugin, but using Python);
- Using internal pyplugins-framework (recomended);
First approach examples you can see here.
The next paragrphes about internal pyplugins-framework.
Plugin sources
Your plugin can use the following paths to the plugin source code:
- A zip whos name ends in either
.pyplugin.zip
,_pyplugin.zip
or just.pyplugin
- A directory whose name ends in
.pyplugin
or_pyplugin
(actual for windows users)
Zips with the .pyplugin
extension are recommended if you release any plugins. When
you use a zip, your must specify your own metadata; it will not allow guessed
metadata.
When using a dir or a zip, your zip or dir must contain a main python file
(with names: main.py
, plugin.py
, __main__.py
or __init__.py
) and
a plugin.yml
configuration file containing metadata (see the following section).
Plugin metadata
Plugins require metadata. The absolute minimum metadata is a name version and main class. The 'main' field of plugin metadata has special behavior:
- the main is used to search for a main class before searching the default class name.
plugin.yml
is able to set all metadata fields that exist
in bukkit, and should be used for all plugins that you release. plugin.yml is
used in all java plugins (as it is the only option for java plugins). as such,
opening up java plugin jars is a good way to learn what can go in it.
Or you can read about it here http://wiki.bukkit.org/Plugin_YAML
Here isan example of plugin.yml:
name: SamplePlugin
main: SampleClass
version: 0.1-dev
commands:
samplecommand:
description: send a sample message
usage: /<command>
Summary of fields:
- "main" - name of main python file or name of main class
- "name" - name of plugin to show in /plugins list and such. used to name the config directory. for this reason it must not equal the full name of the plugin file.
- "version" - version of plugin. shown in errors, and other plugins can access it
- "website" - mainly for people reading the code
Clear Java-like approach
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.
The pyplugins-framework approach
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 (CommandsAPI)
You can inherit your own
PluginNameCommandExecutor
class fromPythonCommandExecutor
to make handlers for "executeCommand" and "onTabComplete" actions (the command must be declared inplugin.yml
). Just create methods for these actions and make thecommands
attribute of yourPluginNameCommandExecutor
class with instances ofPyCommand
class (with command and methods names). Also can be used as commands list acceptor (functional approach) and able to getPyCommand
s as first argument on initialization. -
PythonListener class (EventsAPI)
Similar to CommandsAPI, but with
PythonListener
class as parent, thelisteners
attribute (for save your handlers) of class with instances ofPyEventHandler
(requires name of method to execute, Bukkit event object and (optional) Bukkit ptiority object). Also can be used as listener list acceptor (functional approach) and able to getPyEventHandler
s as first argument on initialization.
Links
Donate
Follow Sponsor button on GitHub page.
Development
NOTE:
bStats version 2.x.x does not allow the use of the org.bukkit.plugin.Plugin
class for plugins and requires org.bukkit.plugin.java.JavaPlugin
.
PyPlugins currently uses bStats 1.8, and needs to be added from the local jar:
mvn install:install-file -Dfile=bstats-bukkit-1.8.jar -DgroupId=org.bstats -DartifactId=bstats-bukkit -Dversion=1.8 -Dpackaging=jar
Author: @dmytrohoi