@ -1,13 +0,0 @@
|
||||
function exit() {
|
||||
var http = require('@ccms/common/dist/http').default
|
||||
function upgradeModules(core) {
|
||||
if (base.version && global.ScriptEngineVersion != core['dist-tags']['latest']) {
|
||||
var Paths = Java.type('java.nio.file.Paths')
|
||||
base.save(Paths.get(root, "upgrade"), core['dist-tags']['latest'])
|
||||
console.info('@ccms/core found new version ' + core['dist-tags']['latest'] + ' will upgrade after reboot!')
|
||||
}
|
||||
}
|
||||
upgradeModules(http.get('https://registry.npmmirror.com/@ccms/core'))
|
||||
console.debug('exit finish!')
|
||||
}
|
||||
exit()
|
@ -50,14 +50,7 @@ class MiaoScriptCore {
|
||||
this.pluginManager.disable(this.pluginManager.getPlugins())
|
||||
this.taskManager.disable()
|
||||
process.emit('core.after.disable')
|
||||
try {
|
||||
engineLoad({
|
||||
script: http.get("https://ms.yumc.pw/api/plugin/download/name/exit"),
|
||||
name: 'core/exit.js'
|
||||
})
|
||||
} catch (error: any) {
|
||||
console.debug(error)
|
||||
}
|
||||
loadCoreScript('exit')
|
||||
process.emit('core.before.exit')
|
||||
process.exit(0)
|
||||
console.i18n("ms.core.engine.disable.finish", {
|
||||
@ -98,18 +91,27 @@ function detectServer(): constants.ServerType {
|
||||
throw Error('Unknow Server Type...')
|
||||
}
|
||||
|
||||
function initialize() {
|
||||
process.emit('core.before.initialize')
|
||||
global.ScriptSlowExecuteTime = 30
|
||||
global.ScriptEngineVersion = require('../package.json').version
|
||||
function loadCoreScript(name) {
|
||||
try {
|
||||
let scriptname = name + (global.debug ? '-debug' : '')
|
||||
engineLoad({
|
||||
script: http.get("https://ms.yumc.pw/api/plugin/download/name/initialize"),
|
||||
name: 'core/initialize.js'
|
||||
script: http.get(`https://ms.yumc.pw/api/plugin/download/name/${scriptname}`),
|
||||
name: `core/${scriptname}.js`
|
||||
})
|
||||
} catch (error: any) {
|
||||
console.debug(error)
|
||||
if (global.debug) {
|
||||
console.debug(error)
|
||||
console.ex(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function initialize() {
|
||||
process.emit('core.before.initialize')
|
||||
global.ScriptSlowExecuteTime = 50
|
||||
global.ScriptEngineVersion = require('../package.json').version
|
||||
global.setGlobal('loadCoreScript', loadCoreScript)
|
||||
loadCoreScript('initialize')
|
||||
try {
|
||||
let corePackageStartTime = new Date().getTime()
|
||||
container.bind(ContainerInstance).toConstantValue(container)
|
||||
@ -141,8 +143,12 @@ function initialize() {
|
||||
process.emit('core.after.initialize')
|
||||
return disable
|
||||
} catch (error: any) {
|
||||
console.i18n("ms.core.initialize.error", { error })
|
||||
console.ex(error)
|
||||
if (console.console) {
|
||||
console.i18n("ms.core.initialize.error", { error })
|
||||
console.ex(error)
|
||||
} else {
|
||||
error.printStackTrace()
|
||||
}
|
||||
return () => console.i18n('ms.core.engine.disable.abnormal')
|
||||
}
|
||||
}
|
||||
|
@ -1,68 +0,0 @@
|
||||
global.initialize = function () {
|
||||
var mspmc = 'https://ms.yumc.pw/api/plugin/download/name/'
|
||||
var artifact = 'https://ci.yumc.pw/job/Minecraft/job/MiaoScript/lastSuccessfulBuild/artifact'
|
||||
|
||||
var fs = require('@ccms/common/dist/fs')
|
||||
var http = require('@ccms/common/dist/http').default
|
||||
|
||||
function updateJar() {
|
||||
var DocumentBuilderFactory = Java.type('javax.xml.parsers.DocumentBuilderFactory')
|
||||
var URLDecoder = Java.type('java.net.URLDecoder')
|
||||
var pom = DocumentBuilderFactory.newInstance().newDocumentBuilder()
|
||||
.parse(artifact + "/pom.xml")
|
||||
var latestVersion = pom.getElementsByTagName("version").item(0).getTextContent()
|
||||
if (base.version != latestVersion) {
|
||||
var pluginFolder = fs.file(fs.concat(root, '..'))
|
||||
var updateFolder = fs.concat(pluginFolder, 'update')
|
||||
fs.mkdirs(updateFolder)
|
||||
var filePath = base.getInstance().class.classLoader.getURLs()[0]
|
||||
var pluginFile = fs.file(URLDecoder.decode(filePath.getFile(), "UTF-8"))
|
||||
var updateFile = fs.file(updateFolder, pluginFile.getName())
|
||||
http.download(artifact + "/target/MiaoScript.jar", updateFile.getAbsolutePath())
|
||||
console.info('MiaoScript found new version ' + latestVersion + ' will upgrade after reboot!')
|
||||
}
|
||||
}
|
||||
function upgradeModules(core) {
|
||||
if (base.version && global.ScriptEngineVersion != core['dist-tags']['latest']) {
|
||||
var Paths = Java.type('java.nio.file.Paths')
|
||||
base.save(Paths.get(root, "upgrade"), core['dist-tags']['latest'])
|
||||
console.info('@ccms/core found new version ' + core['dist-tags']['latest'] + ' will upgrade after reboot!')
|
||||
}
|
||||
}
|
||||
var pluginFolder = fs.concat(root, 'plugins')
|
||||
var updateFolder = fs.concat(pluginFolder, 'update')
|
||||
var pluginFile = fs.concat(pluginFolder, 'MiaoScriptPackageManager.js')
|
||||
if (!fs.exists(pluginFile)) {
|
||||
fs.mkdirs(pluginFile)
|
||||
base.save(fs.concat(updateFolder, 'MiaoScriptPackageManager.auto.install'), '.')
|
||||
}
|
||||
fs.list(updateFolder).forEach(function (path) {
|
||||
var file = path.toFile()
|
||||
if (file.exists()) {
|
||||
var filename = file.getName()
|
||||
if (filename.endsWith(".auto.install")) {
|
||||
var pluginName = filename.replace('.auto.install', '')
|
||||
var pluginFile = fs.concat(pluginFolder, pluginName + '.js')
|
||||
if (!fs.exists(pluginFile)) {
|
||||
var pluginTemp = pluginFile + '.tmp'
|
||||
http.download(mspmc + pluginName, pluginTemp)
|
||||
fs.move(pluginTemp, pluginFile, true)
|
||||
}
|
||||
base.delete(file)
|
||||
}
|
||||
}
|
||||
})
|
||||
try {
|
||||
Java.type("org.bukkit.Bukkit")
|
||||
updateJar()
|
||||
} catch (error) {
|
||||
console.debug(error)
|
||||
if (global.debug) {
|
||||
console.ex(error)
|
||||
}
|
||||
}
|
||||
upgradeModules(http.get('https://registry.npmmirror.com/@ccms/core'))
|
||||
console.debug('initialize finish!')
|
||||
}
|
||||
global.initialize()
|
||||
delete global.initialize
|
Reference in New Issue
Block a user