Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Add event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
seetch committed Sep 7, 2023
1 parent 95d2ea5 commit 039acd7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<build>
<resources>
<resource>
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/me/seetch/basicspawnprotection/EventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import cn.nukkit.event.EventPriority;
import cn.nukkit.event.Listener;
import cn.nukkit.event.block.*;
import cn.nukkit.event.entity.EntityDamageByEntityEvent;
import cn.nukkit.event.entity.EntityDamageEvent;
import cn.nukkit.event.entity.EntityExplodeEvent;
import cn.nukkit.event.player.PlayerDropItemEvent;
Expand Down Expand Up @@ -81,6 +82,7 @@ public void onEntityExplode(EntityExplodeEvent event) {
}
}

@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPlayerDropItem(PlayerDropItemEvent event) {
if (this.checkSpawnProtection(event.getPlayer())) {
event.setCancelled();
Expand All @@ -99,6 +101,14 @@ public void onEntityDamage(EntityDamageEvent event) {
if (this.checkSpawnProtection(event.getEntity())) {
event.setCancelled();
}

if (event instanceof EntityDamageByEntityEvent) {
Entity damager = ((EntityDamageByEntityEvent) event).getDamager();

if (this.checkSpawnProtection(damager)) {
event.setCancelled();
}
}
}

@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
Expand Down

0 comments on commit 039acd7

Please sign in to comment.