CommandExecutor
, TabCompleter
, TabExecutor
, Plugin
public abstract class JavaPlugin extends PluginBase
Modifier | Constructor | Description |
---|---|---|
|
JavaPlugin() |
|
protected |
JavaPlugin(JavaPluginLoader loader,
PluginDescriptionFile description,
java.io.File dataFolder,
java.io.File file) |
Modifier and Type | Method | Description |
---|---|---|
protected java.lang.ClassLoader |
getClassLoader() |
Returns the ClassLoader which holds this plugin
|
PluginCommand |
getCommand(java.lang.String name) |
Gets the command with the given name, specific to this plugin.
|
FileConfiguration |
getConfig() |
Gets a
FileConfiguration for this plugin, read through
"config.yml" |
java.io.File |
getDataFolder() |
Returns the folder that the plugin data's files are located in.
|
ChunkGenerator |
getDefaultWorldGenerator(java.lang.String worldName,
java.lang.String id) |
Gets a
ChunkGenerator for use in a default world, as specified
in the server configuration |
PluginDescriptionFile |
getDescription() |
Returns the plugin.yaml file containing the details for this plugin
|
protected java.io.File |
getFile() |
Returns the file which contains this plugin
|
java.util.logging.Logger |
getLogger() |
Returns the plugin logger associated with this server's logger.
|
static <T extends JavaPlugin> |
getPlugin(java.lang.Class<T> clazz) |
This method provides fast access to the plugin that has
provided the given plugin class, which is
usually the plugin that implemented it. |
PluginLoader |
getPluginLoader() |
Gets the associated PluginLoader responsible for this plugin
|
static JavaPlugin |
getProvidingPlugin(java.lang.Class<?> clazz) |
This method provides fast access to the plugin that has provided the
given class.
|
java.io.InputStream |
getResource(java.lang.String filename) |
Gets an embedded resource in this plugin
|
Server |
getServer() |
Returns the Server instance currently running this plugin
|
protected java.io.Reader |
getTextResource(java.lang.String file) |
Provides a reader for a text file located inside the jar.
|
boolean |
isEnabled() |
Returns a value indicating whether or not this plugin is currently
enabled
|
boolean |
isNaggable() |
Simple boolean if we can still nag to the logs about things
|
boolean |
onCommand(CommandSender sender,
Command command,
java.lang.String label,
java.lang.String[] args) |
Executes the given command, returning its success
|
void |
onDisable() |
Called when this plugin is disabled
|
void |
onEnable() |
Called when this plugin is enabled
|
void |
onLoad() |
Called after a plugin is loaded but before it has been enabled.
|
java.util.List<java.lang.String> |
onTabComplete(CommandSender sender,
Command command,
java.lang.String alias,
java.lang.String[] args) |
Requests a list of possible completions for a command argument.
|
void |
reloadConfig() |
Discards any data in
Plugin.getConfig() and reloads from disk. |
void |
saveConfig() |
Saves the
FileConfiguration retrievable by Plugin.getConfig() . |
void |
saveDefaultConfig() |
Saves the raw contents of the default config.yml file to the location
retrievable by
Plugin.getConfig() . |
void |
saveResource(java.lang.String resourcePath,
boolean replace) |
Saves the raw contents of any resource embedded with a plugin's .jar
file assuming it can be found using
Plugin.getResource(String) . |
protected void |
setEnabled(boolean enabled) |
Sets the enabled state of this plugin
|
void |
setNaggable(boolean canNag) |
Set naggable state
|
java.lang.String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
equals, getName, hashCode
public JavaPlugin()
protected JavaPlugin(JavaPluginLoader loader, PluginDescriptionFile description, java.io.File dataFolder, java.io.File file)
public final java.io.File getDataFolder()
public final PluginLoader getPluginLoader()
public final Server getServer()
public final boolean isEnabled()
protected java.io.File getFile()
public final PluginDescriptionFile getDescription()
public FileConfiguration getConfig()
Plugin
FileConfiguration
for this plugin, read through
"config.yml"
If there is a default config.yml embedded in this plugin, it will be provided as a default for this Configuration.
protected final java.io.Reader getTextResource(java.lang.String file)
The returned reader will read text with the UTF-8 charset.
file
- the filename of the resource to loadgetResource(String)
returns nulljava.lang.IllegalArgumentException
- if file is nullClassLoader.getResourceAsStream(String)
public void reloadConfig()
Plugin
Plugin.getConfig()
and reloads from disk.public void saveConfig()
Plugin
FileConfiguration
retrievable by Plugin.getConfig()
.public void saveDefaultConfig()
Plugin
Plugin.getConfig()
.
This should fail silently if the config.yml already exists.
public void saveResource(java.lang.String resourcePath, boolean replace)
Plugin
Plugin.getResource(String)
.
The resource is saved into the plugin's data folder using the same hierarchy as the .jar file (subdirectories are preserved).
resourcePath
- the embedded resource path to look for within the
plugin's .jar file. (No preceding slash).replace
- if true, the embedded resource will overwrite the
contents of an existing file.public java.io.InputStream getResource(java.lang.String filename)
Plugin
filename
- Filename of the resourceprotected final java.lang.ClassLoader getClassLoader()
protected final void setEnabled(boolean enabled)
enabled
- true if enabled, otherwise falsepublic boolean onCommand(CommandSender sender, Command command, java.lang.String label, java.lang.String[] args)
sender
- Source of the commandcommand
- Command which was executedlabel
- Alias of the command which was usedargs
- Passed command argumentspublic java.util.List<java.lang.String> onTabComplete(CommandSender sender, Command command, java.lang.String alias, java.lang.String[] args)
sender
- Source of the command. For players tab-completing a
command inside of a command block, this will be the player, not
the command block.command
- Command which was executedalias
- The alias usedargs
- The arguments passed to the command, including final
partial argument to be completed and command labelpublic PluginCommand getCommand(java.lang.String name)
PluginDescriptionFile
to exist at runtime.name
- name or alias of the commandpublic void onLoad()
Plugin
When multiple plugins are loaded, the onLoad() for all plugins is called before any onEnable() is called.
public void onDisable()
Plugin
public void onEnable()
Plugin
public ChunkGenerator getDefaultWorldGenerator(java.lang.String worldName, java.lang.String id)
Plugin
ChunkGenerator
for use in a default world, as specified
in the server configurationworldName
- Name of the world that this will be applied toid
- Unique ID, if any, that was specified to indicate which
generator was requestedpublic final boolean isNaggable()
Plugin
public final void setNaggable(boolean canNag)
Plugin
canNag
- is this plugin still naggable?public java.util.logging.Logger getLogger()
Plugin
public java.lang.String toString()
toString
in class java.lang.Object
public static <T extends JavaPlugin> T getPlugin(java.lang.Class<T> clazz)
provided
the given plugin class, which is
usually the plugin that implemented it.
An exception to this would be if plugin's jar that contained the class does not extend the class, where the intended plugin would have resided in a different jar / classloader.
T
- a class that extends JavaPluginclazz
- the class desiredjava.lang.IllegalArgumentException
- if clazz is nulljava.lang.IllegalArgumentException
- if clazz does not extend JavaPlugin
java.lang.IllegalStateException
- if clazz was not provided by a plugin,
for example, if called with
JavaPlugin.getPlugin(JavaPlugin.class)
java.lang.IllegalStateException
- if called from the static initializer for
given JavaPluginjava.lang.ClassCastException
- if plugin that provided the class does not
extend the classpublic static JavaPlugin getProvidingPlugin(java.lang.Class<?> clazz)
clazz
- a class belonging to a pluginjava.lang.IllegalArgumentException
- if the class is not provided by a
JavaPluginjava.lang.IllegalArgumentException
- if class is nulljava.lang.IllegalStateException
- if called from the static initializer for
given JavaPluginCopyright © 2018. All rights reserved.