TNT creates no PlayerDamage

Discussion in 'Spigot Plugin Development' started by MaskenLP, Jun 1, 2017.

  1. Hey there,
    I tried to ignite TNT when a Block of TNT is placed..
    I use this Code to Ignite it

    Code (Text):
    @EventHandler
        public void onBuild(BlockPlaceEvent e) {
            if (!main.getPlayer(e.getPlayer()).isBuild()) {
                if (e.getBlock().getType().equals(Material.TNT)) {
                    e.getBlock().setType(Material.AIR);
                    e.getPlayer().getWorld().spawn(e.getBlock().getLocation(), TNTPrimed.class);
                }else{
                    e.setCancelled(true);
                }
               
            }
        }
    but it does not create PlayerDamage!

    How can I make it work?
     
  2. I think the following would work:

    Code (Text):
    @EventHandler
        public void onBuild(BlockPlaceEvent e) {
            if (!main.getPlayer(e.getPlayer()).isBuild()) {
                if (e.getBlock().getType().equals(Material.TNT)) {
                    e.getBlock().setType(Material.AIR);
                   TNTPrimed tnt = e.getPlayer().getWorld().spawn(e.getBlock().getLocation(), TNTPrimed.class);
                   tnt.setYield(range);
                }else{
                    e.setCancelled(true);
                }
             
            }
        }
    SOURCE: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/Explosive.html
     
  3. Nope it does not work ...
     
  4. I recommend you to cancel EntityExplodeEvent, if the entity-type is PRIMED_TNT, then create a new explosion. The advantage: You can modify the "strength/damage" of the blow.

    Furthermore.. Before you're spawning PRIMED_TNT, I recommend you to add +0.5 y-coord to optimize it. Otherwise the damage output couldn't be normal.
     
  5. Unfortunate, this does not work too ...
     
  6. Show me your code