Don't call EntityDamageByEntityEvent with null damager

This commit is contained in:
Elioby 2023-02-09 01:33:59 +00:00
parent 08b08b1285
commit a58c6be8a0
No known key found for this signature in database
GPG Key ID: DFFAD66792B08FCD

View File

@ -8,6 +8,7 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent; import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.metadata.MobMetaFlagType; import com.gmail.nossr50.metadata.MobMetaFlagType;
import com.gmail.nossr50.metadata.MobMetadataService; import com.gmail.nossr50.metadata.MobMetadataService;
@ -885,8 +886,14 @@ public final class CombatUtils {
return false; return false;
} }
public static boolean canDamage(@NotNull Entity attacker, @NotNull Entity target, @NotNull DamageCause damageCause, double damage) { public static boolean canDamage(@Nullable Entity attacker, @NotNull Entity target, @NotNull DamageCause damageCause, double damage) {
EntityDamageEvent damageEvent = new FakeEntityDamageByEntityEvent(attacker, target, damageCause, damage); EntityDamageEvent damageEvent;
if (attacker != null) {
damageEvent = new FakeEntityDamageByEntityEvent(attacker, target, damageCause, damage);
} else {
damageEvent = new FakeEntityDamageEvent(target, damageCause, damage);
}
mcMMO.p.getServer().getPluginManager().callEvent(damageEvent); mcMMO.p.getServer().getPluginManager().callEvent(damageEvent);
return !damageEvent.isCancelled(); return !damageEvent.isCancelled();