aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/co/fantabos/bscv/BoSCoVicino.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/co/fantabos/bscv/BoSCoVicino.java')
-rw-r--r--src/main/java/co/fantabos/bscv/BoSCoVicino.java29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/main/java/co/fantabos/bscv/BoSCoVicino.java b/src/main/java/co/fantabos/bscv/BoSCoVicino.java
index 883d5b6..f139294 100644
--- a/src/main/java/co/fantabos/bscv/BoSCoVicino.java
+++ b/src/main/java/co/fantabos/bscv/BoSCoVicino.java
@@ -3,9 +3,10 @@ package co.fantabos.bscv;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.client.Minecraft;
+import net.minecraft.command.CommandSource;
+import net.minecraftforge.client.event.ClientChatEvent;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.common.MinecraftForge;
-import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.InterModComms;
@@ -21,6 +22,9 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import com.mojang.brigadier.CommandDispatcher;
+import com.mojang.brigadier.exceptions.CommandSyntaxException;
+
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@@ -37,6 +41,8 @@ public class BoSCoVicino {
public static List<Module> mods;
+ private final CommandDispatcher<CommandSource> dispatcher = new CommandDispatcher<>();
+
public BoSCoVicino() {
// Register the setup method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
@@ -56,7 +62,7 @@ public class BoSCoVicino {
// load and register mods
BoSCoVicino.mods = new ArrayList<Module>();
- BoSCoVicino.mods.add(new Fullbright(builder));
+ BoSCoVicino.mods.add(new Fullbright(builder, this.dispatcher));
ForgeConfigSpec spec = builder.build();
@@ -90,10 +96,23 @@ public class BoSCoVicino {
collect(Collectors.toList()));
}
+ // @SubscribeEvent
+ // public void onRegisterCommand(RegisterCommandsEvent event) {
+ // for (Module mod : BoSCoVicino.mods) {
+ // mod.registerCommands(event.getDispatcher());
+ // }
+ // }
+
@SubscribeEvent
- public void onRegisterCommand(RegisterCommandsEvent event) {
- for (Module mod : BoSCoVicino.mods) {
- mod.registerCommands(event.getDispatcher());
+ public void onClientChatEvent(ClientChatEvent event) {
+ if (event.getMessage().startsWith("/")) {
+ CommandSource source = BoSCoVicino.minecraft.player.createCommandSourceStack();
+ try {
+ this.dispatcher.execute(event.getMessage(), source);
+ event.setCanceled(true);
+ } catch (CommandSyntaxException e) {
+ LOGGER.error("Syntax error in command : %s", e.toString());
+ }
}
}