Skip to content

Commit

Permalink
Fix EntityDamageEvent
Browse files Browse the repository at this point in the history
Add the missing direct entity to Damage events as when using an indirect one, you still need to specify a direct one.
  • Loading branch information
TrueDarkLord committed Mar 19, 2024
1 parent 6e5684b commit ba67c2f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ issues = https://github.com/Crazy-Crew/CrazyEnchantments/issues

group = com.badbones69.crazyenchantments
description = Adds over 80 unique enchantments to your server and more!
version = 2.2.7
version = 2.2.8
apiVersion = 1.20

mcVersion = 1.20.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@
import org.bukkit.damage.DamageSource;
import org.bukkit.damage.DamageType;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.*;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDropItemEvent;
import org.bukkit.event.entity.EntityDamageEvent;
Expand Down Expand Up @@ -395,7 +390,7 @@ public void explode(Entity entity, Entity arrow) {
if (this.pluginSupport.isFriendly(entity, livingEntity)) continue;
if (entity.getName().equalsIgnoreCase(value.getName())) continue;

EntityDamageEvent event = new EntityDamageEvent(livingEntity, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION, DamageSource.builder(DamageType.EXPLOSION).withCausingEntity(entity).build(), 5D);
EntityDamageEvent event = new EntityDamageEvent(livingEntity, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION, DamageSource.builder(DamageType.EXPLOSION).withCausingEntity(entity).withDirectEntity(arrow).build(), 5D);

this.plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) continue;
Expand Down Expand Up @@ -439,14 +434,17 @@ public void entityEvent(Player damager, LivingEntity entity, EntityDamageEvent d
EventUtils.removeIgnoredUUID(damager.getUniqueId());
}

public void lightning(LivingEntity en) {
public Entity lightning(LivingEntity en) {
Location loc = en.getLocation();
if (loc.getWorld() != null) loc.getWorld().strikeLightning(loc);
Entity lightning = null;
if (loc.getWorld() != null) lightning = loc.getWorld().strikeLightning(loc);
int lightningSoundRange = Files.CONFIG.getFile().getInt("Settings.EnchantmentOptions.Lightning-Sound-Range", 160);

try {
loc.getWorld().playSound(loc, Sound.ENTITY_LIGHTNING_BOLT_IMPACT, (float) lightningSoundRange / 16f, 1);
} catch (Exception ignore) {}

return lightning;
}

public void switchCurrency(Player player, Currency option, String one, String two, String cost) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.bukkit.attribute.Attribute;
import org.bukkit.damage.DamageSource;
import org.bukkit.damage.DamageType;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand Down Expand Up @@ -273,13 +274,13 @@ public void onPlayerDamage(EntityDamageByEntityEvent event) {
if (EnchantUtils.isEventActive(CEnchantments.CACTUS, player, armor, enchants)) damager.damage(this.crazyManager.getLevel(armor, CEnchantments.CACTUS));

if (EnchantUtils.isEventActive(CEnchantments.STORMCALLER, player, armor, enchants)) {
this.methods.lightning(damager);
Entity lightning = this.methods.lightning(damager);

// AntiCheat Support.
if (SupportedPlugins.NO_CHEAT_PLUS.isPluginLoaded()) this.noCheatPlusSupport.allowPlayer(player);

for (LivingEntity en : this.methods.getNearbyLivingEntities(2D, player)) {
EntityDamageEvent damageByEntityEvent = new EntityDamageEvent(en, DamageCause.LIGHTNING, DamageSource.builder(DamageType.LIGHTNING_BOLT).withCausingEntity(player).build(), 5D);
EntityDamageEvent damageByEntityEvent = new EntityDamageEvent(en, DamageCause.LIGHTNING, DamageSource.builder(DamageType.LIGHTNING_BOLT).withCausingEntity(player).withDirectEntity(lightning).build(), 5D);
this.methods.entityEvent(player, en, damageByEntityEvent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.bukkit.damage.DamageSource;
import org.bukkit.damage.DamageType;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand Down Expand Up @@ -118,7 +119,7 @@ public void onLand(ProjectileHitEvent event) {
if (EnchantUtils.isEventActive(CEnchantments.LIGHTNING, shooter, arrow.bow(), arrow.enchantments())) {
Location location = arrow.arrow().getLocation();

location.getWorld().strikeLightningEffect(location);
Entity lightning = location.getWorld().strikeLightningEffect(location);

int lightningSoundRange = Files.CONFIG.getFile().getInt("Settings.EnchantmentOptions.Lightning-Sound-Range", 160);

Expand All @@ -131,7 +132,7 @@ public void onLand(ProjectileHitEvent event) {
if (SupportedPlugins.NO_CHEAT_PLUS.isPluginLoaded()) this.noCheatPlusSupport.allowPlayer(shooter);

for (LivingEntity entity : this.methods.getNearbyLivingEntities(2D, arrow.arrow())) {
EntityDamageEvent damageByEntityEvent = new EntityDamageEvent(entity, DamageCause.LIGHTNING, DamageSource.builder(DamageType.LIGHTNING_BOLT).withCausingEntity(shooter).build(), 5D);
EntityDamageEvent damageByEntityEvent = new EntityDamageEvent(entity, DamageCause.LIGHTNING, DamageSource.builder(DamageType.LIGHTNING_BOLT).withCausingEntity(shooter).withDirectEntity(lightning).build(), 5D);

EventUtils.addIgnoredEvent(damageByEntityEvent);
EventUtils.addIgnoredUUID(shooter.getUniqueId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public void run() {
if (SupportedPlugins.NO_CHEAT_PLUS.isPluginLoaded()) this.noCheatPlusSupport.allowPlayer(damager);

for (LivingEntity entity : this.methods.getNearbyLivingEntities(2D, damager)) {
EntityDamageEvent damageByEntityEvent = new EntityDamageEvent(entity, EntityDamageEvent.DamageCause.MAGIC, DamageSource.builder(DamageType.INDIRECT_MAGIC).withCausingEntity(damager).build(), 5D);
EntityDamageEvent damageByEntityEvent = new EntityDamageEvent(entity, EntityDamageEvent.DamageCause.MAGIC, DamageSource.builder(DamageType.INDIRECT_MAGIC).withDirectEntity(damager).build(), 5D);
this.methods.entityEvent(damager, entity, damageByEntityEvent);
}

Expand Down

0 comments on commit ba67c2f

Please sign in to comment.