How to remove the block a player steps on after 3 seconds

Discussion in 'Plugin Development' started by SantaClawz69, Aug 3, 2015.

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

    SantaClawz69

    Hi, so I'm trying to make a plugin so if a player steps in clay after 3 seconds the clay will disappear. After it disappears in 5 minutes the block will regenerate. How can I do something like this? Also if possible can you please leave some pseudo code on how to do such a task?
     
  2. Offline

    ChipDev

    on walk {
    make task 3secs later {
    remove block;
    make task 180 secs later {
    add block;
    }
    }
    }
     
  3. Offline

    SantaClawz69

    Sorry, I know that you have to do that but I'm wondering HOW I can do those things? Like example code would be cool pls :D
     
    ChipDev likes this.
  4. Offline

    Gater12

  5. Offline

    ChipDev

    Oh! Ok, Some schedulers would be helpful on the page above :)
     
  6. Offline

    SantaClawz69

    I know how to use schedulers lel, anyways. Here is my code, not sure why it's not working.

    Code:
        public List<BlockState> blocklist = new ArrayList<BlockState>();
    
    Code:
    public void onPlayerMove(PlayerMoveEvent event)
        {
            final Block block = event.getTo().getBlock().getLocation().add(new Vector(0,-1,0)).getBlock();
            Player player = event.getPlayer();
            if(Main.inRunnerGame.contains(player))
            {
                if(block.getType().equals(Material.CLAY))
                {
                   pl.getServer().getScheduler().scheduleSyncDelayedTask(pl, new Runnable() {
    
                    @Override
                    public void run() {
                        blocklist.add(block.getState());
                        block.setType(Material.AIR);
                    }
                 
                     
                     
                   },60L);
                }
            }
          
        }
     
    ChipDev likes this.
  7. Offline

    AcePilot10

    I'm not positive but I believe when you say event.getTo().getBlock() is the block they moved to, when I'm guessing you want to get the block they were at. In this case use player.getLocation().getBlock()
     
  8. Offline

    SantaClawz69

    Okay I'll test this out. Thanks.

    @AcePilot10 Sadly it still doesn't work. Even thought I changed it to player.getLocation

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

    xXCapzXx

    Try deleting if(block.getType().equals(Material.CLAY)). I might be wrong, I just woke up.
    It could have something to do with that. Just test.
     
  10. Offline

    AcePilot10

    I'm gonna test this out.
    Wait a sec.
    Did you forget the @EventHandler annotation.
     
  11. Offline

    ChipDev

    Use debugger code, Send messages before if's, and as always, register your events and use @EventHandler
     
  12. Offline

    SantaClawz69

    @ChipDev Alright I think I know that I'm supposed to use @EventHandler lel.
    No I didn't it's there.
    Will do.

    @ChipDev @AcePilot10 @xXCapzXx
    So I did what he said and I figured out that the whole method isn't working. Is there a reason why?

    My constructor.
    Code:
    public PlayerMove(Main main)
        {
            pl = main;
        }
        
    My registerEvents method.
    Code:
    public void registerEvents()
        {
            Bukkit.getServer().getPluginManager().registerEvents(new PlayerQuit(this), this);
            Bukkit.getServer().getPluginManager().registerEvents(new PlayerDeath(this), this);
            Bukkit.getServer().getPluginManager().registerEvents(new PlayerJoin(this), this);
            Bukkit.getServer().getPluginManager().registerEvents(new PlayerBreak(this), this);
            Bukkit.getServer().getPluginManager().registerEvents(new PlayerKill(this), this);
    Please tell me if I've done something wrong. Thanks!

    Also along with my PlayerBreak method isn't working, here's the code:

    Code:
        LinkedHashMap<Location, Block> changedBlocks = new LinkedHashMap<Location, Block>();
        Main pl;
        public PlayerBreak(Main main)
        {
            this.pl = main;
            pl.getServer().getPluginManager().registerEvents(this, pl);
        }
        @EventHandler
        public void onPlayerBreak(BlockBreakEvent e)
        {
            Player player = e.getPlayer();
            List<BlockState> blocklist = new ArrayList<BlockState>();
            Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(pl, new Runnable(){
                Block block = e.getBlock();
                Material material = block.getType();
                @Override
                public void run()
                {
                    if(Main.inSpleefGame.contains(player))
                    {
                        if(player.getItemInHand().getType() == Material.DIAMOND_SPADE)
                        {
                            if(material.equals(Material.SNOW))
                            {
                                blocklist.add(e.getBlock().getState());
                               
                                for(BlockState block : blocklist)
                                {
                                    block.update();
                                }
                                blocklist.clear();
                            }
                        }
                        }
                }
               
            }, 20L); //TESTING PURPOSES, CHANGE BACK TO 5 MINUTES AFTER
        }
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 11, 2016
    ChipDev likes this.
  13. Offline

    ChipDev

    I guess it's the class. Try putting in the main class.
     
  14. Offline

    AcePilot10

    Ok, the reason it isn't working is you have to pass through the main class (the class the extends JavaPlugin). You are passing in the listener class as the main class. So what you want to do is since you already get an instance of the main class just do Bukkit.getServer().getPluginManager().registerEvents(this, MainClassInstance);. OR you could just register in you onEnable method (Bukkit.getServer().getPluginManager().registerEvents(new ListenerClass); And make sure you register when the server enables (onEnable())
     
  15. Offline

    SantaClawz69

    I have registered the events
    @AcePilot10

    And I will try to do so @ChipDev

    @ChipDev I did what you said and I put my listener classes inside my main class, I registered the events and they didn't work. I feel as if just the code doesn't work. But I don't know what parts of the code doesn't work?

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

    ChipDev

    Does any of your code work?
    Does the plugin enable?
    Add me on Skype, or Bring to a PM So we can talk faster.
     
  17. Offline

    SantaClawz69

  18. Offline

    ChipDev

    Join our PM ;P
     
Thread Status:
Not open for further replies.

Share This Page