From b094d34c625368d119754dab8b1ed8dc7508dde3 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Wed, 27 Nov 2024 12:20:01 +0100 Subject: [PATCH] Adds debug output and a new working position --- .../knarcraft/blacksmithvisuals/BlacksmithVisuals.java | 10 +++++++++- .../blacksmithvisuals/manager/NPCDataManager.java | 2 ++ .../blacksmithvisuals/property/NPCPosition.java | 6 ++++++ .../knarcraft/blacksmithvisuals/util/SoundHelper.java | 3 +++ src/main/resources/config.yml | 2 ++ 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/knarcraft/blacksmithvisuals/BlacksmithVisuals.java b/src/main/java/net/knarcraft/blacksmithvisuals/BlacksmithVisuals.java index 09a2821..cdb9efa 100644 --- a/src/main/java/net/knarcraft/blacksmithvisuals/BlacksmithVisuals.java +++ b/src/main/java/net/knarcraft/blacksmithvisuals/BlacksmithVisuals.java @@ -24,6 +24,7 @@ public final class BlacksmithVisuals extends JavaPlugin { private static BlacksmithVisuals instance; private ConfigurationManager configurationManager; private NPCDataManager npcDataManager; + private boolean debug = false; @Override public void onEnable() { @@ -35,6 +36,8 @@ public final class BlacksmithVisuals extends JavaPlugin { this.reloadConfig(); this.saveConfig(); + this.debug = this.getConfig().getBoolean("debug", false); + try { this.configurationManager = new ConfigurationManager(this.getConfig()); } catch (InvalidConfigurationException exception) { @@ -68,7 +71,12 @@ public final class BlacksmithVisuals extends JavaPlugin { * @param message

The debug message to log

*/ public static void debug(@NotNull String message) { - getInstance().getLogger().log(Level.FINE, message); + BlacksmithVisuals instance = getInstance(); + if (instance.debug) { + instance.getLogger().log(Level.INFO, "[Debug] " + message); + } else { + instance.getLogger().log(Level.FINE, message); + } } /** diff --git a/src/main/java/net/knarcraft/blacksmithvisuals/manager/NPCDataManager.java b/src/main/java/net/knarcraft/blacksmithvisuals/manager/NPCDataManager.java index e45bb3a..f1cb727 100644 --- a/src/main/java/net/knarcraft/blacksmithvisuals/manager/NPCDataManager.java +++ b/src/main/java/net/knarcraft/blacksmithvisuals/manager/NPCDataManager.java @@ -77,6 +77,7 @@ public class NPCDataManager { npcSection.set("workingPositionNetherite", entry.getValue().positions().get(NPCPosition.WORKING_NETHERITE)); npcSection.set("workingPositionCrafting", entry.getValue().positions().get(NPCPosition.WORKING_CRAFTING)); npcSection.set("workingPositionRepairable", entry.getValue().positions().get(NPCPosition.WORKING_REPAIRABLE)); + npcSection.set("workingPositionEnchantedBook", entry.getValue().positions().get(NPCPosition.WORKING_SPLITTING)); npcSection.set("idlePosition", entry.getValue().positions().get(NPCPosition.IDLE)); } configuration.save(configurationFile); @@ -106,6 +107,7 @@ public class NPCDataManager { locationMap.put(NPCPosition.WORKING_NETHERITE, section.getLocation("workingPositionNetherite")); locationMap.put(NPCPosition.WORKING_CRAFTING, section.getLocation("workingPositionCrafting")); locationMap.put(NPCPosition.WORKING_REPAIRABLE, section.getLocation("workingPositionRepairable")); + locationMap.put(NPCPosition.WORKING_SPLITTING, section.getLocation("workingPositionEnchantedBook")); locationMap.put(NPCPosition.IDLE, section.getLocation("idlePosition")); npcDataMap.put(UUID.fromString(configurationSectionKey), new NPCData(locationMap)); } diff --git a/src/main/java/net/knarcraft/blacksmithvisuals/property/NPCPosition.java b/src/main/java/net/knarcraft/blacksmithvisuals/property/NPCPosition.java index ed686d7..b6249de 100644 --- a/src/main/java/net/knarcraft/blacksmithvisuals/property/NPCPosition.java +++ b/src/main/java/net/knarcraft/blacksmithvisuals/property/NPCPosition.java @@ -33,6 +33,11 @@ public enum NPCPosition { * The position the NPC should be in while un-crafting items */ WORKING_CRAFTING("crafting-workstation", List.of(ScrapperTrait.class)), + + /** + * The position the NPC should be in while salvaging an enchanted book + */ + WORKING_SPLITTING("enchanted-book-workstation", List.of(ScrapperTrait.class)), ; private final String positionName; @@ -71,6 +76,7 @@ public enum NPCPosition { case CRAFTING_TABLE -> NPCPosition.WORKING_CRAFTING; case ANVIL -> NPCPosition.WORKING_REPAIRABLE; case SMITHING_TABLE -> NPCPosition.WORKING_NETHERITE; + case ENCHANTING_TABLE -> NPCPosition.WORKING_SPLITTING; default -> null; }; } diff --git a/src/main/java/net/knarcraft/blacksmithvisuals/util/SoundHelper.java b/src/main/java/net/knarcraft/blacksmithvisuals/util/SoundHelper.java index 4c1079c..f749e0e 100644 --- a/src/main/java/net/knarcraft/blacksmithvisuals/util/SoundHelper.java +++ b/src/main/java/net/knarcraft/blacksmithvisuals/util/SoundHelper.java @@ -25,15 +25,18 @@ public final class SoundHelper { public static void playSound(@NotNull Entity entity, @NotNull SoundData soundData) { // Don't play disabled sounds if (!soundData.enabled()) { + BlacksmithVisuals.debug("Skipping sound " + soundData.sound() + " as it's disabled"); return; } World world = entity.getLocation().getWorld(); if (world == null) { + BlacksmithVisuals.debug("Could not play sound, as world is null"); return; } int delay = Math.max(soundData.offsetTicks(), 0); + BlacksmithVisuals.debug("Playing sound " + soundData.sound() + " after " + delay + " ticks"); Bukkit.getScheduler().scheduleSyncDelayedTask(BlacksmithVisuals.getInstance(), () -> world.playSound(entity, soundData.sound(), soundData.soundCategory(), soundData.volume(), soundData.pitch()), delay); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 1dd17ca..66b70e1 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,3 +1,5 @@ +# Show debug messages in the console +debug: false blacksmith: animation: # Whether to simulate hitting an anvil or similar by animating the blacksmith's off-hand