Search in sources :

Example 11 with PlayerInventory

use of org.bukkit.inventory.PlayerInventory in project Essentials by drtshock.

the class InventoryWorkaround method addAllItems.

// Returns what it couldn't store
// This will will abort if it couldn't store all items
public static Map<Integer, ItemStack> addAllItems(final Inventory inventory, final ItemStack... items) {
    ItemStack[] contents = inventory.getContents();
    final Inventory fakeInventory;
    if (isCombinedInventory(inventory)) {
        fakeInventory = makeTruncatedPlayerInventory((PlayerInventory) inventory);
    } else {
        fakeInventory = Bukkit.getServer().createInventory(null, inventory.getType());
        fakeInventory.setContents(contents);
    }
    Map<Integer, ItemStack> overflow = addItems(fakeInventory, items);
    if (overflow.isEmpty()) {
        addItems(inventory, items);
        return null;
    }
    return addItems(fakeInventory, items);
}
Also used : PlayerInventory(org.bukkit.inventory.PlayerInventory) ItemStack(org.bukkit.inventory.ItemStack) PlayerInventory(org.bukkit.inventory.PlayerInventory) Inventory(org.bukkit.inventory.Inventory)

Example 12 with PlayerInventory

use of org.bukkit.inventory.PlayerInventory in project Essentials by drtshock.

the class InventoryWorkaround method makeTruncatedPlayerInventory.

private static Inventory makeTruncatedPlayerInventory(PlayerInventory playerInventory) {
    Inventory fakeInventory = Bukkit.getServer().createInventory(null, USABLE_PLAYER_INV_SIZE);
    fakeInventory.setContents(Arrays.copyOf(playerInventory.getContents(), fakeInventory.getSize()));
    return fakeInventory;
}
Also used : PlayerInventory(org.bukkit.inventory.PlayerInventory) Inventory(org.bukkit.inventory.Inventory)

Aggregations

PlayerInventory (org.bukkit.inventory.PlayerInventory)12 ItemStack (org.bukkit.inventory.ItemStack)8 Inventory (org.bukkit.inventory.Inventory)4 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2 Location (org.bukkit.Location)2 PotionEffect (org.bukkit.potion.PotionEffect)2 MapDisplayInfo (com.bergerkiller.bukkit.common.internal.CommonMapController.MapDisplayInfo)1 ResultSet (java.sql.ResultSet)1 HashMap (java.util.HashMap)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 GlowServer (net.glowstone.GlowServer)1 CompoundTag (net.glowstone.util.nbt.CompoundTag)1 GameMode (org.bukkit.GameMode)1 Material (org.bukkit.Material)1 HorseInventory (org.bukkit.inventory.HorseInventory)1 ItemMeta (org.bukkit.inventory.meta.ItemMeta)1