Auto PickUP

Discussion in 'Spigot Plugin Help' started by Creper_face, Jul 11, 2015.

  1. Does anyone know what is wrong with this code?

    Code (Text):
    package com.cove.pick;

    import java.util.Collection;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.Server;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin
      implements Listener
    {
      public void onEnable()
      {
        getServer().getPluginManager().registerEvents(this, this);
      }

      public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
      {
        if (!(sender instanceof Player)) {
          sender.sendMessage(ChatColor.RED +
            "Only players can use this command!");
        }

        Player player = (Player)sender;

        cmd.getName().equalsIgnoreCase("autopickup");

        return true;
      }

      @EventHandler
      public void onBlockBreak(BlockBreakEvent event) {
        Player player = event.getPlayer();
        Collection items = event.getBlock().getDrops();

        for (ItemStack drops : items) {
          player.getInventory().addItem(new ItemStack[] { drops });
          event.getBlock().getDrops().remove(event.getBlock().getDrops());
        }

        event.setCancelled(true);
        event.getBlock().setType(Material.AIR);
      }
    }