Solved Issues with createExplosion and the Entity Source

Discussion in 'Spigot Plugin Development' started by CoolLord22, Aug 1, 2020 at 10:16 PM.

  1. I had a quick question if anyone would be able to provide some insight on this issue I'm having.

    I'm looking to create grenades that keep track of who dealt the damage, as is done via
    Code (Text):
    .createExplosion(dropLoc, 2.5F, false, false, thrower);
    However the issue I've run into is that when the thrower is specified, that player doesn't take damage unfortunately. I've tried removing the thrower and as expected it deals damage to any entity within the radius, however the problem is that it no longer keeps track of who dealt the damage (so other plugins like combat loggers and such are made aware of the events).

    I've also tried other ways of getting the same effect by spawning in primedTNT, listening the explode events and setting the damage via the LivingEntity.damage() method but it isn't working as clean as the createExplosion was. Is anyone aware of a way to keep track of the source entity dealing the damage, while also dealing damage to them if they're within the blast radius? I appreciate any insight! Thanks :)
     
  2. Use a hashmap with the player as the key, then get an explosion
     
  3. It sounds like there may be a plugin interfering, have you tried without plugins and made sure pvp=true in server.properties?
     
  4. I think this is an implementation of the method used to create the explosion; I just did go ahead and try it on a fresh server with just a command that runs the createExplosion code, and got the same results.
    Code (Text):
    boolean    createExplosion(Location loc, float power, boolean setFire, boolean breakBlocks, Entity source)  
    Creates explosion at given coordinates with given power and optionally setting blocks on fire or breaking blocks.
    When you specify the Entity source, the source entity doesn't take the damage from the looks of it, but every entity in the radius does.
     
  5. Sorry if I'm missing something obvious, but how exactly would you recommend going about getting an explosion? I initially thought if the createExplosion returned a certain type of instance of the explosion it would be possible, but it only seems to return a true/false value :(.
     
  6. Hashmap with Player and Entity (PRIMED_TNT) to keep track on who placed/ignited it
     
  7. This is the original approach I tried but I struggled with the damage being tracked. Would you suggest retrying what I tried earlier and cancel the EntityDamageByEntityEvent, and then damage the player with something like
    Code (Text):
    ((LivingEntity) e.getEntity()).damage(e.getFinalDamage(), tntExplosion.get(e.getDamager().getUniqueId()));
    EDIT: where e.getDamager() returns the primedTNT that exploded?
     
  8. Yeah, so I'm not sure if I'm doing something wrong or what's happening here. I've instead now created a hashmap
    Code (Text):
    HashMap<UUID, UUID> tntExplosion
    whose first parameter stores the UUID of the entity that's exploding, and the value maps to the Player's UUID. I'm creating the TNT with
    Code (Text):

                            TNTPrimed tntPrimed = (TNTPrimed) particleLoc.getWorld().spawnEntity(particleLoc, EntityType.PRIMED_TNT);
                            tntExplosion.put(tntPrimed.getUniqueId(), thrower.getUniqueId());
                            tntPrimed.setFuseTicks(0);
    and then in my EntityDamageByEntityEvent I'm doing
    Code (Text):
    if(tntExplosion.containsKey(e.getDamager().getUniqueId())) {
                e.setCancelled(true);
                ((LivingEntity) e.getEntity()).damage(e.getFinalDamage(), Bukkit.getPlayer(tntExplosion.get(e.getDamager().getUniqueId())));
            }
    It deals the damage properly, but doesn't actually seem to track that the player was the one damaging the entity :unsure:
     
  9. Lol, found what I was doing wrong. I have a tracker that prevents players from dying by basically resetting their inventory, cancelling the damage dealt to them etc. and that was preventing CombatLog from tagging the two players as being in combat, so I just manually tagged the players as fighting to fix the issue :) thank you guys for your help!