mirror of
https://github.com/Oth3r/Sit.git
synced 2025-09-19 16:03:22 +02:00
move filter presets to Filter.Presets
add filter inverting
This commit is contained in:
parent
668056c19a
commit
de8b66d27a
4 changed files with 83 additions and 45 deletions
|
@ -103,12 +103,16 @@ public class FileData {
|
|||
));
|
||||
|
||||
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(
|
||||
false,true,false, new CustomItem(new ArrayList<>(Arrays.asList("minecraft:filled_map",
|
||||
"minecraft:torch", "minecraft:soul_torch","minecraft:redstone_torch",
|
||||
"minecraft:lantern", "minecraft:soul_lantern")),
|
||||
new ArrayList<>())));
|
||||
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:lantern", "minecraft:soul_lantern")),
|
||||
new ArrayList<>())));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ public class HandSetting {
|
|||
|
||||
@SerializedName("requirement")
|
||||
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(", "));
|
||||
@SerializedName("filter")
|
||||
private Filter filter = new Filter();
|
||||
|
@ -37,38 +37,60 @@ public class HandSetting {
|
|||
|
||||
public static class Filter {
|
||||
|
||||
@SerializedName("block")
|
||||
private boolean block = false;
|
||||
@SerializedName("food")
|
||||
private boolean food = false;
|
||||
@SerializedName("usable")
|
||||
private boolean usable = false;
|
||||
@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 block, boolean food, boolean usable, CustomItem customItems) {
|
||||
this.block = block;
|
||||
this.food = food;
|
||||
this.usable = usable;
|
||||
public Filter(boolean invert, Presets presets, CustomItem customItems) {
|
||||
this.invert = invert;
|
||||
this.presets = presets;
|
||||
this.customItems = customItems;
|
||||
}
|
||||
|
||||
public boolean isBlock() {
|
||||
return block;
|
||||
public Boolean isInverted() {
|
||||
return invert;
|
||||
}
|
||||
|
||||
public boolean isFood() {
|
||||
return food;
|
||||
}
|
||||
|
||||
public boolean isUsable() {
|
||||
return usable;
|
||||
public Presets getPresets() {
|
||||
return presets;
|
||||
}
|
||||
|
||||
public CustomItem getCustomItems() {
|
||||
return customItems;
|
||||
}
|
||||
|
||||
public static class Presets {
|
||||
@SerializedName("block")
|
||||
private boolean block = false;
|
||||
@SerializedName("food")
|
||||
private boolean food = false;
|
||||
@SerializedName("usable")
|
||||
private boolean usable = false;
|
||||
|
||||
public Presets() {}
|
||||
|
||||
public Presets(boolean block, boolean food, boolean usable) {
|
||||
this.block = block;
|
||||
this.food = food;
|
||||
this.usable = usable;
|
||||
}
|
||||
|
||||
public boolean isBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
public boolean isFood() {
|
||||
return food;
|
||||
}
|
||||
|
||||
public boolean isUsable() {
|
||||
return usable;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()))),
|
||||
new HandSetting(
|
||||
handRequirementUpdater((String) properties.computeIfAbsent("hand.main.requirement", a -> String.valueOf(defaultSittingConfig.getHand(Hand.MAIN_HAND).getSittingRequirement()))),
|
||||
new HandSetting.Filter(
|
||||
!Boolean.parseBoolean((String) properties.computeIfAbsent("hand.main.block", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.MAIN_HAND).getFilter().isBlock()))),
|
||||
!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.usable", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.MAIN_HAND).getFilter().isUsable()))),
|
||||
new HandSetting.Filter(false,
|
||||
new HandSetting.Filter.Presets(
|
||||
!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.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 Gson().fromJson((String) properties.computeIfAbsent("hand.main.whitelist", 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(
|
||||
handRequirementUpdater((String) properties.computeIfAbsent("hand.off.requirement", a -> String.valueOf(defaultSittingConfig.getHand(Hand.OFF_HAND).getSittingRequirement()))),
|
||||
new HandSetting.Filter(
|
||||
!Boolean.parseBoolean((String) properties.computeIfAbsent("hand.off.block", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.OFF_HAND).getFilter().isBlock()))),
|
||||
!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.usable", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.OFF_HAND).getFilter().isUsable()))),
|
||||
new HandSetting.Filter(false,
|
||||
new HandSetting.Filter.Presets(
|
||||
!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.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 Gson().fromJson((String) properties.computeIfAbsent("hand.off.whitelist", 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(),
|
||||
new HandSetting(
|
||||
handRequirementUpdater((String) properties.computeIfAbsent("main-hand-requirement", a -> String.valueOf(defaultSittingConfig.getHand(Hand.MAIN_HAND).getSittingRequirement()))),
|
||||
new HandSetting.Filter(
|
||||
!Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-block", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.MAIN_HAND).getFilter().isBlock()))),
|
||||
!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-usable", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.MAIN_HAND).getFilter().isUsable()))),
|
||||
new HandSetting.Filter(false,
|
||||
new HandSetting.Filter.Presets(
|
||||
!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-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 Gson().fromJson((String) properties.computeIfAbsent("main-hand-whitelist", 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(
|
||||
handRequirementUpdater((String) properties.computeIfAbsent("off-hand-requirement", a -> String.valueOf(defaultSittingConfig.getHand(Hand.OFF_HAND).getSittingRequirement()))),
|
||||
new HandSetting.Filter(
|
||||
!Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-block", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.OFF_HAND).getFilter().isBlock()))),
|
||||
!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-usable", a -> String.valueOf(!defaultSittingConfig.getHand(Hand.OFF_HAND).getFilter().isUsable()))),
|
||||
new HandSetting.Filter(false,
|
||||
new HandSetting.Filter.Presets(
|
||||
!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-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 Gson().fromJson((String) properties.computeIfAbsent("off-hand-whitelist", a -> "[]"), listType),
|
||||
new Gson().fromJson((String) properties.computeIfAbsent("off-hand-blacklist", a -> "[]"), listType)
|
||||
|
|
|
@ -107,10 +107,16 @@ public class Utl {
|
|||
// default to true if there's nothing
|
||||
if (itemStack.isEmpty()) return true;
|
||||
|
||||
boolean TRUE = true, FALSE = false;
|
||||
if (filter.isInverted()) {
|
||||
TRUE = false;
|
||||
FALSE = true;
|
||||
}
|
||||
|
||||
boolean itemcheck = filter.getCustomItems().checkItem(itemStack);
|
||||
|
||||
// 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
|
||||
|
||||
|
@ -121,13 +127,15 @@ public class Utl {
|
|||
ArrayList<UseAction> notUsable = new ArrayList<>(food);
|
||||
notUsable.add(UseAction.NONE);
|
||||
|
||||
HandSetting.Filter.Presets presets = filter.getPresets();
|
||||
|
||||
// try the default conditions
|
||||
if (filter.isBlock() && itemStack.getItem() instanceof BlockItem) return true;
|
||||
if (filter.isFood() && food.contains(itemStack.getUseAction())) return true;
|
||||
if (filter.isUsable() && hasItemUse(itemStack)) return true;
|
||||
if (presets.isBlock() && itemStack.getItem() instanceof BlockItem) return TRUE;
|
||||
if (presets.isFood() && food.contains(itemStack.getUseAction())) return TRUE;
|
||||
if (presets.isUsable() && hasItemUse(itemStack)) return TRUE;
|
||||
|
||||
// if nothing else is met, the item is filtered out
|
||||
return false;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue