diff --git a/src/main/java/net/knarcraft/blacksmith/config/Settings.java b/src/main/java/net/knarcraft/blacksmith/config/Settings.java index 6481fb0..24260b5 100644 --- a/src/main/java/net/knarcraft/blacksmith/config/Settings.java +++ b/src/main/java/net/knarcraft/blacksmith/config/Settings.java @@ -24,6 +24,7 @@ public interface Settings { * @param setting

The setting to get

* @return

The current raw setting value

*/ - @NotNull Object getRawValue(@NotNull K setting); + @NotNull + Object getRawValue(@NotNull K setting); } diff --git a/src/main/java/net/knarcraft/blacksmith/trait/ReforgeSession.java b/src/main/java/net/knarcraft/blacksmith/trait/ReforgeSession.java index ab72f31..ce2647f 100644 --- a/src/main/java/net/knarcraft/blacksmith/trait/ReforgeSession.java +++ b/src/main/java/net/knarcraft/blacksmith/trait/ReforgeSession.java @@ -9,6 +9,7 @@ import net.knarcraft.blacksmith.util.ItemHelper; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.Registry; +import org.bukkit.Sound; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -30,7 +31,6 @@ import static net.knarcraft.blacksmith.formatting.BlacksmithStringFormatter.send public class ReforgeSession extends Session implements Runnable { private final BlacksmithTrait blacksmithTrait; - private final NPC npc; private final ItemStack itemToReforge; private final BlacksmithNPCSettings config; private static List enchantments = null; @@ -45,9 +45,8 @@ public class ReforgeSession extends Session implements Runnable { */ ReforgeSession(@NotNull BlacksmithTrait blacksmithTrait, @NotNull Player player, @NotNull NPC npc, @NotNull BlacksmithNPCSettings config) { - super(player); + super(player, npc); this.blacksmithTrait = blacksmithTrait; - this.npc = npc; this.itemToReforge = player.getInventory().getItemInMainHand(); this.config = config; @@ -97,7 +96,9 @@ public class ReforgeSession extends Session implements Runnable { */ @Override public void run() { - sendNPCMessage(this.npc, this.player, reforgeItem() ? this.config.getSuccessMessage() : this.config.getFailMessage()); + boolean success = reforgeItem(); + sendNPCMessage(this.npc, this.player, success ? this.config.getSuccessMessage() : this.config.getFailMessage()); + playSound(success ? Sound.BLOCK_ANVIL_USE : Sound.ENTITY_VILLAGER_NO); //Stop the reforged item from displaying in the blacksmith's hand if (this.npc.getEntity() instanceof Player) { diff --git a/src/main/java/net/knarcraft/blacksmith/trait/SalvageSession.java b/src/main/java/net/knarcraft/blacksmith/trait/SalvageSession.java index e127e04..f914cc1 100644 --- a/src/main/java/net/knarcraft/blacksmith/trait/SalvageSession.java +++ b/src/main/java/net/knarcraft/blacksmith/trait/SalvageSession.java @@ -6,6 +6,7 @@ import net.knarcraft.blacksmith.config.scrapper.ScrapperNPCSettings; import net.knarcraft.blacksmith.manager.EconomyManager; import net.knarcraft.blacksmith.util.ItemHelper; import net.knarcraft.blacksmith.util.SalvageHelper; +import org.bukkit.Sound; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -25,7 +26,6 @@ import static net.knarcraft.blacksmith.formatting.BlacksmithStringFormatter.send public class SalvageSession extends Session implements Runnable { private final ScrapperTrait scrapperTrait; - private final NPC npc; private final ItemStack itemToSalvage; private final ScrapperNPCSettings config; private final List salvage; @@ -47,9 +47,8 @@ public class SalvageSession extends Session implements Runnable { SalvageSession(@NotNull ScrapperTrait scrapperTrait, @NotNull Player player, @NotNull NPC npc, @NotNull ScrapperNPCSettings config, @NotNull List salvage, @NotNull SalvageMethod salvageMethod, int itemsConsumed) { - super(player); + super(player, npc); this.scrapperTrait = scrapperTrait; - this.npc = npc; this.itemToSalvage = player.getInventory().getItemInMainHand().clone(); this.config = config; this.salvage = salvage; @@ -113,8 +112,10 @@ public class SalvageSession extends Session implements Runnable { */ private void salvageItem() { if (random.nextInt(100) < this.config.getFailChance()) { + playSound(Sound.ENTITY_VILLAGER_NO); failSalvage(); } else { + playSound(Sound.BLOCK_ANVIL_USE); giveSalvage(); sendNPCMessage(this.npc, this.player, this.config.getSuccessMessage()); } diff --git a/src/main/java/net/knarcraft/blacksmith/trait/Session.java b/src/main/java/net/knarcraft/blacksmith/trait/Session.java index 3fcd50d..a0b740b 100644 --- a/src/main/java/net/knarcraft/blacksmith/trait/Session.java +++ b/src/main/java/net/knarcraft/blacksmith/trait/Session.java @@ -3,6 +3,9 @@ package net.knarcraft.blacksmith.trait; import net.citizensnpcs.api.npc.NPC; import net.knarcraft.blacksmith.BlacksmithPlugin; import net.knarcraft.blacksmith.util.ItemHelper; +import org.bukkit.Sound; +import org.bukkit.SoundCategory; +import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitScheduler; @@ -18,6 +21,7 @@ public abstract class Session implements Runnable { protected static final Random random = new Random(); protected final Player player; + protected final NPC npc; protected long finishTime; protected int taskId; @@ -25,9 +29,11 @@ public abstract class Session implements Runnable { * Instantiates a new session * * @param player

The player the session belongs to

+ * @param npc

The NPC involved in the session

*/ - public Session(@NotNull Player player) { + public Session(@NotNull Player player, @NotNull NPC npc) { this.player = player; + this.npc = npc; } /** @@ -90,6 +96,10 @@ public abstract class Session implements Runnable { int actionDelay = getActionDelay(); this.finishTime = System.currentTimeMillis() + (actionDelay * 1000L); taskId = scheduler.scheduleSyncDelayedTask(BlacksmithPlugin.getInstance(), this, actionDelay * 20L); + int playWorkSound = scheduler.scheduleSyncRepeatingTask(BlacksmithPlugin.getInstance(), + this::playWorkSound, 20, 20); + scheduler.scheduleSyncDelayedTask(BlacksmithPlugin.getInstance(), () -> scheduler.cancelTask(playWorkSound), + (actionDelay * 20L) - 20); } /** @@ -140,4 +150,26 @@ public abstract class Session implements Runnable { */ protected abstract int getActionDelay(); + /** + * Plays an NPC sound + * + * @param sound

The sound to play

+ */ + protected void playSound(Sound sound) { + World world = this.npc.getEntity().getLocation().getWorld(); + if (world != null) { + world.playSound(this.npc.getEntity(), sound, SoundCategory.AMBIENT, 0.5F, 1.0F); + } + } + + /** + * Plays the working NPC sound + */ + protected void playWorkSound() { + World world = this.npc.getEntity().getLocation().getWorld(); + if (world != null) { + world.playSound(this.npc.getEntity(), Sound.BLOCK_PACKED_MUD_BREAK, SoundCategory.AMBIENT, 0.5F, (float) 0.5); + } + } + } diff --git a/src/main/java/net/knarcraft/blacksmith/util/ItemHelper.java b/src/main/java/net/knarcraft/blacksmith/util/ItemHelper.java index c0dbae6..758d914 100644 --- a/src/main/java/net/knarcraft/blacksmith/util/ItemHelper.java +++ b/src/main/java/net/knarcraft/blacksmith/util/ItemHelper.java @@ -105,6 +105,9 @@ public final class ItemHelper { public static @NotNull Set getAllReforgeAbleMaterials() { Set reforgeAbleMaterials = new HashSet<>(); for (Material material : Material.values()) { + if (!material.isItem()) { + continue; + } ItemStack item = new ItemStack(material); if (isRepairable(item)) { reforgeAbleMaterials.add(material);