Class JavaPlugin
- All Implemented Interfaces:
- LifecycleEventOwner,- CommandExecutor,- TabCompleter,- TabExecutor,- Plugin
Plugin.- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedJavaPlugin(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) Deprecated, for removal: This API element is subject to removal in a future version.
- 
Method SummaryModifier and TypeMethodDescriptionprotected final ClassLoaderReturns the ClassLoader which holds this plugingetCommand(String name) Gets the command with the given name, specific to this plugin.Gets aFileConfigurationfor this plugin, read through "config.yml"final FileReturns the folder that the plugin data files are located in.getDefaultBiomeProvider(String worldName, @Nullable String id) Gets aBiomeProviderfor use in a default world, as specified in the server configurationgetDefaultWorldGenerator(String worldName, @Nullable String id) Gets aChunkGeneratorfor use in a default world, as specified in the server configurationfinal PluginDescriptionFileDeprecated.No longer applicable to all types of pluginsprotected FilegetFile()Returns the file which contains this pluginfinal LifecycleEventManager<Plugin> Get the lifecycle event manager for registering handlers for lifecycle events allowed on thePlugin.Returns the plugin logger associated with this server's logger.static <T extends JavaPlugin>
 TThis method provides fast access to the plugin that hasprovidedthe given plugin class, which is usually the plugin that implemented it.final PluginLoaderDeprecated, for removal: This API element is subject to removal in a future version.Plugin loading now occurs at a point which makes it impossible to expose this behavior.final PluginMetaGets the plugin meta for this plugin.static JavaPlugingetProvidingPlugin(Class<?> clazz) This method provides fast access to the plugin that has provided the given class.getResource(String filename) Gets an embedded resource in this pluginfinal ServerReturns the Server instance currently running this plugingetTextResource(String file) Provides a reader for a text file located inside the jar.final voidinit(PluginLoader loader, Server server, PluginDescriptionFile description, File dataFolder, File file, ClassLoader classLoader) final voidinit(Server server, PluginDescriptionFile description, File dataFolder, File file, ClassLoader classLoader, @Nullable PluginMeta configuration, Logger logger) final booleanReturns a value indicating whether this plugin is currently enabledfinal booleanSimple boolean if we can still nag to the logs about thingsbooleanonCommand(CommandSender sender, Command command, String label, String[] args) Executes the given command, returning its success.voidCalled when this plugin is disabledvoidonEnable()Called when this plugin is enabledvoidonLoad()Called after a plugin is loaded but before it has been enabled.onTabComplete(CommandSender sender, Command command, String alias, String[] args) Requests a list of possible completions for a command argument.voidregisterCommand(String label, BasicCommand basicCommand) Registers a command for this plugin.voidregisterCommand(String label, @Nullable String description, BasicCommand basicCommand) Registers a command for this plugin.voidregisterCommand(String label, @Nullable String description, Collection<String> aliases, BasicCommand basicCommand) Registers a command for this plugin.voidregisterCommand(String label, Collection<String> aliases, BasicCommand basicCommand) Registers a command for this plugin.voidDiscards any data inPlugin.getConfig()and reloads from disk.voidSaves theFileConfigurationretrievable byPlugin.getConfig().voidSaves the raw contents of the default config.yml file to the location retrievable byPlugin.getConfig().voidsaveResource(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).final voidsetEnabled(boolean enabled) Sets the enabled state of this pluginfinal voidsetNaggable(boolean canNag) Set naggable statetoString()Methods inherited from class org.bukkit.plugin.PluginBaseequals, getName, hashCodeMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.bukkit.plugin.PlugingetComponentLogger, getDataPath, getLog4JLogger, getSLF4JLogger
- 
Constructor Details- 
JavaPluginpublic JavaPlugin()
- 
JavaPlugin@Deprecated(forRemoval=true) protected JavaPlugin(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) Deprecated, for removal: This API element is subject to removal in a future version.
 
- 
- 
Method Details- 
getDataFolderReturns the folder that the plugin data files are located in. The folder may not yet exist.- Returns:
- The folder.
 
- 
getPluginLoaderDeprecated, for removal: This API element is subject to removal in a future version.Plugin loading now occurs at a point which makes it impossible to expose this behavior. This instance will only throw unsupported operation exceptions.Gets the associated PluginLoader responsible for this plugin- Returns:
- PluginLoader that controls this plugin
 
- 
getServerReturns the Server instance currently running this plugin- Returns:
- Server running this plugin
 
- 
isEnabledpublic final boolean isEnabled()Returns a value indicating whether this plugin is currently enabled- Returns:
- true if this plugin is enabled, otherwise false
 
- 
getFileReturns the file which contains this plugin- Returns:
- File containing this plugin
 
- 
getDescriptionDeprecated.No longer applicable to all types of pluginsReturns the plugin.yml file containing the details for this plugin- Returns:
- Contents of the plugin.yml file
- See Also:
 
- 
getPluginMetaDescription copied from interface:PluginGets the plugin meta for this plugin.- Returns:
- configuration
 
- 
getConfigDescription 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
 
- 
getTextResourceProvides a reader for a text file located inside the jar.The returned reader will read text with the UTF-8 charset. - Parameters:
- file- the filename of the resource to load
- Returns:
- null if getResource(String)returns null
- Throws:
- IllegalArgumentException- if file is null
- See Also:
 
- 
reloadConfigpublic void reloadConfig()Description copied from interface:PluginDiscards any data inPlugin.getConfig()and reloads from disk.
- 
saveConfigpublic void saveConfig()Description copied from interface:PluginSaves theFileConfigurationretrievable byPlugin.getConfig().
- 
saveDefaultConfigpublic void saveDefaultConfig()Description copied from interface:PluginSaves the raw contents of the default config.yml file to the location retrievable byPlugin.getConfig().This should fail silently if the config.yml already exists. 
- 
saveResourceDescription 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.
 
- 
getResourceDescription copied from interface:PluginGets an embedded resource in this plugin- Parameters:
- filename- Filename of the resource
- Returns:
- File if found, otherwise null
 
- 
getClassLoaderReturns the ClassLoader which holds this plugin- Returns:
- ClassLoader holding this plugin
 
- 
setEnabledSets the enabled state of this plugin- Parameters:
- enabled- true if enabled, otherwise false
 
- 
initpublic final void init(PluginLoader loader, Server server, PluginDescriptionFile description, File dataFolder, File file, ClassLoader classLoader) 
- 
initpublic final void init(Server server, PluginDescriptionFile description, File dataFolder, File file, ClassLoader classLoader, @Nullable PluginMeta configuration, Logger logger) 
- 
onCommandExecutes the given command, returning its success.
 If false is returned, then the "usage" plugin.yml entry for this command (if defined) will be sent to the player.- Parameters:
- sender- Source of the command
- command- Command which was executed
- label- Alias of the command which was used
- args- Passed command arguments
- Returns:
- true if a valid command, otherwise false
 
- 
onTabCompletepublic @Nullable List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) Requests a list of possible completions for a command argument.- Parameters:
- 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 executed
- alias- Alias of the command which was used
- args- The arguments passed to the command, including final partial argument to be completed
- Returns:
- A List of possible completions for the final argument, or null to default to the command executor
 
- 
getCommandGets 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
- Throws:
- UnsupportedOperationException- if this plugin is a paper plugin and the method is called in- onEnable()
- See Also:
 
- 
registerCommandRegisters a command for this plugin. Only valid to be called insideonEnable().Commands have certain overriding behavior: - Aliases will not override already existing commands (excluding namespaced ones)
- Aliases are not Brigadier redirects, they just copy the command to a different label
- The main command/namespaced label will override already existing commands
 - Parameters:
- label- the label of the to-be-registered command
- basicCommand- the basic command instance to register
- See Also:
 
- 
registerCommand@Experimental public void registerCommand(String label, @Nullable String description, BasicCommand basicCommand) Registers a command for this plugin. Only valid to be called insideonEnable().Commands have certain overriding behavior: - Aliases will not override already existing commands (excluding namespaced ones)
- Aliases are not Brigadier redirects, they just copy the command to a different label
- The main command/namespaced label will override already existing commands
 - Parameters:
- label- the label of the to-be-registered command
- description- the help description for the root literal node
- basicCommand- the basic command instance to register
- See Also:
 
- 
registerCommand@Experimental public void registerCommand(String label, Collection<String> aliases, BasicCommand basicCommand) Registers a command for this plugin. Only valid to be called insideonEnable().Commands have certain overriding behavior: - Aliases will not override already existing commands (excluding namespaced ones)
- Aliases are not Brigadier redirects, they just copy the command to a different label
- The main command/namespaced label will override already existing commands
 - Parameters:
- label- the label of the to-be-registered command
- aliases- a collection of aliases to register the basic command under.
- basicCommand- the basic command instance to register
- See Also:
 
- 
registerCommand@Experimental public void registerCommand(String label, @Nullable String description, Collection<String> aliases, BasicCommand basicCommand) Registers a command for this plugin. Only valid to be called insideonEnable().Commands have certain overriding behavior: - Aliases will not override already existing commands (excluding namespaced ones)
- Aliases are not Brigadier redirects, they just copy the command to a different label
- The main command/namespaced label will override already existing commands
 - Parameters:
- label- the label of the to-be-registered command
- description- the help description for the root literal node
- aliases- a collection of aliases to register the basic command under.
- basicCommand- the basic command instance to register
- See Also:
 
- 
onLoadpublic void onLoad()Description copied from interface:PluginCalled after a plugin is loaded but before it has been enabled.When multiple plugins are loaded, the onLoad() for all plugins is called before any onEnable() is called. 
- 
onDisablepublic void onDisable()Description copied from interface:PluginCalled when this plugin is disabled
- 
onEnablepublic void onEnable()Description copied from interface:PluginCalled when this plugin is enabled
- 
getDefaultWorldGeneratorDescription 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 to
- id- Unique ID, if any, that was specified to indicate which generator was requested
- Returns:
- ChunkGenerator for use in the default world generation
 
- 
getDefaultBiomeProviderDescription copied from interface:PluginGets aBiomeProviderfor use in a default world, as specified in the server configuration- Parameters:
- worldName- Name of the world that this will be applied to
- id- Unique ID, if any, that was specified to indicate which biome provider was requested
- Returns:
- BiomeProvider for use in the default world generation
 
- 
isNaggablepublic 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
 
- 
setNaggablepublic final void setNaggable(boolean canNag) Description copied from interface:PluginSet naggable state- Parameters:
- canNag- is this plugin still naggable?
 
- 
getLoggerDescription 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
- 
getPluginThis 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:
- IllegalArgumentException- if clazz is null
- IllegalArgumentException- if clazz does not extend- JavaPlugin
- IllegalStateException- if clazz was not provided by a plugin, for example, if called with- JavaPlugin.getPlugin(JavaPlugin.class)
- IllegalStateException- if called from the static initializer for given JavaPlugin
- ClassCastException- if plugin that provided the class does not extend the class
 
- 
getProvidingPluginThis 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:
- IllegalArgumentException- if the class is not provided by a JavaPlugin
- IllegalArgumentException- if class is null
- IllegalStateException- if called from the static initializer for given JavaPlugin
 
- 
getLifecycleManagerDescription copied from interface:PluginGet the lifecycle event manager for registering handlers for lifecycle events allowed on thePlugin.- Returns:
- the lifecycle event manager
 
 
-