mirror of
https://github.com/JamesPeters98/ChestsPlusPlus.git
synced 2025-02-10 09:32:00 +01:00
Fix for Filters.
Multiple filters were causing problems when rejecting items.
This commit is contained in:
parent
c5e38b6711
commit
11cd27deee
@ -6,6 +6,11 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class Filter {
|
||||
|
||||
enum Type {
|
||||
ACCEPT,
|
||||
REJECT
|
||||
}
|
||||
|
||||
private ItemStack filter;
|
||||
private boolean filterByItemMeta;
|
||||
private boolean dontAllowThisItem;
|
||||
@ -16,10 +21,17 @@ public class Filter {
|
||||
this.dontAllowThisItem = itemFrame.getRotation().equals(Rotation.CLOCKWISE) || itemFrame.getRotation().equals(Rotation.COUNTER_CLOCKWISE);
|
||||
}
|
||||
|
||||
public boolean isFiltered(ItemStack itemStack){
|
||||
if(dontAllowThisItem && !filterByItemMeta) return !filter.isSimilar(itemStack);
|
||||
else if (dontAllowThisItem) return !isFilteredByMeta(itemStack);
|
||||
return isFilteredByMeta(itemStack);
|
||||
public Type getFilterType(ItemStack itemStack){
|
||||
if(dontAllowThisItem && !filterByItemMeta){
|
||||
if(filter.isSimilar(itemStack)) return Type.REJECT;
|
||||
else return Type.ACCEPT;
|
||||
}
|
||||
else if (dontAllowThisItem){
|
||||
if(isFilteredByMeta(itemStack)) return Type.REJECT;
|
||||
else return Type.ACCEPT;
|
||||
}
|
||||
if(isFilteredByMeta(itemStack)) return Type.ACCEPT;
|
||||
return Type.REJECT;
|
||||
}
|
||||
|
||||
private boolean isFilteredByMeta(ItemStack itemStack){
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.jamesdpeters.minecraft.chests.filters;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Rotation;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
@ -16,10 +15,7 @@ public class HopperFilter {
|
||||
public static boolean isInFilter(List<Filter> filters, ItemStack item){
|
||||
if(filters == null) return true;
|
||||
if(filters.size() == 0) return true;
|
||||
for(Filter filter : filters){
|
||||
if(filter.isFiltered(item)) return true;
|
||||
}
|
||||
return false;
|
||||
return filters.stream().noneMatch(filter -> filter.getFilterType(item).equals(Filter.Type.REJECT));
|
||||
}
|
||||
|
||||
public static List<Filter> getHopperFilters(Block block){
|
||||
|
Loading…
Reference in New Issue
Block a user