feat: 格式化代码 添加d.ts文件 去除引擎无关代码 清理单元测试
This commit is contained in:
parent
967e7d1beb
commit
88d71abb2a
@ -1,19 +1,8 @@
|
|||||||
package pw.yumc.MiaoScript;
|
package pw.yumc.MiaoScript;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.val;
|
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
|
||||||
import pw.yumc.YumCore.commands.CommandSub;
|
|
||||||
import pw.yumc.YumCore.commands.annotation.Cmd;
|
|
||||||
import pw.yumc.YumCore.commands.annotation.Help;
|
|
||||||
import pw.yumc.YumCore.commands.interfaces.Executor;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 喵式脚本
|
* 喵式脚本
|
||||||
@ -21,62 +10,14 @@ import pw.yumc.YumCore.commands.interfaces.Executor;
|
|||||||
* @author 喵♂呜
|
* @author 喵♂呜
|
||||||
* @since 2016年8月29日 上午7:50:39
|
* @since 2016年8月29日 上午7:50:39
|
||||||
*/
|
*/
|
||||||
public class MiaoScript extends JavaPlugin implements Executor {
|
public class MiaoScript extends JavaPlugin {
|
||||||
private ScriptEngine engine;
|
private ScriptEngine engine;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
new CommandSub("ms", this);
|
|
||||||
engine = new ScriptEngine(getDataFolder().getCanonicalPath(), getLogger());
|
engine = new ScriptEngine(getDataFolder().getCanonicalPath(), getLogger());
|
||||||
enableEngine();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Cmd
|
|
||||||
@Help("执行 JS 代码")
|
|
||||||
@SneakyThrows
|
|
||||||
public void js(CommandSender sender, String script) {
|
|
||||||
result(sender, engine.getEngine().eval(script));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Cmd
|
|
||||||
@Help("执行 JS 代码文件")
|
|
||||||
@SneakyThrows
|
|
||||||
public void file(CommandSender sender, String file) {
|
|
||||||
result(sender, engine.getEngine().eval("load('" + new File(getDataFolder(), file).getCanonicalPath() + "')"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Cmd
|
|
||||||
@Help("重启脚本引擎")
|
|
||||||
public void reload(CommandSender sender) {
|
|
||||||
engine.disableEngine();
|
|
||||||
val server = Bukkit.getServer();
|
|
||||||
try {
|
|
||||||
server.getScheduler().cancelTasks(this);
|
|
||||||
server.getServicesManager().unregisterAll(this);
|
|
||||||
HandlerList.unregisterAll(this);
|
|
||||||
server.getMessenger().unregisterIncomingPluginChannel(this);
|
|
||||||
server.getMessenger().unregisterOutgoingPluginChannel(this);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Log.d("Error reload", ex);
|
|
||||||
}
|
|
||||||
enableEngine();
|
|
||||||
Log.sender(sender, "§bMiaoScript §eEngine §a重启完成!");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void result(CommandSender sender, Object result) {
|
|
||||||
if (result == null) {
|
|
||||||
Log.sender(sender, "§a运行成功! §c没有返回结果!");
|
|
||||||
} else {
|
|
||||||
Log.sender(sender, "§a运行成功! §b数据类型: §r%s §d结果: §r%s", result.getClass().getName(), result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void enableEngine() {
|
|
||||||
val origin = Thread.currentThread().getContextClassLoader();
|
|
||||||
Thread.currentThread().setContextClassLoader(getClassLoader());
|
|
||||||
engine.enableEngine();
|
engine.enableEngine();
|
||||||
Thread.currentThread().setContextClassLoader(origin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,23 +1,13 @@
|
|||||||
package pw.yumc.MiaoScript;
|
package pw.yumc.MiaoScript;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import javax.script.ScriptException;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.spongepowered.api.Sponge;
|
|
||||||
import org.spongepowered.api.command.CommandResult;
|
|
||||||
import org.spongepowered.api.command.CommandSource;
|
|
||||||
import org.spongepowered.api.command.args.GenericArguments;
|
|
||||||
import org.spongepowered.api.command.spec.CommandSpec;
|
|
||||||
import org.spongepowered.api.config.ConfigDir;
|
import org.spongepowered.api.config.ConfigDir;
|
||||||
import org.spongepowered.api.event.Listener;
|
import org.spongepowered.api.event.Listener;
|
||||||
import org.spongepowered.api.event.game.state.GameInitializationEvent;
|
|
||||||
import org.spongepowered.api.event.game.state.GameStartedServerEvent;
|
import org.spongepowered.api.event.game.state.GameStartedServerEvent;
|
||||||
|
import org.spongepowered.api.event.game.state.GameStoppingServerEvent;
|
||||||
import org.spongepowered.api.plugin.Plugin;
|
import org.spongepowered.api.plugin.Plugin;
|
||||||
import org.spongepowered.api.text.Text;
|
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
@ -39,77 +29,15 @@ public class MiaoScriptSponge {
|
|||||||
private File pluginConfigDir;
|
private File pluginConfigDir;
|
||||||
|
|
||||||
@Listener
|
@Listener
|
||||||
public void onInit(GameInitializationEvent event) {
|
@SneakyThrows
|
||||||
|
public void onStart(GameStartedServerEvent event) {
|
||||||
}
|
engine = new ScriptEngine(pluginConfigDir.getCanonicalPath(), logger);
|
||||||
|
|
||||||
private CommandSpec main() {
|
|
||||||
return CommandSpec.builder()
|
|
||||||
.description(Text.of("喵式脚本主命令"))
|
|
||||||
.permission("MiaoScript.admin")
|
|
||||||
.child(js(), "js")
|
|
||||||
.child(file(), "file")
|
|
||||||
.child(reload(), "reload")
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private CommandSpec js() {
|
|
||||||
return CommandSpec.builder()
|
|
||||||
.description(Text.of("执行JS命令"))
|
|
||||||
.arguments(GenericArguments.onlyOne(GenericArguments.remainingJoinedStrings(Text.of("js"))))
|
|
||||||
.executor((src, args) -> {
|
|
||||||
try {
|
|
||||||
result(src, engine.getEngine().eval(args.<String>getOne("js").orElse("")));
|
|
||||||
} catch (ScriptException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return CommandResult.success();
|
|
||||||
})
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private CommandSpec file() {
|
|
||||||
return CommandSpec.builder()
|
|
||||||
.description(Text.of("执行JS文件"))
|
|
||||||
.arguments(GenericArguments.onlyOne(GenericArguments.remainingJoinedStrings(Text.of("js"))))
|
|
||||||
.executor((src, args) -> {
|
|
||||||
try {
|
|
||||||
result(src, engine.getEngine().eval(new FileReader(new File(pluginConfigDir, args.<String>getOne("js").orElse("")))));
|
|
||||||
} catch (ScriptException | IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return CommandResult.success();
|
|
||||||
})
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private CommandSpec reload() {
|
|
||||||
return CommandSpec.builder()
|
|
||||||
.description(Text.of("重载 JS 引擎"))
|
|
||||||
.executor((src, args) -> {
|
|
||||||
engine.disableEngine();
|
|
||||||
Sponge.getEventManager().unregisterPluginListeners(this);
|
|
||||||
engine.enableEngine();
|
engine.enableEngine();
|
||||||
src.sendMessage(Text.of("§6[§bMiaoScript§6]§r §bMiaoScript §eEngine §a重启完成!"));
|
|
||||||
return CommandResult.success();
|
|
||||||
})
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void result(CommandSource sender, Object result) {
|
|
||||||
if (result == null) {
|
|
||||||
sender.sendMessage(Text.of("§a运行成功! §c没有返回结果!"));
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(Text.of(String.format("§a运行成功! §b数据类型: §r%s §d结果: §r%s", result.getClass().getName(), result)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Listener
|
@Listener
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public void onStart(GameStartedServerEvent event) {
|
public void onStop(GameStoppingServerEvent event) {
|
||||||
Sponge.getServer().getConsole();
|
engine.disableEngine();
|
||||||
Sponge.getCommandManager().register(this, main(), "ms", "mscript", "MiaoScript");
|
|
||||||
engine = new ScriptEngine(pluginConfigDir.getCanonicalPath(), logger);
|
|
||||||
engine.enableEngine();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ public class ScriptEngine {
|
|||||||
ScriptEngineManager manager = new ScriptEngineManager();
|
ScriptEngineManager manager = new ScriptEngineManager();
|
||||||
this.engine = new MiaoScriptEngine(manager, "nashorn");
|
this.engine = new MiaoScriptEngine(manager, "nashorn");
|
||||||
this.engine.put("base", new Base());
|
this.engine.put("base", new Base());
|
||||||
|
this.engine.put("ScriptEngineContextHolder", this);
|
||||||
Path bios = Paths.get(root, "bios.js");
|
Path bios = Paths.get(root, "bios.js");
|
||||||
// 如果存在自定义bios就加载自定义的
|
// 如果存在自定义bios就加载自定义的
|
||||||
if (Files.exists(bios)) {
|
if (Files.exists(bios)) {
|
||||||
|
@ -1,51 +0,0 @@
|
|||||||
package pw.yumc.MiaoScript;
|
|
||||||
|
|
||||||
import org.bukkit.event.Cancellable;
|
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
|
|
||||||
import jdk.nashorn.api.scripting.ScriptObjectMirror;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created with IntelliJ IDEA
|
|
||||||
*
|
|
||||||
* @author 喵♂呜
|
|
||||||
* Created on 2017/9/30 21:32.
|
|
||||||
*/
|
|
||||||
public class ScriptEvent extends Event implements Cancellable {
|
|
||||||
private ScriptObjectMirror mirror;
|
|
||||||
private boolean cancelled = false;
|
|
||||||
|
|
||||||
public ScriptEvent(ScriptObjectMirror mirror) {
|
|
||||||
this.mirror = mirror;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ScriptObjectMirror getMirror() {
|
|
||||||
return mirror;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMirror(ScriptObjectMirror mirror) {
|
|
||||||
this.mirror = mirror;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCancelled() {
|
|
||||||
return cancelled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setCancelled(boolean cancel) {
|
|
||||||
this.cancelled = cancel;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static HandlerList handlerList = new HandlerList();
|
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlerList;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlerList;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +1,6 @@
|
|||||||
/*global Java, base, module, exports, require*/
|
/*global Java, base, module, exports, require*/
|
||||||
function ChatHandlerDefault() {
|
function ChatHandlerDefault() {
|
||||||
|
// noinspection JSUnusedGlobalSymbols
|
||||||
this.tellraw = function(sender, raw) {
|
this.tellraw = function(sender, raw) {
|
||||||
this.json(sender, JSON.stringify(raw));
|
this.json(sender, JSON.stringify(raw));
|
||||||
}
|
}
|
||||||
|
@ -2,16 +2,19 @@
|
|||||||
/**
|
/**
|
||||||
* Bukkit 事件相关类
|
* Bukkit 事件相关类
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*global Java, base, module, exports, require, __FILE__*/
|
/*global Java, base, module, exports, require, __FILE__*/
|
||||||
|
|
||||||
function EventHandlerDefault() {
|
function EventHandlerDefault() {
|
||||||
var Thread = Java.type("java.lang.Thread");
|
var Thread = Java.type("java.lang.Thread");
|
||||||
|
|
||||||
|
// noinspection JSUnresolvedVariable
|
||||||
this.plugin = require('./server').plugin.self;
|
this.plugin = require('./server').plugin.self;
|
||||||
this.mapEvent = [];
|
this.mapEvent = [];
|
||||||
this.listenerMap = [];
|
this.listenerMap = [];
|
||||||
this.baseEventDir = '';
|
this.baseEventDir = '';
|
||||||
|
|
||||||
|
// noinspection JSUnusedLocalSymbols
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,9 +43,10 @@ function EventHandlerDefault() {
|
|||||||
try {
|
try {
|
||||||
var clz = base.getClass(i.substring(0, i.length - 6));
|
var clz = base.getClass(i.substring(0, i.length - 6));
|
||||||
// 继承于 org.bukkit.event.Event 访问符为Public
|
// 继承于 org.bukkit.event.Event 访问符为Public
|
||||||
if (this.isVaildEvent(clz)) {
|
if (this.isValidEvent(clz)) {
|
||||||
// noinspection JSUnresolvedVariable
|
// noinspection JSUnresolvedVariable
|
||||||
var simpleName = this.class2Name(clz).toLowerCase();
|
var simpleName = this.class2Name(clz).toLowerCase();
|
||||||
|
/** @namespace clz.canonicalName */
|
||||||
console.debug("Mapping Event [%s] => %s".format(clz.canonicalName, simpleName));
|
console.debug("Mapping Event [%s] => %s".format(clz.canonicalName, simpleName));
|
||||||
this.mapEvent[simpleName] = clz;
|
this.mapEvent[simpleName] = clz;
|
||||||
count++;
|
count++;
|
||||||
@ -55,11 +59,11 @@ function EventHandlerDefault() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
};
|
||||||
|
|
||||||
this.class2Name = function class2Name(clazz) {
|
this.class2Name = function class2Name(clazz) {
|
||||||
return clazz.simpleName;
|
return clazz.simpleName;
|
||||||
}
|
};
|
||||||
|
|
||||||
this.name2Class = function name2Class(name, event) {
|
this.name2Class = function name2Class(name, event) {
|
||||||
var eventCls = this.mapEvent[event.toLowerCase()] || this.mapEvent[event.toLowerCase() + 'event'];
|
var eventCls = this.mapEvent[event.toLowerCase()] || this.mapEvent[event.toLowerCase() + 'event'];
|
||||||
@ -69,29 +73,30 @@ function EventHandlerDefault() {
|
|||||||
this.mapEvent[event] = eventCls;
|
this.mapEvent[event] = eventCls;
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.console("§6插件 §b%s §6注册事件 §c%s §6失败 §4事件未找到!".format(name, event));
|
console.console("§6插件 §b%s §6注册事件 §c%s §6失败 §4事件未找到!".format(name, event));
|
||||||
console.ex(new Error("插件 %s 注册事件 %s 失败 事件未找到!".format(name, event)))
|
console.ex(new Error("插件 %s 注册事件 %s 失败 事件未找到!".format(name, event)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return eventCls;
|
return eventCls;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
// noinspection JSUnusedLocalSymbols
|
||||||
/**
|
/**
|
||||||
* 判断是否为一个有效的事件类
|
* 判断是否为一个有效的事件类
|
||||||
* @param clz
|
* @param clz
|
||||||
* @returns {*|boolean}
|
* @returns {*|boolean}
|
||||||
*/
|
*/
|
||||||
this.isVaildEvent = function isVaildEvent(clz) {
|
this.isValidEvent = function isValidEvent(clz) {
|
||||||
throw new Error("当前服务器不支持事件系统!");
|
throw new Error("当前服务器不支持事件系统!");
|
||||||
}
|
};
|
||||||
|
// noinspection JSUnusedLocalSymbols
|
||||||
this.register = function register(eventCls, exec, priority, ignoreCancel) {
|
this.register = function register(eventCls, exec, priority, ignoreCancel) {
|
||||||
throw new Error("当前服务器不支持事件系统!");
|
throw new Error("当前服务器不支持事件系统!");
|
||||||
}
|
};
|
||||||
|
// noinspection JSUnusedLocalSymbols
|
||||||
this.unregister = function unregister(event, listener) {
|
this.unregister = function unregister(event, listener) {
|
||||||
throw new Error("当前服务器不支持事件系统!");
|
throw new Error("当前服务器不支持事件系统!");
|
||||||
}
|
};
|
||||||
|
|
||||||
this.execute = function execute(name, exec, eventCls) {
|
this.execute = function execute(name, exec, eventCls) {
|
||||||
return function execute() {
|
return function execute() {
|
||||||
@ -102,7 +107,7 @@ function EventHandlerDefault() {
|
|||||||
console.ex(ex);
|
console.ex(ex);
|
||||||
}
|
}
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加事件监听
|
* 添加事件监听
|
||||||
@ -116,7 +121,9 @@ function EventHandlerDefault() {
|
|||||||
if (!jsp || !jsp.description || !jsp.description.name) throw new TypeError('插件名称为空 请检查传入参数!');
|
if (!jsp || !jsp.description || !jsp.description.name) throw new TypeError('插件名称为空 请检查传入参数!');
|
||||||
var name = jsp.description.name;
|
var name = jsp.description.name;
|
||||||
var eventCls = this.name2Class(name, event);
|
var eventCls = this.name2Class(name, event);
|
||||||
if (!eventCls) { return; }
|
if (!eventCls) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (typeof priority === 'boolean') {
|
if (typeof priority === 'boolean') {
|
||||||
ignoreCancel = priority;
|
ignoreCancel = priority;
|
||||||
priority = 'NORMAL';
|
priority = 'NORMAL';
|
||||||
@ -143,6 +150,7 @@ function EventHandlerDefault() {
|
|||||||
return off;
|
return off;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var EventHandler = Object.assign(new EventHandlerDefault(), requireInternal('event'));
|
var EventHandler = Object.assign(new EventHandlerDefault(), requireInternal('event'));
|
||||||
// 映射事件名称
|
// 映射事件名称
|
||||||
console.info('%s 事件映射完毕 共计 %s 个事件!'.format(DetectServerType, EventHandler.mapEventName().toFixed(0)));
|
console.info('%s 事件映射完毕 共计 %s 个事件!'.format(DetectServerType, EventHandler.mapEventName().toFixed(0)));
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
/**
|
/**
|
||||||
* MiaoScript脚本插件加载类
|
* MiaoScript脚本插件加载类
|
||||||
|
* @namespace plugin.configFile.parentFile, command.enable, permission.enable
|
||||||
*/
|
*/
|
||||||
/*global Java, module, exports, require, __FILE__*/
|
/*global Java, module, exports, require, __FILE__*/
|
||||||
// var zip = require("core/zip");
|
|
||||||
var fs = require('core/fs');
|
var fs = require('core/fs');
|
||||||
var yaml = require('modules/yaml');
|
var yaml = require('modules/yaml');
|
||||||
var event = require('./event');
|
var event = require('./event');
|
||||||
@ -95,7 +95,7 @@ function readPlugin(file) {
|
|||||||
hook: function (origin) {
|
hook: function (origin) {
|
||||||
return beforeLoadHook(origin);
|
return beforeLoadHook(origin);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
console.debug("插件编译结果: %s".format(JSON.stringify(plugin)));
|
console.debug("插件编译结果: %s".format(JSON.stringify(plugin)));
|
||||||
plugin.__FILE__ = file;
|
plugin.__FILE__ = file;
|
||||||
return plugin;
|
return plugin;
|
||||||
@ -141,7 +141,7 @@ function internalInitPlugin(plugin) {
|
|||||||
// 初始化 getDataFolder()
|
// 初始化 getDataFolder()
|
||||||
plugin.getDataFolder = function getDataFolder() {
|
plugin.getDataFolder = function getDataFolder() {
|
||||||
return plugin.__DATA__;
|
return plugin.__DATA__;
|
||||||
}
|
};
|
||||||
// 初始化 getFile()
|
// 初始化 getFile()
|
||||||
plugin.getFile = plugin.file = function getFile(name) {
|
plugin.getFile = plugin.file = function getFile(name) {
|
||||||
return fs.file(plugin.getDataFolder(), name);
|
return fs.file(plugin.getDataFolder(), name);
|
||||||
@ -149,7 +149,9 @@ function internalInitPlugin(plugin) {
|
|||||||
// 初始化插件配置相关方法
|
// 初始化插件配置相关方法
|
||||||
initPluginConfig(plugin);
|
initPluginConfig(plugin);
|
||||||
|
|
||||||
|
/** @namespace command.enable */
|
||||||
if (command.enable) command.enable(plugin);
|
if (command.enable) command.enable(plugin);
|
||||||
|
/** @namespace permission.enable */
|
||||||
if (permission.enable) permission.enable(plugin);
|
if (permission.enable) permission.enable(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +177,7 @@ function initPluginConfig(plugin) {
|
|||||||
}
|
}
|
||||||
return yaml.safeLoad(fs.read(file), {json: true});
|
return yaml.safeLoad(fs.read(file), {json: true});
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
/**
|
/**
|
||||||
* 重载配置文件
|
* 重载配置文件
|
||||||
* @constructor
|
* @constructor
|
||||||
@ -183,7 +185,7 @@ function initPluginConfig(plugin) {
|
|||||||
*/
|
*/
|
||||||
plugin.reloadConfig = function () {
|
plugin.reloadConfig = function () {
|
||||||
plugin.config = plugin.getConfig(plugin.configFile);
|
plugin.config = plugin.getConfig(plugin.configFile);
|
||||||
}
|
};
|
||||||
/**
|
/**
|
||||||
* 保存配置文件
|
* 保存配置文件
|
||||||
* @constructor
|
* @constructor
|
||||||
@ -191,6 +193,7 @@ function initPluginConfig(plugin) {
|
|||||||
*/
|
*/
|
||||||
plugin.saveConfig = function () {
|
plugin.saveConfig = function () {
|
||||||
// 判断插件目录是否存在 并且不为文件 否则删除重建
|
// 判断插件目录是否存在 并且不为文件 否则删除重建
|
||||||
|
// noinspection JSValidateTypes
|
||||||
if (!plugin.configFile.parentFile.isDirectory()) {
|
if (!plugin.configFile.parentFile.isDirectory()) {
|
||||||
fs.del(plugin.configFile.parentFile);
|
fs.del(plugin.configFile.parentFile);
|
||||||
}
|
}
|
||||||
@ -203,7 +206,8 @@ function initPluginConfig(plugin) {
|
|||||||
fs.save(fs.file(plugin.__DATA__, arguments[0]), yaml.safeDump(arguments[1]));
|
fs.save(fs.file(plugin.__DATA__, arguments[0]), yaml.safeDump(arguments[1]));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
// noinspection JSValidateTypes
|
||||||
if (plugin.configFile.isFile()) {
|
if (plugin.configFile.isFile()) {
|
||||||
plugin.config = plugin.getConfig('config.yml');
|
plugin.config = plugin.getConfig('config.yml');
|
||||||
} else if (plugin.description.config) {
|
} else if (plugin.description.config) {
|
||||||
@ -247,27 +251,27 @@ function checkAndRun(args, name, ext) {
|
|||||||
var plugins = [];
|
var plugins = [];
|
||||||
|
|
||||||
function init(path) {
|
function init(path) {
|
||||||
var plugin = exports.$
|
var plugin = exports.$;
|
||||||
if (plugin !== null) {
|
if (plugin !== null) {
|
||||||
// 如果plugin不等于null 则代表是正式环境
|
// 如果plugin不等于null 则代表是正式环境
|
||||||
console.info("初始化 MiaoScript 插件系统: %s".format(plugin));
|
console.info("初始化 MiaoScript 插件系统: %s".format(plugin));
|
||||||
}
|
}
|
||||||
loadPlugins(path);
|
loadPlugins(path);
|
||||||
};
|
}
|
||||||
|
|
||||||
function load() {
|
function load() {
|
||||||
checkAndRun(arguments, 'load');
|
checkAndRun(arguments, 'load');
|
||||||
};
|
}
|
||||||
|
|
||||||
function enable() {
|
function enable() {
|
||||||
checkAndRun(arguments, 'enable');
|
checkAndRun(arguments, 'enable');
|
||||||
};
|
}
|
||||||
|
|
||||||
function disable() {
|
function disable() {
|
||||||
checkAndRun(arguments, 'disable', function eventDisable() {
|
checkAndRun(arguments, 'disable', function eventDisable() {
|
||||||
event.disable(this);
|
event.disable(this);
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
function reload() {
|
function reload() {
|
||||||
checkAndGet(arguments).forEach(function (p) {
|
checkAndGet(arguments).forEach(function (p) {
|
||||||
@ -276,8 +280,9 @@ function reload() {
|
|||||||
load(p);
|
load(p);
|
||||||
enable(p);
|
enable(p);
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
|
// noinspection JSUnresolvedVariable
|
||||||
exports = module.exports = {
|
exports = module.exports = {
|
||||||
$: server.plugin.self,
|
$: server.plugin.self,
|
||||||
plugins: plugins,
|
plugins: plugins,
|
||||||
@ -287,4 +292,4 @@ exports = module.exports = {
|
|||||||
disable: disable,
|
disable: disable,
|
||||||
reload: reload,
|
reload: reload,
|
||||||
loadPlugin: loadPlugin
|
loadPlugin: loadPlugin
|
||||||
}
|
};
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
var player = requireInternal('wrapper/player');
|
var player = requireInternal('wrapper/player');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
player: player.$
|
player: player.$
|
||||||
}
|
};
|
@ -2,6 +2,7 @@
|
|||||||
var log;
|
var log;
|
||||||
var boot;
|
var boot;
|
||||||
var disable;
|
var disable;
|
||||||
|
// noinspection ThisExpressionReferencesGlobalObjectJS
|
||||||
var global = this;
|
var global = this;
|
||||||
/**
|
/**
|
||||||
* 初始化框架引擎
|
* 初始化框架引擎
|
||||||
@ -35,6 +36,7 @@ var global = this;
|
|||||||
var pluginYml;
|
var pluginYml;
|
||||||
|
|
||||||
function checkClassLoader() {
|
function checkClassLoader() {
|
||||||
|
// noinspection JSUnresolvedVariable
|
||||||
var classLoader = java.lang.Thread.currentThread().contextClassLoader;
|
var classLoader = java.lang.Thread.currentThread().contextClassLoader;
|
||||||
pluginYml = classLoader.getResource("plugin.yml");
|
pluginYml = classLoader.getResource("plugin.yml");
|
||||||
if (pluginYml === null) {
|
if (pluginYml === null) {
|
||||||
@ -47,8 +49,8 @@ var global = this;
|
|||||||
}
|
}
|
||||||
|
|
||||||
function release(root, regex, replace) {
|
function release(root, regex, replace) {
|
||||||
var upath = pluginYml.getFile().substring(pluginYml.getFile().indexOf("/") + 1);
|
var filePath = pluginYml.getFile().substring(pluginYml.getFile().indexOf("/") + 1);
|
||||||
var jarPath = java.net.URLDecoder.decode(upath.substring(0, upath.indexOf('!')));
|
var jarPath = java.net.URLDecoder.decode(filePath.substring(0, filePath.indexOf('!')));
|
||||||
if (!java.nio.file.Files.exists(java.nio.file.Paths.get(jarPath))) {
|
if (!java.nio.file.Files.exists(java.nio.file.Paths.get(jarPath))) {
|
||||||
jarPath = "/" + jarPath;
|
jarPath = "/" + jarPath;
|
||||||
}
|
}
|
||||||
@ -56,9 +58,11 @@ var global = this;
|
|||||||
var r = new RegExp(regex);// "[core|modules]/.*"
|
var r = new RegExp(regex);// "[core|modules]/.*"
|
||||||
jar.stream().forEach(function (entry) {
|
jar.stream().forEach(function (entry) {
|
||||||
try {
|
try {
|
||||||
|
// noinspection JSValidateTypes
|
||||||
if (!entry.isDirectory()) {
|
if (!entry.isDirectory()) {
|
||||||
if (r.test(entry.name)) {
|
if (r.test(entry.name)) {
|
||||||
var path = java.nio.file.Paths.get(root, entry.name);
|
var path = java.nio.file.Paths.get(root, entry.name);
|
||||||
|
// noinspection JSUnresolvedVariable
|
||||||
var parentFile = path.toFile().parentFile;
|
var parentFile = path.toFile().parentFile;
|
||||||
if (!parentFile.exists()) { parentFile.mkdirs(); }
|
if (!parentFile.exists()) { parentFile.mkdirs(); }
|
||||||
if (!java.nio.file.Files.exists(path) || replace) {
|
if (!java.nio.file.Files.exists(path) || replace) {
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
}.bind(this),
|
}.bind(this),
|
||||||
set: function (name) {
|
set: function (name) {
|
||||||
this._name = name ? '[' + name + '] ' : '';
|
this._name = name ? '[' + name + '] ' : '';
|
||||||
|
// noinspection JSUnusedGlobalSymbols
|
||||||
this.prefix = name ? '§6[§cMS§6][§b' + name + '§6]§r ' : '§6[§bMiaoScript§6]§r ';
|
this.prefix = name ? '§6[§cMS§6][§b' + name + '§6]§r ' : '§6[§bMiaoScript§6]§r ';
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
});
|
});
|
||||||
@ -19,6 +20,7 @@
|
|||||||
this.log = this.info = function () {
|
this.log = this.info = function () {
|
||||||
log.info(this.name + Array.prototype.join.call(arguments, ' '));
|
log.info(this.name + Array.prototype.join.call(arguments, ' '));
|
||||||
};
|
};
|
||||||
|
// noinspection JSUnusedGlobalSymbols
|
||||||
this.warn = function () {
|
this.warn = function () {
|
||||||
log.warning(this.name + Array.prototype.join.call(arguments, ' '));
|
log.warning(this.name + Array.prototype.join.call(arguments, ' '));
|
||||||
};
|
};
|
||||||
@ -35,7 +37,7 @@
|
|||||||
for (var i in obj) {
|
for (var i in obj) {
|
||||||
this.log(i, '=>', obj[i])
|
this.log(i, '=>', obj[i])
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
this.ex = function (message, ex) {
|
this.ex = function (message, ex) {
|
||||||
if (!ex) {
|
if (!ex) {
|
||||||
this.console('§4' + message);
|
this.console('§4' + message);
|
||||||
@ -55,6 +57,6 @@
|
|||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
global.Console = ConsoleDefault;
|
global.Console = ConsoleDefault;
|
||||||
})(global);
|
})(global);
|
@ -3,18 +3,21 @@
|
|||||||
/*global Java, base, module, exports, require, __FILE__*/
|
/*global Java, base, module, exports, require, __FILE__*/
|
||||||
var File = Java.type("java.io.File");
|
var File = Java.type("java.io.File");
|
||||||
var Files = Java.type("java.nio.file.Files");
|
var Files = Java.type("java.nio.file.Files");
|
||||||
|
// noinspection JSUnresolvedVariable
|
||||||
var separatorChar = File.separatorChar;
|
var separatorChar = File.separatorChar;
|
||||||
var StandardCopyOption = Java.type("java.nio.file.StandardCopyOption");
|
var StandardCopyOption = Java.type("java.nio.file.StandardCopyOption");
|
||||||
|
// noinspection JSUnusedLocalSymbols
|
||||||
var _toString = function (obj) {
|
var _toString = function (obj) {
|
||||||
return Object.prototype.toString.call(obj);
|
return Object.prototype.toString.call(obj);
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用文件分割符合并路径
|
* 用文件分割符合并路径
|
||||||
*/
|
*/
|
||||||
function concat() {
|
function concat() {
|
||||||
return Array.prototype.join.call(arguments, separatorChar);
|
return Array.prototype.join.call(arguments, separatorChar);
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得文件
|
* 获得文件
|
||||||
* @constructor(file)
|
* @constructor(file)
|
||||||
@ -27,39 +30,43 @@ function file() {
|
|||||||
}
|
}
|
||||||
switch (arguments.length) {
|
switch (arguments.length) {
|
||||||
case 1:
|
case 1:
|
||||||
var f = arguments[0]
|
var f = arguments[0];
|
||||||
if (f instanceof File) {
|
if (f instanceof File) {
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
if (typeof f === "string") {
|
if (typeof f === "string") {
|
||||||
return new File(f);
|
return new File(f);
|
||||||
}
|
}
|
||||||
if (f instanceof Path) {
|
if (f instanceof java.nio.file.Path) {
|
||||||
return f.toFile();
|
return f.toFile();
|
||||||
}
|
}
|
||||||
case 2:
|
break;
|
||||||
|
default:
|
||||||
return new File(exports.file(arguments[0]), arguments[1]);
|
return new File(exports.file(arguments[0]), arguments[1]);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建目录
|
* 创建目录
|
||||||
* @param file
|
* @param path
|
||||||
*/
|
*/
|
||||||
function mkdirs(path) {
|
function mkdirs(path) {
|
||||||
// noinspection JSUnresolvedVariable
|
// noinspection JSUnresolvedVariable
|
||||||
fs.file(path).parentFile.mkdirs();
|
fs.file(path).parentFile.mkdirs();
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建文件
|
* 创建文件
|
||||||
* @param file
|
* @param file
|
||||||
*/
|
*/
|
||||||
function create(path) {
|
function create(file) {
|
||||||
var file = fs.file(path)
|
var f = fs.file(path);
|
||||||
if (!file.exists()) {
|
if (!f.exists()) {
|
||||||
mkdirs(file);
|
mkdirs(f);
|
||||||
file.createNewFile();
|
f.createNewFile();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得文件规范路径
|
* 获得文件规范路径
|
||||||
* @param file
|
* @param file
|
||||||
@ -68,7 +75,8 @@ function create(path) {
|
|||||||
function path(file) {
|
function path(file) {
|
||||||
// noinspection JSUnresolvedVariable
|
// noinspection JSUnresolvedVariable
|
||||||
return fs.file(file).canonicalPath;
|
return fs.file(file).canonicalPath;
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 复制文件
|
* 复制文件
|
||||||
* @param inputStream 输入流
|
* @param inputStream 输入流
|
||||||
@ -77,7 +85,8 @@ function path(file) {
|
|||||||
*/
|
*/
|
||||||
function copy(inputStream, target, override) {
|
function copy(inputStream, target, override) {
|
||||||
Files.copy(inputStream, target.toPath(), StandardCopyOption[override ? 'REPLACE_EXISTING' : 'ATOMIC_MOVE']);
|
Files.copy(inputStream, target.toPath(), StandardCopyOption[override ? 'REPLACE_EXISTING' : 'ATOMIC_MOVE']);
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 读取文件
|
* 读取文件
|
||||||
* @param path 文件路径
|
* @param path 文件路径
|
||||||
@ -90,7 +99,8 @@ function read(path) {
|
|||||||
}
|
}
|
||||||
// noinspection JSPrimitiveTypeWrapperUsage
|
// noinspection JSPrimitiveTypeWrapperUsage
|
||||||
return new java.lang.String(Files.readAllBytes(file.toPath()), "UTF-8");
|
return new java.lang.String(Files.readAllBytes(file.toPath()), "UTF-8");
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存内容文件
|
* 保存内容文件
|
||||||
* @param path 路径
|
* @param path 路径
|
||||||
@ -101,19 +111,22 @@ function save(path, content, override) {
|
|||||||
var file = fs.file(path);
|
var file = fs.file(path);
|
||||||
file.getParentFile().mkdirs();
|
file.getParentFile().mkdirs();
|
||||||
Files.write(file.toPath(), new java.lang.String(content).getBytes("UTF-8"));
|
Files.write(file.toPath(), new java.lang.String(content).getBytes("UTF-8"));
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 列出目录文件
|
* 列出目录文件
|
||||||
* @param path
|
* @param path
|
||||||
*/
|
*/
|
||||||
function list(path) {
|
function list(path) {
|
||||||
var dir = file(path);
|
var dir = file(path);
|
||||||
|
// noinspection JSValidateTypes
|
||||||
if (dir.isDirectory()) {
|
if (dir.isDirectory()) {
|
||||||
return Files.list(dir.toPath());
|
return Files.list(dir.toPath());
|
||||||
}
|
}
|
||||||
console.debug('路径', path, '不是一个目录 返回空数组!');
|
console.debug('路径', path, '不是一个目录 返回空数组!');
|
||||||
return [];
|
return [];
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 移动文件
|
* 移动文件
|
||||||
* @param src 原始目录
|
* @param src 原始目录
|
||||||
@ -123,29 +136,37 @@ function list(path) {
|
|||||||
function move(src, des, override) {
|
function move(src, des, override) {
|
||||||
Files.move(fs.file(src).toPath(), fs.file(des).toPath(),
|
Files.move(fs.file(src).toPath(), fs.file(des).toPath(),
|
||||||
override ? StandardCopyOption['REPLACE_EXISTING'] : StandardCopyOption['ATOMIC_MOVE'])
|
override ? StandardCopyOption['REPLACE_EXISTING'] : StandardCopyOption['ATOMIC_MOVE'])
|
||||||
};
|
}
|
||||||
|
|
||||||
function del(file) {
|
function del(file) {
|
||||||
file = fs.file(file);
|
file = fs.file(file);
|
||||||
if (!file.exists()) { return; }
|
if (!file.exists()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// noinspection JSValidateTypes
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
Files.list(file.toPath()).collect(Collectors.toList()).forEach(function (f) { del(f); })
|
// noinspection JSUnresolvedVariable
|
||||||
|
Files.list(file.toPath()).collect(java.util.stream.Collector.toList()).forEach(function (f) {
|
||||||
|
del(f);
|
||||||
|
})
|
||||||
}
|
}
|
||||||
Files.delete(file.toPath());
|
Files.delete(file.toPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// noinspection JSUnusedLocalSymbols
|
||||||
function exists(file) {
|
function exists(file) {
|
||||||
return fs.file(file).exists()
|
return fs.file(file).exists()
|
||||||
}
|
}
|
||||||
|
|
||||||
var fs = {};
|
var fs = {};
|
||||||
|
|
||||||
fs.path = fs.canonical = fs.realpath = path
|
fs.path = fs.canonical = fs.realpath = path;
|
||||||
fs.write = fs.save = save
|
fs.write = fs.save = save;
|
||||||
fs.readdir = fs.list = list
|
fs.readdir = fs.list = list;
|
||||||
fs.rename = fs.move = move
|
fs.rename = fs.move = move;
|
||||||
fs.delete = fs.del = del
|
fs.delete = fs.del = del;
|
||||||
|
|
||||||
|
// noinspection JSUnusedGlobalSymbols
|
||||||
Object.assign(fs, {
|
Object.assign(fs, {
|
||||||
concat: concat,
|
concat: concat,
|
||||||
create: create,
|
create: create,
|
||||||
@ -153,6 +174,6 @@ Object.assign(fs, {
|
|||||||
file: file,
|
file: file,
|
||||||
copy: copy,
|
copy: copy,
|
||||||
read: read
|
read: read
|
||||||
})
|
});
|
||||||
|
|
||||||
exports = module.exports = fs
|
exports = module.exports = fs;
|
@ -38,7 +38,7 @@
|
|||||||
global.engineLoad = load;
|
global.engineLoad = load;
|
||||||
global.load = function __denyGlobalLoad__() {
|
global.load = function __denyGlobalLoad__() {
|
||||||
throw new Error('系统内部不许允许使用 load 如需执行脚本 请使用 engineLoad !');
|
throw new Error('系统内部不许允许使用 load 如需执行脚本 请使用 engineLoad !');
|
||||||
}
|
};
|
||||||
// 初始化加载器
|
// 初始化加载器
|
||||||
global.require = engineLoad(root + '/core/require.js')(root);
|
global.require = engineLoad(root + '/core/require.js')(root);
|
||||||
global.requireInternal = function requireInternal(name) {
|
global.requireInternal = function requireInternal(name) {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
* 补丁和方法扩展
|
* 补丁和方法扩展
|
||||||
*/
|
*/
|
||||||
(function () {
|
(function () {
|
||||||
|
// noinspection JSUnresolvedVariable
|
||||||
if (!Array.prototype.copyPartialMatches) {
|
if (!Array.prototype.copyPartialMatches) {
|
||||||
Object.defineProperty(Array.prototype, "copyPartialMatches", {
|
Object.defineProperty(Array.prototype, "copyPartialMatches", {
|
||||||
enumerable: false,
|
enumerable: false,
|
||||||
@ -10,7 +11,7 @@
|
|||||||
if (e.toLowerCase().startsWith(token.toLowerCase())) {
|
if (e.toLowerCase().startsWith(token.toLowerCase())) {
|
||||||
array.push(e)
|
array.push(e)
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
return array
|
return array
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
* @param fmt 格式化字符串
|
* @param fmt 格式化字符串
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
Date.prototype.format = function (fmt) { //author: meizz
|
Date.prototype.format = function (fmt) {
|
||||||
var o = {
|
var o = {
|
||||||
"M+": this.getMonth() + 1, //月份
|
"M+": this.getMonth() + 1, //月份
|
||||||
"d+": this.getDate(), //日
|
"d+": this.getDate(), //日
|
||||||
|
@ -36,12 +36,12 @@
|
|||||||
writable: true,
|
writable: true,
|
||||||
value: function (target) {
|
value: function (target) {
|
||||||
"use strict";
|
"use strict";
|
||||||
var vals = [];
|
var values = [];
|
||||||
for (var key in target) {
|
for (var key in target) {
|
||||||
var desc = Object.getOwnPropertyDescriptor(target, key);
|
var desc = Object.getOwnPropertyDescriptor(target, key);
|
||||||
if (desc !== undefined && desc.enumerable) vals.push(target[key]);
|
if (desc !== undefined && desc.enumerable) values.push(target[key]);
|
||||||
}
|
}
|
||||||
return vals;
|
return values;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* 补丁和方法扩展
|
* 补丁和方法扩展
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
// Java格式化方法
|
// Java格式化方法
|
||||||
var str = Java.type('java.lang.String');
|
var str = Java.type('java.lang.String');
|
||||||
|
@ -129,6 +129,7 @@
|
|||||||
var _package = new File(dir, 'package.json');
|
var _package = new File(dir, 'package.json');
|
||||||
if (_package.exists()) {
|
if (_package.exists()) {
|
||||||
var json = JSON.parse(base.read(_package));
|
var json = JSON.parse(base.read(_package));
|
||||||
|
/** @namespace json.main */
|
||||||
if (json.main) {
|
if (json.main) {
|
||||||
return resolveAsFile(dir, json.main);
|
return resolveAsFile(dir, json.main);
|
||||||
}
|
}
|
||||||
@ -181,6 +182,7 @@
|
|||||||
compileJson(module, file, optional);
|
compileJson(module, file, optional);
|
||||||
}
|
}
|
||||||
if (_canonical(file).endsWith('.msm')) {
|
if (_canonical(file).endsWith('.msm')) {
|
||||||
|
// noinspection ExceptionCaughtLocallyJS
|
||||||
throw Error("暂不支持解析 MiaoScript 模块");
|
throw Error("暂不支持解析 MiaoScript 模块");
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
@ -192,6 +194,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 预编译JS
|
* 预编译JS
|
||||||
|
* @param module JS模块
|
||||||
* @param file JS文件
|
* @param file JS文件
|
||||||
* @param optional 附加选项
|
* @param optional 附加选项
|
||||||
* @returns {Object}
|
* @returns {Object}
|
||||||
@ -218,6 +221,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 预编译Json
|
* 预编译Json
|
||||||
|
* @param module Json模块
|
||||||
* @param file Json 文件
|
* @param file Json 文件
|
||||||
* @param optional 附加选项
|
* @param optional 附加选项
|
||||||
* @returns {Object}
|
* @returns {Object}
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
var bukkit = require('api/server');
|
var bukkit = require('api/server');
|
||||||
|
|
||||||
var nmsChatSerializerClass;
|
var nmsChatSerializerClass;
|
||||||
var nmsIChatBaseComponentClass;
|
|
||||||
var packetTypeClass;
|
var packetTypeClass;
|
||||||
var nmsChatMessageTypeClass;
|
var nmsChatMessageTypeClass;
|
||||||
|
|
||||||
@ -11,22 +10,28 @@ var chatMessageTypes;
|
|||||||
var String = Java.type('java.lang.String');
|
var String = Java.type('java.lang.String');
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
|
/** @namespace bukkit.nmsVersion */
|
||||||
nmsChatSerializerClass = bukkit.nmsCls(bukkit.nmsVersion.split("_")[1] > 7 ? "IChatBaseComponent$ChatSerializer" : "ChatSerializer");
|
nmsChatSerializerClass = bukkit.nmsCls(bukkit.nmsVersion.split("_")[1] > 7 ? "IChatBaseComponent$ChatSerializer" : "ChatSerializer");
|
||||||
nmsIChatBaseComponentClass = bukkit.nmsCls('IChatBaseComponent');
|
|
||||||
packetTypeClass = bukkit.nmsCls("PacketPlayOutChat");
|
packetTypeClass = bukkit.nmsCls("PacketPlayOutChat");
|
||||||
var packetTypeConstructor;
|
var packetTypeConstructor;
|
||||||
Java.from(packetTypeClass.class.constructors).forEach(function (c) {
|
Java.from(packetTypeClass.class.constructors).forEach(function (c) {
|
||||||
if (c.parameterTypes.length == 2) { packetTypeConstructor = c };
|
if (c.parameterTypes.length === 2) {
|
||||||
})
|
packetTypeConstructor = c
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// noinspection JSUnusedAssignment
|
||||||
nmsChatMessageTypeClass = packetTypeConstructor.parameterTypes[1];
|
nmsChatMessageTypeClass = packetTypeConstructor.parameterTypes[1];
|
||||||
if (nmsChatMessageTypeClass.isEnum()) {
|
if (nmsChatMessageTypeClass.isEnum()) {
|
||||||
chatMessageTypes = nmsChatMessageTypeClass.getEnumConstants();
|
chatMessageTypes = nmsChatMessageTypeClass.getEnumConstants();
|
||||||
} else {
|
} else {
|
||||||
|
/** @namespace nmsChatMessageTypeClass.name */
|
||||||
switch (nmsChatMessageTypeClass.name) {
|
switch (nmsChatMessageTypeClass.name) {
|
||||||
case "int":
|
case "int":
|
||||||
nmsChatMessageTypeClass = java.lang.Integer;
|
nmsChatMessageTypeClass = java.lang.Integer;
|
||||||
|
break;
|
||||||
case "byte":
|
case "byte":
|
||||||
nmsChatMessageTypeClass = java.lang.Byte;
|
nmsChatMessageTypeClass = java.lang.Byte;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -36,7 +41,8 @@ function json(sender, json) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function send(sender, json, type) {
|
function send(sender, json, type) {
|
||||||
var serialized = nmsChatSerializerClass.a(json)
|
var serialized = nmsChatSerializerClass.a(json);
|
||||||
|
// noinspection all
|
||||||
var typeObj = chatMessageTypes == null ? nmsChatMessageTypeClass.valueOf(String.valueOf(type)) : chatMessageTypes[type];
|
var typeObj = chatMessageTypes == null ? nmsChatMessageTypeClass.valueOf(String.valueOf(type)) : chatMessageTypes[type];
|
||||||
sendPacket(sender, new packetTypeClass(serialized, typeObj))
|
sendPacket(sender, new packetTypeClass(serialized, typeObj))
|
||||||
}
|
}
|
||||||
|
@ -10,34 +10,37 @@ var plugin = bukkit.plugin.self;
|
|||||||
var commandMap = ref.on(bukkit.plugin.manager).get('commandMap').get();
|
var commandMap = ref.on(bukkit.plugin.manager).get('commandMap').get();
|
||||||
var PluginCommand = Java.type('org.bukkit.command.PluginCommand');
|
var PluginCommand = Java.type('org.bukkit.command.PluginCommand');
|
||||||
|
|
||||||
var StringUtil = Java.type('org.bukkit.util.StringUtil');
|
|
||||||
|
|
||||||
var ArrayList = Java.type('java.util.ArrayList');
|
|
||||||
var Arrays = Java.type('java.util.Arrays');
|
var Arrays = Java.type('java.util.Arrays');
|
||||||
|
|
||||||
function enable(jsp) {
|
function enable(jsp) {
|
||||||
var commands = jsp.description.commands;
|
var commands = jsp.description.commands;
|
||||||
if (commands) {
|
if (commands) {
|
||||||
var pluginCmds = [];
|
var pluginCommands = [];
|
||||||
for (var name in commands) {
|
for (var name in commands) {
|
||||||
|
// noinspection JSUnfilteredForInLoop
|
||||||
var command = commands[name];
|
var command = commands[name];
|
||||||
if (typeof command !== 'object') continue;
|
if (typeof command !== 'object') continue;
|
||||||
|
// noinspection JSUnfilteredForInLoop
|
||||||
var newCmd = create(jsp, name);
|
var newCmd = create(jsp, name);
|
||||||
if (command.description) newCmd.setDescription(command.description);
|
if (command.description) newCmd.setDescription(command.description);
|
||||||
if (command.usage) newCmd.setUsage(command.usage);
|
if (command.usage) newCmd.setUsage(command.usage);
|
||||||
|
/** @namespace command.aliases */
|
||||||
if (command.aliases) newCmd.setAliases(Arrays.asList(command.aliases));
|
if (command.aliases) newCmd.setAliases(Arrays.asList(command.aliases));
|
||||||
if (command.permission) newCmd.setPermission(command.permission);
|
if (command.permission) newCmd.setPermission(command.permission);
|
||||||
if (command['permission-message']) newCmd.setPermissionMessage(command['permission-message']);
|
if (command['permission-message']) newCmd.setPermissionMessage(command['permission-message']);
|
||||||
pluginCmds.push(newCmd);
|
pluginCommands.push(newCmd);
|
||||||
|
// noinspection JSUnfilteredForInLoop
|
||||||
console.debug('插件 %s 注册命令 %s ...'.format(jsp.description.name, name));
|
console.debug('插件 %s 注册命令 %s ...'.format(jsp.description.name, name));
|
||||||
}
|
}
|
||||||
commandMap.registerAll(jsp.description.name, Arrays.asList(pluginCmds));
|
commandMap.registerAll(jsp.description.name, Arrays.asList(pluginCommands));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// noinspection JSUnusedLocalSymbols
|
||||||
function disable(jsp) {
|
function disable(jsp) {
|
||||||
var commands = jsp.description.commands;
|
var commands = jsp.description.commands;
|
||||||
if (commands) {
|
if (commands) {
|
||||||
|
// noinspection JSUnusedLocalSymbols
|
||||||
for (var name in commands) {
|
for (var name in commands) {
|
||||||
//TODO 删除插件命令
|
//TODO 删除插件命令
|
||||||
}
|
}
|
||||||
@ -62,6 +65,7 @@ function on(jsp, name, exec) {
|
|||||||
console.debug('插件 %s 设置命令 %s(%s) 执行器 ...'.format(jsp.description.name, name, c));
|
console.debug('插件 %s 设置命令 %s(%s) 执行器 ...'.format(jsp.description.name, name, c));
|
||||||
if (exec.cmd) {
|
if (exec.cmd) {
|
||||||
// 必须指定需要实现的接口类型 否则MOD服会报错
|
// 必须指定需要实现的接口类型 否则MOD服会报错
|
||||||
|
// noinspection JSUnusedGlobalSymbols
|
||||||
c.setExecutor(new org.bukkit.command.CommandExecutor({
|
c.setExecutor(new org.bukkit.command.CommandExecutor({
|
||||||
onCommand: function (sender, cmd, command, args) {
|
onCommand: function (sender, cmd, command, args) {
|
||||||
try {
|
try {
|
||||||
@ -76,12 +80,13 @@ function on(jsp, name, exec) {
|
|||||||
}
|
}
|
||||||
if (exec.tab) {
|
if (exec.tab) {
|
||||||
// 必须指定需要实现的接口类型 否则MOD服会报错
|
// 必须指定需要实现的接口类型 否则MOD服会报错
|
||||||
|
// noinspection JSUnusedGlobalSymbols
|
||||||
c.setTabCompleter(new org.bukkit.command.TabCompleter({
|
c.setTabCompleter(new org.bukkit.command.TabCompleter({
|
||||||
onTabComplete: function (sender, cmd, command, args) {
|
onTabComplete: function (sender, cmd, command, args) {
|
||||||
try {
|
try {
|
||||||
var token = args[args.length - 1];
|
var token = args[args.length - 1];
|
||||||
var complate = exec.tab(sender, command, args) || []
|
var complete = exec.tab(sender, command, args) || [];
|
||||||
return Arrays.asList(complate.copyPartialMatches(token, []));
|
return Arrays.asList(complete.copyPartialMatches(token, []));
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.console('§6玩家 §a%s §6执行 §b%s §6插件 §d%s %s §6补全时发生异常 §4%s'
|
console.console('§6玩家 §a%s §6执行 §b%s §6插件 §d%s %s §6补全时发生异常 §4%s'
|
||||||
.format(sender.name, jsp.description.name, command, Java.from(args).join(' '), ex));
|
.format(sender.name, jsp.description.name, command, Java.from(args).join(' '), ex));
|
||||||
|
@ -15,7 +15,7 @@ var EventExecutor = Java.type("org.bukkit.plugin.EventExecutor");
|
|||||||
* @param clz
|
* @param clz
|
||||||
* @returns {*|boolean}
|
* @returns {*|boolean}
|
||||||
*/
|
*/
|
||||||
function isVaildEvent(clz) {
|
function isValidEvent(clz) {
|
||||||
// noinspection JSUnresolvedVariable 继承于 org.bukkit.event.Event
|
// noinspection JSUnresolvedVariable 继承于 org.bukkit.event.Event
|
||||||
return Event.class.isAssignableFrom(clz) &&
|
return Event.class.isAssignableFrom(clz) &&
|
||||||
// 访问符为Public
|
// 访问符为Public
|
||||||
@ -44,7 +44,7 @@ function unregister(event, listener) {
|
|||||||
|
|
||||||
exports = module.exports = {
|
exports = module.exports = {
|
||||||
baseEventDir: 'org/bukkit/event',
|
baseEventDir: 'org/bukkit/event',
|
||||||
isVaildEvent: isVaildEvent,
|
isValidEvent: isValidEvent,
|
||||||
register: register,
|
register: register,
|
||||||
unregister: unregister
|
unregister: unregister
|
||||||
};
|
};
|
@ -16,15 +16,18 @@ function enable(plugin) {
|
|||||||
var permissions = plugin.description.permissions;
|
var permissions = plugin.description.permissions;
|
||||||
if (permissions) {
|
if (permissions) {
|
||||||
for (var name in permissions) {
|
for (var name in permissions) {
|
||||||
|
// noinspection JSUnfilteredForInLoop
|
||||||
var permission = permissions[name];
|
var permission = permissions[name];
|
||||||
if (typeof permission !== 'object') continue;
|
if (typeof permission !== 'object') continue;
|
||||||
var desc = permission.description;
|
var desc = permission.description;
|
||||||
var def = permission.default || 'OP';
|
var def = permission.default || 'OP';
|
||||||
try {
|
try {
|
||||||
|
// noinspection JSUnfilteredForInLoop
|
||||||
manager.addPermission(new Permission(name, desc, PermissionDefault.getByName(def)));
|
manager.addPermission(new Permission(name, desc, PermissionDefault.getByName(def)));
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
// ignore eg: java.lang.IllegalArgumentException: The permission xxxxxx.default is already defined!
|
// ignore eg: java.lang.IllegalArgumentException: The permission xxxxxx.default is already defined!
|
||||||
}
|
}
|
||||||
|
// noinspection JSUnfilteredForInLoop
|
||||||
console.debug('插件 %s 注册权限 %s Default %s ...'.format(plugin.description.name, name, def));
|
console.debug('插件 %s 注册权限 %s Default %s ...'.format(plugin.description.name, name, def));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -35,10 +38,12 @@ function disable(plugin) {
|
|||||||
if (permissions) {
|
if (permissions) {
|
||||||
for (var name in permissions) {
|
for (var name in permissions) {
|
||||||
try {
|
try {
|
||||||
|
// noinspection JSUnfilteredForInLoop
|
||||||
manager.removePermission(name);
|
manager.removePermission(name);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
// ignore eg: java.lang.IllegalArgumentException: The permission xxxxxx.default is already defined!
|
// ignore eg: java.lang.IllegalArgumentException: The permission xxxxxx.default is already defined!
|
||||||
}
|
}
|
||||||
|
// noinspection JSUnfilteredForInLoop
|
||||||
console.debug('插件 %s 注销权限 %s ...'.format(plugin.description.name, name));
|
console.debug('插件 %s 注销权限 %s ...'.format(plugin.description.name, name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
/*global Java, base, module, exports, require, __FILE__*/
|
/*global Java, base, module, exports, require, __FILE__*/
|
||||||
var Bukkit = MServer;
|
var Bukkit = MServer;
|
||||||
var Server = Bukkit.server;
|
var Server = MServer.server;
|
||||||
exports.$ = Bukkit;
|
exports.$ = Bukkit;
|
||||||
/**
|
/**
|
||||||
* 获取NMS版本
|
* 获取NMS版本
|
||||||
@ -43,16 +43,16 @@ exports.player = function () {
|
|||||||
exports.players = function () {
|
exports.players = function () {
|
||||||
switch (arguments.length) {
|
switch (arguments.length) {
|
||||||
case 1:
|
case 1:
|
||||||
return Server.onlinePlayers.forEach(arguments[0]);
|
return Bukkit.onlinePlayers.forEach(arguments[0]);
|
||||||
default:
|
default:
|
||||||
return Server.onlinePlayers;
|
return Bukkit.onlinePlayers;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* 插件管理
|
* 插件管理
|
||||||
* @type {{manager: *, get: exports.plugin.get, load: exports.plugin.load}}
|
* @type {{manager: *, get: exports.plugin.get, load: exports.plugin.load}}
|
||||||
*/
|
*/
|
||||||
var PluginManager = Server.pluginManager;
|
var PluginManager = Bukkit.pluginManager;
|
||||||
exports.plugin = {
|
exports.plugin = {
|
||||||
/**
|
/**
|
||||||
* 插件管理工具
|
* 插件管理工具
|
||||||
@ -84,7 +84,7 @@ exports.plugin = {
|
|||||||
* 服务管理
|
* 服务管理
|
||||||
* @type {{manager: *, get: exports.plugin.get, load: exports.plugin.load}}
|
* @type {{manager: *, get: exports.plugin.get, load: exports.plugin.load}}
|
||||||
*/
|
*/
|
||||||
var ServicesManager = Server.servicesManager;
|
var ServicesManager = Bukkit.servicesManager;
|
||||||
exports.service = {
|
exports.service = {
|
||||||
/**
|
/**
|
||||||
* 服务管理工具
|
* 服务管理工具
|
||||||
@ -99,7 +99,7 @@ exports.service = {
|
|||||||
var reg = ServicesManager.getRegistration(base.getClass(name));
|
var reg = ServicesManager.getRegistration(base.getClass(name));
|
||||||
return reg && reg.provider || null;
|
return reg && reg.provider || null;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
/**
|
/**
|
||||||
* 公告
|
* 公告
|
||||||
* @param message 消息
|
* @param message 消息
|
||||||
@ -125,13 +125,13 @@ exports.console = function (command) {
|
|||||||
/**
|
/**
|
||||||
* 玩家以OP权限执行命令
|
* 玩家以OP权限执行命令
|
||||||
* @param player
|
* @param player
|
||||||
* @param exper
|
* @param command
|
||||||
*/
|
*/
|
||||||
exports.opcommand = function (player, exper) {
|
exports.opcommand = function (player, command) {
|
||||||
var origin = player.isOp();
|
var origin = player.isOp();
|
||||||
player.setOp(true);
|
player.setOp(true);
|
||||||
try {
|
try {
|
||||||
exports.command(player, exper);
|
exports.command(player, command);
|
||||||
} finally {
|
} finally {
|
||||||
player.setOp(origin);
|
player.setOp(origin);
|
||||||
}
|
}
|
||||||
|
82
src/main/resources/internal/internal.d.ts
vendored
Normal file
82
src/main/resources/internal/internal.d.ts
vendored
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
interface Class {
|
||||||
|
name;
|
||||||
|
class;
|
||||||
|
static;
|
||||||
|
methods;
|
||||||
|
simpleName;
|
||||||
|
constructors;
|
||||||
|
parameterTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Task {
|
||||||
|
submit(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Registration {
|
||||||
|
provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PluginManager {
|
||||||
|
isEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
interface bukkit {
|
||||||
|
nmsVersion: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Server {
|
||||||
|
server;
|
||||||
|
service;
|
||||||
|
consoleSender;
|
||||||
|
onlinePlayers;
|
||||||
|
pluginManager;
|
||||||
|
serviceManager;
|
||||||
|
servicesManager;
|
||||||
|
onlinePlayers;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Player {
|
||||||
|
handle: NMSPlayer;
|
||||||
|
|
||||||
|
getName();
|
||||||
|
|
||||||
|
openInventory();
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Inventory {
|
||||||
|
setItem(index: number, item: Item);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PlayerEvent {
|
||||||
|
targetEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ItemEvent {
|
||||||
|
entity: Item;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface InventoryClickEvent {
|
||||||
|
inventory;
|
||||||
|
whoClicked;
|
||||||
|
rawSlot;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface NMSPlayer {
|
||||||
|
playerConnection;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface File {
|
||||||
|
canonicalPath;
|
||||||
|
|
||||||
|
isDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Item {
|
||||||
|
itemStack: ItemStack;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ItemStack {
|
||||||
|
typeId;
|
||||||
|
itemMeta;
|
||||||
|
amount;
|
||||||
|
}
|
@ -8,9 +8,6 @@ var Sponge = MServer;
|
|||||||
var server = require('./server');
|
var server = require('./server');
|
||||||
var plugin = server.plugin.self;
|
var plugin = server.plugin.self;
|
||||||
|
|
||||||
var CommandManager = server.CommandManager;
|
|
||||||
|
|
||||||
var CommandSpec = Java.type('org.spongepowered.api.command.spec.CommandSpec');
|
|
||||||
var CommandCallable = Java.type('org.spongepowered.api.command.CommandCallable');
|
var CommandCallable = Java.type('org.spongepowered.api.command.CommandCallable');
|
||||||
var CommandResult = Java.type('org.spongepowered.api.command.CommandResult');
|
var CommandResult = Java.type('org.spongepowered.api.command.CommandResult');
|
||||||
|
|
||||||
@ -27,7 +24,10 @@ var SimpleCommandCallable = function (command) {
|
|||||||
var that = this;
|
var that = this;
|
||||||
this.name = command.name;
|
this.name = command.name;
|
||||||
this.cmd = noop;
|
this.cmd = noop;
|
||||||
this.tab = function() { return new ArrayList(); };
|
this.tab = function () {
|
||||||
|
return new ArrayList();
|
||||||
|
};
|
||||||
|
// noinspection JSUnusedGlobalSymbols,JSUnusedLocalSymbols
|
||||||
this.callable = new CommandCallable({
|
this.callable = new CommandCallable({
|
||||||
//CommandResult process(CommandSource source, String arguments) throws CommandException;
|
//CommandResult process(CommandSource source, String arguments) throws CommandException;
|
||||||
process: function (src, args) {
|
process: function (src, args) {
|
||||||
@ -60,23 +60,26 @@ var SimpleCommandCallable = function (command) {
|
|||||||
this.setTabCompleter = function (exec) {
|
this.setTabCompleter = function (exec) {
|
||||||
that.tab = exec;
|
that.tab = exec;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
function enable(jsp) {
|
function enable(jsp) {
|
||||||
var pname = jsp.description.name;
|
// noinspection JSUnusedLocalSymbols
|
||||||
|
var plugin = jsp.description.name;
|
||||||
var commands = jsp.description.commands;
|
var commands = jsp.description.commands;
|
||||||
if (commands) {
|
if (commands) {
|
||||||
var pluginCmds = [];
|
// noinspection JSUnusedLocalSymbols
|
||||||
|
var pluginCommands = [];
|
||||||
for (var name in commands) {
|
for (var name in commands) {
|
||||||
var command = commands[name];
|
var command = commands[name];
|
||||||
if (typeof command !== 'object') continue;
|
if (typeof command !== 'object') continue;
|
||||||
command.name = name
|
command.name = name;
|
||||||
create(jsp, command)
|
create(jsp, command);
|
||||||
console.debug('插件 %s 注册命令 %s ...'.format(jsp.description.name, name));
|
console.debug('插件 %s 注册命令 %s ...'.format(jsp.description.name, name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// noinspection JSUnusedLocalSymbols
|
||||||
function get(name) {
|
function get(name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,8 +110,8 @@ function on(jsp, name, exec) {
|
|||||||
c.setTabCompleter(function execTab(sender, command, args) {
|
c.setTabCompleter(function execTab(sender, command, args) {
|
||||||
try {
|
try {
|
||||||
var token = args[args.length - 1];
|
var token = args[args.length - 1];
|
||||||
var complate = exec.tab(sender, command, args) || []
|
var complete = exec.tab(sender, command, args) || [];
|
||||||
return Arrays.asList(complate.copyPartialMatches(token, []));
|
return Arrays.asList(complete.copyPartialMatches(token, []));
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.console('§6玩家 §a%s §6执行 §b%s §6插件 §d%s %s §6补全时发生异常'
|
console.console('§6玩家 §a%s §6执行 §b%s §6插件 §d%s %s §6补全时发生异常'
|
||||||
.format(sender.name, jsp.description.name, command, args.join(' ')));
|
.format(sender.name, jsp.description.name, command, args.join(' ')));
|
||||||
@ -118,8 +121,7 @@ function on(jsp, name, exec) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var exist = Sponge.getCommandManager().getOwnedBy(plugin);
|
Sponge.getCommandManager().getOwnedBy(plugin).forEach(function (commandMapping) {
|
||||||
exist.forEach(function(commandMapping) {
|
|
||||||
if (!commandMapping.getAllAliases().contains("ms")) {
|
if (!commandMapping.getAllAliases().contains("ms")) {
|
||||||
Sponge.getCommandManager().removeMapping(commandMapping);
|
Sponge.getCommandManager().removeMapping(commandMapping);
|
||||||
}
|
}
|
||||||
@ -129,4 +131,4 @@ exports = module.exports = {
|
|||||||
enable: enable,
|
enable: enable,
|
||||||
on: on,
|
on: on,
|
||||||
off: noop
|
off: noop
|
||||||
}
|
};
|
@ -14,6 +14,7 @@
|
|||||||
this.console = function () {
|
this.console = function () {
|
||||||
this.sender(MServer.server.console, Array.prototype.join.call(arguments, ' '));
|
this.sender(MServer.server.console, Array.prototype.join.call(arguments, ' '));
|
||||||
};
|
};
|
||||||
|
// noinspection JSUnusedGlobalSymbols
|
||||||
this.warn = function () {
|
this.warn = function () {
|
||||||
log.warn(this.name + Array.prototype.join.call(arguments, ' '));
|
log.warn(this.name + Array.prototype.join.call(arguments, ' '));
|
||||||
};
|
};
|
||||||
|
@ -15,14 +15,14 @@ var priorityMap = {
|
|||||||
'HIGH': 'LATE',
|
'HIGH': 'LATE',
|
||||||
'HIGHEST': 'LAST',
|
'HIGHEST': 'LAST',
|
||||||
'MONITOR': 'POST'
|
'MONITOR': 'POST'
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断是否为一个有效的事件类
|
* 判断是否为一个有效的事件类
|
||||||
* @param clz
|
* @param clz
|
||||||
* @returns {*|boolean}
|
* @returns {*|boolean}
|
||||||
*/
|
*/
|
||||||
function isVaildEvent(clz) {
|
function isValidEvent(clz) {
|
||||||
// noinspection JSUnresolvedVariable 继承于 org.spongepowered.api.event.Event
|
// noinspection JSUnresolvedVariable 继承于 org.spongepowered.api.event.Event
|
||||||
return Event.class.isAssignableFrom(clz) &&
|
return Event.class.isAssignableFrom(clz) &&
|
||||||
// 访问符为Public
|
// 访问符为Public
|
||||||
@ -46,9 +46,11 @@ function register(eventCls, exec, priority, ignoreCancel) {
|
|||||||
function unregister(event, listener) {
|
function unregister(event, listener) {
|
||||||
MServer.getEventManager().unregisterListeners(listener);
|
MServer.getEventManager().unregisterListeners(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// noinspection JSUnusedGlobalSymbols
|
||||||
exports = module.exports = {
|
exports = module.exports = {
|
||||||
baseEventDir: 'org/spongepowered/api/event',
|
baseEventDir: 'org/spongepowered/api/event',
|
||||||
isVaildEvent: isVaildEvent,
|
isValidEvent: isValidEvent,
|
||||||
class2Name: class2Name,
|
class2Name: class2Name,
|
||||||
register: register,
|
register: register,
|
||||||
unregister: unregister
|
unregister: unregister
|
||||||
|
@ -6,13 +6,13 @@
|
|||||||
|
|
||||||
/*global Java, base, module, exports, require, __FILE__*/
|
/*global Java, base, module, exports, require, __FILE__*/
|
||||||
var Sponge = MServer;
|
var Sponge = MServer;
|
||||||
var Server = Sponge.server;
|
var Server = MServer.server;
|
||||||
var PluginManager = Sponge.pluginManager;
|
|
||||||
exports.$ = Sponge;
|
exports.$ = Sponge;
|
||||||
/**
|
/**
|
||||||
* 插件管理
|
* 插件管理
|
||||||
* @type {{manager: *, get: exports.plugin.get, load: exports.plugin.load}}
|
* @type {{manager: *, get: exports.plugin.get, load: exports.plugin.load}}
|
||||||
*/
|
*/
|
||||||
|
var PluginManager = Sponge.pluginManager;
|
||||||
exports.plugin = {
|
exports.plugin = {
|
||||||
/**
|
/**
|
||||||
* 插件管理工具
|
* 插件管理工具
|
||||||
@ -54,7 +54,7 @@ exports.service = {
|
|||||||
get: function (name) {
|
get: function (name) {
|
||||||
return ServicesManager.provide(base.getClass(name)).orElse(null);
|
return ServicesManager.provide(base.getClass(name)).orElse(null);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
/**
|
/**
|
||||||
* 获取玩家
|
* 获取玩家
|
||||||
*/
|
*/
|
||||||
|
@ -5,14 +5,14 @@
|
|||||||
* Created by 蒋天蓓 on 2017/2/9 0009.
|
* Created by 蒋天蓓 on 2017/2/9 0009.
|
||||||
*/
|
*/
|
||||||
var plugin = require('./server').plugin.self;
|
var plugin = require('./server').plugin.self;
|
||||||
var Comsumer = Java.type('java.util.function.Consumer');
|
var Consumer = Java.type('java.util.function.Consumer');
|
||||||
var Task = Java.type("org.spongepowered.api.scheduler.Task");
|
var Task = Java.type("org.spongepowered.api.scheduler.Task");
|
||||||
/**
|
/**
|
||||||
* 创建任务对象
|
* 创建任务对象
|
||||||
* @param func 任务
|
* @param func 任务
|
||||||
*/
|
*/
|
||||||
exports.create = function (func) {
|
exports.create = function (func) {
|
||||||
return Task.builder().execute(new Comsumer(function () {
|
return Task.builder().execute(new Consumer(function () {
|
||||||
try {
|
try {
|
||||||
func();
|
func();
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
|
@ -22,8 +22,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// constants
|
// constants
|
||||||
var b64chars
|
// noinspection SpellCheckingInspection
|
||||||
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
var b64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
||||||
var b64tab = function (bin) {
|
var b64tab = function (bin) {
|
||||||
var t = {};
|
var t = {};
|
||||||
for (var i = 0, l = bin.length; i < l; i++) t[bin.charAt(i)] = i;
|
for (var i = 0, l = bin.length; i < l; i++) t[bin.charAt(i)] = i;
|
||||||
@ -173,6 +173,7 @@
|
|||||||
return Base64;
|
return Base64;
|
||||||
};
|
};
|
||||||
// export Base64
|
// export Base64
|
||||||
|
// noinspection JSUnusedGlobalSymbols
|
||||||
global.Base64 = {
|
global.Base64 = {
|
||||||
VERSION: version,
|
VERSION: version,
|
||||||
atob: atob,
|
atob: atob,
|
||||||
|
@ -9,29 +9,32 @@
|
|||||||
var URL = Java.type("java.net.URL");
|
var URL = Java.type("java.net.URL");
|
||||||
var Files = Java.type("java.nio.file.Files");
|
var Files = Java.type("java.nio.file.Files");
|
||||||
var Paths = Java.type("java.nio.file.Paths");
|
var Paths = Java.type("java.nio.file.Paths");
|
||||||
var String = Java.type("java.lang.String");
|
var Str = Java.type("java.lang.String");
|
||||||
|
|
||||||
var HttpURLConnection = Java.type("java.net.HttpURLConnection");
|
|
||||||
var HttpsURLConnection = Java.type("javax.net.ssl.HttpsURLConnection");
|
var HttpsURLConnection = Java.type("javax.net.ssl.HttpsURLConnection");
|
||||||
var SSLContext = Java.type("javax.net.ssl.SSLContext");
|
var SSLContext = Java.type("javax.net.ssl.SSLContext");
|
||||||
|
|
||||||
var HostnameVerifier = Java.type("javax.net.ssl.HostnameVerifier");
|
var HostnameVerifier = Java.type("javax.net.ssl.HostnameVerifier");
|
||||||
var X509TrustManager = Java.type("javax.net.ssl.X509TrustManager");
|
var X509TrustManager = Java.type("javax.net.ssl.X509TrustManager");
|
||||||
|
|
||||||
|
// noinspection JSUnusedGlobalSymbols,JSUnusedLocalSymbols
|
||||||
var TrustAnyHostnameVerifier = new HostnameVerifier({
|
var TrustAnyHostnameVerifier = new HostnameVerifier({
|
||||||
verify: function (hostname, session) {
|
verify: function (hostname, session) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
var SSLSocketFactory = function initSSLSocketFactory() {
|
var SSLSocketFactory = function initSSLSocketFactory() {
|
||||||
var sslContext = SSLContext.getInstance("TLS");
|
var sslContext = SSLContext.getInstance("TLS");
|
||||||
|
// noinspection JSUnusedGlobalSymbols
|
||||||
sslContext.init(null, [new X509TrustManager({
|
sslContext.init(null, [new X509TrustManager({
|
||||||
getAcceptedIssuers: function () {
|
getAcceptedIssuers: function () {
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
checkClientTrusted: function (chain, authType) {},
|
checkClientTrusted: function (chain, authType) {
|
||||||
checkServerTrusted: function (chain, authType) {}
|
},
|
||||||
|
checkServerTrusted: function (chain, authType) {
|
||||||
|
}
|
||||||
})], new java.security.SecureRandom());
|
})], new java.security.SecureRandom());
|
||||||
return sslContext.getSocketFactory();
|
return sslContext.getSocketFactory();
|
||||||
}();
|
}();
|
||||||
@ -41,7 +44,7 @@ var config = {
|
|||||||
ConnectTimeout: 10000,
|
ConnectTimeout: 10000,
|
||||||
ReadTimeout: 10000,
|
ReadTimeout: 10000,
|
||||||
Debug: false
|
Debug: false
|
||||||
}
|
};
|
||||||
|
|
||||||
function open(url, method, header) {
|
function open(url, method, header) {
|
||||||
// conn.setRequestProperty
|
// conn.setRequestProperty
|
||||||
@ -57,6 +60,7 @@ function open(url, method, header) {
|
|||||||
conn.setReadTimeout(config.ReadTimeout);
|
conn.setReadTimeout(config.ReadTimeout);
|
||||||
if (header) {
|
if (header) {
|
||||||
for (var key in header) {
|
for (var key in header) {
|
||||||
|
// noinspection JSUnfilteredForInLoop
|
||||||
conn.setRequestProperty(key, header[key]);
|
conn.setRequestProperty(key, header[key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,7 +70,7 @@ function open(url, method, header) {
|
|||||||
function buildUrl(url, params) {
|
function buildUrl(url, params) {
|
||||||
if (params && Object.keys(params).length > 0) {
|
if (params && Object.keys(params).length > 0) {
|
||||||
var queryStart = url.indexOf('?');
|
var queryStart = url.indexOf('?');
|
||||||
if (queryStart == -1) {
|
if (queryStart === -1) {
|
||||||
url += '?';
|
url += '?';
|
||||||
}
|
}
|
||||||
return url += object2URLSearchParams(params);
|
return url += object2URLSearchParams(params);
|
||||||
@ -85,12 +89,13 @@ function request(config) {
|
|||||||
var type = config.header['Content-Type'];
|
var type = config.header['Content-Type'];
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "application/x-www-form-urlencoded":
|
case "application/x-www-form-urlencoded":
|
||||||
data = object2URLSearchParams(params);
|
data = object2URLSearchParams(data);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
data = JSON.stringify(data)
|
data = JSON.stringify(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out.write(new String(data).getBytes(config.Charset));
|
out.write(new Str(data).getBytes(config.Charset));
|
||||||
out.flush();
|
out.flush();
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
@ -103,14 +108,14 @@ function request(config) {
|
|||||||
function response(conn) {
|
function response(conn) {
|
||||||
var temp = Paths.get(java.lang.System.getProperty("java.io.tmpdir"), java.util.UUID.randomUUID().toString());
|
var temp = Paths.get(java.lang.System.getProperty("java.io.tmpdir"), java.util.UUID.randomUUID().toString());
|
||||||
Files.copy(conn.getInputStream(), temp);
|
Files.copy(conn.getInputStream(), temp);
|
||||||
var result = new String(Files.readAllBytes(temp), config.Charset);
|
var result = new Str(Files.readAllBytes(temp), config.Charset);
|
||||||
var tempFile = temp.toFile();
|
var tempFile = temp.toFile();
|
||||||
tempFile.delete() || tempFile.deleteOnExit();
|
tempFile.delete() || tempFile.deleteOnExit();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function object2URLSearchParams(params) {
|
function object2URLSearchParams(params) {
|
||||||
var temp = []
|
var temp = [];
|
||||||
for (var key in params) {
|
for (var key in params) {
|
||||||
temp.push('%s=%s'.format(encodeURIComponent(key), encodeURIComponent(params[key])))
|
temp.push('%s=%s'.format(encodeURIComponent(key), encodeURIComponent(params[key])))
|
||||||
}
|
}
|
||||||
|
3
src/main/resources/modules/modules.d.ts
vendored
Normal file
3
src/main/resources/modules/modules.d.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
interface requestConfig {
|
||||||
|
header;
|
||||||
|
}
|
@ -10,7 +10,7 @@ PlaceholderAPI = {
|
|||||||
setPlaceholders: function () {
|
setPlaceholders: function () {
|
||||||
return arguments[1].replace(/&([1-9a-fA-F])/, '§$1');
|
return arguments[1].replace(/&([1-9a-fA-F])/, '§$1');
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
// 尝试加载 Bukkit 的 PlaceholderAPI
|
// 尝试加载 Bukkit 的 PlaceholderAPI
|
||||||
try {
|
try {
|
||||||
@ -21,15 +21,16 @@ try {
|
|||||||
|
|
||||||
// 尝试加载 Sponge 的 PlaceholderAPI
|
// 尝试加载 Sponge 的 PlaceholderAPI
|
||||||
try {
|
try {
|
||||||
var spapi = server.service.get('me.rojo8399.placeholderapi.PlaceholderService');
|
/** @namespace server.service */
|
||||||
|
var spongePapi = server.service.get('me.rojo8399.placeholderapi.PlaceholderService');
|
||||||
var TextSerializers = Java.type('org.spongepowered.api.text.serializer.TextSerializers');
|
var TextSerializers = Java.type('org.spongepowered.api.text.serializer.TextSerializers');
|
||||||
var s = TextSerializers.formattingCode('§');
|
var s = TextSerializers.formattingCode('§');
|
||||||
if (spapi) {
|
if (spongePapi) {
|
||||||
PlaceholderAPI = {
|
PlaceholderAPI = {
|
||||||
setPlaceholders: function () {
|
setPlaceholders: function () {
|
||||||
return s.serialize(spapi.replacePlaceholders(arguments[1], arguments[0], arguments[0]));
|
return s.serialize(spongePapi.replacePlaceholders(arguments[1], arguments[0], arguments[0]));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
console.log('[PAPI] Found Sponge PlaceholderAPI Hooking...')
|
console.log('[PAPI] Found Sponge PlaceholderAPI Hooking...')
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
@ -45,4 +46,4 @@ function replace() {
|
|||||||
|
|
||||||
exports = module.exports = {
|
exports = module.exports = {
|
||||||
$: replace
|
$: replace
|
||||||
}
|
};
|
||||||
|
@ -44,6 +44,7 @@ function Reflect(obj) {
|
|||||||
return arguments.length === 1 ? this.field(arguments[0]) : this.obj;
|
return arguments.length === 1 ? this.field(arguments[0]) : this.obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// noinspection JSUnusedGlobalSymbols
|
||||||
this.set = function (name, value) {
|
this.set = function (name, value) {
|
||||||
accessible(declaredField(this.class, name)).set(this.obj, value);
|
accessible(declaredField(this.class, name)).set(this.obj, value);
|
||||||
return this;
|
return this;
|
||||||
@ -113,27 +114,15 @@ function declaredField(clazz, name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function declaredMethod(clazz, name, clazzs) {
|
function declaredMethod(clazz, name, clazzs) {
|
||||||
var mkey = clazz.name + '.' + name + ':' + (clazzs || []).join(':');
|
var key = clazz.name + '.' + name + ':' + (clazzs || []).join(':');
|
||||||
if (!methodCache[mkey]) {
|
if (!methodCache[key]) {
|
||||||
try {
|
try {
|
||||||
methodCache[mkey] = clazz.getMethod(name, clazzs);
|
methodCache[key] = clazz.getMethod(name, clazzs);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
methodCache[mkey] = clazz.getDeclaredMethod(name, clazzs);
|
methodCache[key] = clazz.getDeclaredMethod(name, clazzs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return methodCache[mkey];
|
return methodCache[key];
|
||||||
}
|
|
||||||
|
|
||||||
function declaredMethod(clazz, name, clazzs) {
|
|
||||||
var mkey = clazz.name + '.' + name + ':' + (clazzs || []).join(':');
|
|
||||||
if (!methodCache[mkey]) {
|
|
||||||
try {
|
|
||||||
methodCache[mkey] = clazz.getMethod(name, clazzs);
|
|
||||||
} catch (ex) {
|
|
||||||
methodCache[mkey] = clazz.getDeclaredMethod(name, clazzs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return methodCache[mkey];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function declaredMethods(clazz) {
|
function declaredMethods(clazz) {
|
||||||
@ -143,14 +132,18 @@ function declaredMethods(clazz) {
|
|||||||
var classMethodsCache = [];
|
var classMethodsCache = [];
|
||||||
|
|
||||||
function mapToObject(javaObj) {
|
function mapToObject(javaObj) {
|
||||||
if (!javaObj || !javaObj.class) { throw new TypeError('参数 %s 不是一个Java对象!'.format(javaObj)) }
|
if (!javaObj || !javaObj.class) {
|
||||||
|
throw new TypeError('参数 %s 不是一个Java对象!'.format(javaObj))
|
||||||
|
}
|
||||||
var target = {};
|
var target = {};
|
||||||
getJavaObjectMethods(javaObj).forEach(function proxyMethod(t){ mapMethod(target, javaObj, t) })
|
getJavaObjectMethods(javaObj).forEach(function proxyMethod(t) {
|
||||||
|
mapMethod(target, javaObj, t)
|
||||||
|
});
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getJavaObjectMethods(javaObj) {
|
function getJavaObjectMethods(javaObj) {
|
||||||
var className = javaObj.class.name
|
var className = javaObj.class.name;
|
||||||
if (!classMethodsCache[className]) {
|
if (!classMethodsCache[className]) {
|
||||||
var names = [];
|
var names = [];
|
||||||
var methods = javaObj.class.methods;
|
var methods = javaObj.class.methods;
|
||||||
@ -173,13 +166,16 @@ function mapMethod (target, source, name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function on(obj) {
|
function on(obj) {
|
||||||
if (!obj || !obj.class) { throw new TypeError('参数 %s 不是一个Java对象!'.format(obj)) }
|
if (!obj || !obj.class) {
|
||||||
|
throw new TypeError('参数 %s 不是一个Java对象!'.format(obj))
|
||||||
|
}
|
||||||
return new Reflect(obj);
|
return new Reflect(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// noinspection JSUnusedGlobalSymbols
|
||||||
exports = module.exports = {
|
exports = module.exports = {
|
||||||
on: on,
|
on: on,
|
||||||
accessible: accessible,
|
accessible: accessible,
|
||||||
declaredMethods: declaredMethods,
|
declaredMethods: declaredMethods,
|
||||||
mapToObject: mapToObject
|
mapToObject: mapToObject
|
||||||
}
|
};
|
||||||
|
@ -13,12 +13,12 @@ var ChatMessagePart = function () {
|
|||||||
this.click = function (action, value) {
|
this.click = function (action, value) {
|
||||||
this.clickEventAction = action;
|
this.clickEventAction = action;
|
||||||
this.clickEventValue = value;
|
this.clickEventValue = value;
|
||||||
}
|
};
|
||||||
|
|
||||||
this.hover = function (action, value) {
|
this.hover = function (action, value) {
|
||||||
this.hoverEventAction = action;
|
this.hoverEventAction = action;
|
||||||
this.hoverEventValue = value;
|
this.hoverEventValue = value;
|
||||||
}
|
};
|
||||||
|
|
||||||
this.convert = function () {
|
this.convert = function () {
|
||||||
var str = {};
|
var str = {};
|
||||||
@ -42,7 +42,7 @@ var ChatMessagePart = function () {
|
|||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
var Tellraw = function () {
|
var Tellraw = function () {
|
||||||
var parts = [new ChatMessagePart()];
|
var parts = [new ChatMessagePart()];
|
||||||
@ -63,12 +63,12 @@ var Tellraw = function () {
|
|||||||
parts.push(part);
|
parts.push(part);
|
||||||
}
|
}
|
||||||
this.cache = null;
|
this.cache = null;
|
||||||
}
|
};
|
||||||
|
|
||||||
this.text = function (text) {
|
this.text = function (text) {
|
||||||
this.latest().text = text;
|
this.latest().text = text;
|
||||||
return this;
|
return this;
|
||||||
}
|
};
|
||||||
|
|
||||||
this.tip = function (str) {
|
this.tip = function (str) {
|
||||||
if (toString.call(str) === "[object Array]") {
|
if (toString.call(str) === "[object Array]") {
|
||||||
@ -76,63 +76,63 @@ var Tellraw = function () {
|
|||||||
}
|
}
|
||||||
this.latest().hover("show_text", str);
|
this.latest().hover("show_text", str);
|
||||||
return this;
|
return this;
|
||||||
}
|
};
|
||||||
|
|
||||||
this.item = function (str) {
|
this.item = function (str) {
|
||||||
this.latest().hover("show_item", str);
|
this.latest().hover("show_item", str);
|
||||||
return this;
|
return this;
|
||||||
}
|
};
|
||||||
|
|
||||||
this.cmd = this.command = function (command) {
|
this.cmd = this.command = function (command) {
|
||||||
this.latest().click("run_command", command);
|
this.latest().click("run_command", command);
|
||||||
return this;
|
return this;
|
||||||
}
|
};
|
||||||
|
|
||||||
this.suggest = function (url) {
|
this.suggest = function (url) {
|
||||||
this.latest().click("suggest_command", url);
|
this.latest().click("suggest_command", url);
|
||||||
return this;
|
return this;
|
||||||
}
|
};
|
||||||
|
|
||||||
this.file = function (path) {
|
this.file = function (path) {
|
||||||
this.latest().click("open_file", path);
|
this.latest().click("open_file", path);
|
||||||
return this;
|
return this;
|
||||||
}
|
};
|
||||||
|
|
||||||
this.link = function (url) {
|
this.link = function (url) {
|
||||||
this.latest().click("open_url", url);
|
this.latest().click("open_url", url);
|
||||||
return this;
|
return this;
|
||||||
}
|
};
|
||||||
|
|
||||||
this.latest = function () {
|
this.latest = function () {
|
||||||
return parts[parts.length - 1];
|
return parts[parts.length - 1];
|
||||||
}
|
};
|
||||||
|
|
||||||
this.json = function () {
|
this.json = function () {
|
||||||
if (!this.cache) {
|
if (!this.cache) {
|
||||||
var temp = [];
|
var temp = [];
|
||||||
parts.forEach(function (t) {
|
parts.forEach(function (t) {
|
||||||
temp.push(t.convert());
|
temp.push(t.convert());
|
||||||
})
|
});
|
||||||
this.cache = JSON.stringify(temp);
|
this.cache = JSON.stringify(temp);
|
||||||
console.debug(this.cache);
|
console.debug(this.cache);
|
||||||
}
|
}
|
||||||
return this.cache;
|
return this.cache;
|
||||||
}
|
};
|
||||||
|
|
||||||
this.send = function (player) {
|
this.send = function (player) {
|
||||||
chat.json(player, self.json());
|
chat.json(player, self.json());
|
||||||
}
|
};
|
||||||
|
|
||||||
this.sendAll = function () {
|
this.sendAll = function () {
|
||||||
server.players(function sendAllMessage(p) {
|
server.players(function sendAllMessage(p) {
|
||||||
self.send(p);
|
self.send(p);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
Tellraw.create = function () {
|
Tellraw.create = function () {
|
||||||
return new Tellraw().then(Tellraw.duplicateChar);
|
return new Tellraw().then(Tellraw.duplicateChar);
|
||||||
}
|
};
|
||||||
|
|
||||||
Tellraw.duplicateChar = '§卐';
|
Tellraw.duplicateChar = '§卐';
|
||||||
|
|
||||||
|
@ -32,4 +32,4 @@ function compare(prop) {
|
|||||||
|
|
||||||
exports = module.exports = {
|
exports = module.exports = {
|
||||||
compare: compare
|
compare: compare
|
||||||
}
|
};
|
@ -16,9 +16,9 @@ function unzip(zipFile, target) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (target === undefined) {
|
if (target === undefined) {
|
||||||
var fname = zipFile.name;
|
var fileName = zipFile.name;
|
||||||
// noinspection JSUnresolvedVariable
|
// noinspection JSUnresolvedVariable
|
||||||
target = fs.file(zipFile.parentFile.canonicalPath, fname.substring(0, fname.length() - 4));
|
target = fs.file(zipFile.parentFile.canonicalPath, fileName.substring(0, fileName.length() - 4));
|
||||||
}
|
}
|
||||||
console.debug("解压文件 %s 到目录 %s".format(zipFile.canonicalPath, target));
|
console.debug("解压文件 %s 到目录 %s".format(zipFile.canonicalPath, target));
|
||||||
var zipObj = new ZipFile(zipFile);
|
var zipObj = new ZipFile(zipFile);
|
||||||
|
@ -25,6 +25,7 @@ function load() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function enable() {
|
function enable() {
|
||||||
|
// noinspection JSUnusedLocalSymbols
|
||||||
command.on(this, 'hello', {
|
command.on(this, 'hello', {
|
||||||
cmd: function (sender, command, args) {
|
cmd: function (sender, command, args) {
|
||||||
engineLoad(fs.file(root, 'test.js'));
|
engineLoad(fs.file(root, 'test.js'));
|
||||||
@ -34,13 +35,12 @@ function enable() {
|
|||||||
console.log('启用 Hello World 测试插件!');
|
console.log('启用 Hello World 测试插件!');
|
||||||
switch (DetectServerType) {
|
switch (DetectServerType) {
|
||||||
case ServerType.Bukkit:
|
case ServerType.Bukkit:
|
||||||
event.on(this, 'playerloginevent', function join(event) {
|
event.on(this, 'PlayerLoginEvent', function join(event) {
|
||||||
send(event, wrapper.player(event.player));
|
send(event, wrapper.player(event.player));
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case ServerType.Sponge:
|
case ServerType.Sponge:
|
||||||
// clientconnectionevent.join
|
event.on(this, 'ClientConnectionEvent.Join', function join(event) {
|
||||||
event.on(this, 'clientconnectionevent.join', function join(event) {
|
|
||||||
send(event, wrapper.player(event.targetEntity));
|
send(event, wrapper.player(event.targetEntity));
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
/*global Java, base, module, exports, require*/
|
/*global Java, base, module, exports, require*/
|
||||||
|
|
||||||
var server = require('api/server');
|
|
||||||
var event = require('api/event');
|
var event = require('api/event');
|
||||||
var task = require('api/task');
|
var task = require('api/task');
|
||||||
var http = require('http');
|
var http = require('http');
|
||||||
@ -32,23 +30,23 @@ function enable() {
|
|||||||
case ServerType.Bukkit:
|
case ServerType.Bukkit:
|
||||||
event.on(self, 'ItemMergeEvent', function (event) {
|
event.on(self, 'ItemMergeEvent', function (event) {
|
||||||
bukkit(event.target, event.entity.itemStack.amount + event.target.itemStack.amount);
|
bukkit(event.target, event.entity.itemStack.amount + event.target.itemStack.amount);
|
||||||
})
|
});
|
||||||
event.on(self, 'ItemSpawnEvent', function (event) {
|
event.on(self, 'ItemSpawnEvent', function (event) {
|
||||||
if (event.entity.itemStack) {
|
if (event.entity.itemStack) {
|
||||||
bukkit(event.entity, event.entity.itemStack.amount);
|
bukkit(event.entity, event.entity.itemStack.amount);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
break;
|
break;
|
||||||
case ServerType.Sponge:
|
case ServerType.Sponge:
|
||||||
Keys = Java.type('org.spongepowered.api.data.key.Keys');
|
Keys = Java.type('org.spongepowered.api.data.key.Keys');
|
||||||
event.on(self, 'ItemMergeItemEvent', function (event) {
|
event.on(self, 'ItemMergeItemEvent', function (event) {
|
||||||
// Sponge 暂未实现当前事件
|
// Sponge 暂未实现当前事件
|
||||||
})
|
});
|
||||||
event.on(self, 'SpawnEntityEvent', function (event) {
|
event.on(self, 'SpawnEntityEvent', function (event) {
|
||||||
event.entities.forEach(function (entity) {
|
event.entities.forEach(function (entity) {
|
||||||
if (entity.type.name === "item") sponge(entity);
|
if (entity.type.name === "item") sponge(entity);
|
||||||
})
|
})
|
||||||
})
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,12 +57,12 @@ function bukkit(item , amount) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sponge(entity) {
|
function sponge(entity) {
|
||||||
var itemOptional = entity.get(Keys.REPRESENTED_ITEM);
|
var itemOptional = entity.get(Keys['REPRESENTED_ITEM']);
|
||||||
if (itemOptional.isPresent()) {
|
if (itemOptional.isPresent()) {
|
||||||
var item = itemOptional.get();
|
var item = itemOptional.get();
|
||||||
var itemName = '§b' + getItemName(item.type.name.split(':')[1]) + getItemCount(item.count);
|
var itemName = '§b' + getItemName(item.type.name.split(':')[1]) + getItemCount(item.count);
|
||||||
entity.offer(Keys.DISPLAY_NAME, org.spongepowered.api.text.Text.of(itemName));
|
entity.offer(Keys['DISPLAY_NAME'], org.spongepowered.api.text.Text.of(itemName));
|
||||||
entity.offer(Keys.CUSTOM_NAME_VISIBLE, true);
|
entity.offer(Keys['CUSTOM_NAME_VISIBLE'], true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +71,7 @@ function getItemName(name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getItemCount(amount) {
|
function getItemCount(amount) {
|
||||||
return amount == 1 ? "" : "*" + amount;
|
return amount === 1 ? "" : "*" + amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -5,14 +5,13 @@
|
|||||||
/*global Java, base, module, exports, require*/
|
/*global Java, base, module, exports, require*/
|
||||||
|
|
||||||
var event = require('api/event');
|
var event = require('api/event');
|
||||||
var wrapper = require('api/wrapper');
|
|
||||||
var command = require('api/command');
|
var command = require('api/command');
|
||||||
var server = require('api/server');
|
|
||||||
var fs = require('fs');
|
|
||||||
|
|
||||||
var tellraw = require('tellraw');
|
var tellraw = require('tellraw');
|
||||||
var papi = require('papi');
|
var papi = require('papi');
|
||||||
var utils = require('utils')
|
var utils = require('utils');
|
||||||
|
|
||||||
|
var Player;
|
||||||
|
|
||||||
var description = {
|
var description = {
|
||||||
name: 'MiaoChat',
|
name: 'MiaoChat',
|
||||||
@ -34,10 +33,10 @@ var description = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
config: {
|
config: {
|
||||||
"Version":"1.8.5",
|
Version: "1.8.5",
|
||||||
"BungeeCord":true,
|
BungeeCord: true,
|
||||||
"Server":"生存服",
|
Server: "生存服",
|
||||||
"ChatFormats":{
|
ChatFormats: {
|
||||||
"default": {
|
"default": {
|
||||||
"index": 50,
|
"index": 50,
|
||||||
"permission": "MiaoChat.default",
|
"permission": "MiaoChat.default",
|
||||||
@ -120,11 +119,11 @@ function initFormat(chat_formats) {
|
|||||||
chat_formats.forEach(function (chat_format) {
|
chat_formats.forEach(function (chat_format) {
|
||||||
var chat_format_str = chat_format.format;
|
var chat_format_str = chat_format.format;
|
||||||
var temp = [];
|
var temp = [];
|
||||||
var r = [];
|
var r;
|
||||||
while (r = FORMAT_PATTERN.exec(chat_format_str)) {
|
while (r = FORMAT_PATTERN.exec(chat_format_str)) {
|
||||||
temp.push(r[1]);
|
temp.push(r[1]);
|
||||||
}
|
}
|
||||||
var format_list = []
|
var format_list = [];
|
||||||
temp.forEach(function splitStyle(t) {
|
temp.forEach(function splitStyle(t) {
|
||||||
var arr = chat_format_str.split('[' + t + ']', 2);
|
var arr = chat_format_str.split('[' + t + ']', 2);
|
||||||
if (arr[0]) {
|
if (arr[0]) {
|
||||||
@ -147,11 +146,12 @@ function enable() {
|
|||||||
|
|
||||||
function registerCommand() {
|
function registerCommand() {
|
||||||
command.on(self, 'mchat', {
|
command.on(self, 'mchat', {
|
||||||
cmd: mchat
|
cmd: mainCommand
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function mchat(sender, command, args) {
|
// noinspection JSUnusedLocalSymbols
|
||||||
|
function mainCommand(sender, command, args) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,29 +161,36 @@ function registerEvent() {
|
|||||||
event.on(self, 'AsyncPlayerChatEvent', handlerBukkitChat);
|
event.on(self, 'AsyncPlayerChatEvent', handlerBukkitChat);
|
||||||
break;
|
break;
|
||||||
case ServerType.Sponge:
|
case ServerType.Sponge:
|
||||||
|
Player = org.spongepowered.api.entity.living.player.Player;
|
||||||
event.on(self, 'MessageChannelEvent.Chat', handlerSpongeChat);
|
event.on(self, 'MessageChannelEvent.Chat', handlerSpongeChat);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handlerBukkitChat(event) {
|
function handlerBukkitChat(event) {
|
||||||
sendChat(event.player, event.message, function() { event.setCancelled(true); });
|
sendChat(event.player, event.message, function () {
|
||||||
|
event.setCancelled(true);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function handlerSpongeChat(event) {
|
function handlerSpongeChat(event) {
|
||||||
var player = event.getCause().first(org.spongepowered.api.entity.living.player.Player.class).orElse(null);
|
var player = event.getCause().first(Player.class).orElse(null);
|
||||||
if (player == null) { return; }
|
if (player == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
var plain = event.getRawMessage().toPlain();
|
var plain = event.getRawMessage().toPlain();
|
||||||
if (plain.startsWith(tellraw.duplicateChar)) {
|
if (plain.startsWith(tellraw.duplicateChar)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sendChat(player, plain, function() { event.setMessageCancelled(true) });
|
sendChat(player, plain, function () {
|
||||||
|
event.setMessageCancelled(true)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendChat(player, plain, callback) {
|
function sendChat(player, plain, callback) {
|
||||||
var chat_format = getChatFormat(player);
|
var chat_format = getChatFormat(player);
|
||||||
if (!chat_format) {
|
if (!chat_format) {
|
||||||
console.debug('未获得用户', player.name, '的 ChatRule 跳过执行...')
|
console.debug('未获得用户', player.name, '的 ChatRule 跳过执行...');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
callback();
|
callback();
|
||||||
@ -196,7 +203,7 @@ function sendChat(player, plain, callback) {
|
|||||||
tr.tip(replace(player, style.hover));
|
tr.tip(replace(player, style.hover));
|
||||||
}
|
}
|
||||||
if (style.click && style.click.type && style.click.command) {
|
if (style.click && style.click.type && style.click.command) {
|
||||||
var command = replace(player, style.click.command)
|
var command = replace(player, style.click.command);
|
||||||
switch (style.click.type) {
|
switch (style.click.type) {
|
||||||
case "COMMAND":
|
case "COMMAND":
|
||||||
tr.command(command);
|
tr.command(command);
|
||||||
@ -213,7 +220,7 @@ function sendChat(player, plain, callback) {
|
|||||||
} else {
|
} else {
|
||||||
tr.then(replace(player, format));
|
tr.then(replace(player, format));
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
tr.then(replace(player, plain)).sendAll();
|
tr.then(replace(player, plain)).sendAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
'use strict'
|
'use strict';
|
||||||
/*global Java, base, module, exports, require*/
|
/*global Java, base, module, exports, require, __dirname, __filename*/
|
||||||
|
var command = require('api/command');
|
||||||
|
var manager = require('api/plugin');
|
||||||
|
var task = require('api/task');
|
||||||
|
|
||||||
var wrapper = require('api/wrapper')
|
var http = require('http');
|
||||||
var command = require('api/command')
|
var fs = require('fs');
|
||||||
var manager = require('api/plugin')
|
|
||||||
var task = require('api/task')
|
|
||||||
|
|
||||||
var http = require('http')
|
var pluginCache = [];
|
||||||
var fs = require('fs')
|
var packageCache = [];
|
||||||
|
var packageNameCache = [];
|
||||||
var pluginCache = []
|
|
||||||
var packageCache = []
|
|
||||||
var packageNameCache = []
|
|
||||||
|
|
||||||
var description = {
|
var description = {
|
||||||
name: 'MiaoScriptPackageManager',
|
name: 'MiaoScriptPackageManager',
|
||||||
@ -26,7 +24,7 @@ var description = {
|
|||||||
config: {
|
config: {
|
||||||
center: 'https://ms.yumc.pw/api/package/list'
|
center: 'https://ms.yumc.pw/api/package/list'
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
var help = [
|
var help = [
|
||||||
'§6========= §a' + description.name + ' §6帮助 §aBy §b喵♂呜 §6=========',
|
'§6========= §a' + description.name + ' §6帮助 §aBy §b喵♂呜 §6=========',
|
||||||
@ -35,7 +33,7 @@ var help = [
|
|||||||
'§6/mpm §aupdate <插件名称> §6- §3更新插件(无插件名称则更新源)',
|
'§6/mpm §aupdate <插件名称> §6- §3更新插件(无插件名称则更新源)',
|
||||||
'§6/mpm §aupgrade <插件名称> §6- §3及时更新插件(update需要重启生效)',
|
'§6/mpm §aupgrade <插件名称> §6- §3及时更新插件(update需要重启生效)',
|
||||||
'§6/mpm §areload <插件名称> §6- §3重载插件(无插件名称则重载自生)',
|
'§6/mpm §areload <插件名称> §6- §3重载插件(无插件名称则重载自生)',
|
||||||
]
|
];
|
||||||
|
|
||||||
function load() {
|
function load() {
|
||||||
task.async(function () {
|
task.async(function () {
|
||||||
@ -53,19 +51,19 @@ function enable() {
|
|||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
switch (args[0]) {
|
switch (args[0]) {
|
||||||
case "list":
|
case "list":
|
||||||
console.sender(sender, '§6当前 §bMiaoScriptPackageCenter §6中存在下列插件:')
|
console.sender(sender, '§6当前 §bMiaoScriptPackageCenter §6中存在下列插件:');
|
||||||
for (var pkgName in packageCache) {
|
for (var pkgName in packageCache) {
|
||||||
var pkg = packageCache[pkgName]
|
var pkg = packageCache[pkgName];
|
||||||
console.sender(sender, '§6插件名称: §b%s §6版本: §a%s'.format(pkg.name, pkg.version))
|
console.sender(sender, '§6插件名称: §b%s §6版本: §a%s'.format(pkg.name, pkg.version))
|
||||||
}
|
}
|
||||||
break
|
break;
|
||||||
case "install":
|
case "install":
|
||||||
if (args.length > 1) {
|
if (args.length > 1) {
|
||||||
download(sender, args[1]);
|
download(sender, args[1]);
|
||||||
} else {
|
} else {
|
||||||
console.sender(sender, '§c请输入插件名称!')
|
console.sender(sender, '§c请输入插件名称!')
|
||||||
}
|
}
|
||||||
break
|
break;
|
||||||
case "update":
|
case "update":
|
||||||
if (args.length > 1) {
|
if (args.length > 1) {
|
||||||
update(sender, args[1]);
|
update(sender, args[1]);
|
||||||
@ -73,19 +71,19 @@ function enable() {
|
|||||||
load();
|
load();
|
||||||
console.sender(sender, "§a仓库缓存刷新成功 共存在 §b" + pluginCache.length + " §a个插件!")
|
console.sender(sender, "§a仓库缓存刷新成功 共存在 §b" + pluginCache.length + " §a个插件!")
|
||||||
}
|
}
|
||||||
break
|
break;
|
||||||
case "upgrade":
|
case "upgrade":
|
||||||
break
|
break;
|
||||||
case "delete":
|
case "delete":
|
||||||
if (args.length > 1) {
|
if (args.length > 1) {
|
||||||
del(sender, args[1]);
|
del(sender, args[1]);
|
||||||
} else {
|
} else {
|
||||||
console.sender(sender, '§c请输入插件名称!')
|
console.sender(sender, '§c请输入插件名称!')
|
||||||
}
|
}
|
||||||
break
|
break;
|
||||||
case "reload":
|
case "reload":
|
||||||
if (args.length > 1) {
|
if (args.length > 1) {
|
||||||
var pname = args[1]
|
var pname = args[1];
|
||||||
if (pluginCache.indexOf(pname) !== -1) {
|
if (pluginCache.indexOf(pname) !== -1) {
|
||||||
manager.reload(pname)
|
manager.reload(pname)
|
||||||
} else {
|
} else {
|
||||||
@ -95,7 +93,7 @@ function enable() {
|
|||||||
self.reloadConfig();
|
self.reloadConfig();
|
||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
break
|
break;
|
||||||
case "help":
|
case "help":
|
||||||
sendHelp(sender);
|
sendHelp(sender);
|
||||||
break;
|
break;
|
||||||
@ -105,7 +103,7 @@ function enable() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
tab: function (sender, command, args) {
|
tab: function (sender, command, args) {
|
||||||
if (args.length === 1) return ['list', 'install', 'update', 'upgrade', 'reload']
|
if (args.length === 1) return ['list', 'install', 'update', 'upgrade', 'reload'];
|
||||||
if (args.length > 1) {
|
if (args.length > 1) {
|
||||||
switch (args[0]) {
|
switch (args[0]) {
|
||||||
case "install":
|
case "install":
|
||||||
@ -159,4 +157,4 @@ module.exports = {
|
|||||||
load: load,
|
load: load,
|
||||||
enable: enable,
|
enable: enable,
|
||||||
disable: disable
|
disable: disable
|
||||||
}
|
};
|
||||||
|
@ -121,12 +121,13 @@ function newItemFromConfig(config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function enable() {
|
function enable() {
|
||||||
|
// noinspection JSUnusedLocalSymbols
|
||||||
command.on(this, 'l', {
|
command.on(this, 'l', {
|
||||||
cmd: function (sender, command, args) {
|
cmd: function (sender, command, args) {
|
||||||
if (!sender.openInventory) {
|
if (!sender.openInventory) {
|
||||||
console.sender(sender, "§4当前用户无法使用该命令!");
|
console.sender(sender, "§4当前用户无法使用该命令!");
|
||||||
}
|
}
|
||||||
var inv = bukkit.$.createInventory(null, 54, config.title);
|
var inv = MServer.createInventory(null, 54, config.title);
|
||||||
inv.setContents(items);
|
inv.setContents(items);
|
||||||
sender.openInventory(inv);
|
sender.openInventory(inv);
|
||||||
return true;
|
return true;
|
||||||
@ -178,14 +179,14 @@ function enable() {
|
|||||||
console.sender(player, '§c抽奖物品和钥匙不匹配!');
|
console.sender(player, '§c抽奖物品和钥匙不匹配!');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var resultlist = [];
|
var resultList = [];
|
||||||
litem.result.forEach(function (t) {
|
litem.result.forEach(function (t) {
|
||||||
for (var i = 0; i < t.percent; i++) {
|
for (var i = 0; i < t.percent; i++) {
|
||||||
resultlist.push(t);
|
resultList.push(t);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var ri = ext.random(resultlist.length);
|
var ri = ext.random(resultList.length);
|
||||||
var result = resultlist[ri];
|
var result = resultList[ri];
|
||||||
box.amount = box.amount - 1;
|
box.amount = box.amount - 1;
|
||||||
key.amount = key.amount - 1;
|
key.amount = key.amount - 1;
|
||||||
inv.setItem(10, box);
|
inv.setItem(10, box);
|
||||||
|
@ -46,8 +46,8 @@ function load() {
|
|||||||
function enable() {
|
function enable() {
|
||||||
command.on(self, 'mtag', {
|
command.on(self, 'mtag', {
|
||||||
cmd: function cmd(sender, command, args) {
|
cmd: function cmd(sender, command, args) {
|
||||||
var subcommand = args[0];
|
var subCommand = args[0];
|
||||||
switch (subcommand) {
|
switch (subCommand) {
|
||||||
case 'reload':
|
case 'reload':
|
||||||
self.reloadConfig();
|
self.reloadConfig();
|
||||||
fakeTag = new FakeTag(config.format);
|
fakeTag = new FakeTag(config.format);
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
/**
|
|
||||||
* PAPI扩展类
|
|
||||||
*/
|
|
||||||
/*global Java, base, module, exports, require, __FILE__*/
|
|
||||||
var PlaceholderAPI;
|
|
||||||
var bukkit = require('api/server');
|
|
||||||
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]);
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,14 +1,7 @@
|
|||||||
package pw.yumc.MiaoScript;
|
package pw.yumc.MiaoScript;
|
||||||
|
|
||||||
import java.io.FileReader;
|
|
||||||
|
|
||||||
import javax.script.ScriptEngineManager;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
|
||||||
import pw.yumc.YumCore.engine.MiaoScriptEngine;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created with IntelliJ IDEA
|
* Created with IntelliJ IDEA
|
||||||
*
|
*
|
||||||
@ -16,24 +9,7 @@ import pw.yumc.YumCore.engine.MiaoScriptEngine;
|
|||||||
* Created on 2017/9/14 10:08.
|
* Created on 2017/9/14 10:08.
|
||||||
*/
|
*/
|
||||||
public class MiaoScriptTest {
|
public class MiaoScriptTest {
|
||||||
private MiaoScriptEngine engine;
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBoot() {
|
public void testBoot() {
|
||||||
Thread currentThread = Thread.currentThread();
|
|
||||||
ClassLoader previousClassLoader = currentThread.getContextClassLoader();
|
|
||||||
currentThread.setContextClassLoader(getClass().getClassLoader());
|
|
||||||
try {
|
|
||||||
ScriptEngineManager manager = new ScriptEngineManager();
|
|
||||||
this.engine = new MiaoScriptEngine(manager);
|
|
||||||
this.engine.put("base", new Base());
|
|
||||||
this.engine.eval(new FileReader("src/main/resources/bios.js"));
|
|
||||||
engine.invokeFunction("boot", null, engine);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.w("脚本引擎初始化失败! %s:%s", e.getClass().getName(), e.getMessage());
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
currentThread.setContextClassLoader(previousClassLoader);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user