summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author alemi <me@alemi.dev>2023-03-04 01:30:47 +0100
committer alemi <me@alemi.dev>2023-03-04 01:30:47 +0100
commit414fbf4962cafd1286c2cc6c0814ae31ce87ef23 (patch)
tree29431f46813cd00005b90beb4a9df34e21895920 /src
parent6871d1dc3c3ccb3b3327456680153670385d5844 (diff)
feat: added AbstractCommand, load commands
Diffstat (limited to 'src')
-rw-r--r--src/main/java/ftbsc/bscv/commands/AbstractCommand.java35
-rw-r--r--src/main/java/ftbsc/bscv/system/ModManager.java11
2 files changed, 44 insertions, 2 deletions
diff --git a/src/main/java/ftbsc/bscv/commands/AbstractCommand.java b/src/main/java/ftbsc/bscv/commands/AbstractCommand.java
new file mode 100644
index 0000000..9568237
--- /dev/null
+++ b/src/main/java/ftbsc/bscv/commands/AbstractCommand.java
@@ -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));
+ }
+}
diff --git a/src/main/java/ftbsc/bscv/system/ModManager.java b/src/main/java/ftbsc/bscv/system/ModManager.java
index 974142e..9420d44 100644
--- a/src/main/java/ftbsc/bscv/system/ModManager.java
+++ b/src/main/java/ftbsc/bscv/system/ModManager.java
@@ -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,9 +25,9 @@ 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) {
@@ -39,11 +42,15 @@ public class ModManager {
public void load() {
for (ILoadable module : ServiceLoader.load(ILoadable.class)) {
if(module instanceof IModule) {
- IModule mod = (IModule) module;
+ IModule mod = (IModule) module;
this.mods.add(mod);
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);
+ }
}
}