Displays animations for all players in the same world
All checks were successful
KnarCraft/BlacksmithVisuals/pipeline/head This commit looks good

This commit is contained in:
2024-07-29 12:57:17 +02:00
parent 70759bc0e3
commit b1dab9b2cf
3 changed files with 10 additions and 11 deletions

View File

@@ -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 <p>The event that's starting</p>
*/
private void onActionStart(@NotNull ActionStartEvent event) {
@@ -93,17 +92,16 @@ public class BlacksmithListener implements Listener {
return;
}
List<Entity> 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);
}
}
}

View File

@@ -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