mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-11 09:51:40 +01:00
Merge pull request #2450 from BentoBoxWorld/2437_conditional_flag_visibility
Provides an API to hide sub-flags #2437
This commit is contained in:
commit
1155ffd08e
2
pom.xml
2
pom.xml
@ -88,7 +88,7 @@
|
|||||||
<!-- Do not change unless you want different name for local builds. -->
|
<!-- Do not change unless you want different name for local builds. -->
|
||||||
<build.number>-LOCAL</build.number>
|
<build.number>-LOCAL</build.number>
|
||||||
<!-- This allows to change between versions. -->
|
<!-- This allows to change between versions. -->
|
||||||
<build.version>2.4.2</build.version>
|
<build.version>2.4.3</build.version>
|
||||||
<sonar.organization>bentobox-world</sonar.organization>
|
<sonar.organization>bentobox-world</sonar.organization>
|
||||||
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
|
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
|
||||||
<server.jars>${project.basedir}/lib</server.jars>
|
<server.jars>${project.basedir}/lib</server.jars>
|
||||||
|
@ -116,6 +116,25 @@ public class Flag implements Comparable<Flag> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for hiding of sub flags
|
||||||
|
* @since 2.4.3
|
||||||
|
*/
|
||||||
|
public enum HideWhen {
|
||||||
|
/**
|
||||||
|
* Never hide sub-flags
|
||||||
|
*/
|
||||||
|
NEVER,
|
||||||
|
/**
|
||||||
|
* Hide subflags if the setting of the parent flag is true
|
||||||
|
*/
|
||||||
|
SETTING_TRUE,
|
||||||
|
/**
|
||||||
|
* Hide subflags if the setting of the parent flag is false
|
||||||
|
*/
|
||||||
|
SETTING_FALSE
|
||||||
|
}
|
||||||
|
|
||||||
private static final String PROTECTION_FLAGS = "protection.flags.";
|
private static final String PROTECTION_FLAGS = "protection.flags.";
|
||||||
|
|
||||||
private final String id;
|
private final String id;
|
||||||
@ -131,6 +150,7 @@ public class Flag implements Comparable<Flag> {
|
|||||||
private final int cooldown;
|
private final int cooldown;
|
||||||
private final Mode mode;
|
private final Mode mode;
|
||||||
private final Set<Flag> subflags;
|
private final Set<Flag> subflags;
|
||||||
|
private final HideWhen hideWhen;
|
||||||
|
|
||||||
private Flag(Builder builder) {
|
private Flag(Builder builder) {
|
||||||
this.id = builder.id;
|
this.id = builder.id;
|
||||||
@ -148,6 +168,7 @@ public class Flag implements Comparable<Flag> {
|
|||||||
this.addon = builder.addon;
|
this.addon = builder.addon;
|
||||||
this.mode = builder.mode;
|
this.mode = builder.mode;
|
||||||
this.subflags = builder.subflags;
|
this.subflags = builder.subflags;
|
||||||
|
this.hideWhen = builder.hideWhen;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getID() {
|
public String getID() {
|
||||||
@ -276,6 +297,14 @@ public class Flag implements Comparable<Flag> {
|
|||||||
return addon;
|
return addon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get when sub-flags should be hidden
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public HideWhen getHideWhen() {
|
||||||
|
return hideWhen;
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see java.lang.Object#hashCode()
|
* @see java.lang.Object#hashCode()
|
||||||
*/
|
*/
|
||||||
@ -553,6 +582,9 @@ public class Flag implements Comparable<Flag> {
|
|||||||
// Subflags
|
// Subflags
|
||||||
private final Set<Flag> subflags;
|
private final Set<Flag> subflags;
|
||||||
|
|
||||||
|
// Hide when indicator
|
||||||
|
private HideWhen hideWhen = HideWhen.NEVER;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder for making flags
|
* Builder for making flags
|
||||||
* @param id - a unique id that MUST be the same as the enum of the flag
|
* @param id - a unique id that MUST be the same as the enum of the flag
|
||||||
@ -682,6 +714,18 @@ public class Flag implements Comparable<Flag> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When should sub-flags be hidden, if ever
|
||||||
|
* {@see HideWhen}
|
||||||
|
* @param hideWhen hide when indicator
|
||||||
|
* @return Builder - flag builder
|
||||||
|
* @since 2.4.3
|
||||||
|
*/
|
||||||
|
public Builder hideWhen(HideWhen hideWhen) {
|
||||||
|
this.hideWhen = hideWhen;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build the flag
|
* Build the flag
|
||||||
* @return Flag
|
* @return Flag
|
||||||
|
@ -2,8 +2,10 @@ package world.bentobox.bentobox.panels.settings;
|
|||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -17,6 +19,7 @@ import org.eclipse.jdt.annotation.Nullable;
|
|||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.flags.Flag;
|
import world.bentobox.bentobox.api.flags.Flag;
|
||||||
|
import world.bentobox.bentobox.api.flags.Flag.HideWhen;
|
||||||
import world.bentobox.bentobox.api.flags.Flag.Mode;
|
import world.bentobox.bentobox.api.flags.Flag.Mode;
|
||||||
import world.bentobox.bentobox.api.flags.Flag.Type;
|
import world.bentobox.bentobox.api.flags.Flag.Type;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
@ -131,10 +134,25 @@ public class SettingsTab implements Tab, ClickHandler {
|
|||||||
currentMode.put(user.getUniqueId(), currentMode.getOrDefault(user.getUniqueId(), Mode.BASIC).getNext());
|
currentMode.put(user.getUniqueId(), currentMode.getOrDefault(user.getUniqueId(), Mode.BASIC).getNext());
|
||||||
flags = getFlags();
|
flags = getFlags();
|
||||||
}
|
}
|
||||||
|
// Remove any sub-flags that shouldn't be shown
|
||||||
|
Set<Flag> 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.removeAll(toBeRemoved);
|
||||||
|
|
||||||
List<@Nullable PanelItem> result = flags.stream().map(
|
List<@Nullable PanelItem> result = flags.stream().map(
|
||||||
(f -> f.toPanelItem(plugin, user, world, island,
|
(f -> f.toPanelItem(plugin, user, world, island,
|
||||||
plugin.getIWM().getHiddenFlags(world).contains(f.getID()))))
|
plugin.getIWM().getHiddenFlags(world).contains(f.getID()))))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user