public abstract class PluginBase extends Object implements Plugin
PluginDescription| Constructor and Description |
|---|
PluginBase() |
| Modifier and Type | Method and Description |
|---|---|
<T extends Plugin> |
getCommand(String name)
TODO: FINISH JAVADOC
|
Config |
getConfig()
|
File |
getDataFolder()
返回这个Nukkit插件的数据文件夹。
The data folder of this Nukkit plugin. |
PluginDescription |
getDescription()
返回描述这个Nukkit插件的
PluginDescription对象。The description this Nukkit plugin as a PluginDescription object. |
protected File |
getFile()
返回这个插件的文件
File对象。对于jar格式的插件,就是jar文件本身。Returns the File object of this plugin itself. |
String |
getFullName()
返回这个插件完整的名字。
Returns the full name of this plugin. |
org.slf4j.Logger |
getLogger()
|
String |
getName()
返回这个插件的名字。
Returns the name of this plugin. |
PluginLoader |
getPluginLoader()
|
InputStream |
getResource(String filename)
读取这个插件特定的资源文件,并返回为
InputStream对象。Reads a resource of this plugin, and returns as an InputStream object. |
Server |
getServer()
|
void |
init(PluginLoader loader,
Server server,
PluginDescription description,
File dataFolder,
File file)
初始化这个插件。
Initialize the plugin. |
boolean |
isDisabled()
返回这个Nukkit插件是否已停用。
Whether this Nukkit plugin is disabled. |
boolean |
isEnabled()
返回这个Nukkit插件是否已启用。
Whether this Nukkit plugin is enabled. |
boolean |
isInitialized()
返回这个插件是否已经初始化。
Returns if this plugin is initialized. |
boolean |
onCommand(CommandSender sender,
Command command,
String label,
String[] args)
在命令执行时会调用的方法。
Called when a command is executed. |
void |
onDisable()
在一个Nukkit插件被停用时调用的方法。
Called when a Nukkit plugin is disabled. |
void |
onEnable()
在一个Nukkit插件被启用时调用的方法。
Called when a Nukkit plugin is enabled. |
void |
onLoad()
在一个Nukkit插件被加载时调用的方法。这个方法会在
Plugin.onEnable()之前调用。Called when a Nukkit plugin is loaded, before Plugin.onEnable() . |
void |
reloadConfig()
重新读取这个Nukkit插件的默认配置文件。
Reloads the plugin config. |
void |
saveConfig()
保存这个Nukkit插件的配置文件。
Saves the plugin config. |
void |
saveDefaultConfig()
保存这个Nukkit插件的默认配置文件。
Saves the DEFAULT plugin config. |
boolean |
saveResource(String filename)
保存这个Nukkit插件的资源。
Saves the resource of this plugin. |
boolean |
saveResource(String filename,
boolean replace)
保存或替换这个Nukkit插件的资源。
Saves or replaces the resource of this plugin. |
boolean |
saveResource(String filename,
String outputName,
boolean replace) |
void |
setEnabled()
加载这个插件。
Enables this plugin. |
void |
setEnabled(boolean value)
加载或卸载这个插件。
Enables or disables this plugin. |
public void onLoad()
PluginPlugin.onEnable()之前调用。Plugin.onEnable() .
应该填写加载插件时需要作出的动作。例如:初始化数组、初始化数据库连接。
Use this to init a Nukkit plugin, such as init arrays or init database connections.
public void onEnable()
Plugin应该填写插件启用时需要作出的动作。例如:读取配置文件、读取资源、连接数据库。
Use this to open config files, open resources, connect databases.
注意到可能存在的插件管理器插件,这个方法在插件多次重启时可能被调用多次。
Notes that there may be plugin manager plugins,
this method can be called many times when a plugin is restarted many times.
public void onDisable()
Plugin应该填写插件停用时需要作出的动作。例如:关闭数据库,断开资源。
Use this to free open things and finish actions,
such as disconnecting databases and close resources.
注意到可能存在的插件管理器插件,这个方法在插件多次重启时可能被调用多次。
Notes that there may be plugin manager plugins,
this method can be called many times when a plugin is restarted many times.
public final boolean isEnabled()
Pluginpublic final void setEnabled()
如果你需要卸载这个插件,建议使用setEnabled(boolean)
If you need to disable this plugin, it's recommended to use setEnabled(boolean)
public final void setEnabled(boolean value)
插件管理器插件常常使用这个方法。
It's normally used by a plugin manager plugin to manage plugins.
value - true为加载,false为卸载。true for enable, false for disable.public final boolean isDisabled()
PluginisDisabled in interface Pluginpublic final File getDataFolder()
Plugin一般情况下,数据文件夹名字与插件名字相同,而且都放在nukkit安装目录下的plugins文件夹里。
Under normal circumstances, the data folder has the same name with the plugin,
and is placed in the 'plugins' folder inside the nukkit installation directory.
getDataFolder in interface Pluginpublic final PluginDescription getDescription()
PluginPluginDescription对象。PluginDescription object.
对于jar格式的Nukkit插件,插件的描述在plugin.yml文件内定义。
For jar-packed Nukkit plugins, the description is defined in the 'plugin.yml' file.
getDescription in interface PluginPluginDescriptionpublic final void init(PluginLoader loader, Server server, PluginDescription description, File dataFolder, File file)
这个方法会在加载(load)之前被插件加载器调用,初始化关于插件的一些事项,不能被重写。
Called by plugin loader before load, and initialize the plugin. Can't be overridden.
loader - 加载这个插件的插件加载器的PluginLoader对象。PluginLoader object.server - 运行这个插件的服务器的Server对象。Server object.description - 描述这个插件的PluginDescription对象。PluginDescription object that describes this plugin.dataFolder - 这个插件的数据的文件夹。file - 这个插件的文件File对象。对于jar格式的插件,就是jar文件本身。File object of this plugin itself. For jar-packed plugins, it is the jar file itself.public org.slf4j.Logger getLogger()
PluginPluginLogger对象。PluginLogger object.
使用日志记录器,你可以在控制台和日志文件输出信息。
You can use a plugin logger to output messages to the console and log file.
getLogger in interface PluginPluginLoggerpublic final boolean isInitialized()
public <T extends Plugin> PluginCommand<T> getCommand(String name)
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
CommandExecutor一个命令可以是/a_LABEL an_arg1 AN_ARG2...的形式,这时label变量的值为"a_label",
args数组的元素有"an_arg1","AN_ARG2",...。注意到label变量会被转化成小写,
而args数组内字符串元素的大小写不变。
A command can be such a form like /a_LABEL an_arg1 AN_ARG2.... At this time, the value of
variable label is "a_label", and the values of elements of array args are
"an_arg1","AN_ARG2",.... Notice that the value of variable label will be converted to
lower case, but the cases of elements of array args won't change.
关于返回值,如果返回false,Nukkit会给sender发送这个命令的使用方法等信息,来表示这个命令没有使用成功。
如果你的命令成功的发挥了作用,你应该返回true来表示这个命令已执行成功。
If this function returns false, Nukkit will send command usages to command sender, to explain that
the command didn't work normally. If your command works properly, a true should be returned to explain
that the command works.
如果你想测试一个命令发送者是否有权限执行这个命令,
可以使用Command.testPermissionSilent(org.cloudburstmc.server.command.CommandSender)。
If you want to test whether a command sender has the permission to execute a command,
you can use Command.testPermissionSilent(org.cloudburstmc.server.command.CommandSender).
onCommand in interface CommandExecutorsender - 这个命令的发送者,可以是玩家或控制台等。command - 要被发送的命令。label - 这个命令的标签。args - 这个命令的参数列表。public InputStream getResource(String filename)
PluginInputStream对象。InputStream object.
对于jar格式的Nukkit插件,Nukkit会在jar包内的资源文件夹(一般为resources文件夹)寻找资源文件。
For jar-packed Nukkit plugins, Nukkit will look for your resource file in the resources folder,
which is normally named 'resources' and placed in plugin jar file.
当你需要把一个文件的所有内容读取为字符串,可以使用Utils.readFile(java.io.File)函数,
来从InputStream读取所有内容为字符串。例如:
When you need to read the whole file content as a String, you can use Utils.readFile(java.io.File)
to read from a InputStream and get whole content as a String. For example:
String string = Utils.readFile(this.getResource("string.txt"));
getResource in interface Pluginfilename - 要读取的资源文件名字。InputStream对象。若错误会返回nullInputStream object, or null when an error occurred.public boolean saveResource(String filename)
Plugin对于jar格式的Nukkit插件,Nukkit会在jar包内的资源文件夹寻找资源文件,然后保存到数据文件夹。
For jar-packed Nukkit plugins, Nukkit will look for your resource file in the resources folder,
which is normally named 'resources' and placed in plugin jar file, and copy it into data folder.
这个函数通常用来在插件被加载(load)时,保存默认的资源文件。这样插件在启用(enable)时不会错误读取空的资源文件,
用户也无需从开发者处手动下载资源文件后再使用插件。
This is usually used to save the default plugin resource when the plugin is LOADED .If this is used,
it won't happen to load an empty resource when plugin is ENABLED, and plugin users are not required to get
default resources from the developer and place it manually.
如果需要替换已存在的资源文件,建议使用Plugin.saveResource(String, boolean)
If you need to REPLACE an existing resource file, it's recommended
to use Plugin.saveResource(String, boolean).
saveResource in interface Pluginfilename - 要保存的资源文件名字。Plugin.saveDefaultConfig(),
Plugin.saveResource(String, boolean)public boolean saveResource(String filename, boolean replace)
Plugin对于jar格式的Nukkit插件,Nukkit会在jar包内的资源文件夹寻找资源文件,然后保存到数据文件夹。
For jar-packed Nukkit plugins, Nukkit will look for your resource file in the resources folder,
which is normally named 'resources' and placed in plugin jar file, and copy it into data folder.
如果需要保存默认的资源文件,建议使用Plugin.saveResource(String)
If you need to SAVE DEFAULT resource file, it's recommended
to use Plugin.saveResource(String).
saveResource in interface Pluginfilename - 要保存的资源文件名字。replace - 是否替换目标文件。Plugin.saveResource(String)public boolean saveResource(String filename, String outputName, boolean replace)
saveResource in interface Pluginpublic Config getConfig()
PluginConfig对象。Config object.
一般地,插件的配置保存在数据文件夹下的config.yml文件。
Normally, the plugin config is saved in the 'config.yml' file in its data folder.
getConfig in interface PluginPlugin.getDataFolder()public void saveConfig()
PluginsaveConfig in interface PluginPlugin.getDataFolder()public void saveDefaultConfig()
Plugin执行这个函数时,Nukkit会在资源文件夹内寻找开发者配置好的默认配置文件config.yml,然后保存在数据文件夹。
如果数据文件夹已经有一个config.yml文件,Nukkit不会替换这个文件。
When this is used, Nukkit will look for the default 'config.yml' file which is configured by plugin developer
and save it to the data folder. If a config.yml file exists in the data folder, Nukkit won't replace it.
这个函数通常用来在插件被加载(load)时,保存默认的配置文件。这样插件在启用(enable)时不会错误读取空的配置文件,
用户也无需从开发者处手动下载配置文件保存后再使用插件。
This is usually used to save the default plugin config when the plugin is LOADED .If this is used,
it won't happen to load an empty config when plugin is ENABLED, and plugin users are not required to get
default config from the developer and place it manually.
saveDefaultConfig in interface PluginPlugin.getDataFolder(),
Plugin.saveResource(java.lang.String)public void reloadConfig()
Plugin执行这个函数时,Nukkit会从数据文件夹中的config.yml文件重新加载配置。
这样用户在调整插件配置后,无需重启就可以马上使用新的配置。
By using this, Nukkit will reload the config from 'config.yml' file, then it isn't necessary to restart
for plugin user who changes the config and needs to use new config at once.
reloadConfig in interface PluginPlugin.getDataFolder()public String getName()
PluginNukkit会从已经读取的插件描述中获取插件的名字。
Nukkit will read plugin name from plugin description.
getName in interface PluginPlugin.getDescription()public final String getFullName()
一个插件完整的名字由名字+" v"+版本号组成。比如:
A full name of a plugin is composed by name+" v"+version.for example:
HelloWorld v1.0.0
PluginDescription.getFullName()protected File getFile()
File对象。对于jar格式的插件,就是jar文件本身。File object of this plugin itself. For jar-packed plugins, it is the jar file itself.File对象。File object of this plugin itself.public PluginLoader getPluginLoader()
PlugingetPluginLoader in interface PluginPluginLoaderCopyright © 2020. All rights reserved.