From 0875a6a72cc47926cb15310ce7e89c3648a1e545 Mon Sep 17 00:00:00 2001 From: RappyTV Date: Fri, 18 Aug 2023 17:39:51 +0200 Subject: [PATCH] Remove legacy color codes --- build.gradle.kts | 2 +- .../rappytv/deathfinder/DeathFinderAddon.java | 9 +++++- .../deathfinder/commands/BackCommand.java | 4 ++- .../deathfinder/commands/CoordsCommand.java | 17 ++++++----- .../deathfinder/events/DeathEvent.java | 30 +++++++++++-------- .../com/rappytv/deathfinder/util/Util.java | 18 +++++------ .../assets/deathfinder/i18n/en_us.json | 2 +- readme.md | 2 +- 8 files changed, 50 insertions(+), 34 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 2a7e74b..02ffa7f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -21,7 +21,7 @@ labyMod { author = "RappyTV" description = "This addon saves your last death point, so you can find your items again." minecraftVersion = "1.8<1.20.1" - version = System.getenv().getOrDefault("VERSION", "1.0.1") + version = System.getenv().getOrDefault("VERSION", "1.0.2") } minecraft { diff --git a/core/src/main/java/com/rappytv/deathfinder/DeathFinderAddon.java b/core/src/main/java/com/rappytv/deathfinder/DeathFinderAddon.java index 30b727b..76c17bf 100644 --- a/core/src/main/java/com/rappytv/deathfinder/DeathFinderAddon.java +++ b/core/src/main/java/com/rappytv/deathfinder/DeathFinderAddon.java @@ -4,12 +4,19 @@ import com.rappytv.deathfinder.commands.CoordsCommand; import com.rappytv.deathfinder.util.Location; import net.labymod.api.addon.LabyAddon; +import net.labymod.api.client.component.Component; +import net.labymod.api.client.component.format.NamedTextColor; +import net.labymod.api.client.component.format.Style; +import net.labymod.api.client.component.format.TextDecoration; import net.labymod.api.models.addon.annotation.AddonMain; @AddonMain public class DeathFinderAddon extends LabyAddon { - public final static String prefix = "§5§lDF §8» §7"; + public final static Component prefix = Component + .text("DF ", Style.builder().color(NamedTextColor.DARK_PURPLE).decorate(TextDecoration.BOLD).build()) + .append(Component.text("» ", NamedTextColor.DARK_GRAY)); + private static Location deathLocation; private static DeathFinderAddon instance; diff --git a/core/src/main/java/com/rappytv/deathfinder/commands/BackCommand.java b/core/src/main/java/com/rappytv/deathfinder/commands/BackCommand.java index 04b66d7..9840504 100644 --- a/core/src/main/java/com/rappytv/deathfinder/commands/BackCommand.java +++ b/core/src/main/java/com/rappytv/deathfinder/commands/BackCommand.java @@ -6,6 +6,8 @@ import com.rappytv.deathfinder.util.Util; import net.labymod.api.Laby; import net.labymod.api.client.chat.command.Command; +import net.labymod.api.client.component.Component; +import net.labymod.api.client.component.format.NamedTextColor; public class BackCommand extends Command { @@ -22,7 +24,7 @@ public boolean execute(String prefix, String[] arguments) { return false; if(DeathFinderAddon.getDeathLocation() == null) { - Util.msg("§c" + Util.getTranslation("deathfinder.messages.noSavedPoint")); + Util.msg(Component.translatable("deathfinder.messages.noSavedPoint", NamedTextColor.RED)); return true; } Location death = DeathFinderAddon.getDeathLocation(); diff --git a/core/src/main/java/com/rappytv/deathfinder/commands/CoordsCommand.java b/core/src/main/java/com/rappytv/deathfinder/commands/CoordsCommand.java index 1a5b7aa..9ff676d 100644 --- a/core/src/main/java/com/rappytv/deathfinder/commands/CoordsCommand.java +++ b/core/src/main/java/com/rappytv/deathfinder/commands/CoordsCommand.java @@ -5,6 +5,8 @@ import com.rappytv.deathfinder.util.Location; import com.rappytv.deathfinder.util.Util; import net.labymod.api.client.chat.command.Command; +import net.labymod.api.client.component.Component; +import net.labymod.api.client.component.format.NamedTextColor; public class CoordsCommand extends Command { @@ -21,18 +23,17 @@ public boolean execute(String prefix, String[] arguments) { return false; if(DeathFinderAddon.getDeathLocation() == null) { - Util.msg("§c" + Util.getTranslation("deathfinder.messages.noSavedPoint")); + Util.msg(Component.translatable("deathfinder.messages.noSavedPoint", NamedTextColor.RED)); return true; } Location death = DeathFinderAddon.getDeathLocation(); Util.msg( - "§e" + Util.getTranslation("deathfinder.messages.deathPoint", - "§aX: §b" + String.format(java.util.Locale.US,"%.2f", death.getX()), - "§aY: §b" + String.format(java.util.Locale.US,"%.2f", death.getY()), - "§aZ: §b" + String.format(java.util.Locale.US,"%.2f", death.getZ()), - "§aYaw: §b" + String.format(java.util.Locale.US,"%.2f", death.getYaw()), - "§aPitch: §b" + String.format(java.util.Locale.US,"%.2f", death.getPitch()) - ) + Component.translatable("deathfinder.messages.deathPoint", NamedTextColor.YELLOW), + Component.text("X: ", NamedTextColor.GREEN).append(Component.text(String.format(java.util.Locale.US,"%.2f", death.getX()), NamedTextColor.AQUA)), + Component.text("Y: ", NamedTextColor.GREEN).append(Component.text(String.format(java.util.Locale.US,"%.2f", death.getY()), NamedTextColor.AQUA)), + Component.text("Z: ", NamedTextColor.GREEN).append(Component.text(String.format(java.util.Locale.US,"%.2f", death.getZ()), NamedTextColor.AQUA)), + Component.text("Yaw: ", NamedTextColor.GREEN).append(Component.text(String.format(java.util.Locale.US,"%.2f", death.getYaw()), NamedTextColor.AQUA)), + Component.text("Pitch: ", NamedTextColor.GREEN).append(Component.text(String.format(java.util.Locale.US,"%.2f", death.getPitch()), NamedTextColor.AQUA)) ); return true; } diff --git a/core/src/main/java/com/rappytv/deathfinder/events/DeathEvent.java b/core/src/main/java/com/rappytv/deathfinder/events/DeathEvent.java index d742e56..d1b2461 100644 --- a/core/src/main/java/com/rappytv/deathfinder/events/DeathEvent.java +++ b/core/src/main/java/com/rappytv/deathfinder/events/DeathEvent.java @@ -4,9 +4,13 @@ import com.rappytv.deathfinder.util.Location; import com.rappytv.deathfinder.util.Util; import net.labymod.api.Laby; +import net.labymod.api.client.component.Component; import net.labymod.api.client.component.TextComponent; import net.labymod.api.client.component.event.ClickEvent; import net.labymod.api.client.component.event.HoverEvent; +import net.labymod.api.client.component.format.NamedTextColor; +import net.labymod.api.client.component.format.Style; +import net.labymod.api.client.component.format.TextDecoration; public class DeathEvent { @@ -19,27 +23,29 @@ public DeathEvent(Location location) { // Message - TextComponent.Builder builder = TextComponent.builder(); - builder.append("§8»\n"); - builder.append( - DeathFinderAddon.prefix + "§a" + Util.getTranslation("deathfinder.messages.savedPoint") + "\n"); + Component builder = Component + .text("»\n", NamedTextColor.DARK_GRAY) + .append(DeathFinderAddon.prefix) + .append(Component.translatable("deathfinder.messages.savedPoint", NamedTextColor.GREEN)) + .append(Component.text("\n")); + if(backCommand || coordsCommand) builder.append(DeathFinderAddon.prefix); if(backCommand) builder.append( - TextComponent.builder() - .text("§8[§c§lTP§8]") + Component + .text("[", NamedTextColor.DARK_GRAY) + .append(Component.text("TP", Style.builder().color(NamedTextColor.RED).decorate(TextDecoration.BOLD).build())) + .append(Component.text("]", NamedTextColor.DARK_GRAY)) .hoverEvent(HoverEvent.showText(TextComponent.builder().text("§a" + Util.getTranslation("deathfinder.messages.clickToTeleport")).build())) .clickEvent(ClickEvent.runCommand("/back")) - .build() ); - if(backCommand && coordsCommand) builder.append(TextComponent.builder().text(" §7| ").build()); + if(backCommand && coordsCommand) builder.append(Component.text(" §7| ")); if(coordsCommand) builder.append( - TextComponent.builder() + Component .text("§8[§b§lINFO§8]") .hoverEvent(HoverEvent.showText(TextComponent.builder().text("§a" + Util.getTranslation("deathfinder.messages.clickToShow")).build())) .clickEvent(ClickEvent.runCommand("/coords")) - .build() ); - builder.append((backCommand || coordsCommand ? "\n" : "") + "§8»"); - Laby.references().chatExecutor().displayClientMessage(builder.build()); + builder.append(Component.text((backCommand || coordsCommand ? "\n" : "") + "§8»", NamedTextColor.DARK_GRAY)); + Laby.references().chatExecutor().displayClientMessage(builder); } } diff --git a/core/src/main/java/com/rappytv/deathfinder/util/Util.java b/core/src/main/java/com/rappytv/deathfinder/util/Util.java index bbb1f60..aab17ee 100644 --- a/core/src/main/java/com/rappytv/deathfinder/util/Util.java +++ b/core/src/main/java/com/rappytv/deathfinder/util/Util.java @@ -3,7 +3,8 @@ import static com.rappytv.deathfinder.DeathFinderAddon.prefix; import com.rappytv.deathfinder.DeathFinderAddon; -import net.labymod.api.client.component.TextComponent; +import net.labymod.api.client.component.Component; +import net.labymod.api.client.component.format.NamedTextColor; import net.labymod.api.util.I18n; public class Util { @@ -13,16 +14,15 @@ public static String getTranslation(String key, Object... args) { return I18n.getTranslation(key, args); } - public static void msg(String text) { - TextComponent.Builder component = TextComponent.builder(); - String[] lines = text.split("\n"); - component.append("§8»\n"); + public static void msg(Component... lines) { + Component component = Component + .text("»\n", NamedTextColor.DARK_GRAY); - for(String line : lines) { - component.append(prefix + line + "\n"); + for(Component line : lines) { + component.append(prefix).append(line).append(Component.text("\n")); } - component.append("§8»"); - DeathFinderAddon.get().displayMessage(component.build()); + component.append(Component.text("»", NamedTextColor.DARK_GRAY)); + DeathFinderAddon.get().displayMessage(component); } } diff --git a/core/src/main/resources/assets/deathfinder/i18n/en_us.json b/core/src/main/resources/assets/deathfinder/i18n/en_us.json index 4260e09..15e7c57 100644 --- a/core/src/main/resources/assets/deathfinder/i18n/en_us.json +++ b/core/src/main/resources/assets/deathfinder/i18n/en_us.json @@ -31,7 +31,7 @@ "clickToTeleport": "Click to teleport to coordinates!", "clickToShow": "Click to show coordinates", "noSavedPoint": "There is no death point saved!", - "deathPoint": "Those are your death coordinates:\n%s\n%s\n%s\n%s\n%s" + "deathPoint": "Those are your death coordinates:" } } } \ No newline at end of file diff --git a/readme.md b/readme.md index 8e8e3d9..81a5c27 100644 --- a/readme.md +++ b/readme.md @@ -4,7 +4,7 @@ ### 📦 Installation 1. Press `Win` + `R` 2. Paste this into the window that popped up: `%appdata%/.minecraft/LabyMod-neo/addons` and press enter (This path may change when lm4 gets released) -3. It should open your Labymod addon directory; Paste the [Death-Finder.jar](https://github.com/RappyLabyAddons/Death-Finder/releases/download/v1.0.1/Death-Finder.jar) in there. +3. It should open your Labymod addon directory; Paste the [Death-Finder.jar](https://github.com/RappyLabyAddons/Death-Finder/releases/download/v1.0.2/Death-Finder.jar) in there. 4. Launch your Labymod client. If you have any problems with the addon/have update ideas, feel free to