From dfd170d00110b01e39b6c09cc8c146022e144dc1 Mon Sep 17 00:00:00 2001 From: songoda Date: Wed, 18 Sep 2019 12:33:33 -0400 Subject: [PATCH] Added item stacking for items with a max stack size lower than 64. --- .../com/songoda/ultimatestacker/UltimateStacker.java | 9 +++++---- .../songoda/ultimatestacker/listeners/ItemListeners.java | 4 ++-- .../com/songoda/ultimatestacker/settings/Settings.java | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java b/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java index ff1c319..5d1c0b7 100644 --- a/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java +++ b/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java @@ -389,9 +389,9 @@ public class UltimateStacker extends SongodaPlugin { boolean blacklisted = isMaterialBlacklisted(itemStack); - if (newAmount > 32 && !blacklisted) { + if (newAmount > (itemStack.getMaxStackSize() / 2) && !blacklisted) { item.setMetadata("US_AMT", new FixedMetadataValue(INSTANCE, newAmount)); - itemStack.setAmount(32); + itemStack.setAmount(itemStack.getMaxStackSize() / 2); } else { item.removeMetadata("US_AMT", INSTANCE); itemStack.setAmount(newAmount); @@ -415,8 +415,9 @@ public class UltimateStacker extends SongodaPlugin { * @return stacker-corrected value for the stack size */ public static int getActualItemAmount(Item item) { - int amount = item.getItemStack().getAmount(); - if (amount >= 32 && item.hasMetadata("US_AMT")) { + ItemStack itemStack = item.getItemStack(); + int amount = itemStack.getAmount(); + if (amount >= (itemStack.getMaxStackSize() / 2) && item.hasMetadata("US_AMT")) { return item.getMetadata("US_AMT").get(0).asInt(); } else { return amount; diff --git a/src/main/java/com/songoda/ultimatestacker/listeners/ItemListeners.java b/src/main/java/com/songoda/ultimatestacker/listeners/ItemListeners.java index cf3f165..0c98a43 100644 --- a/src/main/java/com/songoda/ultimatestacker/listeners/ItemListeners.java +++ b/src/main/java/com/songoda/ultimatestacker/listeners/ItemListeners.java @@ -75,13 +75,13 @@ public class ItemListeners implements Listener { return; //Compatibility with Shop instance: https://www.spigotmc.org/resources/shop-a-simple-intuitive-shop-instance.9628/ } - UltimateStacker.updateItemAmount(event.getEntity(), itemStack, event.getEntity().getItemStack().getAmount()); + UltimateStacker.updateItemAmount(event.getEntity(), itemStack, itemStack.getAmount()); } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onPickup(PlayerPickupItemEvent event) { if (!Settings.STACK_ITEMS.getBoolean()) return; - if (event.getItem().getItemStack().getAmount() < 32) return; + if (event.getItem().getItemStack().getAmount() < (event.getItem().getItemStack().getMaxStackSize() / 2)) return; event.setCancelled(true); event.getPlayer().playSound(event.getPlayer().getLocation(), CompatibleSound.ENTITY_ITEM_PICKUP.getSound(), .2f, (float) (1 + Math.random())); diff --git a/src/main/java/com/songoda/ultimatestacker/settings/Settings.java b/src/main/java/com/songoda/ultimatestacker/settings/Settings.java index f685199..db2813c 100644 --- a/src/main/java/com/songoda/ultimatestacker/settings/Settings.java +++ b/src/main/java/com/songoda/ultimatestacker/settings/Settings.java @@ -179,7 +179,7 @@ public class Settings { "This is added only because it looks smoother in game. This is only visual and", "doesn't actually effect the item."); - public static final ConfigSetting ITEM_BLACKLIST = new ConfigSetting(config, "Items.Blacklist", Collections.singletonList("EGG"), + public static final ConfigSetting ITEM_BLACKLIST = new ConfigSetting(config, "Items.Blacklist", Collections.singletonList("BARRIER"), "Items included in this list will stack to default Minecraft 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",