Add lore filter

This commit is contained in:
GeorgH93 2020-02-15 03:08:42 +01:00
parent daa1642e2a
commit 519b27713f
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
3 changed files with 24 additions and 1 deletions

View File

@ -137,6 +137,8 @@ ItemFilter:
Materials: [] Materials: []
# List of names that should be filtered. Must match the display name of the item exactly. & color codes will be converted automatically. # List of names that should be filtered. Must match the display name of the item exactly. & color codes will be converted automatically.
Names: [] Names: []
# List of lore that should be filtered. Can be a single line or all lines of the lore.
Lore: []
# This settings allow control over how the plugin behave in different worlds # This settings allow control over how the plugin behave in different worlds
WorldSettings: WorldSettings:

View File

@ -312,6 +312,14 @@ public Set<String> getItemFilterNames()
return names; return names;
} }
public Set<String> getItemFilterLore()
{
if(!isItemFilterEnabledNoShulker()) return new HashSet<>();
Set<String> loreSet = new HashSet<>();
getConfigE().getStringList("ItemFilter.Lore", new LinkedList<>()).forEach(lore -> loreSet.add(ChatColor.translateAlternateColorCodes('&', lore)));
return loreSet;
}
public boolean isItemFilterModeWhitelist() public boolean isItemFilterModeWhitelist()
{ {
return getConfigE().getString("ItemFilter.Mode", "blacklist").toLowerCase(Locale.ENGLISH).equals("whitelist") && isItemFilterEnabledNoShulker(); return getConfigE().getString("ItemFilter.Mode", "blacklist").toLowerCase(Locale.ENGLISH).equals("whitelist") && isItemFilterEnabledNoShulker();

View File

@ -45,7 +45,7 @@ public class ItemFilter extends MinepacksListener implements at.pcgamingfreaks.M
public final ItemNameResolver itemNameResolver; public final ItemNameResolver itemNameResolver;
private final boolean whitelistMode; private final boolean whitelistMode;
private final Collection<MinecraftMaterial> filteredMaterials = new HashSet<>(); private final Collection<MinecraftMaterial> filteredMaterials = new HashSet<>();
private final Set<String> filteredNames; private final Set<String> filteredNames, filteredLore;
public ItemFilter(final Minepacks plugin) public ItemFilter(final Minepacks plugin)
{ {
@ -61,6 +61,7 @@ public ItemFilter(final Minepacks plugin)
} }
filteredMaterials.addAll(plugin.getConfiguration().getItemFilterMaterials()); filteredMaterials.addAll(plugin.getConfiguration().getItemFilterMaterials());
filteredNames = plugin.getConfiguration().getItemFilterNames(); filteredNames = plugin.getConfiguration().getItemFilterNames();
filteredLore = plugin.getConfiguration().getItemFilterLore();
messageNotAllowedInBackpack = plugin.getLanguage().getMessage("Ingame.NotAllowedInBackpack").replaceAll("\\{ItemName}", "%s"); messageNotAllowedInBackpack = plugin.getLanguage().getMessage("Ingame.NotAllowedInBackpack").replaceAll("\\{ItemName}", "%s");
@ -95,6 +96,18 @@ public boolean isItemBlocked(final @Nullable ItemStack item)
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
assert meta != null; //TODO remove after testing assert meta != null; //TODO remove after testing
if(meta.hasDisplayName() && filteredNames.contains(meta.getDisplayName())) return !whitelistMode; if(meta.hasDisplayName() && filteredNames.contains(meta.getDisplayName())) return !whitelistMode;
if(meta.hasLore() && !filteredLore.isEmpty())
{
StringBuilder loreBuilder = new StringBuilder();
//noinspection ConstantConditions
for(String loreLine : meta.getLore())
{
if(filteredLore.contains(loreLine)) return !whitelistMode;
if(loreBuilder.length() > 0) loreBuilder.append("\n");
loreBuilder.append(loreLine);
}
if(filteredLore.contains(loreBuilder.toString())) return !whitelistMode;
}
} }
return whitelistMode; return whitelistMode;
} }