feat: 降低调试等级 优化事件监听
This commit is contained in:
parent
1058677c5f
commit
86d3e74d47
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>pw.yumc</groupId>
|
||||
<artifactId>MiaoScript</artifactId>
|
||||
<version>1.1</version>
|
||||
<version>1.1.1</version>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>502647092</id>
|
||||
|
@ -36,12 +36,12 @@ public class Base {
|
||||
}
|
||||
|
||||
public String read(String path) throws IOException {
|
||||
Log.d("读取文件 %s ...", path);
|
||||
Log.fd("读取文件 %s ...", path);
|
||||
return new String(Files.readAllBytes(new File(path).toPath()), "UTF-8");
|
||||
}
|
||||
|
||||
public void save(String path, String content) throws IOException {
|
||||
Log.d("保存文件 %s ...", path);
|
||||
Log.fd("保存文件 %s ...", path);
|
||||
File file = new File(path);
|
||||
file.getParentFile().mkdirs();
|
||||
Files.write(file.toPath(), content.getBytes("UTF-8"));
|
||||
@ -54,7 +54,7 @@ public class Base {
|
||||
public void delete(Path path) throws IOException {
|
||||
val file = path.toFile();
|
||||
if (!file.exists()) { return; }
|
||||
Log.d("删除文件 %s ...", path);
|
||||
Log.fd("删除文件 %s ...", path);
|
||||
if (file.isDirectory()) {
|
||||
for (Path f : Files.list(file.toPath()).collect(Collectors.toList())) {
|
||||
delete(f);
|
||||
|
@ -79,6 +79,7 @@ public class MiaoScript extends JavaPlugin implements Executor {
|
||||
|
||||
private void saveScript() {
|
||||
P.saveFile(true, "core", "modules");
|
||||
P.saveFile('plugins');
|
||||
}
|
||||
|
||||
private void enableEngine() {
|
||||
|
@ -42,7 +42,7 @@ function Reflect(obj) {
|
||||
};
|
||||
|
||||
this.cacheMethod = function (name, clazzs) {
|
||||
var mkey = this.class.name + '.' + name;
|
||||
var mkey = this.class.name + '.' + name + ':' + clazzs.join(':');
|
||||
if (!methodCache[mkey]) {
|
||||
methodCache[mkey] = this.method(name, clazzs);
|
||||
}
|
||||
@ -53,7 +53,7 @@ function Reflect(obj) {
|
||||
var name = arguments[0];
|
||||
var params = Array.prototype.slice.call(arguments, 1);
|
||||
var method = this.cacheMethod(name, types(params));
|
||||
return exports.on(method.invoke(this.get(), params));
|
||||
return on(method.invoke(this.get(), params));
|
||||
};
|
||||
|
||||
this.get = function () {
|
||||
@ -84,7 +84,7 @@ function types(values, def) {
|
||||
}
|
||||
var result = [];
|
||||
values.forEach(function (t) {
|
||||
result.push((t === null || def) ? Object.class : t instanceof Class ? t : t.class)
|
||||
result.push((t || def) ? Object.class : t instanceof Class ? t : t.class)
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
@ -103,7 +103,7 @@
|
||||
* @returns {Object}
|
||||
*/
|
||||
function compileModule(id, name, file, optional) {
|
||||
log.d('加载模块 %s 位于 %s Optional %s', name, id, optional.toJson());
|
||||
log.fd('加载模块 %s 位于 %s Optional %s', name, id, optional.toJson());
|
||||
// noinspection JSUnresolvedVariable
|
||||
var module = {
|
||||
id: id,
|
||||
@ -116,7 +116,7 @@
|
||||
compiledWrapper.apply(module.exports, [
|
||||
module, module.exports, module.require, file.parentFile, file
|
||||
]);
|
||||
log.d('模块 %s 编译成功!', name);
|
||||
log.fd('模块 %s 编译成功!', name);
|
||||
module.loaded = true;
|
||||
} catch (ex) {
|
||||
log.console("§4警告! §b模块 §a%s §4编译失败! ERR: %s", name, ex);
|
||||
@ -150,7 +150,7 @@
|
||||
function _require(name, path, optional) {
|
||||
var file = resolve(name, path);
|
||||
if (file === undefined) {
|
||||
log.w("模块 %s 加载失败! 未找到该模块!", name);
|
||||
log.console("§c模块 §a%s §c加载失败! §4未找到该模块!", name);
|
||||
return {exports:{}};
|
||||
}
|
||||
if (!optional) optional = { cache: true }
|
||||
|
@ -25,7 +25,7 @@ var listenerMap = [];
|
||||
*/
|
||||
function mapEventName() {
|
||||
var eventPackageDir = "org/bukkit/event";
|
||||
|
||||
var count = 0;
|
||||
var dirs = Thread.currentThread().getContextClassLoader().getResources(eventPackageDir);
|
||||
while (dirs.hasMoreElements()) {
|
||||
var url = dirs.nextElement();
|
||||
@ -48,6 +48,7 @@ function mapEventName() {
|
||||
var simpleName = clz.simpleName.toLowerCase();
|
||||
log.fd("Mapping Event [%s] => %s", clz.name, simpleName);
|
||||
mapEvent[simpleName] = clz;
|
||||
count++;
|
||||
}
|
||||
} catch (ex) {
|
||||
//ignore already loaded class
|
||||
@ -56,6 +57,7 @@ function mapEventName() {
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,7 +85,7 @@ function isVaildEvent(clz) {
|
||||
function listen(jsp, event, exec, priority, ignoreCancel) {
|
||||
var name = jsp.description.name;
|
||||
if (ext.isNull(name)) throw new TypeError('插件名称为空 请检查传入参数!');
|
||||
var eventCls = mapEvent[event];
|
||||
var eventCls = mapEvent[event] || mapEvent[event.toLowerCase()] || mapEvent[event +'Event'] || mapEvent[event.toLowerCase() + 'event'];
|
||||
if (!eventCls) {
|
||||
try {
|
||||
eventCls = base.getClass(eventCls);
|
||||
@ -92,12 +94,11 @@ function listen(jsp, event, exec, priority, ignoreCancel) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (priority === undefined) {
|
||||
priority = 'NORMAL'
|
||||
}
|
||||
if (ignoreCancel === undefined) {
|
||||
ignoreCancel = false;
|
||||
if (typeof priority === 'boolean') {
|
||||
ignoreCancel = priority
|
||||
}
|
||||
priority = priority || 'NORMAL';
|
||||
ignoreCancel = ignoreCancel || false;
|
||||
var listener = new Listener({});
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
/**
|
||||
@ -143,8 +144,7 @@ function listen(jsp, event, exec, priority, ignoreCancel) {
|
||||
|
||||
var mapEvent = [];
|
||||
// 映射事件名称
|
||||
mapEventName();
|
||||
// log.i('Bukkit 事件映射完毕 共计 %s 个事件!', mapEvent.length);
|
||||
log.i('Bukkit 事件映射完毕 共计 %s 个事件!', mapEventName().toFixed(0));
|
||||
|
||||
module.exports = {
|
||||
on: listen,
|
||||
|
@ -197,7 +197,7 @@ function runAndCatch(jsp, exec, ext) {
|
||||
exec.bind(jsp)();
|
||||
if (ext) { ext(); }
|
||||
} catch (ex) {
|
||||
log.w('§6插件 §b%s §6执行 §d%s §6方法时发生错误 §4%s', jsp.description.name, exec.name, ex.message);
|
||||
log.console('§6插件 §b%s §6执行 §d%s §6方法时发生错误 §4%s', jsp.description.name, exec.name, ex.message);
|
||||
console.ex(ex);
|
||||
}
|
||||
}
|
||||
@ -208,7 +208,7 @@ function checkAndGet(args) {
|
||||
var name = args[0];
|
||||
// 如果是插件 则直接返回
|
||||
if (name.description) { return [name]; }
|
||||
if (!exports.plugins[name]) { throw new Error("插件 " + name + "不存在!"); }
|
||||
if (!exports.plugins[name]) { throw new Error("插件 " + name + " 不存在!"); }
|
||||
return [exports.plugins[name]];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user