Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8f3c799531 | |||
| 3389dbd566 | |||
| 54604e10b8 | |||
| d7247bae19 | |||
| 3ee2dcad0b | |||
| bc19021c63 | |||
| e9a4f2f351 |
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"version": "0.9.2",
|
"version": "0.9.3",
|
||||||
"useWorkspaces": true,
|
"useWorkspaces": true,
|
||||||
"npmClient": "yarn",
|
"npmClient": "yarn",
|
||||||
"packages": [
|
"packages": [
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/amqp",
|
"name": "@ccms/amqp",
|
||||||
"version": "0.9.2",
|
"version": "0.9.3",
|
||||||
"description": "MiaoScript amqp package",
|
"description": "MiaoScript amqp package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,12 +19,12 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.9.2",
|
"@ccms/api": "^0.9.3",
|
||||||
"@ccms/common": "^0.9.2",
|
"@ccms/common": "^0.9.3",
|
||||||
"@ccms/container": "^0.9.2"
|
"@ccms/container": "^0.9.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "^0.9.0",
|
"@ccms/nashorn": "^0.9.3",
|
||||||
"@javatypes/amqp-client": "^0.0.2",
|
"@javatypes/amqp-client": "^0.0.2",
|
||||||
"@javatypes/spring-amqp": "^0.0.2",
|
"@javatypes/spring-amqp": "^0.0.2",
|
||||||
"@javatypes/spring-rabbit": "^0.0.2",
|
"@javatypes/spring-rabbit": "^0.0.2",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/api",
|
"name": "@ccms/api",
|
||||||
"version": "0.9.2",
|
"version": "0.9.3",
|
||||||
"description": "MiaoScript api package",
|
"description": "MiaoScript api package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,9 +19,9 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/common": "^0.9.2",
|
"@ccms/common": "^0.9.3",
|
||||||
"@ccms/container": "^0.9.2",
|
"@ccms/container": "^0.9.3",
|
||||||
"@ccms/ployfill": "^0.9.2",
|
"@ccms/ployfill": "^0.9.3",
|
||||||
"base64-js": "^1.3.1",
|
"base64-js": "^1.3.1",
|
||||||
"source-map-builder": "^0.0.7"
|
"source-map-builder": "^0.0.7"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { injectable } from "@ccms/container"
|
import { injectable, inject, provideSingleton } from "@ccms/container"
|
||||||
|
|
||||||
export namespace channel {
|
export namespace channel {
|
||||||
/**
|
/**
|
||||||
@@ -63,4 +63,156 @@ export namespace channel {
|
|||||||
*/
|
*/
|
||||||
abstract unregister(channel: string, listener?: any): void
|
abstract unregister(channel: string, listener?: any): void
|
||||||
}
|
}
|
||||||
|
export namespace proxy {
|
||||||
|
const CHANNEL_NAME = "BungeeCord"
|
||||||
|
const ByteArrayOutputStream = Java.type('java.io.ByteArrayOutputStream')
|
||||||
|
const DataOutputStream = Java.type('java.io.DataOutputStream')
|
||||||
|
const ByteStreams = Java.type('com.google.common.io.ByteStreams')
|
||||||
|
namespace bungeecord {
|
||||||
|
export class SubChannelBuilder {
|
||||||
|
private channel: Channel
|
||||||
|
private player: any
|
||||||
|
private params: string[]
|
||||||
|
constructor(channel: Channel, player: any) {
|
||||||
|
this.channel = channel
|
||||||
|
this.player = player
|
||||||
|
this.params = []
|
||||||
|
}
|
||||||
|
connect(server: string) {
|
||||||
|
this.params.push("Connect")
|
||||||
|
this.params.push(server)
|
||||||
|
}
|
||||||
|
connectOther(player: string, server: string) {
|
||||||
|
this.params.push("ConnectOther")
|
||||||
|
this.params.push(player)
|
||||||
|
this.params.push(server)
|
||||||
|
}
|
||||||
|
ip() {
|
||||||
|
this.params.push("IP")
|
||||||
|
}
|
||||||
|
ipOther(player: string) {
|
||||||
|
this.params.push("IPOther")
|
||||||
|
this.params.push(player)
|
||||||
|
}
|
||||||
|
playerCount(server: string | "ALL") {
|
||||||
|
this.params.push("PlayerCount")
|
||||||
|
this.params.push(server)
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 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[] playerList = in.readUTF().split(", ");
|
||||||
|
*/
|
||||||
|
playerList(server: string | "ALL") {
|
||||||
|
this.params.push("PlayerList")
|
||||||
|
this.params.push(server)
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Get a list of server name strings, as defined in BungeeCord's config.yml
|
||||||
|
* Response:
|
||||||
|
* String[] serverList = in.readUTF().split(", ");
|
||||||
|
*/
|
||||||
|
getServers() {
|
||||||
|
this.params.push("GetServers")
|
||||||
|
return this.finalSend()
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Get this server's name, as defined in BungeeCord's config.yml
|
||||||
|
*/
|
||||||
|
getServer() {
|
||||||
|
this.params.push("GetServer")
|
||||||
|
return this.finalSend()
|
||||||
|
}
|
||||||
|
broadcast(message: string) {
|
||||||
|
this.message("ALL", message)
|
||||||
|
return this.finalSend()
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Send a message (as in, a chat message) to the specified player.
|
||||||
|
* @param player who reciver message
|
||||||
|
* @param message message content
|
||||||
|
*/
|
||||||
|
message(player: string | "ALL", message: string) {
|
||||||
|
this.params.push("Message")
|
||||||
|
this.params.push(player)
|
||||||
|
this.params.push(message)
|
||||||
|
return this.finalSend()
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Send a raw message (as in, a chat message) to the specified player. The advantage of this method over Message is that you can include click events and hover events.
|
||||||
|
* @param player who reciver message
|
||||||
|
* @param message message content
|
||||||
|
*/
|
||||||
|
messageRaw(player: string | "ALL", json: string) {
|
||||||
|
this.params.push("MessageRaw")
|
||||||
|
this.params.push(player)
|
||||||
|
this.params.push(json)
|
||||||
|
return this.finalSend()
|
||||||
|
}
|
||||||
|
forwardAll(channel: string, data: any) {
|
||||||
|
this.forward("ALL", channel, data)
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
* @param data data
|
||||||
|
*/
|
||||||
|
forward(server: string | "ALL", channel: string, data: any) {
|
||||||
|
this.params.push("Forward")
|
||||||
|
this.params.push(server)
|
||||||
|
this.params.push(channel)
|
||||||
|
this.params.push(typeof data === "string" ? data : JSON.stringify(data))
|
||||||
|
return this.finalSend()
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
* @param data data
|
||||||
|
*/
|
||||||
|
forwardToPlayer(server: string | "ALL", channel: string, data: any) {
|
||||||
|
this.params.push("Forward")
|
||||||
|
this.params.push(server)
|
||||||
|
this.params.push(channel)
|
||||||
|
this.params.push(typeof data === "string" ? data : JSON.stringify(data))
|
||||||
|
return this.finalSend()
|
||||||
|
}
|
||||||
|
generic(...args: string[]) {
|
||||||
|
args && this.params.concat(...args)
|
||||||
|
return this.finalSend()
|
||||||
|
}
|
||||||
|
private send(...middlewares: ((out: java.io.DataOutputStream) => void)[]) {
|
||||||
|
let byteArray = new ByteArrayOutputStream()
|
||||||
|
let out = new DataOutputStream(byteArray)
|
||||||
|
this.params.forEach(utf => out.writeUTF(utf))
|
||||||
|
for (let middleware of middlewares) {
|
||||||
|
middleware(out)
|
||||||
|
}
|
||||||
|
this.channel.send(this.player, CHANNEL_NAME, byteArray.toByteArray())
|
||||||
|
}
|
||||||
|
private finalSend() {
|
||||||
|
return {
|
||||||
|
send: this.send.bind(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@provideSingleton(BungeeCord)
|
||||||
|
export class BungeeCord {
|
||||||
|
@inject(Channel)
|
||||||
|
private channel: Channel
|
||||||
|
/**
|
||||||
|
* 获得代理
|
||||||
|
* @param player 玩家
|
||||||
|
*/
|
||||||
|
for(player: any): bungeecord.SubChannelBuilder {
|
||||||
|
return new bungeecord.SubChannelBuilder(this.channel, player)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,15 @@ import { injectable } from '@ccms/container'
|
|||||||
export namespace chat {
|
export namespace chat {
|
||||||
@injectable()
|
@injectable()
|
||||||
export abstract class Chat {
|
export abstract class Chat {
|
||||||
|
/**
|
||||||
|
* sendJsonChat
|
||||||
|
* @param sender reciver
|
||||||
|
* @param json json
|
||||||
|
* @param type chat Type 0: chat 1: system 2: actionBar
|
||||||
|
*/
|
||||||
|
sendJson(sender: any, json: string | object, type = 0) {
|
||||||
|
throw new Error("Method not implemented.")
|
||||||
|
}
|
||||||
sendMessage(sender: any, message: string) {
|
sendMessage(sender: any, message: string) {
|
||||||
throw new Error("Method not implemented.")
|
throw new Error("Method not implemented.")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ export namespace command {
|
|||||||
this.onTabComplete(plugin, cmd, exec.tab)
|
this.onTabComplete(plugin, cmd, exec.tab)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public tabComplete(sender: any, input: string, index?: number): string[] {
|
||||||
|
throw new Error("Method not implemented.")
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 取消命令注册
|
* 取消命令注册
|
||||||
* @param plugin 插件
|
* @param plugin 插件
|
||||||
|
|||||||
@@ -138,6 +138,8 @@ export namespace event {
|
|||||||
// add to cache Be used for close plugin to close event
|
// add to cache Be used for close plugin to close event
|
||||||
if (!listenerMap[name]) listenerMap[name] = []
|
if (!listenerMap[name]) listenerMap[name] = []
|
||||||
var off = () => {
|
var off = () => {
|
||||||
|
if (off['offed']) return
|
||||||
|
off['offed'] = true
|
||||||
this.unregister(eventCls, listener)
|
this.unregister(eventCls, listener)
|
||||||
console.debug(i18n.translate("ms.api.event.unregister", { name, event: this.class2Name(eventCls), exec: executor }))
|
console.debug(i18n.translate("ms.api.event.unregister", { name, event: this.class2Name(eventCls), exec: executor }))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { injectable } from '@ccms/container'
|
||||||
|
|
||||||
export namespace plugin {
|
export namespace plugin {
|
||||||
/**
|
/**
|
||||||
* MiaoScript Plugin
|
* MiaoScript Plugin
|
||||||
@@ -11,23 +13,20 @@ export namespace plugin {
|
|||||||
* Runtime Plugin Instance
|
* Runtime Plugin Instance
|
||||||
*/
|
*/
|
||||||
export const PluginInstance = Symbol("PluginInstance")
|
export const PluginInstance = Symbol("PluginInstance")
|
||||||
/**
|
|
||||||
* MiaoScript Plugin Manager Symbol
|
|
||||||
*/
|
|
||||||
export const PluginManager = Symbol("PluginManager")
|
|
||||||
/**
|
/**
|
||||||
* MiaoScript Plugin Manager Interface
|
* MiaoScript Plugin Manager Interface
|
||||||
*/
|
*/
|
||||||
export interface PluginManager {
|
@injectable()
|
||||||
scan(folder: string): void
|
export abstract class PluginManager {
|
||||||
build(): void
|
abstract scan(folder: string): void
|
||||||
loadFromFile(file: string, scanner?: plugin.PluginScanner): Plugin
|
abstract build(): void
|
||||||
load(...args: any[]): void
|
abstract loadFromFile(file: string, scanner?: plugin.PluginScanner): Plugin
|
||||||
enable(...args: any[]): void
|
abstract load(...args: any[]): void
|
||||||
disable(...args: any[]): void
|
abstract enable(...args: any[]): void
|
||||||
reload(...args: any[]): void
|
abstract disable(...args: any[]): void
|
||||||
getPlugin(name: string): plugin.Plugin
|
abstract reload(...args: any[]): void
|
||||||
getPlugins(): Map<string, plugin.Plugin>
|
abstract getPlugin(name: string): plugin.Plugin
|
||||||
|
abstract getPlugins(): Map<string, plugin.Plugin>
|
||||||
}
|
}
|
||||||
export const PluginScanner = Symbol("PluginScanner")
|
export const PluginScanner = Symbol("PluginScanner")
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import { injectable, inject } from '@ccms/container'
|
|||||||
import { NativePluginManager } from './native_plugin'
|
import { NativePluginManager } from './native_plugin'
|
||||||
import { constants } from '../../constants'
|
import { constants } from '../../constants'
|
||||||
|
|
||||||
|
export { NativePluginManager } from './native_plugin'
|
||||||
|
|
||||||
export namespace server {
|
export namespace server {
|
||||||
/**
|
/**
|
||||||
* Runtime ServerType
|
* Runtime ServerType
|
||||||
@@ -13,10 +15,6 @@ export namespace server {
|
|||||||
* Runtime Console
|
* Runtime Console
|
||||||
*/
|
*/
|
||||||
export const Console = Symbol("Console")
|
export const Console = Symbol("Console")
|
||||||
/**
|
|
||||||
* MiaoScript Server
|
|
||||||
*/
|
|
||||||
export const Server = Symbol("Server")
|
|
||||||
/**
|
/**
|
||||||
* Runtime Server Instance
|
* Runtime Server Instance
|
||||||
*/
|
*/
|
||||||
@@ -24,21 +22,44 @@ export namespace server {
|
|||||||
/**
|
/**
|
||||||
* MiaoScript Server
|
* MiaoScript Server
|
||||||
*/
|
*/
|
||||||
export interface Server {
|
@injectable()
|
||||||
getVersion(): string
|
export abstract class Server {
|
||||||
getPlayer(name: string): any
|
getVersion(): string {
|
||||||
getOnlinePlayers(): any[]
|
throw new Error("Method not implemented.")
|
||||||
getConsoleSender(): any
|
}
|
||||||
getService(service: string): any
|
getPlayer(name: string): any {
|
||||||
dispatchCommand(sender: string | any, command: string): boolean
|
throw new Error("Method not implemented.")
|
||||||
dispatchConsoleCommand(command: string): boolean
|
}
|
||||||
getPluginsFolder(): string
|
getOnlinePlayers(): any[] {
|
||||||
getNativePluginManager(): NativePluginManager
|
throw new Error("Method not implemented.")
|
||||||
getDedicatedServer?(): any
|
}
|
||||||
getNettyPipeline(): any
|
getConsoleSender(): any {
|
||||||
getRootLogger(): any
|
throw new Error("Method not implemented.")
|
||||||
sendJson(sender: string | any, json: object | string): void
|
}
|
||||||
tabComplete?(sender: string | any, input: string, index?: number): string[]
|
getService(service: string): any {
|
||||||
|
throw new Error("Method not implemented.")
|
||||||
|
}
|
||||||
|
dispatchCommand(sender: string | any, command: string): boolean {
|
||||||
|
throw new Error("Method not implemented.")
|
||||||
|
}
|
||||||
|
dispatchConsoleCommand(command: string): boolean {
|
||||||
|
throw new Error("Method not implemented.")
|
||||||
|
}
|
||||||
|
getPluginsFolder(): string {
|
||||||
|
throw new Error("Method not implemented.")
|
||||||
|
}
|
||||||
|
getNativePluginManager(): NativePluginManager {
|
||||||
|
throw new Error("Method not implemented.")
|
||||||
|
}
|
||||||
|
getDedicatedServer?(): any {
|
||||||
|
throw new Error("Method not implemented.")
|
||||||
|
}
|
||||||
|
getNettyPipeline(): any {
|
||||||
|
throw new Error("Method not implemented.")
|
||||||
|
}
|
||||||
|
getRootLogger(): any {
|
||||||
|
throw new Error("Method not implemented.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@injectable()
|
@injectable()
|
||||||
export class ServerChecker {
|
export class ServerChecker {
|
||||||
@@ -58,56 +79,15 @@ export namespace server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
@injectable()
|
@injectable()
|
||||||
export abstract class ReflectServer implements server.Server {
|
export abstract class ReflectServer extends server.Server {
|
||||||
protected pipeline: any
|
protected pipeline: any
|
||||||
protected rootLogger: any
|
protected rootLogger: any
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
super()
|
||||||
this.reflect()
|
this.reflect()
|
||||||
}
|
}
|
||||||
|
|
||||||
getVersion(): string {
|
|
||||||
throw new Error("Method not implemented.")
|
|
||||||
}
|
|
||||||
getPlayer(name: string) {
|
|
||||||
throw new Error("Method not implemented.")
|
|
||||||
}
|
|
||||||
getOnlinePlayers(): any[] {
|
|
||||||
throw new Error("Method not implemented.")
|
|
||||||
}
|
|
||||||
getConsoleSender() {
|
|
||||||
throw new Error("Method not implemented.")
|
|
||||||
}
|
|
||||||
getService(service: string) {
|
|
||||||
throw new Error("Method not implemented.")
|
|
||||||
}
|
|
||||||
dispatchCommand(sender: any, command: string): boolean {
|
|
||||||
throw new Error("Method not implemented.")
|
|
||||||
}
|
|
||||||
dispatchConsoleCommand(command: string): boolean {
|
|
||||||
throw new Error("Method not implemented.")
|
|
||||||
}
|
|
||||||
getPluginsFolder(): string {
|
|
||||||
throw new Error("Method not implemented.")
|
|
||||||
}
|
|
||||||
getNativePluginManager(): NativePluginManager {
|
|
||||||
throw new Error("Method not implemented.")
|
|
||||||
}
|
|
||||||
getDedicatedServer() {
|
|
||||||
throw new Error("Method not implemented.")
|
|
||||||
}
|
|
||||||
getNettyPipeline() {
|
|
||||||
throw new Error("Method not implemented.")
|
|
||||||
}
|
|
||||||
getRootLogger() {
|
|
||||||
throw new Error("Method not implemented.")
|
|
||||||
}
|
|
||||||
sendJson(sender: any, json: string | object): void {
|
|
||||||
throw new Error("Method not implemented.")
|
|
||||||
}
|
|
||||||
tabComplete?(sender: any, input: string, index?: number): string[] {
|
|
||||||
throw new Error("Method not implemented.")
|
|
||||||
}
|
|
||||||
protected reflect() {
|
protected reflect() {
|
||||||
try {
|
try {
|
||||||
let consoleServer = this.getDedicatedServer()
|
let consoleServer = this.getDedicatedServer()
|
||||||
|
|||||||
@@ -1,34 +1,62 @@
|
|||||||
|
import { plugin } from './index'
|
||||||
|
import { injectable } from '@ccms/container'
|
||||||
|
|
||||||
export namespace task {
|
export namespace task {
|
||||||
export const TaskManager = Symbol('TaskManager')
|
@injectable()
|
||||||
export interface TaskManager {
|
export abstract class TaskManager {
|
||||||
|
protected cacheTasks = new Map<string, task.Task[]>()
|
||||||
|
|
||||||
|
protected pluginCreate(plugin: plugin.Plugin, task: task.Task) {
|
||||||
|
if (!this.cacheTasks.has(plugin.description.name)) {
|
||||||
|
this.cacheTasks.set(plugin.description.name, [])
|
||||||
|
}
|
||||||
|
this.cacheTasks.get(plugin.description.name).push(task)
|
||||||
|
return task
|
||||||
|
}
|
||||||
|
protected pluginDisable(plugin: plugin.Plugin) {
|
||||||
|
if (this.cacheTasks.has(plugin.description.name)) {
|
||||||
|
this.cacheTasks.get(plugin.description.name).forEach(task => task.cancel())
|
||||||
|
this.cacheTasks.delete(plugin.description.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 创建任务
|
* 创建任务
|
||||||
* @param func 任务内容
|
* @param func 任务内容
|
||||||
*/
|
*/
|
||||||
create(func: Function): task.Task;
|
create(func: Function, plugin?: plugin.Plugin): task.Task {
|
||||||
|
if (Object.prototype.toString.call(func) !== "[object Function]") { throw TypeError('第一个参数 Task 必须为 function !') };
|
||||||
|
let task = this.create0(func)
|
||||||
|
if (plugin) { return this.pluginCreate(plugin, task) }
|
||||||
|
return task
|
||||||
|
}
|
||||||
|
abstract create0(func: Function): task.Task
|
||||||
/**
|
/**
|
||||||
* 在主线程执行代码
|
* 在主线程执行代码
|
||||||
* @param func 执行内容
|
* @param func 执行内容
|
||||||
*/
|
*/
|
||||||
callSyncMethod(func: Function): any;
|
abstract callSyncMethod(func: Function): any
|
||||||
/**
|
/**
|
||||||
* 关闭任务管理器
|
* 关闭任务管理器
|
||||||
*/
|
*/
|
||||||
disable();
|
disable(plugin?: plugin.Plugin) {
|
||||||
|
if (plugin) { return this.pluginDisable(plugin) }
|
||||||
|
this.disable0()
|
||||||
|
}
|
||||||
|
abstract disable0()
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 任务抽象
|
* 任务抽象
|
||||||
*/
|
*/
|
||||||
export abstract class Task {
|
export abstract class Task {
|
||||||
protected plugin: any;
|
protected plugin: any
|
||||||
protected func: Function;
|
protected func: Function
|
||||||
protected isAsync: boolean = false;
|
protected isAsync: boolean = false;
|
||||||
protected laterTime: number = 0;
|
protected laterTime: number = 0;
|
||||||
protected interval: number = 0;
|
protected interval: number = 0;
|
||||||
|
|
||||||
constructor(plugin: any, func: Function) {
|
constructor(plugin: any, func: Function) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin
|
||||||
this.func = func;
|
this.func = func
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,8 +64,8 @@ export namespace task {
|
|||||||
* @param isAsync 是否异步
|
* @param isAsync 是否异步
|
||||||
*/
|
*/
|
||||||
async(isAsync: boolean = true): task.Task {
|
async(isAsync: boolean = true): task.Task {
|
||||||
this.isAsync = isAsync;
|
this.isAsync = isAsync
|
||||||
return this;
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,8 +73,8 @@ export namespace task {
|
|||||||
* @param tick 延时 Tick
|
* @param tick 延时 Tick
|
||||||
*/
|
*/
|
||||||
later(tick: number): task.Task {
|
later(tick: number): task.Task {
|
||||||
this.laterTime = tick;
|
this.laterTime = tick
|
||||||
return this;
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,16 +82,23 @@ export namespace task {
|
|||||||
* @param tick 循环时间 Tick
|
* @param tick 循环时间 Tick
|
||||||
*/
|
*/
|
||||||
timer(tick: number): task.Task {
|
timer(tick: number): task.Task {
|
||||||
this.interval = tick;
|
this.interval = tick
|
||||||
return this;
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消任务
|
||||||
|
*/
|
||||||
|
cancel(): boolean {
|
||||||
|
throw new Error("Method not implemented.")
|
||||||
}
|
}
|
||||||
|
|
||||||
protected run(...args: any[]): void {
|
protected run(...args: any[]): void {
|
||||||
try {
|
try {
|
||||||
this.func(...args);
|
this.func(...args)
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.console('§4插件执行任务时发生错误', ex)
|
console.console('§4插件执行任务时发生错误', ex)
|
||||||
console.ex(ex);
|
console.ex(ex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,12 +106,22 @@ export namespace task {
|
|||||||
* 提交任务
|
* 提交任务
|
||||||
* @param args 任务参数
|
* @param args 任务参数
|
||||||
*/
|
*/
|
||||||
abstract submit(...args: any[]): Cancelable;
|
submit(...args: any[]): Cancelable {
|
||||||
|
let cancelable = this.submit0(...args)
|
||||||
|
this.cancel = cancelable.cancel
|
||||||
|
return cancelable
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提交任务
|
||||||
|
* @param args 任务参数
|
||||||
|
*/
|
||||||
|
abstract submit0(...args: any[]): Cancelable
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 返可取消的对象
|
* 返可取消的对象
|
||||||
*/
|
*/
|
||||||
export interface Cancelable {
|
export interface Cancelable {
|
||||||
cancel(): boolean;
|
cancel(): boolean
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/bukkit",
|
"name": "@ccms/bukkit",
|
||||||
"version": "0.9.2",
|
"version": "0.9.3",
|
||||||
"description": "MiaoScript bukkit package",
|
"description": "MiaoScript bukkit package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -25,8 +25,8 @@
|
|||||||
"typescript": "^3.9.6"
|
"typescript": "^3.9.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.9.2",
|
"@ccms/api": "^0.9.3",
|
||||||
"@ccms/common": "^0.9.2",
|
"@ccms/common": "^0.9.3",
|
||||||
"@ccms/container": "^0.9.2"
|
"@ccms/container": "^0.9.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,14 @@ import bukkitChat from './enhance/chat'
|
|||||||
|
|
||||||
@provideSingleton(chat.Chat)
|
@provideSingleton(chat.Chat)
|
||||||
export class BukkitChat extends chat.Chat {
|
export class BukkitChat extends chat.Chat {
|
||||||
|
sendJson(sender: any, json: string | object, type = 0) {
|
||||||
|
bukkitChat.send(sender, typeof json === "string" ? json : JSON.stringify(json), type)
|
||||||
|
}
|
||||||
sendMessage(sender: any, message: string) {
|
sendMessage(sender: any, message: string) {
|
||||||
bukkitChat.send(sender, JSON.stringify({ text: message }), 0)
|
this.sendJson(sender, { text: message }, 0)
|
||||||
}
|
}
|
||||||
sendActionBar(sender: any, message: string) {
|
sendActionBar(sender: any, message: string) {
|
||||||
bukkitChat.send(sender, JSON.stringify({ text: message }), 2)
|
this.sendJson(sender, { text: message }, 2)
|
||||||
}
|
}
|
||||||
sendTitle(sender: any, title: string, subtitle: string = '', fadeIn: number = 20, time: number = 100, fadeOut: number = 20) {
|
sendTitle(sender: any, title: string, subtitle: string = '', fadeIn: number = 20, time: number = 100, fadeOut: number = 20) {
|
||||||
sender.sendTitle(title, subtitle, fadeIn, time, fadeOut)
|
sender.sendTitle(title, subtitle, fadeIn, time, fadeOut)
|
||||||
|
|||||||
@@ -4,44 +4,47 @@ import { command, plugin } from '@ccms/api'
|
|||||||
import * as reflect from '@ccms/common/dist/reflect'
|
import * as reflect from '@ccms/common/dist/reflect'
|
||||||
import { provideSingleton, postConstruct, inject } from '@ccms/container'
|
import { provideSingleton, postConstruct, inject } from '@ccms/container'
|
||||||
|
|
||||||
let Bukkit = org.bukkit.Bukkit;
|
let Bukkit = org.bukkit.Bukkit
|
||||||
let TabCompleter = Java.type('org.bukkit.command.TabCompleter');
|
let TabCompleter = Java.type('org.bukkit.command.TabCompleter')
|
||||||
let PluginCommand = Java.type('org.bukkit.command.PluginCommand');
|
let PluginCommand = Java.type('org.bukkit.command.PluginCommand')
|
||||||
let CommandExecutor = Java.type('org.bukkit.command.CommandExecutor');
|
let CommandExecutor = Java.type('org.bukkit.command.CommandExecutor')
|
||||||
|
|
||||||
@provideSingleton(command.Command)
|
@provideSingleton(command.Command)
|
||||||
export class BukkitCommand extends command.Command {
|
export class BukkitCommand extends command.Command {
|
||||||
@inject(plugin.PluginInstance)
|
@inject(plugin.PluginInstance)
|
||||||
private pluginInstance: any
|
private pluginInstance: any
|
||||||
private commandMap: any;
|
private commandMap: any
|
||||||
|
|
||||||
@postConstruct()
|
@postConstruct()
|
||||||
init() {
|
init() {
|
||||||
this.commandMap = reflect.on(Bukkit.getPluginManager()).get('commandMap').get();
|
this.commandMap = reflect.on(Bukkit.getPluginManager()).get('commandMap').get()
|
||||||
}
|
}
|
||||||
create(plugin: any, command: string) {
|
create(plugin: any, command: string) {
|
||||||
var cmd = this.commandMap.getCommand(command)
|
var cmd = this.commandMap.getCommand(command)
|
||||||
if (cmd && cmd instanceof PluginCommand) { return cmd };
|
if (cmd && cmd instanceof PluginCommand) { return cmd };
|
||||||
cmd = reflect.on(PluginCommand).create(command, this.pluginInstance).get();
|
cmd = reflect.on(PluginCommand).create(command, this.pluginInstance).get()
|
||||||
this.commandMap.register(plugin.description.name, cmd);
|
this.commandMap.register(plugin.description.name, cmd)
|
||||||
return cmd;
|
return cmd
|
||||||
}
|
}
|
||||||
remove(plugin: any, command: string) {
|
remove(plugin: any, command: string) {
|
||||||
var cmd = this.commandMap.getCommand(command)
|
var cmd = this.commandMap.getCommand(command)
|
||||||
if (cmd && cmd instanceof PluginCommand) {
|
if (cmd && cmd instanceof PluginCommand) {
|
||||||
cmd.unregister(this.commandMap);
|
cmd.unregister(this.commandMap)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
tabComplete(sender: any, input: string, index?: number): string[] {
|
||||||
|
return Java.from(this.commandMap.tabComplete(sender, input))
|
||||||
|
}
|
||||||
onCommand(plugin: any, command: any, executor: Function) {
|
onCommand(plugin: any, command: any, executor: Function) {
|
||||||
// 必须指定需要实现的接口类型 否则MOD服会报错
|
// 必须指定需要实现的接口类型 否则MOD服会报错
|
||||||
command.setExecutor(new CommandExecutor({
|
command.setExecutor(new CommandExecutor({
|
||||||
onCommand: super.setExecutor(plugin, command, executor)
|
onCommand: super.setExecutor(plugin, command, executor)
|
||||||
}));
|
}))
|
||||||
}
|
}
|
||||||
onTabComplete(plugin: any, command: any, tabCompleter: Function) {
|
onTabComplete(plugin: any, command: any, tabCompleter: Function) {
|
||||||
// 必须指定需要实现的接口类型 否则MOD服会报错
|
// 必须指定需要实现的接口类型 否则MOD服会报错
|
||||||
command.setTabCompleter(new TabCompleter({
|
command.setTabCompleter(new TabCompleter({
|
||||||
onTabComplete: super.setTabCompleter(plugin, command, tabCompleter)
|
onTabComplete: super.setTabCompleter(plugin, command, tabCompleter)
|
||||||
}));
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,16 +54,4 @@ export class BukkitServer extends server.ReflectServer {
|
|||||||
getRootLogger() {
|
getRootLogger() {
|
||||||
return this.rootLogger
|
return this.rootLogger
|
||||||
}
|
}
|
||||||
sendJson(sender: string | any, json: object | string): void {
|
|
||||||
if (typeof sender === "string") {
|
|
||||||
sender = this.getPlayer(sender)
|
|
||||||
}
|
|
||||||
let result = chat.json(sender, typeof json == "string" ? json : JSON.stringify(json))
|
|
||||||
if (result !== false) {
|
|
||||||
this.dispatchConsoleCommand(result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tabComplete?(sender: any, input: string, index?: number): string[] {
|
|
||||||
throw new Error("Method not implemented.")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,28 @@
|
|||||||
import { task, plugin } from '@ccms/api'
|
import { task, plugin } from '@ccms/api'
|
||||||
import { inject, provideSingleton } from '@ccms/container';
|
import { inject, provideSingleton } from '@ccms/container'
|
||||||
|
|
||||||
const Bukkit = Java.type('org.bukkit.Bukkit');
|
const Bukkit = Java.type('org.bukkit.Bukkit')
|
||||||
const BukkitRunnable = Java.type('org.bukkit.scheduler.BukkitRunnable');
|
const BukkitRunnable = Java.type('org.bukkit.scheduler.BukkitRunnable')
|
||||||
const Callable = Java.type('java.util.concurrent.Callable')
|
const Callable = Java.type('java.util.concurrent.Callable')
|
||||||
|
|
||||||
@provideSingleton(task.TaskManager)
|
@provideSingleton(task.TaskManager)
|
||||||
export class BukkitTaskManager implements task.TaskManager {
|
export class BukkitTaskManager extends task.TaskManager {
|
||||||
@inject(plugin.PluginInstance)
|
@inject(plugin.PluginInstance)
|
||||||
private pluginInstance: any;
|
private pluginInstance: any
|
||||||
|
|
||||||
create(func: Function): task.Task {
|
create0(func: Function): task.Task {
|
||||||
if (Object.prototype.toString.call(func) !== "[object Function]") { throw TypeError('第一个参数 Task 必须为 function !'); };
|
return new BukkitTask(this.pluginInstance, func)
|
||||||
return new BukkitTask(this.pluginInstance, func);
|
|
||||||
}
|
}
|
||||||
callSyncMethod(func: Function): any {
|
callSyncMethod(func: Function): any {
|
||||||
return Bukkit.getScheduler().callSyncMethod(this.pluginInstance, new Callable({ call: () => func() })).get()
|
return Bukkit.getScheduler().callSyncMethod(this.pluginInstance, new Callable({ call: () => func() })).get()
|
||||||
}
|
}
|
||||||
disable() {
|
disable0() {
|
||||||
Bukkit.getScheduler().cancelTasks(this.pluginInstance);
|
Bukkit.getScheduler().cancelTasks(this.pluginInstance)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class BukkitTask extends task.Task {
|
export class BukkitTask extends task.Task {
|
||||||
submit(...args: any[]): task.Cancelable {
|
submit0(...args: any[]): task.Cancelable {
|
||||||
let run = new BukkitRunnable({ run: () => this.run(...args) })
|
let run = new BukkitRunnable({ run: () => this.run(...args) })
|
||||||
let funcName = `runTask${this.interval ? 'Timer' : 'Later'}${this.isAsync ? 'Asynchronously' : ''}`
|
let funcName = `runTask${this.interval ? 'Timer' : 'Later'}${this.isAsync ? 'Asynchronously' : ''}`
|
||||||
if (this.interval) {
|
if (this.interval) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/bungee",
|
"name": "@ccms/bungee",
|
||||||
"version": "0.9.2",
|
"version": "0.9.3",
|
||||||
"description": "MiaoScript bungee package",
|
"description": "MiaoScript bungee package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -25,8 +25,8 @@
|
|||||||
"typescript": "^3.9.6"
|
"typescript": "^3.9.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.9.2",
|
"@ccms/api": "^0.9.3",
|
||||||
"@ccms/common": "^0.9.2",
|
"@ccms/common": "^0.9.3",
|
||||||
"@ccms/container": "^0.9.2"
|
"@ccms/container": "^0.9.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,29 +3,29 @@ import { provideSingleton, inject, postConstruct } from '@ccms/container'
|
|||||||
|
|
||||||
import * as reflect from '@ccms/common/dist/reflect'
|
import * as reflect from '@ccms/common/dist/reflect'
|
||||||
|
|
||||||
let Bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy();
|
let Bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy()
|
||||||
|
|
||||||
@provideSingleton(server.Server)
|
@provideSingleton(server.Server)
|
||||||
export class BungeeServer implements server.Server {
|
export class BungeeServer implements server.Server {
|
||||||
private pluginsFolder: string;
|
private pluginsFolder: string
|
||||||
private pipeline: any;
|
private pipeline: any
|
||||||
private rootLogger: any;
|
private rootLogger: any
|
||||||
|
|
||||||
@inject(task.TaskManager)
|
@inject(task.TaskManager)
|
||||||
private task: task.TaskManager
|
private task: task.TaskManager
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.pluginsFolder = Bungee.getPluginsFolder().getCanonicalPath();
|
this.pluginsFolder = Bungee.getPluginsFolder().getCanonicalPath()
|
||||||
}
|
}
|
||||||
|
|
||||||
@postConstruct()
|
@postConstruct()
|
||||||
initialize() {
|
initialize() {
|
||||||
let count = 0;
|
let count = 0
|
||||||
let wait = this.task.create(() => {
|
let wait = this.task.create(() => {
|
||||||
try {
|
try {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this.pipeline = reflect.on(base.getInstance().getProxy()).get('listeners').get().toArray()[0].pipeline()
|
this.pipeline = reflect.on(base.getInstance().getProxy()).get('listeners').get().toArray()[0].pipeline()
|
||||||
wait.cancel();
|
wait.cancel()
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
count++
|
count++
|
||||||
if (count > 50) {
|
if (count > 50) {
|
||||||
@@ -44,7 +44,7 @@ export class BungeeServer implements server.Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getPlayer(name: string) {
|
getPlayer(name: string) {
|
||||||
return Bungee.getPlayer(name);
|
return Bungee.getPlayer(name)
|
||||||
}
|
}
|
||||||
getVersion(): string {
|
getVersion(): string {
|
||||||
return Bungee.getVersion()
|
return Bungee.getVersion()
|
||||||
@@ -56,7 +56,7 @@ export class BungeeServer implements server.Server {
|
|||||||
return Bungee.getConsole()
|
return Bungee.getConsole()
|
||||||
}
|
}
|
||||||
getService(service: string) {
|
getService(service: string) {
|
||||||
throw new Error("Method not implemented.");
|
throw new Error("Method not implemented.")
|
||||||
}
|
}
|
||||||
dispatchCommand(sender: string | any, command: string): boolean {
|
dispatchCommand(sender: string | any, command: string): boolean {
|
||||||
if (typeof sender === 'string') {
|
if (typeof sender === 'string') {
|
||||||
@@ -68,18 +68,15 @@ export class BungeeServer implements server.Server {
|
|||||||
return Bungee.getPluginManager().dispatchCommand(Bungee.getConsole(), command)
|
return Bungee.getPluginManager().dispatchCommand(Bungee.getConsole(), command)
|
||||||
}
|
}
|
||||||
getPluginsFolder(): string {
|
getPluginsFolder(): string {
|
||||||
return this.pluginsFolder;
|
return this.pluginsFolder
|
||||||
}
|
}
|
||||||
getNativePluginManager() {
|
getNativePluginManager() {
|
||||||
return Bungee.getPluginManager() as any
|
return Bungee.getPluginManager() as any
|
||||||
}
|
}
|
||||||
getNettyPipeline() {
|
getNettyPipeline() {
|
||||||
return this.pipeline;
|
return this.pipeline
|
||||||
}
|
}
|
||||||
getRootLogger() {
|
getRootLogger() {
|
||||||
return this.rootLogger;
|
return this.rootLogger
|
||||||
}
|
|
||||||
sendJson(sender: string | any, json: string): void {
|
|
||||||
throw new Error("Method not implemented.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,27 @@
|
|||||||
import { task, plugin } from '@ccms/api'
|
import { task, plugin } from '@ccms/api'
|
||||||
import { inject, provideSingleton } from '@ccms/container';
|
import { inject, provideSingleton } from '@ccms/container'
|
||||||
|
|
||||||
var Runnable = Java.type('java.lang.Runnable')
|
var Runnable = Java.type('java.lang.Runnable')
|
||||||
let TimeUnit = Java.type('java.util.concurrent.TimeUnit')
|
let TimeUnit = Java.type('java.util.concurrent.TimeUnit')
|
||||||
|
|
||||||
@provideSingleton(task.TaskManager)
|
@provideSingleton(task.TaskManager)
|
||||||
export class BungeeTaskManager implements task.TaskManager {
|
export class BungeeTaskManager extends task.TaskManager {
|
||||||
@inject(plugin.PluginInstance)
|
@inject(plugin.PluginInstance)
|
||||||
private pluginInstance: any;
|
private pluginInstance: any
|
||||||
|
|
||||||
create(func: Function): task.Task {
|
create0(func: Function): task.Task {
|
||||||
if (Object.prototype.toString.call(func) !== "[object Function]") { throw TypeError('第一个参数 Task 必须为 function !'); };
|
return new BungeeTask(this.pluginInstance, func)
|
||||||
return new BungeeTask(this.pluginInstance, func);
|
|
||||||
}
|
}
|
||||||
callSyncMethod(func: Function): any {
|
callSyncMethod(func: Function): any {
|
||||||
return func();
|
return func()
|
||||||
}
|
}
|
||||||
disable() {
|
disable0() {
|
||||||
this.pluginInstance.getProxy().getScheduler().cancel(this.pluginInstance)
|
this.pluginInstance.getProxy().getScheduler().cancel(this.pluginInstance)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class BungeeTask extends task.Task {
|
export class BungeeTask extends task.Task {
|
||||||
submit(...args: any[]): task.Cancelable {
|
submit0(...args: any[]): task.Cancelable {
|
||||||
let run = new Runnable({ run: () => this.run(...args) })
|
let run = new Runnable({ run: () => this.run(...args) })
|
||||||
if (this.isAsync) {
|
if (this.isAsync) {
|
||||||
return this.plugin.getProxy().getScheduler().runAsync(this.plugin, run)
|
return this.plugin.getProxy().getScheduler().runAsync(this.plugin, run)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/common",
|
"name": "@ccms/common",
|
||||||
"version": "0.9.2",
|
"version": "0.9.3",
|
||||||
"description": "MiaoScript api package",
|
"description": "MiaoScript api package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "^0.9.0",
|
"@ccms/nashorn": "^0.9.3",
|
||||||
"@javatypes/jdk": "^0.0.2",
|
"@javatypes/jdk": "^0.0.2",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/container",
|
"name": "@ccms/container",
|
||||||
"version": "0.9.2",
|
"version": "0.9.3",
|
||||||
"description": "MiaoScript container package",
|
"description": "MiaoScript container package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "^0.9.0",
|
"@ccms/nashorn": "^0.9.3",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^3.9.6"
|
"typescript": "^3.9.6"
|
||||||
|
|||||||
@@ -60,8 +60,22 @@ export const JSClass = (className: string) => {
|
|||||||
* @param className 类名
|
* @param className 类名
|
||||||
*/
|
*/
|
||||||
export const Autowired = (className?: string | any) => {
|
export const Autowired = (className?: string | any) => {
|
||||||
return function (target: any, propertyKey: string) {
|
return function (target: any, propertyKey: string, index?: number) {
|
||||||
target[propertyKey] = getContainer().getNamed(ioc.Autowired, className || propertyKey)
|
let container = getContainer()
|
||||||
|
let type = Reflect.getMetadata('design:type', target, propertyKey)
|
||||||
|
if (type && type !== Object) {
|
||||||
|
try {
|
||||||
|
return target[propertyKey] = container.getNamed(type, className || propertyKey)
|
||||||
|
} catch (error) {
|
||||||
|
try {
|
||||||
|
return target[propertyKey] = container.get(type)
|
||||||
|
} catch (error) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (container.isBound(ioc.Autowired)) {
|
||||||
|
target[propertyKey] = container.getNamed(ioc.Autowired, className || propertyKey)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +84,7 @@ export const Autowired = (className?: string | any) => {
|
|||||||
* @param className 类名
|
* @param className 类名
|
||||||
*/
|
*/
|
||||||
export const Resource = (resourceName?: string | any) => {
|
export const Resource = (resourceName?: string | any) => {
|
||||||
return function (target: any, propertyKey: string) {
|
return function (target: any, propertyKey: string, index?: number) {
|
||||||
target[propertyKey] = getContainer().getNamed(ioc.Resource, resourceName || propertyKey)
|
target[propertyKey] = getContainer().getNamed(ioc.Resource, resourceName || propertyKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,8 +96,18 @@ export const reduceMetadata = (ctx: interfaces.Context): any => {
|
|||||||
}, {})
|
}, {})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initAutowired(container: Container) {
|
||||||
|
container.bind(ioc.Autowired).toDynamicValue((ctx) => {
|
||||||
|
var metadata: any = reduceMetadata(ctx)
|
||||||
|
let key = Object.toString.call(metadata.named)
|
||||||
|
if (key === "[object Function]" || key === "[object Symbol]") { return container.get(metadata.named) }
|
||||||
|
return undefined
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export const DefaultContainer = new Container()
|
export const DefaultContainer = new Container()
|
||||||
initContainer(DefaultContainer)
|
initContainer(DefaultContainer)
|
||||||
|
initAutowired(DefaultContainer)
|
||||||
|
|
||||||
export * from 'inversify'
|
export * from 'inversify'
|
||||||
export * from './constants'
|
export * from './constants'
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/core",
|
"name": "@ccms/core",
|
||||||
"version": "0.9.2",
|
"version": "0.9.3",
|
||||||
"description": "MiaoScript api package",
|
"description": "MiaoScript api package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -24,8 +24,8 @@
|
|||||||
"typescript": "^3.9.6"
|
"typescript": "^3.9.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.9.2",
|
"@ccms/api": "^0.9.3",
|
||||||
"@ccms/container": "^0.9.2"
|
"@ccms/container": "^0.9.3"
|
||||||
},
|
},
|
||||||
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,10 +49,12 @@ class MiaoScriptCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
disable() {
|
disable() {
|
||||||
|
let disableStartTime = Date.now()
|
||||||
console.i18n("ms.core.engine.disable")
|
console.i18n("ms.core.engine.disable")
|
||||||
this.pluginManager.disable(this.pluginManager.getPlugins())
|
this.pluginManager.disable(this.pluginManager.getPlugins())
|
||||||
this.taskManager.disable()
|
this.taskManager.disable()
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
|
console.i18n("ms.core.engine.disable.finish", { version: 'v' + global.ScriptEngineVersion, time: (new Date().getTime() - disableStartTime) / 1000 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +88,7 @@ function detectServer(): constants.ServerType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function initialize() {
|
function initialize() {
|
||||||
// @ts-ignore
|
global.ScriptEngineVersion = require('../package.json').version
|
||||||
try { engineLoad({ script: http.get("http://ms.yumc.pw/api/plugin/download/name/initialize"), name: 'core/initialize.js' }) } catch (error) { console.debug(error) }
|
try { engineLoad({ script: http.get("http://ms.yumc.pw/api/plugin/download/name/initialize"), name: 'core/initialize.js' }) } catch (error) { console.debug(error) }
|
||||||
try {
|
try {
|
||||||
let corePackageStartTime = new Date().getTime()
|
let corePackageStartTime = new Date().getTime()
|
||||||
@@ -103,7 +105,7 @@ function initialize() {
|
|||||||
container.load(buildProviderModule())
|
container.load(buildProviderModule())
|
||||||
console.i18n("ms.core.package.completed", { scope: global.scope, type, time: (Date.now() - corePackageStartTime) / 1000 })
|
console.i18n("ms.core.package.completed", { scope: global.scope, type, time: (Date.now() - corePackageStartTime) / 1000 })
|
||||||
let disable = container.get<MiaoScriptCore>(MiaoScriptCore).enable()
|
let disable = container.get<MiaoScriptCore>(MiaoScriptCore).enable()
|
||||||
console.i18n("ms.core.engine.completed", { time: (Date.now() - global.NashornEngineStartTime) / 1000 })
|
console.i18n("ms.core.engine.completed", { version: 'v' + global.ScriptEngineVersion, time: (Date.now() - global.ScriptEngineStartTime) / 1000 })
|
||||||
return disable
|
return disable
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.i18n("ms.core.initialize.error", { error })
|
console.i18n("ms.core.initialize.error", { error })
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/database",
|
"name": "@ccms/database",
|
||||||
"version": "0.9.2",
|
"version": "0.9.3",
|
||||||
"description": "MiaoScript database package",
|
"description": "MiaoScript database package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
"typescript": "^3.9.6"
|
"typescript": "^3.9.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.9.2",
|
"@ccms/api": "^0.9.3",
|
||||||
"@ccms/container": "^0.9.2"
|
"@ccms/container": "^0.9.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,9 @@ ms.core.package.initialize: "初始化 MiaoScript 扩展 {scope}/core {scope}/{t
|
|||||||
ms.core.package.completed: "MiaoScript 扩展 {scope}/core {scope}/{type} {scope}/plugin 加载完成 耗时({time}s)"
|
ms.core.package.completed: "MiaoScript 扩展 {scope}/core {scope}/{type} {scope}/plugin 加载完成 耗时({time}s)"
|
||||||
ms.core.plugin.initialize: "MiaoScript 开始引导插件系统. 请稍候..."
|
ms.core.plugin.initialize: "MiaoScript 开始引导插件系统. 请稍候..."
|
||||||
ms.core.plugin.completed: "MiaoScript 插件加载完毕 耗时({time}s)!"
|
ms.core.plugin.completed: "MiaoScript 插件加载完毕 耗时({time}s)!"
|
||||||
ms.core.engine.completed: "MiaoScript 脚本引擎 加载完毕... 耗时({time}s)!"
|
ms.core.engine.completed: "MiaoScript 脚本引擎 {version} 加载完毕... 耗时({time}s)!"
|
||||||
ms.core.engine.disable: "关闭 MiaoScript 引擎..."
|
ms.core.engine.disable: "MiaoScript 关闭脚本引擎 请稍候..."
|
||||||
|
ms.core.engine.disable.finish: "MiaoScript 脚本引擎 {version} 关闭完成... 耗时({time}s)!"
|
||||||
ms.core.engine.disable.abnormal: "引擎异常启动或初始化未完成 跳过关闭流程..."
|
ms.core.engine.disable.abnormal: "引擎异常启动或初始化未完成 跳过关闭流程..."
|
||||||
|
|
||||||
ms.api.event.resource.not.found: "无法映射事件 未找到资源文件 {resource}!"
|
ms.api.event.resource.not.found: "无法映射事件 未找到资源文件 {resource}!"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/i18n",
|
"name": "@ccms/i18n",
|
||||||
"version": "0.9.2",
|
"version": "0.9.3",
|
||||||
"description": "MiaoScript i18n package",
|
"description": "MiaoScript i18n package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "^0.9.0",
|
"@ccms/nashorn": "^0.9.3",
|
||||||
"@types/js-yaml": "^3.12.5",
|
"@types/js-yaml": "^3.12.5",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/keyvalue",
|
"name": "@ccms/keyvalue",
|
||||||
"version": "0.9.2",
|
"version": "0.9.3",
|
||||||
"description": "MiaoScript keyvalue package",
|
"description": "MiaoScript keyvalue package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,12 +19,12 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.9.2",
|
"@ccms/api": "^0.9.3",
|
||||||
"@ccms/common": "^0.9.2",
|
"@ccms/common": "^0.9.3",
|
||||||
"@ccms/container": "^0.9.2"
|
"@ccms/container": "^0.9.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "^0.9.0",
|
"@ccms/nashorn": "^0.9.3",
|
||||||
"@javatypes/amqp-client": "^0.0.2",
|
"@javatypes/amqp-client": "^0.0.2",
|
||||||
"@javatypes/spring-amqp": "^0.0.2",
|
"@javatypes/spring-amqp": "^0.0.2",
|
||||||
"@javatypes/spring-rabbit": "^0.0.2",
|
"@javatypes/spring-rabbit": "^0.0.2",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/nashorn",
|
"name": "@ccms/nashorn",
|
||||||
"version": "0.9.0",
|
"version": "0.9.3",
|
||||||
"description": "MiaoScript api package",
|
"description": "MiaoScript api package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
|
|||||||
@@ -48,7 +48,8 @@ declare global {
|
|||||||
logger: any
|
logger: any
|
||||||
debug: boolean
|
debug: boolean
|
||||||
level: string
|
level: string
|
||||||
NashornEngineStartTime: number
|
ScriptEngineVersion: string
|
||||||
|
ScriptEngineStartTime: number
|
||||||
setGlobal: (key: string, value: any, config?: PropertyDescriptor & ThisType<any>) => void
|
setGlobal: (key: string, value: any, config?: PropertyDescriptor & ThisType<any>) => void
|
||||||
noop: () => void
|
noop: () => void
|
||||||
console: Console
|
console: Console
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/nodejs",
|
"name": "@ccms/nodejs",
|
||||||
"version": "0.9.0",
|
"version": "0.9.3",
|
||||||
"description": "MiaoScript nodejs package",
|
"description": "MiaoScript nodejs package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "^0.9.0",
|
"@ccms/nashorn": "^0.9.3",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^3.9.6"
|
"typescript": "^3.9.6"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/nukkit",
|
"name": "@ccms/nukkit",
|
||||||
"version": "0.9.2",
|
"version": "0.9.3",
|
||||||
"description": "MiaoScript nukkit package",
|
"description": "MiaoScript nukkit package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -25,8 +25,8 @@
|
|||||||
"typescript": "^3.9.6"
|
"typescript": "^3.9.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.9.2",
|
"@ccms/api": "^0.9.3",
|
||||||
"@ccms/common": "^0.9.2",
|
"@ccms/common": "^0.9.3",
|
||||||
"@ccms/container": "^0.9.2"
|
"@ccms/container": "^0.9.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +1,32 @@
|
|||||||
import { task, plugin } from '@ccms/api'
|
import { task, plugin } from '@ccms/api'
|
||||||
import { inject, provideSingleton } from '@ccms/container';
|
import { inject, provideSingleton } from '@ccms/container'
|
||||||
|
|
||||||
const NukkitRunnable = Java.type('cn.nukkit.scheduler.NukkitRunnable');
|
const NukkitRunnable = Java.type('cn.nukkit.scheduler.NukkitRunnable')
|
||||||
|
|
||||||
@provideSingleton(task.TaskManager)
|
@provideSingleton(task.TaskManager)
|
||||||
export class NukkitTaskManager implements task.TaskManager {
|
export class NukkitTaskManager extends task.TaskManager {
|
||||||
@inject(plugin.PluginInstance)
|
@inject(plugin.PluginInstance)
|
||||||
private pluginInstance: any;
|
private pluginInstance: any
|
||||||
|
|
||||||
create(func: Function): task.Task {
|
create0(func: Function): task.Task {
|
||||||
if (Object.prototype.toString.call(func) !== "[object Function]") { throw TypeError('第一个参数 Task 必须为 function !'); };
|
return new NukkitTask(this.pluginInstance, func)
|
||||||
return new NukkitTask(this.pluginInstance, func);
|
|
||||||
}
|
}
|
||||||
callSyncMethod(func: Function): any {
|
callSyncMethod(func: Function): any {
|
||||||
return func()
|
return func()
|
||||||
}
|
}
|
||||||
disable() {
|
disable0() {
|
||||||
base.getInstance().getServer().getScheduler().cancelTask(this.pluginInstance)
|
base.getInstance().getServer().getScheduler().cancelTask(this.pluginInstance)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class NukkitTask extends task.Task {
|
export class NukkitTask extends task.Task {
|
||||||
submit(...args: any[]): task.Cancelable {
|
submit0(...args: any[]): task.Cancelable {
|
||||||
let run = new NukkitRunnable({ run: () => this.run(...args) })
|
let run = new NukkitRunnable({ run: () => this.run(...args) })
|
||||||
let funcName = `runTask${this.interval ? 'Timer' : 'Later'}${this.isAsync ? 'Asynchronously' : ''}`
|
let funcName = `runTask${this.interval ? 'Timer' : 'Later'}${this.isAsync ? 'Asynchronously' : ''}`
|
||||||
if (this.interval) {
|
if (this.interval) {
|
||||||
run[funcName](this.plugin, this.laterTime, this.interval);
|
return run[funcName](this.plugin, this.laterTime, this.interval)
|
||||||
} else {
|
} else {
|
||||||
run[funcName](this.plugin, this.laterTime);
|
return run[funcName](this.plugin, this.laterTime)
|
||||||
}
|
}
|
||||||
return run;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/ployfill",
|
"name": "@ccms/ployfill",
|
||||||
"version": "0.9.2",
|
"version": "0.9.3",
|
||||||
"description": "MiaoScript ployfill package",
|
"description": "MiaoScript ployfill package",
|
||||||
"author": "MiaoWoo <admin@yumc.pw>",
|
"author": "MiaoWoo <admin@yumc.pw>",
|
||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
@@ -14,12 +14,12 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/i18n": "^0.9.2",
|
"@ccms/i18n": "^0.9.3",
|
||||||
"@ccms/nodejs": "^0.9.0",
|
"@ccms/nodejs": "^0.9.3",
|
||||||
"core-js": "^3.6.5"
|
"core-js": "^3.6.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "^0.9.0",
|
"@ccms/nashorn": "^0.9.3",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^3.9.6"
|
"typescript": "^3.9.6"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/plugin",
|
"name": "@ccms/plugin",
|
||||||
"version": "0.9.2",
|
"version": "0.9.3",
|
||||||
"description": "MiaoScript api package",
|
"description": "MiaoScript api package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -25,10 +25,10 @@
|
|||||||
"typescript": "^3.9.6"
|
"typescript": "^3.9.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.9.2",
|
"@ccms/api": "^0.9.3",
|
||||||
"@ccms/common": "^0.9.2",
|
"@ccms/common": "^0.9.3",
|
||||||
"@ccms/container": "^0.9.2",
|
"@ccms/container": "^0.9.3",
|
||||||
"@ccms/i18n": "^0.9.2",
|
"@ccms/i18n": "^0.9.3",
|
||||||
"js-yaml": "^3.14.0"
|
"js-yaml": "^3.14.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ export function cmd(metadata: interfaces.CommandMetadata = {}) {
|
|||||||
metadata.paramtypes = Reflect.getMetadata("design:paramtypes", target, key)
|
metadata.paramtypes = Reflect.getMetadata("design:paramtypes", target, key)
|
||||||
const previousMetadata: Map<string, interfaces.CommandMetadata> = getPluginCommandMetadata(target)
|
const previousMetadata: Map<string, interfaces.CommandMetadata> = getPluginCommandMetadata(target)
|
||||||
previousMetadata.set(metadata.name, metadata)
|
previousMetadata.set(metadata.name, metadata)
|
||||||
|
metadata.alias?.forEach((name) => previousMetadata.set(name, metadata))
|
||||||
Reflect.defineMetadata(METADATA_KEY.cmd, previousMetadata, target.constructor)
|
Reflect.defineMetadata(METADATA_KEY.cmd, previousMetadata, target.constructor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,6 +53,7 @@ export function tab(metadata: interfaces.CommandMetadata = {}) {
|
|||||||
metadata.paramtypes = Reflect.getMetadata("design:paramtypes", target, key)
|
metadata.paramtypes = Reflect.getMetadata("design:paramtypes", target, key)
|
||||||
const previousMetadata: Map<string, interfaces.CommandMetadata> = getPluginTabCompleterMetadata(target)
|
const previousMetadata: Map<string, interfaces.CommandMetadata> = getPluginTabCompleterMetadata(target)
|
||||||
previousMetadata.set(metadata.name, metadata)
|
previousMetadata.set(metadata.name, metadata)
|
||||||
|
metadata.alias?.forEach((name) => previousMetadata.set(name, metadata))
|
||||||
Reflect.defineMetadata(METADATA_KEY.tab, previousMetadata, target.constructor)
|
Reflect.defineMetadata(METADATA_KEY.tab, previousMetadata, target.constructor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ export namespace interfaces {
|
|||||||
executor?: string
|
executor?: string
|
||||||
}
|
}
|
||||||
export interface CommandMetadata extends ExecMetadata {
|
export interface CommandMetadata extends ExecMetadata {
|
||||||
|
/**
|
||||||
|
* 命令别名
|
||||||
|
*/
|
||||||
|
alias?: string[]
|
||||||
/**
|
/**
|
||||||
* 命令描述
|
* 命令描述
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -4,8 +4,9 @@ import { inject, provideSingleton, Container, ContainerInstance } from '@ccms/co
|
|||||||
|
|
||||||
import './config'
|
import './config'
|
||||||
import { interfaces } from './interfaces'
|
import { interfaces } from './interfaces'
|
||||||
import { PluginCommandManager } from './command'
|
import { PluginTaskManager } from './task'
|
||||||
import { PluginEventManager } from './event'
|
import { PluginEventManager } from './event'
|
||||||
|
import { PluginCommandManager } from './command'
|
||||||
|
|
||||||
const Thread = Java.type('java.lang.Thread')
|
const Thread = Java.type('java.lang.Thread')
|
||||||
|
|
||||||
@@ -22,10 +23,12 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
@inject(server.ServerChecker)
|
@inject(server.ServerChecker)
|
||||||
private serverChecker: server.ServerChecker
|
private serverChecker: server.ServerChecker
|
||||||
|
|
||||||
@inject(PluginCommandManager)
|
@inject(PluginTaskManager)
|
||||||
private commandManager: PluginCommandManager
|
private taskManager: PluginTaskManager
|
||||||
@inject(PluginEventManager)
|
@inject(PluginEventManager)
|
||||||
private eventManager: PluginEventManager
|
private eventManager: PluginEventManager
|
||||||
|
@inject(PluginCommandManager)
|
||||||
|
private commandManager: PluginCommandManager
|
||||||
|
|
||||||
private initialized: boolean = false
|
private initialized: boolean = false
|
||||||
|
|
||||||
@@ -43,8 +46,9 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
this.metadataMap = new Map()
|
this.metadataMap = new Map()
|
||||||
|
|
||||||
// ignore unused
|
// ignore unused
|
||||||
this.commandManager
|
this.taskManager
|
||||||
this.eventManager
|
this.eventManager
|
||||||
|
this.commandManager
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize() {
|
initialize() {
|
||||||
@@ -131,7 +135,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
if (loader.require(loadMetadata).loaded) {
|
if (loader.require(loadMetadata).loaded) {
|
||||||
loadMetadata.loader = loader
|
loadMetadata.loader = loader
|
||||||
let metadata = loadMetadata.metadata
|
let metadata = loadMetadata.metadata
|
||||||
if (this.metadataMap.has(metadata.name)) {
|
if (this.metadataMap.has(metadata.name) && this.instanceMap.has(metadata.name)) {
|
||||||
let oldMetadata = this.metadataMap.get(metadata.name)
|
let oldMetadata = this.metadataMap.get(metadata.name)
|
||||||
throw new Error(`Plugin ${oldMetadata.name} is already load from ${oldMetadata.source}...`)
|
throw new Error(`Plugin ${oldMetadata.name} is already load from ${oldMetadata.source}...`)
|
||||||
}
|
}
|
||||||
|
|||||||
16
packages/plugin/src/task.ts
Normal file
16
packages/plugin/src/task.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { plugin, task } from '@ccms/api'
|
||||||
|
import { provideSingleton, inject } from '@ccms/container'
|
||||||
|
|
||||||
|
@provideSingleton(PluginTaskManager)
|
||||||
|
export class PluginTaskManager {
|
||||||
|
@inject(task.TaskManager)
|
||||||
|
private taskManager: task.TaskManager
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
process.on('plugin.after.disable', (plugin: plugin.Plugin) => this.cancelTask(plugin))
|
||||||
|
}
|
||||||
|
|
||||||
|
private cancelTask(pluginInstance: plugin.Plugin) {
|
||||||
|
this.taskManager.disable(pluginInstance)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"name": "@ccms/plugins",
|
"name": "@ccms/plugins",
|
||||||
"version": "0.9.2",
|
"version": "0.9.3",
|
||||||
"description": "MiaoScript plugins package",
|
"description": "MiaoScript plugins package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -28,8 +28,8 @@
|
|||||||
"typescript": "^3.9.6"
|
"typescript": "^3.9.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.9.2",
|
"@ccms/api": "^0.9.3",
|
||||||
"@ccms/container": "^0.9.2",
|
"@ccms/container": "^0.9.3",
|
||||||
"@ccms/plugin": "^0.9.2"
|
"@ccms/plugin": "^0.9.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,16 +2,16 @@
|
|||||||
/// <reference types="@javatypes/spigot-api" />
|
/// <reference types="@javatypes/spigot-api" />
|
||||||
/// <reference types="@javatypes/sponge-api" />
|
/// <reference types="@javatypes/sponge-api" />
|
||||||
|
|
||||||
import { server, plugin as pluginApi, channel, constants } from '@ccms/api'
|
import { server, plugin as pluginApi, channel, constants, chat } from '@ccms/api'
|
||||||
import { inject, optional } from '@ccms/container';
|
import { inject, optional } from '@ccms/container'
|
||||||
import { plugin, interfaces, cmd, listener, tab, config, enable } from '@ccms/plugin'
|
import { plugin, interfaces, cmd, listener, tab, config, enable } from '@ccms/plugin'
|
||||||
import Tellraw from '@ccms/common/dist/tellraw'
|
import Tellraw from '@ccms/common/dist/tellraw'
|
||||||
|
|
||||||
const ByteArrayInputStream = Java.type("java.io.ByteArrayInputStream");
|
const ByteArrayInputStream = Java.type("java.io.ByteArrayInputStream")
|
||||||
const ByteArrayOutputStream = Java.type("java.io.ByteArrayOutputStream");
|
const ByteArrayOutputStream = Java.type("java.io.ByteArrayOutputStream")
|
||||||
const StandardCharsets = Java.type("java.nio.charset.StandardCharsets");
|
const StandardCharsets = Java.type("java.nio.charset.StandardCharsets")
|
||||||
const GZIPInputStream = Java.type("java.util.zip.GZIPInputStream");
|
const GZIPInputStream = Java.type("java.util.zip.GZIPInputStream")
|
||||||
const GZIPOutputStream = Java.type("java.util.zip.GZIPOutputStream");
|
const GZIPOutputStream = Java.type("java.util.zip.GZIPOutputStream")
|
||||||
const BiConsumer = Java.type('java.util.function.BiConsumer')
|
const BiConsumer = Java.type('java.util.function.BiConsumer')
|
||||||
const ByteArray = Java.type("byte[]")
|
const ByteArray = Java.type("byte[]")
|
||||||
|
|
||||||
@@ -22,31 +22,31 @@ class MiaoMessage {
|
|||||||
private static MAX_MESSAGE_LENGTH = 32000;
|
private static MAX_MESSAGE_LENGTH = 32000;
|
||||||
|
|
||||||
private static copy(input, output) {
|
private static copy(input, output) {
|
||||||
let buffer = new ByteArray(1024);
|
let buffer = new ByteArray(1024)
|
||||||
let n: number;
|
let n: number
|
||||||
while ((n = input.read(buffer)) != -1) {
|
while ((n = input.read(buffer)) != -1) {
|
||||||
output.write(buffer, 0, n);
|
output.write(buffer, 0, n)
|
||||||
}
|
}
|
||||||
input.close();
|
input.close()
|
||||||
output.close();
|
output.close()
|
||||||
}
|
}
|
||||||
public static encode(input: any): any {
|
public static encode(input: any): any {
|
||||||
return new MiaoMessage(input).encode();
|
return new MiaoMessage(input).encode()
|
||||||
}
|
}
|
||||||
public static decode(input: any): MiaoMessage {
|
public static decode(input: any): MiaoMessage {
|
||||||
let baos = new ByteArrayOutputStream();
|
let baos = new ByteArrayOutputStream()
|
||||||
MiaoMessage.copy(new GZIPInputStream(new ByteArrayInputStream(input)), baos);
|
MiaoMessage.copy(new GZIPInputStream(new ByteArrayInputStream(input)), baos)
|
||||||
return new MiaoMessage(baos.toString(StandardCharsets.UTF_8.name()));
|
return new MiaoMessage(baos.toString(StandardCharsets.UTF_8.name()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// private String json;
|
// private String json;
|
||||||
constructor(public json: any) { }
|
constructor(public json: any) { }
|
||||||
|
|
||||||
public encode(): any {
|
public encode(): any {
|
||||||
let baos = new ByteArrayOutputStream();
|
let baos = new ByteArrayOutputStream()
|
||||||
MiaoMessage.copy(new ByteArrayInputStream(this.json.getBytes(StandardCharsets.UTF_8)), new GZIPOutputStream(baos));
|
MiaoMessage.copy(new ByteArrayInputStream(this.json.getBytes(StandardCharsets.UTF_8)), new GZIPOutputStream(baos))
|
||||||
if (baos.size() > MiaoMessage.MAX_MESSAGE_LENGTH) { return null; }
|
if (baos.size() > MiaoMessage.MAX_MESSAGE_LENGTH) { return null }
|
||||||
return baos.toByteArray();
|
return baos.toByteArray()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,10 +54,12 @@ class MiaoMessage {
|
|||||||
export class MiaoChat extends interfaces.Plugin {
|
export class MiaoChat extends interfaces.Plugin {
|
||||||
@inject(server.Server)
|
@inject(server.Server)
|
||||||
private Server: server.Server
|
private Server: server.Server
|
||||||
|
@inject(chat.Chat)
|
||||||
|
private chat: chat.Chat
|
||||||
@inject(channel.Channel)
|
@inject(channel.Channel)
|
||||||
@optional() private Channel: channel.Channel
|
@optional() private Channel: channel.Channel
|
||||||
|
|
||||||
private channelOff: { off: () => void };
|
private channelOff: { off: () => void }
|
||||||
|
|
||||||
@config()
|
@config()
|
||||||
private config = {
|
private config = {
|
||||||
@@ -129,34 +131,34 @@ export class MiaoChat extends interfaces.Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private chatFormats: any[];
|
private chatFormats: any[]
|
||||||
private styleFormats: any;
|
private styleFormats: any
|
||||||
// 用于匹配 '[xx]' 聊天格式
|
// 用于匹配 '[xx]' 聊天格式
|
||||||
private FORMAT_PATTERN = /[\[]([^\[\]]+)[\]]/ig;
|
private FORMAT_PATTERN = /[\[]([^\[\]]+)[\]]/ig;
|
||||||
|
|
||||||
private PlaceholderAPI: { setPlaceholders: (player: any, str: string) => string };
|
private PlaceholderAPI: { setPlaceholders: (player: any, str: string) => string }
|
||||||
|
|
||||||
load() {
|
load() {
|
||||||
this.chatFormats = Object.values(this.config.ChatFormats);
|
this.chatFormats = Object.values(this.config.ChatFormats)
|
||||||
this.chatFormats.sort(this.compare('index'));
|
this.chatFormats.sort(this.compare('index'))
|
||||||
this.initFormat(this.chatFormats);
|
this.initFormat(this.chatFormats)
|
||||||
this.styleFormats = this.config.StyleFormats;
|
this.styleFormats = this.config.StyleFormats
|
||||||
}
|
}
|
||||||
|
|
||||||
private compare(prop: string) {
|
private compare(prop: string) {
|
||||||
return function (obj1: { [x: string]: any; }, obj2: { [x: string]: any; }) {
|
return function (obj1: { [x: string]: any }, obj2: { [x: string]: any }) {
|
||||||
var val1 = obj1[prop];
|
var val1 = obj1[prop]
|
||||||
var val2 = obj2[prop];
|
var val2 = obj2[prop]
|
||||||
if (!isNaN(Number(val1)) && !isNaN(Number(val2))) {
|
if (!isNaN(Number(val1)) && !isNaN(Number(val2))) {
|
||||||
val1 = Number(val1);
|
val1 = Number(val1)
|
||||||
val2 = Number(val2);
|
val2 = Number(val2)
|
||||||
}
|
}
|
||||||
if (val1 < val2) {
|
if (val1 < val2) {
|
||||||
return -1;
|
return -1
|
||||||
} else if (val1 > val2) {
|
} else if (val1 > val2) {
|
||||||
return 1;
|
return 1
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,7 +166,7 @@ export class MiaoChat extends interfaces.Plugin {
|
|||||||
enable() {
|
enable() {
|
||||||
this.PlaceholderAPI = {
|
this.PlaceholderAPI = {
|
||||||
setPlaceholders: (player: any, string: string) => {
|
setPlaceholders: (player: any, string: string) => {
|
||||||
return string;
|
return string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -177,7 +179,7 @@ export class MiaoChat extends interfaces.Plugin {
|
|||||||
// 尝试加载 Bukkit 的 PlaceholderAPI
|
// 尝试加载 Bukkit 的 PlaceholderAPI
|
||||||
try {
|
try {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
this.PlaceholderAPI = base.getClass("me.clip.placeholderapi.PlaceholderAPI").static;
|
this.PlaceholderAPI = base.getClass("me.clip.placeholderapi.PlaceholderAPI").static
|
||||||
this.logger.log('[PAPI] Found Bukkit PlaceholderAPI Hooking...')
|
this.logger.log('[PAPI] Found Bukkit PlaceholderAPI Hooking...')
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
this.logger.console("§cCan't found me.clip.placeholderapi.PlaceholderAPI variable will not be replaced! Err: " + ex)
|
this.logger.console("§cCan't found me.clip.placeholderapi.PlaceholderAPI variable will not be replaced! Err: " + ex)
|
||||||
@@ -187,14 +189,14 @@ export class MiaoChat extends interfaces.Plugin {
|
|||||||
spongeenable() {
|
spongeenable() {
|
||||||
// 尝试加载 Sponge 的 PlaceholderAPI
|
// 尝试加载 Sponge 的 PlaceholderAPI
|
||||||
try {
|
try {
|
||||||
var spongePapi = this.Server.getService('me.rojo8399.placeholderapi.PlaceholderService');
|
var spongePapi = this.Server.getService('me.rojo8399.placeholderapi.PlaceholderService')
|
||||||
var s = org.spongepowered.api.text.serializer.TextSerializers.formattingCode('§');
|
var s = org.spongepowered.api.text.serializer.TextSerializers.formattingCode('§')
|
||||||
if (spongePapi) {
|
if (spongePapi) {
|
||||||
this.PlaceholderAPI = {
|
this.PlaceholderAPI = {
|
||||||
setPlaceholders: (player: any, string: string) => {
|
setPlaceholders: (player: any, string: string) => {
|
||||||
return s.serialize(spongePapi.replacePlaceholders(string, player, player));
|
return s.serialize(spongePapi.replacePlaceholders(string, player, player))
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
this.logger.log('[PAPI] Found Sponge PlaceholderAPI Hooking...')
|
this.logger.log('[PAPI] Found Sponge PlaceholderAPI Hooking...')
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
@@ -213,7 +215,7 @@ export class MiaoChat extends interfaces.Plugin {
|
|||||||
this.channelOff = this.Channel?.listen(this, MiaoMessage.CHANNEL, (data, event: net.md_5.bungee.api.event.PluginMessageEvent) => {
|
this.channelOff = this.Channel?.listen(this, MiaoMessage.CHANNEL, (data, event: net.md_5.bungee.api.event.PluginMessageEvent) => {
|
||||||
let bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy()
|
let bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy()
|
||||||
if (event.getTag() == MiaoMessage.CHANNEL) {
|
if (event.getTag() == MiaoMessage.CHANNEL) {
|
||||||
let origin = event.getSender().getAddress();
|
let origin = event.getSender().getAddress()
|
||||||
bungee.getServers().forEach(new BiConsumer({
|
bungee.getServers().forEach(new BiConsumer({
|
||||||
accept: (s, server) => {
|
accept: (s, server) => {
|
||||||
if (server.getAddress() != origin && server.getPlayers().size() > 0) {
|
if (server.getAddress() != origin && server.getPlayers().size() > 0) {
|
||||||
@@ -227,13 +229,13 @@ export class MiaoChat extends interfaces.Plugin {
|
|||||||
|
|
||||||
@cmd({ servers: ["bungee"] })
|
@cmd({ servers: ["bungee"] })
|
||||||
mct(sender: any, command: string, args: string[]) {
|
mct(sender: any, command: string, args: string[]) {
|
||||||
this.logger.log(sender, command, args);
|
this.logger.log(sender, command, args)
|
||||||
sender.sendMessage(JSON.stringify({ command, ...args }))
|
sender.sendMessage(JSON.stringify({ command, ...args }))
|
||||||
}
|
}
|
||||||
|
|
||||||
@cmd({ servers: ["!bungee"] })
|
@cmd({ servers: ["!bungee"] })
|
||||||
mchat(sender: any, command: string, args: string[]) {
|
mchat(sender: any, command: string, args: string[]) {
|
||||||
this.logger.log(sender, command, args);
|
this.logger.log(sender, command, args)
|
||||||
sender.sendMessage(JSON.stringify({ command, ...args }))
|
sender.sendMessage(JSON.stringify({ command, ...args }))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,102 +245,97 @@ export class MiaoChat extends interfaces.Plugin {
|
|||||||
|
|
||||||
@listener({ servers: ['bukkit'] })
|
@listener({ servers: ['bukkit'] })
|
||||||
AsyncPlayerChatEvent(event: org.bukkit.event.player.AsyncPlayerChatEvent) {
|
AsyncPlayerChatEvent(event: org.bukkit.event.player.AsyncPlayerChatEvent) {
|
||||||
this.sendChat(event.getPlayer(), event.getMessage(), function () {
|
this.sendChat(event.getPlayer(), event.getMessage(), () => event.setCancelled(true))
|
||||||
event.setCancelled(true);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@listener({ servers: ['sponge'] })
|
@listener({ servers: ['sponge'] })
|
||||||
MessageChannelEvent$Chat(event: org.spongepowered.api.event.message.MessageChannelEvent.Chat) {
|
MessageChannelEvent$Chat(event: org.spongepowered.api.event.message.MessageChannelEvent.Chat) {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
var player = event.getCause().first(org.spongepowered.api.entity.living.player.Player.class).orElse(null);
|
var player = event.getCause().first(org.spongepowered.api.entity.living.player.Player.class).orElse(null)
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
var plain = event.getRawMessage().toPlain();
|
var plain = event.getRawMessage().toPlain()
|
||||||
if (plain.startsWith(Tellraw.duplicateChar)) {
|
if (plain.startsWith(Tellraw.duplicateChar)) {
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
this.sendChat(player, plain, function () {
|
this.sendChat(player, plain, () => event.setMessageCancelled(true))
|
||||||
event.setMessageCancelled(true)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
initFormat(chatFormats: any[]) {
|
initFormat(chatFormats: any[]) {
|
||||||
chatFormats.forEach(chatFormat => {
|
chatFormats.forEach(chatFormat => {
|
||||||
var chat_format_str = chatFormat.format;
|
var chat_format_str = chatFormat.format
|
||||||
var temp = [];
|
var temp = []
|
||||||
var r: any[];
|
var r: any[]
|
||||||
while (r = this.FORMAT_PATTERN.exec(chat_format_str)) {
|
while (r = this.FORMAT_PATTERN.exec(chat_format_str)) {
|
||||||
temp.push(r[1]);
|
temp.push(r[1])
|
||||||
}
|
}
|
||||||
var format_list = [];
|
var format_list = []
|
||||||
temp.forEach(t => {
|
temp.forEach(t => {
|
||||||
var arr = chat_format_str.split('[' + t + ']', 2);
|
var arr = chat_format_str.split('[' + t + ']', 2)
|
||||||
if (arr[0]) {
|
if (arr[0]) {
|
||||||
format_list.push(arr[0]);
|
format_list.push(arr[0])
|
||||||
}
|
}
|
||||||
format_list.push(t);
|
format_list.push(t)
|
||||||
chat_format_str = arr[1];
|
chat_format_str = arr[1]
|
||||||
});
|
})
|
||||||
if (chat_format_str) {
|
if (chat_format_str) {
|
||||||
format_list.push(chat_format_str);
|
format_list.push(chat_format_str)
|
||||||
}
|
}
|
||||||
chatFormat.format_list = format_list;
|
chatFormat.format_list = format_list
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
sendChat(player: any, plain: string, callback: { (): void; }) {
|
sendChat(player: any, plain: string, callback: { (): void }) {
|
||||||
var chat_format = this.getChatFormat(player);
|
var chat_format = this.getChatFormat(player)
|
||||||
if (!chat_format) {
|
if (!chat_format) {
|
||||||
console.debug('未获得用户', player.getName(), '的 ChatRule 跳过执行...');
|
console.debug('未获得用户', player.getName(), '的 ChatRule 跳过执行...')
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
callback();
|
callback()
|
||||||
var tr = Tellraw.create();
|
var tr = Tellraw.create()
|
||||||
chat_format.format_list.forEach((format) => {
|
chat_format.format_list.forEach((format) => {
|
||||||
var style = this.styleFormats[format];
|
var style = this.styleFormats[format]
|
||||||
if (style) {
|
if (style) {
|
||||||
tr.then(this.replace(player, style.text.replace(/&(\w)/g, '§$1')));
|
tr.then(this.replace(player, style.text.replace(/&(\w)/g, '§$1')))
|
||||||
if (style.hover) {
|
if (style.hover) {
|
||||||
tr.tip(this.replace(player, style.hover.join('\n')));
|
tr.tip(this.replace(player, style.hover.join('\n')))
|
||||||
}
|
}
|
||||||
if (style.click && style.click.type && style.click.command) {
|
if (style.click && style.click.type && style.click.command) {
|
||||||
var command = this.replace(player, style.click.command);
|
var command = this.replace(player, style.click.command)
|
||||||
switch (style.click.type.toUpperCase()) {
|
switch (style.click.type.toUpperCase()) {
|
||||||
case "COMMAND":
|
case "COMMAND":
|
||||||
tr.command(command);
|
tr.command(command)
|
||||||
break;
|
break
|
||||||
case "OPENURL":
|
case "OPENURL":
|
||||||
tr.link(command);
|
tr.link(command)
|
||||||
break;
|
break
|
||||||
case "SUGGEST":
|
case "SUGGEST":
|
||||||
tr.suggest(command);
|
tr.suggest(command)
|
||||||
break;
|
break
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tr.then(this.replace(player, format));
|
tr.then(this.replace(player, format))
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
let json = tr.then(this.replace(player, plain)).json()
|
let json = tr.then(this.replace(player, plain)).json()
|
||||||
this.sendChatAll(json)
|
this.sendChatAll(json)
|
||||||
this.Channel?.send(player, MiaoMessage.CHANNEL, MiaoMessage.encode(json))
|
this.Channel?.send(player, MiaoMessage.CHANNEL, MiaoMessage.encode(json))
|
||||||
}
|
}
|
||||||
|
|
||||||
sendChatAll(json: string) {
|
sendChatAll(json: string) {
|
||||||
this.Server.getOnlinePlayers().forEach(player => this.Server.sendJson(player, json))
|
this.Server.getOnlinePlayers().forEach(player => this.chat.sendJson(player, json))
|
||||||
}
|
}
|
||||||
|
|
||||||
getChatFormat(player: any) {
|
getChatFormat(player: any) {
|
||||||
for (var i in this.chatFormats) {
|
for (let format of this.chatFormats) {
|
||||||
var format = this.chatFormats[i];
|
|
||||||
if (player.hasPermission(format.permission)) {
|
if (player.hasPermission(format.permission)) {
|
||||||
return format;
|
return format
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
replace(player: any, target: string) {
|
replace(player: any, target: string) {
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ export class MiaoCoin extends interfaces.Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
disable() {
|
disable() {
|
||||||
|
// {"app":"com.tencent.autoreply","desc":"","view":"autoreply","ver":"0.0.0.1","prompt":"[动画表情]","meta":{"metadata":{"title":"点击蓝色字体有惊喜","buttons":[{"slot":1,"action_data":"我是傻逼","name":"点我","action":"notify"}],"type":"guest","token":"LAcV49xqyE57S17B8ZT6FU7odBveNMYJzux288tBD3c="}},"config":{"forward":1,"showSender":1}}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cmd()
|
@Cmd()
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/// <reference types="@ccms/nashorn" />
|
/// <reference types="@ccms/nashorn" />
|
||||||
|
|
||||||
import { plugin as pluginApi, server, task, constants } from '@ccms/api'
|
import { plugin as pluginApi, server, task, constants, command } from '@ccms/api'
|
||||||
import { plugin, interfaces, cmd, tab, enable, config, disable } from '@ccms/plugin'
|
import { plugin, interfaces, cmd, tab, enable, config, disable } from '@ccms/plugin'
|
||||||
import { inject, ContainerInstance, Container } from '@ccms/container'
|
import { inject, ContainerInstance, Container } from '@ccms/container'
|
||||||
import io, { Server as SocketIOServer, Socket as SocketIOSocket } from '@ccms/websocket'
|
import io, { Server as SocketIOServer, Socket as SocketIOSocket } from '@ccms/websocket'
|
||||||
@@ -27,6 +27,8 @@ export class MiaoConsole extends interfaces.Plugin {
|
|||||||
private serverType: string
|
private serverType: string
|
||||||
@inject(server.Server)
|
@inject(server.Server)
|
||||||
private server: server.Server
|
private server: server.Server
|
||||||
|
@inject(command.Command)
|
||||||
|
private command: command.Command
|
||||||
@inject(task.TaskManager)
|
@inject(task.TaskManager)
|
||||||
private task: task.TaskManager
|
private task: task.TaskManager
|
||||||
@inject(pluginApi.PluginManager)
|
@inject(pluginApi.PluginManager)
|
||||||
@@ -248,7 +250,7 @@ export class MiaoConsole extends interfaces.Plugin {
|
|||||||
client.emit('log', `§6命令: §b${cmd} §a执行成功!`)
|
client.emit('log', `§6命令: §b${cmd} §a执行成功!`)
|
||||||
})
|
})
|
||||||
client.on('tabComplate', (input, index, callback) => {
|
client.on('tabComplate', (input, index, callback) => {
|
||||||
callback && callback(this.server.tabComplete(this.server.getConsoleSender(), input, index))
|
callback?.(this.command.tabComplete(this.server.getConsoleSender(), input, index))
|
||||||
})
|
})
|
||||||
client.on('exec', (code) => {
|
client.on('exec', (code) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { JSPlugin, interfaces, Cmd, Tab, Listener, Config } from "@ccms/plugin"
|
|||||||
|
|
||||||
import { QRCode, QRErrorCorrectLevel } from '@ccms/common/dist/qrcode'
|
import { QRCode, QRErrorCorrectLevel } from '@ccms/common/dist/qrcode'
|
||||||
|
|
||||||
import { inject, JSClass, optional } from '@ccms/container'
|
import { Autowired, JSClass, optional, inject } from '@ccms/container'
|
||||||
import http from '@ccms/common/dist/http'
|
import http from '@ccms/common/dist/http'
|
||||||
|
|
||||||
let MapView
|
let MapView
|
||||||
@@ -54,9 +54,9 @@ interface PlaceholderAPI {
|
|||||||
setPlaceholders: (player: any, str: string) => string
|
setPlaceholders: (player: any, str: string) => string
|
||||||
}
|
}
|
||||||
|
|
||||||
@JSPlugin({ prefix: 'MRD', version: '1.2.0', author: 'MiaoWoo', servers: [constants.ServerType.Bukkit], source: __filename })
|
@JSPlugin({ prefix: 'MRD', version: '1.2.3', author: 'MiaoWoo', servers: [constants.ServerType.Bukkit], source: __filename })
|
||||||
export class MiaoReward extends interfaces.Plugin {
|
export class MiaoReward extends interfaces.Plugin {
|
||||||
private serverInfo
|
private serverInfo: any
|
||||||
private cacheBindUuid = ''
|
private cacheBindUuid = ''
|
||||||
private zeroMapView = undefined
|
private zeroMapView = undefined
|
||||||
private zeroMapRender: QRCodeRender = undefined
|
private zeroMapRender: QRCodeRender = undefined
|
||||||
@@ -67,14 +67,16 @@ export class MiaoReward extends interfaces.Plugin {
|
|||||||
private bindingNotify = new java.util.HashSet<org.bukkit.entity.Player>()
|
private bindingNotify = new java.util.HashSet<org.bukkit.entity.Player>()
|
||||||
private drawCooldown = new Map<string, number>()
|
private drawCooldown = new Map<string, number>()
|
||||||
|
|
||||||
@inject(chat.Chat)
|
@Autowired()
|
||||||
private chat: chat.Chat
|
private chat: chat.Chat
|
||||||
@inject(server.Server)
|
@Autowired()
|
||||||
private server: server.Server
|
private server: server.Server
|
||||||
@inject(task.TaskManager)
|
@Autowired()
|
||||||
private taskManager: task.TaskManager
|
private taskManager: task.TaskManager
|
||||||
@inject(channel.Channel)
|
@Autowired()
|
||||||
@optional() private Channel: channel.Channel
|
private channel: channel.Channel
|
||||||
|
@Autowired()
|
||||||
|
private bungee: channel.proxy.BungeeCord
|
||||||
|
|
||||||
@Config()
|
@Config()
|
||||||
private config = {
|
private config = {
|
||||||
@@ -97,6 +99,10 @@ export class MiaoReward extends interfaces.Plugin {
|
|||||||
this.config.prefix = this.config.prefix || '§6[§b广告系统§6]§r'
|
this.config.prefix = this.config.prefix || '§6[§b广告系统§6]§r'
|
||||||
this.config.drawCommand = this.config.drawCommand || 'p give %player_name% %amount%'
|
this.config.drawCommand = this.config.drawCommand || 'p give %player_name% %amount%'
|
||||||
this.config.drawCooldown = this.config.drawCooldown || 300
|
this.config.drawCooldown = this.config.drawCooldown || 300
|
||||||
|
this.updateServerInfo()
|
||||||
|
}
|
||||||
|
|
||||||
|
private updateServerInfo(player?: any) {
|
||||||
this.taskManager.create(() => {
|
this.taskManager.create(() => {
|
||||||
if (this.config.serverId) {
|
if (this.config.serverId) {
|
||||||
let result = this.httpPost(`https://reward.yumc.pw/server/server`, {
|
let result = this.httpPost(`https://reward.yumc.pw/server/server`, {
|
||||||
@@ -105,21 +111,61 @@ export class MiaoReward extends interfaces.Plugin {
|
|||||||
})
|
})
|
||||||
if (result.code == 200) {
|
if (result.code == 200) {
|
||||||
this.serverInfo = result.data
|
this.serverInfo = result.data
|
||||||
|
if (player) this.bungee.for(player).forward("ALL", "MiaoReward", { type: "updateServerInfo", data: result.data }).send()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).async().submit()
|
}).async().submit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JSClass('com.google.common.io.ByteStreams')
|
||||||
|
private ByteStreams: any
|
||||||
|
|
||||||
enable() {
|
enable() {
|
||||||
this.initPlaceholderAPI()
|
this.initPlaceholderAPI()
|
||||||
this.channelOff = this.Channel?.listen(this, 'BungeeCord', () => {
|
this.initBungeeCord()
|
||||||
this.isBungeeCord = true
|
this.initZeroMap()
|
||||||
this.PlayerJoinEvent['off']()
|
}
|
||||||
this.channelOff.off()
|
|
||||||
|
private initBungeeCord() {
|
||||||
|
this.channelOff = this.channel?.listen(this, 'BungeeCord', (data) => {
|
||||||
|
if (!this.isBungeeCord) {
|
||||||
|
this.isBungeeCord = true
|
||||||
|
this.PlayerJoinEvent['off']()
|
||||||
|
}
|
||||||
|
let input = this.ByteStreams.newDataInput(data)
|
||||||
|
let subChannel = input.readUTF()
|
||||||
|
switch (subChannel) {
|
||||||
|
case "GetServer":
|
||||||
|
this.isBungeeCord = true
|
||||||
|
let serverName = input.readUTF()
|
||||||
|
break
|
||||||
|
case "MiaoReward":
|
||||||
|
this.readForward(input)
|
||||||
|
break
|
||||||
|
}
|
||||||
})
|
})
|
||||||
let players = this.server.getOnlinePlayers()
|
let players = this.server.getOnlinePlayers()
|
||||||
if (players.length) this.bungeeCordDetect(players[0])
|
if (players.length) this.bungeeCordDetect(players[0])
|
||||||
this.initZeroMap()
|
}
|
||||||
|
|
||||||
|
cmdrun(sender: any, ...args: any[]) {
|
||||||
|
try {
|
||||||
|
let tfunc = new Function(`return '§a返回结果: §r'+ eval(${JSON.stringify(args.join(' '))});`)
|
||||||
|
this.logger.sender(sender, tfunc.apply(this) + '')
|
||||||
|
} catch (ex) {
|
||||||
|
this.logger.sender(sender, this.logger.stack(ex))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private readForward(input) {
|
||||||
|
let message = JSON.parse(input.readUTF())
|
||||||
|
console.log(message)
|
||||||
|
switch (message.type) {
|
||||||
|
case "updateServerInfo":
|
||||||
|
this.serverInfo = message.data
|
||||||
|
console.console(this.config.prefix, '§6兑换比例已更新为:§a', message.data.ratio)
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private initPlaceholderAPI() {
|
private initPlaceholderAPI() {
|
||||||
@@ -140,11 +186,13 @@ export class MiaoReward extends interfaces.Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private initZeroMap() {
|
private initZeroMap() {
|
||||||
this.zeroMapRender = new QRCodeRender()
|
this.taskManager.create(() => {
|
||||||
this.zeroMapView = Bukkit.getMap(0) || Bukkit.createMap(Bukkit.getWorlds()[0])
|
this.zeroMapRender = new QRCodeRender()
|
||||||
this.zeroMapView.setScale(MapView.Scale.FARTHEST)
|
this.zeroMapView = Bukkit.getMap(0) || Bukkit.createMap(Bukkit.getWorlds()[0])
|
||||||
this.zeroMapView.getRenderers().forEach(r => this.zeroMapView.removeRenderer(r))
|
this.zeroMapView.setScale(MapView.Scale.FARTHEST)
|
||||||
this.zeroMapView.addRenderer(this.zeroMapRender.getHandler())
|
this.zeroMapView.getRenderers().forEach(r => this.zeroMapView.removeRenderer(r))
|
||||||
|
this.zeroMapView.addRenderer(this.zeroMapRender.getHandler())
|
||||||
|
}).submit()
|
||||||
}
|
}
|
||||||
|
|
||||||
disable() {
|
disable() {
|
||||||
@@ -167,9 +215,10 @@ export class MiaoReward extends interfaces.Plugin {
|
|||||||
|
|
||||||
private scanAuth(sender: org.bukkit.entity.Player, scanType: string, scanObj: { title: string, content: string }, success: (token: string, user: any) => void, cancel?: () => void) {
|
private scanAuth(sender: org.bukkit.entity.Player, scanType: string, scanObj: { title: string, content: string }, success: (token: string, user: any) => void, cancel?: () => void) {
|
||||||
this.chat.sendTitle(sender, this.config.prefix, '§a正在获取授权二维码...')
|
this.chat.sendTitle(sender, this.config.prefix, '§a正在获取授权二维码...')
|
||||||
|
this.logger.sender(sender, '§a正在获取授权二维码...')
|
||||||
let scan = this.httpPost('https://reward.yumc.pw/auth/scan', { ...scanObj, type: scanType })
|
let scan = this.httpPost('https://reward.yumc.pw/auth/scan', { ...scanObj, type: scanType })
|
||||||
if (scan.code == 200) {
|
if (scan.code == 200) {
|
||||||
let sync = { scaned: false, timeout: false }
|
let sync = { scaned: false }
|
||||||
this.taskManager.create(() => {
|
this.taskManager.create(() => {
|
||||||
let result = this.httpPost('https://reward.yumc.pw/auth/scanCheck', {
|
let result = this.httpPost('https://reward.yumc.pw/auth/scanCheck', {
|
||||||
token: scan.data.token,
|
token: scan.data.token,
|
||||||
@@ -212,14 +261,19 @@ export class MiaoReward extends interfaces.Plugin {
|
|||||||
let bindUser = Bukkit.getPlayerExact(this.bindingUser)
|
let bindUser = Bukkit.getPlayerExact(this.bindingUser)
|
||||||
if (bindUser && bindUser.isOnline() && this.isQrCodeItem(bindUser.getItemInHand())[0]) {
|
if (bindUser && bindUser.isOnline() && this.isQrCodeItem(bindUser.getItemInHand())[0]) {
|
||||||
this.bindingNotify.add(sender)
|
this.bindingNotify.add(sender)
|
||||||
this.logger.sender(sender, "§c当前 §a" + this.bindingUser + " §c玩家正在扫码 §6请稍候 §e" + this.bindingLeftTime + "秒 §6后重试...")
|
this.logger.sender(sender, [
|
||||||
|
"§c当前 §a" + this.bindingUser + " §c玩家正在扫码",
|
||||||
|
"§6请等待 §e" + this.bindingLeftTime + "秒 §6后重试...",
|
||||||
|
"§a玩家操作完成后将会通知您继续操作..."
|
||||||
|
])
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.drawCooldown.has(sender.getName())) {
|
if (this.drawCooldown.has(sender.getName()) && !sender.isOp()) {
|
||||||
let leftTime = cooldown - (Date.now() - this.drawCooldown.get(sender.getName())) / 1000
|
let leftTime = cooldown - (Date.now() - this.drawCooldown.get(sender.getName())) / 1000
|
||||||
if (leftTime > 0) {
|
if (leftTime > 0) {
|
||||||
return this.logger.sender(sender, `§c扫码功能冷却中 剩余 ${leftTime} 秒!`)
|
this.logger.sender(sender, `§c扫码功能冷却中 剩余 ${leftTime} 秒!`)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.drawCooldown.set(sender.getName(), Date.now())
|
this.drawCooldown.set(sender.getName(), Date.now())
|
||||||
@@ -253,7 +307,14 @@ export class MiaoReward extends interfaces.Plugin {
|
|||||||
this.scanAuth(sender,
|
this.scanAuth(sender,
|
||||||
'draw', {
|
'draw', {
|
||||||
title: '兑换授权',
|
title: '兑换授权',
|
||||||
content: "是否授权 " + this.serverInfo.name + " 服务器\n兑换 " + amount + " 喵币 到 " + sender.getName()
|
content: [
|
||||||
|
"是否授权 " + this.serverInfo.name + " 兑换喵币",
|
||||||
|
"兑换玩家: " + sender.getName(),
|
||||||
|
"兑换数量: " + amount,
|
||||||
|
"兑换比例: " + parseFloat(this.serverInfo.ratio),
|
||||||
|
"预计到帐: " + (amount * this.serverInfo.ratio).toFixed(0),
|
||||||
|
"注意: 数据可能更新不及时 请以实际到账金额为准!"
|
||||||
|
].join('\n')
|
||||||
}, (token: string) => {
|
}, (token: string) => {
|
||||||
this.drawCoin(sender, amount, token)
|
this.drawCoin(sender, amount, token)
|
||||||
})
|
})
|
||||||
@@ -282,8 +343,8 @@ export class MiaoReward extends interfaces.Plugin {
|
|||||||
return this.sendError(sender, '§6执行命令 §3/' + command + ' §c可能存在异常')
|
return this.sendError(sender, '§6执行命令 §3/' + command + ' §c可能存在异常')
|
||||||
}
|
}
|
||||||
this.logger.sender(sender, draw.msg.split('\n'))
|
this.logger.sender(sender, draw.msg.split('\n'))
|
||||||
this.sendBoardcast(sender, `${this.config.prefix}§6玩家 §b${sender.getName()} §6成功将 §a${amount}喵币 §6兑换成 §c${draw.data}点券!`)
|
this.sendBroadcast(sender, `${this.config.prefix}§6玩家 §b${sender.getName()} §6成功将 §a${amount}喵币 §6兑换成 §c${draw.data}点券!`)
|
||||||
this.sendBoardcast(sender, `${this.config.prefix}§c/mrd help §b查看广告系统帮助 §6快来一起看广告赚点券吧!`)
|
this.sendBroadcast(sender, `${this.config.prefix}§c/mrd help §b查看广告系统帮助 §6快来一起看广告赚点券吧!`)
|
||||||
}).submit()
|
}).submit()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,7 +374,7 @@ export class MiaoReward extends interfaces.Plugin {
|
|||||||
`§6====== ${this.config.prefix} §a喵币兑换排行 §6======`,
|
`§6====== ${this.config.prefix} §a喵币兑换排行 §6======`,
|
||||||
]
|
]
|
||||||
if (boardcast) {
|
if (boardcast) {
|
||||||
ranks.forEach(l => this.sendBoardcast(sender, l))
|
ranks.forEach(l => this.sendBroadcast(sender, l))
|
||||||
} else {
|
} else {
|
||||||
this.logger.sender(sender, ranks)
|
this.logger.sender(sender, ranks)
|
||||||
}
|
}
|
||||||
@@ -338,13 +399,13 @@ export class MiaoReward extends interfaces.Plugin {
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdratio(sender: any, ratio: number, confirm: string) {
|
cmdratio(sender: any, ratioStr: string, confirm: string) {
|
||||||
if (!sender.isOp()) { return this.logger.sender(sender, '§4你没有此命令的权限!') }
|
if (!sender.isOp()) { return this.logger.sender(sender, '§4你没有此命令的权限!') }
|
||||||
let mbr = (1 / ratio).toFixed(4)
|
let [ratio, mbr, msg] = this.ratio2string(ratioStr)
|
||||||
if (!confirm) {
|
if (!confirm) {
|
||||||
return this.logger.sender(sender, [
|
return this.logger.sender(sender, [
|
||||||
'§4警告: 您正在设置服务器喵币/点券兑换比例 设置后将实时生效!',
|
'§4警告: 您正在设置服务器喵币/点券兑换比例 设置后将实时生效!',
|
||||||
`§6您设置的兑换比例为 §c${ratio} §6=> §a${mbr}喵币 §6兑换 §c1点券`,
|
`§6您设置的兑换比例为 ` + msg,
|
||||||
`§6玩家至少需要 §a${mbr}喵币 §6才可以兑换点券!`,
|
`§6玩家至少需要 §a${mbr}喵币 §6才可以兑换点券!`,
|
||||||
`§6请执行 §b/mrd ratio §c${ratio} §econfirm §c确认修改!`
|
`§6请执行 §b/mrd ratio §c${ratio} §econfirm §c确认修改!`
|
||||||
])
|
])
|
||||||
@@ -359,22 +420,22 @@ export class MiaoReward extends interfaces.Plugin {
|
|||||||
return this.logger.sender(sender, `§4操作异常 §6服务器返回: §c${result.msg}`)
|
return this.logger.sender(sender, `§4操作异常 §6服务器返回: §c${result.msg}`)
|
||||||
}
|
}
|
||||||
this.logger.sender(sender, `§a操作成功 §6服务器返回: §a${result.msg}`)
|
this.logger.sender(sender, `§a操作成功 §6服务器返回: §a${result.msg}`)
|
||||||
this.sendBoardcast(sender, `${this.config.prefix} §6当前兑换比例已调整为 §c${ratio} §6=> §a${mbr}喵币 §6兑换 §c1点券!`)
|
this.updateServerInfo(sender)
|
||||||
|
this.sendBroadcast(sender, `${this.config.prefix} §6当前兑换比例已调整为 ` + msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JSClass('java.io.ByteArrayOutputStream')
|
private ratio2string(ratio) {
|
||||||
private ByteArrayOutputStream
|
ratio = parseFloat(ratio)
|
||||||
@JSClass('java.io.DataOutputStream')
|
if (ratio > 1) {
|
||||||
private DataOutputStream
|
return [ratio, 1, `§c${ratio} §6就是 §a1喵币 §6=> §c${ratio}点券!`]
|
||||||
|
}
|
||||||
|
let mbr = Math.round(1 / ratio * 10000) / 10000
|
||||||
|
return [ratio, mbr, `§c${ratio} §6就是 §a${mbr}喵币 §6=> §c1点券!`]
|
||||||
|
}
|
||||||
|
|
||||||
private sendBoardcast(player, message) {
|
private sendBroadcast(player, message) {
|
||||||
if (!this.isBungeeCord) { return org.bukkit.Bukkit.broadcastMessage(message) }
|
if (!this.isBungeeCord) { return org.bukkit.Bukkit.broadcastMessage(message) }
|
||||||
let byteArray = new this.ByteArrayOutputStream()
|
this.bungee.for(player).broadcast(message).send()
|
||||||
let out = new this.DataOutputStream(byteArray)
|
|
||||||
out.writeUTF("Message")
|
|
||||||
out.writeUTF("ALL")
|
|
||||||
out.writeUTF(message)
|
|
||||||
player.sendPluginMessage(base.getInstance(), "BungeeCord", byteArray.toByteArray())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bindServer(sender: org.bukkit.entity.Player) {
|
private bindServer(sender: org.bukkit.entity.Player) {
|
||||||
@@ -589,10 +650,7 @@ CAST TIME : ${Date.now() - startTime}`)
|
|||||||
|
|
||||||
private bungeeCordDetect(player) {
|
private bungeeCordDetect(player) {
|
||||||
if (this.isBungeeCord === undefined && player) {
|
if (this.isBungeeCord === undefined && player) {
|
||||||
let byteArray = new this.ByteArrayOutputStream()
|
this.bungee.for(player).getServer().send()
|
||||||
let out = new this.DataOutputStream(byteArray)
|
|
||||||
out.writeUTF("GetServer")
|
|
||||||
player.sendPluginMessage(base.getInstance(), "BungeeCord", byteArray.toByteArray())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -606,7 +664,6 @@ CAST TIME : ${Date.now() - startTime}`)
|
|||||||
let [cancelled, id] = this.isQrCodeItem(event.getItemDrop().getItemStack())
|
let [cancelled, id] = this.isQrCodeItem(event.getItemDrop().getItemStack())
|
||||||
if (id != null && id != undefined && cancelled) {
|
if (id != null && id != undefined && cancelled) {
|
||||||
event.getItemDrop().remove()
|
event.getItemDrop().remove()
|
||||||
this.cancelTask(event.getPlayer())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -616,7 +673,6 @@ CAST TIME : ${Date.now() - startTime}`)
|
|||||||
let [cancelled, id] = this.isQrCodeItem(inv.getItem(event.getPreviousSlot() as any))
|
let [cancelled, id] = this.isQrCodeItem(inv.getItem(event.getPreviousSlot() as any))
|
||||||
if (id != null && id != undefined && cancelled) {
|
if (id != null && id != undefined && cancelled) {
|
||||||
inv.setItem(event.getPreviousSlot(), null)
|
inv.setItem(event.getPreviousSlot(), null)
|
||||||
this.cancelTask(event.getPlayer())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -626,7 +682,6 @@ CAST TIME : ${Date.now() - startTime}`)
|
|||||||
let [cancelled, id] = this.isQrCodeItem(item)
|
let [cancelled, id] = this.isQrCodeItem(item)
|
||||||
if (id != null && id != undefined && cancelled) {
|
if (id != null && id != undefined && cancelled) {
|
||||||
event.getInventory().setItem(event.getSlot(), null)
|
event.getInventory().setItem(event.getSlot(), null)
|
||||||
this.cancelTask(event.getWhoClicked())
|
|
||||||
event.setCancelled(true)
|
event.setCancelled(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -637,9 +692,10 @@ CAST TIME : ${Date.now() - startTime}`)
|
|||||||
}
|
}
|
||||||
|
|
||||||
private cancelTask(player) {
|
private cancelTask(player) {
|
||||||
console.ex(new Error())
|
if (!this.isBinding) return
|
||||||
this.isBinding = false
|
this.isBinding = false
|
||||||
this.bindingTask.cancel()
|
this.bindingTask.cancel()
|
||||||
|
this.bindingTask = undefined
|
||||||
this.bindingUser = 'unknow'
|
this.bindingUser = 'unknow'
|
||||||
this.checkAndClear(player)
|
this.checkAndClear(player)
|
||||||
this.chat.sendActionBar(player, "")
|
this.chat.sendActionBar(player, "")
|
||||||
|
|||||||
@@ -27,25 +27,28 @@ let langMap = {
|
|||||||
'main.command.help.tip': '§6请执行 §b/{command} §ahelp §6查看帮助!',
|
'main.command.help.tip': '§6请执行 §b/{command} §ahelp §6查看帮助!',
|
||||||
'main.command.no.permission': '§c你没有此命令的权限!',
|
'main.command.no.permission': '§c你没有此命令的权限!',
|
||||||
'list.install.header': '§6当前 §bMiaoScript §6已安装下列插件:',
|
'list.install.header': '§6当前 §bMiaoScript §6已安装下列插件:',
|
||||||
'list.install.body': '§6插件名称: §b{name}\n§6版本: §a{version}\n§6作者: §3{author}\n§6来源: §c{from}',
|
'list.install.body': '§6插件名称: §b{name} §6版本: §a{version}\n§6作者: §3{author} §6来源: §c{from}',
|
||||||
'list.header': '§6当前 §bMiaoScriptPackageCenter §6中存在下列插件:',
|
'list.header': '§6当前 §bMiaoScriptPackageCenter §6中存在下列插件:',
|
||||||
'list.body': '§6插件名称: §b{name}\n§6版本: §a{version}\n§6作者: §3{author}\n§6更新时间: §9{updated_at}',
|
'list.body': '§6插件名称: §b{name} §6版本: §a{version}\n§6作者: §3{author} §6更新时间: §9{updated_at}',
|
||||||
'plugin.not.exists': '§6插件 §b{name} §c不存在!',
|
'plugin.not.exists': '§6插件 §b{name} §c不存在!',
|
||||||
'plugin.unload.finish': '§6插件 §b{name} §a已卸载!',
|
'plugin.unload.start': '§c开始卸载 §6插件 §b{name} §6版本 §3{version}!',
|
||||||
'plugin.reload.finish': '§6插件 §b{name} §a重载完成!',
|
'plugin.unload.finish': '§6插件 §b{name} §6版本 §3{version} §a已卸载!',
|
||||||
|
'plugin.reload.start': '§a开始重载 §6插件 §b{name} §6版本 §3{version}!',
|
||||||
|
'plugin.reload.finish': '§6插件 §b{name} §6版本 §3{version} §a重载完成!',
|
||||||
'plugin.name.empty': '§c请输入插件名称!',
|
'plugin.name.empty': '§c请输入插件名称!',
|
||||||
'cloud.update.finish': '§6成功从 §aMiaoScriptPackageCenter §6获取到 §a{length} §6个插件!',
|
'cloud.update.finish': '§6成功从 §aMiaoScriptPackageCenter §6获取到 §a{length} §6个插件!',
|
||||||
'cloud.not.exists': '§6当前 §aMiaoScriptPackageCenter §c不存在 §a{name} §c插件!',
|
'cloud.not.exists': '§6当前 §aMiaoScriptPackageCenter §c不存在 §a{name} §c插件!',
|
||||||
'cloud.update.exists': '§6插件 §b{name} §a发现新版本 §3{new_version} §6当前版本 §3{old_version}!',
|
'cloud.update.exists': '§6插件 §b{name} §a发现新版本 §3{new_version} §6当前版本 §3{old_version}!',
|
||||||
'download.start': '§6开始下载插件: §b{name}',
|
'download.start': '§6开始下载插件: §b{name} §6版本 §3{version}',
|
||||||
'download.url': '§6插件下载地址: §b{url}',
|
'download.url': '§6插件下载地址: §b{url}',
|
||||||
'download.finish': '§6插件 §b{name} §a下载完毕 开始加载 ...',
|
'download.finish': '§6插件 §b{name} §6版本 §3{version} §a下载完毕 开始加载 ...',
|
||||||
'install.finish': '§6插件 §b{name} §a安装成功!',
|
'install.finish': '§6插件 §b{name} §6版本 §3{version} §a安装成功!',
|
||||||
'update.finish': '§6插件 §b{name} §a更新成功!',
|
'update.finish': '§6插件 §b{name} §6版本 §3{version} §a更新成功!',
|
||||||
'upgrade.confirm': '§6您正在尝试升级 §bMiaoScript §c核心 §6请执行 §b/mpm §aupgrade §cconfirm §6确认执行!',
|
'upgrade.confirm': '§6您正在尝试更新 §bMiaoScript §c核心 §6请执行 §b/mpm §aupgrade §cconfirm §6确认执行!',
|
||||||
|
'upgrade.failed': '§6尝试热更新 §bMiaoScript §c核心 §4失败! §6请重启服务器完成更新...',
|
||||||
'deploy.token.not.exists': '§4请先配置发布Token!',
|
'deploy.token.not.exists': '§4请先配置发布Token!',
|
||||||
'deploy.success': '§6插件 §b{name} §a发布成功! §6服务器返回: §a{msg}',
|
'deploy.success': '§6插件 §b{name} §6版本 §3{version} §a发布成功! §6服务器返回: §a{msg}',
|
||||||
'deploy.fail': '§6插件 §b{name} §c发布失败! §6服务器返回: §c{msg}',
|
'deploy.fail': '§6插件 §b{name} §6版本 §3{version} §c发布失败! §6服务器返回: §c{msg}',
|
||||||
'run.script': '§b运行脚本:§r {script}',
|
'run.script': '§b运行脚本:§r {script}',
|
||||||
'run.result': '§a返回结果:§r {result}',
|
'run.result': '§a返回结果:§r {result}',
|
||||||
'run.noresult': '§4没有返回结果!',
|
'run.noresult': '§4没有返回结果!',
|
||||||
@@ -53,7 +56,26 @@ let langMap = {
|
|||||||
|
|
||||||
let fallbackMap = langMap
|
let fallbackMap = langMap
|
||||||
|
|
||||||
@JSPlugin({ prefix: 'PM', version: '1.2.0', author: 'MiaoWoo', source: __filename })
|
class FakeSender {
|
||||||
|
private _proxy
|
||||||
|
private name: string
|
||||||
|
private plugin: MiaoScriptPackageManager
|
||||||
|
constructor(name: string, plugin: MiaoScriptPackageManager, superclass: any) {
|
||||||
|
this.name = name
|
||||||
|
this.plugin = plugin
|
||||||
|
let FakeSenderAdapter = Java.extend(superclass, {
|
||||||
|
getName: () => this.name,
|
||||||
|
isOp: () => true,
|
||||||
|
sendMessage: (message) => this.plugin.sendBungeeCordMessage(this.name, `§6[§3BPM§6][§a${this.plugin.serverName}§6] ${message}`)
|
||||||
|
})
|
||||||
|
this._proxy = new FakeSenderAdapter()
|
||||||
|
}
|
||||||
|
getHandler() {
|
||||||
|
return this._proxy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@JSPlugin({ prefix: 'PM', version: '1.3.0', author: 'MiaoWoo', source: __filename })
|
||||||
export class MiaoScriptPackageManager extends interfaces.Plugin {
|
export class MiaoScriptPackageManager extends interfaces.Plugin {
|
||||||
@inject(plugin.PluginManager)
|
@inject(plugin.PluginManager)
|
||||||
private pluginManager: pluginApi.PluginManager
|
private pluginManager: pluginApi.PluginManager
|
||||||
@@ -78,7 +100,8 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
|
|||||||
private packageCache: any[] = [];
|
private packageCache: any[] = [];
|
||||||
private packageNameCache: string[] = [];
|
private packageNameCache: string[] = [];
|
||||||
|
|
||||||
private serverName: string
|
private isBungeeCord = false
|
||||||
|
public serverName: string
|
||||||
private translate: Translate
|
private translate: Translate
|
||||||
private channelOff: { off: () => void }
|
private channelOff: { off: () => void }
|
||||||
|
|
||||||
@@ -97,6 +120,7 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
|
|||||||
let subChannel = input.readUTF()
|
let subChannel = input.readUTF()
|
||||||
switch (subChannel) {
|
switch (subChannel) {
|
||||||
case "GetServer":
|
case "GetServer":
|
||||||
|
this.isBungeeCord = true
|
||||||
this.serverName = input.readUTF()
|
this.serverName = input.readUTF()
|
||||||
break
|
break
|
||||||
case "MiaoScriptPackageManager":
|
case "MiaoScriptPackageManager":
|
||||||
@@ -134,8 +158,20 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
|
|||||||
}
|
}
|
||||||
private readForward(input) {
|
private readForward(input) {
|
||||||
let message = JSON.parse(input.readUTF())
|
let message = JSON.parse(input.readUTF())
|
||||||
this.taskManager.create(() => this.main(this.server.getConsoleSender(), message.command, message.args)).async().submit()
|
let fakeSender = this.getProxySender(message.sender)
|
||||||
this.sendBungeeCordMessage(message.sender, `§6[§cMS§6][§bPM§6] [§3BPM§6][§a${this.serverName}§6] §6命令 §b/mpm ${message.args?.join?.(' ')} §a执行成功!`)
|
this.taskManager.create(() => this.main(fakeSender, message.command, message.args)).async().submit()
|
||||||
|
this.logger.sender(fakeSender, `§6命令 §b/mpm ${message.args?.join?.(' ')} §a执行成功!`)
|
||||||
|
}
|
||||||
|
|
||||||
|
private getProxySender(name: string) {
|
||||||
|
switch (this.serverType) {
|
||||||
|
case constants.ServerType.Bukkit:
|
||||||
|
return new FakeSender(name, this, Java.type('org.bukkit.command.CommandSender')).getHandler()
|
||||||
|
case constants.ServerType.Sponge:
|
||||||
|
return new FakeSender(name, this, Java.type('org.spongepowered.api.command.CommandSource')).getHandler()
|
||||||
|
default:
|
||||||
|
return this.server.getConsoleSender()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Listener({ servers: [constants.ServerType.Bukkit] })
|
@Listener({ servers: [constants.ServerType.Bukkit] })
|
||||||
@@ -154,7 +190,7 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private sendBungeeCordMessage(sender, message) {
|
sendBungeeCordMessage(sender, message) {
|
||||||
let players = this.server.getOnlinePlayers()
|
let players = this.server.getOnlinePlayers()
|
||||||
if (players.length) {
|
if (players.length) {
|
||||||
let byteArray = new this.ByteArrayOutputStream()
|
let byteArray = new this.ByteArrayOutputStream()
|
||||||
@@ -172,20 +208,22 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
|
|||||||
|
|
||||||
@Cmd({ servers: [`!${constants.ServerType.Bungee}`] })
|
@Cmd({ servers: [`!${constants.ServerType.Bungee}`] })
|
||||||
bmpm(sender: any, command: string, args: string[]) {
|
bmpm(sender: any, command: string, args: string[]) {
|
||||||
if (!sender.isOp()) { return this.i18n(sender, 'main.command.no.permission') }
|
if (!sender?.isOp()) { return this.i18n(sender, 'main.command.no.permission') }
|
||||||
|
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.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/mpm ${args.join?.(' ')} §a发布成功!`)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cmd({ servers: [constants.ServerType.Bungee] })
|
@Cmd({ servers: [constants.ServerType.Bungee] })
|
||||||
mpmanager(sender: any, command: string, args: string[]) {
|
mpmanager(sender: any, command: string, args: string[]) {
|
||||||
if (!sender.isOp()) { return this.i18n(sender, 'main.command.no.permission') }
|
if (!sender?.isOp()) { return this.i18n(sender, 'main.command.no.permission') }
|
||||||
this.taskManager.create(() => this.main(sender, command, args)).async().submit()
|
this.taskManager.create(() => this.main(sender, command, args)).async().submit()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cmd({ servers: [`!${constants.ServerType.Bungee}`] })
|
@Cmd({ servers: [`!${constants.ServerType.Bungee}`] })
|
||||||
mpm(sender: any, command: string, args: string[]) {
|
mpm(sender: any, command: string, args: string[]) {
|
||||||
if (!sender.isOp()) { return this.i18n(sender, 'main.command.no.permission') }
|
if (!sender?.isOp()) { return this.i18n(sender, 'main.command.no.permission') }
|
||||||
this.taskManager.create(() => this.main(sender, command, args)).async().submit()
|
this.taskManager.create(() => this.main(sender, command, args)).async().submit()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,6 +246,12 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
|
|||||||
this.logger.sender(sender, help)
|
this.logger.sender(sender, help)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmdinfo(sender: any) {
|
||||||
|
this.logger.sender(sender, [
|
||||||
|
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
cmdload(sender: any, name: string) {
|
cmdload(sender: any, name: string) {
|
||||||
let pluginFile = fs.concat(__dirname + '', name)
|
let pluginFile = fs.concat(__dirname + '', name)
|
||||||
if (!fs.exists(pluginFile)) {
|
if (!fs.exists(pluginFile)) {
|
||||||
@@ -237,7 +281,10 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.download(sender, name)
|
this.download(sender, name, false, () => {
|
||||||
|
let plugin = this.pluginManager.loadFromFile(fs.concat(root, this.pluginFolder, name + '.js'))
|
||||||
|
this.i18n(sender, 'install.finish', { name, version: plugin.description.version })
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdupdate(sender: any, name: string) {
|
cmdupdate(sender: any, name: string) {
|
||||||
@@ -253,29 +300,46 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
|
|||||||
if (!confirm) { return this.i18n(sender, 'upgrade.confirm') }
|
if (!confirm) { return this.i18n(sender, 'upgrade.confirm') }
|
||||||
let enginePath = fs.path(fs.file(root, 'node_modules'))
|
let enginePath = fs.path(fs.file(root, 'node_modules'))
|
||||||
if (enginePath.startsWith(root)) {
|
if (enginePath.startsWith(root)) {
|
||||||
base.delete(enginePath)
|
try {
|
||||||
this.cmdrestart(sender)
|
base.delete(enginePath)
|
||||||
|
this.cmdrestart(sender)
|
||||||
|
} catch (ex) {
|
||||||
|
if (global.debug) {
|
||||||
|
console.ex(ex)
|
||||||
|
}
|
||||||
|
if (fs.exists(enginePath)) {
|
||||||
|
this.i18n(sender, 'upgrade.failed')
|
||||||
|
fs.create(fs.file(root, 'upgrade'))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (this.checkPlugin(sender, name)) {
|
if (this.checkPlugin(sender, name)) {
|
||||||
this.update(sender, name)
|
this.update(sender, name, () => this.reload(sender, name))
|
||||||
this.pluginManager.reload(name)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdunload(sender: any, name: string) {
|
cmdunload(sender: any, name: string) {
|
||||||
if (this.checkPlugin(sender, name)) {
|
if (this.checkPlugin(sender, name)) {
|
||||||
this.pluginManager.disable(name)
|
let plugin = this.pluginManager.getPlugins().get(name)
|
||||||
this.i18n(sender, 'plugin.unload.finish', { name })
|
this.i18n(sender, 'plugin.unload.start', { name, version: plugin.description.version })
|
||||||
|
this.pluginManager.disable(plugin)
|
||||||
|
this.i18n(sender, 'plugin.unload.finish', { name, version: plugin.description.version })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdreload(sender: any, name: string) {
|
cmdreload(sender: any, name: string) {
|
||||||
name = name || this.description.name
|
name = name || this.description.name
|
||||||
|
this.reload(sender, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
private reload(sender: any, name: string) {
|
||||||
if (this.checkPlugin(sender, name)) {
|
if (this.checkPlugin(sender, name)) {
|
||||||
this.pluginManager.reload(name)
|
let plugin = this.pluginManager.getPlugins().get(name)
|
||||||
this.i18n(sender, 'plugin.reload.finish', { name })
|
this.i18n(sender, 'plugin.reload.start', { name, version: plugin.description.version })
|
||||||
|
this.pluginManager.reload(plugin)
|
||||||
|
this.i18n(sender, 'plugin.reload.finish', { name, version: this.pluginManager.getPlugins().get(name).description.version })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,13 +424,16 @@ return '§a返回结果: §r'+ eval(${JSON.stringify(code)});`)
|
|||||||
}).async().submit()
|
}).async().submit()
|
||||||
}
|
}
|
||||||
|
|
||||||
update(sender: any, name: string) {
|
private update(sender: any, name: string, callback?: () => void) {
|
||||||
if (this.checkCloudPlugin(sender, name)) {
|
if (this.checkCloudPlugin(sender, name)) {
|
||||||
this.download(sender, name, true)
|
this.download(sender, name, true, () => {
|
||||||
|
this.i18n(sender, 'update.finish', { name, version: this.packageCache[name].version })
|
||||||
|
callback?.()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Tab()
|
@Tab({ alias: ['bmpm'] })
|
||||||
tabmpm(sender: any, command: any, args: string | any[]) {
|
tabmpm(sender: any, command: any, args: string | any[]) {
|
||||||
if (args.length === 1) { return ['list', 'install', 'update', 'upgrade', 'reload', 'restart', 'run', 'help', 'create', 'deploy'] }
|
if (args.length === 1) { return ['list', 'install', 'update', 'upgrade', 'reload', 'restart', 'run', 'help', 'create', 'deploy'] }
|
||||||
if (args.length > 1) {
|
if (args.length > 1) {
|
||||||
@@ -405,19 +472,15 @@ return '§a返回结果: §r'+ eval(${JSON.stringify(code)});`)
|
|||||||
}).async().submit()
|
}).async().submit()
|
||||||
}
|
}
|
||||||
|
|
||||||
download(sender: any, name: string, update: boolean = false) {
|
download(sender: any, name: string, update: boolean, callback?: () => void) {
|
||||||
this.taskManager.create(() => {
|
this.taskManager.create(() => {
|
||||||
this.i18n(sender, 'download.start', { name })
|
let pluginPkg = this.packageCache[name]
|
||||||
this.i18n(sender, 'download.url', { url: this.packageCache[name].url })
|
this.i18n(sender, 'download.start', { name, version: pluginPkg.version })
|
||||||
|
this.i18n(sender, 'download.url', { url: pluginPkg.url })
|
||||||
let pluginFile = update ? fs.concat(root, this.pluginFolder, 'update', name + '.js') : fs.concat(root, this.pluginFolder, name + '.js')
|
let pluginFile = update ? fs.concat(root, this.pluginFolder, 'update', name + '.js') : fs.concat(root, this.pluginFolder, name + '.js')
|
||||||
http.download(this.packageCache[name].url, pluginFile)
|
http.download(pluginPkg.url, pluginFile)
|
||||||
this.i18n(sender, 'download.finish', { name })
|
this.i18n(sender, 'download.finish', { name, version: pluginPkg.version })
|
||||||
if (!update) {
|
callback?.()
|
||||||
this.pluginManager.loadFromFile(fs.concat(root, this.pluginFolder, name + '.js'))
|
|
||||||
this.i18n(sender, 'install.finish', { name })
|
|
||||||
} else {
|
|
||||||
this.i18n(sender, 'update.finish', { name })
|
|
||||||
}
|
|
||||||
}).async().submit()
|
}).async().submit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/sponge",
|
"name": "@ccms/sponge",
|
||||||
"version": "0.9.2",
|
"version": "0.9.3",
|
||||||
"description": "MiaoScript api package",
|
"description": "MiaoScript api package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -25,8 +25,8 @@
|
|||||||
"typescript": "^3.9.6"
|
"typescript": "^3.9.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.9.2",
|
"@ccms/api": "^0.9.3",
|
||||||
"@ccms/common": "^0.9.2",
|
"@ccms/common": "^0.9.3",
|
||||||
"@ccms/container": "^0.9.2"
|
"@ccms/container": "^0.9.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
22
packages/sponge/src/chat.ts
Normal file
22
packages/sponge/src/chat.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { chat } from '@ccms/api'
|
||||||
|
import { provideSingleton } from '@ccms/container'
|
||||||
|
|
||||||
|
const Sponge = org.spongepowered.api.Sponge
|
||||||
|
const ChatTypes = org.spongepowered.api.text.chat.ChatTypes
|
||||||
|
const TextSerializers = org.spongepowered.api.text.serializer.TextSerializers
|
||||||
|
|
||||||
|
@provideSingleton(chat.Chat)
|
||||||
|
export class SpongeChat extends chat.Chat {
|
||||||
|
sendJson(sender: any, json: string | object) {
|
||||||
|
sender.sendMessage(TextSerializers.JSON.deserialize(typeof json === "string" ? json : JSON.stringify(json)))
|
||||||
|
}
|
||||||
|
sendMessage(sender: any, message: string) {
|
||||||
|
sender.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(message))
|
||||||
|
}
|
||||||
|
sendActionBar(sender: any, message: string) {
|
||||||
|
sender.sendMessage(ChatTypes.ACTION_BAR, TextSerializers.FORMATTING_CODE.deserialize(message))
|
||||||
|
}
|
||||||
|
sendTitle(sender: any, title: string, subtitle: string = '', fadeIn: number = 20, time: number = 100, fadeOut: number = 20) {
|
||||||
|
sender.sendTitle(title, subtitle, fadeIn, time, fadeOut)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@ const Callable = Java.type('java.util.concurrent.Callable')
|
|||||||
const TimeUnit = Java.type('java.util.concurrent.TimeUnit')
|
const TimeUnit = Java.type('java.util.concurrent.TimeUnit')
|
||||||
|
|
||||||
@provideSingleton(task.TaskManager)
|
@provideSingleton(task.TaskManager)
|
||||||
export class SpongeTaskManager implements task.TaskManager {
|
export class SpongeTaskManager extends task.TaskManager {
|
||||||
@inject(plugin.PluginInstance)
|
@inject(plugin.PluginInstance)
|
||||||
private pluginInstance: any
|
private pluginInstance: any
|
||||||
private syncExecutor: any
|
private syncExecutor: any
|
||||||
@@ -18,21 +18,20 @@ export class SpongeTaskManager implements task.TaskManager {
|
|||||||
this.syncExecutor = Sponge.getScheduler().createSyncExecutor(this.pluginInstance)
|
this.syncExecutor = Sponge.getScheduler().createSyncExecutor(this.pluginInstance)
|
||||||
}
|
}
|
||||||
|
|
||||||
create(func: Function): task.Task {
|
create0(func: Function): task.Task {
|
||||||
if (Object.prototype.toString.call(func) !== "[object Function]") { throw TypeError('第一个参数 Task 必须为 function !') }
|
|
||||||
return new SpongeTask(this.pluginInstance, func)
|
return new SpongeTask(this.pluginInstance, func)
|
||||||
}
|
}
|
||||||
callSyncMethod(func: Function): any {
|
callSyncMethod(func: Function): any {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return this.syncExecutor.schedule(new Callable({ call: () => func() }), java.lang.Long.valueOf(0), TimeUnit.NANOSECONDS).get()
|
return this.syncExecutor.schedule(new Callable({ call: () => func() }), java.lang.Long.valueOf(0), TimeUnit.NANOSECONDS).get()
|
||||||
}
|
}
|
||||||
disable() {
|
disable0() {
|
||||||
Sponge.getScheduler().getScheduledTasks(this.pluginInstance).forEach((task: task.Cancelable) => task.cancel())
|
Sponge.getScheduler().getScheduledTasks(this.pluginInstance).forEach((task: task.Cancelable) => task.cancel())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SpongeTask extends task.Task {
|
export class SpongeTask extends task.Task {
|
||||||
submit(...args: any[]): task.Cancelable {
|
submit0(...args: any[]): task.Cancelable {
|
||||||
let run = Task.builder().execute(new Consumer({ accept: () => this.run(...args) }))
|
let run = Task.builder().execute(new Consumer({ accept: () => this.run(...args) }))
|
||||||
if (this.isAsync) { run.async() }
|
if (this.isAsync) { run.async() }
|
||||||
if (this.laterTime) { run.delayTicks(this.laterTime) }
|
if (this.laterTime) { run.delayTicks(this.laterTime) }
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/spring",
|
"name": "@ccms/spring",
|
||||||
"version": "0.9.2",
|
"version": "0.9.3",
|
||||||
"description": "MiaoScript spring package",
|
"description": "MiaoScript spring package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -24,9 +24,9 @@
|
|||||||
"typescript": "^3.9.6"
|
"typescript": "^3.9.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.9.2",
|
"@ccms/api": "^0.9.3",
|
||||||
"@ccms/common": "^0.9.2",
|
"@ccms/common": "^0.9.3",
|
||||||
"@ccms/container": "^0.9.2",
|
"@ccms/container": "^0.9.3",
|
||||||
"@ccms/database": "^0.9.2"
|
"@ccms/database": "^0.9.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ export class SpringCommand extends command.Command {
|
|||||||
protected create(plugin: any, command: string) {
|
protected create(plugin: any, command: string) {
|
||||||
return this.commandMap.register(plugin, command)
|
return this.commandMap.register(plugin, command)
|
||||||
}
|
}
|
||||||
|
public tabComplete(sender: any, input: string, index?: number): string[] {
|
||||||
|
return this.commandMap.tabComplate(sender, input, index)
|
||||||
|
}
|
||||||
protected remove(plugin: any, command: string) {
|
protected remove(plugin: any, command: string) {
|
||||||
this.commandMap.unregister(plugin, command)
|
this.commandMap.unregister(plugin, command)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,10 +20,11 @@ export default function SpringImpl(container: Container) {
|
|||||||
}
|
}
|
||||||
const beanFactory = base.getInstance().getAutowireCapableBeanFactory()
|
const beanFactory = base.getInstance().getAutowireCapableBeanFactory()
|
||||||
container.bind(server.Console).toConstantValue(SpringConsole)
|
container.bind(server.Console).toConstantValue(SpringConsole)
|
||||||
container.bind(ioc.Autowired).toDynamicValue((ctx) => {
|
container.rebind(ioc.Autowired).toDynamicValue((ctx) => {
|
||||||
var metadata: any = reduceMetadata(ctx)
|
var metadata: any = reduceMetadata(ctx)
|
||||||
if (toString.call(metadata.named) === "[object Symbol]") { return container.get(metadata.named) }
|
let key = toString.call(metadata.named)
|
||||||
if (toString.call(metadata.named) === '[object jdk.internal.dynalink.beans.StaticClass]') { metadata.named = metadata.named.class }
|
if (key === "[object Function]" || key === "[object Symbol]") { return container.get(metadata.named) }
|
||||||
|
if (key === '[object jdk.internal.dynalink.beans.StaticClass]') { metadata.named = metadata.named.class }
|
||||||
return beanFactory.getBean(metadata.named)
|
return beanFactory.getBean(metadata.named)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { server } from '@ccms/api'
|
import { server } from '@ccms/api'
|
||||||
import { provideSingleton, inject } from '@ccms/container'
|
import { provideSingleton, inject } from '@ccms/container'
|
||||||
import { NativePluginManager } from '@ccms/api/dist/interfaces/server/native_plugin'
|
import { NativePluginManager } from '@ccms/api'
|
||||||
import { CommandMap } from './internal/command'
|
import { CommandMap } from './internal/command'
|
||||||
|
|
||||||
@provideSingleton(server.Server)
|
@provideSingleton(server.Server)
|
||||||
@@ -8,8 +8,6 @@ export class SpringServer implements server.Server {
|
|||||||
@inject(CommandMap)
|
@inject(CommandMap)
|
||||||
private commandMap: CommandMap
|
private commandMap: CommandMap
|
||||||
|
|
||||||
constructor() {
|
|
||||||
}
|
|
||||||
getVersion(): string {
|
getVersion(): string {
|
||||||
return "SpringFramework"
|
return "SpringFramework"
|
||||||
}
|
}
|
||||||
@@ -47,10 +45,4 @@ export class SpringServer implements server.Server {
|
|||||||
getRootLogger() {
|
getRootLogger() {
|
||||||
return Packages.org.slf4j.LoggerFactory.getLogger("root") || global.logger
|
return Packages.org.slf4j.LoggerFactory.getLogger("root") || global.logger
|
||||||
}
|
}
|
||||||
sendJson(sender: any, json: string | object): void {
|
|
||||||
throw new Error("Method not implemented.")
|
|
||||||
}
|
|
||||||
tabComplete(sender: any, input: string, index?: number) {
|
|
||||||
return this.commandMap.tabComplate(sender, input, index)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,44 +6,57 @@ const AtomicInteger = Java.type("java.util.concurrent.atomic.AtomicInteger")
|
|||||||
const AtomicBoolean = Java.type("java.util.concurrent.atomic.AtomicBoolean")
|
const AtomicBoolean = Java.type("java.util.concurrent.atomic.AtomicBoolean")
|
||||||
const Thread = Java.type('java.lang.Thread')
|
const Thread = Java.type('java.lang.Thread')
|
||||||
|
|
||||||
const taskId = new AtomicInteger(0)
|
|
||||||
const tasks: { [key: number]: task.Cancelable } = {}
|
|
||||||
const executor = thread_pool.create({
|
|
||||||
groupName: '@ccms/spring'
|
|
||||||
})
|
|
||||||
|
|
||||||
@provideSingleton(task.TaskManager)
|
@provideSingleton(task.TaskManager)
|
||||||
export class SpringTaskManager implements task.TaskManager {
|
export class SpringTaskManager extends task.TaskManager {
|
||||||
@inject(plugin.PluginInstance)
|
@inject(plugin.PluginInstance)
|
||||||
private pluginInstance: any
|
private pluginInstance: any
|
||||||
|
|
||||||
private innerTaskId: any
|
private taskId: any
|
||||||
private innerTasks: { [s: string]: task.Cancelable }
|
private tasks: { [s: string]: task.Cancelable }
|
||||||
private innerExecutor: java.util.concurrent.ThreadPoolExecutor
|
private executor: java.util.concurrent.ThreadPoolExecutor
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.innerTaskId = taskId
|
super()
|
||||||
this.innerTasks = tasks
|
this.taskId = new AtomicInteger(0)
|
||||||
this.innerExecutor = executor
|
this.tasks = {}
|
||||||
|
this.executor = thread_pool.create({
|
||||||
|
groupName: '@ccms/spring'
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
create(func: Function): task.Task {
|
create0(func: Function): task.Task {
|
||||||
if (Object.prototype.toString.call(func) !== "[object Function]") { throw TypeError('第一个参数 Task 必须为 function !') }
|
return new SpringTask(this.pluginInstance, func, this)
|
||||||
return new SpringTask(this.pluginInstance, func)
|
|
||||||
}
|
}
|
||||||
callSyncMethod(func: Function): any {
|
callSyncMethod(func: Function): any {
|
||||||
return func()
|
return func()
|
||||||
}
|
}
|
||||||
disable() {
|
disable0() {
|
||||||
Object.values(this.innerTasks).forEach((task) => task?.cancel())
|
Object.values(this.tasks).forEach((task) => task?.cancel())
|
||||||
this.innerExecutor.shutdown()
|
this.executor.shutdown()
|
||||||
|
}
|
||||||
|
nextId() {
|
||||||
|
return this.taskId.incrementAndGet()
|
||||||
|
}
|
||||||
|
submit(id: number, task: SpringTask, func: Function) {
|
||||||
|
this.tasks[id] = task
|
||||||
|
this.executor.execute(func as any)
|
||||||
|
}
|
||||||
|
cancel(id: number) {
|
||||||
|
delete this.tasks[id]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SpringTask extends task.Task {
|
export class SpringTask extends task.Task {
|
||||||
public id = taskId.incrementAndGet()
|
private id: number
|
||||||
|
private taskManager: SpringTaskManager
|
||||||
private running = new AtomicBoolean(true)
|
private running = new AtomicBoolean(true)
|
||||||
|
|
||||||
|
constructor(plugin: any, func: Function, taskManager: SpringTaskManager) {
|
||||||
|
super(plugin, func)
|
||||||
|
this.id = taskManager.nextId()
|
||||||
|
this.taskManager = taskManager
|
||||||
|
}
|
||||||
|
|
||||||
run(...args: any[]) {
|
run(...args: any[]) {
|
||||||
if (this.laterTime > 0) {
|
if (this.laterTime > 0) {
|
||||||
try {
|
try {
|
||||||
@@ -70,19 +83,18 @@ export class SpringTask extends task.Task {
|
|||||||
this.cancel()
|
this.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
cancel(): any {
|
cancel0(): any {
|
||||||
var wasRunning = this.running.getAndSet(false)
|
var wasRunning = this.running.getAndSet(false)
|
||||||
if (wasRunning) {
|
if (wasRunning) {
|
||||||
delete tasks[this.id]
|
this.taskManager.cancel(this.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
submit(...args: any[]): task.Cancelable {
|
submit0(...args: any[]) {
|
||||||
tasks[this.id] = this
|
this.taskManager.submit(this.id, this, () => this.run(...args))
|
||||||
executor.execute((() => this.run(...args)) as any)
|
|
||||||
return {
|
return {
|
||||||
cancel: () => {
|
cancel: () => {
|
||||||
return this.cancel()
|
return this.cancel0()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/web",
|
"name": "@ccms/web",
|
||||||
"version": "0.9.2",
|
"version": "0.9.3",
|
||||||
"description": "MiaoScript web package",
|
"description": "MiaoScript web package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
"typescript": "^3.9.6"
|
"typescript": "^3.9.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.9.2",
|
"@ccms/api": "^0.9.3",
|
||||||
"@ccms/container": "^0.9.2"
|
"@ccms/container": "^0.9.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/websocket",
|
"name": "@ccms/websocket",
|
||||||
"version": "0.9.0",
|
"version": "0.9.3",
|
||||||
"description": "MiaoScript websocket package",
|
"description": "MiaoScript websocket package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "^0.9.0",
|
"@ccms/nashorn": "^0.9.3",
|
||||||
"@javatypes/tomcat-websocket-api": "^0.0.2",
|
"@javatypes/tomcat-websocket-api": "^0.0.2",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
|
|||||||
Reference in New Issue
Block a user