本帖最后由 DefinitlyEvil 于 2015-5-17 23:19 编辑
不会Java? Java太复杂? 现在你可以用JS来写插件了!
JS插件需要符合DAPIS(小龙JS API)格式.
服务端:
小龙服务端
(支持Bukkit插件和JS插件, MC:PC和MC:PE)
本页可能不是最新版:
1. 在JS中导入小龙API
目前提供ServerAPI(管理服务器), PlayerAPI(管理玩家), WorldAPI(管理各个世界), ScriptAPI(管理JS脚本), ConfigAPI(管理配置文件).
导入一个API很简单,比如导入ServerAPI就在开头写: var myServerAPI = new ServerAPI();
2. 使用事件钩子
注意: 一个钩子就是一个普通函数(function xxx(){}).
钩子中传入的所有玩家参数均为Bukkit玩家类, 你可以像调用Bukkit一样调用玩家参数.
比如你可以写:
复制代码钩子列表(参数中#开头为数字, @开头为字符串, %开头为Java类, 各参数可以自己定义变量名称在函数中使用):
Tick() - 每个Tick都会调用一次.
useItem(#目标方块X坐标, #Y, #Z, #方块的面(总共6个,取值0-5), @方块名称, %玩家) - 当一个人使用物品时候
onConnect(%玩家) - 当一个人进入服务器
onQuit(%玩家) - 当一个人离开服务器
onKick(%玩家, @原因) - 当一个人被踢出服务器
onCommand(CommandSender sender, String cmdLabel, String alias, String[] args) - 当一个人执行了一个由整个脚本在服务器注册命令的时候执行.
onLoad(Script currentScript), onEnable(), onDisable() - 和Bukkit插件里的三个函数一样. 但是唯一的不同是onLoad()会传入一个参数, 是一个Script类, 也就是当前脚本. 你也许需要将currentScript保存起来留作注册命令等时候使用. Script继承了Bukkit的Plugin类, 所以你可以直接用这个变量调用任何Bukkit函数.
3. 各API内含方法
PlayerAPI
ScriptAPI可以让你在JS之间互相调用, 这里就用到了每个脚本的getUID()的功能了.
但是由于比较复杂,所以你可以 在这里 看ScriptAPI具体使用方法.
不会Java? Java太复杂? 现在你可以用JS来写插件了!
JS插件需要符合DAPIS(小龙JS API)格式.
服务端:
小龙服务端
(支持Bukkit插件和JS插件, MC:PC和MC:PE)
本页可能不是最新版:
function getUID(){下面开始教程:
return "ExampleScript";
}
还有更多示例脚本可以在这里找到:
https://github.com/DragonetMC/ExampleScripts
1. 在JS中导入小龙API
目前提供ServerAPI(管理服务器), PlayerAPI(管理玩家), WorldAPI(管理各个世界), ScriptAPI(管理JS脚本), ConfigAPI(管理配置文件).
导入一个API很简单,比如导入ServerAPI就在开头写: var myServerAPI = new ServerAPI();
2. 使用事件钩子
注意: 一个钩子就是一个普通函数(function xxx(){}).
钩子中传入的所有玩家参数均为Bukkit玩家类, 你可以像调用Bukkit一样调用玩家参数.
比如你可以写:
- var myServerApi = new ServerAPI();
- function onConnect(player){
- myServerApi.clientMessage("啊, 一个叫 [" + player.getName() +
- "] 的玩家进入了游戏. ");
- }
Tick() - 每个Tick都会调用一次.
useItem(#目标方块X坐标, #Y, #Z, #方块的面(总共6个,取值0-5), @方块名称, %玩家) - 当一个人使用物品时候
onConnect(%玩家) - 当一个人进入服务器
onQuit(%玩家) - 当一个人离开服务器
onKick(%玩家, @原因) - 当一个人被踢出服务器
onCommand(CommandSender sender, String cmdLabel, String alias, String[] args) - 当一个人执行了一个由整个脚本在服务器注册命令的时候执行.
onLoad(Script currentScript), onEnable(), onDisable() - 和Bukkit插件里的三个函数一样. 但是唯一的不同是onLoad()会传入一个参数, 是一个Script类, 也就是当前脚本. 你也许需要将currentScript保存起来留作注册命令等时候使用. Script继承了Bukkit的Plugin类, 所以你可以直接用这个变量调用任何Bukkit函数.
3. 各API内含方法
PlayerAPI
- kill(player) - Kills the provided player
- addItemInventory(player, materialName, Count) - Adds the specified material to the provided player's inventory
- clearInventory(player) - Clears the player's inventory
- getCurrentWorld(player) - Gets the player's current world's name
- setHealth(player, health) - Sets the player player's health to the double health
- getHealth(player) - Returns the player player's health in a double
- getX(player) - Returns the player player's X coord
- getY(player) - Returns the player player's Y coord
- getZ(player) - Returns the player player's Z coord
- setArea(worldName, x1, y1, z1, x2, y2, z2, materialName, tileData) - Sets the area inside the coords provided in the world worldName to materialName with the data of tileData
- setBlock(worldName, x, y, z, materialName, tileData) - Sets the block at the specified coords in the world worldName to materialName with the data of tileData
- dropItem(worldName, x, y, z, materialName, Count) - Drops an item of the type materialName at the specified coords
- getBlockAt(worldName, x, y, z) - Returns the block at the specified coords
- banPlayer(player, reason) - Bans the player player for the reason reason
- clientMessage(message) - Broadcasts the message message to the server
- disconnectPlayer(player, message) - Kicks the player player with the reason message
- getName() - Returns the server's name (in the server.properties file)
- runConsoleCommand(command) - Runs the specified command command (the '/' cannot be used before the command)
- stop(msg) - Kicks everyone on the server with the reason msg and stops the server
- getServer() - Returns the server
- getPlugins() - Returns an array containing all of the enabled plugins (not scripts)
- logMessage(message, type)- Logs the message message to the server's console. Can be a debug, error, trace, warn or info message.
- create(config) - Creates a new directory in the 'plugins' folder with the name config and creates a .yml file with the same name
- exists(config) - Returns true or false depending on if the specified config file config (don't use the .yml extension) exists
- readEntry(config, entry) - Returns the value of the entry entry in the config file config or, if the entry does not exist, "EMPTY_NODE"
ScriptAPI可以让你在JS之间互相调用, 这里就用到了每个脚本的getUID()的功能了.
但是由于比较复杂,所以你可以 在这里 看ScriptAPI具体使用方法.
我为毛运行部了JAVA7....
为毛我运行部了JAVA7....
请问GlowStone有生怪算法吗
iSteven 发表于 2015-5-17 22:48
请问GlowStone有生怪算法吗
目前还不支持怪物AI. GlowStone的主开发人员现在很忙没时间开发, 而我们又只涉及PC、PE平台对接所以我们也不会去弄这块儿.
学校教网页的老师特别讨厌PHP,非要JS
这个有点吊啊,PE连PC?
这个有点吊啊,PE连PC?