Move PlayerShearEntityEvent handling to EventListen to cover for snowman

This commit is contained in:
fullwall 2023-12-22 04:15:00 +08:00
parent 4e4112d531
commit d005c228ff
2 changed files with 11 additions and 10 deletions

View File

@ -46,6 +46,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerShearEntityEvent;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.PluginDisableEvent;
@ -631,6 +632,16 @@ public class EventListen implements Listener {
skinUpdateTracker.updatePlayer(event.getPlayer(), 15, true); skinUpdateTracker.updatePlayer(event.getPlayer(), 15, true);
} }
@EventHandler
public void onPlayerShearEntityEvent(PlayerShearEntityEvent event) {
NPC npc = CitizensAPI.getNPCRegistry().getNPC(event.getEntity());
if (npc == null)
return;
if (npc.isProtected()) {
event.setCancelled(true);
}
}
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onPlayerTeleport(PlayerTeleportEvent event) { public void onPlayerTeleport(PlayerTeleportEvent event) {
NPC npc = CitizensAPI.getNPCRegistry().getNPC(event.getPlayer()); NPC npc = CitizensAPI.getNPCRegistry().getNPC(event.getPlayer());

View File

@ -2,10 +2,7 @@ package net.citizensnpcs.trait;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.entity.Sheep; import org.bukkit.entity.Sheep;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerShearEntityEvent;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.persistence.Persist; import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait; import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName; import net.citizensnpcs.api.trait.TraitName;
@ -32,13 +29,6 @@ public class SheepTrait extends Trait {
return sheared; return sheared;
} }
@EventHandler
private void onPlayerShearEntityEvent(PlayerShearEntityEvent event) {
if (npc != null && npc.isProtected() && npc.equals(CitizensAPI.getNPCRegistry().getNPC(event.getEntity()))) {
event.setCancelled(true);
}
}
@Override @Override
public void run() { public void run() {
if (npc.getEntity() instanceof Sheep) { if (npc.getEntity() instanceof Sheep) {