Java 类org.bukkit.inventory.PlayerInventory 实例源码

项目:BukkitOldCombatMechanics    文件:ModuleOldArmourStrength.java   
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);
}
项目:LeagueOfLegends    文件:PlayerInteractList.java   
@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()));
        }
    }
}
项目:BedwarsXP    文件:XPItemShop.java   
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;
    }
}
项目:BedwarsXP    文件:XPItemShop.java   
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;
    }
}
项目:ProjectAres    文件:ItemKeepPlayerFacet.java   
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();
}
项目:ProjectAres    文件:ViewInventoryMatchModule.java   
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);
    }
}
项目:ProjectAres    文件:ScoreBoxFactory.java   
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);
}
项目:Hub    文件:GuiListener.java   
@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());
        }
    }
}
项目:NyaaCore    文件:InventoryUtils.java   
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;
}
项目:RPGInventory    文件:InventoryListener.java   
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);
        }
    }
}
项目:DynamicAC    文件:PlayerListener.java   
@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());
    }
}
项目:HCFCore    文件:ArcherClass.java   
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);
}
项目:HCFCore    文件:MinerClass.java   
@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);
}
项目:HCFCore    文件:AssassinClass.java   
@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());
}
项目:HCFCore    文件:RogueClass.java   
@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);
}
项目:HCFCore    文件:ArcherClass.java   
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);
}
项目:HCFCore    文件:MinerClass.java   
@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);
}
项目:HCFCore    文件:AssassinClass.java   
@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());
}
项目:HCFCore    文件:RogueClass.java   
@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);
}
项目:UHC    文件:JoinQuitHandlers.java   
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.")));
}
项目:SamaGamesCore    文件:GuiListener.java   
@EventHandler
public void onInventoryClick(InventoryClickEvent event)
{
    if (event.getWhoClicked() instanceof Player)
    {
        Player player = (Player) event.getWhoClicked();
        AbstractGui gui = manager.getPlayerGui(player);

        if (gui != null)
        {
            if (event.getClickedInventory() instanceof PlayerInventory)
                return;

            String action = gui.getAction(event.getSlot());

            if (action != null)
                gui.onClick(player, event.getCurrentItem(), action, event.getClick());

            event.setCancelled(true);
        }
    }
}
项目:StaffPlus    文件:JavaUtils.java   
/**
 * 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;
}
项目:RealisticSwimming    文件:Utility.java   
public static boolean hasElytraStorage(Player player) {
    PlayerInventory inv = player.getInventory();
    if(inv.getStorageContents()!=null){
        for(ItemStack item : inv.getStorageContents()){
            if(item!=null){
                if(!item.getType().equals(Material.AIR)){
                    if(item.getType().equals(Material.ELYTRA)){
                        if(item.getDurability() <= 431)
                            return true;
                    }
                }
            }           
        }
    }
    return false;
}
项目:CastleGates    文件:Helper.java   
public static List<Integer> getConsumeSlots(Player player, ItemStack consumeItem) {
    if(consumeItem == null) return null;

    List<Integer> list = new ArrayList<Integer>();
    PlayerInventory inventory = player.getInventory();
    int inventorySize = inventory.getSize();
    int requiredAmount = consumeItem.getAmount();

    try {
        for(int i = 0; i < inventorySize && requiredAmount > 0; i++) {
            ItemStack item = inventory.getItem(i);

            if(item == null || !consumeItem.isSimilar(item)) {
                continue;
            }

            list.add(i);

            requiredAmount -= item.getAmount();
        }
       } catch (Exception ex) {
       }

    return requiredAmount > 0 ? null :list;
}
项目:BukkitOldCombatMechanics    文件:ModuleDisableElytra.java   
@EventHandler (priority = EventPriority.HIGHEST)
public void onWorldChange(PlayerChangedWorldEvent e){
    Player p = e.getPlayer();
    World w = p.getWorld();
    if(!isEnabled(w)) return;

    PlayerInventory inv = p.getInventory();

    ItemStack chestplate = inv.getChestplate();

    if(chestplate == null || chestplate.getType() != Material.ELYTRA) return;

    inv.setChestplate(new ItemStack(Material.AIR));

    if(inv.firstEmpty() != -1)
        inv.addItem(chestplate);
    else
        w.dropItem(p.getLocation(), chestplate);
}
项目:NationZ    文件:EnchantmentZ.java   
public static int calcInventoryPieceAmount(EnchantmentZ enchantment, PlayerInventory inv) {
    int amount = 0;
    if (Item.get(inv.getHelmet()).hasEnchantment(enchantment)) {
        amount ++;
    }
    if (Item.get(inv.getChestplate()).hasEnchantment(enchantment)) {
        amount ++;
    }
    if (Item.get(inv.getLeggings()).hasEnchantment(enchantment)) {
        amount ++;
    }
    if (Item.get(inv.getBoots()).hasEnchantment(enchantment)) {
        amount ++;
    }
    return amount;
}
项目:Skript    文件:ItemType.java   
/**
 * Removes this type from the given inventory. Does not call updateInventory for players.
 * 
 * @param invi
 * @return Whether everything could be removed from the inventory
 */
public boolean removeFrom(final Inventory invi) {
    ItemStack[] buf = invi.getContents();
    /* This was causing issues with clearing some slots (armor, offhand and last slot)
    // uses an array of size 36. some unknown bug with bukkit
    if (buf.length > 36) {
        ItemStack[] tBuf = buf.clone();
        buf = new ItemStack[35];
        for(int i = 0; i < 35; ++i) {
            buf[i] = tBuf[i];
        }
    }
    */
    final ItemStack[] armour = invi instanceof PlayerInventory ? ((PlayerInventory) invi).getArmorContents() : null;

    @SuppressWarnings("unchecked")
    final boolean ok = removeFrom(Arrays.asList(buf), armour == null ? null : Arrays.asList(armour));

    invi.setContents(buf);
    if (armour != null)
        ((PlayerInventory) invi).setArmorContents(armour);
    return ok;
}
项目:MinigameManager    文件:Minigame.java   
/**
 * Give all the players an item
 * 
 * @param supplier An {@link ItemStackSupplier} that, when given a player,
 *            returns
 *            a pair
 *            of itemstack to give to that player and the slot (-1 for any
 *            available slot)
 * @param backup An instance of {@link PlayerConsumer} that says what to do
 *            in case the player can't receive the item (null
 *            to just ignore)
 */
public void giveAll(final ItemStackSupplier supplier, final PlayerConsumer backup) {
    applyAll(new PlayerConsumer() {
        @Override
        public void apply(Player player) {
            Tuple<ItemStack, Integer> tuple = supplier.apply(player);
            ItemStack itemstack = tuple.getLeft();
            int slot = tuple.getRight();
            PlayerInventory inv = player.getInventory();
            if (slot == -1) {
                HashMap<Integer, ItemStack> error = inv.addItem(itemstack);
                if (error != null && !error.isEmpty())
                    backup.apply(player);
            } else {
                ItemStack i = inv.getItem(slot);
                if (i == null)
                    inv.setItem(slot, itemstack);
                else
                    backup.apply(player);
            }
        }
    });
}
项目:MinigameManager    文件:Minigame.java   
/**
 * Give all the players an item
 * 
 * @param itemstack An {@link ItemStack} to give to each player
 * @param slot The slot number to put the item in
 * @param backup An instance of {@link PlayerConsumer} that says what to do
 *            in case the player can't receive the item (null to just
 *            ignore)
 */
public void giveAll(final ItemStack itemstack, final int slot, final PlayerConsumer backup) {
    applyAll(new PlayerConsumer() {
        @Override
        public void apply(Player player) {
            PlayerInventory inv = player.getInventory();
            if (slot == -1) {
                HashMap<Integer, ItemStack> error = inv.addItem(itemstack);
                if (error != null && !error.isEmpty())
                    backup.apply(player);
            } else {
                ItemStack i = inv.getItem(slot);
                if (i == null)
                    inv.setItem(slot, itemstack);
                else
                    backup.apply(player);
            }
        }
    });
}
项目:GriefPreventionFlags    文件:FlagDef_InfiniteArrows.java   
@EventHandler(priority = EventPriority.LOW)
public void onProjectileHit(ProjectileHitEvent event)
{
    if(event.getEntityType() != EntityType.ARROW && event.getEntityType() != EntityType.SNOWBALL) return;

    Projectile arrow = event.getEntity();

    ProjectileSource source = arrow.getShooter();
    if(source == null || !(source instanceof Player)) return;

    Player player = (Player)source;
    if(player.getGameMode() == GameMode.CREATIVE) return;

    Flag flag = this.GetFlagInstanceAtLocation(arrow.getLocation(), player);
    if(flag == null) return;

    PlayerInventory inventory = player.getInventory();
    ItemMeta meta = inventory.getItemInMainHand().getItemMeta();
    if(meta != null && meta.hasEnchant(Enchantment.ARROW_INFINITE)) return;

    arrow.remove();
    inventory.addItem(new ItemStack(Material.ARROW));
}
项目:AutomaticInventory    文件:AIEventHandler.java   
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onInventoryClose(InventoryCloseEvent event)
{
    Inventory bottomInventory = event.getView().getBottomInventory();
    if(bottomInventory == null) return;
    if(bottomInventory.getType() != InventoryType.PLAYER) return;

    HumanEntity holder = ((PlayerInventory)bottomInventory).getHolder();
    if(!(holder instanceof Player)) return;

    Player player = (Player)holder;
    PlayerData playerData = PlayerData.FromPlayer(player);

    sortPlayerIfEnabled(player, playerData, bottomInventory);

    if(player.getGameMode() != GameMode.CREATIVE && Math.random() < .1 && !playerData.isGotDepositAllInfo() && featureEnabled(Features.DepositAll, player))
    {
        Inventory topInventory = event.getView().getTopInventory();
        if(topInventory != null && topInventory.getType() == InventoryType.CHEST)
        {
            AutomaticInventory.sendMessage(player, TextMode.Instr, Messages.DepositAllAdvertisement);
            playerData.setGotDepositAllInfo(true);
        }
    }
}
项目:AutomaticInventory    文件:AIEventHandler.java   
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPickupItem(PlayerPickupItemEvent event)
{
    Player player = event.getPlayer();
    if(featureEnabled(Features.SortInventory, player))
    {
        PlayerData playerData = PlayerData.FromPlayer(player);
        if(playerData.firstEmptySlot >= 0) return;

        PlayerInventory inventory = player.getInventory();
        int firstEmpty = inventory.firstEmpty();
        if(firstEmpty < 9) return;
        playerData.firstEmptySlot = firstEmpty; 
        PickupSortTask task = new PickupSortTask(player, playerData, inventory);
        Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(AutomaticInventory.instance, task, 100L);
    }
}
项目:CommunityDrivenPlugin    文件:Kits.java   
public static void giveFirstPlayKit(Player p, SQLUser sqlUser) {
    PlayerInventory inv = p.getInventory();
    if ( !sqlUser.getRank().equals("Gracz")){
        Kits.giveVipKit(p);
        inv.addItem(
                new ItemStack(Material.ENDER_CHEST, 2)
        );
    } else {
        Kits.giveDefaultKit(p);
        inv.addItem(
                new ItemStack(Material.ENDER_CHEST, 1)

        );
    }


}
项目:Breakpoint    文件:InventoryMenuManager.java   
public static void displayVIPContents(BPPlayer bpPlayer, PlayerInventory pi)
{
    BPEquipment[] contents = bpPlayer.getLobbyInventory().getContents();
    int k = 0;

    for (int i = 0; i < 3; i++)
        for (int j = 0; j < 4; j++)
        {
            int slotId = 14 + i * 9 + 3 - j;
            BPEquipment bpEquipment = contents[k + 16];
            if (bpEquipment != null)
            {
                ItemStack is = bpEquipment.getItemStack();
                pi.setItem(slotId, is);
                k++;
                continue;
            }
            pi.setItem(slotId, null);
            k++;
        }
}
项目:Breakpoint    文件:PlayerInteractListener.java   
@SuppressWarnings("deprecation")
public void voting(PlayerInteractEvent event, BPPlayer bpPlayer)
{
    Game game = bpPlayer.getGame();
    Player player = bpPlayer.getPlayer();
    MapPoll mapPoll = game.getMapPoll();
    PlayerInventory inv = player.getInventory();
    int mapId = inv.getHeldItemSlot();
    if(mapPoll.isIdCorrect(mapId))
    {
        String playerName = player.getName();
        if(!mapPoll.hasVoted(playerName))
        {
            int strength = player.hasPermission("Breakpoint.vip") ? 2 : 1;
            mapPoll.vote(playerName, mapId, strength);
            PlayerManager.clearHotBar(inv);
            player.updateInventory();
            String mapName = mapPoll.maps[mapId];
            player.sendMessage(MessageType.VOTING_VOTE.getTranslation().getValue(mapName));
        }
    }
}
项目:AnnihilationPro    文件:ShopMenuItem.java   
@Override
public void onItemClick(ItemClickEvent event)
{
    Player player = event.getPlayer();
    PlayerInventory p = player.getInventory();
    if(p.containsAtLeast(new ItemStack(Material.GOLD_INGOT), cost))
    {
        int total = 0;
        for(ItemStack s : p.all(Material.GOLD_INGOT).values())
        {
            total += s.getAmount();
        }
        p.remove(Material.GOLD_INGOT);
        if(total-cost > 0)
            p.addItem(new ItemStack(Material.GOLD_INGOT,total-cost));
        p.addItem(product);
        player.sendMessage(Lang.PURCHASEDITEM.toString());
    }
    else player.sendMessage(Lang.COULDNOTPURCHASE.toString());
}
项目:CS-CoreLib    文件:InvUtils.java   
public static boolean fits(Inventory inv, ItemStack item) {
    Inventory inv2 = null;
    int size = inv.getSize();
    if (inv instanceof PlayerInventory) {
        size = 36;
        inv2 = Bukkit.createInventory(null, size);
    }
    else if (inv.getSize() % 9 == 0) {
        inv2 = Bukkit.createInventory(null, size);
    }
    else {
        inv2 = Bukkit.createInventory(null, inv.getType());
    }
    for (int i = 0; i < size; i++) {
        inv2.setItem(i, inv.getItem(i));
    }
    return inv2.addItem(item).isEmpty();
}
项目:iZenith-PVP    文件:SetKit.java   
@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>");
    }
}
项目:iZenith-PVP    文件:KitManager.java   
public static void clearKit(Player player) {
    PlayerInventory inv = player.getInventory();
    inv.clear();
    inv.setArmorContents(new ItemStack[4]);

    for (PotionEffect effect : player.getActivePotionEffects()) {
        player.removePotionEffect(effect.getType());
    }

    IPlayer iPlayer = IPlayerHandler.getPlayer(player);
    if (iPlayer.isGhost()) {
        iPlayer.setGhost(false);
        iPlayer.setTeam();
    }
    iPlayer.gotKit = false;
}
项目:LeagueOfLegends    文件:PlayerJoinList.java   
@EventHandler
public void onJoin(PlayerJoinEvent e){
    Player p = e.getPlayer();
    p.setHealth(p.getMaxHealth());
    p.setFoodLevel(20); //TODO
    PlayerInventory i = p.getInventory();
    i.clear();
    i.setHeldItemSlot(4);
    i.setItem(4, JOIN_ITEM);

    User u = new User(p);
    UserManager.addUser(u);
    u.setChampion(ChampType.YASUO);
    u.setTeam(TeamType.NONE);
    TabTitle tab = new TabTitle("�2Witaj na serwerze \n Grzybie", "�5League Of Legends!");
    Title title = new Title("�6�lWitamy", "�a�lXD Prodaksh�n", 10, 10, 30);
    bar.addPlayer(p);
    tab.send(p);
    title.send(p);
    runTask(ScoreBoard.get(p)); //test
    ProfileLoader profile = new ProfileLoader(p.getUniqueId().toString(), p.getName(), "skkf");
    profile.loadProfile();
}