Package org.bukkit.plugin.java
Class JavaPlugin
java.lang.Object
org.bukkit.plugin.PluginBase
org.bukkit.plugin.java.JavaPlugin
- All Implemented Interfaces:
CommandExecutor,TabCompleter,TabExecutor,Plugin
public abstract class JavaPlugin extends PluginBase
Represents a Java plugin
-
Constructor Summary
Constructors Modifier Constructor Description JavaPlugin()protectedJavaPlugin(JavaPluginLoader loader, PluginDescriptionFile description, java.io.File dataFolder, java.io.File file)protectedJavaPlugin(PluginLoader loader, Server server, PluginDescriptionFile description, java.io.File dataFolder, java.io.File file)Deprecated.This method is intended for unit testing purposes when the other constructor cannot be used. -
Method Summary
Modifier and Type Method Description protected java.lang.ClassLoadergetClassLoader()Returns the ClassLoader which holds this pluginPluginCommandgetCommand(java.lang.String name)Gets the command with the given name, specific to this plugin.FileConfigurationgetConfig()Gets aFileConfigurationfor this plugin, read through "config.yml"com.avaje.ebean.EbeanServergetDatabase()Gets theEbeanServertied to this plugin.java.util.List<java.lang.Class<?>>getDatabaseClasses()Provides a list of all classes that should be persisted in the databasejava.io.FilegetDataFolder()Returns the folder that the plugin data's files are located in.ChunkGeneratorgetDefaultWorldGenerator(java.lang.String worldName, java.lang.String id)Gets aChunkGeneratorfor use in a default world, as specified in the server configurationPluginDescriptionFilegetDescription()Returns the plugin.yaml file containing the details for this pluginprotected java.io.FilegetFile()Returns the file which contains this pluginjava.util.logging.LoggergetLogger()Returns the plugin logger associated with this server's logger.static <T extends JavaPlugin>
TgetPlugin(java.lang.Class<T> clazz)This method provides fast access to the plugin that hasprovidedthe given plugin class, which is usually the plugin that implemented it.PluginLoadergetPluginLoader()Gets the associated PluginLoader responsible for this pluginstatic JavaPlugingetProvidingPlugin(java.lang.Class<?> clazz)This method provides fast access to the plugin that has provided the given class.java.io.InputStreamgetResource(java.lang.String filename)Gets an embedded resource in this pluginServergetServer()Returns the Server instance currently running this pluginprotected java.io.ReadergetTextResource(java.lang.String file)Provides a reader for a text file located inside the jar.protected voidinitialize(PluginLoader loader, Server server, PluginDescriptionFile description, java.io.File dataFolder, java.io.File file, java.lang.ClassLoader classLoader)Deprecated.This method is legacy and will be removed - it must be replaced by the specially provided constructor(s).protected voidinstallDDL()booleanisEnabled()Returns a value indicating whether or not this plugin is currently enabledbooleanisInitialized()Deprecated.This method cannot return false, asJavaPluginis now initialized in the constructor.booleanisNaggable()Simple boolean if we can still nag to the logs about thingsbooleanonCommand(CommandSender sender, Command command, java.lang.String label, java.lang.String[] args)Executes the given command, returning its successvoidonDisable()Called when this plugin is disabledvoidonEnable()Called when this plugin is enabledvoidonLoad()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.voidreloadConfig()Discards any data inPlugin.getConfig()and reloads from disk.protected voidremoveDDL()voidsaveConfig()Saves theFileConfigurationretrievable byPlugin.getConfig().voidsaveDefaultConfig()Saves the raw contents of the default config.yml file to the location retrievable byPlugin.getConfig().voidsaveResource(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 usingPlugin.getResource(String).protected voidsetEnabled(boolean enabled)Sets the enabled state of this pluginvoidsetNaggable(boolean canNag)Set naggable statejava.lang.StringtoString()
-
Constructor Details
-
JavaPlugin
public JavaPlugin() -
JavaPlugin
@Deprecated protected JavaPlugin(PluginLoader loader, Server server, PluginDescriptionFile description, java.io.File dataFolder, java.io.File file)Deprecated.This method is intended for unit testing purposes when the other constructor cannot be used.Its existence may be temporary.
- Parameters:
loader- the plugin loaderserver- the server instancedescription- the plugin's descriptiondataFolder- the plugin's data folderfile- the location of the plugin
-
JavaPlugin
protected JavaPlugin(JavaPluginLoader loader, PluginDescriptionFile description, java.io.File dataFolder, java.io.File file)
-
-
Method Details
-
getDataFolder
public final java.io.File getDataFolder()Returns the folder that the plugin data's files are located in. The folder may not yet exist.- Returns:
- The folder.
-
getPluginLoader
Gets the associated PluginLoader responsible for this plugin- Returns:
- PluginLoader that controls this plugin
-
getServer
Returns the Server instance currently running this plugin- Returns:
- Server running this plugin
-
isEnabled
public final boolean isEnabled()Returns a value indicating whether or not this plugin is currently enabled- Returns:
- true if this plugin is enabled, otherwise false
-
getFile
protected java.io.File getFile()Returns the file which contains this plugin- Returns:
- File containing this plugin
-
getDescription
Returns the plugin.yaml file containing the details for this plugin- Returns:
- Contents of the plugin.yaml file
-
getConfig
Description copied from interface:PluginGets aFileConfigurationfor 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.
- Returns:
- Plugin configuration
-
getTextResource
protected final java.io.Reader getTextResource(java.lang.String file)Provides a reader for a text file located inside the jar. The behavior of this method adheres toPluginAwareness.Flags.UTF8, or if not defined, uses UTF8 ifFileConfiguration.UTF8_OVERRIDEis specified, or system default otherwise.- Parameters:
file- the filename of the resource to load- Returns:
- null if
getResource(String)returns null - Throws:
java.lang.IllegalArgumentException- if file is null- See Also:
ClassLoader.getResourceAsStream(String)
-
reloadConfig
public void reloadConfig()Description copied from interface:PluginDiscards any data inPlugin.getConfig()and reloads from disk. -
saveConfig
public void saveConfig()Description copied from interface:PluginSaves theFileConfigurationretrievable byPlugin.getConfig(). -
saveDefaultConfig
public void saveDefaultConfig()Description copied from interface:PluginSaves the raw contents of the default config.yml file to the location retrievable byPlugin.getConfig(). If there is no default config.yml embedded in the plugin, an empty config.yml file is saved. This should fail silently if the config.yml already exists. -
saveResource
public void saveResource(java.lang.String resourcePath, boolean replace)Description copied from interface:PluginSaves the raw contents of any resource embedded with a plugin's .jar file assuming it can be found usingPlugin.getResource(String).The resource is saved into the plugin's data folder using the same hierarchy as the .jar file (subdirectories are preserved).
- Parameters:
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.
-
getResource
public java.io.InputStream getResource(java.lang.String filename)Description copied from interface:PluginGets an embedded resource in this plugin- Parameters:
filename- Filename of the resource- Returns:
- File if found, otherwise null
-
getClassLoader
protected final java.lang.ClassLoader getClassLoader()Returns the ClassLoader which holds this plugin- Returns:
- ClassLoader holding this plugin
-
setEnabled
protected final void setEnabled(boolean enabled)Sets the enabled state of this plugin- Parameters:
enabled- true if enabled, otherwise false
-
initialize
@Deprecated protected final void initialize(PluginLoader loader, Server server, PluginDescriptionFile description, java.io.File dataFolder, java.io.File file, java.lang.ClassLoader classLoader)Deprecated.This method is legacy and will be removed - it must be replaced by the specially provided constructor(s).- Parameters:
loader- the plugin loaderserver- the server instancedescription- the plugin's descriptiondataFolder- the plugin's data folderfile- the location of the pluginclassLoader- the class loader
-
getDatabaseClasses
public java.util.List<java.lang.Class<?>> getDatabaseClasses()Provides a list of all classes that should be persisted in the database- Returns:
- List of Classes that are Ebeans
-
isInitialized
@Deprecated public final boolean isInitialized()Deprecated.This method cannot return false, asJavaPluginis now initialized in the constructor.Gets the initialization status of this plugin- Returns:
- true if this plugin is initialized, otherwise false
-
onCommand
public boolean onCommand(CommandSender sender, Command command, java.lang.String label, java.lang.String[] args)Executes the given command, returning its success- Parameters:
sender- Source of the commandcommand- Command which was executedlabel- Alias of the command which was usedargs- Passed command arguments- Returns:
- true if a valid command, otherwise false
-
onTabComplete
public 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.- Parameters:
sender- Source of the commandcommand- Command which was executedalias- The alias usedargs- The arguments passed to the command, including final partial argument to be completed and command label- Returns:
- A List of possible completions for the final argument, or null to default to the command executor
-
getCommand
Gets the command with the given name, specific to this plugin. Commands need to be registered in thePluginDescriptionFileto exist at runtime.- Parameters:
name- name or alias of the command- Returns:
- the plugin command if found, otherwise null
-
onLoad
public void onLoad()Description copied from interface:PluginCalled after a plugin is loaded but before it has been enabled.When mulitple plugins are loaded, the onLoad() for all plugins is called before any onEnable() is called.
-
onDisable
public void onDisable()Description copied from interface:PluginCalled when this plugin is disabled -
onEnable
public void onEnable()Description copied from interface:PluginCalled when this plugin is enabled -
getDefaultWorldGenerator
Description copied from interface:PluginGets aChunkGeneratorfor use in a default world, as specified in the server configuration- Parameters:
worldName- Name of the world that this will be applied toid- Unique ID, if any, that was specified to indicate which generator was requested- Returns:
- ChunkGenerator for use in the default world generation
-
isNaggable
public final boolean isNaggable()Description copied from interface:PluginSimple boolean if we can still nag to the logs about things- Returns:
- boolean whether we can nag
-
setNaggable
public final void setNaggable(boolean canNag)Description copied from interface:PluginSet naggable state- Parameters:
canNag- is this plugin still naggable?
-
getDatabase
public com.avaje.ebean.EbeanServer getDatabase()Description copied from interface:PluginGets theEbeanServertied to this plugin. This will only be available if enabled in thePluginDescriptionFile.isDatabaseEnabled()For more information on the use of Avaje Ebeans ORM, see Avaje Ebeans Documentation
For an example using Ebeans ORM, see Bukkit's Homebukkit Plugin
- Returns:
- ebean server instance or null if not enabled
-
installDDL
protected void installDDL() -
removeDDL
protected void removeDDL() -
getLogger
public final java.util.logging.Logger getLogger()Description copied from interface:PluginReturns the plugin logger associated with this server's logger. The returned logger automatically tags all log messages with the plugin's name.- Returns:
- Logger associated with this plugin
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-
getPlugin
This method provides fast access to the plugin that hasprovidedthe 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.
- Type Parameters:
T- a class that extends JavaPlugin- Parameters:
clazz- the class desired- Returns:
- the plugin that provides and implements said class
- Throws:
java.lang.IllegalArgumentException- if clazz is nulljava.lang.IllegalArgumentException- if clazz does not extendJavaPluginjava.lang.IllegalStateException- if clazz was not provided by a plugin, for example, if called withJavaPlugin.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 class
-
getProvidingPlugin
This method provides fast access to the plugin that has provided the given class.- Parameters:
clazz- a class belonging to a plugin- Returns:
- the plugin that provided the class
- Throws:
java.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 JavaPlugin
-