Detecting when PrimedTNT collides with a player entity

Discussion in 'Plugin Development' started by baighxansgaming, Aug 18, 2015.

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

    baighxansgaming

    Anyone know what kind of event i'd use for this, I can't find it anywhere.

    I'm looking for creating an explosion and removing the entity when it hits a player OR setting the fuse time to 0 when it hits the player
     
  2. There is no real event for this. What you could do is set a timer that runs every tick and check the nearby players/entities, if it's of the desired distance you perform stuff, but it's not really resource-friendly.
     
  3. Offline

    Tecno_Wizard

    @megamichiel, not at all. Best thing to do is to put an arrow in them. That will cause an event.
     
  4. Offline

    teej107

    Idk how well this would work but you could try to spawn an arrow instead and send packets faking the arrow as TNT. Then listen to the EntityDamageByEntityEvent and make the right checks.
     
    griffjack likes this.
  5. Offline

    griffjack

    Have no idea how well it would work, but pretty creative idea.
     
  6. Offline

    drew6017

    Code:
        public void tntListener(final TNTPrimed tnt) {
            Bukkit.getScheduler().scheduleSyncDelayedTask(yourPlugin, new Runnable() {
                @Override
                public void run() {
                    if (tnt!=null && !tnt.isDead()) {
                        for (Entity ent : tnt.getNearbyEntities(0.5D, 0.5D, 0.5D)) {
                            if (ent instanceof Player) {
                                Player p = (Player)ent;
                                // Parameter p is the player that the tnt hit.
                                // Parameter tnt is the tnt that hit them.
                                return;
                            }
                        }
                        tntListener(tnt);
                    }
                }
            }, 1);
        }
    Just check for players that are in the hit box of the tnt entity. Run this method when you spawn the tnt.
     
Thread Status:
Not open for further replies.

Share This Page