mirror of
https://github.com/songoda/EpicHoppers.git
synced 2024-11-25 11:46:45 +01:00
Switched to a itemstack based filter
This commit is contained in:
parent
fe05165f83
commit
3368fdf202
@ -1,22 +1,22 @@
|
||||
package com.songoda.epichoppers.api.hopper;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Filter {
|
||||
List<Material> getWhiteList();
|
||||
List<ItemStack> getWhiteList();
|
||||
|
||||
void setWhiteList(List<Material> whiteList);
|
||||
void setWhiteList(List<ItemStack> whiteList);
|
||||
|
||||
List<Material> getBlackList();
|
||||
List<ItemStack> getBlackList();
|
||||
|
||||
void setBlackList(List<Material> blackList);
|
||||
void setBlackList(List<ItemStack> blackList);
|
||||
|
||||
List<Material> getVoidList();
|
||||
List<ItemStack> getVoidList();
|
||||
|
||||
void setVoidList(List<Material> voidList);
|
||||
void setVoidList(List<ItemStack> voidList);
|
||||
|
||||
Block getEndPoint();
|
||||
|
||||
|
@ -162,9 +162,9 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
UUID lastPlayer = playerStr == null ? null : UUID.fromString(playerStr);
|
||||
UUID placedBy = placedByStr == null ? null : UUID.fromString(placedByStr);
|
||||
|
||||
List<Material> whiteList = row.get("whitelist").asMaterialList();
|
||||
List<Material> blackList = row.get("blacklist").asMaterialList();
|
||||
List<Material> voidList = row.get("void").asMaterialList();
|
||||
List<ItemStack> whiteList = row.get("whitelist").asItemStackList();
|
||||
List<ItemStack> blackList = row.get("blacklist").asItemStackList();
|
||||
List<ItemStack> voidList = row.get("void").asItemStackList();
|
||||
|
||||
Material autoCrafting = Material.valueOf(row.get("autocrafting").asString() == null ? "AIR" : row.get("autocrafting").asString());
|
||||
|
||||
|
@ -119,9 +119,9 @@ public class HopHandler {
|
||||
|
||||
int amt = hopper.getLevel().getAmount() * (boostData == null ? 1 : boostData.getMultiplier());
|
||||
|
||||
List<Material> whiteList = hopper.getFilter().getWhiteList();
|
||||
List<ItemStack> whiteList = hopper.getFilter().getWhiteList();
|
||||
|
||||
List<Material> blackList = hopper.getFilter().getBlackList();
|
||||
List<ItemStack> blackList = hopper.getFilter().getBlackList();
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
ItemStack it = null;
|
||||
@ -129,22 +129,27 @@ public class HopHandler {
|
||||
it = is[i].clone();
|
||||
it.setAmount(1);
|
||||
}
|
||||
if (!hopper.getLocation().getBlock().isBlockPowered()
|
||||
if (hopper.getLocation().getBlock().isBlockPowered()
|
||||
|| is[i] != null && blockedMaterials.contains(is[i].getType())) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
int finalI = i;
|
||||
if (is[i] != null
|
||||
&& !whiteList.isEmpty()
|
||||
&& !whiteList.contains(it.getType())) {
|
||||
doBlacklist(hopperBlock, hopper, is[i].clone(), is, amt, i);
|
||||
} else if (is[i] != null && !blackList.contains(it.getType())) {
|
||||
int im = addItem(hopperBlock, hopper, b2, is[i], is, amt, i);
|
||||
if (im != 10)
|
||||
i = im;
|
||||
} else if (is[i] != null && blackList.contains(it.getType())) {
|
||||
&& whiteList.stream().noneMatch(itemStack -> itemStack.isSimilar(is[finalI]))) {
|
||||
doBlacklist(hopperBlock, hopper, is[i].clone(), is, amt, i);
|
||||
} else {
|
||||
if (is[i] != null && blackList.stream().noneMatch(itemStack -> itemStack.isSimilar(is[finalI]))) {
|
||||
int im = addItem(hopperBlock, hopper, b2, is[i], is, amt, i);
|
||||
if (im != 10)
|
||||
i = im;
|
||||
} else {
|
||||
if (is[i] != null && blackList.stream().anyMatch(itemStack -> itemStack.isSimilar(is[finalI]))) {
|
||||
doBlacklist(hopperBlock, hopper, is[i].clone(), is, amt, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -184,11 +189,7 @@ public class HopHandler {
|
||||
it.setAmount(1);
|
||||
}
|
||||
|
||||
List<Material> ovoid = new ArrayList<>();
|
||||
|
||||
for (Material iss : hopper.getFilter().getVoidList()) {
|
||||
ovoid.add(iss);
|
||||
}
|
||||
List<ItemStack> ovoid = new ArrayList<>(hopper.getFilter().getVoidList());
|
||||
|
||||
if (is.getType() == Material.AIR) {
|
||||
return 10;
|
||||
@ -246,7 +247,8 @@ public class HopHandler {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!ovoid.contains(it.getType())) {
|
||||
ItemStack finalIt = it;
|
||||
if (ovoid.stream().noneMatch(itemStack -> itemStack.isSimilar(finalIt))) {
|
||||
ih.getInventory().addItem(newItem);
|
||||
}
|
||||
isS[place] = is;
|
||||
|
@ -1,50 +1,50 @@
|
||||
package com.songoda.epichoppers.hopper;
|
||||
|
||||
import com.songoda.epichoppers.api.hopper.Filter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EFilter implements Filter {
|
||||
|
||||
private List<Material> whiteList = new ArrayList<>();
|
||||
private List<Material> blackList = new ArrayList<>();
|
||||
private List<Material> voidList = new ArrayList<>();
|
||||
private List<ItemStack> whiteList = new ArrayList<>();
|
||||
private List<ItemStack> blackList = new ArrayList<>();
|
||||
private List<ItemStack> voidList = new ArrayList<>();
|
||||
|
||||
private Block endPoint;
|
||||
|
||||
@Override
|
||||
public List<Material> getWhiteList() {
|
||||
public List<ItemStack> getWhiteList() {
|
||||
if (whiteList == null) return new ArrayList<>();
|
||||
return whiteList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWhiteList(List<Material> whiteList) {
|
||||
public void setWhiteList(List<ItemStack> whiteList) {
|
||||
this.whiteList = whiteList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Material> getBlackList() {
|
||||
public List<ItemStack> getBlackList() {
|
||||
if (blackList == null) return new ArrayList<>();
|
||||
return blackList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlackList(List<Material> blackList) {
|
||||
public void setBlackList(List<ItemStack> blackList) {
|
||||
this.blackList = blackList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Material> getVoidList() {
|
||||
public List<ItemStack> getVoidList() {
|
||||
if (voidList == null) return new ArrayList<>();
|
||||
return voidList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVoidList(List<Material> voidList) {
|
||||
public void setVoidList(List<ItemStack> voidList) {
|
||||
this.voidList = voidList;
|
||||
}
|
||||
|
||||
|
@ -313,7 +313,7 @@ public class EHopper implements Hopper {
|
||||
}
|
||||
|
||||
int num = 0;
|
||||
for (Material m : filter.getWhiteList()) {
|
||||
for (ItemStack m : filter.getWhiteList()) {
|
||||
if (m != null) {
|
||||
i.setItem(whiteSlots[num], new ItemStack(m));
|
||||
num++;
|
||||
@ -330,7 +330,7 @@ public class EHopper implements Hopper {
|
||||
}
|
||||
|
||||
num = 0;
|
||||
for (Material m : filter.getBlackList()) {
|
||||
for (ItemStack m : filter.getBlackList()) {
|
||||
if (m != null) {
|
||||
i.setItem(blackSlots[num], new ItemStack(m));
|
||||
num++;
|
||||
@ -347,7 +347,7 @@ public class EHopper implements Hopper {
|
||||
}
|
||||
|
||||
num = 0;
|
||||
for (Material m : filter.getVoidList()) {
|
||||
for (ItemStack m : filter.getVoidList()) {
|
||||
if (m != null) {
|
||||
i.setItem(avoid[num], new ItemStack(m));
|
||||
num++;
|
||||
@ -393,9 +393,9 @@ public class EHopper implements Hopper {
|
||||
try {
|
||||
ItemStack[] items2 = p.getOpenInventory().getTopInventory().getContents();
|
||||
|
||||
List<Material> owhite = new ArrayList<>();
|
||||
List<Material> oblack = new ArrayList<>();
|
||||
List<Material> ovoid = new ArrayList<>();
|
||||
List<ItemStack> owhite = new ArrayList<>();
|
||||
List<ItemStack> oblack = new ArrayList<>();
|
||||
List<ItemStack> ovoid = new ArrayList<>();
|
||||
|
||||
int[] awhite = {0, 1, 9, 10, 18, 19};
|
||||
int[] ablack = {27, 28, 36, 37, 45, 46};
|
||||
@ -406,19 +406,19 @@ public class EHopper implements Hopper {
|
||||
for (int aa : awhite) {
|
||||
if (aa == num) {
|
||||
if (items2[num] != null && !items2[num].getType().name().contains("STAINED_GLASS") && items2[num].getType() != Material.AIR)
|
||||
owhite.add(items2[num].getType());
|
||||
owhite.add(items2[num]);
|
||||
}
|
||||
}
|
||||
for (int aa : ablack) {
|
||||
if (aa == num) {
|
||||
if (items2[num] != null && !items2[num].getType().name().contains("STAINED_GLASS") && items2[num].getType() != Material.AIR)
|
||||
oblack.add(items2[num].getType());
|
||||
oblack.add(items2[num]);
|
||||
}
|
||||
}
|
||||
for (int aa : avoid) {
|
||||
if (aa == num) {
|
||||
if (items2[num] != null && !items2[num].getType().equals(Material.BARRIER) && items2[num].getType() != Material.AIR)
|
||||
ovoid.add(items2[num].getType());
|
||||
ovoid.add(items2[num]);
|
||||
}
|
||||
}
|
||||
num++;
|
||||
|
@ -123,18 +123,18 @@ public class BlockListeners implements Listener {
|
||||
event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(), item);
|
||||
}
|
||||
|
||||
for (Material m : hopper.getFilter().getWhiteList()) {
|
||||
for (ItemStack m : hopper.getFilter().getWhiteList()) {
|
||||
if (m != null)
|
||||
event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(), new ItemStack(m));
|
||||
event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(),m);
|
||||
}
|
||||
|
||||
for (Material m : hopper.getFilter().getBlackList()) {
|
||||
for (ItemStack m : hopper.getFilter().getBlackList()) {
|
||||
if (m != null)
|
||||
event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(), new ItemStack(m));
|
||||
event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(), m);
|
||||
}
|
||||
for (Material m : hopper.getFilter().getVoidList()) {
|
||||
for (ItemStack m : hopper.getFilter().getVoidList()) {
|
||||
if (m != null)
|
||||
event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(), new ItemStack(m));
|
||||
event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(),m);
|
||||
}
|
||||
instance.getHopperManager().removeHopper(block.getLocation());
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
package com.songoda.epichoppers.storage;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class StorageItem {
|
||||
|
||||
@ -20,10 +23,11 @@ public class StorageItem {
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
public StorageItem(String key, List<Material> material) {
|
||||
String object = "";
|
||||
for (Material m : material) {
|
||||
object += m.name() + ";";
|
||||
public StorageItem(String key, List<ItemStack> material) {
|
||||
List<Map<String, Object>> object = new ArrayList<>();
|
||||
for (ItemStack m : material) {
|
||||
Map<String, Object> serialized = m.serialize();
|
||||
object.add(serialized);
|
||||
}
|
||||
this.key = key;
|
||||
this.object = object;
|
||||
@ -52,13 +56,12 @@ public class StorageItem {
|
||||
return object;
|
||||
}
|
||||
|
||||
public List<Material> asMaterialList() {
|
||||
List<Material> list = new ArrayList<>();
|
||||
public List<ItemStack> asItemStackList() {
|
||||
List<ItemStack> list = new ArrayList<>();
|
||||
if (object == null) return list;
|
||||
String[] stack = ((String)object).split(";");
|
||||
for (String item : stack) {
|
||||
if (item.equals("")) continue;
|
||||
list.add(Material.valueOf(item));
|
||||
List<Map<String,Object>> itemstacks = (List<Map<String, Object>>) object;
|
||||
for (Map<String, Object> serial:itemstacks) {
|
||||
list.add(ItemStack.deserialize(serial));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
public class StorageRow {
|
||||
|
||||
private final String key;
|
||||
|
||||
private final Map<String, StorageItem> items;
|
||||
|
Loading…
Reference in New Issue
Block a user