mirror of
https://github.com/GeorgH93/Minepacks.git
synced 2025-02-27 03:32:22 +01:00
Add lore filter
This commit is contained in:
parent
daa1642e2a
commit
519b27713f
@ -137,6 +137,8 @@ ItemFilter:
|
||||
Materials: []
|
||||
# List of names that should be filtered. Must match the display name of the item exactly. & color codes will be converted automatically.
|
||||
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
|
||||
WorldSettings:
|
||||
|
@ -312,6 +312,14 @@ public Set<String> getItemFilterNames()
|
||||
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()
|
||||
{
|
||||
return getConfigE().getString("ItemFilter.Mode", "blacklist").toLowerCase(Locale.ENGLISH).equals("whitelist") && isItemFilterEnabledNoShulker();
|
||||
|
@ -45,7 +45,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;
|
||||
private final Set<String> filteredNames, filteredLore;
|
||||
|
||||
public ItemFilter(final Minepacks plugin)
|
||||
{
|
||||
@ -61,6 +61,7 @@ public ItemFilter(final Minepacks plugin)
|
||||
}
|
||||
filteredMaterials.addAll(plugin.getConfiguration().getItemFilterMaterials());
|
||||
filteredNames = plugin.getConfiguration().getItemFilterNames();
|
||||
filteredLore = plugin.getConfiguration().getItemFilterLore();
|
||||
|
||||
messageNotAllowedInBackpack = plugin.getLanguage().getMessage("Ingame.NotAllowedInBackpack").replaceAll("\\{ItemName}", "%s");
|
||||
|
||||
@ -95,6 +96,18 @@ public boolean isItemBlocked(final @Nullable ItemStack item)
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
assert meta != null; //TODO remove after testing
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user