diff options
| author | Lulonaut <lulonaut@lulonaut.dev> | 2024-07-24 17:27:31 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-24 17:27:31 +0200 |
| commit | 4c3867277ca007f290e87d2d17fb3d3a97d98854 (patch) | |
| tree | 7e8a371ffe0b6a80690c2c6d8de64a9dcff2df6d | |
| parent | 68284cc4f88bb3a665148c884038abacce23ae2a (diff) | |
| download | notenoughupdates-4c3867277ca007f290e87d2d17fb3d3a97d98854.tar.gz notenoughupdates-4c3867277ca007f290e87d2d17fb3d3a97d98854.tar.bz2 notenoughupdates-4c3867277ca007f290e87d2d17fb3d3a97d98854.zip | |
Fix crash when executing commands via the main-menu config (#1268)
| -rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java index eee396c9..930e76ee 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java @@ -215,20 +215,20 @@ public class NEUConfig extends Config { NotEnoughUpdates.INSTANCE.openGui = new GuiEnchantColour(); return; case 12: - ClientCommandHandler.instance.executeCommand(Minecraft.getMinecraft().thePlayer, "/dn"); + executeRunnableCommand("/dn"); return; case 13: - ClientCommandHandler.instance.executeCommand(Minecraft.getMinecraft().thePlayer, "/pv"); + executeRunnableCommand("/pv"); return; case 15: String command = NotEnoughUpdates.INSTANCE.config.misc.fariySoul ? "/neusouls on" : "/neusouls off"; - ClientCommandHandler.instance.executeCommand(Minecraft.getMinecraft().thePlayer, command); + executeRunnableCommand(command); return; case 16: - ClientCommandHandler.instance.executeCommand(Minecraft.getMinecraft().thePlayer, "/neusouls clear"); + executeRunnableCommand("/neusouls clear"); return; case 17: - ClientCommandHandler.instance.executeCommand(Minecraft.getMinecraft().thePlayer, "/neusouls unclear"); + executeRunnableCommand("/neusouls unclear"); return; case 20: FairySouls.getInstance().setTrackFairySouls(NotEnoughUpdates.INSTANCE.config.misc.trackFairySouls); @@ -259,6 +259,17 @@ public class NEUConfig extends Config { } } + /** + * Adds a check for the player being in a world before executing the given command + */ + private void executeRunnableCommand(String command) { + if (Minecraft.getMinecraft().thePlayer == null) { + System.err.println("Command (" + command + ") not executed since you are not in a world."); + return; + } + ClientCommandHandler.instance.executeCommand(Minecraft.getMinecraft().thePlayer, command); + } + @Expose @Category( name = "About", |
