From 7f29b5d1e87fa5a418c6ec7804911b207eb78c47 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Fri, 7 Aug 2020 13:22:10 +0100 Subject: [PATCH] ComponentPreset inventory to json --- .../bukkit/util/BukkitInventoryUtil.java | 2 +- .../components/ComponentPresetManager.java | 22 ++++++++++--------- Core/src/main/resources/lang/messages_en.json | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitInventoryUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitInventoryUtil.java index ea16fa873..46edc15d9 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitInventoryUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitInventoryUtil.java @@ -96,7 +96,7 @@ import java.util.stream.IntStream; } List lore = new ArrayList<>(); for (String entry : item.lore) { - lore.add(ChatColor.translateAlternateColorCodes('&', entry)); + lore.add(BukkitUtil.LEGACY_COMPONENT_SERIALIZER.serialize(BukkitUtil.MINI_MESSAGE.deserialize(entry))); } meta.setLore(lore); } diff --git a/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java b/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java index 9aabca729..80e894322 100644 --- a/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java +++ b/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java @@ -29,7 +29,6 @@ import com.google.inject.Inject; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.backup.BackupManager; import com.plotsquared.core.command.MainCommand; -import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.configuration.file.YamlConfiguration; import com.plotsquared.core.configuration.serialization.ConfigurationSerialization; @@ -44,6 +43,7 @@ import com.plotsquared.core.util.PatternUtil; import com.plotsquared.core.util.Permissions; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.item.ItemTypes; +import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.Template; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -62,6 +62,7 @@ import java.util.stream.Collectors; public class ComponentPresetManager { + private static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build(); private static final Logger logger = LoggerFactory.getLogger("P2/" + ComponentPresetManager.class.getSimpleName()); private final List presets; @@ -131,7 +132,7 @@ public class ComponentPresetManager { * * @return Build inventory, if it could be created */ - @Nullable public PlotInventory buildInventory(final PlotPlayer player) { + @Nullable public PlotInventory buildInventory(final PlotPlayer player) { final Plot plot = player.getCurrentPlot(); if (plot == null) { @@ -207,19 +208,20 @@ public class ComponentPresetManager { for (int i = 0; i < allowedPresets.size(); i++) { final ComponentPreset preset = allowedPresets.get(i); final List lore = new ArrayList<>(); - if (preset.getCost() > 0 && this.econHandler != null && plot.getArea().useEconomy()){ - lore.add(Captions.PRESET_LORE_COST.getTranslated().replace("%cost%", - String.format("%.2f", preset.getCost()))); + if (preset.getCost() > 0 && this.econHandler != null && plot.getArea().useEconomy()) { + lore.add(MINI_MESSAGE.serialize(MINI_MESSAGE.parse(TranslatableCaption.of("preset.preset_lore_cost").getComponent(player), + Template.of("cost", String.format("%.2f", preset.getCost()))))); } - lore.add(Captions.PRESET_LORE_COMPONENT.getTranslated().replace("%component%", - preset.getComponent().name().toLowerCase())); + lore.add(MINI_MESSAGE.serialize(MINI_MESSAGE.parse(TranslatableCaption.of("preset.preset_lore_component").getComponent(player), + Template.of("component", preset.getComponent().name().toLowerCase())))); lore.removeIf(String::isEmpty); if (!lore.isEmpty()) { - lore.add("&6"); + lore.add(""); } lore.addAll(preset.getDescription()); - plotInventory.setItem(i, new PlotItemStack(preset.getIcon().getId().replace("minecraft:", ""), - 1, preset.getDisplayName(), lore.toArray(new String[0]))); + lore.add(""); + plotInventory.setItem(i, + new PlotItemStack(preset.getIcon().getId().replace("minecraft:", ""), 1, preset.getDisplayName(), lore.toArray(new String[0]))); } return plotInventory; diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index f161e179f..d45552776 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -477,7 +477,7 @@ "preset.preset_cannot_afford": "You cannot afford that preset.", "preset.preset_invalid": "Could not generate a pattern from that preset.", "preset.preset_lore_cost": "Cost: ", - "preset-preset_lore_component": "Component: ", + "preset.preset_lore_component": "Component: ", "generic.generic_other": "other", "generic.generic_merged": "merged",