Only allow block ignite on obsidian? (Solved)

Discussion in 'Plugin Development' started by h4344, Nov 30, 2011.

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

    h4344

    Trying to allow obsidian blocks to ignite so people can make prtals while still canceling all others. Any ideas? This code dosent seem to work. Ty for any help :)

    public class MyBlockListener extends BlockListener {
    @Override
    public void onBlockIgnite(BlockIgniteEvent event) {
    Block block = event.getBlock();
    if(block.getType() != Material.OBSIDIAN){
    event.setCancelled(true);
    }
    }
    }

    Anyone have any idea's?

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

    ArcheCane

    Cancel the right clicking with a lighter perhaps? and do what you're doing now, stating weather or not you ignited obsidian.
     
  3. Offline

    h4344

    Not sure what you mean. I tried thinking of a way to combine the block listener with my player listener but that wont work. I just dont see a reason why the way it is now wont work.
     
  4. Offline

    Taco

    I think what @ArcheCane meant was that you could use the PlayerInteractEvent to check to see if the player has right clicked a block, and if they have and the item they're holding is flint and steel, cancel the event.
     
  5. Offline

    ArcheCane

    Exactly what I meant.
     
  6. Offline

    user_43347

    You need to remove one on the y axis because ignition is just changing the air to fire which is why it returns as not obsidian.

    So like...
    Block fire = block.getLocation().subtract(0, 1, 0);
    if (fire.getType() != Material.OBSIDIAN) {
    Cancel the event here
     
  7. Offline

    h4344

    I Already have a player listener that does that. I just need to modify the block listener because people cant make nether portals since they cany ignite the obsidian.

    Im trying to use the code you recommended but it says "Cannot convert from location to block"

    public class MyBlockListener extends BlockListener {
    @Override
    public void onBlockIgnite(BlockIgniteEvent event) {
    Block block = event.getBlock();
    Block fire = block.getLocation().subtract(0, 1, 0);
    if (fire.getType() != Material.OBSIDIAN) {
    event.setCancelled(true);
    }
    }
    }

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

    user_43347

    Whoops, change the following to the following.
    Code:
    Block fire = block.getLocation().subtract(0, 1, 0);
    Code:
    Block fire = block.getLocation().subtract(0, 1, 0).getBlock();
    So it would be like this...
    Code:
    public void onBlockIgnite(BlockIgniteEvent event) {
       Block block = event.getBlock();
       Block ignited = block.getLocation().subtract(0, 1, 0).getBlock();
       if (ignited.getType() != Material.OBSIDIAN) {
          event.setCancelled(true);
       }
    }
     
    h4344 likes this.
  9. Offline

    h4344

    Dude i love you!!!
     
  10. Offline

    Trc202

    Just curious, if you are at say a depth of zero and light a fire, does it return a null value and break the plugin?
     
  11. Offline

    h4344

    What do you mean by depth zero? Like bedrock? Ill try that out. I wouldn't think so though since it still wont be obsidian.

    Ok i went to the very bottem and tried lighting the bedrock. Went under it too and tried lighting, the plugin was still working fine. Just suppressed it like normal.

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

    Trc202

    My thought was a nearly impossible situation where someone lights a block on fire at minecraft y value of 0 which would cause the
    Code:
    block.getLocation().subtract(0, 1, 0).getBlock();
    to possibly return a null value (as it's coordinate y value would be -1, below the possible value of any block).

    It's so unlikely that you'll (probably) never have the need to account for it in code though.
     
Thread Status:
Not open for further replies.

Share This Page