mirror of
https://github.com/GeorgH93/Minepacks.git
synced 2025-01-31 23:11:30 +01:00
Add item filter whitelist mode (closes #44)
This commit is contained in:
parent
c40c6ee812
commit
eeb3770de0
@ -126,6 +126,8 @@ Shulkerboxes:
|
|||||||
ItemFilter:
|
ItemFilter:
|
||||||
# Enables the item filter. Make sure to define items to be filtered.
|
# Enables the item filter. Make sure to define items to be filtered.
|
||||||
Enable: false
|
Enable: false
|
||||||
|
# Changes the filter mode, either blacklist (only not listed materials are allowed) or whitelist (only listed materials are allowed)
|
||||||
|
Mode: blacklist
|
||||||
# List off items not allowed in the backpack. Can be name or id (id only for MC versions older than 1.13!).
|
# List off items not allowed in the backpack. Can be name or id (id only for MC versions older than 1.13!).
|
||||||
Blacklist: []
|
Blacklist: []
|
||||||
|
|
||||||
@ -175,4 +177,4 @@ Misc:
|
|||||||
UseBungeeCord: false
|
UseBungeeCord: false
|
||||||
|
|
||||||
# Config file version. Don't touch it!
|
# Config file version. Don't touch it!
|
||||||
Version: 22
|
Version: 23
|
@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
public class Config extends Configuration implements DatabaseConnectionConfiguration
|
public class Config extends Configuration implements DatabaseConnectionConfiguration
|
||||||
{
|
{
|
||||||
private static final int CONFIG_VERSION = 22, UPGRADE_THRESHOLD = 22, PRE_V2_VERSION = 20;
|
private static final int CONFIG_VERSION = 23, UPGRADE_THRESHOLD = CONFIG_VERSION, PRE_V2_VERSION = 20;
|
||||||
|
|
||||||
public Config(JavaPlugin plugin)
|
public Config(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
@ -278,14 +278,21 @@ public boolean isShulkerboxesExistingDestroyEnabled()
|
|||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
//region Item filter
|
//region Item filter
|
||||||
|
public boolean isItemFilterEnabledNoShulker()
|
||||||
|
{
|
||||||
|
return getConfigE().getBoolean("ItemFilter.Enabled", false);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isItemFilterEnabled()
|
public boolean isItemFilterEnabled()
|
||||||
{
|
{
|
||||||
return getConfigE().getBoolean("ItemFilter.Enable", false) || getConfigE().getBoolean("Shulkerboxes.PreventInBackpack", true);
|
return isItemFilterEnabledNoShulker() || getConfigE().getBoolean("Shulkerboxes.PreventInBackpack", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<MinecraftMaterial> getItemFilterBlacklist()
|
public Collection<MinecraftMaterial> getItemFilterBlacklist()
|
||||||
{
|
{
|
||||||
|
if(!isItemFilterEnabledNoShulker()) return new LinkedList<>();
|
||||||
List<String> stringBlacklist = getConfigE().getStringList("ItemFilter.Blacklist", new LinkedList<>());
|
List<String> stringBlacklist = getConfigE().getStringList("ItemFilter.Blacklist", new LinkedList<>());
|
||||||
|
if(isItemFilterModeWhitelist()) stringBlacklist.add("air");
|
||||||
Collection<MinecraftMaterial> blacklist = new LinkedList<>();
|
Collection<MinecraftMaterial> blacklist = new LinkedList<>();
|
||||||
for(String item : stringBlacklist)
|
for(String item : stringBlacklist)
|
||||||
{
|
{
|
||||||
@ -294,6 +301,11 @@ public Collection<MinecraftMaterial> getItemFilterBlacklist()
|
|||||||
}
|
}
|
||||||
return blacklist;
|
return blacklist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isItemFilterModeWhitelist()
|
||||||
|
{
|
||||||
|
return getConfigE().getString("ItemFilter.Mode", "blacklist").toLowerCase(Locale.ENGLISH).equals("whitelist") && isItemFilterEnabledNoShulker();
|
||||||
|
}
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
//region World settings
|
//region World settings
|
||||||
|
@ -40,13 +40,15 @@ public class ItemFilter extends MinepacksListener implements at.pcgamingfreaks.M
|
|||||||
{
|
{
|
||||||
public final Message messageNotAllowedInBackpack;
|
public final Message messageNotAllowedInBackpack;
|
||||||
public final ItemNameResolver itemNameResolver;
|
public final ItemNameResolver itemNameResolver;
|
||||||
|
private final boolean whitelistMode;
|
||||||
private final Collection<MinecraftMaterial> blockedMaterials = new HashSet<>();
|
private final Collection<MinecraftMaterial> blockedMaterials = new HashSet<>();
|
||||||
|
|
||||||
public ItemFilter(final Minepacks plugin)
|
public ItemFilter(final Minepacks plugin)
|
||||||
{
|
{
|
||||||
super(plugin);
|
super(plugin);
|
||||||
|
|
||||||
if(plugin.getConfiguration().isShulkerboxesPreventInBackpackEnabled())
|
whitelistMode = plugin.getConfiguration().isItemFilterModeWhitelist();
|
||||||
|
if(plugin.getConfiguration().isShulkerboxesPreventInBackpackEnabled() && !whitelistMode)
|
||||||
{
|
{
|
||||||
for(Material mat : DisableShulkerboxes.SHULKER_BOX_MATERIALS)
|
for(Material mat : DisableShulkerboxes.SHULKER_BOX_MATERIALS)
|
||||||
{
|
{
|
||||||
@ -78,6 +80,12 @@ public ItemFilter(final Minepacks plugin)
|
|||||||
/*end[STANDALONE]*/
|
/*end[STANDALONE]*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isItemBlocked(ItemStack item)
|
||||||
|
{
|
||||||
|
return whitelistMode ^ blockedMaterials.contains(new MinecraftMaterial(item));
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onItemMove(InventoryMoveItemEvent event)
|
public void onItemMove(InventoryMoveItemEvent event)
|
||||||
{
|
{
|
||||||
@ -92,7 +100,7 @@ public void onItemMove(InventoryMoveItemEvent event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onItemMove(InventoryClickEvent event)
|
public void onItemClick(InventoryClickEvent event)
|
||||||
{
|
{
|
||||||
if(event.getInventory().getHolder() instanceof Backpack)
|
if(event.getInventory().getHolder() instanceof Backpack)
|
||||||
{
|
{
|
||||||
@ -124,10 +132,4 @@ public void onItemMove(InventoryDragEvent event)
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isItemBlocked(ItemStack item)
|
|
||||||
{
|
|
||||||
return blockedMaterials.contains(new MinecraftMaterial(item));
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user