Minigame.java 文件源码

java
阅读 24 收藏 0 点赞 0 评论 0

项目:MinigameManager 作者:
/**
 * 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);
            }
        }
    });
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号