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


Java Inventory類代碼示例

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


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

示例1: registerContainer

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

示例2: equipWeaponEvent

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

示例3: handleWinner

import org.bukkit.inventory.Inventory; //導入依賴的package包/類
/**
 * 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.
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:29,代碼來源:EventTimer.java

示例4: onClick

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

示例5: isTrue

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

示例6: takeItem

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

示例7: tryToSaveSlot

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

示例8: run

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

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

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

示例11: limitWorkbenches

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

示例12: archived

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

示例13: onClick

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

示例14: openGUI

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

示例15: check

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


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