ComponentPreset inventory to json

This commit is contained in:
dordsor21 2020-08-07 13:22:10 +01:00
parent 6012705e95
commit 7f29b5d1e8
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
3 changed files with 14 additions and 12 deletions

View File

@ -96,7 +96,7 @@ import java.util.stream.IntStream;
} }
List<String> lore = new ArrayList<>(); List<String> lore = new ArrayList<>();
for (String entry : item.lore) { 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); meta.setLore(lore);
} }

View File

@ -29,7 +29,6 @@ import com.google.inject.Inject;
import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.backup.BackupManager; import com.plotsquared.core.backup.BackupManager;
import com.plotsquared.core.command.MainCommand; import com.plotsquared.core.command.MainCommand;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.configuration.file.YamlConfiguration; import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.configuration.serialization.ConfigurationSerialization; 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.plotsquared.core.util.Permissions;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.item.ItemTypes;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.Template; import net.kyori.adventure.text.minimessage.Template;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -62,6 +62,7 @@ import java.util.stream.Collectors;
public class ComponentPresetManager { public class ComponentPresetManager {
private static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build();
private static final Logger logger = LoggerFactory.getLogger("P2/" + ComponentPresetManager.class.getSimpleName()); private static final Logger logger = LoggerFactory.getLogger("P2/" + ComponentPresetManager.class.getSimpleName());
private final List<ComponentPreset> presets; private final List<ComponentPreset> presets;
@ -131,7 +132,7 @@ public class ComponentPresetManager {
* *
* @return Build inventory, if it could be created * @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(); final Plot plot = player.getCurrentPlot();
if (plot == null) { if (plot == null) {
@ -207,19 +208,20 @@ public class ComponentPresetManager {
for (int i = 0; i < allowedPresets.size(); i++) { for (int i = 0; i < allowedPresets.size(); i++) {
final ComponentPreset preset = allowedPresets.get(i); final ComponentPreset preset = allowedPresets.get(i);
final List<String> lore = new ArrayList<>(); final List<String> lore = new ArrayList<>();
if (preset.getCost() > 0 && this.econHandler != null && plot.getArea().useEconomy()){ if (preset.getCost() > 0 && this.econHandler != null && plot.getArea().useEconomy()) {
lore.add(Captions.PRESET_LORE_COST.getTranslated().replace("%cost%", lore.add(MINI_MESSAGE.serialize(MINI_MESSAGE.parse(TranslatableCaption.of("preset.preset_lore_cost").getComponent(player),
String.format("%.2f", preset.getCost()))); Template.of("cost", String.format("%.2f", preset.getCost())))));
} }
lore.add(Captions.PRESET_LORE_COMPONENT.getTranslated().replace("%component%", lore.add(MINI_MESSAGE.serialize(MINI_MESSAGE.parse(TranslatableCaption.of("preset.preset_lore_component").getComponent(player),
preset.getComponent().name().toLowerCase())); Template.of("component", preset.getComponent().name().toLowerCase()))));
lore.removeIf(String::isEmpty); lore.removeIf(String::isEmpty);
if (!lore.isEmpty()) { if (!lore.isEmpty()) {
lore.add("&6"); lore.add("<gold>");
} }
lore.addAll(preset.getDescription()); lore.addAll(preset.getDescription());
plotInventory.setItem(i, new PlotItemStack(preset.getIcon().getId().replace("minecraft:", ""), lore.add("</gold>");
1, preset.getDisplayName(), lore.toArray(new String[0]))); plotInventory.setItem(i,
new PlotItemStack(preset.getIcon().getId().replace("minecraft:", ""), 1, preset.getDisplayName(), lore.toArray(new String[0])));
} }
return plotInventory; return plotInventory;

View File

@ -477,7 +477,7 @@
"preset.preset_cannot_afford": "<prefix><red>You cannot afford that preset.</red>", "preset.preset_cannot_afford": "<prefix><red>You cannot afford that preset.</red>",
"preset.preset_invalid": "<prefix><red>Could not generate a pattern from that preset.</red>", "preset.preset_invalid": "<prefix><red>Could not generate a pattern from that preset.</red>",
"preset.preset_lore_cost": "<prefix><gray>Cost: </gray><gold><cost></gold>", "preset.preset_lore_cost": "<prefix><gray>Cost: </gray><gold><cost></gold>",
"preset-preset_lore_component": "<prefix><gray>Component: </gray><gold><component></gold>", "preset.preset_lore_component": "<prefix><gray>Component: </gray><gold><component></gold>",
"generic.generic_other": "<prefix><gray>other</gray>", "generic.generic_other": "<prefix><gray>other</gray>",
"generic.generic_merged": "<prefix><gray>merged</gray>", "generic.generic_merged": "<prefix><gray>merged</gray>",