Merge branch 'develop' of https://github.com/BentoBoxWorld/BentoBox.git into develop

This commit is contained in:
tastybento 2024-08-02 07:45:46 -07:00
commit 0766f2967d
2 changed files with 30 additions and 10 deletions

View File

@ -151,6 +151,8 @@ public class Flag implements Comparable<Flag> {
private final Mode mode; private final Mode mode;
private final Set<Flag> subflags; private final Set<Flag> subflags;
private final HideWhen hideWhen; private final HideWhen hideWhen;
private boolean isSubFlag;
private Flag parentFlag;
private Flag(Builder builder) { private Flag(Builder builder) {
this.id = builder.id; this.id = builder.id;
@ -169,6 +171,8 @@ public class Flag implements Comparable<Flag> {
this.mode = builder.mode; this.mode = builder.mode;
this.subflags = builder.subflags; this.subflags = builder.subflags;
this.hideWhen = builder.hideWhen; this.hideWhen = builder.hideWhen;
this.isSubFlag = false;
this.parentFlag = null;
} }
public String getID() { public String getID() {
@ -305,6 +309,20 @@ public class Flag implements Comparable<Flag> {
return hideWhen; return hideWhen;
} }
/**
* @return the isSubFlag
*/
public boolean isSubFlag() {
return isSubFlag;
}
/**
* @return the parentFlag
*/
public Flag getParentFlag() {
return parentFlag;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see java.lang.Object#hashCode() * @see java.lang.Object#hashCode()
*/ */
@ -711,6 +729,9 @@ public class Flag implements Comparable<Flag> {
*/ */
public Builder subflags(Flag... flags) { public Builder subflags(Flag... flags) {
this.subflags.addAll(Arrays.asList(flags)); this.subflags.addAll(Arrays.asList(flags));
for (Flag flag : flags) {
flag.isSubFlag = true;
}
return this; return this;
} }
@ -739,9 +760,9 @@ public class Flag implements Comparable<Flag> {
default -> new CycleClick(id); default -> new CycleClick(id);
}; };
} }
Flag flag = new Flag(this);
return new Flag(this); subflags.forEach(subflag -> subflag.parentFlag = flag);
return flag;
} }
} }
} }

View File

@ -136,15 +136,14 @@ public class SettingsTab implements Tab, ClickHandler {
} }
// Remove any sub-flags that shouldn't be shown // Remove any sub-flags that shouldn't be shown
Set<Flag> toBeRemoved = new HashSet<>(); Set<Flag> toBeRemoved = new HashSet<>();
flags.stream().forEach(flag -> { flags.forEach(flag -> {
if ((flag.getType() == Type.SETTING || flag.getType() == Type.WORLD_SETTING) && flag.hasSubflags()) { if (flag.isSubFlag() && flag.getHideWhen() != HideWhen.NEVER) {
if (flag.isSetForWorld(world) && flag.getHideWhen() == HideWhen.SETTING_TRUE) { if (!flag.getParentFlag().isSetForWorld(world) && flag.getHideWhen() == HideWhen.SETTING_FALSE) {
toBeRemoved.addAll(flag.getSubflags()); toBeRemoved.add(flag);
} else if (!flag.isSetForWorld(world) && flag.getHideWhen() == HideWhen.SETTING_FALSE) { } else if (flag.getParentFlag().isSetForWorld(world) && flag.getHideWhen() == HideWhen.SETTING_TRUE) {
toBeRemoved.addAll(flag.getSubflags()); toBeRemoved.add(flag);
} }
} }
}); });
flags.removeAll(toBeRemoved); flags.removeAll(toBeRemoved);