release: v0.23.0

1. add item api
2. support rollup source map
3. fix database drvice error
4. support loliserver
5. support 1.19 bukkit chat
6. config add migrate options
7.

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2022-06-20 00:48:00 +08:00
parent b5fac23c5c
commit 15d1f8392b
26 changed files with 2752 additions and 188 deletions

View File

@ -129,12 +129,14 @@ function declaredField(clazz: java.lang.Class<any>, name: string | java.lang.Str
let field = null
// noinspection JSUnresolvedVariable
while (target !== JavaObject.class) {
console.debug(`reflect field ${name} from ${target.getName()}`)
try {
field = target.getDeclaredField(name)
if (field !== null) { break }
} catch (error: any) {
if (target === undefined) { break }
target = target.getSuperclass()
console.debug(`切换到超类: ${target.getName()}`)
}
}
if (field === null) {
@ -146,21 +148,32 @@ function declaredField(clazz: java.lang.Class<any>, name: string | java.lang.Str
function declaredMethod(clazz: java.lang.Class<any>, nameOrIndex: string | number, ...clazzs: java.lang.Class<any>[]): java.lang.reflect.Method {
let key = clazz.getName() + '.' + nameOrIndex + ':' + (clazzs || []).map(c => c.getName()).join(':')
if (methodCache.has(key)) { return methodCache.get(key) }
let target = clazz
if (typeof nameOrIndex === "number") {
methodCache.set(key, declaredMethods(clazz)[nameOrIndex])
} else {
try {
methodCache.set(key, clazz.getMethod(nameOrIndex, clazzs as any))
} catch (ex: any) {
while (target !== JavaObject.class && !methodCache.has(key)) {
try {
methodCache.set(key, clazz.getDeclaredMethod(nameOrIndex, clazzs as any))
} catch (ex: any) {
for (const m of Java.from(declaredMethods(clazz))) {
if (m.getName() == nameOrIndex) {
methodCache.set(key, m)
break
console.debug(`reflect method ${typeof nameOrIndex == "number" ? 'index' : 'name'} ${nameOrIndex} from ${target.getName()}`)
try {
methodCache.set(key, target.getMethod(nameOrIndex, clazzs as any))
} catch (ex: any) {
try {
methodCache.set(key, target.getDeclaredMethod(nameOrIndex, clazzs as any))
} catch (ex: any) {
for (const m of Java.from(declaredMethods(target))) {
if (m.getName() == nameOrIndex) {
methodCache.set(key, m)
break
}
}
throw new Error(`method ${typeof nameOrIndex == "number" ? 'index' : 'name'} ${nameOrIndex} not found.`)
}
}
} catch (error) {
if (target === undefined) { break }
target = target.getSuperclass()
console.debug(`切换到超类: ${target.getName()}`)
}
}
}

View File

@ -17,14 +17,14 @@ class ChatMessagePart {
}
convert() {
return this.internal;
return this.internal
}
}
class Tellraw {
static duplicateChar = '§卐'
static create() {
return new Tellraw().then(Tellraw.duplicateChar);
return new Tellraw().then(Tellraw.duplicateChar)
}
private cache: string = '';
@ -32,77 +32,81 @@ class Tellraw {
then(part: ChatMessagePart | string) {
if (typeof part === "string") {
var newPart = new ChatMessagePart();
var newPart = new ChatMessagePart()
newPart.text = part
this.then(newPart);
return this;
this.then(newPart)
return this
}
var last = this.latest();
var last = this.latest()
if (!last.text) {
last.text = part.text;
last.text = part.text
} else {
this.parts.push(part);
this.parts.push(part)
}
this.cache = null;
this.cache = null
}
text(text: string) {
this.latest().text = text;
return this;
this.latest().text = text
return this
}
tip(text: string) {
this.latest().hover("show_text", text);
return this;
tip(texts: string) {
return this.hover(texts)
}
item(text: string) {
this.latest().hover("show_item", text);
return this;
hover(texts: string) {
this.latest().hover("show_text", texts)
return this
}
item(item: string) {
this.latest().hover("show_item", item)
return this
}
command(command: string) {
this.latest().click("run_command", command);
return this;
this.latest().click("run_command", command)
return this
}
suggest(url: string) {
this.latest().click("suggest_command", url);
return this;
this.latest().click("suggest_command", url)
return this
}
file(path: string) {
this.latest().click("open_file", path);
return this;
this.latest().click("open_file", path)
return this
}
link(url: string) {
this.latest().click("open_url", url);
return this;
this.latest().click("open_url", url)
return this
}
latest() {
return this.parts[this.parts.length - 1];
return this.parts[this.parts.length - 1]
}
json() {
if (!this.cache) {
var temp = [];
var temp = []
this.parts.forEach(t => {
temp.push(t.convert());
});
this.cache = JSON.stringify(temp);
console.trace(this.cache);
temp.push(t.convert())
})
this.cache = JSON.stringify(temp)
console.trace(this.cache)
}
return this.cache;
return this.cache
}
string() {
var temp = '';
var temp = ''
this.parts.forEach(t => {
temp += t.text
});
return temp;
})
return temp
}
}