当前位置: 首页>>代码示例>>Java>>正文


Java PlayerInventory.firstEmpty方法代码示例

本文整理汇总了Java中org.bukkit.inventory.PlayerInventory.firstEmpty方法的典型用法代码示例。如果您正苦于以下问题:Java PlayerInventory.firstEmpty方法的具体用法?Java PlayerInventory.firstEmpty怎么用?Java PlayerInventory.firstEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bukkit.inventory.PlayerInventory的用法示例。


在下文中一共展示了PlayerInventory.firstEmpty方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: onPickupItem

import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
@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);
    }
}
 
开发者ID:BigScary,项目名称:AutomaticInventory,代码行数:18,代码来源:AIEventHandler.java

示例3: 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

示例4: 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

示例5: onPlayerMove

import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
@EventHandler
public void onPlayerMove(PlayerMoveEvent e) {
   	Player p = e.getPlayer();
   	
   	//set velocities
   	if (!p.hasPermission("redprotect.bypass.velocity")){
   		if (RPConfig.getGlobalFlagFloat(p.getWorld().getName()+".player-velocity.walk-speed") >= 0){
       		p.setWalkSpeed(RPConfig.getGlobalFlagFloat(p.getWorld().getName()+".player-velocity.walk-speed"));
       	}
       	if (RPConfig.getGlobalFlagFloat(p.getWorld().getName()+".player-velocity.fly-speed") >= 0){
       		p.setFlySpeed(RPConfig.getGlobalFlagFloat(p.getWorld().getName()+".player-velocity.fly-speed"));
       	}
   	}
   	
   	if (RedProtect.get().version >= 191){    		
   		if (!RPConfig.getGlobalFlagBool(p.getWorld().getName()+".elytra.allow")){
   			ItemStack item = p.getInventory().getChestplate();
   			if (item != null && item.getType().equals(Material.ELYTRA)){
   				PlayerInventory inv = p.getInventory();
   				inv.setChestplate(new ItemStack(Material.AIR));
   				if (inv.firstEmpty() == -1){
   					p.getWorld().dropItem(p.getLocation(), item);
   				} else {
   					inv.setItem(inv.firstEmpty(),item);
   				}    				
   				p.playSound(p.getLocation(), Sound.ENTITY_ITEM_PICKUP, 10, 1);
   				RPLang.sendMessage(p, "globallistener.elytra.cantequip");
   				return;
   			}
   		}
   		    		 		    		
   		double boost = RPConfig.getGlobalFlagDouble(p.getWorld().getName()+".elytra.boost");
   		if (boost > 0 && p.isGliding() && RPConfig.getGlobalFlagBool(p.getWorld().getName()+".elytra.allow")){
   			Vector vec = new Vector(0.0D, p.getLocation().getDirection().getY(), 0.0D);
               p.setVelocity(p.getVelocity().add(vec.multiply(0.1D*boost/2)));
   		}
   	}    	
   }
 
开发者ID:FabioZumbi12,项目名称:RedProtect,代码行数:39,代码来源:RPGlobalListener.java

示例6: onClickOnObsidian

import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.NORMAL)
public void onClickOnObsidian(final PlayerInteractEvent event) {
    if (!plugin.isSkyWorld(event.getPlayer().getWorld())) {
        return;
    }
    long now = System.currentTimeMillis();
    Player player = event.getPlayer();
    PlayerInventory inventory = player != null ? player.getInventory() : null;
    Block block = event.getClickedBlock();
    Long lastClick = obsidianClick.get(player.getUniqueId());
    if (lastClick != null && (lastClick + OBSIDIAN_SPAM) >= now) {
        plugin.notifyPlayer(player, tr("\u00a74You can only convert obsidian once every 10 seconds"));
        return;
    }
    if (Settings.extras_obsidianToLava && plugin.playerIsOnIsland(player)
            && plugin.isSkyWorld(player.getWorld())
            && event.getAction() == Action.RIGHT_CLICK_BLOCK
            && player.getItemInHand() != null
            && player.getItemInHand().getType() == Material.BUCKET
            && block != null
            && block.getType() == Material.OBSIDIAN
            && !testForObsidian(block)) {
        if (inventory.firstEmpty() != -1) {
            obsidianClick.put(player.getUniqueId(), now);
            player.sendMessage(tr("\u00a7eChanging your obsidian back into lava. Be careful!"));
            inventory.removeItem(new ItemStack(Material.BUCKET, 1));
            inventory.addItem(new ItemStack(Material.LAVA_BUCKET, 1));
            player.updateInventory();
            block.setType(Material.AIR);
            event.setCancelled(true); // Don't execute the click anymore (since that would re-place the lava).
        } else {
            player.sendMessage(tr("\u00a7eYour inventory must have another empty space!"));
        }
    }
}
 
开发者ID:rlf,项目名称:uSkyBlock,代码行数:36,代码来源:PlayerEvents.java

示例7: 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.zeus"))
			return true;
		
		
		player = (Player)sender;
		PlayerInventory inv = player.getInventory();
		Material mat = Material.getMaterial(LetItRain.itemZeus);
		ItemStack item = new ItemStack(mat);
		if (!inv.contains(mat) && inv.firstEmpty() != -1){                	
			inv.addItem(item);
			String outputMsg = LetItRain.dZeusMsg;
			outputMsg = outputMsg.replaceAll(Pattern.quote("[player]"), player.getName());
			if(!outputMsg.isEmpty()){
				Resources.broadcast(outputMsg);
			}
		}
	}
	return true;
}
 
开发者ID:Bathlamos,项目名称:Let-It-Rain,代码行数:28,代码来源:Zeus.java

示例8: lootChest

import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
/**
 * 
 * @param player		player doing the looting
 * @param block			block to attempt to loot
 * @param iterations	depth of recursion
 */
private void lootChest(Player player, Block block, int iterations) {
	
	// increment iteration count for recursion
	iterations++;
	
	if (block.getType().equals(Material.CHEST)) {
		PlayerInventory playerinventory = player.getInventory();
		BlockState state = block.getState();
		Chest chest = (Chest)state;
		ItemStack[] chestinventory = chest.getInventory().getContents();
		for(int i = 0; i < chestinventory.length && playerinventory.firstEmpty() != -1; i++) {
			if(chestinventory[i] != null) {
				playerinventory.addItem(chestinventory[i]);
				chest.getInventory().removeItem(chestinventory[i]);
				if (plugin.getConfig().getBoolean("sound-effects")) {
					player.playSound(player.getLocation(), Sound.ENTITY_ITEM_PICKUP, 1, 1);
				}
			}
		}
	}

	// destroy DeathChestBlock
	destroyDeathChestBlock(block);
	
	// if less than two chests have been detected,
	// check surrounding blocks for another chest
	if (iterations < 2) {
		
		BlockFace[] faces = { BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST };
	
		for (BlockFace face : faces) {
			Block testblock = block.getRelative(face);
			if (testblock.getType().equals(Material.CHEST) &&
					DeathChestBlock.isDeathChestBlock(testblock)) {
				lootChest(player,testblock,iterations);
			}
		}
	}
}
 
开发者ID:tim-savage,项目名称:SavageDeathChest,代码行数:46,代码来源:ChestManager.java

示例9: giveMagicHoe

import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
void giveMagicHoe(Player player, ItemStack hoe) {

        if (player.hasPermission("umagic.gethoe")) {

            PlayerInventory playerInventory = player.getInventory();
            int firstEmpty = playerInventory.firstEmpty();

            if (firstEmpty >= 0) {
                player.playSound(player.getLocation(), Sound.BLOCK_LAVA_POP, 0.75f, 0.75f);
                playerInventory.setItem(firstEmpty, hoe);
            } else getActionMessage().message(player, "" + ChatColor.AQUA + ChatColor.BOLD
                    + "Your inventory is full!");

        }

    }
 
开发者ID:Ullarah,项目名称:MinecraftPlugins,代码行数:17,代码来源:MagicFunctions.java


注:本文中的org.bukkit.inventory.PlayerInventory.firstEmpty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。