Fix instantiate subclass if constructor parameter is the command's type

This commit is contained in:
Ben Woo
2025-04-06 11:50:00 +08:00
parent 5efec647c5
commit 8cc4aa0115
@@ -287,7 +287,7 @@ public abstract class BaseCommand {
declaredConstructor.setAccessible(true);
Parameter[] parameters = declaredConstructor.getParameters();
if (parameters.length == 1) {
if (parameters.length == 1 && parameters[0].getType().isAssignableFrom(this.getClass())) {
subScope = (BaseCommand) declaredConstructor.newInstance(this);
} else {
manager.log(LogLevel.INFO, "Found unusable constructor: " + declaredConstructor.getName() + "(" + Stream.of(parameters).map(p -> p.getType().getSimpleName() + " " + p.getName()).collect(Collectors.joining("<c2>,</c2> ")) + ")");