Skip to content

Commit

Permalink
Do not parse filler if it is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
zrdzn committed Apr 27, 2022
1 parent 52b0e6c commit e25650a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down

0 comments on commit e25650a

Please sign in to comment.