diff --git a/src/main/resources/bios.js b/src/main/resources/bios.js index 666bfa2..8d428e8 100644 --- a/src/main/resources/bios.js +++ b/src/main/resources/bios.js @@ -23,7 +23,7 @@ var global = this; // 检查类加载器 防止找不到核心文件 loader = checkClassLoader(); // 解压文件到根目录 非调试模式直接从jar解压覆盖 - release(root, '(api|core|internal|modules)+/.*', !global.debug); + release(root, '(core|node_modules)+/.*', !global.debug); load(root + '/core/init.js'); try { init(root); diff --git a/src/main/resources/core/ext.js b/src/main/resources/core/ext.js deleted file mode 100644 index da9b561..0000000 --- a/src/main/resources/core/ext.js +++ /dev/null @@ -1,39 +0,0 @@ -/*global Java, base, module, exports, require, __FILE__*/ -/** - * 菜单基础扩展脚本 - * Created by 蒋天蓓 on 2017/2/8 0008. - */ -var ext = {}; -/** - * 获得静态类 - * @param name 类名 - * @returns {*} - */ -ext.getStatic = function (name) { - return base.getClass(name).static; -}; -/** - * 获得随机数 - * @param max 最大值 - * @param min 最小值 - */ -ext.random = function (max, min) { - min = min === undefined ? 0 : min; - return Math.floor(Math.random() * (max - min) + min); -}; -/** - * 判断对象是否为Null - * @param obj 对象 - * @returns {boolean} notNull返回True - */ -ext.notNull = function (obj) { - return obj !== undefined && obj !== null; -}; -/** - * 判断对象是否为Null - * @param obj 对象 - * @returns {boolean} Null返回True - */ -ext.isNull = function (obj) { - return obj === undefined || obj === null; -}; \ No newline at end of file diff --git a/src/main/resources/core/init.js b/src/main/resources/core/init.js index 6c39879..7a467bd 100644 --- a/src/main/resources/core/init.js +++ b/src/main/resources/core/init.js @@ -25,8 +25,6 @@ * 初始化核心 */ function loadCore() { - // 加载基础模块 - load(root + '/core/ext.js'); // 加载Console load(root + '/core/console.js'); // 探测服务器类型 @@ -59,7 +57,7 @@ global.require = engineLoad(root + '/core/require.js')(root); global.requireInternal = function requireInternal(name, ignoreError) { try { - return require(root + '/internal/' + DetectServerType + '/' + name + '.js'); + return require('internal/' + DetectServerType + '/' + name + '.js'); } catch (ex) { if (ignoreError) { return {} } throw ex; diff --git a/src/main/resources/core/require.js b/src/main/resources/core/require.js index 896ad0c..a112839 100644 --- a/src/main/resources/core/require.js +++ b/src/main/resources/core/require.js @@ -31,7 +31,7 @@ var File = Java.type("java.io.File"); var separatorChar = File.separatorChar; var cacheDir = parent + separatorChar + "runtime"; - var paths = [parent, parent + separatorChar + 'core', parent + separatorChar + 'api', parent + separatorChar + 'modules']; + var paths = [parent, parent + separatorChar + 'node_modules']; try { base.delete(cacheDir); @@ -75,8 +75,7 @@ * 按照下列顺序查找 * 当前目录 ./ * 父目录 ../ - * 核心目录 /core - * 模块目录 /modules + * 模块目录 /node_modules * @param name 模块名称 * @param parent 父目录 */ @@ -103,7 +102,7 @@ * @returns {*} */ function resolveAsFile(dir, file) { - file = ext.notNull(dir) ? new File(dir, file) : new File(file); + file = dir != undefined ? new File(dir, file) : new File(file); // 直接文件 if (file.isFile()) { return file; @@ -125,11 +124,10 @@ * @returns {*} */ function resolveAsDirectory(dir, file) { - dir = ext.notNull(dir) ? new File(dir, file) : new File(file); + dir = dir != undefined ? new File(dir, file) : new File(file); var _package = new File(dir, 'package.json'); if (_package.exists()) { var json = JSON.parse(base.read(_package)); - /** @namespace json.main */ if (json.main) { return resolveAsFile(dir, json.main); } diff --git a/src/main/resources/api/chat.js b/src/main/resources/node_modules/api/chat.js similarity index 100% rename from src/main/resources/api/chat.js rename to src/main/resources/node_modules/api/chat.js diff --git a/src/main/resources/api/command.js b/src/main/resources/node_modules/api/command.js similarity index 100% rename from src/main/resources/api/command.js rename to src/main/resources/node_modules/api/command.js diff --git a/src/main/resources/api/event.js b/src/main/resources/node_modules/api/event.js similarity index 99% rename from src/main/resources/api/event.js rename to src/main/resources/node_modules/api/event.js index b629674..ca53ed6 100644 --- a/src/main/resources/api/event.js +++ b/src/main/resources/node_modules/api/event.js @@ -8,7 +8,7 @@ function EventHandlerDefault() { var Thread = Java.type("java.lang.Thread"); // noinspection JSUnresolvedVariable - this.plugin = require('./server').plugin.self; + this.plugin = require('api/server').plugin.self; this.mapEvent = []; this.listenerMap = []; this.baseEventDir = ''; diff --git a/src/main/resources/api/item.js b/src/main/resources/node_modules/api/item.js similarity index 100% rename from src/main/resources/api/item.js rename to src/main/resources/node_modules/api/item.js diff --git a/src/main/resources/api/permission.js b/src/main/resources/node_modules/api/permission.js similarity index 100% rename from src/main/resources/api/permission.js rename to src/main/resources/node_modules/api/permission.js diff --git a/src/main/resources/api/plugin.js b/src/main/resources/node_modules/api/plugin.js similarity index 99% rename from src/main/resources/api/plugin.js rename to src/main/resources/node_modules/api/plugin.js index 247d074..ac2a6a6 100644 --- a/src/main/resources/api/plugin.js +++ b/src/main/resources/node_modules/api/plugin.js @@ -3,8 +3,8 @@ * MiaoScript脚本插件加载类 */ /*global Java, module, exports, require, __FILE__*/ -var fs = require('core/fs'); -var yaml = require('modules/yaml'); +var fs = require('fs'); +var yaml = require('yaml'); var event = require('./event'); var server = require('./server'); var command = require('./command'); diff --git a/src/main/resources/api/server.js b/src/main/resources/node_modules/api/server.js similarity index 100% rename from src/main/resources/api/server.js rename to src/main/resources/node_modules/api/server.js diff --git a/src/main/resources/api/task.js b/src/main/resources/node_modules/api/task.js similarity index 100% rename from src/main/resources/api/task.js rename to src/main/resources/node_modules/api/task.js diff --git a/src/main/resources/api/wrapper.js b/src/main/resources/node_modules/api/wrapper.js similarity index 100% rename from src/main/resources/api/wrapper.js rename to src/main/resources/node_modules/api/wrapper.js diff --git a/src/main/resources/modules/base64.js b/src/main/resources/node_modules/base64.js similarity index 100% rename from src/main/resources/modules/base64.js rename to src/main/resources/node_modules/base64.js diff --git a/src/main/resources/core/fs.js b/src/main/resources/node_modules/fs.js similarity index 96% rename from src/main/resources/core/fs.js rename to src/main/resources/node_modules/fs.js index 9851e67..a17284d 100644 --- a/src/main/resources/core/fs.js +++ b/src/main/resources/node_modules/fs.js @@ -7,7 +7,7 @@ var Files = Java.type("java.nio.file.Files"); var separatorChar = File.separatorChar; var StandardCopyOption = Java.type("java.nio.file.StandardCopyOption"); // noinspection JSUnusedLocalSymbols -var _toString = function (obj) { +var _toString = function(obj) { return Object.prototype.toString.call(obj); }; @@ -109,7 +109,9 @@ function read(path) { */ function save(path, content, override) { var file = fs.file(path); - file.getParentFile().mkdirs(); + if (file.parentFile) { + file.parentFile.mkdirs(); + } Files.write(file.toPath(), new java.lang.String(content).getBytes("UTF-8")); } @@ -146,7 +148,7 @@ function del(file) { // noinspection JSValidateTypes if (file.isDirectory()) { // noinspection JSUnresolvedVariable - Files.list(file.toPath()).collect(java.util.stream.Collector.toList()).forEach(function (f) { + Files.list(file.toPath()).collect(java.util.stream.Collector.toList()).forEach(function(f) { del(f); }) } diff --git a/src/main/resources/modules/http.js b/src/main/resources/node_modules/http.js similarity index 100% rename from src/main/resources/modules/http.js rename to src/main/resources/node_modules/http.js diff --git a/src/main/resources/internal/bukkit/chat.js b/src/main/resources/node_modules/internal/bukkit/chat.js similarity index 72% rename from src/main/resources/internal/bukkit/chat.js rename to src/main/resources/node_modules/internal/bukkit/chat.js index 2c20b89..f07685e 100644 --- a/src/main/resources/internal/bukkit/chat.js +++ b/src/main/resources/node_modules/internal/bukkit/chat.js @@ -9,6 +9,8 @@ var chatMessageTypes; var String = Java.type('java.lang.String'); +var downgrade = false; + function init() { nmsChatSerializerClass = bukkit.nmsCls(bukkit.nmsVersion.split("_")[1] > 7 ? "IChatBaseComponent$ChatSerializer" : "ChatSerializer"); packetTypeClass = bukkit.nmsCls("PacketPlayOutChat"); @@ -18,12 +20,10 @@ function init() { packetTypeConstructor = c } }); - // noinspection JSUnusedAssignment nmsChatMessageTypeClass = packetTypeConstructor.parameterTypes[1]; if (nmsChatMessageTypeClass.isEnum()) { chatMessageTypes = nmsChatMessageTypeClass.getEnumConstants(); } else { - /** @namespace nmsChatMessageTypeClass.name */ switch (nmsChatMessageTypeClass.name) { case "int": nmsChatMessageTypeClass = java.lang.Integer; @@ -36,22 +36,28 @@ function init() { } function json(sender, json) { - send(sender, json, 0); + if (downgrade) { + bukkit.console('/tellraw ' + sender.name + ' ' + json) + } else { + send(sender, json, 0); + } } function send(sender, json, type) { - var serialized = nmsChatSerializerClass.a(json); - // noinspection all - var typeObj = chatMessageTypes == null ? nmsChatMessageTypeClass.valueOf(String.valueOf(type)) : chatMessageTypes[type]; - sendPacket(sender, new packetTypeClass(serialized, typeObj)) + sendPacket(sender, new packetTypeClass(nmsChatSerializerClass.a(json), chatMessageTypes == null ? nmsChatMessageTypeClass.valueOf(String.valueOf(type)) : chatMessageTypes[type])) } function sendPacket(player, p) { player.handle.playerConnection.sendPacket(p); } -init(); +try { + init(); +} catch (ex) { + console.console("§6[§bbukkit-chat§6] §cNMS Inject Error §4" + ex + " §6Downgrade to Command Mode...") + downgrade = true; +} exports = module.exports = { json: json -}; \ No newline at end of file +}; diff --git a/src/main/resources/internal/bukkit/command.js b/src/main/resources/node_modules/internal/bukkit/command.js similarity index 98% rename from src/main/resources/internal/bukkit/command.js rename to src/main/resources/node_modules/internal/bukkit/command.js index 082bc4a..ccf127f 100644 --- a/src/main/resources/internal/bukkit/command.js +++ b/src/main/resources/node_modules/internal/bukkit/command.js @@ -4,7 +4,7 @@ */ /*global Java, base, module, exports, require, __FILE__*/ -var ref = require('modules/reflect'); +var ref = require('reflect'); var bukkit = require('./server'); var plugin = bukkit.plugin.self; var commandMap = ref.on(bukkit.plugin.manager).get('commandMap').get(); diff --git a/src/main/resources/internal/bukkit/console.js b/src/main/resources/node_modules/internal/bukkit/console.js similarity index 100% rename from src/main/resources/internal/bukkit/console.js rename to src/main/resources/node_modules/internal/bukkit/console.js diff --git a/src/main/resources/internal/bukkit/event.js b/src/main/resources/node_modules/internal/bukkit/event.js similarity index 100% rename from src/main/resources/internal/bukkit/event.js rename to src/main/resources/node_modules/internal/bukkit/event.js diff --git a/src/main/resources/internal/bukkit/item.js b/src/main/resources/node_modules/internal/bukkit/item.js similarity index 95% rename from src/main/resources/internal/bukkit/item.js rename to src/main/resources/node_modules/internal/bukkit/item.js index 82ec2ce..9c4a169 100644 --- a/src/main/resources/internal/bukkit/item.js +++ b/src/main/resources/node_modules/internal/bukkit/item.js @@ -22,7 +22,8 @@ item.create = function() { case "[object Number]": break; case "[object String]": - idOrType = Material[idOrType]; + // 尝试获取老版本枚举 + idOrType = Material[idOrType] || Material[Material['LEGACY_PREFIX'] + idOrType]; break; case "[object Array]": idOrType.forEach(function(type) { diff --git a/src/main/resources/internal/bukkit/permission.js b/src/main/resources/node_modules/internal/bukkit/permission.js similarity index 100% rename from src/main/resources/internal/bukkit/permission.js rename to src/main/resources/node_modules/internal/bukkit/permission.js diff --git a/src/main/resources/internal/bukkit/server.js b/src/main/resources/node_modules/internal/bukkit/server.js similarity index 100% rename from src/main/resources/internal/bukkit/server.js rename to src/main/resources/node_modules/internal/bukkit/server.js diff --git a/src/main/resources/internal/bukkit/task.js b/src/main/resources/node_modules/internal/bukkit/task.js similarity index 100% rename from src/main/resources/internal/bukkit/task.js rename to src/main/resources/node_modules/internal/bukkit/task.js diff --git a/src/main/resources/internal/bukkit/wrapper/player.js b/src/main/resources/node_modules/internal/bukkit/wrapper/player.js similarity index 100% rename from src/main/resources/internal/bukkit/wrapper/player.js rename to src/main/resources/node_modules/internal/bukkit/wrapper/player.js diff --git a/src/main/resources/internal/internal.d.ts b/src/main/resources/node_modules/internal/internal.d.ts similarity index 100% rename from src/main/resources/internal/internal.d.ts rename to src/main/resources/node_modules/internal/internal.d.ts diff --git a/src/main/resources/internal/sponge/chat.js b/src/main/resources/node_modules/internal/sponge/chat.js similarity index 100% rename from src/main/resources/internal/sponge/chat.js rename to src/main/resources/node_modules/internal/sponge/chat.js diff --git a/src/main/resources/internal/sponge/command.js b/src/main/resources/node_modules/internal/sponge/command.js similarity index 100% rename from src/main/resources/internal/sponge/command.js rename to src/main/resources/node_modules/internal/sponge/command.js diff --git a/src/main/resources/internal/sponge/console.js b/src/main/resources/node_modules/internal/sponge/console.js similarity index 100% rename from src/main/resources/internal/sponge/console.js rename to src/main/resources/node_modules/internal/sponge/console.js diff --git a/src/main/resources/internal/sponge/event.js b/src/main/resources/node_modules/internal/sponge/event.js similarity index 100% rename from src/main/resources/internal/sponge/event.js rename to src/main/resources/node_modules/internal/sponge/event.js diff --git a/src/main/resources/internal/sponge/server.js b/src/main/resources/node_modules/internal/sponge/server.js similarity index 100% rename from src/main/resources/internal/sponge/server.js rename to src/main/resources/node_modules/internal/sponge/server.js diff --git a/src/main/resources/internal/sponge/task.js b/src/main/resources/node_modules/internal/sponge/task.js similarity index 100% rename from src/main/resources/internal/sponge/task.js rename to src/main/resources/node_modules/internal/sponge/task.js diff --git a/src/main/resources/internal/sponge/wrapper/player.js b/src/main/resources/node_modules/internal/sponge/wrapper/player.js similarity index 100% rename from src/main/resources/internal/sponge/wrapper/player.js rename to src/main/resources/node_modules/internal/sponge/wrapper/player.js diff --git a/src/main/resources/modules/modules.d.ts b/src/main/resources/node_modules/modules.d.ts similarity index 100% rename from src/main/resources/modules/modules.d.ts rename to src/main/resources/node_modules/modules.d.ts diff --git a/src/main/resources/modules/papi.js b/src/main/resources/node_modules/papi.js similarity index 92% rename from src/main/resources/modules/papi.js rename to src/main/resources/node_modules/papi.js index 690b8b0..8915dd1 100644 --- a/src/main/resources/modules/papi.js +++ b/src/main/resources/node_modules/papi.js @@ -14,14 +14,13 @@ PlaceholderAPI = { // 尝试加载 Bukkit 的 PlaceholderAPI try { - PlaceholderAPI = ext.getStatic("me.clip.placeholderapi.PlaceholderAPI"); + PlaceholderAPI = base.getClass("me.clip.placeholderapi.PlaceholderAPI").static; console.log('[PAPI] Found Bukkit PlaceholderAPI Hooking...') } catch (ex) { } // 尝试加载 Sponge 的 PlaceholderAPI try { - /** @namespace server.service */ var spongePapi = server.service.get('me.rojo8399.placeholderapi.PlaceholderService'); var TextSerializers = Java.type('org.spongepowered.api.text.serializer.TextSerializers'); var s = TextSerializers.formattingCode('§'); diff --git a/src/main/resources/modules/reflect.js b/src/main/resources/node_modules/reflect.js similarity index 93% rename from src/main/resources/modules/reflect.js rename to src/main/resources/node_modules/reflect.js index 3da86b3..1b127b4 100644 --- a/src/main/resources/modules/reflect.js +++ b/src/main/resources/node_modules/reflect.js @@ -18,6 +18,16 @@ function Reflect(obj) { this.class = obj.class; } + this.method = function(name) { + var name = arguments[0]; + var params = Array.prototype.slice.call(arguments, 1); + return declaredMethod(this.class, name, types(params)); + } + + this.methods = function() { + return Java.from(declaredMethods(this.class)); + } + this.field = function(name) { try { // Try getting a public field @@ -34,7 +44,7 @@ function Reflect(obj) { }; this.fields = function(declared) { - return declared ? this.class.declaredFields : this.class.fields; + return Java.from(declared ? this.class.declaredFields : this.class.fields); } this.values = function(declared) { diff --git a/src/main/resources/modules/tellraw.js b/src/main/resources/node_modules/tellraw.js similarity index 100% rename from src/main/resources/modules/tellraw.js rename to src/main/resources/node_modules/tellraw.js diff --git a/src/main/resources/modules/template.js b/src/main/resources/node_modules/template.js similarity index 100% rename from src/main/resources/modules/template.js rename to src/main/resources/node_modules/template.js diff --git a/src/main/resources/modules/utils.js b/src/main/resources/node_modules/utils.js similarity index 100% rename from src/main/resources/modules/utils.js rename to src/main/resources/node_modules/utils.js diff --git a/src/main/resources/modules/yaml/index.js b/src/main/resources/node_modules/yaml/index.js similarity index 100% rename from src/main/resources/modules/yaml/index.js rename to src/main/resources/node_modules/yaml/index.js diff --git a/src/main/resources/modules/yaml/js-yaml/common.js b/src/main/resources/node_modules/yaml/js-yaml/common.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/common.js rename to src/main/resources/node_modules/yaml/js-yaml/common.js diff --git a/src/main/resources/modules/yaml/js-yaml/dumper.js b/src/main/resources/node_modules/yaml/js-yaml/dumper.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/dumper.js rename to src/main/resources/node_modules/yaml/js-yaml/dumper.js diff --git a/src/main/resources/modules/yaml/js-yaml/exception.js b/src/main/resources/node_modules/yaml/js-yaml/exception.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/exception.js rename to src/main/resources/node_modules/yaml/js-yaml/exception.js diff --git a/src/main/resources/modules/yaml/js-yaml/loader.js b/src/main/resources/node_modules/yaml/js-yaml/loader.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/loader.js rename to src/main/resources/node_modules/yaml/js-yaml/loader.js diff --git a/src/main/resources/modules/yaml/js-yaml/mark.js b/src/main/resources/node_modules/yaml/js-yaml/mark.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/mark.js rename to src/main/resources/node_modules/yaml/js-yaml/mark.js diff --git a/src/main/resources/modules/yaml/js-yaml/schema.js b/src/main/resources/node_modules/yaml/js-yaml/schema.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/schema.js rename to src/main/resources/node_modules/yaml/js-yaml/schema.js diff --git a/src/main/resources/modules/yaml/js-yaml/schema/core.js b/src/main/resources/node_modules/yaml/js-yaml/schema/core.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/schema/core.js rename to src/main/resources/node_modules/yaml/js-yaml/schema/core.js diff --git a/src/main/resources/modules/yaml/js-yaml/schema/default_full.js b/src/main/resources/node_modules/yaml/js-yaml/schema/default_full.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/schema/default_full.js rename to src/main/resources/node_modules/yaml/js-yaml/schema/default_full.js diff --git a/src/main/resources/modules/yaml/js-yaml/schema/default_safe.js b/src/main/resources/node_modules/yaml/js-yaml/schema/default_safe.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/schema/default_safe.js rename to src/main/resources/node_modules/yaml/js-yaml/schema/default_safe.js diff --git a/src/main/resources/modules/yaml/js-yaml/schema/failsafe.js b/src/main/resources/node_modules/yaml/js-yaml/schema/failsafe.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/schema/failsafe.js rename to src/main/resources/node_modules/yaml/js-yaml/schema/failsafe.js diff --git a/src/main/resources/modules/yaml/js-yaml/schema/json.js b/src/main/resources/node_modules/yaml/js-yaml/schema/json.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/schema/json.js rename to src/main/resources/node_modules/yaml/js-yaml/schema/json.js diff --git a/src/main/resources/modules/yaml/js-yaml/type.js b/src/main/resources/node_modules/yaml/js-yaml/type.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/type.js rename to src/main/resources/node_modules/yaml/js-yaml/type.js diff --git a/src/main/resources/modules/yaml/js-yaml/type/binary.js b/src/main/resources/node_modules/yaml/js-yaml/type/binary.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/type/binary.js rename to src/main/resources/node_modules/yaml/js-yaml/type/binary.js diff --git a/src/main/resources/modules/yaml/js-yaml/type/bool.js b/src/main/resources/node_modules/yaml/js-yaml/type/bool.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/type/bool.js rename to src/main/resources/node_modules/yaml/js-yaml/type/bool.js diff --git a/src/main/resources/modules/yaml/js-yaml/type/float.js b/src/main/resources/node_modules/yaml/js-yaml/type/float.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/type/float.js rename to src/main/resources/node_modules/yaml/js-yaml/type/float.js diff --git a/src/main/resources/modules/yaml/js-yaml/type/int.js b/src/main/resources/node_modules/yaml/js-yaml/type/int.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/type/int.js rename to src/main/resources/node_modules/yaml/js-yaml/type/int.js diff --git a/src/main/resources/modules/yaml/js-yaml/type/js/function.js b/src/main/resources/node_modules/yaml/js-yaml/type/js/function.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/type/js/function.js rename to src/main/resources/node_modules/yaml/js-yaml/type/js/function.js diff --git a/src/main/resources/modules/yaml/js-yaml/type/js/regexp.js b/src/main/resources/node_modules/yaml/js-yaml/type/js/regexp.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/type/js/regexp.js rename to src/main/resources/node_modules/yaml/js-yaml/type/js/regexp.js diff --git a/src/main/resources/modules/yaml/js-yaml/type/js/undefined.js b/src/main/resources/node_modules/yaml/js-yaml/type/js/undefined.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/type/js/undefined.js rename to src/main/resources/node_modules/yaml/js-yaml/type/js/undefined.js diff --git a/src/main/resources/modules/yaml/js-yaml/type/map.js b/src/main/resources/node_modules/yaml/js-yaml/type/map.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/type/map.js rename to src/main/resources/node_modules/yaml/js-yaml/type/map.js diff --git a/src/main/resources/modules/yaml/js-yaml/type/merge.js b/src/main/resources/node_modules/yaml/js-yaml/type/merge.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/type/merge.js rename to src/main/resources/node_modules/yaml/js-yaml/type/merge.js diff --git a/src/main/resources/modules/yaml/js-yaml/type/null.js b/src/main/resources/node_modules/yaml/js-yaml/type/null.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/type/null.js rename to src/main/resources/node_modules/yaml/js-yaml/type/null.js diff --git a/src/main/resources/modules/yaml/js-yaml/type/omap.js b/src/main/resources/node_modules/yaml/js-yaml/type/omap.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/type/omap.js rename to src/main/resources/node_modules/yaml/js-yaml/type/omap.js diff --git a/src/main/resources/modules/yaml/js-yaml/type/pairs.js b/src/main/resources/node_modules/yaml/js-yaml/type/pairs.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/type/pairs.js rename to src/main/resources/node_modules/yaml/js-yaml/type/pairs.js diff --git a/src/main/resources/modules/yaml/js-yaml/type/seq.js b/src/main/resources/node_modules/yaml/js-yaml/type/seq.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/type/seq.js rename to src/main/resources/node_modules/yaml/js-yaml/type/seq.js diff --git a/src/main/resources/modules/yaml/js-yaml/type/set.js b/src/main/resources/node_modules/yaml/js-yaml/type/set.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/type/set.js rename to src/main/resources/node_modules/yaml/js-yaml/type/set.js diff --git a/src/main/resources/modules/yaml/js-yaml/type/str.js b/src/main/resources/node_modules/yaml/js-yaml/type/str.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/type/str.js rename to src/main/resources/node_modules/yaml/js-yaml/type/str.js diff --git a/src/main/resources/modules/yaml/js-yaml/type/timestamp.js b/src/main/resources/node_modules/yaml/js-yaml/type/timestamp.js similarity index 100% rename from src/main/resources/modules/yaml/js-yaml/type/timestamp.js rename to src/main/resources/node_modules/yaml/js-yaml/type/timestamp.js diff --git a/src/main/resources/modules/zip.js b/src/main/resources/node_modules/zip.js similarity index 100% rename from src/main/resources/modules/zip.js rename to src/main/resources/node_modules/zip.js diff --git a/src/main/resources/plugins/bukkit/Lottery.js b/src/main/resources/plugins/bukkit/Lottery.js index 37731fb..c806319 100644 --- a/src/main/resources/plugins/bukkit/Lottery.js +++ b/src/main/resources/plugins/bukkit/Lottery.js @@ -13,6 +13,8 @@ var Arrays = Java.type('java.util.Arrays'); var Material = Java.type('org.bukkit.Material'); var ItemStackArray = Java.type('org.bukkit.inventory.ItemStack[]'); +var PANE = 'STAINED_GLASS_PANE' + var description = { name: 'Lottery', version: '1.0', @@ -25,14 +27,14 @@ var description = { config: { title: '§m§s§a幸运抽奖', control: { - panel: 'GLASS_PANE:13', - ok: 'GLASS_PANE:14', - no: 'GLASS_PANE:15', + panel: PANE + ':13', + ok: PANE + ':14', + no: PANE + ':15', }, list: [ { box: { - id: 'GLASS_PANE', + id: PANE, damage: 1, name: '§a箱子', lore: [ @@ -40,7 +42,7 @@ var description = { ] }, key: { - id: 'GLASS_PANE', + id: PANE, damage: 2, name: '§b钥匙', lore: [ @@ -52,7 +54,7 @@ var description = { percent: 10, command: 'money give %player% 100', item: { - id: 'GLASS_PANE', + id: PANE, damage: 3, name: '§c奖品1', lore: [ @@ -64,7 +66,7 @@ var description = { percent: 20, command: 'money give %player% 200', item: { - id: 'GLASS_PANE', + id: PANE, damage: 4, name: '§c奖品2', lore: [ @@ -83,14 +85,13 @@ var config; var items; function load() { - panel = item.create('GLASS_PANE', 1, 13); config = this.config; - panel = newItemFromString(config.control.panel || 'GLASS_PANE:13') + panel = newItemFromString(config.control.panel || PANE + ':13') items = new ItemStackArray(54); item.setName(panel, ''); - var ok = newItemFromString(config.control.ok || 'GLASS_PANE:14') + var ok = newItemFromString(config.control.ok || PANE + ':14') item.setName(ok, '§a确定抽奖'); - var no = newItemFromString(config.control.no || 'GLASS_PANE:15') + var no = newItemFromString(config.control.no || PANE + ':15') item.setName(no, '§c取消抽奖'); Arrays.fill(items, 0, 10, panel); Arrays.fill(items, 11, 16, panel); @@ -133,6 +134,8 @@ function enable() { // noinspection JSUnusedLocalSymbols command.on(this, 'l', { cmd: function(sender, command, args) { + sender.inventory.addItem(newItemFromConfig(config.list[0].box)) + sender.inventory.addItem(newItemFromConfig(config.list[0].key)) if (!sender.openInventory) { console.sender(sender, "§4当前用户无法使用该命令!"); } @@ -144,7 +147,7 @@ function enable() { }); event.on(this, 'InventoryClick', function click(event) { var inv = event.inventory; - if (inv.title !== config.title) return; + if (inv && inv.title !== config.title) return; var player = event.whoClicked; var slot = event.rawSlot; if (slot > 53 || slot < 0) { @@ -169,6 +172,10 @@ function enable() { } var litem; var box = inv.getItem(10); + if (!box) { + console.sender(player, '§c请先放入抽奖物品和钥匙!'); + return; + } var key = inv.getItem(16); if (box && box.typeId !== 0 && key && key.typeId !== 0) { for (var i = 0; i < config.list.length; i++) { @@ -194,7 +201,7 @@ function enable() { resultList.push(t); } }); - var ri = ext.random(resultList.length); + var ri = random(resultList.length); var result = resultList[ri]; box.amount = box.amount - 1; key.amount = key.amount - 1; @@ -209,6 +216,11 @@ function enable() { }); } +function random(max, min) { + min = min === undefined ? 0 : min; + return Math.floor(Math.random() * (max - min) + min); +}; + function disable() { } diff --git a/src/main/resources/plugins/bukkit/MiaoTag.js b/src/main/resources/plugins/bukkit/MiaoTag.js index 20dae37..a1a79c6 100644 --- a/src/main/resources/plugins/bukkit/MiaoTag.js +++ b/src/main/resources/plugins/bukkit/MiaoTag.js @@ -94,10 +94,15 @@ function FakeTag(name) { try { var ScoreboardBaseCriteria = bukkit.nmsCls('ScoreboardBaseCriteria'); } catch (ex) { - ver1_13 = true; - var IScoreboardCriteria = bukkit.nmsCls('IScoreboardCriteria'); - var ScoreboardServer = bukkit.nmsCls("ScoreboardServer"); - var ChatComponentText = bukkit.nmsCls('ChatComponentText'); + try { + var IScoreboardCriteria = bukkit.nmsCls('IScoreboardCriteria'); + var ScoreboardServer = bukkit.nmsCls("ScoreboardServer"); + var ChatComponentText = bukkit.nmsCls('ChatComponentText'); + ver1_13 = true; + } catch (ex) { + console.log(ex); + throw ex; + } } var PacketPlayOutScoreboardScore = bukkit.nmsCls('PacketPlayOutScoreboardScore'); var PacketPlayOutScoreboardObjective = bukkit.nmsCls('PacketPlayOutScoreboardObjective');