java类org.bukkit.inventory.PlayerInventory的实例源码

ModuleOldArmourStrength.java 文件源码 项目:BukkitOldCombatMechanics 阅读 19 收藏 0 点赞 0 评论 0
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);
}
PlayerInteractList.java 文件源码 项目:LeagueOfLegends 阅读 20 收藏 0 点赞 0 评论 0
@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()));
        }
    }
}
XPItemShop.java 文件源码 项目:BedwarsXP 阅读 20 收藏 0 点赞 0 评论 0
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;
    }
}
XPItemShop.java 文件源码 项目:BedwarsXP 阅读 25 收藏 0 点赞 0 评论 0
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;
    }
}
ItemKeepPlayerFacet.java 文件源码 项目:ProjectAres 阅读 22 收藏 0 点赞 0 评论 0
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();
}
ViewInventoryMatchModule.java 文件源码 项目:ProjectAres 阅读 30 收藏 0 点赞 0 评论 0
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);
    }
}
ScoreBoxFactory.java 文件源码 项目:ProjectAres 阅读 19 收藏 0 点赞 0 评论 0
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);
}
GuiListener.java 文件源码 项目:Hub 阅读 21 收藏 0 点赞 0 评论 0
@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());
        }
    }
}
InventoryUtils.java 文件源码 项目:NyaaCore 阅读 20 收藏 0 点赞 0 评论 0
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;
}
InventoryListener.java 文件源码 项目:RPGInventory 阅读 24 收藏 0 点赞 0 评论 0
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);
        }
    }
}
PlayerListener.java 文件源码 项目:DynamicAC 阅读 26 收藏 0 点赞 0 评论 0
@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());
    }
}
ArcherClass.java 文件源码 项目:HCFCore 阅读 18 收藏 0 点赞 0 评论 0
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);
}
MinerClass.java 文件源码 项目:HCFCore 阅读 17 收藏 0 点赞 0 评论 0
@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);
}
AssassinClass.java 文件源码 项目:HCFCore 阅读 28 收藏 0 点赞 0 评论 0
@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());
}
RogueClass.java 文件源码 项目:HCFCore 阅读 20 收藏 0 点赞 0 评论 0
@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);
}
ArcherClass.java 文件源码 项目:HCFCore 阅读 18 收藏 0 点赞 0 评论 0
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);
}
MinerClass.java 文件源码 项目:HCFCore 阅读 20 收藏 0 点赞 0 评论 0
@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);
}
AssassinClass.java 文件源码 项目:HCFCore 阅读 23 收藏 0 点赞 0 评论 0
@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());
}
RogueClass.java 文件源码 项目:HCFCore 阅读 25 收藏 0 点赞 0 评论 0
@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);
}
JoinQuitHandlers.java 文件源码 项目:UHC 阅读 27 收藏 0 点赞 0 评论 0
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.")));
}
GuiListener.java 文件源码 项目:SamaGamesCore 阅读 19 收藏 0 点赞 0 评论 0
@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);
        }
    }
}
JavaUtils.java 文件源码 项目:StaffPlus 阅读 23 收藏 0 点赞 0 评论 0
/**
 * 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;
}
Utility.java 文件源码 项目:RealisticSwimming 阅读 45 收藏 0 点赞 0 评论 0
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;
}
Helper.java 文件源码 项目:CastleGates 阅读 34 收藏 0 点赞 0 评论 0
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;
}
ModuleDisableElytra.java 文件源码 项目:BukkitOldCombatMechanics 阅读 21 收藏 0 点赞 0 评论 0
@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);
}
EnchantmentZ.java 文件源码 项目:NationZ 阅读 18 收藏 0 点赞 0 评论 0
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;
}
ItemType.java 文件源码 项目:Skript 阅读 29 收藏 0 点赞 0 评论 0
/**
 * 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;
}
Minigame.java 文件源码 项目:MinigameManager 阅读 21 收藏 0 点赞 0 评论 0
/**
 * 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);
            }
        }
    });
}
Minigame.java 文件源码 项目:MinigameManager 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 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);
            }
        }
    });
}
FlagDef_InfiniteArrows.java 文件源码 项目:GriefPreventionFlags 阅读 27 收藏 0 点赞 0 评论 0
@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));
}


问题


面经


文章

微信
公众号

扫码关注公众号