feat: added AbstractCommand, load commands
This commit is contained in:
parent
6871d1dc3c
commit
414fbf4962
2 changed files with 44 additions and 2 deletions
35
src/main/java/ftbsc/bscv/commands/AbstractCommand.java
Normal file
35
src/main/java/ftbsc/bscv/commands/AbstractCommand.java
Normal file
|
@ -0,0 +1,35 @@
|
|||
package ftbsc.bscv.commands;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
|
||||
import ftbsc.bscv.Boscovicino;
|
||||
import ftbsc.bscv.ICommons;
|
||||
import ftbsc.bscv.api.ICommand;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.command.Commands;
|
||||
|
||||
public abstract class AbstractCommand implements ICommand, ICommons {
|
||||
|
||||
public String getName() {
|
||||
return this.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
public CommandDispatcher<CommandSource> getDispatcher() {
|
||||
return Boscovicino.modManager.getDispatcher();
|
||||
}
|
||||
|
||||
public List<LiteralArgumentBuilder<CommandSource>> subcommands() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
abstract LiteralArgumentBuilder<CommandSource> register(LiteralArgumentBuilder<CommandSource> builder);
|
||||
|
||||
public AbstractCommand() {
|
||||
LiteralArgumentBuilder<CommandSource> builder = Commands.literal(this.getName().toLowerCase());
|
||||
this.getDispatcher().register(this.register(builder));
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package ftbsc.bscv.system;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
|
||||
import ftbsc.bscv.api.ICommand;
|
||||
import ftbsc.bscv.api.ILoadable;
|
||||
import ftbsc.bscv.api.IModule;
|
||||
import net.minecraft.command.CommandSource;
|
||||
|
@ -15,6 +17,7 @@ public class ModManager {
|
|||
private Builder cfgBuilder;
|
||||
private CommandDispatcher<CommandSource> dispatcher;
|
||||
|
||||
public final Set<ICommand> commands;
|
||||
public final Set<IModule> mods;
|
||||
public final Set<String> categories;
|
||||
|
||||
|
@ -22,10 +25,10 @@ public class ModManager {
|
|||
this.cfgBuilder = cfgBuilder;
|
||||
this.dispatcher = dispatcher;
|
||||
this.mods = new HashSet<>();
|
||||
this.commands = new HashSet<>();
|
||||
this.categories = new HashSet<>();
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public IModule get(Class<? extends IModule> clazz) {
|
||||
for (IModule m : this.mods) {
|
||||
|
@ -44,6 +47,10 @@ public class ModManager {
|
|||
this.categories.add(mod.getGroup());
|
||||
this.cfgBuilder.pop(); // TODO
|
||||
}
|
||||
if(module instanceof ICommand) { // TODO do these belong here?
|
||||
ICommand cmd = (ICommand) module;
|
||||
this.commands.add(cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue