From fb65f9565861345c85cc83c0ee2debf76e9b6d15 Mon Sep 17 00:00:00 2001 From: coding Date: Tue, 9 Jan 2018 12:22:24 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=A1=88=E4=BE=8B?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=20=E6=9B=B4=E6=96=B0=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 ++ pom.xml | 10 ++- src/main/resources/plugins/HelloWorld.js | 2 +- src/main/resources/plugins/ItemTag.js | 79 ++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 src/main/resources/plugins/ItemTag.js diff --git a/README.md b/README.md index 4204168..52689d7 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,12 @@ - [项目代码](https://git.yumc.pw/502647092/MiaoScript) - [项目脑图](http://naotu.baidu.com/file/293b9a0fc7cef23c69de81c55e3617d5?token=1eee8fd759198eb7) +### 规划 + +- 初期只会支持JS类型的插件开发 +- 二期会出一个建议版本的MS脚本 可以用简单的语法实现简单的功能 +- 各个层级会有依赖控制 比如 `MS脚本 => JS脚本 => 调用Java原生API` + ### 填坑 - 实际上说了那么多 最终希望的就是 有大佬能一起来填坑 毕竟这个坑太大了 diff --git a/pom.xml b/pom.xml index 4728383..59965c9 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 pw.yumc MiaoScript - 1.2.0 + 1.2.1 502647092 @@ -84,12 +84,16 @@ DEV + §618-01-09 §afeat: 优化加载流程 完善事件注册 + §618-01-02 §afeat: 新增http网络访问模块 + §617-12-28 §afeat: 完善Sponge事件注册 新增player封装类 + + §617-11-30 §afeat: 新增Sponge的兼容; §617-11-03 §afeat: 新增抽奖插件; §617-10-16 §cfix: 修复关闭MiaoScript时task异常; §617-10-15 §6alpha: 第一个版本发布; - - + UTF-8 1.8 1.8 diff --git a/src/main/resources/plugins/HelloWorld.js b/src/main/resources/plugins/HelloWorld.js index 198b5fd..75d5e2d 100644 --- a/src/main/resources/plugins/HelloWorld.js +++ b/src/main/resources/plugins/HelloWorld.js @@ -27,7 +27,7 @@ function load() { function enable() { command.on(this, 'hello', { cmd: function (sender, command, args) { - global.load(fs.file(root, 'test.js')); + engineLoad(fs.file(root, 'test.js')); return true; } }); diff --git a/src/main/resources/plugins/ItemTag.js b/src/main/resources/plugins/ItemTag.js new file mode 100644 index 0000000..4275ff1 --- /dev/null +++ b/src/main/resources/plugins/ItemTag.js @@ -0,0 +1,79 @@ +'use strict'; +/*global Java, base, module, exports, require*/ + +var event = require('api/event'); +var wrapper = require('api/wrapper'); +var command = require('api/command'); +var server = require('api/server'); +var http = require('http'); +var fs = require('fs'); + +var nameMap = []; + +var description = { + name: 'ItemTag', + version: '1.0', + author: '喵♂呜' +}; + +var itemConfig; + +function load() { + var itemFile = self.file('item.yml'); + if (!itemFile.exists()) { + base.save(itemFile, http.get('https://data.yumc.pw/config/Item_zh_CN.yml')); + } + itemConfig = self.getConfig('item.yml'); +} + +function enable() { + switch (DetectServerType) { + case ServerType.Bukkit: + event.on(self, 'ItemMergeEvent', function (event) { + bukkit(event.target, event.entity.itemStack.amount + event.target.itemStack.amount); + }) + event.on(self, 'ItemSpawnEvent', function (event) { + if (event.entity.itemStack) { + bukkit(event.entity, event.entity.itemStack.amount); + } + }) + break; + case ServerType.Sponge: + event.on(self, 'itemmergeitemevent', function (event) { + // Sponge 暂未实现当前事件 + }) + event.on(self, 'spawnentityevent', function (event) { + event.entities.forEach(function (entity) { + if (entity.type.name === "item") sponge(entity); + }) + }) + break; + } +} + +function getItemName(name) { + return itemConfig[(name + '').toUpperCase()] || name; +} + +function bukkit(item , amount) { + var amounts = amount == 1 ? "" : "*" + amount; + item.setCustomName('§b' + getItemName(item.itemStack.type) + amounts); + item.setCustomNameVisible(true); +} + +function sponge(entity) { + var itemOptional = entity.get(Keys.REPRESENTED_ITEM); + if (itemOptional.isPresent()) { + var item = itemOptional.get(); + var amounts = item.count == 1 ? "" : "*" + item.count; + entity.offer(org.spongepowered.api.data.key.Keys.DISPLAY_NAME, org.spongepowered.api.text.Text.of('§b' + getItemName(item.type.name.split(':')[1]) + amounts)); + entity.offer(org.spongepowered.api.data.key.Keys.CUSTOM_NAME_VISIBLE, true); + } +} + +module.exports = { + description: description, + load: load, + enable: enable, + disable: disable +};