Adds debug output and a new working position
All checks were successful
KnarCraft/BlacksmithVisuals/pipeline/head This commit looks good

This commit is contained in:
Kristian Knarvik 2024-11-27 12:20:01 +01:00
parent 9b04dd042e
commit b094d34c62
5 changed files with 22 additions and 1 deletions

View File

@ -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 <p>The debug message to log</p>
*/
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);
}
}
/**

View File

@ -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));
}

View File

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

View File

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

View File

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