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


Java PlayerInventory.getContents方法代碼示例

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


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

示例1: setArmourAccordingly

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
public static void setArmourAccordingly(final Player player, boolean enabled) {
	final PlayerInventory inv = player.getInventory();
	ItemStack[] armours = inv.getContents();
	// Check the whole inventory for armour pieces

	for (int i = 0; i < armours.length; i++) {
		ItemStack piece = armours[i];

		if (piece != null && piece.getType() != Material.AIR) {
			Messenger.debug("Attempting to apply armour value to item", player);

			//If this piece is one of the ones being worn right now
			if(ArrayUtils.contains(inv.getArmorContents(), armours[i]))
				armours[i] = apply(piece, enabled); //Apply/remove values according state of module in this world
			else armours[i] = apply(piece, false); //Otherwise set values back to default
		}
	}

	player.getInventory().setContents(armours);
}
 
開發者ID:gvlfm78,項目名稱:BukkitOldCombatMechanics,代碼行數:21,代碼來源:ModuleOldArmourStrength.java

示例2: disqualified

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
public void disqualified(UUID id, String name, Location logoffPosition, PlayerInventory inventory) {
    if (Bukkit.getServer().getOnlinePlayers().stream().anyMatch(pl -> pl.getUniqueId().equals(id))) return;

    if(deadRepresentatives.containsKey(id)) deadRepresentatives.get(id).remove();
    logoffPosition.getWorld().strikeLightning(logoffPosition);
    UserManager.getInstance().removeUser(id);

    for(ItemStack cur : inventory.getContents()) if(cur != null) logoffPosition.getWorld().dropItem(logoffPosition, cur);

    long survivors = Bukkit.getServer().getOnlinePlayers().stream().filter(player -> player.getGameMode() != GameMode.SPECTATOR).count() - 1;

    if (survivors <= 1) {
        Player winner = Bukkit.getServer().getOnlinePlayers().stream().filter(player -> player.getGameMode() != GameMode.SPECTATOR).findFirst().get();
        GameState.ENDED.setCurrent();
        DeathHandler.onGameEnd(winner);
    }

    Bukkit.getOnlinePlayers().forEach(player -> player.sendMessage(colour("&6" + name + " was disqualified.\n&bThere are " + survivors + " players left.")));
}
 
開發者ID:Project-Coalesce,項目名稱:UHC,代碼行數:20,代碼來源:JoinQuitHandlers.java

示例3: getItemSlot

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
/**
 * Gets the slot of the given item through iteration.
 * 
 * @param player The inventory to iterate through.
 * @param item The ItemStack to check for.
 * @return The found slot in the inventory.
 */
public static int getItemSlot(PlayerInventory inventory, ItemStack item)
{
	int slot = 0;
	ItemStack[] contents = inventory.getContents();
	
	for(int i = 0; i < contents.length; i++)
	{
		ItemStack current = contents[i];
		
		if(current == null)
		{
			continue;
		}
		
		if(current.equals(item))
		{
			slot = i;
			break;
		}
	}
	
	return slot;
}
 
開發者ID:Shortninja66,項目名稱:StaffPlus,代碼行數:31,代碼來源:JavaUtils.java

示例4: onCommand

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
@Override
public void onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
	Player player = (Player) sender;
	PlayerInventory inv = player.getInventory();
	ItemStack[][] contents = { inv.getContents(), inv.getArmorContents() };
	String world = player.getWorld().getName().split("_")[0];
	try {
		if(KitManager.getKit(world,args[0]) == null){
			KitManager.createKit(world,args[0], "temp", "temp", 1, (short) 0, contents);
			player.sendMessage(Util.parseColors("&7Kit &a" + args[0] + " &7created!"));
		} else {
			KitManager.setKit(world,args[0], contents);
			player.sendMessage(Util.parseColors("&7Kit &a" + args[0] + " &7modified!"));
		}
	} catch (Exception e) {
		player.sendMessage(ChatColor.RED + "Invalid arguments");
		player.sendMessage("/setkit <name>");
	}
}
 
開發者ID:bobmandude9889,項目名稱:iZenith-PVP,代碼行數:20,代碼來源:SetKit.java

示例5: testInventory

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
/**This method checks the inventory of the player; as to
 * whether it's clear, or is polluted, or has armor pollution
 * @param p the player we're testing
 * @return InventoryResult result of this test
 */
public static IceBall.InventoryResult testInventory(Player p) {
	PlayerInventory pi = p.getInventory();
	if(pi.getHelmet() != null)
		return InventoryResult.ARMOR_POLLUTION;
	if(pi.getChestplate() != null)
		return InventoryResult.ARMOR_POLLUTION;
	if(pi.getLeggings() != null)
		return InventoryResult.ARMOR_POLLUTION;
	if(pi.getBoots() != null)
		return InventoryResult.ARMOR_POLLUTION;
	
	ItemStack is[] = pi.getContents();
	for(int i = 0; i < is.length; i++) {
		if(is[i] != null) {
			if(is[i].getType() != Material.AIR) {
				return InventoryResult.POLLUTED;
			}
		}
	}
	return InventoryResult.CLEAR;
}
 
開發者ID:CrystalCraftMC,項目名稱:IceBall,代碼行數:27,代碼來源:Utility.java

示例6: sell

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
private double sell(PlayerInventory inv, int cAmount, MaterialData matType, UUID uuid, double baseCost) {
    double totalCost = 0.0;
    ArrayList<ItemStack> foundItems = new ArrayList<>();
    for (ItemStack s : inv.getContents()) {
        if (s == null)
            continue;
        if (cAmount > 0 && s.getType().equals(matType.getItemType()) && s.getEnchantments().size() == 0 && s.getType().getMaxDurability() != 0) {
            short maxDur = (short) (s.getType().getMaxDurability() + 1), dur = s.getDurability();
            cAmount--;
            double cost = s.getAmount() * baseCost * ((maxDur - 1.0 * dur) / maxDur);//why does it not work if not also divided by two?
            System.out.println(dur + " " + maxDur + " " + cost);
            ItemStack toRemove = s.clone();
            toRemove.setAmount(1);
            foundItems.add(toRemove);
            totalCost += cost;
        }
        if (cAmount == 0) {
            foundItems.forEach(inv::remove);
            Necessities.getEconomy().addMoney(uuid, totalCost);
            return totalCost;
        }
    }
    return -1.00;
}
 
開發者ID:pupnewfster,項目名稱:Necessities,代碼行數:25,代碼來源:CmdSell.java

示例7: createShipDataCoreCallback

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
private static void createShipDataCoreCallback(UUID u, String name, ArrayList<String> lore){
	Player p = Bukkit.getPlayer(u);
	if(p == null) return;
	PlayerInventory i = p.getInventory();
	for(ItemStack item : i.getContents()){
		if(item == null) continue;
		ItemMeta m = item.getItemMeta();
		if(m == null) continue;
		String displayName = m.getDisplayName();
		if(displayName == null) continue;
		if(m.getDisplayName().equals(DATA_PENDING)){
			m.setDisplayName(name);
			m.setLore(lore);
			item.setItemMeta(m);
			p.updateInventory();
			return;
		}
	}
}
 
開發者ID:StarQuestMinecraft,項目名稱:StarQuestCode,代碼行數:20,代碼來源:ShipDataCore.java

示例8: getContents

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
/**
 * Get the core contents of an inventory.
 *
 * @param inventory The inventory
 * @return The contents of the inventory.
 * @deprecated Use {@link org.bukkit.inventory.Inventory#getStorageContents()}
 */
public static ItemStack[] getContents(Inventory inventory) {
	if (inventory != null) {
		if (inventory instanceof PlayerInventory) {
			PlayerInventory playerInventory = (PlayerInventory) inventory;
			ItemStack[] itemContents = playerInventory.getContents();
			if (itemContents == null) itemContents = new ItemStack[36];
			if (itemContents.length > 36) {
				ItemStack[] actualContents = new ItemStack[itemContents.length];
				System.arraycopy(itemContents, 0, actualContents, 0, 36);
				return actualContents;
			} else {
				return itemContents;
			}
		} else {
			return inventory.getContents();
		}
	} else {
		return new ItemStack[36];
	}
}
 
開發者ID:KingFaris10,項目名稱:KingKits,代碼行數:28,代碼來源:ItemUtilities.java

示例9: playerInventoryToString

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
public static String playerInventoryToString(PlayerInventory inv) {
    StringBuilder builder = new StringBuilder();
    ItemStack[] armor = inv.getArmorContents();

    for (int i = 0; i < armor.length; i++) {
        if (i == 3) {
            if (armor[i] == null) {
                builder.append(itemStackToString(new ItemStack(Material.AIR)));
            } else {
                builder.append(itemStackToString(armor[3]));
            }
        } else {
            if (armor[i] == null) {
                builder.append(itemStackToString(new ItemStack(Material.AIR))).append(";");
            } else {
                builder.append(itemStackToString(armor[i])).append(";");
            }
        }
    }

    builder.append("|");

    for (int i = 0; i < inv.getContents().length; ++i) {
        builder.append(i).append("#").append(itemStackToString(inv.getContents()[i]))
                .append((i == inv.getContents().length - 1) ? "" : ";");
    }

    return builder.toString();
}
 
開發者ID:ijoeleoli,項目名稱:ZorahPractice,代碼行數:30,代碼來源:InventoryUtils.java

示例10: getAmount

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
public static int getAmount(String ownerName, ItemStack compareItem) {
	if (Bukkit.getPlayer(ownerName) == null) return 0;
	PlayerInventory inventory = Bukkit.getPlayer(ownerName).getInventory();
	ItemStack[] items = inventory.getContents();
	int has = 0;
	for (ItemStack item : items) {
		if (isSameItem(compareItem, item)) {
			has += item.getAmount();
		}
	}
	return has;
}
 
開發者ID:virustotalop,項目名稱:ObsidianAuctions,代碼行數:13,代碼來源:Items.java

示例11: Kit

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
public Kit(String name, PlayerInventory playerInventory) {
    this.name = name;
    this.displayed = ItemBuilder.builder().type(Material.DIAMOND_SWORD).name("&7&l" + name).lore(Arrays.asList("&aClick to send", "&aa duel request", "&awith this kit!")).build();
    
    Map<Integer, ItemStack> inventory = new HashMap<>();

    for (int i = 0; i < playerInventory.getSize(); i++) {
        ItemStack item = playerInventory.getContents()[i];

        if (item == null) {
            continue;
        }

        inventory.put(i, item.clone());
    }

    Map<Integer, ItemStack> armor = new HashMap<>();

    if (playerInventory.getHelmet() != null) {
        armor.put(1, playerInventory.getHelmet().clone());
    }

    if (playerInventory.getChestplate() != null) {
        armor.put(2, playerInventory.getChestplate().clone());
    }

    if (playerInventory.getLeggings() != null) {
        armor.put(3, playerInventory.getLeggings().clone());
    }

    if (playerInventory.getBoots() != null) {
        armor.put(4, playerInventory.getBoots().clone());
    }

    items.put(KitManager.Type.INVENTORY, inventory);
    items.put(KitManager.Type.ARMOR, armor);
}
 
開發者ID:RealizedMC,項目名稱:Duels,代碼行數:38,代碼來源:Kit.java

示例12: checkPvpProtectionNeeded

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
public void checkPvpProtectionNeeded(Player player)
{
    //if anti spawn camping feature is not enabled, do nothing
       if(!this.config_pvp_protectFreshSpawns) return;
       
    //if pvp is disabled, do nothing
	if(!this.config_pvp_enabledWorlds.contains(player.getWorld())) return;
	
	//if player is in creative mode, do nothing
	if(player.getGameMode() == GameMode.CREATIVE) return;
	
	//if the player has the damage any player permission enabled, do nothing
	if(player.hasPermission("griefprevention.nopvpimmunity")) return;
	
	//check inventory for well, anything
	PlayerInventory inventory = player.getInventory();
	ItemStack [] armorStacks = inventory.getArmorContents();
	
	//check armor slots, stop if any items are found
	for(int i = 0; i < armorStacks.length; i++)
	{
		if(!(armorStacks[i] == null || armorStacks[i].getType() == Material.AIR)) return;
	}
	
	//check other slots, stop if any items are found
	ItemStack [] generalStacks = inventory.getContents();
	for(int i = 0; i < generalStacks.length; i++)
	{
		if(!(generalStacks[i] == null || generalStacks[i].getType() == Material.AIR)) return;
	}
		
	//otherwise, apply immunity
	PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId());
	playerData.pvpImmune = true;
	
	//inform the player
	GriefPrevention.sendMessage(player, TextMode.Success, Messages.PvPImmunityStart);
}
 
開發者ID:john01dav,項目名稱:GriefPreventionPlus,代碼行數:39,代碼來源:GriefPrevention.java

示例13: PlayerBackup

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
public PlayerBackup(PlayerInventory inv, float exp, int level) {
    this.items = inv.getContents();
    this.armorItems = inv.getArmorContents();
    this.exp = exp;
    this.level = level;
}
 
開發者ID:upperlevel,項目名稱:uppercore,代碼行數:7,代碼來源:PlayerBackup.java

示例14: fromPlayerInventory

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
public static PlayerInv fromPlayerInventory(PlayerInventory inv) {
    return new PlayerInv(inv.getContents(), inv.getArmorContents());
}
 
開發者ID:ijoeleoli,項目名稱:ZorahPractice,代碼行數:4,代碼來源:PlayerInv.java


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