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