Compare commits
58 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c947ff7a14 | |||
| be2988fc58 | |||
| 3beed64319 | |||
| 23c7cb955a | |||
| 3be1f78a14 | |||
| d919fa07fc | |||
| d8fd7b0a7d | |||
| 907f9ed03f | |||
| e28d881976 | |||
| 1bdb324fc4 | |||
| 5c90ac3b1f | |||
| 653d7268cf | |||
| efa5e6d110 | |||
| ceb354f11e | |||
| d97af356fd | |||
| 6fd7174ca5 | |||
| 784ea2d65a | |||
| 3ccc9b3d06 | |||
| beef57d85d | |||
| 166b17b527 | |||
| d6ca19a56f | |||
| c61f87a449 | |||
| ede3f83dd5 | |||
| 69ef3b3979 | |||
|
|
0a8574621d | ||
| 5426ec1eed | |||
| 831f6d0916 | |||
| 1a5175f466 | |||
|
|
2ad290bd48 | ||
| 611d4e5425 | |||
| 894d5d43e6 | |||
| cd57944cb8 | |||
| 75b34bfc48 | |||
| 47478e13aa | |||
|
|
17af1fd49b | ||
| b5423cd26c | |||
| aca864500f | |||
| f86e1a8c94 | |||
| a76f9e8b50 | |||
| 6dcc56b0e5 | |||
| 6f8ea8290b | |||
| 1f574695a1 | |||
| 090c0b2668 | |||
| db8f2d9bc2 | |||
| e02f673c82 | |||
| 47c85f70eb | |||
| da9e2063ca | |||
| 0568a7abbe | |||
| 7375e8e2e9 | |||
| 41d3923d94 | |||
| f111b9891c | |||
| 2e4fdcb798 | |||
| ab7ca932a3 | |||
| e8b3d43cdf | |||
| eaaa0ef139 | |||
| 94840ae59d | |||
| c31eaeb8f6 | |||
| 469a66a277 |
12
.editorconfig
Normal file
12
.editorconfig
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# http://editorconfig.org
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"version": "0.9.7",
|
"version": "0.15.0",
|
||||||
"useWorkspaces": true,
|
"useWorkspaces": true,
|
||||||
"npmClient": "yarn",
|
"npmClient": "yarn",
|
||||||
"packages": [
|
"packages": [
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
"build": "lerna run build --scope=\"@ccms/!(plugins)\"",
|
"build": "lerna run build --scope=\"@ccms/!(plugins)\"",
|
||||||
"build:plugins": "lerna run build --scope=\"@ccms/plugins\"",
|
"build:plugins": "lerna run build --scope=\"@ccms/plugins\"",
|
||||||
"ug": "yarn upgrade-interactive --latest",
|
"ug": "yarn upgrade-interactive --latest",
|
||||||
"np": "lerna exec \"npm publish --access=public --registry https://registry.npmjs.org\" --scope=\"@ccms/!(client|plugins)\"",
|
"np": "./script/push.sh",
|
||||||
"lsp": "npm login --registry=https://registry.npmjs.org --scope=@ccms",
|
"lsp": "npm login --registry=https://registry.npmjs.org --scope=@ccms",
|
||||||
"lp": "lerna publish --registry https://registry.npmjs.org"
|
"lp": "lerna publish --registry https://registry.npmjs.org"
|
||||||
},
|
},
|
||||||
@@ -20,6 +20,6 @@
|
|||||||
"packages/*"
|
"packages/*"
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"lerna": "^3.22.1"
|
"lerna": "^4.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/amqp",
|
"name": "@ccms/amqp",
|
||||||
"version": "0.9.5",
|
"version": "0.15.0",
|
||||||
"description": "MiaoScript amqp package",
|
"description": "MiaoScript amqp package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,17 +19,17 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.9.5",
|
"@ccms/api": "^0.15.0",
|
||||||
"@ccms/common": "^0.9.4",
|
"@ccms/common": "^0.15.0",
|
||||||
"@ccms/container": "^0.9.4"
|
"@ccms/container": "^0.15.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "^0.9.4",
|
"@ccms/nashorn": "^0.15.0",
|
||||||
"@javatypes/amqp-client": "^0.0.2",
|
"@javatypes/amqp-client": "^0.0.3",
|
||||||
"@javatypes/spring-amqp": "^0.0.2",
|
"@javatypes/spring-amqp": "^0.0.3",
|
||||||
"@javatypes/spring-rabbit": "^0.0.2",
|
"@javatypes/spring-rabbit": "^0.0.3",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^4.0.3"
|
"typescript": "^4.3.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { ConnectionFactoryAdapter, ConnectionFactory } from "./connection"
|
|||||||
import { ChannelAwareMessageListenerAdapter, ChannelAwareMessageListener } from "./listener"
|
import { ChannelAwareMessageListenerAdapter, ChannelAwareMessageListener } from "./listener"
|
||||||
|
|
||||||
export const SimpleMessageListenerContainer = org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer
|
export const SimpleMessageListenerContainer = org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer
|
||||||
export const AcknowledgeMode: org.springframework.amqp.core.AcknowledgeMode = Java.type('org.springframework.amqp.core.AcknowledgeMode')
|
export const AcknowledgeMode = org.springframework.amqp.core.AcknowledgeMode
|
||||||
interface ContainerConfig {
|
interface ContainerConfig {
|
||||||
connectionFactory: ConnectionFactoryAdapter | typeof ConnectionFactory
|
connectionFactory: ConnectionFactoryAdapter | typeof ConnectionFactory
|
||||||
queueNames: string[]
|
queueNames: string[]
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export class AmqpAdmin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
declareBinding(queue: string, exchange: string, routerKey: string, argument: any = null) {
|
declareBinding(queue: string, exchange: string, routerKey: string, argument: any = null) {
|
||||||
let binding = new this.Binding(queue, this.DestinationType.QUEUE, exchange, routerKey, argument)
|
let binding = new this.Binding(queue, org.springframework.amqp.core.Binding.DestinationType.QUEUE, exchange, routerKey, argument)
|
||||||
this.amqpAdmin.declareBinding(binding)
|
this.amqpAdmin.declareBinding(binding)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/api",
|
"name": "@ccms/api",
|
||||||
"version": "0.9.5",
|
"version": "0.15.0",
|
||||||
"description": "MiaoScript api package",
|
"description": "MiaoScript api package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,16 +19,16 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/common": "^0.9.4",
|
"@ccms/common": "^0.15.0",
|
||||||
"@ccms/container": "^0.9.4",
|
"@ccms/container": "^0.15.0",
|
||||||
"@ccms/ployfill": "^0.9.4",
|
"@ccms/polyfill": "^0.15.0",
|
||||||
"base64-js": "^1.3.1",
|
"base64-js": "^1.5.1",
|
||||||
"source-map-builder": "^0.0.7"
|
"source-map-builder": "^0.0.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/base64-js": "^1.3.0",
|
"@types/base64-js": "^1.3.0",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^4.0.3"
|
"typescript": "^4.3.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import i18n from '@ccms/i18n'
|
import i18n from '@ccms/i18n'
|
||||||
import { injectable } from "@ccms/container"
|
import { injectable } from "@ccms/container"
|
||||||
import { plugin } from './interfaces'
|
import { plugin } from './plugin'
|
||||||
|
|
||||||
export namespace command {
|
export namespace command {
|
||||||
@injectable()
|
@injectable()
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ enum LogLevel {
|
|||||||
|
|
||||||
export class MiaoScriptConsole implements Console {
|
export class MiaoScriptConsole implements Console {
|
||||||
Console: NodeJS.ConsoleConstructor
|
Console: NodeJS.ConsoleConstructor
|
||||||
|
memory: any
|
||||||
|
|
||||||
private static sourceMaps: { [key: string]: SourceMapBuilder } = {}
|
private static sourceMaps: { [key: string]: SourceMapBuilder } = {}
|
||||||
private static sourceFileMaps: { [key: string]: string } = {}
|
private static sourceFileMaps: { [key: string]: string } = {}
|
||||||
@@ -27,7 +28,8 @@ export class MiaoScriptConsole implements Console {
|
|||||||
private _level: LogLevel = LogLevel.INFO
|
private _level: LogLevel = LogLevel.INFO
|
||||||
|
|
||||||
protected logger: any
|
protected logger: any
|
||||||
protected prefix: string = '§6[§bMiaoScript§6]§r '
|
|
||||||
|
public prefix: string = '§6[§bMiaoScript§6]§r '
|
||||||
|
|
||||||
constructor(name?: string) {
|
constructor(name?: string) {
|
||||||
this.name = name
|
this.name = name
|
||||||
@@ -47,10 +49,10 @@ export class MiaoScriptConsole implements Console {
|
|||||||
set name(name: string) {
|
set name(name: string) {
|
||||||
if (name) {
|
if (name) {
|
||||||
this._name = `[${name}] `
|
this._name = `[${name}] `
|
||||||
// noinspection JSUnusedGlobalSymbols
|
|
||||||
this.prefix = `§6[§cMS§6][§b${name}§6]§r `
|
this.prefix = `§6[§cMS§6][§b${name}§6]§r `
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log(...args: any[]): void {
|
log(...args: any[]): void {
|
||||||
this.logger.info(this.name + args.join(' '))
|
this.logger.info(this.name + args.join(' '))
|
||||||
}
|
}
|
||||||
@@ -90,7 +92,7 @@ export class MiaoScriptConsole implements Console {
|
|||||||
ex(ex: Error) {
|
ex(ex: Error) {
|
||||||
this.stack(ex).forEach(line => this.console(line))
|
this.stack(ex).forEach(line => this.console(line))
|
||||||
}
|
}
|
||||||
readSourceMap(fileName: string, lineNumber: number) {
|
readSourceMap(fileName: string, lineNumber: any) {
|
||||||
try {
|
try {
|
||||||
if (fileName.endsWith('js')) {
|
if (fileName.endsWith('js')) {
|
||||||
if (MiaoScriptConsole.sourceMaps[fileName] === undefined) {
|
if (MiaoScriptConsole.sourceMaps[fileName] === undefined) {
|
||||||
@@ -133,6 +135,7 @@ export class MiaoScriptConsole implements Console {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
stack(ex: Error, color: boolean = true): string[] {
|
stack(ex: Error, color: boolean = true): string[] {
|
||||||
|
if (!ex) return []
|
||||||
let stack = ex.getStackTrace()
|
let stack = ex.getStackTrace()
|
||||||
let cache = [(color ? '§c' : '') + ex]
|
let cache = [(color ? '§c' : '') + ex]
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
@@ -152,17 +155,20 @@ export class MiaoScriptConsole implements Console {
|
|||||||
} else {
|
} else {
|
||||||
let className = trace.className
|
let className = trace.className
|
||||||
var fileName = trace.fileName as string
|
var fileName = trace.fileName as string
|
||||||
|
var lineNumber = trace.lineNumber
|
||||||
if (className.startsWith('jdk.nashorn.internal.scripts')) {
|
if (className.startsWith('jdk.nashorn.internal.scripts')) {
|
||||||
className = className.substr(className.lastIndexOf('$') + 1)
|
className = className.substr(className.lastIndexOf('$') + 1)
|
||||||
var { fileName, lineNumber } = this.readSourceMap(trace.fileName, trace.lineNumber)
|
var { fileName, lineNumber } = this.readSourceMap(fileName, lineNumber)
|
||||||
if (fileName.startsWith(root)) { fileName = fileName.split(root)[1] }
|
if (fileName.startsWith(root)) { fileName = fileName.split(root)[1] }
|
||||||
} else {
|
} else {
|
||||||
|
if (!global.debug) {
|
||||||
for (let prefix in ignoreLogPrefix) {
|
for (let prefix in ignoreLogPrefix) {
|
||||||
if (className.startsWith(ignoreLogPrefix[prefix])) {
|
if (className.startsWith(ignoreLogPrefix[prefix])) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (color) {
|
if (color) {
|
||||||
cache.push(` §e->§c ${className}.${trace.methodName}(§4${fileName}:${lineNumber}§c)`)
|
cache.push(` §e->§c ${className}.${trace.methodName}(§4${fileName}:${lineNumber}§c)`)
|
||||||
} else {
|
} else {
|
||||||
@@ -190,6 +196,9 @@ export class MiaoScriptConsole implements Console {
|
|||||||
dirxml(...data: any[]): void {
|
dirxml(...data: any[]): void {
|
||||||
throw new Error("Method not implemented.")
|
throw new Error("Method not implemented.")
|
||||||
}
|
}
|
||||||
|
exception(message?: string, ...optionalParams: any[]): void {
|
||||||
|
throw new Error('Method not implemented.')
|
||||||
|
}
|
||||||
group(...label: any[]): void {
|
group(...label: any[]): void {
|
||||||
throw new Error("Method not implemented.")
|
throw new Error("Method not implemented.")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,14 @@
|
|||||||
export namespace constants {
|
export namespace constants {
|
||||||
|
export namespace ServiceIdentifier {
|
||||||
|
/**
|
||||||
|
* Runtime Server NettyPipeline
|
||||||
|
*/
|
||||||
|
export const NettyPipeline = Symbol("NettyPipeline")
|
||||||
|
/**
|
||||||
|
* Runtime Server RootLogger
|
||||||
|
*/
|
||||||
|
export const RootLogger = Symbol("RootLogger")
|
||||||
|
}
|
||||||
export namespace Reflect {
|
export namespace Reflect {
|
||||||
export const Method = {
|
export const Method = {
|
||||||
getServerConnection: [/*spigot 1.8.8*/'aq',/*spigot 1.12.2*/ 'an', /*spigot 1.14.4+*/'getServerConnection', /*catserver 1.12.2*/'func_147137_ag']
|
getServerConnection: [/*spigot 1.8.8*/'aq',/*spigot 1.12.2*/ 'an', /*spigot 1.14.4+*/'getServerConnection', /*catserver 1.12.2*/'func_147137_ag']
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
import "@ccms/nashorn"
|
import "@ccms/nashorn"
|
||||||
|
|
||||||
|
export * from './web'
|
||||||
|
export * from './amqp'
|
||||||
export * from './chat'
|
export * from './chat'
|
||||||
export * from './task'
|
export * from './task'
|
||||||
export * from './event'
|
export * from './event'
|
||||||
export * from './proxy'
|
export * from './proxy'
|
||||||
|
export * from './plugin'
|
||||||
|
export * from './server'
|
||||||
export * from './console'
|
export * from './console'
|
||||||
export * from './channel'
|
export * from './channel'
|
||||||
export * from './command'
|
export * from './command'
|
||||||
|
export * from './database'
|
||||||
|
export * from './particle'
|
||||||
export * from './constants'
|
export * from './constants'
|
||||||
export * from './interfaces'
|
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
export * from './web'
|
|
||||||
export * from './amqp'
|
|
||||||
export * from './plugin'
|
|
||||||
export * from './server'
|
|
||||||
export * from './database'
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
export interface NativePluginManager {
|
|
||||||
load(name: string): boolean;
|
|
||||||
unload(name: string): boolean;
|
|
||||||
reload(name: string): boolean;
|
|
||||||
delete(name: string): boolean;
|
|
||||||
}
|
|
||||||
494
packages/api/src/particle.ts
Normal file
494
packages/api/src/particle.ts
Normal file
@@ -0,0 +1,494 @@
|
|||||||
|
import { Autowired, injectable } from '@ccms/container'
|
||||||
|
|
||||||
|
import { task, plugin } from './index'
|
||||||
|
|
||||||
|
const UUID = Java.type('java.util.UUID')
|
||||||
|
const Math = Java.type('java.lang.Math')
|
||||||
|
|
||||||
|
export namespace particle {
|
||||||
|
/**
|
||||||
|
* 表示一个特效对象
|
||||||
|
*
|
||||||
|
* @author Zoyn
|
||||||
|
*/
|
||||||
|
export abstract class Particle {
|
||||||
|
private spawner: ParticleSpawner
|
||||||
|
private readonly uuid: string
|
||||||
|
|
||||||
|
private particle: any /* Particle */
|
||||||
|
private count: number = 1;
|
||||||
|
private offsetX: number = 0;
|
||||||
|
private offsetY: number = 0;
|
||||||
|
private offsetZ: number = 0;
|
||||||
|
private extra: number = 0;
|
||||||
|
private data: Object = null;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.uuid = UUID.randomUUID().toString()
|
||||||
|
}
|
||||||
|
abstract show(location: any)
|
||||||
|
|
||||||
|
getUUID() {
|
||||||
|
return this.uuid
|
||||||
|
}
|
||||||
|
|
||||||
|
getSpawner() {
|
||||||
|
return this.spawner
|
||||||
|
}
|
||||||
|
|
||||||
|
setSpawner(spawner: ParticleSpawner) {
|
||||||
|
this.spawner = spawner
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getParticle() {
|
||||||
|
return this.particle
|
||||||
|
}
|
||||||
|
|
||||||
|
setParticle(particle: any, data: any = null) {
|
||||||
|
this.particle = particle
|
||||||
|
this.data = data
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getCount() {
|
||||||
|
return this.count
|
||||||
|
}
|
||||||
|
|
||||||
|
setCount(count: number) {
|
||||||
|
this.count = count
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getOffsetX() {
|
||||||
|
return this.offsetX
|
||||||
|
}
|
||||||
|
|
||||||
|
setOffsetX(offsetX: number) {
|
||||||
|
this.offsetX = offsetX
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getOffsetY() {
|
||||||
|
return this.offsetY
|
||||||
|
}
|
||||||
|
|
||||||
|
setOffsetY(offsetY: number) {
|
||||||
|
this.offsetY = offsetY
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getOffsetZ() {
|
||||||
|
return this.offsetZ
|
||||||
|
}
|
||||||
|
|
||||||
|
setOffsetZ(offsetZ: number) {
|
||||||
|
this.offsetZ = offsetZ
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getExtra() {
|
||||||
|
return this.extra
|
||||||
|
}
|
||||||
|
|
||||||
|
setExtra(extra: number) {
|
||||||
|
this.extra = extra
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getData() {
|
||||||
|
return this.data
|
||||||
|
}
|
||||||
|
|
||||||
|
setData(data) {
|
||||||
|
this.data = data
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过给定一个坐标就可以使用已经指定的参数来播放粒子
|
||||||
|
*
|
||||||
|
* @param location 坐标
|
||||||
|
*/
|
||||||
|
spawn(location: any) {
|
||||||
|
if (!this.spawner) throw new Error(`particle ${this.uuid} not set spawner can't spawn!`)
|
||||||
|
this.spawner.spawn(location, this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 表示一条线
|
||||||
|
*
|
||||||
|
* @author Zoyn
|
||||||
|
*/
|
||||||
|
export class Line extends Particle {
|
||||||
|
private vector: any
|
||||||
|
private start: any
|
||||||
|
private end: any
|
||||||
|
/**
|
||||||
|
* 步长
|
||||||
|
*/
|
||||||
|
private step: number
|
||||||
|
/**
|
||||||
|
* 向量长度
|
||||||
|
*/
|
||||||
|
private length: number
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造一条线
|
||||||
|
*
|
||||||
|
* @param start 线的起点
|
||||||
|
* @param end 线的终点
|
||||||
|
*/
|
||||||
|
constructor(start: any, end: any)
|
||||||
|
/**
|
||||||
|
* 构造一条线
|
||||||
|
*
|
||||||
|
* @param start 线的起点
|
||||||
|
* @param end 线的终点
|
||||||
|
* @param step 每个粒子之间的间隔 (也即步长)
|
||||||
|
*/
|
||||||
|
constructor(start: any, end: any, step: number = 0.1) {
|
||||||
|
super()
|
||||||
|
this.start = start
|
||||||
|
this.end = end
|
||||||
|
this.step = step
|
||||||
|
// 对向量进行重置
|
||||||
|
this.resetVector()
|
||||||
|
}
|
||||||
|
|
||||||
|
show() {
|
||||||
|
for (let i = 0; i < this.length; i += this.step) {
|
||||||
|
let vectorTemp = this.vector.clone().multiply(i)
|
||||||
|
this.spawn(this.start.clone().add(vectorTemp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取线的起始坐标
|
||||||
|
*
|
||||||
|
* @return {@link Location}
|
||||||
|
*/
|
||||||
|
getStart() {
|
||||||
|
return this.start
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 利用给定的坐标设置线的起始坐标
|
||||||
|
*
|
||||||
|
* @param start 起始坐标
|
||||||
|
* @return {@link Line}
|
||||||
|
*/
|
||||||
|
setStart(start) {
|
||||||
|
this.start = start
|
||||||
|
this.resetVector()
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取线的终点坐标
|
||||||
|
*
|
||||||
|
* @return {@link Location}
|
||||||
|
*/
|
||||||
|
getEnd() {
|
||||||
|
return this.end
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 利用给定的坐标设置线的终点坐标
|
||||||
|
*
|
||||||
|
* @param end 终点
|
||||||
|
* @return {@link Line}
|
||||||
|
*/
|
||||||
|
setEnd(end) {
|
||||||
|
this.end = end
|
||||||
|
this.resetVector()
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取每个粒子之间的间隔
|
||||||
|
*
|
||||||
|
* @return 也就是循环的步长
|
||||||
|
*/
|
||||||
|
getStep() {
|
||||||
|
return this.step
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置每个粒子之间的间隔
|
||||||
|
*
|
||||||
|
* @param step 间隔
|
||||||
|
* @return {@link Line}
|
||||||
|
*/
|
||||||
|
setStep(step) {
|
||||||
|
this.step = step
|
||||||
|
this.resetVector()
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手动重设线的向量
|
||||||
|
*/
|
||||||
|
resetVector() {
|
||||||
|
this.vector = this.end.clone().subtract(this.start).toVector()
|
||||||
|
this.length = this.vector.length()
|
||||||
|
this.vector.normalize()
|
||||||
|
}
|
||||||
|
|
||||||
|
public static buildLine(locA: any, locB: any, step: number, particle: any) {
|
||||||
|
let vectorAB = locB.clone().subtract(locA).toVector()
|
||||||
|
let vectorLength = vectorAB.length()
|
||||||
|
vectorAB.normalize()
|
||||||
|
for (let i = 0; i < vectorLength; i += step) {
|
||||||
|
ParticleManager.globalSpawner.spawn(locA.clone().add(vectorAB.clone().multiply(i)), particle)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 表示一个弧
|
||||||
|
*
|
||||||
|
* @author Zoyn
|
||||||
|
*/
|
||||||
|
export class Arc extends Particle {
|
||||||
|
private angle: number
|
||||||
|
private radius: number
|
||||||
|
private step: number
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造一个弧
|
||||||
|
*
|
||||||
|
* @param origin 弧所在的圆的圆点
|
||||||
|
* @param angle 弧所占的角度
|
||||||
|
* @param radius 弧所在的圆的半径
|
||||||
|
* @param step 每个粒子的间隔(也即步长)
|
||||||
|
*/
|
||||||
|
constructor(angle: number = 30, radius: number = 1, step: number = 1) {
|
||||||
|
super()
|
||||||
|
this.angle = angle
|
||||||
|
this.radius = radius
|
||||||
|
this.step = step
|
||||||
|
}
|
||||||
|
|
||||||
|
show(location: any) {
|
||||||
|
for (let i = 0; i < this.angle; i += this.step) {
|
||||||
|
let radians: number = Math.toRadians(i)
|
||||||
|
let x: number = this.radius * Math.cos(radians)
|
||||||
|
let z: number = this.radius * Math.sin(radians)
|
||||||
|
|
||||||
|
super.spawn(location.clone().add(x, 0, z))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getAngle(): number {
|
||||||
|
return this.angle
|
||||||
|
}
|
||||||
|
|
||||||
|
setAngle(angle: number): Arc {
|
||||||
|
this.angle = angle
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getRadius(): number {
|
||||||
|
return this.radius
|
||||||
|
}
|
||||||
|
|
||||||
|
setRadius(radius: number): Arc {
|
||||||
|
this.radius = radius
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
getStep(): number {
|
||||||
|
return this.step
|
||||||
|
}
|
||||||
|
|
||||||
|
setStep(step: number): Arc {
|
||||||
|
this.step = step
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 表示一个圆
|
||||||
|
*
|
||||||
|
* @author Zoyn
|
||||||
|
*/
|
||||||
|
export class Circle extends Arc {
|
||||||
|
constructor(radius: number)
|
||||||
|
constructor(radius: number, step: number)
|
||||||
|
/**
|
||||||
|
* 构造一个圆
|
||||||
|
*
|
||||||
|
* @param origin 圆的圆点
|
||||||
|
* @param radius 圆的半径
|
||||||
|
* @param step 每个粒子的间隔(也即步长)
|
||||||
|
* @param period 特效周期(如果需要可以使用)
|
||||||
|
*/
|
||||||
|
constructor(radius: number = 1, step: number = 1) {
|
||||||
|
// Circle只需要控制这个fullArc就可以满足所有的要求
|
||||||
|
super(360, radius, step)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const AtomicInteger = Java.type("java.util.concurrent.atomic.AtomicInteger")
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export abstract class ParticleManager {
|
||||||
|
public static globalSpawner: ParticleSpawner = undefined
|
||||||
|
@Autowired()
|
||||||
|
private taskManager: task.TaskManager
|
||||||
|
|
||||||
|
protected taskId: java.util.concurrent.atomic.AtomicInteger
|
||||||
|
protected cacheTasks = new Map<string, ParticleTask>()
|
||||||
|
protected pluginCacheTasks = new Map<string, Map<number, ParticleTask>>()
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.taskId = new AtomicInteger(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得自增的任务ID
|
||||||
|
*/
|
||||||
|
public nextId() {
|
||||||
|
return this.taskId.incrementAndGet()
|
||||||
|
}
|
||||||
|
|
||||||
|
public getTaskManager() {
|
||||||
|
return this.taskManager
|
||||||
|
}
|
||||||
|
|
||||||
|
public create(particle: Particle, plugin?: plugin.Plugin) {
|
||||||
|
let uuid = particle.getUUID()
|
||||||
|
if (this.cacheTasks.has(uuid)) {
|
||||||
|
return this.cacheTasks.get(uuid)
|
||||||
|
}
|
||||||
|
let task = this.create0(plugin, particle)
|
||||||
|
this.cacheTasks.set(uuid, task)
|
||||||
|
if (plugin) {
|
||||||
|
if (!this.pluginCacheTasks.has(plugin.description.name)) {
|
||||||
|
this.pluginCacheTasks.set(plugin.description.name, new Map())
|
||||||
|
}
|
||||||
|
this.pluginCacheTasks.get(plugin.description.name).set(task.getTaskId(), task)
|
||||||
|
}
|
||||||
|
return task
|
||||||
|
}
|
||||||
|
|
||||||
|
public cancel(particle: Particle) {
|
||||||
|
let uuid = particle.getUUID()
|
||||||
|
if (this.cacheTasks.has(uuid)) {
|
||||||
|
this.cacheTasks.get(uuid).cancel()
|
||||||
|
this.cacheTasks.delete(uuid)
|
||||||
|
} else {
|
||||||
|
throw new Error(`particle ${uuid} not found!`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
disable(plugin: plugin.Plugin) {
|
||||||
|
if (this.pluginCacheTasks.has(plugin.description.name)) {
|
||||||
|
this.pluginCacheTasks
|
||||||
|
.get(plugin.description.name)
|
||||||
|
.forEach((task) => task.cancel())
|
||||||
|
this.pluginCacheTasks.delete(plugin.description.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected create0(owner: plugin.Plugin, particle: Particle): ParticleTask {
|
||||||
|
particle.setSpawner(this.getGlobalSpawner())
|
||||||
|
return new ParticleTask(owner, particle, this)
|
||||||
|
}
|
||||||
|
protected abstract getGlobalSpawner(): ParticleSpawner
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ParticleTask {
|
||||||
|
|
||||||
|
private particle: Particle
|
||||||
|
private isAsync: boolean = false
|
||||||
|
private interval: number = 0
|
||||||
|
private _location: any
|
||||||
|
private _follow: any
|
||||||
|
|
||||||
|
private owner: plugin.Plugin
|
||||||
|
private taskId: number
|
||||||
|
private task: task.Task
|
||||||
|
private taskManager: task.TaskManager
|
||||||
|
protected particleManager: ParticleManager
|
||||||
|
|
||||||
|
constructor(owner: plugin.Plugin, particle: Particle, particleManager: ParticleManager) {
|
||||||
|
this.owner = owner
|
||||||
|
this.taskId = particleManager.nextId()
|
||||||
|
this.particle = particle
|
||||||
|
this.taskManager = particleManager.getTaskManager()
|
||||||
|
this.particleManager = particleManager
|
||||||
|
}
|
||||||
|
|
||||||
|
getOwner() {
|
||||||
|
return this.task.getOwner()
|
||||||
|
}
|
||||||
|
|
||||||
|
getTaskId() {
|
||||||
|
return this.taskId
|
||||||
|
}
|
||||||
|
|
||||||
|
getParticle() {
|
||||||
|
return this.particle
|
||||||
|
}
|
||||||
|
|
||||||
|
async(isAsync: boolean = true) {
|
||||||
|
this.isAsync = isAsync
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
timer(tick: number) {
|
||||||
|
this.interval = tick
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
follow(entity: { getLocation: () => any }) {
|
||||||
|
this._follow = entity
|
||||||
|
this._location = undefined
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
location(location: any) {
|
||||||
|
this._location = location
|
||||||
|
this._follow = undefined
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
submit() {
|
||||||
|
this.cancel()
|
||||||
|
if (this._follow && !this.interval) throw new Error(`enable follow entity but interval is ${this.interval}!`)
|
||||||
|
this.taskManager.create(() => {
|
||||||
|
this.task = this.taskManager
|
||||||
|
.create(() => {
|
||||||
|
try {
|
||||||
|
if (this._follow) {
|
||||||
|
if (!this._follow.isOnline()) return this.cancel()
|
||||||
|
this.particle.show(this._follow.getLocation().clone().add(0, 1, 0))
|
||||||
|
} else if (this._location) {
|
||||||
|
this.particle.show(this._location)
|
||||||
|
} else {
|
||||||
|
console.warn(`ParticleTask ${this.taskId} particle ${this.particle.getUUID()} cancel because entity and location both undefined!`)
|
||||||
|
this.task.cancel()
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`§6插件 §a${this.owner.description.name} §c播放粒子发送异常 §4粒子播放任务已终止!`)
|
||||||
|
console.ex(error)
|
||||||
|
this.cancel()
|
||||||
|
}
|
||||||
|
}, this.owner)
|
||||||
|
.async(this.isAsync)
|
||||||
|
.timer(this.interval)
|
||||||
|
.submit()
|
||||||
|
}, this.owner).later(2).submit()
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
cancel() {
|
||||||
|
if (this.task != null) {
|
||||||
|
this.task.cancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export abstract class ParticleSpawner {
|
||||||
|
abstract spawnParticle(location: any, particle: any, count: number)
|
||||||
|
abstract spawn(location: any, particle: Particle)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -162,6 +162,14 @@ export namespace plugin {
|
|||||||
* 插件作者 不填默认为 Unknow
|
* 插件作者 不填默认为 Unknow
|
||||||
*/
|
*/
|
||||||
author?: string | string[]
|
author?: string | string[]
|
||||||
|
/**
|
||||||
|
* 脚本依赖
|
||||||
|
*/
|
||||||
|
depends?: string[]
|
||||||
|
/**
|
||||||
|
* 插件依赖
|
||||||
|
*/
|
||||||
|
nativeDepends?: string[]
|
||||||
/**
|
/**
|
||||||
* 插件源文件 必须指定为 __filename
|
* 插件源文件 必须指定为 __filename
|
||||||
*/
|
*/
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { provideSingleton, Autowired } from '@ccms/container'
|
import { provideSingleton, Autowired, optional } from '@ccms/container'
|
||||||
import { channel } from './channel'
|
import { channel } from './channel'
|
||||||
|
|
||||||
export namespace proxy {
|
export namespace proxy {
|
||||||
@@ -147,6 +147,7 @@ export namespace proxy {
|
|||||||
}
|
}
|
||||||
@provideSingleton(BungeeCord)
|
@provideSingleton(BungeeCord)
|
||||||
export class BungeeCord {
|
export class BungeeCord {
|
||||||
|
@optional()
|
||||||
@Autowired()
|
@Autowired()
|
||||||
private channel: channel.Channel
|
private channel: channel.Channel
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
import * as reflect from '@ccms/common/dist/reflect'
|
import * as reflect from '@ccms/common/dist/reflect'
|
||||||
import { injectable, inject } from '@ccms/container'
|
import { injectable, Autowired, ContainerInstance, Container, postConstruct } from '@ccms/container'
|
||||||
|
|
||||||
import { NativePluginManager } from './native_plugin'
|
import { constants } from './constants'
|
||||||
import { constants } from '../../constants'
|
|
||||||
|
|
||||||
export { NativePluginManager } from './native_plugin'
|
|
||||||
|
|
||||||
export namespace server {
|
export namespace server {
|
||||||
/**
|
/**
|
||||||
@@ -19,6 +16,30 @@ export namespace server {
|
|||||||
* Runtime Server Instance
|
* Runtime Server Instance
|
||||||
*/
|
*/
|
||||||
export const ServerInstance = Symbol("ServerInstance")
|
export const ServerInstance = Symbol("ServerInstance")
|
||||||
|
@injectable()
|
||||||
|
export abstract class NativePluginManager {
|
||||||
|
list(): any[] {
|
||||||
|
throw new Error("Method not implemented.")
|
||||||
|
}
|
||||||
|
has(name: string): boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
get(name: string): any {
|
||||||
|
throw new Error("Method not implemented.")
|
||||||
|
}
|
||||||
|
load(name: string): boolean {
|
||||||
|
throw new Error("Method not implemented.")
|
||||||
|
}
|
||||||
|
unload(name: string): boolean {
|
||||||
|
throw new Error("Method not implemented.")
|
||||||
|
}
|
||||||
|
reload(name: string): boolean {
|
||||||
|
throw new Error("Method not implemented.")
|
||||||
|
}
|
||||||
|
delete(name: string): boolean {
|
||||||
|
throw new Error("Method not implemented.")
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* MiaoScript Server
|
* MiaoScript Server
|
||||||
*/
|
*/
|
||||||
@@ -48,9 +69,6 @@ export namespace server {
|
|||||||
getPluginsFolder(): string {
|
getPluginsFolder(): string {
|
||||||
throw new Error("Method not implemented.")
|
throw new Error("Method not implemented.")
|
||||||
}
|
}
|
||||||
getNativePluginManager(): NativePluginManager {
|
|
||||||
throw new Error("Method not implemented.")
|
|
||||||
}
|
|
||||||
getDedicatedServer?(): any {
|
getDedicatedServer?(): any {
|
||||||
throw new Error("Method not implemented.")
|
throw new Error("Method not implemented.")
|
||||||
}
|
}
|
||||||
@@ -63,8 +81,9 @@ export namespace server {
|
|||||||
}
|
}
|
||||||
@injectable()
|
@injectable()
|
||||||
export class ServerChecker {
|
export class ServerChecker {
|
||||||
@inject(ServerType)
|
@Autowired(ServerType)
|
||||||
private serverType: string
|
private serverType: string
|
||||||
|
|
||||||
check(servers: string[]) {
|
check(servers: string[]) {
|
||||||
// Not set servers -> allow
|
// Not set servers -> allow
|
||||||
if (!servers || !servers.length) return true
|
if (!servers || !servers.length) return true
|
||||||
@@ -80,14 +99,17 @@ export namespace server {
|
|||||||
}
|
}
|
||||||
@injectable()
|
@injectable()
|
||||||
export abstract class ReflectServer extends server.Server {
|
export abstract class ReflectServer extends server.Server {
|
||||||
|
@Autowired(ContainerInstance)
|
||||||
|
private container: Container
|
||||||
|
|
||||||
protected pipeline: any
|
protected pipeline: any
|
||||||
protected rootLogger: any
|
protected rootLogger: any
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super()
|
super()
|
||||||
this.reflect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@postConstruct()
|
||||||
protected reflect() {
|
protected reflect() {
|
||||||
try {
|
try {
|
||||||
let consoleServer = this.getDedicatedServer()
|
let consoleServer = this.getDedicatedServer()
|
||||||
@@ -107,7 +129,11 @@ export namespace server {
|
|||||||
if (connection.class.name.indexOf('ServerConnection') !== -1
|
if (connection.class.name.indexOf('ServerConnection') !== -1
|
||||||
|| connection.class.name.indexOf('NetworkSystem') !== -1) { break }
|
|| connection.class.name.indexOf('NetworkSystem') !== -1) { break }
|
||||||
connection = undefined
|
connection = undefined
|
||||||
} catch (error) { }
|
} catch (error) {
|
||||||
|
if (global.debug) {
|
||||||
|
console.ex(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!connection) { console.error("Can't found ServerConnection!"); return }
|
if (!connection) { console.error("Can't found ServerConnection!"); return }
|
||||||
for (const field of constants.Reflect.Field.listeningChannels) {
|
for (const field of constants.Reflect.Field.listeningChannels) {
|
||||||
@@ -115,16 +141,30 @@ export namespace server {
|
|||||||
promise = reflect.on(connection).get(field).get().get(0)
|
promise = reflect.on(connection).get(field).get().get(0)
|
||||||
if (promise.class.name.indexOf('Promise') !== -1) { break }
|
if (promise.class.name.indexOf('Promise') !== -1) { break }
|
||||||
promise = undefined
|
promise = undefined
|
||||||
} catch (error) { }
|
} catch (error) {
|
||||||
|
if (global.debug) {
|
||||||
|
console.ex(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!promise) { console.error("Can't found listeningChannels!"); return }
|
if (!promise) { console.error("Can't found listeningChannels!"); return }
|
||||||
this.pipeline = reflect.on(promise).get('channel').get().pipeline()
|
this.pipeline = reflect.on(promise).get('channel').get().pipeline()
|
||||||
|
this.container.bind(constants.ServiceIdentifier.NettyPipeline).toConstantValue(this.pipeline)
|
||||||
}
|
}
|
||||||
protected reflectRootLogger(consoleServer: any) {
|
protected reflectRootLogger(consoleServer: any) {
|
||||||
try {
|
try {
|
||||||
this.rootLogger = reflect.on(consoleServer).get('LOGGER').get().parent
|
this.rootLogger = reflect.on(consoleServer).get('LOGGER').get().parent
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
try { this.rootLogger = reflect.on(consoleServer).get(0).get().parent } catch (error) { }
|
if (global.debug) {
|
||||||
|
console.ex(error)
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
this.rootLogger = reflect.on(consoleServer).get(0).get().parent
|
||||||
|
} catch (error) {
|
||||||
|
if (global.debug) {
|
||||||
|
console.ex(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (this.rootLogger && this.rootLogger.class.name.indexOf('Logger') === -1) {
|
if (this.rootLogger && this.rootLogger.class.name.indexOf('Logger') === -1) {
|
||||||
console.error('Error Logger Class: ' + this.rootLogger.class.name)
|
console.error('Error Logger Class: ' + this.rootLogger.class.name)
|
||||||
@@ -135,6 +175,7 @@ export namespace server {
|
|||||||
this.rootLogger = this.rootLogger.parent
|
this.rootLogger = this.rootLogger.parent
|
||||||
}
|
}
|
||||||
if (!this.rootLogger) { console.error("Can't found rootLogger!") }
|
if (!this.rootLogger) { console.error("Can't found rootLogger!") }
|
||||||
|
this.container.bind(constants.ServiceIdentifier.RootLogger).toConstantValue(this.rootLogger)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,35 +1,66 @@
|
|||||||
import { plugin } from './index'
|
import { plugin } from './index'
|
||||||
import { injectable } from '@ccms/container'
|
import { injectable } from '@ccms/container'
|
||||||
|
|
||||||
|
const AtomicInteger = Java.type("java.util.concurrent.atomic.AtomicInteger")
|
||||||
|
|
||||||
export namespace task {
|
export namespace task {
|
||||||
@injectable()
|
@injectable()
|
||||||
export abstract class TaskManager {
|
export abstract class TaskManager {
|
||||||
protected cacheTasks = new Map<string, task.Task[]>()
|
protected taskId: java.util.concurrent.atomic.AtomicInteger
|
||||||
|
protected cacheTasks = new Map<number, task.Task>()
|
||||||
|
protected pluginCacheTasks = new Map<string, Map<number, task.Task>>()
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.taskId = new AtomicInteger(0)
|
||||||
|
process.on('task.finish', (task: task.Task) => {
|
||||||
|
let taskId = task.getTaskId()
|
||||||
|
this.cacheTasks.delete(taskId)
|
||||||
|
let ownerName = task.getOwner()?.description.name
|
||||||
|
if (ownerName && this.pluginCacheTasks.has(ownerName)) {
|
||||||
|
this.pluginCacheTasks.get(ownerName).delete(taskId)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
protected pluginCreate(plugin: plugin.Plugin, task: task.Task) {
|
protected pluginCreate(plugin: plugin.Plugin, task: task.Task) {
|
||||||
if (!this.cacheTasks.has(plugin.description.name)) {
|
if (!this.pluginCacheTasks.has(plugin.description.name)) {
|
||||||
this.cacheTasks.set(plugin.description.name, [])
|
this.pluginCacheTasks.set(plugin.description.name, new Map())
|
||||||
}
|
}
|
||||||
this.cacheTasks.get(plugin.description.name).push(task)
|
this.pluginCacheTasks.get(plugin.description.name).set(task.getTaskId(), task)
|
||||||
return task
|
return task
|
||||||
}
|
}
|
||||||
|
|
||||||
protected pluginDisable(plugin: plugin.Plugin) {
|
protected pluginDisable(plugin: plugin.Plugin) {
|
||||||
if (this.cacheTasks.has(plugin.description.name)) {
|
if (this.pluginCacheTasks.has(plugin.description.name)) {
|
||||||
this.cacheTasks.get(plugin.description.name).forEach(task => task.cancel())
|
this.pluginCacheTasks.get(plugin.description.name).forEach((task) => {
|
||||||
this.cacheTasks.delete(plugin.description.name)
|
task.cancel()
|
||||||
|
})
|
||||||
|
this.pluginCacheTasks.delete(plugin.description.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得自增的任务ID
|
||||||
|
*/
|
||||||
|
protected nextId() {
|
||||||
|
return this.taskId.incrementAndGet()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建任务
|
* 创建任务
|
||||||
* @param func 任务内容
|
* @param func 任务内容
|
||||||
*/
|
*/
|
||||||
create(func: Function, plugin?: plugin.Plugin): task.Task {
|
create(func: Function, plugin?: plugin.Plugin): 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 !') };
|
||||||
let task = this.create0(func)
|
let task = this.create0(plugin, func, this.nextId())
|
||||||
|
this.cacheTasks.set(task.getTaskId(), task)
|
||||||
if (plugin) { return this.pluginCreate(plugin, task) }
|
if (plugin) { return this.pluginCreate(plugin, task) }
|
||||||
return task
|
return task
|
||||||
}
|
}
|
||||||
abstract create0(func: Function): task.Task
|
cancel(taskId: number) {
|
||||||
|
if (!this.cacheTasks.has(taskId)) { throw new Error(`Task ${taskId} not found!`) }
|
||||||
|
this.cacheTasks.get(taskId).cancel()
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 在主线程执行代码
|
* 在主线程执行代码
|
||||||
* @param func 执行内容
|
* @param func 执行内容
|
||||||
@@ -42,21 +73,33 @@ export namespace task {
|
|||||||
if (plugin) { return this.pluginDisable(plugin) }
|
if (plugin) { return this.pluginDisable(plugin) }
|
||||||
this.disable0()
|
this.disable0()
|
||||||
}
|
}
|
||||||
abstract disable0()
|
protected abstract create0(owner: plugin.Plugin, func: Function, id: number): task.Task
|
||||||
|
protected abstract disable0()
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 任务抽象
|
* 任务抽象
|
||||||
*/
|
*/
|
||||||
export abstract class Task {
|
export abstract class Task implements Cancelable {
|
||||||
protected plugin: any
|
|
||||||
protected func: Function
|
protected func: Function
|
||||||
protected isAsync: boolean = false;
|
protected isAsync: boolean = false;
|
||||||
protected laterTime: number = 0;
|
protected laterTime: number = 0;
|
||||||
protected interval: number = 0;
|
protected interval: number = 0;
|
||||||
|
protected owner: plugin.Plugin
|
||||||
|
protected taskId: number
|
||||||
|
protected innerTask: any
|
||||||
|
|
||||||
constructor(plugin: any, func: Function) {
|
constructor(owner: plugin.Plugin, func: Function, id: number) {
|
||||||
this.plugin = plugin
|
this.owner = owner
|
||||||
this.func = func
|
this.func = func
|
||||||
|
this.taskId = id
|
||||||
|
}
|
||||||
|
|
||||||
|
getOwner() {
|
||||||
|
return this.owner
|
||||||
|
}
|
||||||
|
|
||||||
|
getTaskId() {
|
||||||
|
return this.taskId
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,12 +133,15 @@ export namespace task {
|
|||||||
* 取消任务
|
* 取消任务
|
||||||
*/
|
*/
|
||||||
cancel(): boolean {
|
cancel(): boolean {
|
||||||
throw new Error("Method not implemented.")
|
let result = this.cancel0()
|
||||||
|
process.emit('task.finish', this)
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
protected run(...args: any[]): void {
|
protected run(...args: any[]): void {
|
||||||
try {
|
try {
|
||||||
this.func(...args)
|
this.func(...args)
|
||||||
|
!this.interval && process.emit('task.finish', this)
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.console('§4插件执行任务时发生错误', ex)
|
console.console('§4插件执行任务时发生错误', ex)
|
||||||
console.ex(ex)
|
console.ex(ex)
|
||||||
@@ -106,17 +152,22 @@ export namespace task {
|
|||||||
* 提交任务
|
* 提交任务
|
||||||
* @param args 任务参数
|
* @param args 任务参数
|
||||||
*/
|
*/
|
||||||
submit(...args: any[]): Cancelable {
|
submit(...args: any[]): task.Task {
|
||||||
let cancelable = this.submit0(...args)
|
this.innerTask = this.submit0(...args)
|
||||||
this.cancel = cancelable.cancel
|
return this
|
||||||
return cancelable
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 提交任务
|
* 提交任务
|
||||||
* @param args 任务参数
|
* @param args 任务参数
|
||||||
*/
|
*/
|
||||||
abstract submit0(...args: any[]): Cancelable
|
protected abstract submit0(...args: any[]): any
|
||||||
|
/**
|
||||||
|
* 取消任务
|
||||||
|
*/
|
||||||
|
protected cancel0(): boolean {
|
||||||
|
return this.innerTask?.cancel()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 返可取消的对象
|
* 返可取消的对象
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/bukkit",
|
"name": "@ccms/bukkit",
|
||||||
"version": "0.9.5",
|
"version": "0.15.0",
|
||||||
"description": "MiaoScript bukkit package",
|
"description": "MiaoScript bukkit package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,14 +19,14 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@javatypes/spigot-api": "^0.0.2",
|
"@javatypes/spigot-api": "^0.0.3",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^4.0.3"
|
"typescript": "^4.3.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.9.5",
|
"@ccms/api": "^0.15.0",
|
||||||
"@ccms/common": "^0.9.4",
|
"@ccms/common": "^0.15.0",
|
||||||
"@ccms/container": "^0.9.4"
|
"@ccms/container": "^0.15.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ let downgrade = false
|
|||||||
* 获取NMS版本
|
* 获取NMS版本
|
||||||
*/
|
*/
|
||||||
let nmsVersion = undefined
|
let nmsVersion = undefined
|
||||||
|
let nmsSubVersion = undefined
|
||||||
/**
|
/**
|
||||||
* 获取NMS类
|
* 获取NMS类
|
||||||
*/
|
*/
|
||||||
@@ -49,15 +50,23 @@ function remapFieldName(clazz: any, origin: string, test: string) {
|
|||||||
function init() {
|
function init() {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
nmsVersion = org.bukkit.Bukkit.server.class.name.split('.')[3]
|
nmsVersion = org.bukkit.Bukkit.server.class.name.split('.')[3]
|
||||||
|
nmsSubVersion = nmsVersion.split("_")[1]
|
||||||
try {
|
try {
|
||||||
RemapUtils = Java.type('catserver.server.remapper.RemapUtils')
|
RemapUtils = Java.type('catserver.server.remapper.RemapUtils')
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
}
|
}
|
||||||
let nmsChatSerializerClass = nmsCls(nmsVersion.split("_")[1] > 7 ? "IChatBaseComponent$ChatSerializer" : "ChatSerializer")
|
let nmsChatSerializerClass = undefined
|
||||||
|
if (nmsSubVersion < 8) {
|
||||||
|
nmsChatSerializerClass = nmsCls("ChatSerializer")
|
||||||
|
} else if (nmsSubVersion < 17) {
|
||||||
|
nmsChatSerializerClass = nmsCls("IChatBaseComponent$ChatSerializer")
|
||||||
|
} else {
|
||||||
|
nmsChatSerializerClass = base.getClass('net.minecraft.network.chat.IChatBaseComponent$ChatSerializer')
|
||||||
|
}
|
||||||
let nmsChatSerializerMethod = remapMethod(nmsChatSerializerClass, 'a', 'func_150699_a', base.getClass('java.lang.String'))
|
let nmsChatSerializerMethod = remapMethod(nmsChatSerializerClass, 'a', 'func_150699_a', base.getClass('java.lang.String'))
|
||||||
nmsChatSerializerMethodName = nmsChatSerializerMethod.getName()
|
nmsChatSerializerMethodName = nmsChatSerializerMethod.getName()
|
||||||
ChatSerializer = Java.type(nmsChatSerializerClass.getName())
|
ChatSerializer = Java.type(nmsChatSerializerClass.getName())
|
||||||
let packetTypeClass = nmsCls("PacketPlayOutChat")
|
let packetTypeClass = nmsSubVersion < 17 ? nmsCls("PacketPlayOutChat") : base.getClass('net.minecraft.network.protocol.game.PacketPlayOutChat')
|
||||||
PacketPlayOutChat = Java.type(packetTypeClass.getName())
|
PacketPlayOutChat = Java.type(packetTypeClass.getName())
|
||||||
let packetTypeConstructor: { parameterTypes: any[] }
|
let packetTypeConstructor: { parameterTypes: any[] }
|
||||||
let constructors = packetTypeClass.constructors
|
let constructors = packetTypeClass.constructors
|
||||||
@@ -75,9 +84,14 @@ function init() {
|
|||||||
if (nmsChatMessageTypeClass.isEnum()) {
|
if (nmsChatMessageTypeClass.isEnum()) {
|
||||||
chatMessageTypes = nmsChatMessageTypeClass.getEnumConstants()
|
chatMessageTypes = nmsChatMessageTypeClass.getEnumConstants()
|
||||||
}
|
}
|
||||||
let playerConnectionField = remapFieldName(nmsCls('EntityPlayer'), 'playerConnection', 'field_71135_a')
|
let playerConnectionField = undefined
|
||||||
|
if (nmsSubVersion < 17) {
|
||||||
|
playerConnectionField = remapFieldName(nmsCls('EntityPlayer'), 'playerConnection', 'field_71135_a')
|
||||||
|
} else {
|
||||||
|
playerConnectionField = base.getClass('net.minecraft.server.level.EntityPlayer').getField('b')
|
||||||
|
}
|
||||||
playerConnectionFieldName = playerConnectionField.getName()
|
playerConnectionFieldName = playerConnectionField.getName()
|
||||||
sendPacketMethodName = remapMethod(playerConnectionField.getType(), 'sendPacket', 'func_179290_a', nmsCls('Packet')).getName()
|
sendPacketMethodName = remapMethod(playerConnectionField.getType(), 'sendPacket', 'func_179290_a', nmsSubVersion < 17 ? nmsCls('Packet') : base.getClass('net.minecraft.network.protocol.Packet')).getName()
|
||||||
}
|
}
|
||||||
|
|
||||||
function json(sender: { name: string }, json: string) {
|
function json(sender: { name: string }, json: string) {
|
||||||
|
|||||||
@@ -8,9 +8,12 @@ import './chat'
|
|||||||
import './task'
|
import './task'
|
||||||
import './event'
|
import './event'
|
||||||
import './server'
|
import './server'
|
||||||
|
import { BukkitNativePluginManager } from './plugin'
|
||||||
import './command'
|
import './command'
|
||||||
import './channel'
|
import './channel'
|
||||||
|
import './particle'
|
||||||
|
|
||||||
export default function BukkitImpl(container: Container) {
|
export default function BukkitImpl(container: Container) {
|
||||||
container.bind(server.Console).toConstantValue(BukkitConsole)
|
container.bind(server.Console).toConstantValue(BukkitConsole)
|
||||||
|
container.rebind(server.NativePluginManager).toConstantValue(new BukkitNativePluginManager())
|
||||||
}
|
}
|
||||||
|
|||||||
31
packages/bukkit/src/particle.ts
Normal file
31
packages/bukkit/src/particle.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import { provideSingleton } from '@ccms/container'
|
||||||
|
import { particle, plugin } from '@ccms/api'
|
||||||
|
|
||||||
|
@provideSingleton(particle.ParticleManager)
|
||||||
|
export class BukkitParticleManager extends particle.ParticleManager {
|
||||||
|
private globalSpawner = new BukkitParticleSpawner()
|
||||||
|
constructor() {
|
||||||
|
super()
|
||||||
|
particle.ParticleManager.globalSpawner = this.globalSpawner
|
||||||
|
}
|
||||||
|
protected getGlobalSpawner() {
|
||||||
|
return this.globalSpawner
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export class BukkitParticleSpawner extends particle.ParticleSpawner {
|
||||||
|
spawnParticle(location: any, particle: any, count: number = 1) {
|
||||||
|
location.getWorld().spawnParticle(particle, location, count)
|
||||||
|
}
|
||||||
|
spawn(location: any, particle: particle.Particle) {
|
||||||
|
location.getWorld().spawnParticle(
|
||||||
|
particle.getParticle(),
|
||||||
|
location,
|
||||||
|
particle.getCount(),
|
||||||
|
particle.getOffsetX(),
|
||||||
|
particle.getOffsetY(),
|
||||||
|
particle.getOffsetZ(),
|
||||||
|
particle.getExtra(),
|
||||||
|
particle.getData()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
12
packages/bukkit/src/plugin.ts
Normal file
12
packages/bukkit/src/plugin.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { server } from '@ccms/api'
|
||||||
|
|
||||||
|
const Bukkit = org.bukkit.Bukkit
|
||||||
|
|
||||||
|
export class BukkitNativePluginManager extends server.NativePluginManager {
|
||||||
|
has(name: string) {
|
||||||
|
return !!this.get(name)
|
||||||
|
}
|
||||||
|
get(name: string) {
|
||||||
|
return Bukkit.getPluginManager().getPlugin(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,13 +16,13 @@ export class BukkitServer extends server.ReflectServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getPlayer(name: string) {
|
getPlayer(name: string) {
|
||||||
return Bukkit.getPlayer(name)
|
return Bukkit.getPlayerExact(name)
|
||||||
}
|
}
|
||||||
getVersion(): string {
|
getVersion(): string {
|
||||||
return Bukkit.getVersion()
|
return Bukkit.getVersion()
|
||||||
}
|
}
|
||||||
getOnlinePlayers() {
|
getOnlinePlayers() {
|
||||||
return Bukkit.getOnlinePlayers() as unknown as any[]
|
return Bukkit.getOnlinePlayers()
|
||||||
}
|
}
|
||||||
getConsoleSender() {
|
getConsoleSender() {
|
||||||
return Bukkit.getConsoleSender()
|
return Bukkit.getConsoleSender()
|
||||||
|
|||||||
@@ -7,17 +7,14 @@ const Callable = Java.type('java.util.concurrent.Callable')
|
|||||||
|
|
||||||
@provideSingleton(task.TaskManager)
|
@provideSingleton(task.TaskManager)
|
||||||
export class BukkitTaskManager extends task.TaskManager {
|
export class BukkitTaskManager extends task.TaskManager {
|
||||||
@inject(plugin.PluginInstance)
|
create0(owner: plugin.Plugin, func: Function, id: number): task.Task {
|
||||||
private pluginInstance: any
|
return new BukkitTask(owner, func, id)
|
||||||
|
|
||||||
create0(func: Function): task.Task {
|
|
||||||
return new BukkitTask(this.pluginInstance, func)
|
|
||||||
}
|
}
|
||||||
callSyncMethod(func: Function): any {
|
callSyncMethod(func: Function): any {
|
||||||
return Bukkit.getScheduler().callSyncMethod(this.pluginInstance, new Callable({ call: () => func() })).get()
|
return Bukkit.getScheduler().callSyncMethod(base.getInstance(), new Callable({ call: () => func() })).get()
|
||||||
}
|
}
|
||||||
disable0() {
|
disable0() {
|
||||||
Bukkit.getScheduler().cancelTasks(this.pluginInstance)
|
Bukkit.getScheduler().cancelTasks(base.getInstance())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,9 +23,9 @@ export class BukkitTask extends task.Task {
|
|||||||
let run = new BukkitRunnable({ run: () => this.run(...args) })
|
let run = new BukkitRunnable({ run: () => this.run(...args) })
|
||||||
let funcName = `runTask${this.interval ? 'Timer' : 'Later'}${this.isAsync ? 'Asynchronously' : ''}`
|
let funcName = `runTask${this.interval ? 'Timer' : 'Later'}${this.isAsync ? 'Asynchronously' : ''}`
|
||||||
if (this.interval) {
|
if (this.interval) {
|
||||||
return run[funcName](this.plugin, this.laterTime, this.interval)
|
return run[funcName](base.getInstance(), this.laterTime, this.interval)
|
||||||
} else {
|
} else {
|
||||||
return run[funcName](this.plugin, this.laterTime)
|
return run[funcName](base.getInstance(), this.laterTime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/bungee",
|
"name": "@ccms/bungee",
|
||||||
"version": "0.9.5",
|
"version": "0.15.0",
|
||||||
"description": "MiaoScript bungee package",
|
"description": "MiaoScript bungee package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,14 +19,14 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@javatypes/bungee-api": "^0.0.2",
|
"@javatypes/bungee-api": "^0.0.3",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^4.0.3"
|
"typescript": "^4.3.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.9.5",
|
"@ccms/api": "^0.15.0",
|
||||||
"@ccms/common": "^0.9.4",
|
"@ccms/common": "^0.15.0",
|
||||||
"@ccms/container": "^0.9.4"
|
"@ccms/container": "^0.15.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,15 @@
|
|||||||
import { server } from '@ccms/api'
|
import { server } from '@ccms/api'
|
||||||
import { Container } from '@ccms/container'
|
import { Container } from '@ccms/container'
|
||||||
|
|
||||||
import { BungeeConsole } from './console';
|
import { BungeeConsole } from './console'
|
||||||
import './event';
|
import './task'
|
||||||
import './server';
|
import './event'
|
||||||
import './command';
|
import './server'
|
||||||
import './channel';
|
import { BungeeNativePluginManager } from './plugin'
|
||||||
import './task';
|
import './command'
|
||||||
|
import './channel'
|
||||||
|
|
||||||
export default function BungeeImpl(container: Container) {
|
export default function BungeeImpl(container: Container) {
|
||||||
container.bind(server.Console).toConstantValue(BungeeConsole);
|
container.bind(server.Console).toConstantValue(BungeeConsole)
|
||||||
|
container.rebind(server.NativePluginManager).toConstantValue(new BungeeNativePluginManager())
|
||||||
}
|
}
|
||||||
|
|||||||
12
packages/bungee/src/plugin.ts
Normal file
12
packages/bungee/src/plugin.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { server } from '@ccms/api'
|
||||||
|
|
||||||
|
let Bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy()
|
||||||
|
|
||||||
|
export class BungeeNativePluginManager extends server.NativePluginManager {
|
||||||
|
has(name: string) {
|
||||||
|
return !!this.get(name)
|
||||||
|
}
|
||||||
|
get(name: string) {
|
||||||
|
return Bungee.getPluginManager().getPlugin(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,17 +6,14 @@ let TimeUnit = Java.type('java.util.concurrent.TimeUnit')
|
|||||||
|
|
||||||
@provideSingleton(task.TaskManager)
|
@provideSingleton(task.TaskManager)
|
||||||
export class BungeeTaskManager extends task.TaskManager {
|
export class BungeeTaskManager extends task.TaskManager {
|
||||||
@inject(plugin.PluginInstance)
|
create0(owner: plugin.Plugin, func: Function, id: number): task.Task {
|
||||||
private pluginInstance: any
|
return new BungeeTask(owner, func, id)
|
||||||
|
|
||||||
create0(func: Function): task.Task {
|
|
||||||
return new BungeeTask(this.pluginInstance, func)
|
|
||||||
}
|
}
|
||||||
callSyncMethod(func: Function): any {
|
callSyncMethod(func: Function): any {
|
||||||
return func()
|
return func()
|
||||||
}
|
}
|
||||||
disable0() {
|
disable0() {
|
||||||
this.pluginInstance.getProxy().getScheduler().cancel(this.pluginInstance)
|
base.getInstance().getProxy().getScheduler().cancel(base.getInstance())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,12 +21,12 @@ export class BungeeTask extends task.Task {
|
|||||||
submit0(...args: any[]): task.Cancelable {
|
submit0(...args: any[]): task.Cancelable {
|
||||||
let run = new Runnable({ run: () => this.run(...args) })
|
let run = new Runnable({ run: () => this.run(...args) })
|
||||||
if (this.isAsync) {
|
if (this.isAsync) {
|
||||||
return this.plugin.getProxy().getScheduler().runAsync(this.plugin, run)
|
return base.getInstance().getProxy().getScheduler().runAsync(base.getInstance(), run)
|
||||||
}
|
}
|
||||||
if (this.interval) {
|
if (this.interval) {
|
||||||
return this.plugin.getProxy().getScheduler().schedule(this.plugin, run, this.laterTime * 50, this.interval * 50, TimeUnit.MILLISECONDS)
|
return base.getInstance().getProxy().getScheduler().schedule(base.getInstance(), run, this.laterTime * 50, this.interval * 50, TimeUnit.MILLISECONDS)
|
||||||
} else {
|
} else {
|
||||||
return this.plugin.getProxy().getScheduler().schedule(this.plugin, run, this.laterTime * 50, TimeUnit.MILLISECONDS)
|
return base.getInstance().getProxy().getScheduler().schedule(base.getInstance(), run, this.laterTime * 50, TimeUnit.MILLISECONDS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"name": "@ccms/client",
|
"name": "@ccms/client",
|
||||||
"version": "0.9.4",
|
"version": "0.15.0",
|
||||||
"description": "MiaoScript client package",
|
"description": "MiaoScript client package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -22,10 +22,11 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"minecraft-protocol": "^1.16.0"
|
"minecraft-protocol": "^1.25.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/node": "^15.12.4",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^4.0.3"
|
"typescript": "^4.3.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,12 @@ import { createClient } from 'minecraft-protocol'
|
|||||||
import { attachForge } from './forge'
|
import { attachForge } from './forge'
|
||||||
import { attachEvents } from './event'
|
import { attachEvents } from './event'
|
||||||
|
|
||||||
let username = process.argv[2] || 'Mr_jtb'
|
let readUserInfo = process.argv[2] || 'Mr_jtb'
|
||||||
let password = process.argv[3] || ''
|
let realUserInfo = readUserInfo.split(":")
|
||||||
let version = process.argv[4] || '1.12.2'
|
let username = realUserInfo[0]
|
||||||
let readAddress = process.argv[5] || '192.168.2.5:25577'
|
let password = realUserInfo[1] || ''
|
||||||
|
let version = process.argv[3] || '1.12.2'
|
||||||
|
let readAddress = process.argv[4] || '192.168.2.25:25565'
|
||||||
let realAddress = readAddress.split(":")
|
let realAddress = readAddress.split(":")
|
||||||
let address = realAddress[0]
|
let address = realAddress[0]
|
||||||
let port = parseInt(realAddress[1] || "25565")
|
let port = parseInt(realAddress[1] || "25565")
|
||||||
@@ -18,17 +20,23 @@ function commandLineCreateClient() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createConnection(host: string, port: number, username: string, password: string) {
|
function createConnection(host: string, port: number, username: string, password: string) {
|
||||||
let client = createClient({
|
let clientOptions: any = {
|
||||||
version,
|
version,
|
||||||
host,
|
host,
|
||||||
port,
|
port,
|
||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
clientToken: 'd02c7f39-2376-45da-a5a5-50e24fa8b185',
|
// clientToken: 'd02c7f39-2376-45da-a5a5-50e24fa8b185',
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
authServer: 'https://mcsso.yumc.pw/api/yggdrasil/authserver',
|
// authServer: 'https://skin.yumc.pw/api/yggdrasil/authserver',
|
||||||
sessionServer: 'https://mcsso.yumc.pw/api/yggdrasil/sessionserver'
|
// sessionServer: 'https://skin.yumc.pw/api/yggdrasil/sessionserver'
|
||||||
})
|
}
|
||||||
|
if (clientOptions.password) {
|
||||||
|
clientOptions.clientToken = 'd02c7f39-2376-45da-a5a5-50e24fa8b185'
|
||||||
|
clientOptions.authServer = 'https://skin.yumc.pw/api/yggdrasil/authserver'
|
||||||
|
clientOptions.sessionServer = 'https://skin.yumc.pw/api/yggdrasil/sessionserver'
|
||||||
|
}
|
||||||
|
let client = createClient(clientOptions)
|
||||||
|
|
||||||
attachCommon(client)
|
attachCommon(client)
|
||||||
attachForge(client)
|
attachForge(client)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/common",
|
"name": "@ccms/common",
|
||||||
"version": "0.9.4",
|
"version": "0.15.0",
|
||||||
"description": "MiaoScript api package",
|
"description": "MiaoScript api package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,11 +19,11 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "^0.9.4",
|
"@ccms/nashorn": "^0.15.0",
|
||||||
"@javatypes/jdk": "^0.0.2",
|
"@javatypes/jdk": "^0.0.3",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^4.0.3"
|
"typescript": "^4.3.4"
|
||||||
},
|
},
|
||||||
"gitHead": "562e2d00175c9d3a99c8b672aa07e6d92706a027"
|
"gitHead": "562e2d00175c9d3a99c8b672aa07e6d92706a027"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ interface RequestConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function request(config: RequestConfig) {
|
function request(config: RequestConfig) {
|
||||||
// @ts-ignore
|
// @ts-ignore XMLHttpRequest class only exist nashorn polyfill
|
||||||
let xhr = new XMLHttpRequest()
|
let xhr = new XMLHttpRequest()
|
||||||
xhr.open(config.method, config.url, false)
|
xhr.open(config.method, config.url, false)
|
||||||
for (const header in config.headers) {
|
for (const header in config.headers) {
|
||||||
@@ -44,6 +44,7 @@ function request(config: RequestConfig) {
|
|||||||
if (xhr.getResponseHeader("Content-Type").indexOf('application/json') != -1) {
|
if (xhr.getResponseHeader("Content-Type").indexOf('application/json') != -1) {
|
||||||
xhr.responseType = "json"
|
xhr.responseType = "json"
|
||||||
}
|
}
|
||||||
|
// @ts-ignore get only exist nashorn polyfill
|
||||||
return xhr.get()
|
return xhr.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
/// <reference types="@javatypes/jdk" />
|
/// <reference types="@javatypes/jdk" />
|
||||||
|
|
||||||
|
const JavaClass = Java.type('java.lang.Class')
|
||||||
|
const JavaObject = Java.type('java.lang.Object')
|
||||||
|
const NoSuchFieldException = Java.type('java.lang.NoSuchFieldException')
|
||||||
|
const fieldCache = new Map<string, java.lang.reflect.Field>()
|
||||||
|
const methodCache = new Map<string, java.lang.reflect.Method>()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 反射工具类
|
* 反射工具类
|
||||||
* Created by MiaoWoo on 2017/2/9 0009.
|
* Created by MiaoWoo on 2017/2/9 0009.
|
||||||
*/
|
*/
|
||||||
const JavaClass = Java.type('java.lang.Class')
|
|
||||||
const JavaObject = Java.type('java.lang.Object')
|
|
||||||
const NoSuchFieldException = Java.type('java.lang.NoSuchFieldException')
|
|
||||||
const methodCache = []
|
|
||||||
|
|
||||||
class Reflect {
|
class Reflect {
|
||||||
private obj: java.lang.Object
|
private obj: java.lang.Object
|
||||||
private class: java.lang.Class<any>
|
private class: java.lang.Class<any>
|
||||||
@@ -34,23 +35,34 @@ class Reflect {
|
|||||||
return Java.from(declaredMethods(this.class))
|
return Java.from(declaredMethods(this.class))
|
||||||
}
|
}
|
||||||
|
|
||||||
field(name: string | java.lang.String): Reflect {
|
field(nameOrIndex: string | java.lang.String | number, declared = false): java.lang.reflect.Field {
|
||||||
|
if (nameOrIndex == undefined || nameOrIndex == null) throw new Error(`reflect field name can't be ${nameOrIndex} from ${this.class.getName()}!`)
|
||||||
|
let key = this.class.getName() + ':' + nameOrIndex + ':' + declared
|
||||||
|
if (fieldCache.has(key)) {
|
||||||
|
return fieldCache.get(key)
|
||||||
|
}
|
||||||
|
let field = null
|
||||||
|
if (typeof nameOrIndex == "number") {
|
||||||
|
field = this.fields(declared)[nameOrIndex]
|
||||||
|
} else {
|
||||||
try {
|
try {
|
||||||
// Try getting a public field
|
// Try getting a public field
|
||||||
let field = this.class.getField(name)
|
field = this.class.getField(nameOrIndex)
|
||||||
return on(field.get(this.obj))
|
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
// Try again, getting a non-public field
|
// Try again, getting a non-public field
|
||||||
return on(accessible(declaredField(this.class, name)).get(this.obj))
|
field = declaredField(this.class, nameOrIndex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!field) throw new Error(`can't reflect field ${typeof nameOrIndex == "number" ? 'index' : 'name'} ${nameOrIndex} from ${this.class.getName()}!`)
|
||||||
|
return accessible(field)
|
||||||
|
}
|
||||||
|
|
||||||
fields(declared = false): java.lang.reflect.Field[] {
|
fields(declared = false): java.lang.reflect.Field[] {
|
||||||
return Java.from(declared ? this.class.getDeclaredFields() : this.class.getFields())
|
return Java.from(declared ? this.class.getDeclaredFields() : this.class.getFields())
|
||||||
}
|
}
|
||||||
|
|
||||||
values(declared = false) {
|
values(declared = false) {
|
||||||
return this.fields(declared).reduce((cache, field) => { return cache[field.getName()] = this.field(field.getName()).get() }, {}) as any
|
return this.fields(declared).reduce((cache, field) => { return cache[field.getName()] = this.get(field.getName()).get() }, {}) as any
|
||||||
}
|
}
|
||||||
|
|
||||||
call(...args: any[]): Reflect {
|
call(...args: any[]): Reflect {
|
||||||
@@ -64,17 +76,12 @@ class Reflect {
|
|||||||
get(index: number, declared?: boolean): Reflect
|
get(index: number, declared?: boolean): Reflect
|
||||||
get(prop: string): Reflect
|
get(prop: string): Reflect
|
||||||
get(param?: string | number, declared: boolean = true): Reflect | any {
|
get(param?: string | number, declared: boolean = true): Reflect | any {
|
||||||
if (param == undefined || param == null) return this.obj
|
if (arguments.length === 0) return this.obj
|
||||||
if (typeof param == "number") {
|
return on(this.field(param, declared).get(this.obj))
|
||||||
return on(accessible(this.fields(declared)[param]).get(this.obj))
|
|
||||||
}
|
|
||||||
if (typeof param == "string") {
|
|
||||||
return this.field(param)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
set(name: any, value: any): Reflect {
|
set(param: string | number, value: any, declared: boolean = true): Reflect {
|
||||||
accessible(declaredField(this.class, name)).set(this.obj, value)
|
this.field(param, declared).set(this.obj, value)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,64 +143,43 @@ function declaredField(clazz: java.lang.Class<any>, name: string | java.lang.Str
|
|||||||
return field
|
return field
|
||||||
}
|
}
|
||||||
|
|
||||||
function declaredMethod(clazz: java.lang.Class<any>, name: string, ...clazzs: java.lang.Class<any>[]): java.lang.reflect.Method {
|
function declaredMethod(clazz: java.lang.Class<any>, nameOrIndex: string | number, ...clazzs: java.lang.Class<any>[]): java.lang.reflect.Method {
|
||||||
let key = clazz.getName() + '.' + name + ':' + (clazzs || []).join(':')
|
let key = clazz.getName() + '.' + nameOrIndex + ':' + (clazzs || []).map(c => c.getName()).join(':')
|
||||||
if (!methodCache[key]) {
|
if (methodCache.has(key)) { return methodCache.get(key) }
|
||||||
|
if (typeof nameOrIndex === "number") {
|
||||||
|
methodCache.set(key, declaredMethods(clazz)[nameOrIndex])
|
||||||
|
} else {
|
||||||
try {
|
try {
|
||||||
// @ts-ignore
|
methodCache.set(key, clazz.getMethod(nameOrIndex, clazzs as any))
|
||||||
methodCache[key] = clazz.getMethod(name, clazzs)
|
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
try {
|
try {
|
||||||
methodCache[key] = clazz.getDeclaredMethod(name, clazzs as any)
|
methodCache.set(key, clazz.getDeclaredMethod(nameOrIndex, clazzs as any))
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
for (const m of Java.from(declaredMethods(clazz))) {
|
for (const m of Java.from(declaredMethods(clazz))) {
|
||||||
if (m.getName() == name) {
|
if (m.getName() == nameOrIndex) {
|
||||||
methodCache[key] = m
|
methodCache.set(key, m)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return methodCache[key]
|
if (!methodCache.has(key)) throw new Error(`can't reflect method ${typeof nameOrIndex == "number" ? 'index' : 'name'} ${nameOrIndex} from ${clazz.getName()}!`)
|
||||||
|
return methodCache.get(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
function declaredMethods(clazz: java.lang.Class<any>) {
|
function declaredMethods(clazz: java.lang.Class<any>) {
|
||||||
return clazz.getDeclaredMethods()
|
return clazz.getDeclaredMethods()
|
||||||
}
|
}
|
||||||
|
|
||||||
let classMethodsCache: any[] = []
|
|
||||||
|
|
||||||
function mapToObject(javaObj) {
|
function mapToObject(javaObj) {
|
||||||
if (!javaObj || !javaObj.class) { throw new TypeError(`参数 ${javaObj} 不是一个Java对象!`) }
|
if (!Java.isJavaObject(javaObj)) { throw new TypeError(`参数 ${javaObj} 不是一个Java对象!`) }
|
||||||
let target = {}
|
let target = Proxy.newProxy(javaObj, {
|
||||||
getJavaObjectMethods(javaObj).forEach(t => mapMethod(target, javaObj, t))
|
apply: (target, name, args) => { return args ? javaObj[name](args) : javaObj[name]() }
|
||||||
|
})
|
||||||
return target
|
return target
|
||||||
}
|
}
|
||||||
|
|
||||||
function getJavaObjectMethods(javaObj) {
|
|
||||||
let className = javaObj.class.name
|
|
||||||
if (!classMethodsCache[className]) {
|
|
||||||
let names: any[] = []
|
|
||||||
let methods = javaObj.class.methods
|
|
||||||
for (let i in methods) {
|
|
||||||
names.push(methods[i].name)
|
|
||||||
}
|
|
||||||
classMethodsCache[className] = names
|
|
||||||
}
|
|
||||||
return classMethodsCache[className]
|
|
||||||
}
|
|
||||||
|
|
||||||
function mapMethod(target, source, name) {
|
|
||||||
target[name] = function __SimpleDynamicMethod__(...args) {
|
|
||||||
if (args.length > 0) {
|
|
||||||
return source[name](args)
|
|
||||||
} else {
|
|
||||||
return source[name]()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function on(obj) {
|
function on(obj) {
|
||||||
// if (!obj || !obj.class) { throw new TypeError(`参数 ${obj} 不是一个Java对象!`) }
|
// if (!obj || !obj.class) { throw new TypeError(`参数 ${obj} 不是一个Java对象!`) }
|
||||||
return new Reflect(obj)
|
return new Reflect(obj)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/compile",
|
"name": "@ccms/compile",
|
||||||
"version": "0.9.4",
|
"version": "0.15.0",
|
||||||
"description": "MiaoScript compile package",
|
"description": "MiaoScript compile package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -21,6 +21,6 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^4.0.3"
|
"typescript": "^4.3.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/container",
|
"name": "@ccms/container",
|
||||||
"version": "0.9.4",
|
"version": "0.15.0",
|
||||||
"description": "MiaoScript container package",
|
"description": "MiaoScript container package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,13 +19,13 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "^0.9.4",
|
"@ccms/nashorn": "^0.15.0",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^4.0.3"
|
"typescript": "^4.3.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"inversify": "^5.0.1",
|
"inversify": "^5.1.1",
|
||||||
"inversify-binding-decorators": "^4.0.0"
|
"inversify-binding-decorators": "^4.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,14 +62,15 @@ export const JSClass = (className: string) => {
|
|||||||
export const Autowired = (className?: any) => {
|
export const Autowired = (className?: any) => {
|
||||||
return function (target: any, propertyKey: string, index?: number) {
|
return function (target: any, propertyKey: string, index?: number) {
|
||||||
let container = getContainer()
|
let container = getContainer()
|
||||||
if (className instanceof Symbol || className instanceof Function) {
|
if (className && (className instanceof Symbol || className instanceof Function)) {
|
||||||
return inject(className)(target, propertyKey, index)
|
return inject(className)(target, propertyKey, index)
|
||||||
}
|
}
|
||||||
let type = Reflect.getMetadata('design:type', target, propertyKey)
|
let type = Reflect.getMetadata('design:type', target, propertyKey)
|
||||||
if (type && type !== Object) {
|
if (type && type !== Object && !Java.isJavaObject(type)) {
|
||||||
inject(type)(target, propertyKey, index)
|
inject(type)(target, propertyKey, index)
|
||||||
named(className || propertyKey)(target, propertyKey, index)
|
named(className || propertyKey)(target, propertyKey, index)
|
||||||
} else if (container.isBound(ioc.Autowired)) {
|
} else if (container.isBound(ioc.Autowired)) {
|
||||||
|
console.debug('Autowired', 'ioc.Autowired', 'named', className || propertyKey)
|
||||||
target[propertyKey] = container.getNamed(ioc.Autowired, className || propertyKey)
|
target[propertyKey] = container.getNamed(ioc.Autowired, className || propertyKey)
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`No matching bindings found for target: ${target.constructor.name} type: ${type} named: ${className || propertyKey}`)
|
throw new Error(`No matching bindings found for target: ${target.constructor.name} type: ${type} named: ${className || propertyKey}`)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/core",
|
"name": "@ccms/core",
|
||||||
"version": "0.9.5",
|
"version": "0.15.0",
|
||||||
"description": "MiaoScript api package",
|
"description": "MiaoScript api package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -21,11 +21,11 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^4.0.3"
|
"typescript": "^4.3.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.9.5",
|
"@ccms/api": "^0.15.0",
|
||||||
"@ccms/container": "^0.9.4"
|
"@ccms/container": "^0.15.0"
|
||||||
},
|
},
|
||||||
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,23 @@
|
|||||||
let containerStartTime = Date.now()
|
let containerStartTime = Date.now()
|
||||||
console.i18n("ms.core.ioc.initialize", { scope: global.scope })
|
console.i18n("ms.core.ioc.initialize", { scope: global.scope })
|
||||||
import { plugin, server, task, constants } from '@ccms/api'
|
import { plugin, server, task, constants } from '@ccms/api'
|
||||||
import { DefaultContainer as container, inject, provideSingleton, ContainerInstance, buildProviderModule } from '@ccms/container'
|
import { DefaultContainer as container, inject, provideSingleton, ContainerInstance, buildProviderModule, Autowired } from '@ccms/container'
|
||||||
console.i18n("ms.core.ioc.completed", { scope: global.scope, time: (Date.now() - containerStartTime) / 1000 })
|
console.i18n("ms.core.ioc.completed", { scope: global.scope, time: (Date.now() - containerStartTime) / 1000 })
|
||||||
import http from '@ccms/common/dist/http'
|
import http from '@ccms/common/dist/http'
|
||||||
|
|
||||||
@provideSingleton(MiaoScriptCore)
|
@provideSingleton(MiaoScriptCore)
|
||||||
class MiaoScriptCore {
|
class MiaoScriptCore {
|
||||||
@inject(server.Console)
|
@Autowired(server.Console)
|
||||||
private Console: Console
|
private Console: Console
|
||||||
@inject(task.TaskManager)
|
@Autowired(plugin.PluginFolder)
|
||||||
private taskManager: task.TaskManager
|
|
||||||
@inject(plugin.PluginFolder)
|
|
||||||
private pluginFolder: string
|
private pluginFolder: string
|
||||||
@inject(plugin.PluginManager)
|
@Autowired()
|
||||||
|
private taskManager: task.TaskManager
|
||||||
|
@Autowired()
|
||||||
private pluginManager: plugin.PluginManager
|
private pluginManager: plugin.PluginManager
|
||||||
|
|
||||||
enable() {
|
enable() {
|
||||||
this.loadServerConsole()
|
this.loadServerConsole()
|
||||||
this.loadTaskFunction()
|
|
||||||
global.level = "TRACE"
|
|
||||||
this.loadPlugins()
|
this.loadPlugins()
|
||||||
return () => this.disable()
|
return () => this.disable()
|
||||||
}
|
}
|
||||||
@@ -29,15 +27,6 @@ class MiaoScriptCore {
|
|||||||
global.setGlobal('console', new this.Console(), { writable: false, configurable: false })
|
global.setGlobal('console', new this.Console(), { writable: false, configurable: false })
|
||||||
}
|
}
|
||||||
|
|
||||||
loadTaskFunction() {
|
|
||||||
global.setGlobal('setTimeout', (func: Function, tick: number, ...args: any[]) => {
|
|
||||||
return this.taskManager.create(func).later(tick).submit(...args)
|
|
||||||
}, { writable: false, configurable: false })
|
|
||||||
global.setGlobal('setInterval', (func: Function, tick: number, ...args: any[]) => {
|
|
||||||
return this.taskManager.create(func).timer(tick).submit(...args)
|
|
||||||
}, { writable: false, configurable: false })
|
|
||||||
}
|
|
||||||
|
|
||||||
loadPlugins() {
|
loadPlugins() {
|
||||||
let loadPluginStartTime = new Date().getTime()
|
let loadPluginStartTime = new Date().getTime()
|
||||||
console.i18n("ms.core.plugin.initialize")
|
console.i18n("ms.core.plugin.initialize")
|
||||||
@@ -99,6 +88,7 @@ function initialize() {
|
|||||||
console.i18n("ms.core.initialize.detect", { scope: global.scope, type })
|
console.i18n("ms.core.initialize.detect", { scope: global.scope, type })
|
||||||
container.bind(server.ServerType).toConstantValue(type)
|
container.bind(server.ServerType).toConstantValue(type)
|
||||||
container.bind(server.ServerChecker).toSelf().inSingletonScope()
|
container.bind(server.ServerChecker).toSelf().inSingletonScope()
|
||||||
|
container.bind(server.NativePluginManager).toSelf().inSingletonScope()
|
||||||
console.i18n("ms.core.package.initialize", { scope: global.scope, type })
|
console.i18n("ms.core.package.initialize", { scope: global.scope, type })
|
||||||
require(`${global.scope}/${type}`).default(container)
|
require(`${global.scope}/${type}`).default(container)
|
||||||
require(`${global.scope}/plugin`)
|
require(`${global.scope}/plugin`)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/database",
|
"name": "@ccms/database",
|
||||||
"version": "0.9.5",
|
"version": "0.15.0",
|
||||||
"description": "MiaoScript database package",
|
"description": "MiaoScript database package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,13 +19,13 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@javatypes/spring-jdbc": "^0.0.2",
|
"@javatypes/spring-jdbc": "^0.0.3",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^4.0.3"
|
"typescript": "^4.3.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.9.5",
|
"@ccms/api": "^0.15.0",
|
||||||
"@ccms/container": "^0.9.4"
|
"@ccms/container": "^0.15.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
ms.i18n.completed: "Internationalization component initialization completed. Current Language: English"
|
ms.i18n.completed: "Internationalization component initialization completed. Current Language: English"
|
||||||
ms.ployfill.initialize: "Initialization Java Nashorn ployfill. Please wait..."
|
ms.polyfill.initialize: "Initialization Java Nashorn polyfill. Please wait..."
|
||||||
ms.ployfill.completed: "Java Nashorn ployfill loading completed... Cost ({time}s)!"
|
ms.polyfill.completed: "Java Nashorn polyfill loading completed... Cost ({time}s)!"
|
||||||
|
|
||||||
ms.core.ioc.initialize: "Initialization MiaoScript IOC Container {scope}/container. Please wait..."
|
ms.core.ioc.initialize: "Initialization MiaoScript IOC Container {scope}/container. Please wait..."
|
||||||
ms.core.ioc.completed: "MiaoScript IOC Container {scope}/container loading completed({time}s)!"
|
ms.core.ioc.completed: "MiaoScript IOC Container {scope}/container loading completed({time}s)!"
|
||||||
@@ -31,7 +31,8 @@ ms.api.command.tab.completer.error: "§6Player {player} §6exec §b{plugin} §6P
|
|||||||
|
|
||||||
ms.plugin.initialize: "Initialization MiaoScript Plugin System: Plugin: {plugin} Loader: {loader}..."
|
ms.plugin.initialize: "Initialization MiaoScript Plugin System: Plugin: {plugin} Loader: {loader}..."
|
||||||
ms.plugin.event.map: "Total {count} {type} Event Mapping Complate..."
|
ms.plugin.event.map: "Total {count} {type} Event Mapping Complate..."
|
||||||
ms.plugin.manager.scan: "Scanning Plugins in {folder} ..."
|
ms.plugin.manager.scan: "Scanner {scanner} Scanning Plugins in {folder} ..."
|
||||||
|
ms.plugin.manager.scan.finish: "Scanner {scanner} Found {size} Plugins in {folder} Start Build..."
|
||||||
ms.plugin.manager.initialize.error: "§6Plugin §b{name} §6initialize error §4{ex}"
|
ms.plugin.manager.initialize.error: "§6Plugin §b{name} §6initialize error §4{ex}"
|
||||||
ms.plugin.manager.stage: "{stage} {plugin} version {version} by {author}"
|
ms.plugin.manager.stage: "{stage} {plugin} version {version} by {author}"
|
||||||
ms.plugin.manager.stage.exec: "[{plugin}] Exec {name} Stage {stage} When servers is {servers}..."
|
ms.plugin.manager.stage.exec: "[{plugin}] Exec {name} Stage {stage} When servers is {servers}..."
|
||||||
@@ -39,6 +40,7 @@ ms.plugin.manager.stage.exec.error: "§6Plugin §b{plugin} §6exec §d{executor}
|
|||||||
ms.plugin.manager.stage.load: "Loading"
|
ms.plugin.manager.stage.load: "Loading"
|
||||||
ms.plugin.manager.stage.enable: "Enabling"
|
ms.plugin.manager.stage.enable: "Enabling"
|
||||||
ms.plugin.manager.stage.disable: "Disabling"
|
ms.plugin.manager.stage.disable: "Disabling"
|
||||||
|
ms.plugin.manager.build: "Plugin {name}({version}) Build Finish source: {file}({scanner}) loader: {loader} Cost: {cost}s."
|
||||||
ms.plugin.manager.build.error: "§6Load Plugin From §b{file} §6failed. §4Error: §c{error}"
|
ms.plugin.manager.build.error: "§6Load Plugin From §b{file} §6failed. §4Error: §c{error}"
|
||||||
ms.plugin.manager.build.update: "Auto Update Plugin {name} ..."
|
ms.plugin.manager.build.update: "Auto Update Plugin {name} ..."
|
||||||
ms.plugin.manager.build.not.extends: "§4Found error plugin §b{source} §4it's not extends interfaces.Plugin, the plugin will be ignore!"
|
ms.plugin.manager.build.not.extends: "§4Found error plugin §b{source} §4it's not extends interfaces.Plugin, the plugin will be ignore!"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
ms.i18n.completed: "国际化组件 初始化完成 当前语言: 简体中文"
|
ms.i18n.completed: "国际化组件 初始化完成 当前语言: 简体中文"
|
||||||
ms.ployfill.initialize: "加载 Java Nashorn 补丁. 请稍候..."
|
ms.polyfill.initialize: "加载 Java Nashorn 补丁. 请稍候..."
|
||||||
ms.ployfill.completed: "Java Nashorn 补丁 加载完成... 耗时 ({time}s)!"
|
ms.polyfill.completed: "Java Nashorn 补丁 加载完成... 耗时 ({time}s)!"
|
||||||
|
|
||||||
ms.core.ioc.initialize: "初始化 MiaoScript IOC 容器 {scope}/container. 请稍候..."
|
ms.core.ioc.initialize: "初始化 MiaoScript IOC 容器 {scope}/container. 请稍候..."
|
||||||
ms.core.ioc.completed: "MiaoScript IOC 容器 {scope}/container 加载完成 耗时({time}s)"
|
ms.core.ioc.completed: "MiaoScript IOC 容器 {scope}/container 加载完成 耗时({time}s)"
|
||||||
@@ -32,7 +32,8 @@ ms.api.command.tab.completer.error: "§6玩家 §a{player} §6执行 §b{plugin}
|
|||||||
|
|
||||||
ms.plugin.initialize: "初始化 MiaoScript 插件系统: 实例: {plugin} 加载器: {loader}..."
|
ms.plugin.initialize: "初始化 MiaoScript 插件系统: 实例: {plugin} 加载器: {loader}..."
|
||||||
ms.plugin.event.map: "总计 {count} 个 {type} 事件 映射完成..."
|
ms.plugin.event.map: "总计 {count} 个 {type} 事件 映射完成..."
|
||||||
ms.plugin.manager.scan: "扫描 {folder} 文件夹中插件..."
|
ms.plugin.manager.scan: "扫描器 {scanner} 扫描 {folder} 中的插件..."
|
||||||
|
ms.plugin.manager.scan.finish: "扫描器 {scanner} 在 {folder} 中 发现 {size} 个插件 开始构建..."
|
||||||
ms.plugin.manager.initialize.error: "§6插件 §b{name} §6初始化错误 §4{ex}"
|
ms.plugin.manager.initialize.error: "§6插件 §b{name} §6初始化错误 §4{ex}"
|
||||||
ms.plugin.manager.stage: "{stage} {plugin} 版本 {version} 作者 {author}"
|
ms.plugin.manager.stage: "{stage} {plugin} 版本 {version} 作者 {author}"
|
||||||
ms.plugin.manager.stage.exec: "[{plugin}] 执行 {stage} 阶段函数 {name} 匹配类型 {servers}..."
|
ms.plugin.manager.stage.exec: "[{plugin}] 执行 {stage} 阶段函数 {name} 匹配类型 {servers}..."
|
||||||
@@ -40,6 +41,7 @@ ms.plugin.manager.stage.exec.error: "§6插件 §b{plugin} §6执行 §d{executo
|
|||||||
ms.plugin.manager.stage.load: "加载"
|
ms.plugin.manager.stage.load: "加载"
|
||||||
ms.plugin.manager.stage.enable: "启用"
|
ms.plugin.manager.stage.enable: "启用"
|
||||||
ms.plugin.manager.stage.disable: "关闭"
|
ms.plugin.manager.stage.disable: "关闭"
|
||||||
|
ms.plugin.manager.build: "插件 {name}({version}) 构建完成 来源: {file}({scanner}) 引导: {loader} 构建耗时: {cost}s."
|
||||||
ms.plugin.manager.build.error: "§6从文件 §b{file} §6加载插件失败 §4错误: §c{error}"
|
ms.plugin.manager.build.error: "§6从文件 §b{file} §6加载插件失败 §4错误: §c{error}"
|
||||||
ms.plugin.manager.build.update: "自动更新插件 {name} ..."
|
ms.plugin.manager.build.update: "自动更新插件 {name} ..."
|
||||||
ms.plugin.manager.build.not.extends: "§4发现错误的插件 §b{source} §4未继承接口 interfaces.Plugin, 将不会被载入到服务器!"
|
ms.plugin.manager.build.not.extends: "§4发现错误的插件 §b{source} §4未继承接口 interfaces.Plugin, 将不会被载入到服务器!"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/i18n",
|
"name": "@ccms/i18n",
|
||||||
"version": "0.9.4",
|
"version": "0.15.0",
|
||||||
"description": "MiaoScript i18n package",
|
"description": "MiaoScript i18n package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,14 +19,14 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "^0.9.4",
|
"@ccms/nashorn": "^0.15.0",
|
||||||
"@types/js-yaml": "^3.12.5",
|
"@types/js-yaml": "^4.0.1",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^4.0.3"
|
"typescript": "^4.3.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"js-yaml": "^3.14.0"
|
"js-yaml": "^4.1.0"
|
||||||
},
|
},
|
||||||
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
/// <reference types="@ccms/nashorn" />
|
/// <reference types="@ccms/nashorn" />
|
||||||
import * as yaml from 'js-yaml'
|
import * as yaml from 'js-yaml'
|
||||||
|
|
||||||
const File = Java.type("java.io.File");
|
const File = Java.type("java.io.File")
|
||||||
const separatorChar = File.separatorChar;
|
const separatorChar = File.separatorChar
|
||||||
type TranslateParam = { [key: string]: any }
|
type TranslateParam = { [key: string]: any }
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Console {
|
interface Console {
|
||||||
i18n(name: string, param?: TranslateParam);
|
i18n(name: string, param?: TranslateParam)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,20 +23,20 @@ export class Translate {
|
|||||||
|
|
||||||
constructor(root: string | TranslateContent) {
|
constructor(root: string | TranslateContent) {
|
||||||
if (typeof root == 'string') {
|
if (typeof root == 'string') {
|
||||||
this.root = root;
|
this.root = root
|
||||||
} else {
|
} else {
|
||||||
this.langMap = root.langMap;
|
this.langMap = root.langMap
|
||||||
this.fallbackMap = root.fallbackMap || {};
|
this.fallbackMap = root.fallbackMap || {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
translate(name: string, param?: TranslateParam) {
|
translate(name: string, param?: TranslateParam) {
|
||||||
let langText: string = this.langMap[name] || this.fallbackMap[name];
|
let langText: string = this.langMap[name] || this.fallbackMap[name]
|
||||||
if (!langText) { return '[WARN] @ccms/i18n miss lang translate: ' + name }
|
if (!langText) { return '[WARN] @ccms/i18n miss lang translate: ' + name }
|
||||||
for (const key in param) {
|
for (const key in param) {
|
||||||
langText = langText.replace(new RegExp("{" + key + "}", 'gm'), param[key])
|
langText = langText.replace(new RegExp("{" + key + "}", 'gm'), param[key])
|
||||||
}
|
}
|
||||||
return langText;
|
return langText
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize(lang: string = 'zh_cn', fallback: string = 'zh_cn') {
|
initialize(lang: string = 'zh_cn', fallback: string = 'zh_cn') {
|
||||||
@@ -49,8 +49,8 @@ export class Translate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
readYamlFile(dir: string, name: string) {
|
readYamlFile(dir: string, name: string) {
|
||||||
let langFile = this.concat(dir, 'languages', name + '.yml');
|
let langFile = this.concat(dir, 'languages', name + '.yml')
|
||||||
return this.exists(langFile) && yaml.safeLoad(base.read(langFile))
|
return this.exists(langFile) && yaml.load(base.read(langFile))
|
||||||
}
|
}
|
||||||
|
|
||||||
concat(...args: string[]) {
|
concat(...args: string[]) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/keyvalue",
|
"name": "@ccms/keyvalue",
|
||||||
"version": "0.9.5",
|
"version": "0.15.0",
|
||||||
"description": "MiaoScript keyvalue package",
|
"description": "MiaoScript keyvalue package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,18 +19,18 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.9.5",
|
"@ccms/api": "^0.15.0",
|
||||||
"@ccms/common": "^0.9.4",
|
"@ccms/common": "^0.15.0",
|
||||||
"@ccms/container": "^0.9.4"
|
"@ccms/container": "^0.15.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "^0.9.4",
|
"@ccms/nashorn": "^0.15.0",
|
||||||
"@javatypes/amqp-client": "^0.0.2",
|
"@javatypes/amqp-client": "^0.0.3",
|
||||||
"@javatypes/spring-amqp": "^0.0.2",
|
"@javatypes/spring-amqp": "^0.0.3",
|
||||||
"@javatypes/spring-rabbit": "^0.0.2",
|
"@javatypes/spring-rabbit": "^0.0.3",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^4.0.3"
|
"typescript": "^4.3.4"
|
||||||
},
|
},
|
||||||
"gitHead": "2589633069d24f646ac09261b1b2304c21d4ea75"
|
"gitHead": "2589633069d24f646ac09261b1b2304c21d4ea75"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
import { ConnectionFactoryAdapter } from "./connection"
|
|
||||||
import { RabbitTemplateAdapter } from "./template"
|
|
||||||
import { JSClass } from "@ccms/container"
|
|
||||||
|
|
||||||
export const RabbitAdmin = Java.type('org.springframework.amqp.rabbit.core.RabbitAdmin')
|
|
||||||
|
|
||||||
export class RabbitAdminAdapter {
|
|
||||||
@JSClass('org.springframework.amqp.rabbit.core.RabbitAdmin')
|
|
||||||
private RabbitAdmin: org.springframework.amqp.rabbit.core.RabbitAdmin
|
|
||||||
private _Handler: org.springframework.amqp.rabbit.core.RabbitAdmin
|
|
||||||
constructor(config: RabbitTemplateAdapter | org.springframework.amqp.rabbit.core.RabbitTemplate | ConnectionFactoryAdapter | org.springframework.amqp.rabbit.connection.ConnectionFactory) {
|
|
||||||
this._Handler = new RabbitAdmin((config instanceof RabbitTemplateAdapter || config instanceof ConnectionFactoryAdapter) ? config.getHandler() : config)
|
|
||||||
}
|
|
||||||
getHandler(): org.springframework.amqp.rabbit.core.RabbitAdmin {
|
|
||||||
return this._Handler
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
export const ConfirmCallback = Java.type('org.springframework.amqp.rabbit.core.RabbitTemplate.ConfirmCallback')
|
|
||||||
export const ReturnCallback = Java.type('org.springframework.amqp.rabbit.core.RabbitTemplate.ReturnCallback')
|
|
||||||
|
|
||||||
export abstract class ConfirmCallbackAdapter {
|
|
||||||
private _Handler: org.springframework.amqp.rabbit.core.RabbitTemplate.ConfirmCallback
|
|
||||||
constructor() {
|
|
||||||
let ConfirmCallbackImpl = Java.extend(ReturnCallback, {
|
|
||||||
confirm: (correlationData: org.springframework.amqp.rabbit.connection.CorrelationData, ack: boolean, cause: string) => this.confirm(correlationData, ack, cause)
|
|
||||||
})
|
|
||||||
this._Handler = new ConfirmCallbackImpl()
|
|
||||||
}
|
|
||||||
abstract confirm(correlationData: org.springframework.amqp.rabbit.connection.CorrelationData, ack: boolean, cause: string)
|
|
||||||
getHandler() {
|
|
||||||
return this._Handler
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export abstract class ReturnCallbackAdapter {
|
|
||||||
private _Handler: org.springframework.amqp.rabbit.core.RabbitTemplate.ReturnCallback
|
|
||||||
constructor() {
|
|
||||||
let ReturnCallbackImpl = Java.extend(ReturnCallback, {
|
|
||||||
returnedMessage: (message: org.springframework.amqp.core.Message, replyCode: number, replyText: string, exchange: string, routingKey: string) => this.returnedMessage(message, replyCode, replyText, exchange, routingKey)
|
|
||||||
})
|
|
||||||
this._Handler = new ReturnCallbackImpl()
|
|
||||||
}
|
|
||||||
abstract returnedMessage(message: org.springframework.amqp.core.Message, replyCode: number, replyText: string, exchange: string, routingKey: string)
|
|
||||||
getHandler() {
|
|
||||||
return this._Handler
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
import threadPool from '@ccms/common/dist/thread-pool'
|
|
||||||
|
|
||||||
export const ConnectionFactory = Java.type('org.springframework.amqp.rabbit.connection.ConnectionFactory')
|
|
||||||
const CachingConnectionFactory = Java.type('org.springframework.amqp.rabbit.connection.CachingConnectionFactory')
|
|
||||||
interface ConnectionConfig {
|
|
||||||
url: string,
|
|
||||||
username?: string,
|
|
||||||
password?: string,
|
|
||||||
publisherConfirms?: boolean
|
|
||||||
cacheSize?: number
|
|
||||||
}
|
|
||||||
|
|
||||||
export class ConnectionFactoryAdapter {
|
|
||||||
private _Handler: org.springframework.amqp.rabbit.connection.CachingConnectionFactory
|
|
||||||
|
|
||||||
constructor(config: ConnectionConfig) {
|
|
||||||
if (!config.url) { throw new Error('Connection UrI Can\'t be undefiend!') }
|
|
||||||
config = { publisherConfirms: true, cacheSize: 50, ...config }
|
|
||||||
this._Handler = new CachingConnectionFactory(new java.net.URI(config.url))
|
|
||||||
config.username && this._Handler.setUsername(config.username)
|
|
||||||
config.password && this._Handler.setPassword(config.password)
|
|
||||||
this._Handler.setPublisherConfirms(config.publisherConfirms)
|
|
||||||
this._Handler.setExecutor(threadPool.create({
|
|
||||||
groupName: '@ccms/amqp-rabbit'
|
|
||||||
}))
|
|
||||||
this._Handler.setChannelCacheSize(config.cacheSize)
|
|
||||||
}
|
|
||||||
getHandler() {
|
|
||||||
return this._Handler
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
import { ConnectionFactoryAdapter, ConnectionFactory } from "./connection"
|
|
||||||
import { ChannelAwareMessageListenerAdapter, ChannelAwareMessageListener } from "./listener"
|
|
||||||
|
|
||||||
export const SimpleMessageListenerContainer = org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer
|
|
||||||
export const AcknowledgeMode: org.springframework.amqp.core.AcknowledgeMode = Java.type('org.springframework.amqp.core.AcknowledgeMode')
|
|
||||||
interface ContainerConfig {
|
|
||||||
connectionFactory: ConnectionFactoryAdapter | typeof ConnectionFactory
|
|
||||||
queueNames: string[]
|
|
||||||
messageListener: ChannelAwareMessageListenerAdapter | typeof ChannelAwareMessageListener
|
|
||||||
maxConcurrentConsumers?: number
|
|
||||||
concurrentConsumers?: number
|
|
||||||
acknowledgeMode?: org.springframework.amqp.core.AcknowledgeMode
|
|
||||||
}
|
|
||||||
|
|
||||||
export class MessageListenerContainerAdapter {
|
|
||||||
private _Handler: org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer
|
|
||||||
constructor(config: ContainerConfig) {
|
|
||||||
config = { concurrentConsumers: 5, maxConcurrentConsumers: 10, acknowledgeMode: AcknowledgeMode.AUTO, ...config }
|
|
||||||
this._Handler = new SimpleMessageListenerContainer(config.connectionFactory instanceof ConnectionFactoryAdapter ? config.connectionFactory.getHandler() : config.connectionFactory)
|
|
||||||
//@ts-ignore
|
|
||||||
this._Handler.setQueueNames(config.queueNames)
|
|
||||||
this._Handler.setMaxConcurrentConsumers(config.maxConcurrentConsumers)
|
|
||||||
this._Handler.setConcurrentConsumers(config.concurrentConsumers)
|
|
||||||
this._Handler.setAcknowledgeMode(config.acknowledgeMode)
|
|
||||||
this._Handler.setMessageListener(config.messageListener instanceof ChannelAwareMessageListenerAdapter ? config.messageListener.getHandler() : config.messageListener)
|
|
||||||
}
|
|
||||||
getHandler() {
|
|
||||||
return this._Handler
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
const JavaString = Java.type('java.lang.String')
|
|
||||||
const MessageProperties = org.springframework.amqp.core.MessageProperties
|
|
||||||
const Message = org.springframework.amqp.core.Message
|
|
||||||
|
|
||||||
export const MessageConverter = Java.type('org.springframework.amqp.support.converter.MessageConverter')
|
|
||||||
|
|
||||||
export class MessageConverterAdapter {
|
|
||||||
private _Handler: org.springframework.amqp.support.converter.MessageConverter
|
|
||||||
constructor() {
|
|
||||||
var MessageConverterImpl = Java.extend(MessageConverter, {
|
|
||||||
toMessage: (object: any, messageProperties: org.springframework.amqp.core.MessageProperties) => this.toMessage(object, messageProperties),
|
|
||||||
fromMessage: (message: org.springframework.amqp.core.Message) => this.fromMessage(message)
|
|
||||||
})
|
|
||||||
this._Handler = new MessageConverterImpl()
|
|
||||||
}
|
|
||||||
toMessage(object: any, messageProperties: org.springframework.amqp.core.MessageProperties) {
|
|
||||||
if (typeof object == "string") {
|
|
||||||
messageProperties.setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN)
|
|
||||||
return new Message(new JavaString(object).getBytes(), messageProperties)
|
|
||||||
} else {
|
|
||||||
messageProperties.setContentType(MessageProperties.CONTENT_TYPE_JSON)
|
|
||||||
return new Message(new JavaString(JSON.stringify(object)).getBytes(), messageProperties)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fromMessage(message: org.springframework.amqp.core.Message) {
|
|
||||||
if (message.getMessageProperties().getContentType() == MessageProperties.CONTENT_TYPE_TEXT_PLAIN) {
|
|
||||||
return new JavaString(message.getBody(), message.getMessageProperties().getContentEncoding())
|
|
||||||
}
|
|
||||||
if (message.getMessageProperties().getContentType() == MessageProperties.CONTENT_TYPE_JSON) {
|
|
||||||
return JSON.parse(new JavaString(message.getBody(), message.getMessageProperties().getContentEncoding()))
|
|
||||||
}
|
|
||||||
return message
|
|
||||||
}
|
|
||||||
getHandler() {
|
|
||||||
return this._Handler
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
export * from './admin'
|
|
||||||
export * from './callback'
|
|
||||||
export * from './connection'
|
|
||||||
export * from './container'
|
|
||||||
export * from './converter'
|
|
||||||
export * from './listener'
|
|
||||||
export * from './template'
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
const JavaString = Java.type('java.lang.String')
|
|
||||||
export const MessageProperties = org.springframework.amqp.core.MessageProperties
|
|
||||||
export const ChannelAwareMessageListener = Java.type('org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener')
|
|
||||||
export const AmqpRejectAndDontRequeueException = org.springframework.amqp.AmqpRejectAndDontRequeueException
|
|
||||||
export const Channel: com.rabbitmq.client.Channel = Java.type('com.rabbitmq.client.Channel')
|
|
||||||
export const Message = org.springframework.amqp.core.Message
|
|
||||||
export type MessageHandler<T> = (content: T, message: org.springframework.amqp.core.Message, channel: com.rabbitmq.client.Channel) => any
|
|
||||||
export abstract class ChannelAwareMessageListenerAdapter<T = any> {
|
|
||||||
private _Handler: org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener
|
|
||||||
constructor(manual: boolean = false) {
|
|
||||||
let ChannelAwareMessageListenerImpl = Java.extend(ChannelAwareMessageListener, {
|
|
||||||
onMessage: (message: org.springframework.amqp.core.Message, channel: com.rabbitmq.client.Channel) => {
|
|
||||||
let content = new JavaString(message.getBody(), message.getMessageProperties().getContentEncoding() || "UTF-8")
|
|
||||||
try {
|
|
||||||
if (message.getMessageProperties().getContentType() == MessageProperties.CONTENT_TYPE_JSON) {
|
|
||||||
content = JSON.parse(content)
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
if (manual) {
|
|
||||||
channel.basicReject(message.getMessageProperties().getDeliveryTag(), true)
|
|
||||||
} else {
|
|
||||||
throw new AmqpRejectAndDontRequeueException(`${error}`, error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
manual ? this.manualOnMessage(content, message, channel) : this.onMessage(content, message, channel)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
this._Handler = new ChannelAwareMessageListenerImpl()
|
|
||||||
}
|
|
||||||
abstract onMessage(content: T, message: org.springframework.amqp.core.Message, channel: com.rabbitmq.client.Channel): any
|
|
||||||
onError(error: Error, message: org.springframework.amqp.core.Message, channel: com.rabbitmq.client.Channel): any { }
|
|
||||||
getHandler() {
|
|
||||||
return this._Handler
|
|
||||||
}
|
|
||||||
private manualOnMessage(content: T, message: org.springframework.amqp.core.Message, channel: com.rabbitmq.client.Channel) {
|
|
||||||
let deliveryTag = message.getMessageProperties().getDeliveryTag()
|
|
||||||
try {
|
|
||||||
if (this.onMessage(content, message, channel)) {
|
|
||||||
channel.basicAck(deliveryTag, false)
|
|
||||||
} else if (message.getMessageProperties().getRedelivered()) {
|
|
||||||
channel.basicReject(deliveryTag, true)
|
|
||||||
} else {
|
|
||||||
channel.basicNack(deliveryTag, false, true)
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
channel.basicReject(deliveryTag, this.onError(error, message, channel))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
import { MessageConverterAdapter } from "./converter"
|
|
||||||
import { ConnectionFactoryAdapter } from "./connection"
|
|
||||||
import { ConfirmCallbackAdapter, ReturnCallbackAdapter } from "./callback"
|
|
||||||
|
|
||||||
export const RabbitTemplate = Java.type('org.springframework.amqp.rabbit.core.RabbitTemplate')
|
|
||||||
|
|
||||||
interface TemplateConfig {
|
|
||||||
connectionFactory: ConnectionFactoryAdapter | org.springframework.amqp.rabbit.connection.ConnectionFactory
|
|
||||||
confirmCallback?: ConfirmCallbackAdapter
|
|
||||||
returnCallback?: ReturnCallbackAdapter
|
|
||||||
messageConverter?: MessageConverterAdapter
|
|
||||||
}
|
|
||||||
export class RabbitTemplateAdapter {
|
|
||||||
private _Handler: org.springframework.amqp.rabbit.core.RabbitTemplate
|
|
||||||
constructor(config: TemplateConfig) {
|
|
||||||
config = { messageConverter: new MessageConverterAdapter(), ...config }
|
|
||||||
console.debug(JSON.stringify(config))
|
|
||||||
this._Handler = new RabbitTemplate(config.connectionFactory instanceof ConnectionFactoryAdapter ? config.connectionFactory.getHandler() : config.connectionFactory)
|
|
||||||
config.returnCallback && this._Handler.setReturnCallback(config.returnCallback.getHandler())
|
|
||||||
config.confirmCallback && this._Handler.setConfirmCallback(config.confirmCallback.getHandler())
|
|
||||||
config.messageConverter && this._Handler.setMessageConverter(config.messageConverter.getHandler())
|
|
||||||
}
|
|
||||||
|
|
||||||
getHandler() {
|
|
||||||
return this._Handler
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
import { JSClass } from "@ccms/container"
|
|
||||||
import { RabbitAdminAdapter, MessageListenerContainerAdapter, AcknowledgeMode, MessageHandler, ChannelAwareMessageListenerAdapter } from "./adapter"
|
|
||||||
|
|
||||||
export class AmqpAdmin {
|
|
||||||
@JSClass('org.springframework.amqp.core.TopicExchange')
|
|
||||||
private TopicExchange: typeof org.springframework.amqp.core.TopicExchange
|
|
||||||
@JSClass('org.springframework.amqp.core.Queue')
|
|
||||||
private Queue: typeof org.springframework.amqp.core.Queue
|
|
||||||
@JSClass('org.springframework.amqp.core.Binding')
|
|
||||||
private Binding: typeof org.springframework.amqp.core.Binding
|
|
||||||
@JSClass('org.springframework.amqp.rabbit.core.RabbitAdmin')
|
|
||||||
private RabbitAdmin: typeof org.springframework.amqp.rabbit.core.RabbitAdmin
|
|
||||||
@JSClass('org.springframework.amqp.core.Binding.DestinationType')
|
|
||||||
private DestinationType: org.springframework.amqp.core.Binding.DestinationType
|
|
||||||
|
|
||||||
private amqpAdmin: org.springframework.amqp.rabbit.core.RabbitAdmin
|
|
||||||
|
|
||||||
constructor(amqpAdmin: org.springframework.amqp.rabbit.core.RabbitAdmin | any) {
|
|
||||||
if (amqpAdmin instanceof this.RabbitAdmin) {
|
|
||||||
this.amqpAdmin = amqpAdmin
|
|
||||||
} else if (amqpAdmin instanceof RabbitAdminAdapter) {
|
|
||||||
this.amqpAdmin = amqpAdmin.getHandler()
|
|
||||||
} else {
|
|
||||||
this.amqpAdmin = new RabbitAdminAdapter(amqpAdmin).getHandler()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getHandler() {
|
|
||||||
return this.amqpAdmin
|
|
||||||
}
|
|
||||||
|
|
||||||
getQueueProperties(name: string) {
|
|
||||||
return this.amqpAdmin.getQueueProperties(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
declareExchange(name: string) {
|
|
||||||
let exchange = new this.TopicExchange(name, true, false)
|
|
||||||
this.amqpAdmin.declareExchange(exchange)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
declareQueue(name: string) {
|
|
||||||
let queue = new this.Queue(name, true)
|
|
||||||
this.amqpAdmin.declareQueue(queue)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
declareBinding(queue: string, exchange: string, routerKey: string, argument: any = null) {
|
|
||||||
let binding = new this.Binding(queue, this.DestinationType.QUEUE, exchange, routerKey, argument)
|
|
||||||
this.amqpAdmin.declareBinding(binding)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
declareQueueAndBindExchange(queue: string, exchange: string, routerKey: string) {
|
|
||||||
return this.declareQueue(queue).declareExchange(exchange).declareBinding(queue, exchange, routerKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
createContainer<T>(queue: string, listener: MessageHandler<T>, acknowledgeMode = AcknowledgeMode.AUTO) {
|
|
||||||
let connection = this.amqpAdmin.getRabbitTemplate().getConnectionFactory()
|
|
||||||
return new MessageListenerContainerAdapter({
|
|
||||||
connectionFactory: connection,
|
|
||||||
queueNames: [queue],
|
|
||||||
messageListener: new SimpleMessageHandler(listener),
|
|
||||||
acknowledgeMode: acknowledgeMode
|
|
||||||
}).getHandler()
|
|
||||||
}
|
|
||||||
|
|
||||||
send()
|
|
||||||
send() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
getTemplate() {
|
|
||||||
return this.amqpAdmin.getRabbitTemplate()
|
|
||||||
}
|
|
||||||
|
|
||||||
close() {
|
|
||||||
this.getTemplate().stop()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class SimpleMessageHandler extends ChannelAwareMessageListenerAdapter {
|
|
||||||
constructor(private handler: MessageHandler<any>) {
|
|
||||||
super()
|
|
||||||
}
|
|
||||||
onMessage(content: any, message: org.springframework.amqp.core.Message, channel: com.rabbitmq.client.Channel) {
|
|
||||||
return this.handler(content, message, channel)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
export const METADATA_KEY = {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,34 +1,3 @@
|
|||||||
/// <reference types="@ccms/nashorn" />
|
/// <reference types="@ccms/nashorn" />
|
||||||
/// <reference types="@javatypes/jdk" />
|
/// <reference types="@javatypes/jdk" />
|
||||||
/// <reference types="@javatypes/spring-amqp" />
|
export { }
|
||||||
/// <reference types="@javatypes/spring-rabbit" />
|
|
||||||
/// <reference types="@javatypes/amqp-client" />
|
|
||||||
|
|
||||||
import { amqp } from '@ccms/api'
|
|
||||||
import { getContainer, reduceMetadata } from '@ccms/container'
|
|
||||||
|
|
||||||
function init() {
|
|
||||||
const beanFactory = base.getInstance().getAutowireCapableBeanFactory()
|
|
||||||
getContainer().bind(amqp.rabbit.Template).toDynamicValue((ctx) => {
|
|
||||||
let metadata = reduceMetadata(ctx)
|
|
||||||
if (!metadata.named) {
|
|
||||||
return beanFactory.getBean('rabbitTemplate')
|
|
||||||
} else {
|
|
||||||
return beanFactory.getBean(`${metadata.named}-rabbitTemplate`)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
getContainer().bind(amqp.rabbit.Admin).toDynamicValue((ctx) => {
|
|
||||||
let metadata = reduceMetadata(ctx)
|
|
||||||
if (!metadata.named) {
|
|
||||||
return beanFactory.getBean('rabbitAdmin')
|
|
||||||
} else {
|
|
||||||
return beanFactory.getBean(`${metadata.named}-rabbitAdmin`)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
init()
|
|
||||||
|
|
||||||
export * from './admin'
|
|
||||||
export * from './adapter'
|
|
||||||
export * from './manager'
|
|
||||||
export * from './constants'
|
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
export class AmqpListener {
|
|
||||||
constructor() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
import { amqp } from "@ccms/api"
|
|
||||||
import { provideSingleton } from "@ccms/container"
|
|
||||||
|
|
||||||
import { ConnectionFactoryAdapter, RabbitTemplateAdapter, RabbitAdminAdapter } from "./adapter"
|
|
||||||
import { AmqpAdmin } from "./admin"
|
|
||||||
|
|
||||||
@provideSingleton(amqp.Manager)
|
|
||||||
export class AmqpManager {
|
|
||||||
createConnection(url: string, username: string, password: string) {
|
|
||||||
return new ConnectionFactoryAdapter({ url, username, password })
|
|
||||||
}
|
|
||||||
createTemplate(adapter: ConnectionFactoryAdapter) {
|
|
||||||
return new RabbitTemplateAdapter({ connectionFactory: adapter })
|
|
||||||
}
|
|
||||||
createAdmin(adapter: RabbitTemplateAdapter | ConnectionFactoryAdapter) {
|
|
||||||
return new AmqpAdmin(new RabbitAdminAdapter(adapter))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/nashorn",
|
"name": "@ccms/nashorn",
|
||||||
"version": "0.9.4",
|
"version": "0.15.0",
|
||||||
"description": "MiaoScript api package",
|
"description": "MiaoScript api package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -22,6 +22,6 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^4.0.3"
|
"typescript": "^4.3.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ declare global {
|
|||||||
function to<T = any>(array: T[], type?: T): T[]
|
function to<T = any>(array: T[], type?: T): T[]
|
||||||
function extend(...parentTypes: any[]): any
|
function extend(...parentTypes: any[]): any
|
||||||
function synchronized(func: () => void, lock: any): Function
|
function synchronized(func: () => void, lock: any): Function
|
||||||
|
function isJavaObject(obj: any): boolean
|
||||||
function asJSONCompatible<T = any>(obj: T): T
|
function asJSONCompatible<T = any>(obj: T): T
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
// function super(type: any);
|
// function super(type: any);
|
||||||
@@ -66,12 +67,14 @@ declare global {
|
|||||||
interface Core {
|
interface Core {
|
||||||
getClass(name: String): any
|
getClass(name: String): any
|
||||||
getProxyClass(): any
|
getProxyClass(): any
|
||||||
|
getJavaScriptTaskClass(): any
|
||||||
getInstance(): any
|
getInstance(): any
|
||||||
read(path: string): string
|
read(path: string): string
|
||||||
save(path: string, content: string): void
|
save(path: string, content: string): void
|
||||||
delete(path: string): void
|
delete(path: string): void
|
||||||
}
|
}
|
||||||
interface Console {
|
interface Console {
|
||||||
|
prefix: string
|
||||||
ex(err: Error): void
|
ex(err: Error): void
|
||||||
stack(err: Error, color?: boolean): string[]
|
stack(err: Error, color?: boolean): string[]
|
||||||
sender(sender: any, ...args: any): void
|
sender(sender: any, ...args: any): void
|
||||||
@@ -80,8 +83,18 @@ declare global {
|
|||||||
i18n(name: string, ...params: any[]): void
|
i18n(name: string, ...params: any[]): void
|
||||||
}
|
}
|
||||||
interface ProxyConstructor {
|
interface ProxyConstructor {
|
||||||
newProxy<T extends object>(target: T, handler: ProxyHandler<T>): T
|
newProxy<T extends object>(target: T, handler: ProxyHandle<T>): T
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
export interface ProxyHandle<T = any> extends ProxyHandler<any> {
|
||||||
|
setPrototypeOf?(target: T, v: any): any
|
||||||
|
// get: (target: any, name: string) => any
|
||||||
|
// set: (target: any, name: string, value: any) => boolean
|
||||||
|
// construct: (target: any, ...args: any[]) => any
|
||||||
|
// has: (target: any, name: string) => boolean
|
||||||
|
// ownKeys: (target: any) => string[]
|
||||||
|
values?: (target: T) => any[]
|
||||||
|
// call: (target: any, name: string, ...args: any[]) => any
|
||||||
|
// deleteProperty: (target: any, name: string) => boolean
|
||||||
|
}
|
||||||
export { }
|
export { }
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/nodejs",
|
"name": "@ccms/nodejs",
|
||||||
"version": "0.9.4",
|
"version": "0.15.0",
|
||||||
"description": "MiaoScript nodejs package",
|
"description": "MiaoScript nodejs package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,10 +19,11 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "^0.9.4",
|
"@ccms/nashorn": "^0.15.0",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^4.0.3"
|
"tslib": "^2.3.0",
|
||||||
|
"typescript": "^4.3.4"
|
||||||
},
|
},
|
||||||
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/nukkit",
|
"name": "@ccms/nukkit",
|
||||||
"version": "0.9.5",
|
"version": "0.15.0",
|
||||||
"description": "MiaoScript nukkit package",
|
"description": "MiaoScript nukkit package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,14 +19,14 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@javatypes/nukkit-api": "^0.0.2",
|
"@javatypes/nukkit-api": "^0.0.3",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^4.0.3"
|
"typescript": "^4.3.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.9.5",
|
"@ccms/api": "^0.15.0",
|
||||||
"@ccms/common": "^0.9.4",
|
"@ccms/common": "^0.15.0",
|
||||||
"@ccms/container": "^0.9.4"
|
"@ccms/container": "^0.15.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,25 @@
|
|||||||
import { MiaoScriptConsole } from '@ccms/api'
|
import { MiaoScriptConsole } from '@ccms/api'
|
||||||
|
|
||||||
let Nukkit = base.getInstance().getServer();
|
let Nukkit = base.getInstance().getServer()
|
||||||
|
let LogLevel = Java.type('cn.nukkit.utils.LogLevel')
|
||||||
let CommandSender = Java.type('cn.nukkit.command.CommandSender')
|
let CommandSender = Java.type('cn.nukkit.command.CommandSender')
|
||||||
|
|
||||||
export class NukkitConsole extends MiaoScriptConsole {
|
export class NukkitConsole extends MiaoScriptConsole {
|
||||||
sender(sender, ...args) {
|
sender(sender, ...args) {
|
||||||
if (!(sender instanceof CommandSender)) {
|
if (!(sender instanceof CommandSender)) {
|
||||||
this.error(`First parameter ${sender} not instanceof cn.nukkit.command.CommandSender can't send message!`)
|
this.error(`First parameter ${sender} not instanceof cn.nukkit.command.CommandSender can't send message!`)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
if (Object.prototype.toString.call(args[0]) === "[object Array]") {
|
if (Object.prototype.toString.call(args[0]) === "[object Array]") {
|
||||||
args[0].forEach(line => sender.sendMessage(this.prefix + line))
|
args[0].forEach(line => sender.sendMessage(this.prefix + line))
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(this.prefix + args.join(' '));
|
sender.sendMessage(this.prefix + args.join(' '))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console(...args: string[]): void {
|
console(...args: string[]): void {
|
||||||
this.sender(Nukkit.getConsoleSender(), args.join(' '));
|
this.sender(Nukkit.getConsoleSender(), args.join(' '))
|
||||||
|
}
|
||||||
|
error(...args: any[]) {
|
||||||
|
this.logger.log(LogLevel.ERROR, this.name + args.join(' '))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,14 @@
|
|||||||
import { server } from '@ccms/api'
|
import { server } from '@ccms/api'
|
||||||
import { Container } from '@ccms/container'
|
import { Container } from '@ccms/container'
|
||||||
|
|
||||||
import { NukkitConsole } from './console';
|
import { NukkitConsole } from './console'
|
||||||
import './event';
|
import './task'
|
||||||
import './server';
|
import './event'
|
||||||
import './command';
|
import './server'
|
||||||
import './task';
|
import { NukkitNativePluginManager } from './plugin'
|
||||||
|
import './command'
|
||||||
|
|
||||||
export default function NukkitImpl(container: Container) {
|
export default function NukkitImpl(container: Container) {
|
||||||
container.bind(server.Console).toConstantValue(NukkitConsole);
|
container.bind(server.Console).toConstantValue(NukkitConsole)
|
||||||
|
container.bind(server.NativePluginManager).toConstantValue(new NukkitNativePluginManager())
|
||||||
}
|
}
|
||||||
|
|||||||
12
packages/nukkit/src/plugin.ts
Normal file
12
packages/nukkit/src/plugin.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { server } from '@ccms/api'
|
||||||
|
|
||||||
|
let Nukkit: cn.nukkit.Server = base.getInstance().getServer()
|
||||||
|
|
||||||
|
export class NukkitNativePluginManager extends server.NativePluginManager {
|
||||||
|
has(name: string) {
|
||||||
|
return !!this.get(name)
|
||||||
|
}
|
||||||
|
get(name: string) {
|
||||||
|
return Nukkit.getPluginManager().getPlugin(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,25 +1,25 @@
|
|||||||
import { server } from '@ccms/api'
|
import { server } from '@ccms/api'
|
||||||
import { provideSingleton } from '@ccms/container';
|
import { provideSingleton } from '@ccms/container'
|
||||||
|
|
||||||
let Nukkit: cn.nukkit.Server = base.getInstance().getServer();
|
let Nukkit: cn.nukkit.Server = base.getInstance().getServer()
|
||||||
const File = Java.type("java.io.File");
|
const File = Java.type("java.io.File")
|
||||||
|
|
||||||
@provideSingleton(server.Server)
|
@provideSingleton(server.Server)
|
||||||
export class NukkitServer implements server.Server {
|
export class NukkitServer implements server.Server {
|
||||||
private pluginsFolder: string;
|
private pluginsFolder: string
|
||||||
|
|
||||||
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()
|
||||||
}
|
}
|
||||||
|
|
||||||
getPlayer(name: string) {
|
getPlayer(name: string) {
|
||||||
return Nukkit.getPlayer(name)
|
return Nukkit.getPlayerExact(name)
|
||||||
}
|
}
|
||||||
getVersion(): string {
|
getVersion(): string {
|
||||||
return Nukkit.getVersion()
|
return Nukkit.getVersion()
|
||||||
}
|
}
|
||||||
getOnlinePlayers() {
|
getOnlinePlayers() {
|
||||||
return Nukkit.getOnlinePlayers() as unknown as any[]
|
return Nukkit.getOnlinePlayers().values()
|
||||||
}
|
}
|
||||||
getConsoleSender() {
|
getConsoleSender() {
|
||||||
return Nukkit.getConsoleSender()
|
return Nukkit.getConsoleSender()
|
||||||
@@ -37,18 +37,15 @@ export class NukkitServer implements server.Server {
|
|||||||
return Nukkit.dispatchCommand(Nukkit.getConsoleSender(), command)
|
return Nukkit.dispatchCommand(Nukkit.getConsoleSender(), command)
|
||||||
}
|
}
|
||||||
getPluginsFolder(): string {
|
getPluginsFolder(): string {
|
||||||
return this.pluginsFolder;
|
return this.pluginsFolder
|
||||||
}
|
}
|
||||||
getNativePluginManager() {
|
getNativePluginManager() {
|
||||||
return Nukkit.getPluginManager() as any;
|
return Nukkit.getPluginManager() as any
|
||||||
}
|
}
|
||||||
getNettyPipeline() {
|
getNettyPipeline() {
|
||||||
throw new Error("Method not implemented.");
|
throw new Error("Method not implemented.")
|
||||||
}
|
}
|
||||||
getRootLogger() {
|
getRootLogger() {
|
||||||
return Packages.org.apache.logging.log4j.LogManager.getRootLogger()
|
return Packages.org.apache.logging.log4j.LogManager.getRootLogger()
|
||||||
}
|
}
|
||||||
sendJson(sender: string | any, json: object | string): void {
|
|
||||||
throw new Error("Method not implemented.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,17 +5,14 @@ const NukkitRunnable = Java.type('cn.nukkit.scheduler.NukkitRunnable')
|
|||||||
|
|
||||||
@provideSingleton(task.TaskManager)
|
@provideSingleton(task.TaskManager)
|
||||||
export class NukkitTaskManager extends task.TaskManager {
|
export class NukkitTaskManager extends task.TaskManager {
|
||||||
@inject(plugin.PluginInstance)
|
create0(owner: plugin.Plugin, func: Function, id: number): task.Task {
|
||||||
private pluginInstance: any
|
return new NukkitTask(owner, func, id)
|
||||||
|
|
||||||
create0(func: Function): task.Task {
|
|
||||||
return new NukkitTask(this.pluginInstance, func)
|
|
||||||
}
|
}
|
||||||
callSyncMethod(func: Function): any {
|
callSyncMethod(func: Function): any {
|
||||||
return func()
|
return func()
|
||||||
}
|
}
|
||||||
disable0() {
|
disable0() {
|
||||||
base.getInstance().getServer().getScheduler().cancelTask(this.pluginInstance)
|
base.getInstance().getServer().getScheduler().cancelTask(base.getInstance())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,9 +21,9 @@ export class NukkitTask extends task.Task {
|
|||||||
let run = new NukkitRunnable({ run: () => this.run(...args) })
|
let run = new NukkitRunnable({ run: () => this.run(...args) })
|
||||||
let funcName = `runTask${this.interval ? 'Timer' : 'Later'}${this.isAsync ? 'Asynchronously' : ''}`
|
let funcName = `runTask${this.interval ? 'Timer' : 'Later'}${this.isAsync ? 'Asynchronously' : ''}`
|
||||||
if (this.interval) {
|
if (this.interval) {
|
||||||
return run[funcName](this.plugin, this.laterTime, this.interval)
|
return run[funcName](base.getInstance(), this.laterTime, this.interval)
|
||||||
} else {
|
} else {
|
||||||
return run[funcName](this.plugin, this.laterTime)
|
return run[funcName](base.getInstance(), this.laterTime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
import { EventEmitter } from 'events'
|
|
||||||
|
|
||||||
const Thread = Java.type('java.lang.Thread')
|
|
||||||
const ThreadGroup = Java.type("java.lang.ThreadGroup")
|
|
||||||
const AtomicInteger = Java.type("java.util.concurrent.atomic.AtomicInteger")
|
|
||||||
const ThreadPoolExecutor = Java.type('java.util.concurrent.ThreadPoolExecutor')
|
|
||||||
const LinkedBlockingQueue = Java.type("java.util.concurrent.LinkedBlockingQueue")
|
|
||||||
|
|
||||||
const threadCount = new AtomicInteger(0)
|
|
||||||
const threadGroup = new ThreadGroup("@ccms/ployfill-micro-task")
|
|
||||||
const microTaskPool = new ThreadPoolExecutor(
|
|
||||||
10, 100, 60, Packages.java.util.concurrent.TimeUnit.SECONDS,
|
|
||||||
new LinkedBlockingQueue(500),
|
|
||||||
(run: any) => new Thread(threadGroup, run, "@ccms/micro-task-" + threadCount.incrementAndGet()),
|
|
||||||
new ThreadPoolExecutor.CallerRunsPolicy()
|
|
||||||
)
|
|
||||||
|
|
||||||
class Process extends EventEmitter {
|
|
||||||
env = {
|
|
||||||
__noSuchProperty__: (prop) => {
|
|
||||||
return Packages.java.lang.System.getenv(prop)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
platform = Packages.java.lang.System.getProperty("os.name")
|
|
||||||
nextTick(func: Function) {
|
|
||||||
microTaskPool.execute(func)
|
|
||||||
}
|
|
||||||
queueMicrotask(func: Function) {
|
|
||||||
microTaskPool.execute(func)
|
|
||||||
}
|
|
||||||
exit(code: number) {
|
|
||||||
process.emit('exit', code)
|
|
||||||
microTaskPool.shutdown()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
global.setGlobal('process', new Process(), {})
|
|
||||||
global.setGlobal('queueMicrotask', (func: any) => microTaskPool.execute(func), {})
|
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
(function nashornEventLoopMain(context) {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var Thread = Java.type('java.lang.Thread');
|
|
||||||
var Phaser = Java.type('java.util.concurrent.Phaser');
|
|
||||||
var ArrayDeque = Java.type('java.util.ArrayDeque');
|
|
||||||
var HashMap = Java.type('java.util.HashMap');
|
|
||||||
var TimeUnit = Java.type("java.util.concurrent.TimeUnit");
|
|
||||||
var Runnable = Java.type('java.lang.Runnable');
|
|
||||||
|
|
||||||
var globalTimerId;
|
|
||||||
var timerMap;
|
|
||||||
var eventLoop;
|
|
||||||
var phaser = new Phaser();
|
|
||||||
|
|
||||||
// __NASHORN_POLYFILL_TIMER__ type is ScheduledExecutorService
|
|
||||||
var scheduler = context.__NASHORN_POLYFILL_TIMER__;
|
|
||||||
|
|
||||||
resetEventLoop();
|
|
||||||
|
|
||||||
// console.log('main javasript thread ' + Thread.currentThread().getName());
|
|
||||||
|
|
||||||
function resetEventLoop() {
|
|
||||||
globalTimerId = 1;
|
|
||||||
if (timerMap) {
|
|
||||||
timerMap.forEach(function(key, value) {
|
|
||||||
value.cancel(true);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
timerMap = new HashMap();
|
|
||||||
eventLoop = new ArrayDeque();
|
|
||||||
}
|
|
||||||
|
|
||||||
function waitForMessages() {
|
|
||||||
phaser.register();
|
|
||||||
var wait = !(eventLoop.size() === 0);
|
|
||||||
phaser.arriveAndDeregister();
|
|
||||||
return wait;
|
|
||||||
}
|
|
||||||
|
|
||||||
function processNextMessages() {
|
|
||||||
var remaining = 1;
|
|
||||||
while (remaining) {
|
|
||||||
phaser.register();
|
|
||||||
var message = eventLoop.removeFirst();
|
|
||||||
remaining = eventLoop.size();
|
|
||||||
phaser.arriveAndDeregister();
|
|
||||||
|
|
||||||
var fn = message.fn;
|
|
||||||
var args = message.args;
|
|
||||||
|
|
||||||
try {
|
|
||||||
fn.apply(context, args);
|
|
||||||
} catch (e) {
|
|
||||||
console.trace(e);
|
|
||||||
console.trace(fn);
|
|
||||||
console.trace(args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
context.nashornEventLoop = {
|
|
||||||
process: function() {
|
|
||||||
while (waitForMessages()) {
|
|
||||||
processNextMessages()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
reset: resetEventLoop
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
function createRunnable(fn, timerId, args, repeated) {
|
|
||||||
return new Runnable({
|
|
||||||
run: function() {
|
|
||||||
try {
|
|
||||||
var phase = phaser.register();
|
|
||||||
eventLoop.addLast({
|
|
||||||
fn: fn,
|
|
||||||
args: args
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
console.trace(e);
|
|
||||||
} finally {
|
|
||||||
if (!repeated) timerMap.remove(timerId);
|
|
||||||
phaser.arriveAndDeregister();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
var setTimeout = function(fn, millis /* [, args...] */) {
|
|
||||||
var args = [].slice.call(arguments, 2, arguments.length);
|
|
||||||
|
|
||||||
var timerId = globalTimerId++;
|
|
||||||
var runnable = createRunnable(fn, timerId, args, false);
|
|
||||||
|
|
||||||
var task = scheduler.schedule(runnable, millis, TimeUnit.MILLISECONDS);
|
|
||||||
timerMap.put(timerId, task);
|
|
||||||
|
|
||||||
return timerId;
|
|
||||||
};
|
|
||||||
|
|
||||||
var setImmediate = function(fn /* [, args...] */) {
|
|
||||||
var args = [].slice.call(arguments, 1, arguments.length);
|
|
||||||
// @ts-ignore
|
|
||||||
return setTimeout(fn, 0, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
var clearImmediate = function(timerId) {
|
|
||||||
clearTimeout(timerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
var clearTimeout = function(timerId) {
|
|
||||||
var task = timerMap.get(timerId);
|
|
||||||
if (task) {
|
|
||||||
task.cancel(true);
|
|
||||||
timerMap.remove(timerId);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var setInterval = function(fn, delay /* [, args...] */) {
|
|
||||||
var args = [].slice.call(arguments, 2, arguments.length);
|
|
||||||
var timerId = globalTimerId++;
|
|
||||||
var runnable = createRunnable(fn, timerId, args, true);
|
|
||||||
var task = scheduler.scheduleWithFixedDelay(runnable, delay, delay, TimeUnit.MILLISECONDS);
|
|
||||||
timerMap.put(timerId, task);
|
|
||||||
return timerId;
|
|
||||||
};
|
|
||||||
|
|
||||||
var clearInterval = function(timerId) {
|
|
||||||
clearTimeout(timerId);
|
|
||||||
};
|
|
||||||
|
|
||||||
context.setTimeout = setTimeout;
|
|
||||||
context.clearTimeout = clearTimeout;
|
|
||||||
context.setImmediate = setImmediate;
|
|
||||||
context.clearImmediate = clearImmediate;
|
|
||||||
context.setInterval = setInterval;
|
|
||||||
context.clearInterval = clearInterval;
|
|
||||||
// @ts-ignore
|
|
||||||
})(typeof global !== "undefined" && global || typeof self !== "undefined" && self || this);
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/plugin",
|
"name": "@ccms/plugin",
|
||||||
"version": "0.9.7",
|
"version": "0.15.0",
|
||||||
"description": "MiaoScript api package",
|
"description": "MiaoScript api package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,16 +19,17 @@
|
|||||||
"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.5",
|
"@types/js-yaml": "^4.0.1",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^4.0.3"
|
"typescript": "^4.3.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.9.5",
|
"@ccms/api": "^0.15.0",
|
||||||
"@ccms/common": "^0.9.4",
|
"@ccms/common": "^0.15.0",
|
||||||
"@ccms/container": "^0.9.4",
|
"@ccms/container": "^0.15.0",
|
||||||
"@ccms/i18n": "^0.9.4",
|
"@ccms/i18n": "^0.15.0",
|
||||||
"js-yaml": "^3.14.0"
|
"js-yaml": "^4.1.0",
|
||||||
|
"yaml": "^1.10.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { command, plugin, server } from '@ccms/api'
|
import { command, plugin, server } from '@ccms/api'
|
||||||
import { provideSingleton, inject, Autowired } from '@ccms/container'
|
import { provideSingleton, Autowired } from '@ccms/container'
|
||||||
|
import { interfaces } from './interfaces'
|
||||||
import { getPluginCommandMetadata, getPluginTabCompleterMetadata } from './utils'
|
import { getPluginCommandMetadata, getPluginTabCompleterMetadata } from './utils'
|
||||||
|
|
||||||
@provideSingleton(PluginCommandManager)
|
@provideSingleton(PluginCommandManager)
|
||||||
@@ -23,11 +24,10 @@ export class PluginCommandManager {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for (let command of [cmd.name, ...cmd.alias]) {
|
for (let command of [cmd.name, ...cmd.alias]) {
|
||||||
|
let [cmdExecutor, cmdCompleter] = this.generateAutoMainCommand(pluginInstance, cmd, tabs.get(command))
|
||||||
this.CommandManager.on(pluginInstance, command, {
|
this.CommandManager.on(pluginInstance, command, {
|
||||||
cmd: pluginInstance[cmd.executor].bind(pluginInstance),
|
cmd: cmdExecutor.bind(pluginInstance),
|
||||||
tab: tabs.has(command) ?
|
tab: cmdCompleter?.bind(pluginInstance)
|
||||||
pluginInstance[tabs.get(command).executor].bind(pluginInstance) :
|
|
||||||
console.debug(`[${pluginInstance.description.name}] command ${cmd.name} is not registry tabCompleter`)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,8 +35,31 @@ export class PluginCommandManager {
|
|||||||
|
|
||||||
private unregistryCommand(pluginInstance: plugin.Plugin) {
|
private unregistryCommand(pluginInstance: plugin.Plugin) {
|
||||||
let cmds = getPluginCommandMetadata(pluginInstance)
|
let cmds = getPluginCommandMetadata(pluginInstance)
|
||||||
cmds.forEach(cmd => {
|
cmds.forEach(cmd => this.CommandManager.off(pluginInstance, cmd.name))
|
||||||
this.CommandManager.off(pluginInstance, cmd.name)
|
}
|
||||||
})
|
|
||||||
|
private generateAutoMainCommand(pluginInstance: plugin.Plugin, cmd: interfaces.CommandMetadata, tab: interfaces.CommandMetadata) {
|
||||||
|
let cmdExecutor = pluginInstance[cmd.executor]
|
||||||
|
let cmdCompleter = tab ? pluginInstance[tab.executor] : undefined
|
||||||
|
let cmdSubCache = Object.keys(pluginInstance.constructor.prototype).filter(s => s.startsWith('cmd')).map(s => s.substring(3))
|
||||||
|
if (cmd.autoMain) {
|
||||||
|
cmdExecutor = (sender: any, command: string, args: string[]) => {
|
||||||
|
let subcommand = args[0] || 'help'
|
||||||
|
let cmdKey = 'cmd' + subcommand
|
||||||
|
if (!pluginInstance[cmdKey]) {
|
||||||
|
pluginInstance.logger.sender(sender, '§4未知的子命令: §c' + subcommand)
|
||||||
|
pluginInstance['cmdhelp'] && pluginInstance.logger.sender(sender, `§6请执行 §b/${command} §ahelp §6查看帮助!`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
args.shift()
|
||||||
|
return pluginInstance[cmdKey].apply(pluginInstance, [sender, ...args])
|
||||||
|
}
|
||||||
|
let originCompleter = cmdCompleter
|
||||||
|
cmdCompleter = (sender: any, command: string, args: string[]) => {
|
||||||
|
return (args.length == 1 ? cmdSubCache : []).concat(originCompleter?.apply(pluginInstance, [sender, command, args]) || [])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!cmdCompleter) { console.warn(`[${pluginInstance.description.name}] command ${cmd.name} is not registry tabCompleter`) }
|
||||||
|
return [cmdExecutor, cmdCompleter]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ export interface PluginConfigLoader {
|
|||||||
|
|
||||||
export class YamlPluginConfig implements PluginConfigLoader {
|
export class YamlPluginConfig implements PluginConfigLoader {
|
||||||
load(content: string) {
|
load(content: string) {
|
||||||
return yaml.safeLoad(content)
|
return yaml.load(content)
|
||||||
}
|
}
|
||||||
dump(variable: any): string {
|
dump(variable: any): string {
|
||||||
return yaml.safeDump(variable, { skipInvalid: true, lineWidth: 120 })
|
return yaml.dump(variable, { skipInvalid: true, lineWidth: 120 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,6 +29,18 @@ export class JsonPluginConfig implements PluginConfigLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface PluginConfig {
|
||||||
|
/**
|
||||||
|
* Save Config to File
|
||||||
|
*/
|
||||||
|
readonly save?: () => void
|
||||||
|
/**
|
||||||
|
* Reload Config from File
|
||||||
|
*/
|
||||||
|
readonly reload?: () => void
|
||||||
|
[key: string]: any
|
||||||
|
}
|
||||||
|
|
||||||
@provideSingleton(PluginConfigManager)
|
@provideSingleton(PluginConfigManager)
|
||||||
export class PluginConfigManager {
|
export class PluginConfigManager {
|
||||||
private configLoaderMap = new Map<string, PluginConfigLoader>()
|
private configLoaderMap = new Map<string, PluginConfigLoader>()
|
||||||
@@ -50,34 +62,58 @@ export class PluginConfigManager {
|
|||||||
loadConfig(plugin: plugin.Plugin) {
|
loadConfig(plugin: plugin.Plugin) {
|
||||||
let configs = getPluginConfigMetadata(plugin)
|
let configs = getPluginConfigMetadata(plugin)
|
||||||
for (let [_, config] of configs) {
|
for (let [_, config] of configs) {
|
||||||
try {
|
this.loadConfig0(plugin, config)
|
||||||
config.file = fs.concat(fs.file(plugin.description.loadMetadata.file).parent, plugin.description.name, config.filename)
|
|
||||||
let configLoader = this.getConfigLoader(config.format)
|
|
||||||
if (!fs.exists(config.file)) {
|
|
||||||
base.save(config.file, configLoader.dump(plugin[config.variable]))
|
|
||||||
console.i18n("ms.plugin.manager.config.save.default", { plugin: plugin.description.name, name: config.name, format: config.format })
|
|
||||||
} else {
|
|
||||||
Object.defineProperty(plugin, config.variable, { value: configLoader.load(base.read(config.file)) })
|
|
||||||
plugin[config.variable].save = () => this.saveConfig0(plugin, config)
|
|
||||||
console.debug(`[${plugin.description.name}] Load Config ${config.variable} from file ${config.file} =>\n${JSON.stringify(plugin[config.variable], undefined, 4)}`)
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.i18n("ms.plugin.manager.config.load.error", { plugin: plugin.description.name, name: config.name, format: config.format, error })
|
|
||||||
console.ex(error)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
saveConfig(plugin: plugin.Plugin) {
|
saveConfig(plugin: plugin.Plugin) {
|
||||||
let configs = getPluginConfigMetadata(plugin)
|
let configs = getPluginConfigMetadata(plugin)
|
||||||
for (let [_, config] of configs) {
|
for (let [_, config] of configs) {
|
||||||
this.saveConfig0(plugin, config)
|
config.autosave && this.saveConfig0(plugin, config)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private defienConfigProp(plugin: plugin.Plugin, metadata: interfaces.ConfigMetadata, value: any) {
|
||||||
|
Object.defineProperties(value, {
|
||||||
|
'save': { value: () => this.saveConfig0(plugin, metadata) },
|
||||||
|
'reload': { value: () => this.loadConfig0(plugin, metadata) }
|
||||||
|
})
|
||||||
|
Object.defineProperty(plugin, metadata.variable, { value })
|
||||||
|
}
|
||||||
|
|
||||||
|
private loadConfig0(plugin: plugin.Plugin, metadata: interfaces.ConfigMetadata) {
|
||||||
|
try {
|
||||||
|
metadata.file = fs.concat(fs.file(plugin.description.loadMetadata.file).parent, plugin.description.name, metadata.filename)
|
||||||
|
let configLoader = this.getConfigLoader(metadata.format)
|
||||||
|
let defaultValue = metadata.default ?? plugin[metadata.variable]
|
||||||
|
let configValue = defaultValue
|
||||||
|
if (!fs.exists(metadata.file)) {
|
||||||
|
base.save(metadata.file, configLoader.dump(defaultValue))
|
||||||
|
console.i18n("ms.plugin.manager.config.save.default", { plugin: plugin.description.name, name: metadata.name, format: metadata.format })
|
||||||
|
} else {
|
||||||
|
configValue = configLoader.load(base.read(metadata.file)) || {}
|
||||||
|
if (defaultValue) {
|
||||||
|
let needSave = false
|
||||||
|
for (const key of Object.keys(defaultValue)) {
|
||||||
|
// 当配置文件不存在当前属性时才进行赋值
|
||||||
|
if (!Object.prototype.hasOwnProperty.call(configValue, key)) {
|
||||||
|
configValue[key] = defaultValue[key]
|
||||||
|
needSave = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
needSave && base.save(metadata.file, configLoader.dump(configValue))
|
||||||
|
}
|
||||||
|
console.debug(`[${plugin.description.name}] Load Config ${metadata.variable} from file ${metadata.file} =>\n${JSON.stringify(configValue, undefined, 4)}`)
|
||||||
|
}
|
||||||
|
this.defienConfigProp(plugin, metadata, configValue)
|
||||||
|
} catch (error) {
|
||||||
|
console.i18n("ms.plugin.manager.config.load.error", { plugin: plugin.description.name, name: metadata.name, format: metadata.format, error })
|
||||||
|
console.ex(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private saveConfig0(plugin: plugin.Plugin, metadata: interfaces.ConfigMetadata) {
|
private saveConfig0(plugin: plugin.Plugin, metadata: interfaces.ConfigMetadata) {
|
||||||
try {
|
try {
|
||||||
if (metadata.readonly) { console.debug(`[${plugin.description.name}] Skip Save Config ${metadata.variable} Because it's readonly!`) }
|
|
||||||
metadata.file = fs.concat(fs.file(plugin.description.loadMetadata.file).parent, plugin.description.name, metadata.filename)
|
metadata.file = fs.concat(fs.file(plugin.description.loadMetadata.file).parent, plugin.description.name, metadata.filename)
|
||||||
let result = this.getConfigLoader(metadata.format).dump(plugin[metadata.variable])
|
let result = this.getConfigLoader(metadata.format).dump(plugin[metadata.variable])
|
||||||
base.save(metadata.file, result)
|
base.save(metadata.file, result)
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ export function config(metadata: interfaces.ConfigMetadata = {}) {
|
|||||||
metadata.variable = key
|
metadata.variable = key
|
||||||
metadata.version = metadata.version ?? 1
|
metadata.version = metadata.version ?? 1
|
||||||
metadata.format = metadata.format ?? 'yml'
|
metadata.format = metadata.format ?? 'yml'
|
||||||
|
metadata.autosave = metadata.autosave ?? false
|
||||||
metadata.filename = metadata.filename ?? metadata.name + '.' + metadata.format
|
metadata.filename = metadata.filename ?? metadata.name + '.' + metadata.format
|
||||||
let previousMetadata = getPluginConfigMetadata(target)
|
let previousMetadata = getPluginConfigMetadata(target)
|
||||||
previousMetadata.set(metadata.name, metadata)
|
previousMetadata.set(metadata.name, metadata)
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ export * from './manager'
|
|||||||
export * from './decorators'
|
export * from './decorators'
|
||||||
export * from './interfaces'
|
export * from './interfaces'
|
||||||
|
|
||||||
|
export { PluginConfig } from './config'
|
||||||
|
|
||||||
export {
|
export {
|
||||||
plugin as JSPlugin,
|
plugin as JSPlugin,
|
||||||
cmd as Cmd,
|
cmd as Cmd,
|
||||||
|
|||||||
@@ -47,6 +47,10 @@ export namespace interfaces {
|
|||||||
* 参数列表
|
* 参数列表
|
||||||
*/
|
*/
|
||||||
paramtypes?: string[]
|
paramtypes?: string[]
|
||||||
|
/**
|
||||||
|
* 自动化主命令
|
||||||
|
*/
|
||||||
|
autoMain?: boolean
|
||||||
}
|
}
|
||||||
export interface ListenerMetadata extends ExecMetadata {
|
export interface ListenerMetadata extends ExecMetadata {
|
||||||
/**
|
/**
|
||||||
@@ -63,6 +67,10 @@ export namespace interfaces {
|
|||||||
* 配置文件版本号
|
* 配置文件版本号
|
||||||
*/
|
*/
|
||||||
version?: number
|
version?: number
|
||||||
|
/**
|
||||||
|
* 默认配置
|
||||||
|
*/
|
||||||
|
default?: any
|
||||||
/**
|
/**
|
||||||
* 实体变量名称
|
* 实体变量名称
|
||||||
*/
|
*/
|
||||||
@@ -72,9 +80,9 @@ export namespace interfaces {
|
|||||||
*/
|
*/
|
||||||
format?: string
|
format?: string
|
||||||
/**
|
/**
|
||||||
* 是否为只读(关闭时将不会自动保存)
|
* 自动保存 默认为 false
|
||||||
*/
|
*/
|
||||||
readonly?: boolean
|
autosave?: boolean
|
||||||
/**
|
/**
|
||||||
* 配置文件名称
|
* 配置文件名称
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import i18n from '@ccms/i18n'
|
import i18n from '@ccms/i18n'
|
||||||
import { plugin, server, event } from '@ccms/api'
|
import { plugin, server } from '@ccms/api'
|
||||||
import { inject, provideSingleton, Container, ContainerInstance, Autowired } from '@ccms/container'
|
import { provideSingleton, Container, ContainerInstance, Autowired } from '@ccms/container'
|
||||||
|
|
||||||
import './config'
|
import './config'
|
||||||
import { interfaces } from './interfaces'
|
import { interfaces } from './interfaces'
|
||||||
@@ -13,15 +13,17 @@ const Thread = Java.type('java.lang.Thread')
|
|||||||
|
|
||||||
@provideSingleton(plugin.PluginManager)
|
@provideSingleton(plugin.PluginManager)
|
||||||
export class PluginManagerImpl implements plugin.PluginManager {
|
export class PluginManagerImpl implements plugin.PluginManager {
|
||||||
@inject(ContainerInstance)
|
@Autowired(ContainerInstance)
|
||||||
private container: Container
|
private container: Container
|
||||||
@inject(plugin.PluginInstance)
|
@Autowired(plugin.PluginInstance)
|
||||||
private pluginInstance: any
|
private pluginInstance: any
|
||||||
@inject(server.ServerType)
|
@Autowired(server.ServerType)
|
||||||
private serverType: string
|
private serverType: string
|
||||||
|
|
||||||
@Autowired()
|
@Autowired()
|
||||||
private serverChecker: server.ServerChecker
|
private serverChecker: server.ServerChecker
|
||||||
|
@Autowired()
|
||||||
|
private nativePluginManager: server.NativePluginManager
|
||||||
|
|
||||||
@Autowired()
|
@Autowired()
|
||||||
private taskManager: PluginTaskManager
|
private taskManager: PluginTaskManager
|
||||||
@@ -39,6 +41,10 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
|
|
||||||
private instanceMap: Map<string, plugin.Plugin>
|
private instanceMap: Map<string, plugin.Plugin>
|
||||||
private metadataMap: Map<string, plugin.PluginMetadata>
|
private metadataMap: Map<string, plugin.PluginMetadata>
|
||||||
|
/**
|
||||||
|
* 延时加载插件
|
||||||
|
*/
|
||||||
|
private lazyMetadataMap: Map<string, plugin.PluginMetadata>
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.sacnnerMap = new Map()
|
this.sacnnerMap = new Map()
|
||||||
@@ -46,6 +52,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
|
|
||||||
this.instanceMap = new Map()
|
this.instanceMap = new Map()
|
||||||
this.metadataMap = new Map()
|
this.metadataMap = new Map()
|
||||||
|
this.lazyMetadataMap = new Map()
|
||||||
|
|
||||||
// ignore unused
|
// ignore unused
|
||||||
this.taskManager
|
this.taskManager
|
||||||
@@ -79,9 +86,12 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
this.initialize()
|
this.initialize()
|
||||||
for (const [, scanner] of this.sacnnerMap) {
|
for (const [, scanner] of this.sacnnerMap) {
|
||||||
try {
|
try {
|
||||||
scanner.scan(folder).forEach(loadMetadata => {
|
console.i18n('ms.plugin.manager.scan', { scanner: scanner.type, folder })
|
||||||
|
let plugins = scanner.scan(folder)
|
||||||
|
console.i18n('ms.plugin.manager.scan.finish', { scanner: scanner.type, folder, size: plugins.length })
|
||||||
|
plugins.forEach(loadMetadata => {
|
||||||
try {
|
try {
|
||||||
this.loadPlugin(scanner.load(loadMetadata))
|
this.loadAndRequirePlugin(loadMetadata)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`plugin scanner ${scanner.type} load ${loadMetadata.file} occurred error ${error}`)
|
console.error(`plugin scanner ${scanner.type} load ${loadMetadata.file} occurred error ${error}`)
|
||||||
console.ex(error)
|
console.ex(error)
|
||||||
@@ -156,6 +166,20 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private loadAndRequirePlugin(loadMetadata: plugin.PluginLoadMetadata) {
|
||||||
|
let startTime = Date.now()
|
||||||
|
let metadata = this.loadPlugin(loadMetadata.scanner.load(loadMetadata))
|
||||||
|
console.i18n('ms.plugin.manager.build', {
|
||||||
|
name: loadMetadata.metadata.name,
|
||||||
|
version: loadMetadata.metadata.version,
|
||||||
|
file: loadMetadata.file.toString().replace(root, ''),
|
||||||
|
scanner: loadMetadata.scanner.type,
|
||||||
|
loader: loadMetadata.loader.type,
|
||||||
|
cost: (Date.now() - startTime) / 1000
|
||||||
|
})
|
||||||
|
return metadata
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从文件加载插件
|
* 从文件加载插件
|
||||||
* @param file java.io.File
|
* @param file java.io.File
|
||||||
@@ -163,7 +187,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
loadFromFile(file: string, scanner = this.sacnnerMap.get('file')): plugin.Plugin {
|
loadFromFile(file: string, scanner = this.sacnnerMap.get('file')): plugin.Plugin {
|
||||||
if (!file) { throw new Error('plugin file can\'t be undefiend!') }
|
if (!file) { throw new Error('plugin file can\'t be undefiend!') }
|
||||||
if (!scanner) { throw new Error('plugin scanner can\'t be undefiend!') }
|
if (!scanner) { throw new Error('plugin scanner can\'t be undefiend!') }
|
||||||
let metadata = this.loadPlugin(scanner.load(scanner.read(file)))
|
let metadata = this.loadAndRequirePlugin(scanner.read(file))
|
||||||
let plugin = this.buildPlugin(metadata)
|
let plugin = this.buildPlugin(metadata)
|
||||||
this.load(plugin)
|
this.load(plugin)
|
||||||
this.enable(plugin)
|
this.enable(plugin)
|
||||||
@@ -220,22 +244,44 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private buildPlugins() {
|
private buildPlugins() {
|
||||||
this.metadataMap.forEach((metadata) => {
|
this.metadataMap.forEach((metadata, key) => {
|
||||||
try {
|
if (metadata?.depends?.length) {
|
||||||
|
this.lazyMetadataMap.set(key, metadata)
|
||||||
|
} else {
|
||||||
this.buildPlugin(metadata)
|
this.buildPlugin(metadata)
|
||||||
} catch (error) {
|
|
||||||
console.console(error)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
this.lazyMetadataMap.forEach((metadata, key) => this.buildPlugin(metadata))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private checkDepends(depends: string | string[]) {
|
||||||
|
if (!depends) return []
|
||||||
|
let loseDepends = []
|
||||||
|
for (const depend of depends) { if (!this.metadataMap.has(depend)) loseDepends.push(depend) }
|
||||||
|
return loseDepends
|
||||||
|
}
|
||||||
|
private checkNativeDepends(depends: string | string[]) {
|
||||||
|
if (!depends) return []
|
||||||
|
let loseDepends = []
|
||||||
|
for (const depend of depends) { if (!this.nativePluginManager.has(depend)) loseDepends.push(depend) }
|
||||||
|
return loseDepends
|
||||||
|
}
|
||||||
private buildPlugin(metadata: plugin.PluginMetadata) {
|
private buildPlugin(metadata: plugin.PluginMetadata) {
|
||||||
if (!this.loaderMap.has(metadata.type)) { throw new Error(`§4无法加载插件 §c${metadata.name} §4请检查 §c${metadata.type} §4加载器是否正常启用!`) }
|
try {
|
||||||
if (this.instanceMap.has(metadata.name)) { throw new Error(`Plugin ${metadata.name} is already load from ${metadata.source}...`) }
|
if (this.instanceMap.has(metadata.name)) { throw new Error(`Plugin ${metadata.name} is already load from ${metadata.source}...`) }
|
||||||
|
if (!this.loaderMap.has(metadata.type)) { throw new Error(`§4无法加载插件 §b${metadata.name} §4请检查 §c${metadata.type} §4加载器是否正常启用!`) }
|
||||||
if (!this.serverChecker.check(metadata.servers)) { throw new Error(`§6插件 §b${metadata.name} §c服务器类型不兼容(${metadata.servers.join(',')}) §6忽略加载...`) }
|
if (!this.serverChecker.check(metadata.servers)) { throw new Error(`§6插件 §b${metadata.name} §c服务器类型不兼容(${metadata.servers.join(',')}) §6忽略加载...`) }
|
||||||
|
let loseDepends = this.checkDepends(metadata.depends) || []
|
||||||
|
if (loseDepends.length) { throw new Error(`§4无法加载插件 §b${metadata.name} §4请检查脚本依赖 §3[${loseDepends.join(',')}] §4是否安装完整!`) }
|
||||||
|
let loseNativeDepends = this.checkNativeDepends(metadata.nativeDepends) || []
|
||||||
|
if (loseNativeDepends.length) { throw new Error(`§4无法加载插件 §b${metadata.name} §4请检查插件依赖 §3[${loseNativeDepends.join(',')}] §4是否安装完整!`) }
|
||||||
let pluginInstance = this.loaderMap.get(metadata.type).build(metadata)
|
let pluginInstance = this.loaderMap.get(metadata.type).build(metadata)
|
||||||
if (!pluginInstance) { throw new Error(`§4加载器 §c${metadata.type} §4加载插件 §c${metadata.name} §4失败!`) }
|
if (!pluginInstance) { throw new Error(`§4加载器 §c${metadata.type} §4加载插件 §c${metadata.name} §4失败!`) }
|
||||||
this.instanceMap.set(metadata.name, pluginInstance)
|
this.instanceMap.set(metadata.name, pluginInstance)
|
||||||
return pluginInstance
|
return pluginInstance
|
||||||
|
} catch (error) {
|
||||||
|
console.console(`§4无法加载插件 §b${metadata.name} §4构建插件失败!`)
|
||||||
|
console.ex(error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ export class JSFileScanner implements plugin.PluginScanner {
|
|||||||
|
|
||||||
private scanFolder(folder: any): string[] {
|
private scanFolder(folder: any): string[] {
|
||||||
var files = []
|
var files = []
|
||||||
console.i18n('ms.plugin.manager.scan', { folder })
|
|
||||||
this.checkUpdateFolder(folder)
|
this.checkUpdateFolder(folder)
|
||||||
// must check file is exist maybe is a illegal symbolic link file
|
// must check file is exist maybe is a illegal symbolic link file
|
||||||
fs.list(folder).forEach((path: any) => {
|
fs.list(folder).forEach((path: any) => {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export class PluginTaskManager {
|
|||||||
private taskManager: task.TaskManager
|
private taskManager: task.TaskManager
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
process.on('plugin.after.disable', (plugin: plugin.Plugin) => this.cancelTask(plugin))
|
process.on('plugin.after.disable', this.cancelTask.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
private cancelTask(pluginInstance: plugin.Plugin) {
|
private cancelTask(pluginInstance: plugin.Plugin) {
|
||||||
|
|||||||
67
packages/plugins/docs/MiaoBlockly.md
Normal file
67
packages/plugins/docs/MiaoBlockly.md
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
# MiaoBlockly
|
||||||
|
|
||||||
|
## 前言
|
||||||
|
|
||||||
|
- 嗯 我又来了
|
||||||
|
- 之前承诺的 MiaoScript 腐竹可以用的版本
|
||||||
|
- 第一个 Demo 版本 MiaoBlockly 写完了
|
||||||
|
|
||||||
|
### 什么是 MiaoBlockly
|
||||||
|
|
||||||
|
#### ~~对于开发者~~(开发一般不会用这玩意儿)
|
||||||
|
|
||||||
|
#### 对于腐竹
|
||||||
|
- 可以在网页上开发一些简单的插件
|
||||||
|
- 拖动方块就能实现了
|
||||||
|
|
||||||
|
### 图片展示
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### MiaoBlockly 的兼容性
|
||||||
|
- 跨端兼容 Sponge Bukkit BungeeCord
|
||||||
|
- Bukkit 支持 1.12.2 +(由于1.12.2以下版本Netty版本过老需要适配 后续兼容到1.7.10)
|
||||||
|
- Sponge
|
||||||
|
- CatServer 1.12.2+
|
||||||
|
- BungeeCord
|
||||||
|
|
||||||
|
### 安装教程
|
||||||
|
- 安装 `MiaoConsole` [站内地址](https://www.mcbbs.net/thread-1129227-1-1.html) 没错 就是装 MiaoConsole
|
||||||
|
- 因为 `MiaoBlockly` 底层还是运行的 js 只是用 `Blockly` 生成了代码而已
|
||||||
|
- 需要 `MiaoConsole` 是因为需要和服务器通信
|
||||||
|
|
||||||
|
### 使用教程
|
||||||
|
- 查看启动日志 获取临时 `Token`
|
||||||
|
- 或者 执行 `mconsole token` 获得临时Token
|
||||||
|
- 打开 `http://ms.yumc.pw/blockly.html`
|
||||||
|
- 在地址栏输入服务器地址 需要带上端口
|
||||||
|
- 在 Token 栏输入获取到的 Token
|
||||||
|
- 点击链接即可
|
||||||
|
|
||||||
|
### 编辑器使用
|
||||||
|
- 默认界面有一个插件主体
|
||||||
|
- 拖动积木 右侧会自动生成代码
|
||||||
|
- 在代码界面 按下 `Ctrl + S` 代码会自动传送到服务器 并且重载插件
|
||||||
|
- 更多功能还在开发
|
||||||
|
|
||||||
|
### RoadMap
|
||||||
|
- 开发聊天相关功能
|
||||||
|
- 完善事件相关功能
|
||||||
|
- 开发命令相关功能
|
||||||
|
- 开发跨服相关功能
|
||||||
|
- 统一各个端之间的事件(工作量较大 可能会咕咕咕)
|
||||||
|
- 脚本商城 方便开发和腐竹之前的 PY 交易
|
||||||
|
- 脚本打包成 Jar 方便部署
|
||||||
|
|
||||||
|
### Miao系列插件
|
||||||
|
|
||||||
|
- [[经济]MiaoReward —— 喵式奖励 让玩家看广告为服务器提供收入吧[1.7.10+全版本]](https://www.mcbbs.net/thread-1121423-1-1.html)
|
||||||
|
- [[编程]MiaoBlockly —— 喵式积木 用简单的积木来写插件吧[1.12.2+全版本]](https://www.mcbbs.net/thread-1129411-1-1.html)
|
||||||
|
- [[编程]MiaoConsole —— 喵式终端 通过MC端口直接控制服务器 调试插件[1.12.2+全版本]](https://www.mcbbs.net/thread-1129227-1-1.html)
|
||||||
|
- [[管理]MiaoBind —— 喵式绑定 兼容SoulBound的绑定插件 支持自定义关键词[1.7+全版本]](https://www.mcbbs.net/thread-922072-1-1.html)
|
||||||
|
- [[信息]MiaoBoard —— 喵式记分板 自定义动态记分板[1.7+全版本]](https://www.mcbbs.net/thread-631482-1-1.html)
|
||||||
|
- [[聊天]MiaoChat —— 喵式聊天 多功能自定义聊天格式 新增支持跨服[1.7.10+全版本]](https://www.mcbbs.net/thread-631240-1-1.html)
|
||||||
|
- [[菜单]MiaoMenu —— 喵式菜单 强大的自定义菜单 支持多种自定义操作[1.7+全版本]](https://www.mcbbs.net/thread-860047-1-1.html)
|
||||||
|
- [[管理]YUM —— 全能的服务器插件管理工具 全自动安装插件 更新插件[1.7.2+全版本]](https://www.mcbbs.net/thread-701333-1-1.html)
|
||||||
|
|
||||||
|
本插件所用所有代码均为原创,不存在借用/抄袭等行为
|
||||||
@@ -1,12 +1,24 @@
|
|||||||
|
# MiaoConsole
|
||||||
|
|
||||||
## 前言
|
## 前言
|
||||||
|
|
||||||
> 各位开发 在调试Minecraft插件的时候 是不是经常面临下列情况
|
> 各位开发 在调试Minecraft插件的时候 是不是经常面临下列情况
|
||||||
- 编译等半天 重启等半天 测试找不到问题
|
- 编译等半天 重启等半天 测试找不到问题
|
||||||
- 后台 IDE SCP/FTP 来回切换
|
- 后台 IDE SCP/FTP 来回切换
|
||||||
|
|
||||||
### 什么是MiaoConsole
|
> 各位腐竹 在开服的时候 是不是经常遇到下列情况
|
||||||
- MiaoConsole 是 基于 MiaoScript 开发的 在线调试工具
|
- 修改一个配置文件 经常格式错误
|
||||||
- 通过复用 Minecraft的Netty 通道 实现服务器端口 在线调试(并不是Java的调试哦)
|
- 各种报错看不懂 插件依赖找不到
|
||||||
|
|
||||||
|
### 什么是 MiaoConsole
|
||||||
|
|
||||||
|
#### 对于开发者
|
||||||
|
- MiaoConsole 是 基于 `MiaoScript` 开发的 在线调试工具
|
||||||
|
- 通过复用 Minecraft 的 Netty 通道 实现服务器端口 `MiaoScript` 在线调试
|
||||||
|
|
||||||
|
#### 对于腐竹
|
||||||
|
- 可以在网页上实时看到服务器日志
|
||||||
|
- 共享 Token 给插件开发者 让其帮助调试服务器
|
||||||
|
|
||||||
### 工具动图
|
### 工具动图
|
||||||
|
|
||||||
@@ -16,8 +28,8 @@
|
|||||||
### MiaoConsole 有哪些功能
|
### MiaoConsole 有哪些功能
|
||||||
- 无需编译 上传等步骤 实时在线debug
|
- 无需编译 上传等步骤 实时在线debug
|
||||||
- 实时转发服务端日志 无需来回切换
|
- 实时转发服务端日志 无需来回切换
|
||||||
- 基于Nashorn的动态脚本语言
|
- 基于 Nashorn 的动态脚本语言
|
||||||
- 基于TypeScript的自动补全逻辑(以实现BungeeCord Sponge Bukkit的API全自动补全)
|
- 基于 TypeScript 的自动补全逻辑(以实现BungeeCord Sponge Bukkit的API全自动补全)
|
||||||
|
|
||||||
### MiaoConsole 的兼容性
|
### MiaoConsole 的兼容性
|
||||||
- 跨端兼容 Sponge Bukkit BungeeCord
|
- 跨端兼容 Sponge Bukkit BungeeCord
|
||||||
@@ -27,25 +39,27 @@
|
|||||||
- BungeeCord ~~终端转发暂未兼容~~ 已经能兼容了
|
- BungeeCord ~~终端转发暂未兼容~~ 已经能兼容了
|
||||||
|
|
||||||
### 安装教程
|
### 安装教程
|
||||||
- 安装MiaoScript [下载地址](http://w.yumc.pw/free.html#MiaoScript-download)
|
- 安装 `MiaoScript` [站内地址](https://www.mcbbs.net/thread-774401-1-1.html)
|
||||||
- 首次启动 等待加载基础环境类库
|
- 如果你已经安装了 Yum 可以通过 Yum 快速安装 `/yum install MiaoScript`
|
||||||
- 执行 `mpm i MiaoConsole`
|
- 等待 MiaoScript 引擎启动完成(首次启动可能需要10-20秒 依赖于您的网络环境)
|
||||||
|
- 执行 `mspm i MiaoConsole`
|
||||||
|
|
||||||
### 使用教程
|
### 使用教程
|
||||||
- 执行 `mconsole token` 获得临时Token
|
- 查看启动日志 获取临时 `Token`
|
||||||
|
- 或者 执行 `mconsole token` 获得临时Token
|
||||||
- 打开 `http://ms.yumc.pw/console.html`
|
- 打开 `http://ms.yumc.pw/console.html`
|
||||||
- 在地址栏输入服务器地址 需要带上端口
|
- 在地址栏输入服务器地址 需要带上端口
|
||||||
- 在Token栏输入获取到的Token
|
- 在 Token 栏输入获取到的 Token
|
||||||
- 点击链接即可
|
- 点击链接即可
|
||||||
|
|
||||||
### 终端使用
|
### 终端使用
|
||||||
- 支持实时传输服务器日志到终端
|
- 支持实时传输服务器日志到终端
|
||||||
- 直接在终端输入命令 会转发到服务器
|
- 直接在终端输入命令 会转发到服务器
|
||||||
- 目前暂不支持命令自动补全
|
- 支持命令自动补全
|
||||||
- 支持命令历史
|
- 支持命令历史
|
||||||
|
|
||||||
### 代码编辑器使用
|
### 代码编辑器使用
|
||||||
- 支持 Java 的 lang包和util包自动补全
|
- 支持 Java 的类自动补全
|
||||||
- 支持服务端所有代码补全
|
- 支持服务端所有代码补全
|
||||||
- 注意 暂时不支持自动导入包 所以需要手动输入全类名
|
- 注意 暂时不支持自动导入包 所以需要手动输入全类名
|
||||||
- 快捷键说明(选中代码后 只会执行选中部分)
|
- 快捷键说明(选中代码后 只会执行选中部分)
|
||||||
@@ -53,8 +67,27 @@
|
|||||||
- Ctrl + E 执行命令
|
- Ctrl + E 执行命令
|
||||||
- Ctrl + Q 切换代码页
|
- Ctrl + Q 切换代码页
|
||||||
|
|
||||||
|
## 插件源码
|
||||||
|
|
||||||
|
- [MiaoScript包管理中心](https://git.yumc.pw/circlecloud/ms/src/branch/master/packages/plugins/src/MiaoConsole.ts)
|
||||||
|
|
||||||
### RoadMap
|
### RoadMap
|
||||||
- 支持命令自动补全
|
- 支持 Java 类的自动补全
|
||||||
- 支持常用的开发脚本
|
- 支持命令自动补全(已完成)
|
||||||
- 支持快捷操作服务器数据
|
- 支持常用的开发脚本(开发中)
|
||||||
|
- 支持快捷操作服务器数据(开发中)
|
||||||
- 支持在线编辑服务器文件(开发了一半)
|
- 支持在线编辑服务器文件(开发了一半)
|
||||||
|
- 配置文件格式效验(开发中)
|
||||||
|
|
||||||
|
### Miao系列插件
|
||||||
|
|
||||||
|
- [[经济]MiaoReward —— 喵式奖励 让玩家看广告为服务器提供收入吧[1.7.10+全版本]](https://www.mcbbs.net/thread-1121423-1-1.html)
|
||||||
|
- [[编程]MiaoBlockly —— 喵式积木 用简单的积木来写插件吧[1.12.2+全版本]](https://www.mcbbs.net/thread-1129411-1-1.html)
|
||||||
|
- [[编程]MiaoConsole —— 喵式终端 通过MC端口直接控制服务器 调试插件[1.12.2+全版本]](https://www.mcbbs.net/thread-1129227-1-1.html)
|
||||||
|
- [[管理]MiaoBind —— 喵式绑定 兼容SoulBound的绑定插件 支持自定义关键词[1.7+全版本]](https://www.mcbbs.net/thread-922072-1-1.html)
|
||||||
|
- [[信息]MiaoBoard —— 喵式记分板 自定义动态记分板[1.7+全版本]](https://www.mcbbs.net/thread-631482-1-1.html)
|
||||||
|
- [[聊天]MiaoChat —— 喵式聊天 多功能自定义聊天格式 新增支持跨服[1.7.10+全版本]](https://www.mcbbs.net/thread-631240-1-1.html)
|
||||||
|
- [[菜单]MiaoMenu —— 喵式菜单 强大的自定义菜单 支持多种自定义操作[1.7+全版本]](https://www.mcbbs.net/thread-860047-1-1.html)
|
||||||
|
- [[管理]YUM —— 全能的服务器插件管理工具 全自动安装插件 更新插件[1.7.2+全版本]](https://www.mcbbs.net/thread-701333-1-1.html)
|
||||||
|
|
||||||
|
本插件所用所有代码均为原创,不存在借用/抄袭等行为
|
||||||
|
|||||||
76
packages/plugins/docs/MiaoLobby.md
Normal file
76
packages/plugins/docs/MiaoLobby.md
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
# MiaoLobby
|
||||||
|
|
||||||
|
## 插件简介
|
||||||
|
|
||||||
|
- 用户进入服务器/用户登录后 自动选择大厅进行传送 防止堆积在登录服
|
||||||
|
- 支持配置 是否登录后自动分配 或 玩家手动执行随机分配
|
||||||
|
- 支持通过 ActionBar 展示传送状态
|
||||||
|
|
||||||
|
### 插件截图
|
||||||
|
|
||||||
|
- 
|
||||||
|
- 
|
||||||
|
|
||||||
|
### 插件配置
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
#配置文件版本 请勿修改
|
||||||
|
Version: 1.5
|
||||||
|
|
||||||
|
#服务器列表
|
||||||
|
Servers:
|
||||||
|
- lobby1
|
||||||
|
- lobby2
|
||||||
|
#传送超时时间(单位: Tick)
|
||||||
|
WaitTime: 35
|
||||||
|
#自带传送(如果开启 则Login自动传送失效)
|
||||||
|
AutoTP: false
|
||||||
|
#登录自动传送(暂时支持AuthMe)
|
||||||
|
LoginAutoTP: true
|
||||||
|
#传送延时(单位: 秒)
|
||||||
|
AutoTPDelay: 10
|
||||||
|
#尝试完毕后是否继续重试
|
||||||
|
ReTry: true
|
||||||
|
#传送提示
|
||||||
|
Message: '&a请稍候 正在传送至服务器 %s ...'
|
||||||
|
TimeOut: '&c传送超时 正在切换到服务器 %s ...'
|
||||||
|
TPDelay: '&a登陆成功 正在为您匹配服务器 剩余 %s 秒...'
|
||||||
|
Unavailable: '&4已尝试所有可用服务器 传送失败!'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 插件命令
|
||||||
|
|
||||||
|
```
|
||||||
|
插件注册命令:
|
||||||
|
- MiaoLobby
|
||||||
|
别名: ml
|
||||||
|
描述: MiaoLobby - Minecraft 服务器插件父项目
|
||||||
|
权限: MiaoLobby.reload
|
||||||
|
用法: 使用/MiaoLobby help 查看帮助!
|
||||||
|
```
|
||||||
|
|
||||||
|
### 插件权限
|
||||||
|
|
||||||
|
```
|
||||||
|
插件注册权限:
|
||||||
|
- MiaoLobby.default - MiaoLobby 默认权限!
|
||||||
|
- MiaoLobby.admin - MiaoLobby 管理员权限!
|
||||||
|
- MiaoLobby.reload - 重新载入插件!
|
||||||
|
```
|
||||||
|
|
||||||
|
### 插件下载
|
||||||
|
|
||||||
|
[attach]1802025[/attach]
|
||||||
|
|
||||||
|
### Miao系列插件
|
||||||
|
|
||||||
|
- [[经济]MiaoReward —— 喵式奖励 让玩家看广告为服务器提供收入吧[1.7.10+全版本]](https://www.mcbbs.net/thread-1121423-1-1.html)
|
||||||
|
- [[编程]MiaoBlockly —— 喵式积木 用简单的积木来写插件吧[1.12.2+全版本]](https://www.mcbbs.net/thread-1129411-1-1.html)
|
||||||
|
- [[编程]MiaoConsole —— 喵式终端 通过MC端口直接控制服务器 调试插件[1.12.2+全版本]](https://www.mcbbs.net/thread-1129227-1-1.html)
|
||||||
|
- [[管理]MiaoBind —— 喵式绑定 兼容SoulBound的绑定插件 支持自定义关键词[1.7+全版本]](https://www.mcbbs.net/thread-922072-1-1.html)
|
||||||
|
- [[信息]MiaoBoard —— 喵式记分板 自定义动态记分板[1.7+全版本]](https://www.mcbbs.net/thread-631482-1-1.html)
|
||||||
|
- [[聊天]MiaoChat —— 喵式聊天 多功能自定义聊天格式 新增支持跨服[1.7.10+全版本]](https://www.mcbbs.net/thread-631240-1-1.html)
|
||||||
|
- [[菜单]MiaoMenu —— 喵式菜单 强大的自定义菜单 支持多种自定义操作[1.7+全版本]](https://www.mcbbs.net/thread-860047-1-1.html)
|
||||||
|
- [[管理]YUM —— 全能的服务器插件管理工具 全自动安装插件 更新插件[1.7.2+全版本]](https://www.mcbbs.net/thread-701333-1-1.html)
|
||||||
|
|
||||||
|
#### 本插件所用所有代码均为原创,不存在借用/抄袭等行为
|
||||||
33
packages/plugins/docs/MiaoMail.md
Normal file
33
packages/plugins/docs/MiaoMail.md
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
private static void injectInventoryAddItemMethod() {
|
||||||
|
System.out.println("Injectoring Mail...");
|
||||||
|
try {
|
||||||
|
ClassPool pool = ClassPool.getDefault();
|
||||||
|
String inventoryClassName = Bukkit.getServer().getClass().getPackage().getName() + ".inventory.CraftInventory";
|
||||||
|
File classFile = new File(URLDecoder.decode(InventoryDragEvent.class.getProtectionDomain().getCodeSource().getLocation().getPath().split("!")[0], "UTF-8"));
|
||||||
|
pool.appendClassPath(classFile.getPath());
|
||||||
|
classFile = new File(URLDecoder.decode(MailPlugin.class.getProtectionDomain().getCodeSource().getLocation().getPath().split("!")[0], "UTF-8"));
|
||||||
|
pool.appendClassPath(classFile.getPath());
|
||||||
|
CtClass inventoryClass = pool.get(inventoryClassName);
|
||||||
|
CtMethod addItemMethod = inventoryClass.getDeclaredMethod("addItem");
|
||||||
|
|
||||||
|
addItemMethod.insertAfter(
|
||||||
|
"if(this instanceof org.bukkit.inventory.PlayerInventory){"
|
||||||
|
+ " final org.bukkit.inventory.PlayerInventory playerInventory = (org.bukkit.inventory.PlayerInventory)this;"
|
||||||
|
+ " final org.bukkit.entity.Player player = (org.bukkit.entity.Player)playerInventory.getHolder();"
|
||||||
|
+ " if(!$_.values().isEmpty()){"
|
||||||
|
+ " org.bukkit.event.inventory.InventoryDragEvent event = new org.bukkit.event.inventory.InventoryDragEvent(player.getOpenInventory(), new org.bukkit.inventory.ItemStack(org.bukkit.Material.AIR), new org.bukkit.inventory.ItemStack(org.bukkit.Material.AIR), true, $_);"
|
||||||
|
+ " event.setCancelled(true);"
|
||||||
|
+ " event.setResult(org.bukkit.event.Event.Result.DENY);"
|
||||||
|
+ " org.bukkit.Bukkit.getPluginManager().callEvent(event);"
|
||||||
|
+ " }"
|
||||||
|
+ "}");
|
||||||
|
try {
|
||||||
|
inventoryClass.toClass();
|
||||||
|
System.out.println("Injected");
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("Inject fail, Please restart server");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
22
packages/plugins/docs/MiaoNashorn.md
Normal file
22
packages/plugins/docs/MiaoNashorn.md
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
[综合|前置]MiaoNashorn —— 喵式犀牛引擎 用于 Java14+ 自动安装脚本引擎[全版本]
|
||||||
|
# MiaoNashorn
|
||||||
|
|
||||||
|
## 插件介绍
|
||||||
|
|
||||||
|
> 在Java14+环境下缺少Nashorn 本插件用于自动下载并且加载Nashorn依赖
|
||||||
|
> 自动从云端下载依赖 插件仅 8kb 大小
|
||||||
|
|
||||||
|
## 可用于下列插件 在 Java14+ 环境运行
|
||||||
|
|
||||||
|
- PlaceholderAPI 的 Javascript 扩展
|
||||||
|
- MiaoMenu
|
||||||
|
- MiaoScript
|
||||||
|
- TrMenu
|
||||||
|
- AttributePlus
|
||||||
|
- 等其他任何需要 Nashorn 引擎的插件
|
||||||
|
|
||||||
|
## 下载地址
|
||||||
|
|
||||||
|
[attach]1834431[/attach]
|
||||||
|
|
||||||
|
#### 本插件所用所有代码均为原创,不存在借用/抄袭等行为
|
||||||
57
packages/plugins/docs/MiaoPay.md
Normal file
57
packages/plugins/docs/MiaoPay.md
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
# MiaoPay
|
||||||
|
|
||||||
|
## 安装方式
|
||||||
|
|
||||||
|
先按照帖子
|
||||||
|
|
||||||
|
### 网关
|
||||||
|
|
||||||
|
- https://pay.yumc.pw/api
|
||||||
|
|
||||||
|
### 请求规范
|
||||||
|
|
||||||
|
- 除业务参数外 每个请求必须包含下列系统参数
|
||||||
|
- 系统级参数
|
||||||
|
- 应用 ID `appid`
|
||||||
|
- 时间戳 `timestamp` 单位: 秒
|
||||||
|
- 随机字符串 `nonce` 32 位以内的随机字符串
|
||||||
|
|
||||||
|
#### 签名生成
|
||||||
|
|
||||||
|
- 对参数按照字典升序排列
|
||||||
|
- 拼接成查询字符串后追加 key=secret
|
||||||
|
- 获得字符串的 MD5 值 并且转换成大写
|
||||||
|
|
||||||
|
```php
|
||||||
|
ksort($data);
|
||||||
|
$signStr = urldecode(http_build_query($data)).'&key='.\getAppSecret();
|
||||||
|
return strtoupper(md5($signStr));
|
||||||
|
```
|
||||||
|
|
||||||
|
### 相关接口
|
||||||
|
|
||||||
|
#### 创建订单
|
||||||
|
|
||||||
|
- METHOD: /create
|
||||||
|
- PARAM:
|
||||||
|
- 订单标题 `subject` 必填
|
||||||
|
- 订单金额 `amount` 必填 单位: 元
|
||||||
|
- 用户名 `username` 选填
|
||||||
|
- 用户唯一 ID `unionId` 选填
|
||||||
|
- 外部订单 ID `outOrderId` 选填 用于三方系统
|
||||||
|
- 通知地址 `notifyUrl` 选填 用于三方系统回调
|
||||||
|
- RETURN:
|
||||||
|
- 订单ID `order_id`
|
||||||
|
- 订单金额 `amount`
|
||||||
|
- 订单支付地址 `url`
|
||||||
|
|
||||||
|
#### 查询订单
|
||||||
|
|
||||||
|
- METHOD: /query
|
||||||
|
- PARAM:
|
||||||
|
- 订单ID `subject` 必填
|
||||||
|
- 订单金额 `amount` 必填 单位: 元
|
||||||
|
- 用户名 `username` 选填
|
||||||
|
- 用户唯一 ID `uuid` 选填
|
||||||
|
- RETURN:
|
||||||
|
- 订单数据
|
||||||
24
packages/plugins/docs/MiaoPlugin.md
Normal file
24
packages/plugins/docs/MiaoPlugin.md
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
### Miao系列插件
|
||||||
|
|
||||||
|
- [[经济]MiaoReward —— 喵式奖励 让玩家看广告为服务器提供收入吧[1.7.10+全版本]](https://www.mcbbs.net/thread-1121423-1-1.html)
|
||||||
|
- [[编程]MiaoBlockly —— 喵式积木 用简单的积木来写插件吧[1.12.2+全版本]](https://www.mcbbs.net/thread-1129411-1-1.html)
|
||||||
|
- [[编程]MiaoConsole —— 喵式终端 通过MC端口直接控制服务器 调试插件[1.12.2+全版本]](https://www.mcbbs.net/thread-1129227-1-1.html)
|
||||||
|
- [[管理]MiaoBind —— 喵式绑定 兼容SoulBound的绑定插件 支持自定义关键词[1.7+全版本]](https://www.mcbbs.net/thread-922072-1-1.html)
|
||||||
|
- [[信息]MiaoBoard —— 喵式记分板 自定义动态记分板[1.7+全版本]](https://www.mcbbs.net/thread-631482-1-1.html)
|
||||||
|
- [[聊天]MiaoChat —— 喵式聊天 多功能自定义聊天格式 新增支持跨服[1.7.10+全版本]](https://www.mcbbs.net/thread-631240-1-1.html)
|
||||||
|
- [[菜单]MiaoMenu —— 喵式菜单 强大的自定义菜单 支持多种自定义操作[1.7+全版本]](https://www.mcbbs.net/thread-860047-1-1.html)
|
||||||
|
- [[管理]YUM —— 全能的服务器插件管理工具 全自动安装插件 更新插件[1.7.2+全版本]](https://www.mcbbs.net/thread-701333-1-1.html)
|
||||||
|
|
||||||
|
[size=20px][b]Miao系列插件[/b][/size]
|
||||||
|
|
||||||
|
[size=16px][list]
|
||||||
|
[*][url=https://www.mcbbs.net/thread-1121423-1-1.html][经济]MiaoReward —— 喵式奖励 让玩家看广告为服务器提供收入吧[1.7.10+全版本][/url]
|
||||||
|
[*][url=https://www.mcbbs.net/thread-1129411-1-1.html][编程]MiaoBlockly —— 喵式积木 用简单的积木来写插件吧[1.12.2+全版本][/url]
|
||||||
|
[*][url=https://www.mcbbs.net/thread-1129227-1-1.html][编程]MiaoConsole —— 喵式终端 通过MC端口直接控制服务器 调试插件[1.12.2+全版本][/url]
|
||||||
|
[*][url=https://www.mcbbs.net/thread-922072-1-1.html][管理]MiaoBind —— 喵式绑定 兼容SoulBound的绑定插件 支持自定义关键词[1.7+全版本][/url]
|
||||||
|
[*][url=https://www.mcbbs.net/thread-631482-1-1.html][信息]MiaoBoard —— 喵式记分板 自定义动态记分板[1.7+全版本][/url]
|
||||||
|
[*][url=https://www.mcbbs.net/thread-631240-1-1.html][聊天]MiaoChat —— 喵式聊天 多功能自定义聊天格式 新增支持跨服[1.7.10+全版本][/url]
|
||||||
|
[*][url=https://www.mcbbs.net/thread-860047-1-1.html][菜单]MiaoMenu —— 喵式菜单 强大的自定义菜单 支持多种自定义操作[1.7+全版本][/url]
|
||||||
|
[*][url=https://www.mcbbs.net/thread-701333-1-1.html][管理]YUM —— 全能的服务器插件管理工具 全自动安装插件 更新插件[1.7.2+全版本][/url][/list][/size]
|
||||||
|
|
||||||
|
[size=16px]本插件所用所有代码均为原创,不存在借用/抄袭等行为[/size]
|
||||||
114
packages/plugins/docs/MiaoRebate.md
Normal file
114
packages/plugins/docs/MiaoRebate.md
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
# MiaoRebate
|
||||||
|
|
||||||
|
## 插件简介
|
||||||
|
|
||||||
|
- 还在为服务器收入不足而倒闭烦恼嘛
|
||||||
|
- 还在为肝帝不氪金而烦恼嘛
|
||||||
|
- 快来接入 喵式返利
|
||||||
|
- 饿了么美团战略合作 玩家点外卖 腐竹拿返利 增加服务器收入
|
||||||
|
|
||||||
|
### 先来一张 1 块钱吃一餐的图
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### 再来一张红包兑换的图
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### 限时活动
|
||||||
|
|
||||||
|
> 即日起 至 7 月 15 日 额外奖励活动
|
||||||
|
> 每满 50 人关注公众号 额外奖励 50 元 上不封顶 (当月取消关注不算)
|
||||||
|
> 请绑定后加 QQ 群 1055983539 参加活动
|
||||||
|
|
||||||
|
## 插件展示
|
||||||
|
|
||||||
|
> 多图预警 折叠了
|
||||||
|
|
||||||
|
`[spoiler]`
|
||||||
|
|
||||||
|
- 命令帮助
|
||||||
|
- 扫码绑定
|
||||||
|
- 个人信息
|
||||||
|
- 兑换列表
|
||||||
|
|
||||||
|
`[/spoiler]`
|
||||||
|
|
||||||
|
## 插件命令
|
||||||
|
|
||||||
|
```
|
||||||
|
>mre help
|
||||||
|
[外卖系统]====== [外卖系统] 帮助菜单 ======
|
||||||
|
[外卖系统]/mre bind 绑定账号
|
||||||
|
[外卖系统]/mre draw <兑换数量> 兑换点券
|
||||||
|
[外卖系统]由于您是管理员 以为您展示额外命令
|
||||||
|
[外卖系统]/mrd bind server 绑定服务器
|
||||||
|
```
|
||||||
|
|
||||||
|
## 接下来就是赚钱的操作
|
||||||
|
|
||||||
|
### 服务器准备工作
|
||||||
|
|
||||||
|
- 本插件依赖于 `MiaoReward` 请前往 [站内帖子](https://www.mcbbs.net/thread-1121423-1-1.html) 完成安装
|
||||||
|
- 执行 `/mspm install MiaoRebate` 安装 MiaoRebate 脚本插件
|
||||||
|
- 完成安装
|
||||||
|
|
||||||
|
### 绑定服务器
|
||||||
|
|
||||||
|
- 执行 `/mre bind server`
|
||||||
|
- 使用绿色儿的那个 APP 扫码 完成绑定
|
||||||
|
|
||||||
|
### 玩家绑定账号
|
||||||
|
|
||||||
|
- 执行 `/mre bind`
|
||||||
|
- 使用绿色儿的那个 APP 扫码 完成绑定
|
||||||
|
|
||||||
|
## 使用说明
|
||||||
|
|
||||||
|
- 玩家可以通过下列方式获取圈币
|
||||||
|
- 进入公众号 领取红包
|
||||||
|
- 小程序直接点餐或到饿了么/美团 APP 点餐
|
||||||
|
- 点餐后 发送订单号 兑换奖励
|
||||||
|
- 返利额度约为实付金额的 `1%-3%` 左右
|
||||||
|
- 获得的圈币 在服务器使用 `/mre draw 兑换金额`
|
||||||
|
- 腐竹获得圈币后 在公众号兑换成红包即可
|
||||||
|
|
||||||
|
## PAPI 兼容
|
||||||
|
|
||||||
|
- 目前暂不支持 PAPI 变量 后续会支持
|
||||||
|
|
||||||
|
## 配置文件
|
||||||
|
|
||||||
|
```yml
|
||||||
|
# 提示前缀
|
||||||
|
prefix: §6[§b外卖系统§6]§r
|
||||||
|
# 用于检查货币的变量
|
||||||
|
check: "%playerpoints_points%"
|
||||||
|
# 用于充值货币的命令
|
||||||
|
command: points give %player_name% %amount%
|
||||||
|
# 兑换比例 圈币 对应多少 货币
|
||||||
|
ratio: 1
|
||||||
|
# 货币名称
|
||||||
|
coinName: 点券
|
||||||
|
# 进服提示
|
||||||
|
joinTip: true
|
||||||
|
# 绑定数据(请勿手动修改 绑定后会自动填写数据)
|
||||||
|
owner:
|
||||||
|
userid:
|
||||||
|
ccid:
|
||||||
|
openid:
|
||||||
|
```
|
||||||
|
|
||||||
|
## 插件源码
|
||||||
|
|
||||||
|
- [MiaoScript 包管理中心](https://git.yumc.pw/circlecloud/ms/src/branch/master/packages/plugins/src/MiaoRebate.ts)
|
||||||
|
|
||||||
|
## 更新日志
|
||||||
|
|
||||||
|
- 暂无
|
||||||
|
|
||||||
|
## Roadmap
|
||||||
|
|
||||||
|
- 绑定服务器(已完成)
|
||||||
|
- 绑定玩家(已完成)
|
||||||
|
- 兑换圈币(已完成)
|
||||||
112
packages/plugins/docs/MiaoReport.md
Normal file
112
packages/plugins/docs/MiaoReport.md
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
# MiaoReport(喵式报告)
|
||||||
|
|
||||||
|
## 插件简介
|
||||||
|
|
||||||
|
- 本插件只有一个功能 就是上报当前服务器信息和运行日志到 Ubuntu Paste
|
||||||
|
- 适用于哪些 有问题 但是不知道怎么提供报错的用户
|
||||||
|
|
||||||
|
## 插件命令
|
||||||
|
|
||||||
|
- 只有一个 `/mbrp`
|
||||||
|
- 并且只有 OP 权限用户才可以执行
|
||||||
|
|
||||||
|
## 功能预览
|
||||||
|
|
||||||
|
- 报告地址 https://paste.ubuntu.com/p/mVjJtb6Xcg/
|
||||||
|
- 报告详情(已删除无用信息 并不是完整报告)
|
||||||
|
|
||||||
|
```
|
||||||
|
当前报告由 MiaoBugReport(0.0.1) 生成 作者 MiaoWoo 官网 https://w.yumc.pw
|
||||||
|
生成时间: 2021-02-13 21:52:54
|
||||||
|
============================== 以下为本次报告内容 ==============================
|
||||||
|
服务器版本: git-Spigot-dcd1643-e60fc34 (MC: 1.12.2)
|
||||||
|
Bukkit版本: 1.12.2-R0.1-SNAPSHOT
|
||||||
|
============================== 运行数据 ==============================
|
||||||
|
运行时间: 1 小时 25 分 48 秒
|
||||||
|
CPU 核心: 16
|
||||||
|
最大内存: 7282 MB
|
||||||
|
分配内存: 626 MB
|
||||||
|
空闲内存: 307 MB
|
||||||
|
============================== 数据统计 ==============================
|
||||||
|
世界列表:
|
||||||
|
- world(NORMAL)
|
||||||
|
- 已加载区块: 272
|
||||||
|
- 实体数量: 146
|
||||||
|
- Tile数量: 10
|
||||||
|
- 玩家数量: 0
|
||||||
|
- world_nether(NETHER)
|
||||||
|
- 已加载区块: 0
|
||||||
|
- 实体数量: 0
|
||||||
|
- Tile数量: 0
|
||||||
|
- 玩家数量: 0
|
||||||
|
- world_the_end(THE_END)
|
||||||
|
- 已加载区块: 0
|
||||||
|
- 实体数量: 0
|
||||||
|
- Tile数量: 0
|
||||||
|
- 玩家数量: 0
|
||||||
|
在线玩家: Mr_jtb
|
||||||
|
插件列表: MiaoBugReport(0.0.1)
|
||||||
|
============================== 服务器线程堆栈 ==============================
|
||||||
|
"Spigot Metrics Thread" daemon prio=5 id=32
|
||||||
|
java.lang.Thread.State: TIMED_WAITING
|
||||||
|
at java.lang.Object.wait(Native Method)
|
||||||
|
at java.util.TimerThread.mainLoop(Unknown Source)
|
||||||
|
at java.util.TimerThread.run(Unknown Source)
|
||||||
|
|
||||||
|
"Spigot Watchdog Thread" prio=5 id=31
|
||||||
|
java.lang.Thread.State: TIMED_WAITING
|
||||||
|
at java.lang.Thread.sleep(Native Method)
|
||||||
|
at org.spigotmc.WatchdogThread.run(WatchdogThread.java:92)
|
||||||
|
|
||||||
|
"Server thread" prio=5 id=26
|
||||||
|
java.lang.Thread.State: TIMED_WAITING
|
||||||
|
at java.lang.Thread.sleep(Native Method)
|
||||||
|
at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:560)
|
||||||
|
at java.lang.Thread.run(Unknown Source)
|
||||||
|
|
||||||
|
"Server console handler" daemon prio=5 id=29
|
||||||
|
java.lang.Thread.State: RUNNABLE
|
||||||
|
at org.fusesource.jansi.internal.Kernel32.ReadConsoleInputW(Native Method)
|
||||||
|
at org.fusesource.jansi.internal.Kernel32.readConsoleInputHelper(Kernel32.java:761)
|
||||||
|
at org.fusesource.jansi.internal.Kernel32.readConsoleKeyInput(Kernel32.java:794)
|
||||||
|
at org.fusesource.jansi.internal.WindowsSupport.readConsoleInput(WindowsSupport.java:97)
|
||||||
|
at org.bukkit.craftbukkit.libs.jline.WindowsTerminal.readConsoleInput(WindowsTerminal.java:215)
|
||||||
|
at org.bukkit.craftbukkit.libs.jline.WindowsTerminal.access$000(WindowsTerminal.java:55)
|
||||||
|
at org.bukkit.craftbukkit.libs.jline.WindowsTerminal$1.read(WindowsTerminal.java:157)
|
||||||
|
at org.bukkit.craftbukkit.libs.jline.internal.NonBlockingInputStream.read(NonBlockingInputStream.java:169)
|
||||||
|
at org.bukkit.craftbukkit.libs.jline.internal.NonBlockingInputStream.read(NonBlockingInputStream.java:137)
|
||||||
|
at org.bukkit.craftbukkit.libs.jline.internal.NonBlockingInputStream.read(NonBlockingInputStream.java:246)
|
||||||
|
at org.bukkit.craftbukkit.libs.jline.internal.InputStreamReader.read(InputStreamReader.java:261)
|
||||||
|
at org.bukkit.craftbukkit.libs.jline.internal.InputStreamReader.read(InputStreamReader.java:198)
|
||||||
|
at org.bukkit.craftbukkit.libs.jline.console.ConsoleReader.readCharacter(ConsoleReader.java:2145)
|
||||||
|
at org.bukkit.craftbukkit.libs.jline.console.ConsoleReader.readLine(ConsoleReader.java:2349)
|
||||||
|
at net.minecraft.server.v1_12_R1.DedicatedServer$2.run(DedicatedServer.java:85)
|
||||||
|
|
||||||
|
"Netty Server IO #0" daemon prio=5 id=34
|
||||||
|
java.lang.Thread.State: RUNNABLE
|
||||||
|
at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method)
|
||||||
|
at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(Unknown Source)
|
||||||
|
at sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(Unknown Source)
|
||||||
|
at sun.nio.ch.WindowsSelectorImpl.doSelect(Unknown Source)
|
||||||
|
at sun.nio.ch.SelectorImpl.lockAndDoSelect(Unknown Source)
|
||||||
|
at sun.nio.ch.SelectorImpl.select(Unknown Source)
|
||||||
|
at io.netty.channel.nio.SelectedSelectionKeySetSelector.select(SelectedSelectionKeySetSelector.java:62)
|
||||||
|
at io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:753)
|
||||||
|
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:409)
|
||||||
|
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
|
||||||
|
at java.lang.Thread.run(Unknown Source)
|
||||||
|
...忽略其他线程信息
|
||||||
|
============================== 本次运行日志 ==============================
|
||||||
|
[20:27:18] [Server thread/INFO]: Starting minecraft server version 1.12.2
|
||||||
|
...忽略启动日志
|
||||||
|
[20:27:27] [Server thread/INFO]: [MiaoBugReport] Enabling MiaoBugReport v0.0.1
|
||||||
|
[20:27:28] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
|
||||||
|
[20:27:28] [Server thread/INFO]: Done (8.205s)! For help, type "help" or "?"
|
||||||
|
[20:27:53] [Craft Scheduler Thread - 0/INFO]: [0;33;22m[[0;36;1mMiaoBugReport[0;33;22m][m [0;32;1m正在生成日志数据...[m
|
||||||
|
[20:27:55] [Craft Scheduler Thread - 0/INFO]: [0;33;22m[[0;36;1mMiaoBugReport[0;33;22m][m [0;32;1m正在上报数据至UbuntuPaste...[m
|
||||||
|
[20:27:55] [Craft Scheduler Thread - 0/INFO]: [0;33;22m[[0;36;1mMiaoBugReport[0;33;22m][m [0;32;1m数据上报完成 您可以分享地址给他人[m
|
||||||
|
============================== 报告结束 ==============================
|
||||||
|
```
|
||||||
|
|
||||||
|
## 下载地址
|
||||||
|
|
||||||
@@ -6,7 +6,16 @@
|
|||||||
- 快来接入 喵式奖励
|
- 快来接入 喵式奖励
|
||||||
- 通过QQ小程序广告 增加服务器收入
|
- 通过QQ小程序广告 增加服务器收入
|
||||||
|
|
||||||
|
### 先来一张近期的服务器提现订单
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## 插件展示
|
## 插件展示
|
||||||
|
|
||||||
|
> 多图预警 折叠了
|
||||||
|
|
||||||
|
`[spoiler]`
|
||||||
|
|
||||||
- 插件帮助
|
- 插件帮助
|
||||||
- 扫码绑定
|
- 扫码绑定
|
||||||
- 查看个人信息
|
- 查看个人信息
|
||||||
@@ -20,6 +29,9 @@
|
|||||||
- 玩家扫码兑换完成
|
- 玩家扫码兑换完成
|
||||||
- 腐竹扫码确认
|
- 腐竹扫码确认
|
||||||
- 腐竹扫码完成
|
- 腐竹扫码完成
|
||||||
|
|
||||||
|
`[/spoiler]`
|
||||||
|
|
||||||
## 插件命令
|
## 插件命令
|
||||||
```
|
```
|
||||||
>mrd
|
>mrd
|
||||||
@@ -38,28 +50,42 @@
|
|||||||
[17:56:54 INFO]: [MS][MRD] 比如 设置了0.001 那就是 玩家至少 1000喵币 才能兑换!
|
[17:56:54 INFO]: [MS][MRD] 比如 设置了0.001 那就是 玩家至少 1000喵币 才能兑换!
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 接下来就是赚钱的操作
|
||||||
|
|
||||||
## 插件安装/配置
|
## 插件安装/配置
|
||||||
|
|
||||||
### 基础准备工作
|
### 基础准备工作
|
||||||
- QQ搜索小程序 `圈云盒子` 并登录
|
- QQ搜索小程序 `圈云盒子` 并登录
|
||||||
- 申请内测服务器账号 个人中心 => 配置面板 => 圈云盒子客服群 加群申请
|
- 申请内测服务器账号
|
||||||
|
- 个人中心 => 配置面板 => 圈云盒子客服群
|
||||||
|
- 打开群详情 加群
|
||||||
|
|
||||||
|
### 申请账号
|
||||||
|
- 打开 [圈云盒子管理后台](https://reward.yumc.pw)
|
||||||
|
- 扫码登录 并且加入客服群
|
||||||
|
- 创建一个服务器 等待管理员审核通过
|
||||||
|
|
||||||
|
`[hide]`
|
||||||
|
|
||||||
### 服务器准备工作
|
### 服务器准备工作
|
||||||
- 先安装 `MiaoScript` [站内地址]()
|
- 安装 `MiaoScript` [站内地址](https://www.mcbbs.net/thread-774401-1-1.html)
|
||||||
- 可以通过 Yum 快速安装 `/yum install MiaoScript`
|
- 如果你已经安装了 Yum 可以通过 Yum 快速安装 `/yum install MiaoScript`
|
||||||
- 等待 MiaoScript 引擎启动完成(首次启动可能需要10-20秒 依赖于您的网络环境)
|
- 等待 MiaoScript 引擎启动完成(首次启动可能需要10-20秒 依赖于您的网络环境)
|
||||||
- 执行 `/mspm install MiaoReward`
|
- 执行 `/mspm install MiaoReward` 安装 MiaoReward 脚本插件
|
||||||
|
- 完成安装
|
||||||
|
|
||||||
### 绑定服务器
|
### 绑定服务器
|
||||||
- 执行 `/mrd bind server`
|
- 执行 `/mrd bind server`
|
||||||
- 使用QQ扫码
|
- 使用QQ扫码 => 选择需要绑定的服务器 => 完成绑定
|
||||||
- 选择需要绑定的服务器
|
|
||||||
- 完成绑定
|
|
||||||
- 配置服务器兑换比例
|
- 配置服务器兑换比例
|
||||||
- 执行 `/mrd ratio 0.001` (最低为 1:0.0001)
|
- 执行 `/mrd ratio <兑换比例>` (最低为 1:0.0001)
|
||||||
- 执行兑换比例确认指令
|
- 执行兑换比例确认指令
|
||||||
- 执行 `/mrd server` 查看服务器信息
|
- 执行 `/mrd server` 查看服务器信息
|
||||||
- 如需绑定多台 可以直接复制绑定之后的 `MiaoScript/plugins/MiaoReward/config.yml` 文件到多台服务器上 然后 `/mrd reload` 重载插件
|
- 如果群组服需要绑定多台服务器(前提是每个服务器都有玩家在)
|
||||||
|
- 执行 `/gmspm install MiaoReward` 批量安装
|
||||||
|
- 可以直接复制绑定之后的 `MiaoScript/plugins/MiaoReward/config.yml`
|
||||||
|
- 黏贴配置文件到所有需要绑定的服务器上
|
||||||
|
- 然后 `/gmspm reload MiaoReward` 批量重载插件
|
||||||
|
|
||||||
### QQ群配置
|
### QQ群配置
|
||||||
- 打开小程序
|
- 打开小程序
|
||||||
@@ -72,6 +98,7 @@
|
|||||||
- 执行 `/mrd bind`
|
- 执行 `/mrd bind`
|
||||||
- 使用QQ扫码
|
- 使用QQ扫码
|
||||||
- 完成绑定
|
- 完成绑定
|
||||||
|
- 执行 `/mrd query` 查询信息
|
||||||
|
|
||||||
## 使用说明
|
## 使用说明
|
||||||
- 玩家可以通过下列方式获取喵币
|
- 玩家可以通过下列方式获取喵币
|
||||||
@@ -82,13 +109,21 @@
|
|||||||
- 腐竹可以在平台将喵币兑换成RMB(兑换比例请加群联系客服详谈)
|
- 腐竹可以在平台将喵币兑换成RMB(兑换比例请加群联系客服详谈)
|
||||||
- 登录小程序后 个人中心 => 配置面板 => 圈云盒子客服群
|
- 登录小程序后 个人中心 => 配置面板 => 圈云盒子客服群
|
||||||
|
|
||||||
|
## PAPI兼容
|
||||||
|
- 目前已经兼容 PAPI 变量
|
||||||
|
- `%mrd_balance%` 玩家喵币
|
||||||
|
- `%mrd_sign%` 玩家签到(*/1)
|
||||||
|
- `%mrd_video%` 玩家视频观看次数(*/300)
|
||||||
|
- `%mrd_box%` 玩家盒子观看次数(*/300)
|
||||||
|
- 如果玩家变量没有及时更新 执行 `/mrd query` 或 `重新登录游戏` 即可
|
||||||
|
|
||||||
## 配置文件
|
## 配置文件
|
||||||
|
|
||||||
``` yaml
|
```yml
|
||||||
# 服务器ID
|
# 服务器ID
|
||||||
serverId: '16'
|
serverId: 16
|
||||||
# 服务器Token
|
# 服务器Token
|
||||||
serverToken: d50d3f6e-2a59-460a-2b29-82b66c4bbf52
|
serverToken: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
||||||
# 兑换指令
|
# 兑换指令
|
||||||
drawCommand: 'p give %player_name% %amount%'
|
drawCommand: 'p give %player_name% %amount%'
|
||||||
# 冷却时间
|
# 冷却时间
|
||||||
@@ -97,10 +132,20 @@ drawCooldown: 300
|
|||||||
prefix: '§6[§b广告系统§6]§r'
|
prefix: '§6[§b广告系统§6]§r'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 插件源码
|
||||||
|
|
||||||
|
- [MiaoScript包管理中心](https://git.yumc.pw/circlecloud/ms/src/branch/master/packages/plugins/src/MiaoReward.ts)
|
||||||
|
|
||||||
|
`[/hide]`
|
||||||
|
|
||||||
|
## 更新日志
|
||||||
|
- 2020-10-12 完成提现功能
|
||||||
|
- 2020-10-06 使用发包的方式展示地图
|
||||||
|
|
||||||
## Roadmap
|
## Roadmap
|
||||||
- 绑定服务器(已完成)
|
- 绑定服务器(已完成)
|
||||||
- 绑定玩家(已完成)
|
- 绑定玩家(已完成)
|
||||||
- 兑换喵币(已完成)
|
- 兑换喵币(已完成)
|
||||||
- 自助开通服务器(开发中)
|
- [自助开通](https://reward.yumc.pw)服务器(已完成)
|
||||||
- 自助兑换RMB(开发中)
|
- [自助兑换](https://reward.yumc.pw)RMB(已完成)
|
||||||
- 自助提现(开发中)
|
- [自助提现](https://reward.yumc.pw)(已完成)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"name": "@ccms/plugins",
|
"name": "@ccms/plugins",
|
||||||
"version": "0.9.7",
|
"version": "0.15.0",
|
||||||
"description": "MiaoScript plugins package",
|
"description": "MiaoScript plugins package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -20,16 +20,22 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@javatypes/spring-data-redis": "^0.0.2",
|
"@javatypes/bukkit-api": "^0.0.3",
|
||||||
"@javatypes/spring-web": "^0.0.2",
|
"@javatypes/bungee-api": "^0.0.3",
|
||||||
"@javatypes/tomcat": "^0.0.2",
|
"@javatypes/sponge-api": "^0.0.3",
|
||||||
|
"@javatypes/spring-data-redis": "^0.0.3",
|
||||||
|
"@javatypes/spring-web": "^0.0.3",
|
||||||
|
"@javatypes/tomcat": "^0.0.3",
|
||||||
|
"@types/crypto-js": "^4.0.1",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^4.0.3"
|
"typescript": "^4.3.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.9.5",
|
"@babel/standalone": "^7.14.7",
|
||||||
"@ccms/container": "^0.9.4",
|
"@ccms/api": "^0.15.0",
|
||||||
"@ccms/plugin": "^0.9.7"
|
"@ccms/container": "^0.15.0",
|
||||||
|
"@ccms/plugin": "^0.15.0",
|
||||||
|
"crypto-js": "^4.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,24 @@
|
|||||||
/// <reference types="@javatypes/bungee-api" />
|
/// <reference types="@javatypes/bungee-api" />
|
||||||
/// <reference types="@javatypes/spigot-api" />
|
/// <reference types="@javatypes/bukkit-api" />
|
||||||
/// <reference types="@javatypes/sponge-api" />
|
/// <reference types="@javatypes/sponge-api" />
|
||||||
|
|
||||||
import { server } from '@ccms/api';
|
import { server } from '@ccms/api'
|
||||||
import { inject } from '@ccms/container';
|
import { Autowired } from '@ccms/container'
|
||||||
import { plugin, interfaces, cmd, listener, tab } from '@ccms/plugin'
|
import { Cmd, JSPlugin, Listener, Tab, interfaces } from '@ccms/plugin'
|
||||||
|
|
||||||
@plugin({ name: 'HelloWorld', version: '1.0.0', author: 'MiaoWoo', source: __filename })
|
@JSPlugin({ name: 'HelloWorld', version: '1.0.0', author: 'MiaoWoo', source: __filename })
|
||||||
export class HelloWorld extends interfaces.Plugin {
|
export class HelloWorld extends interfaces.Plugin {
|
||||||
@inject(server.Server)
|
@Autowired(server.Server)
|
||||||
private Server: server.Server
|
private Server: server.Server
|
||||||
|
|
||||||
load() {
|
load() {
|
||||||
this.logger.log('Plugin load from MiaoScript Plugin System...');
|
this.logger.log('Plugin load from MiaoScript Plugin System...')
|
||||||
}
|
}
|
||||||
enable() {
|
enable() {
|
||||||
this.logger.log('Plugin enable from MiaoScript Plugin System...');
|
this.logger.log('Plugin enable from MiaoScript Plugin System...')
|
||||||
}
|
}
|
||||||
disable() {
|
disable() {
|
||||||
this.logger.log('Plugin disable from MiaoScript Plugin System...');
|
this.logger.log('Plugin disable from MiaoScript Plugin System...')
|
||||||
}
|
}
|
||||||
|
|
||||||
bukkitload() {
|
bukkitload() {
|
||||||
@@ -61,28 +61,29 @@ export class HelloWorld extends interfaces.Plugin {
|
|||||||
this.logger.log('Plugin Disable When ServerType is Nukkit!')
|
this.logger.log('Plugin Disable When ServerType is Nukkit!')
|
||||||
}
|
}
|
||||||
|
|
||||||
@cmd()
|
@Cmd()
|
||||||
hello(sender: any, command: string, args: string[]) {
|
hello(sender: any, command: string, args: string[]) {
|
||||||
this.logger.log(sender, command, args);
|
this.logger.log(sender, command, args)
|
||||||
sender.sendMessage(JSON.stringify({ command, ...args }))
|
sender.sendMessage(JSON.stringify({ command, ...args }))
|
||||||
}
|
}
|
||||||
|
|
||||||
@tab()
|
@Tab()
|
||||||
tabhello(_sender: any, _command: string, _args: string[]) {
|
tabhello(_sender: any, _command: string, _args: string[]) {
|
||||||
return ['world']
|
return ['world']
|
||||||
}
|
}
|
||||||
|
|
||||||
@listener({ servers: ['bukkit', 'nukkit'] })
|
@Listener({ servers: ['bukkit', 'nukkit'] })
|
||||||
PlayerJoin(event: org.bukkit.event.player.PlayerJoinEvent) {
|
PlayerJoin(event: org.bukkit.event.player.PlayerJoinEvent) {
|
||||||
let plyaer = event.getPlayer();
|
let plyaer = event.getPlayer()
|
||||||
this.logger.console(`§cBukkit §aPlayerJoinEvent: §b${plyaer.getName()}`)
|
this.logger.console(`§cBukkit §aPlayerJoinEvent: §b${plyaer.getName()}`)
|
||||||
setTimeout(() => this.sendWelcome(plyaer), 10);
|
setTimeout(() => this.sendWelcome(plyaer), 500)
|
||||||
}
|
}
|
||||||
|
|
||||||
@listener({ servers: ['sponge'] })
|
@Listener({ servers: ['sponge'] })
|
||||||
ClientConnectionEvent$Join(event: org.spongepowered.api.event.network.ClientConnectionEvent.Join) {
|
ClientConnectionEvent$Join(event: org.spongepowered.api.event.network.ClientConnectionEvent.Join) {
|
||||||
|
event.getTargetEntity().getLocation()
|
||||||
this.logger.console(`§cSponge §aClientConnectionEvent.Join: §b${event.getTargetEntity().getName()}`)
|
this.logger.console(`§cSponge §aClientConnectionEvent.Join: §b${event.getTargetEntity().getName()}`)
|
||||||
setTimeout(() => this.sendWelcome(event.getTargetEntity()), 10);
|
setTimeout(() => this.sendWelcome(event.getTargetEntity()), 500)
|
||||||
}
|
}
|
||||||
|
|
||||||
private sendWelcome(player: any) {
|
private sendWelcome(player: any) {
|
||||||
@@ -90,10 +91,9 @@ export class HelloWorld extends interfaces.Plugin {
|
|||||||
this.logger.sender(player, `§6当前版本: §c${this.Server.getVersion()}`)
|
this.logger.sender(player, `§6当前版本: §c${this.Server.getVersion()}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
@listener({ servers: ['bungee'] })
|
@Listener({ servers: ['bungee'] })
|
||||||
ServerConnected(e: any) {
|
ServerConnected(event: net.md_5.bungee.api.event.ServerConnectedEvent) {
|
||||||
let event = e as net.md_5.bungee.api.event.ServerConnectedEvent
|
|
||||||
this.logger.console(`§cBungeeCord §aServerConnectedEvent: §b${event.getPlayer().getDisplayName()}`)
|
this.logger.console(`§cBungeeCord §aServerConnectedEvent: §b${event.getPlayer().getDisplayName()}`)
|
||||||
setTimeout(() => this.logger.sender(event.getPlayer(), `§a欢迎来到 §bMiaoScript §a的世界 §6来自 §cBungeeCord §6的问候!`), 10);
|
setTimeout(() => this.logger.sender(event.getPlayer(), `§a欢迎来到 §bMiaoScript §a的世界 §6来自 §cBungeeCord §6的问候!`), 500)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
78
packages/plugins/src/McbbsPlugin.ts
Normal file
78
packages/plugins/src/McbbsPlugin.ts
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
/// <reference types="@javatypes/bungee-api" />
|
||||||
|
/// <reference types="@javatypes/bukkit-api" />
|
||||||
|
/// <reference types="@javatypes/sponge-api" />
|
||||||
|
|
||||||
|
import { plugin, server } from '@ccms/api'
|
||||||
|
import { Autowired } from '@ccms/container'
|
||||||
|
import { Cmd, interfaces, JSPlugin, Tab } from '@ccms/plugin'
|
||||||
|
import { Server as SocketIOServer, Socket as SocketIOSocket, Namespace } from '@ccms/websocket'
|
||||||
|
|
||||||
|
import * as fs from '@ccms/common/dist/fs'
|
||||||
|
|
||||||
|
const FileFilter = Java.type('java.io.FileFilter')
|
||||||
|
const ByteArrayInputStream = java.io.ByteArrayInputStream
|
||||||
|
const ByteArrayOutputStream = java.io.ByteArrayOutputStream
|
||||||
|
const StandardCharsets = Java.type("java.nio.charset.StandardCharsets")
|
||||||
|
const GZIPInputStream = Java.type('java.util.zip.GZIPInputStream')
|
||||||
|
const ByteArray = Java.type("byte[]")
|
||||||
|
|
||||||
|
@JSPlugin({ version: '1.0.0', author: 'MiaoWoo', source: __filename })
|
||||||
|
export class McbbsPlugin extends interfaces.Plugin {
|
||||||
|
@Autowired()
|
||||||
|
private Server: server.Server
|
||||||
|
@Autowired()
|
||||||
|
private pluginManager: plugin.PluginManager
|
||||||
|
|
||||||
|
private namespace: any
|
||||||
|
|
||||||
|
load() {
|
||||||
|
}
|
||||||
|
|
||||||
|
enable() {
|
||||||
|
let consolePlugin: any = this.pluginManager.getPlugin('MiaoConsole')
|
||||||
|
if (consolePlugin.socketIOServer) {
|
||||||
|
this.startWebSocketServer(consolePlugin.socketIOServer)
|
||||||
|
} else {
|
||||||
|
process.on('websocket.create', (server: SocketIOServer) => {
|
||||||
|
this.startWebSocketServer(server)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private startWebSocketServer(server: SocketIOServer) {
|
||||||
|
this.namespace = server.of('/McbbsPlugin')
|
||||||
|
this.namespace.on('connect', (client: SocketIOSocket) => {
|
||||||
|
this.initWebSocketClient(client)
|
||||||
|
this.logger.console(`§6客户端 §b${client.id} §a新建连接...`)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
disable() {
|
||||||
|
this.namespace.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
private initWebSocketClient(client: SocketIOSocket) {
|
||||||
|
client.on('ungzip', (content) => {
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
client.on('error', (error) => {
|
||||||
|
this.logger.console(`§6客户端 §b${client.id} §c触发异常: ${error}`)
|
||||||
|
this.logger.error(error)
|
||||||
|
})
|
||||||
|
client.on('disconnect', () => {
|
||||||
|
this.logger.console(`§6客户端 §b${client.id} §c断开连接...`)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
@Cmd()
|
||||||
|
msme(sender: any, command: string, args: string[]) {
|
||||||
|
this.logger.log(sender, command, args)
|
||||||
|
sender.sendMessage(JSON.stringify({ command, ...args }))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Tab()
|
||||||
|
tabmsme(_sender: any, _command: string, _args: string[]) {
|
||||||
|
return ['world']
|
||||||
|
}
|
||||||
|
}
|
||||||
48
packages/plugins/src/MiaoAuth.ts
Normal file
48
packages/plugins/src/MiaoAuth.ts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/// <reference types="@javatypes/bungee-api" />
|
||||||
|
/// <reference types="@javatypes/bukkit-api" />
|
||||||
|
/// <reference types="@javatypes/sponge-api" />
|
||||||
|
|
||||||
|
import { plugin, server } from '@ccms/api'
|
||||||
|
import { Autowired } from '@ccms/container'
|
||||||
|
import { Cmd, interfaces, JSPlugin, Tab } from '@ccms/plugin'
|
||||||
|
|
||||||
|
import type { MiaoReward } from './MiaoReward'
|
||||||
|
import * as fs from '@ccms/common/dist/fs'
|
||||||
|
|
||||||
|
@JSPlugin({ version: '1.0.0', author: 'MiaoWoo', source: __filename, depends: ['MiaoReward'] })
|
||||||
|
export class MiaoAuth extends interfaces.Plugin {
|
||||||
|
@Autowired()
|
||||||
|
private Server: server.Server
|
||||||
|
@Autowired()
|
||||||
|
private pluginManager: plugin.PluginManager
|
||||||
|
|
||||||
|
private MiaoReward: MiaoReward
|
||||||
|
|
||||||
|
load() {
|
||||||
|
}
|
||||||
|
|
||||||
|
enable() {
|
||||||
|
this.MiaoReward = this.pluginManager.getPlugin('MiaoReward') as MiaoReward
|
||||||
|
if (!this.MiaoReward) { return this.logger.error('当前脚本插件需要 MiaoReward 作为前置插件!') }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
disable() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Cmd({ autoMain: true })
|
||||||
|
msma() { }
|
||||||
|
|
||||||
|
cmdbind(sender: org.bukkit.entity.Player) {
|
||||||
|
if (!sender.getItemInHand) { return this.logger.sender(sender, '§4控制台无法执行此命令!') }
|
||||||
|
if (!this.MiaoReward.serverInfo) { return this.logger.sender(sender, '§4当前服务器尚未配置 请联系管理员配置MiaoReward!') }
|
||||||
|
this.MiaoReward.scanAuth(sender, 'bind', { title: '账号绑定', content: '是否绑定' }, (token, user) => {
|
||||||
|
|
||||||
|
}, () => {
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
@Tab()
|
||||||
|
tabmsma() { }
|
||||||
|
}
|
||||||
@@ -50,7 +50,7 @@ class MiaoMessage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@plugin({ name: 'MiaoChat', version: '1.0.0', author: 'MiaoWoo', source: __filename })
|
@plugin({ version: '1.1.0', author: 'MiaoWoo', nativeDepends: ['PlaceholderAPI'], source: __filename })
|
||||||
export class MiaoChat extends interfaces.Plugin {
|
export class MiaoChat extends interfaces.Plugin {
|
||||||
@Autowired()
|
@Autowired()
|
||||||
private Server: server.Server
|
private Server: server.Server
|
||||||
@@ -170,11 +170,6 @@ export class MiaoChat extends interfaces.Plugin {
|
|||||||
return string
|
return string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!this.chat) {
|
|
||||||
this.logger.console('§4消息管理器注入失败 请检查当前服务器是否兼容...')
|
|
||||||
this.AsyncPlayerChatEvent['off']()
|
|
||||||
this.MessageChannelEvent$Chat['off']()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
disable() {
|
disable() {
|
||||||
@@ -182,6 +177,10 @@ export class MiaoChat extends interfaces.Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bukkitenable() {
|
bukkitenable() {
|
||||||
|
if (!this.chat) {
|
||||||
|
this.logger.console('§4消息管理器注入失败 请检查当前服务器是否兼容...')
|
||||||
|
this.AsyncPlayerChatEvent['off']()
|
||||||
|
}
|
||||||
// 尝试加载 Bukkit 的 PlaceholderAPI
|
// 尝试加载 Bukkit 的 PlaceholderAPI
|
||||||
try {
|
try {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
@@ -193,6 +192,10 @@ export class MiaoChat extends interfaces.Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
spongeenable() {
|
spongeenable() {
|
||||||
|
if (!this.chat) {
|
||||||
|
this.logger.console('§4消息管理器注入失败 请检查当前服务器是否兼容...')
|
||||||
|
this.MessageChannelEvent$Chat['off']()
|
||||||
|
}
|
||||||
// 尝试加载 Sponge 的 PlaceholderAPI
|
// 尝试加载 Sponge 的 PlaceholderAPI
|
||||||
try {
|
try {
|
||||||
var spongePapi = this.Server.getService('me.rojo8399.placeholderapi.PlaceholderService')
|
var spongePapi = this.Server.getService('me.rojo8399.placeholderapi.PlaceholderService')
|
||||||
|
|||||||
109
packages/plugins/src/MiaoChatRGBSupport.ts
Normal file
109
packages/plugins/src/MiaoChatRGBSupport.ts
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
import { task, server, constants } from "@ccms/api"
|
||||||
|
import { Autowired, JSClass } from "@ccms/container"
|
||||||
|
import { interfaces, JSPlugin } from "@ccms/plugin"
|
||||||
|
|
||||||
|
let createPacketAdapterFunction = eval(`
|
||||||
|
function(cls, plugin, type, onPacketSending){
|
||||||
|
return new cls(plugin, type) {
|
||||||
|
onPacketSending: onPacketSending
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
const ChatColor = Java.type('net.md_5.bungee.api.ChatColor')
|
||||||
|
const Pattern = Java.type('java.util.regex.Pattern')
|
||||||
|
|
||||||
|
@JSPlugin({ prefix: 'MCRS', version: '1.0.0', author: 'MiaoWoo', servers: [constants.ServerType.Bukkit], nativeDepends: ['ProtocolLib'], source: __filename })
|
||||||
|
export class MiaoChatRGBSupport extends interfaces.Plugin {
|
||||||
|
private supportRGB: boolean = false
|
||||||
|
// 用于匹配 '#FFFFFF' 颜色格式
|
||||||
|
private RGBCOLOR_PATTERN = Pattern.compile("(#[a-fA-F0-9]{6}?)([^#?]*)");
|
||||||
|
|
||||||
|
@JSClass('com.comphenix.protocol.events.PacketAdapter')
|
||||||
|
private PacketAdapter: any
|
||||||
|
@JSClass('com.comphenix.protocol.PacketType')
|
||||||
|
private PacketType: any
|
||||||
|
@JSClass('com.comphenix.protocol.ProtocolLibrary')
|
||||||
|
private ProtocolLibrary: any
|
||||||
|
|
||||||
|
private adapter: any
|
||||||
|
|
||||||
|
load() {
|
||||||
|
try {
|
||||||
|
ChatColor.of('#FFFFFF').toString()
|
||||||
|
this.supportRGB = true
|
||||||
|
this.logger.console('§a检测到兼容RGB的服务端 已启动相关支持...')
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.console('§c当前服务端不支持RGB色彩 Error: ' + error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enable() {
|
||||||
|
if (this.supportRGB) {
|
||||||
|
this.initPacketAdapter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
disable() {
|
||||||
|
if (this.supportRGB) {
|
||||||
|
this.ProtocolLibrary.getProtocolManager().removePacketListener(this.adapter)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
createPacketAdapter(onPacketSending: (event) => void) {
|
||||||
|
return createPacketAdapterFunction(this.PacketAdapter, base.getInstance(), [this.PacketType.Play.Server.CHAT], onPacketSending)
|
||||||
|
}
|
||||||
|
|
||||||
|
colorJson(jsonObj) {
|
||||||
|
if (jsonObj.extra && jsonObj.extra.length) {
|
||||||
|
for (const extra of jsonObj.extra) {
|
||||||
|
this.colorJson(extra)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let text: string = jsonObj.text
|
||||||
|
var matcher = this.RGBCOLOR_PATTERN.matcher(text)
|
||||||
|
let colors = []
|
||||||
|
let texts = []
|
||||||
|
let lastStart = 0
|
||||||
|
while (matcher.find()) {
|
||||||
|
if (lastStart == 0) {
|
||||||
|
texts.push(text.substr(lastStart, matcher.start()))
|
||||||
|
lastStart = matcher.end()
|
||||||
|
}
|
||||||
|
colors.push(matcher.group(1))
|
||||||
|
texts.push(matcher.group(2))
|
||||||
|
}
|
||||||
|
if (colors.length) {
|
||||||
|
jsonObj.text = ''
|
||||||
|
let extras = []
|
||||||
|
let firstText = texts.shift()
|
||||||
|
if (firstText) { extras.push({ text: firstText }) }
|
||||||
|
texts.forEach((value, index) => {
|
||||||
|
extras.push({
|
||||||
|
text: value,
|
||||||
|
color: colors[index]
|
||||||
|
})
|
||||||
|
})
|
||||||
|
if (jsonObj.extra) {
|
||||||
|
jsonObj.extra = extras.concat(jsonObj.extra)
|
||||||
|
} else {
|
||||||
|
jsonObj.extra = extras
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return jsonObj
|
||||||
|
}
|
||||||
|
|
||||||
|
initPacketAdapter() {
|
||||||
|
this.adapter = this.createPacketAdapter((event) => {
|
||||||
|
try {
|
||||||
|
if (!event.getPlayer().hasPermission('MiaoChatRGBSupport.color')) { return }
|
||||||
|
let wcc = event.getPacket().getChatComponents().read(0)
|
||||||
|
if (wcc == null) { return }
|
||||||
|
wcc.setJson(JSON.stringify(this.colorJson(JSON.parse(wcc.getJson()))))
|
||||||
|
event.getPacket().getChatComponents().writeSafely(0, wcc)
|
||||||
|
} catch (error) {
|
||||||
|
console.ex(error)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
this.ProtocolLibrary.getProtocolManager().addPacketListener(this.adapter)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
/// <reference types="@ccms/nashorn" />
|
/// <reference types="@ccms/nashorn" />
|
||||||
|
|
||||||
import { plugin as pluginApi, server, task, constants, command } from '@ccms/api'
|
import { plugin as pluginApi, server, task, constants, command } from '@ccms/api'
|
||||||
import { plugin, interfaces, cmd, tab, enable, config, disable } from '@ccms/plugin'
|
import { plugin, interfaces, cmd, tab, enable, config, disable, PluginConfig } from '@ccms/plugin'
|
||||||
import { inject, ContainerInstance, Container } from '@ccms/container'
|
import { ContainerInstance, Container, Autowired } from '@ccms/container'
|
||||||
import io, { Server as SocketIOServer, Socket as SocketIOSocket } from '@ccms/websocket'
|
import io, { Server as SocketIOServer, Socket as SocketIOSocket } from '@ccms/websocket'
|
||||||
import * as fs from '@ccms/common/dist/fs'
|
import * as fs from '@ccms/common/dist/fs'
|
||||||
import * as reflect from '@ccms/common/dist/reflect'
|
import * as reflect from '@ccms/common/dist/reflect'
|
||||||
@@ -19,22 +19,22 @@ let help = [
|
|||||||
'§6/mconsole §areload §6- §3重载插件',
|
'§6/mconsole §areload §6- §3重载插件',
|
||||||
]
|
]
|
||||||
|
|
||||||
@plugin({ name: 'MiaoConsole', prefix: 'Console', version: '1.0.0', author: 'MiaoWoo', servers: ['!nukkit'], source: __filename })
|
@plugin({ prefix: 'Console', version: '1.1.1', author: 'MiaoWoo', servers: ['!nukkit'], source: __filename })
|
||||||
export class MiaoConsole extends interfaces.Plugin {
|
export class MiaoConsole extends interfaces.Plugin {
|
||||||
@inject(ContainerInstance)
|
@Autowired(ContainerInstance)
|
||||||
private container: Container
|
private container: Container
|
||||||
@inject(server.ServerType)
|
@Autowired(server.ServerType)
|
||||||
private serverType: string
|
private serverType: string
|
||||||
@inject(server.Server)
|
@Autowired(pluginApi.PluginFolder)
|
||||||
private server: server.Server
|
|
||||||
@inject(command.Command)
|
|
||||||
private command: command.Command
|
|
||||||
@inject(task.TaskManager)
|
|
||||||
private task: task.TaskManager
|
|
||||||
@inject(pluginApi.PluginManager)
|
|
||||||
private pluginManager: pluginApi.PluginManager
|
|
||||||
@inject(pluginApi.PluginFolder)
|
|
||||||
private pluginFolder: string
|
private pluginFolder: string
|
||||||
|
@Autowired()
|
||||||
|
private server: server.Server
|
||||||
|
@Autowired()
|
||||||
|
private command: command.Command
|
||||||
|
@Autowired()
|
||||||
|
private task: task.TaskManager
|
||||||
|
@Autowired()
|
||||||
|
private pluginManager: pluginApi.PluginManager
|
||||||
|
|
||||||
private token: string
|
private token: string
|
||||||
private instance: any
|
private instance: any
|
||||||
@@ -42,11 +42,13 @@ export class MiaoConsole extends interfaces.Plugin {
|
|||||||
private rootLogger: any
|
private rootLogger: any
|
||||||
private appender: any
|
private appender: any
|
||||||
private handler: any
|
private handler: any
|
||||||
|
private babel: any
|
||||||
|
private downgrade = true
|
||||||
|
|
||||||
private logCache: string[] = []
|
private logCache: string[] = []
|
||||||
|
|
||||||
@config()
|
@config()
|
||||||
private secret = { token: undefined }
|
private secret: PluginConfig = { token: undefined }
|
||||||
|
|
||||||
load() {
|
load() {
|
||||||
if (this.secret.token) {
|
if (this.secret.token) {
|
||||||
@@ -58,10 +60,25 @@ export class MiaoConsole extends interfaces.Plugin {
|
|||||||
}
|
}
|
||||||
process.on('message', (msg) => {
|
process.on('message', (msg) => {
|
||||||
this.logCache.push(msg)
|
this.logCache.push(msg)
|
||||||
if (this.logCache.length > 30) {
|
if (this.logCache.length > 100) {
|
||||||
this.logCache = this.logCache.slice(this.logCache.length - 30, this.logCache.length)
|
this.logCache = this.logCache.slice(this.logCache.length - 100, this.logCache.length)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
this.task.create(() => {
|
||||||
|
if (!this.babel) {
|
||||||
|
try {
|
||||||
|
this.logger.console('§3脚本 Babel 引擎初始化中 请稍候...')
|
||||||
|
let startTime = Date.now()
|
||||||
|
this.babel = require('@babel/standalone')
|
||||||
|
this.compileCode(`() => console.log("Babel ready!")`)
|
||||||
|
this.logger.console(`§3脚本 Babel 引擎初始化完毕 耗时 §a${Date.now() - startTime}ms...`)
|
||||||
|
this.downgrade = false
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.console(`§c脚本 Babel 引擎初始化失败 将无法使用ES5以上语法!`)
|
||||||
|
console.ex(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).async().submit()
|
||||||
}
|
}
|
||||||
|
|
||||||
@cmd()
|
@cmd()
|
||||||
@@ -81,8 +98,6 @@ export class MiaoConsole extends interfaces.Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmdreload(sender: any) {
|
cmdreload(sender: any) {
|
||||||
// @ts-ignore
|
|
||||||
require.clear('websocket')
|
|
||||||
this.pluginManager.reload(this)
|
this.pluginManager.reload(this)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -90,6 +105,7 @@ export class MiaoConsole extends interfaces.Plugin {
|
|||||||
cmdtoken(sender: any, sub: string, token: string) {
|
cmdtoken(sender: any, sub: string, token: string) {
|
||||||
if (sub == "set") {
|
if (sub == "set") {
|
||||||
this.secret.token = this.token = token
|
this.secret.token = this.token = token
|
||||||
|
this.secret.save()
|
||||||
this.logger.sender(sender, '§a已保存§6服务器登录Token:§3', this.token, '§4请勿分享给其他人 防止服务器被攻击!')
|
this.logger.sender(sender, '§a已保存§6服务器登录Token:§3', this.token, '§4请勿分享给其他人 防止服务器被攻击!')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -185,8 +201,8 @@ export class MiaoConsole extends interfaces.Plugin {
|
|||||||
@disable({ servers: [constants.ServerType.Bukkit, constants.ServerType.Sponge] })
|
@disable({ servers: [constants.ServerType.Bukkit, constants.ServerType.Sponge] })
|
||||||
removeLog4jForward() {
|
removeLog4jForward() {
|
||||||
try {
|
try {
|
||||||
this.appender.stop()
|
this.appender?.stop()
|
||||||
this.rootLogger.removeAppender(this.appender)
|
this.rootLogger?.removeAppender(this.appender)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.ex(error)
|
console.ex(error)
|
||||||
}
|
}
|
||||||
@@ -195,7 +211,7 @@ export class MiaoConsole extends interfaces.Plugin {
|
|||||||
@disable({ servers: [constants.ServerType.Bungee] })
|
@disable({ servers: [constants.ServerType.Bungee] })
|
||||||
removeLoggerForward() {
|
removeLoggerForward() {
|
||||||
try {
|
try {
|
||||||
this.rootLogger.removeHandler(this.handler)
|
this.rootLogger?.removeHandler(this.handler)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.ex(error)
|
console.ex(error)
|
||||||
}
|
}
|
||||||
@@ -204,7 +220,7 @@ export class MiaoConsole extends interfaces.Plugin {
|
|||||||
@disable({ servers: [constants.ServerType.Spring] })
|
@disable({ servers: [constants.ServerType.Spring] })
|
||||||
removeLogbackForward() {
|
removeLogbackForward() {
|
||||||
try {
|
try {
|
||||||
this.rootLogger.detachAppender(this.LOGBACK_APPENDER_NAME)
|
this.rootLogger?.detachAppender(this.LOGBACK_APPENDER_NAME)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.ex(error)
|
console.ex(error)
|
||||||
}
|
}
|
||||||
@@ -216,28 +232,28 @@ export class MiaoConsole extends interfaces.Plugin {
|
|||||||
root: fs.concat(root, 'wwwroot')
|
root: fs.concat(root, 'wwwroot')
|
||||||
})
|
})
|
||||||
this.container.bind(io.Instance).toConstantValue(this.socketIOServer)
|
this.container.bind(io.Instance).toConstantValue(this.socketIOServer)
|
||||||
|
process.emit('websocket.create', this.socketIOServer)
|
||||||
}
|
}
|
||||||
|
|
||||||
startSocketIOServer() {
|
startSocketIOServer() {
|
||||||
let namespace = this.socketIOServer.of('/MiaoConsole')
|
let namespace = this.socketIOServer.of('/MiaoConsole')
|
||||||
process.on('message', (msg) => namespace.emit('log', msg))
|
process.on('message', (msg) => namespace.emit('log', msg))
|
||||||
namespace.on('connect', (client: SocketIOSocket) => {
|
namespace.on('connection', (client: SocketIOSocket) => {
|
||||||
if (!this.token) {
|
if (!this.token) {
|
||||||
this.logger.console(`§6客户端 §b${client.id} §a请求连接 §4服务器尚未设置 Token 无法连接!`)
|
this.logger.console(`§6客户端 §b${client.id} §a请求连接 §4服务器尚未设置 Token 无法连接!`)
|
||||||
client.emit('unauthorized')
|
client.emit('unauthorized', () => client.disconnect(true))
|
||||||
client.disconnect(true)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (this.token != client.handshake.query.token) {
|
if (this.token != client.handshake.query.token) {
|
||||||
this.logger.console(`§6客户端 §b${client.id} §c无效请求 §4请提供正确Token后再次连接!`)
|
this.logger.console(`§6客户端 §b${client.id} §c无效请求 §4请提供正确Token后再次连接!`)
|
||||||
client.emit('unauthorized')
|
client.emit('unauthorized', () => client.disconnect(true))
|
||||||
client.disconnect(true)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.initWebSocketClient(client)
|
this.initWebSocketClient(client)
|
||||||
this.logCache.forEach(msg => client.emit('log', msg))
|
this.logCache.forEach(msg => client.emit('log', msg))
|
||||||
this.logger.console(`§6客户端 §b${client.id} §a新建连接 ${this.rootLogger ? '启动日志转发' : '§4转发日志启动失败'}...`)
|
this.logger.console(`§6客户端 §b${client.id} §a新建连接 ${this.rootLogger ? '启动日志转发' : '§4转发日志启动失败'}...`)
|
||||||
})
|
})
|
||||||
|
process.emit('websocket.start', this.socketIOServer)
|
||||||
}
|
}
|
||||||
|
|
||||||
private initWebSocketClient(client: SocketIOSocket) {
|
private initWebSocketClient(client: SocketIOSocket) {
|
||||||
@@ -246,14 +262,23 @@ export class MiaoConsole extends interfaces.Plugin {
|
|||||||
client.emit('log', `Currect Server Version is ${this.server.getVersion()}`)
|
client.emit('log', `Currect Server Version is ${this.server.getVersion()}`)
|
||||||
})
|
})
|
||||||
client.on('command', (cmd) => {
|
client.on('command', (cmd) => {
|
||||||
setTimeout(() => this.server.dispatchConsoleCommand(cmd), 0)
|
this.task.callSyncMethod(() => this.server.dispatchConsoleCommand(cmd))
|
||||||
client.emit('log', `§6命令: §b${cmd} §a执行成功!`)
|
client.emit('log', `§6命令: §b${cmd} §a执行成功!`)
|
||||||
})
|
})
|
||||||
client.on('tabComplate', (input, index, callback) => {
|
client.on('tabComplate', (input, index, callback) => {
|
||||||
callback?.(this.command.tabComplete(this.server.getConsoleSender(), input, index))
|
try {
|
||||||
|
callback?.(this.command.tabComplete(this.server.getConsoleSender(), input, index) || [])
|
||||||
|
} catch (error) {
|
||||||
|
callback?.([])
|
||||||
|
client.emit('log', `§4命令补全发生异常: ${error}!`)
|
||||||
|
console.ex(error)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
client.on('exec', (code) => {
|
client.on('exec', (code) => {
|
||||||
try {
|
try {
|
||||||
|
if (!this.babel) {
|
||||||
|
return client.emit('log', '§cBabel 引擎初始化中 请稍候再试!')
|
||||||
|
}
|
||||||
client.emit('log', this.runCode(code, client.nsp, client))
|
client.emit('log', this.runCode(code, client.nsp, client))
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
client.emit('log', `§4代码执行异常 错误: ${ex}\n${console.stack(ex).join('\n')}`)
|
client.emit('log', `§4代码执行异常 错误: ${ex}\n${console.stack(ex).join('\n')}`)
|
||||||
@@ -280,7 +305,7 @@ export class MiaoConsole extends interfaces.Plugin {
|
|||||||
if (!dir.isDirectory()) {
|
if (!dir.isDirectory()) {
|
||||||
return fn(undefined, `${file} 不是一个目录!`)
|
return fn(undefined, `${file} 不是一个目录!`)
|
||||||
}
|
}
|
||||||
fn(fs.list(dir))
|
fn(fs.list(dir).map(f => f.name))
|
||||||
})
|
})
|
||||||
client.on('error', (error) => {
|
client.on('error', (error) => {
|
||||||
this.logger.console(`§6客户端 §b${client.id} §c触发异常: ${error}`)
|
this.logger.console(`§6客户端 §b${client.id} §c触发异常: ${error}`)
|
||||||
@@ -306,15 +331,33 @@ export class MiaoConsole extends interfaces.Plugin {
|
|||||||
this.container,
|
this.container,
|
||||||
this.pluginManager
|
this.pluginManager
|
||||||
]
|
]
|
||||||
let tfunc = new Function(
|
client.emit('log', '§3代码编译中 请稍候...')
|
||||||
...paramNames,
|
let startTime = Date.now()
|
||||||
`var api = require('@ccms/api');
|
let tfunc = new Function(...paramNames, this.compileCode(code))
|
||||||
|
client.emit('log', `§3代码编译完成 耗时 §e${Date.now() - startTime}ms §b开始执行 请稍候...`)
|
||||||
|
return tfunc.apply(this, params) + ''
|
||||||
|
}
|
||||||
|
|
||||||
|
private compileCode(code: string) {
|
||||||
|
if (!this.downgrade && this.babel?.transform) {
|
||||||
|
code = this.babel.transform(code, {
|
||||||
|
filename: 'miaoconsole-temp.ts',
|
||||||
|
presets: ['typescript', 'es2015'],
|
||||||
|
plugins: [
|
||||||
|
['proposal-decorators', { legacy: true }],
|
||||||
|
'transform-runtime'
|
||||||
|
],
|
||||||
|
sourceMaps: "inline"
|
||||||
|
}).code
|
||||||
|
}
|
||||||
|
return `var api = require('@ccms/api');
|
||||||
if (this.serverType == "spring") {
|
if (this.serverType == "spring") {
|
||||||
var dbm = container.get(api.database.DataBaseManager)
|
var dbm = container.get(api.database.DataBaseManager)
|
||||||
var db = dbm.getMainDatabase()
|
var db = dbm.getMainDatabase()
|
||||||
var bf = base.getInstance().getAutowireCapableBeanFactory()
|
var bf = base.getInstance().getAutowireCapableBeanFactory()
|
||||||
}
|
}
|
||||||
return '§a返回结果: §r'+ eval(${JSON.stringify(code)});`)
|
var startTime = Date.now()
|
||||||
return this.task.callSyncMethod(() => tfunc.apply(this, params)) + ''
|
var result = eval(${JSON.stringify(code)});
|
||||||
|
return '§3代码执行完成 耗时 §e' + (Date.now() - startTime) + 'ms §a返回结果: §r'+ result`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
175
packages/plugins/src/MiaoExplorer.ts
Normal file
175
packages/plugins/src/MiaoExplorer.ts
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
/// <reference types="@javatypes/bungee-api" />
|
||||||
|
/// <reference types="@javatypes/bukkit-api" />
|
||||||
|
/// <reference types="@javatypes/sponge-api" />
|
||||||
|
|
||||||
|
import { plugin, server } from '@ccms/api'
|
||||||
|
import { Autowired } from '@ccms/container'
|
||||||
|
import { Cmd, interfaces, JSPlugin, Tab } from '@ccms/plugin'
|
||||||
|
import { Server as SocketIOServer, Socket as SocketIOSocket, Namespace } from '@ccms/websocket'
|
||||||
|
|
||||||
|
import * as fs from '@ccms/common/dist/fs'
|
||||||
|
|
||||||
|
const FileFilter = Java.type('java.io.FileFilter')
|
||||||
|
const ByteArrayInputStream = java.io.ByteArrayInputStream
|
||||||
|
const ByteArrayOutputStream = java.io.ByteArrayOutputStream
|
||||||
|
const StandardCharsets = Java.type("java.nio.charset.StandardCharsets")
|
||||||
|
const GZIPInputStream = Java.type('java.util.zip.GZIPInputStream')
|
||||||
|
const ByteArray = Java.type("byte[]")
|
||||||
|
|
||||||
|
@JSPlugin({ prefix: 'Explorer', version: '1.0.0', author: 'MiaoWoo', source: __filename })
|
||||||
|
export class MiaoExplorer extends interfaces.Plugin {
|
||||||
|
@Autowired()
|
||||||
|
private Server: server.Server
|
||||||
|
@Autowired()
|
||||||
|
private pluginManager: plugin.PluginManager
|
||||||
|
|
||||||
|
private token: string
|
||||||
|
private namespace: any
|
||||||
|
private chunkCacheMap: Map<string, Array<string>>
|
||||||
|
|
||||||
|
load() {
|
||||||
|
this.chunkCacheMap = new Map()
|
||||||
|
}
|
||||||
|
|
||||||
|
enable() {
|
||||||
|
let consolePlugin: any = this.pluginManager.getPlugin('MiaoConsole')
|
||||||
|
if (consolePlugin.socketIOServer) {
|
||||||
|
this.startWebSocketServer(consolePlugin.socketIOServer)
|
||||||
|
} else {
|
||||||
|
process.on('websocket.create', (server: SocketIOServer) => {
|
||||||
|
this.startWebSocketServer(server)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private startWebSocketServer(server: SocketIOServer) {
|
||||||
|
let consolePlugin: any = this.pluginManager.getPlugin('MiaoConsole')
|
||||||
|
this.token = consolePlugin.token
|
||||||
|
this.namespace = server.of('/MiaoExplorer')
|
||||||
|
this.namespace.on('connection', (client: SocketIOSocket) => {
|
||||||
|
if (!this.token) {
|
||||||
|
this.logger.console(`§6客户端 §b${client.id} §a请求连接 §4服务器尚未设置 Token 无法连接!`)
|
||||||
|
client.emit('unauthorized', () => client.disconnect(true))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (this.token != client.handshake.query.token) {
|
||||||
|
this.logger.console(`§6客户端 §b${client.id} §c无效请求 §4请提供正确Token后再次连接!`)
|
||||||
|
client.emit('unauthorized', () => client.disconnect(true))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.initWebSocketClient(client)
|
||||||
|
this.logger.console(`§6客户端 §b${client.id} §a新建连接...`)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
disable() {
|
||||||
|
this.namespace.removeAllListeners('connect')
|
||||||
|
this.namespace.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
private readDir(dir) {
|
||||||
|
let children = Java.from(dir.listFiles(new FileFilter({
|
||||||
|
accept: file => file.getName().endsWith('.yml') || file.getName().endsWith('.js') || file.isDirectory()
|
||||||
|
}))).sort().map(file => {
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
let children = this.readDir(file)
|
||||||
|
if (!children.length) { return null }
|
||||||
|
return {
|
||||||
|
label: file.getName(),
|
||||||
|
value: fs.path(file),
|
||||||
|
children,
|
||||||
|
disabled: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
label: file.getName(),
|
||||||
|
value: fs.path(file),
|
||||||
|
creatable: true,
|
||||||
|
editable: true,
|
||||||
|
removable: true,
|
||||||
|
deleteApi: "delete"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return children.filter(s => s)
|
||||||
|
}
|
||||||
|
|
||||||
|
private initWebSocketClient(client: SocketIOSocket) {
|
||||||
|
client.on('ls', (fn) => {
|
||||||
|
var pluginDirs = Java.from(fs.file('./plugins').listFiles(new FileFilter({
|
||||||
|
accept: dirs => dirs.isDirectory()
|
||||||
|
})))
|
||||||
|
let result = {
|
||||||
|
options: pluginDirs.sort().map(f => {
|
||||||
|
let node: any = {
|
||||||
|
label: f.getName(),
|
||||||
|
value: fs.path(f)
|
||||||
|
}
|
||||||
|
let children = this.readDir(f)
|
||||||
|
if (!children.length) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
node.children = children
|
||||||
|
node.disabled = true
|
||||||
|
return node
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fn && fn(result.options.filter(s => s))
|
||||||
|
})
|
||||||
|
client.on('read', (file, callback) => {
|
||||||
|
callback?.(base.read(file))
|
||||||
|
})
|
||||||
|
client.on('chunk', (file, index, content, callback) => {
|
||||||
|
if (!this.chunkCacheMap.has(file)) {
|
||||||
|
this.chunkCacheMap.set(file, [])
|
||||||
|
}
|
||||||
|
this.chunkCacheMap.get(file)[index] = content
|
||||||
|
callback?.(true)
|
||||||
|
})
|
||||||
|
client.on('ungzip', (content) => {
|
||||||
|
try {
|
||||||
|
console.log(content)
|
||||||
|
let baos = new ByteArrayOutputStream()
|
||||||
|
let byte = java.util.Base64.getDecoder().decode(content)
|
||||||
|
let gzip = new GZIPInputStream(new ByteArrayInputStream(byte))
|
||||||
|
let buffer = new ByteArray(1024)
|
||||||
|
let n: number
|
||||||
|
while ((n = gzip.read(buffer)) != -1) {
|
||||||
|
baos.write(buffer, 0, n)
|
||||||
|
}
|
||||||
|
gzip.close()
|
||||||
|
baos.close()
|
||||||
|
content = baos.toString(StandardCharsets.UTF_8.name())
|
||||||
|
this.logger.log(content)
|
||||||
|
} catch (error) {
|
||||||
|
console.ex(error)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
client.on('save', (file, callback) => {
|
||||||
|
if (!this.chunkCacheMap.has(file)) {
|
||||||
|
return callback?.(false)
|
||||||
|
}
|
||||||
|
let content = this.chunkCacheMap.get(file).join('')
|
||||||
|
this.chunkCacheMap.delete(file)
|
||||||
|
base.save(file, content)
|
||||||
|
callback?.(true)
|
||||||
|
})
|
||||||
|
client.on('error', (error) => {
|
||||||
|
this.logger.console(`§6客户端 §b${client.id} §c触发异常: ${error}`)
|
||||||
|
this.logger.error(error)
|
||||||
|
})
|
||||||
|
client.on('disconnect', () => {
|
||||||
|
this.logger.console(`§6客户端 §b${client.id} §c断开连接...`)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
@Cmd()
|
||||||
|
msme(sender: any, command: string, args: string[]) {
|
||||||
|
this.logger.log(sender, command, args)
|
||||||
|
sender.sendMessage(JSON.stringify({ command, ...args }))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Tab()
|
||||||
|
tabmsme(_sender: any, _command: string, _args: string[]) {
|
||||||
|
return ['world']
|
||||||
|
}
|
||||||
|
}
|
||||||
36
packages/plugins/src/MiaoParticle.ts
Normal file
36
packages/plugins/src/MiaoParticle.ts
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/// <reference types="@javatypes/bungee-api" />
|
||||||
|
/// <reference types="@javatypes/bukkit-api" />
|
||||||
|
/// <reference types="@javatypes/sponge-api" />
|
||||||
|
|
||||||
|
import { particle } from '@ccms/api'
|
||||||
|
import { Autowired } from '@ccms/container'
|
||||||
|
import { Cmd, JSPlugin, Tab, interfaces } from '@ccms/plugin'
|
||||||
|
|
||||||
|
@JSPlugin({ version: '1.0.0', author: 'MiaoWoo', source: __filename })
|
||||||
|
export class MiaoParticle extends interfaces.Plugin {
|
||||||
|
@Autowired()
|
||||||
|
private particleManager: particle.ParticleManager
|
||||||
|
|
||||||
|
private particleTask: particle.ParticleTask
|
||||||
|
|
||||||
|
enable() {
|
||||||
|
// let boot = new Bootstrap()
|
||||||
|
this.particleTask = this.particleManager.create(new particle.Circle(2, 20).setParticle(org.bukkit.Particle.BLOCK_DUST), this)
|
||||||
|
}
|
||||||
|
|
||||||
|
diable() {
|
||||||
|
this.particleTask.cancel()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Cmd({ autoMain: true })
|
||||||
|
mpt() { }
|
||||||
|
|
||||||
|
cmdtest(sender: org.bukkit.entity.Player) {
|
||||||
|
this.particleTask.follow(sender).async(true).timer(5).submit()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Tab()
|
||||||
|
tabmpt(_sender: any, _command: string, _args: string[]) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user