[Unsolved] Best Way to Stop Firespread/Igniting Blocks

Discussion in 'Plugin Development' started by Infamous Jeezy, Sep 23, 2012.

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

    Infamous Jeezy

    Hello, I've tried various methods for this but all of them seem to have some sort of issue.
    I tried looking at the WorldGuard source but some of it contains some weird methods that only pertain to that plugin itself so I don't completely understand it. I tried a method like this but it only works so well, if it's even working at all.
    This is called on the BlockBurnEvent.
    Code:
        public void ExtinguishFire (Block block) {
            Block tarBlock = block;
            World selWorld = block.getWorld();
            String worldName = selWorld.getName();
            Location blockLoc = tarBlock.getLocation();
            Block upperBlock = plugin.getServer().getWorld(worldName).getBlockAt(blockLoc.add(0, 1, 0));
            Block lowerBlock = plugin.getServer().getWorld(worldName).getBlockAt(blockLoc.subtract(0, 1, 0));
            Block frontBlock = plugin.getServer().getWorld(worldName).getBlockAt(blockLoc.add(1, 0, 0));
            Block behindBlock = plugin.getServer().getWorld(worldName).getBlockAt(blockLoc.subtract(1, 0, 0));
            Block rightBlock = plugin.getServer().getWorld(worldName).getBlockAt(blockLoc.add(0, 0, 1));
            Block leftBlock = plugin.getServer().getWorld(worldName).getBlockAt(blockLoc.subtract(0, 0, 1));
            List<Block> extinguishBlocks = new ArrayList<Block>();
            extinguishBlocks.add(upperBlock);
            extinguishBlocks.add(lowerBlock);
            extinguishBlocks.add(frontBlock);
            extinguishBlocks.add(behindBlock);
            extinguishBlocks.add(rightBlock);
            extinguishBlocks.add(leftBlock);
            for(Block tarFire : extinguishBlocks)
            {
            if (tarFire.getType() == Material.FIRE) {
                tarFire.setType(Material.AIR);
            }
            }
        }
    
     
  2. Offline

    Mitizmitiz

    There is an event for BlockSpreadEvent, which covers fire spreading.
    BlockIgniteEvent for when a player starts the fire.
     
  3. Offline

    Infamous Jeezy

    Mitizmitiz
    So theoretically, if I cancel the BlockSpreadEvent it should put out the fire?
    It seems too easy.. o.o
     
  4. Offline

    Mitizmitiz

    Yes, if you cancel the BlockSpreadEvent the fire wont be able to spread, it wont put out the source fire though. You'll need to deal with that with BlockIgniteEvent.
     
  5. Offline

    Infamous Jeezy

    Makes sense, I'll try it and let you know if it works as planned.
    Thanks.
     
  6. Offline

    Waffletastic

    I'm pretty sure block spread is for like water. I may be wrong. But I've stopped fire spreading in another way before. Use block ignite event, then check the reason, and if spread, cancel. Sorry on an iPad, don't have the code to paste but you get the idea.

    Woah, just read all of your first post! That's waay over complicated. With a ton of things Bukkit: a lot has already been done before. If you feel like you're reinventing the wheel then chances are you don't have to.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  7. Offline

    Infamous Jeezy

    Waffletastic
    I have not gotten a chance to test the BlockSpreadEvent yet.
    Also I've tried the method for the BlockIgniteEvent but if a fire is already spreading it doesn't seem to stop it.
    Only when fires are initially started. I could be wrong but I remember I was having a lot of problems stopping fire spread to protected blocks.
     
  8. Offline

    Waffletastic

    Did you do something along the lines of:

    if (event.getReason.equals(BlockIgniteEvent.reason.SPREAD) {
    event.setcancelled(true);
    }
     
  9. Offline

    Infamous Jeezy

    Well I had it cancel it completely without checking for the cause if the block was protected.

    With school and what not I have not yet gotten a chance to work on this.
    I'm not asking for the code but I'd like some opinions on some of the methods suggested here so I have an idea
    of what I should do when I get the chance to complete this. It should be later tonight.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
Thread Status:
Not open for further replies.

Share This Page