How to remove block after certain time rapidly

Discussion in 'Plugin Development' started by Ruptur, Feb 14, 2015.

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

    Ruptur

    The title explains everything

    What i have so far

    Code:
        public void onPlayerMove(PlayerMoveEvent e){
            Player p = e.getPlayer();
            if (!(flashed.contains(p.getName()))){
                return;
            }
           
            if(p.isSprinting() || (!(p.isOnGround()) || still(p))){
                return;
            }
            if(!(p.getItemInHand().hasItemMeta() || p.getItemInHand().getType() == Material.REDSTONE_TORCH_ON )) {
                return;
            }
            Location l = p.getLocation();
            Block bl = l.getBlock();
            try{
                bl.setType(Material.TORCH);
            }catch(Exception ex){
                p.sendMessage(ChatColor.RED + "Couldnt palce down torch - Watch your pace!");
               
            }
            Location old = l.add(0, 0, -2);
            Block o = old.getBlock();
            try{
                o.setType(Material.AIR);
            }catch(Exception ex){
                p.sendMessage(ChatColor.RED + "Couldnt not remove - Watch your pace!");
               
            }
    
     
  2. Offline

    JPG2000

    What are you asking for? Are you asking for a way to remove all blocks placed down after a certain time? If so, catch the BlockBreakEvent and schedule a repeating task to invoke event.setCancelled(true). Use this resource for help with the scheduler.
     
  3. Offline

    Ruptur

    @JPG2000

    If the player is quicker than the scheduler some blocks wont get removed.

    Update:
    This is what i have now which works perfectly except ..
    Code:
    
        @SuppressWarnings("deprecation")
        @EventHandler
       
       
        public void onPlayerMove(final PlayerMoveEvent e){
            Player p = e.getPlayer();
            if(!(p.getItemInHand().hasItemMeta() || p.getItemInHand().getType() == Material.REDSTONE_TORCH_ON )) {
                return;
            }
            if(e.getFrom().getX() == e.getTo().getX()
                    && e.getFrom().getY() == e.getTo().getY()
                    && e.getFrom().getZ() == e.getTo().getZ()){
                return;
            }
           
            if(blocks.containsValue(p)){
                for (Entry<Block, Player> entry : blocks.entrySet())
                {
                  Block block = entry.getKey();
                  Player player = entry.getValue();
                  if (player == p)
                  {
                      block.setType(Material.AIR);
                  }
                }
            }
            if (!(pl.flashed.contains(p.getName())))
            {
                return;
            }
           
            if(p.isSprinting() || (!(p.isOnGround()) || still(p)))
            {
                return;
            }
            Location l = p.getLocation();
            Block bl = l.getBlock();
            try{
                bl.setType(Material.TORCH);
                blocks.put(bl, p);
            }catch(Exception ex){
                p.sendMessage(ChatColor.RED + "Couldnt palce down torch - Watch your pace!");
               
            }
    
        }
    
    if the player is standing on the edge of a block, it block attempts to place down a torch.
    The torch then 'pops' to player inven. How do i stop this and make sure this doesn't happen
     
Thread Status:
Not open for further replies.

Share This Page