Solved EntityDamageEvent (the non-depreciated one)

Discussion in 'Spigot Plugin Development' started by SkylixMC, Feb 27, 2020.

  1. I am trying to call an EntityDamageEvent (to call damage done for custom fall damage). However, I am getting errors when I try to use this code:

    (If you try to cast, it tells you they are an inconvertible type all along.

    Code (Text):

    // This is obviously defined in my class by the way
    private static final Function<? super Double, Double> ZERO = Functions.constant(-0.0);

    public void onLandGround (PlayerMoveEvent e) {
        Player target = e.getPlayer();

    int distanceFallen = (int) player.getFallDistance();

    final double damage = distanceFallen-2;
    final Entity damagee = target;
    final EntityDamageEvent.DamageCause cause = EntityDamageEvent.DamageCause.FALL;
    final Map<EntityDamageEvent.DamageModifier, Double> modifiers = new EnumMap<>(ImmutableMap.of(EntityDamageEvent.DamageModifier.BASE, damage));
    final Map<EntityDamageEvent.DamageModifier, ? extends Function<? super Double, Double>> modifierFunctions = new EnumMap<>(ImmutableMap.of(EntityDamageEvent.DamageModifier.BASE, ZERO));
    EntityDamageEvent event = new EntityDamageEvent(damagee, cause, modifiers, modfierFunctions);
    Note: Only code relevant to my question is included.

    What am I doing wrong? How do you call this event?
    #1 SkylixMC, Feb 27, 2020
    Last edited: Feb 27, 2020
  2. Since it doesn't look like you're even using the modifiers for anything, is there any reason you aren't using this constructor instead? The DamageModifiers are deprecated in newer versions due to implementation problems, so it's probably best not to use it anyway.
  3. Which one are you talking about?

    I already tried the first constructor. First of all, the first one is depreciated, and also it actually did not work either :/.

    And the one above in my code is actually the second constructor.

    But yes, you are right. I do not need the damage modfiers.
  4. Probably, it is down to your mis-use of 'final'
    Once that a 'final' attribute is established, the content is not able to be updated.
  5. Anyone? Common' ya smart nerds! XD
  6. Choco


    The only reason that would be giving you a compiler error is if you're importing the wrong Function. Spigot makes use of Guava's Function interface as opposed to Java's. Be sure sure to have imported, not java.util.function.Function.

    However, @Esophose is correct here. You're using nothing more than base damage. Use EntityDamageEvent(Entity, DamageCause, double)
    • Useful Useful x 1
  7. Wow. You are right. Rookie mistake. Thanks, alot @Choco.
    • Like Like x 1