Solved Disable firework damage

Discussion in 'Spigot Plugin Development' started by cheesyfreezy, Feb 10, 2020.

  1. Hello there Spigot users,

    Currently I am making a plugin with loot drops falling from the sky. Before the actual loot spawns on the ground I want a particle effect of a trail of firework to work its way down to the loot. This all works, but I am running into a problem. The firework that I spawn deals damage which I want to disable. I know I can disable it by cancelling the EntityDamageByEntity event, but this will disable all incoming damage coming from firework. All I want is to disable the damage coming from the firework trail that I spawn when dropping a loot drop.

    Thank you in advance!
     
  2. Provide some code. What code are you using to spawn your firework?
     
  3. You could give your firework when spawning it metadata and check if the damager on EntityDamageByEntityEvent is like you said a Firework and then check if the firework has metadata of the one you gave it. I doubt it would matter if it was lost over restarts also since this seems like the type of the that you want in the moment that it happens.
     
  4. Here is the code I use to spawn firework:
    Code (Java):
    Firework fw = location.getWorld().spawn(locationCentered, Firework.class);


    How can I give custom meta data to firework?
     
  5. Since a firework is an entity you could give it a custom name and listen for the entity damage event. Look if it's a firework and if the custom name fits your custom name and then cancel it.
     
    • Useful Useful x 1
  6. I have tried it with the NBT API, but to give entities custom data it requires another library that does not fully work on 1.14.4 and is kind of buggy. So I will give the idea of Maxx_Qc's a go.
    Thank you
     
  7. Check if entity is firework, damage cause ENTITY_EXPLOSION, that'd disable all so you should look into the PersistentDataHolder perhaps, not sure if that exists for entities otherwise look for metadata.
     
  8. well if the idea you were given above didn't work it should just be
    Code (Text):
    fw.setMetadata("nodamage", new FixedMetadataValue(owningPluginInstance, true);
    then on EntityDamagebyEntityEvent:
    Code (Text):
    if (e.getDamager() instanceof Firework) {
        Firework fw = (Firework) e.getDamager();
        if (fw.hasMetadata("nodamage")) {
            e.setCancelled(true);
        }
    }
     
    • Useful Useful x 4
    • Agree Agree x 1
  9. I used the method setting a custom name and that worked, but obviously that isn't the way to go. So I tried this method and this works too. Thank you :)
     
    • Like Like x 2
    • Useful Useful x 1