forked from virt-mirrors/Sit
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(
|
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),
|
||||||
"minecraft:torch", "minecraft:soul_torch","minecraft:redstone_torch",
|
new CustomItem(new ArrayList<>(Arrays.asList("minecraft:filled_map",
|
||||||
"minecraft:lantern", "minecraft:soul_lantern")),
|
"minecraft:torch", "minecraft:soul_torch","minecraft:redstone_torch",
|
||||||
new ArrayList<>())));
|
"minecraft:lantern", "minecraft:soul_lantern")),
|
||||||
|
new ArrayList<>())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,38 +37,60 @@ public class HandSetting {
|
||||||
|
|
||||||
public static class Filter {
|
public static class Filter {
|
||||||
|
|
||||||
@SerializedName("block")
|
@SerializedName("invert-filter")
|
||||||
private boolean block = false;
|
private Boolean invert = false;
|
||||||
@SerializedName("food")
|
@SerializedName("presets")
|
||||||
private boolean food = false;
|
private Presets presets = new Presets();
|
||||||
@SerializedName("usable")
|
|
||||||
private boolean usable = false;
|
|
||||||
@SerializedName("custom-items")
|
@SerializedName("custom-items")
|
||||||
private CustomItem customItems = new CustomItem();
|
private CustomItem customItems = new CustomItem();
|
||||||
|
|
||||||
public Filter() {}
|
public Filter() {}
|
||||||
|
|
||||||
public Filter(boolean block, boolean food, boolean usable, CustomItem customItems) {
|
public Filter(boolean invert, Presets presets, CustomItem customItems) {
|
||||||
this.block = block;
|
this.invert = invert;
|
||||||
this.food = food;
|
this.presets = presets;
|
||||||
this.usable = usable;
|
|
||||||
this.customItems = customItems;
|
this.customItems = customItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBlock() {
|
public Boolean isInverted() {
|
||||||
return block;
|
return invert;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFood() {
|
public Presets getPresets() {
|
||||||
return food;
|
return presets;
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isUsable() {
|
|
||||||
return usable;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustomItem getCustomItems() {
|
public CustomItem getCustomItems() {
|
||||||
return customItems;
|
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()))),
|
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)
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue