added hopper support.

This commit is contained in:
Brianna O'Keefe 2018-11-11 15:21:35 -05:00
parent 8b8e2c3018
commit 1e01dcd4ec
2 changed files with 33 additions and 0 deletions

6
.gitignore vendored
View File

@ -152,3 +152,9 @@ target/classes/com/songoda/ultimatestacker/events/InteractListeners\.class
target/classes/com/songoda/ultimatestacker/utils/Reflection\.class
target/classes/com/songoda/ultimatestacker/utils/ServerVersion\.class
target/classes/com/songoda/ultimatestacker/command/commands/CommandRemoveAll\.class
target/classes/com/songoda/ultimatestacker/command/commands/CommandSettings\.class
target/classes/SettingDefinitions\.yml

View File

@ -7,6 +7,7 @@ import org.bukkit.Material;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
@ -21,6 +22,32 @@ public class InteractListeners implements Listener {
this.instance = instance;
}
@EventHandler
public void onAccept(InventoryPickupItemEvent event) {
ItemStack item = event.getItem().getItemStack();
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.getInventory().addItem(newItem);
amt = amt - max;
}
ItemStack newItem = new ItemStack(item);
newItem.setAmount(amt);
event.getInventory().addItem(newItem);
}
@EventHandler
public void onInteract(PlayerInteractAtEntityEvent event) {
Player player = event.getPlayer();