From c80bef984181af78690353b22fd0a9892291d5e3 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Tue, 15 Oct 2024 07:13:16 -0400 Subject: [PATCH] Fix recipe message not being translated correctly (#5952) I truly don't understand how this slipped through the cracks. Fixes #5943 --- .../essentials/commands/Commandrecipe.java | 22 ++++++++++++++----- .../src/main/resources/messages.properties | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java index 448d2476ef9..5d9a27beb00 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java @@ -3,10 +3,12 @@ import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.User; import com.earth2me.essentials.craftbukkit.Inventories; +import com.earth2me.essentials.utils.AdventureUtil; import com.earth2me.essentials.utils.EnumUtil; import com.earth2me.essentials.utils.NumberUtil; import com.earth2me.essentials.utils.VersionUtil; import net.ess3.api.TranslatableException; +import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Material; import org.bukkit.Server; import org.bukkit.inventory.FurnaceRecipe; @@ -150,18 +152,28 @@ public void shapedRecipe(final CommandSource sender, final ShapedRecipe recipe, materials[j][k] = item == null ? null : item.getType(); } } - sender.sendTl("recipeGrid", colorMap.get(materials[0][0]), colorMap.get(materials[0][1]), colorMap.get(materials[0][2])); - sender.sendTl("recipeGrid", colorMap.get(materials[1][0]), colorMap.get(materials[1][1]), colorMap.get(materials[1][2])); - sender.sendTl("recipeGrid", colorMap.get(materials[2][0]), colorMap.get(materials[2][1]), colorMap.get(materials[2][2])); + sender.sendTl("recipeGrid", colorTag(colorMap, materials, 0, 0), colorTag(colorMap, materials, 0, 1), colorTag(colorMap, materials, 0, 2)); + sender.sendTl("recipeGrid", colorTag(colorMap, materials, 1, 0), colorTag(colorMap, materials, 1, 1), colorTag(colorMap, materials, 1, 2)); + sender.sendTl("recipeGrid", colorTag(colorMap, materials, 2, 0), colorTag(colorMap, materials, 2, 1), colorTag(colorMap, materials, 2, 2)); final StringBuilder s = new StringBuilder(); for (final Material items : colorMap.keySet().toArray(new Material[0])) { - s.append(sender.tl("recipeGridItem", colorMap.get(items), getMaterialName(sender, items))); + s.append(sender.tl("recipeGridItem", colorMap.get(items), getMaterialName(sender, items))).append(" "); } - sender.sendTl("recipeWhere", s.toString()); + sender.sendTl("recipeWhere", AdventureUtil.parsed(s.toString())); } } + private AdventureUtil.ParsedPlaceholder colorTag(final Map colorMap, final Material[][] materials, final int x, final int y) { + final char colorChar = colorMap.get(materials[x][y]).charAt(0); + final NamedTextColor namedTextColor = AdventureUtil.fromChar(colorChar); + if (namedTextColor == null) { + throw new IllegalStateException("Illegal amount of materials in recipe"); + } + + return AdventureUtil.parsed("<" + namedTextColor + ">" + colorChar); + } + public void shapelessRecipe(final CommandSource sender, final ShapelessRecipe recipe, final boolean showWindow) { final List ingredients = recipe.getIngredientList(); if (showWindow) { diff --git a/Essentials/src/main/resources/messages.properties b/Essentials/src/main/resources/messages.properties index e22ce23731a..7836b85e483 100644 --- a/Essentials/src/main/resources/messages.properties +++ b/Essentials/src/main/resources/messages.properties @@ -1042,7 +1042,7 @@ recipeCommandUsage=/ <|hand> [number] recipeCommandUsage1=/ <|hand> [page] recipeCommandUsage1Description=Displays how to craft the given item recipeFurnace=Smelt\: {0}. -recipeGrid={0}X | §{1}X | §{2}X +recipeGrid={0}X | {1}X | {2}X recipeGridItem={0}X is {1} recipeMore=Type /{0} {1} to see other recipes for {2}. recipeNone=No recipes exist for {0}.