fix: item fromJson error
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
bdf674b678
commit
496d278a93
@ -12,9 +12,11 @@
|
|||||||
"build": "lerna run build",
|
"build": "lerna run build",
|
||||||
"ug": "yarn upgrade-interactive --latest",
|
"ug": "yarn upgrade-interactive --latest",
|
||||||
"np": "./script/push.sh",
|
"np": "./script/push.sh",
|
||||||
"lsp": "npm login --registry=https://registry.npmjs.org --scope=@ccms",
|
"lsp": "npm login -scope=@ccms",
|
||||||
"lp": "lerna publish --registry https://registry.npmjs.org",
|
"lp": "lerna publish",
|
||||||
"lpb": "lerna publish --registry https://registry.npmjs.org --canary --preid beta --pre-dist-tag beta"
|
"lpb": "lerna publish --dist-tag beta",
|
||||||
|
"lpc": "lerna publish --canary --preid beta --pre-dist-tag beta",
|
||||||
|
"lpf": "lerna publish from-package --yes"
|
||||||
},
|
},
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"packages/*"
|
"packages/*"
|
||||||
|
@ -44,13 +44,13 @@ export namespace jsconsole {
|
|||||||
let file = Paths.get(Paths.get(fileName, '..', sourceMappingURL).toFile().getCanonicalPath()).toFile()
|
let file = Paths.get(Paths.get(fileName, '..', sourceMappingURL).toFile().getCanonicalPath()).toFile()
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
sourceContent = base.read(file)
|
sourceContent = base.read(file)
|
||||||
|
sourceFileMaps[fileName] = file.getCanonicalPath()
|
||||||
} else if (global.debug) {
|
} else if (global.debug) {
|
||||||
console.debug('readSourceMap can\'t found', fileName, 'source map file', sourceMappingURL)
|
console.debug('readSourceMap can\'t found', fileName, 'source map file', sourceMappingURL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sourceContent) {
|
if (sourceContent) {
|
||||||
sourceMaps[fileName] = new SourceMapBuilder(JSON.parse(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)
|
let { fileName, lineNumber } = readSourceMap(trace.fileName, trace.lineNumber)
|
||||||
if (fileName.startsWith(root)) { fileName = fileName.split(root)[1] }
|
if (fileName.startsWith(root)) { fileName = fileName.split(root)[1] }
|
||||||
if (color) {
|
if (color) {
|
||||||
cache.push(` §e->§c ${fileName}:${lineNumber} => §4${trace.methodName}`)
|
cache.push(` §e->§c ${fileName}:${lineNumber}(${trace.lineNumber}) => §4${trace.methodName}`)
|
||||||
} else {
|
} else {
|
||||||
cache.push(` -> ${fileName}:${lineNumber} => ${trace.methodName}`)
|
cache.push(` -> ${fileName}:${lineNumber}(${trace.lineNumber}) => ${trace.methodName}`)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let className = trace.className
|
let className = trace.className
|
||||||
|
@ -5,7 +5,7 @@ export namespace item {
|
|||||||
export abstract class Item {
|
export abstract class Item {
|
||||||
abstract builder(): ItemBuilder
|
abstract builder(): ItemBuilder
|
||||||
abstract toJson(item: any): string
|
abstract toJson(item: any): string
|
||||||
abstract fromJSON(json: string): any
|
abstract fromJson(json: string): any
|
||||||
}
|
}
|
||||||
export interface ItemBuilder {
|
export interface ItemBuilder {
|
||||||
from(item: any): ItemBuilder
|
from(item: any): ItemBuilder
|
||||||
|
@ -12,6 +12,7 @@ export class BukkitItem extends item.Item {
|
|||||||
private NBTTagCompound: any
|
private NBTTagCompound: any
|
||||||
private nmsSaveNBTMethodName: any
|
private nmsSaveNBTMethodName: any
|
||||||
private MojangsonParser: any
|
private MojangsonParser: any
|
||||||
|
private nmsItemStack: any
|
||||||
private mpParseMethodName: any
|
private mpParseMethodName: any
|
||||||
private nmsVersion: any
|
private nmsVersion: any
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -25,8 +26,8 @@ export class BukkitItem extends item.Item {
|
|||||||
let nbt = new this.NBTTagCompound()
|
let nbt = new this.NBTTagCompound()
|
||||||
return this.CraftItemStack.asNMSCopy(item)[this.nmsSaveNBTMethodName](nbt).toString()
|
return this.CraftItemStack.asNMSCopy(item)[this.nmsSaveNBTMethodName](nbt).toString()
|
||||||
}
|
}
|
||||||
fromJSON(json: string) {
|
fromJson(json: string) {
|
||||||
return this.CraftItemStack.asBukkitCopy(this.MojangsonParser[this.mpParseMethodName](json))
|
return this.CraftItemStack.asBukkitCopy(new this.nmsItemStack(this.MojangsonParser[this.mpParseMethodName](json)))
|
||||||
}
|
}
|
||||||
private obcCls(name: string) {
|
private obcCls(name: string) {
|
||||||
return base.getClass(['org.bukkit.craftbukkit', this.nmsVersion, name].join('.'))
|
return base.getClass(['org.bukkit.craftbukkit', this.nmsVersion, name].join('.'))
|
||||||
@ -44,6 +45,7 @@ export class BukkitItem extends item.Item {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
let asNMSCopyMethod = CraftItemStackClass.getMethod('asNMSCopy', ItemStack.class)
|
let asNMSCopyMethod = CraftItemStackClass.getMethod('asNMSCopy', ItemStack.class)
|
||||||
let nmsItemStackClass = asNMSCopyMethod.getReturnType()
|
let nmsItemStackClass = asNMSCopyMethod.getReturnType()
|
||||||
|
this.nmsItemStack = Java.type(nmsItemStackClass.getName())
|
||||||
let nmsNBTTagCompoundClass = undefined
|
let nmsNBTTagCompoundClass = undefined
|
||||||
for (let method of Java.from(nmsItemStackClass.getMethods())) {
|
for (let method of Java.from(nmsItemStackClass.getMethods())) {
|
||||||
let rt = method.getReturnType()
|
let rt = method.getReturnType()
|
||||||
@ -61,7 +63,7 @@ export class BukkitItem extends item.Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
this.MojangsonParser = this.nmsCls('MojangsonParser')
|
this.MojangsonParser = this.nmsCls('MojangsonParser').static
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.MojangsonParser = Java.type('net.minecraft.nbt.MojangsonParser')
|
this.MojangsonParser = Java.type('net.minecraft.nbt.MojangsonParser')
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user