@ -6,13 +6,30 @@
|
||||
|
||||
/*global Java, base, module, exports, require, __FILE__*/
|
||||
var Bukkit = Java.type("org.bukkit.Bukkit");
|
||||
// noinspection JSUnresolvedVariable
|
||||
var PluginManager = Bukkit.pluginManager;
|
||||
|
||||
/**
|
||||
* 插件管理
|
||||
* @type {{manager: *, get: exports.plugin.get, load: exports.plugin.load}}
|
||||
*/
|
||||
exports.plugin = {
|
||||
/**
|
||||
* 插件管理工具
|
||||
*/
|
||||
manager: PluginManager,
|
||||
/**
|
||||
* 获得插件实例
|
||||
* @param name 插件名称
|
||||
* @returns {*}
|
||||
*/
|
||||
get: function (name) {
|
||||
return PluginManager.getPlugin(name);
|
||||
},
|
||||
/**
|
||||
* 载入插件 并且返回结果
|
||||
* @param name 插件名称
|
||||
* @returns {*}
|
||||
*/
|
||||
load: function (name) {
|
||||
var plugin = this.get(name);
|
||||
if (ext.notNull(plugin) && !plugin.isEnabled()) {
|
||||
@ -21,6 +38,10 @@ exports.plugin = {
|
||||
return PluginManager.isPluginEnabled(name);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* 公告
|
||||
* @param message 消息
|
||||
*/
|
||||
exports.broadcast = function (message) {
|
||||
Bukkit.broadcastMessage(message);
|
||||
};
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
var papi = require("modules/ext/papi");
|
||||
var event = require('modules/event');
|
||||
var joinCancel;
|
||||
var join;
|
||||
/*global Java, base, module, exports, require*/
|
||||
var description = {
|
||||
name: 'HelloWorld',
|
||||
@ -18,15 +18,15 @@ function load() {
|
||||
|
||||
function enable() {
|
||||
log.i('启用 Hello Wrold 测试插件!');
|
||||
joinCancel = event.on('playerloginevent', function (event) {
|
||||
join = event.on('playerloginevent', function (event) {
|
||||
// noinspection JSUnresolvedVariable
|
||||
event.player.sendMessage('§a欢迎来到 §bMiaoScript §a的世界!');
|
||||
event.player.sendMessage(papi.$(event.player, "§a欢迎来到 §bMiaoScript §a的世界! 当前在线: %server_onlone%"));
|
||||
});
|
||||
}
|
||||
|
||||
function disable() {
|
||||
log.i('卸载 Hello Wrold 测试插件!');
|
||||
event.off(joinCancel);
|
||||
event.off(join);
|
||||
}
|
||||
|
||||
exports = {
|
||||
|
@ -1,39 +0,0 @@
|
||||
package pw.yumc.MiaoScript;
|
||||
|
||||
import java.io.FileReader;
|
||||
|
||||
import javax.script.ScriptEngineManager;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import pw.yumc.YumCore.bukkit.Log;
|
||||
import pw.yumc.YumCore.engine.MiaoScriptEngine;
|
||||
|
||||
/**
|
||||
* Created with IntelliJ IDEA
|
||||
*
|
||||
* @author 喵♂呜
|
||||
* Created on 2017/9/14 10:08.
|
||||
*/
|
||||
public class MiaoScriptTest {
|
||||
private MiaoScriptEngine engine;
|
||||
|
||||
@Test
|
||||
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 MiaoScript.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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user