Skip to content
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 @@ -31,7 +31,10 @@
caller.sendMessage(Caption.of("error.backpacks_disabled"));
return;
}
if (GameListener.startPhase) return;
if (GameListener.startPhase) {
caller.sendMessage(Caption.of("error.game_not_started"));
return;
};

Check warning on line 37 in src/main/java/net/fameless/forcebattle/command/BackpackCommand.java

View check run for this annotation

codefactor.io / CodeFactor

src/main/java/net/fameless/forcebattle/command/BackpackCommand.java#L37

Empty statement. (com.puppycrawl.tools.checkstyle.checks.coding.EmptyStatementCheck)

Optional<BattlePlayer> senderOpt = BattlePlayer.adapt(caller.getName());

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -30,15 +31,15 @@ public void executeCommand(@NotNull CommandCaller caller, String[] args) {
if (!(caller instanceof BattlePlayer player)) return;

if (args.length == 0) {
player.getPlayer().sendMessage("§cUsage: /item <item>");
sendUsage(caller);
return;
}

String input = args[0].toUpperCase();
Material material = Material.matchMaterial(input);

if (material == null) {
player.getPlayer().sendMessage("§cInvalid item: " + args[0]);
caller.sendMessage(Caption.of("command.no_such_material"));
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> loreLines = new ArrayList<>(List.of(rawLore.split("\n")));

return ItemStackCreator.getStack(
Expand Down
129 changes: 101 additions & 28 deletions src/main/java/net/fameless/forcebattle/gui/impl/CraftingRecipeGUI.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
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;
import net.fameless.forcebattle.player.BattlePlayer;
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.*;
Expand All @@ -21,13 +25,16 @@ public class CraftingRecipeGUI extends ForceBattleGUI {
private final List<Recipe> 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;
Expand Down Expand Up @@ -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()) {
Expand All @@ -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;
}
Expand All @@ -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<RecipeChoice> 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) {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> loreLines = new ArrayList<>(List.of(rawLore.split("\n")));

return ItemStackCreator.getStack(
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

Expand Down
8 changes: 7 additions & 1 deletion src/main/resources/languages/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
"gui.settings_title" : "Settings",
"gui.reset_title" : "Reset",
"gui.language_title" : "Choose a language",
"gui.backpack_title" : "<player>'s Backpack",
"gui.team_backpack_title" : "Team Backpack | Page: <page>",
"gui.recipe_title" : "Recipe for <material> | Page: <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" : "<blue>Force Item",
"gui.force_item_lore" : " <br><gray>Click to toggle ForceItem.<br><br><blue>Current Status<dark_gray>: <state>",
Expand All @@ -30,7 +36,6 @@
"gui.result_title_player" : "Results | <player-name>",
"gui.result_title_team" : "Results | Team <team-id>",
"gui.result_animated" : "Results",
"gui.backpack_title" : "<player>'s Backpack",
"gui.backpack_lore" : " <br><gray>Click to toggle Backpacks.<br><br><blue>Current Status<dark_gray>: <state>",
"gui.hide_points_name" : "<blue>Hide Points",
"gui.hide_points_lore" : " <br><gray>Click to toggle Hide Points.<br><br><blue>Current Status<dark_gray>: <state>",
Expand Down Expand Up @@ -112,6 +117,7 @@
"command.player_not_in_a_team" : "<prefix><red>This player is not part of your team.",
"command.no_such_player" : "<prefix><red>Player couldn't be found.",
"command.no_such_team" : "<prefix><red>Team couldn't be found.",
"command.no_such_material" : "<prefix><red>Material couldn't be found.",
"command.not_a_number" : "<prefix><red>Please specify a valid number.",
"command.negative_number" : "<prefix><red>Number must be positive.",
"command.usage" : "<prefix><red>Usage: <usage>.",
Expand Down
Loading