Unarmed.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package com.gmail.nossr50.skills.unarmed;
  2. import com.gmail.nossr50.util.sounds.SoundManager;
  3. import com.gmail.nossr50.util.sounds.SoundType;
  4. import org.bukkit.entity.Player;
  5. import org.bukkit.event.entity.EntityPickupItemEvent;
  6. import org.bukkit.inventory.ItemStack;
  7. public class Unarmed {
  8. // public static boolean blockCrackerSmoothBrick = MainConfig.getInstance().getUnarmedBlockCrackerSmoothbrickToCracked();
  9. public static double berserkDamageModifier = 1.5;
  10. public static long lastAttacked = 0;
  11. public static long attackInterval = 750;
  12. public static void handleItemPickup(Player player, EntityPickupItemEvent event) {
  13. ItemStack[] storageContents = player.getInventory().getStorageContents();
  14. ItemStack itemDrop = event.getItem().getItemStack();
  15. int heldItemSlotID = player.getInventory().getHeldItemSlot();
  16. int amount = itemDrop.getAmount();
  17. boolean grabbedItem = false;
  18. for (int i = 0; i <= storageContents.length - 1; i++) {
  19. if (amount <= 0)
  20. break;
  21. if (i == heldItemSlotID)
  22. continue;
  23. //EMPTY SLOT!
  24. if (storageContents[i] == null) {
  25. player.getInventory().setItem(i, itemDrop);
  26. amount = 0;
  27. grabbedItem = true;
  28. break;
  29. } else if (itemDrop.isSimilar(storageContents[i]) && storageContents[i].getAmount() < storageContents[i].getMaxStackSize()) {
  30. //If we can fit this whole itemstack into this item
  31. if (amount + storageContents[i].getAmount() <= storageContents[i].getMaxStackSize()) {
  32. ItemStack modifiedAmount = storageContents[i];
  33. modifiedAmount.setAmount(amount + storageContents[i].getAmount());
  34. player.getInventory().setItem(i, modifiedAmount);
  35. grabbedItem = true;
  36. amount = 0;
  37. } else {
  38. //Add what we can from this stack
  39. ItemStack modifiedAmount = storageContents[i];
  40. int amountThatCanFit = storageContents[i].getMaxStackSize() - storageContents[i].getAmount();
  41. modifiedAmount.setAmount(amountThatCanFit);
  42. player.getInventory().setItem(i, modifiedAmount);
  43. //Remove the amount we've added
  44. grabbedItem = true;
  45. amount -= amountThatCanFit;
  46. }
  47. }
  48. }
  49. if (amount <= 0)
  50. event.getItem().remove(); //Cleanup Item
  51. else
  52. event.getItem().getItemStack().setAmount(amount);
  53. event.setCancelled(true);
  54. if (grabbedItem) {
  55. SoundManager.sendSound(player, player.getLocation(), SoundType.POP);
  56. player.updateInventory();
  57. }
  58. }
  59. }