From f3d6167d73d4d8250367f13ec64c95de6864413e Mon Sep 17 00:00:00 2001 From: CoderJoe Date: Tue, 10 Mar 2026 15:33:01 -0500 Subject: [PATCH] Add configurable logging setting to disable plugin info logs Adds a `logging` config option (default true) that controls whether info-level log messages are emitted. Warnings and errors always show regardless of this setting. --- run-server.sh | 2 ++ src/main/kotlin/com/coderjoe/atlas/Atlas.kt | 12 ++++++----- .../kotlin/com/coderjoe/atlas/AtlasConfig.kt | 20 +++++++++++++++++++ .../com/coderjoe/atlas/NexoIntegration.kt | 8 ++++---- .../com/coderjoe/atlas/ResourcePackManager.kt | 6 +++--- .../com/coderjoe/atlas/core/AtlasBlock.kt | 5 +++-- .../coderjoe/atlas/core/BlockPersistence.kt | 11 +++++----- .../com/coderjoe/atlas/core/BlockRegistry.kt | 7 ++++--- .../atlas/fluid/block/FluidContainer.kt | 7 ++++--- .../coderjoe/atlas/fluid/block/FluidPipe.kt | 7 ++++--- .../coderjoe/atlas/fluid/block/FluidPump.kt | 3 ++- .../coderjoe/atlas/power/block/PowerCable.kt | 3 ++- .../atlas/power/block/SmallBattery.kt | 3 ++- .../atlas/power/block/SmallSolarPanel.kt | 5 +++-- src/main/resources/config.yml | 3 +++ 15 files changed, 69 insertions(+), 33 deletions(-) create mode 100644 src/main/kotlin/com/coderjoe/atlas/AtlasConfig.kt diff --git a/run-server.sh b/run-server.sh index 25ec052..23600e8 100755 --- a/run-server.sh +++ b/run-server.sh @@ -76,6 +76,8 @@ cat > "$SERVER_DIR/plugins/Atlas/config.yml" << EOF # Atlas Plugin Configuration (auto-generated for testing) # Resource pack is disabled because Nexo handles resource pack generation and hosting +logging: false + resource-pack: enabled: false url: "" diff --git a/src/main/kotlin/com/coderjoe/atlas/Atlas.kt b/src/main/kotlin/com/coderjoe/atlas/Atlas.kt index 5cbaa7a..f889028 100644 --- a/src/main/kotlin/com/coderjoe/atlas/Atlas.kt +++ b/src/main/kotlin/com/coderjoe/atlas/Atlas.kt @@ -27,6 +27,8 @@ class Atlas : JavaPlugin() { dataFolder.mkdirs() } + AtlasConfig.load(this) + nexoIntegration = NexoIntegration(this) nexoIntegration.initialize() @@ -34,7 +36,7 @@ class Atlas : JavaPlugin() { resourcePackManager.load() if (resourcePackManager.isConfigured()) { - logger.info("Resource pack is configured and will be sent to players on join") + logger.atlasInfo("Resource pack is configured and will be sent to players on join") server.pluginManager.registerEvents(PlayerJoinListener(resourcePackManager), this) } @@ -76,7 +78,7 @@ class Atlas : JavaPlugin() { fluidBlockPersistence.save(fluidBlockRegistry) }, 6000L, 6000L) - logger.info("Atlas plugin enabled!") + logger.atlasInfo("Atlas plugin enabled!") } override fun onDisable() { @@ -101,7 +103,7 @@ class Atlas : JavaPlugin() { fluidBlockRegistry.stopAll() } - logger.info("Atlas plugin has been disabled!") + logger.atlasInfo("Atlas plugin has been disabled!") } fun initPowerSystem() { @@ -110,7 +112,7 @@ class Atlas : JavaPlugin() { powerBlockPersistence = PowerBlockPersistence(this) powerBlockPersistence.load(powerBlockRegistry) - logger.info("Power system initialized with ${PowerBlockFactory.getRegisteredBlockIds().size} block types") + logger.atlasInfo("Power system initialized with ${PowerBlockFactory.getRegisteredBlockIds().size} block types") } fun initFluidSystem() { @@ -119,7 +121,7 @@ class Atlas : JavaPlugin() { fluidBlockPersistence = FluidBlockPersistence(this) fluidBlockPersistence.load(fluidBlockRegistry) - logger.info("Fluid system initialized with ${FluidBlockFactory.getRegisteredBlockIds().size} block types") + logger.atlasInfo("Fluid system initialized with ${FluidBlockFactory.getRegisteredBlockIds().size} block types") } private fun powerDescriptors(): Map { diff --git a/src/main/kotlin/com/coderjoe/atlas/AtlasConfig.kt b/src/main/kotlin/com/coderjoe/atlas/AtlasConfig.kt new file mode 100644 index 0000000..a10ea54 --- /dev/null +++ b/src/main/kotlin/com/coderjoe/atlas/AtlasConfig.kt @@ -0,0 +1,20 @@ +package com.coderjoe.atlas + +import org.bukkit.plugin.java.JavaPlugin +import java.util.logging.Logger + +object AtlasConfig { + var loggingEnabled: Boolean = true + private set + + fun load(plugin: JavaPlugin) { + plugin.saveDefaultConfig() + loggingEnabled = plugin.config.getBoolean("logging", true) + } +} + +fun Logger.atlasInfo(message: String) { + if (AtlasConfig.loggingEnabled) { + info(message) + } +} diff --git a/src/main/kotlin/com/coderjoe/atlas/NexoIntegration.kt b/src/main/kotlin/com/coderjoe/atlas/NexoIntegration.kt index 0cbede7..751da9d 100644 --- a/src/main/kotlin/com/coderjoe/atlas/NexoIntegration.kt +++ b/src/main/kotlin/com/coderjoe/atlas/NexoIntegration.kt @@ -13,7 +13,7 @@ class NexoIntegration(private val plugin: JavaPlugin) { copyItemConfigurations() copyTextures() copyRecipes() - plugin.logger.info("Atlas Nexo integration initialized") + plugin.logger.atlasInfo("Atlas Nexo integration initialized") } private fun copyItemConfigurations() { @@ -29,7 +29,7 @@ class NexoIntegration(private val plugin: JavaPlugin) { if (sourceFile.exists()) { sourceFile.copyTo(targetFile, overwrite = true) sourceFile.delete() - plugin.logger.info("Copied Atlas block configurations to Nexo") + plugin.logger.atlasInfo("Copied Atlas block configurations to Nexo") } } @@ -50,7 +50,7 @@ class NexoIntegration(private val plugin: JavaPlugin) { if (sourceFile.exists()) { sourceFile.copyTo(textureFile, overwrite = true) sourceFile.delete() - plugin.logger.info("Copied ${fileName.removeSuffix(".png")} texture to Nexo") + plugin.logger.atlasInfo("Copied ${fileName.removeSuffix(".png")} texture to Nexo") } } } @@ -90,7 +90,7 @@ class NexoIntegration(private val plugin: JavaPlugin) { if (sourceFile.exists()) { sourceFile.copyTo(targetFile, overwrite = true) sourceFile.delete() - plugin.logger.info("Copied Atlas recipes to Nexo") + plugin.logger.atlasInfo("Copied Atlas recipes to Nexo") } } } diff --git a/src/main/kotlin/com/coderjoe/atlas/ResourcePackManager.kt b/src/main/kotlin/com/coderjoe/atlas/ResourcePackManager.kt index 6508fdd..4a5a607 100644 --- a/src/main/kotlin/com/coderjoe/atlas/ResourcePackManager.kt +++ b/src/main/kotlin/com/coderjoe/atlas/ResourcePackManager.kt @@ -21,7 +21,7 @@ class ResourcePackManager(private val plugin: JavaPlugin) { val enabled = config.getBoolean("resource-pack.enabled", false) if (!enabled) { - plugin.logger.info("Resource pack is disabled in config") + plugin.logger.atlasInfo("Resource pack is disabled in config") return } @@ -49,7 +49,7 @@ class ResourcePackManager(private val plugin: JavaPlugin) { promptMessage = Component.text(prompt) } - plugin.logger.info("Resource pack configured: $url") + plugin.logger.atlasInfo("Resource pack configured: $url") } catch (e: Exception) { plugin.logger.severe("Failed to configure resource pack: ${e.message}") } @@ -69,7 +69,7 @@ class ResourcePackManager(private val plugin: JavaPlugin) { player.sendResourcePacks(request) - plugin.logger.info("Sent resource pack to ${player.name}") + plugin.logger.atlasInfo("Sent resource pack to ${player.name}") } fun isConfigured(): Boolean = packInfo != null diff --git a/src/main/kotlin/com/coderjoe/atlas/core/AtlasBlock.kt b/src/main/kotlin/com/coderjoe/atlas/core/AtlasBlock.kt index ce22002..b5ff5af 100644 --- a/src/main/kotlin/com/coderjoe/atlas/core/AtlasBlock.kt +++ b/src/main/kotlin/com/coderjoe/atlas/core/AtlasBlock.kt @@ -1,6 +1,7 @@ package com.coderjoe.atlas.core import com.coderjoe.atlas.Atlas +import com.coderjoe.atlas.atlasInfo import com.nexomc.nexo.api.NexoBlocks import org.bukkit.Location import org.bukkit.Material @@ -60,12 +61,12 @@ abstract class AtlasBlock( } }, updateIntervalTicks, updateIntervalTicks) - plugin.logger.info("${this::class.simpleName} at ${location.blockX},${location.blockY},${location.blockZ} started") + plugin.logger.atlasInfo("${this::class.simpleName} at ${location.blockX},${location.blockY},${location.blockZ} started") } fun stop() { updateTask?.cancel() updateTask = null - plugin.logger.info("${this::class.simpleName} at ${location.blockX},${location.blockY},${location.blockZ} stopped") + plugin.logger.atlasInfo("${this::class.simpleName} at ${location.blockX},${location.blockY},${location.blockZ} stopped") } } diff --git a/src/main/kotlin/com/coderjoe/atlas/core/BlockPersistence.kt b/src/main/kotlin/com/coderjoe/atlas/core/BlockPersistence.kt index 48d23e5..9df85ed 100644 --- a/src/main/kotlin/com/coderjoe/atlas/core/BlockPersistence.kt +++ b/src/main/kotlin/com/coderjoe/atlas/core/BlockPersistence.kt @@ -1,5 +1,6 @@ package com.coderjoe.atlas.core +import com.coderjoe.atlas.atlasInfo import org.bukkit.Location import org.bukkit.block.BlockFace import org.bukkit.configuration.file.YamlConfiguration @@ -20,7 +21,7 @@ class BlockPersistence( val config = YamlConfiguration() val blocksWithIds = registry.getAllBlocksWithIds() - plugin.logger.info("Saving ${blocksWithIds.size} blocks to $fileName...") + plugin.logger.atlasInfo("Saving ${blocksWithIds.size} blocks to $fileName...") val blockDataList = mutableListOf>() @@ -44,7 +45,7 @@ class BlockPersistence( try { config.save(dataFile) - plugin.logger.info("Successfully saved ${blockDataList.size} blocks to $fileName") + plugin.logger.atlasInfo("Successfully saved ${blockDataList.size} blocks to $fileName") } catch (e: Exception) { plugin.logger.severe("Failed to save blocks to $fileName: ${e.message}") e.printStackTrace() @@ -53,14 +54,14 @@ class BlockPersistence( fun load(registry: BlockRegistry) { if (!dataFile.exists()) { - plugin.logger.info("No $fileName data file found, starting fresh") + plugin.logger.atlasInfo("No $fileName data file found, starting fresh") return } val config = YamlConfiguration.loadConfiguration(dataFile) val blockDataList = config.getMapList(yamlKey) - plugin.logger.info("Loading ${blockDataList.size} blocks from $fileName...") + plugin.logger.atlasInfo("Loading ${blockDataList.size} blocks from $fileName...") var loadedCount = 0 var failedCount = 0 @@ -104,6 +105,6 @@ class BlockPersistence( } } - plugin.logger.info("Loaded $loadedCount blocks from $fileName, $failedCount failed") + plugin.logger.atlasInfo("Loaded $loadedCount blocks from $fileName, $failedCount failed") } } diff --git a/src/main/kotlin/com/coderjoe/atlas/core/BlockRegistry.kt b/src/main/kotlin/com/coderjoe/atlas/core/BlockRegistry.kt index 9e9d836..b08dea9 100644 --- a/src/main/kotlin/com/coderjoe/atlas/core/BlockRegistry.kt +++ b/src/main/kotlin/com/coderjoe/atlas/core/BlockRegistry.kt @@ -1,5 +1,6 @@ package com.coderjoe.atlas.core +import com.coderjoe.atlas.atlasInfo import org.bukkit.Location import org.bukkit.block.BlockFace import org.bukkit.plugin.java.JavaPlugin @@ -21,7 +22,7 @@ open class BlockRegistry(protected val plugin: JavaPlugin) { blocks[key] = block blockIds[key] = blockId block.start() - plugin.logger.info("Registered ${block::class.simpleName} at ${block.location.blockX},${block.location.blockY},${block.location.blockZ}") + plugin.logger.atlasInfo("Registered ${block::class.simpleName} at ${block.location.blockX},${block.location.blockY},${block.location.blockZ}") } fun unregister(location: Location): T? { @@ -30,7 +31,7 @@ open class BlockRegistry(protected val plugin: JavaPlugin) { blockIds.remove(key) block?.stop() if (block != null) { - plugin.logger.info("Unregistered ${block::class.simpleName} at ${location.blockX},${location.blockY},${location.blockZ}") + plugin.logger.atlasInfo("Unregistered ${block::class.simpleName} at ${location.blockX},${location.blockY},${location.blockZ}") } return block } @@ -71,7 +72,7 @@ open class BlockRegistry(protected val plugin: JavaPlugin) { } fun stopAll() { - plugin.logger.info("Stopping ${blocks.size} blocks...") + plugin.logger.atlasInfo("Stopping ${blocks.size} blocks...") blocks.values.forEach { it.stop() } blocks.clear() } diff --git a/src/main/kotlin/com/coderjoe/atlas/fluid/block/FluidContainer.kt b/src/main/kotlin/com/coderjoe/atlas/fluid/block/FluidContainer.kt index 6cce10b..67d8df8 100644 --- a/src/main/kotlin/com/coderjoe/atlas/fluid/block/FluidContainer.kt +++ b/src/main/kotlin/com/coderjoe/atlas/fluid/block/FluidContainer.kt @@ -1,5 +1,6 @@ package com.coderjoe.atlas.fluid.block +import com.coderjoe.atlas.atlasInfo import com.coderjoe.atlas.core.BlockDescriptor import com.coderjoe.atlas.core.PlacementType import com.coderjoe.atlas.fluid.FluidBlock @@ -133,7 +134,7 @@ class FluidContainer(location: Location, override val facing: BlockFace) : Fluid if (source.canRemoveFluidFrom(facing)) { val fluid = source.removeFluid() if (storeFluid(fluid)) { - plugin.logger.info("FluidContainer at ${location.blockX},${location.blockY},${location.blockZ} pulled ${fluid.name} from FluidPump") + plugin.logger.atlasInfo("FluidContainer at ${location.blockX},${location.blockY},${location.blockZ} pulled ${fluid.name} from FluidPump") } else { source.storeFluid(fluid) } @@ -143,7 +144,7 @@ class FluidContainer(location: Location, override val facing: BlockFace) : Fluid if (source.hasFluid()) { val fluid = source.removeFluid() if (storeFluid(fluid)) { - plugin.logger.info("FluidContainer at ${location.blockX},${location.blockY},${location.blockZ} pulled ${fluid.name} from FluidPipe") + plugin.logger.atlasInfo("FluidContainer at ${location.blockX},${location.blockY},${location.blockZ} pulled ${fluid.name} from FluidPipe") } else { source.storeFluid(fluid) } @@ -153,7 +154,7 @@ class FluidContainer(location: Location, override val facing: BlockFace) : Fluid if (source.canRemoveFluidFrom(facing)) { val fluid = source.removeFluid() if (storeFluid(fluid)) { - plugin.logger.info("FluidContainer at ${location.blockX},${location.blockY},${location.blockZ} pulled ${fluid.name} from FluidContainer") + plugin.logger.atlasInfo("FluidContainer at ${location.blockX},${location.blockY},${location.blockZ} pulled ${fluid.name} from FluidContainer") } else { source.storeFluid(fluid) } diff --git a/src/main/kotlin/com/coderjoe/atlas/fluid/block/FluidPipe.kt b/src/main/kotlin/com/coderjoe/atlas/fluid/block/FluidPipe.kt index 43860c2..92a8b4a 100644 --- a/src/main/kotlin/com/coderjoe/atlas/fluid/block/FluidPipe.kt +++ b/src/main/kotlin/com/coderjoe/atlas/fluid/block/FluidPipe.kt @@ -1,5 +1,6 @@ package com.coderjoe.atlas.fluid.block +import com.coderjoe.atlas.atlasInfo import com.coderjoe.atlas.core.BlockDescriptor import com.coderjoe.atlas.core.PlacementType import com.coderjoe.atlas.fluid.FluidBlock @@ -77,21 +78,21 @@ class FluidPipe(location: Location, override val facing: BlockFace) : FluidBlock if (source.canRemoveFluidFrom(facing)) { val fluid = source.removeFluid() storeFluid(fluid) - plugin.logger.info("FluidPipe at ${location.blockX},${location.blockY},${location.blockZ} pulled ${fluid.name} from FluidPump") + plugin.logger.atlasInfo("FluidPipe at ${location.blockX},${location.blockY},${location.blockZ} pulled ${fluid.name} from FluidPump") } } is FluidPipe -> { if (source.hasFluid()) { val fluid = source.removeFluid() storeFluid(fluid) - plugin.logger.info("FluidPipe at ${location.blockX},${location.blockY},${location.blockZ} pulled ${fluid.name} from FluidPipe") + plugin.logger.atlasInfo("FluidPipe at ${location.blockX},${location.blockY},${location.blockZ} pulled ${fluid.name} from FluidPipe") } } is FluidContainer -> { if (source.canRemoveFluidFrom(facing)) { val fluid = source.removeFluid() storeFluid(fluid) - plugin.logger.info("FluidPipe at ${location.blockX},${location.blockY},${location.blockZ} pulled ${fluid.name} from FluidContainer") + plugin.logger.atlasInfo("FluidPipe at ${location.blockX},${location.blockY},${location.blockZ} pulled ${fluid.name} from FluidContainer") } } } diff --git a/src/main/kotlin/com/coderjoe/atlas/fluid/block/FluidPump.kt b/src/main/kotlin/com/coderjoe/atlas/fluid/block/FluidPump.kt index 386b6ab..f122075 100644 --- a/src/main/kotlin/com/coderjoe/atlas/fluid/block/FluidPump.kt +++ b/src/main/kotlin/com/coderjoe/atlas/fluid/block/FluidPump.kt @@ -1,5 +1,6 @@ package com.coderjoe.atlas.fluid.block +import com.coderjoe.atlas.atlasInfo import com.coderjoe.atlas.core.BlockDescriptor import com.coderjoe.atlas.core.PlacementType import com.coderjoe.atlas.fluid.FluidBlock @@ -138,6 +139,6 @@ class FluidPump(location: Location) : FluidBlock(location) { storeFluid(fluidType) cauldronFace = foundFace pumpStatus = PumpStatus.EXTRACTING - plugin.logger.info("FluidPump at ${location.blockX},${location.blockY},${location.blockZ} extracted ${fluidType.name} from $foundFace") + plugin.logger.atlasInfo("FluidPump at ${location.blockX},${location.blockY},${location.blockZ} extracted ${fluidType.name} from $foundFace") } } diff --git a/src/main/kotlin/com/coderjoe/atlas/power/block/PowerCable.kt b/src/main/kotlin/com/coderjoe/atlas/power/block/PowerCable.kt index 2af5b8c..0003dba 100644 --- a/src/main/kotlin/com/coderjoe/atlas/power/block/PowerCable.kt +++ b/src/main/kotlin/com/coderjoe/atlas/power/block/PowerCable.kt @@ -1,5 +1,6 @@ package com.coderjoe.atlas.power.block +import com.coderjoe.atlas.atlasInfo import com.coderjoe.atlas.core.BlockDescriptor import com.coderjoe.atlas.core.PlacementType import com.coderjoe.atlas.power.PowerBlock @@ -64,7 +65,7 @@ class PowerCable(location: Location, override val facing: BlockFace) : PowerBloc val pulled = source.removePower(1) if (pulled > 0) { addPower(pulled) - plugin.logger.info("PowerCable at ${location.blockX},${location.blockY},${location.blockZ} pulled $pulled power from ${source::class.simpleName} (now $currentPower/$maxStorage)") + plugin.logger.atlasInfo("PowerCable at ${location.blockX},${location.blockY},${location.blockZ} pulled $pulled power from ${source::class.simpleName} (now $currentPower/$maxStorage)") } } } diff --git a/src/main/kotlin/com/coderjoe/atlas/power/block/SmallBattery.kt b/src/main/kotlin/com/coderjoe/atlas/power/block/SmallBattery.kt index 7706b8a..54ec29f 100644 --- a/src/main/kotlin/com/coderjoe/atlas/power/block/SmallBattery.kt +++ b/src/main/kotlin/com/coderjoe/atlas/power/block/SmallBattery.kt @@ -1,5 +1,6 @@ package com.coderjoe.atlas.power.block +import com.coderjoe.atlas.atlasInfo import com.coderjoe.atlas.core.BlockDescriptor import com.coderjoe.atlas.core.PlacementType import com.coderjoe.atlas.power.PowerBlock @@ -60,7 +61,7 @@ class SmallBattery(location: Location, facing: BlockFace) : PowerBlock(location, val pulled = source.removePower(1) if (pulled > 0) { addPower(pulled) - plugin.logger.info("SmallBattery at ${location.blockX},${location.blockY},${location.blockZ} pulled $pulled power from ${source::class.simpleName} (now $currentPower/$maxStorage)") + plugin.logger.atlasInfo("SmallBattery at ${location.blockX},${location.blockY},${location.blockZ} pulled $pulled power from ${source::class.simpleName} (now $currentPower/$maxStorage)") } } } diff --git a/src/main/kotlin/com/coderjoe/atlas/power/block/SmallSolarPanel.kt b/src/main/kotlin/com/coderjoe/atlas/power/block/SmallSolarPanel.kt index 4d878f3..c5ec00a 100644 --- a/src/main/kotlin/com/coderjoe/atlas/power/block/SmallSolarPanel.kt +++ b/src/main/kotlin/com/coderjoe/atlas/power/block/SmallSolarPanel.kt @@ -1,5 +1,6 @@ package com.coderjoe.atlas.power.block +import com.coderjoe.atlas.atlasInfo import com.coderjoe.atlas.core.BlockDescriptor import com.coderjoe.atlas.core.PlacementType import com.coderjoe.atlas.power.PowerBlock @@ -39,10 +40,10 @@ class SmallSolarPanel(location: Location): PowerBlock(location, maxStorage = 1) if (isDaytime) { val generated = addPower(1) if (generated > 0) { - plugin.logger.info("SmallSolarPanel at ${location.blockX},${location.blockY},${location.blockZ} generated $generated power (now $currentPower/$maxStorage)") + plugin.logger.atlasInfo("SmallSolarPanel at ${location.blockX},${location.blockY},${location.blockZ} generated $generated power (now $currentPower/$maxStorage)") } } else { - plugin.logger.info("SmallSolarPanel at ${location.blockX},${location.blockY},${location.blockZ} is not generating power because it is not daytime.") + plugin.logger.atlasInfo("SmallSolarPanel at ${location.blockX},${location.blockY},${location.blockZ} is not generating power because it is not daytime.") } // TODO: Implement power transfer to connected blocks diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index ec7347f..93a8429 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,5 +1,8 @@ # Atlas Plugin Configuration +# Enable or disable plugin logging (warnings and errors are always shown) +logging: false + resource-pack: # Enable or disable resource pack distribution enabled: false