Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/com/sk89q/craftbook/mechanics/pipe/Pipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -526,5 +526,8 @@ public void loadConfiguration (YAMLProcessor config, String path) {

config.setComment(path + "require-sign", "Requires pipes to have a [Pipe] sign connected to them. This is the only way to require permissions to make pipes.");
pipeRequireSign = config.getBoolean(path + "require-sign", false);

config.setComment(path + "filters-match-type", "When a filter entry has no item meta, match by item type alone so potions, enchanted books and renamed items are caught by plain filters instead of passing through. Filters that specify meta still compare it exactly.");
ItemUtil.setLooseFilterMatching(config.getBoolean(path + "filters-match-type", false));
}
}
23 changes: 21 additions & 2 deletions src/main/java/com/sk89q/craftbook/util/ItemUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static boolean doesItemPassFilters(ItemStack stack, Set<ItemStack> inclus
if(!ItemUtil.isStackValid(fil))
continue;

if(ItemUtil.areItemsIdentical(fil, stack)) {
if(ItemUtil.matchesFilter(fil, stack)) {
passesFilters = true;
break;
} else
Expand All @@ -105,7 +105,7 @@ public static boolean doesItemPassFilters(ItemStack stack, Set<ItemStack> inclus

if(!ItemUtil.isStackValid(fil))
continue;
if(ItemUtil.areItemsIdentical(fil, stack)) {
if(ItemUtil.matchesFilter(fil, stack)) {
passesFilters = false;
break;
}
Expand Down Expand Up @@ -371,6 +371,25 @@ public static boolean areItemMetaIdentical(ItemMeta meta, ItemMeta meta2, boolea
return true;
}

/**
* When enabled, filter entries that carry no item meta match on type alone, so a
* plain 'potion' filter also catches brewed potions, enchanted books and renamed
* items instead of letting them pass through. Filter entries that do specify meta
* always compare it exactly. Configured by the Pipes mechanic; off by default,
* which keeps the strict comparison below.
*/
private static boolean looseFilterMatching = false;

public static void setLooseFilterMatching(boolean loose) {
looseFilterMatching = loose;
}

public static boolean matchesFilter(ItemStack filter, ItemStack stack) {
if (looseFilterMatching && !filter.hasItemMeta())
return areBaseItemsIdentical(filter, stack);
return areItemsIdentical(filter, stack);
}

public static boolean areItemsIdentical(ItemStack item, ItemStack item2) {

if(!isStackValid(item) || !isStackValid(item2)) {
Expand Down
Loading