當前位置: 首頁>>代碼示例>>Java>>正文


Java Inventory.firstEmpty方法代碼示例

本文整理匯總了Java中org.bukkit.inventory.Inventory.firstEmpty方法的典型用法代碼示例。如果您正苦於以下問題:Java Inventory.firstEmpty方法的具體用法?Java Inventory.firstEmpty怎麽用?Java Inventory.firstEmpty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.bukkit.inventory.Inventory的用法示例。


在下文中一共展示了Inventory.firstEmpty方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: SimpleMovingInventory

import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
/**
 * Creates a new {@link Inventory} with multiple Sites
 *
 * @param p        the {@link Player} to open the {@link Inventory} for
 * @param size     the site of the {@link Inventory}
 * @param items    a {@link ArrayList} of {@link ItemStack}s which should be inside the {@link Inventory}
 * @param name     the name of the {@link Inventory}
 * @param nextPage the name for the {@link ItemStack} for the next page
 * @param prevPage the name for the {@link ItemStack} for the previous page
 */
public SimpleMovingInventory(Player p, int size, ArrayList<ItemStack> items, String name, ItemStack nextPage, ItemStack prevPage) {
    Bukkit.getPluginManager().registerEvents(this, AlphaLibary.getInstance());
    this.title = name;
    this.items = items;
    this.size = size;
    this.nextPage = nextPage;
    this.previousPage = prevPage;

    Inventory page = getBlankPage(name, size);

    for (ItemStack item : items) {
        if (page.firstEmpty() == -1) {
            PAGES.add(page);
            page = getBlankPage(name, size);
            page.addItem(item);
        } else {
            page.addItem(item);
        }
    }

    PAGES.add(page);
    p.openInventory(PAGES.get(currpage));
    USERS.put(p.getUniqueId(), this);
}
 
開發者ID:AlphaHelixDev,項目名稱:AlphaLibary,代碼行數:35,代碼來源:SimpleMovingInventory.java

示例2: construct

import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
public void construct(Player p) {
    Bukkit.getPluginManager().registerEvents(this, AlphaLibary.getInstance());

    Inventory page = getBlankPage(title, size);

    for (ItemStack item : items) {
        if (page.firstEmpty() == -1) {
            PAGES.add(page);
            page = getBlankPage(title, size);
            page.addItem(item);
        } else {
            page.addItem(item);
        }
    }
    PAGES.add(page);
    p.openInventory(PAGES.get(currpage));
    USERS.put(p.getUniqueId(), this);
}
 
開發者ID:AlphaHelixDev,項目名稱:AlphaLibary,代碼行數:19,代碼來源:SimpleMovingInventory.java

示例3: onClick

import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
/**
 * Handle a player click.
 * @param evt
 */
public void onClick(InventoryClickEvent evt) {
    InventoryAction action = evt.getAction();
    if (IGNORE.contains(action)) {
        evt.setCancelled(true);
        return; // Don't allow these clicks.
    }

    Inventory top = evt.getView().getTopInventory();
    boolean isTop = top.equals(evt.getClickedInventory());
    boolean isBottom = evt.getView().getBottomInventory().equals(evt.getClickedInventory());
    ItemStack add = null;
    int slot = evt.getRawSlot();

    if (slot >= 0 && isTop) {
        GUIItem item = getItem(slot);
        if (item != null) {
            evt.setCancelled(true);
            item.onClick(evt);
        } else {
            if (!isAllowStorage()) {
                evt.setCancelled(true); // Don't allow depositing / withdrawing items.
                return;
            }

            if (action == InventoryAction.HOTBAR_MOVE_AND_READD || action == InventoryAction.HOTBAR_SWAP) {
                // Hotbar swap.
                if (item != null || !isAllowStorage()) // Either they're not allowed or they're swapping with a DisplayItem.
                    add = evt.getWhoClicked().getInventory().getItem(evt.getHotbarButton());
            } else if (action == InventoryAction.PLACE_ALL || action == InventoryAction.PLACE_ONE) { //PLACE_SOME adds to an existing stack, we only want to fire when a new item is added.
                add = evt.getCursor().clone();
                if (action == InventoryAction.PLACE_ONE)
                    add.setAmount(1); // They're right clicking an item in.
            }
        }
    } else if (isBottom && evt.isShiftClick()) { // They're trying to shift click an item in.
        if (isAllowStorage() && top.firstEmpty() > -1) {
            add = evt.getCurrentItem();
        } else {
            evt.setCancelled(true);
        }
    }

    if (add != null) {
        // We're depositing an item.
        if (canDeposit(slot, add)) {
            deposit(add);
        } else {
            evt.setCancelled(true);
        }
    }
}
 
開發者ID:Kneesnap,項目名稱:Kineticraft,代碼行數:56,代碼來源:GUI.java

示例4: spawnLootFor

import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
/**
 * Spawn loot for the specific dragon battle
 * 
 * @param battle the battle to spawn loot for
 * @param dragon the dragon whose egg should be spawned
 */
public void spawnLootFor(DragonBattle battle, EnderDragon dragon) {
	Validate.notNull(battle, "Cannot spawn loot for null dragon battle");
	Validate.notNull(dragon, "Cannot spawn loot for null ender dragon");
	
	Location location = battle.getEndPortalLocation();
	
	boolean spawnEgg = RANDOM.nextDouble() * 100 <= eggSpawnChance;
	boolean spawnChest = RANDOM.nextDouble() * 100 <= chestSpawnChance;
	
	// Spawn a chest
	if (spawnChest) {
		location.getBlock().setType(Material.CHEST);
		Chest chest = (Chest) location.getBlock().getState();
		NMS_ABSTRACT.setChestName(chest, chestName);
		
		Inventory inventory = chest.getInventory();
		inventory.clear();
		
		// Spawn an egg within the chest
		if (spawnEgg) {
			ItemStack eggItem = new ItemStack(Material.DRAGON_EGG);
			ItemMeta eggMeta = eggItem.getItemMeta();
			eggMeta.setDisplayName(eggName.replace("%dragon%", dragon.getName()));
			eggMeta.setLore(eggLore);
			eggItem.setItemMeta(eggMeta);
			
			inventory.setItem(inventory.getSize() / 2, eggItem);
		}
		
		// Generate loot within the chest
		int itemGenCount = Math.max(RANDOM.nextInt(maxLootGen), minLootGen);
		for (int i = 0; i < itemGenCount; i++) {
			if (inventory.firstEmpty() == -1) break;
			
			int slot = RANDOM.nextInt(inventory.getSize());
			
			if (inventory.getItem(slot) != null) {
				i--;
				continue;
			}
			
			inventory.setItem(slot, loot.next());
		}
	}
	
	// Spawn the egg
	else if (spawnEgg) {
		location.getBlock().setType(Material.DRAGON_EGG);
	}
	
	// Execute commands
	List<Player> playersInWorld = dragon.getWorld().getPlayers();
	Player commandTarget = playersInWorld.size() > 0 ? playersInWorld.get(0) : null;
	
	for (String command : commands) {
		if (command.contains("%player%") && commandTarget == null) continue;
		
		String commandToExecute = command.replace("%dragon%", dragon.getCustomName());
		if (commandTarget != null) {
			commandToExecute = commandToExecute.replace("%player%", commandTarget.getName());
		}
		
		Bukkit.dispatchCommand(Bukkit.getConsoleSender(), commandToExecute);
	}
}
 
開發者ID:2008Choco,項目名稱:DragonEggDrop,代碼行數:72,代碼來源:DragonLoot.java


注:本文中的org.bukkit.inventory.Inventory.firstEmpty方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。