-
-
Notifications
You must be signed in to change notification settings - Fork 496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Method overloading support in script api #5242
base: nextgen
Are you sure you want to change the base?
Method overloading support in script api #5242
Conversation
for (final var overload : overloads) | ||
methodsToRemap.add(getReflectionMethodFromSingleMethod(overload)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brackets { ... }
but actually this is just logging in a catch block, for (var entry : entries) {
String key = entry.getKey();
Object value = entry.getValue();
String remapped;
try {
Member member = retriever.getMember(value);
remapped = remapDescriptor(member);
} catch (ReflectiveOperationException e) {
ClientUtilsKt.getLogger().error("Failed to remap field: {}", key, e);
continue;
}
if (remapped != null) {
map.remove(key);
map.put(remapped, value);
}
} Produced by enabling the following script (copied and combined from documentation), note that the key settings are still not yet correct. But the output in chat appears to be working as intended though. const script = registerScript({
name: "MyScript",
version: "1.0.0",
authors: ["My Name"]
});
script.registerModule({
name: "MyModule",
category: "Misc",
description: "An example module created with LiquidBounce's script API.",
settings: {
fastSwing: Setting.boolean({
name: "FastSwing",
default: true
}),
range: Setting.float({
name: "Range",
default: 3.0,
range: [0.5, 8.0],
suffix: "blocks"
}),
randomness: Setting.floatRange({
name: "Randomness",
default: [2.3, 7.8],
range: [0.0, 10.0],
suffix: "jitter"
}),
expand: Setting.int({
name: "Expand",
default: 4,
range: [0, 10],
suffix: "blocks"
}),
cps: Setting.intRange({
name: "CPS",
default: [4, 10],
range: [0, 20],
suffix: "cps"
}),
key: Setting.key({
name: "Key",
default: "key.keyboard.d"
}),
message: Setting.text({
name: "Message",
default: "This is a default message."
}),
messages: Setting.textArray({
name: "Messages",
default: ["This is a message", "This is another message"]
}),
animal: Setting.choose({
name: "Animal",
default: "Capybara",
choices: ["Axolotl", "Capybara", "Snek"]
})
}
}, (mod) => {
mod.on("enable", () => {
Client.displayChatMessage(`FastSwing: ${mod.settings.fastSwing.value}`);
Client.displayChatMessage(`Range: ${mod.settings.range.value}`);
Client.displayChatMessage(`Randomness: ${mod.settings.randomness.value}`);
Client.displayChatMessage(`Expand: ${mod.settings.expand.value}`);
Client.displayChatMessage(`CPS: ${mod.settings.cps.value}`);
Client.displayChatMessage(`Key: ${mod.settings.key.value}`);
Client.displayChatMessage(`Message: ${mod.settings.message.value}`);
Client.displayChatMessage(`Messages: ${mod.settings.messages.value}`);
Client.displayChatMessage(`Animal: ${mod.settings.animal.value}`);
mod.settings.fastSwing.value = false;
mod.settings.range.value = 2.3;
mod.settings.randomness.value = [2, 4.34];
mod.settings.expand.value = 2;
mod.settings.cps.value = [5, 12];
mod.settings.key.value = "key.keyboard.a";
mod.settings.message.value = "Axolotls are cool";
mod.settings.messages.value = ["New message 1", "New message 2"];
mod.settings.animal.value = "Axolotl";
});
});
script.registerCommand({
name: "addition",
aliases: ["add"],
parameters: [{
name: "a",
required: true,
validate: ParameterValidator.integer
},
{
name: "b",
required: true,
validate: ParameterValidator.integer
}
],
onExecute(arg1, arg2) {
Client.displayChatMessage(`Result of ${arg1} + ${arg2} is ${arg1 + arg2}`);
}
});
script.registerCommand({
name: "description",
parameters: [{
name: "module",
required: true,
validate: ParameterValidator.module,
}],
onExecute(mod) {
Client.displayChatMessage(`Description of module ${mod.name} is '${mod.description}'`);
}
}); |
This (intended behavior or not) is not introduced in this pr, and can be reproduced on previous build
|
This pr fixes this issue, now corresponding method overloads can be automatically selected by arguments as shown below (Without using
ReflectionUtil
).method-overload-support.mp4