From 5c70fb1291fdc717402c46f97032526ed29290a7 Mon Sep 17 00:00:00 2001 From: Aria Date: Tue, 28 Feb 2023 09:26:46 -0700 Subject: [PATCH] Add a chat replacement helper --- gradle.properties | 2 +- .../libzontreck/util/ChatHelpers.java | 19 +++++++++++++++++++ src/main/resources/META-INF/mods.toml | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index d8733f7..13f77c1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,5 +5,5 @@ org.gradle.daemon=false mc_version=1.18.2 forge_version=40.2.1 -myversion=1.0.5.0228230829 +myversion=1.0.5.0228230925 parchment_version=2022.11.06 \ No newline at end of file diff --git a/src/main/java/dev/zontreck/libzontreck/util/ChatHelpers.java b/src/main/java/dev/zontreck/libzontreck/util/ChatHelpers.java index 5329e65..26a99bb 100644 --- a/src/main/java/dev/zontreck/libzontreck/util/ChatHelpers.java +++ b/src/main/java/dev/zontreck/libzontreck/util/ChatHelpers.java @@ -3,6 +3,7 @@ package dev.zontreck.libzontreck.util; import java.util.UUID; import dev.zontreck.libzontreck.LibZontreck; +import dev.zontreck.libzontreck.chat.ChatColor; import net.minecraft.network.chat.Component; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; @@ -72,4 +73,22 @@ public class ChatHelpers { { broadcastTo(ID.getUUID(), message, server, true); } + + /** + * Returns the output with colors applied, and chat entries replaced using [number] as the format + * @param input + * @param inputs Entries to replace with in input + * @return + */ + public static String macroize(String input, String... inputs) + { + String output = input; + for (int i = 0; i < inputs.length; i++) { + String inp = inputs[i]; + + output = output.replaceAll("\\["+String.valueOf(i)+"]", inp); + } + + return ChatColor.doColors(output); + } } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 53d965d..b107e9d 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -19,7 +19,7 @@ modId="libzontreck" #mandatory # The version number of the mod - there's a few well known ${} variables useable here or just hardcode it # ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata # see the associated build.gradle script for how to populate this completely automatically during a build -version="1.0.5.0228230829" #mandatory +version="1.0.5.0228230925" #mandatory # A display name for the mod displayName="LibZontreck" #mandatory # A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/