Skip to content

Commit

Permalink
🐛 fix(InventoryFilter): Fix #58. Check against display name aswell as…
Browse files Browse the repository at this point in the history
… material type
  • Loading branch information
ProfElements committed Apr 10, 2021
1 parent 2d2d05b commit e62bcb6
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
import org.bukkit.inventory.ItemStack;

import javax.annotation.Nonnull;

import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;

public class InventoryFilterListener implements Listener {
Expand Down Expand Up @@ -46,19 +49,22 @@ private void checkAndFilter(Player p) {
}

private void filterInventory(@Nonnull Player p, @Nonnull PlayerBackpack backpack) {
List<String> blacklistedStrings = new ArrayList<String>();
for (ItemStack item : backpack.getInventory().getContents()) {
if (item != null && item.getType() != Material.AIR) {
blacklistedMaterials.add(item.getType());
blacklistedStrings.add(item.getItemMeta().getDisplayName());
}

if (backpack.getInventory().isEmpty()) {
blacklistedMaterials.clear();
blacklistedStrings.clear();
}
}

//CANT DROP AIR SO HAVE TO ITERATE THROUGH THE INVENTORY
for (ItemStack item : p.getInventory().getStorageContents()) {
if (item != null && blacklistedMaterials.contains(item.getType())) {
if (item != null && blacklistedMaterials.contains(item.getType()) && blacklistedStrings.contains(item.getItemMeta().getDisplayName())) {
item.setAmount(0);
break;
}
Expand Down

0 comments on commit e62bcb6

Please sign in to comment.