Get TnT Location

Discussion in 'Plugin Development' started by BrennyMullan, Sep 7, 2014.

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

    BrennyMullan

    I want to stop tnt from launching above sky limit for example, if a player has a cannon at 250 y and it launches tnt above sky limit i want to turn the tnt to air.

    I have tried the ExplosionPrimeEvent but that gets called just as its exploding, is there a way to track the tnt as its flying and check its location?
     
  2. Offline

    Cerberus XII

    BrennyMullan,
    Maybe something like this will work:
    Code:java
    1. @EventHandler
    2. public void onBlockIgnite(BlockIgniteEvent event) {
    3. TNTPrimed tnt = (TNTPrimed) event.getBlock();
    4. if(tnt.getLocation().getBlockY() >= 250) {
    5. tnt.remove();
    6. }
    7. }
     
  3. Offline

    TheMintyMate

    BrennyMullan

    Alongside Cerberus XII 's suggestion, you may also want to detect a BlockPlaceEvent:
    Code:
    @EventHandler
    public void onBlockPlace(BlockPlaceEvent event){
    Block block = event.getBlock;
    if (block /*is tnt*/){
    /* you may want to include other tests before cancelling event - such as if the player is OP or has perms*/
    event.setCancelled(true);
    }
    }
    
    Hope this helped,
    - Minty
     
Thread Status:
Not open for further replies.

Share This Page