bit shifting.

This commit is contained in:
Brianna O'Keefe 2018-12-29 14:05:19 -05:00
parent ee981846b3
commit 6a7e1e53f3

View File

@ -3,6 +3,7 @@ package com.songoda.ultimatestacker.events;
import com.songoda.ultimatestacker.UltimateStacker;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.inventory.ItemStack;
@ -14,6 +15,34 @@ public class InventoryListeners implements Listener {
this.instance = instance;
}
@EventHandler
public void onMove(InventoryMoveItemEvent event) {
ItemStack item = event.getItem();
if (new ItemStack(item.getType()).getMaxStackSize() == item.getMaxStackSize()) return;
instance.getStackingTask().setMax(item, 0, true);
int amt = item.getAmount();
int max = item.getMaxStackSize();
if (amt <= max) return;
item.setAmount(max);
amt = amt - max;
while (amt > max) {
ItemStack newItem = new ItemStack(item);
newItem.setAmount(max);
event.getDestination().addItem(newItem);
amt = amt - max;
}
ItemStack newItem = new ItemStack(item);
newItem.setAmount(amt);
event.getDestination().addItem(newItem);
}
@EventHandler
public void onAccept(InventoryPickupItemEvent event) {
ItemStack item = event.getItem().getItemStack();