mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-29 11:59:17 +00:00
refactor: refactor
This commit is contained in:
@@ -27,11 +27,15 @@ public abstract class ArgumentNode<T> extends CommandNode {
|
||||
return Suggestions.empty();
|
||||
}
|
||||
|
||||
protected boolean overrideSuggestions() {
|
||||
return isMethodOverridden("getSuggestions", ArgumentNode.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ArgumentBuilder<CommandSourceStack, ?> compileBase() {
|
||||
RequiredArgumentBuilder<CommandSourceStack, T> argumentBuilder = Commands.argument(name, argumentType);
|
||||
|
||||
if (isMethodOverridden("getSuggestions", ArgumentNode.class)) {
|
||||
if (overrideSuggestions()) {
|
||||
argumentBuilder.suggests(
|
||||
(context, builder) -> getSuggestions(new CommandContext(context), builder)
|
||||
);
|
||||
|
||||
@@ -50,7 +50,7 @@ public abstract class CommandNode {
|
||||
builder = builder.then(child.compile());
|
||||
}
|
||||
|
||||
if (isMethodOverridden("execute", CommandNode.class)) {
|
||||
if (canExecute()) {
|
||||
builder = builder.executes(mojangCtx -> {
|
||||
CommandContext ctx = new CommandContext(mojangCtx);
|
||||
return execute(ctx) ? 1 : 0;
|
||||
@@ -60,6 +60,10 @@ public abstract class CommandNode {
|
||||
return builder;
|
||||
}
|
||||
|
||||
protected boolean canExecute() {
|
||||
return isMethodOverridden("execute", CommandNode.class);
|
||||
}
|
||||
|
||||
protected boolean isMethodOverridden(String methodName, @NotNull Class<?> baseClass) {
|
||||
for (Method method : getClass().getDeclaredMethods()) {
|
||||
if (method.getName().equals(methodName)) {
|
||||
|
||||
@@ -32,7 +32,7 @@ public class CustomArgumentNode<T, B> extends ArgumentNode<B> {
|
||||
protected ArgumentBuilder<CommandSourceStack, ?> compileBase() {
|
||||
RequiredArgumentBuilder<CommandSourceStack, T> argumentBuilder = (RequiredArgumentBuilder<CommandSourceStack, T>) super.compileBase();
|
||||
|
||||
if (!isMethodOverridden("getSuggestions", ArgumentNode.class)) {
|
||||
if (overrideSuggestions()) {
|
||||
CustomArgumentType<T, B> customArgumentType = (CustomArgumentType<T, B>) TYPES.get(getClass());
|
||||
argumentBuilder.suggests(
|
||||
(context, builder) -> customArgumentType.getSuggestions(new CommandContext(context), builder)
|
||||
|
||||
Reference in New Issue
Block a user