Skip to content

Commit

Permalink
Fix recipe message not being translated correctly (#5952)
Browse files Browse the repository at this point in the history
I truly don't understand how this slipped through the cracks.

Fixes #5943
  • Loading branch information
JRoy authored Oct 15, 2024
1 parent 9c3e0eb commit c80bef9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Material, String> 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<ItemStack> ingredients = recipe.getIngredientList();
if (showWindow) {
Expand Down
2 changes: 1 addition & 1 deletion Essentials/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ recipeCommandUsage=/<command> <<item>|hand> [number]
recipeCommandUsage1=/<command> <<item>|hand> [page]
recipeCommandUsage1Description=Displays how to craft the given item
recipeFurnace=<primary>Smelt\: <secondary>{0}<primary>.
recipeGrid=<secondary>{0}X <primary>| §{1}X <primary>| §{2}X
recipeGrid=<secondary>{0}X <primary>| {1}X <primary>| {2}X
recipeGridItem=<secondary>{0}X <primary>is <secondary>{1}
recipeMore=<primary>Type<secondary> /{0} {1} <number><primary> to see other recipes for <secondary>{2}<primary>.
recipeNone=No recipes exist for {0}.
Expand Down

0 comments on commit c80bef9

Please sign in to comment.