use of org.bukkit.inventory.ItemStack in project BKCommonLib by bergerhealer.
the class InventoryTest method testItemStackConversion.
@Test
public void testItemStackConversion() {
ItemStack item = new ItemStack(Material.WOOD, 1);
Object nmsHandle = HandleConversion.toItemStackHandle(item);
assertNotNull(nmsHandle);
ItemStack itemBackConv = WrapperConversion.toItemStack(nmsHandle);
assertItemEquals(item, itemBackConv);
}
use of org.bukkit.inventory.ItemStack in project BKCommonLib by bergerhealer.
the class ItemMaterialTest method testEmptyItem.
@Test
public void testEmptyItem() {
ItemStack item = ItemUtil.emptyItem();
assertNotNull(item);
assertTrue(ItemUtil.isEmpty(item));
}
use of org.bukkit.inventory.ItemStack in project BKCommonLib by bergerhealer.
the class CraftRecipe method create.
/**
* Creates a new Craft Recipe from an IRecipe instance. This method is not
* recommended to be used.
*
* @param recipe to use
* @return the CraftRecipe, or null on failure
*/
@Deprecated
public static CraftRecipe create(Object recipe) {
final ItemStack output = NMSRecipe.getOutput(recipe);
final List<ItemStack> inputs = NMSRecipe.getInputItems(recipe);
if (inputs != null) {
return create(inputs, output);
} else {
return null;
}
}
use of org.bukkit.inventory.ItemStack in project Essentials by drtshock.
the class InventoryWorkaround method addOversizedItems.
// Returns what it couldn't store
// Set oversizedStack to below normal stack size to disable oversized stacks
public static Map<Integer, ItemStack> addOversizedItems(final Inventory inventory, final int oversizedStacks, final ItemStack... items) {
if (isCombinedInventory(inventory)) {
Inventory fakeInventory = makeTruncatedPlayerInventory((PlayerInventory) inventory);
Map<Integer, ItemStack> overflow = addOversizedItems(fakeInventory, oversizedStacks, items);
for (int i = 0; i < fakeInventory.getContents().length; i++) {
inventory.setItem(i, fakeInventory.getContents()[i]);
}
return overflow;
}
final Map<Integer, ItemStack> leftover = new HashMap<>();
/*
* TODO: some optimization - Create a 'firstPartial' with a 'fromIndex' - Record the lastPartial per Material -
* Cache firstEmpty result
*/
// combine items
final ItemStack[] combined = new ItemStack[items.length];
for (ItemStack item : items) {
if (item == null || item.getAmount() < 1) {
continue;
}
for (int j = 0; j < combined.length; j++) {
if (combined[j] == null) {
combined[j] = item.clone();
break;
}
if (combined[j].isSimilar(item)) {
combined[j].setAmount(combined[j].getAmount() + item.getAmount());
break;
}
}
}
for (int i = 0; i < combined.length; i++) {
final ItemStack item = combined[i];
if (item == null || item.getType() == Material.AIR) {
continue;
}
while (true) {
// Do we already have a stack of it?
final int maxAmount = oversizedStacks > item.getType().getMaxStackSize() ? oversizedStacks : item.getType().getMaxStackSize();
final int firstPartial = firstPartial(inventory, item, maxAmount);
// Drat! no partial stack
if (firstPartial == -1) {
// Find a free spot!
final int firstFree = inventory.firstEmpty();
if (firstFree == -1) {
// No space at all!
leftover.put(i, item);
break;
} else {
// More than a single stack!
if (item.getAmount() > maxAmount) {
final ItemStack stack = item.clone();
stack.setAmount(maxAmount);
inventory.setItem(firstFree, stack);
item.setAmount(item.getAmount() - maxAmount);
} else {
// Just store it
inventory.setItem(firstFree, item);
break;
}
}
} else {
// So, apparently it might only partially fit, well lets do just that
final ItemStack partialItem = inventory.getItem(firstPartial);
final int amount = item.getAmount();
final int partialAmount = partialItem.getAmount();
// Check if it fully fits
if (amount + partialAmount <= maxAmount) {
partialItem.setAmount(amount + partialAmount);
break;
}
// It fits partially
partialItem.setAmount(maxAmount);
item.setAmount(amount + partialAmount - maxAmount);
}
}
}
return leftover;
}
use of org.bukkit.inventory.ItemStack in project Essentials by drtshock.
the class SignProtection method checkIfSignsAreBroken.
private void checkIfSignsAreBroken(final Block block, final User player, final String username, final IEssentials ess) throws MaxMoneyException {
final Map<Location, SignProtectionState> signs = getConnectedSigns(block, player, username, false);
for (Map.Entry<Location, SignProtectionState> entry : signs.entrySet()) {
if (entry.getValue() != SignProtectionState.NOSIGN) {
final Block sign = entry.getKey().getBlock();
if (!hasAdjacentBlock(sign, block)) {
block.setType(Material.AIR);
final Trade trade = new Trade(new ItemStack(Material.SIGN, 1), ess);
trade.pay(player, OverflowType.DROP);
}
}
}
}
Aggregations