PySpigot's Managers¶
PySpigot provides a variety of managers to more easily work with parts of the Bukkit/Spigot API as well as other plugins, databases, and more. For instructions on importing these into your script, see below. The current managers built into PySpigot include:
- The Script Manager, for loading and unloading scripts from within another script.
- The Listener Manager, for registering event listeners.
- The Command Manager, for registering and working with commands.
- The Task Manager, for registering a variety of repeating, delayed, and asynchronous tasks.
- The Config Manager, for working with configuration files.
- The Database Manager, to connect to and interact with SQL-type and Mongo databases.
- The Redis Manager, to connect to and interact with a Redis server instance.
Also included in PySpigot are two optional managers, which are available to use if the plugin they depend on is running on the server:
- The ProtocolLib Manager, to work with ProtocolLib.
- The Placeholder Manager, to work with PlaceholderAPI.
Managers must be imported into your script inn order for you to access them. The following table summarizes how to access managers, but read the sections below for more detail on how to import them:
Manager | Access Via Helper Module | Access Under PySpigot | Standalone Import |
---|---|---|---|
Script Manager | pyspigot.script_manager() |
PySpigot.script |
from dev.magicmq.pyspigot.manager.script import ScriptManager |
Listener Manager | pyspigot.listener_manager() |
PySpigot.listener |
from dev.magicmq.pyspigot.manager.listener import ListenerManager |
Command Manager | pyspigot.command_manager() |
PySpigot.command |
from dev.magicmq.pyspigot.manager.command import CommandManager |
Task Manager | pyspigot.task_manager() |
PySpigot.scheduler |
from dev.magicmq.pyspigot.manager.task import TaskManager |
Config Manager | pyspigot.config_manager() |
PySpigot.config |
from dev.magicmq.pyspigot.manager.config import ConfigManager |
Database Manager | pyspigot.database_manager() |
PySpigot.database |
from dev.nagicmq.pyspigot.manager.database import DatabaseManager |
Redis Manager | pyspigot.redis_manager() |
PySpigot.redis |
from dev.magicmq.pyspigot.manager.redis import RedisManager |
Protocol Manager | pyspigot.protocol_manager() |
PySpigot.protocol |
from dev.magicmq.pyspigot.manager.protocol import ProtocolManager |
Placeholder Manager | pyspigot.placeholder_manager() |
PySpigot.placeholder |
from dev.magicmq.pyspigot.manager.placeholder import PlaceholderManager |
Warning
The Protocol Manager and Placeholder Manager are optional managers. These managers should only be accessed if the ProtocolLib and/or PlaceholderAPI plugins are loaded and enabled.
Using PySpigot's Managers¶
To utilize these managers, they must be imported into your script. This can be done in three ways:
Import managers via the pyspigot.py
helper library¶
As of version 0.5.0, PySpigot ships with a pyspigot.py
helper module, which is automatically placed into the python-libs
folder when the plugin is initialized. This module contains several functions to allow for access to all managers.
In the above code, the PySpigot library is imported as ps
. Then, functions within the library are called to get each manager. Of course, you can also assign the needed managers to a variable for ease of use in multiple locations within your code, like so:
Import all managers at once using the PySpigot class¶
This used to be the preferred way to access managers, but is no longer the preferred method as of version 0.5.0. This method is nevertheless still functional and can be used if desired.
In the above code, PySpigot is imported as ps. Managers are called using their simplified name, script
for ScriptManager, listener
for ListenerManager, command
for CommandManager, scheduler
for TaskManager, config
for ConfigManager, and protocol
for ProtocolManager.
Import each manager individually¶
You can also import each manager class individually, directly from PySpigot's Java code.
Warning
If importing a manager individually, get()
must be used each time the manager is called!