當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。