-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only show relevant server whitelists
Show Whitelist config in whitelist mode, and Blacklist in blacklist mode. Don't show either in "no restriction" mode.
- Loading branch information
1 parent
be167bb
commit 18e5da9
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
common/src/main/java/net/xolt/freecam/config/gui/ServerRestrictionDependencies.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package net.xolt.freecam.config.gui; | ||
|
||
import me.shedaniel.autoconfig.gui.registry.GuiRegistry; | ||
import me.shedaniel.clothconfig2.gui.entries.SelectionListEntry; | ||
import me.shedaniel.clothconfig2.gui.entries.StringListListEntry; | ||
import net.xolt.freecam.config.ModConfig; | ||
|
||
class ServerRestrictionDependencies { | ||
|
||
private static SelectionListEntry<ModConfig.ServerRestriction> mode; | ||
|
||
static void apply(GuiRegistry registry) { | ||
// Capture a reference to the mode entry | ||
registry.registerPredicateTransformer( | ||
(guis, i18n, field, config, defaults, guiProvider) -> { | ||
//noinspection unchecked | ||
mode = guis.stream() | ||
.filter(SelectionListEntry.class::isInstance) | ||
.map(SelectionListEntry.class::cast) | ||
.filter(entry -> entry.getValue() instanceof ModConfig.ServerRestriction) | ||
.reduce((prev, next) -> { throw new IllegalStateException("Multiple selection entries added to %s.mode".formatted(ModConfig.ServerConfig.class.getSimpleName())); }) | ||
.orElseThrow(() -> new IllegalStateException("No selection entries added to %s.mode".formatted(ModConfig.ServerConfig.class.getSimpleName()))); | ||
return guis; | ||
}, | ||
field -> field.getDeclaringClass().equals(ModConfig.ServerConfig.class) && field.getName().equals("mode") | ||
); | ||
|
||
// Whitelist dependency | ||
registry.registerPredicateTransformer( | ||
(guis, i18n, field, config, defaults, guiProvider) -> { | ||
guis.stream() | ||
.filter(StringListListEntry.class::isInstance) | ||
.map(StringListListEntry.class::cast) | ||
.forEach(entry -> entry.setDisplayRequirement(() -> mode == null || mode.getValue().equals(ModConfig.ServerRestriction.WHITELIST))); | ||
return guis; | ||
}, | ||
field -> field.getDeclaringClass().equals(ModConfig.ServerConfig.class) && field.getName().equals("whitelist") | ||
); | ||
|
||
// Blacklist dependency | ||
registry.registerPredicateTransformer( | ||
(guis, i18n, field, config, defaults, guiProvider) -> { | ||
guis.stream() | ||
.filter(StringListListEntry.class::isInstance) | ||
.map(StringListListEntry.class::cast) | ||
.forEach(entry -> entry.setDisplayRequirement(() -> mode == null || mode.getValue().equals(ModConfig.ServerRestriction.BLACKLIST))); | ||
return guis; | ||
}, | ||
field -> field.getDeclaringClass().equals(ModConfig.ServerConfig.class) && field.getName().equals("blacklist") | ||
); | ||
} | ||
} |