Right click tnt with item

Discussion in 'Plugin Development' started by PizzaPixel, Nov 3, 2013.

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

    PizzaPixel

    I am making a plugin but I need help on something:
    That I want that you can right click tnt with blaze powder and then the tnt turns to primed tnt
     
  2. Offline

    FinalFred

    I believe you can use the player interaction event to test for when the player right clicks on TNT.

    Then check to see if the player is holding blaze powder.

    If so, prime the TNT. There might be a method to do so, I'm afraid I'm not familiar enough with recent Bukkit changes to know. If there isn't, perhaps you could destroy the TNT block (turn it to air) and spawn a primed TNT entity?
     
    Fozie likes this.
  3. Offline

    PizzaPixel

    @EventHandler
    public void Command(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    if(event.getAction().equals(Action.RIGHT_CLICK_BLOCK) && player.getItemInHand().getType().equals(Material.BLAZE_POWDER) && event.getClickedBlock().getType().equals(Material.TNT)){
    event.setCancelled(true);
    event.getClickedBlock().setType(Material.AIR);
    TNTPrimed tnt = (TNTPrimed) event.getClickedBlock().getWorld().spawn(event.getClickedBlock().getLocation().add(0, 1, 0), TNTPrimed.class);
    tnt.setFuseTicks(30);
    }
    }
     
  4. Offline

    HeroWorkbrine

    that should work
     
  5. Offline

    PizzaPixel

    And also how would I add a broadcast of 30 seconds when the tnt turns into prime tnt
     
  6. Offline

    HeroWorkbrine

    getServer().broadcastMessage("Tnt has just been primed!");
     
  7. Offline

    PizzaPixel

    Where in the code
     
  8. Offline

    HeroWorkbrine

    where you want it to be of course!
    you said:
    "when the tnt turns into prime tnt"
    just after the primed tnt is created put that code
     
  9. Offline

    PizzaPixel

    Ok thanx

    So like this

    @EventHandler
    public void Command(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    if(event.getAction().equals(Action.RIGHT_CLICK_BLOCK) && player.getItemInHand().getType().equals(Material.BLAZE_POWDER) && event.getClickedBlock().getType().equals(Material.TNT)){
    event.setCancelled(true);
    event.getClickedBlock().setType(Material.AIR);
    TNTPrimed tnt = (TNTPrimed) event.getClickedBlock().getWorld().spawn(event.getClickedBlock().getLocation().add(0, 1, 0), TNTPrimed.class);
    tnt.setFuseTicks(30);
    getServer().broadcastMessage("Tnt has just been primed!");
    }
    }

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

    Fozie

  11. Offline

    PizzaPixel

  12. Offline

    njb_said

    You may want to put a null check in there to check that the block isnt null and the item in hand isnt null etc..
     
  13. Offline

    PizzaPixel

    How would I do that. Can you show me the code.
     
Thread Status:
Not open for further replies.

Share This Page