Stop players from punching out fire

Discussion in 'Plugin Development' started by Chipmunk9998, Mar 11, 2012.

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

    Chipmunk9998

    Hey, I need to add a simple feature to my plugin that stops players from punching out fire. I couldn't figure out how to do this, so could someone help? Thanks!
     
  2. Offline

    Pandemoneus

    You need to listen for BlockBreakEvents, check whether the broken block is of type FIRE and then cancel it.
     
  3. Offline

    Chipmunk9998

    I tried cancelling all block break events, but it didn't work.
     
  4. Offline

    Digi

    Did you try: BlockDamageEvent, BlockFadeEvent or PlayerInteractEvent ?
     
  5. Offline

    Chipmunk9998

    I tried PlayerInteractEvent, not sure about the other 2.
     
  6. Offline

    TechGuard

    Really easy to do, use PlayerInteractEvent

    Get the block above the player clicked on.
    Is it fire? cancel the event.

    Done!
     
    RobotA69 likes this.
  7. Offline

    Digi

    TechGuard
    And what if the player hit the side of a block and that side was the fire ? :p
    I belive there's a event.getClickedFace() method, use that as input for event.getClickedBlock().getRelative() to get the block on the side you hit... but I dunno if you can extinguish fires that way tough.
     
    Eccentric_Gamer likes this.
  8. Offline

    TechGuard

    I didn't think of that, but I don't think you can put it out like that.
     
  9. Offline

    Digi

    Hmm, well, fires can be on sides of the blocks but I don't know if you can put out a floor fire by hitting the side of a nearby block.

    Still, the clicked face's block is the best way.
     
  10. Offline

    MuisYa

    This SHOULD work i think...

    Code:
    @EventHandler
    public void onBlockBreak(BlockBreakEvent event) {
        Block block = event.getBlock();
        Player player = event.getPlayer();
        if (block.getType() == Material.FIRE) {
            event.setCancelled(true);
            System.out.println(player.getName() + " tried to break fire.");
        }
        else {
            Location loc = block.getLocation();
            Block two = loc.getChunk().getBlockAt(block.getX(), block.getZ(), block.getY());
            if (two.getType() == Material.FIRE) {
                event.setCancelled(true);
                System.out.prinltn(player.getName() + " tried to break a block under fire.");
            }
        }
    }
        
     
  11. Offline

    Digi

    MuisYa ehm... get block, if not fire, get block at location of block and check if fire... same thing ?

    Oh, you also screwed up X,Y,Z arguments in the blockAt()
     
  12. Offline

    MuisYa

    Digi Oh im sorry. I was on school and had no Eclipse.
    But it should be the y + 1, so it sees if the block above it is Fire...
     
  13. Offline

    Father Of Time

    I had to do this a week ago for a "shrine" plug-in of mine; use PlayerInteractEvent.

    inside the player interact event use the getAction() function, if the action is LeftClickAir (anything that doesn't block movement returns air; water, air, fire, etc.) check to see if the air block that you clicked (getClickedBlock() ) is Material.FIRE, if so cancel the player interact event.

    This is super easy and I know it works with the current RB and the 1.2 dev build.

    Good luck with your project!
     
  14. Offline

    Digi

    Not exacly true, it doesn't return blocks that aren't selectable because you're not clicking on it...like air, water, lava and fire, those are not selectable but grass for example is selectable and it doesn't block movement.
     
  15. Offline

    Father Of Time

    Well if we want to split hairs you are correct, but for simplicity sake of explaining my point it sufficed.

    Long story short fire will return "ClickedAirBlock" when punched, which you can then check the "getBlockClicked()" to make sure the air block you clicked (or as stated above failed to click) is Material.FIRE.
     
Thread Status:
Not open for further replies.

Share This Page