java类org.bukkit.inventory.Inventory的实例源码

WoolMatchModule.java 文件源码 项目:ProjectAres 阅读 21 收藏 0 点赞 0 评论 0
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());
                }
            }
        }
    }
}
Guns.java 文件源码 项目:AddGun 阅读 24 收藏 0 点赞 0 评论 0
@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.
    }

}
EventTimer.java 文件源码 项目:HCFCore 阅读 25 收藏 0 点赞 0 评论 0
/**
 * 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.
}
DemandMenu.java 文件源码 项目:FactionsXL 阅读 23 收藏 0 点赞 0 评论 0
@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);
    }
}
FireCraftTableRecipe.java 文件源码 项目:RealSurvival 阅读 22 收藏 0 点赞 0 评论 0
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;
}
Inventories.java 文件源码 项目:MCLibrary 阅读 18 收藏 0 点赞 0 评论 0
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;
}
HotbarView.java 文件源码 项目:uppercore 阅读 17 收藏 0 点赞 0 评论 0
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;
}
CellSpawner.java 文件源码 项目:AgarMC 阅读 19 收藏 0 点赞 0 评论 0
@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)));
    }
}
BukkitEventHandler.java 文件源码 项目:OMGPI 阅读 23 收藏 0 点赞 0 评论 0
@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);
}
ViewInventoryMatchModule.java 文件源码 项目:ProjectAres 阅读 26 收藏 0 点赞 0 评论 0
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);
    }
}
BenchBlitz.java 文件源码 项目:OpenUHC 阅读 20 收藏 0 点赞 0 评论 0
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
      }
    }
  }
}
GUIManager.java 文件源码 项目:EpicBanRequests 阅读 20 收藏 0 点赞 0 评论 0
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;
}
PageGUICache.java 文件源码 项目:FactionsXL 阅读 19 收藏 0 点赞 0 评论 0
@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);
    }
}
GUI.java 文件源码 项目:ArmorPlus 阅读 19 收藏 0 点赞 0 评论 0
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);
}
CustomCraftingRecipe.java 文件源码 项目:SuperiorCraft 阅读 26 收藏 0 点赞 0 评论 0
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;
}
KitsMenu.java 文件源码 项目:ZorahPractice 阅读 18 收藏 0 点赞 0 评论 0
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);
}
VotePanelEvents.java 文件源码 项目:mczone 阅读 18 收藏 0 点赞 0 评论 0
@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);
        }
    }
}
InventoryUtils.java 文件源码 项目:NyaaCore 阅读 24 收藏 0 点赞 0 评论 0
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;
}
InventoryListener.java 文件源码 项目:RPGInventory 阅读 26 收藏 0 点赞 0 评论 0
@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);
    }
}
CompassEvents.java 文件源码 项目:mczone 阅读 26 收藏 0 点赞 0 评论 0
@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();
        }
    }
}
RailGun.java 文件源码 项目:AddGun 阅读 20 收藏 0 点赞 0 评论 0
@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.
    }

}
TradeOfferCommand.java 文件源码 项目:FactionsXL 阅读 25 收藏 0 点赞 0 评论 0
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;
}
AntiNegativeItemDupe.java 文件源码 项目:NeverLag 阅读 20 收藏 0 点赞 0 评论 0
@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);
            }
        }
    }
}
MenuManager.java 文件源码 项目:ZentrelaCore 阅读 36 收藏 0 点赞 0 评论 0
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);
}
MainInventory.java 文件源码 项目:AsgardAscension 阅读 23 收藏 0 点赞 0 评论 0
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);
}
InventoryManager.java 文件源码 项目:RPGInventory 阅读 20 收藏 0 点赞 0 评论 0
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);
}
CreativeCommandExecutor.java 文件源码 项目:Transport-Pipes 阅读 17 收藏 0 点赞 0 评论 0
@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;
}
Menu.java 文件源码 项目:AlphaLibary 阅读 28 收藏 0 点赞 0 评论 0
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);
}
SimpleGUI.java 文件源码 项目:MCLibrary 阅读 33 收藏 0 点赞 0 评论 0
@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;
}
InventoryUtils.java 文件源码 项目:ZorahPractice 阅读 21 收藏 0 点赞 0 评论 0
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;
}


问题


面经


文章

微信
公众号

扫码关注公众号