當前位置: 首頁>>代碼示例>>Java>>正文


Java PlayerInventory.addItem方法代碼示例

本文整理匯總了Java中org.bukkit.inventory.PlayerInventory.addItem方法的典型用法代碼示例。如果您正苦於以下問題:Java PlayerInventory.addItem方法的具體用法?Java PlayerInventory.addItem怎麽用?Java PlayerInventory.addItem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.bukkit.inventory.PlayerInventory的用法示例。


在下文中一共展示了PlayerInventory.addItem方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onWorldChange

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
@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);
}
 
開發者ID:gvlfm78,項目名稱:BukkitOldCombatMechanics,代碼行數:20,代碼來源:ModuleDisableElytra.java

示例2: onProjectileHit

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
@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));
}
 
開發者ID:BigScary,項目名稱:GriefPreventionFlags,代碼行數:24,代碼來源:FlagDef_InfiniteArrows.java

示例3: giveFirstPlayKit

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
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)

        );
    }


}
 
開發者ID:grzegorz2047,項目名稱:CommunityDrivenPlugin,代碼行數:18,代碼來源:Kits.java

示例4: onItemClick

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
@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());
}
 
開發者ID:MrLittleKitty,項目名稱:AnnihilationPro,代碼行數:21,代碼來源:ShopMenuItem.java

示例5: restoreInventory

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
void restoreInventory(Player p) {
    removeAllTools(p);
    UUID uuid = p.getUniqueId();
    ItemStack[] savedInv = savedInventories.get(uuid);
    if(savedInv == null) return;
    PlayerInventory plrInv = p.getInventory();
    ItemStack[] newItems = plrInv.getContents().clone();
    plrInv.setContents(savedInv);
    savedInventories.remove(uuid);
    for(ItemStack i : newItems) {
        if(i == null) continue;
        HashMap<Integer, ItemStack> couldntFit = plrInv.addItem(i);
        for (ItemStack is : couldntFit.values()) {
            p.getWorld().dropItem(p.getLocation(), is);
        }
    }
    p.sendMessage(ChatColor.GREEN + Config.invReturned);
}
 
開發者ID:St3venAU,項目名稱:ArmorStandTools,代碼行數:19,代碼來源:Main.java

示例6: checkMobInventoy

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
public static void checkMobInventoy(EntityType Entity, Player p, EntityDeathEvent ede){
	
	PlayerInventory pi = p.getInventory();
	FileConfiguration gc = Core.plugin.getConfig();
	
	//Checks to see if killed entity is a Player
	if(Entity.equals(EntityType.PLAYER)){
		if(!Globals.PlayerDrops){ede.getDrops().clear();}
	}else{
		if(!Globals.BothDrops){ ede.getDrops().clear(); };
	}
	
	//Shows Killed Entity and What item is in config according to said Entity.
	if(Globals.Debug){
		p.sendMessage(Globals.Debug(Entity.name()));
		p.sendMessage(Globals.Debug(gc.getString("eDrop.Mobs." + Entity.name() + ".Item")));
	}
	
	Material m = Material.valueOf(gc.getString("eDrop.Mobs." + Entity.name() + ".Item")); 	//Gets Mobs Item
	int a = gc.getInt("eDrop.Mobs." + Entity.name() + ".ItemAmount");						//Gets Mobs Item Amount
	
	pi.addItem(new ItemStack(m, a)); //Adds Item to Inventory of Player
	
}
 
開發者ID:EpicUnknown,項目名稱:EpicDrop,代碼行數:25,代碼來源:MobDeath.java

示例7: mergeIntoPlayerInventory

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
public void mergeIntoPlayerInventory(Player player, Location overflowDropLocation) {
	PlayerInventory inventory = player.getInventory();
	
	LinkedList<ItemStack> overflows = new LinkedList<ItemStack>();
	
	inventory.setArmorContents(itemsToSet(inventory.getArmorContents(), savedArmorContents, overflows));
	inventory.setContents(itemsToSet(inventory.getContents(), savedInventoryContents, overflows));
	
	// Now add any overflows
	HashMap<Integer, ItemStack> failedToAdd = inventory.addItem(overflows.toArray(new ItemStack[overflows.size()]));
	
	// If we failed to add any items (due to a full inventory), drop them near the player
	// This can only occur if another plugin has filled up the player's inventory before us
	for (ItemStack item : failedToAdd.values()) {
		player.sendMessage("Dropping " + item.getAmount() + " " + item.getType() + " due to full inventory!");
		player.getWorld().dropItem(overflowDropLocation, item);
	}
}
 
開發者ID:pavben,項目名稱:Bukkit-DropProtect,代碼行數:19,代碼來源:ProtectedItemsSnapshot.java

示例8: onCommand

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
public boolean onCommand(CommandSender sender, Command cmd, String label,  String[] args){
	
	Player player = null;
	if (!(sender instanceof Player))
		Resources.privateMsg(sender, "Only a player can execute this command");
	else{
		//Permissions
		if (!sender.hasPermission("LetItRain.launcher"))
			return true;
		
		
		player = (Player)sender;
		PlayerInventory inventory = player.getInventory();
		
		inventory.addItem(new ItemStack(LetItRain.item));
		
		String outputMsg = LetItRain.dGrenadeMsg;
		outputMsg = outputMsg.replaceAll(Pattern.quote("[player]"), player.getName());
		if(!outputMsg.isEmpty())
			Resources.broadcast(outputMsg);
	}
	
	return true;
	
}
 
開發者ID:Bathlamos,項目名稱:Let-It-Rain,代碼行數:27,代碼來源:Launcher.java

示例9: handlePlayer

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
public boolean handlePlayer(BytecraftPlayer player, String[] args)
{
    if(!player.getRank().canSpawnHeads()){
        player.sendMessage(getInvalidPermsMessage());
        return true;
    }
    
    
    if (args.length == 1) {
        ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
        SkullMeta itemMeta = (SkullMeta) item.getItemMeta();
        itemMeta.setOwner(args[0]);
        itemMeta.setDisplayName(ChatColor.YELLOW + args[0] + "'s head");
        item.setItemMeta(itemMeta);
        PlayerInventory inventory = player.getInventory();
        inventory.addItem(item);
        player.sendMessage(ChatColor.YELLOW + "You received the head of "
                + args[0]);
    }
    else {
        player.sendMessage(ChatColor.RED + "Type /head <player>");
    }
    return true;
}
 
開發者ID:sabersamus,項目名稱:Bytecraft,代碼行數:25,代碼來源:HeadCommand.java

示例10: stuff

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
/**
 * Give an item set to a player.
 * @param player
 * @param item
 */
public void stuff(Player player, ItemSet item)
{
	PlayerInventory inv = player.getInventory();

	switch (item)
	{
	case MANUAL:
		if (new Random().nextInt(20) > 0)
			inv.addItem(manual);
		else
			inv.addItem(manual_bonus);
		break;
	case SPECTATOR:
		inv.addItem(spectating_compass);
		break;
	}
}
 
開發者ID:Elarcis,項目名稱:Scapegoat,代碼行數:23,代碼來源:ItemStuffer.java

示例11: giveVipKit

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
public static void giveVipKit(Player p) {
    PlayerInventory inv = p.getInventory();
    if (inv.firstEmpty() != -1) {
        inv.addItem(
                new ItemStack(Material.IRON_SWORD, 1),
                new ItemStack(Material.IRON_PICKAXE, 1),
                new ItemStack(Material.IRON_AXE, 1),
                new ItemStack(Material.IRON_SPADE, 1),
                new ItemStack(Material.COOKED_BEEF, 32),
                new ItemStack(Material.BOAT, 1)
        );
    }
}
 
開發者ID:grzegorz2047,項目名稱:CommunityDrivenPlugin,代碼行數:14,代碼來源:Kits.java

示例12: giveDefaultKit

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
public static void giveDefaultKit(Player p) {
    PlayerInventory inv = p.getInventory();
    if (inv.firstEmpty() != -1) {
        inv.addItem(
                new ItemStack(Material.STONE_SWORD, 1),
                new ItemStack(Material.STONE_PICKAXE, 1),
                new ItemStack(Material.STONE_AXE, 1),
                new ItemStack(Material.STONE_SPADE, 1),
                new ItemStack(Material.COOKED_BEEF, 32),
                new ItemStack(Material.BOAT, 1)
        );
    }
}
 
開發者ID:grzegorz2047,項目名稱:CommunityDrivenPlugin,代碼行數:14,代碼來源:Kits.java

示例13: giveStartingGear

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
/**Gives the players starting gear, called during dungeon startup.
 * @param p 	The player to give stuff to.
 */
private void giveStartingGear(Player p) {
PlayerInventory i = p.getInventory();
i.clear();
i.addItem( new ItemStack(Material.STONE_SWORD, 	 1));
i.addItem( new ItemStack(Material.BOW, 			 1));
i.addItem( new ItemStack(Material.ARROW, 		 1));
i.addItem( new ItemStack(Material.MUSHROOM_SOUP, 1));

i.setBoots(new ItemStack(Material.LEATHER_BOOTS, 1));
}
 
開發者ID:TheRoot89,項目名稱:DungeonGen,代碼行數:14,代碼來源:DunGen.java

示例14: give

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
@Override
public void give(Player player) {
	for (ItemReward item : getItems()) {
		Material material = Material.getMaterial(item.getId());
		if (material != null) {
			ItemStack stack = new ItemStack(material, item.getAmount());
			
			PlayerInventory inventory = player.getInventory();
			HashMap<Integer, ItemStack> leftOvers = inventory.addItem(stack);
			for (ItemStack itemStack : leftOvers.values()) {
				player.getWorld().dropItemNaturally(player.getLocation(), itemStack);
			}
		}				
	}		
}
 
開發者ID:Allov,項目名稱:world-of-icerealm,代碼行數:16,代碼來源:ItemsReward.java

示例15: apply

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
@Override
public void apply(GamePlayer player) {
    PlayerInventory inventory = player.getBukkit().getInventory();

    if (this.hasSlot()) {
        inventory.setItem(this.getSlot(), this.getResult());
    } else {
        inventory.addItem(this.getResult());
    }
}
 
開發者ID:ShootGame,項目名稱:Arcade2,代碼行數:11,代碼來源:ItemStackContent.java


注:本文中的org.bukkit.inventory.PlayerInventory.addItem方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。