From a8aab6c29521b954e042ed6ff44da2c32c7d12f8 Mon Sep 17 00:00:00 2001 From: ILikePlayingGames <22475143+ILikePlayingGames@users.noreply.github.com> Date: Mon, 20 May 2024 22:15:19 -0400 Subject: [PATCH] Add Ability to Toggle Fancy UI with Command - Toggle Fancy UI with `/fwm on` and `/fwm off` - Use `/fwm` to open mod settings - Fix error spam due to InventoryChangeListener not being removed when GuiFancyWarp stops initialization due to an error - Fix version missing warning from Forge on startup - Bump version to v2.0-beta.1 --- build.gradle.kts | 2 +- gradle.properties | 2 +- .../fancywarpmenu/FancyWarpMenu.java | 4 +- ...Command.java => FancyWarpMenuCommand.java} | 52 ++++++++++++++++--- .../fancywarpmenu/gui/GuiFancyWarp.java | 2 + .../assets/fancywarpmenu/lang/en_US.lang | 1 + src/main/resources/version.properties | 25 +++++++++ version/update.json | 2 +- 8 files changed, 79 insertions(+), 11 deletions(-) rename src/main/java/ca/tirelesstraveler/fancywarpmenu/commands/{OpenConfigCommand.java => FancyWarpMenuCommand.java} (52%) create mode 100644 src/main/resources/version.properties diff --git a/build.gradle.kts b/build.gradle.kts index 9883603..3d6d9e8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -104,7 +104,7 @@ tasks.processResources { inputs.property("mcversion", mcVersion) inputs.property("modid", modid) - filesMatching("mcmod.info") { + filesMatching(arrayListOf("mcmod.info", "version.properties")) { expand(inputs.properties) } diff --git a/gradle.properties b/gradle.properties index 9742a71..60cde48 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,4 +3,4 @@ org.gradle.jvmargs=-Xmx2g baseGroup = ca.tirelesstraveler mcVersion = 1.8.9 modid = fancywarpmenu -version = 2.0 \ No newline at end of file +version = 2.0-beta.1 \ No newline at end of file diff --git a/src/main/java/ca/tirelesstraveler/fancywarpmenu/FancyWarpMenu.java b/src/main/java/ca/tirelesstraveler/fancywarpmenu/FancyWarpMenu.java index 65b25d4..4e47e9a 100644 --- a/src/main/java/ca/tirelesstraveler/fancywarpmenu/FancyWarpMenu.java +++ b/src/main/java/ca/tirelesstraveler/fancywarpmenu/FancyWarpMenu.java @@ -22,7 +22,7 @@ package ca.tirelesstraveler.fancywarpmenu; -import ca.tirelesstraveler.fancywarpmenu.commands.OpenConfigCommand; +import ca.tirelesstraveler.fancywarpmenu.commands.FancyWarpMenuCommand; import ca.tirelesstraveler.fancywarpmenu.data.layout.Island; import ca.tirelesstraveler.fancywarpmenu.data.layout.Layout; import ca.tirelesstraveler.fancywarpmenu.data.Settings; @@ -103,7 +103,7 @@ public void init(FMLInitializationEvent event) { updateCheckResult = ForgeVersion.getResult(modContainer); keyBindingOpenWarpMenu = new KeyBinding("fancywarpmenu.key.openMenu", Keyboard.KEY_C, "fancywarpmenu.key.categories.fancyWarpMenu"); ClientRegistry.registerKeyBinding(keyBindingOpenWarpMenu); - ClientCommandHandler.instance.registerCommand(new OpenConfigCommand()); + ClientCommandHandler.instance.registerCommand(new FancyWarpMenuCommand()); Layout overworldLayout = FancyWarpMenuState.getOverworldLayout(); ProgressManager.ProgressBar bar = ProgressManager.push("Loading Textures", diff --git a/src/main/java/ca/tirelesstraveler/fancywarpmenu/commands/OpenConfigCommand.java b/src/main/java/ca/tirelesstraveler/fancywarpmenu/commands/FancyWarpMenuCommand.java similarity index 52% rename from src/main/java/ca/tirelesstraveler/fancywarpmenu/commands/OpenConfigCommand.java rename to src/main/java/ca/tirelesstraveler/fancywarpmenu/commands/FancyWarpMenuCommand.java index cc70b5f..7b87ccf 100644 --- a/src/main/java/ca/tirelesstraveler/fancywarpmenu/commands/OpenConfigCommand.java +++ b/src/main/java/ca/tirelesstraveler/fancywarpmenu/commands/FancyWarpMenuCommand.java @@ -22,14 +22,33 @@ package ca.tirelesstraveler.fancywarpmenu.commands; +import ca.tirelesstraveler.fancywarpmenu.data.Settings; import ca.tirelesstraveler.fancywarpmenu.state.FancyWarpMenuState; -import net.minecraft.command.CommandBase; -import net.minecraft.command.ICommandSender; +import ca.tirelesstraveler.fancywarpmenu.utils.ChatUtils; +import net.minecraft.command.*; +import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.util.ChatStyle; +import net.minecraft.util.EnumChatFormatting; import java.util.Collections; import java.util.List; -public class OpenConfigCommand extends CommandBase { +/** + * This is the main command of the mod.
+ * Syntax
+ * + *
+ * Arguments + * + */ +public class FancyWarpMenuCommand extends CommandBase { @Override public int getRequiredPermissionLevel() { return 0; @@ -42,7 +61,7 @@ public List getCommandAliases() { @Override public String getCommandName() { - return "fancywarpmenuconfig"; + return "fancywarpmenu"; } @Override @@ -56,7 +75,28 @@ public String getCommandUsage(ICommandSender sender) { * The {@link net.minecraftforge.event.CommandEvent} is intercepted instead to prevent the screen from being closed. */ @Override - public void processCommand(ICommandSender sender, String[] args) { - FancyWarpMenuState.setOpenConfigMenuRequested(true); + public void processCommand(ICommandSender sender, String[] args) throws CommandException { + if (args.length > 0) { + switch (args[0]) { + case "1": + case "on": + Settings.setWarpMenuEnabled(true); + ChatUtils.sendMessageWithModNamePrefix( + new ChatComponentTranslation("fancywarpmenu.messages.fancyWarpMenuEnabled") + .setChatStyle(new ChatStyle().setColor(EnumChatFormatting.GREEN))); + break; + case "0": + case "off": + Settings.setWarpMenuEnabled(false); + ChatUtils.sendMessageWithModNamePrefix( + new ChatComponentTranslation("fancywarpmenu.messages.fancyWarpMenuDisabled") + .setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED))); + break; + default: + throw new SyntaxErrorException(); + } + } else { + FancyWarpMenuState.setOpenConfigMenuRequested(true); + } } } diff --git a/src/main/java/ca/tirelesstraveler/fancywarpmenu/gui/GuiFancyWarp.java b/src/main/java/ca/tirelesstraveler/fancywarpmenu/gui/GuiFancyWarp.java index b74c52d..bd3d5aa 100644 --- a/src/main/java/ca/tirelesstraveler/fancywarpmenu/gui/GuiFancyWarp.java +++ b/src/main/java/ca/tirelesstraveler/fancywarpmenu/gui/GuiFancyWarp.java @@ -126,6 +126,7 @@ public void initGui() { inventoryTooSmallMessageTranslationKey, chestInventory.getSizeInventory(), lastSlotIndexToCheck) .setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED))); setCustomUIState(false, false); + chestInventory.removeInventoryChangeListener(inventoryListener); return; } @@ -143,6 +144,7 @@ public void initGui() { } catch (RuntimeException e) { guiInitException = e; buttonList.clear(); + chestInventory.removeInventoryChangeListener(inventoryListener); int lineCount = 2; int labelX = 0; diff --git a/src/main/resources/assets/fancywarpmenu/lang/en_US.lang b/src/main/resources/assets/fancywarpmenu/lang/en_US.lang index b7674d9..d2a224a 100644 --- a/src/main/resources/assets/fancywarpmenu/lang/en_US.lang +++ b/src/main/resources/assets/fancywarpmenu/lang/en_US.lang @@ -52,6 +52,7 @@ fancywarpmenu.key.categories.fancyWarpMenu=Fancy Warp Menu fancywarpmenu.messages.useWarpMenuInsteadOfCommand=Reminder to use the Fancy Warp Menu instead! fancywarpmenu.messages.fancyWarpMenuEnabled=Fancy Warp Menu Enabled +fancywarpmenu.messages.fancyWarpMenuDisabled=Fancy Warp Menu Disabled fancywarpmenu.errors.notUnlocked=Not Unlocked fancywarpmenu.errors.unknownDestination=Unknown Destination diff --git a/src/main/resources/version.properties b/src/main/resources/version.properties new file mode 100644 index 0000000..4f005a7 --- /dev/null +++ b/src/main/resources/version.properties @@ -0,0 +1,25 @@ +# +# Copyright (c) 2024. TirelessTraveler +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE +# OR OTHER DEALINGS IN THE SOFTWARE. +# + +# Forge expects a mod version in the main mod class or in this file, otherwise it logs a warning on startup. +# suppress inspection "UnusedProperty" +fancywarpmenu.version = ${version} \ No newline at end of file diff --git a/version/update.json b/version/update.json index 75beb44..2df4fdb 100644 --- a/version/update.json +++ b/version/update.json @@ -2,7 +2,7 @@ "homepage": "https://github.com/ILikePlayingGames/FancyWarpMenu/releases", "promos": { "1.8.9-recommended": "1.0", - "1.8.9-latest": "1.0" + "1.8.9-latest": "2.0-beta.1" }, "1.8.9": { "1.0": "New textures and additional language support",