From 46471d4205c2624cab76e4e8aa02acd7ca76e01d Mon Sep 17 00:00:00 2001 From: ItzKatze <136186750+ItzKatze@users.noreply.github.com> Date: Thu, 23 Oct 2025 20:42:12 +0200 Subject: [PATCH] added more recipes some caption work --- .../forcebattle/command/BackpackCommand.java | 5 +- .../forcebattle/command/RecipeCommand.java | 5 +- .../gui/impl/ConfigSettingsGUI.java | 4 +- .../gui/impl/CraftingRecipeGUI.java | 129 ++++++++++++++---- .../forcebattle/gui/impl/SettingsGUI.java | 4 +- .../forcebattle/gui/impl/TeamBackpackGUI.java | 8 +- src/main/resources/languages/en_US.json | 8 +- 7 files changed, 124 insertions(+), 39 deletions(-) diff --git a/src/main/java/net/fameless/forcebattle/command/BackpackCommand.java b/src/main/java/net/fameless/forcebattle/command/BackpackCommand.java index 092815b..d165a4c 100644 --- a/src/main/java/net/fameless/forcebattle/command/BackpackCommand.java +++ b/src/main/java/net/fameless/forcebattle/command/BackpackCommand.java @@ -31,7 +31,10 @@ public void executeCommand(CommandCaller caller, String[] args) { caller.sendMessage(Caption.of("error.backpacks_disabled")); return; } - if (GameListener.startPhase) return; + if (GameListener.startPhase) { + caller.sendMessage(Caption.of("error.game_not_started")); + return; + }; Optional senderOpt = BattlePlayer.adapt(caller.getName()); diff --git a/src/main/java/net/fameless/forcebattle/command/RecipeCommand.java b/src/main/java/net/fameless/forcebattle/command/RecipeCommand.java index ef79c4a..84f7e4b 100644 --- a/src/main/java/net/fameless/forcebattle/command/RecipeCommand.java +++ b/src/main/java/net/fameless/forcebattle/command/RecipeCommand.java @@ -1,5 +1,6 @@ package net.fameless.forcebattle.command; +import net.fameless.forcebattle.caption.Caption; import net.fameless.forcebattle.command.framework.CallerType; import net.fameless.forcebattle.command.framework.Command; import net.fameless.forcebattle.command.framework.CommandCaller; @@ -30,7 +31,7 @@ public void executeCommand(@NotNull CommandCaller caller, String[] args) { if (!(caller instanceof BattlePlayer player)) return; if (args.length == 0) { - player.getPlayer().sendMessage("§cUsage: /item "); + sendUsage(caller); return; } @@ -38,7 +39,7 @@ public void executeCommand(@NotNull CommandCaller caller, String[] args) { Material material = Material.matchMaterial(input); if (material == null) { - player.getPlayer().sendMessage("§cInvalid item: " + args[0]); + caller.sendMessage(Caption.of("command.no_such_material")); return; } diff --git a/src/main/java/net/fameless/forcebattle/gui/impl/ConfigSettingsGUI.java b/src/main/java/net/fameless/forcebattle/gui/impl/ConfigSettingsGUI.java index 41d9fb1..0258c77 100644 --- a/src/main/java/net/fameless/forcebattle/gui/impl/ConfigSettingsGUI.java +++ b/src/main/java/net/fameless/forcebattle/gui/impl/ConfigSettingsGUI.java @@ -11,7 +11,6 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.tag.Tag; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.Material; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; @@ -61,9 +60,8 @@ public enum ConfigSettingButton { public ItemStack createItem() { if (lore != null && setting != null) { String state = SettingsManager.getState(setting).getDisplayName(SettingsManager.isMultiState(setting)); - Component componentLore = Caption.of(lore, TagResolver.resolver("state", Tag.inserting(Component.text(state)))); - String rawLore = LegacyComponentSerializer.legacySection().serialize(componentLore); + String rawLore = Caption.getAsLegacy(lore, TagResolver.resolver("state", Tag.inserting(Component.text(state)))); List loreLines = new ArrayList<>(List.of(rawLore.split("\n"))); return ItemStackCreator.getStack( diff --git a/src/main/java/net/fameless/forcebattle/gui/impl/CraftingRecipeGUI.java b/src/main/java/net/fameless/forcebattle/gui/impl/CraftingRecipeGUI.java index e572f83..067a1f7 100644 --- a/src/main/java/net/fameless/forcebattle/gui/impl/CraftingRecipeGUI.java +++ b/src/main/java/net/fameless/forcebattle/gui/impl/CraftingRecipeGUI.java @@ -1,5 +1,6 @@ package net.fameless.forcebattle.gui.impl; +import net.fameless.forcebattle.caption.Caption; import net.fameless.forcebattle.gui.ForceBattleGUI; import net.fameless.forcebattle.gui.GUIClickableItem; import net.fameless.forcebattle.gui.GUIItem; @@ -7,6 +8,9 @@ import net.fameless.forcebattle.util.ItemStackCreator; import net.fameless.forcebattle.util.Skull; import net.fameless.forcebattle.util.StringUtility; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.tag.Tag; +import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.inventory.*; @@ -21,13 +25,16 @@ public class CraftingRecipeGUI extends ForceBattleGUI { private final List recipes; private final int page; private static final int[] GRID_SLOTS = {1, 2, 3, 10, 11, 12, 19, 20, 21}; + private static final int TRANSFORM_SLOT = 5; public CraftingRecipeGUI(ItemStack result) { this(result, 0); } private CraftingRecipeGUI(ItemStack result, int page) { - super("Recipe for " + StringUtility.formatName(result.getType().name()) + " §7(" + (page + 1) + ")", 27); + super(Caption.getAsLegacy("gui.recipe_title", + TagResolver.resolver("material", Tag.inserting(Component.text(StringUtility.formatName(result.getType().name())))), + TagResolver.resolver("page", Tag.inserting(Component.text(String.valueOf(page + 1))))), 27); this.result = result; this.recipes = Bukkit.getRecipesFor(result); this.page = page; @@ -61,12 +68,10 @@ public ItemStack getItem(BattlePlayer player) { } if (recipes.size() > 1) { - if (page > 0) { + if (page > 0) set(GUIClickableItem.getGoBackItem(0, new CraftingRecipeGUI(result, page - 1))); - } - if (page < recipes.size() - 1) { + if (page < recipes.size() - 1) set(GUIClickableItem.getGoForthItem(8, new CraftingRecipeGUI(result, page + 1))); - } } if (recipes.isEmpty()) { @@ -75,7 +80,7 @@ public ItemStack getItem(BattlePlayer player) { public ItemStack getItem(BattlePlayer player) { ItemStack barrier = new ItemStack(Material.BARRIER); ItemMeta meta = barrier.getItemMeta(); - if (meta != null) meta.setDisplayName("§cNo recipe found"); + if (meta != null) meta.setDisplayName("§c" + Caption.getAsLegacy("gui.no_recipe_found")); barrier.setItemMeta(meta); return barrier; } @@ -94,26 +99,101 @@ public ItemStack getItem(BattlePlayer player) { for (int col = 0; col < Math.min(line.length(), 3); col++) { char c = line.charAt(col); RecipeChoice choice = choiceMap.get(c); - if (choice instanceof RecipeChoice.MaterialChoice matChoice && !matChoice.getChoices().isEmpty()) { - grid[row * 3 + col] = new ItemStack(matChoice.getChoices().getFirst()); - } else if (choice instanceof RecipeChoice.ExactChoice exact && !exact.getChoices().isEmpty()) { - grid[row * 3 + col] = exact.getChoices().getFirst().clone(); - } + grid[row * 3 + col] = getChoiceItem(choice); } } } else if (recipe instanceof ShapelessRecipe shapeless) { List ingredients = shapeless.getChoiceList(); for (int i = 0; i < Math.min(ingredients.size(), 9); i++) { - RecipeChoice choice = ingredients.get(i); - if (choice instanceof RecipeChoice.MaterialChoice matChoice && !matChoice.getChoices().isEmpty()) { - grid[i] = new ItemStack(matChoice.getChoices().getFirst()); - } else if (choice instanceof RecipeChoice.ExactChoice exact && !exact.getChoices().isEmpty()) { - grid[i] = exact.getChoices().getFirst().clone(); - } + grid[i] = getChoiceItem(ingredients.get(i)); } + + } else if (recipe instanceof CookingRecipe cooking) { + ItemStack input = getChoiceItem(cooking.getInputChoice()); + Material icon = switch (recipe) { + case BlastingRecipe ignored -> Material.BLAST_FURNACE; + case SmokingRecipe ignored -> Material.SMOKER; + case CampfireRecipe ignored -> Material.CAMPFIRE; + default -> Material.FURNACE; + }; + setSimpleProcess(input, icon, "§7" + StringUtility.formatName(icon.name())); + + } else if (recipe instanceof StonecuttingRecipe stonecutting) { + ItemStack input = getChoiceItem(stonecutting.getInputChoice()); + setSimpleProcess(input, Material.STONECUTTER, "§7" + Caption.getAsLegacy("gui.stonecutting_name")); + + } else if (recipe instanceof SmithingTransformRecipe smithing) { + try { + RecipeChoice base = smithing.getBase(); + RecipeChoice addition = smithing.getAddition(); + RecipeChoice template = smithing.getTemplate(); + + ItemStack baseItem = getChoiceItem(base); + ItemStack additionItem = getChoiceItem(addition); + ItemStack templateItem = getChoiceItem(template); + + setItemSafe(2, templateItem); + setItemSafe(10, baseItem); + setItemSafe(12, additionItem); + + set(new GUIItem(TRANSFORM_SLOT) { + @Override + public ItemStack getItem(BattlePlayer player) { + ItemStack table = new ItemStack(Material.SMITHING_TABLE); + ItemMeta meta = table.getItemMeta(); + if (meta != null) meta.setDisplayName("§7" + Caption.getAsLegacy("gui.smithing_name")); + table.setItemMeta(meta); + return table; + } + }); + } catch (Exception ignored) {} + } + centerAndPlaceGrid(grid); + } + + private void setSimpleProcess(ItemStack input, Material icon, String name) { + final ItemStack inputFinal = input; + set(new GUIItem(11) { + @Override + public ItemStack getItem(BattlePlayer player) { + return inputFinal != null ? inputFinal : ItemStackCreator.getStack(" ", Material.AIR, 1); + } + }); + set(new GUIItem(TRANSFORM_SLOT) { + @Override + public ItemStack getItem(BattlePlayer player) { + ItemStack item = new ItemStack(icon); + ItemMeta meta = item.getItemMeta(); + if (meta != null) meta.setDisplayName(name); + item.setItemMeta(meta); + return item; + } + }); + } + + private void setItemSafe(int slot, ItemStack stack) { + if (stack == null) return; + final ItemStack s = stack; + set(new GUIItem(GRID_SLOTS[Math.min(slot, GRID_SLOTS.length - 1)]) { + @Override + public ItemStack getItem(BattlePlayer player) { + return s; + } + }); + } + + private ItemStack getChoiceItem(RecipeChoice choice) { + return switch (choice) { + case RecipeChoice.MaterialChoice mat when !mat.getChoices().isEmpty() -> new ItemStack(mat.getChoices().getFirst()); + case RecipeChoice.ExactChoice exact when !exact.getChoices().isEmpty() -> exact.getChoices().getFirst().clone(); + case null, default -> null; + }; + } + + private void centerAndPlaceGrid(ItemStack[] grid) { int minRow = 3, maxRow = -1, minCol = 3, maxCol = -1; for (int i = 0; i < 9; i++) { if (grid[i] != null) { @@ -125,21 +205,14 @@ public ItemStack getItem(BattlePlayer player) { } } - int height = (maxRow - minRow + 1); - int width = (maxCol - minCol + 1); - int rowOffset = 0, colOffset = 0; - - if (height == 1) rowOffset = 1 - minRow; - if (width == 1) colOffset = 1 - minCol; - if (height == 1 && width == 1) { - rowOffset = 1 - minRow; - colOffset = 1 - minCol; - } + int usedWidth = (maxCol - minCol + 1); + int usedHeight = (maxRow - minRow + 1); + int rowOffset = (usedHeight < 3) ? (1 - (minRow + usedHeight / 2)) : 0; + int colOffset = (usedWidth < 3) ? (1 - (minCol + usedWidth / 2)) : 0; for (int i = 0; i < 9; i++) { ItemStack ingredient = grid[i]; if (ingredient == null) continue; - int row = i / 3 + rowOffset; int col = i % 3 + colOffset; if (row < 0 || row > 2 || col < 0 || col > 2) continue; diff --git a/src/main/java/net/fameless/forcebattle/gui/impl/SettingsGUI.java b/src/main/java/net/fameless/forcebattle/gui/impl/SettingsGUI.java index eb5bde3..7301b9a 100644 --- a/src/main/java/net/fameless/forcebattle/gui/impl/SettingsGUI.java +++ b/src/main/java/net/fameless/forcebattle/gui/impl/SettingsGUI.java @@ -11,7 +11,6 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.tag.Tag; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.event.inventory.InventoryClickEvent; @@ -84,9 +83,8 @@ public enum SettingButton { public ItemStack createItem() { if (lore != null && setting != null) { String state = SettingsManager.getState(setting).getDisplayName(SettingsManager.isMultiState(setting)); - Component componentLore = Caption.of(lore, TagResolver.resolver("state", Tag.inserting(Component.text(state)))); - String rawLore = LegacyComponentSerializer.legacySection().serialize(componentLore); + String rawLore = Caption.getAsLegacy(lore, TagResolver.resolver("state", Tag.inserting(Component.text(state)))); List loreLines = new ArrayList<>(List.of(rawLore.split("\n"))); return ItemStackCreator.getStack( diff --git a/src/main/java/net/fameless/forcebattle/gui/impl/TeamBackpackGUI.java b/src/main/java/net/fameless/forcebattle/gui/impl/TeamBackpackGUI.java index 83b8e9c..d77a9f8 100644 --- a/src/main/java/net/fameless/forcebattle/gui/impl/TeamBackpackGUI.java +++ b/src/main/java/net/fameless/forcebattle/gui/impl/TeamBackpackGUI.java @@ -1,16 +1,22 @@ package net.fameless.forcebattle.gui.impl; +import net.fameless.forcebattle.caption.Caption; import net.fameless.forcebattle.game.Team; import net.fameless.forcebattle.gui.ForceBattleGUI; import net.fameless.forcebattle.gui.GUIClickableItem; import net.fameless.forcebattle.player.BattlePlayer; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.tag.Tag; +import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; public class TeamBackpackGUI extends ForceBattleGUI { private final int index; + public TeamBackpackGUI(int index, int size) { - super("Team Backpack Page: " + (index + 1), size); + super(Caption.getAsLegacy("gui.team_backpack_title", + TagResolver.resolver("page", Tag.inserting(Component.text(String.valueOf(index + 1))))), size); this.index = index; } diff --git a/src/main/resources/languages/en_US.json b/src/main/resources/languages/en_US.json index 6c25579..2a3ded8 100644 --- a/src/main/resources/languages/en_US.json +++ b/src/main/resources/languages/en_US.json @@ -9,6 +9,12 @@ "gui.settings_title" : "Settings", "gui.reset_title" : "Reset", "gui.language_title" : "Choose a language", + "gui.backpack_title" : "'s Backpack", + "gui.team_backpack_title" : "Team Backpack | Page: ", + "gui.recipe_title" : "Recipe for | Page: ", + "gui.no_recipe_found" : "No recipe found", + "gui.stonecutting_name" : "Stonecutting", + "gui.smithing_name" : "Smithing", "gui.config_settings_title" : "Config Settings", "gui.force_item_name" : "Force Item", "gui.force_item_lore" : "
Click to toggle ForceItem.

Current Status: ", @@ -30,7 +36,6 @@ "gui.result_title_player" : "Results | ", "gui.result_title_team" : "Results | Team ", "gui.result_animated" : "Results", - "gui.backpack_title" : "'s Backpack", "gui.backpack_lore" : "
Click to toggle Backpacks.

Current Status: ", "gui.hide_points_name" : "Hide Points", "gui.hide_points_lore" : "
Click to toggle Hide Points.

Current Status: ", @@ -112,6 +117,7 @@ "command.player_not_in_a_team" : "This player is not part of your team.", "command.no_such_player" : "Player couldn't be found.", "command.no_such_team" : "Team couldn't be found.", + "command.no_such_material" : "Material couldn't be found.", "command.not_a_number" : "Please specify a valid number.", "command.negative_number" : "Number must be positive.", "command.usage" : "Usage: .",