From 16548d892246b69db1358f833b01299fe7dc59cc Mon Sep 17 00:00:00 2001 From: Brianna Date: Mon, 12 Aug 2019 22:55:31 -0400 Subject: [PATCH] Added blacklist/ability to hide holograms for blacklisted items. --- .../listeners/ItemListeners.java | 5 ++-- .../ultimatestacker/utils/Methods.java | 26 +++++++++++++------ .../utils/settings/Setting.java | 12 ++++++++- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/songoda/ultimatestacker/listeners/ItemListeners.java b/src/main/java/com/songoda/ultimatestacker/listeners/ItemListeners.java index e830433..ea7f2c3 100644 --- a/src/main/java/com/songoda/ultimatestacker/listeners/ItemListeners.java +++ b/src/main/java/com/songoda/ultimatestacker/listeners/ItemListeners.java @@ -5,6 +5,7 @@ import com.songoda.ultimatestacker.utils.Methods; import com.songoda.ultimatestacker.utils.ServerVersion; import com.songoda.ultimatestacker.utils.settings.Setting; import org.apache.commons.lang.StringUtils; +import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.Item; import org.bukkit.event.EventHandler; @@ -39,10 +40,8 @@ public class ItemListeners implements Listener { int specific = instance.getItemFile().getConfig().getInt("Items." + itemStack.getType().name() + ".Max Stack Size"); int max = specific == -1 && new ItemStack(itemStack.getType()).getMaxStackSize() != 1 ? maxItemStackSize : specific; - List whitelist = Setting.ITEM_WHITELIST.getStringList(); - if (!whitelist.isEmpty() && !whitelist.contains(itemStack.getType().name())) { + if (Methods.isMaterialBlacklisted(itemStack.getType())) max = new ItemStack(itemStack.getType()).getMaxStackSize(); - } if (max == -1) max = 1; diff --git a/src/main/java/com/songoda/ultimatestacker/utils/Methods.java b/src/main/java/com/songoda/ultimatestacker/utils/Methods.java index ee6cae9..a86ab2e 100644 --- a/src/main/java/com/songoda/ultimatestacker/utils/Methods.java +++ b/src/main/java/com/songoda/ultimatestacker/utils/Methods.java @@ -1,6 +1,5 @@ package com.songoda.ultimatestacker.utils; -import com.songoda.lootables.loot.Drop; import com.songoda.ultimatestacker.UltimateStacker; import com.songoda.ultimatestacker.utils.settings.Setting; import org.bukkit.*; @@ -14,7 +13,10 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.util.Vector; -import java.util.*; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.concurrent.ThreadLocalRandom; public class Methods { @@ -41,6 +43,13 @@ public class Methods { Methods.updateItemAmount(item, itemStack, amount); } + public static boolean isMaterialBlacklisted(Material type) { + List whitelist = Setting.ITEM_WHITELIST.getStringList(); + List blacklist = Setting.ITEM_BLACKLIST.getStringList(); + return !whitelist.isEmpty() && !whitelist.contains(type.name()) + || !blacklist.isEmpty() && blacklist.contains(type.name()); + } + public static void updateItemAmount(Item item, ItemStack itemStack, int newAmount) { UltimateStacker plugin = UltimateStacker.getInstance(); Material material = itemStack.getType(); @@ -55,12 +64,13 @@ public class Methods { itemStack.setAmount(newAmount); } - if (plugin.getItemFile().getConfig().getBoolean("Items." + material + ".Has Hologram") - && Setting.ITEM_HOLOGRAMS.getBoolean()) { - if (newAmount == 1 && !Setting.ITEM_HOLOGRAM_SINGLE.getBoolean()) return; - item.setCustomName(name); - item.setCustomNameVisible(true); - } + if ((isMaterialBlacklisted(itemStack.getType()) && !Setting.ITEM_HOLOGRAM_BLACKLIST.getBoolean()) + || !plugin.getItemFile().getConfig().getBoolean("Items." + material + ".Has Hologram") + || !Setting.ITEM_HOLOGRAMS.getBoolean() + || newAmount == 1 && !Setting.ITEM_HOLOGRAM_SINGLE.getBoolean()) return; + + item.setCustomName(name); + item.setCustomNameVisible(true); } public static int getActualItemAmount(Item item) { diff --git a/src/main/java/com/songoda/ultimatestacker/utils/settings/Setting.java b/src/main/java/com/songoda/ultimatestacker/utils/settings/Setting.java index 52d49bb..05de485 100644 --- a/src/main/java/com/songoda/ultimatestacker/utils/settings/Setting.java +++ b/src/main/java/com/songoda/ultimatestacker/utils/settings/Setting.java @@ -142,6 +142,9 @@ public enum Setting { "Should holograms be displayed above items when there is only a single", "item in the stack?"), + ITEM_HOLOGRAM_BLACKLIST("Items.Show Holograms For Blacklisted Items", true, + "Should items that are blacklisted display holograms?"), + MAX_STACK_ITEMS("Items.Max Stack Size", 512, "The max stack size for items.", "Currently this can only be set to a max of 120."), @@ -154,10 +157,17 @@ public enum Setting { "This is added only because it looks smoother in game. This is only visual and", "doesn't actually effect the item."), + ITEM_BLACKLIST("Items.Blacklist", Collections.singletonList("EGG"), + "Items included in this list will stack to normal amounts.", + "Material list: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html", + "Leave this empty by using \"blacklist: []\" if you do not wish to disable", + "stacking for any items."), + ITEM_WHITELIST("Items.Whitelist", new ArrayList(), "Items included in this whitelist will be stacked.", "Material list: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html", - "Leave this empty by using \"whitelist: []\" if you want everything to be stacked."), + "Leave this empty by using \"whitelist: []\" if you want everything to be stacked.", + "Items not in this list will act as if they are blacklisted."), SHOW_STACK_SIZE_SINGLE("Items.Show Stack Size For Single", false, "When enabled stack sizes for a stack with a single item will",