Search in sources :

Example 26 with Inventory

use of org.bukkit.inventory.Inventory in project EliteMobs by MagmaGuy.

the class LootGUI method lootGUI.

public void lootGUI(Player player) {
    Inventory fakeChestInventory = Bukkit.createInventory(null, 54, "EliteMobs loot.yml");
    tierConstructor(fakeChestInventory);
    headerConstructor(fakeChestInventory);
    lootNavigationConstructor(fakeChestInventory);
    lootConstructor(fakeChestInventory);
    player.openInventory(fakeChestInventory);
}
Also used : Inventory(org.bukkit.inventory.Inventory)

Example 27 with Inventory

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

the class Commandinvsee method run.

//This method has a hidden param, which if given will display the equip slots. #easteregg
@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
    if (args.length < 1) {
        throw new NotEnoughArgumentsException();
    }
    final User invUser = getPlayer(server, user, args, 0);
    Inventory inv;
    if (args.length > 1 && user.isAuthorized("essentials.invsee.equip")) {
        inv = server.createInventory(invUser.getBase(), 9, "Equipped");
        inv.setContents(invUser.getBase().getInventory().getArmorContents());
    } else {
        inv = invUser.getBase().getInventory();
    }
    user.getBase().closeInventory();
    user.getBase().openInventory(inv);
    user.setInvSee(true);
}
Also used : User(com.earth2me.essentials.User) Inventory(org.bukkit.inventory.Inventory)

Example 28 with Inventory

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

the class SignFree method onSignInteract.

@Override
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException {
    ItemStack itemStack = getItemStack(sign.getLine(1), 1, ess);
    itemStack = getItemMeta(itemStack, sign.getLine(2), ess);
    final ItemStack item = getItemMeta(itemStack, sign.getLine(3), ess);
    if (item.getType() == Material.AIR) {
        throw new SignException(tl("cantSpawnItem", "Air"));
    }
    item.setAmount(item.getType().getMaxStackSize());
    ItemMeta meta = item.getItemMeta();
    final String displayName = meta.hasDisplayName() ? meta.getDisplayName() : item.getType().toString();
    Inventory invent = ess.getServer().createInventory(player.getBase(), 36, displayName);
    for (int i = 0; i < 36; i++) {
        invent.addItem(item);
    }
    player.getBase().openInventory(invent);
    Trade.log("Sign", "Free", "Interact", username, null, username, new Trade(item, ess), sign.getBlock().getLocation(), ess);
    return true;
}
Also used : Trade(com.earth2me.essentials.Trade) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Inventory(org.bukkit.inventory.Inventory)

Example 29 with Inventory

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

the class EssentialsPlayerListener method onInventoryCloseEvent.

@EventHandler(priority = EventPriority.MONITOR)
public void onInventoryCloseEvent(final InventoryCloseEvent event) {
    Player refreshPlayer = null;
    final Inventory top = event.getView().getTopInventory();
    final InventoryType type = top.getType();
    if (type == InventoryType.PLAYER) {
        final User user = ess.getUser((Player) event.getPlayer());
        user.setInvSee(false);
        refreshPlayer = user.getBase();
    } else if (type == InventoryType.ENDER_CHEST) {
        final User user = ess.getUser((Player) event.getPlayer());
        user.setEnderSee(false);
        refreshPlayer = user.getBase();
    } else if (type == InventoryType.WORKBENCH) {
        final User user = ess.getUser((Player) event.getPlayer());
        if (user.isRecipeSee()) {
            user.setRecipeSee(false);
            event.getView().getTopInventory().clear();
            refreshPlayer = user.getBase();
        }
    } else if (type == InventoryType.CHEST && top.getSize() == 9) {
        final InventoryHolder invHolder = top.getHolder();
        if (invHolder != null && invHolder instanceof HumanEntity) {
            final User user = ess.getUser((Player) event.getPlayer());
            user.setInvSee(false);
            refreshPlayer = user.getBase();
        }
    }
    if (refreshPlayer != null) {
        final Player player = refreshPlayer;
        ess.scheduleSyncDelayedTask(new Runnable() {

            @Override
            public void run() {
                player.updateInventory();
            }
        }, 1);
    }
}
Also used : Player(org.bukkit.entity.Player) InventoryType(org.bukkit.event.inventory.InventoryType) HumanEntity(org.bukkit.entity.HumanEntity) InventoryHolder(org.bukkit.inventory.InventoryHolder) Inventory(org.bukkit.inventory.Inventory) EventHandler(org.bukkit.event.EventHandler)

Example 30 with Inventory

use of org.bukkit.inventory.Inventory 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)

Aggregations

Inventory (org.bukkit.inventory.Inventory)31 ItemStack (org.bukkit.inventory.ItemStack)15 InventoryHolder (org.bukkit.inventory.InventoryHolder)8 Player (org.bukkit.entity.Player)6 EventHandler (org.bukkit.event.EventHandler)6 PlayerInventory (org.bukkit.inventory.PlayerInventory)4 HashMap (java.util.HashMap)3 ItemActionInfo (com.gamingmesh.jobs.actions.ItemActionInfo)2 JobsPlayer (com.gamingmesh.jobs.container.JobsPlayer)2 Block (org.bukkit.block.Block)2 HumanEntity (org.bukkit.entity.HumanEntity)2 InventoryType (org.bukkit.event.inventory.InventoryType)2 AnvilInventory (org.bukkit.inventory.AnvilInventory)2 CraftingInventory (org.bukkit.inventory.CraftingInventory)2 EnchantingInventory (org.bukkit.inventory.EnchantingInventory)2 EntityHandle (com.bergerkiller.generated.net.minecraft.server.EntityHandle)1 IInventoryHandle (com.bergerkiller.generated.net.minecraft.server.IInventoryHandle)1 CraftEntityHandle (com.bergerkiller.generated.org.bukkit.craftbukkit.entity.CraftEntityHandle)1 CraftInventoryHandle (com.bergerkiller.generated.org.bukkit.craftbukkit.inventory.CraftInventoryHandle)1 Trade (com.earth2me.essentials.Trade)1