Skip to content

Commit

Permalink
fix FireworkDeathEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
fantahund committed May 13, 2024
1 parent d1a4584 commit 26f8aec
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.fanta.fancyfirework.events;

import org.bukkit.damage.DamageSource;
import org.bukkit.entity.ArmorStand;
import org.bukkit.event.Cancellable;
import org.bukkit.event.entity.EntityDeathEvent;
Expand All @@ -11,8 +12,8 @@ public class FireworkDeathEvent extends EntityDeathEvent implements Cancellable

private boolean cancelled;

public FireworkDeathEvent(ArmorStand stand, List<ItemStack> drops) {
super(stand, drops);
public FireworkDeathEvent(ArmorStand stand, List<ItemStack> drops, DamageSource damageSource) {
super(stand, damageSource, drops);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.DoubleChest;
import org.bukkit.damage.DamageSource;
import org.bukkit.damage.DamageType;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
Expand Down Expand Up @@ -253,7 +255,7 @@ public void onInteractItem(PlayerInteractEvent e) {

private void damageFNS(Player player, EquipmentSlot slot) {
ItemStack stack = player.getEquipment().getItem(slot);
if (player.getGameMode() != GameMode.CREATIVE) {
if (player.getGameMode() != GameMode.CREATIVE || stack.getItemMeta().isUnbreakable()) {
ItemMeta meta = stack.getItemMeta();
int maxDurability = stack.getType().getMaxDurability();
if (maxDurability > 0) {
Expand Down Expand Up @@ -307,7 +309,8 @@ public void onDamage(EntityDamageByEntityEvent e) {
List<ItemStack> stackList = new ArrayList<>();
stackList.add(stack);
stand.setLastDamageCause(e);
FireworkDeathEvent fireworkDeathEvent = new FireworkDeathEvent(stand, stackList);
DamageSource damageSource = DamageSource.builder(DamageType.PLAYER_ATTACK).withCausingEntity(player).withDirectEntity(player).withDamageLocation(stand.getLocation()).build();
FireworkDeathEvent fireworkDeathEvent = new FireworkDeathEvent(stand, stackList, damageSource);
player.getServer().getPluginManager().callEvent(fireworkDeathEvent);
if (fireworkDeathEvent.isCancelled()) {
e.setCancelled(true);
Expand Down

0 comments on commit 26f8aec

Please sign in to comment.