mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-24 21:53:22 +00:00
refactored help command
This commit is contained in:
@@ -1,61 +0,0 @@
|
||||
package dev.sheldan.abstracto.core.command.config;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter @Builder
|
||||
public class CommandHierarchy {
|
||||
private List<PackedModule> rootModules;
|
||||
|
||||
public PackedModule getModuleWithName(String name){
|
||||
for (PackedModule module: rootModules) {
|
||||
PackedModule found = getModuleWithName(name, module);
|
||||
if(found != null){
|
||||
return found;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private PackedModule getModuleWithName(String name, PackedModule module){
|
||||
if(module.getModuleInterface().getInfo().getName().equals(name)){
|
||||
return module;
|
||||
} else {
|
||||
for (PackedModule subModule: module.getSubModules()) {
|
||||
PackedModule possibleModule = getModuleWithName(name, subModule);
|
||||
if(possibleModule != null){
|
||||
return possibleModule;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Command getCommandWithName(String name) {
|
||||
for (PackedModule module: rootModules) {
|
||||
Command command = getCommandFromModule(name, module);
|
||||
if(command != null){
|
||||
return command;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Command getCommandFromModule(String name, PackedModule module){
|
||||
Command foundCommand = module.getCommands().stream().filter(command -> command.getConfiguration().getName().equals(name)).findAny().orElse(null);
|
||||
if(foundCommand == null){
|
||||
for (PackedModule subModule: module.getSubModules()) {
|
||||
Command command = getCommandFromModule(name, subModule);
|
||||
if(command != null){
|
||||
return command;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} else {
|
||||
return foundCommand;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package dev.sheldan.abstracto.core.command.config;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class SingleLevelPackedModule {
|
||||
private ModuleInterface moduleInterface;
|
||||
private List<Command> commands;
|
||||
}
|
||||
@@ -14,5 +14,7 @@ public interface CommandRegistry {
|
||||
List<Command> getAllCommands();
|
||||
List<Command> getAllCommandsFromModule(ModuleInterface module);
|
||||
boolean isCommand(Message message);
|
||||
boolean commandExists(String name);
|
||||
Command getCommandByName(String name);
|
||||
String getCommandName(String input, Long serverId);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
package dev.sheldan.abstracto.core.command.service;
|
||||
|
||||
|
||||
import dev.sheldan.abstracto.core.command.config.CommandHierarchy;
|
||||
import dev.sheldan.abstracto.core.command.config.ModuleInterface;
|
||||
import dev.sheldan.abstracto.core.command.config.SingleLevelPackedModule;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ModuleRegistry {
|
||||
CommandHierarchy getDetailedModules();
|
||||
List<ModuleInterface> getModuleInterfaces();
|
||||
SingleLevelPackedModule getPackedModule(ModuleInterface moduleInterface);
|
||||
boolean moduleExists(String name);
|
||||
ModuleInterface getModuleByName(String name);
|
||||
List<ModuleInterface> getSubModules(ModuleInterface moduleInterface);
|
||||
ModuleInterface getDefaultModule();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package dev.sheldan.abstracto.core.models.template.commands.help;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.core.models.context.UserInitiatedServerContext;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@SuperBuilder
|
||||
public class HelpCommandDetailsModel extends UserInitiatedServerContext {
|
||||
private CommandConfiguration command;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package dev.sheldan.abstracto.core.models.template.commands.help;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.config.ModuleInterface;
|
||||
import dev.sheldan.abstracto.core.command.config.SingleLevelPackedModule;
|
||||
import dev.sheldan.abstracto.core.models.context.UserInitiatedServerContext;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@SuperBuilder
|
||||
public class HelpModuleDetailsModel extends UserInitiatedServerContext {
|
||||
private SingleLevelPackedModule module;
|
||||
private List<ModuleInterface> subModules;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package dev.sheldan.abstracto.core.models.template.commands.help;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.config.ModuleInterface;
|
||||
import dev.sheldan.abstracto.core.command.config.SingleLevelPackedModule;
|
||||
import dev.sheldan.abstracto.core.models.context.UserInitiatedServerContext;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@SuperBuilder
|
||||
public class HelpModuleOverviewModel extends UserInitiatedServerContext {
|
||||
private List<ModuleInterface> modules;
|
||||
}
|
||||
Reference in New Issue
Block a user