BlockBurnEvent + BlockIgniteEvent ?!

Discussion in 'Plugin Development' started by recon88, May 24, 2012.

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

    recon88

    Do I need to cancel to BlockBurnEvent if I'm canceling the BlockIgniteEvent (as protection)?

    This one works great:
    Code:
          @EventHandler
          public void onBlockIgnite(BlockIgniteEvent event) {
              if (event.getCause() == IgniteCause.FLINT_AND_STEEL) {
            if (Protection.chunk.contains(event.getPlayer().getName()))
            {
              event.setCancelled(true);
            }
            }
          }
    This one is causing an error (on natural events):
    Code:
          @EventHandler
          public void onBlockBurn(BlockBurnEvent event)
           {
              event.setCancelled(true);
            }
            }
          }
    Code:
    2012-05-23 23:08:03 [SEVERE] Could not pass event BlockBurnEvent to Protection
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:303)
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:459)
    at net.minecraft.server.BlockFire.a(BlockFire.java:183)
    at net.minecraft.server.BlockFire.a(BlockFire.java:105)
    at net.minecraft.server.World.a(World.java:2407)
    at net.minecraft.server.World.doTick(World.java:1755)
    at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:545)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:450)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.NullPointerException
    at com.recon88.arg.RegionHandler.ClaimCheck(RegionHandler.java:318)
    at com.recon88.arg.listener.block.PROTBlockListener.onBlockBurn(PROTBlockListener.java:109)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301)
    Edit:
    I want to protect it against Ignites + Natural made Fire (Caused by Lava/Strikes/etc).
     
  2. Well, if you block the ignite event you'll prevent people from *directly* igniting stuff with items, however, by placing lava near wood and stuff, things can still burn.

    The BlockBurnEvent doesn't have a getPlayer() method, however that error triggers in your: com.recon88.arg.RegionHandler.ClaimCheck(RegionHandler.java:318), is that event in that class at line 318 ? Because compiling with missing methods shouldn't give NPEs :confused:
     
  3. Offline

    recon88

    Well it just checks who is owning the chunk. That should not be the problem.

    RegionHandler
    Code:
    public String ClaimCheck(OwnedChunk targetchunk) {
            OwnedChunk test=targetchunk;
     
    318 here:        if (!PROT.OwnerCash.containsKey(getstrchunk(targetchunk))){
         
                String owner_name="";
            ---  SQL QUERY HERE  ---
                }
                PROT.OwnerCash.put(getstrchunk(targetchunk), owner_name);
                return owner_name;
            }else{
                return  PROT.OwnerCash.get(getstrchunk(targetchunk));
            }
        }
    Edit:
    I'm also getting this problem without that check (just canceling the event).
     
  4. Well, I guess it's because of getPlayer() not existing then... however, replace that with a hardcoded value like "whateverplayername" and test if you get the NPE.
     
  5. Offline

    recon88

    How I can get the player in BlockBurnEvent? *confused*

    Also I don't know why this isn't working in 1.2+>.<
    It works great in CB1.1.
     
  6. Offline

    r0306

    recon88
    Well, you should use BlockIgniteEvent to get the player but if you're really desperate, you may add a BlockPlaceEvent and check if the block is lava or fire. Then add that location to a list. In the BlockBurnEvent, check for event.getBlock().getLocation() and compare it in relation with each of the items on the list to check which one is closest.
     
  7. Offline

    recon88

    Wait.
    Wouldn't it be enough to add all ignite causes?

    Like:
    Code:
        if(event.getCause() == IgniteCause.LAVA)
            cause = "LAVA";
        } else if(event.getCause() == IgniteCause.LIGHTNING){
            cause = "LIGHTNING";
        } else if(event.getCause() == IgniteCause.FLINT_AND_STEEL){
            cause = "FLINT_AND_STEEL";
        } else if(event.getCause() == IgniteCause.FIRE){
            cause = "FIRE";
        }
    This should stop the spreading in protected chunks too, right?

    Edit:
    But blocks still can burn down IF they catch fire.
     
  8. Offline

    r0306

    recon88
    Add IgniteCause.SPREAD and it will. :)
     
  9. Offline

    recon88

    Finally (hope this works):

    Code:
     public void onBlockIgnite2(BlockIgniteEvent event){               
     if (event.getCause() == IgniteCause.SPREAD || (event.getCause() == IgniteCause.LAVA || (event.getCause() == IgniteCause.LIGHTNING || (event.getCause() == IgniteCause.FIREBALL))))
                     {
                         event.setCancelled(true);
                     }
                     if (event.getCause() == IgniteCause.FLINT_AND_STEEL){
                         if (!plugin.RegionHandler.CanBuildHere(player, newchunk)){
                             event.setCancelled(true);
     }
    }
     }
    
    Uhm doesn't work -.-°
    It's still spreading and burning down everything :/

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

    r0306

    recon88
    Remove those extra "("'s before the events.
    Code:
     if (event.getCause() == IgniteCause.SPREAD || event.getCause() == IgniteCause.LAVA || event.getCause() == IgniteCause.LIGHTNING || event.getCause() == IgniteCause.FIREBALL)
     
  11. Offline

    recon88

    Nope no difference.

    BTW:
    I don't get any errors on my local testserver if I cancel the BlockBurnEvent. It works like a charm.
    But 2 other people reported it.. See here <- The error report by Sunset
     
  12. Offline

    r0306

    recon88
    Can you post line 318 of RegionHandler ClaimCheck?
     
  13. Offline

    recon88

    See my 2nd post here. Already posted.
     
  14. Offline

    r0306

    recon88
    Okay. So here's the thing. BlockBurnEvent is only triggered by fire. Not anything else. That means that there is absolutely NO player involved in this event. I agree with Digi in that this is the cause of the NPE. Basically, you can either cancel all of the blockburnevents without the player check or you can use blockigniteevent instead (or a combination of both).
     
  15. Offline

    recon88

    I just looked into worldguard's source.
    It does the same.. Just canceling the BlockBurnEvent. There's nothing special in it.

    Also as I said, I can't reproduce the reported error. Don't know how this could happen.

    I just tried this:
    Code:
            @EventHandler
            public void onBlockBurn(BlockBurnEvent event){
                        event.setCancelled(true);
                    }
    Set a tree on fire (spreading activated):
    http://i.imgur.com/3UKm0.jpg

    Result:
    No errors

    I really don't know why those 2 people are getting erros but it can't be a code problem...

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

    r0306

    recon88
    Are those two using this code or are they still using the code with the event.getPlayer()
     
  17. Offline

    recon88

    They are using the BlockBurnEvent with the claimcheck.
    But I also tried to reproduce the error with the claimcheck: No errors.
    It just blocks the burn event and works as it should.

    Edit:
    There's still no getPlayer() in BlockBurnEvent
     
Thread Status:
Not open for further replies.

Share This Page