当前位置: 首页>>代码示例>>Java>>正文


Java PlayerInventory类代码示例

本文整理汇总了Java中org.bukkit.inventory.PlayerInventory的典型用法代码示例。如果您正苦于以下问题:Java PlayerInventory类的具体用法?Java PlayerInventory怎么用?Java PlayerInventory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PlayerInventory类属于org.bukkit.inventory包,在下文中一共展示了PlayerInventory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: onInteract

import org.bukkit.inventory.PlayerInventory; //导入依赖的package包/类
@EventHandler
public void onInteract(PlayerInteractEvent e) {
	Player p = e.getPlayer();
	PlayerInventory i = p.getInventory();
	if(i.getItemInMainHand().equals(PlayerJoinList.JOIN_ITEM) && (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK)){
		DrawSystem.addUser(UserManager.getUser(p));
		i.clear();
		// TODO ?
		return;
	}
	
	String turretName = TurretManager.getNearestTurretName(e.getPlayer());
	Turret turret = TurretManager.getTurretByName(turretName);
	if(turret == null) {
		return;
	}
	if(e.getAction() == Action.LEFT_CLICK_BLOCK) {
		if (e.getClickedBlock().getType() != Material.GRASS) {
			Bukkit.getPluginManager().callEvent(new PlayerAttackTurretEvent(turret, e.getPlayer(), e.getClickedBlock()));
		}
	}
}
 
开发者ID:xdev-pl,项目名称:LeagueOfLegends,代码行数:23,代码来源:PlayerInteractList.java

示例3: hasEnoughRessource

import org.bukkit.inventory.PlayerInventory; //导入依赖的package包/类
private boolean hasEnoughRessource(Player player, VillagerTrade trade) {
	if (trade instanceof XPVillagerTrade) {
		return XPManager.hasEnoughXP(bedwars.getName(), player,
				((XPVillagerTrade) trade).getXP());
	} else {
		ItemStack item1 = trade.getItem1();
		ItemStack item2 = trade.getItem2();
		PlayerInventory inventory = player.getInventory();

		if (item2 != null) {
			if ((!inventory.contains(item1.getType(), item1.getAmount()))
					|| (!inventory.contains(item2.getType(),
							item2.getAmount()))) {
				return false;
			}
		} else if (!inventory.contains(item1.getType(), item1.getAmount())) {
			return false;
		}

		return true;
	}
}
 
开发者ID:Ldcr993519867,项目名称:BedwarsXP,代码行数:23,代码来源:XPItemShop.java

示例4: restoreKeptInventory

import org.bukkit.inventory.PlayerInventory; //导入依赖的package包/类
public void restoreKeptInventory() {
    final List<ItemStack> displaced = new ArrayList<>();
    final PlayerInventory inv = bukkit.getInventory();

    kept.forEach((slot, keptStack) -> {
        final ItemStack invStack = slot.getItem(bukkit);

        if(invStack == null || slot instanceof Slot.Armor) {
            slot.putItem(inv, keptStack);
        } else {
            if(invStack.isSimilar(keptStack)) {
                int n = Math.min(keptStack.getAmount(), invStack.getMaxStackSize() - invStack.getAmount());
                invStack.setAmount(invStack.getAmount() + n);
                keptStack.setAmount(keptStack.getAmount() - n);
            }
            if(keptStack.getAmount() > 0) {
                displaced.add(keptStack);
            }
        }

        for(ItemStack stack : displaced) {
            inv.addItem(stack);
        }
    });
    kept.clear();
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:27,代码来源:ItemKeepPlayerFacet.java

示例5: previewInventory

import org.bukkit.inventory.PlayerInventory; //导入依赖的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

示例6: redeemItems

import org.bukkit.inventory.PlayerInventory; //导入依赖的package包/类
private double redeemItems(MatchPlayer player) {
    if(redeemables.isEmpty()) return 0;

    final PlayerInventory inventory = player.getInventory();
    return Slot.Player.player()
                      .map(slot -> {
                          final ItemStack item = slot.getItem(inventory);
                          final double points = redeemItem(item);
                          if(Double.isNaN(points)) {
                              return 0D;
                          } else {
                              // Note that redeeming a zero-amount stack will remove the item, but give no points
                              slot.putItem(inventory, ItemUtils.something(item).orElse(null));
                              return points;
                          }
                      })
                      .reduce(0D, (a, b) -> a + b);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:19,代码来源:ScoreBoxFactory.java

示例7: onInventoryClick

import org.bukkit.inventory.PlayerInventory; //导入依赖的package包/类
@EventHandler
public void onInventoryClick(InventoryClickEvent event)
{
    if (event.getWhoClicked() instanceof Player)
    {
        Player player = (Player) event.getWhoClicked();
        AbstractGui gui = (AbstractGui) this.hub.getGuiManager().getPlayerGui(player);

        if (event.getClickedInventory() instanceof PlayerInventory)
        {
            this.hub.getPlayerManager().getStaticInventory().doInteraction(player, event.getCurrentItem());
            return;
        }

        if (gui != null)
        {
            String action = gui.getAction(event.getSlot());

            if (action != null)
                gui.onClick(player, event.getCurrentItem(), action, event.getClick());
        }
    }
}
 
开发者ID:SamaGames,项目名称:Hub,代码行数:24,代码来源:GuiListener.java

示例8: hasEnoughSpace

import org.bukkit.inventory.PlayerInventory; //导入依赖的package包/类
public static boolean hasEnoughSpace(Inventory inventory, ItemStack item, int amount) {
    for (int i = 0; i < inventory.getSize(); i++) {
        if (i >= 36 && i <= 39 && inventory instanceof PlayerInventory) {
            continue;
        }
        if (inventory.getItem(i) != null && item.isSimilar(inventory.getItem(i)) &&
                inventory.getItem(i).getAmount() < item.getMaxStackSize()) {
            amount -= item.getMaxStackSize() - inventory.getItem(i).getAmount();
        } else if (inventory.getItem(i) == null || inventory.getItem(i).getType() == Material.AIR) {
            amount = 0;
        }
        if (amount < 1) {
            return true;
        }
    }
    return false;
}
 
开发者ID:NyaaCat,项目名称:NyaaCore,代码行数:18,代码来源:InventoryUtils.java

示例9: onItemDisappeared

import org.bukkit.inventory.PlayerInventory; //导入依赖的package包/类
private void onItemDisappeared(PlayerEvent event, ItemStack item) {
    final Player player = event.getPlayer();
    final PlayerInventory inventory = player.getInventory();
    final int slotId = inventory.getHeldItemSlot();

    if (!InventoryManager.playerIsLoaded(player)) {
        return;
    }

    if (ItemUtils.isEmpty(inventory.getItemInMainHand()) || item.equals(inventory.getItemInMainHand())) {
        final Slot slot = InventoryManager.getQuickSlot(slotId);
        if (slot != null) {
            new BukkitRunnable() {
                @Override
                public void run() {
                    InventoryUtils.heldFreeSlot(player, slotId, InventoryUtils.SearchType.NEXT);
                    inventory.setItem(slotId, slot.getCup());
                }
            }.runTaskLater(RPGInventory.getInstance(), 1);
        }
    }
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:23,代码来源:InventoryListener.java

示例10: onPlayerInteract2

import org.bukkit.inventory.PlayerInventory; //导入依赖的package包/类
@EventHandler
public void onPlayerInteract2(PlayerInteractEvent e) {
    Player player = e.getPlayer();
    PlayerInventory inventory = player.getInventory();
    if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
        Material material = inventory.getItemInHand().getType();
        if(material == Material.BOW) {
            DynamicAC.getManager().getBackend().logBowWindUp(player, System.currentTimeMillis());
        } else if(Utilities.isFood(material)) {
            DynamicAC.getManager().getBackend().logEatingStart(player);
        }
    }
    Block block = e.getClickedBlock();
    if(block != null) {
        Distance distance = new Distance(player.getLocation(), block.getLocation());
        DynamicAC.getManager().getBackend().checkLongReachBlock(player,distance.getXDifference(),distance
                .getYDifference(),distance.getZDifference());
    }
}
 
开发者ID:Notoh,项目名称:DynamicAC,代码行数:20,代码来源:PlayerListener.java

示例11: isApplicableFor

import org.bukkit.inventory.PlayerInventory; //导入依赖的package包/类
public boolean isApplicableFor(Player player)
{
    PlayerInventory playerInventory = player.getInventory();
    ItemStack helmet = playerInventory.getHelmet();
    if ((helmet == null) || (helmet.getType() != Material.LEATHER_HELMET)) {
        return false;
    }
    ItemStack chestplate = playerInventory.getChestplate();
    if ((chestplate == null) || (chestplate.getType() != Material.LEATHER_CHESTPLATE)) {
        return false;
    }
    ItemStack leggings = playerInventory.getLeggings();
    if ((leggings == null) || (leggings.getType() != Material.LEATHER_LEGGINGS)) {
        return false;
    }
    ItemStack boots = playerInventory.getBoots();
    return (boots != null) && (boots.getType() == Material.LEATHER_BOOTS);
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:19,代码来源:ArcherClass.java

示例12: isApplicableFor

import org.bukkit.inventory.PlayerInventory; //导入依赖的package包/类
@Override
public boolean isApplicableFor(Player player) {
    PlayerInventory playerInventory = player.getInventory();

    ItemStack helmet = playerInventory.getHelmet();
    if (helmet == null || helmet.getType() != Material.IRON_HELMET)
        return false;

    ItemStack chestplate = playerInventory.getChestplate();
    if (chestplate == null || chestplate.getType() != Material.IRON_CHESTPLATE)
        return false;

    ItemStack leggings = playerInventory.getLeggings();
    if (leggings == null || leggings.getType() != Material.IRON_LEGGINGS)
        return false;

    ItemStack boots = playerInventory.getBoots();
    return !(boots == null || boots.getType() != Material.IRON_BOOTS);
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:20,代码来源:MinerClass.java

示例13: isApplicableFor

import org.bukkit.inventory.PlayerInventory; //导入依赖的package包/类
@Override
public boolean isApplicableFor(Player player) {
    PlayerInventory playerInventory = player.getInventory();

    ItemStack helmet = playerInventory.getHelmet();
    if (helmet == null || helmet.getType() != Material.IRON_HELMET || !helmet.getEnchantments().isEmpty())
        return false;

    ItemStack chestplate = playerInventory.getChestplate();
    if (chestplate == null || chestplate.getType() != Material.IRON_CHESTPLATE || !chestplate.getEnchantments().isEmpty())
        return false;

    ItemStack leggings = playerInventory.getLeggings();
    if (leggings == null || leggings.getType() != Material.IRON_LEGGINGS || !leggings.getEnchantments().isEmpty())
        return false;

    ItemStack boots = playerInventory.getBoots();
    return !(boots == null || boots.getType() != Material.IRON_BOOTS || !boots.getEnchantments().isEmpty());
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:20,代码来源:AssassinClass.java

示例14: isApplicableFor

import org.bukkit.inventory.PlayerInventory; //导入依赖的package包/类
@Override
public boolean isApplicableFor(Player player) {
    PlayerInventory playerInventory = player.getInventory();

    ItemStack helmet = playerInventory.getHelmet();
    if (helmet == null || helmet.getType() != Material.CHAINMAIL_HELMET) {
        return false;
    }

    ItemStack chestplate = playerInventory.getChestplate();
    if (chestplate == null || chestplate.getType() != Material.CHAINMAIL_CHESTPLATE) {
        return false;
    }

    ItemStack leggings = playerInventory.getLeggings();
    if (leggings == null || leggings.getType() != Material.CHAINMAIL_LEGGINGS) {
        return false;
    }

    ItemStack boots = playerInventory.getBoots();
    return !(boots == null || boots.getType() != Material.CHAINMAIL_BOOTS);
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:23,代码来源:RogueClass.java

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


注:本文中的org.bukkit.inventory.PlayerInventory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。