当前位置: 首页>>代码示例>>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;未经允许,请勿转载。