mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-12-26 02:17:38 +01:00
bit shifting.
This commit is contained in:
parent
ee981846b3
commit
6a7e1e53f3
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user