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


Java Inventory.setContents方法代碼示例

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


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

示例1: showWindow

import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
/**
 * Open the window for the given player, or refresh its contents
 * if they already have it open, and return the current contents.
 *
 * If the window is currently open but too small to hold the current
 * contents, it will be closed and reopened.
 *
 * If the player is not currently allowed to have the window open,
 * close any window they have open and return null.
 */
private @Nullable Inventory showWindow(MatchPlayer player) {
    if(!checkWindow(player)) return null;

    ItemStack[] contents = createWindowContents(player);
    Inventory inv = getOpenWindow(player);
    if(inv != null && inv.getSize() < contents.length) {
        inv = null;
        closeWindow(player);
    }
    if(inv == null) {
        inv = openWindow(player, contents);
    } else {
        inv.setContents(contents);
    }
    return inv;
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:27,代碼來源:PickerMatchModule.java

示例2: refreshWindow

import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
/**
 * If the given player currently has the window open, refresh its contents
 * and return the updated inventory. The window will be closed and reopened
 * if it is too small to hold the current contents.
 *
 * If the window is open but should be closed, close it and return null.
 *
 * If the player does not have the window open, return null.
 */
private @Nullable Inventory refreshWindow(MatchPlayer player) {
    if(!checkWindow(player)) return null;

    Inventory inv = getOpenWindow(player);
    if(inv != null) {
        ItemStack[] contents = createWindowContents(player);
        if(inv.getSize() < contents.length) {
            closeWindow(player);
            inv = openWindow(player, contents);
        } else {
            inv.setContents(contents);
        }
    }
    return inv;
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:25,代碼來源:PickerMatchModule.java

示例3: previewInventory

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

示例4: openWindow

import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
/**
 * Open a new window for the given player displaying the given contents
 */
private Inventory openWindow(MatchPlayer player, ItemStack[] contents) {
    closeWindow(player);
    Inventory inv = getMatch().getServer().createInventory(player.getBukkit(),
                                                           contents.length,
                                                           StringUtils.truncate(getWindowTitle(player), 32));
    inv.setContents(contents);
    player.getBukkit().openInventory(inv);
    picking.add(player);
    return inv;
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:14,代碼來源:PickerMatchModule.java

示例5: onLoadInventory

import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST)
public void onLoadInventory(PlayerInventoryLoadEvent.Post event) {
    Player player = event.getPlayer();
    ItemManager.updateStats(player);

    // Sync armor
    player.getInventory().setArmorContents(ItemUtils.syncItems(player.getInventory().getArmorContents()));

    // Sync inventory
    player.getInventory().setContents(ItemUtils.syncItems(player.getInventory().getContents()));

    // Sync RPG Inventory
    Inventory inventory = InventoryManager.get(player).getInventory();
    inventory.setContents(ItemUtils.syncItems(inventory.getContents()));
}
 
開發者ID:EndlessCodeGroup,項目名稱:RPGInventory,代碼行數:16,代碼來源:InventoryListener.java

示例6: getInventory

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

示例7: createInventory

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

示例8: open

import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
public void open(HumanEntity human) {
    Inventory topInv = human.getOpenInventory().getTopInventory();
    Inventory newInv = createInventory();
    if (topInv != null && topInv.getTitle().equals(data.title())
            && topInv.getSize() == data.size()) {
        topInv.setContents(newInv.getContents());
        if (human instanceof Player) {
            ((Player) human).updateInventory();
        }
    } else {
        human.openInventory(newInv);
    }
    GUI_MAP.put(human.getName(), this);
}
 
開發者ID:EntryPointKR,項目名稱:MCLibrary,代碼行數:15,代碼來源:GUI.java

示例9: open

import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
public void open(HumanEntity human) {
    if (init) {
        factory.initialize(this);
        init = false;
    }

    Inventory topInv = human.getOpenInventory().getTopInventory();
    Inventory newInv = factory.create(this, human);
    if (signature.isSimilar(topInv)) {
        topInv.setContents(newInv.getContents());
    } else {
        human.openInventory(newInv);
    }
    guiMap.put(human, this);
}
 
開發者ID:EntryPointKR,項目名稱:MCLibrary,代碼行數:16,代碼來源:GUI.java

示例10: 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

示例11: choosePriceAndAmount

import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
private Inventory choosePriceAndAmount(int amount, double price) {
    Inventory gui = Bukkit.createInventory(null, 27, tradeOfferChoosePriceAndAmount.replace("&v1", String.valueOf(amount)).replace("&v2", String.valueOf(price)));
    gui.setContents(choosePriceAndAmount);
    return gui;
}
 
開發者ID:DRE2N,項目名稱:FactionsXL,代碼行數:6,代碼來源:TradeOfferCommand.java

示例12: withdrawInventoryAtomic

import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
/**
 * Remove items from inventory.
 * Either all removed or none removed.
 *
 * @param inv           the inventory
 * @param itemToBeTaken items to be removed
 * @return If null, then all designated items are removed. If not null, it contains the items missing
 */
public static List<ItemStack> withdrawInventoryAtomic(Inventory inv, List<ItemStack> itemToBeTaken) {
    ItemStack[] itemStacks = inv.getContents();
    ItemStack[] cloneStacks = new ItemStack[itemStacks.length];
    for (int i = 0; i < itemStacks.length; i++) {
        cloneStacks[i] = itemStacks[i] == null ? null : itemStacks[i].clone();
    }

    List<ItemStack> ret = new ArrayList<>();

    for (ItemStack item : itemToBeTaken) {
        int sizeReq = item.getAmount();

        for (int i = 0; i < cloneStacks.length; i++) {
            if (cloneStacks[i] == null) continue;
            if (cloneStacks[i].isSimilar(item)) {
                int sizeSupp = cloneStacks[i].getAmount();
                if (sizeSupp > sizeReq) {
                    cloneStacks[i].setAmount(sizeSupp - sizeReq);
                    sizeReq = 0;
                    break;
                } else {
                    cloneStacks[i] = null;
                    sizeReq -= sizeSupp;
                    if (sizeReq == 0) break;
                }
            }
        }

        if (sizeReq > 0) {
            ItemStack n = item.clone();
            item.setAmount(sizeReq);
            ret.add(n);
        }
    }

    if (ret.size() == 0) {
        inv.setContents(cloneStacks);
        return null;
    } else {
        return ret;
    }
}
 
開發者ID:NyaaCat,項目名稱:NyaaCore,代碼行數:51,代碼來源:InventoryUtils.java

示例13: onPlayerInteract

import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    Action action = event.getAction();
    ItemStack stack = event.getItem();

    // Keys can only be used by right clicking blocks.
    if (action != Action.RIGHT_CLICK_BLOCK)
        return;

    Key key = plugin.getKeyManager().getKey(stack);

    // No keys were used in the making of this video.
    if (key == null)
        return;

    Block block = event.getClickedBlock();
    BlockState state = block.getState();
    if (key instanceof EventKey && state instanceof Chest) {
        EventKey eventKey = (EventKey) key;
        EventKey.EventKeyData eventKeyData = eventKey.getData(stack.getItemMeta().getLore());
        EventType eventType = eventKeyData.getEventType();
        List<Inventory> inventories = eventKey.getInventories(eventType);
        int inventoryNumber = eventKeyData.getInventoryNumber();

        if (inventories.size() < inventoryNumber) {
            player.sendMessage(ChatColor.RED + "This key is for " + eventType.getDisplayName() + ChatColor.RED + " loottable " + inventoryNumber + ", whilst there are only " + inventories.size()
                    + " possible. Please inform an admin.");

            return;
        }

        Inventory inventory = inventories.get(inventoryNumber - 1);
        ItemStack[] contents = inventory.getContents();

        Chest chest = (Chest) state;
        InventoryHolder inventoryHolder = chest.getInventory().getHolder();
        if (inventoryHolder instanceof DoubleChestInventory) {
            inventoryHolder = ((DoubleChestInventory) inventoryHolder).getHolder();
        }

        if (contents.length > chest.getInventory().getSize()) {
            player.sendMessage(ChatColor.RED + "This single chest is too small to fit the contents of this key.");
            return;
        }

        Inventory chestInventory = inventoryHolder.getInventory();

        if (!InventoryUtils.isEmpty(chestInventory)) {
            player.sendMessage(ChatColor.RED + "This chest is not empty.");
            return;
        }

        chestInventory.setContents(inventory.getContents());
        decrementHand(player);
        event.setCancelled(true);

        player.openInventory(chestInventory);
        player.sendMessage(ChatColor.YELLOW + "Your " + ChatColor.AQUA + eventType.getDisplayName() + ' ' + eventKey.getDisplayName() + ChatColor.YELLOW + " key has transferred loot "
                + inventoryNumber + ChatColor.YELLOW + " to the chest.");
    }
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:63,代碼來源:KeyListener.java

示例14: clearInventory

import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
/**
 * fully clear the inventory, even armors
 * @param inv
 */
public static void clearInventory(Inventory inv) {
    inv.setContents(new ItemStack[inv.getSize()]);
}
 
開發者ID:DragonetMC,項目名稱:PlayerStevesBattleGrounds,代碼行數:8,代碼來源:InventoryUtils.java


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