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


Java Inventory.clear方法代碼示例

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


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

示例1: setPage

import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
/**
 * Sets a specific GUI page
 *
 * @param player  player
 * @param page    page
 * @param petMeta meta
 */
public void setPage(Player player, GUIPage page, PetMeta petMeta) {
    if (!this.manager.inventories.containsKey(player)) {
        return;
    }
    final Inventory inventory = this.manager.inventories.get(player);
    inventory.clear();
    if (page == GUIPage.MAIN) {
        this.setOtherItems(player, inventory, petMeta, GUIPage.MAIN);
        this.manager.pages.put(player, new GuiPageContainer(GUIPage.MAIN, null));
    } else if (page == GUIPage.WARDROBE) {
        this.setOtherItems(player, inventory, petMeta, page);
        this.manager.pages.put(player, new GuiPageContainer(page, this.manager.pages.get(player)));
    } else {
        this.setListAble(player, page, 0);
    }
    final GUIItemContainer backGuiItemContainer = Config.getInstance().getGuiItemsController().getGUIItemByName("back");
    inventory.setItem(backGuiItemContainer.getPosition(), (ItemStack) backGuiItemContainer.generate(player));
    this.fillEmptySlots(inventory);
    player.updateInventory();
}
 
開發者ID:Shynixn,項目名稱:PetBlocks,代碼行數:28,代碼來源:GUI.java

示例2: event

import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
@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);
}
 
開發者ID:BurnyDaKath,項目名稱:OMGPI,代碼行數:26,代碼來源:BukkitEventHandler.java

示例3: clearHeaderGUI

import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
public static void clearHeaderGUI(Inventory gui) {
    int i = 9;
    do {
        gui.clear(i);
        i++;
    } while (i < gui.getSize());
}
 
開發者ID:DRE2N,項目名稱:FactionsXL,代碼行數:8,代碼來源:PageGUI.java

示例4: onBreakWorkbench

import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST)
public void onBreakWorkbench(BlockBreakEvent e)
{
	if(e.isCancelled()) return;
	Block workbench = e.getBlock();

	if (!workbench.hasMetadata("shared_players") || workbench.getType() != Material.WORKBENCH)
		return;
	
	@SuppressWarnings("unchecked")
	List<UUID> list = (workbench.getMetadata("shared_players").get(0).value() instanceof List<?>) ? (List<UUID>)workbench.getMetadata("shared_players").get(0).value() : new ArrayList<UUID>();
	
	Iterator<UUID> iterator = list.iterator();
	
	Inventory sharedInventory = Bukkit.createInventory(null, InventoryType.WORKBENCH);
	
	while (iterator.hasNext())
	{
		UUID next = iterator.next();
		
		iterator.remove();
		
		final Player idPlayer = Bukkit.getPlayer(next);
		
		if (idPlayer != null)
		{
			idPlayer.removeMetadata("shared_inv", Survival.instance);
			
			if(idPlayer.isOnline())
			{
				final Inventory open = idPlayer.getOpenInventory().getTopInventory();
				
				if (open != null && open.getType() == InventoryType.WORKBENCH)
				{
					sharedInventory.setContents(open.getContents());
					open.clear();
					idPlayer.closeInventory();
				}
			}
		}
	}
	
	for(int i = 1; i < sharedInventory.getSize(); i++)
	{
		ItemStack item = sharedInventory.getItem(i);
		if(item != null)
			workbench.getWorld().dropItem(workbench.getLocation(), item);
	}
	
	workbench.removeMetadata("shared_players", Survival.instance);
}
 
開發者ID:FattyMieo,項目名稱:SurvivalPlus,代碼行數:52,代碼來源:WorkbenchShare.java

示例5: onPlayerInteract

import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
/**
 * Fill a legacy chest
 *
 * @param event Event
 */
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event)
{
    if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK) && event.getClickedBlock().getType().equals(Material.CHEST))
    {
        Chest chest = (Chest) event.getClickedBlock().getState();

        if (chest.hasMetadata("playerInteracted"))
            return;

        Inventory inventory = chest.getInventory();
        inventory.clear();

        int addedItems = 0;
        int slot;

        for (ItemStack item : this.items.keySet())
        {
            if (addedItems > 20)
                break;

            int frequency = 0;

            for(Map.Entry<ItemStack, Integer> entry : this.items.entrySet())
                if(entry.getKey().equals(item))
                    frequency = entry.getValue();

            SecureRandom random = new SecureRandom();

            if (random.nextInt(1000) <= frequency * 10)
            {
                ItemStack stack = item.clone();
                stack.setAmount((random.nextInt(3) + 1) * stack.getAmount());

                slot = random.nextInt(inventory.getSize());

                while (inventory.getItem(slot) != null)
                {
                    slot++;

                    if (slot >= inventory.getSize())
                        slot = 0;
                }

                inventory.setItem(slot, this.addMetaIfNeeded(stack));
                addedItems++;
            }
        }

        chest.setMetadata("playerInteracted", new FixedMetadataValue(this.plugin, true));
    }
}
 
開發者ID:SamaGames,項目名稱:SurvivalAPI,代碼行數:58,代碼來源:RandomChestModule.java

示例6: modItems

import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
public static void modItems(Player p)
{
  Inventory inv = p.getInventory();
  inv.clear();
  ItemStack modCompass = new ItemStack(Material.COMPASS);
  ItemStack modBook = new ItemStack(Material.BOOK);
  ItemStack modFreeze = new ItemStack(Material.PACKED_ICE);
  ItemStack modTp = new ItemStack(Material.EYE_OF_ENDER);
  ItemStack modVanish = new ItemStack(Material.FEATHER);
 
  ItemMeta compassMeta = modCompass.getItemMeta();
  ItemMeta bookMeta = modBook.getItemMeta();
  ItemMeta freezeMeta = modFreeze.getItemMeta();
  ItemMeta tpMeta = modTp.getItemMeta();
  ItemMeta vanishMeta = modVanish.getItemMeta();
 
  compassMeta.setDisplayName("§cWhoosh");
  bookMeta.setDisplayName("§cInspect Player");
  freezeMeta.setDisplayName("§cFreeze Player");
  vanishMeta.setDisplayName("§cToggle Vanish");
  tpMeta.setDisplayName("§cRandom Teleporter");
 
  ArrayList<String> modCompassLore = new ArrayList();
  ArrayList<String> modBookLore = new ArrayList();
  ArrayList<String> modFreezeLore = new ArrayList();
  ArrayList<String> modVanishLore = new ArrayList();
  ArrayList<String> modTpLore = new ArrayList();
 
  modCompassLore.add("§7Used to teleport to eye location.");
  modBookLore.add("§7Used to inspect a players inventory.");
  modFreezeLore.add("§7Used to freeze a player.");
  modVanishLore.add("§7Used to toggle vanish.");
  modTpLore.add("§7Used to teleport to a random player.");
 
  compassMeta.setLore(modCompassLore);
  bookMeta.setLore(modBookLore);
  freezeMeta.setLore(modFreezeLore);
  vanishMeta.setLore(modVanishLore);
  tpMeta.setLore(modTpLore);
 
  modCompass.setItemMeta(compassMeta);
  modBook.setItemMeta(bookMeta);
  modFreeze.setItemMeta(freezeMeta);
  modTp.setItemMeta(tpMeta);
  modVanish.setItemMeta(vanishMeta);
 
  inv.setItem(0, modCompass);
  inv.setItem(3, modVanish);
  inv.setItem(4, modBook);
  inv.setItem(5, modFreeze);
  inv.setItem(8, modTp);
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:53,代碼來源:ModeratorMode.java

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