2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.skills.unarmed;
|
|
|
|
|
2013-04-10 19:20:25 +02:00
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
import org.bukkit.entity.Item;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import org.bukkit.inventory.PlayerInventory;
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.config.AdvancedConfig;
|
|
|
|
import com.gmail.nossr50.config.Config;
|
|
|
|
|
|
|
|
public class Unarmed {
|
2013-09-12 20:18:13 +02:00
|
|
|
public static double ironArmMinBonusDamage = AdvancedConfig.getInstance().getIronArmMinBonus();
|
|
|
|
public static double ironArmMaxBonusDamage = AdvancedConfig.getInstance().getIronArmMaxBonus();
|
|
|
|
public static int ironArmIncreaseLevel = AdvancedConfig.getInstance().getIronArmIncreaseLevel();
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2014-05-11 15:14:46 +02:00
|
|
|
for (ItemStack itemstack : inventory) {
|
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);
|
|
|
|
inventory.setItem(nextSlot, addStack);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
addStack.setAmount(itemMax);
|
|
|
|
dropAmount = dropAmount + itemAmount - itemMax;
|
|
|
|
inventory.setItem(nextSlot, addStack);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dropAmount == 0) {
|
|
|
|
drop.remove();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nextSlot++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (firstEmpty == inventory.getHeldItemSlot()) {
|
|
|
|
int nextSlot = firstEmpty + 1;
|
|
|
|
|
2014-05-11 15:14:46 +02:00
|
|
|
for (Iterator<ItemStack> iterator = inventory.iterator(nextSlot); iterator.hasNext(); ) {
|
2013-04-10 19:20:25 +02:00
|
|
|
ItemStack itemstack = iterator.next();
|
|
|
|
|
|
|
|
if (itemstack == null) {
|
|
|
|
drop.remove();
|
2013-08-03 17:34:55 +02:00
|
|
|
dropStack.setAmount(dropAmount);
|
2013-04-10 19:20:25 +02:00
|
|
|
inventory.setItem(nextSlot, dropStack);
|
|
|
|
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
|
|
|
}
|