Displays animations for all players in the same world

This commit is contained in:
Kristian Knarvik 2024-07-29 12:57:17 +02:00
parent 70759bc0e3
commit b1dab9b2cf
3 changed files with 10 additions and 11 deletions
README.md
src/main/java/net/knarcraft/blacksmithvisuals

@ -1,4 +1,5 @@
# Blacksmith Visuals # Blacksmith Visuals
This plugin adds additional visual and audial details to blacksmiths while they are working, so it's easier to see if This plugin adds additional visual and audial details to blacksmiths while they are working, so it's easier to see if
they are working or not. It is recommended to put a mace or other hammer-like item in the NPC's off-hand for full effect. they are working or not. It is recommended to put a mace or other hammer-like item in the NPC's off-hand for full
effect.

@ -24,7 +24,6 @@ import org.bukkit.event.Listener;
import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitScheduler;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.Random; import java.util.Random;
/** /**
@ -93,17 +92,16 @@ public class BlacksmithListener implements Listener {
return; return;
} }
List<Entity> nearby = event.getNpc().getEntity().getNearbyEntities(16, 16, 5);
nearby.removeIf((entity) -> !(entity instanceof Player));
this.playWorkSound(event.getNpc().getEntity()); this.playWorkSound(event.getNpc().getEntity());
ProtocolManager manager = ProtocolLibrary.getProtocolManager(); ProtocolManager manager = ProtocolLibrary.getProtocolManager();
PacketContainer packet = manager.createPacket(PacketType.Play.Server.ANIMATION); PacketContainer packet = manager.createPacket(PacketType.Play.Server.ANIMATION);
packet.getIntegers().write(0, event.getNpc().getEntity().getEntityId()); packet.getIntegers().write(0, event.getNpc().getEntity().getEntityId());
packet.getIntegers().write(1, 3); packet.getIntegers().write(1, 3);
for (Entity entity : nearby) { for (Player player : Bukkit.getOnlinePlayers()) {
manager.sendServerPacket((Player) entity, packet); if (player.getWorld().equals(event.getNpc().getEntity().getWorld())) {
manager.sendServerPacket(player, packet);
}
} }
} }