Help with command taking inventory items!

Discussion in 'Plugin Development' started by Bernabeast, Jun 25, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Bernabeast

    I want the players to type /bos and it checks their inventory for 64 Dirt.
    If they have the dirt, it takes it and gives them a Stick that does magical stuff.
    How do i get it to understand that the player needs a specific recipe in order to use the command and get the stick?

    Code:
    public void onEnable(){
        getLogger().info("BOOMSTICK plugin has been Enabled!");
        getServer().getPluginManager().registerEvents(this, this);
    }
    
        public void onPlayerInteractEvent1(PlayerInteractEvent event){
            Player player = event.getPlayer();
            ItemStack itst = new ItemStack(Material.DIRT);
        }
        @EventHandler
        public void onPlayerInteractEvent2(PlayerInteractEvent event){
            Player player = event.getPlayer();
            int blockId = player.getItemInHand().getType().getId();
            if(blockId == 280)
            if(player.getInventory().contains(DIRT, 32){
                Block block = player.getTargetBlock(null, 30);
                Location location = block.getLocation();
                World world = player.getWorld();
                world.createExplosion(location, 5);
                player.sendMessage(ChatColor.GREEN + "Ka-Boom!");
            }
        }
    anyone?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
  2. Offline

    BartMiner

    Do: ItemStack dirt = new ItemStack(Material.DIRT, 64);
    And then check the inventory if it contains that itemstack and then removeitem... Should work.

    [not tested code]
     
  3. Offline

    Bernabeast

    BartMiner How do I check their inventory again?

    Like to see if they do have a stack of Dirt?
    If they do then give them the wand(Stick)

    Anyone? I'm a noob and jd.bukkit sucks...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
  4. Offline

    MehrPvM

    Haven't tested it, but here's some code, for giving the boomstick anyway. Since that's what you asked for:
    Code:java
    1. @EventHandler
    2. public void onPlayerInteractEvent2(PlayerInteractEvent event){
    3. ItemStack dirt = new ItemStack(Material.DIRT, 64);
    4. Player player = event.getPlayer();
    5. if(player.getInventory().contains(dirt)){
    6. //Give The BoomStick ETC
    7. }
    8. }
     
    BartMiner likes this.
  5. Offline

    BartMiner


    ^ That looks good.
     
Thread Status:
Not open for further replies.

Share This Page