Buscript 为服务器提供了从文本文件运行 JavaScript 的能力。除了 JavaScript 本身提供的功能外,buscript 还添加了一些全局函数,旨在让脚本的编写变得简单易懂,希望任何人都能轻松上手!
最新的开发版本始终可以在 找到
命令
目前只有一个命令
- 权限: buscript.run
- <script> 是包含你希望运行的脚本的文件名。Buscript 会在 plugins/Buscript/scripts 目录下查找该文件名。由于这表示一个文件名,因此必须包含文件扩展名。如果你的脚本文件是 myscript.txt,那么你需要输入 /run myscript.txt。
- [player] 是 可选的。此字段用于指定脚本的目标对象。通常,如果你要使用它,目标应该是当前在线的玩家。
- run 命令总是会重新加载文件,因此如果你修改了脚本,无需进行任何特殊操作。
- 如果命令未找到脚本,它将尝试为你创建该文件(尽管它是空白的且不会执行任何操作。)
脚本
脚本是包含 JavaScript 代码的文本文件。对于不熟悉编程的人来说,这听起来可能有些吓人,但幸运的是,buscript 提供了几种易于使用的方法来创建基本脚本。
你的脚本文件必须位于 Buscript 插件自动为你创建的 scripts 目录中。文件扩展名可以是任何形式(甚至没有扩展名),只要文件包含有效的 JavaScript 即可。
脚本特性
- 易于使用的全局函数,包括运行命令、广播消息、权限管理等。
- 这些全局函数中使用的所有字符串都可以访问 "%target%",它代表脚本的当前目标。示例:broadcast("Hello, %target%")
- 能够以 100% 的可靠性在稍后时间运行另一个脚本,即使服务器崩溃也能做到!
- Buscript 定义了全局变量 target,以便对脚本的目标进行更高级的操作。
- 全局变量 server 也可用,它允许直接访问 Bukkit 服务器变量,就像你在插件内部工作一样!
详细脚本特性
示例脚本
- /run broadcast-sample.txt dumptruckman
- broadcast-sample.txt:
broadcast("Hey everyone, §c%target% §fis a cool guy!")
command("op %target%")
- 这是一个简单的脚本,它会告诉服务器上的所有人目标对象(在本例中是 dumptruckman)有多酷,然后将其设为管理员。
- 它还会给名字加上颜色,想想看。
- /run perm-sample.txt dumptruckman
- perm-sample.txt:
message("%target%", "You have just been given flight in the creative world for 30 minutes!")
addPerm("creative", "%target%", "flight.permission")
runLater("remove-perm.txt", "30m", "%target%")
- remove-perm.txt:
message("%target%", "Your flight power has been removed, hope you weren't up there!")
removePerm("creative", "%target%", "flight.permission")
- 请注意 这两个脚本需要 Vault 和一个与 Vault 兼容的权限管理器,以便在玩家不在线时也能正常工作。
- 你也可以改用 command() 函数来运行你自己的权限命令,而无需使用 Vault。
- 另外注意 "flight.permission" 并不是一个真实的权限。你实际启用飞行的权限可能有所不同(甚至可能不存在!)
面向开发者
源代码:
Javadoc:
Maven 仓库:
Maven pom 信息:
<groupId>com.dumptruckman.minecraft</groupId>
<artifactId>buscript</artifactId>
<version>1.0-SNAPSHOT</version>
你可以轻松地将此作为库而非插件使用,只需将其添加到你自己的插件中即可。建议使用 Maven 进行阴影打包(shading),并可能将代码重新定位到新的命名空间。
之后,简单创建一个
从这里开始,你将找到运行自己脚本所需的所有方法,甚至添加你自己的全局方法!
如果你希望以插件的形式扩展 Buscript 的功能,主插件类 BuscriptPlugin 提供了一个便捷的 getAPI() 方法来返回其持有的 Buscript 对象。
Javadoc 可通过 Maven 仓库下载。
Buscript adds the capability for a server to run Javascript from text files. Beyond what is normally offered by Javascript, buscript adds some global functions to enable scripts to be written easily and hopefully by anyone!
The latest development builds can always be found at
Commands
Currently there's just one command
- Permission: buscript.run
- <script> is the name of the file that contains the script you wish to run. Buscript will look in plugins/Buscript/scripts for this file name. Since it indicates a file name, it needs to have the file extension as well. If your script file is myscript.txt, then you need to type /run myscript.txt.
- [player] is optional. This field is used to indicate a target for your script. In general, this should probably be someone that is online if you are going to use it.
- The run command will always reload the file so there is no need to do anything special should you modify the script.
- Should the command not locate a script, it will attempt to create the file for you (though it will be blank and do nothing.)
Scripts
Scripts are text files that contain Javascript code. This may sound scary to people unfamiliar with coding but luckily buscript provides several easy to use methods for creating basic scripts.
Your script files must be located in the scripts directory that the Buscript plugin creates for you automatically. The file extension used can be anything (even nothing) as long as the file contains valid Javascript.
Script Features
- Easy to use global functions including command running, message broadcasting, permission management and more.
- Any string used in these global functions has access to "%target%" which represents the current target of the script. Example: broadcast("Hello, %target%")
- The ability to run another script at a later time with 100% reliability, even if the server crashes!
- Buscript defines the global variable target so more advanced things can be done with the script's target.
- The global variable server is also available which gives direct access to the Bukkit server variable just as if you were working from within a plugin!
Detailed Script Features
Example Scripts
- /run broadcast-sample.txt dumptruckman
- broadcast-sample.txt:
broadcast("Hey everyone, §c%target% §fis a cool guy!")
command("op %target%")
- This is a simple script that tells everyone on the server what a cool guy the target (dumptruckman in this case) is and then ops them.
- It even colors the name, imagine that.
- /run perm-sample.txt dumptruckman
- perm-sample.txt:
message("%target%", "You have just been given flight in the creative world for 30 minutes!")
addPerm("creative", "%target%", "flight.permission")
runLater("remove-perm.txt", "30m", "%target%")
- remove-perm.txt:
message("%target%", "Your flight power has been removed, hope you weren't up there!")
removePerm("creative", "%target%", "flight.permission")
- Please note these two scripts require Vault and a Vault compatible permission manager which allows them to work even when the player is not online.
- It is possible to instead use the command() function to run your own permission commands without using Vault.
- Also note "flight.permission" is not a real permission. Your actual flight enabling permission may vary (or not even exist!)
For Developers
Source code:
Javadoc:
Maven repository:
Maven pom information:
<groupId>com.dumptruckman.minecraft</groupId>
<artifactId>buscript</artifactId>
<version>1.0-SNAPSHOT</version>
You can easily use this as a library instead of a plugin by adding it as a library to your plugin. I would recommend shading it in with maven, possibly relocating the code to a new namespace.
After that, simple create a
and from there you will find all the methods you need to run your own scripts and even add your own global methods!
If you wish to extend the functionality of Buscript as a plugin, the main plugin class BuscriptPlugin has a convenient getAPI() method to return the Buscript object it has on hand.
The javadocs are available for download via the maven repository.
评论 0
登录后参与评分
还没有评论,来抢沙发吧