本文整理汇总了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);
}
示例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.")));
}
示例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;
}
示例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>");
}
}
示例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;
}
示例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;
}
示例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;
}
}
}
示例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];
}
}
示例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();
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例14: fromPlayerInventory
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
public static PlayerInv fromPlayerInventory(PlayerInventory inv) {
return new PlayerInv(inv.getContents(), inv.getArmorContents());
}