public abstract class JavaPlugin extends PluginBase
限定符 | 构造器和说明 |
---|---|
|
JavaPlugin() |
protected |
JavaPlugin(JavaPluginLoader loader,
PluginDescriptionFile description,
java.io.File dataFolder,
java.io.File file) |
限定符和类型 | 方法和说明 |
---|---|
protected java.lang.ClassLoader |
getClassLoader()
返回这个插件的ClassLoader.
|
PluginCommand |
getCommand(java.lang.String name)
获取这个插件在plugin.yml里注册的命令
命令需要在
PluginDescriptionFile 里已被注册
原文:
Gets the command with the given name, specific to this plugin. |
FileConfiguration |
getConfig()
获取这个插件的
FileConfiguration 实例, 它将读取config.yml中的内容. |
java.io.File |
getDataFolder()
返回存放插件文件数据的文件夹.
|
ChunkGenerator |
getDefaultWorldGenerator(java.lang.String worldName,
java.lang.String id)
获取在服务器配置中指定的默认世界中使用的
ChunkGenerator . |
PluginDescriptionFile |
getDescription()
返回插件的plugin.yml的内容的描述信息.
|
protected java.io.File |
getFile()
返回这个插件的文件.
|
java.util.logging.Logger |
getLogger()
返回与此服务器日志记录器关联的插件日志记录器.返回的日志记录器自动地用插件的名称标记所有日志消息.
|
static <T extends JavaPlugin> |
getPlugin(java.lang.Class<T> clazz)
这个方法可以通过
provided 的类来快速访问插件对象 . |
PluginLoader |
getPluginLoader()
获取这个插件关联的PluginLoader.
|
static JavaPlugin |
getProvidingPlugin(java.lang.Class<?> clazz)
此方法给给定的类提供了快速访问.
|
java.io.InputStream |
getResource(java.lang.String filename)
获取此插件包中的资源.
|
Server |
getServer()
返回正在运行此插件的服务器对象.
|
protected java.io.Reader |
getTextResource(java.lang.String file)
提供jar中文本文件的读取器.
|
boolean |
isEnabled()
返回插件是否已正常启用.
|
boolean |
isNaggable()
使用一个简单的布尔值表达 我们是否可以把一些东西记录到日志文件.
|
boolean |
onCommand(CommandSender sender,
Command command,
java.lang.String label,
java.lang.String[] args)
执行给定的命令,成功时返回.
|
void |
onDisable()
当这个插件被关闭时调用.
|
void |
onEnable()
启用此插件时调用.
|
void |
onLoad()
在一个插件被加载之后启动之前调用.
|
java.util.List<java.lang.String> |
onTabComplete(CommandSender sender,
Command command,
java.lang.String alias,
java.lang.String[] args)
用命令传递的参数请求可能的补全项的list.
|
void |
reloadConfig()
丢弃
Plugin.getConfig() 中所有数据并且从磁盘重载. |
void |
saveConfig()
保存插件的
FileConfiguration , 这可以使用Plugin.getConfig() 获取. |
void |
saveDefaultConfig()
将默认的config.yml文件数据保存到
Plugin.getConfig() 获取的config.yml所在的位置. |
void |
saveResource(java.lang.String resourcePath,
boolean replace)
保存内置于插件的.jar文件的某个资源的原始内容(假使该资源可以使用
Plugin.getResource(String) 找到). |
protected void |
setEnabled(boolean enabled)
设置插件开启的状态.
|
void |
setNaggable(boolean canNag)
设置 Naggable 状态
原文: Set naggable state
|
java.lang.String |
toString() |
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()
原文: Returns the folder that the plugin data's files are located in. The folder may not yet exist.
public final PluginLoader getPluginLoader()
原文: Gets the associated PluginLoader responsible for this plugin
public final Server getServer()
原文: Returns the Server instance currently running this plugin
public final boolean isEnabled()
原文: Returns a value indicating whether or not this plugin is currently enabled
protected java.io.File getFile()
原文: Returns the file which contains this plugin
public final PluginDescriptionFile getDescription()
原文: Returns the plugin.yaml file containing the details for this plugin
public FileConfiguration getConfig()
Plugin
FileConfiguration
实例, 它将读取config.yml中的内容.
如果这个插件中含有config.yml文件, 那么这个config.yml将作为默认的配置文件.
原文:Gets a 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)
PluginAwareness.Flags#UTF8
提供编码, 在没有
定义的情况下, 如果指定了 FileConfiguration#UTF8_OVERRIDE
将使用UTF8编码
否则使用系统默认的编码.
原文:
Provides a reader for a text file located inside the jar. The behavior
of this method adheres to PluginAwareness.Flags#UTF8
, or if not
defined, uses UTF8 if FileConfiguration#UTF8_OVERRIDE
is
specified, or system default otherwise.
file
- 需要加载的文本资源文件名getResource(String)
返回 nulljava.lang.IllegalArgumentException
- 如果文件为空, 抛出无效的参数(IllegalArgumentException)错误ClassLoader.getResourceAsStream(String)
public void reloadConfig()
Plugin
Plugin.getConfig()
中所有数据并且从磁盘重载.
原文:Discards any data in Plugin.getConfig()
and reloads from disk.
public void saveConfig()
Plugin
FileConfiguration
, 这可以使用Plugin.getConfig()
获取.
原文: Saves the FileConfiguration
retrievable by Plugin.getConfig()
.
public void saveDefaultConfig()
Plugin
Plugin.getConfig()
获取的config.yml所在的位置.
原文:Saves the raw contents of the default config.yml file to the location
retrievable by 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)
找到).
原文:Saves the raw contents of any resource embedded with a plugin's .jar file
assuming it can be found using 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
- 在插件的.jar文件中查找的内置资源路径.(没有前面的斜杠)replace
- 如果为true,则内置的资源将覆盖现有文件的内容public java.io.InputStream getResource(java.lang.String filename)
Plugin
原文: Gets an embedded resource in this plugin
filename
- 资源文件名protected final java.lang.ClassLoader getClassLoader()
原文: Returns the ClassLoader which holds this plugin
protected final void setEnabled(boolean enabled)
原文: Sets the enabled state of this plugin
enabled
- true表示设置插件为开启, false就是设置插件为关闭public boolean onCommand(CommandSender sender, Command command, java.lang.String label, java.lang.String[] args)
原文:Executes the given command, returning its success
sender
- 命令执行的来源command
- 被执行的命令label
- 使用的命令别名args
- 传递的命令参数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.
sender
- 发起命令的来源. 至于玩家在命令方块内补全命令,这个来源就是玩家,而不是命令方块.command
- 执行的Commandalias
- 使用的别名args
- 传递给这个命令的参数,包括用来补全的部分最终参数和命令别名public PluginCommand getCommand(java.lang.String name)
PluginDescriptionFile
里已被注册
原文:
Gets the command with the given name, specific to this plugin. Commands
need to be registered in the PluginDescriptionFile
to exist at runtime.
name
- 一个属于这个插件注册了的命令public void onLoad()
Plugin
原文:Called 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.
public void onDisable()
Plugin
原文:Called when this plugin is disabled
public void onEnable()
Plugin
原文:Called when this plugin is enabled
public ChunkGenerator getDefaultWorldGenerator(java.lang.String worldName, java.lang.String id)
Plugin
ChunkGenerator
.
原文:Gets a ChunkGenerator
for use in a default world, as specified
in the server configuration
worldName
- 将应用于世界的名称id
- 唯一 ID,如果有的话,被指定来指示哪个生成器被调用public final boolean isNaggable()
Plugin
原文:Simple boolean if we can still nag to the logs about things
public final void setNaggable(boolean canNag)
Plugin
原文: Set naggable state
canNag
- 这个插件是可以被记录的吗public final java.util.logging.Logger getLogger()
Plugin
原文: Returns the plugin logger associated with this server's logger. The returned logger automatically tags all log messages with the plugin's name.
public java.lang.String toString()
toString
在类中 java.lang.Object
public static <T extends JavaPlugin> T getPlugin(java.lang.Class<T> clazz)
provided
的类来快速访问插件对象 .
这通常是创建插件对象.
例外:如果插件jar中的类不能继承类, 将可能是不同的jar/类加载器.
原文:
This method provides fast access to the plugin that has 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
- 任何一个继承了JavaPlugin的类clazz
- 类所需的类如果这个类为null,
- 抛出无效的参数(IllegalArgumentException)错误如果插件没有继承此类
- JavaPlugin
, 抛出无效的参数(IllegalArgumentException)错误java.lang.IllegalStateException
- 如果这个类不是插件提供的,抛出无效的状态(IllegalStateException)错误
for example, if called with
JavaPlugin.getPlugin(JavaPlugin.class)
java.lang.IllegalStateException
- if called from the static initializer for
given JavaPluginjava.lang.ClassCastException
- 如果插件提供的类没有继承类, 抛出(ClassCastException)错误public static JavaPlugin getProvidingPlugin(java.lang.Class<?> clazz)
原文: This method provides fast access to the plugin that has provided the given class.
clazz
- 这个类归属的插件java.lang.IllegalArgumentException
- 如果这个类不是JavaPlugin提供的,
抛出无效的参数(IllegalArgumentException)错误java.lang.IllegalArgumentException
- 如果这个类为null, 抛出无效的参数(IllegalArgumentException)错误java.lang.IllegalStateException
- 如果从给定的JavaPlugin静态初始化,抛出无效的状态(IllegalStateException)错误