From f1f4526f9d3a2b05186b017a2b51efde8da230c0 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Fri, 27 Sep 2024 01:43:13 +0200 Subject: [PATCH] Updates to the Blacksmith Snapshot API --- README.md | 2 +- pom.xml | 4 +-- .../command/PlayTestSoundCommand.java | 7 +++-- .../listener/BlacksmithListener.java | 30 ++++++++++--------- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 6f89689..a5daf55 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ effect. ## Dependencies -This plugins requires the following: +This plugin requires the following: - [Blacksmith](https://www.spigotmc.org/resources/blacksmith.105938/) - [Citizens](https://www.spigotmc.org/resources/citizens.13811/) (also a dependency for Blacksmith) diff --git a/pom.xml b/pom.xml index 9db469a..f301a2d 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.knarcraft BlacksmithVisuals - 1.0.0 + 1.0.1-SNAPSHOT jar BlacksmithVisuals @@ -111,7 +111,7 @@ net.knarcraft blacksmith - 1.1.2 + 1.1.3-SNAPSHOT provided diff --git a/src/main/java/net/knarcraft/blacksmithvisuals/command/PlayTestSoundCommand.java b/src/main/java/net/knarcraft/blacksmithvisuals/command/PlayTestSoundCommand.java index caba5c4..748722f 100644 --- a/src/main/java/net/knarcraft/blacksmithvisuals/command/PlayTestSoundCommand.java +++ b/src/main/java/net/knarcraft/blacksmithvisuals/command/PlayTestSoundCommand.java @@ -11,6 +11,7 @@ import org.bukkit.SoundCategory; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Entity; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -34,7 +35,8 @@ public class PlayTestSoundCommand implements TabExecutor { return true; } - if (arguments.length < 2) { + Entity entity = npc.getEntity(); + if (arguments.length < 2 || !npc.isSpawned() || entity == null) { return false; } @@ -62,8 +64,7 @@ public class PlayTestSoundCommand implements TabExecutor { return false; } - SoundData soundData = new SoundData(soundCategory, sound, volume, pitch, 0, true); - SoundHelper.playSound(npc.getEntity(), soundData); + SoundHelper.playSound(entity, new SoundData(soundCategory, sound, volume, pitch, 0, true)); return true; } diff --git a/src/main/java/net/knarcraft/blacksmithvisuals/listener/BlacksmithListener.java b/src/main/java/net/knarcraft/blacksmithvisuals/listener/BlacksmithListener.java index dd4b89c..32e5611 100644 --- a/src/main/java/net/knarcraft/blacksmithvisuals/listener/BlacksmithListener.java +++ b/src/main/java/net/knarcraft/blacksmithvisuals/listener/BlacksmithListener.java @@ -80,22 +80,22 @@ public class BlacksmithListener implements Listener { @EventHandler public void onReforgeSuccess(@NotNull BlacksmithReforgeSucceedEvent event) { - SoundHelper.playSound(event.getNpc().getEntity(), this.configurationManager.getSoundData(SoundIdentifier.REFORGING_SUCCESS)); + SoundHelper.playSound(event.getEntity(), this.configurationManager.getSoundData(SoundIdentifier.REFORGING_SUCCESS)); } @EventHandler public void onSalvageSuccess(@NotNull ScrapperSalvageSucceedEvent event) { - SoundHelper.playSound(event.getNpc().getEntity(), this.configurationManager.getSoundData(SoundIdentifier.SALVAGING_SUCCESS)); + SoundHelper.playSound(event.getEntity(), this.configurationManager.getSoundData(SoundIdentifier.SALVAGING_SUCCESS)); } @EventHandler public void onReforgeFail(@NotNull BlacksmithReforgeFailEvent event) { - SoundHelper.playSound(event.getNpc().getEntity(), this.configurationManager.getSoundData(SoundIdentifier.REFORGING_FAILURE)); + SoundHelper.playSound(event.getEntity(), this.configurationManager.getSoundData(SoundIdentifier.REFORGING_FAILURE)); } @EventHandler public void onSalvageFail(@NotNull ScrapperSalvageFailEvent event) { - SoundHelper.playSound(event.getNpc().getEntity(), this.configurationManager.getSoundData(SoundIdentifier.SALVAGING_FAILURE)); + SoundHelper.playSound(event.getEntity(), this.configurationManager.getSoundData(SoundIdentifier.SALVAGING_FAILURE)); } /** @@ -112,7 +112,7 @@ public class BlacksmithListener implements Listener { NPC npc = event.getNpc(); NPCPosition npcPosition = NPCPosition.getFromMaterial(event.getCraftingStation()); - long delay = moveToWorkingPosition(npc, npcPosition); + long delay = moveToWorkingPosition(npc, event.getEntity(), npcPosition); if (npc.hasTrait(LookClose.class)) { LookClose trait = npc.getTraitNullable(LookClose.class); this.oldLookRanges.put(npc.getUniqueId(), trait.getRange()); @@ -120,17 +120,18 @@ public class BlacksmithListener implements Listener { } long finishTime = event.getActionDurationTicks() - (2 * delay); - scheduler.scheduleSyncDelayedTask(instance, () -> startWorkAnimation(npc.getEntity(), + scheduler.scheduleSyncDelayedTask(instance, () -> startWorkAnimation(event.getEntity(), this.configurationManager.getSoundData(soundIdentifier), animationData, finishTime - 20, npcPosition), delay); - scheduler.scheduleSyncDelayedTask(instance, () -> moveBack(event.getNpc()), finishTime); + scheduler.scheduleSyncDelayedTask(instance, () -> moveBack(event.getNpc(), event.getEntity()), finishTime); } /** * Moves an NPC back to its idle position * - * @param npc

The NPC to move

+ * @param npc

The NPC to move

+ * @param entity

The entity of the NPC

*/ - private void moveBack(@NotNull NPC npc) { + private void moveBack(@NotNull NPC npc, @NotNull Entity entity) { if (!npc.isSpawned()) { return; } @@ -156,7 +157,7 @@ public class BlacksmithListener implements Listener { } Bukkit.getScheduler().scheduleSyncDelayedTask(BlacksmithVisuals.getInstance(), () -> - npc.getEntity().teleport(targetLocation), getWalkTime(npc.getEntity().getLocation(), targetLocation)); + entity.teleport(targetLocation), getWalkTime(entity.getLocation(), targetLocation)); npc.getNavigator().setTarget(targetLocation); } @@ -164,10 +165,11 @@ public class BlacksmithListener implements Listener { * Moves a npc to its working position * * @param npc

The NPC to move

+ * @param entity

The entity of the NPC

* @param npcPosition

The npc position to move to

* @return

The time the move will take

*/ - private long moveToWorkingPosition(@NotNull NPC npc, @Nullable NPCPosition npcPosition) { + private long moveToWorkingPosition(@NotNull NPC npc, @NotNull Entity entity, @Nullable NPCPosition npcPosition) { if (!npc.isSpawned() || npcPosition == null) { return 0; } @@ -193,15 +195,15 @@ public class BlacksmithListener implements Listener { Location finalTargetLocation = targetLocation; // Move NPC using Citizens path-finding - Location current = npc.getEntity().getLocation().clone(); + Location current = entity.getLocation().clone(); npc.teleport(current.setDirection(targetLocation.toVector().subtract(current.toVector())), PlayerTeleportEvent.TeleportCause.PLUGIN); Bukkit.getScheduler().scheduleSyncDelayedTask(BlacksmithVisuals.getInstance(), () -> npc.getNavigator().setTarget(finalTargetLocation), 2); // Teleport the NPC tp get it in the exact final location - long walkTime = getWalkTime(npc.getEntity().getLocation(), targetLocation); + long walkTime = getWalkTime(entity.getLocation(), targetLocation); Bukkit.getScheduler().scheduleSyncDelayedTask(BlacksmithVisuals.getInstance(), () -> - npc.getEntity().teleport(finalTargetLocation), walkTime); + entity.teleport(finalTargetLocation), walkTime); return walkTime; }