Added item stacking for items with a max stack size lower than 64.

This commit is contained in:
songoda 2019-09-18 12:33:33 -04:00
parent 92064fa86d
commit dfd170d001
3 changed files with 8 additions and 7 deletions

View File

@ -389,9 +389,9 @@ public class UltimateStacker extends SongodaPlugin {
boolean blacklisted = isMaterialBlacklisted(itemStack); boolean blacklisted = isMaterialBlacklisted(itemStack);
if (newAmount > 32 && !blacklisted) { if (newAmount > (itemStack.getMaxStackSize() / 2) && !blacklisted) {
item.setMetadata("US_AMT", new FixedMetadataValue(INSTANCE, newAmount)); item.setMetadata("US_AMT", new FixedMetadataValue(INSTANCE, newAmount));
itemStack.setAmount(32); itemStack.setAmount(itemStack.getMaxStackSize() / 2);
} else { } else {
item.removeMetadata("US_AMT", INSTANCE); item.removeMetadata("US_AMT", INSTANCE);
itemStack.setAmount(newAmount); itemStack.setAmount(newAmount);
@ -415,8 +415,9 @@ public class UltimateStacker extends SongodaPlugin {
* @return stacker-corrected value for the stack size * @return stacker-corrected value for the stack size
*/ */
public static int getActualItemAmount(Item item) { public static int getActualItemAmount(Item item) {
int amount = item.getItemStack().getAmount(); ItemStack itemStack = item.getItemStack();
if (amount >= 32 && item.hasMetadata("US_AMT")) { int amount = itemStack.getAmount();
if (amount >= (itemStack.getMaxStackSize() / 2) && item.hasMetadata("US_AMT")) {
return item.getMetadata("US_AMT").get(0).asInt(); return item.getMetadata("US_AMT").get(0).asInt();
} else { } else {
return amount; return amount;

View File

@ -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/ 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) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPickup(PlayerPickupItemEvent event) { public void onPickup(PlayerPickupItemEvent event) {
if (!Settings.STACK_ITEMS.getBoolean()) return; 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.setCancelled(true);
event.getPlayer().playSound(event.getPlayer().getLocation(), CompatibleSound.ENTITY_ITEM_PICKUP.getSound(), .2f, (float) (1 + Math.random())); event.getPlayer().playSound(event.getPlayer().getLocation(), CompatibleSound.ENTITY_ITEM_PICKUP.getSound(), .2f, (float) (1 + Math.random()));

View File

@ -179,7 +179,7 @@ public class Settings {
"This is added only because it looks smoother in game. This is only visual and", "This is added only because it looks smoother in game. This is only visual and",
"doesn't actually effect the item."); "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.", "Items included in this list will stack to default Minecraft amounts.",
"Material list: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html", "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", "Leave this empty by using \"blacklist: []\" if you do not wish to disable",