Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=false)
- public void onPickup(PlayerPickupItemEvent e) {
- Player player = e.getPlayer();
- Inventory inventory = player.getInventory();
- ItemStack[] contents = inventory.getContents();
- Item foundItem = e.getItem();
- ItemStack foundItemStack = foundItem.getItemStack();
- int invSize = inventory.getSize();
- for(int i = 0; i < invSize; i++) {
- ItemStack item = contents[i];
- if(item != null) {
- ItemMeta foundMeta = foundItem.getItemStack().getItemMeta();
- ItemMeta invMeta = item.getItemMeta();
- Material foundType = foundItem.getItemStack().getType();
- Material invType = item.getType();
- int foundAmount = foundItem.getItemStack().getAmount();
- int invAmount = item.getAmount();
- if(item.isSimilar(foundItemStack) && foundType == invType && foundMeta.isUnbreakable() && invMeta.isUnbreakable()) {
- int math = (foundAmount + invAmount);
- if(math < 65) {
- e.setCancelled(true);
- foundItemStack.setAmount(0);
- foundItem.remove();
- item.setAmount(foundAmount + invAmount);
- }else {
- System.out.println("Count invAmount before Loop: " + invAmount);
- System.out.println("Count foundAmount before Loop: " + foundAmount);
- while(invAmount <= 63 && foundAmount >= 1) {
- System.out.println("Count invAmount in Loop: " + invAmount);
- System.out.println("Count foundAmount in Loop: " + foundAmount);
- invAmount = invAmount + 1;
- foundAmount = foundAmount - 1;
- }
- System.out.println("Count invAmount as final result: " + invAmount);
- System.out.println("Count foundAmount as final result: " + foundAmount);
- e.setCancelled(true);
- foundItemStack.setAmount(foundAmount);
- foundItem.remove();
- item.setAmount(invAmount);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement