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