refactored help command

This commit is contained in:
Sheldan
2020-04-28 15:39:47 +02:00
parent 8e7bc7d98f
commit 93f587bf26
14 changed files with 224 additions and 215 deletions

View File

@@ -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;
}
}
}

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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();
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}