From 2cfbc35405232f3c271884d75c006cfae22d330c Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Wed, 9 Feb 2022 12:53:01 +0100 Subject: [PATCH] feat: Don't enable presets with prices if economy is disabled --- .../components/ComponentPresetManager.java | 25 +++++++++++++------ Core/src/main/resources/lang/messages_en.json | 4 ++- 2 files changed, 21 insertions(+), 8 deletions(-) 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 0b514996f..1ef349572 100644 --- a/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java +++ b/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java @@ -128,7 +128,7 @@ public class ComponentPresetManager { 0, "", "Disco Floor", - Arrays.asList("Spice up your plot floor"), + List.of("Spice up your plot floor"), ItemTypes.YELLOW_WOOL )); yamlConfiguration.set("presets", defaultPreset.stream().map(ComponentPreset::serialize).collect(Collectors.toList())); @@ -210,7 +210,13 @@ public class ComponentPresetManager { return false; } - if (componentPreset.getCost() > 0.0D && econHandler.isEnabled(plot.getArea())) { + if (componentPreset.getCost() > 0.0D) { + if (!econHandler.isEnabled(plot.getArea())) { + getPlayer().sendMessage( + TranslatableCaption.of("preset.economy_disabled"), + Template.of("preset", componentPreset.getDisplayName())); + return false; + } if (econHandler.getMoney(getPlayer()) < componentPreset.getCost()) { getPlayer().sendMessage(TranslatableCaption.of("preset.preset_cannot_afford")); return false; @@ -246,11 +252,16 @@ 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.isEnabled(plot.getArea())) { - lore.add(MINI_MESSAGE.serialize(MINI_MESSAGE.parse( - TranslatableCaption.of("preset.preset_lore_cost").getComponent(player), - Template.of("cost", String.format("%.2f", preset.getCost())) - ))); + if (preset.getCost() > 0) { + if (!this.econHandler.isEnabled(plot.getArea())) { + lore.add(MINI_MESSAGE.serialize(MINI_MESSAGE.parse( + TranslatableCaption.of("preset.preset_lore_economy_disabled").getComponent(player)))); + } else { + 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(MINI_MESSAGE.serialize(MINI_MESSAGE.parse( TranslatableCaption.of("preset.preset_lore_component").getComponent(player), diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index 6ca0e0229..1dc9a7a95 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -460,9 +460,11 @@ "backups.backup_automatic_failure": "The automatic backup process failed. Your pending action has been canceled. Reason: ", "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_cost": "Cost: ", + "preset.preset_lore_economy_disabled": "Cost: Economy is disabled", "preset.preset_lore_component": "Component: ", "preset.title": "Plot Components", + "preset.economy_disabled": "The component preset '' has a price set but economy is disabled.", "generic.generic_other": "other", "generic.generic_merged": "merged", "generic.generic_unowned": "unowned",