feat: 新增案例插件 更新插件版本

This commit is contained in:
coding 2018-01-09 12:22:24 +00:00
parent 96f93754e6
commit fb65f95658
4 changed files with 93 additions and 4 deletions

View File

@ -76,6 +76,12 @@
- [项目代码](https://git.yumc.pw/502647092/MiaoScript)
- [项目脑图](http://naotu.baidu.com/file/293b9a0fc7cef23c69de81c55e3617d5?token=1eee8fd759198eb7)
### 规划
- 初期只会支持JS类型的插件开发
- 二期会出一个建议版本的MS脚本 可以用简单的语法实现简单的功能
- 各个层级会有依赖控制 比如 `MS脚本 => JS脚本 => 调用Java原生API`
### 填坑
- 实际上说了那么多 最终希望的就是 有大佬能一起来填坑 毕竟这个坑太大了

10
pom.xml
View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>pw.yumc</groupId>
<artifactId>MiaoScript</artifactId>
<version>1.2.0</version>
<version>1.2.1</version>
<developers>
<developer>
<id>502647092</id>
@ -84,12 +84,16 @@
<properties>
<env.GIT_COMMIT>DEV</env.GIT_COMMIT>
<update.changes>
§618-01-09 §afeat: 优化加载流程 完善事件注册
§618-01-02 §afeat: 新增http网络访问模块
§617-12-28 §afeat: 完善Sponge事件注册 新增player封装类
</update.changes>
<update.changelog>
§617-11-30 §afeat: 新增Sponge的兼容;
§617-11-03 §afeat: 新增抽奖插件;
§617-10-16 §cfix: 修复关闭MiaoScript时task异常;
§617-10-15 §6alpha: 第一个版本发布;
</update.changes>
<update.changelog></update.changelog>
</update.changelog>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>

View File

@ -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;
}
});

View File

@ -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
};