refactor: 重新调整项目框架
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
e2566c4bf1
commit
e454066cce
2
src/main/resources/api/command.js
Normal file
2
src/main/resources/api/command.js
Normal file
@ -0,0 +1,2 @@
|
||||
/*global Java, base, module, exports, require*/
|
||||
module.exports = require('./mserver').command;
|
2
src/main/resources/api/event.js
Normal file
2
src/main/resources/api/event.js
Normal file
@ -0,0 +1,2 @@
|
||||
/*global Java, base, module, exports, require*/
|
||||
module.exports = require('./mserver').event;
|
13
src/main/resources/api/mserver.js
Normal file
13
src/main/resources/api/mserver.js
Normal file
@ -0,0 +1,13 @@
|
||||
/*global Java, base, module, exports, require*/
|
||||
function impl(name) {
|
||||
return require('../internal/' + DetectServerType + '/' + name);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
command: impl('command'),
|
||||
event: impl('event'),
|
||||
permission: impl('permission'),
|
||||
plugin: impl('plugin'),
|
||||
server: impl('server'),
|
||||
task: impl('task')
|
||||
};
|
@ -1 +1,2 @@
|
||||
/*global Java, base, module, exports, require*/
|
||||
module.exports = require('./mserver').permission;
|
2
src/main/resources/api/plugin.js
Normal file
2
src/main/resources/api/plugin.js
Normal file
@ -0,0 +1,2 @@
|
||||
/*global Java, base, module, exports, require*/
|
||||
module.exports = require('./mserver').plugin;
|
2
src/main/resources/api/server.js
Normal file
2
src/main/resources/api/server.js
Normal file
@ -0,0 +1,2 @@
|
||||
/*global Java, base, module, exports, require*/
|
||||
module.exports = require('./mserver').server;
|
2
src/main/resources/api/task.js
Normal file
2
src/main/resources/api/task.js
Normal file
@ -0,0 +1,2 @@
|
||||
/*global Java, base, module, exports, require*/
|
||||
module.exports = require('./mserver').task;
|
@ -39,11 +39,15 @@ var disable;
|
||||
|
||||
var classLoader = java.lang.Thread.currentThread().getContextClassLoader();
|
||||
var url = classLoader.getResource("plugin.yml");
|
||||
if (url === null) { return; }
|
||||
if (url === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var upath = url.getFile().substring(url.getFile().indexOf("/") + 1);
|
||||
var jarPath = java.net.URLDecoder.decode(upath.substring(0, upath.indexOf('!')));
|
||||
if (!Files.exists(Paths.get(jarPath))) { jarPath = "/" + jarPath; }
|
||||
if (!Files.exists(Paths.get(jarPath))) {
|
||||
jarPath = "/" + jarPath;
|
||||
}
|
||||
|
||||
try {
|
||||
var jar = new java.util.jar.JarFile(jarPath);
|
||||
|
@ -1,214 +0,0 @@
|
||||
/*
|
||||
* $Id: base64.js,v 2.15 2014/04/05 12:58:57 dankogai Exp dankogai $
|
||||
*
|
||||
* Licensed under the BSD 3-Clause License.
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
* References:
|
||||
* http://en.wikipedia.org/wiki/Base64
|
||||
*/
|
||||
|
||||
(function(global) {
|
||||
'use strict';
|
||||
// existing version for noConflict()
|
||||
var _Base64 = global.Base64;
|
||||
var version = "2.3.2";
|
||||
// if node.js, we use Buffer
|
||||
var buffer;
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
try {
|
||||
buffer = require('buffer').Buffer;
|
||||
} catch (err) {}
|
||||
}
|
||||
// constants
|
||||
var b64chars
|
||||
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
||||
var b64tab = function(bin) {
|
||||
var t = {};
|
||||
for (var i = 0, l = bin.length; i < l; i++) t[bin.charAt(i)] = i;
|
||||
return t;
|
||||
}(b64chars);
|
||||
var fromCharCode = String.fromCharCode;
|
||||
// encoder stuff
|
||||
var cb_utob = function(c) {
|
||||
if (c.length < 2) {
|
||||
var cc = c.charCodeAt(0);
|
||||
return cc < 0x80 ? c
|
||||
: cc < 0x800 ? (fromCharCode(0xc0 | (cc >>> 6))
|
||||
+ fromCharCode(0x80 | (cc & 0x3f)))
|
||||
: (fromCharCode(0xe0 | ((cc >>> 12) & 0x0f))
|
||||
+ fromCharCode(0x80 | ((cc >>> 6) & 0x3f))
|
||||
+ fromCharCode(0x80 | ( cc & 0x3f)));
|
||||
} else {
|
||||
var cc = 0x10000
|
||||
+ (c.charCodeAt(0) - 0xD800) * 0x400
|
||||
+ (c.charCodeAt(1) - 0xDC00);
|
||||
return (fromCharCode(0xf0 | ((cc >>> 18) & 0x07))
|
||||
+ fromCharCode(0x80 | ((cc >>> 12) & 0x3f))
|
||||
+ fromCharCode(0x80 | ((cc >>> 6) & 0x3f))
|
||||
+ fromCharCode(0x80 | ( cc & 0x3f)));
|
||||
}
|
||||
};
|
||||
var re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
|
||||
var utob = function(u) {
|
||||
return u.replace(re_utob, cb_utob);
|
||||
};
|
||||
var cb_encode = function(ccc) {
|
||||
var padlen = [0, 2, 1][ccc.length % 3],
|
||||
ord = ccc.charCodeAt(0) << 16
|
||||
| ((ccc.length > 1 ? ccc.charCodeAt(1) : 0) << 8)
|
||||
| ((ccc.length > 2 ? ccc.charCodeAt(2) : 0)),
|
||||
chars = [
|
||||
b64chars.charAt( ord >>> 18),
|
||||
b64chars.charAt((ord >>> 12) & 63),
|
||||
padlen >= 2 ? '=' : b64chars.charAt((ord >>> 6) & 63),
|
||||
padlen >= 1 ? '=' : b64chars.charAt(ord & 63)
|
||||
];
|
||||
return chars.join('');
|
||||
};
|
||||
var btoa = global.btoa ? function(b) {
|
||||
return global.btoa(b);
|
||||
} : function(b) {
|
||||
return b.replace(/[\s\S]{1,3}/g, cb_encode);
|
||||
};
|
||||
var _encode = buffer ?
|
||||
buffer.from && buffer.from !== Uint8Array.from ? function (u) {
|
||||
return (u.constructor === buffer.constructor ? u : buffer.from(u))
|
||||
.toString('base64')
|
||||
}
|
||||
: function (u) {
|
||||
return (u.constructor === buffer.constructor ? u : new buffer(u))
|
||||
.toString('base64')
|
||||
}
|
||||
: function (u) { return btoa(utob(u)) }
|
||||
;
|
||||
var encode = function(u, urisafe) {
|
||||
return !urisafe
|
||||
? _encode(String(u))
|
||||
: _encode(String(u)).replace(/[+\/]/g, function(m0) {
|
||||
return m0 == '+' ? '-' : '_';
|
||||
}).replace(/=/g, '');
|
||||
};
|
||||
var encodeURI = function(u) { return encode(u, true) };
|
||||
// decoder stuff
|
||||
var re_btou = new RegExp([
|
||||
'[\xC0-\xDF][\x80-\xBF]',
|
||||
'[\xE0-\xEF][\x80-\xBF]{2}',
|
||||
'[\xF0-\xF7][\x80-\xBF]{3}'
|
||||
].join('|'), 'g');
|
||||
var cb_btou = function(cccc) {
|
||||
switch(cccc.length) {
|
||||
case 4:
|
||||
var cp = ((0x07 & cccc.charCodeAt(0)) << 18)
|
||||
| ((0x3f & cccc.charCodeAt(1)) << 12)
|
||||
| ((0x3f & cccc.charCodeAt(2)) << 6)
|
||||
| (0x3f & cccc.charCodeAt(3)),
|
||||
offset = cp - 0x10000;
|
||||
return (fromCharCode((offset >>> 10) + 0xD800)
|
||||
+ fromCharCode((offset & 0x3FF) + 0xDC00));
|
||||
case 3:
|
||||
return fromCharCode(
|
||||
((0x0f & cccc.charCodeAt(0)) << 12)
|
||||
| ((0x3f & cccc.charCodeAt(1)) << 6)
|
||||
| (0x3f & cccc.charCodeAt(2))
|
||||
);
|
||||
default:
|
||||
return fromCharCode(
|
||||
((0x1f & cccc.charCodeAt(0)) << 6)
|
||||
| (0x3f & cccc.charCodeAt(1))
|
||||
);
|
||||
}
|
||||
};
|
||||
var btou = function(b) {
|
||||
return b.replace(re_btou, cb_btou);
|
||||
};
|
||||
var cb_decode = function(cccc) {
|
||||
var len = cccc.length,
|
||||
padlen = len % 4,
|
||||
n = (len > 0 ? b64tab[cccc.charAt(0)] << 18 : 0)
|
||||
| (len > 1 ? b64tab[cccc.charAt(1)] << 12 : 0)
|
||||
| (len > 2 ? b64tab[cccc.charAt(2)] << 6 : 0)
|
||||
| (len > 3 ? b64tab[cccc.charAt(3)] : 0),
|
||||
chars = [
|
||||
fromCharCode( n >>> 16),
|
||||
fromCharCode((n >>> 8) & 0xff),
|
||||
fromCharCode( n & 0xff)
|
||||
];
|
||||
chars.length -= [0, 0, 2, 1][padlen];
|
||||
return chars.join('');
|
||||
};
|
||||
var atob = global.atob ? function(a) {
|
||||
return global.atob(a);
|
||||
} : function(a){
|
||||
return a.replace(/[\s\S]{1,4}/g, cb_decode);
|
||||
};
|
||||
var _decode = buffer ?
|
||||
buffer.from && buffer.from !== Uint8Array.from ? function(a) {
|
||||
return (a.constructor === buffer.constructor
|
||||
? a : buffer.from(a, 'base64')).toString();
|
||||
}
|
||||
: function(a) {
|
||||
return (a.constructor === buffer.constructor
|
||||
? a : new buffer(a, 'base64')).toString();
|
||||
}
|
||||
: function(a) { return btou(atob(a)) };
|
||||
var decode = function(a){
|
||||
return _decode(
|
||||
String(a).replace(/[-_]/g, function(m0) { return m0 == '-' ? '+' : '/' })
|
||||
.replace(/[^A-Za-z0-9\+\/]/g, '')
|
||||
);
|
||||
};
|
||||
var noConflict = function() {
|
||||
var Base64 = global.Base64;
|
||||
global.Base64 = _Base64;
|
||||
return Base64;
|
||||
};
|
||||
// export Base64
|
||||
global.Base64 = {
|
||||
VERSION: version,
|
||||
atob: atob,
|
||||
btoa: btoa,
|
||||
fromBase64: decode,
|
||||
toBase64: encode,
|
||||
utob: utob,
|
||||
encode: encode,
|
||||
encodeURI: encodeURI,
|
||||
btou: btou,
|
||||
decode: decode,
|
||||
noConflict: noConflict
|
||||
};
|
||||
// if ES5 is available, make Base64.extendString() available
|
||||
if (typeof Object.defineProperty === 'function') {
|
||||
var noEnum = function(v){
|
||||
return {value:v,enumerable:false,writable:true,configurable:true};
|
||||
};
|
||||
global.Base64.extendString = function () {
|
||||
Object.defineProperty(
|
||||
String.prototype, 'fromBase64', noEnum(function () {
|
||||
return decode(this)
|
||||
}));
|
||||
Object.defineProperty(
|
||||
String.prototype, 'toBase64', noEnum(function (urisafe) {
|
||||
return encode(this, urisafe)
|
||||
}));
|
||||
Object.defineProperty(
|
||||
String.prototype, 'toBase64URI', noEnum(function () {
|
||||
return encode(this, true)
|
||||
}));
|
||||
};
|
||||
}
|
||||
// module.exports and AMD are mutually exclusive.
|
||||
// module.exports has precedence.
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
module.exports = global.Base64;
|
||||
}
|
||||
else if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define([], function(){ return global.Base64 });
|
||||
}
|
||||
// that's it!
|
||||
})( typeof self !== 'undefined' ? self
|
||||
: typeof window !== 'undefined' ? window
|
||||
: typeof global !== 'undefined' ? global
|
||||
: this
|
||||
);
|
@ -6,7 +6,7 @@
|
||||
var Arrays = Java.type('java.util.Arrays');
|
||||
var Level = Java.type('java.util.logging.Level');
|
||||
var Console = {
|
||||
createNew: function(name) {
|
||||
createNew: function (name) {
|
||||
var console = {};
|
||||
Object.defineProperty(console, 'name', {
|
||||
get: function () {
|
||||
@ -46,10 +46,10 @@
|
||||
this.console(' §e位于 §c%s.%s(§4%s:%s§c)'.format(stack.className, stack.methodName, stack.fileName, stack.lineNumber));
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
};
|
||||
return console;
|
||||
}
|
||||
}
|
||||
};
|
||||
var BukkitConsole = {
|
||||
createNew: function () {
|
||||
var console = Console.createNew();
|
||||
@ -66,7 +66,7 @@
|
||||
};
|
||||
return console;
|
||||
}
|
||||
}
|
||||
};
|
||||
var SpongeConsole = {
|
||||
createNew: function () {
|
||||
var console = Console.createNew();
|
||||
@ -87,7 +87,7 @@
|
||||
};
|
||||
return console;
|
||||
}
|
||||
}
|
||||
};
|
||||
switch (DetectServerType) {
|
||||
case ServerType.Bukkit:
|
||||
global.Console = BukkitConsole;
|
||||
|
@ -12,7 +12,7 @@ var StandardCopyOption = Java.type("java.nio.file.StandardCopyOption");
|
||||
*/
|
||||
exports.concat = function () {
|
||||
return Array.prototype.join.call(arguments, separatorChar);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* 获得文件
|
||||
* @constructor(file)
|
||||
|
@ -17,7 +17,8 @@ function init(root) {
|
||||
* 初始化核心
|
||||
*/
|
||||
function loadCore() {
|
||||
global.noop = function () {};
|
||||
global.noop = function () {
|
||||
};
|
||||
// 加载基础模块
|
||||
load(root + '/core/ext.js');
|
||||
// 探测服务器类型
|
||||
@ -46,7 +47,7 @@ function loadPatch() {
|
||||
* 加载Bukkit的类库
|
||||
*/
|
||||
function loadServerLib() {
|
||||
var task = require('modules/task');
|
||||
var task = require('api/task');
|
||||
global.setTimeout = function (func, time, _async) {
|
||||
return _async ? task.laterAsync(func, time) : task.later(func, time);
|
||||
};
|
||||
@ -66,7 +67,7 @@ function loadServerLib() {
|
||||
*/
|
||||
function loadPlugins() {
|
||||
// 初始化本体插件
|
||||
global.manager = require('modules/plugin');
|
||||
global.manager = require('api/plugin');
|
||||
if (manager) {
|
||||
manager.init('plugins');
|
||||
// 只有当在正式环境运行的时候才加载
|
||||
|
@ -2,15 +2,21 @@
|
||||
* 补丁和方法扩展
|
||||
*/
|
||||
|
||||
(function(){
|
||||
(function () {
|
||||
// Java格式化方法
|
||||
var str = Java.type('java.lang.String');
|
||||
String.prototype.format = function(){ return str.format(this, Array.prototype.slice.call(arguments, 0))}
|
||||
String.prototype.format = function () {
|
||||
return str.format(this, Array.prototype.slice.call(arguments, 0))
|
||||
};
|
||||
|
||||
// JSON快捷方法
|
||||
Object.prototype.toJson = function(){ return JSON.stringify(this); }
|
||||
Object.prototype.toJson = function () {
|
||||
return JSON.stringify(this);
|
||||
};
|
||||
|
||||
// YAML快速生成
|
||||
var yaml = require('modules/yaml');
|
||||
Object.prototype.toYaml = function(){ return yaml.safeDump(this); }
|
||||
Object.prototype.toYaml = function () {
|
||||
return yaml.safeDump(this);
|
||||
}
|
||||
})();
|
||||
|
@ -1,6 +1,27 @@
|
||||
/**
|
||||
* 符合 CommonJS 规范的 模块化加载
|
||||
*
|
||||
* 符合 CommonJS 规范的 类似 Node 的模块化加载
|
||||
* 一. 注: MiaoScript 中 require.main 不存在
|
||||
* 二. 加载 require 流程 例如 在 dir 目录下 调用 require('xx');
|
||||
* a) 加载流程
|
||||
* 1. 如果xx模块是一个內建模块
|
||||
* a. 编译并返回该模块
|
||||
* b. 停止执行
|
||||
* 2. 如果模块以 `./` `../` 开头
|
||||
* a. 尝试使用 resolveAsFile(dir/xx) 加载文件
|
||||
* b. 尝试使用 resolveAsDirectory(dir/xx) 加载目录
|
||||
* 3. 尝试去 root root/core root/modules 用方法2加载模块
|
||||
* 4. 抛出 not found 异常
|
||||
* b) resolveAsFile 解析流程
|
||||
* 1. 如果 xx 是一个文件 则作为 `javascript` 文本加载 并停止执行
|
||||
* 2. 如果 xx.js 是一个文件 则作为 `javascript` 文本加载 并停止执行
|
||||
* 暂不支持 3. 如果 xx.json 是一个文件 则使用 `JSON.parse(xx.json)` 解析为对象加载 并停止执行
|
||||
* 暂不支持 4. 如果 xx.ms 是一个文件 则使用MScript解析器解析 并停止执行
|
||||
* c) resolveAsDirectory 解析流程
|
||||
* 1. 如果 xx/package.json 存在 则使用 `JSON.parse(xx/package.json)` 解析并取得 main 字段使用 resolveAsFile(main) 加载
|
||||
* 2. 如果 xx/index.js 存在 则使用 resolveAsFile(xx/index.js) 加载
|
||||
* 暂不支持 3. 如果 xx/index.json 存在 则使用 `xx/index.json` 解析为对象加载 并停止执行
|
||||
* 暂不支持 4. 如果 xx/index.ms 是一个文件 则使用MScript解析器解析 并停止执行
|
||||
* 注: MiaoScript 暂不支持多层 modules 加载 暂时不需要(估计以后也不会需要)
|
||||
*/
|
||||
/*global Java, base*/
|
||||
(function (parent) {
|
||||
@ -151,7 +172,7 @@
|
||||
* @private
|
||||
*/
|
||||
function _require(name, path, optional) {
|
||||
var file = _canonical(name) ? name : resolve(name, path);
|
||||
var file = name.isFile && name.isFile() ? name : resolve(name, path);
|
||||
if (file === undefined) {
|
||||
console.console("§c模块 §a%s §c加载失败! §4未找到该模块!".format(name));
|
||||
return {exports: {}};
|
||||
@ -181,9 +202,8 @@
|
||||
|
||||
var cacheDir = parent + separatorChar + "runtime";
|
||||
|
||||
// 等于 undefined 说明 parent 是一个字符串 需要转成File
|
||||
// 可能有更加准确的方案
|
||||
if (_canonical(parent) === undefined) {
|
||||
// 判断是否存在 isFile 不存在说明 parent 是一个字符串 需要转成File
|
||||
if (parent.isFile) {
|
||||
parent = new File(parent);
|
||||
}
|
||||
var cacheModules = [];
|
||||
|
@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
/*global Java, base, module, exports, require, __FILE__*/
|
||||
var ref = require('core/reflect');
|
||||
var ref = require('modules/reflect');
|
||||
var bukkit = require('./server');
|
||||
var plugin = bukkit.plugin.self;
|
||||
var commandMap = ref.on(bukkit.plugin.manager).get('commandMap').get();
|
@ -8,10 +8,8 @@ var Bukkit = Java.type("org.bukkit.Bukkit");
|
||||
var Listener = Java.type("org.bukkit.event.Listener");
|
||||
var Modifier = Java.type("java.lang.reflect.Modifier");
|
||||
var BukkitEvent = Java.type("org.bukkit.event.Event");
|
||||
var HandlerList = Java.type('org.bukkit.event.HandlerList');
|
||||
var EventPriority = Java.type("org.bukkit.event.EventPriority");
|
||||
var EventExecutor = Java.type("org.bukkit.plugin.EventExecutor");
|
||||
var IllegalStateException = Java.type("java.lang.IllegalStateException");
|
||||
|
||||
var plugin = require('./server').plugin.self;
|
||||
|
||||
@ -126,7 +124,7 @@ function listen(jsp, event, exec, priority, ignoreCancel) {
|
||||
plugin,
|
||||
ignoreCancel);
|
||||
// 添加到缓存 用于关闭插件的时候关闭事件
|
||||
if (!listenerMap[name]) listenerMap[name] = []
|
||||
if (!listenerMap[name]) listenerMap[name] = [];
|
||||
var listeners = listenerMap[name];
|
||||
var off = {
|
||||
event: eventCls,
|
||||
@ -135,7 +133,7 @@ function listen(jsp, event, exec, priority, ignoreCancel) {
|
||||
ref.on(this.event).call('getHandlerList').get().unregister(this.listener);
|
||||
console.debug('插件 %s 注销事件 %s'.format(name, this.event.simpleName));
|
||||
}
|
||||
}
|
||||
};
|
||||
listeners.push(off);
|
||||
// noinspection JSUnresolvedVariable
|
||||
console.debug('插件 %s 注册事件 %s => %s'.format(name, eventCls.simpleName, exec.name === '' ? '匿名方法' : exec.name));
|
@ -13,7 +13,7 @@ var permission = require('./permission');
|
||||
|
||||
/**
|
||||
* 载入插件
|
||||
* @param path
|
||||
* @param dir
|
||||
*/
|
||||
function loadPlugins(dir) {
|
||||
var plugin = fs.file(root, dir);
|
@ -6,7 +6,6 @@
|
||||
|
||||
/*global Java, base, module, exports, require, __FILE__*/
|
||||
var Bukkit = MServer;
|
||||
// noinspection JSUnresolvedVariable
|
||||
var Server = Bukkit.server;
|
||||
var PluginManager = Server.pluginManager;
|
||||
exports.$ = Bukkit;
|
@ -6,7 +6,6 @@
|
||||
|
||||
/*global Java, base, module, exports, require, __FILE__*/
|
||||
var Sponge = MServer;
|
||||
// noinspection JSUnresolvedVariable
|
||||
var Server = Sponge.server;
|
||||
var PluginManager = Sponge.pluginManager;
|
||||
exports.$ = Sponge;
|
225
src/main/resources/modules/base64.js
Normal file
225
src/main/resources/modules/base64.js
Normal file
@ -0,0 +1,225 @@
|
||||
/*
|
||||
* $Id: base64.js,v 2.15 2014/04/05 12:58:57 dankogai Exp dankogai $
|
||||
*
|
||||
* Licensed under the BSD 3-Clause License.
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
* References:
|
||||
* http://en.wikipedia.org/wiki/Base64
|
||||
*/
|
||||
|
||||
(function (global) {
|
||||
'use strict';
|
||||
// existing version for noConflict()
|
||||
var _Base64 = global.Base64;
|
||||
var version = "2.3.2";
|
||||
// if node.js, we use Buffer
|
||||
var buffer;
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
try {
|
||||
buffer = require('buffer').Buffer;
|
||||
} catch (err) {
|
||||
}
|
||||
}
|
||||
// constants
|
||||
var b64chars
|
||||
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
||||
var b64tab = function (bin) {
|
||||
var t = {};
|
||||
for (var i = 0, l = bin.length; i < l; i++) t[bin.charAt(i)] = i;
|
||||
return t;
|
||||
}(b64chars);
|
||||
var fromCharCode = String.fromCharCode;
|
||||
// encoder stuff
|
||||
var cb_utob = function (c) {
|
||||
if (c.length < 2) {
|
||||
var cc = c.charCodeAt(0);
|
||||
return cc < 0x80 ? c
|
||||
: cc < 0x800 ? (fromCharCode(0xc0 | (cc >>> 6))
|
||||
+ fromCharCode(0x80 | (cc & 0x3f)))
|
||||
: (fromCharCode(0xe0 | ((cc >>> 12) & 0x0f))
|
||||
+ fromCharCode(0x80 | ((cc >>> 6) & 0x3f))
|
||||
+ fromCharCode(0x80 | ( cc & 0x3f)));
|
||||
} else {
|
||||
var ccc = 0x10000
|
||||
+ (c.charCodeAt(0) - 0xD800) * 0x400
|
||||
+ (c.charCodeAt(1) - 0xDC00);
|
||||
return (fromCharCode(0xf0 | ((ccc >>> 18) & 0x07))
|
||||
+ fromCharCode(0x80 | ((ccc >>> 12) & 0x3f))
|
||||
+ fromCharCode(0x80 | ((ccc >>> 6) & 0x3f))
|
||||
+ fromCharCode(0x80 | ( ccc & 0x3f)));
|
||||
}
|
||||
};
|
||||
var re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
|
||||
var utob = function (u) {
|
||||
return u.replace(re_utob, cb_utob);
|
||||
};
|
||||
var cb_encode = function (ccc) {
|
||||
var padlen = [0, 2, 1][ccc.length % 3],
|
||||
ord = ccc.charCodeAt(0) << 16
|
||||
| ((ccc.length > 1 ? ccc.charCodeAt(1) : 0) << 8)
|
||||
| ((ccc.length > 2 ? ccc.charCodeAt(2) : 0)),
|
||||
chars = [
|
||||
b64chars.charAt(ord >>> 18),
|
||||
b64chars.charAt((ord >>> 12) & 63),
|
||||
padlen >= 2 ? '=' : b64chars.charAt((ord >>> 6) & 63),
|
||||
padlen >= 1 ? '=' : b64chars.charAt(ord & 63)
|
||||
];
|
||||
return chars.join('');
|
||||
};
|
||||
var btoa = global.btoa ? function (b) {
|
||||
return global.btoa(b);
|
||||
} : function (b) {
|
||||
return b.replace(/[\s\S]{1,3}/g, cb_encode);
|
||||
};
|
||||
var _encode = buffer ?
|
||||
buffer.from && buffer.from !== Uint8Array.from ? function (u) {
|
||||
return (u.constructor === buffer.constructor ? u : buffer.from(u))
|
||||
.toString('base64')
|
||||
}
|
||||
: function (u) {
|
||||
return (u.constructor === buffer.constructor ? u : new buffer(u))
|
||||
.toString('base64')
|
||||
}
|
||||
: function (u) {
|
||||
return btoa(utob(u))
|
||||
}
|
||||
;
|
||||
var encode = function (u, urisafe) {
|
||||
return !urisafe
|
||||
? _encode(String(u))
|
||||
: _encode(String(u)).replace(/[+\/]/g, function (m0) {
|
||||
return m0 === '+' ? '-' : '_';
|
||||
}).replace(/=/g, '');
|
||||
};
|
||||
var encodeURI = function (u) {
|
||||
return encode(u, true)
|
||||
};
|
||||
// decoder stuff
|
||||
var re_btou = new RegExp([
|
||||
'[\xC0-\xDF][\x80-\xBF]',
|
||||
'[\xE0-\xEF][\x80-\xBF]{2}',
|
||||
'[\xF0-\xF7][\x80-\xBF]{3}'
|
||||
].join('|'), 'g');
|
||||
var cb_btou = function (cccc) {
|
||||
switch (cccc.length) {
|
||||
case 4:
|
||||
var cp = ((0x07 & cccc.charCodeAt(0)) << 18)
|
||||
| ((0x3f & cccc.charCodeAt(1)) << 12)
|
||||
| ((0x3f & cccc.charCodeAt(2)) << 6)
|
||||
| (0x3f & cccc.charCodeAt(3)),
|
||||
offset = cp - 0x10000;
|
||||
return (fromCharCode((offset >>> 10) + 0xD800)
|
||||
+ fromCharCode((offset & 0x3FF) + 0xDC00));
|
||||
case 3:
|
||||
return fromCharCode(
|
||||
((0x0f & cccc.charCodeAt(0)) << 12)
|
||||
| ((0x3f & cccc.charCodeAt(1)) << 6)
|
||||
| (0x3f & cccc.charCodeAt(2))
|
||||
);
|
||||
default:
|
||||
return fromCharCode(
|
||||
((0x1f & cccc.charCodeAt(0)) << 6)
|
||||
| (0x3f & cccc.charCodeAt(1))
|
||||
);
|
||||
}
|
||||
};
|
||||
var btou = function (b) {
|
||||
return b.replace(re_btou, cb_btou);
|
||||
};
|
||||
var cb_decode = function (cccc) {
|
||||
var len = cccc.length,
|
||||
padlen = len % 4,
|
||||
n = (len > 0 ? b64tab[cccc.charAt(0)] << 18 : 0)
|
||||
| (len > 1 ? b64tab[cccc.charAt(1)] << 12 : 0)
|
||||
| (len > 2 ? b64tab[cccc.charAt(2)] << 6 : 0)
|
||||
| (len > 3 ? b64tab[cccc.charAt(3)] : 0),
|
||||
chars = [
|
||||
fromCharCode(n >>> 16),
|
||||
fromCharCode((n >>> 8) & 0xff),
|
||||
fromCharCode(n & 0xff)
|
||||
];
|
||||
chars.length -= [0, 0, 2, 1][padlen];
|
||||
return chars.join('');
|
||||
};
|
||||
var atob = global.atob ? function (a) {
|
||||
return global.atob(a);
|
||||
} : function (a) {
|
||||
return a.replace(/[\s\S]{1,4}/g, cb_decode);
|
||||
};
|
||||
var _decode = buffer ?
|
||||
buffer.from && buffer.from !== Uint8Array.from ? function (a) {
|
||||
return (a.constructor === buffer.constructor
|
||||
? a : buffer.from(a, 'base64')).toString();
|
||||
}
|
||||
: function (a) {
|
||||
return (a.constructor === buffer.constructor
|
||||
? a : new buffer(a, 'base64')).toString();
|
||||
}
|
||||
: function (a) {
|
||||
return btou(atob(a))
|
||||
};
|
||||
var decode = function (a) {
|
||||
return _decode(
|
||||
String(a).replace(/[-_]/g, function (m0) {
|
||||
return m0 === '-' ? '+' : '/'
|
||||
})
|
||||
.replace(/[^A-Za-z0-9+\/]/g, '')
|
||||
);
|
||||
};
|
||||
var noConflict = function () {
|
||||
var Base64 = global.Base64;
|
||||
global.Base64 = _Base64;
|
||||
return Base64;
|
||||
};
|
||||
// export Base64
|
||||
global.Base64 = {
|
||||
VERSION: version,
|
||||
atob: atob,
|
||||
btoa: btoa,
|
||||
fromBase64: decode,
|
||||
toBase64: encode,
|
||||
utob: utob,
|
||||
encode: encode,
|
||||
encodeURI: encodeURI,
|
||||
btou: btou,
|
||||
decode: decode,
|
||||
noConflict: noConflict
|
||||
};
|
||||
// if ES5 is available, make Base64.extendString() available
|
||||
if (typeof Object.defineProperty === 'function') {
|
||||
var noEnum = function (v) {
|
||||
return {value: v, enumerable: false, writable: true, configurable: true};
|
||||
};
|
||||
global.Base64.extendString = function () {
|
||||
Object.defineProperty(
|
||||
String.prototype, 'fromBase64', noEnum(function () {
|
||||
return decode(this)
|
||||
}));
|
||||
Object.defineProperty(
|
||||
String.prototype, 'toBase64', noEnum(function (urisafe) {
|
||||
return encode(this, urisafe)
|
||||
}));
|
||||
Object.defineProperty(
|
||||
String.prototype, 'toBase64URI', noEnum(function () {
|
||||
return encode(this, true)
|
||||
}));
|
||||
};
|
||||
}
|
||||
// module.exports and AMD are mutually exclusive.
|
||||
// module.exports has precedence.
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
module.exports = global.Base64;
|
||||
}
|
||||
else if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define([], function () {
|
||||
return global.Base64
|
||||
});
|
||||
}
|
||||
// that's it!
|
||||
})(typeof self !== 'undefined' ? self
|
||||
: typeof window !== 'undefined' ? window
|
||||
: typeof global !== 'undefined' ? global
|
||||
: this
|
||||
);
|
@ -1,19 +0,0 @@
|
||||
var BukkitConsole = {
|
||||
createNew: function () {
|
||||
var console = Console.createNew();
|
||||
console.sender = function () {
|
||||
var sender = arguments[0];
|
||||
if (!(sender instanceof org.bukkit.command.CommandSender)) {
|
||||
this.error("第一个参数未实现 org.bukkit.command.CommandSender 无法发送消息!")
|
||||
}
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
sender.sendMessage(console.prefix + args.join(' '));
|
||||
};
|
||||
console.console = function () {
|
||||
this.sender(MServer.consoleSender, Array.prototype.join.call(arguments, ' '));
|
||||
};
|
||||
return console;
|
||||
}
|
||||
}
|
||||
global.Console = BukkitConsole;
|
||||
exports = global.Console;
|
@ -1 +0,0 @@
|
||||
module.exports = require('./mserver').command;
|
@ -1 +0,0 @@
|
||||
module.exports = require('./mserver').event;
|
@ -1,8 +0,0 @@
|
||||
module.exports = {
|
||||
command: require('./' + DetectServerType + '/command'),
|
||||
event: require('./' + DetectServerType + '/event'),
|
||||
permission: require('./' + DetectServerType + '/permission'),
|
||||
plugin: require('./' + DetectServerType + '/plugin'),
|
||||
server: require('./' + DetectServerType + '/server'),
|
||||
task: require('./' + DetectServerType + '/task')
|
||||
}
|
@ -1 +0,0 @@
|
||||
module.exports = require('./mserver').plugin;
|
@ -67,8 +67,8 @@ function Reflect(obj) {
|
||||
accessible(this.class.getDeclaredField(name)).set(this.obj, value);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
this.create = function () {
|
||||
var param = Array.prototype.slice.call(arguments);
|
||||
return on(declaredConstructor(this.class, param).newInstance(param));
|
@ -1 +0,0 @@
|
||||
module.exports = require('./mserver').server;
|
@ -1,23 +0,0 @@
|
||||
var SpongeConsole = {
|
||||
createNew: function () {
|
||||
var console = Console.createNew();
|
||||
console.sender = function () {
|
||||
var Text = Java.type("org.spongepowered.api.text.Text");
|
||||
var sender = arguments[0];
|
||||
if (!(sender instanceof org.spongepowered.api.command.CommandSource)) {
|
||||
this.error("第一个参数未实现 org.spongepowered.api.command.CommandSource 无法发送消息!")
|
||||
}
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
sender.sendMessage(Text.of(console.prefix + args.join(' ')));
|
||||
};
|
||||
console.console = function () {
|
||||
this.sender(MServer.server.console, Array.prototype.join.call(arguments, ' '));
|
||||
};
|
||||
console.warn = function () {
|
||||
log.warn(this.name + Array.prototype.join.call(arguments, ' '));
|
||||
};
|
||||
return console;
|
||||
}
|
||||
}
|
||||
global.Console = SpongeConsole;
|
||||
exports = global.Console;
|
@ -1 +0,0 @@
|
||||
module.exports = require('./mserver').task;
|
@ -3,7 +3,7 @@
|
||||
/*global Java, base, module, exports, require, __FILE__*/
|
||||
|
||||
var ZipFile = Java.type("java.util.zip.ZipFile");
|
||||
var fs = require('fs');
|
||||
var fs = require('core/fs');
|
||||
|
||||
/**
|
||||
* 解压文件
|
@ -4,19 +4,19 @@
|
||||
*/
|
||||
/*global Java, base, module, exports, require*/
|
||||
|
||||
var event = require('modules/event');
|
||||
var command = require('modules/command');
|
||||
var event = require('api/event');
|
||||
var command = require('api/command');
|
||||
var papi = require('./ext/papi');
|
||||
var join;
|
||||
|
||||
var description = {
|
||||
name: 'HelloWorld',
|
||||
version: '1.0',
|
||||
//commands: {
|
||||
// 'hello': {
|
||||
// description: 'HelloWorld主命令'
|
||||
// }
|
||||
//}
|
||||
commands: {
|
||||
'hello': {
|
||||
description: 'HelloWorld主命令'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function load() {
|
||||
|
@ -4,13 +4,9 @@
|
||||
* 可兼容任何记分板
|
||||
*/
|
||||
/*global Java, base, module, exports, require*/
|
||||
|
||||
var fs = require('core/fs');
|
||||
var event = require('modules/event');
|
||||
var bukkit = require('modules/server');
|
||||
var command = require('modules/command');
|
||||
|
||||
var papi = require('./ext/papi');
|
||||
var event = require('api/event');
|
||||
var bukkit = require('api/server');
|
||||
var command = require('api/command');
|
||||
|
||||
var fakeTag;
|
||||
|
||||
@ -25,7 +21,7 @@ var description = {
|
||||
'mtag': {
|
||||
description: 'MiaoTag主命令',
|
||||
usage: '',
|
||||
permission: 'MiaoTag.admin',
|
||||
permission: 'MiaoTag.admin'
|
||||
}
|
||||
},
|
||||
permissions: {
|
||||
@ -86,8 +82,6 @@ function disable() {
|
||||
|
||||
function FakeTag(name) {
|
||||
// NMS CLASS
|
||||
var Scoreboard = bukkit.nmsCls('Scoreboard');
|
||||
var ScoreboardScore = bukkit.nmsCls('ScoreboardScore');
|
||||
var ScoreboardBaseCriteria = bukkit.nmsCls('ScoreboardBaseCriteria');
|
||||
var PacketPlayOutScoreboardScore = bukkit.nmsCls('PacketPlayOutScoreboardScore');
|
||||
var PacketPlayOutScoreboardObjective = bukkit.nmsCls('PacketPlayOutScoreboardObjective');
|
||||
|
@ -4,7 +4,7 @@
|
||||
*/
|
||||
/*global Java, base, module, exports, require, __FILE__*/
|
||||
var PlaceholderAPI;
|
||||
var bukkit = require('modules/server');
|
||||
var bukkit = require('api/server');
|
||||
if (bukkit.plugin.load("PlaceholderAPI")) {
|
||||
PlaceholderAPI = ext.getStatic("me.clip.placeholderapi.PlaceholderAPI");
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user