From e25650a400a4bca94d16f451a1395e991e8721a9 Mon Sep 17 00:00:00 2001 From: zrdzn Date: Wed, 27 Apr 2022 16:16:32 +0200 Subject: [PATCH] Do not parse filler if it is disabled --- .../minecraft/lovelydrop/menu/MenuFiller.java | 8 +----- .../minecraft/lovelydrop/menu/MenuParser.java | 26 +++++++++++-------- .../lovelydrop/menu/MenuService.java | 2 +- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/plugin/src/main/java/io/github/zrdzn/minecraft/lovelydrop/menu/MenuFiller.java b/plugin/src/main/java/io/github/zrdzn/minecraft/lovelydrop/menu/MenuFiller.java index b0c9ebe..fab19cd 100644 --- a/plugin/src/main/java/io/github/zrdzn/minecraft/lovelydrop/menu/MenuFiller.java +++ b/plugin/src/main/java/io/github/zrdzn/minecraft/lovelydrop/menu/MenuFiller.java @@ -19,20 +19,14 @@ public class MenuFiller { - private final boolean enabled; private final Material type; private final String displayName; - public MenuFiller(boolean enabled, Material type, String displayName) { - this.enabled = enabled; + public MenuFiller(Material type, String displayName) { this.type = type; this.displayName = displayName; } - public boolean isEnabled() { - return this.enabled; - } - public Material getType() { return this.type; } diff --git a/plugin/src/main/java/io/github/zrdzn/minecraft/lovelydrop/menu/MenuParser.java b/plugin/src/main/java/io/github/zrdzn/minecraft/lovelydrop/menu/MenuParser.java index 3147de8..bbb57c6 100644 --- a/plugin/src/main/java/io/github/zrdzn/minecraft/lovelydrop/menu/MenuParser.java +++ b/plugin/src/main/java/io/github/zrdzn/minecraft/lovelydrop/menu/MenuParser.java @@ -24,6 +24,7 @@ import java.util.AbstractMap; import java.util.List; import java.util.Map.Entry; +import java.util.Optional; import java.util.logging.Logger; public class MenuParser { @@ -52,21 +53,24 @@ public Menu parse(ConfigurationSection section) throws InvalidConfigurationExcep throw new InvalidConfigurationException("Key 'rows' cannot be 0 and lower"); } + MenuFiller filler = null; + boolean fillerEnabled = section.getBoolean("filler.enabled", false); + if (fillerEnabled) { + String fillerTypeRaw = section.getString("filler.type"); + if (fillerTypeRaw == null) { + throw new InvalidConfigurationException("Key 'filler.type' is null."); + } - String fillerTypeRaw = section.getString("filler.type"); - if (fillerTypeRaw == null) { - throw new InvalidConfigurationException("Key 'filler.type' is null."); - } + Material fillerType = Material.matchMaterial(fillerTypeRaw); + if (fillerType == null) { + throw new InvalidConfigurationException("Material with key 'filler.type' does not exist."); + } - Material fillerType = Material.matchMaterial(fillerTypeRaw); - if (fillerType == null) { - throw new InvalidConfigurationException("Material with key 'filler.type' does not exist."); - } + String fillerName = LovelyDropPlugin.color(section.getString("filler.displayname", "none")); - String fillerName = LovelyDropPlugin.color(section.getString("filler.displayname", "none")); - - MenuFiller filler = new MenuFiller(fillerEnabled, fillerType, fillerName); + filler = new MenuFiller(fillerType, fillerName); + } String dropSwitchEnabled = LovelyDropPlugin.color(section.getString("drop-switch.enabled", "&aon")); String dropSwitchDisabled = LovelyDropPlugin.color(section.getString("drop-switch.disabled", "&coff")); diff --git a/plugin/src/main/java/io/github/zrdzn/minecraft/lovelydrop/menu/MenuService.java b/plugin/src/main/java/io/github/zrdzn/minecraft/lovelydrop/menu/MenuService.java index b84e6e4..374ec76 100644 --- a/plugin/src/main/java/io/github/zrdzn/minecraft/lovelydrop/menu/MenuService.java +++ b/plugin/src/main/java/io/github/zrdzn/minecraft/lovelydrop/menu/MenuService.java @@ -196,7 +196,7 @@ public boolean open(Player player) { // Fill the rest inventory with the specified item if enabled. MenuFiller filler = this.menu.getFiller(); - if (filler.isEnabled()) { + if (filler != null) { ItemStack fillerItem = new ItemStack(filler.getType()); ItemMeta fillerMeta = fillerItem.getItemMeta(); if (filler.getDisplayName().equalsIgnoreCase("none")) {