Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix recipe message not being translated correctly #5952

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading