From 534e09c5b2e267311b8b7f352a6c775aa0d12bd8 Mon Sep 17 00:00:00 2001 From: ILikePlayingGames <22475143+ILikePlayingGames@users.noreply.github.com> Date: Tue, 5 Sep 2023 23:12:32 -0400 Subject: [PATCH] Move SkyBlock constants to a separate file and update Gradle to 8.3 - Better error handling when a resource is not found - Remove build dependency on DownloadTranslationsTask :warning: This update breaks existing Fancy Warp Menu resource packs. Please disable any Fancy Warp Menu resource packs before updating --- .github/workflows/build.yml | 2 +- build.gradle.kts | 5 +- .../DownloadTranslationsTask.kt | 12 +- gradle.properties | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../fancywarpmenu/FancyWarpMenu.java | 30 ++++- .../fancywarpmenu/data/DataCommon.java | 30 +++++ .../data/{ => layout}/Button.java | 6 +- .../data/{ => layout}/ConfigButton.java | 2 +- .../data/{ => layout}/Island.java | 6 +- .../data/{ => layout}/Layout.java | 26 +--- .../{ => layout}/RegularWarpMenuButton.java | 2 +- .../fancywarpmenu/data/{ => layout}/Warp.java | 6 +- .../data/{ => layout}/WarpIcon.java | 6 +- .../skyblockconstants/SkyBlockConstants.java | 65 ++++++++++ .../WarpCommandVariant.java | 2 +- .../{ => skyblockconstants}/WarpMessages.java | 2 +- .../fancywarpmenu/gui/GuiButtonConfig.java | 4 +- .../fancywarpmenu/gui/GuiButtonIsland.java | 4 +- .../gui/GuiButtonRegularWarpMenu.java | 2 +- .../fancywarpmenu/gui/GuiButtonWarp.java | 4 +- .../fancywarpmenu/gui/GuiFancyWarp.java | 4 +- .../hooks/EntityPlayerSPHook.java | 2 +- .../listeners/WarpMenuListener.java | 12 +- .../{ => resourceloaders}/LayoutLoader.java | 75 +++--------- .../resourceloaders/ResourceLoader.java | 111 ++++++++++++++++++ .../SkyBlockConstantsLoader.java | 63 ++++++++++ .../assets/fancywarpmenu/data/layout.json | 39 +----- .../fancywarpmenu/data/skyBlockConstants.json | 39 ++++++ version/update.json | 5 +- 30 files changed, 397 insertions(+), 173 deletions(-) create mode 100644 src/main/java/ca/tirelesstraveler/fancywarpmenu/data/DataCommon.java rename src/main/java/ca/tirelesstraveler/fancywarpmenu/data/{ => layout}/Button.java (96%) rename src/main/java/ca/tirelesstraveler/fancywarpmenu/data/{ => layout}/ConfigButton.java (98%) rename src/main/java/ca/tirelesstraveler/fancywarpmenu/data/{ => layout}/Island.java (97%) rename src/main/java/ca/tirelesstraveler/fancywarpmenu/data/{ => layout}/Layout.java (75%) rename src/main/java/ca/tirelesstraveler/fancywarpmenu/data/{ => layout}/RegularWarpMenuButton.java (97%) rename src/main/java/ca/tirelesstraveler/fancywarpmenu/data/{ => layout}/Warp.java (97%) rename src/main/java/ca/tirelesstraveler/fancywarpmenu/data/{ => layout}/WarpIcon.java (96%) create mode 100644 src/main/java/ca/tirelesstraveler/fancywarpmenu/data/skyblockconstants/SkyBlockConstants.java rename src/main/java/ca/tirelesstraveler/fancywarpmenu/data/{ => skyblockconstants}/WarpCommandVariant.java (97%) rename src/main/java/ca/tirelesstraveler/fancywarpmenu/data/{ => skyblockconstants}/WarpMessages.java (97%) rename src/main/java/ca/tirelesstraveler/fancywarpmenu/{ => resourceloaders}/LayoutLoader.java (58%) create mode 100644 src/main/java/ca/tirelesstraveler/fancywarpmenu/resourceloaders/ResourceLoader.java create mode 100644 src/main/java/ca/tirelesstraveler/fancywarpmenu/resourceloaders/SkyBlockConstantsLoader.java create mode 100644 src/main/resources/assets/fancywarpmenu/data/skyBlockConstants.json diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a576ad9..4a32d55 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -55,7 +55,7 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build with Gradle - run: ./gradlew build --no-daemon -x downloadTranslations + run: ./gradlew build --no-daemon - name: Read Project Version id: read_project_version if: ${{ github.ref_name == 'main' || contains(github.event.inputs.upload_artifact, 'y') }} diff --git a/build.gradle.kts b/build.gradle.kts index 20b521b..2da4026 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -136,7 +136,6 @@ tasks.shadowJar { tasks.register("downloadTranslations") { group = "translations" - getTranslationsDirectory().set(buildDir.resolve("generated/resources/crowdin")) } tasks.register("uploadTranslations") { group = "translations" @@ -153,7 +152,7 @@ tasks.register("copyTranslationsToClassesDirectory") { * Copy built jar into a Minecraft launcher instance for debugging in a production environment */ tasks.register("copyJarToMinecraftLauncher") { - from(buildDir.resolve("libs")) + from(layout.buildDirectory.dir("libs")) into(file(System.getenv("MC_LAUNCHER_DIR"))) } @@ -161,5 +160,5 @@ tasks.assemble.get().dependsOn(tasks.remapJar) sourceSets.main { output.setResourcesDir(sourceSets.main.flatMap { it.java.classesDirectory }) - output.dir(tasks.getByName("downloadTranslations")) + output.dir(layout.buildDirectory.dir("generated/resources/crowdin")) } \ No newline at end of file diff --git a/buildSrc/src/main/java/ca/tirelesstraveler/DownloadTranslationsTask.kt b/buildSrc/src/main/java/ca/tirelesstraveler/DownloadTranslationsTask.kt index 919509f..b511447 100644 --- a/buildSrc/src/main/java/ca/tirelesstraveler/DownloadTranslationsTask.kt +++ b/buildSrc/src/main/java/ca/tirelesstraveler/DownloadTranslationsTask.kt @@ -23,10 +23,8 @@ package ca.tirelesstraveler import org.gradle.api.DefaultTask -import org.gradle.api.file.DirectoryProperty import org.gradle.api.file.ProjectLayout import org.gradle.api.tasks.Input -import org.gradle.api.tasks.OutputDirectory import org.gradle.api.tasks.TaskAction import org.gradle.process.ExecOperations import java.io.ByteArrayOutputStream @@ -55,8 +53,7 @@ import javax.inject.Inject */ /** - * This task uses the Crowdin CLI to download translations. - * It also tells the jar task to pull them from a folder specified by "getTranslationsDirectory" when building. + * This task uses the Crowdin CLI to download translations to the folder configured in crowdin.yml. * It is incremental and will re-run when the Crowdin project's translation progress changes. */ abstract class DownloadTranslationsTask: DefaultTask() { @@ -79,13 +76,6 @@ abstract class DownloadTranslationsTask: DefaultTask() { return outputStream.toString() } - /** - * This property tells the jar task where it should pull the translation files from. It doesn't set the folder - * Crowdin CLI downloads to. That is configured by crowdin.yml. - */ - @OutputDirectory - abstract fun getTranslationsDirectory(): DirectoryProperty - @TaskAction fun downloadTranslations() { getExecOperations().exec { diff --git a/gradle.properties b/gradle.properties index 9bf99fb..a0574f4 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 = 0.9.0 \ No newline at end of file +version = 1.0 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 84a0b92..db9a6b8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/ca/tirelesstraveler/fancywarpmenu/FancyWarpMenu.java b/src/main/java/ca/tirelesstraveler/fancywarpmenu/FancyWarpMenu.java index 351a002..949ff32 100644 --- a/src/main/java/ca/tirelesstraveler/fancywarpmenu/FancyWarpMenu.java +++ b/src/main/java/ca/tirelesstraveler/fancywarpmenu/FancyWarpMenu.java @@ -22,11 +22,14 @@ package ca.tirelesstraveler.fancywarpmenu; -import ca.tirelesstraveler.fancywarpmenu.data.Island; -import ca.tirelesstraveler.fancywarpmenu.data.Layout; +import ca.tirelesstraveler.fancywarpmenu.data.layout.Island; +import ca.tirelesstraveler.fancywarpmenu.data.layout.Layout; import ca.tirelesstraveler.fancywarpmenu.data.Settings; +import ca.tirelesstraveler.fancywarpmenu.resourceloaders.LayoutLoader; +import ca.tirelesstraveler.fancywarpmenu.data.skyblockconstants.SkyBlockConstants; import ca.tirelesstraveler.fancywarpmenu.listeners.SkyBlockJoinListener; import ca.tirelesstraveler.fancywarpmenu.listeners.WarpMenuListener; +import ca.tirelesstraveler.fancywarpmenu.resourceloaders.SkyBlockConstantsLoader; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.resources.IReloadableResourceManager; @@ -56,6 +59,7 @@ public class FancyWarpMenu { static Logger logger; private static ForgeVersion.CheckResult updateCheckResult; private static Layout layout; + private static SkyBlockConstants skyBlockConstants; private static SkyBlockJoinListener skyblockJoinListener; private static WarpMenuListener warpMenuListener; private static KeyBinding keyBindingOpenWarpMenu; @@ -66,7 +70,7 @@ public static FancyWarpMenu getInstance() { @Mod.EventHandler public void preInit(FMLPreInitializationEvent event) { - ProgressManager.ProgressBar bar = ProgressManager.push("Pre-init", 3); + ProgressManager.ProgressBar bar = ProgressManager.push("Pre-init", 4); EnvironmentDetails.deobfuscatedEnvironment = (Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment"); modId = event.getModMetadata().modId; modContainer = Loader.instance().activeModContainer(); @@ -82,7 +86,9 @@ public void preInit(FMLPreInitializationEvent event) { Settings.syncConfig(true); logger = event.getModLog(); event.getModMetadata().version = modContainer.getVersion(); - bar.step("Loading Warp Configuration"); + bar.step("Loading SkyBlock Constants"); + skyBlockConstants = SkyBlockConstantsLoader.loadSkyBlockConstants(); + bar.step("Loading Layout"); layout = LayoutLoader.loadLayout(); ProgressManager.pop(bar); } @@ -137,13 +143,23 @@ public boolean isPlayerOnSkyBlock() { public void reloadResources() { Minecraft.getMinecraft().refreshResources(); + reloadSkyBlockConstants(); reloadLayout(); } + public void reloadSkyBlockConstants() { + SkyBlockConstants loadedSkyBlockConstants = SkyBlockConstantsLoader.loadSkyBlockConstants(); + + // Will be null if json syntax is wrong or SkyBlock constants are invalid + if (loadedSkyBlockConstants != null) { + FancyWarpMenu.skyBlockConstants = loadedSkyBlockConstants; + } + } + public void reloadLayout() { Layout loadedLayout = LayoutLoader.loadLayout(); - // Will be null if json syntax is wrong or config is invalid + // Will be null if json syntax is wrong or layout is invalid if (loadedLayout != null) { FancyWarpMenu.layout = loadedLayout; } @@ -163,4 +179,8 @@ public static KeyBinding getKeyBindingOpenWarpMenu() { public static Layout getLayout() { return layout; } + + public static SkyBlockConstants getSkyBlockConstants() { + return skyBlockConstants; + } } diff --git a/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/DataCommon.java b/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/DataCommon.java new file mode 100644 index 0000000..5e8898d --- /dev/null +++ b/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/DataCommon.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023. 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. + */ + +package ca.tirelesstraveler.fancywarpmenu.data; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +public class DataCommon { + public static final Gson gson = new GsonBuilder().setPrettyPrinting().create(); +} diff --git a/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/Button.java b/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/layout/Button.java similarity index 96% rename from src/main/java/ca/tirelesstraveler/fancywarpmenu/data/Button.java rename to src/main/java/ca/tirelesstraveler/fancywarpmenu/data/layout/Button.java index 2bb932c..4671552 100644 --- a/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/Button.java +++ b/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/layout/Button.java @@ -20,12 +20,14 @@ * OR OTHER DEALINGS IN THE SOFTWARE. */ -package ca.tirelesstraveler.fancywarpmenu.data; +package ca.tirelesstraveler.fancywarpmenu.data.layout; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.util.ResourceLocation; +import static ca.tirelesstraveler.fancywarpmenu.data.DataCommon.gson; + /** * Class that holds the settings for drawing buttons that are not islands, like the config button. * This class should not be used directly. Subclasses should provide their own textures and additional fields. @@ -89,7 +91,7 @@ public void setTextureDimensions(int textureWidth, int textureHeight) { } public String toString() { - return Layout.gson.toJson(this); + return gson.toJson(this); } public static void validateButtonIcon(Button button) throws IllegalArgumentException, NullPointerException { diff --git a/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/ConfigButton.java b/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/layout/ConfigButton.java similarity index 98% rename from src/main/java/ca/tirelesstraveler/fancywarpmenu/data/ConfigButton.java rename to src/main/java/ca/tirelesstraveler/fancywarpmenu/data/layout/ConfigButton.java index 08dc714..27efd20 100644 --- a/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/ConfigButton.java +++ b/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/layout/ConfigButton.java @@ -20,7 +20,7 @@ * OR OTHER DEALINGS IN THE SOFTWARE. */ -package ca.tirelesstraveler.fancywarpmenu.data; +package ca.tirelesstraveler.fancywarpmenu.data.layout; import ca.tirelesstraveler.fancywarpmenu.FancyWarpMenu; import net.minecraft.client.Minecraft; diff --git a/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/Island.java b/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/layout/Island.java similarity index 97% rename from src/main/java/ca/tirelesstraveler/fancywarpmenu/data/Island.java rename to src/main/java/ca/tirelesstraveler/fancywarpmenu/data/layout/Island.java index 6c667a6..36ec085 100644 --- a/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/Island.java +++ b/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/layout/Island.java @@ -20,7 +20,7 @@ * OR OTHER DEALINGS IN THE SOFTWARE. */ -package ca.tirelesstraveler.fancywarpmenu.data; +package ca.tirelesstraveler.fancywarpmenu.data.layout; import ca.tirelesstraveler.fancywarpmenu.FancyWarpMenu; import net.minecraft.client.Minecraft; @@ -32,6 +32,8 @@ import java.io.IOException; import java.util.List; +import static ca.tirelesstraveler.fancywarpmenu.data.DataCommon.gson; + /** * Island data used to create the island buttons on the GUI */ @@ -153,7 +155,7 @@ public void setHoverEffectTextureLocation() { } public String toString() { - return Layout.gson.toJson(this); + return gson.toJson(this); } public static void validateIsland(Island island) throws IllegalArgumentException, NullPointerException { diff --git a/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/Layout.java b/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/layout/Layout.java similarity index 75% rename from src/main/java/ca/tirelesstraveler/fancywarpmenu/data/Layout.java rename to src/main/java/ca/tirelesstraveler/fancywarpmenu/data/layout/Layout.java index 0971fad..7264b8e 100644 --- a/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/Layout.java +++ b/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/layout/Layout.java @@ -20,22 +20,19 @@ * OR OTHER DEALINGS IN THE SOFTWARE. */ -package ca.tirelesstraveler.fancywarpmenu.data; - -import com.google.gson.Gson; +package ca.tirelesstraveler.fancywarpmenu.data.layout; import java.util.List; +import static ca.tirelesstraveler.fancywarpmenu.data.DataCommon.gson; + @SuppressWarnings("unused") public class Layout { - static Gson gson = new Gson(); private List islandList; private WarpIcon warpIcon; private ConfigButton configButton; private RegularWarpMenuButton regularWarpMenuButton; - private WarpMessages warpMessages; - private List warpCommandVariants; private Layout(){} @@ -55,14 +52,6 @@ public RegularWarpMenuButton getRegularWarpMenuButton() { return regularWarpMenuButton; } - public WarpMessages getWarpMessages() { - return warpMessages; - } - - public List getWarpCommandVariants() { - return warpCommandVariants; - } - public static void validateLayout(Layout layout) throws IllegalArgumentException, NullPointerException { if (layout == null) { throw new NullPointerException("Warp configuration cannot be null"); @@ -79,15 +68,6 @@ public static void validateLayout(Layout layout) throws IllegalArgumentException WarpIcon.validateWarpIcon(layout.getWarpIcon()); ConfigButton.validateConfigButtonIcon(layout.getConfigButton()); RegularWarpMenuButton.validateRegularMenuButtonIcon(layout.getRegularWarpMenuButton()); - WarpMessages.validateWarpMessages(layout.getWarpMessages()); - - if (layout.warpCommandVariants == null || layout.warpCommandVariants.isEmpty()) { - throw new NullPointerException("Warp command variant list cannot be empty"); - } - - for (WarpCommandVariant warpCommandVariant : layout.warpCommandVariants) { - WarpCommandVariant.validateWarpCommandVariant(warpCommandVariant); - } } @Override diff --git a/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/RegularWarpMenuButton.java b/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/layout/RegularWarpMenuButton.java similarity index 97% rename from src/main/java/ca/tirelesstraveler/fancywarpmenu/data/RegularWarpMenuButton.java rename to src/main/java/ca/tirelesstraveler/fancywarpmenu/data/layout/RegularWarpMenuButton.java index 5473639..2174426 100644 --- a/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/RegularWarpMenuButton.java +++ b/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/layout/RegularWarpMenuButton.java @@ -20,7 +20,7 @@ * OR OTHER DEALINGS IN THE SOFTWARE. */ -package ca.tirelesstraveler.fancywarpmenu.data; +package ca.tirelesstraveler.fancywarpmenu.data.layout; import ca.tirelesstraveler.fancywarpmenu.FancyWarpMenu; import net.minecraft.client.Minecraft; diff --git a/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/Warp.java b/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/layout/Warp.java similarity index 97% rename from src/main/java/ca/tirelesstraveler/fancywarpmenu/data/Warp.java rename to src/main/java/ca/tirelesstraveler/fancywarpmenu/data/layout/Warp.java index 8e7f860..aa9118a 100644 --- a/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/Warp.java +++ b/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/layout/Warp.java @@ -20,12 +20,14 @@ * OR OTHER DEALINGS IN THE SOFTWARE. */ -package ca.tirelesstraveler.fancywarpmenu.data; +package ca.tirelesstraveler.fancywarpmenu.data.layout; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.util.ResourceLocation; +import static ca.tirelesstraveler.fancywarpmenu.data.DataCommon.gson; + /** * Warp entry data used to create the warp buttons on the GUI */ @@ -104,7 +106,7 @@ public boolean shouldHideButton() { } public String toString() { - return Layout.gson.toJson(this); + return gson.toJson(this); } /** diff --git a/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/WarpIcon.java b/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/layout/WarpIcon.java similarity index 96% rename from src/main/java/ca/tirelesstraveler/fancywarpmenu/data/WarpIcon.java rename to src/main/java/ca/tirelesstraveler/fancywarpmenu/data/layout/WarpIcon.java index 9d37a70..a55bd3a 100644 --- a/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/WarpIcon.java +++ b/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/layout/WarpIcon.java @@ -20,7 +20,7 @@ * OR OTHER DEALINGS IN THE SOFTWARE. */ -package ca.tirelesstraveler.fancywarpmenu.data; +package ca.tirelesstraveler.fancywarpmenu.data.layout; import ca.tirelesstraveler.fancywarpmenu.FancyWarpMenu; import net.minecraft.client.Minecraft; @@ -30,6 +30,8 @@ import java.io.IOException; +import static ca.tirelesstraveler.fancywarpmenu.data.DataCommon.gson; + /** * Class that holds the settings for drawing the warp icon (portal) */ @@ -91,7 +93,7 @@ public void setTextureDimensions(int textureWidth, int textureHeight) { heightPercentage = textureHeight / textureWidth; } public String toString() { - return Layout.gson.toJson(this); + return gson.toJson(this); } public static void validateWarpIcon(WarpIcon warpIcon) throws IllegalArgumentException, NullPointerException { diff --git a/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/skyblockconstants/SkyBlockConstants.java b/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/skyblockconstants/SkyBlockConstants.java new file mode 100644 index 0000000..c8cfb2e --- /dev/null +++ b/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/skyblockconstants/SkyBlockConstants.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2023. 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. + */ + +package ca.tirelesstraveler.fancywarpmenu.data.skyblockconstants; + +import java.util.List; + +import static ca.tirelesstraveler.fancywarpmenu.data.DataCommon.gson; + +@SuppressWarnings("unused") +public class SkyBlockConstants { + private SkyBlockConstants() { + } + + private WarpMessages warpMessages; + private List warpCommandVariants; + + public WarpMessages getWarpMessages() { + return warpMessages; + } + + public List getWarpCommandVariants() { + return warpCommandVariants; + } + + @Override + public String toString() { + return gson.toJson(this); + } + + public static void validateSkyBlockConstants(SkyBlockConstants skyBlockConstants) { + if (skyBlockConstants == null) { + throw new NullPointerException("SkyBlock constants cannot be null"); + } + + WarpMessages.validateWarpMessages(skyBlockConstants.getWarpMessages()); + + if (skyBlockConstants.warpCommandVariants == null || skyBlockConstants.warpCommandVariants.isEmpty()) { + throw new NullPointerException("Warp command variant list cannot be empty"); + } + + for (WarpCommandVariant warpCommandVariant : skyBlockConstants.warpCommandVariants) { + WarpCommandVariant.validateWarpCommandVariant(warpCommandVariant); + } + } +} diff --git a/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/WarpCommandVariant.java b/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/skyblockconstants/WarpCommandVariant.java similarity index 97% rename from src/main/java/ca/tirelesstraveler/fancywarpmenu/data/WarpCommandVariant.java rename to src/main/java/ca/tirelesstraveler/fancywarpmenu/data/skyblockconstants/WarpCommandVariant.java index b9575ad..f391a4c 100644 --- a/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/WarpCommandVariant.java +++ b/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/skyblockconstants/WarpCommandVariant.java @@ -20,7 +20,7 @@ * OR OTHER DEALINGS IN THE SOFTWARE. */ -package ca.tirelesstraveler.fancywarpmenu.data; +package ca.tirelesstraveler.fancywarpmenu.data.skyblockconstants; @SuppressWarnings("unused") public class WarpCommandVariant { diff --git a/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/WarpMessages.java b/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/skyblockconstants/WarpMessages.java similarity index 97% rename from src/main/java/ca/tirelesstraveler/fancywarpmenu/data/WarpMessages.java rename to src/main/java/ca/tirelesstraveler/fancywarpmenu/data/skyblockconstants/WarpMessages.java index 739d7df..3df89f5 100644 --- a/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/WarpMessages.java +++ b/src/main/java/ca/tirelesstraveler/fancywarpmenu/data/skyblockconstants/WarpMessages.java @@ -20,7 +20,7 @@ * OR OTHER DEALINGS IN THE SOFTWARE. */ -package ca.tirelesstraveler.fancywarpmenu.data; +package ca.tirelesstraveler.fancywarpmenu.data.skyblockconstants; import java.util.List; import java.util.Map; diff --git a/src/main/java/ca/tirelesstraveler/fancywarpmenu/gui/GuiButtonConfig.java b/src/main/java/ca/tirelesstraveler/fancywarpmenu/gui/GuiButtonConfig.java index 5aff006..d6c8ec6 100644 --- a/src/main/java/ca/tirelesstraveler/fancywarpmenu/gui/GuiButtonConfig.java +++ b/src/main/java/ca/tirelesstraveler/fancywarpmenu/gui/GuiButtonConfig.java @@ -23,8 +23,8 @@ package ca.tirelesstraveler.fancywarpmenu.gui; import ca.tirelesstraveler.fancywarpmenu.FancyWarpMenu; -import ca.tirelesstraveler.fancywarpmenu.data.ConfigButton; -import ca.tirelesstraveler.fancywarpmenu.data.Island; +import ca.tirelesstraveler.fancywarpmenu.data.layout.ConfigButton; +import ca.tirelesstraveler.fancywarpmenu.data.layout.Island; import ca.tirelesstraveler.fancywarpmenu.data.Settings; import ca.tirelesstraveler.fancywarpmenu.gui.grid.GridRectangle; import ca.tirelesstraveler.fancywarpmenu.gui.grid.ScaledGrid; diff --git a/src/main/java/ca/tirelesstraveler/fancywarpmenu/gui/GuiButtonIsland.java b/src/main/java/ca/tirelesstraveler/fancywarpmenu/gui/GuiButtonIsland.java index ff49d5a..b78eac2 100644 --- a/src/main/java/ca/tirelesstraveler/fancywarpmenu/gui/GuiButtonIsland.java +++ b/src/main/java/ca/tirelesstraveler/fancywarpmenu/gui/GuiButtonIsland.java @@ -22,9 +22,9 @@ package ca.tirelesstraveler.fancywarpmenu.gui; -import ca.tirelesstraveler.fancywarpmenu.data.Island; +import ca.tirelesstraveler.fancywarpmenu.data.layout.Island; import ca.tirelesstraveler.fancywarpmenu.data.Settings; -import ca.tirelesstraveler.fancywarpmenu.data.Warp; +import ca.tirelesstraveler.fancywarpmenu.data.layout.Warp; import ca.tirelesstraveler.fancywarpmenu.gui.grid.ScaledGrid; import ca.tirelesstraveler.fancywarpmenu.gui.transitions.ScaleTransition; import net.minecraft.client.Minecraft; diff --git a/src/main/java/ca/tirelesstraveler/fancywarpmenu/gui/GuiButtonRegularWarpMenu.java b/src/main/java/ca/tirelesstraveler/fancywarpmenu/gui/GuiButtonRegularWarpMenu.java index 021914c..df604c7 100644 --- a/src/main/java/ca/tirelesstraveler/fancywarpmenu/gui/GuiButtonRegularWarpMenu.java +++ b/src/main/java/ca/tirelesstraveler/fancywarpmenu/gui/GuiButtonRegularWarpMenu.java @@ -23,7 +23,7 @@ package ca.tirelesstraveler.fancywarpmenu.gui; import ca.tirelesstraveler.fancywarpmenu.FancyWarpMenu; -import ca.tirelesstraveler.fancywarpmenu.data.RegularWarpMenuButton; +import ca.tirelesstraveler.fancywarpmenu.data.layout.RegularWarpMenuButton; import ca.tirelesstraveler.fancywarpmenu.gui.grid.GridRectangle; import ca.tirelesstraveler.fancywarpmenu.gui.grid.ScaledGrid; import ca.tirelesstraveler.fancywarpmenu.gui.transitions.ScaleTransition; diff --git a/src/main/java/ca/tirelesstraveler/fancywarpmenu/gui/GuiButtonWarp.java b/src/main/java/ca/tirelesstraveler/fancywarpmenu/gui/GuiButtonWarp.java index 2f495ad..d1bb9b6 100644 --- a/src/main/java/ca/tirelesstraveler/fancywarpmenu/gui/GuiButtonWarp.java +++ b/src/main/java/ca/tirelesstraveler/fancywarpmenu/gui/GuiButtonWarp.java @@ -22,9 +22,9 @@ package ca.tirelesstraveler.fancywarpmenu.gui; -import ca.tirelesstraveler.fancywarpmenu.data.Island; +import ca.tirelesstraveler.fancywarpmenu.data.layout.Island; import ca.tirelesstraveler.fancywarpmenu.data.Settings; -import ca.tirelesstraveler.fancywarpmenu.data.Warp; +import ca.tirelesstraveler.fancywarpmenu.data.layout.Warp; import ca.tirelesstraveler.fancywarpmenu.gui.grid.GridRectangle; import ca.tirelesstraveler.fancywarpmenu.gui.transitions.ScaleTransition; import net.minecraft.client.Minecraft; diff --git a/src/main/java/ca/tirelesstraveler/fancywarpmenu/gui/GuiFancyWarp.java b/src/main/java/ca/tirelesstraveler/fancywarpmenu/gui/GuiFancyWarp.java index 98b0a01..5a81b7b 100644 --- a/src/main/java/ca/tirelesstraveler/fancywarpmenu/gui/GuiFancyWarp.java +++ b/src/main/java/ca/tirelesstraveler/fancywarpmenu/gui/GuiFancyWarp.java @@ -25,9 +25,9 @@ import ca.tirelesstraveler.fancywarpmenu.EnvironmentDetails; import ca.tirelesstraveler.fancywarpmenu.FancyWarpMenu; import ca.tirelesstraveler.fancywarpmenu.GameState; -import ca.tirelesstraveler.fancywarpmenu.data.Island; +import ca.tirelesstraveler.fancywarpmenu.data.layout.Island; import ca.tirelesstraveler.fancywarpmenu.data.Settings; -import ca.tirelesstraveler.fancywarpmenu.data.Warp; +import ca.tirelesstraveler.fancywarpmenu.data.layout.Warp; import ca.tirelesstraveler.fancywarpmenu.gui.grid.ScaledGrid; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; diff --git a/src/main/java/ca/tirelesstraveler/fancywarpmenu/hooks/EntityPlayerSPHook.java b/src/main/java/ca/tirelesstraveler/fancywarpmenu/hooks/EntityPlayerSPHook.java index 5ee2a7b..9d92f75 100644 --- a/src/main/java/ca/tirelesstraveler/fancywarpmenu/hooks/EntityPlayerSPHook.java +++ b/src/main/java/ca/tirelesstraveler/fancywarpmenu/hooks/EntityPlayerSPHook.java @@ -3,7 +3,7 @@ import ca.tirelesstraveler.fancywarpmenu.FancyWarpMenu; import ca.tirelesstraveler.fancywarpmenu.LogHelper; import ca.tirelesstraveler.fancywarpmenu.data.Settings; -import ca.tirelesstraveler.fancywarpmenu.data.WarpCommandVariant; +import ca.tirelesstraveler.fancywarpmenu.data.skyblockconstants.WarpCommandVariant; import ca.tirelesstraveler.fancywarpmenu.listeners.WarpMenuListener; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; diff --git a/src/main/java/ca/tirelesstraveler/fancywarpmenu/listeners/WarpMenuListener.java b/src/main/java/ca/tirelesstraveler/fancywarpmenu/listeners/WarpMenuListener.java index 5eda65a..84a664a 100644 --- a/src/main/java/ca/tirelesstraveler/fancywarpmenu/listeners/WarpMenuListener.java +++ b/src/main/java/ca/tirelesstraveler/fancywarpmenu/listeners/WarpMenuListener.java @@ -26,8 +26,8 @@ import ca.tirelesstraveler.fancywarpmenu.GameState; import ca.tirelesstraveler.fancywarpmenu.OpenConfigCommand; import ca.tirelesstraveler.fancywarpmenu.data.Settings; -import ca.tirelesstraveler.fancywarpmenu.data.WarpCommandVariant; -import ca.tirelesstraveler.fancywarpmenu.data.WarpMessages; +import ca.tirelesstraveler.fancywarpmenu.data.skyblockconstants.WarpCommandVariant; +import ca.tirelesstraveler.fancywarpmenu.data.skyblockconstants.WarpMessages; import ca.tirelesstraveler.fancywarpmenu.gui.FancyWarpMenuConfigScreen; import ca.tirelesstraveler.fancywarpmenu.gui.GuiButtonConfig; import ca.tirelesstraveler.fancywarpmenu.gui.GuiFancyWarp; @@ -85,10 +85,10 @@ public void onChatMessageReceived(ClientChatReceivedEvent event) { if (event.type == 0 && warpScreen != null && mc.currentScreen == warpScreen) { String unformattedText = event.message.getUnformattedText(); - if (FancyWarpMenu.getLayout().getWarpMessages().getWarpSuccessMessages().contains(unformattedText)) { + if (FancyWarpMenu.getSkyBlockConstants().getWarpMessages().getWarpSuccessMessages().contains(unformattedText)) { mc.displayGuiScreen(null); - } else if (FancyWarpMenu.getLayout().getWarpMessages().getWarpFailMessages().containsKey(unformattedText)) { - WarpMessages warpMessages = FancyWarpMenu.getLayout().getWarpMessages(); + } else if (FancyWarpMenu.getSkyBlockConstants().getWarpMessages().getWarpFailMessages().containsKey(unformattedText)) { + WarpMessages warpMessages = FancyWarpMenu.getSkyBlockConstants().getWarpMessages(); Map warpFailMessages = warpMessages.getWarpFailMessages(); String failMessageKey = warpFailMessages.get(unformattedText); warpScreen.onWarpFail(failMessageKey); @@ -253,7 +253,7 @@ public static WarpCommandVariant getWarpCommandVariant(String command) { // Trim off the slash and all arguments String baseCommand = command.toLowerCase(Locale.US).substring(1).split(" ")[0]; - for (WarpCommandVariant commandVariant : FancyWarpMenu.getLayout().getWarpCommandVariants()) { + for (WarpCommandVariant commandVariant : FancyWarpMenu.getSkyBlockConstants().getWarpCommandVariants()) { if (commandVariant.getCommand().equals(baseCommand)) { return commandVariant; } diff --git a/src/main/java/ca/tirelesstraveler/fancywarpmenu/LayoutLoader.java b/src/main/java/ca/tirelesstraveler/fancywarpmenu/resourceloaders/LayoutLoader.java similarity index 58% rename from src/main/java/ca/tirelesstraveler/fancywarpmenu/LayoutLoader.java rename to src/main/java/ca/tirelesstraveler/fancywarpmenu/resourceloaders/LayoutLoader.java index 3bfce5f..0554028 100644 --- a/src/main/java/ca/tirelesstraveler/fancywarpmenu/LayoutLoader.java +++ b/src/main/java/ca/tirelesstraveler/fancywarpmenu/resourceloaders/LayoutLoader.java @@ -20,49 +20,41 @@ * OR OTHER DEALINGS IN THE SOFTWARE. */ -package ca.tirelesstraveler.fancywarpmenu; +package ca.tirelesstraveler.fancywarpmenu.resourceloaders; -import ca.tirelesstraveler.fancywarpmenu.data.*; -import com.google.gson.Gson; +import ca.tirelesstraveler.fancywarpmenu.FancyWarpMenu; +import ca.tirelesstraveler.fancywarpmenu.data.layout.*; import com.google.gson.stream.JsonReader; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.TextureUtil; import net.minecraft.client.resources.IResource; import net.minecraft.client.resources.IResourceManager; -import net.minecraft.client.resources.ResourcePackRepository; import net.minecraft.crash.CrashReport; -import net.minecraft.crash.CrashReportCategory; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ReportedException; import net.minecraft.util.ResourceLocation; import org.apache.commons.lang3.tuple.Pair; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import java.awt.image.BufferedImage; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -public class LayoutLoader { - private static final ResourceLocation WARP_CONFIG_LOCATION = new ResourceLocation("fancywarpmenu", +public class LayoutLoader extends ResourceLoader { + private static final ResourceLocation LAYOUT_LOCATION = new ResourceLocation("fancywarpmenu", "data/layout.json"); - private static final Gson gson = new Gson(); - private static final Logger logger = LogManager.getLogger(); public static Layout loadLayout() { try { - IResource layoutResource = Minecraft.getMinecraft().getResourceManager().getResource(WARP_CONFIG_LOCATION); + IResource layoutResource = Minecraft.getMinecraft().getResourceManager().getResource(LAYOUT_LOCATION); try (InputStream stream = layoutResource.getInputStream(); JsonReader reader = new JsonReader(new InputStreamReader(stream))) { Layout layout = gson.fromJson(reader, Layout.class); - WarpIcon warpIcon = layout.getWarpIcon(); - Warp.setWarpIcon(warpIcon); Layout.validateLayout(layout); // Warp icon + WarpIcon warpIcon = layout.getWarpIcon(); + Warp.setWarpIcon(warpIcon); warpIcon.init(); Pair warpIconDimensions = getTextureDimensions(warpIcon.getTextureLocation()); warpIcon.setTextureDimensions(warpIconDimensions.getLeft(), warpIconDimensions.getRight()); @@ -92,53 +84,16 @@ public static Layout loadLayout() { return layout; } catch (RuntimeException e) { - ResourcePackRepository.Entry resourcePackEntry = Minecraft.getMinecraft().getResourcePackRepository().getRepositoryEntries().stream().filter( - entry -> entry.getResourcePackName().equals(layoutResource.getResourcePackName())).findFirst().orElse(null); - String resourcePackName; - String resourcePackDescription; - - if (resourcePackEntry != null) { - resourcePackName = layoutResource.getResourcePackName(); - resourcePackDescription = resourcePackEntry.getTexturePackDescription(); - } else { - resourcePackName = FancyWarpMenu.getInstance().getModContainer().getName() + " " + FancyWarpMenu.getInstance().getModContainer().getVersion(); - resourcePackDescription = "Built-in resource pack"; - } - - if (FancyWarpMenu.getLayout() != null) { - StringBuilder stringBuilder = new StringBuilder("Your Fancy Warp Menu resource pack may be outdated."); - stringBuilder.append("\n").append(String.format("Layout loading failed: %s", e.getMessage())); - stringBuilder.append("\n").append("Resource Pack Details:"); - stringBuilder.append("\n").append("Name: ").append(resourcePackName); - stringBuilder.append("\n").append("Description: ").append(resourcePackDescription); - - if (resourcePackEntry != null) { - stringBuilder.append("\n").append("File: ").append(resourcePackEntry); - } - - logger.error(stringBuilder, e); + boolean fatal = FancyWarpMenu.getLayout() == null; - if (Minecraft.getMinecraft().ingameGUI != null) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + stringBuilder.toString())); - } - - return null; - } else { - CrashReport crashReport = new CrashReport("Your Fancy Warp Menu resource pack may be outdated", e); - CrashReportCategory resourcePackDetails = crashReport.makeCategory("Resource Pack"); - - resourcePackDetails.addCrashSection("Name", resourcePackName); - resourcePackDetails.addCrashSection("Description", resourcePackDescription); - - if (resourcePackEntry != null) { - resourcePackDetails.addCrashSection("File", resourcePackEntry.toString()); - } - - throw new ReportedException(crashReport); - } + handleResourceLoadException(layoutResource, fatal, e); + return null; } } catch (IOException e) { - throw new RuntimeException(e); + boolean fatal = FancyWarpMenu.getLayout() == null; + + handleGetResourceException(LAYOUT_LOCATION.toString(), fatal, e); + return null; } } diff --git a/src/main/java/ca/tirelesstraveler/fancywarpmenu/resourceloaders/ResourceLoader.java b/src/main/java/ca/tirelesstraveler/fancywarpmenu/resourceloaders/ResourceLoader.java new file mode 100644 index 0000000..6c37b77 --- /dev/null +++ b/src/main/java/ca/tirelesstraveler/fancywarpmenu/resourceloaders/ResourceLoader.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2023. 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. + */ + +package ca.tirelesstraveler.fancywarpmenu.resourceloaders; + +import ca.tirelesstraveler.fancywarpmenu.FancyWarpMenu; +import com.google.gson.Gson; +import net.minecraft.client.Minecraft; +import net.minecraft.client.resources.IResource; +import net.minecraft.client.resources.ResourcePackRepository; +import net.minecraft.crash.CrashReport; +import net.minecraft.crash.CrashReportCategory; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.ReportedException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.IOException; + +public abstract class ResourceLoader { + protected static final Gson gson = new Gson(); + protected static final Logger logger = LogManager.getLogger(); + + protected static void handleResourceLoadException(IResource resource, boolean fatal, RuntimeException e) { + ResourcePackRepository.Entry resourcePackEntry = Minecraft.getMinecraft().getResourcePackRepository().getRepositoryEntries().stream().filter( + entry -> entry.getResourcePackName().equals(resource.getResourcePackName())).findFirst().orElse(null); + String resourcePackName; + String resourcePackDescription; + + if (resourcePackEntry != null) { + resourcePackName = resource.getResourcePackName(); + resourcePackDescription = resourcePackEntry.getTexturePackDescription(); + } else { + resourcePackName = FancyWarpMenu.getInstance().getModContainer().getName() + " " + FancyWarpMenu.getInstance().getModContainer().getVersion(); + resourcePackDescription = "Built-in resource pack"; + } + + if (!fatal) { + StringBuilder stringBuilder = new StringBuilder("Your Fancy Warp Menu resource pack may be outdated."); + stringBuilder.append("\n").append(String.format("Resource loading failed: %s", e.getMessage())); + stringBuilder.append("\n").append(String.format("Resource Path: %s", resource.getResourceLocation().toString())); + stringBuilder.append("\n").append("Resource Pack Details:"); + stringBuilder.append("\n").append("Name: ").append(resourcePackName); + stringBuilder.append("\n").append("Description: ").append(resourcePackDescription); + + if (resourcePackEntry != null) { + stringBuilder.append("\n").append("File: ").append(resourcePackEntry); + } + + logger.error(stringBuilder, e); + + if (Minecraft.getMinecraft().ingameGUI != null) { + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + stringBuilder.toString())); + } + } else { + CrashReport crashReport = new CrashReport("Your Fancy Warp Menu resource pack may be outdated", e); + CrashReportCategory resourceDetails = crashReport.makeCategory("Resource"); + CrashReportCategory resourcePackDetails = crashReport.makeCategory("Resource Pack"); + + resourceDetails.addCrashSection("Path", resource.getResourceLocation().toString()); + + resourcePackDetails.addCrashSection("Name", resourcePackName); + resourcePackDetails.addCrashSection("Description", resourcePackDescription); + + if (resourcePackEntry != null) { + resourcePackDetails.addCrashSection("File", resourcePackEntry.toString()); + } + + throw new ReportedException(crashReport); + } + } + + protected static void handleGetResourceException(String resourcePath, boolean fatal, IOException e) { + if (!fatal) { + StringBuilder stringBuilder = new StringBuilder("Your Fancy Warp Menu resource pack may be outdated."); + stringBuilder.append("\n").append(String.format("Resource loading failed: %s", e.getMessage())); + stringBuilder.append("\n").append(String.format("Resource Path: %s", resourcePath)); + + logger.error(stringBuilder, e); + + if (Minecraft.getMinecraft().ingameGUI != null) { + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + stringBuilder.toString())); + } + } else { + CrashReport crashReport = new CrashReport("Your Fancy Warp Menu resource pack may be outdated", e); + CrashReportCategory resourceDetails = crashReport.makeCategory("Resource"); + resourceDetails.addCrashSection("Path", resourcePath); + throw new ReportedException(crashReport); + } + } +} diff --git a/src/main/java/ca/tirelesstraveler/fancywarpmenu/resourceloaders/SkyBlockConstantsLoader.java b/src/main/java/ca/tirelesstraveler/fancywarpmenu/resourceloaders/SkyBlockConstantsLoader.java new file mode 100644 index 0000000..e0dc0ee --- /dev/null +++ b/src/main/java/ca/tirelesstraveler/fancywarpmenu/resourceloaders/SkyBlockConstantsLoader.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2023. 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. + */ + +package ca.tirelesstraveler.fancywarpmenu.resourceloaders; + +import ca.tirelesstraveler.fancywarpmenu.FancyWarpMenu; +import ca.tirelesstraveler.fancywarpmenu.data.skyblockconstants.SkyBlockConstants; +import com.google.gson.stream.JsonReader; +import net.minecraft.client.Minecraft; +import net.minecraft.client.resources.IResource; +import net.minecraft.util.ResourceLocation; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +public class SkyBlockConstantsLoader extends ResourceLoader { + private static final ResourceLocation SKY_BLOCK_CONSTANTS_LOCATION = new ResourceLocation("fancywarpmenu", + "data/skyBlockConstants.json"); + + public static SkyBlockConstants loadSkyBlockConstants() { + try { + IResource skyBlockConstantsResource = Minecraft.getMinecraft().getResourceManager().getResource(SKY_BLOCK_CONSTANTS_LOCATION); + + try (InputStream stream = skyBlockConstantsResource.getInputStream(); + JsonReader reader = new JsonReader(new InputStreamReader(stream))) { + SkyBlockConstants skyBlockConstants = gson.fromJson(reader, SkyBlockConstants.class); + SkyBlockConstants.validateSkyBlockConstants(skyBlockConstants); + + return skyBlockConstants; + } catch (RuntimeException e) { + boolean fatal = FancyWarpMenu.getSkyBlockConstants() == null; + + handleResourceLoadException(skyBlockConstantsResource, fatal, e); + return null; + } + } catch (IOException e) { + boolean fatal = FancyWarpMenu.getSkyBlockConstants() == null; + + handleGetResourceException(SKY_BLOCK_CONSTANTS_LOCATION.toString(), fatal, e); + return null; + } + } +} diff --git a/src/main/resources/assets/fancywarpmenu/data/layout.json b/src/main/resources/assets/fancywarpmenu/data/layout.json index 9c92022..add1aa4 100644 --- a/src/main/resources/assets/fancywarpmenu/data/layout.json +++ b/src/main/resources/assets/fancywarpmenu/data/layout.json @@ -338,17 +338,6 @@ ] } ], - "warpMessages": { - "warpSuccessMessages": [ - "Warping..." - ], - "warpFailMessages": { - "Unknown destination! Check the Fast Travel menu to view options!": "fancywarpmenu.errors.unknownDestination", - "You haven't unlocked this fast travel destination!": "fancywarpmenu.errors.notUnlocked", - "Couldn't warp you! Try again later. (NO_DESTINATION_FOUND)": "fancywarpmenu.errors.noDestination", - "You need to have visited this island at least once before fast traveling to it!": "fancywarpmenu.errors.notVisited" - } - }, "warpIcon": { "texturePath": "textures/gui/Portal.png", "widthPercentage": 0.02, @@ -363,31 +352,5 @@ "gridX": 60, "gridY": 29, "widthPercentage": 0.05 - }, - "warpCommandVariants": [ - { - "command": "warp", - "type": "ALIAS" - }, - { - "command": "travel", - "type": "ALIAS" - }, - { - "command": "is", - "type": "WARP" - }, - { - "command": "hub", - "type": "WARP" - }, - { - "command": "warpforge", - "type": "WARP" - }, - { - "command": "savethejerrys", - "type": "WARP" - } - ] + } } \ No newline at end of file diff --git a/src/main/resources/assets/fancywarpmenu/data/skyBlockConstants.json b/src/main/resources/assets/fancywarpmenu/data/skyBlockConstants.json new file mode 100644 index 0000000..c6d6fe1 --- /dev/null +++ b/src/main/resources/assets/fancywarpmenu/data/skyBlockConstants.json @@ -0,0 +1,39 @@ +{ + "warpMessages": { + "warpSuccessMessages": [ + "Warping..." + ], + "warpFailMessages": { + "Unknown destination! Check the Fast Travel menu to view options!": "fancywarpmenu.errors.unknownDestination", + "You haven't unlocked this fast travel destination!": "fancywarpmenu.errors.notUnlocked", + "Couldn't warp you! Try again later. (NO_DESTINATION_FOUND)": "fancywarpmenu.errors.noDestination", + "You need to have visited this island at least once before fast traveling to it!": "fancywarpmenu.errors.notVisited" + } + }, + "warpCommandVariants": [ + { + "command": "warp", + "type": "ALIAS" + }, + { + "command": "travel", + "type": "ALIAS" + }, + { + "command": "is", + "type": "WARP" + }, + { + "command": "hub", + "type": "WARP" + }, + { + "command": "warpforge", + "type": "WARP" + }, + { + "command": "savethejerrys", + "type": "WARP" + } + ] +} \ No newline at end of file diff --git a/version/update.json b/version/update.json index 131f389..75beb44 100644 --- a/version/update.json +++ b/version/update.json @@ -1,10 +1,11 @@ { "homepage": "https://github.com/ILikePlayingGames/FancyWarpMenu/releases", "promos": { - "1.8.9-recommended": "0.8.0", - "1.8.9-latest": "0.9.0+77" + "1.8.9-recommended": "1.0", + "1.8.9-latest": "1.0" }, "1.8.9": { + "1.0": "New textures and additional language support", "0.9.0+77": "Link update available button to GitHub releases" } } \ No newline at end of file