Block change for 5 seconds then go back to normal.

Discussion in 'Spigot Plugin Development' started by Orangemaster123, May 28, 2017.

Thread Status:
Not open for further replies.
  1. I am making a paintball gun which fires snowballs and when it hits the ground the block it hits changes to a coloured wool block. But i want this change to be temporary. Is there a way that after 5 seconds the wool goes back to normal? Heres my code.
    Code (Text):

    Material block = loc.getBlock().getType();

            loc.getBlock().setType(Material.WOOL);

            loc.getBlock().setData((byte) woolcolour);

           

            loc.getBlock().setType(block);
     
    loc is the location of the block the snowball hits.

    Also, is there a way i could select the blocks around the block the snowball hits, so multiple blocks turn to wool, so it looks more like a real paintball.
     
  2. Use a bukkit runnable.
     
  3. Code (Text):
    public static List<Block> getNearbyBlocks(Location location, int radius) {
            List<Block> blocks = new ArrayList<Block>();
            for (int x = location.getBlockX() - radius; x <= location.getBlockX() + radius; x++) {
                for (int y = location.getBlockY() - radius; y <= location.getBlockY() + radius; y++) {
                    for (int z = location.getBlockZ() - radius; z <= location.getBlockZ() + radius; z++) {
                        blocks.add(location.getWorld().getBlockAt(x, y, z));
                    }
                }
            }
            return blocks;
        }


     
    You can get nearby blocks with the following code
     
  4. How exactly would i use this?
     
  5. When you use a bukkit runnable doesnt it constantly repeat itself?
     
  6. BukkitRunnable#runTaskTimer
     
  7. No, there is a timer, a delay, and a repeat.
     
Thread Status:
Not open for further replies.