feat: framework optimization

Signed-off-by: MiaoWoo <admin@yumc.pw>
backup
MiaoWoo 2022-10-14 10:07:36 +08:00
parent 2fe9bce2ea
commit 1c579c9789
6 changed files with 47 additions and 17 deletions

View File

@ -30,6 +30,10 @@ export namespace database {
*
*/
properties?: { [key: string]: any }
/**
*
*/
debug?: boolean
}
@injectable()

View File

@ -161,11 +161,12 @@ class BukkitChatInvoke_1_17_1 extends BukkitChatInvoke_1_16_5 {
return base.getClass('net.minecraft.network.protocol.Packet')
}
}
class BukkitChatInvoke_1_19 extends BukkitChatInvoke_1_17_1 {
class BukkitChatInvoke_1_18_2 extends BukkitChatInvoke_1_17_1 {
getSendPacketMethodName(playerConnectionClass: any) {
return playerConnectionClass.getMethod('a', this.getPacketClass()).getName()
}
}
class BukkitChatInvoke_1_19 extends BukkitChatInvoke_1_18_2 {
getPacketPlayOutChatClass() {
return base.getClass('net.minecraft.network.protocol.game.ClientboundSystemChatPacket')
}
@ -181,6 +182,8 @@ try {
let nmsSubVersion = nmsVersion.split("_")[1]
if (nmsSubVersion >= 19) {
bukkitChatInvoke = new BukkitChatInvoke_1_19(nmsVersion)
} else if (nmsSubVersion >= 18) {
bukkitChatInvoke = new BukkitChatInvoke_1_18_2(nmsVersion)
} else if (nmsSubVersion >= 17) {
bukkitChatInvoke = new BukkitChatInvoke_1_17_1(nmsVersion)
} else if (nmsSubVersion >= 16) {

View File

@ -19,12 +19,20 @@ interface RequestConfig {
method?: Method
headers?: { [key: string]: string }
params?: { [key: string]: string }
data?: any
data?: any,
connectTimeout?: number,
readTimeout?: number,
}
function request(config: RequestConfig) {
// @ts-ignore XMLHttpRequest class only exist nashorn polyfill
let xhr = new XMLHttpRequest()
if (config.connectTimeout) {
xhr.connectTimeout = config.connectTimeout
}
if (config.readTimeout) {
xhr.readTimeout = config.readTimeout
}
xhr.open(config.method, config.url, false)
for (const header in config.headers) {
xhr.setRequestHeader(header, config.headers[header])

View File

@ -9,6 +9,7 @@ import * as fs from '@ccms/common/dist/fs'
import { VersionUtils } from '@ccms/common/dist/version'
const UUID = Java.type('java.util.UUID')
const MiaoScriptAPI = Java.type('pw.yumc.MiaoScript.api.MiaoScriptAPI')
@provideSingleton(MiaoScriptCore)
class MiaoScriptCore {
@ -24,6 +25,10 @@ class MiaoScriptCore {
enable() {
process.emit('core.before.enable')
this.loadServerConsole()
try {
MiaoScriptAPI.setPluginManager(this.pluginManager)
} catch (error) {
}
this.loadPlugins()
process.emit('core.after.enable')
console.i18n("ms.core.engine.completed", {

View File

@ -2,12 +2,11 @@ import i18n from '@ccms/i18n'
import { plugin, server } from '@ccms/api'
import { provideSingleton, Container, ContainerInstance, Autowired } from '@ccms/container'
import './config'
import { interfaces } from './interfaces'
import { PluginTaskManager } from './task'
import { PluginEventManager } from './event'
import { PluginCommandManager } from './command'
import { PluginConfigManager } from './config'
import { PluginCommandManager } from './command'
const Thread = Java.type('java.lang.Thread')
@ -93,18 +92,16 @@ export class PluginManagerImpl implements plugin.PluginManager {
for (const [, scanner] of this.sacnnerMap) {
try {
console.i18n('ms.plugin.manager.scan', { scanner: scanner.type, folder })
let plugins = scanner.scan(folder)
console.i18n('ms.plugin.manager.scan.finish', { scanner: scanner.type, folder, size: plugins.length })
plugins.forEach(loadMetadata => {
let loadMetadatas = scanner.scan(folder)
console.i18n('ms.plugin.manager.scan.finish', { scanner: scanner.type, folder, size: loadMetadatas.length })
for (const loadMetadata of loadMetadatas) {
try {
this.loadAndRequirePlugin(loadMetadata)
} catch (error: any) {
console.error(`plugin scanner ${scanner.type} load ${loadMetadata.file} occurred error ${error}`)
console.ex(error)
}
})
}
} catch (error: any) {
console.error(`plugin scanner ${scanner.type} occurred error ${error}`)
console.ex(error)
}
}

View File

@ -74,7 +74,8 @@ type HttpHeader = { [key: string]: string }
const executor = Executors.newCachedThreadPool()
export class XMLHttpRequest {
private _timeout: number = 120000;
private _connectTimeout: number = 5000;
private _readTimeout: number = 120000;
private _responseType: ResponseType = 'text';
private _withCredentials: boolean
@ -96,10 +97,22 @@ export class XMLHttpRequest {
private _connection = null;
get timeout() {
return this._timeout
return this._readTimeout
}
set timeout(timeout: number) {
this._timeout = timeout
this._readTimeout = timeout
}
get connectTimeout() {
return this._connectTimeout
}
set connectTimeout(timeout: number) {
this._connectTimeout = timeout
}
get readTimeout() {
return this._readTimeout
}
set readTimeout(timeout: number) {
this._readTimeout = timeout
}
get readyState() {
return this._readyState
@ -169,8 +182,8 @@ export class XMLHttpRequest {
this._connection.setRequestMethod(this._method)
this._connection.setDoOutput(true)
this._connection.setDoInput(true)
this._connection.setConnectTimeout(this._timeout)
this._connection.setReadTimeout(this._timeout)
this._connection.setConnectTimeout(this._connectTimeout)
this._connection.setReadTimeout(this._readTimeout)
this.setRequestHeader('X-Requested-With', 'XMLHttpRequest')
this.setReadyState(ReadyState.OPENED)
@ -181,7 +194,7 @@ export class XMLHttpRequest {
}
if (this._readyState !== ReadyState.OPENED) { throw new Error(`Error Status ${this._readyState}!`) }
let future = executor.submit(new Callable({ call: () => this._send(body) }))
if (!this._async) { future.get(this._timeout, TimeUnit.MILLISECONDS) }
if (!this._async) { future.get(this._connectTimeout + this._readTimeout + 100, TimeUnit.MILLISECONDS) }
return future
}
get() {