Package net.risingworld.api
Klasse Plugin
java.lang.Object
net.risingworld.api.Plugin
Plugin
is the base class for all plugins. Extend this class to create your own plugin.-
Konstruktorübersicht
-
Methodenübersicht
Modifizierer und TypMethodeBeschreibungfinal void
"Enqueues" a task (Runnable).final void
executeDelayed
(float delay, Runnable runnable) Executes a task after a given delay.final Collection<Plugin>
Returns a collection of all plugins which are currently loaded.getDescription
(String name) Gets the description for this plugin (which is defined in the plugin.yml file).final String
Gets the current version of the game/server.final int
getID()
Gets the internal id of this plugin.int
Gets the load order for this plugin.final Database
getMySQLConnection
(String database, String ip, int port, String username, String password) Creates a new MySQL database connection.getName()
Gets the name of this plugin.getPath()
Gets the path to the plugin folder (for example: "C:/Server/plugins/MyPlugin"), without a slash at the end.final Plugin
getPluginByID
(int pluginID) Finds a plugin by id.final Plugin
getPluginByName
(String pluginName) Finds a plugin with the according name and returns the instance.final float
Gets the total running time of the game/server in seconds.final Database
getSQLiteConnection
(String database) Creates a new SQLite database connection (in thread-safe mode).final WorldDatabase
Gets an interface providing access to the world database.final boolean
Checks whether or not the currently executing thread is the main thread.abstract void
This method is called when the plugin will be disabled and unloaded.abstract void
onEnable()
This method is called when the plugin will be enabled.void
onLoad()
This method is called when the plugin will be loaded (beforeonEnable()
is called).final void
registerEventListener
(Listener listener) Registers an eventListener
.final String
sendHttpRequest
(String url) Sends a http request to the target url.final String
sendHttpRequest
(String url, HashMap<String, String> postData) Sends a http request with POST data to the target url.final void
triggerEvent
(Event event) Calls an event.final void
unregisterEventListener
(Listener listener) Unregisters an eventListener
, i.e this listener will no longer be called when an event triggers.
-
Konstruktordetails
-
Plugin
protected Plugin()
-
-
Methodendetails
-
onLoad
public void onLoad()This method is called when the plugin will be loaded (beforeonEnable()
is called). Other plugins may not be loaded at this stage. Override this method if necessary, otherwise just use theonEnable()
method for initialization purposes. -
onEnable
public abstract void onEnable()This method is called when the plugin will be enabled. At this point all other plugins are already loaded. You have to override this method when extending this class.- Example:
-
onDisable
public abstract void onDisable()This method is called when the plugin will be disabled and unloaded. You have to override this method when extending this class. -
getID
public final int getID()Gets the internal id of this plugin. Once the game / server is started, it assigns a unique id to every plugin, but this id is only valid during runtime (i.e the plugin may get a different id after restart).- Gibt zurück:
- the internal id of this plugin.
-
getName
Gets the name of this plugin.- Gibt zurück:
- the plugin name.
-
getDescription
Gets the description for this plugin (which is defined in the plugin.yml file).- Parameter:
name
- the actual property you want to get. Valid names:name, version, author, team, description, main, license, website, contact, git
- Gibt zurück:
- the property, or "N/A" when no such property was found.
-
getLoadOrder
public int getLoadOrder()Gets the load order for this plugin. The lower the value, the earlier the plugin gets loaded (when the API gets initialized). Default value is 0.- Gibt zurück:
- the load order for this plugin.
-
getPath
Gets the path to the plugin folder (for example: "C:/Server/plugins/MyPlugin"), without a slash at the end.- Gibt zurück:
- the path to the plugin folder (the subfolder of this particular plugin).
- Example: Access text file "config.txt" in plugin folder
-
getGameVersion
Gets the current version of the game/server.- Gibt zurück:
- the current version of the game/server as a String.
-
getPluginByID
Finds a plugin by id. Please bear in mind that plugin ids are not persistent and they're only valid during the session!- Parameter:
pluginID
- the id of the plugin you're looking for.- Gibt zurück:
- the plugin instance, or null if no plugin with this id was found.
-
getPluginByName
Finds a plugin with the according name and returns the instance.- Parameter:
pluginName
- the name of the plugin you're looking for (which is specified in the plugin.yml file)- Gibt zurück:
- the plugin instance, or null if no such plugin was found.
- Example: Access another plugin called "PluginB"
-
getAllPlugins
Returns a collection of all plugins which are currently loaded. This method creates a new collection, so modifying it has no effect on the plugins or the server.- Gibt zurück:
- a newly created collection containing all currently loaded plugins.
-
getWorldDatabase
Gets an interface providing access to the world database.- Parameter:
db
- the world database type / target (i.e which world database you want to access).- Gibt zurück:
- an interface which provides access to the desired world database.
-
getSQLiteConnection
Creates a new SQLite database connection (in thread-safe mode). If the provided database file does not exists, it will be created. Instead of providing a file path, you can also create a memory database (by providing null as parameter).
Note: Calling this method always creates a new connection. It's recommendable to create a connection to a database only once and reuse that database object. If you no longer need the connection, callDatabase.close()
to free the resources.- Parameter:
database
- the path to the database (to get the relative plugin path, callgetPath()
). Set to null if you want to create a temporary memory database (which only exists while the game is running).- Gibt zurück:
- a
Database
object which represents this database connection, or null if an error occurred. - Example: Create connection to "MyDatabase.db" in plugin folder and create new table if not exists
- Example: Create connection to "MyDatabase.db" in subfolder "config"
- Example: Create temporary memory database
-
getMySQLConnection
public final Database getMySQLConnection(String database, String ip, int port, String username, String password) Creates a new MySQL database connection.
Note: Calling this method always creates a new connection. It's recommendable to create a connection to a database only once and reuse that database object. If you no longer need the connection, callDatabase.close()
to free the resources.- Parameter:
database
- the database name.ip
- the ip of the MySQL server.port
- the port of the MySQL server (by default 3306).username
- the login username, e.g "root"password
- the login password.- Gibt zurück:
- a
Database
object which represents this database connection, or null if an error occurred (access denied, wrong ip etc.) - Example: Create connection to "rwdb" database on local server
-
sendHttpRequest
Sends a http request to the target url. Returns the content as a string.- Parameter:
url
- the target url- Gibt zurück:
- the content of the target page.
-
sendHttpRequest
Sends a http request with POST data to the target url. Returns the content as a string.- Parameter:
url
- the target urlpostData
- the POST data as a hash map- Gibt zurück:
- the content of the target page.
-
registerEventListener
Registers an eventListener
. The particular methods of this event will be called when an event was triggered (depending on the parameter of the method - an event method is supposed to have a singleEvent
parameter). Also make sure to use the@EventMethod
annotation for these methods.- Parameter:
listener
- the event listener you want to register.- Example: An example class for an event listener
- Example: Register the "MyListener" event listener
-
unregisterEventListener
Unregisters an eventListener
, i.e this listener will no longer be called when an event triggers.- Parameter:
listener
- the event listener you want to unregister.
-
triggerEvent
Calls an event. This is useful if you create your own custom events and want to call them through the event pipeline.- Parameter:
event
- the event you want to trigger.- Example: Create a custom event and an according listener
- Example: Trigger the "CustomEvent"
-
enqueue
"Enqueues" a task (Runnable). This runnable will be processed the next tick. All runnables that are "enqueued" will always be processed from the same thread, so this might be useful to achieve a thread-safety.- Parameter:
runnable
- the Runnable that will be processed in the next tick.- Example: Enqueue a runnable, using lambda expression
- Example: Same as example #1, but without lamda expressions, instead passing the anonymous class as parameter (old style)
-
executeDelayed
Executes a task after a given delay. Task will be executed from the main server thread (this is always the same thread), similar toenqueue(java.lang.Runnable)
.- Parameter:
delay
- the delay in seconds.runnable
- the task you want to execute delayed.- Example: Execute a task (runnable) after 5 seconds (using lambda expression)
-
isMainThread
public final boolean isMainThread()Checks whether or not the currently executing thread is the main thread.- Gibt zurück:
- true if this method was called from the main thread, false if not.
-
getRunningTime
public final float getRunningTime()Gets the total running time of the game/server in seconds. Same asServer.getRunningTime()
.- Gibt zurück:
- the total running time in seconds.
-