Solved Disable fire spread and vine growth?

Discussion in 'Plugin Development' started by xxHell_Killerxx, Aug 12, 2015.

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

    xxHell_Killerxx

    Hello,

    I'm having problems when I try to stop the spreading of fire (by lava and fire etec) and vine growth, I've tried the following code:

    Fire Spread:
    Code:
        @EventHandler(priority = EventPriority.HIGHEST)
        public void onBlockSpread(BlockSpreadEvent event)
        {
            Bukkit.getLogger().info(event.getBlock().getWorld().getName() + " EL1162 Triggered " + event.getNewState().getType());
            if (event.getNewState().getType().equals(Material.FIRE))
            {
                Bukkit.getLogger().info("Cancelled!");
                event.setCancelled(true);
            }
        }
    "Cancelled!" is displayed in the console.
    Code:
        @EventHandler
        public void onBlockIgnite(BlockIgniteEvent event)
        {
            Bukkit.getLogger().info(event.getBlock().getWorld().getName() + " EL1172 Triggered " + event.getCause());
            event.setCancelled(true);
        }
    The text is displayed in the console.

    Vine growth:
    Code:
        @EventHandler
        public void onBlockGrow(BlockGrowEvent event)
        {
            if (event.getBlock().getType().equals(Material.VINE))
            {
                event.setCancelled(true);
            }
        }
    All those methods fail somehow, hope it's possible to fix, thx~
     
  2. Offline

    AcePilot10

    Try setting the fire tick to 0. And for the vine growth... try using this.
    Code:
    if(event.getNewState.getType() == Material.VINE) {
    event.setCancelled(true);
     
  3. Offline

    javipepe

    Basically the string.equals() function checks the actual contents of the string, only for strings, the == operator checks whether the references to the objects are equal. Note that string constants are usually "interned" such that two constants with the same value can actually be compared with ==, but it's better not to rely on that.

    So what you do want here is check whether the references to the objects are equal or not, for which you would use "==" instead of "StateType.equals(state)".

    So the fire spread and the vine growth should not work as they are, but the fire ignition should. Does the fire ignition actually work for you?
     
  4. Offline

    xxHell_Killerxx

    Thx for the information, but the result's the same when I use "==".
    And the fire ignition does not work, tho the text's displayed :/
     
  5. Offline

    javipepe

    Oke, I think I got the solution for you. The following code merges the spreading and the ignition into one.

    Code:
    @EventHandler
    public void onBlockIgnite(BlockIgniteEvent event) {
        if (event.getCause() == IgniteCause.FLINT_AND_STEEL || event.getCause() == IgniteCause.SPREAD) {
            //the console message
            event.setCancelled(true);
        }
    }
     
  6. Offline

    xxHell_Killerxx

    Hmm I just tried, the fire still spread :/
    Strange, the event's cancelled, but it still spread.

    ---

    Cancelling the event will result this:
    [​IMG]


    {{Posts merged by Myrathi}}
     
    Last edited by a moderator: Aug 12, 2015
  7. Offline

    CoolDude53

    If you aren't dead set on coding it in yourself, just use worldguard and add the necessary flags to the global region. (I tried doing this and decided to just go with worldguard since I was using it for regions anyways).
     
  8. Offline

    xxHell_Killerxx

    Ye I was using worldguard for this, but i think it would be easier to manage if I code it myself.
    Worldguard uses BlockIgniteEvent too, I wonder what I am missing... :/
     
  9. Offline

    Tecno_Wizard

    There are a lot of Java noobs on this site so I want to continue this briefly.
    The equals method is actually inherited from Object, meaning that ALL Objects have an equals method. As javipepe said, it checks the contents of an Object- not it's memory location. When you use == you are telling the VM Object one is Object two. When you are using constants such as numbers or enums, == works perfectly. However if you want to check if 2 itemstacks are the same, you might notice that it isn't perfect. .equals makes a check to an Objects contents while == checks memory location.[/QUOTE]
     
  10. Offline

    xxHell_Killerxx

    [/QUOTE]
    Thx~ So i think i should use the equal method here.
    But still, I can't find the reason why the fire still spread when I cancel the event. :/
     
  11. Offline

    xxHell_Killerxx

    Helpless bump,
    I found a solution of vine spread, but i need help about the fire spread. :/
     
  12. Offline

    xxHell_Killerxx

    Nvm fixed it myself using another event xD
     
Thread Status:
Not open for further replies.

Share This Page