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: []
|
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:
|
||||||
|
@ -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();
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user