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;
|
2013-04-10 19:20:25 +02:00
|
|
|
import org.bukkit.entity.Item;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import org.bukkit.inventory.PlayerInventory;
|
|
|
|
|
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
|
|
|
|
|
|
|
public static boolean handleItemPickup(PlayerInventory inventory, Item drop) {
|
|
|
|
ItemStack dropStack = drop.getItemStack();
|
|
|
|
int firstEmpty = inventory.firstEmpty();
|
2013-08-03 17:34:55 +02:00
|
|
|
int dropAmount = dropStack.getAmount();
|
2013-04-10 19:20:25 +02:00
|
|
|
|
|
|
|
if (inventory.containsAtLeast(dropStack, 1)) {
|
|
|
|
int nextSlot = 0;
|
|
|
|
|
2016-12-17 23:32:16 +01:00
|
|
|
ItemStack[] items = inventory.getStorageContents();
|
|
|
|
for (ItemStack itemstack : items) {
|
2013-04-10 20:04:46 +02:00
|
|
|
if (dropStack.isSimilar(itemstack)) {
|
2013-04-10 19:20:25 +02:00
|
|
|
int itemAmount = itemstack.getAmount();
|
|
|
|
int itemMax = itemstack.getMaxStackSize();
|
|
|
|
|
|
|
|
ItemStack addStack = itemstack.clone();
|
|
|
|
|
2013-05-18 22:41:42 +02:00
|
|
|
if (dropAmount + itemAmount <= itemMax) {
|
2013-04-10 19:20:25 +02:00
|
|
|
drop.remove();
|
|
|
|
addStack.setAmount(dropAmount + itemAmount);
|
2016-12-17 23:32:16 +01:00
|
|
|
items[nextSlot] = addStack;
|
|
|
|
inventory.setStorageContents(items);
|
2013-04-10 19:20:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
addStack.setAmount(itemMax);
|
|
|
|
dropAmount = dropAmount + itemAmount - itemMax;
|
2016-12-17 23:32:16 +01:00
|
|
|
items[nextSlot] = addStack;
|
|
|
|
inventory.setStorageContents(items);
|
2013-04-10 19:20:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dropAmount == 0) {
|
|
|
|
drop.remove();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nextSlot++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (firstEmpty == inventory.getHeldItemSlot()) {
|
|
|
|
int nextSlot = firstEmpty + 1;
|
|
|
|
|
2016-12-17 23:32:16 +01:00
|
|
|
ItemStack[] items = inventory.getStorageContents();
|
|
|
|
for (; nextSlot < items.length; nextSlot++) {
|
|
|
|
ItemStack itemstack = items[nextSlot];
|
2013-04-10 19:20:25 +02:00
|
|
|
|
|
|
|
if (itemstack == null) {
|
|
|
|
drop.remove();
|
2013-08-03 17:34:55 +02:00
|
|
|
dropStack.setAmount(dropAmount);
|
2016-12-17 23:32:16 +01:00
|
|
|
items[nextSlot] = dropStack;
|
|
|
|
inventory.setStorageContents(items);
|
2013-04-10 19:20:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nextSlot++;
|
|
|
|
}
|
2014-04-05 13:13:33 +02:00
|
|
|
|
|
|
|
// Inventory is full - cancel the item pickup
|
2015-02-16 04:03:30 +01:00
|
|
|
if (dropStack.getAmount() == dropAmount) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
drop.remove();
|
|
|
|
dropStack.setAmount(dropAmount);
|
|
|
|
((Item) drop.getWorld().dropItem(drop.getLocation(), dropStack)).setPickupDelay(0);
|
|
|
|
return true;
|
|
|
|
}
|
2014-01-20 22:58:40 +01:00
|
|
|
}
|
|
|
|
else if (firstEmpty != -1) {
|
2013-08-04 17:38:52 +02:00
|
|
|
drop.remove();
|
2013-08-04 17:34:04 +02:00
|
|
|
dropStack.setAmount(dropAmount);
|
|
|
|
inventory.setItem(firstEmpty, dropStack);
|
|
|
|
return true;
|
2013-04-10 19:20:25 +02:00
|
|
|
}
|
|
|
|
|
2013-08-04 17:56:37 +02:00
|
|
|
drop.remove();
|
|
|
|
return true;
|
2013-04-10 19:20:25 +02:00
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|