/* * This file is a part of the SteamWar software. * * Copyright (C) 2026 SteamWar.de-Serverteam * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ package de.steamwar.lobby.particle.gui; import de.steamwar.lobby.LobbySystem; import de.steamwar.lobby.particle.ParticleRequirement; import de.steamwar.lobby.particle.UnlockContext; import de.steamwar.lobby.particle.design.*; import de.steamwar.lobby.particle.slot.ParticleEntry; import de.steamwar.lobby.particle.slot.ParticleSlot; import de.steamwar.lobby.particle.slot.ParticleSlots; import de.steamwar.sql.SteamwarUser; import lombok.experimental.UtilityClass; import org.bukkit.entity.Player; import java.awt.Color; import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.MissingResourceException; import static de.steamwar.lobby.particle.design.EntryParameters.*; @UtilityClass class ParticleGuiText { String msg(String key, Player player, Object... params) { return LobbySystem.getMessage().parse(key, player, params); } // Falls back to a readable form of the key for names without a translation String name(String key, Player player) { try { return LobbySystem.getMessage().parse(key, player); } catch (MissingResourceException e) { return "§f" + prettify(key.replaceFirst("^PARTICLE_(TYPE_|DESIGN_|PARAM_)?", "")); } } String prettify(String id) { StringBuilder builder = new StringBuilder(); for (String word : id.toLowerCase(Locale.ROOT).split("_")) { if (word.isEmpty()) continue; if (!builder.isEmpty()) builder.append(' '); builder.append(Character.toUpperCase(word.charAt(0))).append(word.substring(1)); } return builder.toString(); } String designName(ParticleDesign design, Player player) { return name(design.getNameKey(), player); } String particleName(ParticleType type, Player player) { return name(type.getNameKey(), player); } String choiceName(ChoiceParameter parameter, E value, Player player) { for (ChoiceParameter.Choice choice : parameter.getChoices()) { if (choice.value() != value) continue; if (value instanceof ParticleType type) return particleName(type, player); return name("PARTICLE_CHOICE_" + parameter.getKey().toUpperCase(Locale.ROOT) + "_" + choice.id().toUpperCase(Locale.ROOT), player); } return String.valueOf(value); } String number(double value) { return value == Math.rint(value) ? String.valueOf((long) value) : String.format(Locale.ROOT, "%.2f", value).replaceAll("0+$", ""); } @SuppressWarnings("unchecked") String valueText(Parameter parameter, Object value, Player player) { if (parameter instanceof DoubleParameter) return "§e" + number((Double) value); if (parameter instanceof IntParameter) return "§e" + value; if (parameter instanceof BooleanParameter) return msg((Boolean) value ? "PARTICLE_VALUE_YES" : "PARTICLE_VALUE_NO", player); if (parameter instanceof ChoiceParameter choice) return choiceName((ChoiceParameter) choice, value, player); if (parameter instanceof GradientParameter) { List colors = (List) value; if (colors.isEmpty()) return msg("PARTICLE_VALUE_RANDOM", player); StringBuilder builder = new StringBuilder(); colors.forEach(color -> builder.append(net.md_5.bungee.api.ChatColor.of(color)).append('█')); return builder.toString(); } return String.valueOf(value); } // Requirement lines for an item's lore, empty when there is no requirement List requirement(ParticleRequirement requirement, Player player) { List lore = new ArrayList<>(); String name = requirement.getRequirementName(player); if (name != null) { lore.add(msg("PARTICLE_UNLOCKED_BY", player)); lore.add(name); } return lore; } // Short description of an entry: design, particle and the conditions that are set List entrySummary(ParticleEntry entry, UnlockContext context, Player player) { List lore = new ArrayList<>(); ParameterValues values = entry.getValues(); lore.add(msg("PARTICLE_ENTRY_DESIGN", player, designName(entry.getDesign(), player))); if (entry.getDesign().usesEntryParticle()) { lore.add(msg("PARTICLE_ENTRY_PARTICLE", player, particleName(values.get(PARTICLE), player))); } lore.add("§8- " + choiceName(TICK_MODE, values.get(TICK_MODE), player)); addCondition(lore, MOVEMENT, values.get(MOVEMENT), Movement.ANY, player); addCondition(lore, GLIDING, values.get(GLIDING), Gliding.ANY, player); addCondition(lore, GROUND, values.get(GROUND), Ground.ANY, player); addCondition(lore, SNEAK, values.get(SNEAK), Sneak.ANY, player); addCondition(lore, VISIBILITY, values.get(VISIBILITY), Visibility.EVERYONE, player); if (!entry.getDesign().getRequirement().test(context)) { lore.add(msg("PARTICLE_ENTRY_LOCKED", player)); } return lore; } private void addCondition(List lore, ChoiceParameter parameter, E value, E none, Player player) { if (value != none) { lore.add("§8- " + choiceName(parameter, value, player)); } } // The slot's name followed by how many of its allowed particles per tick it uses String slotName(ParticleSlot slot, SteamwarUser user, Player player) { return msg("PARTICLE_SLOT_NAME", player, slot.getName(), number(slot.cost()), number(ParticleSlots.maxCost(user))); } String slotTitle(ParticleSlot slot, SteamwarUser user, Player player) { return msg("PARTICLE_SLOT_TITLE", player, slot.getName(), number(slot.cost()), number(ParticleSlots.maxCost(user))); } List slotSummary(ParticleSlot slot, Player player) { List lore = new ArrayList<>(); lore.add(msg("PARTICLE_SLOT_ENTRIES", player, slot.getEntries().size())); for (ParticleEntry entry : slot.getEntries()) { String particle = entry.getDesign().usesEntryParticle() ? " §8(" + particleName(entry.getValues().get(PARTICLE), player) + "§8)" : ""; lore.add("§8- " + designName(entry.getDesign(), player) + particle); } return lore; } }