Java 类org.bukkit.inventory.Inventory 实例源码

项目:ProjectAres    文件:WoolMatchModule.java   
private void registerContainer(Inventory inv) {
    // When a chest (or other block inventory) is accessed, check if it's a wool chest
    Boolean isWoolChest = this.chests.get(inv);
    if(isWoolChest == null) {
        // If we haven't seen this chest yet, check it for wool
        isWoolChest = this.containsObjectiveWool(inv);
        this.chests.put(inv, isWoolChest);

        if(isWoolChest) {
            // If it is a wool chest, take a snapshot of the wools
            Map<Integer, ItemStack> contents = new HashMap<>();
            this.woolChests.put(inv, contents);
            for(int slot = 0; slot < inv.getSize(); ++slot) {
                ItemStack stack = inv.getItem(slot);
                if(stack != null && this.isObjectiveWool(stack)) {
                    contents.put(slot, stack.clone());
                }
            }
        }
    }
}
项目:AddGun    文件:Guns.java   
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void equipWeaponEvent(InventoryDragEvent event) {
    if (Result.DENY.equals(event.getResult())) return;
    HumanEntity human = event.getWhoClicked();

    Inventory inv = event.getInventory();
    ItemStack prior = event.getOldCursor();
    StandardGun priorGun = findGun(prior); 

    // Don't really care what sort of drag, if we have a gun in inv and this was a gun, deny.
    if (priorGun != null && inv != null && !InventoryType.PLAYER.equals(inv.getType()) && priorGun.isLimitToOne() && priorGun.hasGun(human)) {
        event.setResult(Result.DENY);
        // yes this will prevent drag style of weapon in chest invs. Oh well.
    }

}
项目:HCFCore    文件:EventTimer.java   
/**
 * Handles the winner for this event.
 *
 * @param winner
 *            the {@link Player} that won
 */
public void handleWinner(Player winner) {
    if (this.eventFaction == null)
        return;

    PlayerFaction playerFaction = plugin.getFactionManager().getPlayerFaction(winner);
    Bukkit.broadcastMessage(ChatColor.GOLD + "[" + "WIN" + "] " + ChatColor.RED + winner.getName() + ChatColor.AQUA
            + ChatColor.YELLOW + " has captured " + ChatColor.RED + this.eventFaction.getName()
            + ChatColor.YELLOW + " after " + ChatColor.RED + DurationFormatUtils.formatDurationWords(getUptime(), true, true) + " of up-time" + ChatColor.YELLOW + '.');

    EventType eventType = this.eventFaction.getEventType();
    World world = winner.getWorld();
    Location location = winner.getLocation();
    EventKey eventKey = plugin.getKeyManager().getEventKey();
    Collection<Inventory> inventories = eventKey.getInventories(eventType);
    ItemStack keyStack = eventKey.getItemStack(new EventKey.EventKeyData(eventType, inventories.isEmpty() ? 1 : plugin.getRandom().nextInt(inventories.size()) + 1));
    Map<Integer, ItemStack> excess = winner.getInventory().addItem(keyStack, EventSignListener.getEventSign(eventFaction.getName(), winner.getName()));
    for (ItemStack entry : excess.values()) {
        world.dropItemNaturally(location, entry);
    }

    this.clearCooldown(); // must always be cooled last as this nulls some variables.
}
项目:FactionsXL    文件:DemandMenu.java   
@EventHandler
public void onClick(InventoryClickEvent event) {
    HumanEntity player = event.getWhoClicked();
    Inventory inventory = event.getClickedInventory();
    if (inventory == null || gui == null || !gui.getTitle().equals(inventory.getTitle())) {
        return;
    }
    event.setCancelled(true);
    PageGUI.playSound(event);
    ItemStack button = event.getCurrentItem();
    if (BACK.equals(button)) {
        faction.getPopulationMenu().openDemands(player);
        return;
    }
    Resource resource = Resource.getByIcon(button);
    if (resource != null && faction.isPrivileged(player)) {
        saturationMenu.open(player, resource);
    }
}
项目:RealSurvival    文件:FireCraftTableRecipe.java   
public boolean isTrue(Inventory inv){
    short index=0;
    for(String s:shape)
        for(char c:s.toCharArray()){
            if(c==' ')
                if(inv.getItem(FireCraftTableGUI.mSlot.get(index++))==null)
                    continue;
                else 
                    return false;
            else{
                ItemStack is=inv.getItem(FireCraftTableGUI.mSlot.get(index++));
                if(is==null)return false;
                if(is.equals(materials.get(c)))
                    continue;
                else 
                    return false;
            }
        }
    return true;
}
项目:MCLibrary    文件:Inventories.java   
public static boolean takeItem(Inventory inv, ItemStack item, int takeAmount) {
    Set<Integer> removeSlots = new HashSet<>(takeAmount);
    for (int i = 0; i < inv.getSize(); i++) {
        ItemStack elemItem = inv.getItem(i);
        if (elemItem == null || elemItem.getType() == Material.AIR
                || !elemItem.isSimilar(item))
            continue;

        int amount = elemItem.getAmount();
        if (takeAmount > amount) {
            takeAmount -= amount;
            removeSlots.add(i);
        } else {
            if (takeAmount < amount) {
                elemItem.setAmount(amount - takeAmount);
            } else {
                removeSlots.add(i);
            }
            removeSlots.forEach(inv::clear);
            return true;
        }
    }
    return false;
}
项目:uppercore    文件:HotbarView.java   
public boolean tryToSaveSlot(int slot) {
    Inventory inv = player.getInventory();
    ItemStack item = inv.getItem(slot);
    if (item == null)
        return true;
    ListIterator<ItemStack> i = inv.iterator();
    while (i.hasNext()) {
        int ind = i.nextIndex();
        ItemStack itm = i.next();
        if (ind == slot || (ind < 9 && hotbarsBySlot[ind] != null))
            continue;
        if(itm == null) {
            i.set(item);
            return true;
        } else if (itm.isSimilar(item)) {
            int free = itm.getAmount() - itm.getMaxStackSize();
            if(item.getAmount() > free) {
                itm.setAmount(itm.getMaxStackSize());
            } else {
                itm.setAmount(itm.getAmount() + free);
                return true;
            }
        }
    }
    return false;
}
项目:AgarMC    文件:CellSpawner.java   
@Override
public void run() {
    AgarMC plugin = AgarMC.get();
    if (plugin.getGame().getPlayers().isEmpty())
        return ;

    if(plugin.getGame().getVirus().size() < plugin.getGame().getMaxVirus()) {
        VirusCell virus = new VirusCell(Utils.randomLocation(plugin.getGame().getOrigin().getX(), plugin.getGame().getDimensions()), Utils.randomLocation(plugin.getGame().getOrigin().getZ(), plugin.getGame().getDimensions()));
        plugin.getGame().addVirus(virus);
    }

    for (CPlayer player : plugin.getGame().getPlayers())
    {
        player.getPlayer().getInventory().setItem(1, updateColorBlock(player.getPlayer().getInventory().getItem(1)));
        InventoryView iv = player.getPlayer().getOpenInventory();
        if (iv == null)
            continue ;
        Inventory i = iv.getTopInventory();
        if (i == null || !i.getName().equals(MenuGui.INV_NAME))
            continue ;
        i.setItem(0, updateColorBlock(i.getItem(0)));
    }
}
项目:OMGPI    文件:BukkitEventHandler.java   
@EventHandler
public void event(BlockBreakEvent e) {
    new OMGBreakEvent(e, get(e.getPlayer()), e.getBlock());
    if (Area.registeredAreas.values().stream().anyMatch(a -> a.isInside(e.getBlock().getLocation())) && Area.registeredAreas.values().stream().noneMatch(a -> a.isInside(e.getBlock().getLocation()) && a.isBreakAllowed(get(e.getPlayer()).team, e.getBlock().getType()))) {
        e.setCancelled(true);
        return;
    }
    if (g.settings.isLootingOn && e.getBlock().getType() == Material.CHEST) {
        e.setCancelled(true);
        Inventory inv = ((Chest) e.getBlock().getState()).getBlockInventory();
        String lootid = inv.getTitle() == null ? "" : inv.getTitle();
        OMGLoot.LootParser lp = g.loot_contents(get(e.getPlayer()), lootid);
        if (lp != null) {
            inv.clear();
            for (int i = 0; i < inv.getSize(); i++) {
                ItemStack ii = lp.getRandom().toItem();
                if (ii != null && NBTParser.getTagCompound(ii).getByte("Undroppable") != 1)
                    e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), ii);
            }
        }
        e.getBlock().setType(Material.AIR);
        e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), new ItemStack(Material.CHEST));
    }
    if (!GameArea.isBlockInside(e.getBlock())) e.setCancelled(true);
}
项目:ProjectAres    文件:ViewInventoryMatchModule.java   
public void previewInventory(Player viewer, Inventory realInventory) {
    if(viewer == null) { return; }

    if(realInventory instanceof PlayerInventory) {
        previewPlayerInventory(viewer, (PlayerInventory) realInventory);
    }else {
        Inventory fakeInventory;
        if(realInventory instanceof DoubleChestInventory) {
            if(realInventory.hasCustomName()) {
                fakeInventory = Bukkit.createInventory(viewer, realInventory.getSize(), realInventory.getName());
            } else {
                fakeInventory = Bukkit.createInventory(viewer, realInventory.getSize());
            }
        } else {
            if(realInventory.hasCustomName()) {
                fakeInventory = Bukkit.createInventory(viewer, realInventory.getType(), realInventory.getName());
            } else {
                fakeInventory = Bukkit.createInventory(viewer, realInventory.getType());
            }
        }
        fakeInventory.setContents(realInventory.contents());

        this.showInventoryPreview(viewer, realInventory, fakeInventory);
    }
}
项目:OpenUHC    文件:BenchBlitz.java   
private void limitWorkbenches(Player player) {
  boolean workbench = false;
  Inventory inventory = player.getInventory();
  for (int slot = 0; slot < inventory.getSize(); ++slot) {
    ItemStack item = inventory.getItem(slot);
    if (item != null && item.getType().equals(Material.WORKBENCH)) {
      if (workbench) {
        inventory.setItem(slot, null);
      } else {
        workbench = true;
        item.setAmount(1);
        //TODO: Ensure that the amount of workbenches in the inventory updates on the client
      }
    }
  }
}
项目:EpicBanRequests    文件:GUIManager.java   
public static Inventory archived(Player player) {
    Inventory i = Bukkit.createInventory(null, 54, Messager.color("&7Archived Requests"));


    ItemStack back = new ItemStack(Material.ARROW);
    ItemMeta im = back.getItemMeta();
    im.setDisplayName(Messager.color("&cBack"));
    back.setItemMeta(im);       
    i.setItem(45, back);

    int tillFull = 0;
    for (int x = Main.getInstance().getConfig().getInt("current_id"); x <= 0; x--) {    

        if (tillFull >= 53) {
            Messager.msgPlayer("&cAll of the archived requests could not fit in the GUI. Showing the newest first.", player);
            break;
        }
        BanRequest br = new BanRequest(x);
        if (br.closed) {
            i.addItem(br.getArchivedItem());
            tillFull++;
        }
    }

    return i;
}
项目:FactionsXL    文件:PageGUICache.java   
@EventHandler
public void onClick(InventoryClickEvent event) {
    ItemStack button = event.getCurrentItem();
    if (button == null || button.getType() == Material.AIR) {
        return;
    }
    Inventory inventory = event.getInventory();
    PageGUI gui = PageGUI.getByInventory(inventory);
    if (gui == null) {
        return;
    }

    event.setCancelled(true);
    PageGUI.playSound(event);
    int index = gui.getPages().indexOf(inventory);
    HumanEntity player = event.getWhoClicked();
    if (button.equals(NEXT_PAGE)) {
        gui.open(player, index + 1);
    } else if (button.equals(PREVIOUS_PAGE)) {
        gui.open(player, index - 1);
    }
}
项目:ArmorPlus    文件:GUI.java   
public static void openGUI(Player p){
    Inventory inv = Bukkit.createInventory(null, 54, "장신구 장착");

    for(int i = 0; i < 54; i++)
        Util.stack("",101,0,1, Arrays.asList(""),i,inv);

    Util.stack("",1,0,0, Arrays.asList(""),20,inv);
    Util.stack("",1,0,0, Arrays.asList(""),21,inv);
    Util.stack("",1,0,0, Arrays.asList(""),22,inv);
    Util.stack("",1,0,0, Arrays.asList(""),23,inv);
    Util.stack("",1,0,0, Arrays.asList(""),24,inv);

    Util.stack("§e투구 장착",323,0,1, Arrays.asList(""),29,inv); // 모자
    Util.stack("§e갑옷 장착",323,0,1, Arrays.asList(""),30,inv);  // 옷
    Util.stack("§e바지 장착",323,0,1, Arrays.asList(""),31,inv);  // 바지
    Util.stack("§e신발 장착",323,0,1, Arrays.asList(""),32,inv);  // 신발
    Util.stack("§e반지 장착",323,0,1, Arrays.asList(""),33,inv);  // 반지

    p.openInventory(inv);
}
项目:SuperiorCraft    文件:CustomCraftingRecipe.java   
public boolean check(ItemStack[] a, Inventory inv) {
    boolean match = true;
    //System.out.println(inv.getName());
    //System.out.println(ncon);
    if (inv.getSize() == 9 && nCheck(inv.getName())) {
        for (int i = 0; i < recipe.length; i++) {
            if (match) {
                System.out.println(a[i]);
                System.out.println(recipe[i]);
                if (recipe[i] != null) {
                    match = recipe[i].equals(a[i]);
                }
                else {

                }
            }
        }
    } else {
        return false;
    }

    return match;
}
项目:ZorahPractice    文件:KitsMenu.java   
public static void open(Player player) {
    PracticeProfile profile = ManagerHandler.getPlayerManager().getPlayerProfile(player);

    if (profile.getStatus() != PlayerStatus.LOBBY) {
        player.sendMessage(ChatColor.RED + "You must be in the lobby to open that menu.");
        return;
    }

    Inventory inv = Bukkit.createInventory(null, ManagerHandler.getLadderManager().getLadderAmount(), ChatColor.RED + "Kit Editor");

    if (!ManagerHandler.getLadderManager().getLadders().isEmpty()) {
        for (Ladder ladder : ManagerHandler.getLadderManager().getLadders().values()) {
            if (ladder.allowEdit()) {
                inv.setItem(ladder.getDisplayOrder(), new ItemBuilder(ladder.getDisplayIcon().getType(), MessageUtils.color(ladder.getDisplayName()), 1, ladder.getDisplayIcon().getDurability(), ChatColor.GRAY + "Click to edit this ladder's kits.").getItem());
            }
        }
    }

    player.openInventory(inv);
}
项目:mczone    文件:VotePanelEvents.java   
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
    Player p = (Player) event.getWhoClicked();
    Inventory inv = event.getInventory();
    if (Chat.stripColor(inv.getTitle()).equalsIgnoreCase("Voting Panel")) {
        event.setCancelled(true);
        if (event.getRawSlot() > 9 || event.getCurrentItem() == null || event.getCurrentItem().getType() == Material.AIR)
            return;
        ItemStack i = event.getCurrentItem();
        Map m = Map.getByTitle(Chat.stripColor(i.getItemMeta().getDisplayName()));
        if (m != null) {
            m.addVote(p);
            p.closeInventory();
            event.setCancelled(true);
        }
    }
}
项目:NyaaCore    文件:InventoryUtils.java   
public static boolean hasEnoughSpace(Inventory inventory, ItemStack item, int amount) {
    for (int i = 0; i < inventory.getSize(); i++) {
        if (i >= 36 && i <= 39 && inventory instanceof PlayerInventory) {
            continue;
        }
        if (inventory.getItem(i) != null && item.isSimilar(inventory.getItem(i)) &&
                inventory.getItem(i).getAmount() < item.getMaxStackSize()) {
            amount -= item.getMaxStackSize() - inventory.getItem(i).getAmount();
        } else if (inventory.getItem(i) == null || inventory.getItem(i).getType() == Material.AIR) {
            amount = 0;
        }
        if (amount < 1) {
            return true;
        }
    }
    return false;
}
项目:RPGInventory    文件:InventoryListener.java   
@EventHandler(priority = EventPriority.LOW)
public void onInventoryOpen(InventoryOpenEvent event) {
    Inventory inventory = event.getInventory();
    HumanEntity player = event.getPlayer();

    if (!InventoryManager.playerIsLoaded(player)) {
        return;
    }

    if (InventoryAPI.isRPGInventory(inventory)) {
        PlayerWrapper playerWrapper = (PlayerWrapper) inventory.getHolder();
        InventoryManager.syncQuickSlots(playerWrapper);
        InventoryManager.syncInfoSlots(playerWrapper);
        InventoryManager.syncShieldSlot(playerWrapper);
        InventoryManager.syncArmor(playerWrapper);
    }
}
项目:mczone    文件:CompassEvents.java   
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
    Player p = (Player) event.getWhoClicked();
    Inventory inv = event.getInventory();

    if (p.getGameMode() != GameMode.CREATIVE)
        event.setCancelled(true);

    if (Chat.stripColor(inv.getTitle()).equalsIgnoreCase("MC Zone Games")) {
        if (event.getRawSlot() > 9 || event.getCurrentItem() == null || event.getCurrentItem().getType() == Material.AIR)
            return;
        GameIcon game = GameIcon.get(event.getCurrentItem());
        if (game != null) {
            p.teleport(game.getTo());
            p.closeInventory();
        }
    }
}
项目:AddGun    文件:RailGun.java   
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void equipWeaponEvent(InventoryDragEvent event) {
    if (!enabled) return;
    HumanEntity human = event.getWhoClicked();
    boolean alreadyHasGun = hasGun(human);

    Inventory inv = event.getInventory();
    ItemStack prior = event.getOldCursor();

    // Don't really care what sort of drag, if we have a gun in inv and this was a gun, deny.
    if (alreadyHasGun && (inv != null && !InventoryType.PLAYER.equals(inv.getType()))
            && (prior != null && isGun(prior))) {
        event.setResult(Result.DENY);
        // yes this will prevent drag style of weapon in chest invs. Oh well.
    }

}
项目:FactionsXL    文件:TradeOfferCommand.java   
private Inventory choosePartner(Faction creator) {
    int size = (int) (9 * Math.ceil(((double) factions.getActive().size() / 9)));
    Inventory gui = Bukkit.createInventory(null, size, FMessage.TRADE_OFFER_CHOOSE_PARTNER.getMessage());
    int i = 0;
    for (Faction faction : factions.getActive()) {
        ItemStack icon = faction.getBannerStack();
        ItemMeta meta = icon.getItemMeta();
        meta.setDisplayName(creator.getRelation(faction).getColor() + faction.getName());
        meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
        icon.setItemMeta(meta);
        gui.setItem(i, icon);
        factionBySlot.put(i, faction);
        i++;
    }
    return gui;
}
项目:NeverLag    文件:AntiNegativeItemDupe.java   
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onBlockDispense(BlockDispenseEvent e) {
    if (!cm.isAntiNegativeItemDupe) {
        return;
    }
    Inventory content = null;
    if (e.getBlock().getState() instanceof InventoryHolder) {
        content = ((InventoryHolder) e.getBlock().getState()).getInventory();
    }
    if (content == null || content.getSize() == 0) {
        return;
    }
    for (ItemStack item : content.getContents()) {
        if (item != null && item.getType() != Material.AIR) {
            if (item.getAmount() <= 0) {
                item.setType(Material.AIR);
            }
        }
    }
}
项目:ZentrelaCore    文件:MenuManager.java   
public static void registerListener(Player p, ItemStack item, Inventory inventory, Runnable runnable) {
    if (!invClickables.containsKey(p.getUniqueId()))
        invClickables.put(p.getUniqueId(), new HashMap<String, HashMap<String, Runnable>>());
    HashMap<String, HashMap<String, Runnable>> inventories = invClickables.get(p.getUniqueId());
    if (!inventories.containsKey(inventory.getName()))
        inventories.put(inventory.getName(), new HashMap<String, Runnable>());
    HashMap<String, Runnable> thisInv = inventories.get(inventory.getName());
    thisInv.put(serializeForMenu(item), runnable);
}
项目:AsgardAscension    文件:MainInventory.java   
public static void setupGodFoodInventory(Player player) {
    Inventory inv = Bukkit.createInventory(player, 9, ChatColor.BOLD + "Food of the Gods");
    inv.setItem(2, ItemStackGenerator.createItem(Material.SLIME_BALL, 0, 0,
            ChatColor.RED + "" + ChatColor.BOLD + "Add Food of the Gods", null));
    inv.setItem(4, ItemStackGenerator.createItem(Material.PAPER, 0, 0,
            ChatColor.RED + "" + ChatColor.BOLD + "Statistics", 
            Arrays.asList(ChatColor.GRAY + "Amount of God Foods: " + ChatColor.RED + GodFoodFile.getEffectAmount())));
    inv.setItem(6, ItemStackGenerator.createItem(Material.BOOK_AND_QUILL, 0, 0,
            ChatColor.RED + "" + ChatColor.BOLD + "Edit Food of the Gods", null));
    player.openInventory(inv);
}
项目:RPGInventory    文件:InventoryManager.java   
public static void updateQuickSlot(@NotNull Player player, @NotNull Inventory inventory, @NotNull Slot slot, int slotId,
                                   InventoryType.SlotType slotType, InventoryAction action,
                                   ItemStack currentItem, ItemStack cursor) {
    ActionType actionType = ActionType.getTypeOfAction(action);
    if (actionType == ActionType.GET) {
        if (slot.isCup(currentItem)) {
            return;
        }

        if (player.getInventory().getHeldItemSlot() == slot.getQuickSlot()) {
            InventoryUtils.heldFreeSlot(player, slot.getQuickSlot(), InventoryUtils.SearchType.NEXT);
        }

        if (slotType == InventoryType.SlotType.QUICKBAR && InventoryAPI.isRPGInventory(inventory)) {
            inventory.setItem(slot.getSlotId(), slot.getCup());
        } else {
            player.getInventory().setItem(slot.getQuickSlot(), slot.getCup());
        }

        action = InventoryAction.SWAP_WITH_CURSOR;
        cursor = slot.getCup();
    } else if (actionType == ActionType.SET) {
        if (slot.isCup(currentItem)) {
            currentItem = null;
            action = InventoryAction.PLACE_ALL;
        }

        if (slotType == InventoryType.SlotType.QUICKBAR && InventoryAPI.isRPGInventory(inventory)) {
            inventory.setItem(slot.getSlotId(), cursor);
        } else {
            player.getInventory().setItem(slot.getQuickSlot(), cursor);
        }
    }

    InventoryManager.updateInventory(player, inventory, slotId, slotType, action, currentItem, cursor);
}
项目:Transport-Pipes    文件:CreativeCommandExecutor.java   
@Override
public boolean onCommand(CommandSender cs, String[] args) {

    if (!cs.hasPermission("transportpipes.creative")) {
        return false;
    }

    if (cs instanceof Player) {
        Inventory inv = Bukkit.createInventory(null, 9 * 3, LocConf.load(LocConf.CREATIVE_TITLE));

        int i = 0;
        List<ItemStack> ductItems = DuctItemUtils.getAllDuctItems();
        for (ItemStack is : ductItems) {
            ItemStack clonedIs = is.clone();
            clonedIs.setAmount(16);
            inv.setItem(i, clonedIs);
            i++;
        }
        inv.setItem(i++, DuctItemUtils.getClonedWrenchItem());

        ((Player) cs).openInventory(inv);
    } else {
        cs.sendMessage("§cYou're not a player!");
    }

    return true;
}
项目:AlphaLibary    文件:Menu.java   
public void open(Player p, InventoryHolder holder) {
    Inventory inv = Bukkit.createInventory(holder, getSize(), getTitle());

    for (Map.Entry<Integer, MenuElement> element : this.elements.entrySet()) {
        inv.setItem(element.getKey(), element.getValue().getIcon(p));
    }

    getMenuManager().setMenuOpened(p, this);

    p.openInventory(inv);
}
项目:MCLibrary    文件:SimpleGUI.java   
@Override
protected Inventory createInventory() {
    GUIData data = getData();
    Inventory inv = data.type() == InventoryType.CHEST
            ? Bukkit.createInventory(null, data.size(), data.title())
            : Bukkit.createInventory(null, data.type(), data.title());
    inv.setContents(data.contents());
    return inv;
}
项目:ZorahPractice    文件:InventoryUtils.java   
public static Inventory inventoryFromString(String in) {
    Inventory inv = Bukkit.createInventory((InventoryHolder) null, 54);
    String[] split;
    @SuppressWarnings("unused")
    String[] data = split = in.split(";");

    for (String s : split) {
        String[] info = s.split("#");
        inv.setItem(Integer.parseInt(info[0]), (info.length > 1) ? itemStackFromString(info[1]) : null);
    }

    return inv;
}
项目:RPGInventory    文件:InventoryManager.java   
private static void updateInventory(
        @NotNull Player player,
        @NotNull Inventory inventory,
        int slot,
        InventoryAction action,
        ItemStack currentItem,
        @NotNull ItemStack cursor
) {
    InventoryManager.updateInventory(player, inventory, slot, InventoryType.SlotType.CONTAINER, action, currentItem, cursor);
}
项目:CustomRecipes    文件:ShapedAdder.java   
@EventHandler
public void onInventoryClose(InventoryCloseEvent event) {
    if (event.getInventory().getHolder() instanceof ShapedRecipeHolder) {
        ShapedRecipeHolder holder = (ShapedRecipeHolder) event.getInventory().getHolder();
        if (holder != this) return;

        Inventory inventory = event.getInventory();
        if (InventoryUtils.isEmpty(inventory)) {
            holder.callbackPlayer.sendMessage(ChatColor.RED + "Do you seriously want to create a recipe without ingredients?");
            return;
        }

        ShapedRecipes nmsRecipe = holder.toRecipe();
        CRShapedRecipe<ShapedRecipes> shapedRecipe = new CRShapedRecipe<>(nmsRecipe);
        List<List<String>> recipeIngredients = shapedRecipe.getIngredients().stream()
                .map((CRChoiceIngredient ingr) -> ingr.getChoices().stream()
                        .map(InventoryUtils::getItemName).collect(Collectors.toList()))
                .collect(Collectors.toList());
        String recipeString = recipeIngredients + "" +
                ChatColor.RESET + " -> " +
                InventoryUtils.getItemName(shapedRecipe.getResult());

        boolean success = holder.plugin.getCraftingManager().addRecipe(holder.key, nmsRecipe, shapedRecipe);
        if (success) {
            holder.callbackPlayer.sendMessage(String.format("%sAdded shaped recipe: %s%s%s!",
                    ChatColor.GREEN, ChatColor.WHITE, recipeString, ChatColor.WHITE));
            plugin.saveCraftingRecipeFile("shaped", shapedRecipe);
        } else {
            holder.callbackPlayer.sendMessage(ChatColor.RED + "Couldn't create a shaped recipe. Possibly a duplicate key.");
        }

        HandlerList.unregisterAll(holder);
    }
}
项目:CustomRecipes    文件:ListRecipesInventoryHolder.java   
public ListRecipesInventoryHolder(String type, Iterable<? extends ItemStack> items) {
    items.forEach(recipeItems::add);

    //fill page inventories
    int recipeIndex = 0;
    Inventory inventory = null;
    do {
        int inPageIndex = recipeIndex % MAX_RECIPES_PER_PAGE;
        if (inPageIndex == 0) {
            inventory = Bukkit.createInventory(this, 54, type + " recipes");
            pages.add(inventory);
        }

        inventory.setItem(inPageIndex, recipeItems.get(recipeIndex));
    } while (++recipeIndex < recipeItems.size());

    //add previous and next buttons where applicable
    for (int pageNr = 0; pageNr < pages.size(); pageNr++) {
        Inventory page = pages.get(pageNr);
        if (pageNr != 0) {
            page.setItem(45, ListRecipesListener.previousItem());
        }
        if (pageNr != pages.size() - 1) {
            page.setItem(53, ListRecipesListener.nextItem());
        }
    }
}
项目:RPGInventory    文件:MyPetManager.java   
@EventHandler
public void onMyPetItemUse(PlayerInteractEvent event) {
    if (event.getItem() != null) {
        Player player = event.getPlayer();

        if (!InventoryManager.playerIsLoaded(player)) {
            return;
        }

        Inventory inventory = InventoryManager.get(player).getInventory();

        if (isMyPetItem(event.getItem())
                && (event.getAction() == Action.RIGHT_CLICK_BLOCK
                || event.getAction() == Action.RIGHT_CLICK_AIR)) {
            Slot petSlot = getMyPetSlot();

            ItemStack currentPet = inventory.getItem(petSlot.getSlotId());
            boolean hasPet = !petSlot.isCup(currentPet);
            ItemStack newPet = event.getItem();

            if (!hasPet) {
                currentPet = null;
            }

            player.getEquipment().setItemInMainHand(currentPet);
            inventory.setItem(petSlot.getSlotId(), newPet);

            swapMyPets(player, hasPet, newPet);
        }
    }
}
项目:CloudNet    文件:MobSelector.java   
public Collection<Inventory> inventories()
{
    return CollectionWrapper.getCollection(this.mobs, new Catcher<Inventory, MobImpl>() {
        @Override
        public Inventory doCatch(MobImpl key)
        {
            return key.getInventory();
        }
    });
}
项目:CloudNet    文件:MobSelector.java   
public MobImpl find(Inventory inventory)
{
    return CollectionWrapper.filter(this.mobs.values(), new Acceptable<MobImpl>() {
        @Override
        public boolean isAccepted(MobImpl value)
        {
            return value.getInventory().equals(inventory);
        }
    });
}
项目:NeverLag    文件:GUISortPing.java   
public Inventory getNextPage() {
    if (this.page >= this.maxPage) {
        if (this.guiMaker != null) {
            return this.guiMaker.get();
        } else {
            return get(this.page);
        }
    } else {
        this.page++;
        return get(this.page);
    }
}
项目:Transport-Pipes    文件:SettingsInv.java   
private static void populateInventoryLine(Inventory inv, int row, ItemStack... items) {
    for (int i = 0; i < 9; i++) {
        if (items.length > i && items[i] != null) {
            ItemStack is = items[i];
            inv.setItem(row * 9 + i, is);
        }
    }
}
项目:PA    文件:BagEvents.java   
private static Inventory getInventory(TOAUser p) {
    Inventory i = Bukkit.createInventory(null, getInvSize(p), ChatColor.RED + "Mochila");
    ItemStack[] item = i.getContents();
    if (FileUtils.getInv().contains(p.getName())) {
        for (int x = 0; x < getInvSize(p); x++)
            item[x] = FileUtils.getInv().getItemStack(p.getName() + ".inv_" + x);
        i.setContents(item);
        return i;
    }
    return i;
}
项目:ProjectAres    文件:GizmoUtils.java   
public static void openMenu(Player player) {
    Inventory inventory = Bukkit.createInventory(player, 18, ChatColor.RED + LobbyTranslations.get().t("gizmos", player));
    inventory.setItem(4, Utils.getGhastTear(player, RaindropsListener.raindrops.get(player)));

    int i = 9;
    for(Gizmo gizmo : Gizmos.gizmos) {
        inventory.setItem(i++, gizmo.getItemStack(player));
    }

    player.openInventory(inventory);
}