feat: 新增 Console 和 reflect 部分完善 command
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
@ -2,4 +2,49 @@
|
||||
/**
|
||||
* Bukkit 命令相关类
|
||||
*/
|
||||
|
||||
/*global Java, base, module, exports, require, __FILE__*/
|
||||
var plugin = base.plugin;
|
||||
var bukkit = require('bukkit');
|
||||
var ref = require('kit/reflect');
|
||||
var lookupNames = ref.on(bukkit.plugin.manager).get('lookupNames').get();
|
||||
var knownCommands = ref.on(bukkit.plugin.manager).get('commandMap').get('knownCommands').get();
|
||||
var PluginCommand = Java.type('org.bukkit.command.PluginCommand');
|
||||
|
||||
function create(jsp, name) {
|
||||
var cmd = ref.on(PluginCommand).create(name, plugin).get();
|
||||
register(jsp, name, cmd);
|
||||
}
|
||||
|
||||
function register(jsp, name, cmd) {
|
||||
if (name.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
knownCommands.put(name, cmd);
|
||||
knownCommands.computeIfAbsent(jsp.description.name + ":" + name, function () {
|
||||
return cmd;
|
||||
});
|
||||
knownCommands.computeIfAbsent('ms:' + jsp.description.name + ":" + name, function () {
|
||||
return cmd;
|
||||
});
|
||||
lookupNames.put(name, plugin);
|
||||
}
|
||||
|
||||
// var exec = {
|
||||
// onCommand: function (sender, cmd, command, args) {
|
||||
//
|
||||
// },
|
||||
// onTabComplete: function (sender, cmd, command, args) {
|
||||
//
|
||||
// }
|
||||
// };
|
||||
|
||||
exports.on = function (plugin, name, exec) {
|
||||
var c = create(plugin, name);
|
||||
if (exec.onCommand) {
|
||||
c.setExecutor(exec);
|
||||
}
|
||||
if (exec.onTabComplete) {
|
||||
c.setTabCompleter(exec);
|
||||
}
|
||||
};
|
@ -80,7 +80,7 @@ function listen(event, exec, priority, ignoreCancel) {
|
||||
try {
|
||||
eventCls = base.getClass(eventCls);
|
||||
} catch (ex) {
|
||||
log.w("事件 %s 未找到!");
|
||||
log.w("事件 %s 未找到!", event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +0,0 @@
|
||||
'use strict';
|
||||
/**
|
||||
* PAPI扩展类
|
||||
*/
|
||||
/*global Java, base, module, exports, require, __FILE__*/
|
||||
var PlaceholderAPI;
|
||||
var bukkit = require('modules/bukkit');
|
||||
if (bukkit.plugin.load("PlaceholderAPI")) {
|
||||
PlaceholderAPI = ext.getStatic("me.clip.placeholderapi.PlaceholderAPI");
|
||||
} else {
|
||||
log.w("PlaceholderAPI 未找到 变量替换功能失效!");
|
||||
PlaceholderAPI = {
|
||||
setPlaceholders: function () {
|
||||
return arguments[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.$ = function () {
|
||||
if (arguments.length > 1) {
|
||||
return PlaceholderAPI.setPlaceholders(arguments[0], arguments[1]);
|
||||
} else {
|
||||
return PlaceholderAPI.setPlaceholders(null, arguments[0]);
|
||||
}
|
||||
};
|
@ -11,15 +11,19 @@ var fs = require('core/fs');
|
||||
* @param path
|
||||
*/
|
||||
function loadPlugins(path) {
|
||||
path = fs.file(path);
|
||||
log.i("开始扫描 %s 下的插件...", path);
|
||||
updatePlugins(path);
|
||||
var files = [];
|
||||
fs.list(path).forEach(function (file) {
|
||||
files.push(file.toFile());
|
||||
});
|
||||
loadZipPlugin(files);
|
||||
loadJsPlugin(files);
|
||||
var plugin = fs.file(path);
|
||||
if (!plugin) {
|
||||
log.i("首次加载 创建文件夹 %s ...", path);
|
||||
} else {
|
||||
log.i("开始扫描 %s 下的插件 ...", path);
|
||||
updatePlugins(path);
|
||||
var files = [];
|
||||
fs.list(path).forEach(function (file) {
|
||||
files.push(file.toFile());
|
||||
});
|
||||
loadZipPlugin(files);
|
||||
loadJsPlugin(files);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -28,9 +32,13 @@ function loadPlugins(path) {
|
||||
*/
|
||||
function updatePlugins(path) {
|
||||
var update = fs.file(path, "update");
|
||||
fs.list(update).forEach(function (file) {
|
||||
fs.move(fs.file(update, file.name), fs.file(path, file.name), true);
|
||||
})
|
||||
if (!update.exists()) {
|
||||
update.mkdirs();
|
||||
} else {
|
||||
fs.list(update).forEach(function (file) {
|
||||
fs.move(fs.file(update, file.name), fs.file(path, file.name), true);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user