diff options
author | syeyoung <cyoung06@naver.com> | 2022-11-17 22:52:19 +0900 |
---|---|---|
committer | syeyoung <cyoung06@naver.com> | 2022-11-17 22:52:19 +0900 |
commit | 600cdd77c0c1bbb79fff9c5ed06d45de2bd0528b (patch) | |
tree | 411eedef7de77bc9ce8c283fa971a0c4c9e8c7ba /mod/src/main/java/kr/syeyoung | |
parent | ba20df9f7bd9d465ef075752c42369f81bc4e719 (diff) | |
download | Skyblock-Dungeons-Guide-600cdd77c0c1bbb79fff9c5ed06d45de2bd0528b.tar.gz Skyblock-Dungeons-Guide-600cdd77c0c1bbb79fff9c5ed06d45de2bd0528b.tar.bz2 Skyblock-Dungeons-Guide-600cdd77c0c1bbb79fff9c5ed06d45de2bd0528b.zip |
- Unload commands
Signed-off-by: syeyoung <cyoung06@naver.com>
Diffstat (limited to 'mod/src/main/java/kr/syeyoung')
-rwxr-xr-x | mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java index 91541a86..f45164e9 100755 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java @@ -47,6 +47,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.*; import net.minecraft.client.resources.IResourceManager; import net.minecraft.client.resources.IResourcePack; +import net.minecraft.command.ICommand; import net.minecraft.launchwrapper.LaunchClassLoader; import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.client.event.GuiOpenEvent; @@ -130,6 +131,12 @@ public class DungeonsGuide implements DGInterface { registeredListeners.add(object); MinecraftForge.EVENT_BUS.register(object); } + private List<ICommand> registeredCommands = new ArrayList<>(); + + public void registerCommands(ICommand command) { + registeredCommands.add(command); + ClientCommandHandler.instance.registerCommand(command); + } public void init(File f) { @@ -194,8 +201,8 @@ public class DungeonsGuide implements DGInterface { CommandDungeonsGuide commandDungeonsGuide = new CommandDungeonsGuide(); CommandDgDebug command = new CommandDgDebug(); - ClientCommandHandler.instance.registerCommand(commandDungeonsGuide); - ClientCommandHandler.instance.registerCommand(command); + registerCommands(commandDungeonsGuide); + registerCommands(command); registerEventsForge(command); registerEventsForge(commandDungeonsGuide); @@ -248,6 +255,15 @@ public class DungeonsGuide implements DGInterface { for (Object registeredListener : registeredListeners) { MinecraftForge.EVENT_BUS.unregister(registeredListener); } + Set<ICommand> commands = ReflectionHelper.getPrivateValue(ClientCommandHandler.class, ClientCommandHandler.instance, "commandSet"); + + for (ICommand registeredCommand : registeredCommands) { + ClientCommandHandler.instance.getCommands().remove(registeredCommand.getCommandName()); + for (String commandAlias : registeredCommand.getCommandAliases()) { + ClientCommandHandler.instance.getCommands().remove(commandAlias); + } + commands.remove(registeredCommand); + } THREAD_GROUP.interrupt(); THREAD_GROUP.stop(); try { |