Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d90980726 | |||
| 42de3700ba | |||
| 5991662764 | |||
| 1c98c19e37 | |||
| c596280d8d | |||
| 77301e0130 | |||
| 90878fc7df | |||
| a0a4c13e7b | |||
| 0e92a9c795 |
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"version": "0.4.1",
|
"version": "0.4.2",
|
||||||
"useWorkspaces": true,
|
"useWorkspaces": true,
|
||||||
"npmClient": "yarn",
|
"npmClient": "yarn",
|
||||||
"packages": [
|
"packages": [
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ms/api",
|
"name": "@ms/api",
|
||||||
"version": "0.4.1",
|
"version": "0.4.2",
|
||||||
"description": "MiaoScript api package",
|
"description": "MiaoScript api package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ms/container": "^0.4.0",
|
"@ms/container": "^0.4.0",
|
||||||
"@ms/ployfill": "^0.4.1",
|
"@ms/ployfill": "^0.4.2",
|
||||||
"source-map-builder": "^0.0.7"
|
"source-map-builder": "^0.0.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -41,9 +41,11 @@ export namespace command {
|
|||||||
try {
|
try {
|
||||||
return executor(sender, command, Java.from(args));
|
return executor(sender, command, Java.from(args));
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.i18n("ms.api.command.execute.error", { sender: sender.name, plugin: plugin.description.name, command, args: Java.from(args).join(' '), ex })
|
console.i18n("ms.api.command.execute.error", { player: sender.name, plugin: plugin.description.name, command, args: Java.from(args).join(' '), ex })
|
||||||
console.ex(ex);
|
console.ex(ex);
|
||||||
console.sender(sender, [i18n.translate("ms.api.command.execute.error", { sender: sender.name, plugin: plugin.description.name, command, args: Java.from(args).join(' '), ex }), ...console.stack(ex)])
|
if (sender.name != 'CONSOLE') {
|
||||||
|
console.sender(sender, [i18n.translate("ms.api.command.execute.error", { player: sender.name, plugin: plugin.description.name, command, args: Java.from(args).join(' '), ex }), ...console.stack(ex)])
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ export namespace server {
|
|||||||
dispatchConsoleCommand(command: string): boolean;
|
dispatchConsoleCommand(command: string): boolean;
|
||||||
getPluginsFolder(): string;
|
getPluginsFolder(): string;
|
||||||
getNativePluginManager(): NativePluginManager;
|
getNativePluginManager(): NativePluginManager;
|
||||||
|
getNettyPipeline(): any;
|
||||||
sendJson(sender: string | any, json: object | string): void;
|
sendJson(sender: string | any, json: object | string): void;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ export namespace task {
|
|||||||
* @param func 执行内容
|
* @param func 执行内容
|
||||||
*/
|
*/
|
||||||
callSyncMethod(func: Function): any;
|
callSyncMethod(func: Function): any;
|
||||||
|
/**
|
||||||
|
* 关闭任务管理器
|
||||||
|
*/
|
||||||
|
disable();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 任务抽象
|
* 任务抽象
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ms/bukkit",
|
"name": "@ms/bukkit",
|
||||||
"version": "0.4.1",
|
"version": "0.4.2",
|
||||||
"description": "MiaoScript bukkit package",
|
"description": "MiaoScript bukkit package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -27,8 +27,8 @@
|
|||||||
"typescript": "^3.8.3"
|
"typescript": "^3.8.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ms/api": "^0.4.1",
|
"@ms/api": "^0.4.2",
|
||||||
"@ms/common": "^0.4.0",
|
"@ms/common": "^0.4.2",
|
||||||
"@ms/container": "^0.4.0"
|
"@ms/container": "^0.4.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,26 @@
|
|||||||
import { server } from '@ms/api'
|
import { server } from '@ms/api'
|
||||||
import { provideSingleton } from '@ms/container';
|
import { provideSingleton } from '@ms/container';
|
||||||
|
|
||||||
|
import * as reflect from '@ms/common/dist/reflect'
|
||||||
import chat from './enhance/chat'
|
import chat from './enhance/chat'
|
||||||
|
|
||||||
|
const refList: Array<{ server: string, future: string }> = [
|
||||||
|
{ server: 'aq', future: 'g' },//spigot 1.8.8
|
||||||
|
{ server: 'an', future: 'g' },//spigot 1.12.2
|
||||||
|
{ server: 'getServerConnection', future: 'f' },//after spigot 1.14.4
|
||||||
|
{ server: 'func_147137_ag', future: 'field_151274_e' }//catserver 1.12.2
|
||||||
|
]
|
||||||
|
|
||||||
let Bukkit = org.bukkit.Bukkit;
|
let Bukkit = org.bukkit.Bukkit;
|
||||||
|
|
||||||
@provideSingleton(server.Server)
|
@provideSingleton(server.Server)
|
||||||
export class BukkitServer implements server.Server {
|
export class BukkitServer implements server.Server {
|
||||||
private pluginsFolder: string;
|
private pluginsFolder: string;
|
||||||
|
private pipeline: any;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.pluginsFolder = Bukkit.getUpdateFolderFile().getParentFile().getCanonicalPath();
|
this.pluginsFolder = Bukkit.getUpdateFolderFile().getParentFile().getCanonicalPath();
|
||||||
|
this.reflectPipeline()
|
||||||
}
|
}
|
||||||
|
|
||||||
getPlayer(name: string) {
|
getPlayer(name: string) {
|
||||||
@@ -43,6 +53,9 @@ export class BukkitServer implements server.Server {
|
|||||||
getNativePluginManager() {
|
getNativePluginManager() {
|
||||||
return Bukkit.getPluginManager() as any;
|
return Bukkit.getPluginManager() as any;
|
||||||
}
|
}
|
||||||
|
getNettyPipeline() {
|
||||||
|
return this.pipeline;
|
||||||
|
}
|
||||||
sendJson(sender: string | any, json: object | string): void {
|
sendJson(sender: string | any, json: object | string): void {
|
||||||
if (typeof sender === "string") {
|
if (typeof sender === "string") {
|
||||||
sender = this.getPlayer(sender)
|
sender = this.getPlayer(sender)
|
||||||
@@ -52,4 +65,17 @@ export class BukkitServer implements server.Server {
|
|||||||
this.dispatchConsoleCommand(result)
|
this.dispatchConsoleCommand(result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private reflectPipeline() {
|
||||||
|
let consoleServer = reflect.on(Bukkit.getServer()).get('console').get()
|
||||||
|
let promise: any;
|
||||||
|
for (const ref of refList) {
|
||||||
|
try {
|
||||||
|
promise = reflect.on(consoleServer).call(ref.server).get(ref.future).get().get(0); break;
|
||||||
|
} catch (error) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!promise) { console.error("Can't found ServerConnection or ChannelFuture !"); return }
|
||||||
|
this.pipeline = reflect.on(promise).get('channel').get().pipeline()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ export class BukkitTaskManager implements task.TaskManager {
|
|||||||
callSyncMethod(func: Function): any {
|
callSyncMethod(func: Function): any {
|
||||||
return Bukkit.getScheduler().callSyncMethod(this.pluginInstance, new Callable({ call: () => func() })).get()
|
return Bukkit.getScheduler().callSyncMethod(this.pluginInstance, new Callable({ call: () => func() })).get()
|
||||||
}
|
}
|
||||||
|
disable() {
|
||||||
|
Bukkit.getScheduler().cancelTasks(this.pluginInstance);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class BukkitTask extends task.Task {
|
export class BukkitTask extends task.Task {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ms/bungee",
|
"name": "@ms/bungee",
|
||||||
"version": "0.4.1",
|
"version": "0.4.2",
|
||||||
"description": "MiaoScript bungee package",
|
"description": "MiaoScript bungee package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -27,8 +27,8 @@
|
|||||||
"typescript": "^3.8.3"
|
"typescript": "^3.8.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ms/api": "^0.4.1",
|
"@ms/api": "^0.4.2",
|
||||||
"@ms/common": "^0.4.0",
|
"@ms/common": "^0.4.2",
|
||||||
"@ms/container": "^0.4.0"
|
"@ms/container": "^0.4.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,42 @@
|
|||||||
import { server } from '@ms/api'
|
import { server, task } from '@ms/api'
|
||||||
import { provideSingleton } from '@ms/container';
|
import { provideSingleton, inject, postConstruct } from '@ms/container'
|
||||||
|
|
||||||
|
import * as reflect from '@ms/common/dist/reflect'
|
||||||
|
|
||||||
let Bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy();
|
let Bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy();
|
||||||
|
|
||||||
@provideSingleton(server.Server)
|
@provideSingleton(server.Server)
|
||||||
export class BungeeServer implements server.Server {
|
export class BungeeServer implements server.Server {
|
||||||
private pluginsFolder: string;
|
private pluginsFolder: string;
|
||||||
|
private pipeline: any;
|
||||||
|
|
||||||
|
@inject(task.TaskManager)
|
||||||
|
private task: task.TaskManager
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.pluginsFolder = Bungee.getPluginsFolder().getCanonicalPath();
|
this.pluginsFolder = Bungee.getPluginsFolder().getCanonicalPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@postConstruct()
|
||||||
|
initialize() {
|
||||||
|
let count = 0;
|
||||||
|
let wait = this.task.create(() => {
|
||||||
|
try {
|
||||||
|
// @ts-ignore
|
||||||
|
this.pipeline = reflect.on(base.getInstance().getProxy()).get('listeners').get().toArray()[0].pipeline()
|
||||||
|
wait.cancel();
|
||||||
|
} catch (ex) {
|
||||||
|
count++
|
||||||
|
if (count > 50) {
|
||||||
|
console.error('Reflect BungeeCord netty channel pipeline error time > 50times. Err: ' + ex)
|
||||||
|
wait.cancel()
|
||||||
|
} else {
|
||||||
|
console.warn('Wait BungeeCord start ready to get netty channel pipeline. Err: ' + ex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).later(10).timer(20).submit()
|
||||||
|
}
|
||||||
|
|
||||||
getPlayer(name: string) {
|
getPlayer(name: string) {
|
||||||
return Bungee.getPlayer(name);
|
return Bungee.getPlayer(name);
|
||||||
}
|
}
|
||||||
@@ -41,6 +67,9 @@ export class BungeeServer implements server.Server {
|
|||||||
getNativePluginManager() {
|
getNativePluginManager() {
|
||||||
return Bungee.getPluginManager() as any
|
return Bungee.getPluginManager() as any
|
||||||
}
|
}
|
||||||
|
getNettyPipeline() {
|
||||||
|
return this.pipeline;
|
||||||
|
}
|
||||||
sendJson(sender: string | any, json: string): void {
|
sendJson(sender: string | any, json: string): void {
|
||||||
throw new Error("Method not implemented.");
|
throw new Error("Method not implemented.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ export class BungeeTaskManager implements task.TaskManager {
|
|||||||
callSyncMethod(func: Function): any {
|
callSyncMethod(func: Function): any {
|
||||||
return func();
|
return func();
|
||||||
}
|
}
|
||||||
|
disable() {
|
||||||
|
this.pluginInstance.getProxy().getScheduler().cancel(this.pluginInstance)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class BungeeTask extends task.Task {
|
export class BungeeTask extends task.Task {
|
||||||
@@ -25,9 +28,9 @@ export class BungeeTask extends task.Task {
|
|||||||
return this.plugin.getProxy().getScheduler().runAsync(this.plugin, run)
|
return this.plugin.getProxy().getScheduler().runAsync(this.plugin, run)
|
||||||
}
|
}
|
||||||
if (this.interval) {
|
if (this.interval) {
|
||||||
return this.plugin.getProxy().getScheduler().schedule(this.plugin, run, this.laterTime, this.interval, TimeUnit.MILLISECONDS)
|
return this.plugin.getProxy().getScheduler().schedule(this.plugin, run, this.laterTime * 50, this.interval * 50, TimeUnit.MILLISECONDS)
|
||||||
} else {
|
} else {
|
||||||
return this.plugin.getProxy().getScheduler().schedule(this.plugin, run, this.laterTime, TimeUnit.MILLISECONDS)
|
return this.plugin.getProxy().getScheduler().schedule(this.plugin, run, this.laterTime * 50, TimeUnit.MILLISECONDS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"name": "@ms/client",
|
"name": "@ms/client",
|
||||||
"version": "0.4.0",
|
"version": "0.4.2",
|
||||||
"description": "MiaoScript client package",
|
"description": "MiaoScript client package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -28,7 +28,6 @@
|
|||||||
"minecraft-protocol": "^1.11.0"
|
"minecraft-protocol": "^1.11.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nestjs/cli": "^6.14.2",
|
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^3.8.3"
|
"typescript": "^3.8.3"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ import { attachForge } from './forge'
|
|||||||
import { attachEvents } from './event'
|
import { attachEvents } from './event'
|
||||||
|
|
||||||
let username = process.argv[2] || 'Mr_jtb'
|
let username = process.argv[2] || 'Mr_jtb'
|
||||||
|
let version = process.argv[3] || '1.12.2'
|
||||||
let client = createConnection('192.168.2.5', 25577, username)
|
let client = createConnection('192.168.2.5', 25577, username)
|
||||||
|
|
||||||
function createConnection(host: string, port: number, username: string) {
|
function createConnection(host: string, port: number, username: string) {
|
||||||
let client = createClient({
|
let client = createClient({
|
||||||
version: '1.12.2',
|
version,
|
||||||
host,
|
host,
|
||||||
port,
|
port,
|
||||||
username,
|
username,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ms/common",
|
"name": "@ms/common",
|
||||||
"version": "0.4.0",
|
"version": "0.4.2",
|
||||||
"description": "MiaoScript api package",
|
"description": "MiaoScript api package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
|
|||||||
@@ -198,4 +198,4 @@ export = {
|
|||||||
accessible,
|
accessible,
|
||||||
declaredMethods,
|
declaredMethods,
|
||||||
mapToObject
|
mapToObject
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ms/core",
|
"name": "@ms/core",
|
||||||
"version": "0.4.1",
|
"version": "0.4.2",
|
||||||
"description": "MiaoScript api package",
|
"description": "MiaoScript api package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
"typescript": "^3.8.3"
|
"typescript": "^3.8.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ms/api": "^0.4.1",
|
"@ms/api": "^0.4.2",
|
||||||
"@ms/container": "^0.4.0"
|
"@ms/container": "^0.4.0"
|
||||||
},
|
},
|
||||||
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ class MiaoScriptCore {
|
|||||||
disable() {
|
disable() {
|
||||||
console.i18n("ms.core.engine.disable")
|
console.i18n("ms.core.engine.disable")
|
||||||
this.pluginManager.disable();
|
this.pluginManager.disable();
|
||||||
|
this.taskManager.disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ms/i18n",
|
"name": "@ms/i18n",
|
||||||
"version": "0.4.1",
|
"version": "0.4.2",
|
||||||
"description": "MiaoScript i18n package",
|
"description": "MiaoScript i18n package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/js-yaml": "^3.12.2",
|
"@types/js-yaml": "^3.12.3",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^3.8.3"
|
"typescript": "^3.8.3"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ms/nodejs",
|
"name": "@ms/nodejs",
|
||||||
"version": "0.4.1",
|
"version": "0.4.2",
|
||||||
"description": "MiaoScript nodejs package",
|
"description": "MiaoScript nodejs package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
|
|||||||
442
packages/nodejs/src/punycode/index.ts
Normal file
442
packages/nodejs/src/punycode/index.ts
Normal file
@@ -0,0 +1,442 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/** Highest positive signed 32-bit float value */
|
||||||
|
const maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1
|
||||||
|
|
||||||
|
/** Bootstring parameters */
|
||||||
|
const base = 36;
|
||||||
|
const tMin = 1;
|
||||||
|
const tMax = 26;
|
||||||
|
const skew = 38;
|
||||||
|
const damp = 700;
|
||||||
|
const initialBias = 72;
|
||||||
|
const initialN = 128; // 0x80
|
||||||
|
const delimiter = '-'; // '\x2D'
|
||||||
|
|
||||||
|
/** Regular expressions */
|
||||||
|
const regexPunycode = /^xn--/;
|
||||||
|
const regexNonASCII = /[^\0-\x7E]/; // non-ASCII chars
|
||||||
|
const regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
|
||||||
|
|
||||||
|
/** Error messages */
|
||||||
|
const errors = {
|
||||||
|
'overflow': 'Overflow: input needs wider integers to process',
|
||||||
|
'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
|
||||||
|
'invalid-input': 'Invalid input'
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Convenience shortcuts */
|
||||||
|
const baseMinusTMin = base - tMin;
|
||||||
|
const floor = Math.floor;
|
||||||
|
const stringFromCharCode = String.fromCharCode;
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A generic error utility function.
|
||||||
|
* @private
|
||||||
|
* @param {String} type The error type.
|
||||||
|
* @returns {Error} Throws a `RangeError` with the applicable error message.
|
||||||
|
*/
|
||||||
|
function error(type) {
|
||||||
|
throw new RangeError(errors[type]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A generic `Array#map` utility function.
|
||||||
|
* @private
|
||||||
|
* @param {Array} array The array to iterate over.
|
||||||
|
* @param {Function} callback The function that gets called for every array
|
||||||
|
* item.
|
||||||
|
* @returns {Array} A new array of values returned by the callback function.
|
||||||
|
*/
|
||||||
|
function map(array, fn) {
|
||||||
|
const result = [];
|
||||||
|
let length = array.length;
|
||||||
|
while (length--) {
|
||||||
|
result[length] = fn(array[length]);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple `Array#map`-like wrapper to work with domain name strings or email
|
||||||
|
* addresses.
|
||||||
|
* @private
|
||||||
|
* @param {String} domain The domain name or email address.
|
||||||
|
* @param {Function} callback The function that gets called for every
|
||||||
|
* character.
|
||||||
|
* @returns {Array} A new string of characters returned by the callback
|
||||||
|
* function.
|
||||||
|
*/
|
||||||
|
function mapDomain(string, fn) {
|
||||||
|
const parts = string.split('@');
|
||||||
|
let result = '';
|
||||||
|
if (parts.length > 1) {
|
||||||
|
// In email addresses, only the domain name should be punycoded. Leave
|
||||||
|
// the local part (i.e. everything up to `@`) intact.
|
||||||
|
result = parts[0] + '@';
|
||||||
|
string = parts[1];
|
||||||
|
}
|
||||||
|
// Avoid `split(regex)` for IE8 compatibility. See #17.
|
||||||
|
string = string.replace(regexSeparators, '\x2E');
|
||||||
|
const labels = string.split('.');
|
||||||
|
const encoded = map(labels, fn).join('.');
|
||||||
|
return result + encoded;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an array containing the numeric code points of each Unicode
|
||||||
|
* character in the string. While JavaScript uses UCS-2 internally,
|
||||||
|
* this function will convert a pair of surrogate halves (each of which
|
||||||
|
* UCS-2 exposes as separate characters) into a single code point,
|
||||||
|
* matching UTF-16.
|
||||||
|
* @see `punycode.ucs2.encode`
|
||||||
|
* @see <https://mathiasbynens.be/notes/javascript-encoding>
|
||||||
|
* @memberOf punycode.ucs2
|
||||||
|
* @name decode
|
||||||
|
* @param {String} string The Unicode input string (UCS-2).
|
||||||
|
* @returns {Array} The new array of code points.
|
||||||
|
*/
|
||||||
|
function ucs2decode(string) {
|
||||||
|
const output = [];
|
||||||
|
let counter = 0;
|
||||||
|
const length = string.length;
|
||||||
|
while (counter < length) {
|
||||||
|
const value = string.charCodeAt(counter++);
|
||||||
|
if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
|
||||||
|
// It's a high surrogate, and there is a next character.
|
||||||
|
const extra = string.charCodeAt(counter++);
|
||||||
|
if ((extra & 0xFC00) == 0xDC00) { // Low surrogate.
|
||||||
|
output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
|
||||||
|
} else {
|
||||||
|
// It's an unmatched surrogate; only append this code unit, in case the
|
||||||
|
// next code unit is the high surrogate of a surrogate pair.
|
||||||
|
output.push(value);
|
||||||
|
counter--;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
output.push(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a string based on an array of numeric code points.
|
||||||
|
* @see `punycode.ucs2.decode`
|
||||||
|
* @memberOf punycode.ucs2
|
||||||
|
* @name encode
|
||||||
|
* @param {Array} codePoints The array of numeric code points.
|
||||||
|
* @returns {String} The new Unicode string (UCS-2).
|
||||||
|
*/
|
||||||
|
const ucs2encode = array => String.fromCodePoint(...array);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a basic code point into a digit/integer.
|
||||||
|
* @see `digitToBasic()`
|
||||||
|
* @private
|
||||||
|
* @param {Number} codePoint The basic numeric code point value.
|
||||||
|
* @returns {Number} The numeric value of a basic code point (for use in
|
||||||
|
* representing integers) in the range `0` to `base - 1`, or `base` if
|
||||||
|
* the code point does not represent a value.
|
||||||
|
*/
|
||||||
|
const basicToDigit = function (codePoint) {
|
||||||
|
if (codePoint - 0x30 < 0x0A) {
|
||||||
|
return codePoint - 0x16;
|
||||||
|
}
|
||||||
|
if (codePoint - 0x41 < 0x1A) {
|
||||||
|
return codePoint - 0x41;
|
||||||
|
}
|
||||||
|
if (codePoint - 0x61 < 0x1A) {
|
||||||
|
return codePoint - 0x61;
|
||||||
|
}
|
||||||
|
return base;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a digit/integer into a basic code point.
|
||||||
|
* @see `basicToDigit()`
|
||||||
|
* @private
|
||||||
|
* @param {Number} digit The numeric value of a basic code point.
|
||||||
|
* @returns {Number} The basic code point whose value (when used for
|
||||||
|
* representing integers) is `digit`, which needs to be in the range
|
||||||
|
* `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
|
||||||
|
* used; else, the lowercase form is used. The behavior is undefined
|
||||||
|
* if `flag` is non-zero and `digit` has no uppercase form.
|
||||||
|
*/
|
||||||
|
const digitToBasic = function (digit: number, flag: number) {
|
||||||
|
// 0..25 map to ASCII a..z or A..Z
|
||||||
|
// 26..35 map to ASCII 0..9
|
||||||
|
//@ts-ignore
|
||||||
|
return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bias adaptation function as per section 3.4 of RFC 3492.
|
||||||
|
* https://tools.ietf.org/html/rfc3492#section-3.4
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
const adapt = function (delta, numPoints, firstTime) {
|
||||||
|
let k = 0;
|
||||||
|
delta = firstTime ? floor(delta / damp) : delta >> 1;
|
||||||
|
delta += floor(delta / numPoints);
|
||||||
|
for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {
|
||||||
|
delta = floor(delta / baseMinusTMin);
|
||||||
|
}
|
||||||
|
return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a Punycode string of ASCII-only symbols to a string of Unicode
|
||||||
|
* symbols.
|
||||||
|
* @memberOf punycode
|
||||||
|
* @param {String} input The Punycode string of ASCII-only symbols.
|
||||||
|
* @returns {String} The resulting string of Unicode symbols.
|
||||||
|
*/
|
||||||
|
const decode = function (input) {
|
||||||
|
// Don't use UCS-2.
|
||||||
|
const output = [];
|
||||||
|
const inputLength = input.length;
|
||||||
|
let i = 0;
|
||||||
|
let n = initialN;
|
||||||
|
let bias = initialBias;
|
||||||
|
|
||||||
|
// Handle the basic code points: let `basic` be the number of input code
|
||||||
|
// points before the last delimiter, or `0` if there is none, then copy
|
||||||
|
// the first basic code points to the output.
|
||||||
|
|
||||||
|
let basic = input.lastIndexOf(delimiter);
|
||||||
|
if (basic < 0) {
|
||||||
|
basic = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let j = 0; j < basic; ++j) {
|
||||||
|
// if it's not a basic code point
|
||||||
|
if (input.charCodeAt(j) >= 0x80) {
|
||||||
|
error('not-basic');
|
||||||
|
}
|
||||||
|
output.push(input.charCodeAt(j));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Main decoding loop: start just after the last delimiter if any basic code
|
||||||
|
// points were copied; start at the beginning otherwise.
|
||||||
|
|
||||||
|
for (let index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {
|
||||||
|
|
||||||
|
// `index` is the index of the next character to be consumed.
|
||||||
|
// Decode a generalized variable-length integer into `delta`,
|
||||||
|
// which gets added to `i`. The overflow checking is easier
|
||||||
|
// if we increase `i` as we go, then subtract off its starting
|
||||||
|
// value at the end to obtain `delta`.
|
||||||
|
let oldi = i;
|
||||||
|
for (let w = 1, k = base; /* no condition */; k += base) {
|
||||||
|
|
||||||
|
if (index >= inputLength) {
|
||||||
|
error('invalid-input');
|
||||||
|
}
|
||||||
|
|
||||||
|
const digit = basicToDigit(input.charCodeAt(index++));
|
||||||
|
|
||||||
|
if (digit >= base || digit > floor((maxInt - i) / w)) {
|
||||||
|
error('overflow');
|
||||||
|
}
|
||||||
|
|
||||||
|
i += digit * w;
|
||||||
|
const t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
|
||||||
|
|
||||||
|
if (digit < t) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
const baseMinusT = base - t;
|
||||||
|
if (w > floor(maxInt / baseMinusT)) {
|
||||||
|
error('overflow');
|
||||||
|
}
|
||||||
|
|
||||||
|
w *= baseMinusT;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const out = output.length + 1;
|
||||||
|
bias = adapt(i - oldi, out, oldi == 0);
|
||||||
|
|
||||||
|
// `i` was supposed to wrap around from `out` to `0`,
|
||||||
|
// incrementing `n` each time, so we'll fix that now:
|
||||||
|
if (floor(i / out) > maxInt - n) {
|
||||||
|
error('overflow');
|
||||||
|
}
|
||||||
|
|
||||||
|
n += floor(i / out);
|
||||||
|
i %= out;
|
||||||
|
|
||||||
|
// Insert `n` at position `i` of the output.
|
||||||
|
output.splice(i++, 0, n);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return String.fromCodePoint(...output);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a string of Unicode symbols (e.g. a domain name label) to a
|
||||||
|
* Punycode string of ASCII-only symbols.
|
||||||
|
* @memberOf punycode
|
||||||
|
* @param {String} input The string of Unicode symbols.
|
||||||
|
* @returns {String} The resulting Punycode string of ASCII-only symbols.
|
||||||
|
*/
|
||||||
|
const encode = function (input) {
|
||||||
|
const output = [];
|
||||||
|
|
||||||
|
// Convert the input in UCS-2 to an array of Unicode code points.
|
||||||
|
input = ucs2decode(input);
|
||||||
|
|
||||||
|
// Cache the length.
|
||||||
|
let inputLength = input.length;
|
||||||
|
|
||||||
|
// Initialize the state.
|
||||||
|
let n = initialN;
|
||||||
|
let delta = 0;
|
||||||
|
let bias = initialBias;
|
||||||
|
|
||||||
|
// Handle the basic code points.
|
||||||
|
for (const currentValue of input) {
|
||||||
|
if (currentValue < 0x80) {
|
||||||
|
output.push(stringFromCharCode(currentValue));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let basicLength = output.length;
|
||||||
|
let handledCPCount = basicLength;
|
||||||
|
|
||||||
|
// `handledCPCount` is the number of code points that have been handled;
|
||||||
|
// `basicLength` is the number of basic code points.
|
||||||
|
|
||||||
|
// Finish the basic string with a delimiter unless it's empty.
|
||||||
|
if (basicLength) {
|
||||||
|
output.push(delimiter);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Main encoding loop:
|
||||||
|
while (handledCPCount < inputLength) {
|
||||||
|
|
||||||
|
// All non-basic code points < n have been handled already. Find the next
|
||||||
|
// larger one:
|
||||||
|
let m = maxInt;
|
||||||
|
for (const currentValue of input) {
|
||||||
|
if (currentValue >= n && currentValue < m) {
|
||||||
|
m = currentValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
|
||||||
|
// but guard against overflow.
|
||||||
|
const handledCPCountPlusOne = handledCPCount + 1;
|
||||||
|
if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
|
||||||
|
error('overflow');
|
||||||
|
}
|
||||||
|
|
||||||
|
delta += (m - n) * handledCPCountPlusOne;
|
||||||
|
n = m;
|
||||||
|
|
||||||
|
for (const currentValue of input) {
|
||||||
|
if (currentValue < n && ++delta > maxInt) {
|
||||||
|
error('overflow');
|
||||||
|
}
|
||||||
|
if (currentValue == n) {
|
||||||
|
// Represent delta as a generalized variable-length integer.
|
||||||
|
let q = delta;
|
||||||
|
for (let k = base; /* no condition */; k += base) {
|
||||||
|
const t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
|
||||||
|
if (q < t) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const qMinusT = q - t;
|
||||||
|
const baseMinusT = base - t;
|
||||||
|
output.push(
|
||||||
|
stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
|
||||||
|
);
|
||||||
|
q = floor(qMinusT / baseMinusT);
|
||||||
|
}
|
||||||
|
|
||||||
|
output.push(stringFromCharCode(digitToBasic(q, 0)));
|
||||||
|
bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
|
||||||
|
delta = 0;
|
||||||
|
++handledCPCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
++delta;
|
||||||
|
++n;
|
||||||
|
|
||||||
|
}
|
||||||
|
return output.join('');
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a Punycode string representing a domain name or an email address
|
||||||
|
* to Unicode. Only the Punycoded parts of the input will be converted, i.e.
|
||||||
|
* it doesn't matter if you call it on a string that has already been
|
||||||
|
* converted to Unicode.
|
||||||
|
* @memberOf punycode
|
||||||
|
* @param {String} input The Punycoded domain name or email address to
|
||||||
|
* convert to Unicode.
|
||||||
|
* @returns {String} The Unicode representation of the given Punycode
|
||||||
|
* string.
|
||||||
|
*/
|
||||||
|
const toUnicode = function (input) {
|
||||||
|
return mapDomain(input, function (string) {
|
||||||
|
return regexPunycode.test(string)
|
||||||
|
? decode(string.slice(4).toLowerCase())
|
||||||
|
: string;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a Unicode string representing a domain name or an email address to
|
||||||
|
* Punycode. Only the non-ASCII parts of the domain name will be converted,
|
||||||
|
* i.e. it doesn't matter if you call it with a domain that's already in
|
||||||
|
* ASCII.
|
||||||
|
* @memberOf punycode
|
||||||
|
* @param {String} input The domain name or email address to convert, as a
|
||||||
|
* Unicode string.
|
||||||
|
* @returns {String} The Punycode representation of the given domain name or
|
||||||
|
* email address.
|
||||||
|
*/
|
||||||
|
const toASCII = function (input) {
|
||||||
|
return mapDomain(input, function (string) {
|
||||||
|
return regexNonASCII.test(string)
|
||||||
|
? 'xn--' + encode(string)
|
||||||
|
: string;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/** Define the public API */
|
||||||
|
//@ts-ignore
|
||||||
|
const punycode = {
|
||||||
|
/**
|
||||||
|
* A string representing the current Punycode.js version number.
|
||||||
|
* @memberOf punycode
|
||||||
|
* @type String
|
||||||
|
*/
|
||||||
|
'version': '2.1.0',
|
||||||
|
/**
|
||||||
|
* An object of methods to convert from JavaScript's internal character
|
||||||
|
* representation (UCS-2) to Unicode code points, and back.
|
||||||
|
* @see <https://mathiasbynens.be/notes/javascript-encoding>
|
||||||
|
* @memberOf punycode
|
||||||
|
* @type Object
|
||||||
|
*/
|
||||||
|
'ucs2': {
|
||||||
|
'decode': ucs2decode,
|
||||||
|
'encode': ucs2encode
|
||||||
|
},
|
||||||
|
'decode': decode,
|
||||||
|
'encode': encode,
|
||||||
|
'toASCII': toASCII,
|
||||||
|
'toUnicode': toUnicode
|
||||||
|
};
|
||||||
|
|
||||||
|
export = punycode;
|
||||||
@@ -21,8 +21,8 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var punycode = require('punycode');
|
import * as punycode from 'punycode'
|
||||||
// @ts-ignore
|
|
||||||
var util = {
|
var util = {
|
||||||
isString: function (arg) {
|
isString: function (arg) {
|
||||||
return typeof (arg) === 'string';
|
return typeof (arg) === 'string';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ms/nukkit",
|
"name": "@ms/nukkit",
|
||||||
"version": "0.4.1",
|
"version": "0.4.2",
|
||||||
"description": "MiaoScript nukkit package",
|
"description": "MiaoScript nukkit package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -27,8 +27,8 @@
|
|||||||
"typescript": "^3.8.3"
|
"typescript": "^3.8.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ms/api": "^0.4.1",
|
"@ms/api": "^0.4.2",
|
||||||
"@ms/common": "^0.4.0",
|
"@ms/common": "^0.4.2",
|
||||||
"@ms/container": "^0.4.0"
|
"@ms/container": "^0.4.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,9 @@ export class NukkitServer implements server.Server {
|
|||||||
getNativePluginManager() {
|
getNativePluginManager() {
|
||||||
return Nukkit.getPluginManager() as any;
|
return Nukkit.getPluginManager() as any;
|
||||||
}
|
}
|
||||||
|
getNettyPipeline() {
|
||||||
|
throw new Error("Method not implemented.");
|
||||||
|
}
|
||||||
sendJson(sender: string | any, json: object | string): void {
|
sendJson(sender: string | any, json: object | string): void {
|
||||||
throw new Error("Method not implemented.");
|
throw new Error("Method not implemented.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ export class NukkitTaskManager implements task.TaskManager {
|
|||||||
callSyncMethod(func: Function): any {
|
callSyncMethod(func: Function): any {
|
||||||
return func()
|
return func()
|
||||||
}
|
}
|
||||||
|
disable() {
|
||||||
|
base.getInstance().getServer().getScheduler().cancelTask(this.pluginInstance)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class NukkitTask extends task.Task {
|
export class NukkitTask extends task.Task {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ms/ployfill",
|
"name": "@ms/ployfill",
|
||||||
"version": "0.4.1",
|
"version": "0.4.2",
|
||||||
"description": "MiaoScript ployfill package",
|
"description": "MiaoScript ployfill package",
|
||||||
"author": "MiaoWoo <admin@yumc.pw>",
|
"author": "MiaoWoo <admin@yumc.pw>",
|
||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ms/i18n": "^0.4.1",
|
"@ms/i18n": "^0.4.2",
|
||||||
"@ms/nashorn": "^0.4.0",
|
"@ms/nashorn": "^0.4.0",
|
||||||
"core-js": "^3.6.4"
|
"core-js": "^3.6.4"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ms/plugin",
|
"name": "@ms/plugin",
|
||||||
"version": "0.4.1",
|
"version": "0.4.2",
|
||||||
"description": "MiaoScript api package",
|
"description": "MiaoScript api package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -22,16 +22,16 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/js-yaml": "^3.12.2",
|
"@types/js-yaml": "^3.12.3",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^3.8.3"
|
"typescript": "^3.8.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ms/api": "^0.4.1",
|
"@ms/api": "^0.4.2",
|
||||||
"@ms/common": "^0.4.0",
|
"@ms/common": "^0.4.2",
|
||||||
"@ms/container": "^0.4.0",
|
"@ms/container": "^0.4.0",
|
||||||
"@ms/i18n": "^0.4.1",
|
"@ms/i18n": "^0.4.2",
|
||||||
"js-yaml": "^3.13.1"
|
"js-yaml": "^3.13.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,13 +37,13 @@ export function cmd(metadata: interfaces.CommandMetadata = {}) {
|
|||||||
* MiaoScript TabComplete
|
* MiaoScript TabComplete
|
||||||
* @param metadata TabCompleterMetadata
|
* @param metadata TabCompleterMetadata
|
||||||
*/
|
*/
|
||||||
export function tab(metadata: interfaces.TabCompleterMetadata = {}) {
|
export function tab(metadata: interfaces.CommandMetadata = {}) {
|
||||||
return function(target: any, key: string, value: any) {
|
return function(target: any, key: string, value: any) {
|
||||||
metadata.name = metadata.name || (key.startsWith('tab') ? key.split('tab', 2)[1] : key);
|
metadata.name = metadata.name || (key.startsWith('tab') ? key.split('tab', 2)[1] : key);
|
||||||
if (!metadata.name) { return; }
|
if (!metadata.name) { return; }
|
||||||
metadata.executor = key;
|
metadata.executor = key;
|
||||||
metadata.paramtypes = Reflect.getMetadata("design:paramtypes", target, key)
|
metadata.paramtypes = Reflect.getMetadata("design:paramtypes", target, key)
|
||||||
const previousMetadata: Map<string, interfaces.TabCompleterMetadata> = getPluginTabCompleterMetadata(target)
|
const previousMetadata: Map<string, interfaces.CommandMetadata> = getPluginTabCompleterMetadata(target)
|
||||||
previousMetadata.set(metadata.name, metadata)
|
previousMetadata.set(metadata.name, metadata)
|
||||||
Reflect.defineMetadata(METADATA_KEY.tab, previousMetadata, target.constructor);
|
Reflect.defineMetadata(METADATA_KEY.tab, previousMetadata, target.constructor);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -67,12 +67,6 @@ export namespace interfaces {
|
|||||||
*/
|
*/
|
||||||
paramtypes?: string[];
|
paramtypes?: string[];
|
||||||
}
|
}
|
||||||
export interface TabCompleterMetadata extends ExecMetadata {
|
|
||||||
/**
|
|
||||||
* 参数列表
|
|
||||||
*/
|
|
||||||
paramtypes?: string[];
|
|
||||||
}
|
|
||||||
export interface ListenerMetadata extends ExecMetadata {
|
export interface ListenerMetadata extends ExecMetadata {
|
||||||
}
|
}
|
||||||
export interface ConfigMetadata extends BaseMetadata {
|
export interface ConfigMetadata extends BaseMetadata {
|
||||||
|
|||||||
@@ -34,10 +34,10 @@ function getPluginCommandMetadata(target: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getPluginTabCompleterMetadata(target: any) {
|
function getPluginTabCompleterMetadata(target: any) {
|
||||||
let tabcompleterMetadata: Map<string, interfaces.TabCompleterMetadata> = Reflect.getMetadata(
|
let tabcompleterMetadata: Map<string, interfaces.CommandMetadata> = Reflect.getMetadata(
|
||||||
METADATA_KEY.tab,
|
METADATA_KEY.tab,
|
||||||
target.constructor
|
target.constructor
|
||||||
) || new Map<string, interfaces.TabCompleterMetadata>();
|
) || new Map<string, interfaces.CommandMetadata>();
|
||||||
return tabcompleterMetadata;
|
return tabcompleterMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"name": "@ms/plugins",
|
"name": "@ms/plugins",
|
||||||
"version": "0.4.1",
|
"version": "0.4.2",
|
||||||
"description": "MiaoScript plugins package",
|
"description": "MiaoScript plugins package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -28,8 +28,8 @@
|
|||||||
"typescript": "^3.8.3"
|
"typescript": "^3.8.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ms/api": "^0.4.1",
|
"@ms/api": "^0.4.2",
|
||||||
"@ms/container": "^0.4.0",
|
"@ms/container": "^0.4.0",
|
||||||
"@ms/plugin": "^0.4.1"
|
"@ms/plugin": "^0.4.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ms/sponge",
|
"name": "@ms/sponge",
|
||||||
"version": "0.4.1",
|
"version": "0.4.2",
|
||||||
"description": "MiaoScript api package",
|
"description": "MiaoScript api package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -27,8 +27,8 @@
|
|||||||
"typescript": "^3.8.3"
|
"typescript": "^3.8.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ms/api": "^0.4.1",
|
"@ms/api": "^0.4.2",
|
||||||
"@ms/common": "^0.4.0",
|
"@ms/common": "^0.4.2",
|
||||||
"@ms/container": "^0.4.0"
|
"@ms/container": "^0.4.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,26 @@
|
|||||||
import { server } from '@ms/api'
|
import { server } from '@ms/api'
|
||||||
import { provideSingleton } from '@ms/container';
|
import { provideSingleton } from '@ms/container';
|
||||||
|
|
||||||
import * as fs from '@ms/common/dist/fs'
|
import * as reflect from '@ms/common/dist/reflect'
|
||||||
|
|
||||||
|
const refList: Array<{ server: string, future: string }> = [
|
||||||
|
{ server: 'an', future: 'g' },//spigot 1.12.2
|
||||||
|
{ server: 'getServerConnection', future: 'f' },//after spigot 1.14.4
|
||||||
|
{ server: 'func_147137_ag', future: 'field_151274_e' }//catserver 1.12.2
|
||||||
|
]
|
||||||
|
|
||||||
const Sponge = org.spongepowered.api.Sponge;
|
const Sponge = org.spongepowered.api.Sponge;
|
||||||
const TextSerializers = org.spongepowered.api.text.serializer.TextSerializers;
|
const TextSerializers = org.spongepowered.api.text.serializer.TextSerializers;
|
||||||
const URL = Java.type("java.net.URL");
|
|
||||||
const File = Java.type("java.io.File");
|
const File = Java.type("java.io.File");
|
||||||
|
|
||||||
@provideSingleton(server.Server)
|
@provideSingleton(server.Server)
|
||||||
export class SpongeServer implements server.Server {
|
export class SpongeServer implements server.Server {
|
||||||
private pluginsFolder: string;
|
private pluginsFolder: string;
|
||||||
|
private pipeline: any;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.pluginsFolder = new File(base.getInstance().getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile().getCanonicalPath()
|
this.pluginsFolder = new File(base.getInstance().getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile().getCanonicalPath()
|
||||||
|
this.reflectPipeline()
|
||||||
}
|
}
|
||||||
|
|
||||||
getPlayer(name: string) {
|
getPlayer(name: string) {
|
||||||
@@ -46,10 +53,25 @@ export class SpongeServer implements server.Server {
|
|||||||
getNativePluginManager() {
|
getNativePluginManager() {
|
||||||
return Sponge.getPluginManager() as any;
|
return Sponge.getPluginManager() as any;
|
||||||
}
|
}
|
||||||
|
getNettyPipeline() {
|
||||||
|
return this.pipeline;
|
||||||
|
}
|
||||||
sendJson(sender: string | any, json: string): void {
|
sendJson(sender: string | any, json: string): void {
|
||||||
if (typeof sender === "string") {
|
if (typeof sender === "string") {
|
||||||
sender = this.getPlayer(sender)
|
sender = this.getPlayer(sender)
|
||||||
}
|
}
|
||||||
sender.sendMessage(TextSerializers.JSON.deserialize(json))
|
sender.sendMessage(TextSerializers.JSON.deserialize(json))
|
||||||
}
|
}
|
||||||
|
private reflectPipeline() {
|
||||||
|
let consoleServer = reflect.on(Sponge.getServer()).get()
|
||||||
|
let promise: any;
|
||||||
|
for (const ref of refList) {
|
||||||
|
try {
|
||||||
|
promise = reflect.on(consoleServer).call(ref.server).get(ref.future).get().get(0); break;
|
||||||
|
} catch (error) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!promise) { throw Error(`Can't found ServerConnection or ChannelFuture !`) }
|
||||||
|
this.pipeline = reflect.on(promise).get('channel').get().pipeline()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { task, plugin } from '@ms/api'
|
import { task, plugin } from '@ms/api'
|
||||||
import { inject, provideSingleton } from '@ms/container';
|
import { inject, provideSingleton, postConstruct } from '@ms/container';
|
||||||
|
|
||||||
const Sponge = Java.type("org.spongepowered.api.Sponge");
|
const Sponge = Java.type("org.spongepowered.api.Sponge");
|
||||||
const Task = Java.type("org.spongepowered.api.scheduler.Task");
|
const Task = Java.type("org.spongepowered.api.scheduler.Task");
|
||||||
@@ -11,16 +11,23 @@ const TimeUnit = Java.type('java.util.concurrent.TimeUnit');
|
|||||||
export class SpongeTaskManager implements task.TaskManager {
|
export class SpongeTaskManager implements task.TaskManager {
|
||||||
@inject(plugin.PluginInstance)
|
@inject(plugin.PluginInstance)
|
||||||
private pluginInstance: any;
|
private pluginInstance: any;
|
||||||
|
private syncExecutor: any;
|
||||||
|
|
||||||
|
@postConstruct()
|
||||||
|
initialize() {
|
||||||
|
this.syncExecutor = Sponge.getScheduler().createSyncExecutor(this.pluginInstance)
|
||||||
|
}
|
||||||
|
|
||||||
create(func: Function): task.Task {
|
create(func: Function): task.Task {
|
||||||
if (Object.prototype.toString.call(func) !== "[object Function]") { throw TypeError('第一个参数 Task 必须为 function !'); };
|
if (Object.prototype.toString.call(func) !== "[object Function]") { throw TypeError('第一个参数 Task 必须为 function !'); };
|
||||||
return new SpongeTask(this.pluginInstance, func);
|
return new SpongeTask(this.pluginInstance, func);
|
||||||
}
|
}
|
||||||
callSyncMethod(func: Function): any {
|
callSyncMethod(func: Function): any {
|
||||||
return Sponge.getScheduler()
|
|
||||||
.createSyncExecutor(this.pluginInstance)
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
.schedule(new Callable({ call: () => func() }), java.lang.Long.valueOf(0), TimeUnit.NANOSECONDS).get()
|
return this.syncExecutor.schedule(new Callable({ call: () => func() }), java.lang.Long.valueOf(0), TimeUnit.NANOSECONDS).get()
|
||||||
|
}
|
||||||
|
disable() {
|
||||||
|
Sponge.getScheduler().getScheduledTasks(this.pluginInstance).forEach((task: task.Cancelable) => task.cancel())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ms/websocket",
|
"name": "@ms/websocket",
|
||||||
"version": "0.4.1",
|
"version": "0.4.2",
|
||||||
"description": "MiaoScript websocket package",
|
"description": "MiaoScript websocket package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
|
|||||||
@@ -1,3 +1,46 @@
|
|||||||
/// <reference types="@ms/nashorn" />
|
/// <reference types="@ms/nashorn" />
|
||||||
|
|
||||||
|
import { Server, ServerOptions } from './socket-io'
|
||||||
|
|
||||||
|
interface SocketIOStatic {
|
||||||
|
/**
|
||||||
|
* Default Server constructor
|
||||||
|
*/
|
||||||
|
(): Server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new Server
|
||||||
|
* @param srv The HTTP server that we're going to bind to
|
||||||
|
* @param opts An optional parameters object
|
||||||
|
*/
|
||||||
|
(srv: any, opts?: ServerOptions): Server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new Server
|
||||||
|
* @param port A port to bind to, as a number, or a string
|
||||||
|
* @param An optional parameters object
|
||||||
|
*/
|
||||||
|
(port: string | number, opts?: ServerOptions): Server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new Server
|
||||||
|
* @param A parameters object
|
||||||
|
*/
|
||||||
|
(opts: ServerOptions): Server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Backwards compatibility
|
||||||
|
* @see io().listen()
|
||||||
|
*/
|
||||||
|
listen?: SocketIOStatic;
|
||||||
|
}
|
||||||
|
|
||||||
|
type SocketStatic = SocketIOStatic & { Instance?: symbol }
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
let io: SocketStatic = function (pipeline: any, options: ServerOptions) {
|
||||||
|
return new Server(pipeline, options)
|
||||||
|
}
|
||||||
|
io.Instance = Symbol("@ms/websocket")
|
||||||
|
export default io
|
||||||
export * from './socket-io'
|
export * from './socket-io'
|
||||||
@@ -15,6 +15,8 @@ export enum Keys {
|
|||||||
Default = "DefaultChannelPipeline"
|
Default = "DefaultChannelPipeline"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let RequestAttributeKey: any
|
||||||
|
try { RequestAttributeKey = AttributeKey.valueOf('request') } catch (error) { }
|
||||||
export enum AttributeKeys {
|
export enum AttributeKeys {
|
||||||
Request = AttributeKey.valueOf('request')
|
Request = RequestAttributeKey
|
||||||
}
|
}
|
||||||
@@ -22,6 +22,7 @@ class NettyWebSocketServer extends EventEmitter {
|
|||||||
ctx.fireChannelRead(channel)
|
ctx.fireChannelRead(channel)
|
||||||
})
|
})
|
||||||
connectEvent.on(ServerEvent.connect, (ctx) => {
|
connectEvent.on(ServerEvent.connect, (ctx) => {
|
||||||
|
console.log('NettyWebSocketServer ServerEvent.connect', ctx, ctx.channel().id(), ctx.channel().class.name)
|
||||||
let nettyClient = new NettyClient(this, ctx.channel());
|
let nettyClient = new NettyClient(this, ctx.channel());
|
||||||
this.allClients[nettyClient.id] = nettyClient;
|
this.allClients[nettyClient.id] = nettyClient;
|
||||||
this.emit(ServerEvent.connect, nettyClient);
|
this.emit(ServerEvent.connect, nettyClient);
|
||||||
|
|||||||
Reference in New Issue
Block a user