AutoCollect Plugin

Discussion in 'Plugin Development' started by Trill, Dec 19, 2014.

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

    Trill

    I am trying to make an AutoCollect plugin where a player types "/autocollect" abbreviated "/ac" and then every block that they break goes straight to their inventory. If they don't have enough place in their inventory then it sends a message to the player saying that their inventory is full and drops the block on the ground. If they type /ac or /autocollect again then it goes back to normal dropping broken blocks on the ground for the certain player.

    Any help?
     
  2. Offline

    mythbusterma

    @Trill

    What have you attempted so far? What are you getting hung up on?
     
  3. Offline

    Trill

    @mythbusterma
    Code:
    public class AutoCollect extends JavaPlugin
    { 
        @Override
        public void onEnable()
        {
         
        }
     
        @Override
        public void onDisable()
        {
         
        }
    
        public boolean onCommand(CommandSender theSender, Command cmd, String commandLabel, String[] args)
        { 
            if(commandLabel.equalsIgnoreCase("autocollect"))
            {
             
            }
        }
    }
    Not sure how to give a player the block that they broke.
     
    Last edited: Dec 19, 2014
  4. Offline

    mythbusterma

    pookeythekid likes this.
  5. Offline

    Trill

    @mythbusterma
    I am having trouble getting the BlockBreakEvent to work.
     
  6. Offline

    mythbusterma

  7. Offline

    Trill

    @mythbusterma
    Code:
    public class AutoCollect extends JavaPlugin
    {  
        @Override
        public void onEnable()
        {
          
        }
      
        @Override
        public void onDisable()
        {
          
        }
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(commandLabel.equalsIgnoreCase("autocollect")){
                   Player player = (Player) sender;
                   BlockBreakEvent.getPlayer();
                   player.getInventory().addItem(new ItemStack(Material., 384));
                }
            else
                {
                   sender.sendMessage("You must be a player!");
                   return false;
                }
                // do something
                return false;  
        }
    }
    Not very finalized but still a starting point.
    What the plugin is supposed to do is check to see if a player breaks a block, then it finds out what that block is, and gives it to the player that broke the block. Problem is, if a player breaks a diamond ore then they will get the ore block and not the diamonds themselves.

    Only way to fix this is to give the player what is about to drop on the ground and then delete the ores that were about to drop.
     
  8. Offline

    teej107

    I laughed out loud at that response!

    Read the plugin tutorial that
    @mythbusterma linked to. You have the wrong idea of using events.
     
  9. Offline

    mythbusterma

    @Trill

    Eh, I linked the wrong page, I meant to link this one, it will probably help with your Events.
     
  10. Offline

    ResultStatic

    @Trill I suggest researching a bit more because that code will get you no where very fast. Your code checks if the command is autocollect if it isn't tell the sender they arnt a player.
     
  11. Offline

    Trill

    @ResultStatic
    True... Sort of a beginner at Bukkit. How would I make it check for a BlockBreakEvent continuously after the command is sent?
     
  12. Offline

    ResultStatic

    You have to use Events. The code under the command check will NEVER be called when a player breaks a block. You must have a seperate method of checking when blocks are broken
     
  13. Offline

    teej107

    @Trill
     
  14. Offline

    Trill

    @teej107
    I saw that page but I still can't figure out how to do it.
     
  15. Offline

    teej107

    @Trill How to do what exactly?
     
  16. Offline

    Trill

    @teej107
    How to check to see if a player breaks a block, then it finds out what that block is, and gives it to the player that broke the block. But if they broke a stone block then it would have to give them cobblestone, and diamond ore would give them diamonds.
     
  17. Offline

    Skionz

    @Trill The BlockBreakEvent class has all the methods you need. You can get the block's drops, which you can add to the player's inventory and cancel the event.
     
  18. Offline

    teej107

  19. Offline

    Trill

    @Skionz
    How would I get the block drops. After looking at the link you sent me I can only seem to find exp drops.

    Can someone help me with the code?
     
  20. Offline

    mythbusterma

    @Trill

    I told you how to get the block drop, you can also do Block#getDrops().....it's kinda hard to miss that method.
     
  21. Offline

    Skionz

    @Trill Get the Block using BlockBreakEvent#getBlock() then use Block#getDrops() to get the Block's drops.
     
  22. Offline

    teej107

    Does the BlockBreakEvent drop the items or does the <blank> drop the items?


    @Skionz @mythbusterma Gee thanks for ninja-ing me and ruining my riddle....
     
    Monkey_Swag and Skionz like this.
  23. Offline

    Trill

    So how do I tie it all together?
    Code:
    package me.CubedOutGaming.AutoCollect;
    
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class AutoCollect extends JavaPlugin
    {   
        @Override
        public void onEnable()
        {
           
        }
       
        @Override
        public void onDisable()
        {
           
        }
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(commandLabel.equalsIgnoreCase("autocollect")){
                   //DO SOMETHING
                }
            else
                {   
                   sender.sendMessage("You must be a player!");
                   return false;
                }
    
        public void onBlockBreak(BlockBreakEvent)
        {
            BlockBreakEvent.getPlayer();
            Block.getDrops();
            player.getInventory().addItem(new ItemStack(Material.Block.getDrops(), Block.getDrops()));
            player.getExpToDrop();
        }
    
     
    Last edited: Dec 19, 2014
  24. Offline

    mythbusterma

    @Trill

    I would recommend storing a Set of Players that are in the mode, and checking to see if someone's in it each time a block is broken.
     
  25. Offline

    Trill

    One question, how would I link up the command /autocollect to start checking for:
    Code:
    public void onBlockBreak(BlockBreakEvent)
    And then if you type it again to stop checking for it.
     
  26. Offline

    teej107

    @Trill You do realize that making plugins require a basic knowledge of Java right? From your other code, I highly doubt you are sufficient enough.
     
  27. Offline

    Skionz

    @Trill You are getting a syntax error.
     
  28. Offline

    Trill

    @Skionz I am for the (BlockBreakEvent) part.
    How can I fix this?
     
  29. Offline

    Skionz

  30. Offline

    teej107

    @Trill
     
Thread Status:
Not open for further replies.

Share This Page