Skip to content

Commit

Permalink
check active item and no longer remove entity
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Aug 5, 2024
1 parent 4b9ce96 commit 301de20
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
Expand Down Expand Up @@ -313,10 +314,16 @@ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
return;
}

if (EntityUtil.isLivingEntity(event.getDamager())) {
if (legalityOf(((LivingEntity) event.getDamager()).getActiveItem()) != ItemLegality.LEGAL) {
event.setCancelled(true);
return;
}
}

if (EntityUtil.isInventoryHolder(event.getDamager())) {
if (legalityOf(((InventoryHolder) event.getDamager()).getInventory()) != ItemLegality.LEGAL) {
event.setCancelled(true);
event.getDamager().getScheduler().execute(plugin, event.getDamager()::remove, null, 1L);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
Expand Down Expand Up @@ -291,10 +292,16 @@ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
return;
}

if (EntityUtil.isLivingEntity(event.getDamager())) {
if (legalityOf(((LivingEntity) event.getDamager()).getActiveItem()) != ItemLegality.LEGAL) {
event.setCancelled(true);
return;
}
}

if (EntityUtil.isInventoryHolder(event.getDamager())) {
if (legalityOf(((InventoryHolder) event.getDamager()).getInventory()) != ItemLegality.LEGAL) {
event.setCancelled(true);
event.getDamager().remove();
}
}
}
Expand Down

0 comments on commit 301de20

Please sign in to comment.