fix: item fromJson error

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2022-07-17 07:11:36 +08:00
parent bdf674b678
commit 496d278a93
4 changed files with 14 additions and 10 deletions

View File

@ -12,9 +12,11 @@
"build": "lerna run build",
"ug": "yarn upgrade-interactive --latest",
"np": "./script/push.sh",
"lsp": "npm login --registry=https://registry.npmjs.org --scope=@ccms",
"lp": "lerna publish --registry https://registry.npmjs.org",
"lpb": "lerna publish --registry https://registry.npmjs.org --canary --preid beta --pre-dist-tag beta"
"lsp": "npm login -scope=@ccms",
"lp": "lerna publish",
"lpb": "lerna publish --dist-tag beta",
"lpc": "lerna publish --canary --preid beta --pre-dist-tag beta",
"lpf": "lerna publish from-package --yes"
},
"workspaces": [
"packages/*"

View File

@ -44,13 +44,13 @@ export namespace jsconsole {
let file = Paths.get(Paths.get(fileName, '..', sourceMappingURL).toFile().getCanonicalPath()).toFile()
if (file.exists()) {
sourceContent = base.read(file)
sourceFileMaps[fileName] = file.getCanonicalPath()
} else if (global.debug) {
console.debug('readSourceMap can\'t found', fileName, 'source map file', sourceMappingURL)
}
}
if (sourceContent) {
sourceMaps[fileName] = new SourceMapBuilder(JSON.parse(sourceContent))
sourceFileMaps[fileName] = Paths.get(fileName, '..', sourceMaps[fileName].sources[0]).toFile().getCanonicalPath()
}
}
}
@ -88,9 +88,9 @@ export namespace jsconsole {
let { fileName, lineNumber } = readSourceMap(trace.fileName, trace.lineNumber)
if (fileName.startsWith(root)) { fileName = fileName.split(root)[1] }
if (color) {
cache.push(` §e->§c ${fileName}:${lineNumber} => §4${trace.methodName}`)
cache.push(` §e->§c ${fileName}:${lineNumber}(${trace.lineNumber}) => §4${trace.methodName}`)
} else {
cache.push(` -> ${fileName}:${lineNumber} => ${trace.methodName}`)
cache.push(` -> ${fileName}:${lineNumber}(${trace.lineNumber}) => ${trace.methodName}`)
}
} else {
let className = trace.className

View File

@ -5,7 +5,7 @@ export namespace item {
export abstract class Item {
abstract builder(): ItemBuilder
abstract toJson(item: any): string
abstract fromJSON(json: string): any
abstract fromJson(json: string): any
}
export interface ItemBuilder {
from(item: any): ItemBuilder

View File

@ -12,6 +12,7 @@ export class BukkitItem extends item.Item {
private NBTTagCompound: any
private nmsSaveNBTMethodName: any
private MojangsonParser: any
private nmsItemStack: any
private mpParseMethodName: any
private nmsVersion: any
constructor() {
@ -25,8 +26,8 @@ export class BukkitItem extends item.Item {
let nbt = new this.NBTTagCompound()
return this.CraftItemStack.asNMSCopy(item)[this.nmsSaveNBTMethodName](nbt).toString()
}
fromJSON(json: string) {
return this.CraftItemStack.asBukkitCopy(this.MojangsonParser[this.mpParseMethodName](json))
fromJson(json: string) {
return this.CraftItemStack.asBukkitCopy(new this.nmsItemStack(this.MojangsonParser[this.mpParseMethodName](json)))
}
private obcCls(name: string) {
return base.getClass(['org.bukkit.craftbukkit', this.nmsVersion, name].join('.'))
@ -44,6 +45,7 @@ export class BukkitItem extends item.Item {
// @ts-ignore
let asNMSCopyMethod = CraftItemStackClass.getMethod('asNMSCopy', ItemStack.class)
let nmsItemStackClass = asNMSCopyMethod.getReturnType()
this.nmsItemStack = Java.type(nmsItemStackClass.getName())
let nmsNBTTagCompoundClass = undefined
for (let method of Java.from(nmsItemStackClass.getMethods())) {
let rt = method.getReturnType()
@ -61,7 +63,7 @@ export class BukkitItem extends item.Item {
}
}
try {
this.MojangsonParser = this.nmsCls('MojangsonParser')
this.MojangsonParser = this.nmsCls('MojangsonParser').static
} catch (error) {
this.MojangsonParser = Java.type('net.minecraft.nbt.MojangsonParser')
}