Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6dcc56b0e5 | |||
| 6f8ea8290b | |||
| 1f574695a1 | |||
| 090c0b2668 | |||
| db8f2d9bc2 | |||
| e02f673c82 | |||
| 47c85f70eb | |||
| da9e2063ca | |||
| 0568a7abbe | |||
| 7375e8e2e9 | |||
| 41d3923d94 | |||
| f111b9891c | |||
| 2e4fdcb798 | |||
| ab7ca932a3 | |||
| e8b3d43cdf | |||
| eaaa0ef139 | |||
| 94840ae59d | |||
| c31eaeb8f6 | |||
| 469a66a277 | |||
| cd6a2023dc | |||
| 498b0ee017 | |||
| 9bfaf984c1 | |||
| 3c33ebf4e6 | |||
| 8af69c98f3 | |||
| 72277f4d1a | |||
| d85f75ba1f | |||
| ed14d317f4 |
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.4",
|
||||
"version": "0.10.0",
|
||||
"useWorkspaces": true,
|
||||
"npmClient": "yarn",
|
||||
"packages": [
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/amqp",
|
||||
"version": "0.9.4",
|
||||
"version": "0.10.0",
|
||||
"description": "MiaoScript amqp package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,15 +19,15 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.9.4",
|
||||
"@ccms/common": "^0.9.4",
|
||||
"@ccms/container": "^0.9.4"
|
||||
"@ccms/api": "^0.10.0",
|
||||
"@ccms/common": "^0.10.0",
|
||||
"@ccms/container": "^0.10.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.9.4",
|
||||
"@javatypes/amqp-client": "^0.0.2",
|
||||
"@javatypes/spring-amqp": "^0.0.2",
|
||||
"@javatypes/spring-rabbit": "^0.0.2",
|
||||
"@ccms/nashorn": "^0.10.0",
|
||||
"@javatypes/amqp-client": "^0.0.3",
|
||||
"@javatypes/spring-amqp": "^0.0.3",
|
||||
"@javatypes/spring-rabbit": "^0.0.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.0.3"
|
||||
|
||||
@@ -2,7 +2,7 @@ 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')
|
||||
export const AcknowledgeMode = org.springframework.amqp.core.AcknowledgeMode
|
||||
interface ContainerConfig {
|
||||
connectionFactory: ConnectionFactoryAdapter | typeof ConnectionFactory
|
||||
queueNames: string[]
|
||||
@@ -27,4 +27,4 @@ export class MessageListenerContainerAdapter {
|
||||
getHandler() {
|
||||
return this._Handler
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ export class AmqpAdmin {
|
||||
}
|
||||
|
||||
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)
|
||||
return this
|
||||
}
|
||||
@@ -86,4 +86,4 @@ export class SimpleMessageHandler extends ChannelAwareMessageListenerAdapter {
|
||||
onMessage(content: any, message: org.springframework.amqp.core.Message, channel: com.rabbitmq.client.Channel) {
|
||||
return this.handler(content, message, channel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/api",
|
||||
"version": "0.9.4",
|
||||
"version": "0.10.0",
|
||||
"description": "MiaoScript api package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,9 +19,9 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/common": "^0.9.4",
|
||||
"@ccms/container": "^0.9.4",
|
||||
"@ccms/ployfill": "^0.9.4",
|
||||
"@ccms/common": "^0.10.0",
|
||||
"@ccms/container": "^0.10.0",
|
||||
"@ccms/ployfill": "^0.10.0",
|
||||
"base64-js": "^1.3.1",
|
||||
"source-map-builder": "^0.0.7"
|
||||
},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import i18n from '@ccms/i18n'
|
||||
import { injectable } from "@ccms/container"
|
||||
import { plugin } from './interfaces'
|
||||
import { plugin } from './plugin'
|
||||
|
||||
export namespace command {
|
||||
@injectable()
|
||||
@@ -13,7 +13,7 @@ export namespace command {
|
||||
*/
|
||||
on(plugin: plugin.Plugin, name: string, exec: { cmd: Function, tab?: Function }) {
|
||||
var cmd = this.create(plugin, name)
|
||||
if (!cmd) { throw Error("") }
|
||||
if (!cmd) { throw Error(`Plugin ${plugin.description.name} can't create Command ${name}!`) }
|
||||
console.debug(i18n.translate("ms.api.command.register", { plugin: plugin.description.name, name, cmd }))
|
||||
if (exec.cmd && typeof exec.cmd === "function") {
|
||||
this.onCommand(plugin, cmd, exec.cmd)
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
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 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']
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
import "@ccms/nashorn"
|
||||
|
||||
export * from './web'
|
||||
export * from './amqp'
|
||||
export * from './chat'
|
||||
export * from './task'
|
||||
export * from './event'
|
||||
export * from './proxy'
|
||||
export * from './plugin'
|
||||
export * from './server'
|
||||
export * from './console'
|
||||
export * from './channel'
|
||||
export * from './command'
|
||||
export * from './database'
|
||||
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;
|
||||
}
|
||||
@@ -78,7 +78,7 @@ export namespace plugin {
|
||||
scan(target: any): PluginLoadMetadata[]
|
||||
/**
|
||||
* 读取插件 返回插件加载元信息
|
||||
* @param target
|
||||
* @param target
|
||||
*/
|
||||
read(target: any): PluginLoadMetadata
|
||||
/**
|
||||
@@ -162,6 +162,14 @@ export namespace plugin {
|
||||
* 插件作者 不填默认为 Unknow
|
||||
*/
|
||||
author?: string | string[]
|
||||
/**
|
||||
* 脚本依赖
|
||||
*/
|
||||
depends?: string[]
|
||||
/**
|
||||
* 插件依赖
|
||||
*/
|
||||
nativeDepends?: string[]
|
||||
/**
|
||||
* 插件源文件 必须指定为 __filename
|
||||
*/
|
||||
@@ -1,4 +1,4 @@
|
||||
import { provideSingleton, Autowired } from '@ccms/container'
|
||||
import { provideSingleton, Autowired, optional } from '@ccms/container'
|
||||
import { channel } from './channel'
|
||||
|
||||
export namespace proxy {
|
||||
@@ -44,7 +44,7 @@ export namespace proxy {
|
||||
* Get a list of players connected on a certain server, or on ALL the servers.
|
||||
* @param server count server
|
||||
* Response:
|
||||
* String server = in.readUTF(); // The name of the server you got the player list of, as given in args.
|
||||
* String server = in.readUTF(); // The name of the server you got the player list of, as given in args.
|
||||
* String[] playerList = in.readUTF().split(", ");
|
||||
*/
|
||||
playerList(server: string | "ALL") {
|
||||
@@ -98,7 +98,7 @@ export namespace proxy {
|
||||
return this.forward("ALL", channel, data)
|
||||
}
|
||||
/**
|
||||
* Send a custom plugin message to said server. This is one of the most useful channels ever.
|
||||
* Send a custom plugin message to said server. This is one of the most useful channels ever.
|
||||
* Remember, the sending and receiving server(s) need to have a player online.
|
||||
* @param server reciver
|
||||
* @param channel channelName
|
||||
@@ -112,7 +112,7 @@ export namespace proxy {
|
||||
return this.finalSend()
|
||||
}
|
||||
/**
|
||||
* Send a custom plugin message to said server. This is one of the most useful channels ever.
|
||||
* Send a custom plugin message to said server. This is one of the most useful channels ever.
|
||||
* Remember, the sending and receiving server(s) need to have a player online.
|
||||
* @param server reciver
|
||||
* @param channel channelName
|
||||
@@ -147,6 +147,7 @@ export namespace proxy {
|
||||
}
|
||||
@provideSingleton(BungeeCord)
|
||||
export class BungeeCord {
|
||||
@optional()
|
||||
@Autowired()
|
||||
private channel: channel.Channel
|
||||
/**
|
||||
@@ -157,4 +158,4 @@ export namespace proxy {
|
||||
return new bungeecord.SubChannelBuilder(this.channel, player)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
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'
|
||||
|
||||
export { NativePluginManager } from './native_plugin'
|
||||
import { constants } from './constants'
|
||||
|
||||
export namespace server {
|
||||
/**
|
||||
@@ -19,6 +16,24 @@ export namespace server {
|
||||
* Runtime Server Instance
|
||||
*/
|
||||
export const ServerInstance = Symbol("ServerInstance")
|
||||
@injectable()
|
||||
export abstract class NativePluginManager {
|
||||
has(name: string): boolean {
|
||||
return true
|
||||
}
|
||||
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
|
||||
*/
|
||||
@@ -48,9 +63,6 @@ export namespace server {
|
||||
getPluginsFolder(): string {
|
||||
throw new Error("Method not implemented.")
|
||||
}
|
||||
getNativePluginManager(): NativePluginManager {
|
||||
throw new Error("Method not implemented.")
|
||||
}
|
||||
getDedicatedServer?(): any {
|
||||
throw new Error("Method not implemented.")
|
||||
}
|
||||
@@ -63,8 +75,9 @@ export namespace server {
|
||||
}
|
||||
@injectable()
|
||||
export class ServerChecker {
|
||||
@inject(ServerType)
|
||||
@Autowired(ServerType)
|
||||
private serverType: string
|
||||
|
||||
check(servers: string[]) {
|
||||
// Not set servers -> allow
|
||||
if (!servers || !servers.length) return true
|
||||
@@ -80,14 +93,17 @@ export namespace server {
|
||||
}
|
||||
@injectable()
|
||||
export abstract class ReflectServer extends server.Server {
|
||||
@Autowired(ContainerInstance)
|
||||
private container: Container
|
||||
|
||||
protected pipeline: any
|
||||
protected rootLogger: any
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
this.reflect()
|
||||
}
|
||||
|
||||
@postConstruct()
|
||||
protected reflect() {
|
||||
try {
|
||||
let consoleServer = this.getDedicatedServer()
|
||||
@@ -107,7 +123,11 @@ export namespace server {
|
||||
if (connection.class.name.indexOf('ServerConnection') !== -1
|
||||
|| connection.class.name.indexOf('NetworkSystem') !== -1) { break }
|
||||
connection = undefined
|
||||
} catch (error) { }
|
||||
} catch (error) {
|
||||
if (global.debug) {
|
||||
console.ex(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!connection) { console.error("Can't found ServerConnection!"); return }
|
||||
for (const field of constants.Reflect.Field.listeningChannels) {
|
||||
@@ -115,16 +135,30 @@ export namespace server {
|
||||
promise = reflect.on(connection).get(field).get().get(0)
|
||||
if (promise.class.name.indexOf('Promise') !== -1) { break }
|
||||
promise = undefined
|
||||
} catch (error) { }
|
||||
} catch (error) {
|
||||
if (global.debug) {
|
||||
console.ex(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!promise) { console.error("Can't found listeningChannels!"); return }
|
||||
this.pipeline = reflect.on(promise).get('channel').get().pipeline()
|
||||
this.container.bind(constants.ServiceIdentifier.NettyPipeline).toConstantValue(this.pipeline)
|
||||
}
|
||||
protected reflectRootLogger(consoleServer: any) {
|
||||
try {
|
||||
this.rootLogger = reflect.on(consoleServer).get('LOGGER').get().parent
|
||||
} 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) {
|
||||
console.error('Error Logger Class: ' + this.rootLogger.class.name)
|
||||
@@ -135,6 +169,7 @@ export namespace server {
|
||||
this.rootLogger = this.rootLogger.parent
|
||||
}
|
||||
if (!this.rootLogger) { console.error("Can't found rootLogger!") }
|
||||
this.container.bind(constants.ServiceIdentifier.RootLogger).toConstantValue(this.rootLogger)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,6 @@ export namespace task {
|
||||
if (plugin) { return this.pluginCreate(plugin, task) }
|
||||
return task
|
||||
}
|
||||
abstract create0(func: Function): task.Task
|
||||
/**
|
||||
* 在主线程执行代码
|
||||
* @param func 执行内容
|
||||
@@ -42,7 +41,8 @@ export namespace task {
|
||||
if (plugin) { return this.pluginDisable(plugin) }
|
||||
this.disable0()
|
||||
}
|
||||
abstract disable0()
|
||||
protected abstract create0(func: Function): task.Task
|
||||
protected abstract disable0()
|
||||
}
|
||||
/**
|
||||
* 任务抽象
|
||||
@@ -116,7 +116,7 @@ export namespace task {
|
||||
* 提交任务
|
||||
* @param args 任务参数
|
||||
*/
|
||||
abstract submit0(...args: any[]): Cancelable
|
||||
protected abstract submit0(...args: any[]): Cancelable
|
||||
}
|
||||
/**
|
||||
* 返可取消的对象
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/bukkit",
|
||||
"version": "0.9.4",
|
||||
"version": "0.10.0",
|
||||
"description": "MiaoScript bukkit package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,14 +19,14 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@javatypes/spigot-api": "^0.0.2",
|
||||
"@javatypes/spigot-api": "^0.0.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.0.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.9.4",
|
||||
"@ccms/common": "^0.9.4",
|
||||
"@ccms/container": "^0.9.4"
|
||||
"@ccms/api": "^0.10.0",
|
||||
"@ccms/common": "^0.10.0",
|
||||
"@ccms/container": "^0.10.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,13 +16,13 @@ export class BukkitServer extends server.ReflectServer {
|
||||
}
|
||||
|
||||
getPlayer(name: string) {
|
||||
return Bukkit.getPlayer(name)
|
||||
return Bukkit.getPlayerExact(name)
|
||||
}
|
||||
getVersion(): string {
|
||||
return Bukkit.getVersion()
|
||||
}
|
||||
getOnlinePlayers() {
|
||||
return Bukkit.getOnlinePlayers() as unknown as any[]
|
||||
return Bukkit.getOnlinePlayers()
|
||||
}
|
||||
getConsoleSender() {
|
||||
return Bukkit.getConsoleSender()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/bungee",
|
||||
"version": "0.9.4",
|
||||
"version": "0.10.0",
|
||||
"description": "MiaoScript bungee package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,14 +19,14 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@javatypes/bungee-api": "^0.0.2",
|
||||
"@javatypes/bungee-api": "^0.0.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.0.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.9.4",
|
||||
"@ccms/common": "^0.9.4",
|
||||
"@ccms/container": "^0.9.4"
|
||||
"@ccms/api": "^0.10.0",
|
||||
"@ccms/common": "^0.10.0",
|
||||
"@ccms/container": "^0.10.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "@ccms/client",
|
||||
"version": "0.9.4",
|
||||
"version": "0.10.0",
|
||||
"description": "MiaoScript client package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/common",
|
||||
"version": "0.9.4",
|
||||
"version": "0.10.0",
|
||||
"description": "MiaoScript api package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,8 +19,8 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.9.4",
|
||||
"@javatypes/jdk": "^0.0.2",
|
||||
"@ccms/nashorn": "^0.10.0",
|
||||
"@javatypes/jdk": "^0.0.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.0.3"
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
/// <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.
|
||||
*/
|
||||
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 {
|
||||
private obj: java.lang.Object
|
||||
private class: java.lang.Class<any>
|
||||
@@ -34,15 +35,26 @@ class Reflect {
|
||||
return Java.from(declaredMethods(this.class))
|
||||
}
|
||||
|
||||
field(name: string | java.lang.String): Reflect {
|
||||
try {
|
||||
// Try getting a public field
|
||||
let field = this.class.getField(name)
|
||||
return on(field.get(this.obj))
|
||||
} catch (ex) {
|
||||
// Try again, getting a non-public field
|
||||
return on(accessible(declaredField(this.class, name)).get(this.obj))
|
||||
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 getting a public field
|
||||
field = this.class.getField(nameOrIndex)
|
||||
} catch (ex) {
|
||||
// Try again, getting a non-public field
|
||||
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[] {
|
||||
@@ -50,7 +62,7 @@ class Reflect {
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -64,17 +76,12 @@ class Reflect {
|
||||
get(index: number, declared?: boolean): Reflect
|
||||
get(prop: string): Reflect
|
||||
get(param?: string | number, declared: boolean = true): Reflect | any {
|
||||
if (param == undefined || param == null) return this.obj
|
||||
if (typeof param == "number") {
|
||||
return on(accessible(this.fields(declared)[param]).get(this.obj))
|
||||
}
|
||||
if (typeof param == "string") {
|
||||
return this.field(param)
|
||||
}
|
||||
if (arguments.length === 0) return this.obj
|
||||
return on(this.field(param, declared).get(this.obj))
|
||||
}
|
||||
|
||||
set(name: any, value: any): Reflect {
|
||||
accessible(declaredField(this.class, name)).set(this.obj, value)
|
||||
set(param: string | number, value: any, declared: boolean = true): Reflect {
|
||||
this.field(param, declared).set(this.obj, value)
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -136,64 +143,43 @@ function declaredField(clazz: java.lang.Class<any>, name: string | java.lang.Str
|
||||
return field
|
||||
}
|
||||
|
||||
function declaredMethod(clazz: java.lang.Class<any>, name: string, ...clazzs: java.lang.Class<any>[]): java.lang.reflect.Method {
|
||||
let key = clazz.getName() + '.' + name + ':' + (clazzs || []).join(':')
|
||||
if (!methodCache[key]) {
|
||||
function declaredMethod(clazz: java.lang.Class<any>, nameOrIndex: string | number, ...clazzs: java.lang.Class<any>[]): java.lang.reflect.Method {
|
||||
let key = clazz.getName() + '.' + nameOrIndex + ':' + (clazzs || []).map(c => c.getName()).join(':')
|
||||
if (methodCache.has(key)) { return methodCache.get(key) }
|
||||
if (typeof nameOrIndex === "number") {
|
||||
methodCache.set(key, declaredMethods(clazz)[nameOrIndex])
|
||||
} else {
|
||||
try {
|
||||
// @ts-ignore
|
||||
methodCache[key] = clazz.getMethod(name, clazzs)
|
||||
methodCache.set(key, clazz.getMethod(nameOrIndex, clazzs as any))
|
||||
} catch (ex) {
|
||||
try {
|
||||
methodCache[key] = clazz.getDeclaredMethod(name, clazzs as any)
|
||||
methodCache.set(key, clazz.getDeclaredMethod(nameOrIndex, clazzs as any))
|
||||
} catch (ex) {
|
||||
for (const m of Java.from(declaredMethods(clazz))) {
|
||||
if (m.getName() == name) {
|
||||
methodCache[key] = m
|
||||
if (m.getName() == nameOrIndex) {
|
||||
methodCache.set(key, m)
|
||||
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>) {
|
||||
return clazz.getDeclaredMethods()
|
||||
}
|
||||
|
||||
let classMethodsCache: any[] = []
|
||||
|
||||
function mapToObject(javaObj) {
|
||||
if (!javaObj || !javaObj.class) { throw new TypeError(`参数 ${javaObj} 不是一个Java对象!`) }
|
||||
let target = {}
|
||||
getJavaObjectMethods(javaObj).forEach(t => mapMethod(target, javaObj, t))
|
||||
if (!Java.isJavaObject(javaObj)) { throw new TypeError(`参数 ${javaObj} 不是一个Java对象!`) }
|
||||
let target = Proxy.newProxy(javaObj, {
|
||||
apply: (target, name, args) => { return args ? javaObj[name](args) : javaObj[name]() }
|
||||
})
|
||||
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) {
|
||||
// if (!obj || !obj.class) { throw new TypeError(`参数 ${obj} 不是一个Java对象!`) }
|
||||
return new Reflect(obj)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/compile",
|
||||
"version": "0.9.4",
|
||||
"version": "0.10.0",
|
||||
"description": "MiaoScript compile package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/container",
|
||||
"version": "0.9.4",
|
||||
"version": "0.10.0",
|
||||
"description": "MiaoScript container package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,7 +19,7 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.9.4",
|
||||
"@ccms/nashorn": "^0.10.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.0.3"
|
||||
|
||||
@@ -62,14 +62,15 @@ export const JSClass = (className: string) => {
|
||||
export const Autowired = (className?: any) => {
|
||||
return function (target: any, propertyKey: string, index?: number) {
|
||||
let container = getContainer()
|
||||
if (className instanceof Symbol || className instanceof Function) {
|
||||
if (className && (className instanceof Symbol || className instanceof Function)) {
|
||||
return inject(className)(target, propertyKey, index)
|
||||
}
|
||||
let type = Reflect.getMetadata('design:type', target, propertyKey)
|
||||
if (type && type !== Object) {
|
||||
if (type && type !== Object && !Java.isJavaObject(type)) {
|
||||
inject(type)(target, propertyKey, index)
|
||||
named(className || propertyKey)(target, propertyKey, index)
|
||||
} else if (container.isBound(ioc.Autowired)) {
|
||||
console.debug('Autowired', 'ioc.Autowired', 'named', className || propertyKey)
|
||||
target[propertyKey] = container.getNamed(ioc.Autowired, className || propertyKey)
|
||||
} else {
|
||||
throw new Error(`No matching bindings found for target: ${target.constructor.name} type: ${type} named: ${className || propertyKey}`)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/core",
|
||||
"version": "0.9.4",
|
||||
"version": "0.10.0",
|
||||
"description": "MiaoScript api package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -24,8 +24,8 @@
|
||||
"typescript": "^4.0.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.9.4",
|
||||
"@ccms/container": "^0.9.4"
|
||||
"@ccms/api": "^0.10.0",
|
||||
"@ccms/container": "^0.10.0"
|
||||
},
|
||||
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
||||
}
|
||||
|
||||
@@ -99,6 +99,7 @@ function initialize() {
|
||||
console.i18n("ms.core.initialize.detect", { scope: global.scope, type })
|
||||
container.bind(server.ServerType).toConstantValue(type)
|
||||
container.bind(server.ServerChecker).toSelf().inSingletonScope()
|
||||
container.bind(server.NativePluginManager).toSelf().inSingletonScope()
|
||||
console.i18n("ms.core.package.initialize", { scope: global.scope, type })
|
||||
require(`${global.scope}/${type}`).default(container)
|
||||
require(`${global.scope}/plugin`)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/database",
|
||||
"version": "0.9.4",
|
||||
"version": "0.10.0",
|
||||
"description": "MiaoScript database package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,13 +19,13 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@javatypes/spring-jdbc": "^0.0.2",
|
||||
"@javatypes/spring-jdbc": "^0.0.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.0.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.9.4",
|
||||
"@ccms/container": "^0.9.4"
|
||||
"@ccms/api": "^0.10.0",
|
||||
"@ccms/container": "^0.10.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/i18n",
|
||||
"version": "0.9.4",
|
||||
"version": "0.10.0",
|
||||
"description": "MiaoScript i18n package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,7 +19,7 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.9.4",
|
||||
"@ccms/nashorn": "^0.10.0",
|
||||
"@types/js-yaml": "^3.12.5",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/keyvalue",
|
||||
"version": "0.9.4",
|
||||
"version": "0.10.0",
|
||||
"description": "MiaoScript keyvalue package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,15 +19,15 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.9.4",
|
||||
"@ccms/common": "^0.9.4",
|
||||
"@ccms/container": "^0.9.4"
|
||||
"@ccms/api": "^0.10.0",
|
||||
"@ccms/common": "^0.10.0",
|
||||
"@ccms/container": "^0.10.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.9.4",
|
||||
"@javatypes/amqp-client": "^0.0.2",
|
||||
"@javatypes/spring-amqp": "^0.0.2",
|
||||
"@javatypes/spring-rabbit": "^0.0.2",
|
||||
"@ccms/nashorn": "^0.10.0",
|
||||
"@javatypes/amqp-client": "^0.0.3",
|
||||
"@javatypes/spring-amqp": "^0.0.3",
|
||||
"@javatypes/spring-rabbit": "^0.0.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.0.3"
|
||||
|
||||
@@ -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="@javatypes/jdk" />
|
||||
/// <reference types="@javatypes/spring-amqp" />
|
||||
/// <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'
|
||||
export { }
|
||||
|
||||
@@ -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",
|
||||
"version": "0.9.4",
|
||||
"version": "0.10.0",
|
||||
"description": "MiaoScript api package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
|
||||
@@ -17,6 +17,7 @@ declare global {
|
||||
function to<T = any>(array: T[], type?: T): T[]
|
||||
function extend(...parentTypes: any[]): any
|
||||
function synchronized(func: () => void, lock: any): Function
|
||||
function isJavaObject(obj: any): boolean
|
||||
function asJSONCompatible<T = any>(obj: T): T
|
||||
//@ts-ignore
|
||||
// function super(type: any);
|
||||
@@ -80,8 +81,18 @@ declare global {
|
||||
i18n(name: string, ...params: any[]): void
|
||||
}
|
||||
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 { }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/nodejs",
|
||||
"version": "0.9.4",
|
||||
"version": "0.10.0",
|
||||
"description": "MiaoScript nodejs package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,7 +19,7 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.9.4",
|
||||
"@ccms/nashorn": "^0.10.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.0.3"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/nukkit",
|
||||
"version": "0.9.4",
|
||||
"version": "0.10.0",
|
||||
"description": "MiaoScript nukkit package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,14 +19,14 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@javatypes/nukkit-api": "^0.0.2",
|
||||
"@javatypes/nukkit-api": "^0.0.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.0.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.9.4",
|
||||
"@ccms/common": "^0.9.4",
|
||||
"@ccms/container": "^0.9.4"
|
||||
"@ccms/api": "^0.10.0",
|
||||
"@ccms/common": "^0.10.0",
|
||||
"@ccms/container": "^0.10.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
import { server } from '@ccms/api'
|
||||
import { provideSingleton } from '@ccms/container';
|
||||
import { provideSingleton } from '@ccms/container'
|
||||
|
||||
let Nukkit: cn.nukkit.Server = base.getInstance().getServer();
|
||||
const File = Java.type("java.io.File");
|
||||
let Nukkit: cn.nukkit.Server = base.getInstance().getServer()
|
||||
const File = Java.type("java.io.File")
|
||||
|
||||
@provideSingleton(server.Server)
|
||||
export class NukkitServer implements server.Server {
|
||||
private pluginsFolder: string;
|
||||
private pluginsFolder: string
|
||||
|
||||
constructor() {
|
||||
this.pluginsFolder = new File(base.getInstance().getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile().getCanonicalPath()
|
||||
}
|
||||
|
||||
getPlayer(name: string) {
|
||||
return Nukkit.getPlayer(name)
|
||||
return Nukkit.getPlayerExact(name)
|
||||
}
|
||||
getVersion(): string {
|
||||
return Nukkit.getVersion()
|
||||
}
|
||||
getOnlinePlayers() {
|
||||
return Nukkit.getOnlinePlayers() as unknown as any[]
|
||||
return Nukkit.getOnlinePlayers().values()
|
||||
}
|
||||
getConsoleSender() {
|
||||
return Nukkit.getConsoleSender()
|
||||
@@ -37,18 +37,15 @@ export class NukkitServer implements server.Server {
|
||||
return Nukkit.dispatchCommand(Nukkit.getConsoleSender(), command)
|
||||
}
|
||||
getPluginsFolder(): string {
|
||||
return this.pluginsFolder;
|
||||
return this.pluginsFolder
|
||||
}
|
||||
getNativePluginManager() {
|
||||
return Nukkit.getPluginManager() as any;
|
||||
return Nukkit.getPluginManager() as any
|
||||
}
|
||||
getNettyPipeline() {
|
||||
throw new Error("Method not implemented.");
|
||||
throw new Error("Method not implemented.")
|
||||
}
|
||||
getRootLogger() {
|
||||
return Packages.org.apache.logging.log4j.LogManager.getRootLogger()
|
||||
}
|
||||
sendJson(sender: string | any, json: object | string): void {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/ployfill",
|
||||
"version": "0.9.4",
|
||||
"version": "0.10.0",
|
||||
"description": "MiaoScript ployfill package",
|
||||
"author": "MiaoWoo <admin@yumc.pw>",
|
||||
"homepage": "https://github.com/circlecloud/ms.git",
|
||||
@@ -14,12 +14,12 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/i18n": "^0.9.4",
|
||||
"@ccms/nodejs": "^0.9.4",
|
||||
"@ccms/i18n": "^0.10.0",
|
||||
"@ccms/nodejs": "^0.10.0",
|
||||
"core-js": "^3.6.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.9.4",
|
||||
"@ccms/nashorn": "^0.10.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.0.3"
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
import { ProxyHandle } from '@ccms/nashorn'
|
||||
|
||||
// Nashorn JSAdapter See https://wiki.openjdk.java.net/display/Nashorn/Nashorn+extensions#Nashornextensions-JSAdapterconstructor
|
||||
let createProxy = eval(`
|
||||
function(handle){ return new JSAdapter(handle) }
|
||||
`)
|
||||
export interface ProxyHandle extends ProxyHandler<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: any) => any[];
|
||||
// call: (target: any, name: string, ...args: any[]) => any
|
||||
// deleteProperty: (target: any, name: string) => boolean
|
||||
}
|
||||
export class Proxy {
|
||||
static newProxy(target: any, handle: Partial<ProxyHandle>): any {
|
||||
return new Proxy(target, handle)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/plugin",
|
||||
"version": "0.9.4",
|
||||
"version": "0.10.0",
|
||||
"description": "MiaoScript api package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -25,10 +25,10 @@
|
||||
"typescript": "^4.0.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.9.4",
|
||||
"@ccms/common": "^0.9.4",
|
||||
"@ccms/container": "^0.9.4",
|
||||
"@ccms/i18n": "^0.9.4",
|
||||
"@ccms/api": "^0.10.0",
|
||||
"@ccms/common": "^0.10.0",
|
||||
"@ccms/container": "^0.10.0",
|
||||
"@ccms/i18n": "^0.10.0",
|
||||
"js-yaml": "^3.14.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +1,40 @@
|
||||
import { command, plugin, server } from '@ccms/api'
|
||||
import { provideSingleton, inject } from '@ccms/container'
|
||||
import { provideSingleton, inject, Autowired } from '@ccms/container'
|
||||
import { getPluginCommandMetadata, getPluginTabCompleterMetadata } from './utils'
|
||||
|
||||
@provideSingleton(PluginCommandManager)
|
||||
export class PluginCommandManager {
|
||||
@inject(server.ServerChecker)
|
||||
private ServerChecker: server.ServerChecker
|
||||
@inject(command.Command)
|
||||
@Autowired()
|
||||
private CommandManager: command.Command
|
||||
@Autowired()
|
||||
private ServerChecker: server.ServerChecker
|
||||
|
||||
constructor() {
|
||||
process.on('plugin.before.enable', (plugin: plugin.Plugin) => this.registryCommand(plugin))
|
||||
process.on('plugin.after.disable', (plugin: plugin.Plugin) => this.unregistryCommand(plugin))
|
||||
process.on('plugin.before.enable', this.registryCommand.bind(this))
|
||||
process.on('plugin.after.disable', this.unregistryCommand.bind(this))
|
||||
}
|
||||
|
||||
private registryCommand(pluginInstance: plugin.Plugin) {
|
||||
let cmds = getPluginCommandMetadata(pluginInstance)
|
||||
let tabs = getPluginTabCompleterMetadata(pluginInstance)
|
||||
for (const cmd of cmds) {
|
||||
let tab = tabs.get(cmd.name)
|
||||
if (!this.ServerChecker.check(cmd.servers)) {
|
||||
console.debug(`[${pluginInstance.description.name}] ${cmd.target.constructor.name} incompatible command ${cmd.name} server(${cmd.servers}) ignore.`)
|
||||
continue
|
||||
}
|
||||
let exec = {
|
||||
cmd: pluginInstance[cmd.executor].bind(pluginInstance),
|
||||
tab: tab ? pluginInstance[tab.executor].bind(pluginInstance) : undefined
|
||||
}
|
||||
for (let command of [cmd.name, ...cmd.alias]) {
|
||||
this.CommandManager.on(pluginInstance, command, exec)
|
||||
this.CommandManager.on(pluginInstance, command, {
|
||||
cmd: pluginInstance[cmd.executor].bind(pluginInstance),
|
||||
tab: tabs.has(command) ?
|
||||
pluginInstance[tabs.get(command).executor].bind(pluginInstance) :
|
||||
console.debug(`[${pluginInstance.description.name}] command ${cmd.name} is not registry tabCompleter`)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private unregistryCommand(pluginInstance: plugin.Plugin) {
|
||||
let cmds = getPluginCommandMetadata(pluginInstance)
|
||||
cmds.forEach(cmd => {
|
||||
this.CommandManager.off(pluginInstance, cmd.name)
|
||||
})
|
||||
cmds.forEach(cmd => this.CommandManager.off(pluginInstance, cmd.name))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import * as yaml from 'js-yaml'
|
||||
import * as fs from '@ccms/common/dist/fs'
|
||||
import { plugin } from '@ccms/api'
|
||||
import { provideSingleton } from '@ccms/container'
|
||||
|
||||
import { interfaces } from './interfaces'
|
||||
import { getPluginConfigMetadata } from './utils'
|
||||
|
||||
export interface PluginConfigLoader {
|
||||
@@ -13,7 +16,7 @@ export class YamlPluginConfig implements PluginConfigLoader {
|
||||
return yaml.safeLoad(content)
|
||||
}
|
||||
dump(variable: any): string {
|
||||
return yaml.safeDump(variable, { skipInvalid: true })
|
||||
return yaml.safeDump(variable, { skipInvalid: true, lineWidth: 120 })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,63 +25,92 @@ export class JsonPluginConfig implements PluginConfigLoader {
|
||||
return JSON.parse(content)
|
||||
}
|
||||
dump(variable: any): string {
|
||||
return JSON.stringify(variable)
|
||||
return JSON.stringify(variable, undefined, 4)
|
||||
}
|
||||
}
|
||||
|
||||
const configLoaderMap = new Map<string, PluginConfigLoader>()
|
||||
|
||||
export function getConfigLoader(format: string) {
|
||||
if (!configLoaderMap.has(format)) { throw new Error(`Unsupport config format ${format} !`) }
|
||||
return configLoaderMap.get(format)
|
||||
export interface PluginConfig {
|
||||
/**
|
||||
* Save Config to File
|
||||
*/
|
||||
readonly save?: () => void
|
||||
/**
|
||||
* Reload Config from File
|
||||
*/
|
||||
readonly reload?: () => void
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
function loadConfig(plugin: plugin.Plugin) {
|
||||
let configs = getPluginConfigMetadata(plugin)
|
||||
for (let [_, config] of configs) {
|
||||
@provideSingleton(PluginConfigManager)
|
||||
export class PluginConfigManager {
|
||||
private configLoaderMap = new Map<string, PluginConfigLoader>()
|
||||
|
||||
constructor() {
|
||||
this.configLoaderMap.set("json", new JsonPluginConfig())
|
||||
let yaml = new YamlPluginConfig()
|
||||
this.configLoaderMap.set("yml", yaml)
|
||||
this.configLoaderMap.set("yaml", yaml)
|
||||
process.on('plugin.before.load', this.loadConfig.bind(this))
|
||||
process.on('plugin.after.disable', this.saveConfig.bind(this))
|
||||
}
|
||||
|
||||
getConfigLoader(format: string) {
|
||||
if (!this.configLoaderMap.has(format)) { throw new Error(`Unsupport config format ${format} !`) }
|
||||
return this.configLoaderMap.get(format)
|
||||
}
|
||||
|
||||
loadConfig(plugin: plugin.Plugin) {
|
||||
let configs = getPluginConfigMetadata(plugin)
|
||||
for (let [_, config] of configs) {
|
||||
this.loadConfig0(plugin, config)
|
||||
}
|
||||
}
|
||||
|
||||
saveConfig(plugin: plugin.Plugin) {
|
||||
let configs = getPluginConfigMetadata(plugin)
|
||||
for (let [_, config] of configs) {
|
||||
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 {
|
||||
let configFile = fs.concat(fs.file(plugin.description.loadMetadata.file).parent, plugin.description.name, config.name + '.' + config.format)
|
||||
let configFactory = getConfigLoader(config.format)
|
||||
if (!fs.exists(configFile)) {
|
||||
base.save(configFile, configFactory.dump(plugin[config.variable]))
|
||||
console.i18n("ms.plugin.manager.config.save.default", { plugin: plugin.description.name, name: config.name, format: config.format })
|
||||
metadata.file = fs.concat(fs.file(plugin.description.loadMetadata.file).parent, plugin.description.name, metadata.filename)
|
||||
let configLoader = this.getConfigLoader(metadata.format)
|
||||
let value = plugin[metadata.variable]
|
||||
if (!fs.exists(metadata.file)) {
|
||||
base.save(metadata.file, configLoader.dump(value))
|
||||
console.i18n("ms.plugin.manager.config.save.default", { plugin: plugin.description.name, name: metadata.name, format: metadata.format })
|
||||
} else {
|
||||
Object.defineProperty(plugin, config.variable, { value: configFactory.load(base.read(configFile)) })
|
||||
plugin[config.variable].save = () => {
|
||||
let result = configFactory.dump(plugin[config.variable])
|
||||
base.save(configFile, result)
|
||||
console.debug(`[${plugin.description.name}] Save Config ${config.variable} to file ${configFile} result ${result}`)
|
||||
}
|
||||
console.debug(`[${plugin.description.name}] Load Config ${config.variable} from file ${configFile} result ${JSON.stringify(plugin[config.variable])}`)
|
||||
value = configLoader.load(base.read(metadata.file))
|
||||
console.debug(`[${plugin.description.name}] Load Config ${metadata.variable} from file ${metadata.file} =>\n${JSON.stringify(value, undefined, 4)}`)
|
||||
}
|
||||
this.defienConfigProp(plugin, metadata, value)
|
||||
} catch (error) {
|
||||
console.i18n("ms.plugin.manager.config.load.error", { plugin: plugin.description.name, name: config.name, format: config.format, error })
|
||||
console.i18n("ms.plugin.manager.config.load.error", { plugin: plugin.description.name, name: metadata.name, format: metadata.format, error })
|
||||
console.ex(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function saveConfig(plugin: plugin.Plugin) {
|
||||
let configs = getPluginConfigMetadata(plugin)
|
||||
for (let [_, config] of configs) {
|
||||
private saveConfig0(plugin: plugin.Plugin, metadata: interfaces.ConfigMetadata) {
|
||||
try {
|
||||
let configFile = fs.concat(fs.file(plugin.description.loadMetadata.file).parent, plugin.description.name, config.name + '.' + config.format)
|
||||
let configFactory = getConfigLoader(config.format)
|
||||
if (!config.readonly) { base.save(configFile, configFactory.dump(plugin[config.variable])) }
|
||||
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])
|
||||
base.save(metadata.file, result)
|
||||
console.debug(`[${plugin.description.name}] Save Config ${metadata.variable} to file ${metadata.file} =>\n${result}`)
|
||||
return true
|
||||
} catch (error) {
|
||||
console.i18n("ms.plugin.manager.config.save.error", { plugin: plugin.description.name, name: config.name, format: config.format, error })
|
||||
console.i18n("ms.plugin.manager.config.save.error", { plugin: plugin.description.name, name: metadata.name, format: metadata.format, error })
|
||||
console.ex(error)
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
configLoaderMap.set("json", new JsonPluginConfig())
|
||||
let yaml = new YamlPluginConfig()
|
||||
configLoaderMap.set("yml", yaml)
|
||||
configLoaderMap.set("yaml", yaml)
|
||||
process.on('plugin.before.load', loadConfig)
|
||||
process.on('plugin.after.load', saveConfig)
|
||||
}
|
||||
|
||||
init()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export const METADATA_KEY = {
|
||||
plugin: Symbol.for("@ccms/plugin:plugin"),
|
||||
souece: Symbol.for("@ccms/plugin:souece"),
|
||||
source: Symbol.for("@ccms/plugin:source"),
|
||||
cmd: Symbol.for("@ccms/plugin:cmd"),
|
||||
tab: Symbol.for("@ccms/plugin:tab"),
|
||||
listener: Symbol.for("@ccms/plugin:listener"),
|
||||
@@ -10,4 +10,4 @@ export const METADATA_KEY = {
|
||||
enable: Symbol.for("@ccms/plugin:stage:enable"),
|
||||
disable: Symbol.for("@ccms/plugin:stage:disable")
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ export function plugin(metadata: pluginApi.PluginMetadata | any) {
|
||||
Reflect.defineMetadata(METADATA_KEY.plugin, previousMetadata, Reflect)
|
||||
const previousSources: Map<string, pluginApi.PluginMetadata> = getPluginSources()
|
||||
previousSources.set(metadata.source.toString(), metadata)
|
||||
Reflect.defineMetadata(METADATA_KEY.souece, previousSources, Reflect)
|
||||
Reflect.defineMetadata(METADATA_KEY.source, previousSources, Reflect)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,6 +77,8 @@ export function config(metadata: interfaces.ConfigMetadata = {}) {
|
||||
metadata.variable = key
|
||||
metadata.version = metadata.version ?? 1
|
||||
metadata.format = metadata.format ?? 'yml'
|
||||
metadata.autosave = metadata.autosave ?? false
|
||||
metadata.filename = metadata.filename ?? metadata.name + '.' + metadata.format
|
||||
let previousMetadata = getPluginConfigMetadata(target)
|
||||
previousMetadata.set(metadata.name, metadata)
|
||||
Reflect.defineMetadata(METADATA_KEY.config, previousMetadata, target.constructor)
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
import { event, plugin, server } from '@ccms/api'
|
||||
import { provideSingleton, postConstruct, inject } from '@ccms/container'
|
||||
import { provideSingleton, Autowired } from '@ccms/container'
|
||||
import { getPluginListenerMetadata } from './utils'
|
||||
|
||||
@provideSingleton(PluginEventManager)
|
||||
export class PluginEventManager {
|
||||
@inject(server.ServerChecker)
|
||||
private ServerChecker: server.ServerChecker
|
||||
@inject(event.Event)
|
||||
@Autowired()
|
||||
private EventManager: event.Event
|
||||
@Autowired()
|
||||
private ServerChecker: server.ServerChecker
|
||||
|
||||
constructor() {
|
||||
process.on('plugin.before.enable', (plugin: plugin.Plugin) => this.registryListener(plugin))
|
||||
process.on('plugin.after.disable', (plugin: plugin.Plugin) => this.unregistryListener(plugin))
|
||||
process.on('plugin.before.enable', this.registryListener.bind(this))
|
||||
process.on('plugin.after.disable', this.unregistryListener.bind(this))
|
||||
}
|
||||
|
||||
mapEventName() {
|
||||
return this.EventManager.mapEventName().toFixed(0)
|
||||
}
|
||||
|
||||
private registryListener(pluginInstance: plugin.Plugin) {
|
||||
|
||||
@@ -6,6 +6,8 @@ export * from './manager'
|
||||
export * from './decorators'
|
||||
export * from './interfaces'
|
||||
|
||||
export { PluginConfig } from './config'
|
||||
|
||||
export {
|
||||
plugin as JSPlugin,
|
||||
cmd as Cmd,
|
||||
|
||||
@@ -72,8 +72,16 @@ export namespace interfaces {
|
||||
*/
|
||||
format?: string
|
||||
/**
|
||||
* 是否为只读(关闭时将不会自动保存)
|
||||
* 自动保存 默认为 false
|
||||
*/
|
||||
readonly?: boolean
|
||||
autosave?: boolean
|
||||
/**
|
||||
* 配置文件名称
|
||||
*/
|
||||
filename?: string
|
||||
/**
|
||||
* 配置文件全路径
|
||||
*/
|
||||
file?: any
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { plugin, server } from "@ccms/api"
|
||||
import { inject, ContainerInstance, Container, provideSingletonNamed } from "@ccms/container"
|
||||
import { inject, ContainerInstance, Container, provideSingletonNamed, Autowired } from "@ccms/container"
|
||||
|
||||
import { interfaces } from "../interfaces"
|
||||
import { getPluginStageMetadata, getPluginSources } from "../utils"
|
||||
@@ -11,7 +11,7 @@ export class IocLoader implements plugin.PluginLoader {
|
||||
type: string = LOADER_TYPE_NAME
|
||||
@inject(ContainerInstance)
|
||||
private container: Container
|
||||
@inject(server.ServerChecker)
|
||||
@Autowired()
|
||||
private serverChecker: server.ServerChecker
|
||||
|
||||
private pluginMetadataMap: Map<string, plugin.PluginMetadata>
|
||||
@@ -69,7 +69,7 @@ export class IocLoader implements plugin.PluginLoader {
|
||||
console.i18n('ms.plugin.manager.build.duplicate', { exists: pluginInstance.description.source, source: metadata.source })
|
||||
}
|
||||
this.container.rebind(plugin.Plugin).to(metadata.target).inSingletonScope().whenTargetNamed(metadata.name)
|
||||
} catch{
|
||||
} catch {
|
||||
this.container.bind(plugin.Plugin).to(metadata.target).inSingletonScope().whenTargetNamed(metadata.name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,37 @@
|
||||
import i18n from '@ccms/i18n'
|
||||
import { plugin, server, event } from '@ccms/api'
|
||||
import { inject, provideSingleton, Container, ContainerInstance } from '@ccms/container'
|
||||
import { plugin, server } from '@ccms/api'
|
||||
import { provideSingleton, Container, ContainerInstance, Autowired } from '@ccms/container'
|
||||
|
||||
import './config'
|
||||
import { interfaces } from './interfaces'
|
||||
import { PluginTaskManager } from './task'
|
||||
import { PluginEventManager } from './event'
|
||||
import { PluginCommandManager } from './command'
|
||||
import { PluginConfigManager } from './config'
|
||||
|
||||
const Thread = Java.type('java.lang.Thread')
|
||||
|
||||
@provideSingleton(plugin.PluginManager)
|
||||
export class PluginManagerImpl implements plugin.PluginManager {
|
||||
@inject(ContainerInstance)
|
||||
@Autowired(ContainerInstance)
|
||||
private container: Container
|
||||
@inject(plugin.PluginInstance)
|
||||
@Autowired(plugin.PluginInstance)
|
||||
private pluginInstance: any
|
||||
@inject(server.ServerType)
|
||||
@Autowired(server.ServerType)
|
||||
private serverType: string
|
||||
@inject(event.Event)
|
||||
private EventManager: event.Event
|
||||
@inject(server.ServerChecker)
|
||||
private serverChecker: server.ServerChecker
|
||||
|
||||
@inject(PluginTaskManager)
|
||||
@Autowired()
|
||||
private serverChecker: server.ServerChecker
|
||||
@Autowired()
|
||||
private nativePluginManager: server.NativePluginManager
|
||||
|
||||
@Autowired()
|
||||
private taskManager: PluginTaskManager
|
||||
@inject(PluginEventManager)
|
||||
@Autowired()
|
||||
private eventManager: PluginEventManager
|
||||
@inject(PluginCommandManager)
|
||||
@Autowired()
|
||||
private configManager: PluginConfigManager
|
||||
@Autowired()
|
||||
private commandManager: PluginCommandManager
|
||||
|
||||
private initialized: boolean = false
|
||||
@@ -48,6 +52,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
||||
// ignore unused
|
||||
this.taskManager
|
||||
this.eventManager
|
||||
this.configManager
|
||||
this.commandManager
|
||||
}
|
||||
|
||||
@@ -55,7 +60,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
||||
if (this.pluginInstance === undefined) { throw new Error("Can't found Plugin Instance!") }
|
||||
if (this.initialized !== true) {
|
||||
console.i18n('ms.plugin.initialize', { plugin: this.pluginInstance, loader: Thread.currentThread().contextClassLoader })
|
||||
console.i18n('ms.plugin.event.map', { count: this.EventManager.mapEventName().toFixed(0), type: this.serverType })
|
||||
console.i18n('ms.plugin.event.map', { count: this.eventManager.mapEventName(), type: this.serverType })
|
||||
let pluginScanner = this.container.getAll<plugin.PluginScanner>(plugin.PluginScanner)
|
||||
pluginScanner.forEach((scanner) => {
|
||||
console.debug(`loading plugin sacnner ${scanner.type}...`)
|
||||
@@ -221,15 +226,28 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
||||
try {
|
||||
this.buildPlugin(metadata)
|
||||
} catch (error) {
|
||||
console.console(error)
|
||||
console.console(`§4无法加载插件 §b${metadata.name} §4构建插件失败!`)
|
||||
console.ex(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private checkDepends(depends: string | string[]) {
|
||||
if (!depends) return true
|
||||
for (const depend of depends) { if (!this.metadataMap.has(depend)) return false }
|
||||
return true
|
||||
}
|
||||
private checkNativeDepends(depends: string | string[]) {
|
||||
if (!depends) return true
|
||||
for (const depend of depends) { if (!this.nativePluginManager.has(depend)) return false }
|
||||
return true
|
||||
}
|
||||
private buildPlugin(metadata: plugin.PluginMetadata) {
|
||||
if (!this.loaderMap.has(metadata.type)) { throw new Error(`§4无法加载插件 §c${metadata.name} §4请检查 §c${metadata.type} §4加载器是否正常启用!`) }
|
||||
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.checkDepends(metadata.depends)) { throw new Error(`§4无法加载插件 §b${metadata.name} §4请检查依赖 §3${metadata.depends.join(',')} §4是否安装完整!`) }
|
||||
if (!this.checkNativeDepends(metadata.nativeDepends)) { throw new Error(`§4无法加载插件 §b${metadata.name} §4请检查插件依赖 §3${metadata.nativeDepends.join(',')} §4是否安装完整!`) }
|
||||
let pluginInstance = this.loaderMap.get(metadata.type).build(metadata)
|
||||
if (!pluginInstance) { throw new Error(`§4加载器 §c${metadata.type} §4加载插件 §c${metadata.name} §4失败!`) }
|
||||
this.instanceMap.set(metadata.name, pluginInstance)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { plugin, task } from '@ccms/api'
|
||||
import { provideSingleton, inject } from '@ccms/container'
|
||||
import { provideSingleton, Autowired } from '@ccms/container'
|
||||
|
||||
@provideSingleton(PluginTaskManager)
|
||||
export class PluginTaskManager {
|
||||
@inject(task.TaskManager)
|
||||
@Autowired()
|
||||
private taskManager: task.TaskManager
|
||||
|
||||
constructor() {
|
||||
|
||||
@@ -14,7 +14,7 @@ function getPlugin(name: string) {
|
||||
|
||||
function getPluginSources() {
|
||||
let pluginSources: Map<string, plugin.PluginMetadata> = Reflect.getMetadata(
|
||||
METADATA_KEY.souece,
|
||||
METADATA_KEY.source,
|
||||
Reflect
|
||||
) || pluginSourceCache
|
||||
return pluginSources
|
||||
|
||||
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插件的时候 是不是经常面临下列情况
|
||||
- 编译等半天 重启等半天 测试找不到问题
|
||||
- 后台 IDE SCP/FTP 来回切换
|
||||
|
||||
### 什么是MiaoConsole
|
||||
- MiaoConsole 是 基于 MiaoScript 开发的 在线调试工具
|
||||
- 通过复用 Minecraft的Netty 通道 实现服务器端口 在线调试(并不是Java的调试哦)
|
||||
> 各位腐竹 在开服的时候 是不是经常遇到下列情况
|
||||
- 修改一个配置文件 经常格式错误
|
||||
- 各种报错看不懂 插件依赖找不到
|
||||
|
||||
### 什么是 MiaoConsole
|
||||
|
||||
#### 对于开发者
|
||||
- MiaoConsole 是 基于 `MiaoScript` 开发的 在线调试工具
|
||||
- 通过复用 Minecraft 的 Netty 通道 实现服务器端口 `MiaoScript` 在线调试
|
||||
|
||||
#### 对于腐竹
|
||||
- 可以在网页上实时看到服务器日志
|
||||
- 共享 Token 给插件开发者 让其帮助调试服务器
|
||||
|
||||
### 工具动图
|
||||
|
||||
@@ -16,8 +28,8 @@
|
||||
### MiaoConsole 有哪些功能
|
||||
- 无需编译 上传等步骤 实时在线debug
|
||||
- 实时转发服务端日志 无需来回切换
|
||||
- 基于Nashorn的动态脚本语言
|
||||
- 基于TypeScript的自动补全逻辑(以实现BungeeCord Sponge Bukkit的API全自动补全)
|
||||
- 基于 Nashorn 的动态脚本语言
|
||||
- 基于 TypeScript 的自动补全逻辑(以实现BungeeCord Sponge Bukkit的API全自动补全)
|
||||
|
||||
### MiaoConsole 的兼容性
|
||||
- 跨端兼容 Sponge Bukkit BungeeCord
|
||||
@@ -27,25 +39,27 @@
|
||||
- BungeeCord ~~终端转发暂未兼容~~ 已经能兼容了
|
||||
|
||||
### 安装教程
|
||||
- 安装MiaoScript [下载地址](http://w.yumc.pw/free.html#MiaoScript-download)
|
||||
- 首次启动 等待加载基础环境类库
|
||||
- 执行 `mpm i MiaoConsole`
|
||||
- 安装 `MiaoScript` [站内地址](https://www.mcbbs.net/thread-774401-1-1.html)
|
||||
- 如果你已经安装了 Yum 可以通过 Yum 快速安装 `/yum install MiaoScript`
|
||||
- 等待 MiaoScript 引擎启动完成(首次启动可能需要10-20秒 依赖于您的网络环境)
|
||||
- 执行 `mspm i MiaoConsole`
|
||||
|
||||
### 使用教程
|
||||
- 执行 `mconsole token` 获得临时Token
|
||||
- 查看启动日志 获取临时 `Token`
|
||||
- 或者 执行 `mconsole token` 获得临时Token
|
||||
- 打开 `http://ms.yumc.pw/console.html`
|
||||
- 在地址栏输入服务器地址 需要带上端口
|
||||
- 在Token栏输入获取到的Token
|
||||
- 在 Token 栏输入获取到的 Token
|
||||
- 点击链接即可
|
||||
|
||||
### 终端使用
|
||||
- 支持实时传输服务器日志到终端
|
||||
- 直接在终端输入命令 会转发到服务器
|
||||
- 目前暂不支持命令自动补全
|
||||
- 支持命令自动补全
|
||||
- 支持命令历史
|
||||
|
||||
### 代码编辑器使用
|
||||
- 支持 Java 的 lang包和util包自动补全
|
||||
- 支持 Java 的类自动补全
|
||||
- 支持服务端所有代码补全
|
||||
- 注意 暂时不支持自动导入包 所以需要手动输入全类名
|
||||
- 快捷键说明(选中代码后 只会执行选中部分)
|
||||
@@ -53,8 +67,27 @@
|
||||
- Ctrl + E 执行命令
|
||||
- Ctrl + Q 切换代码页
|
||||
|
||||
## 插件源码
|
||||
|
||||
- [MiaoScript包管理中心](https://git.yumc.pw/circlecloud/ms/src/branch/master/packages/plugins/src/MiaoConsole.ts)
|
||||
|
||||
### 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)
|
||||
|
||||
本插件所用所有代码均为原创,不存在借用/抄袭等行为
|
||||
|
||||
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]
|
||||
@@ -6,7 +6,16 @@
|
||||
- 快来接入 喵式奖励
|
||||
- 通过QQ小程序广告 增加服务器收入
|
||||
|
||||
### 先来一张近期的服务器提现订单
|
||||
|
||||

|
||||
|
||||
## 插件展示
|
||||
|
||||
> 多图预警 折叠了
|
||||
|
||||
`[spoiler]`
|
||||
|
||||
- 插件帮助
|
||||
- 扫码绑定
|
||||
- 查看个人信息
|
||||
@@ -20,6 +29,9 @@
|
||||
- 玩家扫码兑换完成
|
||||
- 腐竹扫码确认
|
||||
- 腐竹扫码完成
|
||||
|
||||
`[/spoiler]`
|
||||
|
||||
## 插件命令
|
||||
```
|
||||
>mrd
|
||||
@@ -38,28 +50,42 @@
|
||||
[17:56:54 INFO]: [MS][MRD] 比如 设置了0.001 那就是 玩家至少 1000喵币 才能兑换!
|
||||
```
|
||||
|
||||
## 接下来就是赚钱的操作
|
||||
|
||||
## 插件安装/配置
|
||||
|
||||
### 基础准备工作
|
||||
- QQ搜索小程序 `圈云盒子` 并登录
|
||||
- 申请内测服务器账号 个人中心 => 配置面板 => 圈云盒子客服群 加群申请
|
||||
- 申请内测服务器账号
|
||||
- 个人中心 => 配置面板 => 圈云盒子客服群
|
||||
- 打开群详情 加群
|
||||
|
||||
### 申请账号
|
||||
- 打开 [圈云盒子管理后台](https://reward.yumc.pw)
|
||||
- 扫码登录 并且加入客服群
|
||||
- 创建一个服务器 等待管理员审核通过
|
||||
|
||||
`[hide]`
|
||||
|
||||
### 服务器准备工作
|
||||
- 先安装 `MiaoScript` [站内地址]()
|
||||
- 可以通过 Yum 快速安装 `/yum install MiaoScript`
|
||||
- 安装 `MiaoScript` [站内地址](https://www.mcbbs.net/thread-774401-1-1.html)
|
||||
- 如果你已经安装了 Yum 可以通过 Yum 快速安装 `/yum install MiaoScript`
|
||||
- 等待 MiaoScript 引擎启动完成(首次启动可能需要10-20秒 依赖于您的网络环境)
|
||||
- 执行 `/mspm install MiaoReward`
|
||||
- 执行 `/mspm install MiaoReward` 安装 MiaoReward 脚本插件
|
||||
- 完成安装
|
||||
|
||||
### 绑定服务器
|
||||
- 执行 `/mrd bind server`
|
||||
- 使用QQ扫码
|
||||
- 选择需要绑定的服务器
|
||||
- 完成绑定
|
||||
- 使用QQ扫码 => 选择需要绑定的服务器 => 完成绑定
|
||||
- 配置服务器兑换比例
|
||||
- 执行 `/mrd ratio 0.001` (最低为 1:0.0001)
|
||||
- 执行 `/mrd ratio <兑换比例>` (最低为 1:0.0001)
|
||||
- 执行兑换比例确认指令
|
||||
- 执行 `/mrd server` 查看服务器信息
|
||||
- 如需绑定多台 可以直接复制绑定之后的 `MiaoScript/plugins/MiaoReward/config.yml` 文件到多台服务器上 然后 `/mrd reload` 重载插件
|
||||
- 如果群组服需要绑定多台服务器(前提是每个服务器都有玩家在)
|
||||
- 执行 `/gmspm install MiaoReward` 批量安装
|
||||
- 可以直接复制绑定之后的 `MiaoScript/plugins/MiaoReward/config.yml`
|
||||
- 黏贴配置文件到所有需要绑定的服务器上
|
||||
- 然后 `/gmspm reload MiaoReward` 批量重载插件
|
||||
|
||||
### QQ群配置
|
||||
- 打开小程序
|
||||
@@ -72,6 +98,7 @@
|
||||
- 执行 `/mrd bind`
|
||||
- 使用QQ扫码
|
||||
- 完成绑定
|
||||
- 执行 `/mrd query` 查询信息
|
||||
|
||||
## 使用说明
|
||||
- 玩家可以通过下列方式获取喵币
|
||||
@@ -82,13 +109,21 @@
|
||||
- 腐竹可以在平台将喵币兑换成RMB(兑换比例请加群联系客服详谈)
|
||||
- 登录小程序后 个人中心 => 配置面板 => 圈云盒子客服群
|
||||
|
||||
## PAPI兼容
|
||||
- 目前已经兼容 PAPI 变量
|
||||
- `%mrd_balance%` 玩家喵币
|
||||
- `%mrd_sign%` 玩家签到(*/1)
|
||||
- `%mrd_video%` 玩家视频观看次数(*/300)
|
||||
- `%mrd_box%` 玩家盒子观看次数(*/300)
|
||||
- 如果玩家变量没有及时更新 执行 `/mrd query` 或 `重新登录游戏` 即可
|
||||
|
||||
## 配置文件
|
||||
|
||||
``` yaml
|
||||
```yml
|
||||
# 服务器ID
|
||||
serverId: '16'
|
||||
serverId: 16
|
||||
# 服务器Token
|
||||
serverToken: d50d3f6e-2a59-460a-2b29-82b66c4bbf52
|
||||
serverToken: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
||||
# 兑换指令
|
||||
drawCommand: 'p give %player_name% %amount%'
|
||||
# 冷却时间
|
||||
@@ -97,10 +132,20 @@ drawCooldown: 300
|
||||
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
|
||||
- 绑定服务器(已完成)
|
||||
- 绑定玩家(已完成)
|
||||
- 兑换喵币(已完成)
|
||||
- 自助开通服务器(开发中)
|
||||
- 自助兑换RMB(开发中)
|
||||
- 自助提现(开发中)
|
||||
- [自助开通](https://reward.yumc.pw)服务器(已完成)
|
||||
- [自助兑换](https://reward.yumc.pw)RMB(已完成)
|
||||
- [自助提现](https://reward.yumc.pw)(已完成)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "@ccms/plugins",
|
||||
"version": "0.9.4",
|
||||
"version": "0.10.0",
|
||||
"description": "MiaoScript plugins package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -20,16 +20,16 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@javatypes/spring-data-redis": "^0.0.2",
|
||||
"@javatypes/spring-web": "^0.0.2",
|
||||
"@javatypes/tomcat": "^0.0.2",
|
||||
"@javatypes/spring-data-redis": "^0.0.3",
|
||||
"@javatypes/spring-web": "^0.0.3",
|
||||
"@javatypes/tomcat": "^0.0.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.0.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.9.4",
|
||||
"@ccms/container": "^0.9.4",
|
||||
"@ccms/plugin": "^0.9.4"
|
||||
"@ccms/api": "^0.10.0",
|
||||
"@ccms/container": "^0.10.0",
|
||||
"@ccms/plugin": "^0.10.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,11 +170,6 @@ export class MiaoChat extends interfaces.Plugin {
|
||||
return string
|
||||
}
|
||||
}
|
||||
if (!this.chat) {
|
||||
this.logger.console('§4消息管理器注入失败 请检查当前服务器是否兼容...')
|
||||
this.AsyncPlayerChatEvent['off']()
|
||||
this.MessageChannelEvent$Chat['off']()
|
||||
}
|
||||
}
|
||||
|
||||
disable() {
|
||||
@@ -182,6 +177,10 @@ export class MiaoChat extends interfaces.Plugin {
|
||||
}
|
||||
|
||||
bukkitenable() {
|
||||
if (!this.chat) {
|
||||
this.logger.console('§4消息管理器注入失败 请检查当前服务器是否兼容...')
|
||||
this.AsyncPlayerChatEvent['off']()
|
||||
}
|
||||
// 尝试加载 Bukkit 的 PlaceholderAPI
|
||||
try {
|
||||
//@ts-ignore
|
||||
@@ -193,6 +192,10 @@ export class MiaoChat extends interfaces.Plugin {
|
||||
}
|
||||
|
||||
spongeenable() {
|
||||
if (!this.chat) {
|
||||
this.logger.console('§4消息管理器注入失败 请检查当前服务器是否兼容...')
|
||||
this.MessageChannelEvent$Chat['off']()
|
||||
}
|
||||
// 尝试加载 Sponge 的 PlaceholderAPI
|
||||
try {
|
||||
var spongePapi = this.Server.getService('me.rojo8399.placeholderapi.PlaceholderService')
|
||||
|
||||
@@ -185,8 +185,8 @@ export class MiaoConsole extends interfaces.Plugin {
|
||||
@disable({ servers: [constants.ServerType.Bukkit, constants.ServerType.Sponge] })
|
||||
removeLog4jForward() {
|
||||
try {
|
||||
this.appender.stop()
|
||||
this.rootLogger.removeAppender(this.appender)
|
||||
this.appender?.stop()
|
||||
this.rootLogger?.removeAppender(this.appender)
|
||||
} catch (error) {
|
||||
console.ex(error)
|
||||
}
|
||||
@@ -195,7 +195,7 @@ export class MiaoConsole extends interfaces.Plugin {
|
||||
@disable({ servers: [constants.ServerType.Bungee] })
|
||||
removeLoggerForward() {
|
||||
try {
|
||||
this.rootLogger.removeHandler(this.handler)
|
||||
this.rootLogger?.removeHandler(this.handler)
|
||||
} catch (error) {
|
||||
console.ex(error)
|
||||
}
|
||||
@@ -204,7 +204,7 @@ export class MiaoConsole extends interfaces.Plugin {
|
||||
@disable({ servers: [constants.ServerType.Spring] })
|
||||
removeLogbackForward() {
|
||||
try {
|
||||
this.rootLogger.detachAppender(this.LOGBACK_APPENDER_NAME)
|
||||
this.rootLogger?.detachAppender(this.LOGBACK_APPENDER_NAME)
|
||||
} catch (error) {
|
||||
console.ex(error)
|
||||
}
|
||||
@@ -250,7 +250,7 @@ export class MiaoConsole extends interfaces.Plugin {
|
||||
client.emit('log', `§6命令: §b${cmd} §a执行成功!`)
|
||||
})
|
||||
client.on('tabComplate', (input, index, callback) => {
|
||||
callback?.(this.command.tabComplete(this.server.getConsoleSender(), input, index))
|
||||
callback?.(this.command.tabComplete(this.server.getConsoleSender(), input, index) || [])
|
||||
})
|
||||
client.on('exec', (code) => {
|
||||
try {
|
||||
|
||||
@@ -1,18 +1,31 @@
|
||||
import { task, server, constants } from "@ccms/api";
|
||||
import { inject } from "@ccms/container";
|
||||
import { plugin, interfaces, cmd } from "@ccms/plugin";
|
||||
import { task, server, constants } from "@ccms/api"
|
||||
import { Autowired, JSClass } from "@ccms/container"
|
||||
import { plugin, interfaces } from "@ccms/plugin"
|
||||
|
||||
import http from '@ccms/common/dist/http'
|
||||
import * as fs from '@ccms/common/dist/fs'
|
||||
let createPacketAdapterFunction = eval(`
|
||||
function(cls, plugin, type, onPacketSending){
|
||||
return new cls(plugin, type) {
|
||||
onPacketSending: onPacketSending
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
@plugin({ name: 'MiaoProtocol', prefix: 'MPTL', version: '1.0.0', author: 'MiaoWoo', servers: [constants.ServerType.Bukkit], source: __filename })
|
||||
@plugin({ prefix: 'MPTL', version: '1.0.0', author: 'MiaoWoo', servers: [constants.ServerType.Bukkit], source: __filename })
|
||||
export class MiaoProtocol extends interfaces.Plugin {
|
||||
@inject(server.Server)
|
||||
private server: server.Server;
|
||||
@inject(task.TaskManager)
|
||||
private taskManager: task.TaskManager;
|
||||
@Autowired()
|
||||
private server: server.Server
|
||||
@Autowired()
|
||||
private taskManager: task.TaskManager
|
||||
|
||||
@JSClass('com.comphenix.protocol.events.PacketAdapter')
|
||||
private PacketAdapter
|
||||
@JSClass('com.comphenix.protocol.PacketType')
|
||||
private PacketType
|
||||
@JSClass('com.comphenix.protocol.ProtocolLibrary')
|
||||
private ProtocolLibrary
|
||||
|
||||
private pipeline: any
|
||||
private adapter: any
|
||||
|
||||
enable() {
|
||||
let count = 0
|
||||
@@ -25,6 +38,28 @@ export class MiaoProtocol extends interfaces.Plugin {
|
||||
this.logger.console('§cNetty通道注入失败 §4所有功能将无法使用!')
|
||||
}
|
||||
}).later(20).timer(40).submit()
|
||||
this.initPacketAdapter()
|
||||
}
|
||||
|
||||
disable() {
|
||||
this.ProtocolLibrary.getProtocolManager().removePacketListener(this.adapter)
|
||||
}
|
||||
|
||||
createPacketAdapter(onPacketSending: (event) => void) {
|
||||
return createPacketAdapterFunction(this.PacketAdapter, base.getInstance(), [this.PacketType.Play.Server.MAP], onPacketSending)
|
||||
}
|
||||
|
||||
initPacketAdapter() {
|
||||
this.adapter = this.createPacketAdapter((event) => {
|
||||
let integers = event.getPacket().getIntegers().getValues()
|
||||
console.log(`ProtocolLib onPacketSending filter Map
|
||||
Player: ${event.getPlayer()}
|
||||
MapId: ${integers.get(0)}
|
||||
Size: ${integers.get(3)}x${integers.get(4)}
|
||||
Bytes: ${event.getPacket().getByteArrays().read(0).length}
|
||||
`)
|
||||
// org.bukkit.map.MapPalette.imageToBytes()
|
||||
})
|
||||
this.ProtocolLibrary.getProtocolManager().addPacketListener(this.adapter)
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -47,13 +47,16 @@ let langMap = {
|
||||
'download.start': '§6开始下载插件: §b{name} §6版本 §3{version}',
|
||||
'download.url': '§6插件下载地址: §b{url}',
|
||||
'download.finish': '§6插件 §b{name} §6版本 §3{version} §a下载完毕 开始加载 ...',
|
||||
'install.already': '§6插件 §b{name} §6版本 §3{version} §c已安装在服务器 §3更新请用 update 命令!',
|
||||
'install.finish': '§6插件 §b{name} §6版本 §3{version} §a安装成功!',
|
||||
'update.finish': '§6插件 §b{name} §6版本 §3{version} §a更新成功!',
|
||||
'upgrade.confirm': '§6您正在尝试更新 §bMiaoScript §c核心 §6请执行 §b/mpm §aupgrade §cconfirm §6确认执行!',
|
||||
'upgrade.start': '§6开始§a更新 §bMiaoScript §6核心 §c正在清理 node_modules 请稍候...',
|
||||
'upgrade.failed': '§6尝试热更新 §bMiaoScript §c核心 §4失败! §6请重启服务器完成更新...',
|
||||
'deploy.token.not.exists': '§4请先配置发布Token!',
|
||||
'deploy.success': '§6插件 §b{name} §6版本 §3{version} §a发布成功! §6服务器返回: §a{msg}',
|
||||
'deploy.fail': '§6插件 §b{name} §6版本 §3{version} §c发布失败! §6服务器返回: §c{msg}',
|
||||
'prun.script': '§6指定插件:§b {name}',
|
||||
'run.script': '§b运行脚本:§r {script}',
|
||||
'run.result': '§a返回结果:§r {result}',
|
||||
'run.noresult': '§4没有返回结果!',
|
||||
@@ -102,7 +105,7 @@ class SpongeFakeSender extends FakeSender {
|
||||
}
|
||||
}
|
||||
|
||||
@JSPlugin({ prefix: 'PM', version: '1.3.0', author: 'MiaoWoo', source: __filename })
|
||||
@JSPlugin({ prefix: 'PM', version: '1.3.1', author: 'MiaoWoo', source: __filename })
|
||||
export class MiaoScriptPackageManager extends interfaces.Plugin {
|
||||
@Autowired()
|
||||
private pluginManager: pluginApi.PluginManager
|
||||
@@ -176,7 +179,7 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
|
||||
let message = JSON.parse(input.readUTF())
|
||||
let fakeSender = this.getProxySender(message.sender)
|
||||
this.taskManager.create(() => this.main(fakeSender, message.command, message.args)).async().submit()
|
||||
this.logger.sender(fakeSender, `§6命令 §b/mpm ${message.args?.join?.(' ')} §a执行成功!`)
|
||||
this.logger.sender(fakeSender, `§6命令 §b/mspm ${message.args?.join?.(' ')} §a执行成功!`)
|
||||
}
|
||||
|
||||
private getProxySender(name: string) {
|
||||
@@ -223,7 +226,7 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
|
||||
if (!this.isBungeeCord) return this.logger.sender(sender, '§c当前服务器尚未检测到 BungeeCord 链接...')
|
||||
this.taskManager.create(() => this.main(sender, command, args)).async().submit()
|
||||
this.bungeeCordForward(sender, { sender: sender.getName(), command, args })
|
||||
this.logger.sender(sender, `§6[§3BPM§6][§a${this.serverName}§6] §6命令 §b/mpm ${args.join?.(' ')} §a发布成功!`)
|
||||
this.logger.sender(sender, `§6[§3BPM§6][§a${this.serverName}§6] §6命令 §b/mspm ${args.join?.(' ')} §a发布成功!`)
|
||||
}
|
||||
|
||||
@Cmd({ servers: [constants.ServerType.Bungee] })
|
||||
@@ -263,6 +266,18 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
|
||||
])
|
||||
}
|
||||
|
||||
cmdsudo(sender: any, name: string, ...args: string[]) {
|
||||
this.taskManager.create(() => {
|
||||
let player = this.server.getPlayer(name)
|
||||
if (!player) {
|
||||
return this.logger.sender(sender, `§4玩家 ${player.getName()} 不在线或不存在!`)
|
||||
}
|
||||
let command = args.join(' ')
|
||||
this.server.dispatchCommand(player, command)
|
||||
this.logger.sender(sender, `§6玩家 §a${player.getName()} §6命令 §b${command} §a执行完成!`)
|
||||
}).submit()
|
||||
}
|
||||
|
||||
cmdload(sender: any, name: string) {
|
||||
let pluginFile = fs.concat(__dirname + '', name)
|
||||
if (!fs.exists(pluginFile)) {
|
||||
@@ -289,7 +304,7 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
|
||||
cmdinstall(sender: any, name: string) {
|
||||
if (!name) { return this.i18n(sender, 'plugin.name.empty') }
|
||||
if (this.pluginManager.getPlugins().has(name)) {
|
||||
|
||||
this.i18n(sender, 'install.already', { name, version: this.pluginManager.getPlugins().get(name).description.version })
|
||||
return
|
||||
}
|
||||
this.download(sender, name, false, () => {
|
||||
@@ -312,6 +327,7 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
|
||||
let enginePath = fs.path(fs.file(root, 'node_modules'))
|
||||
if (enginePath.startsWith(root)) {
|
||||
try {
|
||||
this.i18n(sender, 'upgrade.start')
|
||||
base.delete(enginePath)
|
||||
this.cmdrestart(sender)
|
||||
} catch (ex) {
|
||||
@@ -367,34 +383,49 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
|
||||
}
|
||||
|
||||
cmdrestart(sender: any) {
|
||||
if (this.serverType === "sponge") {
|
||||
setTimeout(() => this.server.dispatchConsoleCommand('sponge plugins reload'), 0)
|
||||
return
|
||||
}
|
||||
try {
|
||||
this.logger.sender(sender, '§6Reloading §3MiaoScript Engine...')
|
||||
ScriptEngineContextHolder.disableEngine()
|
||||
Packages.java.lang.System.gc()
|
||||
ScriptEngineContextHolder.enableEngine()
|
||||
this.logger.sender(sender, '§3MiaoScript Engine §6Reload §aSuccessful...')
|
||||
} catch (ex) {
|
||||
this.logger.sender(sender, "§3MiaoScript Engine §6Reload §cError! ERR: " + ex)
|
||||
this.logger.sender(sender, this.logger.stack(ex))
|
||||
}
|
||||
setTimeout(() => {
|
||||
if (this.serverType === "sponge") {
|
||||
this.server.dispatchConsoleCommand('sponge plugins reload')
|
||||
return
|
||||
}
|
||||
try {
|
||||
this.logger.sender(sender, '§6Reloading §3MiaoScript Engine...')
|
||||
ScriptEngineContextHolder.disableEngine()
|
||||
Packages.java.lang.System.gc()
|
||||
ScriptEngineContextHolder.enableEngine()
|
||||
this.logger.sender(sender, '§3MiaoScript Engine §6Reload §aSuccessful...')
|
||||
} catch (ex) {
|
||||
this.logger.sender(sender, "§3MiaoScript Engine §6Reload §cError! ERR: " + ex)
|
||||
this.logger.sender(sender, this.logger.stack(ex))
|
||||
}
|
||||
}, 0)
|
||||
}
|
||||
|
||||
cmdrun(sender: any, ...args: any[]) {
|
||||
try {
|
||||
let script = args.join(' ')
|
||||
this.i18n(sender, 'run.script', { script })
|
||||
let result = this.runCode(script, sender)
|
||||
let result = this.runCode(script, sender, this)
|
||||
this.i18n(sender, 'run.result', { result: result == undefined ? this.translate.translate('run.noresult') : result + '' })
|
||||
} catch (ex) {
|
||||
this.logger.sender(sender, this.logger.stack(ex))
|
||||
}
|
||||
}
|
||||
|
||||
private runCode(code: string, sender: any) {
|
||||
cmdprun(sender: any, name: string, ...args: any[]) {
|
||||
try {
|
||||
if (!this.pluginManager.getPlugins().has(name)) { return this.logger.sender(sender, `§4插件 §c${name} §4不存在!`) }
|
||||
let script = args.join(' ')
|
||||
this.i18n(sender, 'prun.script', { name })
|
||||
this.i18n(sender, 'run.script', { script })
|
||||
let result = this.runCode(script, sender, this.pluginManager.getPlugins().get(name))
|
||||
this.i18n(sender, 'run.result', { result: result == undefined ? this.translate.translate('run.noresult') : typeof result == "string" ? result : JSON.stringify(result) })
|
||||
} catch (ex) {
|
||||
this.logger.sender(sender, this.logger.stack(ex))
|
||||
}
|
||||
}
|
||||
|
||||
private runCode(code: string, sender: any, _this: any) {
|
||||
let paramNames = [
|
||||
'sender',
|
||||
'reflect',
|
||||
@@ -415,8 +446,8 @@ if (this.serverType == "spring") {
|
||||
var db = dbm.getMainDatabase()
|
||||
var df = base.getInstance().getAutowireCapableBeanFactory()
|
||||
}
|
||||
return ''+ eval(${JSON.stringify(code)});`)
|
||||
return tfunc.apply(this, params) + ''
|
||||
return eval(${JSON.stringify(code)});`)
|
||||
return tfunc.apply(_this, params)
|
||||
}
|
||||
|
||||
cmddeploy(sender: any, name: any) {
|
||||
@@ -430,7 +461,7 @@ return ''+ eval(${JSON.stringify(code)});`)
|
||||
version: plugin.description.version,
|
||||
source: base.read((plugin.description.source || plugin.description.loadMetadata.file).toString())
|
||||
})
|
||||
this.i18n(sender, result.code == 200 ? 'deploy.success' : 'deploy.fail', { name, msg: result.msg })
|
||||
this.i18n(sender, result.code == 200 ? 'deploy.success' : 'deploy.fail', { name, version: plugin.description.version, msg: result.msg })
|
||||
}
|
||||
}).async().submit()
|
||||
}
|
||||
@@ -445,8 +476,8 @@ return ''+ eval(${JSON.stringify(code)});`)
|
||||
}
|
||||
|
||||
@Tab({ alias: ['gmspm', 'bungeemspm'] })
|
||||
tabmspm(args: string | any[]) {
|
||||
if (args.length === 1) { return ['list', 'install', 'update', 'upgrade', 'reload', 'restart', 'run', 'help', 'create', 'deploy'] }
|
||||
tabmspm(_sender: any, _command: any, args: string | any[]) {
|
||||
if (args.length === 1) { return ['list', 'install', 'update', 'upgrade', 'reload', 'restart', 'run', 'prun', 'sudo', 'help', 'create', 'deploy'] }
|
||||
if (args.length > 1) {
|
||||
switch (args[0]) {
|
||||
case "list":
|
||||
@@ -457,6 +488,12 @@ return ''+ eval(${JSON.stringify(code)});`)
|
||||
if (args.length == 2) return ["system", ...this.pluginManager.getPlugins().keys()]
|
||||
if (args.length == 3 && args[1] == "system") return ["confirm"]
|
||||
return []
|
||||
case "prun":
|
||||
if (args.length == 2) return [...this.pluginManager.getPlugins().keys()]
|
||||
return []
|
||||
case "sudo":
|
||||
if (args.length == 2) return Java.from(this.server.getOnlinePlayers()).map(p => p.getName())
|
||||
return []
|
||||
case "update":
|
||||
case "load":
|
||||
case "unload":
|
||||
|
||||
1
packages/protocol/.npmignore
Symbolic link
1
packages/protocol/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
||||
../../.npmignore
|
||||
27
packages/protocol/package.json
Normal file
27
packages/protocol/package.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "@ccms/protocol",
|
||||
"version": "0.10.0",
|
||||
"description": "MiaoScript protocol package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
"minecraft",
|
||||
"bukkit",
|
||||
"sponge"
|
||||
],
|
||||
"author": "MiaoWoo <admin@yumc.pw>",
|
||||
"homepage": "https://github.com/circlecloud/ms.git",
|
||||
"license": "ISC",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"clean": "rimraf dist",
|
||||
"watch": "tsc --watch",
|
||||
"build": "yarn clean && tsc",
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.0.3"
|
||||
}
|
||||
}
|
||||
1
packages/protocol/src/index.ts
Normal file
1
packages/protocol/src/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { }
|
||||
7
packages/protocol/tsconfig.json
Normal file
7
packages/protocol/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "src",
|
||||
"outDir": "dist"
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/sponge",
|
||||
"version": "0.9.4",
|
||||
"version": "0.10.0",
|
||||
"description": "MiaoScript api package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,14 +19,14 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@javatypes/sponge-api": "^0.0.2",
|
||||
"@javatypes/sponge-api": "^0.0.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.0.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.9.4",
|
||||
"@ccms/common": "^0.9.4",
|
||||
"@ccms/container": "^0.9.4"
|
||||
"@ccms/api": "^0.10.0",
|
||||
"@ccms/common": "^0.10.0",
|
||||
"@ccms/container": "^0.10.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/spring",
|
||||
"version": "0.9.4",
|
||||
"version": "0.10.0",
|
||||
"description": "MiaoScript spring package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -24,9 +24,9 @@
|
||||
"typescript": "^4.0.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.9.4",
|
||||
"@ccms/common": "^0.9.4",
|
||||
"@ccms/container": "^0.9.4",
|
||||
"@ccms/database": "^0.9.4"
|
||||
"@ccms/api": "^0.10.0",
|
||||
"@ccms/common": "^0.10.0",
|
||||
"@ccms/container": "^0.10.0",
|
||||
"@ccms/database": "^0.10.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,32 @@
|
||||
import { server } from '@ccms/api'
|
||||
import { provideSingleton, inject } from '@ccms/container'
|
||||
import { NativePluginManager } from '@ccms/api'
|
||||
import { constants, server } from '@ccms/api'
|
||||
import { provideSingleton, postConstruct, Autowired, Container, ContainerInstance } from '@ccms/container'
|
||||
import { CommandMap } from './internal/command'
|
||||
|
||||
@provideSingleton(server.Server)
|
||||
export class SpringServer implements server.Server {
|
||||
@inject(CommandMap)
|
||||
export class SpringServer extends server.Server {
|
||||
@Autowired(ContainerInstance)
|
||||
private container: Container
|
||||
@Autowired()
|
||||
private commandMap: CommandMap
|
||||
|
||||
private nettyPipeline = base.getInstance().getAutowireCapableBeanFactory()
|
||||
private rootLogger = Packages.org.slf4j.LoggerFactory.getLogger("root") || global.logger
|
||||
|
||||
@postConstruct()
|
||||
initialize() {
|
||||
this.container.bind(constants.ServiceIdentifier.NettyPipeline).toConstantValue(this.nettyPipeline)
|
||||
this.container.bind(constants.ServiceIdentifier.RootLogger).toConstantValue(this.rootLogger)
|
||||
}
|
||||
|
||||
getVersion(): string {
|
||||
return "SpringFramework"
|
||||
}
|
||||
getPlayer(name: string) {
|
||||
throw new Error("Method not implemented.")
|
||||
}
|
||||
getOnlinePlayers(): any[] {
|
||||
throw new Error("Method not implemented.")
|
||||
}
|
||||
getConsoleSender() {
|
||||
return {
|
||||
name: 'CONSOLE',
|
||||
sendMessage: (message: string) => console.console(message)
|
||||
}
|
||||
}
|
||||
getService(service: string) {
|
||||
throw new Error("Method not implemented.")
|
||||
}
|
||||
dispatchCommand(sender: any, command: string): boolean {
|
||||
let cmd_args = command.split(" ")
|
||||
return this.commandMap.dispatch(sender, cmd_args.shift(), cmd_args || [])
|
||||
@@ -33,16 +34,10 @@ export class SpringServer implements server.Server {
|
||||
dispatchConsoleCommand(command: string): boolean {
|
||||
return this.dispatchCommand(this.getConsoleSender(), command)
|
||||
}
|
||||
getPluginsFolder(): string {
|
||||
throw new Error("Method not implemented.")
|
||||
}
|
||||
getNativePluginManager(): NativePluginManager {
|
||||
throw new Error("Method not implemented.")
|
||||
}
|
||||
getNettyPipeline() {
|
||||
return base.getInstance().getAutowireCapableBeanFactory()
|
||||
return this.nettyPipeline
|
||||
}
|
||||
getRootLogger() {
|
||||
return Packages.org.slf4j.LoggerFactory.getLogger("root") || global.logger
|
||||
return this.rootLogger
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/web",
|
||||
"version": "0.9.4",
|
||||
"version": "0.10.0",
|
||||
"description": "MiaoScript web package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,17 +19,17 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@javatypes/jdk": "^0.0.2",
|
||||
"@javatypes/spring-beans": "^0.0.2",
|
||||
"@javatypes/spring-core": "^0.0.2",
|
||||
"@javatypes/spring-web": "^0.0.2",
|
||||
"@javatypes/tomcat": "^0.0.2",
|
||||
"@javatypes/jdk": "^0.0.3",
|
||||
"@javatypes/spring-beans": "^0.0.3",
|
||||
"@javatypes/spring-core": "^0.0.3",
|
||||
"@javatypes/spring-web": "^0.0.3",
|
||||
"@javatypes/tomcat": "^0.0.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.0.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.9.4",
|
||||
"@ccms/container": "^0.9.4"
|
||||
"@ccms/api": "^0.10.0",
|
||||
"@ccms/container": "^0.10.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ccms/websocket",
|
||||
"version": "0.9.4",
|
||||
"version": "0.10.0",
|
||||
"description": "MiaoScript websocket package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -19,8 +19,8 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ccms/nashorn": "^0.9.4",
|
||||
"@javatypes/tomcat-websocket-api": "^0.0.2",
|
||||
"@ccms/nashorn": "^0.10.0",
|
||||
"@javatypes/tomcat-websocket-api": "^0.0.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.0.3"
|
||||
|
||||
Reference in New Issue
Block a user