Init: Create & Init ms Project...
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
4
packages/bukkit/.gitignore
vendored
Normal file
4
packages/bukkit/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
/node_modules
|
||||
/dist
|
||||
/package-lock.json
|
||||
/yarn.lock
|
22
packages/bukkit/.npmignore
Normal file
22
packages/bukkit/.npmignore
Normal file
@ -0,0 +1,22 @@
|
||||
src
|
||||
test
|
||||
typings
|
||||
bundled
|
||||
build
|
||||
coverage
|
||||
docs
|
||||
wiki
|
||||
gulpfile.js
|
||||
bower.json
|
||||
karma.conf.js
|
||||
tsconfig.json
|
||||
typings.json
|
||||
CONTRIBUTING.md
|
||||
ISSUE_TEMPLATE.md
|
||||
PULL_REQUEST_TEMPLATE.md
|
||||
tslint.json
|
||||
wallaby.js
|
||||
.travis.yml
|
||||
.gitignore
|
||||
.vscode
|
||||
type_definitions
|
33
packages/bukkit/package.json
Normal file
33
packages/bukkit/package.json
Normal file
@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "@ms/bukkit",
|
||||
"version": "0.0.0",
|
||||
"description": "MiaoScript api package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
"minecraft",
|
||||
"bukkit",
|
||||
"sponge"
|
||||
],
|
||||
"author": "MiaoWoo <admin@yumc.pw>",
|
||||
"homepage": "https://github.com/circlecloud/ms.git",
|
||||
"license": "ISC",
|
||||
"main": "dist/index.js",
|
||||
"publishConfig": {
|
||||
"registry": "https://repo.yumc.pw/repository/npm/"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rimraf dist",
|
||||
"watch": "npx tsc --watch",
|
||||
"build": "yarn clean && npx tsc",
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.0",
|
||||
"typescript": "^3.6.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ms/api": "^0.0.0",
|
||||
"inversify": "^5.0.1"
|
||||
}
|
||||
}
|
98
packages/bukkit/src/command.ts
Normal file
98
packages/bukkit/src/command.ts
Normal file
@ -0,0 +1,98 @@
|
||||
import '@ms/nashorn'
|
||||
|
||||
import { injectable, postConstruct, inject } from 'inversify'
|
||||
import { command } from '@ms/api'
|
||||
import * as ref from '@ms/common/dist/reflect'
|
||||
|
||||
var bukkit = require('./server');
|
||||
var plugin = bukkit.plugin.self;
|
||||
var commandMap = ref.on(bukkit.plugin.manager).get('commandMap').get();
|
||||
var PluginCommand = Java.type('org.bukkit.command.PluginCommand');
|
||||
|
||||
var Arrays = Java.type('java.util.Arrays');
|
||||
var TabCompleter = Java.type("org.bukkit.command.TabCompleter");
|
||||
var CommandExecutor = Java.type("org.bukkit.command.CommandExecutor");
|
||||
|
||||
@injectable()
|
||||
export class BukkitCommand extends command.Command {
|
||||
@inject("Plugin.Self")
|
||||
private plugin: any
|
||||
|
||||
@postConstruct()
|
||||
init() {
|
||||
|
||||
}
|
||||
|
||||
enable(jsp) {
|
||||
var commands = jsp.description.commands;
|
||||
if (commands) {
|
||||
var pluginCommands = [];
|
||||
for (var name in commands) {
|
||||
// noinspection JSUnfilteredForInLoop
|
||||
var command = commands[name];
|
||||
if (typeof command !== 'object') continue;
|
||||
command.name = name;
|
||||
// noinspection JSUnfilteredForInLoop
|
||||
var newCmd = this.create(jsp, command);
|
||||
if (command.description) newCmd.setDescription(command.description);
|
||||
if (command.usage) newCmd.setUsage(command.usage);
|
||||
/** @namespace command.aliases */
|
||||
if (command.aliases) newCmd.setAliases(Arrays.asList(command.aliases));
|
||||
if (command.permission) newCmd.setPermission(command.permission);
|
||||
if (command['permission-message']) newCmd.setPermissionMessage(command['permission-message']);
|
||||
pluginCommands.push(newCmd);
|
||||
// noinspection JSUnfilteredForInLoop
|
||||
console.debug(`插件 ${jsp.description.name} 注册命令 ${name} ...`);
|
||||
}
|
||||
commandMap.registerAll(jsp.description.name, Arrays.asList(pluginCommands));
|
||||
}
|
||||
}
|
||||
|
||||
disable(jsp) {
|
||||
var commands = jsp.description.commands;
|
||||
if (commands) {
|
||||
for (var name in commands) {
|
||||
//TODO 删除插件命令
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
create(jsp, command) {
|
||||
var cmd = commandMap.getCommand(command.name)
|
||||
if (cmd && cmd instanceof PluginCommand) { return cmd };
|
||||
cmd = ref.on(PluginCommand).create(command.name, plugin).get();
|
||||
commandMap.register(jsp.description.name, cmd);
|
||||
return cmd;
|
||||
}
|
||||
|
||||
onCommand(jsp, c, cmd) {
|
||||
// 必须指定需要实现的接口类型 否则MOD服会报错
|
||||
c.setExecutor(new CommandExecutor({
|
||||
onCommand: function(sender, _, command, args) {
|
||||
try {
|
||||
return cmd(sender, command, Java.from(args));
|
||||
} catch (ex) {
|
||||
console.console(`§6玩家 §a${sender.name} §6执行 §b${jsp.description.name} §6插件 §d${command} ${Java.from(args).join(' ')} §6命令时发生异常 §4${ex}`);
|
||||
console.ex(ex);
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
onTabComplete(jsp, c, tab) {
|
||||
// 必须指定需要实现的接口类型 否则MOD服会报错
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
c.setTabCompleter(new TabCompleter({
|
||||
onTabComplete: function(sender, _, command, args) {
|
||||
try {
|
||||
var token = args[args.length - 1];
|
||||
var complete = tab(sender, command, Java.from(args)) || [];
|
||||
return Arrays.asList(complete.copyPartialMatches(token, []));
|
||||
} catch (ex) {
|
||||
console.console(`§6玩家 §a${sender.name} §6执行 §b${jsp.description.name} §6插件 §d${command} ${Java.from(args).join(' ')} §6补全时发生异常 §4${ex}`);
|
||||
console.ex(ex);
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
21
packages/bukkit/src/console.ts
Normal file
21
packages/bukkit/src/console.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { MiaoScriptConsole } from '@ms/api'
|
||||
|
||||
let Bukkit = Java.type("org.bukkit.Bukkit");
|
||||
let CommandSender = Java.type("org.bukkit.command.CommandSender");
|
||||
|
||||
export class BukkitConsole extends MiaoScriptConsole {
|
||||
sender(sender, ...args) {
|
||||
if (!(sender instanceof CommandSender)) {
|
||||
this.error("第一个参数未实现 org.bukkit.command.CommandSender 无法发送消息!")
|
||||
return;
|
||||
}
|
||||
if (args[0].toString() === "[object Array]") {
|
||||
args[0].forEach(line => sender.sendMessage(this.prefix + line))
|
||||
} else {
|
||||
sender.sendMessage(this.prefix + args.join(' '));
|
||||
}
|
||||
}
|
||||
console(...args): void {
|
||||
this.sender(Bukkit.consoleSender, args.join(' '));
|
||||
}
|
||||
}
|
11
packages/bukkit/src/index.ts
Normal file
11
packages/bukkit/src/index.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { server, plugin } from '@ms/api'
|
||||
import { DefaultContainer as container } from '@ms/container'
|
||||
|
||||
import { BukkitConsole } from './console'
|
||||
|
||||
let BukkitServerType = 'bukkit';
|
||||
let Bukkit = Java.type("org.bukkit.Bukkit");
|
||||
|
||||
container.bind(server.Console).toConstantValue(BukkitConsole);
|
||||
container.bind(server.ServerType).toConstantValue(BukkitServerType);
|
||||
container.bind(plugin.PluginInstance).toConstantValue(Bukkit.pluginManager.getPlugin('MiaoScript'));
|
7
packages/bukkit/tsconfig.json
Normal file
7
packages/bukkit/tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "src",
|
||||
"outDir": "dist"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user