Loading Locations from ArrayList and setting Type doesn't work

Discussion in 'Plugin Development' started by FlxiFlix, Jul 14, 2013.

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

    FlxiFlix

    I am coding a spleef plugin but the resetting doesn't work!

    This is my code:

    Code:java
    1. ArrayList<Location> blocks = new ArrayList<Location>();
    2.  
    3. @EventHandler
    4. public void onPlayerInteract(PlayerInteractEvent e) {
    5. if(e.getAction() == Action.LEFT_CLICK_BLOCK) {
    6. if(e.getClickedBlock().getType() == Material.GRASS) {
    7. e.getClickedBlock().setType(Material.AIR);
    8. blocks.add(e.getClickedBlock().getLocation());
    9. }
    10. }
    11. }
    12.  
    13. // In the main class I set the Exceutor to this class
    14. @Override
    15. public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
    16.  
    17. for(Location l : blocks) {
    18. l.getBlock().setTypeId(5);
    19. }
    20.  
    21. blocks.clear();
    22.  
    23. return true;
    24. }


    NOTE: setting the clicked block to air works!
     
  2. Offline

    adam753

    I don't believe onCommand needs @override before it. Does it?
     
  3. Offline

    FlxiFlix

    adam753
    No it doesn't.
    But it doesn't changes anything
     
  4. Offline

    ERROR372

    Uh... well you aren't even providing a command in the onCommand method...

    You need to do something like:

    Code:
    public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args)
    {
        if(cmd.getName().equalsIgnoreCase("reset"))
        {
            for(Location l : blocks)
            {
                l.getBlock().setType(5);
            }
            return true;
        }
        return false;
    }
     
  5. Offline

    rylinaux

    I don't see what is wrong with that, I've copy pasted your code and it works fine. Have you registered the command properly? Has it been added to your plugin.yml?

    Here's my code for reference: http://hastebin.com/xusaqawuno.avrasm
     
Thread Status:
Not open for further replies.

Share This Page