Skip to content

Commit

Permalink
Fix EntityDamage Events
Browse files Browse the repository at this point in the history
Fixes the breaking change that Spigot had made.
  • Loading branch information
TrueDarkLord committed Feb 17, 2024
1 parent bde17b1 commit 1f9ecd9
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 46 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,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.3
version = 2.2.4
apiVersion = 1.20

minecraftVersion = 1.20.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.bukkit.entity.*;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDropItemEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
Expand Down Expand Up @@ -374,15 +373,7 @@ public void explode(Entity entity, Entity arrow) {
if (pluginSupport.isFriendly(entity, livingEntity)) continue;
if (entity.getName().equalsIgnoreCase(value.getName())) continue;

EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(
entity,
livingEntity,
EntityDamageEvent.DamageCause.BLOCK_EXPLOSION,
DamageSource.builder(DamageType.EXPLOSION).build(),
new HashMap<>(),
new HashMap<>(),
false
);
EntityDamageEvent event = new EntityDamageEvent(livingEntity, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION, DamageSource.builder(DamageType.EXPLOSION).withCausingEntity(entity).build(), 5D);

plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) continue;
Expand All @@ -395,28 +386,6 @@ public void explode(Entity entity, Entity arrow) {
}
}

public static EntityDamageEvent getDamageEvent(Entity entity, Entity directEntity, EntityDamageEvent.DamageCause damageCause, DamageType damageType) {
return new EntityDamageEvent(
entity,
damageCause,
DamageSource.builder(damageType).withDirectEntity(directEntity).build(),
new HashMap<>(),
new HashMap<>()
);
}

public static EntityDamageByEntityEvent entityDamageByEntityEvent(Entity damager, Entity damagee, EntityDamageEvent.DamageCause cause, DamageType damageType) {
return new EntityDamageByEntityEvent(
damager,
damagee,
cause,
DamageSource.builder(damageType).build(),
new HashMap<>(),
new HashMap<>(),
false
);
}

public HashSet<Block> getEnchantBlocks(Location loc, Location loc2) {
HashSet<Block> blockList = new HashSet<>();
int topBlockX = (Math.max(loc.getBlockX(), loc2.getBlockX()));
Expand All @@ -437,7 +406,7 @@ public HashSet<Block> getEnchantBlocks(Location loc, Location loc2) {
return blockList;
}

public void entityEvent(Player damager, LivingEntity entity, EntityDamageByEntityEvent damageByEntityEvent) {
public void entityEvent(Player damager, LivingEntity entity, EntityDamageEvent damageByEntityEvent) {
EventUtils.addIgnoredEvent(damageByEntityEvent);
EventUtils.addIgnoredUUID(damager.getUniqueId());
plugin.getServer().getPluginManager().callEvent(damageByEntityEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,6 @@ public boolean allowCombat(Location location) {
return !SupportedPlugins.WORLDEDIT.isPluginLoaded() || !SupportedPlugins.WORLDGUARD.isPluginLoaded() || this.worldGuardUtils.getWorldGuardSupport().allowsPVP(location);
}

private boolean damageCheck(Player one, Player two) { // Would cause lag if used on player move event, but might be the only way to actually check.
EntityDamageByEntityEvent event = Methods.entityDamageByEntityEvent(one, two, EntityDamageEvent.DamageCause.ENTITY_ATTACK, DamageType.PLAYER_ATTACK);
event.setDamage(0);
EventUtils.addIgnoredEvent(event);
plugin.getServer().getPluginManager().callEvent(event);
EventUtils.removeIgnoredEvent(event);
return event.isCancelled();
}

public boolean allowDestruction(Location location) {
return !SupportedPlugins.WORLDEDIT.isPluginLoaded() || !SupportedPlugins.WORLDGUARD.isPluginLoaded() || this.worldGuardUtils.getWorldGuardSupport().allowsBreak(location);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.attribute.Attribute;
import org.bukkit.damage.DamageSource;
import org.bukkit.damage.DamageType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -251,7 +252,7 @@ public void onPlayerDamage(EntityDamageByEntityEvent event) {
if (SupportedPlugins.NO_CHEAT_PLUS.isPluginLoaded()) noCheatPlusSupport.allowPlayer(player);

for (LivingEntity en : methods.getNearbyLivingEntities(2D, player)) {
EntityDamageByEntityEvent damageByEntityEvent = Methods.entityDamageByEntityEvent(player, en, DamageCause.CUSTOM, DamageType.INDIRECT_MAGIC);
EntityDamageEvent damageByEntityEvent = new EntityDamageEvent(en, DamageCause.LIGHTNING, DamageSource.builder(DamageType.LIGHTNING_BOLT).withCausingEntity(player).build(), 5D);
methods.entityEvent(player, en, damageByEntityEvent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.attribute.Attribute;
import org.bukkit.damage.DamageSource;
import org.bukkit.damage.DamageType;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.LivingEntity;
Expand All @@ -29,6 +30,7 @@
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
Expand Down Expand Up @@ -117,7 +119,7 @@ public void onLand(ProjectileHitEvent event) {
if (SupportedPlugins.NO_CHEAT_PLUS.isPluginLoaded()) noCheatPlusSupport.allowPlayer(shooter);

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

EventUtils.addIgnoredEvent(damageByEntityEvent);
EventUtils.addIgnoredUUID(shooter.getUniqueId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.badbones69.crazyenchantments.paper.utilities.misc.EventUtils;
import org.bukkit.Material;
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;
Expand Down Expand Up @@ -264,7 +265,7 @@ public void run() {
if (SupportedPlugins.NO_CHEAT_PLUS.isPluginLoaded()) noCheatPlusSupport.allowPlayer(damager);

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

Expand Down

0 comments on commit 1f9ecd9

Please sign in to comment.