Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. @EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=false)
  2. public void onPickup(PlayerPickupItemEvent e) {
  3. Player player = e.getPlayer();
  4. Inventory inventory = player.getInventory();
  5. ItemStack[] contents = inventory.getContents();
  6. Item foundItem = e.getItem();
  7. ItemStack foundItemStack = foundItem.getItemStack();
  8. int invSize = inventory.getSize();
  9. for(int i = 0; i < invSize; i++) {
  10. ItemStack item = contents[i];
  11. if(item != null) {
  12.  
  13. ItemMeta foundMeta = foundItem.getItemStack().getItemMeta();
  14. ItemMeta invMeta = item.getItemMeta();
  15.  
  16. Material foundType = foundItem.getItemStack().getType();
  17. Material invType = item.getType();
  18.  
  19. int foundAmount = foundItem.getItemStack().getAmount();
  20. int invAmount = item.getAmount();
  21.  
  22. if(item.isSimilar(foundItemStack) && foundType == invType && foundMeta.isUnbreakable() && invMeta.isUnbreakable()) {
  23. int math = (foundAmount + invAmount);
  24. if(math < 65) {
  25. e.setCancelled(true);
  26. foundItemStack.setAmount(0);
  27. foundItem.remove();
  28. item.setAmount(foundAmount + invAmount);
  29.  
  30. }else {
  31. System.out.println("Count invAmount before Loop: " + invAmount);
  32. System.out.println("Count foundAmount before Loop: " + foundAmount);
  33. while(invAmount <= 63 && foundAmount >= 1) {
  34. System.out.println("Count invAmount in Loop: " + invAmount);
  35. System.out.println("Count foundAmount in Loop: " + foundAmount);
  36. invAmount = invAmount + 1;
  37. foundAmount = foundAmount - 1;
  38.  
  39. }
  40. System.out.println("Count invAmount as final result: " + invAmount);
  41. System.out.println("Count foundAmount as final result: " + foundAmount);
  42. e.setCancelled(true);
  43. foundItemStack.setAmount(foundAmount);
  44. foundItem.remove();
  45. item.setAmount(invAmount);
  46.  
  47. }
  48. }
  49.  
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement