From 0418663a058a5337b01af9d729c2a6548994836b Mon Sep 17 00:00:00 2001 From: nea Date: Tue, 12 Jul 2022 00:50:56 +0200 Subject: Update notification changes --- CONTRIBUTING.md | 109 ++++++++++++++++++ .../notenoughupdates/NotEnoughUpdates.java | 35 +++--- .../commands/help/LinksCommand.java | 2 +- .../listener/NEUEventListener.java | 125 ++++++++++----------- .../options/seperateSections/Misc.java | 6 +- .../options/seperateSections/Notifications.java | 5 +- 6 files changed, 195 insertions(+), 87 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 922bdf60..c1913734 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -32,3 +32,112 @@ Use [DevAuth](https://github.com/DJtheRedstoner/DevAuth). Download the `forge-le ## Hot Reloading Hot Reloading is possible by first launching using the IntelliJ debugger with [DCEVM 1.8](https://dcevm.github.io/). Then running a regular build and confirming the reload prompt. This can cause issues (especially with commands), so restarting is sometimes still necessary. + +## Creating a new Release +
+Minimized, for your convenience + +> **Release Types** +> +> Right now we can create Full Releases, Pre Releases and Hotfixes. +> +> - A Full Release is sent to all users, regardless of update stream. +> - A Pre Release is only sent to users who have opted into receiving beta updates. +> - A Hotfix is only sent to users who have *not* opted into receiving beta updates. +> - Therefore when a bug is fixed in a hotfix update, it should *also* be fixed in a separate prerelease update. +> On the other hand, not all bugs fixed in a prerelease update need to be also dispatched in a hotfix. + +### Creating a new Full Release + +> Full Releases should be bug free, feature complete, and ideally checked by not only the community, but also by Moulberry himself, if he so desires. + +- Edit `NotEnoughUpdates.java` and change + +```java +public static final String VERSION = "2.2.0-REL"; /* Update the VERSION name */ +public static final int VERSION_ID = 20200; /* Set the VERSION_ID to match the version name like so: MAJOR * 10000 + MINOR * 100 + PATCH */ +public static final int PRE_VERSION_ID = 0; /* Reset the PRE_VERSION_ID back to 0 */ +public static final int HOTFIX_VERSION_ID = 0; /* Reset the HOTFIX_VERSION_ID back to 0 */ +``` + +- Build a jar from this, either using the CI in github actions, or using `gradle remapJar` directly. + - If building locally, make sure that all your changes are in version control so that the commit hash is set correctly (A non `dirty` jar) +- Create a github release (marked as full release). This should also simultaneously create a tag on which to base future hotfixes. +- Edit the `update.json` in the repository and change + +```json5 +{ + "version": "2.1.0-REL", /* Update to match the VERSION name in java */ + "version_id": 20100, /* Update to match the VERSION_ID in java */ + "update_msg": "§7§m§l--------------------§6§l[§c§lNEU§6§l]§7§m§l--------------------\n\n§7A new version, v§6{version}§7, is now available!\n ", /* Update the version name. Remove old patch notes; Optionally add in a short new patch note. */ + "pre_version": "0.0", /* Reset to 0.0 */ + "pre_version_id": 0, /* Reset to 0 */ + "update_link": "https://github.com/NotEnoughUpdates/NotEnoughUpdates/releases/tag/", /* Change download link to the github release */ +} +``` + +- Launch the game in an older version with this new repo locally to test the messages look first, then push to the central NEU repo (both `master` and `dangerous`) +- Create an announcement in discord [#neu-download](https://discord.com/channels/516977525906341928/693586404256645231). + +### Creating a pre release + +> Pre Releases are intended to be mostly feature complete, mostly bug free releases that either don't have enough changes to justify a new Full Release, or have outstanding PRs that are probably merged soon. + +- Edit `NotEnoughUpdates.java` and change + +```java +public static final String VERSION = "2.2.0-REL"; /* The VERSION name should still be the same as the latest previously released FULL release */ +public static final int VERSION_ID = 20200; /* Same as VERSION name */ +public static final int PRE_VERSION_ID = 1; /* Increment the PRE_VERSION_ID */ +``` + +- Build a jar from this, either using the CI in github actions, or using `gradle remapJar` directly. + - If building locally, make sure that all your changes are in version control so that the commit hash is set correctly (A non `dirty` jar) +- Create a github release (marked as pre release) +- Edit the `update.json` in the repository and change + +```json5 +{ + "version": "2.1.0-REL", /* The VERSION name should still be the same as the latest previously released FULL release */ + "version_id": 20100, /* Same as VERSION name */ + "pre_update_msg": "§7§m§l--------------------§5§l[§c§lNEU§5§l]§7§m§l--------------------\n\n§7A new pre-release, v§52.0-PRE{pre_version}§7, is now available!\n ", /* Update the version name. Remove old patch notes; Optionally add in a short new patch note. */ + "pre_version": "0.0", /* Set to a new string (preferably increase the major version every time, except for hotfixes on the prerelease stream) */ + "pre_version_id": 0, /* Set to PRE_VERSION_ID from java */ + "update_link": "https://github.com/NotEnoughUpdates/NotEnoughUpdates/releases/tag/", /* Change download link to the github release */ +} +``` + +- Launch the game in an older version with this new repo locally to test the messages look first, then push to the central NEU repo (both `master` and `dangerous`, as some prerelease people sadly don't know how to change repo branches) +- Create an announcement in discord [#unofficial-prereleases](https://discord.com/channels/516977525906341928/837679819487313971). + +### Creating a Hotfix + +> Hotfixes spring off of a Full Release and intend to fix bugs and security flaws. They can, but ideally shouldn't, contain features from pre releases and are intended as a drop in replacement of the current full release of NEU. These bug fixes should ideally also be released as a prerelease in tandem with the hotfix. + +- Edit `NotEnoughUpdates.java` and change + +```java +public static final String VERSION = "2.2.0-REL"; /* The VERSION name should still be the same as the latest previously released FULL release */ +public static final int VERSION_ID = 20200; /* Same as VERSION name */ +public static final int PRE_VERSION_ID = 0; /* The PRE_VERSION_ID should still be 0 (as this is based off a full release) */ +public static final int HOTFIX_VERSION_ID = 1; /* Increment the HOTFIX_VERSION_ID */ +``` + +- Build a jar from this, either using the CI in github actions, or using `gradle remapJar` directly. + - If building locally, make sure that all your changes are in version control so that the commit hash is set correctly (A non `dirty` jar) +- Create a github release (marked as full release) +- Edit the previous FULL release on github with a link to the new release. +- Edit the `update.json` in the repository and change + +```json5 +{ + "version": "2.1.0-REL", /* This version should still remain the same as the last full release */ + "version_id": 20100, /* Same as version */ + "update_msg": "§7§m§l--------------------§6§l[§c§lNEU§6§l]§7§m§l--------------------\n\n§7A new version, v§6{version}§7, is now available!\n ", /* Update the version name. Don't remove old patch notes; Optionally add in a short new patch note. Indicate that there is a hotfix present */ + "update_link": "https://github.com/NotEnoughUpdates/NotEnoughUpdates/releases/tag/", /* Change download link to the github release */ +} +``` + +- Launch the game in an older version with this new repo locally to test the messages look first, then push to the central NEU repo (both `master` and `dangerous`) +- Create an announcement in discord [#neu-download](https://discord.com/channels/516977525906341928/693586404256645231). +
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index 3ef305f2..82db6373 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -34,7 +34,6 @@ import io.github.moulberry.notenoughupdates.listener.NEUEventListener; import io.github.moulberry.notenoughupdates.listener.OldAnimationChecker; import io.github.moulberry.notenoughupdates.listener.RenderListener; import io.github.moulberry.notenoughupdates.miscfeatures.AuctionProfit; -import io.github.moulberry.notenoughupdates.miscfeatures.CookieWarning; import io.github.moulberry.notenoughupdates.miscfeatures.CrystalOverlay; import io.github.moulberry.notenoughupdates.miscfeatures.CrystalWishingCompassSolver; import io.github.moulberry.notenoughupdates.miscfeatures.CustomItemEffects; @@ -70,6 +69,7 @@ import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.Utils; import io.github.moulberry.notenoughupdates.util.XPInformation; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.resources.IReloadableResourceManager; import net.minecraft.client.settings.KeyBinding; @@ -108,9 +108,9 @@ import java.util.Set; public class NotEnoughUpdates { public static final String MODID = "notenoughupdates"; public static final String VERSION = "2.1.0-REL"; - public static final String PRE_VERSION = "0.0"; - public static final int VERSION_ID = 20100; + public static final int VERSION_ID = 20200; public static final int PRE_VERSION_ID = 0; + public static final int HOTFIX_VERSION_ID = 1; /** * Registers the biomes for the crystal hollows here so optifine knows they exists */ @@ -371,11 +371,10 @@ public class NotEnoughUpdates { } } - public void displayLinks(JsonObject update) { + public void displayLinks(JsonObject update, int totalWidth) { String discord_link = update.get("discord_link").getAsString(); String youtube_link = update.get("youtube_link").getAsString(); String twitch_link = update.get("twitch_link").getAsString(); - String update_link = update.get("update_link").getAsString(); String github_link = update.get("github_link").getAsString(); String other_text = update.get("other_text").getAsString(); String other_link = update.get("other_link").getAsString(); @@ -388,8 +387,7 @@ public class NotEnoughUpdates { } ChatComponentText links = new ChatComponentText(""); ChatComponentText separator = new ChatComponentText( - EnumChatFormatting.GRAY + EnumChatFormatting.BOLD.toString() + EnumChatFormatting.STRIKETHROUGH + - (other == null ? "--" : "-")); + EnumChatFormatting.GRAY + EnumChatFormatting.BOLD.toString() + EnumChatFormatting.STRIKETHROUGH + "-"); ChatComponentText discord = new ChatComponentText( EnumChatFormatting.GRAY + "[" + EnumChatFormatting.BLUE + "Discord" + EnumChatFormatting.GRAY + "]"); discord.setChatStyle(Utils.createClickStyle(ClickEvent.Action.OPEN_URL, discord_link)); @@ -399,9 +397,6 @@ public class NotEnoughUpdates { ChatComponentText twitch = new ChatComponentText( EnumChatFormatting.GRAY + "[" + EnumChatFormatting.DARK_PURPLE + "Twitch" + EnumChatFormatting.GRAY + "]"); twitch.setChatStyle(Utils.createClickStyle(ClickEvent.Action.OPEN_URL, twitch_link)); - ChatComponentText release = new ChatComponentText( - EnumChatFormatting.GRAY + "[" + EnumChatFormatting.GREEN + "Release" + EnumChatFormatting.GRAY + "]"); - release.setChatStyle(Utils.createClickStyle(ClickEvent.Action.OPEN_URL, update_link)); ChatComponentText github = new ChatComponentText( EnumChatFormatting.GRAY + "[" + EnumChatFormatting.DARK_PURPLE + "GitHub" + EnumChatFormatting.GRAY + "]"); github.setChatStyle(Utils.createClickStyle(ClickEvent.Action.OPEN_URL, github_link)); @@ -413,16 +408,28 @@ public class NotEnoughUpdates { links.appendSibling(separator); links.appendSibling(twitch); links.appendSibling(separator); - links.appendSibling(release); - links.appendSibling(separator); links.appendSibling(github); links.appendSibling(separator); if (other != null) { links.appendSibling(other); links.appendSibling(separator); } - - Minecraft.getMinecraft().thePlayer.addChatMessage(links); + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + int missingWidth = Math.max(0, totalWidth - fr.getStringWidth(links.getFormattedText())); + int missingCharsOnEitherSide = missingWidth / fr.getStringWidth(EnumChatFormatting.BOLD + "-") / 2; + StringBuilder sb = new StringBuilder(missingCharsOnEitherSide + 6); + sb.append(EnumChatFormatting.GRAY); + sb.append(EnumChatFormatting.BOLD); + sb.append(EnumChatFormatting.STRIKETHROUGH); + for (int i = 0; i < missingCharsOnEitherSide; i++) { + sb.append("-"); + } + String padding = sb.toString(); + ChatComponentText cp = new ChatComponentText(""); + cp.appendText(padding); + cp.appendSibling(links); + cp.appendText(padding); + Minecraft.getMinecraft().thePlayer.addChatMessage(cp); } @SubscribeEvent diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/LinksCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/help/LinksCommand.java index cb8ba6ed..9938403c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/LinksCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/help/LinksCommand.java @@ -44,7 +44,7 @@ public class LinksCommand extends ClientCommandBase { JsonObject update = NotEnoughUpdates.INSTANCE.manager.getJsonFromFile(updateJson); Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("")); - NotEnoughUpdates.INSTANCE.displayLinks(update); + NotEnoughUpdates.INSTANCE.displayLinks(update,0 ); Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("")); } catch (Exception ignored) { } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java index 8b924d78..d5b39487 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java @@ -19,6 +19,7 @@ package io.github.moulberry.notenoughupdates.listener; +import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; @@ -59,6 +60,7 @@ import org.lwjgl.input.Keyboard; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -78,6 +80,37 @@ public class NEUEventListener { this.neu = neu; } + private void displayUpdateMessage(JsonObject updateJson, String updateMessage, String downloadLink) { + int firstWidth = -1; + + for (String line : Iterables.concat(Arrays.asList(updateMessage.split("\n")), Arrays.asList("Download here"))) { + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + boolean isDownloadLink = line.equals("Download here"); + int width = fr.getStringWidth(line); + if (firstWidth == -1) { + firstWidth = width; + } + int missingLen = firstWidth - width; + if (missingLen > 0) { + StringBuilder sb = new StringBuilder(missingLen / 4 / 2 +line.length()); + for (int i = 0; i < missingLen / 4 / 2; i++) { /* fr.getCharWidth(' ') == 4 */ + sb.append(" "); + } + sb.append(line); + line = sb.toString(); + } + ChatComponentText cp = new ChatComponentText(line); + if (isDownloadLink) + cp.setChatStyle(Utils.createClickStyle(ClickEvent.Action.OPEN_URL, downloadLink)); + Minecraft.getMinecraft().thePlayer.addChatMessage(cp); + } + neu.displayLinks(updateJson, firstWidth); + NotificationHandler.displayNotification(Arrays.asList( + "§eThere is a new version of NotEnoughUpdates available.", + "§eCheck the chat for more information" + ), true); + } + private void displayUpdateMessageIfOutOfDate() { File repo = neu.manager.repoLocation; if (repo.exists()) { @@ -85,73 +118,31 @@ public class NEUEventListener { try { JsonObject o = neu.manager.getJsonFromFile(updateJson); - String version = o.get("version").getAsString(); - String preVersion = o.get("pre_version").getAsString(); - - boolean shouldUpdate = !NotEnoughUpdates.VERSION.equalsIgnoreCase(version); - boolean shouldPreUpdate = !NotEnoughUpdates.PRE_VERSION.equalsIgnoreCase(preVersion); - - if (o.has("version_id") && o.get("version_id").isJsonPrimitive()) { - int version_id = o.get("version_id").getAsInt(); - shouldUpdate = version_id > NotEnoughUpdates.VERSION_ID; - } - if (o.has("pre_version_id") && o.get("pre_version_id").isJsonPrimitive()) { - int pre_version_id = o.get("pre_version_id").getAsInt(); - shouldPreUpdate = pre_version_id > NotEnoughUpdates.PRE_VERSION_ID; - } - - if (shouldUpdate) { - String update_msg = o.get("update_msg").getAsString(); - - int first_len = -1; - for (String line : update_msg.split("\n")) { - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - int len = fr.getStringWidth(line); - if (first_len == -1) { - first_len = len; - } - int missing_len = first_len - len; - if (missing_len > 0) { - StringBuilder sb = new StringBuilder(line); - for (int i = 0; i < missing_len / 8; i++) { - sb.insert(0, " "); - } - line = sb.toString(); - } - line = line.replaceAll("\\{version}", version); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(line)); - } - - neu.displayLinks(o); - - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("")); - } else if (shouldPreUpdate && NotEnoughUpdates.VERSION_ID == o.get("version").getAsInt()) { - String pre_update_msg = o.get("pre_update_msg").getAsString(); - - int first_len = -1; - for (String line : pre_update_msg.split("\n")) { - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - int len = fr.getStringWidth(line); - if (first_len == -1) { - first_len = len; - } - int missing_len = first_len - len; - if (missing_len > 0) { - StringBuilder sb = new StringBuilder(line); - for (int i = 0; i < missing_len / 8; i++) { - sb.insert(0, " "); - } - line = sb.toString(); - } - line = line.replaceAll("\\{pre_version}", preVersion); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(line)); - } - - neu.displayLinks(o); - - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("")); + int fullReleaseVersion = + o.has("version_id") && o.get("version_id").isJsonPrimitive() ? o.get("version_id").getAsInt() : -1; + int preReleaseVersion = + o.has("version_id") && o.get("version_id").isJsonPrimitive() ? o.get("version_id").getAsInt() : -1; + int hotfixVersion = + o.has("hotfix_id") && o.get("hotfix_id").isJsonPrimitive() ? o.get("hotfix_id").getAsInt() : -1; + + boolean hasFullReleaseAvailableForUpgrade = fullReleaseVersion > NotEnoughUpdates.VERSION_ID; + boolean hasHotfixAvailableForUpgrade = + fullReleaseVersion == NotEnoughUpdates.VERSION_ID && hotfixVersion > NotEnoughUpdates.HOTFIX_VERSION_ID; + boolean hasPreReleaseAvailableForUpdate = + fullReleaseVersion == NotEnoughUpdates.VERSION_ID && preReleaseVersion > NotEnoughUpdates.PRE_VERSION_ID; + + int updateChannel = NotEnoughUpdates.INSTANCE.config.notifications.showUpdateMsg; /* 1 = Full, 2 = Pre */ + if (hasFullReleaseAvailableForUpgrade || (hasHotfixAvailableForUpgrade && updateChannel == 1)) { + displayUpdateMessage(o, o.get("update_msg").getAsString(), o.get("update_link").getAsString()); + } else if (hasPreReleaseAvailableForUpdate && updateChannel == 2) { + displayUpdateMessage(o, o.get("pre_update_msg").getAsString(), o.get("pre_update_link").getAsString()); } - } catch (Exception ignored) { + } catch (Exception e) { + e.printStackTrace(); + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( + "§e[NEU] §cThere has been an error checking for updates. Check the log or join the discord for more information.").setChatStyle( + Utils.createClickStyle( + ClickEvent.Action.OPEN_URL, "https://discord.gg/moulberry"))); } } } @@ -274,7 +265,7 @@ public class NEUEventListener { if (!joinedSB) { joinedSB = true; - if (NotEnoughUpdates.INSTANCE.config.notifications.showUpdateMsg) { + if (NotEnoughUpdates.INSTANCE.config.notifications.showUpdateMsg != 0) { displayUpdateMessageIfOutOfDate(); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java index 08ae5745..b0e4c60b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java @@ -196,8 +196,8 @@ public class Misc { name = "Waypoint Keybind", desc = "Press this keybind to show waypoints to various NPCs" ) - @ConfigEditorKeybind(defaultKey = Keyboard.KEY_N) - public int keybindWaypoint = Keyboard.KEY_N; + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_NONE) + public int keybindWaypoint = Keyboard.KEY_NONE; @Expose @ConfigOption( @@ -210,7 +210,7 @@ public class Misc { @Expose @ConfigOption( name = "Warp twice", - desc = "Warp twice when using SHIFT+N to /warp to a waypoint." + desc = "Warp twice when using SHIFT+ to /warp to a waypoint." ) @ConfigEditorBoolean public boolean warpTwice = true; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Notifications.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Notifications.java index 353cd36d..c89110aa 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Notifications.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Notifications.java @@ -21,6 +21,7 @@ package io.github.moulberry.notenoughupdates.options.seperateSections; import com.google.gson.annotations.Expose; import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorBoolean; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorDropdown; import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorSlider; import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigOption; @@ -30,8 +31,8 @@ public class Notifications { name = "Update Messages", desc = "Give a notification in chat whenever a new version of NEU is released" ) - @ConfigEditorBoolean - public boolean showUpdateMsg = true; + @ConfigEditorDropdown(values = {"Off", "Releases", "Pre-Releases"}) + public int showUpdateMsg = 1; @Expose @ConfigOption( -- cgit