diff --git a/src/main/java/world/bentobox/bentobox/api/flags/Flag.java b/src/main/java/world/bentobox/bentobox/api/flags/Flag.java index ca9c0a3b2..6d40f889c 100644 --- a/src/main/java/world/bentobox/bentobox/api/flags/Flag.java +++ b/src/main/java/world/bentobox/bentobox/api/flags/Flag.java @@ -151,6 +151,8 @@ public class Flag implements Comparable { private final Mode mode; private final Set subflags; private final HideWhen hideWhen; + private boolean isSubFlag; + private Flag parentFlag; private Flag(Builder builder) { this.id = builder.id; @@ -169,6 +171,8 @@ public class Flag implements Comparable { this.mode = builder.mode; this.subflags = builder.subflags; this.hideWhen = builder.hideWhen; + this.isSubFlag = false; + this.parentFlag = null; } public String getID() { @@ -305,6 +309,20 @@ public class Flag implements Comparable { return hideWhen; } + /** + * @return the isSubFlag + */ + public boolean isSubFlag() { + return isSubFlag; + } + + /** + * @return the parentFlag + */ + public Flag getParentFlag() { + return parentFlag; + } + /* (non-Javadoc) * @see java.lang.Object#hashCode() */ @@ -711,6 +729,9 @@ public class Flag implements Comparable { */ public Builder subflags(Flag... flags) { this.subflags.addAll(Arrays.asList(flags)); + for (Flag flag : flags) { + flag.isSubFlag = true; + } return this; } @@ -739,9 +760,9 @@ public class Flag implements Comparable { default -> new CycleClick(id); }; } - - return new Flag(this); + Flag flag = new Flag(this); + subflags.forEach(subflag -> subflag.parentFlag = flag); + return flag; } } - } diff --git a/src/main/java/world/bentobox/bentobox/panels/settings/SettingsTab.java b/src/main/java/world/bentobox/bentobox/panels/settings/SettingsTab.java index 934b22848..9987d2e40 100644 --- a/src/main/java/world/bentobox/bentobox/panels/settings/SettingsTab.java +++ b/src/main/java/world/bentobox/bentobox/panels/settings/SettingsTab.java @@ -136,15 +136,14 @@ public class SettingsTab implements Tab, ClickHandler { } // Remove any sub-flags that shouldn't be shown Set toBeRemoved = new HashSet<>(); - flags.stream().forEach(flag -> { - if ((flag.getType() == Type.SETTING || flag.getType() == Type.WORLD_SETTING) && flag.hasSubflags()) { - if (flag.isSetForWorld(world) && flag.getHideWhen() == HideWhen.SETTING_TRUE) { - toBeRemoved.addAll(flag.getSubflags()); - } else if (!flag.isSetForWorld(world) && flag.getHideWhen() == HideWhen.SETTING_FALSE) { - toBeRemoved.addAll(flag.getSubflags()); + flags.forEach(flag -> { + if (flag.isSubFlag() && flag.getHideWhen() != HideWhen.NEVER) { + if (!flag.getParentFlag().isSetForWorld(world) && flag.getHideWhen() == HideWhen.SETTING_FALSE) { + toBeRemoved.add(flag); + } else if (flag.getParentFlag().isSetForWorld(world) && flag.getHideWhen() == HideWhen.SETTING_TRUE) { + toBeRemoved.add(flag); } } - }); flags.removeAll(toBeRemoved);