mirror of
https://github.com/GeorgH93/Minepacks.git
synced 2025-01-05 19:08:45 +01:00
Add option to filter by name #33
This commit is contained in:
parent
0070d5bb84
commit
d25e6c5b1e
@ -129,11 +129,14 @@ Shulkerboxes:
|
||||
|
||||
ItemFilter:
|
||||
# Enables the item filter. Make sure to define items to be filtered.
|
||||
Enable: false
|
||||
Enabled: false
|
||||
# Changes the filter mode, either blacklist (only not listed materials are allowed) or whitelist (only listed materials are allowed)
|
||||
Mode: blacklist
|
||||
# List off materials that should be filtered. Can be name or id (id only for MC versions older than 1.13!).
|
||||
# Filter lists bellow. An item will be blocked (in blacklist mode) or allowed (in whitelist mode) if it matches on of the given filters.
|
||||
# List of materials that should be filtered. Can be name or id (id only for MC versions older than 1.13!).
|
||||
Materials: []
|
||||
# List of names that should be filtered. Must match the display name of the item exactly. & color codes will be converted automatically.
|
||||
Names: []
|
||||
|
||||
# This settings allow control over how the plugin behave in different worlds
|
||||
WorldSettings:
|
||||
|
@ -304,6 +304,13 @@ public Collection<MinecraftMaterial> getItemFilterMaterials()
|
||||
return blacklist;
|
||||
}
|
||||
|
||||
public Set<String> getItemFilterNames()
|
||||
{
|
||||
Set<String> names = new HashSet<>();
|
||||
getConfigE().getStringList("ItemFilter.Names", new LinkedList<>()).forEach(name -> names.add(ChatColor.translateAlternateColorCodes('&', name)));
|
||||
return names;
|
||||
}
|
||||
|
||||
public boolean isItemFilterModeWhitelist()
|
||||
{
|
||||
return getConfigE().getString("ItemFilter.Mode", "blacklist").toLowerCase(Locale.ENGLISH).equals("whitelist") && isItemFilterEnabledNoShulker();
|
||||
|
@ -32,9 +32,11 @@
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
import org.bukkit.event.inventory.InventoryMoveItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class ItemFilter extends MinepacksListener implements at.pcgamingfreaks.Minepacks.Bukkit.API.ItemFilter
|
||||
{
|
||||
@ -42,6 +44,7 @@ public class ItemFilter extends MinepacksListener implements at.pcgamingfreaks.M
|
||||
public final ItemNameResolver itemNameResolver;
|
||||
private final boolean whitelistMode;
|
||||
private final Collection<MinecraftMaterial> filteredMaterials = new HashSet<>();
|
||||
private final Set<String> filteredNames;
|
||||
|
||||
public ItemFilter(final Minepacks plugin)
|
||||
{
|
||||
@ -56,6 +59,7 @@ public ItemFilter(final Minepacks plugin)
|
||||
}
|
||||
}
|
||||
filteredMaterials.addAll(plugin.getConfiguration().getItemFilterMaterials());
|
||||
filteredNames = plugin.getConfiguration().getItemFilterNames();
|
||||
|
||||
messageNotAllowedInBackpack = plugin.getLanguage().getMessage("Ingame.NotAllowedInBackpack").replaceAll("\\{ItemName}", "%s");
|
||||
|
||||
@ -83,7 +87,14 @@ public ItemFilter(final Minepacks plugin)
|
||||
@Override
|
||||
public boolean isItemBlocked(ItemStack item)
|
||||
{
|
||||
return whitelistMode ^ filteredMaterials.contains(new MinecraftMaterial(item));
|
||||
if(filteredMaterials.contains(new MinecraftMaterial(item))) return !whitelistMode;
|
||||
if(item.hasItemMeta())
|
||||
{
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
assert meta != null; //TODO remove after testing
|
||||
if(meta.hasDisplayName() && filteredNames.contains(meta.getDisplayName())) return !whitelistMode;
|
||||
}
|
||||
return whitelistMode;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
|
Loading…
Reference in New Issue
Block a user