fix: strict parent command class in ICommand interface

This commit is contained in:
AXOLOTsh
2026-08-18 03:34:46 +03:00
parent 6c59468628
commit 6e49b2a0e5
2 changed files with 8 additions and 6 deletions

View File

@@ -107,16 +107,17 @@ public abstract class BaseJavaPlugin extends JavaPlugin {
for (var command : commands) {
var clazzName = command.getClass().getName();
command.parentCommand().ifPresent(parentClazz -> {
var parent = commandsByClazz.get(parentClazz);
var parentCommand = command.parentCommand();
if (parentCommand != null) {
var parent = commandsByClazz.get(parentCommand);
if (parent == null) {
logger.error("Parent command '{}' for command '{}' cannot be found.",
parentClazz.getName(),
parentCommand.getName(),
clazzName);
} else
result.get(parent).add(command);
});
}
}
return result;

View File

@@ -1,9 +1,9 @@
package org.axolotsh.pluginutils.dependency_injection.entities;
import java.util.Collection;
import java.util.Optional;
import org.bukkit.permissions.Permission;
import org.jetbrains.annotations.Nullable;
import dev.jorel.commandapi.CommandAPICommand;
@@ -12,5 +12,6 @@ public interface ICommand {
public CommandAPICommand command();
public Optional<Class<ICommand>> parentCommand();
@Nullable
public Class<? extends ICommand> parentCommand();
}