move filter presets to Filter.Presets

add filter inverting
This commit is contained in:
Oth3r 2024-11-10 11:18:42 -06:00
commit de8b66d27a
4 changed files with 83 additions and 45 deletions

View file

@ -103,10 +103,14 @@ public class FileData {
)); ));
public static final HandSetting MAIN_HAND = new HandSetting(HandSetting.SittingRequirement.EMPTY, new HandSetting.Filter( public static final HandSetting MAIN_HAND = new HandSetting(HandSetting.SittingRequirement.EMPTY, new HandSetting.Filter(
false,false,false,new CustomItem(new ArrayList<>(), new ArrayList<>(Arrays.asList("#minecraft:bookshelf_books","!#minecraft:lectern_books"))))); false,new HandSetting.Filter.Presets(),
new CustomItem(
new ArrayList<>(),
new ArrayList<>(Arrays.asList("#minecraft:bookshelf_books","!#minecraft:lectern_books")))));
public static final HandSetting OFF_HAND = new HandSetting(HandSetting.SittingRequirement.FILTER, new HandSetting.Filter( public static final HandSetting OFF_HAND = new HandSetting(HandSetting.SittingRequirement.FILTER, new HandSetting.Filter(
false,true,false, new CustomItem(new ArrayList<>(Arrays.asList("minecraft:filled_map", false, new HandSetting.Filter.Presets(false, true, false),
new CustomItem(new ArrayList<>(Arrays.asList("minecraft:filled_map",
"minecraft:torch", "minecraft:soul_torch","minecraft:redstone_torch", "minecraft:torch", "minecraft:soul_torch","minecraft:redstone_torch",
"minecraft:lantern", "minecraft:soul_lantern")), "minecraft:lantern", "minecraft:soul_lantern")),
new ArrayList<>()))); new ArrayList<>())));

View file

@ -9,7 +9,7 @@ public class HandSetting {
@SerializedName("requirement") @SerializedName("requirement")
private SittingRequirement sittingRequirement = SittingRequirement.NONE; private SittingRequirement sittingRequirement = SittingRequirement.NONE;
@SerializedName("requirement-options") @SerializedName("requirement-options") @SuppressWarnings("unused")
private final String sittingRequirementOptions = Arrays.stream(SittingRequirement.values()).map(Enum::toString).collect(Collectors.joining(", ")); private final String sittingRequirementOptions = Arrays.stream(SittingRequirement.values()).map(Enum::toString).collect(Collectors.joining(", "));
@SerializedName("filter") @SerializedName("filter")
private Filter filter = new Filter(); private Filter filter = new Filter();
@ -37,22 +37,47 @@ public class HandSetting {
public static class Filter { public static class Filter {
@SerializedName("invert-filter")
private Boolean invert = false;
@SerializedName("presets")
private Presets presets = new Presets();
@SerializedName("custom-items")
private CustomItem customItems = new CustomItem();
public Filter() {}
public Filter(boolean invert, Presets presets, CustomItem customItems) {
this.invert = invert;
this.presets = presets;
this.customItems = customItems;
}
public Boolean isInverted() {
return invert;
}
public Presets getPresets() {
return presets;
}
public CustomItem getCustomItems() {
return customItems;
}
public static class Presets {
@SerializedName("block") @SerializedName("block")
private boolean block = false; private boolean block = false;
@SerializedName("food") @SerializedName("food")
private boolean food = false; private boolean food = false;
@SerializedName("usable") @SerializedName("usable")
private boolean usable = false; private boolean usable = false;
@SerializedName("custom-items")
private CustomItem customItems = new CustomItem();
public Filter() {} public Presets() {}
public Filter(boolean block, boolean food, boolean usable, CustomItem customItems) { public Presets(boolean block, boolean food, boolean usable) {
this.block = block; this.block = block;
this.food = food; this.food = food;
this.usable = usable; this.usable = usable;
this.customItems = customItems;
} }
public boolean isBlock() { public boolean isBlock() {
@ -66,9 +91,6 @@ public class HandSetting {
public boolean isUsable() { public boolean isUsable() {
return usable; return usable;
} }
public CustomItem getCustomItems() {
return customItems;
} }
} }
} }

View file

@ -295,10 +295,11 @@ public class ServerConfig implements CustomFile<ServerConfig> {
1.0, true, Boolean.parseBoolean((String) properties.computeIfAbsent("hand.sitting", a -> String.valueOf(defaultSittingConfig.canSitWithHand()))), 1.0, true, Boolean.parseBoolean((String) properties.computeIfAbsent("hand.sitting", a -> String.valueOf(defaultSittingConfig.canSitWithHand()))),
new HandSetting( new HandSetting(
handRequirementUpdater((String) properties.computeIfAbsent("hand.main.requirement", a -> String.valueOf(defaultSittingConfig.getHand(Hand.MAIN_HAND).getSittingRequirement()))), handRequirementUpdater((String) properties.computeIfAbsent("hand.main.requirement", a -> String.valueOf(defaultSittingConfig.getHand(Hand.MAIN_HAND).getSittingRequirement()))),
new HandSetting.Filter( new HandSetting.Filter(false,
!Boolean.parseBoolean((String) properties.computeIfAbsent("hand.main.block", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.MAIN_HAND).getFilter().isBlock()))), new HandSetting.Filter.Presets(
!Boolean.parseBoolean((String) properties.computeIfAbsent("hand.main.food", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.MAIN_HAND).getFilter().isFood()))), !Boolean.parseBoolean((String) properties.computeIfAbsent("hand.main.block", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.MAIN_HAND).getFilter().getPresets().isBlock()))),
!Boolean.parseBoolean((String) properties.computeIfAbsent("hand.main.usable", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.MAIN_HAND).getFilter().isUsable()))), !Boolean.parseBoolean((String) properties.computeIfAbsent("hand.main.food", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.MAIN_HAND).getFilter().getPresets().isFood()))),
!Boolean.parseBoolean((String) properties.computeIfAbsent("hand.main.usable", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.MAIN_HAND).getFilter().getPresets().isUsable())))),
new CustomItem(getFilterList( new CustomItem(getFilterList(
new Gson().fromJson((String) properties.computeIfAbsent("hand.main.whitelist", a -> "[]"), listType), new Gson().fromJson((String) properties.computeIfAbsent("hand.main.whitelist", a -> "[]"), listType),
new Gson().fromJson((String) properties.computeIfAbsent("hand.main.blacklist", a -> "[]"), listType) new Gson().fromJson((String) properties.computeIfAbsent("hand.main.blacklist", a -> "[]"), listType)
@ -308,10 +309,11 @@ public class ServerConfig implements CustomFile<ServerConfig> {
), ),
new HandSetting( new HandSetting(
handRequirementUpdater((String) properties.computeIfAbsent("hand.off.requirement", a -> String.valueOf(defaultSittingConfig.getHand(Hand.OFF_HAND).getSittingRequirement()))), handRequirementUpdater((String) properties.computeIfAbsent("hand.off.requirement", a -> String.valueOf(defaultSittingConfig.getHand(Hand.OFF_HAND).getSittingRequirement()))),
new HandSetting.Filter( new HandSetting.Filter(false,
!Boolean.parseBoolean((String) properties.computeIfAbsent("hand.off.block", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.OFF_HAND).getFilter().isBlock()))), new HandSetting.Filter.Presets(
!Boolean.parseBoolean((String) properties.computeIfAbsent("hand.off.food", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.OFF_HAND).getFilter().isFood()))), !Boolean.parseBoolean((String) properties.computeIfAbsent("hand.off.block", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.OFF_HAND).getFilter().getPresets().isBlock()))),
!Boolean.parseBoolean((String) properties.computeIfAbsent("hand.off.usable", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.OFF_HAND).getFilter().isUsable()))), !Boolean.parseBoolean((String) properties.computeIfAbsent("hand.off.food", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.OFF_HAND).getFilter().getPresets().isFood()))),
!Boolean.parseBoolean((String) properties.computeIfAbsent("hand.off.usable", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.OFF_HAND).getFilter().getPresets().isUsable())))),
new CustomItem(getFilterList( new CustomItem(getFilterList(
new Gson().fromJson((String) properties.computeIfAbsent("hand.off.whitelist", a -> "[]"), listType), new Gson().fromJson((String) properties.computeIfAbsent("hand.off.whitelist", a -> "[]"), listType),
new Gson().fromJson((String) properties.computeIfAbsent("hand.off.blacklist", a -> "[]"), listType) new Gson().fromJson((String) properties.computeIfAbsent("hand.off.blacklist", a -> "[]"), listType)
@ -329,10 +331,11 @@ public class ServerConfig implements CustomFile<ServerConfig> {
1.0, true, defaultSittingConfig.canSitWithHand(), 1.0, true, defaultSittingConfig.canSitWithHand(),
new HandSetting( new HandSetting(
handRequirementUpdater((String) properties.computeIfAbsent("main-hand-requirement", a -> String.valueOf(defaultSittingConfig.getHand(Hand.MAIN_HAND).getSittingRequirement()))), handRequirementUpdater((String) properties.computeIfAbsent("main-hand-requirement", a -> String.valueOf(defaultSittingConfig.getHand(Hand.MAIN_HAND).getSittingRequirement()))),
new HandSetting.Filter( new HandSetting.Filter(false,
!Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-block", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.MAIN_HAND).getFilter().isBlock()))), new HandSetting.Filter.Presets(
!Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-food", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.MAIN_HAND).getFilter().isFood()))), !Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-block", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.MAIN_HAND).getFilter().getPresets().isBlock()))),
!Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-usable", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.MAIN_HAND).getFilter().isUsable()))), !Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-food", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.MAIN_HAND).getFilter().getPresets().isFood()))),
!Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-usable", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.MAIN_HAND).getFilter().getPresets().isUsable())))),
new CustomItem(getFilterList( new CustomItem(getFilterList(
new Gson().fromJson((String) properties.computeIfAbsent("main-hand-whitelist", a -> "[]"), listType), new Gson().fromJson((String) properties.computeIfAbsent("main-hand-whitelist", a -> "[]"), listType),
new Gson().fromJson((String) properties.computeIfAbsent("main-hand-blacklist", a -> "[]"), listType) new Gson().fromJson((String) properties.computeIfAbsent("main-hand-blacklist", a -> "[]"), listType)
@ -342,10 +345,11 @@ public class ServerConfig implements CustomFile<ServerConfig> {
), ),
new HandSetting( new HandSetting(
handRequirementUpdater((String) properties.computeIfAbsent("off-hand-requirement", a -> String.valueOf(defaultSittingConfig.getHand(Hand.OFF_HAND).getSittingRequirement()))), handRequirementUpdater((String) properties.computeIfAbsent("off-hand-requirement", a -> String.valueOf(defaultSittingConfig.getHand(Hand.OFF_HAND).getSittingRequirement()))),
new HandSetting.Filter( new HandSetting.Filter(false,
!Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-block", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.OFF_HAND).getFilter().isBlock()))), new HandSetting.Filter.Presets(
!Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-food", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.OFF_HAND).getFilter().isFood()))), !Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-block", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.OFF_HAND).getFilter().getPresets().isBlock()))),
!Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-usable", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.OFF_HAND).getFilter().isUsable()))), !Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-food", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.OFF_HAND).getFilter().getPresets().isFood()))),
!Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-usable", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.OFF_HAND).getFilter().getPresets().isUsable())))),
new CustomItem(getFilterList( new CustomItem(getFilterList(
new Gson().fromJson((String) properties.computeIfAbsent("off-hand-whitelist", a -> "[]"), listType), new Gson().fromJson((String) properties.computeIfAbsent("off-hand-whitelist", a -> "[]"), listType),
new Gson().fromJson((String) properties.computeIfAbsent("off-hand-blacklist", a -> "[]"), listType) new Gson().fromJson((String) properties.computeIfAbsent("off-hand-blacklist", a -> "[]"), listType)

View file

@ -107,10 +107,16 @@ public class Utl {
// default to true if there's nothing // default to true if there's nothing
if (itemStack.isEmpty()) return true; if (itemStack.isEmpty()) return true;
boolean TRUE = true, FALSE = false;
if (filter.isInverted()) {
TRUE = false;
FALSE = true;
}
boolean itemcheck = filter.getCustomItems().checkItem(itemStack); boolean itemcheck = filter.getCustomItems().checkItem(itemStack);
// iif the item passes the checks, return true // iif the item passes the checks, return true
if (itemcheck) return true; if (itemcheck) return TRUE;
// if none of the custom were met, try the default conditions // if none of the custom were met, try the default conditions
@ -121,13 +127,15 @@ public class Utl {
ArrayList<UseAction> notUsable = new ArrayList<>(food); ArrayList<UseAction> notUsable = new ArrayList<>(food);
notUsable.add(UseAction.NONE); notUsable.add(UseAction.NONE);
HandSetting.Filter.Presets presets = filter.getPresets();
// try the default conditions // try the default conditions
if (filter.isBlock() && itemStack.getItem() instanceof BlockItem) return true; if (presets.isBlock() && itemStack.getItem() instanceof BlockItem) return TRUE;
if (filter.isFood() && food.contains(itemStack.getUseAction())) return true; if (presets.isFood() && food.contains(itemStack.getUseAction())) return TRUE;
if (filter.isUsable() && hasItemUse(itemStack)) return true; if (presets.isUsable() && hasItemUse(itemStack)) return TRUE;
// if nothing else is met, the item is filtered out // if nothing else is met, the item is filtered out
return false; return FALSE;
} }
/** /**