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