2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.skills.unarmed;
|
|
|
|
|
2019-01-15 07:11:58 +01:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2019-01-30 01:13:04 +01:00
|
|
|
import com.gmail.nossr50.util.sounds.SoundManager;
|
|
|
|
import com.gmail.nossr50.util.sounds.SoundType;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.entity.EntityPickupItemEvent;
|
2013-04-10 19:20:25 +02:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
public class Unarmed {
|
|
|
|
public static boolean blockCrackerSmoothBrick = Config.getInstance().getUnarmedBlockCrackerSmoothbrickToCracked();
|
|
|
|
public static double berserkDamageModifier = 1.5;
|
2013-04-10 19:20:25 +02:00
|
|
|
|
2019-01-30 01:13:04 +01:00
|
|
|
public static void handleItemPickup(Player player, EntityPickupItemEvent event) {
|
|
|
|
ItemStack[] storageContents = player.getInventory().getStorageContents();
|
|
|
|
ItemStack itemDrop = event.getItem().getItemStack();
|
|
|
|
int heldItemSlotID = player.getInventory().getHeldItemSlot();
|
|
|
|
|
|
|
|
int amount = itemDrop.getAmount();
|
|
|
|
boolean grabbedItem = false;
|
|
|
|
|
|
|
|
for(int i = 0; i <= storageContents.length-1; i++)
|
|
|
|
{
|
|
|
|
if(amount <= 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if(i == heldItemSlotID)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
//EMPTY SLOT!
|
|
|
|
if(storageContents[i] == null)
|
|
|
|
{
|
|
|
|
player.getInventory().setItem(i, itemDrop);
|
|
|
|
amount = 0;
|
|
|
|
grabbedItem = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if(itemDrop.isSimilar(storageContents[i]) && storageContents[i].getAmount() < storageContents[i].getMaxStackSize())
|
|
|
|
{
|
|
|
|
//If we can fit this whole itemstack into this item
|
|
|
|
if(amount + storageContents[i].getAmount() <= storageContents[i].getMaxStackSize())
|
|
|
|
{
|
|
|
|
ItemStack modifiedAmount = storageContents[i];
|
|
|
|
modifiedAmount.setAmount(amount + storageContents[i].getAmount());
|
|
|
|
|
|
|
|
player.getInventory().setItem(i, modifiedAmount);
|
|
|
|
grabbedItem = true;
|
|
|
|
amount = 0;
|
|
|
|
} else {
|
|
|
|
//Add what we can from this stack
|
|
|
|
ItemStack modifiedAmount = storageContents[i];
|
|
|
|
int amountThatCanFit = storageContents[i].getMaxStackSize() - storageContents[i].getAmount();
|
|
|
|
modifiedAmount.setAmount(amountThatCanFit);
|
|
|
|
|
|
|
|
player.getInventory().setItem(i, modifiedAmount);
|
|
|
|
|
|
|
|
//Remove the amount we've added
|
|
|
|
grabbedItem = true;
|
|
|
|
amount -= amountThatCanFit;
|
2013-04-10 19:20:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-30 01:13:04 +01:00
|
|
|
if(amount <= 0)
|
|
|
|
event.getItem().remove(); //Cleanup Item
|
|
|
|
else
|
|
|
|
event.getItem().getItemStack().setAmount(amount);
|
2013-04-10 19:20:25 +02:00
|
|
|
|
2019-01-30 01:13:04 +01:00
|
|
|
event.setCancelled(true);
|
2014-04-05 13:13:33 +02:00
|
|
|
|
2019-01-30 01:13:04 +01:00
|
|
|
if(grabbedItem)
|
|
|
|
{
|
|
|
|
SoundManager.sendSound(player, player.getLocation(), SoundType.POP);
|
|
|
|
player.updateInventory();
|
2014-01-20 22:58:40 +01:00
|
|
|
}
|
2013-04-10 19:20:25 +02:00
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|