EntityDamageEvent StackOverflowError: null

Discussion in 'Plugin Development' started by runaowi, Aug 12, 2020.

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

    runaowi

    So i'm trying to make every player receive the same damage, and i'm receiving this error.

    Code:
    Could not pass event EntityDamageEvent to DreamDamageAll v0.0.1
    java.lang.StackOverflowError: null
        at java.util.Collections$UnmodifiableCollection$1.<init>(Collections.java:1041) ~[?:1.8.0_265]
        at java.util.Collections$UnmodifiableCollection.iterator(Collections.java:1040) ~[?:1.8.0_265]
        at detox.DamageListener.damagePlayerPart2(DamageListener.java:21) ~[?:?]
        at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor1.execute(Unknown Source) ~[?:?]
        at org.bukkit.plugin.EventExecutor.lambda$create$1(EventExecutor.java:69) ~[patched_1.14.4.jar:git-Paper-243]
        at org.bukkit.plugin.EventExecutor$$Lambda$2650/0000000008826340.execute(Unknown Source) ~[?:?]
        at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:80) ~[patched_1.14.4.jar:git-Paper-243]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[patched_1.14.4.jar:git-Paper-243]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:545) ~[patched_1.14.4.jar:git-Paper-243]
        at detox.DamageListener.damagePlayerPart2(DamageListener.java:23) ~[?:?]
    This is the code

    Code:
        @EventHandler
        public void damagePlayerPart2(EntityDamageEvent e)
        {
            if (e.getEntity() instanceof Player)
            {
                e.setCancelled(true);
                for(Player p : Bukkit.getOnlinePlayers())
                {
                    Bukkit.getPluginManager().callEvent(new EntityDamageEvent(p, e.getCause(), e.getDamage()));
                }
            }
        }
    I've also tried checking if every value is null and it still continues on to that point.
    I've googled and cant find the answer, if anyone could help that would be lovely:)
     
  2. Offline

    timtower Moderator Moderator

    @runaowi You are calling new events from within the event, that is a bad thing to do.
     
  3. Offline

    runaowi

    is there a better way to do this?
     
  4. Offline

    KarimAKL

    @runaowi Try setting their health to "current health - final damage" instead.
     
  5. Offline

    runaowi

    i will try that now:)

    it worked! Thank you karim, however i had to add a check to see if it would go under 0 first otherwise it would give an error:) thank you!! this is what i ender up with

    Code:
        @EventHandler
        public void damagePlayerPart2(EntityDamageEvent e)
        {
            if (e.getEntity() instanceof Player)
            {
                e.setCancelled(true);
                for(Player p : Bukkit.getOnlinePlayers())
                {
                    Double damageTake = p.getHealth() - e.getDamage();
                    if (damageTake < 0)
                    {
                        p.setHealth(0);
                        return;
                    }
                    p.setHealth(damageTake);
                }
            }
        }
    However i have one more question, how would i make it so the player still gets the screen shake as it doesnt show up

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Aug 12, 2020
  6. Offline

    KarimAKL

    @runaowi You can use Math.max(double, double) instead of the if statement.

    For the animation, i believe you can play the effect "HURT".
     
  7. Offline

    runaowi

    thank you so much!!
     
    KarimAKL likes this.
Thread Status:
Not open for further replies.

Share This Page