From b1dab9b2cf47d5d096300c17b14de31c66d03faa Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Mon, 29 Jul 2024 12:57:17 +0200 Subject: [PATCH] Displays animations for all players in the same world --- README.md | 5 +++-- .../blacksmithvisuals/BlacksmithListener.java | 14 ++++++-------- .../blacksmithvisuals/BlacksmithVisuals.java | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 710137c..2d3d833 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Blacksmith Visuals -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. \ No newline at end of file +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. \ No newline at end of file diff --git a/src/main/java/net/knarcraft/blacksmithvisuals/BlacksmithListener.java b/src/main/java/net/knarcraft/blacksmithvisuals/BlacksmithListener.java index c2a2e88..2652fb2 100644 --- a/src/main/java/net/knarcraft/blacksmithvisuals/BlacksmithListener.java +++ b/src/main/java/net/knarcraft/blacksmithvisuals/BlacksmithListener.java @@ -24,7 +24,6 @@ import org.bukkit.event.Listener; import org.bukkit.scheduler.BukkitScheduler; import org.jetbrains.annotations.NotNull; -import java.util.List; import java.util.Random; /** @@ -71,7 +70,7 @@ public class BlacksmithListener implements Listener { /** * A method performing actions required when a blacksmith or scrapper action starts - * + * * @param event

The event that's starting

*/ private void onActionStart(@NotNull ActionStartEvent event) { @@ -93,17 +92,16 @@ public class BlacksmithListener implements Listener { return; } - List nearby = event.getNpc().getEntity().getNearbyEntities(16, 16, 5); - nearby.removeIf((entity) -> !(entity instanceof Player)); - this.playWorkSound(event.getNpc().getEntity()); ProtocolManager manager = ProtocolLibrary.getProtocolManager(); PacketContainer packet = manager.createPacket(PacketType.Play.Server.ANIMATION); packet.getIntegers().write(0, event.getNpc().getEntity().getEntityId()); packet.getIntegers().write(1, 3); - - for (Entity entity : nearby) { - manager.sendServerPacket((Player) entity, packet); + + for (Player player : Bukkit.getOnlinePlayers()) { + if (player.getWorld().equals(event.getNpc().getEntity().getWorld())) { + manager.sendServerPacket(player, packet); + } } } diff --git a/src/main/java/net/knarcraft/blacksmithvisuals/BlacksmithVisuals.java b/src/main/java/net/knarcraft/blacksmithvisuals/BlacksmithVisuals.java index cc5ae72..35b23cf 100644 --- a/src/main/java/net/knarcraft/blacksmithvisuals/BlacksmithVisuals.java +++ b/src/main/java/net/knarcraft/blacksmithvisuals/BlacksmithVisuals.java @@ -12,7 +12,7 @@ public final class BlacksmithVisuals extends JavaPlugin { public void onEnable() { // Plugin startup logic getServer().getPluginManager().registerEvents(new BlacksmithListener(), this); - + //TODO: Allow customization of sounds, volumes and pitches // Allow setting an idle position and a working position, and move the NPC to the right position at the right time. // Use the distance between the two locations to decide how much sooner before the success/fail sounds are played the NPC should start walking