From d2ad83e2182c9e6e436b17ca7daba38b00046f38 Mon Sep 17 00:00:00 2001 From: Roch Blonndiaux Date: Wed, 7 Dec 2022 16:05:54 +0100 Subject: [PATCH] Stations name update --- .../api/crafting/CraftingStation.java | 288 +++++++++--------- 1 file changed, 146 insertions(+), 142 deletions(-) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/CraftingStation.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/CraftingStation.java index 2cd1b1ad..9160c223 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/CraftingStation.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/CraftingStation.java @@ -20,175 +20,179 @@ import java.util.*; import java.util.logging.Level; public class CraftingStation extends PostLoadObject { - private final String id, name; - private final Layout layout; - private final Sound sound; - private final StationItemOptions itemOptions; - private final int maxQueueSize; + private final String id; + private final String name; + private final String unparsedName; + private final Layout layout; + private final Sound sound; + private final StationItemOptions itemOptions; + private final int maxQueueSize; - /** - * This is not all the recipes of that crafting station. It only - * contains the recipes that are specific to that station, relative - * to the position of that station in the station inheritance tree. - *

- * In other words that map doesn't contain the crafting recipes of - * the parent crafting station saved in {@link #parent} - */ - private final Map recipes = new LinkedHashMap<>(); + /** + * This is not all the recipes of that crafting station. It only + * contains the recipes that are specific to that station, relative + * to the position of that station in the station inheritance tree. + *

+ * In other words that map doesn't contain the crafting recipes of + * the parent crafting station saved in {@link #parent} + */ + private final Map recipes = new LinkedHashMap<>(); - private CraftingStation parent; + private CraftingStation parent; - public CraftingStation(String id, FileConfiguration config) { - super(config); + public CraftingStation(String id, FileConfiguration config) { + super(config); - this.id = id.toLowerCase().replace("_", "-").replace(" ", "-"); - this.name = config.getString("name", "Unnamed"); - this.layout = MMOItems.plugin.getLayouts().getLayout(config.getString("layout", "default")); - this.sound = Sound.valueOf(config.getString("sound", "ENTITY_EXPERIENCE_ORB_PICKUP").toUpperCase()); + this.id = id.toLowerCase().replace("_", "-").replace(" ", "-"); + this.unparsedName = config.getString("name", "Unnamed"); + this.name = MythicLib.plugin.parseColors(unparsedName); + this.layout = MMOItems.plugin.getLayouts().getLayout(config.getString("layout", "default")); + this.sound = Sound.valueOf(config.getString("sound", "ENTITY_EXPERIENCE_ORB_PICKUP").toUpperCase()); - for (String key : config.getConfigurationSection("recipes").getKeys(false)) - try { - registerRecipe(loadRecipe(config.getConfigurationSection("recipes." + key))); - } catch (IllegalArgumentException exception) { - MMOItems.plugin.getLogger().log(Level.INFO, - "An issue occurred registering recipe '" + key + "' from crafting station '" + id + "': " + exception.getMessage()); - } + for (String key : config.getConfigurationSection("recipes").getKeys(false)) + try { + registerRecipe(loadRecipe(config.getConfigurationSection("recipes." + key))); + } catch (IllegalArgumentException exception) { + MMOItems.plugin.getLogger().log(Level.INFO, + "An issue occurred registering recipe '" + key + "' from crafting station '" + id + "': " + exception.getMessage()); + } - itemOptions = new StationItemOptions(config.getConfigurationSection("items")); - maxQueueSize = Math.max(1, Math.min(config.getInt("max-queue-size"), 64)); - } + itemOptions = new StationItemOptions(config.getConfigurationSection("items")); + maxQueueSize = Math.max(1, Math.min(config.getInt("max-queue-size"), 64)); + } - public CraftingStation(String id, String name, Layout layout, Sound sound, StationItemOptions itemOptions, int maxQueueSize, CraftingStation parent) { - super(null); + public CraftingStation(String id, String name, Layout layout, Sound sound, StationItemOptions itemOptions, int maxQueueSize, CraftingStation parent) { + super(null); - Validate.notNull(id, "Crafting station ID must not be null"); - Validate.notNull(name, "Crafting station name must not be null"); - Validate.notNull(sound, "Crafting station sound must not be null"); + Validate.notNull(id, "Crafting station ID must not be null"); + Validate.notNull(name, "Crafting station name must not be null"); + Validate.notNull(sound, "Crafting station sound must not be null"); - this.id = id.toLowerCase().replace("_", "-").replace(" ", "-"); - this.name = name; - this.layout = layout; - this.sound = sound; - this.itemOptions = itemOptions; - this.maxQueueSize = maxQueueSize; - this.parent = parent; - } + this.id = id.toLowerCase().replace("_", "-").replace(" ", "-"); + this.unparsedName = name; + this.name = MythicLib.plugin.parseColors(name); + this.layout = layout; + this.sound = sound; + this.itemOptions = itemOptions; + this.maxQueueSize = maxQueueSize; + this.parent = parent; + } - public String getId() { - return id; - } + public String getId() { + return id; + } - @Deprecated - public String getName() { - return MythicLib.plugin.parseColors(name); - } + @Deprecated + public String getName() { + return name; + } - public String getUnformattedName() { - return name; - } + public String getUnparsedName() { + return unparsedName; + } - public Layout getLayout() { - return layout; - } + public Layout getLayout() { + return layout; + } - public Sound getSound() { - return sound; - } + public Sound getSound() { + return sound; + } - @Nullable - public CraftingStation getParent() { - return parent; - } + @Nullable + public CraftingStation getParent() { + return parent; + } - /** - * @return Recursively collects all recipes from that station and from - * its parent station. - */ - public Collection getRecipes() { - if (parent == null) - return recipes.values(); + /** + * @return Recursively collects all recipes from that station and from + * its parent station. + */ + public Collection getRecipes() { + if (parent == null) + return recipes.values(); - // Collect recipes from station inheritance tree - List collected = new ArrayList<>(recipes.values()); - CraftingStation next = parent; - while (next != null) { - collected.addAll(next.recipes.values()); - next = next.parent; - } + // Collect recipes from station inheritance tree + List collected = new ArrayList<>(recipes.values()); + CraftingStation next = parent; + while (next != null) { + collected.addAll(next.recipes.values()); + next = next.parent; + } - return collected; - } + return collected; + } - /** - * @param id Recipe identifier - * @return Recursively checks if that station has the provided recipe. - */ - public boolean hasRecipe(String id) { - return recipes.containsKey(id) || (parent != null && parent.hasRecipe(id)); - } + /** + * @param id Recipe identifier + * @return Recursively checks if that station has the provided recipe. + */ + public boolean hasRecipe(String id) { + return recipes.containsKey(id) || (parent != null && parent.hasRecipe(id)); + } - /** - * @param id Recipe identifier - * @return Recursively finds the corresponding recipe - */ - public Recipe getRecipe(String id) { - Recipe found = recipes.get(id); - return found == null && parent != null ? parent.getRecipe(id) : found; - } + /** + * @param id Recipe identifier + * @return Recursively finds the corresponding recipe + */ + public Recipe getRecipe(String id) { + Recipe found = recipes.get(id); + return found == null && parent != null ? parent.getRecipe(id) : found; + } - public int getMaxQueueSize() { - return maxQueueSize; - } + public int getMaxQueueSize() { + return maxQueueSize; + } - public List getAvailableRecipes(PlayerData data, IngredientInventory inv) { - List infos = new ArrayList<>(); + public List getAvailableRecipes(PlayerData data, IngredientInventory inv) { + List infos = new ArrayList<>(); - for (Recipe recipe : getRecipes()) { - CheckedRecipe info = recipe.evaluateRecipe(data, inv); - if ((info.areConditionsMet() || !info.getRecipe().hasOption(RecipeOption.HIDE_WHEN_LOCKED)) - && (info.allIngredientsHad() || !info.getRecipe().hasOption(RecipeOption.HIDE_WHEN_NO_INGREDIENTS))) - infos.add(info); - } + for (Recipe recipe : getRecipes()) { + CheckedRecipe info = recipe.evaluateRecipe(data, inv); + if ((info.areConditionsMet() || !info.getRecipe().hasOption(RecipeOption.HIDE_WHEN_LOCKED)) + && (info.allIngredientsHad() || !info.getRecipe().hasOption(RecipeOption.HIDE_WHEN_NO_INGREDIENTS))) + infos.add(info); + } - return infos; - } + return infos; + } - public StationItemOptions getItemOptions() { - return itemOptions; - } + public StationItemOptions getItemOptions() { + return itemOptions; + } - /** - * Keep in mind this method also has the effect of register a recipe - * inside any crafting station that has the current station as child. - * - * @param recipe Recipe being registered - * @see {@link #hasRecipe(String)} - */ - public void registerRecipe(Recipe recipe) { - recipes.put(recipe.getId(), recipe); - } + /** + * Keep in mind this method also has the effect of register a recipe + * inside any crafting station that has the current station as child. + * + * @param recipe Recipe being registered + * @see {@link #hasRecipe(String)} + */ + public void registerRecipe(Recipe recipe) { + recipes.put(recipe.getId(), recipe); + } - public int getMaxPage() { - int recipes = getRecipes().size(); - return Math.max(1, (int) Math.ceil((double) recipes / getLayout().getRecipeSlots().size())); - } + public int getMaxPage() { + int recipes = getRecipes().size(); + return Math.max(1, (int) Math.ceil((double) recipes / getLayout().getRecipeSlots().size())); + } - @Override - protected void whenPostLoaded(ConfigurationSection config) { - if (config.contains("parent")) { - String id = config.getString("parent").toLowerCase().replace(" ", "-").replace("_", "-"); - Validate.isTrue(!id.equals(this.id), "Station cannot use itself as parent"); - Validate.isTrue(MMOItems.plugin.getCrafting().hasStation(id), "Could not find parent station with ID '" + id + "'"); - parent = MMOItems.plugin.getCrafting().getStation(id); - } - } + @Override + protected void whenPostLoaded(ConfigurationSection config) { + if (config.contains("parent")) { + String id = config.getString("parent").toLowerCase().replace(" ", "-").replace("_", "-"); + Validate.isTrue(!id.equals(this.id), "Station cannot use itself as parent"); + Validate.isTrue(MMOItems.plugin.getCrafting().hasStation(id), "Could not find parent station with ID '" + id + "'"); + parent = MMOItems.plugin.getCrafting().getStation(id); + } + } - /* - * find type of crafting recipe based on section. there is no 'type' recipe - * parameter because old files would be out of date, instead just looks for - * a parameter of the crafting recipe which is 'output' - */ - private Recipe loadRecipe(ConfigurationSection config) throws IllegalArgumentException { - return config.contains("output") ? new CraftingRecipe(config) : new UpgradingRecipe(config); - } + /* + * find type of crafting recipe based on section. there is no 'type' recipe + * parameter because old files would be out of date, instead just looks for + * a parameter of the crafting recipe which is 'output' + */ + private Recipe loadRecipe(ConfigurationSection config) throws IllegalArgumentException { + return config.contains("output") ? new CraftingRecipe(config) : new UpgradingRecipe(config); + } }