diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..a851c94 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +version: 2 +updates: + - package-ecosystem: "maven" + directory: "/" + schedule: + interval: "weekly" + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ea12ccd..8353b5f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,13 +11,13 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Set up JDK 21 - uses: actions/setup-java@v4 + uses: actions/setup-java@v5 with: java-version: '21' - distribution: 'temurin' + distribution: 'corretto' cache: maven - name: Build and verify diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml new file mode 100644 index 0000000..90b521f --- /dev/null +++ b/.github/workflows/code-coverage.yml @@ -0,0 +1,30 @@ +name: Code Coverage + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + coverage: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v6 + + - name: Set up JDK 21 + uses: actions/setup-java@v5 + with: + java-version: '21' + distribution: 'corretto' + cache: maven + + - name: Run tests with coverage + run: mvn test jacoco:report -B + + - name: Upload coverage report + uses: actions/upload-artifact@v6 + with: + name: coverage-report + path: target/site/jacoco/ \ No newline at end of file diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml new file mode 100644 index 0000000..1bcab4d --- /dev/null +++ b/.github/workflows/code-quality.yml @@ -0,0 +1,24 @@ +name: Code Quality + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + formatting: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v6 + + - name: Set up JDK 21 + uses: actions/setup-java@v5 + with: + java-version: '21' + distribution: 'corretto' + cache: maven + + - name: Check formatting + run: mvn spotless:check -B \ No newline at end of file diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..ef75120 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,5 @@ +# Atlas Project Instructions + +## Code Style +- Always use explicit imports — never use wildcard imports (e.g., `import com.example.Foo`, not `import com.example.*`) +- No line should exceed 140 characters in length diff --git a/pom.xml b/pom.xml index f01d259..4572842 100644 --- a/pom.xml +++ b/pom.xml @@ -14,6 +14,7 @@ official 2.1.10 21 + 0.8.14 @@ -99,6 +100,68 @@ + + com.diffplug.spotless + spotless-maven-plugin + 3.2.1 + + + + 1.0.1 + + + + + 1.19.1 + + + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + net/sf/jsqlparser/** + + + + + prepare-agent + + prepare-agent + + + + report + test + + report + + + + jacoco-check + + check + + + + + PACKAGE + + + LINE + COVEREDRATIO + 0.0 + + + + + + + + diff --git a/src/main/kotlin/com/coderjoe/atlas/Atlas.kt b/src/main/kotlin/com/coderjoe/atlas/Atlas.kt index 89e54a5..fb38c0a 100644 --- a/src/main/kotlin/com/coderjoe/atlas/Atlas.kt +++ b/src/main/kotlin/com/coderjoe/atlas/Atlas.kt @@ -2,12 +2,12 @@ package com.coderjoe.atlas import com.coderjoe.atlas.core.AtlasBlockListener import com.coderjoe.atlas.core.BlockSystem -import com.coderjoe.atlas.guide.GuideBook -import com.coderjoe.atlas.guide.GuideBookListener import com.coderjoe.atlas.fluid.FluidBlockDialog import com.coderjoe.atlas.fluid.FluidBlockFactory import com.coderjoe.atlas.fluid.FluidBlockPersistence import com.coderjoe.atlas.fluid.FluidBlockRegistry +import com.coderjoe.atlas.guide.GuideBook +import com.coderjoe.atlas.guide.GuideBookListener import com.coderjoe.atlas.power.PowerBlockDialog import com.coderjoe.atlas.power.PowerBlockFactory import com.coderjoe.atlas.power.PowerBlockPersistence @@ -57,39 +57,46 @@ class Atlas : JavaPlugin() { initTransportSystem() // Register unified listener - val powerSystem = BlockSystem( - name = "power", - registry = powerBlockRegistry, - factory = PowerBlockFactory, - descriptors = powerDescriptors(), - showDialog = { player, block -> - PowerBlockDialog.showPowerDialog(player, block as com.coderjoe.atlas.power.PowerBlock, powerBlockRegistry) - } - ) - - val fluidSystem = BlockSystem( - name = "fluid", - registry = fluidBlockRegistry, - factory = FluidBlockFactory, - descriptors = fluidDescriptors(), - showDialog = { player, block -> - FluidBlockDialog.showFluidDialog(player, block as com.coderjoe.atlas.fluid.FluidBlock, fluidBlockRegistry) - } - ) - - val transportSystem = BlockSystem( - name = "transport", - registry = transportBlockRegistry, - factory = TransportBlockFactory, - descriptors = transportDescriptors(), - showDialog = { player, block -> - TransportBlockDialog.showTransportDialog(player, block as com.coderjoe.atlas.transport.TransportBlock, transportBlockRegistry) - } - ) + val powerSystem = + BlockSystem( + name = "power", + registry = powerBlockRegistry, + factory = PowerBlockFactory, + descriptors = powerDescriptors(), + showDialog = { player, block -> + PowerBlockDialog.showPowerDialog(player, block as com.coderjoe.atlas.power.PowerBlock, powerBlockRegistry) + }, + ) + + val fluidSystem = + BlockSystem( + name = "fluid", + registry = fluidBlockRegistry, + factory = FluidBlockFactory, + descriptors = fluidDescriptors(), + showDialog = { player, block -> + FluidBlockDialog.showFluidDialog(player, block as com.coderjoe.atlas.fluid.FluidBlock, fluidBlockRegistry) + }, + ) + + val transportSystem = + BlockSystem( + name = "transport", + registry = transportBlockRegistry, + factory = TransportBlockFactory, + descriptors = transportDescriptors(), + showDialog = { player, block -> + TransportBlockDialog.showTransportDialog( + player, + block as com.coderjoe.atlas.transport.TransportBlock, + transportBlockRegistry, + ) + }, + ) server.pluginManager.registerEvents( AtlasBlockListener(this, listOf(powerSystem, fluidSystem, transportSystem)), - this + this, ) val guideBookListener = GuideBookListener(this) @@ -97,11 +104,16 @@ class Atlas : JavaPlugin() { server.addRecipe(GuideBook.createRecipe(this)) // Auto-save every 5 minutes (6000 ticks) - autoSaveTask = server.scheduler.runTaskTimer(this, Runnable { - powerBlockPersistence.save(powerBlockRegistry) - fluidBlockPersistence.save(fluidBlockRegistry) - transportBlockPersistence.save(transportBlockRegistry) - }, 6000L, 6000L) + autoSaveTask = + server.scheduler.runTaskTimer( + this, + Runnable { + powerBlockPersistence.save(powerBlockRegistry) + fluidBlockPersistence.save(fluidBlockRegistry) + transportBlockPersistence.save(transportBlockRegistry) + }, + 6000L, 6000L, + ) logger.atlasInfo("Atlas plugin enabled!") } @@ -169,7 +181,7 @@ class Atlas : JavaPlugin() { private fun transportDescriptors(): Map { return listOf( - com.coderjoe.atlas.transport.block.ConveyorBelt.descriptor + com.coderjoe.atlas.transport.block.ConveyorBelt.descriptor, ).associateBy { it.baseBlockId } } @@ -184,7 +196,7 @@ class Atlas : JavaPlugin() { com.coderjoe.atlas.power.block.MultiPowerCable.descriptor, com.coderjoe.atlas.power.block.CobblestoneFactory.descriptor, com.coderjoe.atlas.power.block.ObsidianFactory.descriptor, - com.coderjoe.atlas.power.block.PowerMerger.descriptor + com.coderjoe.atlas.power.block.PowerMerger.descriptor, ).associateBy { it.baseBlockId } } @@ -193,7 +205,7 @@ class Atlas : JavaPlugin() { com.coderjoe.atlas.fluid.block.FluidPump.descriptor, com.coderjoe.atlas.fluid.block.FluidPipe.descriptor, com.coderjoe.atlas.fluid.block.FluidContainer.descriptor, - com.coderjoe.atlas.fluid.block.FluidMerger.descriptor + com.coderjoe.atlas.fluid.block.FluidMerger.descriptor, ).associateBy { it.baseBlockId } } } diff --git a/src/main/kotlin/com/coderjoe/atlas/NexoIntegration.kt b/src/main/kotlin/com/coderjoe/atlas/NexoIntegration.kt index 524cc1d..248a159 100644 --- a/src/main/kotlin/com/coderjoe/atlas/NexoIntegration.kt +++ b/src/main/kotlin/com/coderjoe/atlas/NexoIntegration.kt @@ -57,7 +57,10 @@ class NexoIntegration(private val plugin: JavaPlugin) { } } - private fun discoverResources(prefix: String, suffix: String): List { + private fun discoverResources( + prefix: String, + suffix: String, + ): List { val url = javaClass.classLoader.getResource(prefix) ?: return emptyList() return when (url.protocol) { diff --git a/src/main/kotlin/com/coderjoe/atlas/PlayerJoinListener.kt b/src/main/kotlin/com/coderjoe/atlas/PlayerJoinListener.kt index bd1d17c..8e20b40 100644 --- a/src/main/kotlin/com/coderjoe/atlas/PlayerJoinListener.kt +++ b/src/main/kotlin/com/coderjoe/atlas/PlayerJoinListener.kt @@ -5,9 +5,8 @@ import org.bukkit.event.Listener import org.bukkit.event.player.PlayerJoinEvent class PlayerJoinListener( - private val resourcePackManager: ResourcePackManager + private val resourcePackManager: ResourcePackManager, ) : Listener { - @EventHandler fun onPlayerJoin(event: PlayerJoinEvent) { val player = event.player diff --git a/src/main/kotlin/com/coderjoe/atlas/ResourcePackManager.kt b/src/main/kotlin/com/coderjoe/atlas/ResourcePackManager.kt index 4a5a607..b4edf7a 100644 --- a/src/main/kotlin/com/coderjoe/atlas/ResourcePackManager.kt +++ b/src/main/kotlin/com/coderjoe/atlas/ResourcePackManager.kt @@ -3,14 +3,12 @@ package com.coderjoe.atlas import net.kyori.adventure.resource.ResourcePackInfo import net.kyori.adventure.resource.ResourcePackRequest import net.kyori.adventure.text.Component -import net.kyori.adventure.text.format.NamedTextColor import org.bukkit.entity.Player import org.bukkit.plugin.java.JavaPlugin import java.net.URI import java.util.UUID class ResourcePackManager(private val plugin: JavaPlugin) { - private var packInfo: ResourcePackInfo? = null private var isRequired: Boolean = false private var promptMessage: Component? = null @@ -39,11 +37,12 @@ class ResourcePackManager(private val plugin: JavaPlugin) { val packId = UUID.nameUUIDFromBytes(url.toByteArray()) try { - packInfo = ResourcePackInfo.resourcePackInfo() - .uri(URI.create(url)) - .hash(hash) - .id(packId) - .build() + packInfo = + ResourcePackInfo.resourcePackInfo() + .uri(URI.create(url)) + .hash(hash) + .id(packId) + .build() if (prompt.isNotBlank()) { promptMessage = Component.text(prompt) @@ -58,14 +57,15 @@ class ResourcePackManager(private val plugin: JavaPlugin) { fun sendToPlayer(player: Player) { val info = packInfo ?: return - val request = ResourcePackRequest.resourcePackRequest() - .packs(info) - .required(isRequired) - .replace(true) - .apply { - promptMessage?.let { prompt(it) } - } - .build() + val request = + ResourcePackRequest.resourcePackRequest() + .packs(info) + .required(isRequired) + .replace(true) + .apply { + promptMessage?.let { prompt(it) } + } + .build() player.sendResourcePacks(request) diff --git a/src/main/kotlin/com/coderjoe/atlas/core/AtlasBlock.kt b/src/main/kotlin/com/coderjoe/atlas/core/AtlasBlock.kt index b5ff5af..0370ee9 100644 --- a/src/main/kotlin/com/coderjoe/atlas/core/AtlasBlock.kt +++ b/src/main/kotlin/com/coderjoe/atlas/core/AtlasBlock.kt @@ -10,7 +10,7 @@ import org.bukkit.plugin.java.JavaPlugin import org.bukkit.scheduler.BukkitTask abstract class AtlasBlock( - val location: Location + val location: Location, ) { private var updateTask: BukkitTask? = null protected val plugin: JavaPlugin get() = testPlugin ?: JavaPlugin.getPlugin(Atlas::class.java) @@ -23,7 +23,9 @@ abstract class AtlasBlock( } protected abstract fun blockUpdate() + abstract fun getVisualStateBlockId(): String + abstract fun getRegistry(): BlockRegistry<*> open val facing: BlockFace get() = BlockFace.SELF @@ -48,18 +50,30 @@ abstract class AtlasBlock( fun start() { currentVisualState = NexoBlocks.customBlockMechanic(location.block)?.itemID - plugin.server.scheduler.runTask(plugin, Runnable { - updateVisualState() - }) - - updateTask = plugin.server.scheduler.runTaskTimer(plugin, Runnable { - try { - blockUpdate() + plugin.server.scheduler.runTask( + plugin, + Runnable { updateVisualState() - } catch (e: Exception) { - plugin.logger.warning("Error in block tick at ${location.blockX},${location.blockY},${location.blockZ}: ${e.message}") - } - }, updateIntervalTicks, updateIntervalTicks) + }, + ) + + updateTask = + plugin.server.scheduler.runTaskTimer( + plugin, + Runnable { + try { + blockUpdate() + updateVisualState() + } catch (e: Exception) { + plugin.logger.warning( + """ + Error in block tick at ${'$'}{location.blockX},${'$'}{location.blockY},${'$'}{location.blockZ}: ${'$'}{e.message} + """.trimIndent(), + ) + } + }, + updateIntervalTicks, updateIntervalTicks, + ) plugin.logger.atlasInfo("${this::class.simpleName} at ${location.blockX},${location.blockY},${location.blockZ} started") } diff --git a/src/main/kotlin/com/coderjoe/atlas/core/AtlasBlockDialog.kt b/src/main/kotlin/com/coderjoe/atlas/core/AtlasBlockDialog.kt index c4d3ece..43e1942 100644 --- a/src/main/kotlin/com/coderjoe/atlas/core/AtlasBlockDialog.kt +++ b/src/main/kotlin/com/coderjoe/atlas/core/AtlasBlockDialog.kt @@ -23,7 +23,7 @@ object AtlasBlockDialog { player: Player, block: AtlasBlock, registry: BlockRegistry<*>, - renderDialog: (Player, AtlasBlock, onClose: (Player) -> Unit) -> Unit + renderDialog: (Player, AtlasBlock, onClose: (Player) -> Unit) -> Unit, ) { activeDialogs.remove(player.uniqueId)?.cancel() @@ -31,21 +31,27 @@ object AtlasBlockDialog { renderDialog(player, block, onClose) - val task = plugin.server.scheduler.runTaskTimer(plugin, Runnable { - if (!player.isOnline) { - activeDialogs.remove(player.uniqueId)?.cancel() - return@Runnable - } - if (player.location.distance(block.location) > 10) { - activeDialogs.remove(player.uniqueId)?.cancel() - return@Runnable - } - if (registry.getBlock(block.location) == null) { - activeDialogs.remove(player.uniqueId)?.cancel() - return@Runnable - } - renderDialog(player, block, onClose) - }, 10L, 10L) + val task = + plugin.server.scheduler.runTaskTimer( + plugin, + Runnable { + if (!player.isOnline) { + activeDialogs.remove(player.uniqueId)?.cancel() + return@Runnable + } + if (player.location.distance(block.location) > 10) { + activeDialogs.remove(player.uniqueId)?.cancel() + return@Runnable + } + if (registry.getBlock(block.location) == null) { + activeDialogs.remove(player.uniqueId)?.cancel() + return@Runnable + } + renderDialog(player, block, onClose) + }, + 10L, + 10L, + ) activeDialogs[player.uniqueId] = task } diff --git a/src/main/kotlin/com/coderjoe/atlas/core/AtlasBlockListener.kt b/src/main/kotlin/com/coderjoe/atlas/core/AtlasBlockListener.kt index 356e488..dd1791a 100644 --- a/src/main/kotlin/com/coderjoe/atlas/core/AtlasBlockListener.kt +++ b/src/main/kotlin/com/coderjoe/atlas/core/AtlasBlockListener.kt @@ -14,9 +14,8 @@ import org.bukkit.plugin.java.JavaPlugin class AtlasBlockListener( private val plugin: JavaPlugin, - private val systems: List> + private val systems: List>, ) : Listener { - @EventHandler fun onBlockPlace(event: BlockPlaceEvent) { val location = event.block.location @@ -47,37 +46,44 @@ class AtlasBlockListener( event: BlockPlaceEvent, system: BlockSystem<*>, descriptor: BlockDescriptor, - blockId: String + blockId: String, ) { when (descriptor.placementType) { PlacementType.SIMPLE -> { val location = event.block.location.clone() - val facing = if (descriptor.directionalVariants.isEmpty()) { - getPlayerFacing(event) - } else { - BlockFace.SELF - } + val facing = + if (descriptor.directionalVariants.isEmpty()) { + getPlayerFacing(event) + } else { + BlockFace.SELF + } createAndRegister(system, blockId, location, facing) } PlacementType.DIRECTIONAL -> { val facing = getDirectionalFacing(event, descriptor) val variantId = descriptor.directionalVariants[facing] ?: return val location = event.block.location.clone() - plugin.server.scheduler.runTask(plugin, Runnable { - location.block.setType(Material.AIR, false) - NexoBlocks.place(variantId, location) - createAndRegister(system, variantId, location, facing) - }) + plugin.server.scheduler.runTask( + plugin, + Runnable { + location.block.setType(Material.AIR, false) + NexoBlocks.place(variantId, location) + createAndRegister(system, variantId, location, facing) + }, + ) } PlacementType.DIRECTIONAL_OPPOSITE -> { val facing = getDirectionalFacing(event, descriptor, opposite = true) val variantId = descriptor.directionalVariants[facing] ?: blockId val location = event.block.location.clone() - plugin.server.scheduler.runTask(plugin, Runnable { - location.block.setType(Material.AIR, false) - NexoBlocks.place(variantId, location) - createAndRegister(system, variantId, location, facing) - }) + plugin.server.scheduler.runTask( + plugin, + Runnable { + location.block.setType(Material.AIR, false) + NexoBlocks.place(variantId, location) + createAndRegister(system, variantId, location, facing) + }, + ) } } } @@ -87,7 +93,7 @@ class AtlasBlockListener( system: BlockSystem<*>, blockId: String, location: org.bukkit.Location, - facing: BlockFace + facing: BlockFace, ) { val factory = system.factory as BlockFactory val registry = system.registry as BlockRegistry @@ -138,7 +144,10 @@ class AtlasBlockListener( } } - private fun resolveFacingFromVariant(descriptor: BlockDescriptor, blockId: String): BlockFace { + private fun resolveFacingFromVariant( + descriptor: BlockDescriptor, + blockId: String, + ): BlockFace { for ((face, id) in descriptor.directionalVariants) { if (id == blockId) return face } @@ -146,7 +155,11 @@ class AtlasBlockListener( } companion object { - fun getDirectionalFacing(event: BlockPlaceEvent, descriptor: BlockDescriptor, opposite: Boolean = false): BlockFace { + fun getDirectionalFacing( + event: BlockPlaceEvent, + descriptor: BlockDescriptor, + opposite: Boolean = false, + ): BlockFace { val raw = getPlayerFacing(event) val facing = if (opposite) raw.oppositeFace else raw if (descriptor.directionalVariants.containsKey(facing)) return facing diff --git a/src/main/kotlin/com/coderjoe/atlas/core/BlockDescriptor.kt b/src/main/kotlin/com/coderjoe/atlas/core/BlockDescriptor.kt index 11c4921..2fb2d45 100644 --- a/src/main/kotlin/com/coderjoe/atlas/core/BlockDescriptor.kt +++ b/src/main/kotlin/com/coderjoe/atlas/core/BlockDescriptor.kt @@ -6,7 +6,7 @@ import org.bukkit.block.BlockFace enum class PlacementType { SIMPLE, DIRECTIONAL, - DIRECTIONAL_OPPOSITE + DIRECTIONAL_OPPOSITE, } data class BlockDescriptor( @@ -16,5 +16,5 @@ data class BlockDescriptor( val placementType: PlacementType, val directionalVariants: Map, val allRegistrableIds: List, - val constructor: (Location, BlockFace) -> AtlasBlock + val constructor: (Location, BlockFace) -> AtlasBlock, ) diff --git a/src/main/kotlin/com/coderjoe/atlas/core/BlockFactory.kt b/src/main/kotlin/com/coderjoe/atlas/core/BlockFactory.kt index a53e351..f45d9bd 100644 --- a/src/main/kotlin/com/coderjoe/atlas/core/BlockFactory.kt +++ b/src/main/kotlin/com/coderjoe/atlas/core/BlockFactory.kt @@ -6,11 +6,18 @@ import org.bukkit.block.BlockFace open class BlockFactory { private val blockConstructors = mutableMapOf T>() - fun register(blockId: String, constructor: (Location, BlockFace) -> T) { + fun register( + blockId: String, + constructor: (Location, BlockFace) -> T, + ) { blockConstructors[blockId] = constructor } - fun create(blockId: String, location: Location, facing: BlockFace = BlockFace.SELF): T? { + fun create( + blockId: String, + location: Location, + facing: BlockFace = BlockFace.SELF, + ): T? { return blockConstructors[blockId]?.invoke(location, facing) } diff --git a/src/main/kotlin/com/coderjoe/atlas/core/BlockPersistence.kt b/src/main/kotlin/com/coderjoe/atlas/core/BlockPersistence.kt index 9df85ed..2879dfe 100644 --- a/src/main/kotlin/com/coderjoe/atlas/core/BlockPersistence.kt +++ b/src/main/kotlin/com/coderjoe/atlas/core/BlockPersistence.kt @@ -13,7 +13,7 @@ class BlockPersistence( private val yamlKey: String, private val factory: BlockFactory, private val serialize: (T, String) -> Map, - private val restore: (T, Map) -> Unit + private val restore: (T, Map) -> Unit, ) { private val dataFile = File(plugin.dataFolder, fileName) @@ -26,13 +26,14 @@ class BlockPersistence( val blockDataList = mutableListOf>() for ((block, blockId) in blocksWithIds) { - val map = mutableMapOf( - "blockId" to blockId, - "world" to (block.location.world?.name ?: "world"), - "x" to block.location.blockX, - "y" to block.location.blockY, - "z" to block.location.blockZ - ) + val map = + mutableMapOf( + "blockId" to blockId, + "world" to (block.location.world?.name ?: "world"), + "x" to block.location.blockX, + "y" to block.location.blockY, + "z" to block.location.blockZ, + ) val facing = block.facing if (facing != BlockFace.SELF) { map["facing"] = facing.name @@ -83,11 +84,16 @@ class BlockPersistence( } val location = Location(world, x.toDouble(), y.toDouble(), z.toDouble()) - val facing = if (facingStr != null) { - try { BlockFace.valueOf(facingStr) } catch (_: Exception) { BlockFace.SELF } - } else { - BlockFace.SELF - } + val facing = + if (facingStr != null) { + try { + BlockFace.valueOf(facingStr) + } catch (_: Exception) { + BlockFace.SELF + } + } else { + BlockFace.SELF + } val block = factory.create(blockId, location, facing) if (block != null) { diff --git a/src/main/kotlin/com/coderjoe/atlas/core/BlockRegistry.kt b/src/main/kotlin/com/coderjoe/atlas/core/BlockRegistry.kt index b08dea9..52f8b39 100644 --- a/src/main/kotlin/com/coderjoe/atlas/core/BlockRegistry.kt +++ b/src/main/kotlin/com/coderjoe/atlas/core/BlockRegistry.kt @@ -17,12 +17,19 @@ open class BlockRegistry(protected val plugin: JavaPlugin) { } } - fun register(block: T, blockId: String) { + fun register( + block: T, + blockId: String, + ) { val key = locationKey(block.location) blocks[key] = block blockIds[key] = blockId block.start() - plugin.logger.atlasInfo("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} + """.trimIndent(), + ) } fun unregister(location: Location): T? { @@ -40,22 +47,40 @@ open class BlockRegistry(protected val plugin: JavaPlugin) { return blocks[locationKey(location)] } - fun getAdjacentBlock(location: Location, face: BlockFace): T? { + fun getAdjacentBlock( + location: Location, + face: BlockFace, + ): T? { val offset = face.direction - return getBlock(Location(location.world, - (location.blockX + offset.blockX).toDouble(), - (location.blockY + offset.blockY).toDouble(), - (location.blockZ + offset.blockZ).toDouble())) + return getBlock( + Location( + location.world, + (location.blockX + offset.blockX).toDouble(), + (location.blockY + offset.blockY).toDouble(), + (location.blockZ + offset.blockZ).toDouble(), + ), + ) } fun getAdjacentBlocks(location: Location): List { - val offsets = listOf( - intArrayOf(1, 0, 0), intArrayOf(-1, 0, 0), - intArrayOf(0, 1, 0), intArrayOf(0, -1, 0), - intArrayOf(0, 0, 1), intArrayOf(0, 0, -1) - ) + val offsets = + listOf( + intArrayOf(1, 0, 0), + intArrayOf(-1, 0, 0), + intArrayOf(0, 1, 0), + intArrayOf(0, -1, 0), + intArrayOf(0, 0, 1), + intArrayOf(0, 0, -1), + ) return offsets.mapNotNull { (dx, dy, dz) -> - getBlock(Location(location.world, (location.blockX + dx).toDouble(), (location.blockY + dy).toDouble(), (location.blockZ + dz).toDouble())) + getBlock( + Location( + location.world, + (location.blockX + dx).toDouble(), + (location.blockY + dy).toDouble(), + (location.blockZ + dz).toDouble(), + ), + ) } } diff --git a/src/main/kotlin/com/coderjoe/atlas/core/BlockSystem.kt b/src/main/kotlin/com/coderjoe/atlas/core/BlockSystem.kt index 22cc42f..09d049b 100644 --- a/src/main/kotlin/com/coderjoe/atlas/core/BlockSystem.kt +++ b/src/main/kotlin/com/coderjoe/atlas/core/BlockSystem.kt @@ -7,7 +7,7 @@ class BlockSystem( val registry: BlockRegistry, val factory: BlockFactory, val descriptors: Map, - val showDialog: (Player, AtlasBlock) -> Unit + val showDialog: (Player, AtlasBlock) -> Unit, ) { fun findDescriptorForBlockId(blockId: String): BlockDescriptor? { return descriptors.values.find { blockId in it.allRegistrableIds } diff --git a/src/main/kotlin/com/coderjoe/atlas/fluid/FluidBlock.kt b/src/main/kotlin/com/coderjoe/atlas/fluid/FluidBlock.kt index 1073fcc..498edd9 100644 --- a/src/main/kotlin/com/coderjoe/atlas/fluid/FluidBlock.kt +++ b/src/main/kotlin/com/coderjoe/atlas/fluid/FluidBlock.kt @@ -6,9 +6,8 @@ import org.bukkit.Location abstract class FluidBlock( location: Location, - var storedFluid: FluidType = FluidType.NONE + var storedFluid: FluidType = FluidType.NONE, ) : AtlasBlock(location) { - open fun hasFluid(): Boolean = storedFluid != FluidType.NONE open fun storeFluid(type: FluidType): Boolean { diff --git a/src/main/kotlin/com/coderjoe/atlas/fluid/FluidBlockData.kt b/src/main/kotlin/com/coderjoe/atlas/fluid/FluidBlockData.kt index 3a6d6bc..d83e58d 100644 --- a/src/main/kotlin/com/coderjoe/atlas/fluid/FluidBlockData.kt +++ b/src/main/kotlin/com/coderjoe/atlas/fluid/FluidBlockData.kt @@ -13,16 +13,20 @@ data class FluidBlockData( val z: Int, val fluidType: String, val facing: String? = null, - val storedAmount: Int? = null + val storedAmount: Int? = null, ) { companion object { - fun fromFluidBlock(fluidBlock: FluidBlock, blockId: String): FluidBlockData { + fun fromFluidBlock( + fluidBlock: FluidBlock, + blockId: String, + ): FluidBlockData { val loc = fluidBlock.location val facing = fluidBlock.facing.let { if (it == BlockFace.SELF) null else it.name } - val storedAmount = when (fluidBlock) { - is FluidContainer -> fluidBlock.storedAmount - else -> null - } + val storedAmount = + when (fluidBlock) { + is FluidContainer -> fluidBlock.storedAmount + else -> null + } return FluidBlockData( blockId = blockId, world = loc.world?.name ?: "world", @@ -31,7 +35,7 @@ data class FluidBlockData( z = loc.blockZ, fluidType = fluidBlock.storedFluid.name, facing = facing, - storedAmount = storedAmount + storedAmount = storedAmount, ) } } @@ -43,13 +47,21 @@ data class FluidBlockData( fun toBlockFace(): BlockFace { return if (facing != null) { - try { BlockFace.valueOf(facing) } catch (_: Exception) { BlockFace.SELF } + try { + BlockFace.valueOf(facing) + } catch (_: Exception) { + BlockFace.SELF + } } else { BlockFace.SELF } } fun toFluidType(): FluidType { - return try { FluidType.valueOf(fluidType) } catch (_: Exception) { FluidType.NONE } + return try { + FluidType.valueOf(fluidType) + } catch (_: Exception) { + FluidType.NONE + } } } diff --git a/src/main/kotlin/com/coderjoe/atlas/fluid/FluidBlockDialog.kt b/src/main/kotlin/com/coderjoe/atlas/fluid/FluidBlockDialog.kt index d7c6c13..4df156d 100644 --- a/src/main/kotlin/com/coderjoe/atlas/fluid/FluidBlockDialog.kt +++ b/src/main/kotlin/com/coderjoe/atlas/fluid/FluidBlockDialog.kt @@ -3,8 +3,8 @@ package com.coderjoe.atlas.fluid import com.coderjoe.atlas.core.AtlasBlockDialog import com.coderjoe.atlas.core.BlockRegistry import com.coderjoe.atlas.fluid.block.FluidContainer -import com.coderjoe.atlas.fluid.block.FluidPipe import com.coderjoe.atlas.fluid.block.FluidMerger +import com.coderjoe.atlas.fluid.block.FluidPipe import com.coderjoe.atlas.fluid.block.FluidPump import io.papermc.paper.dialog.Dialog import io.papermc.paper.registry.data.dialog.ActionButton @@ -21,12 +21,15 @@ import org.bukkit.entity.Player import org.bukkit.plugin.java.JavaPlugin object FluidBlockDialog { - fun init(plugin: JavaPlugin) { AtlasBlockDialog.init(plugin) } - fun showFluidDialog(player: Player, fluidBlock: FluidBlock, registry: BlockRegistry<*>) { + fun showFluidDialog( + player: Player, + fluidBlock: FluidBlock, + registry: BlockRegistry<*>, + ) { AtlasBlockDialog.showDialog(player, fluidBlock, registry) { p, block, onClose -> sendDialog(p, block as FluidBlock, onClose) } @@ -36,110 +39,131 @@ object FluidBlockDialog { AtlasBlockDialog.cleanup() } - private fun sendDialog(player: Player, fluidBlock: FluidBlock, onClose: (Player) -> Unit) { + private fun sendDialog( + player: Player, + fluidBlock: FluidBlock, + onClose: (Player) -> Unit, + ) { val title = Component.text(getBlockDisplayName(fluidBlock)) val bodyText = buildFluidInfo(fluidBlock) val body = DialogBody.plainMessage(bodyText) - val closeAction = DialogAction.customClick( - DialogActionCallback { _, audience -> - val p = audience as? Player ?: return@DialogActionCallback - onClose(p) - }, - ClickCallback.Options.builder().build() - ) - - val closeButton = ActionButton.builder(Component.text("Close")) - .action(closeAction) - .build() - - val dialog = Dialog.create { factory -> - factory.empty() - .base( - DialogBase.builder(title) - .body(listOf(body)) - .canCloseWithEscape(false) - .afterAction(DialogBase.DialogAfterAction.CLOSE) - .build() - ) - .type(DialogType.notice(closeButton)) - } + val closeAction = + DialogAction.customClick( + DialogActionCallback { _, audience -> + val p = audience as? Player ?: return@DialogActionCallback + onClose(p) + }, + ClickCallback.Options.builder().build(), + ) + + val closeButton = + ActionButton.builder(Component.text("Close")) + .action(closeAction) + .build() + + val dialog = + Dialog.create { factory -> + factory.empty() + .base( + DialogBase.builder(title) + .body(listOf(body)) + .canCloseWithEscape(false) + .afterAction(DialogBase.DialogAfterAction.CLOSE) + .build(), + ) + .type(DialogType.notice(closeButton)) + } player.showDialog(dialog) } - private fun getBlockDisplayName(fluidBlock: FluidBlock): String = when (fluidBlock) { - is FluidPump -> "Fluid Pump" - is FluidPipe -> "Fluid Pipe (${fluidBlock.facing.name.lowercase().replaceFirstChar { it.uppercase() }})" - is FluidContainer -> "Fluid Container (${fluidBlock.facing.name.lowercase().replaceFirstChar { it.uppercase() }})" - is FluidMerger -> "Fluid Merger (${fluidBlock.facing.name.lowercase().replaceFirstChar { it.uppercase() }})" - else -> "Fluid Block" - } + private fun getBlockDisplayName(fluidBlock: FluidBlock): String = + when (fluidBlock) { + is FluidPump -> "Fluid Pump" + is FluidPipe -> "Fluid Pipe (${fluidBlock.facing.name.lowercase().replaceFirstChar { it.uppercase() }})" + is FluidContainer -> "Fluid Container (${fluidBlock.facing.name.lowercase().replaceFirstChar { it.uppercase() }})" + is FluidMerger -> "Fluid Merger (${fluidBlock.facing.name.lowercase().replaceFirstChar { it.uppercase() }})" + else -> "Fluid Block" + } private fun buildFluidInfo(fluidBlock: FluidBlock): Component { - val fluidName = if (fluidBlock is FluidContainer && fluidBlock.storedAmount > 0) { - when (fluidBlock.storedFluid) { - FluidType.WATER -> "Water (${fluidBlock.storedAmount}/${FluidContainer.MAX_CAPACITY})" - FluidType.LAVA -> "Lava (${fluidBlock.storedAmount}/${FluidContainer.MAX_CAPACITY})" - FluidType.NONE -> "Empty" - } - } else { - when (fluidBlock.storedFluid) { - FluidType.WATER -> "Water" - FluidType.LAVA -> "Lava" - FluidType.NONE -> "Empty" + val fluidName = + if (fluidBlock is FluidContainer && fluidBlock.storedAmount > 0) { + when (fluidBlock.storedFluid) { + FluidType.WATER -> "Water (${fluidBlock.storedAmount}/${FluidContainer.MAX_CAPACITY})" + FluidType.LAVA -> "Lava (${fluidBlock.storedAmount}/${FluidContainer.MAX_CAPACITY})" + FluidType.NONE -> "Empty" + } + } else { + when (fluidBlock.storedFluid) { + FluidType.WATER -> "Water" + FluidType.LAVA -> "Lava" + FluidType.NONE -> "Empty" + } } - } - val fluidColor = when (fluidBlock.storedFluid) { - FluidType.WATER -> NamedTextColor.AQUA - FluidType.LAVA -> NamedTextColor.GOLD - FluidType.NONE -> NamedTextColor.GRAY - } - - val statusLine = Component.text("Fluid: ") - .color(NamedTextColor.WHITE) - .decorate(TextDecoration.BOLD) - .append(Component.text(fluidName).color(fluidColor).decoration(TextDecoration.BOLD, false)) - - val infoLine = when (fluidBlock) { - is FluidPump -> Component.text("Pump - extracts fluid from adjacent cauldrons (1 power/s)") - .color(NamedTextColor.GRAY) - is FluidPipe -> Component.text("Pipe - transports fluid in facing direction") - .color(NamedTextColor.GRAY) - is FluidContainer -> Component.text("Container - stores up to ${FluidContainer.MAX_CAPACITY} units of fluid") - .color(NamedTextColor.GRAY) - is FluidMerger -> Component.text("Merger - merges fluid from all sides, outputs in facing direction") - .color(NamedTextColor.GRAY) - else -> Component.text("Fluid block") - .color(NamedTextColor.GRAY) - } - - var result = statusLine - .append(Component.newline()) - .append(infoLine) - - if (fluidBlock is FluidPump) { - val powerLine = if (fluidBlock.isPowered) { - Component.text("Powered").color(NamedTextColor.GREEN) - } else { - Component.text("No Power").color(NamedTextColor.RED) + val fluidColor = + when (fluidBlock.storedFluid) { + FluidType.WATER -> NamedTextColor.AQUA + FluidType.LAVA -> NamedTextColor.GOLD + FluidType.NONE -> NamedTextColor.GRAY } - val statusText = when (fluidBlock.pumpStatus) { - FluidPump.PumpStatus.IDLE -> Component.text("Idle — holding fluid").color(NamedTextColor.YELLOW) - FluidPump.PumpStatus.EXTRACTING -> Component.text("Extracting from cauldron").color(NamedTextColor.GREEN) - FluidPump.PumpStatus.NO_SOURCE -> Component.text("No source nearby").color(NamedTextColor.RED) - FluidPump.PumpStatus.NO_POWER -> Component.text("Waiting for power").color(NamedTextColor.RED) + val statusLine = + Component.text("Fluid: ") + .color(NamedTextColor.WHITE) + .decorate(TextDecoration.BOLD) + .append(Component.text(fluidName).color(fluidColor).decoration(TextDecoration.BOLD, false)) + + val infoLine = + when (fluidBlock) { + is FluidPump -> + Component.text("Pump - extracts fluid from adjacent cauldrons (1 power/s)") + .color(NamedTextColor.GRAY) + is FluidPipe -> + Component.text("Pipe - transports fluid in facing direction") + .color(NamedTextColor.GRAY) + is FluidContainer -> + Component.text("Container - stores up to ${FluidContainer.MAX_CAPACITY} units of fluid") + .color(NamedTextColor.GRAY) + is FluidMerger -> + Component.text("Merger - merges fluid from all sides, outputs in facing direction") + .color(NamedTextColor.GRAY) + else -> + Component.text("Fluid block") + .color(NamedTextColor.GRAY) } - result = result - .append(Component.newline()) - .append(Component.text("Power: ").color(NamedTextColor.WHITE).decorate(TextDecoration.BOLD)) - .append(powerLine.decoration(TextDecoration.BOLD, false)) + var result = + statusLine .append(Component.newline()) - .append(Component.text("Status: ").color(NamedTextColor.WHITE).decorate(TextDecoration.BOLD)) - .append(statusText.decoration(TextDecoration.BOLD, false)) + .append(infoLine) + + if (fluidBlock is FluidPump) { + val powerLine = + if (fluidBlock.isPowered) { + Component.text("Powered").color(NamedTextColor.GREEN) + } else { + Component.text("No Power").color(NamedTextColor.RED) + } + + val statusText = + when (fluidBlock.pumpStatus) { + FluidPump.PumpStatus.IDLE -> Component.text("Idle — holding fluid").color(NamedTextColor.YELLOW) + FluidPump.PumpStatus.EXTRACTING -> Component.text("Extracting from cauldron").color(NamedTextColor.GREEN) + FluidPump.PumpStatus.NO_SOURCE -> Component.text("No source nearby").color(NamedTextColor.RED) + FluidPump.PumpStatus.NO_POWER -> Component.text("Waiting for power").color(NamedTextColor.RED) + } + + result = + result + .append(Component.newline()) + .append(Component.text("Power: ").color(NamedTextColor.WHITE).decorate(TextDecoration.BOLD)) + .append(powerLine.decoration(TextDecoration.BOLD, false)) + .append(Component.newline()) + .append(Component.text("Status: ").color(NamedTextColor.WHITE).decorate(TextDecoration.BOLD)) + .append(statusText.decoration(TextDecoration.BOLD, false)) } return result diff --git a/src/main/kotlin/com/coderjoe/atlas/fluid/FluidBlockFactory.kt b/src/main/kotlin/com/coderjoe/atlas/fluid/FluidBlockFactory.kt index 6adb444..cd28fdf 100644 --- a/src/main/kotlin/com/coderjoe/atlas/fluid/FluidBlockFactory.kt +++ b/src/main/kotlin/com/coderjoe/atlas/fluid/FluidBlockFactory.kt @@ -5,8 +5,11 @@ import org.bukkit.Location import org.bukkit.block.BlockFace object FluidBlockFactory : BlockFactory() { - - fun createFluidBlock(blockId: String, location: Location, facing: BlockFace = BlockFace.SELF): FluidBlock? { + fun createFluidBlock( + blockId: String, + location: Location, + facing: BlockFace = BlockFace.SELF, + ): FluidBlock? { return create(blockId, location, facing) } } diff --git a/src/main/kotlin/com/coderjoe/atlas/fluid/FluidBlockPersistence.kt b/src/main/kotlin/com/coderjoe/atlas/fluid/FluidBlockPersistence.kt index 97f2f48..680ea71 100644 --- a/src/main/kotlin/com/coderjoe/atlas/fluid/FluidBlockPersistence.kt +++ b/src/main/kotlin/com/coderjoe/atlas/fluid/FluidBlockPersistence.kt @@ -5,36 +5,44 @@ import com.coderjoe.atlas.fluid.block.FluidContainer import org.bukkit.plugin.java.JavaPlugin class FluidBlockPersistence(plugin: JavaPlugin) { - private val persistence = BlockPersistence( - plugin = plugin, - fileName = "fluid_blocks.yml", - yamlKey = "fluid_blocks", - factory = FluidBlockFactory, - serialize = { block, _ -> - val map = mutableMapOf( - "fluidType" to block.storedFluid.name - ) - if (block is FluidContainer) { - map["storedAmount"] = block.storedAmount - } - map - }, - restore = { block, data -> - val fluidTypeName = data["fluidType"] as? String ?: "NONE" - val fluidType = try { FluidType.valueOf(fluidTypeName) } catch (_: Exception) { FluidType.NONE } - if (block is FluidContainer) { - val storedAmount = (data["storedAmount"] as? Number)?.toInt() - if (storedAmount != null) { - block.restoreState(fluidType, storedAmount) + private val persistence = + BlockPersistence( + plugin = plugin, + fileName = "fluid_blocks.yml", + yamlKey = "fluid_blocks", + factory = FluidBlockFactory, + serialize = { block, _ -> + val map = + mutableMapOf( + "fluidType" to block.storedFluid.name, + ) + if (block is FluidContainer) { + map["storedAmount"] = block.storedAmount + } + map + }, + restore = { block, data -> + val fluidTypeName = data["fluidType"] as? String ?: "NONE" + val fluidType = + try { + FluidType.valueOf(fluidTypeName) + } catch (_: Exception) { + FluidType.NONE + } + if (block is FluidContainer) { + val storedAmount = (data["storedAmount"] as? Number)?.toInt() + if (storedAmount != null) { + block.restoreState(fluidType, storedAmount) + } else { + block.storedFluid = fluidType + } } else { block.storedFluid = fluidType } - } else { - block.storedFluid = fluidType - } - } - ) + }, + ) fun save(registry: FluidBlockRegistry) = persistence.save(registry) + fun load(registry: FluidBlockRegistry) = persistence.load(registry) } diff --git a/src/main/kotlin/com/coderjoe/atlas/fluid/FluidBlockRegistry.kt b/src/main/kotlin/com/coderjoe/atlas/fluid/FluidBlockRegistry.kt index 8496eeb..24026d4 100644 --- a/src/main/kotlin/com/coderjoe/atlas/fluid/FluidBlockRegistry.kt +++ b/src/main/kotlin/com/coderjoe/atlas/fluid/FluidBlockRegistry.kt @@ -6,7 +6,6 @@ import org.bukkit.block.BlockFace import org.bukkit.plugin.java.JavaPlugin class FluidBlockRegistry(plugin: JavaPlugin) : BlockRegistry(plugin) { - companion object { var instance: FluidBlockRegistry? = null private set @@ -18,13 +17,19 @@ class FluidBlockRegistry(plugin: JavaPlugin) : BlockRegistry(plugin) instance = this } - fun registerFluidBlock(fluidBlock: FluidBlock, blockId: String) = register(fluidBlock, blockId) + fun registerFluidBlock( + fluidBlock: FluidBlock, + blockId: String, + ) = register(fluidBlock, blockId) fun unregisterFluidBlock(location: Location): FluidBlock? = unregister(location) fun getFluidBlock(location: Location): FluidBlock? = getBlock(location) - fun getAdjacentFluidBlock(location: Location, face: BlockFace): FluidBlock? = getAdjacentBlock(location, face) + fun getAdjacentFluidBlock( + location: Location, + face: BlockFace, + ): FluidBlock? = getAdjacentBlock(location, face) fun getAllFluidBlocksWithIds(): List> = getAllBlocksWithIds() } diff --git a/src/main/kotlin/com/coderjoe/atlas/fluid/FluidType.kt b/src/main/kotlin/com/coderjoe/atlas/fluid/FluidType.kt index 23e6018..8743ed8 100644 --- a/src/main/kotlin/com/coderjoe/atlas/fluid/FluidType.kt +++ b/src/main/kotlin/com/coderjoe/atlas/fluid/FluidType.kt @@ -3,5 +3,5 @@ package com.coderjoe.atlas.fluid enum class FluidType { WATER, LAVA, - NONE + NONE, } 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 9a1af2f..acb6e8d 100644 --- a/src/main/kotlin/com/coderjoe/atlas/fluid/block/FluidContainer.kt +++ b/src/main/kotlin/com/coderjoe/atlas/fluid/block/FluidContainer.kt @@ -10,7 +10,6 @@ import org.bukkit.Location import org.bukkit.block.BlockFace class FluidContainer(location: Location, override val facing: BlockFace) : FluidBlock(location) { - var storedAmount: Int = 0 private set @@ -20,46 +19,51 @@ class FluidContainer(location: Location, override val facing: BlockFace) : Fluid const val BLOCK_ID = "fluid_container" const val MAX_CAPACITY = 10 - val DIRECTIONAL_IDS = mapOf( - BlockFace.NORTH to "fluid_container_north", - BlockFace.SOUTH to "fluid_container_south", - BlockFace.EAST to "fluid_container_east", - BlockFace.WEST to "fluid_container_west", - BlockFace.UP to "fluid_container_up", - BlockFace.DOWN to "fluid_container_down" - ) + val DIRECTIONAL_IDS = + mapOf( + BlockFace.NORTH to "fluid_container_north", + BlockFace.SOUTH to "fluid_container_south", + BlockFace.EAST to "fluid_container_east", + BlockFace.WEST to "fluid_container_west", + BlockFace.UP to "fluid_container_up", + BlockFace.DOWN to "fluid_container_down", + ) val ID_TO_FACING = DIRECTIONAL_IDS.entries.associate { (face, id) -> id to face } private val FILL_LEVELS = listOf("low", "medium", "full") private val FLUID_TYPES = listOf("water", "lava") - val FILLED_IDS: Map>> = BlockFace.values() - .filter { DIRECTIONAL_IDS.containsKey(it) } - .associateWith { face -> - val dir = face.name.lowercase() - mapOf( - FluidType.WATER to mapOf( - "low" to "fluid_container_${dir}_water_low", - "medium" to "fluid_container_${dir}_water_medium", - "full" to "fluid_container_${dir}_water_full" - ), - FluidType.LAVA to mapOf( - "low" to "fluid_container_${dir}_lava_low", - "medium" to "fluid_container_${dir}_lava_medium", - "full" to "fluid_container_${dir}_lava_full" + val FILLED_IDS: Map>> = + BlockFace.values() + .filter { DIRECTIONAL_IDS.containsKey(it) } + .associateWith { face -> + val dir = face.name.lowercase() + mapOf( + FluidType.WATER to + mapOf( + "low" to "fluid_container_${dir}_water_low", + "medium" to "fluid_container_${dir}_water_medium", + "full" to "fluid_container_${dir}_water_full", + ), + FluidType.LAVA to + mapOf( + "low" to "fluid_container_${dir}_lava_low", + "medium" to "fluid_container_${dir}_lava_medium", + "full" to "fluid_container_${dir}_lava_full", + ), ) - ) - } + } - val ALL_VARIANT_IDS: List = buildList { - addAll(DIRECTIONAL_IDS.values) - for (face in FILLED_IDS.keys) { - for (fluidMap in FILLED_IDS[face]!!.values) { - addAll(fluidMap.values) + val ALL_VARIANT_IDS: List = + buildList { + addAll(DIRECTIONAL_IDS.values) + for (face in FILLED_IDS.keys) { + for (fluidMap in FILLED_IDS[face]!!.values) { + addAll(fluidMap.values) + } } } - } fun facingFromBlockId(blockId: String): BlockFace? { ID_TO_FACING[blockId]?.let { return it } @@ -71,15 +75,16 @@ class FluidContainer(location: Location, override val facing: BlockFace) : Fluid return null } - val descriptor = BlockDescriptor( - baseBlockId = BLOCK_ID, - displayName = "Fluid Container", - description = "Container - stores up to $MAX_CAPACITY units of fluid", - placementType = PlacementType.DIRECTIONAL, - directionalVariants = DIRECTIONAL_IDS, - allRegistrableIds = ALL_VARIANT_IDS, - constructor = { loc, facing -> FluidContainer(loc, facing) } - ) + val descriptor = + BlockDescriptor( + baseBlockId = BLOCK_ID, + displayName = "Fluid Container", + description = "Container - stores up to $MAX_CAPACITY units of fluid", + placementType = PlacementType.DIRECTIONAL, + directionalVariants = DIRECTIONAL_IDS, + allRegistrableIds = ALL_VARIANT_IDS, + constructor = { loc, facing -> FluidContainer(loc, facing) }, + ) } override val baseBlockId: String = BLOCK_ID @@ -108,12 +113,13 @@ class FluidContainer(location: Location, override val facing: BlockFace) : Fluid return direction == facing && hasFluid() } - fun getFillLevel(): String = when (storedAmount) { - 0 -> "empty" - in 1..3 -> "low" - in 4..7 -> "medium" - else -> "full" - } + fun getFillLevel(): String = + when (storedAmount) { + 0 -> "empty" + in 1..3 -> "low" + in 4..7 -> "medium" + else -> "full" + } override fun getVisualStateBlockId(): String { if (storedAmount == 0 || storedFluid == FluidType.NONE) { @@ -134,7 +140,11 @@ class FluidContainer(location: Location, override val facing: BlockFace) : Fluid if (source.canRemoveFluidFrom(facing)) { val fluid = source.removeFluid() if (storeFluid(fluid)) { - plugin.logger.atlasInfo("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 + """.trimIndent(), + ) } else { source.storeFluid(fluid) } @@ -144,7 +154,11 @@ class FluidContainer(location: Location, override val facing: BlockFace) : Fluid if (source.hasFluid()) { val fluid = source.removeFluid() if (storeFluid(fluid)) { - plugin.logger.atlasInfo("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 + """.trimIndent(), + ) } else { source.storeFluid(fluid) } @@ -154,7 +168,11 @@ class FluidContainer(location: Location, override val facing: BlockFace) : Fluid if (source.canRemoveFluidFrom(facing)) { val fluid = source.removeFluid() if (storeFluid(fluid)) { - plugin.logger.atlasInfo("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 + """.trimIndent(), + ) } else { source.storeFluid(fluid) } @@ -164,7 +182,11 @@ class FluidContainer(location: Location, override val facing: BlockFace) : Fluid if (source.hasFluid()) { val fluid = source.removeFluid() if (storeFluid(fluid)) { - plugin.logger.atlasInfo("FluidContainer at ${location.blockX},${location.blockY},${location.blockZ} pulled ${fluid.name} from FluidMerger") + plugin.logger.atlasInfo( + """ + FluidContainer at ${location.blockX},${location.blockY},${location.blockZ} pulled ${fluid.name} from FluidMerger + """.trimIndent(), + ) } else { source.storeFluid(fluid) } @@ -173,7 +195,10 @@ class FluidContainer(location: Location, override val facing: BlockFace) : Fluid } } - fun restoreState(type: FluidType, amount: Int) { + fun restoreState( + type: FluidType, + amount: Int, + ) { storedFluid = type storedAmount = amount.coerceIn(0, MAX_CAPACITY) } diff --git a/src/main/kotlin/com/coderjoe/atlas/fluid/block/FluidMerger.kt b/src/main/kotlin/com/coderjoe/atlas/fluid/block/FluidMerger.kt index 0fca43d..393d390 100644 --- a/src/main/kotlin/com/coderjoe/atlas/fluid/block/FluidMerger.kt +++ b/src/main/kotlin/com/coderjoe/atlas/fluid/block/FluidMerger.kt @@ -10,61 +10,65 @@ import org.bukkit.Location import org.bukkit.block.BlockFace class FluidMerger(location: Location, override val facing: BlockFace) : FluidBlock(location) { - override val updateIntervalTicks: Long = 20L companion object { const val BLOCK_ID = "fluid_merger" - val DIRECTIONAL_IDS = mapOf( - BlockFace.NORTH to "fluid_merger_north", - BlockFace.SOUTH to "fluid_merger_south", - BlockFace.EAST to "fluid_merger_east", - BlockFace.WEST to "fluid_merger_west", - BlockFace.UP to "fluid_merger_up", - BlockFace.DOWN to "fluid_merger_down" - ) - - val WATER_FILLED_IDS = mapOf( - BlockFace.NORTH to "fluid_merger_north_filled", - BlockFace.SOUTH to "fluid_merger_south_filled", - BlockFace.EAST to "fluid_merger_east_filled", - BlockFace.WEST to "fluid_merger_west_filled", - BlockFace.UP to "fluid_merger_up_filled", - BlockFace.DOWN to "fluid_merger_down_filled" - ) - - val LAVA_FILLED_IDS = mapOf( - BlockFace.NORTH to "fluid_merger_north_filled_lava", - BlockFace.SOUTH to "fluid_merger_south_filled_lava", - BlockFace.EAST to "fluid_merger_east_filled_lava", - BlockFace.WEST to "fluid_merger_west_filled_lava", - BlockFace.UP to "fluid_merger_up_filled_lava", - BlockFace.DOWN to "fluid_merger_down_filled_lava" - ) + val DIRECTIONAL_IDS = + mapOf( + BlockFace.NORTH to "fluid_merger_north", + BlockFace.SOUTH to "fluid_merger_south", + BlockFace.EAST to "fluid_merger_east", + BlockFace.WEST to "fluid_merger_west", + BlockFace.UP to "fluid_merger_up", + BlockFace.DOWN to "fluid_merger_down", + ) + + val WATER_FILLED_IDS = + mapOf( + BlockFace.NORTH to "fluid_merger_north_filled", + BlockFace.SOUTH to "fluid_merger_south_filled", + BlockFace.EAST to "fluid_merger_east_filled", + BlockFace.WEST to "fluid_merger_west_filled", + BlockFace.UP to "fluid_merger_up_filled", + BlockFace.DOWN to "fluid_merger_down_filled", + ) + + val LAVA_FILLED_IDS = + mapOf( + BlockFace.NORTH to "fluid_merger_north_filled_lava", + BlockFace.SOUTH to "fluid_merger_south_filled_lava", + BlockFace.EAST to "fluid_merger_east_filled_lava", + BlockFace.WEST to "fluid_merger_west_filled_lava", + BlockFace.UP to "fluid_merger_up_filled_lava", + BlockFace.DOWN to "fluid_merger_down_filled_lava", + ) val ID_TO_FACING = DIRECTIONAL_IDS.entries.associate { (face, id) -> id to face } fun facingFromBlockId(blockId: String): BlockFace? = ID_TO_FACING[blockId] - val descriptor = BlockDescriptor( - baseBlockId = BLOCK_ID, - displayName = "Fluid Merger", - description = "Merger - merges fluid from all sides, outputs in facing direction", - placementType = PlacementType.DIRECTIONAL, - directionalVariants = DIRECTIONAL_IDS, - allRegistrableIds = DIRECTIONAL_IDS.values.toList() + WATER_FILLED_IDS.values.toList() + LAVA_FILLED_IDS.values.toList(), - constructor = { loc, facing -> FluidMerger(loc, facing) } - ) + val descriptor = + BlockDescriptor( + baseBlockId = BLOCK_ID, + displayName = "Fluid Merger", + description = "Merger - merges fluid from all sides, outputs in facing direction", + placementType = PlacementType.DIRECTIONAL, + directionalVariants = DIRECTIONAL_IDS, + allRegistrableIds = DIRECTIONAL_IDS.values.toList() + WATER_FILLED_IDS.values.toList() + LAVA_FILLED_IDS.values.toList(), + constructor = { loc, facing -> FluidMerger(loc, facing) }, + ) } override val baseBlockId: String = BLOCK_ID - override fun getVisualStateBlockId(): String = when (storedFluid) { - FluidType.WATER -> WATER_FILLED_IDS[facing]!! - FluidType.LAVA -> LAVA_FILLED_IDS[facing]!! - FluidType.NONE -> DIRECTIONAL_IDS[facing]!! - } + override fun getVisualStateBlockId(): String = + when (storedFluid) { + FluidType.WATER -> WATER_FILLED_IDS[facing]!! + FluidType.LAVA -> LAVA_FILLED_IDS[facing]!! + FluidType.NONE -> DIRECTIONAL_IDS[facing]!! + } override fun fluidUpdate() { if (hasFluid()) return @@ -72,8 +76,9 @@ class FluidMerger(location: Location, override val facing: BlockFace) : FluidBlo val registry = FluidBlockRegistry.instance ?: return // Pull fluid from all faces except the output (facing) direction - val inputFaces = listOf(BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST, BlockFace.UP, BlockFace.DOWN) - .filter { it != facing } + val inputFaces = + listOf(BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST, BlockFace.UP, BlockFace.DOWN) + .filter { it != facing } for (face in inputFaces) { val source = registry.getAdjacentFluidBlock(location, face) ?: continue @@ -83,7 +88,11 @@ class FluidMerger(location: Location, override val facing: BlockFace) : FluidBlo if (source.canRemoveFluidFrom(face.oppositeFace) && source.hasFluid()) { val fluid = source.removeFluid() storeFluid(fluid) - plugin.logger.atlasInfo("FluidMerger at ${location.blockX},${location.blockY},${location.blockZ} pulled ${fluid.name} from FluidPump at ${face.name}") + plugin.logger.atlasInfo( + """ + FluidMerger at ${location.blockX},${location.blockY},${location.blockZ} pulled ${fluid.name} from FluidPump at ${face.name} + """.trimIndent(), + ) return } } @@ -91,7 +100,11 @@ class FluidMerger(location: Location, override val facing: BlockFace) : FluidBlo if (source.hasFluid()) { val fluid = source.removeFluid() storeFluid(fluid) - plugin.logger.atlasInfo("FluidMerger at ${location.blockX},${location.blockY},${location.blockZ} pulled ${fluid.name} from FluidPipe at ${face.name}") + plugin.logger.atlasInfo( + """ + FluidMerger at ${location.blockX},${location.blockY},${location.blockZ} pulled ${fluid.name} from FluidPipe at ${face.name} + """.trimIndent(), + ) return } } @@ -99,7 +112,11 @@ class FluidMerger(location: Location, override val facing: BlockFace) : FluidBlo if (source.canRemoveFluidFrom(face.oppositeFace) && source.hasFluid()) { val fluid = source.removeFluid() storeFluid(fluid) - plugin.logger.atlasInfo("FluidMerger at ${location.blockX},${location.blockY},${location.blockZ} pulled ${fluid.name} from FluidContainer at ${face.name}") + plugin.logger.atlasInfo( + """ + FluidMerger at ${location.blockX},${location.blockY},${location.blockZ} pulled ${fluid.name} from FluidContainer at ${face.name} + """.trimIndent(), + ) return } } @@ -107,7 +124,11 @@ class FluidMerger(location: Location, override val facing: BlockFace) : FluidBlo if (source.hasFluid()) { val fluid = source.removeFluid() storeFluid(fluid) - plugin.logger.atlasInfo("FluidMerger at ${location.blockX},${location.blockY},${location.blockZ} pulled ${fluid.name} from FluidMerger at ${face.name}") + plugin.logger.atlasInfo( + """ + FluidMerger at ${location.blockX},${location.blockY},${location.blockZ} pulled ${fluid.name} from FluidMerger at ${face.name} + """.trimIndent(), + ) return } } 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 d3708c0..bba752e 100644 --- a/src/main/kotlin/com/coderjoe/atlas/fluid/block/FluidPipe.kt +++ b/src/main/kotlin/com/coderjoe/atlas/fluid/block/FluidPipe.kt @@ -10,61 +10,65 @@ import org.bukkit.Location import org.bukkit.block.BlockFace class FluidPipe(location: Location, override val facing: BlockFace) : FluidBlock(location) { - override val updateIntervalTicks: Long = 20L companion object { const val BLOCK_ID = "fluid_pipe" - val DIRECTIONAL_IDS = mapOf( - BlockFace.NORTH to "fluid_pipe_north", - BlockFace.SOUTH to "fluid_pipe_south", - BlockFace.EAST to "fluid_pipe_east", - BlockFace.WEST to "fluid_pipe_west", - BlockFace.UP to "fluid_pipe_up", - BlockFace.DOWN to "fluid_pipe_down" - ) + val DIRECTIONAL_IDS = + mapOf( + BlockFace.NORTH to "fluid_pipe_north", + BlockFace.SOUTH to "fluid_pipe_south", + BlockFace.EAST to "fluid_pipe_east", + BlockFace.WEST to "fluid_pipe_west", + BlockFace.UP to "fluid_pipe_up", + BlockFace.DOWN to "fluid_pipe_down", + ) val ID_TO_FACING = DIRECTIONAL_IDS.entries.associate { (face, id) -> id to face } - val WATER_FILLED_IDS = mapOf( - BlockFace.NORTH to "fluid_pipe_north_filled", - BlockFace.SOUTH to "fluid_pipe_south_filled", - BlockFace.EAST to "fluid_pipe_east_filled", - BlockFace.WEST to "fluid_pipe_west_filled", - BlockFace.UP to "fluid_pipe_up_filled", - BlockFace.DOWN to "fluid_pipe_down_filled" - ) + val WATER_FILLED_IDS = + mapOf( + BlockFace.NORTH to "fluid_pipe_north_filled", + BlockFace.SOUTH to "fluid_pipe_south_filled", + BlockFace.EAST to "fluid_pipe_east_filled", + BlockFace.WEST to "fluid_pipe_west_filled", + BlockFace.UP to "fluid_pipe_up_filled", + BlockFace.DOWN to "fluid_pipe_down_filled", + ) - val LAVA_FILLED_IDS = mapOf( - BlockFace.NORTH to "fluid_pipe_north_filled_lava", - BlockFace.SOUTH to "fluid_pipe_south_filled_lava", - BlockFace.EAST to "fluid_pipe_east_filled_lava", - BlockFace.WEST to "fluid_pipe_west_filled_lava", - BlockFace.UP to "fluid_pipe_up_filled_lava", - BlockFace.DOWN to "fluid_pipe_down_filled_lava" - ) + val LAVA_FILLED_IDS = + mapOf( + BlockFace.NORTH to "fluid_pipe_north_filled_lava", + BlockFace.SOUTH to "fluid_pipe_south_filled_lava", + BlockFace.EAST to "fluid_pipe_east_filled_lava", + BlockFace.WEST to "fluid_pipe_west_filled_lava", + BlockFace.UP to "fluid_pipe_up_filled_lava", + BlockFace.DOWN to "fluid_pipe_down_filled_lava", + ) fun facingFromBlockId(blockId: String): BlockFace? = ID_TO_FACING[blockId] - val descriptor = BlockDescriptor( - baseBlockId = BLOCK_ID, - displayName = "Fluid Pipe", - description = "Pipe - transports fluid in facing direction", - placementType = PlacementType.DIRECTIONAL, - directionalVariants = DIRECTIONAL_IDS, - allRegistrableIds = DIRECTIONAL_IDS.values.toList() + WATER_FILLED_IDS.values.toList() + LAVA_FILLED_IDS.values.toList(), - constructor = { loc, facing -> FluidPipe(loc, facing) } - ) + val descriptor = + BlockDescriptor( + baseBlockId = BLOCK_ID, + displayName = "Fluid Pipe", + description = "Pipe - transports fluid in facing direction", + placementType = PlacementType.DIRECTIONAL, + directionalVariants = DIRECTIONAL_IDS, + allRegistrableIds = DIRECTIONAL_IDS.values.toList() + WATER_FILLED_IDS.values.toList() + LAVA_FILLED_IDS.values.toList(), + constructor = { loc, facing -> FluidPipe(loc, facing) }, + ) } override val baseBlockId: String = BLOCK_ID - override fun getVisualStateBlockId(): String = when (storedFluid) { - FluidType.WATER -> WATER_FILLED_IDS[facing]!! - FluidType.LAVA -> LAVA_FILLED_IDS[facing]!! - FluidType.NONE -> DIRECTIONAL_IDS[facing]!! - } + override fun getVisualStateBlockId(): String = + when (storedFluid) { + FluidType.WATER -> WATER_FILLED_IDS[facing]!! + FluidType.LAVA -> LAVA_FILLED_IDS[facing]!! + FluidType.NONE -> DIRECTIONAL_IDS[facing]!! + } override fun fluidUpdate() { if (hasFluid()) return @@ -78,28 +82,44 @@ class FluidPipe(location: Location, override val facing: BlockFace) : FluidBlock if (source.canRemoveFluidFrom(facing)) { val fluid = source.removeFluid() storeFluid(fluid) - plugin.logger.atlasInfo("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 + """.trimIndent(), + ) } } is FluidPipe -> { if (source.hasFluid()) { val fluid = source.removeFluid() storeFluid(fluid) - plugin.logger.atlasInfo("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 + """.trimIndent(), + ) } } is FluidContainer -> { if (source.canRemoveFluidFrom(facing)) { val fluid = source.removeFluid() storeFluid(fluid) - plugin.logger.atlasInfo("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 + """.trimIndent(), + ) } } is FluidMerger -> { if (source.hasFluid()) { val fluid = source.removeFluid() storeFluid(fluid) - plugin.logger.atlasInfo("FluidPipe at ${location.blockX},${location.blockY},${location.blockZ} pulled ${fluid.name} from FluidMerger") + plugin.logger.atlasInfo( + """ + FluidPipe at ${location.blockX},${location.blockY},${location.blockZ} pulled ${fluid.name} from FluidMerger + """.trimIndent(), + ) } } } 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 0cea20d..032592d 100644 --- a/src/main/kotlin/com/coderjoe/atlas/fluid/block/FluidPump.kt +++ b/src/main/kotlin/com/coderjoe/atlas/fluid/block/FluidPump.kt @@ -11,12 +11,11 @@ import org.bukkit.Material import org.bukkit.block.BlockFace class FluidPump(location: Location) : FluidBlock(location) { - enum class PumpStatus { IDLE, NO_SOURCE, NO_POWER, - EXTRACTING + EXTRACTING, } override val updateIntervalTicks: Long = 20L @@ -35,20 +34,26 @@ class FluidPump(location: Location) : FluidBlock(location) { const val BLOCK_ID_ACTIVE = "fluid_pump_active" const val BLOCK_ID_ACTIVE_LAVA = "fluid_pump_active_lava" - private val ADJACENT_FACES = listOf( - BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, - BlockFace.WEST, BlockFace.UP, BlockFace.DOWN - ) - - val descriptor = BlockDescriptor( - baseBlockId = BLOCK_ID, - displayName = "Fluid Pump", - description = "Pump - extracts fluid from adjacent cauldrons or source blocks (1 power/s)", - placementType = PlacementType.SIMPLE, - directionalVariants = emptyMap(), - allRegistrableIds = listOf(BLOCK_ID, BLOCK_ID_ACTIVE, BLOCK_ID_ACTIVE_LAVA), - constructor = { loc, _ -> FluidPump(loc) } - ) + private val ADJACENT_FACES = + listOf( + BlockFace.NORTH, + BlockFace.SOUTH, + BlockFace.EAST, + BlockFace.WEST, + BlockFace.UP, + BlockFace.DOWN, + ) + + val descriptor = + BlockDescriptor( + baseBlockId = BLOCK_ID, + displayName = "Fluid Pump", + description = "Pump - extracts fluid from adjacent cauldrons or source blocks (1 power/s)", + placementType = PlacementType.SIMPLE, + directionalVariants = emptyMap(), + allRegistrableIds = listOf(BLOCK_ID, BLOCK_ID_ACTIVE, BLOCK_ID_ACTIVE_LAVA), + constructor = { loc, _ -> FluidPump(loc) }, + ) } override val baseBlockId: String = BLOCK_ID @@ -58,11 +63,12 @@ class FluidPump(location: Location) : FluidBlock(location) { return direction == cauldron.oppositeFace && hasFluid() } - override fun getVisualStateBlockId(): String = when (storedFluid) { - FluidType.WATER -> BLOCK_ID_ACTIVE - FluidType.LAVA -> BLOCK_ID_ACTIVE_LAVA - FluidType.NONE -> BLOCK_ID - } + override fun getVisualStateBlockId(): String = + when (storedFluid) { + FluidType.WATER -> BLOCK_ID_ACTIVE + FluidType.LAVA -> BLOCK_ID_ACTIVE_LAVA + FluidType.NONE -> BLOCK_ID + } override fun fluidUpdate() { val powerRegistry = PowerBlockRegistry.instance ?: return @@ -82,25 +88,27 @@ class FluidPump(location: Location) : FluidBlock(location) { for (face in ADJACENT_FACES) { val offset = face.direction - val adjacentBlock = location.world?.getBlockAt( - location.blockX + offset.blockX, - location.blockY + offset.blockY, - location.blockZ + offset.blockZ - ) ?: continue - - val type = when (adjacentBlock.type) { - Material.WATER_CAULDRON -> FluidType.WATER - Material.LAVA_CAULDRON -> FluidType.LAVA - Material.WATER -> { - val levelData = adjacentBlock.blockData as? org.bukkit.block.data.Levelled - if (levelData != null && levelData.level == 0) FluidType.WATER else continue - } - Material.LAVA -> { - val levelData = adjacentBlock.blockData as? org.bukkit.block.data.Levelled - if (levelData != null && levelData.level == 0) FluidType.LAVA else continue + val adjacentBlock = + location.world?.getBlockAt( + location.blockX + offset.blockX, + location.blockY + offset.blockY, + location.blockZ + offset.blockZ, + ) ?: continue + + val type = + when (adjacentBlock.type) { + Material.WATER_CAULDRON -> FluidType.WATER + Material.LAVA_CAULDRON -> FluidType.LAVA + Material.WATER -> { + val levelData = adjacentBlock.blockData as? org.bukkit.block.data.Levelled + if (levelData != null && levelData.level == 0) FluidType.WATER else continue + } + Material.LAVA -> { + val levelData = adjacentBlock.blockData as? org.bukkit.block.data.Levelled + if (levelData != null && levelData.level == 0) FluidType.LAVA else continue + } + else -> continue } - else -> continue - } foundFace = face foundBlock = adjacentBlock @@ -153,6 +161,10 @@ class FluidPump(location: Location) : FluidBlock(location) { storeFluid(fluidType) cauldronFace = foundFace pumpStatus = PumpStatus.EXTRACTING - plugin.logger.atlasInfo("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 + """.trimIndent(), + ) } } diff --git a/src/main/kotlin/com/coderjoe/atlas/guide/GuideBook.kt b/src/main/kotlin/com/coderjoe/atlas/guide/GuideBook.kt index 6f26b59..7a34518 100644 --- a/src/main/kotlin/com/coderjoe/atlas/guide/GuideBook.kt +++ b/src/main/kotlin/com/coderjoe/atlas/guide/GuideBook.kt @@ -13,7 +13,6 @@ import org.bukkit.inventory.meta.BookMeta import org.bukkit.plugin.java.JavaPlugin object GuideBook { - private const val SOLAR_PANEL = "\uE100" private const val LAVA_GENERATOR = "\uE101" private const val POWER_CABLE = "\uE102" @@ -49,7 +48,7 @@ object GuideBook { player.world.dropItem(player.location, book) player.sendMessage( Component.text("Your inventory was full! The Atlas Guide was dropped at your feet.") - .color(NamedTextColor.YELLOW) + .color(NamedTextColor.YELLOW), ) } } @@ -82,15 +81,18 @@ object GuideBook { .append(Component.text(" - Fluid\n", darkAqua)) .append(Component.text(" - Transport", darkGreen)) .build(), - // Page 2: Power System overview Component.text() .append(Component.text("Power System\n", Style.style(TextDecoration.BOLD).color(gold))) - .append(Component.text("\nGenerators produce\npower. Cables transfer\nit. Batteries store it.\nMachines consume it.\n\n", darkGray)) + .append( + Component.text( + "\nGenerators produce\npower. Cables transfer\nit. Batteries store it.\nMachines consume it.\n\n", + darkGray, + ), + ) .append(Component.text("Pull-based: ", bold)) .append(Component.text("each block\npulls power from the\nblock behind it\n(opposite its facing\ndirection).", darkGray)) .build(), - // Page 3: Small Solar Panel Component.text() .append(Component.text(SOLAR_PANEL)) @@ -102,7 +104,6 @@ object GuideBook { .append(Component.text("Requires: ", bold)) .append(Component.text("clear sky access\nabove the panel.", darkGray)) .build(), - // Page 4: Lava Generator Component.text() .append(Component.text(LAVA_GENERATOR)) @@ -114,7 +115,6 @@ object GuideBook { .append(Component.text("Input: ", bold)) .append(Component.text("pulls lava from\nadjacent fluid blocks.", darkGray)) .build(), - // Page 5: Power Cable Component.text() .append(Component.text(POWER_CABLE)) @@ -126,7 +126,6 @@ object GuideBook { .append(Component.text("Tip: ", bold)) .append(Component.text("place cables in a\nline from generator\nto machine.", darkGray)) .build(), - // Page 6: Small Battery Component.text() .append(Component.text(SMALL_BATTERY)) @@ -138,7 +137,6 @@ object GuideBook { .append(Component.text("Tip: ", bold)) .append(Component.text("place between a\ngenerator and machine\nto buffer power.", darkGray)) .build(), - // Page 7: Small Drill Component.text() .append(Component.text(SMALL_DRILL)) @@ -150,7 +148,6 @@ object GuideBook { .append(Component.text("Tip: ", bold)) .append(Component.text("combine with a\nconveyor belt to auto-\ncollect drops.", darkGray)) .build(), - // Page 8: Fluid System overview Component.text() .append(Component.text("Fluid System\n", Style.style(TextDecoration.BOLD).color(darkAqua))) @@ -160,7 +157,6 @@ object GuideBook { .append(Component.text("Pull-based: ", bold)) .append(Component.text("same as\npower — each block\npulls from behind.", darkGray)) .build(), - // Page 9: Fluid Pump Component.text() .append(Component.text(FLUID_PUMP)) @@ -172,7 +168,6 @@ object GuideBook { .append(Component.text("Storage: ", bold)) .append(Component.text("1 unit", darkGray)) .build(), - // Page 10: Fluid Pipe Component.text() .append(Component.text(FLUID_PIPE)) @@ -184,7 +179,6 @@ object GuideBook { .append(Component.text("Tip: ", bold)) .append(Component.text("chain pipes from\npump to container.", darkGray)) .build(), - // Page 11: Fluid Container Component.text() .append(Component.text(FLUID_CONTAINER)) @@ -196,7 +190,6 @@ object GuideBook { .append(Component.text("Tip: ", bold)) .append(Component.text("store lava for\nuse with the Lava\nGenerator.", darkGray)) .build(), - // Page 12: Transport System + Conveyor Belt Component.text() .append(Component.text("Transport System\n", Style.style(TextDecoration.BOLD).color(darkGreen))) @@ -208,7 +201,6 @@ object GuideBook { .append(Component.text("Tip: ", bold)) .append(Component.text("place after a drill\nto auto-collect mined\nblocks.", darkGray)) .build(), - // Page 13: Auto Smelter Component.text() .append(Component.text("Auto Smelter\n", Style.style(TextDecoration.BOLD).color(darkGreen))) @@ -216,11 +208,12 @@ object GuideBook { .append(Component.text(AUTO_SMELTER)) .append(Component.text(" ")) .append(Component.text("Auto Smelter\n", Style.style(TextDecoration.BOLD).color(darkGreen))) - .append(Component.text("\nSmelts items passing\nthrough it. Conveyor\nbelt on the bottom,\nfire chamber on top.\n\n", darkGray)) + .append( + Component.text("\nSmelts items passing\nthrough it. Conveyor\nbelt on the bottom,\nfire chamber on top.\n\n", darkGray), + ) .append(Component.text("Power cost: ", bold)) .append(Component.text("2 per item", darkGray)) .build(), - // Page 14: Tips Component.text() .append(Component.text("Tips & Tricks\n", Style.style(TextDecoration.BOLD).color(darkRed))) @@ -231,7 +224,7 @@ object GuideBook { .append(Component.text("Drill + Conveyor Belt\n+ Auto Smelter for\nauto ore processing\n\n", darkGray)) .append(Component.text("Placement:\n", bold)) .append(Component.text("blocks face where you\nlook. The pull direction\nis always from behind.", darkGray)) - .build() + .build(), ) } } diff --git a/src/main/kotlin/com/coderjoe/atlas/guide/GuideBookListener.kt b/src/main/kotlin/com/coderjoe/atlas/guide/GuideBookListener.kt index 361904c..1ff37ee 100644 --- a/src/main/kotlin/com/coderjoe/atlas/guide/GuideBookListener.kt +++ b/src/main/kotlin/com/coderjoe/atlas/guide/GuideBookListener.kt @@ -8,7 +8,6 @@ import org.bukkit.plugin.java.JavaPlugin import java.io.File class GuideBookListener(private val plugin: JavaPlugin) : Listener { - private val recipientsFile = File(plugin.dataFolder, "guide-recipients.yml") private val config = YamlConfiguration() private val recipients: MutableSet diff --git a/src/main/kotlin/com/coderjoe/atlas/power/PowerBlock.kt b/src/main/kotlin/com/coderjoe/atlas/power/PowerBlock.kt index 671de83..2ecea3a 100644 --- a/src/main/kotlin/com/coderjoe/atlas/power/PowerBlock.kt +++ b/src/main/kotlin/com/coderjoe/atlas/power/PowerBlock.kt @@ -7,9 +7,8 @@ import org.bukkit.Location abstract class PowerBlock( location: Location, val maxStorage: Int, - var currentPower: Int = 0 + var currentPower: Int = 0, ) : AtlasBlock(location) { - protected open val canReceivePower: Boolean = true fun hasPower(): Boolean = currentPower > 0 diff --git a/src/main/kotlin/com/coderjoe/atlas/power/PowerBlockData.kt b/src/main/kotlin/com/coderjoe/atlas/power/PowerBlockData.kt index ff79f0d..9d602d2 100644 --- a/src/main/kotlin/com/coderjoe/atlas/power/PowerBlockData.kt +++ b/src/main/kotlin/com/coderjoe/atlas/power/PowerBlockData.kt @@ -12,10 +12,13 @@ data class PowerBlockData( val z: Int, val currentPower: Int, val facing: String? = null, - val enabled: Boolean? = null + val enabled: Boolean? = null, ) { companion object { - fun fromPowerBlock(powerBlock: PowerBlock, blockId: String): PowerBlockData { + fun fromPowerBlock( + powerBlock: PowerBlock, + blockId: String, + ): PowerBlockData { val loc = powerBlock.location val facing = powerBlock.facing.let { if (it == BlockFace.SELF) null else it.name } val enabled = if (powerBlock is SmallDrill) powerBlock.enabled else null @@ -27,7 +30,7 @@ data class PowerBlockData( z = loc.blockZ, currentPower = powerBlock.currentPower, facing = facing, - enabled = enabled + enabled = enabled, ) } } @@ -39,7 +42,11 @@ data class PowerBlockData( fun toBlockFace(): BlockFace { return if (facing != null) { - try { BlockFace.valueOf(facing) } catch (_: Exception) { BlockFace.SELF } + try { + BlockFace.valueOf(facing) + } catch (_: Exception) { + BlockFace.SELF + } } else { BlockFace.SELF } diff --git a/src/main/kotlin/com/coderjoe/atlas/power/PowerBlockDialog.kt b/src/main/kotlin/com/coderjoe/atlas/power/PowerBlockDialog.kt index 31dc006..3d6d3c7 100644 --- a/src/main/kotlin/com/coderjoe/atlas/power/PowerBlockDialog.kt +++ b/src/main/kotlin/com/coderjoe/atlas/power/PowerBlockDialog.kt @@ -3,14 +3,14 @@ package com.coderjoe.atlas.power import com.coderjoe.atlas.core.AtlasBlockDialog import com.coderjoe.atlas.core.BlockRegistry import com.coderjoe.atlas.power.block.AutoSmelter +import com.coderjoe.atlas.power.block.CobblestoneFactory import com.coderjoe.atlas.power.block.LavaGenerator -import com.coderjoe.atlas.power.block.PowerCable -import com.coderjoe.atlas.power.block.SmallBattery -import com.coderjoe.atlas.power.block.SmallDrill import com.coderjoe.atlas.power.block.MultiPowerCable -import com.coderjoe.atlas.power.block.CobblestoneFactory import com.coderjoe.atlas.power.block.ObsidianFactory +import com.coderjoe.atlas.power.block.PowerCable import com.coderjoe.atlas.power.block.PowerMerger +import com.coderjoe.atlas.power.block.SmallBattery +import com.coderjoe.atlas.power.block.SmallDrill import com.coderjoe.atlas.power.block.SmallSolarPanel import io.papermc.paper.dialog.Dialog import io.papermc.paper.registry.data.dialog.ActionButton @@ -27,12 +27,15 @@ import org.bukkit.entity.Player import org.bukkit.plugin.java.JavaPlugin object PowerBlockDialog { - fun init(plugin: JavaPlugin) { AtlasBlockDialog.init(plugin) } - fun showPowerDialog(player: Player, powerBlock: PowerBlock, registry: BlockRegistry<*>) { + fun showPowerDialog( + player: Player, + powerBlock: PowerBlock, + registry: BlockRegistry<*>, + ) { AtlasBlockDialog.showDialog(player, powerBlock, registry) { p, block, onClose -> sendDialog(p, block as PowerBlock, onClose) } @@ -42,7 +45,11 @@ object PowerBlockDialog { AtlasBlockDialog.cleanup() } - private fun sendDialog(player: Player, powerBlock: PowerBlock, onClose: (Player) -> Unit) { + private fun sendDialog( + player: Player, + powerBlock: PowerBlock, + onClose: (Player) -> Unit, + ) { if (powerBlock is SmallDrill) { sendDrillDialog(player, powerBlock, onClose) } else { @@ -50,148 +57,182 @@ object PowerBlockDialog { } } - private fun sendDefaultDialog(player: Player, powerBlock: PowerBlock, onClose: (Player) -> Unit) { + private fun sendDefaultDialog( + player: Player, + powerBlock: PowerBlock, + onClose: (Player) -> Unit, + ) { val title = Component.text(getBlockDisplayName(powerBlock)) val bodyText = buildPowerInfo(powerBlock) val body = DialogBody.plainMessage(bodyText) - val closeAction = DialogAction.customClick( - DialogActionCallback { _, audience -> - val p = audience as? Player ?: return@DialogActionCallback - onClose(p) - }, - ClickCallback.Options.builder().build() - ) - - val closeButton = ActionButton.builder(Component.text("Close")) - .action(closeAction) - .build() - - val dialog = Dialog.create { factory -> - factory.empty() - .base( - DialogBase.builder(title) - .body(listOf(body)) - .canCloseWithEscape(false) - .afterAction(DialogBase.DialogAfterAction.CLOSE) - .build() - ) - .type(DialogType.notice(closeButton)) - } + val closeAction = + DialogAction.customClick( + DialogActionCallback { _, audience -> + val p = audience as? Player ?: return@DialogActionCallback + onClose(p) + }, + ClickCallback.Options.builder().build(), + ) + + val closeButton = + ActionButton.builder(Component.text("Close")) + .action(closeAction) + .build() + + val dialog = + Dialog.create { factory -> + factory.empty() + .base( + DialogBase.builder(title) + .body(listOf(body)) + .canCloseWithEscape(false) + .afterAction(DialogBase.DialogAfterAction.CLOSE) + .build(), + ) + .type(DialogType.notice(closeButton)) + } player.showDialog(dialog) } - private fun sendDrillDialog(player: Player, drill: SmallDrill, onClose: (Player) -> Unit) { + private fun sendDrillDialog( + player: Player, + drill: SmallDrill, + onClose: (Player) -> Unit, + ) { val title = Component.text("Small Drill") val bodyText = buildPowerInfo(drill) val body = DialogBody.plainMessage(bodyText) val toggleLabel = if (drill.enabled) "Turn Off" else "Turn On" - val toggleAction = DialogAction.customClick( - DialogActionCallback { _, _ -> - drill.toggleEnabled() - }, - ClickCallback.Options.builder().build() - ) - val toggleButton = ActionButton.builder(Component.text(toggleLabel)) - .action(toggleAction) - .build() - - val closeAction = DialogAction.customClick( - DialogActionCallback { _, audience -> - val p = audience as? Player ?: return@DialogActionCallback - onClose(p) - }, - ClickCallback.Options.builder().build() - ) - val closeButton = ActionButton.builder(Component.text("Close")) - .action(closeAction) - .build() - - val dialog = Dialog.create { factory -> - factory.empty() - .base( - DialogBase.builder(title) - .body(listOf(body)) - .canCloseWithEscape(false) - .afterAction(DialogBase.DialogAfterAction.CLOSE) - .build() - ) - .type(DialogType.confirmation(toggleButton, closeButton)) - } + val toggleAction = + DialogAction.customClick( + DialogActionCallback { _, _ -> + drill.toggleEnabled() + }, + ClickCallback.Options.builder().build(), + ) + val toggleButton = + ActionButton.builder(Component.text(toggleLabel)) + .action(toggleAction) + .build() + + val closeAction = + DialogAction.customClick( + DialogActionCallback { _, audience -> + val p = audience as? Player ?: return@DialogActionCallback + onClose(p) + }, + ClickCallback.Options.builder().build(), + ) + val closeButton = + ActionButton.builder(Component.text("Close")) + .action(closeAction) + .build() + + val dialog = + Dialog.create { factory -> + factory.empty() + .base( + DialogBase.builder(title) + .body(listOf(body)) + .canCloseWithEscape(false) + .afterAction(DialogBase.DialogAfterAction.CLOSE) + .build(), + ) + .type(DialogType.confirmation(toggleButton, closeButton)) + } player.showDialog(dialog) } - private fun getBlockDisplayName(powerBlock: PowerBlock): String = when (powerBlock) { - is SmallSolarPanel -> "Small Solar Panel" - is SmallBattery -> "Small Battery" - is SmallDrill -> "Small Drill" - is PowerCable -> "Power Cable (${powerBlock.facing.name.lowercase().replaceFirstChar { it.uppercase() }})" - is LavaGenerator -> "Lava Generator" - is AutoSmelter -> "Auto Smelter (${powerBlock.facing.name.lowercase().replaceFirstChar { it.uppercase() }})" - is MultiPowerCable -> "Multi Power Cable (${powerBlock.facing.name.lowercase().replaceFirstChar { it.uppercase() }})" - is CobblestoneFactory -> "Cobblestone Factory" - is ObsidianFactory -> "Obsidian Factory" - is PowerMerger -> "Power Merger (${powerBlock.facing.name.lowercase().replaceFirstChar { it.uppercase() }})" - else -> "Power Block" - } + private fun getBlockDisplayName(powerBlock: PowerBlock): String = + when (powerBlock) { + is SmallSolarPanel -> "Small Solar Panel" + is SmallBattery -> "Small Battery" + is SmallDrill -> "Small Drill" + is PowerCable -> "Power Cable (${powerBlock.facing.name.lowercase().replaceFirstChar { it.uppercase() }})" + is LavaGenerator -> "Lava Generator" + is AutoSmelter -> "Auto Smelter (${powerBlock.facing.name.lowercase().replaceFirstChar { it.uppercase() }})" + is MultiPowerCable -> "Multi Power Cable (${powerBlock.facing.name.lowercase().replaceFirstChar { it.uppercase() }})" + is CobblestoneFactory -> "Cobblestone Factory" + is ObsidianFactory -> "Obsidian Factory" + is PowerMerger -> "Power Merger (${powerBlock.facing.name.lowercase().replaceFirstChar { it.uppercase() }})" + else -> "Power Block" + } private fun buildPowerInfo(powerBlock: PowerBlock): Component { - val ratio = if (powerBlock.maxStorage > 0) - powerBlock.currentPower.toFloat() / powerBlock.maxStorage - else 0f + val ratio = + if (powerBlock.maxStorage > 0) { + powerBlock.currentPower.toFloat() / powerBlock.maxStorage + } else { + 0f + } val barLength = 10 val filled = (ratio * barLength).toInt() val empty = barLength - filled - val barColor = when { - ratio >= 0.7f -> NamedTextColor.GREEN - ratio >= 0.3f -> NamedTextColor.YELLOW - else -> NamedTextColor.RED - } - - val bar = Component.text("[") - .color(NamedTextColor.GRAY) - .append(Component.text("\u2588".repeat(filled)).color(barColor)) - .append(Component.text("\u2591".repeat(empty)).color(NamedTextColor.DARK_GRAY)) - .append(Component.text("]").color(NamedTextColor.GRAY)) - .append(Component.text(" ${(ratio * 100).toInt()}%").color(barColor)) - - val powerLine = Component.text("Power: ${powerBlock.currentPower}/${powerBlock.maxStorage}") - .color(NamedTextColor.WHITE) - .decorate(TextDecoration.BOLD) + val barColor = + when { + ratio >= 0.7f -> NamedTextColor.GREEN + ratio >= 0.3f -> NamedTextColor.YELLOW + else -> NamedTextColor.RED + } - val infoLine = when (powerBlock) { - is SmallSolarPanel -> Component.text("Generator - produces 1 power/min during daytime") - .color(NamedTextColor.GRAY) - is SmallBattery -> Component.text("Storage - holds up to 10 power") + val bar = + Component.text("[") .color(NamedTextColor.GRAY) - is SmallDrill -> { - val directionName = powerBlock.miningDirection.name.lowercase().replaceFirstChar { it.uppercase() } - val status = if (powerBlock.enabled) "ON" else "OFF" - Component.text("Machine - mining $directionName, $status, consumes 10 power/s") - .color(NamedTextColor.GRAY) + .append(Component.text("\u2588".repeat(filled)).color(barColor)) + .append(Component.text("\u2591".repeat(empty)).color(NamedTextColor.DARK_GRAY)) + .append(Component.text("]").color(NamedTextColor.GRAY)) + .append(Component.text(" ${(ratio * 100).toInt()}%").color(barColor)) + + val powerLine = + Component.text("Power: ${powerBlock.currentPower}/${powerBlock.maxStorage}") + .color(NamedTextColor.WHITE) + .decorate(TextDecoration.BOLD) + + val infoLine = + when (powerBlock) { + is SmallSolarPanel -> + Component.text("Generator - produces 1 power/min during daytime") + .color(NamedTextColor.GRAY) + is SmallBattery -> + Component.text("Storage - holds up to 10 power") + .color(NamedTextColor.GRAY) + is SmallDrill -> { + val directionName = powerBlock.miningDirection.name.lowercase().replaceFirstChar { it.uppercase() } + val status = if (powerBlock.enabled) "ON" else "OFF" + Component.text("Machine - mining $directionName, $status, consumes 10 power/s") + .color(NamedTextColor.GRAY) + } + is PowerCable -> + Component.text("Cable - transfers power in facing direction") + .color(NamedTextColor.GRAY) + is LavaGenerator -> + Component.text("Generator - produces ${LavaGenerator.POWER_PER_LAVA} power per lava unit") + .color(NamedTextColor.GRAY) + is AutoSmelter -> + Component.text("Machine - smelts items passing through, consumes ${AutoSmelter.POWER_PER_SMELT} power/item") + .color(NamedTextColor.GRAY) + is MultiPowerCable -> + Component.text("Cable - distributes power to all adjacent faces") + .color(NamedTextColor.GRAY) + is CobblestoneFactory -> + Component.text("Machine - consumes ${CobblestoneFactory.POWER_COST} power + water + lava → cobblestone") + .color(NamedTextColor.GRAY) + is ObsidianFactory -> + Component.text("Machine - consumes ${ObsidianFactory.POWER_COST} power + water + lava → obsidian") + .color(NamedTextColor.GRAY) + is PowerMerger -> + Component.text("Cable - merges power from all sides, outputs in facing direction") + .color(NamedTextColor.GRAY) + else -> + Component.text("Power block") + .color(NamedTextColor.GRAY) } - is PowerCable -> Component.text("Cable - transfers power in facing direction") - .color(NamedTextColor.GRAY) - is LavaGenerator -> Component.text("Generator - produces ${LavaGenerator.POWER_PER_LAVA} power per lava unit") - .color(NamedTextColor.GRAY) - is AutoSmelter -> Component.text("Machine - smelts items passing through, consumes ${AutoSmelter.POWER_PER_SMELT} power/item") - .color(NamedTextColor.GRAY) - is MultiPowerCable -> Component.text("Cable - distributes power to all adjacent faces") - .color(NamedTextColor.GRAY) - is CobblestoneFactory -> Component.text("Machine - consumes ${CobblestoneFactory.POWER_COST} power + water + lava → cobblestone") - .color(NamedTextColor.GRAY) - is ObsidianFactory -> Component.text("Machine - consumes ${ObsidianFactory.POWER_COST} power + water + lava → obsidian") - .color(NamedTextColor.GRAY) - is PowerMerger -> Component.text("Cable - merges power from all sides, outputs in facing direction") - .color(NamedTextColor.GRAY) - else -> Component.text("Power block") - .color(NamedTextColor.GRAY) - } return powerLine .append(Component.newline()) diff --git a/src/main/kotlin/com/coderjoe/atlas/power/PowerBlockFactory.kt b/src/main/kotlin/com/coderjoe/atlas/power/PowerBlockFactory.kt index e8e20bf..ad59e9e 100644 --- a/src/main/kotlin/com/coderjoe/atlas/power/PowerBlockFactory.kt +++ b/src/main/kotlin/com/coderjoe/atlas/power/PowerBlockFactory.kt @@ -5,8 +5,11 @@ import org.bukkit.Location import org.bukkit.block.BlockFace object PowerBlockFactory : BlockFactory() { - - fun createPowerBlock(blockId: String, location: Location, facing: BlockFace = BlockFace.SELF): PowerBlock? { + fun createPowerBlock( + blockId: String, + location: Location, + facing: BlockFace = BlockFace.SELF, + ): PowerBlock? { return create(blockId, location, facing) } } diff --git a/src/main/kotlin/com/coderjoe/atlas/power/PowerBlockPersistence.kt b/src/main/kotlin/com/coderjoe/atlas/power/PowerBlockPersistence.kt index edfa771..b8c1fa8 100644 --- a/src/main/kotlin/com/coderjoe/atlas/power/PowerBlockPersistence.kt +++ b/src/main/kotlin/com/coderjoe/atlas/power/PowerBlockPersistence.kt @@ -5,31 +5,34 @@ import com.coderjoe.atlas.power.block.SmallDrill import org.bukkit.plugin.java.JavaPlugin class PowerBlockPersistence(plugin: JavaPlugin) { - private val persistence = BlockPersistence( - plugin = plugin, - fileName = "power_blocks.yml", - yamlKey = "power_blocks", - factory = PowerBlockFactory, - serialize = { block, _ -> - val map = mutableMapOf( - "currentPower" to block.currentPower - ) - if (block is SmallDrill) { - map["enabled"] = block.enabled - } - map - }, - restore = { block, data -> - block.currentPower = (data["currentPower"] as? Number)?.toInt() ?: 0 - if (block is SmallDrill) { - val enabled = data["enabled"] as? Boolean - if (enabled != null) { - block.enabled = enabled + private val persistence = + BlockPersistence( + plugin = plugin, + fileName = "power_blocks.yml", + yamlKey = "power_blocks", + factory = PowerBlockFactory, + serialize = { block, _ -> + val map = + mutableMapOf( + "currentPower" to block.currentPower, + ) + if (block is SmallDrill) { + map["enabled"] = block.enabled } - } - } - ) + map + }, + restore = { block, data -> + block.currentPower = (data["currentPower"] as? Number)?.toInt() ?: 0 + if (block is SmallDrill) { + val enabled = data["enabled"] as? Boolean + if (enabled != null) { + block.enabled = enabled + } + } + }, + ) fun save(registry: PowerBlockRegistry) = persistence.save(registry) + fun load(registry: PowerBlockRegistry) = persistence.load(registry) } diff --git a/src/main/kotlin/com/coderjoe/atlas/power/PowerBlockRegistry.kt b/src/main/kotlin/com/coderjoe/atlas/power/PowerBlockRegistry.kt index da1c0b9..683977b 100644 --- a/src/main/kotlin/com/coderjoe/atlas/power/PowerBlockRegistry.kt +++ b/src/main/kotlin/com/coderjoe/atlas/power/PowerBlockRegistry.kt @@ -6,7 +6,6 @@ import org.bukkit.block.BlockFace import org.bukkit.plugin.java.JavaPlugin class PowerBlockRegistry(plugin: JavaPlugin) : BlockRegistry(plugin) { - companion object { var instance: PowerBlockRegistry? = null private set @@ -18,13 +17,19 @@ class PowerBlockRegistry(plugin: JavaPlugin) : BlockRegistry(plugin) instance = this } - fun registerPowerBlock(powerBlock: PowerBlock, blockId: String) = register(powerBlock, blockId) + fun registerPowerBlock( + powerBlock: PowerBlock, + blockId: String, + ) = register(powerBlock, blockId) fun unregisterPowerBlock(location: Location): PowerBlock? = unregister(location) fun getPowerBlock(location: Location): PowerBlock? = getBlock(location) - fun getAdjacentPowerBlock(location: Location, face: BlockFace): PowerBlock? = getAdjacentBlock(location, face) + fun getAdjacentPowerBlock( + location: Location, + face: BlockFace, + ): PowerBlock? = getAdjacentBlock(location, face) fun getAdjacentPowerBlocks(location: Location): List = getAdjacentBlocks(location) diff --git a/src/main/kotlin/com/coderjoe/atlas/power/block/AutoSmelter.kt b/src/main/kotlin/com/coderjoe/atlas/power/block/AutoSmelter.kt index c6bc3da..60ae981 100644 --- a/src/main/kotlin/com/coderjoe/atlas/power/block/AutoSmelter.kt +++ b/src/main/kotlin/com/coderjoe/atlas/power/block/AutoSmelter.kt @@ -12,7 +12,6 @@ import org.bukkit.inventory.FurnaceRecipe import org.bukkit.inventory.ItemStack class AutoSmelter(location: Location, facing: BlockFace = BlockFace.NORTH) : PowerBlock(location, maxStorage = 2) { - override val canReceivePower: Boolean = true override val updateIntervalTicks: Long = 20L override val baseBlockId: String = BLOCK_ID @@ -26,38 +25,42 @@ class AutoSmelter(location: Location, facing: BlockFace = BlockFace.NORTH) : Pow const val POWER_PER_SMELT = 2 private const val MOVE_DISTANCE = 1.0 - val DIRECTIONAL_IDS = mapOf( - BlockFace.NORTH to "auto_smelter_north", - BlockFace.SOUTH to "auto_smelter_south", - BlockFace.EAST to "auto_smelter_east", - BlockFace.WEST to "auto_smelter_west" - ) - - val POWERED_IDS = mapOf( - BlockFace.NORTH to "auto_smelter_north_on", - BlockFace.SOUTH to "auto_smelter_south_on", - BlockFace.EAST to "auto_smelter_east_on", - BlockFace.WEST to "auto_smelter_west_on" - ) - - val ID_TO_FACING: Map = buildMap { - DIRECTIONAL_IDS.forEach { (face, id) -> put(id, face) } - POWERED_IDS.forEach { (face, id) -> put(id, face) } - } + val DIRECTIONAL_IDS = + mapOf( + BlockFace.NORTH to "auto_smelter_north", + BlockFace.SOUTH to "auto_smelter_south", + BlockFace.EAST to "auto_smelter_east", + BlockFace.WEST to "auto_smelter_west", + ) + + val POWERED_IDS = + mapOf( + BlockFace.NORTH to "auto_smelter_north_on", + BlockFace.SOUTH to "auto_smelter_south_on", + BlockFace.EAST to "auto_smelter_east_on", + BlockFace.WEST to "auto_smelter_west_on", + ) + + val ID_TO_FACING: Map = + buildMap { + DIRECTIONAL_IDS.forEach { (face, id) -> put(id, face) } + POWERED_IDS.forEach { (face, id) -> put(id, face) } + } val ALL_VARIANT_IDS: List = DIRECTIONAL_IDS.values.toList() + POWERED_IDS.values.toList() fun facingFromBlockId(blockId: String): BlockFace? = ID_TO_FACING[blockId] - val descriptor = BlockDescriptor( - baseBlockId = BLOCK_ID, - displayName = "Auto Smelter", - description = "Smelts items passing through, consumes 2 power per item", - placementType = PlacementType.DIRECTIONAL, - directionalVariants = DIRECTIONAL_IDS, - allRegistrableIds = ALL_VARIANT_IDS, - constructor = { loc, face -> AutoSmelter(loc, face) } - ) + val descriptor = + BlockDescriptor( + baseBlockId = BLOCK_ID, + displayName = "Auto Smelter", + description = "Smelts items passing through, consumes 2 power per item", + placementType = PlacementType.DIRECTIONAL, + directionalVariants = DIRECTIONAL_IDS, + allRegistrableIds = ALL_VARIANT_IDS, + constructor = { loc, face -> AutoSmelter(loc, face) }, + ) fun getSmeltingResult(input: ItemStack): ItemStack? { return try { @@ -99,8 +102,9 @@ class AutoSmelter(location: Location, facing: BlockFace = BlockFace.NORTH) : Pow // Scan for items on the belt surface (same as conveyor belt) val scanCenter = location.clone().add(0.5, 0.75, 0.5) - val nearbyItems = world.getNearbyEntities(scanCenter, 0.5, 0.75, 0.5) - .filterIsInstance() + val nearbyItems = + world.getNearbyEntities(scanCenter, 0.5, 0.75, 0.5) + .filterIsInstance() if (nearbyItems.isEmpty()) return diff --git a/src/main/kotlin/com/coderjoe/atlas/power/block/CobblestoneFactory.kt b/src/main/kotlin/com/coderjoe/atlas/power/block/CobblestoneFactory.kt index 29ea727..f6d3130 100644 --- a/src/main/kotlin/com/coderjoe/atlas/power/block/CobblestoneFactory.kt +++ b/src/main/kotlin/com/coderjoe/atlas/power/block/CobblestoneFactory.kt @@ -17,7 +17,6 @@ import org.bukkit.block.BlockFace import org.bukkit.inventory.ItemStack class CobblestoneFactory(location: Location) : PowerBlock(location, maxStorage = 2) { - override val canReceivePower: Boolean = true override val updateIntervalTicks: Long = 20L @@ -26,28 +25,35 @@ class CobblestoneFactory(location: Location) : PowerBlock(location, maxStorage = const val BLOCK_ID_ACTIVE = "cobblestone_factory_active" const val POWER_COST = 2 - private val ADJACENT_FACES = listOf( - BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, - BlockFace.WEST, BlockFace.UP, BlockFace.DOWN - ) - - val descriptor = BlockDescriptor( - baseBlockId = BLOCK_ID, - displayName = "Cobblestone Factory", - description = "Machine - consumes $POWER_COST power + water + lava → cobblestone", - placementType = PlacementType.SIMPLE, - directionalVariants = emptyMap(), - allRegistrableIds = listOf(BLOCK_ID, BLOCK_ID_ACTIVE), - constructor = { loc, _ -> CobblestoneFactory(loc) } - ) + private val ADJACENT_FACES = + listOf( + BlockFace.NORTH, + BlockFace.SOUTH, + BlockFace.EAST, + BlockFace.WEST, + BlockFace.UP, + BlockFace.DOWN, + ) + + val descriptor = + BlockDescriptor( + baseBlockId = BLOCK_ID, + displayName = "Cobblestone Factory", + description = "Machine - consumes $POWER_COST power + water + lava → cobblestone", + placementType = PlacementType.SIMPLE, + directionalVariants = emptyMap(), + allRegistrableIds = listOf(BLOCK_ID, BLOCK_ID_ACTIVE), + constructor = { loc, _ -> CobblestoneFactory(loc) }, + ) } override val baseBlockId: String = BLOCK_ID - override fun getVisualStateBlockId(): String = when { - currentPower >= POWER_COST -> BLOCK_ID_ACTIVE - else -> BLOCK_ID - } + override fun getVisualStateBlockId(): String = + when { + currentPower >= POWER_COST -> BLOCK_ID_ACTIVE + else -> BLOCK_ID + } override fun powerUpdate() { // Pull power from adjacent blocks @@ -97,7 +103,11 @@ class CobblestoneFactory(location: Location) : PowerBlock(location, maxStorage = plugin.logger.atlasInfo("CobblestoneFactory at ${location.blockX},${location.blockY},${location.blockZ} produced 1 cobblestone") } - private fun hasFluidAvailable(source: com.coderjoe.atlas.fluid.FluidBlock, face: BlockFace, fluidType: FluidType): Boolean { + private fun hasFluidAvailable( + source: com.coderjoe.atlas.fluid.FluidBlock, + face: BlockFace, + fluidType: FluidType, + ): Boolean { return when (source) { is FluidPump -> source.canRemoveFluidFrom(face.oppositeFace) && source.storedFluid == fluidType is FluidPipe -> source.hasFluid() && source.storedFluid == fluidType @@ -107,7 +117,10 @@ class CobblestoneFactory(location: Location) : PowerBlock(location, maxStorage = } } - private fun pullFluid(source: com.coderjoe.atlas.fluid.FluidBlock, face: BlockFace) { + private fun pullFluid( + source: com.coderjoe.atlas.fluid.FluidBlock, + face: BlockFace, + ) { when (source) { is FluidPump -> source.removeFluid() is FluidPipe -> source.removeFluid() diff --git a/src/main/kotlin/com/coderjoe/atlas/power/block/LavaGenerator.kt b/src/main/kotlin/com/coderjoe/atlas/power/block/LavaGenerator.kt index 53dd541..f63d4b4 100644 --- a/src/main/kotlin/com/coderjoe/atlas/power/block/LavaGenerator.kt +++ b/src/main/kotlin/com/coderjoe/atlas/power/block/LavaGenerator.kt @@ -14,7 +14,6 @@ import org.bukkit.Location import org.bukkit.block.BlockFace class LavaGenerator(location: Location) : PowerBlock(location, maxStorage = 50) { - override val canReceivePower: Boolean = false override val updateIntervalTicks: Long = 20L @@ -23,28 +22,35 @@ class LavaGenerator(location: Location) : PowerBlock(location, maxStorage = 50) const val BLOCK_ID_ACTIVE = "lava_generator_active" const val POWER_PER_LAVA = 5 - private val ADJACENT_FACES = listOf( - BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, - BlockFace.WEST, BlockFace.UP, BlockFace.DOWN - ) + private val ADJACENT_FACES = + listOf( + BlockFace.NORTH, + BlockFace.SOUTH, + BlockFace.EAST, + BlockFace.WEST, + BlockFace.UP, + BlockFace.DOWN, + ) - val descriptor = BlockDescriptor( - baseBlockId = BLOCK_ID, - displayName = "Lava Generator", - description = "Generator - produces $POWER_PER_LAVA power per lava unit", - placementType = PlacementType.SIMPLE, - directionalVariants = emptyMap(), - allRegistrableIds = listOf(BLOCK_ID, BLOCK_ID_ACTIVE), - constructor = { loc, _ -> LavaGenerator(loc) } - ) + val descriptor = + BlockDescriptor( + baseBlockId = BLOCK_ID, + displayName = "Lava Generator", + description = "Generator - produces $POWER_PER_LAVA power per lava unit", + placementType = PlacementType.SIMPLE, + directionalVariants = emptyMap(), + allRegistrableIds = listOf(BLOCK_ID, BLOCK_ID_ACTIVE), + constructor = { loc, _ -> LavaGenerator(loc) }, + ) } override val baseBlockId: String = BLOCK_ID - override fun getVisualStateBlockId(): String = when { - currentPower > 0 -> BLOCK_ID_ACTIVE - else -> BLOCK_ID - } + override fun getVisualStateBlockId(): String = + when { + currentPower > 0 -> BLOCK_ID_ACTIVE + else -> BLOCK_ID + } override fun powerUpdate() { if (currentPower >= maxStorage) return @@ -60,12 +66,19 @@ class LavaGenerator(location: Location) : PowerBlock(location, maxStorage = 50) val lava = tryPullLava(source, face) if (lava) { val generated = addPower(POWER_PER_LAVA) - plugin.logger.atlasInfo("LavaGenerator at ${location.blockX},${location.blockY},${location.blockZ} consumed 1 lava, generated $generated power (now $currentPower/$maxStorage)") + plugin.logger.atlasInfo( + """ + LavaGenerator at ${'$'}{location.blockX},${'$'}{location.blockY},${'$'}{location.blockZ} consumed 1 lava, generated ${'$'}generated power (now ${'$'}currentPower/${'$'}maxStorage) + """.trimIndent(), + ) } } } - private fun tryPullLava(source: com.coderjoe.atlas.fluid.FluidBlock, face: BlockFace): Boolean { + private fun tryPullLava( + source: com.coderjoe.atlas.fluid.FluidBlock, + face: BlockFace, + ): Boolean { when (source) { is FluidPump -> { if (source.canRemoveFluidFrom(face.oppositeFace) && source.storedFluid == FluidType.LAVA) { diff --git a/src/main/kotlin/com/coderjoe/atlas/power/block/MultiPowerCable.kt b/src/main/kotlin/com/coderjoe/atlas/power/block/MultiPowerCable.kt index db4cc5f..7a2299e 100644 --- a/src/main/kotlin/com/coderjoe/atlas/power/block/MultiPowerCable.kt +++ b/src/main/kotlin/com/coderjoe/atlas/power/block/MultiPowerCable.kt @@ -9,42 +9,46 @@ import org.bukkit.Location import org.bukkit.block.BlockFace class MultiPowerCable(location: Location, override val facing: BlockFace) : PowerBlock(location, maxStorage = 10) { - companion object { const val BLOCK_ID = "multi_power_cable" - val DIRECTIONAL_IDS = mapOf( - BlockFace.NORTH to "multi_power_cable_north", - BlockFace.SOUTH to "multi_power_cable_south", - BlockFace.EAST to "multi_power_cable_east", - BlockFace.WEST to "multi_power_cable_west", - BlockFace.UP to "multi_power_cable_up", - BlockFace.DOWN to "multi_power_cable_down" - ) - - val POWERED_IDS = mapOf( - BlockFace.NORTH to "multi_power_cable_north_powered", - BlockFace.SOUTH to "multi_power_cable_south_powered", - BlockFace.EAST to "multi_power_cable_east_powered", - BlockFace.WEST to "multi_power_cable_west_powered", - BlockFace.UP to "multi_power_cable_up_powered", - BlockFace.DOWN to "multi_power_cable_down_powered" + val DIRECTIONAL_IDS = + mapOf( + BlockFace.NORTH to "multi_power_cable_north", + BlockFace.SOUTH to "multi_power_cable_south", + BlockFace.EAST to "multi_power_cable_east", + BlockFace.WEST to "multi_power_cable_west", + BlockFace.UP to "multi_power_cable_up", + BlockFace.DOWN to "multi_power_cable_down", + ) + + val POWERED_IDS = + mapOf( + BlockFace.NORTH to "multi_power_cable_north_powered", + BlockFace.SOUTH to "multi_power_cable_south_powered", + BlockFace.EAST to "multi_power_cable_east_powered", + BlockFace.WEST to "multi_power_cable_west_powered", + BlockFace.UP to "multi_power_cable_up_powered", + BlockFace.DOWN to "multi_power_cable_down_powered", + ) + + val ID_TO_FACING = ( + DIRECTIONAL_IDS.entries.associate { (face, id) -> id to face } + + POWERED_IDS.entries.associate { (face, id) -> id to face } ) - val ID_TO_FACING = (DIRECTIONAL_IDS.entries.associate { (face, id) -> id to face } + - POWERED_IDS.entries.associate { (face, id) -> id to face }) - fun facingFromBlockId(blockId: String): BlockFace? = ID_TO_FACING[blockId] - val descriptor = BlockDescriptor( - baseBlockId = BLOCK_ID, - displayName = "Multi Power Cable", - description = "Cable - distributes power to all adjacent faces", - placementType = PlacementType.DIRECTIONAL, - directionalVariants = DIRECTIONAL_IDS, - allRegistrableIds = DIRECTIONAL_IDS.values.toList() + POWERED_IDS.values.toList(), - constructor = { loc, facing -> MultiPowerCable(loc, facing) } - ) + val descriptor = + BlockDescriptor( + baseBlockId = BLOCK_ID, + displayName = "Multi Power Cable", + description = "Cable - distributes power to all adjacent faces", + placementType = PlacementType.DIRECTIONAL, + directionalVariants = DIRECTIONAL_IDS, + allRegistrableIds = DIRECTIONAL_IDS.values.toList() + POWERED_IDS.values.toList(), + constructor = { loc, facing -> MultiPowerCable(loc, facing) }, + ) } override val baseBlockId: String = BLOCK_ID @@ -52,8 +56,11 @@ class MultiPowerCable(location: Location, override val facing: BlockFace) : Powe override val updateIntervalTicks: Long = 20L // 1 second override fun getVisualStateBlockId(): String = - if (currentPower > 0) POWERED_IDS[facing]!! - else DIRECTIONAL_IDS[facing]!! + if (currentPower > 0) { + POWERED_IDS[facing]!! + } else { + DIRECTIONAL_IDS[facing]!! + } override fun powerUpdate() { val registry = PowerBlockRegistry.instance ?: return @@ -66,15 +73,20 @@ class MultiPowerCable(location: Location, override val facing: BlockFace) : Powe val pulled = source.removePower(minOf(remaining, source.currentPower)) if (pulled > 0) { addPower(pulled) - plugin.logger.atlasInfo("MultiPowerCable at ${location.blockX},${location.blockY},${location.blockZ} pulled $pulled power (now $currentPower/$maxStorage)") + plugin.logger.atlasInfo( + """ + MultiPowerCable at ${location.blockX},${location.blockY},${location.blockZ} pulled $pulled power (now $currentPower/$maxStorage) + """.trimIndent(), + ) } } // Push 1 power to each adjacent power block on the other 5 faces if (!hasPower()) return - val outputFaces = listOf(BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST, BlockFace.UP, BlockFace.DOWN) - .filter { it != facing.oppositeFace } + val outputFaces = + listOf(BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST, BlockFace.UP, BlockFace.DOWN) + .filter { it != facing.oppositeFace } for (face in outputFaces) { if (!hasPower()) break @@ -83,7 +95,11 @@ class MultiPowerCable(location: Location, override val facing: BlockFace) : Powe val pushed = removePower(1) if (pushed > 0) { target.addPower(pushed) - plugin.logger.atlasInfo("MultiPowerCable at ${location.blockX},${location.blockY},${location.blockZ} pushed $pushed power to ${target::class.simpleName} at ${face.name}") + plugin.logger.atlasInfo( + """ + MultiPowerCable at ${location.blockX},${location.blockY},${location.blockZ} pushed $pushed power to ${target::class.simpleName} at ${face.name} + """.trimIndent(), + ) } } } diff --git a/src/main/kotlin/com/coderjoe/atlas/power/block/ObsidianFactory.kt b/src/main/kotlin/com/coderjoe/atlas/power/block/ObsidianFactory.kt index 15a784b..2fc36d0 100644 --- a/src/main/kotlin/com/coderjoe/atlas/power/block/ObsidianFactory.kt +++ b/src/main/kotlin/com/coderjoe/atlas/power/block/ObsidianFactory.kt @@ -17,7 +17,6 @@ import org.bukkit.block.BlockFace import org.bukkit.inventory.ItemStack class ObsidianFactory(location: Location) : PowerBlock(location, maxStorage = 100) { - override val canReceivePower: Boolean = true override val updateIntervalTicks: Long = 20L @@ -26,28 +25,35 @@ class ObsidianFactory(location: Location) : PowerBlock(location, maxStorage = 10 const val BLOCK_ID_ACTIVE = "obsidian_factory_active" const val POWER_COST = 100 - private val ADJACENT_FACES = listOf( - BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, - BlockFace.WEST, BlockFace.UP, BlockFace.DOWN - ) - - val descriptor = BlockDescriptor( - baseBlockId = BLOCK_ID, - displayName = "Obsidian Factory", - description = "Machine - consumes $POWER_COST power + water + lava → obsidian", - placementType = PlacementType.SIMPLE, - directionalVariants = emptyMap(), - allRegistrableIds = listOf(BLOCK_ID, BLOCK_ID_ACTIVE), - constructor = { loc, _ -> ObsidianFactory(loc) } - ) + private val ADJACENT_FACES = + listOf( + BlockFace.NORTH, + BlockFace.SOUTH, + BlockFace.EAST, + BlockFace.WEST, + BlockFace.UP, + BlockFace.DOWN, + ) + + val descriptor = + BlockDescriptor( + baseBlockId = BLOCK_ID, + displayName = "Obsidian Factory", + description = "Machine - consumes $POWER_COST power + water + lava → obsidian", + placementType = PlacementType.SIMPLE, + directionalVariants = emptyMap(), + allRegistrableIds = listOf(BLOCK_ID, BLOCK_ID_ACTIVE), + constructor = { loc, _ -> ObsidianFactory(loc) }, + ) } override val baseBlockId: String = BLOCK_ID - override fun getVisualStateBlockId(): String = when { - currentPower >= POWER_COST -> BLOCK_ID_ACTIVE - else -> BLOCK_ID - } + override fun getVisualStateBlockId(): String = + when { + currentPower >= POWER_COST -> BLOCK_ID_ACTIVE + else -> BLOCK_ID + } override fun powerUpdate() { // Pull power from adjacent blocks @@ -97,7 +103,11 @@ class ObsidianFactory(location: Location) : PowerBlock(location, maxStorage = 10 plugin.logger.atlasInfo("ObsidianFactory at ${location.blockX},${location.blockY},${location.blockZ} produced 1 obsidian") } - private fun hasFluidAvailable(source: com.coderjoe.atlas.fluid.FluidBlock, face: BlockFace, fluidType: FluidType): Boolean { + private fun hasFluidAvailable( + source: com.coderjoe.atlas.fluid.FluidBlock, + face: BlockFace, + fluidType: FluidType, + ): Boolean { return when (source) { is FluidPump -> source.canRemoveFluidFrom(face.oppositeFace) && source.storedFluid == fluidType is FluidPipe -> source.hasFluid() && source.storedFluid == fluidType @@ -107,7 +117,10 @@ class ObsidianFactory(location: Location) : PowerBlock(location, maxStorage = 10 } } - private fun pullFluid(source: com.coderjoe.atlas.fluid.FluidBlock, face: BlockFace) { + private fun pullFluid( + source: com.coderjoe.atlas.fluid.FluidBlock, + face: BlockFace, + ) { when (source) { is FluidPump -> source.removeFluid() is FluidPipe -> source.removeFluid() 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 0003dba..3826c46 100644 --- a/src/main/kotlin/com/coderjoe/atlas/power/block/PowerCable.kt +++ b/src/main/kotlin/com/coderjoe/atlas/power/block/PowerCable.kt @@ -9,41 +9,43 @@ import org.bukkit.Location import org.bukkit.block.BlockFace class PowerCable(location: Location, override val facing: BlockFace) : PowerBlock(location, maxStorage = 1) { - companion object { const val BLOCK_ID = "power_cable" - val DIRECTIONAL_IDS = mapOf( - BlockFace.NORTH to "power_cable_north", - BlockFace.SOUTH to "power_cable_south", - BlockFace.EAST to "power_cable_east", - BlockFace.WEST to "power_cable_west", - BlockFace.UP to "power_cable_up", - BlockFace.DOWN to "power_cable_down" - ) + val DIRECTIONAL_IDS = + mapOf( + BlockFace.NORTH to "power_cable_north", + BlockFace.SOUTH to "power_cable_south", + BlockFace.EAST to "power_cable_east", + BlockFace.WEST to "power_cable_west", + BlockFace.UP to "power_cable_up", + BlockFace.DOWN to "power_cable_down", + ) val ID_TO_FACING = DIRECTIONAL_IDS.entries.associate { (face, id) -> id to face } - val POWERED_IDS = mapOf( - BlockFace.NORTH to "power_cable_north_powered", - BlockFace.SOUTH to "power_cable_south_powered", - BlockFace.EAST to "power_cable_east_powered", - BlockFace.WEST to "power_cable_west_powered", - BlockFace.UP to "power_cable_up_powered", - BlockFace.DOWN to "power_cable_down_powered" - ) + val POWERED_IDS = + mapOf( + BlockFace.NORTH to "power_cable_north_powered", + BlockFace.SOUTH to "power_cable_south_powered", + BlockFace.EAST to "power_cable_east_powered", + BlockFace.WEST to "power_cable_west_powered", + BlockFace.UP to "power_cable_up_powered", + BlockFace.DOWN to "power_cable_down_powered", + ) fun facingFromBlockId(blockId: String): BlockFace? = ID_TO_FACING[blockId] - val descriptor = BlockDescriptor( - baseBlockId = BLOCK_ID, - displayName = "Power Cable", - description = "Cable - transfers power in facing direction", - placementType = PlacementType.DIRECTIONAL, - directionalVariants = DIRECTIONAL_IDS, - allRegistrableIds = DIRECTIONAL_IDS.values.toList(), - constructor = { loc, facing -> PowerCable(loc, facing) } - ) + val descriptor = + BlockDescriptor( + baseBlockId = BLOCK_ID, + displayName = "Power Cable", + description = "Cable - transfers power in facing direction", + placementType = PlacementType.DIRECTIONAL, + directionalVariants = DIRECTIONAL_IDS, + allRegistrableIds = DIRECTIONAL_IDS.values.toList(), + constructor = { loc, facing -> PowerCable(loc, facing) }, + ) } override val baseBlockId: String = BLOCK_ID @@ -51,8 +53,11 @@ class PowerCable(location: Location, override val facing: BlockFace) : PowerBloc override val updateIntervalTicks: Long = 20L // 1 second override fun getVisualStateBlockId(): String = - if (currentPower > 0) POWERED_IDS[facing]!! - else DIRECTIONAL_IDS[facing]!! + if (currentPower > 0) { + POWERED_IDS[facing]!! + } else { + DIRECTIONAL_IDS[facing]!! + } override fun powerUpdate() { val registry = PowerBlockRegistry.instance ?: return @@ -65,7 +70,11 @@ class PowerCable(location: Location, override val facing: BlockFace) : PowerBloc val pulled = source.removePower(1) if (pulled > 0) { addPower(pulled) - plugin.logger.atlasInfo("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) + """.trimIndent(), + ) } } } diff --git a/src/main/kotlin/com/coderjoe/atlas/power/block/PowerMerger.kt b/src/main/kotlin/com/coderjoe/atlas/power/block/PowerMerger.kt index 7b26ce3..58b8de1 100644 --- a/src/main/kotlin/com/coderjoe/atlas/power/block/PowerMerger.kt +++ b/src/main/kotlin/com/coderjoe/atlas/power/block/PowerMerger.kt @@ -9,59 +9,67 @@ import org.bukkit.Location import org.bukkit.block.BlockFace class PowerMerger(location: Location, override val facing: BlockFace) : PowerBlock(location, maxStorage = 2) { - override val canReceivePower: Boolean = false override val updateIntervalTicks: Long = 20L companion object { const val BLOCK_ID = "power_merger" - val DIRECTIONAL_IDS = mapOf( - BlockFace.NORTH to "power_merger_north", - BlockFace.SOUTH to "power_merger_south", - BlockFace.EAST to "power_merger_east", - BlockFace.WEST to "power_merger_west", - BlockFace.UP to "power_merger_up", - BlockFace.DOWN to "power_merger_down" - ) + val DIRECTIONAL_IDS = + mapOf( + BlockFace.NORTH to "power_merger_north", + BlockFace.SOUTH to "power_merger_south", + BlockFace.EAST to "power_merger_east", + BlockFace.WEST to "power_merger_west", + BlockFace.UP to "power_merger_up", + BlockFace.DOWN to "power_merger_down", + ) - val POWERED_IDS = mapOf( - BlockFace.NORTH to "power_merger_north_powered", - BlockFace.SOUTH to "power_merger_south_powered", - BlockFace.EAST to "power_merger_east_powered", - BlockFace.WEST to "power_merger_west_powered", - BlockFace.UP to "power_merger_up_powered", - BlockFace.DOWN to "power_merger_down_powered" - ) + val POWERED_IDS = + mapOf( + BlockFace.NORTH to "power_merger_north_powered", + BlockFace.SOUTH to "power_merger_south_powered", + BlockFace.EAST to "power_merger_east_powered", + BlockFace.WEST to "power_merger_west_powered", + BlockFace.UP to "power_merger_up_powered", + BlockFace.DOWN to "power_merger_down_powered", + ) - val ID_TO_FACING = (DIRECTIONAL_IDS.entries.associate { (face, id) -> id to face } + - POWERED_IDS.entries.associate { (face, id) -> id to face }) + val ID_TO_FACING = ( + DIRECTIONAL_IDS.entries.associate { (face, id) -> id to face } + + POWERED_IDS.entries.associate { (face, id) -> id to face } + ) fun facingFromBlockId(blockId: String): BlockFace? = ID_TO_FACING[blockId] - val descriptor = BlockDescriptor( - baseBlockId = BLOCK_ID, - displayName = "Power Merger", - description = "Cable - merges power from all sides, outputs in facing direction", - placementType = PlacementType.DIRECTIONAL, - directionalVariants = DIRECTIONAL_IDS, - allRegistrableIds = DIRECTIONAL_IDS.values.toList() + POWERED_IDS.values.toList(), - constructor = { loc, facing -> PowerMerger(loc, facing) } - ) + val descriptor = + BlockDescriptor( + baseBlockId = BLOCK_ID, + displayName = "Power Merger", + description = "Cable - merges power from all sides, outputs in facing direction", + placementType = PlacementType.DIRECTIONAL, + directionalVariants = DIRECTIONAL_IDS, + allRegistrableIds = DIRECTIONAL_IDS.values.toList() + POWERED_IDS.values.toList(), + constructor = { loc, facing -> PowerMerger(loc, facing) }, + ) } override val baseBlockId: String = BLOCK_ID override fun getVisualStateBlockId(): String = - if (currentPower > 0) POWERED_IDS[facing]!! - else DIRECTIONAL_IDS[facing]!! + if (currentPower > 0) { + POWERED_IDS[facing]!! + } else { + DIRECTIONAL_IDS[facing]!! + } override fun powerUpdate() { val registry = PowerBlockRegistry.instance ?: return // Pull power from all faces except the output (facing) direction - val inputFaces = listOf(BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST, BlockFace.UP, BlockFace.DOWN) - .filter { it != facing } + val inputFaces = + listOf(BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST, BlockFace.UP, BlockFace.DOWN) + .filter { it != facing } for (face in inputFaces) { if (currentPower >= maxStorage) break @@ -70,7 +78,11 @@ class PowerMerger(location: Location, override val facing: BlockFace) : PowerBlo val pulled = source.removePower(1) if (pulled > 0) { addPower(pulled) - plugin.logger.atlasInfo("PowerMerger at ${location.blockX},${location.blockY},${location.blockZ} pulled $pulled power from ${source::class.simpleName} at ${face.name} (now $currentPower/$maxStorage)") + plugin.logger.atlasInfo( + """ + PowerMerger at ${'$'}{location.blockX},${'$'}{location.blockY},${'$'}{location.blockZ} pulled ${'$'}pulled power from ${'$'}{source::class.simpleName} at ${'$'}{face.name} (now ${'$'}currentPower/${'$'}maxStorage) + """.trimIndent(), + ) } } } 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 54ec29f..2a6436e 100644 --- a/src/main/kotlin/com/coderjoe/atlas/power/block/SmallBattery.kt +++ b/src/main/kotlin/com/coderjoe/atlas/power/block/SmallBattery.kt @@ -9,7 +9,6 @@ import org.bukkit.Location import org.bukkit.block.BlockFace class SmallBattery(location: Location, facing: BlockFace) : PowerBlock(location, maxStorage = 10) { - override val facing: BlockFace = if (facing == BlockFace.SELF) BlockFace.DOWN else facing override val canReceivePower: Boolean = true @@ -18,37 +17,39 @@ class SmallBattery(location: Location, facing: BlockFace) : PowerBlock(location, companion object { const val BLOCK_ID = "small_battery" - val CHARGE_VARIANT_IDS = mapOf( - 0 to "small_battery", - 1 to "small_battery_low", - 2 to "small_battery_medium", - 3 to "small_battery_full" - ) + val CHARGE_VARIANT_IDS = + mapOf( + 0 to "small_battery", + 1 to "small_battery_low", + 2 to "small_battery_medium", + 3 to "small_battery_full", + ) val ALL_VARIANT_IDS: List = CHARGE_VARIANT_IDS.values.toList() - val descriptor = BlockDescriptor( - baseBlockId = BLOCK_ID, - displayName = "Small Battery", - description = "Storage - holds up to 10 power", - placementType = PlacementType.SIMPLE, - directionalVariants = emptyMap(), - allRegistrableIds = ALL_VARIANT_IDS, - constructor = { loc, facing -> SmallBattery(loc, facing) } - ) + val descriptor = + BlockDescriptor( + baseBlockId = BLOCK_ID, + displayName = "Small Battery", + description = "Storage - holds up to 10 power", + placementType = PlacementType.SIMPLE, + directionalVariants = emptyMap(), + allRegistrableIds = ALL_VARIANT_IDS, + constructor = { loc, facing -> SmallBattery(loc, facing) }, + ) } override val baseBlockId: String = BLOCK_ID - private fun chargeLevel(): Int = when (currentPower) { - 0 -> 0 - in 1..3 -> 1 - in 4..7 -> 2 - else -> 3 - } + private fun chargeLevel(): Int = + when (currentPower) { + 0 -> 0 + in 1..3 -> 1 + in 4..7 -> 2 + else -> 3 + } - override fun getVisualStateBlockId(): String = - CHARGE_VARIANT_IDS[chargeLevel()]!! + override fun getVisualStateBlockId(): String = CHARGE_VARIANT_IDS[chargeLevel()]!! override fun powerUpdate() { if (!canAcceptPower()) return @@ -61,7 +62,11 @@ class SmallBattery(location: Location, facing: BlockFace) : PowerBlock(location, val pulled = source.removePower(1) if (pulled > 0) { addPower(pulled) - plugin.logger.atlasInfo("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) + """.trimIndent(), + ) } } } diff --git a/src/main/kotlin/com/coderjoe/atlas/power/block/SmallDrill.kt b/src/main/kotlin/com/coderjoe/atlas/power/block/SmallDrill.kt index a58ff68..0f70016 100644 --- a/src/main/kotlin/com/coderjoe/atlas/power/block/SmallDrill.kt +++ b/src/main/kotlin/com/coderjoe/atlas/power/block/SmallDrill.kt @@ -9,7 +9,6 @@ import org.bukkit.Material import org.bukkit.block.BlockFace class SmallDrill(location: Location, facing: BlockFace? = null) : PowerBlock(location, maxStorage = 10) { - override val canReceivePower: Boolean = true override val updateIntervalTicks: Long = 20L @@ -20,33 +19,34 @@ class SmallDrill(location: Location, facing: BlockFace? = null) : PowerBlock(loc const val BLOCK_ID = "small_drill" private const val MAX_HORIZONTAL_RANGE = 64 - val DIRECTIONAL_IDS = mapOf( - BlockFace.NORTH to "small_drill_north", - BlockFace.SOUTH to "small_drill_south", - BlockFace.EAST to "small_drill_east", - BlockFace.WEST to "small_drill_west", - BlockFace.UP to "small_drill_up", - BlockFace.DOWN to "small_drill_down", - ) + val DIRECTIONAL_IDS = + mapOf( + BlockFace.NORTH to "small_drill_north", + BlockFace.SOUTH to "small_drill_south", + BlockFace.EAST to "small_drill_east", + BlockFace.WEST to "small_drill_west", + BlockFace.UP to "small_drill_up", + BlockFace.DOWN to "small_drill_down", + ) val ALL_DIRECTIONAL_IDS: List = DIRECTIONAL_IDS.values.toList() - val descriptor = BlockDescriptor( - baseBlockId = BLOCK_ID, - displayName = "Small Drill", - description = "Machine - consumes 10 power/s", - placementType = PlacementType.DIRECTIONAL_OPPOSITE, - directionalVariants = DIRECTIONAL_IDS, - allRegistrableIds = ALL_DIRECTIONAL_IDS, - constructor = { loc, facing -> SmallDrill(loc, facing) } - ) + val descriptor = + BlockDescriptor( + baseBlockId = BLOCK_ID, + displayName = "Small Drill", + description = "Machine - consumes 10 power/s", + placementType = PlacementType.DIRECTIONAL_OPPOSITE, + directionalVariants = DIRECTIONAL_IDS, + allRegistrableIds = ALL_DIRECTIONAL_IDS, + constructor = { loc, facing -> SmallDrill(loc, facing) }, + ) } override val baseBlockId: String = BLOCK_ID override val facing: BlockFace get() = miningDirection - override fun getVisualStateBlockId(): String = - DIRECTIONAL_IDS[miningDirection] ?: BLOCK_ID + override fun getVisualStateBlockId(): String = DIRECTIONAL_IDS[miningDirection] ?: BLOCK_ID fun toggleEnabled() { enabled = !enabled @@ -92,11 +92,12 @@ class SmallDrill(location: Location, facing: BlockFace? = null) : PowerBlock(loc val dz = miningDirection.modZ for (i in 1..MAX_HORIZONTAL_RANGE) { - val block = world.getBlockAt( - location.blockX + dx * i, - location.blockY, - location.blockZ + dz * i - ) + val block = + world.getBlockAt( + location.blockX + dx * i, + location.blockY, + location.blockZ + dz * i, + ) if (block.type == Material.AIR || block.type == Material.CAVE_AIR || block.type == Material.VOID_AIR) { continue 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 c5ec00a..9a70dda 100644 --- a/src/main/kotlin/com/coderjoe/atlas/power/block/SmallSolarPanel.kt +++ b/src/main/kotlin/com/coderjoe/atlas/power/block/SmallSolarPanel.kt @@ -5,33 +5,33 @@ import com.coderjoe.atlas.core.BlockDescriptor import com.coderjoe.atlas.core.PlacementType import com.coderjoe.atlas.power.PowerBlock import org.bukkit.Location -import org.bukkit.block.BlockFace - -class SmallSolarPanel(location: Location): PowerBlock(location, maxStorage = 1) { +class SmallSolarPanel(location: Location) : PowerBlock(location, maxStorage = 1) { override val canReceivePower: Boolean = false override val updateIntervalTicks: Long = 1200L companion object { const val BLOCK_ID = "small_solar_panel" - val descriptor = BlockDescriptor( - baseBlockId = BLOCK_ID, - displayName = "Small Solar Panel", - description = "Generator - produces 1 power/min during daytime", - placementType = PlacementType.SIMPLE, - directionalVariants = emptyMap(), - allRegistrableIds = listOf(BLOCK_ID), - constructor = { loc, _ -> SmallSolarPanel(loc) } - ) + val descriptor = + BlockDescriptor( + baseBlockId = BLOCK_ID, + displayName = "Small Solar Panel", + description = "Generator - produces 1 power/min during daytime", + placementType = PlacementType.SIMPLE, + directionalVariants = emptyMap(), + allRegistrableIds = listOf(BLOCK_ID), + constructor = { loc, _ -> SmallSolarPanel(loc) }, + ) } override val baseBlockId: String = BLOCK_ID - override fun getVisualStateBlockId(): String = when (currentPower) { - 0 -> "small_solar_panel" - else -> "small_solar_panel_full" - } + override fun getVisualStateBlockId(): String = + when (currentPower) { + 0 -> "small_solar_panel" + else -> "small_solar_panel_full" + } override fun powerUpdate() { val world = location.world ?: return @@ -40,12 +40,20 @@ class SmallSolarPanel(location: Location): PowerBlock(location, maxStorage = 1) if (isDaytime) { val generated = addPower(1) if (generated > 0) { - plugin.logger.atlasInfo("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) + """.trimIndent(), + ) } } else { - plugin.logger.atlasInfo("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. + """.trimIndent(), + ) } // TODO: Implement power transfer to connected blocks } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/coderjoe/atlas/transport/TransportBlock.kt b/src/main/kotlin/com/coderjoe/atlas/transport/TransportBlock.kt index 0b9bfd8..a3d5820 100644 --- a/src/main/kotlin/com/coderjoe/atlas/transport/TransportBlock.kt +++ b/src/main/kotlin/com/coderjoe/atlas/transport/TransportBlock.kt @@ -5,9 +5,8 @@ import com.coderjoe.atlas.core.BlockRegistry import org.bukkit.Location abstract class TransportBlock( - location: Location + location: Location, ) : AtlasBlock(location) { - protected abstract fun transportUpdate() override fun blockUpdate() { diff --git a/src/main/kotlin/com/coderjoe/atlas/transport/TransportBlockDialog.kt b/src/main/kotlin/com/coderjoe/atlas/transport/TransportBlockDialog.kt index 0fa5d60..fd2ecbb 100644 --- a/src/main/kotlin/com/coderjoe/atlas/transport/TransportBlockDialog.kt +++ b/src/main/kotlin/com/coderjoe/atlas/transport/TransportBlockDialog.kt @@ -17,12 +17,15 @@ import org.bukkit.entity.Player import org.bukkit.plugin.java.JavaPlugin object TransportBlockDialog { - fun init(plugin: JavaPlugin) { AtlasBlockDialog.init(plugin) } - fun showTransportDialog(player: Player, block: TransportBlock, registry: BlockRegistry<*>) { + fun showTransportDialog( + player: Player, + block: TransportBlock, + registry: BlockRegistry<*>, + ) { AtlasBlockDialog.showDialog(player, block, registry) { p, b, onClose -> sendDialog(p, b as TransportBlock, onClose) } @@ -32,47 +35,58 @@ object TransportBlockDialog { AtlasBlockDialog.cleanup() } - private fun sendDialog(player: Player, block: TransportBlock, onClose: (Player) -> Unit) { + private fun sendDialog( + player: Player, + block: TransportBlock, + onClose: (Player) -> Unit, + ) { val title = Component.text(getBlockDisplayName(block)) val bodyText = getBlockDescription(block) val body = DialogBody.plainMessage(bodyText) - val closeAction = DialogAction.customClick( - DialogActionCallback { _, audience -> - val p = audience as? Player ?: return@DialogActionCallback - onClose(p) - }, - ClickCallback.Options.builder().build() - ) + val closeAction = + DialogAction.customClick( + DialogActionCallback { _, audience -> + val p = audience as? Player ?: return@DialogActionCallback + onClose(p) + }, + ClickCallback.Options.builder().build(), + ) - val closeButton = ActionButton.builder(Component.text("Close")) - .action(closeAction) - .build() + val closeButton = + ActionButton.builder(Component.text("Close")) + .action(closeAction) + .build() - val dialog = Dialog.create { factory -> - factory.empty() - .base( - DialogBase.builder(title) - .body(listOf(body)) - .canCloseWithEscape(false) - .afterAction(DialogBase.DialogAfterAction.CLOSE) - .build() - ) - .type(DialogType.notice(closeButton)) - } + val dialog = + Dialog.create { factory -> + factory.empty() + .base( + DialogBase.builder(title) + .body(listOf(body)) + .canCloseWithEscape(false) + .afterAction(DialogBase.DialogAfterAction.CLOSE) + .build(), + ) + .type(DialogType.notice(closeButton)) + } player.showDialog(dialog) } - private fun getBlockDisplayName(block: TransportBlock): String = when (block) { - is ConveyorBelt -> "Conveyor Belt (${block.facing.name.lowercase().replaceFirstChar { it.uppercase() }})" - else -> "Transport Block" - } + private fun getBlockDisplayName(block: TransportBlock): String = + when (block) { + is ConveyorBelt -> "Conveyor Belt (${block.facing.name.lowercase().replaceFirstChar { it.uppercase() }})" + else -> "Transport Block" + } - private fun getBlockDescription(block: TransportBlock): Component = when (block) { - is ConveyorBelt -> Component.text("Moves items forward 1 block every second") - .color(NamedTextColor.GRAY) - else -> Component.text("Transport block") - .color(NamedTextColor.GRAY) - } + private fun getBlockDescription(block: TransportBlock): Component = + when (block) { + is ConveyorBelt -> + Component.text("Moves items forward 1 block every second") + .color(NamedTextColor.GRAY) + else -> + Component.text("Transport block") + .color(NamedTextColor.GRAY) + } } diff --git a/src/main/kotlin/com/coderjoe/atlas/transport/TransportBlockFactory.kt b/src/main/kotlin/com/coderjoe/atlas/transport/TransportBlockFactory.kt index ad47df5..f562013 100644 --- a/src/main/kotlin/com/coderjoe/atlas/transport/TransportBlockFactory.kt +++ b/src/main/kotlin/com/coderjoe/atlas/transport/TransportBlockFactory.kt @@ -5,8 +5,11 @@ import org.bukkit.Location import org.bukkit.block.BlockFace object TransportBlockFactory : BlockFactory() { - - fun createTransportBlock(blockId: String, location: Location, facing: BlockFace = BlockFace.SELF): TransportBlock? { + fun createTransportBlock( + blockId: String, + location: Location, + facing: BlockFace = BlockFace.SELF, + ): TransportBlock? { return create(blockId, location, facing) } } diff --git a/src/main/kotlin/com/coderjoe/atlas/transport/TransportBlockPersistence.kt b/src/main/kotlin/com/coderjoe/atlas/transport/TransportBlockPersistence.kt index 06af196..8571180 100644 --- a/src/main/kotlin/com/coderjoe/atlas/transport/TransportBlockPersistence.kt +++ b/src/main/kotlin/com/coderjoe/atlas/transport/TransportBlockPersistence.kt @@ -4,15 +4,17 @@ import com.coderjoe.atlas.core.BlockPersistence import org.bukkit.plugin.java.JavaPlugin class TransportBlockPersistence(plugin: JavaPlugin) { - private val persistence = BlockPersistence( - plugin = plugin, - fileName = "transport_blocks.yml", - yamlKey = "transport_blocks", - factory = TransportBlockFactory, - serialize = { _, _ -> emptyMap() }, - restore = { _, _ -> } - ) + private val persistence = + BlockPersistence( + plugin = plugin, + fileName = "transport_blocks.yml", + yamlKey = "transport_blocks", + factory = TransportBlockFactory, + serialize = { _, _ -> emptyMap() }, + restore = { _, _ -> }, + ) fun save(registry: TransportBlockRegistry) = persistence.save(registry) + fun load(registry: TransportBlockRegistry) = persistence.load(registry) } diff --git a/src/main/kotlin/com/coderjoe/atlas/transport/TransportBlockRegistry.kt b/src/main/kotlin/com/coderjoe/atlas/transport/TransportBlockRegistry.kt index 36bfbe0..5c93db1 100644 --- a/src/main/kotlin/com/coderjoe/atlas/transport/TransportBlockRegistry.kt +++ b/src/main/kotlin/com/coderjoe/atlas/transport/TransportBlockRegistry.kt @@ -6,7 +6,6 @@ import org.bukkit.block.BlockFace import org.bukkit.plugin.java.JavaPlugin class TransportBlockRegistry(plugin: JavaPlugin) : BlockRegistry(plugin) { - companion object { var instance: TransportBlockRegistry? = null private set @@ -18,13 +17,19 @@ class TransportBlockRegistry(plugin: JavaPlugin) : BlockRegistry instance = this } - fun registerTransportBlock(block: TransportBlock, blockId: String) = register(block, blockId) + fun registerTransportBlock( + block: TransportBlock, + blockId: String, + ) = register(block, blockId) fun unregisterTransportBlock(location: Location): TransportBlock? = unregister(location) fun getTransportBlock(location: Location): TransportBlock? = getBlock(location) - fun getAdjacentTransportBlock(location: Location, face: BlockFace): TransportBlock? = getAdjacentBlock(location, face) + fun getAdjacentTransportBlock( + location: Location, + face: BlockFace, + ): TransportBlock? = getAdjacentBlock(location, face) fun getAllTransportBlocksWithIds(): List> = getAllBlocksWithIds() } diff --git a/src/main/kotlin/com/coderjoe/atlas/transport/block/ConveyorBelt.kt b/src/main/kotlin/com/coderjoe/atlas/transport/block/ConveyorBelt.kt index 5f8fd08..ad76572 100644 --- a/src/main/kotlin/com/coderjoe/atlas/transport/block/ConveyorBelt.kt +++ b/src/main/kotlin/com/coderjoe/atlas/transport/block/ConveyorBelt.kt @@ -8,31 +8,32 @@ import org.bukkit.block.BlockFace import org.bukkit.entity.Item class ConveyorBelt(location: Location, override val facing: BlockFace) : TransportBlock(location) { - companion object { const val BLOCK_ID = "conveyor_belt" private const val MOVE_DISTANCE = 1.0 - val DIRECTIONAL_IDS = mapOf( - BlockFace.NORTH to "conveyor_belt_north", - BlockFace.SOUTH to "conveyor_belt_south", - BlockFace.EAST to "conveyor_belt_east", - BlockFace.WEST to "conveyor_belt_west" - ) + val DIRECTIONAL_IDS = + mapOf( + BlockFace.NORTH to "conveyor_belt_north", + BlockFace.SOUTH to "conveyor_belt_south", + BlockFace.EAST to "conveyor_belt_east", + BlockFace.WEST to "conveyor_belt_west", + ) val ID_TO_FACING = DIRECTIONAL_IDS.entries.associate { (face, id) -> id to face } fun facingFromBlockId(blockId: String): BlockFace? = ID_TO_FACING[blockId] - val descriptor = BlockDescriptor( - baseBlockId = BLOCK_ID, - displayName = "Conveyor Belt", - description = "Moves items forward in the facing direction", - placementType = PlacementType.DIRECTIONAL, - directionalVariants = DIRECTIONAL_IDS, - allRegistrableIds = DIRECTIONAL_IDS.values.toList(), - constructor = { loc, face -> ConveyorBelt(loc, face) } - ) + val descriptor = + BlockDescriptor( + baseBlockId = BLOCK_ID, + displayName = "Conveyor Belt", + description = "Moves items forward in the facing direction", + placementType = PlacementType.DIRECTIONAL, + directionalVariants = DIRECTIONAL_IDS, + allRegistrableIds = DIRECTIONAL_IDS.values.toList(), + constructor = { loc, face -> ConveyorBelt(loc, face) }, + ) } override val baseBlockId: String = BLOCK_ID @@ -46,8 +47,9 @@ class ConveyorBelt(location: Location, override val facing: BlockFace) : Transpo // Belt surface is at y + 6/16 (0.375), scan items resting on top val scanCenter = location.clone().add(0.5, 0.75, 0.5) - val nearbyItems = world.getNearbyEntities(scanCenter, 0.5, 0.75, 0.5) - .filterIsInstance() + val nearbyItems = + world.getNearbyEntities(scanCenter, 0.5, 0.75, 0.5) + .filterIsInstance() if (nearbyItems.isEmpty()) return diff --git a/src/test/kotlin/com/coderjoe/atlas/AtlasPluginTest.kt b/src/test/kotlin/com/coderjoe/atlas/AtlasPluginTest.kt index 37b989b..67a967b 100644 --- a/src/test/kotlin/com/coderjoe/atlas/AtlasPluginTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/AtlasPluginTest.kt @@ -9,11 +9,15 @@ import com.coderjoe.atlas.power.PowerBlockRegistry import com.coderjoe.atlas.transport.TransportBlockDialog import com.coderjoe.atlas.transport.TransportBlockFactory import com.coderjoe.atlas.transport.TransportBlockRegistry -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertDoesNotThrow +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotNull +import org.junit.jupiter.api.Assertions.assertSame +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class AtlasPluginTest { - @BeforeEach fun setup() { TestHelper.setup() diff --git a/src/test/kotlin/com/coderjoe/atlas/CrossSystemIntegrationTest.kt b/src/test/kotlin/com/coderjoe/atlas/CrossSystemIntegrationTest.kt index 216ea37..2247261 100644 --- a/src/test/kotlin/com/coderjoe/atlas/CrossSystemIntegrationTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/CrossSystemIntegrationTest.kt @@ -15,11 +15,13 @@ import org.bukkit.Material import org.bukkit.block.Block import org.bukkit.block.BlockFace import org.bukkit.block.data.Levelled -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class CrossSystemIntegrationTest { - private lateinit var powerRegistry: PowerBlockRegistry private lateinit var fluidRegistry: FluidBlockRegistry diff --git a/src/test/kotlin/com/coderjoe/atlas/NexoIntegrationTest.kt b/src/test/kotlin/com/coderjoe/atlas/NexoIntegrationTest.kt index 191c530..e6a3ac1 100644 --- a/src/test/kotlin/com/coderjoe/atlas/NexoIntegrationTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/NexoIntegrationTest.kt @@ -1,12 +1,13 @@ package com.coderjoe.atlas -import io.mockk.* -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import io.mockk.every +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertDoesNotThrow +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test import java.io.File class NexoIntegrationTest { - @BeforeEach fun setup() { TestHelper.setup() diff --git a/src/test/kotlin/com/coderjoe/atlas/PlayerJoinListenerTest.kt b/src/test/kotlin/com/coderjoe/atlas/PlayerJoinListenerTest.kt index a489107..4e1ae76 100644 --- a/src/test/kotlin/com/coderjoe/atlas/PlayerJoinListenerTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/PlayerJoinListenerTest.kt @@ -1,12 +1,15 @@ package com.coderjoe.atlas -import io.mockk.* +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify import org.bukkit.entity.Player import org.bukkit.event.player.PlayerJoinEvent -import org.junit.jupiter.api.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class PlayerJoinListenerTest { - @BeforeEach fun setup() { TestHelper.setup() diff --git a/src/test/kotlin/com/coderjoe/atlas/ResourcePackManagerTest.kt b/src/test/kotlin/com/coderjoe/atlas/ResourcePackManagerTest.kt index 991303e..781ead9 100644 --- a/src/test/kotlin/com/coderjoe/atlas/ResourcePackManagerTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/ResourcePackManagerTest.kt @@ -1,14 +1,18 @@ package com.coderjoe.atlas -import io.mockk.* +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify import net.kyori.adventure.resource.ResourcePackRequest import org.bukkit.configuration.file.YamlConfiguration import org.bukkit.entity.Player -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class ResourcePackManagerTest { - @BeforeEach fun setup() { TestHelper.setup() @@ -19,7 +23,11 @@ class ResourcePackManagerTest { TestHelper.teardown() } - private fun createManagerWithConfig(enabled: Boolean, url: String = "", hash: String = ""): ResourcePackManager { + private fun createManagerWithConfig( + enabled: Boolean, + url: String = "", + hash: String = "", + ): ResourcePackManager { val config = YamlConfiguration() config.set("resource-pack.enabled", enabled) config.set("resource-pack.url", url) diff --git a/src/test/kotlin/com/coderjoe/atlas/TestHelper.kt b/src/test/kotlin/com/coderjoe/atlas/TestHelper.kt index 18aa10a..14f7428 100644 --- a/src/test/kotlin/com/coderjoe/atlas/TestHelper.kt +++ b/src/test/kotlin/com/coderjoe/atlas/TestHelper.kt @@ -6,27 +6,29 @@ import com.coderjoe.atlas.fluid.FluidBlock import com.coderjoe.atlas.fluid.FluidBlockFactory import com.coderjoe.atlas.fluid.FluidBlockRegistry import com.coderjoe.atlas.fluid.block.FluidContainer -import com.coderjoe.atlas.fluid.block.FluidPipe import com.coderjoe.atlas.fluid.block.FluidMerger +import com.coderjoe.atlas.fluid.block.FluidPipe import com.coderjoe.atlas.fluid.block.FluidPump import com.coderjoe.atlas.power.PowerBlock import com.coderjoe.atlas.power.PowerBlockFactory import com.coderjoe.atlas.power.PowerBlockRegistry -import com.coderjoe.atlas.transport.TransportBlock -import com.coderjoe.atlas.transport.TransportBlockFactory -import com.coderjoe.atlas.transport.TransportBlockRegistry -import com.coderjoe.atlas.transport.block.ConveyorBelt import com.coderjoe.atlas.power.block.AutoSmelter +import com.coderjoe.atlas.power.block.CobblestoneFactory import com.coderjoe.atlas.power.block.LavaGenerator -import com.coderjoe.atlas.power.block.PowerCable -import com.coderjoe.atlas.power.block.SmallBattery -import com.coderjoe.atlas.power.block.SmallDrill import com.coderjoe.atlas.power.block.MultiPowerCable -import com.coderjoe.atlas.power.block.CobblestoneFactory import com.coderjoe.atlas.power.block.ObsidianFactory +import com.coderjoe.atlas.power.block.PowerCable import com.coderjoe.atlas.power.block.PowerMerger +import com.coderjoe.atlas.power.block.SmallBattery +import com.coderjoe.atlas.power.block.SmallDrill import com.coderjoe.atlas.power.block.SmallSolarPanel -import io.mockk.* +import com.coderjoe.atlas.transport.TransportBlock +import com.coderjoe.atlas.transport.TransportBlockFactory +import com.coderjoe.atlas.transport.TransportBlockRegistry +import com.coderjoe.atlas.transport.block.ConveyorBelt +import io.mockk.every +import io.mockk.mockk +import io.mockk.unmockkAll import org.bukkit.Location import org.bukkit.Server import org.bukkit.World @@ -37,7 +39,6 @@ import java.io.File import java.util.logging.Logger object TestHelper { - lateinit var mockPlugin: Atlas lateinit var mockServer: Server lateinit var mockWorld: World @@ -82,7 +83,12 @@ object TestHelper { dataFolder.deleteRecursively() } - fun createLocation(x: Double = 0.0, y: Double = 64.0, z: Double = 0.0, world: World? = null): Location { + fun createLocation( + x: Double = 0.0, + y: Double = 64.0, + z: Double = 0.0, + world: World? = null, + ): Location { return Location(world ?: mockWorld, x, y, z) } @@ -104,7 +110,11 @@ object TestHelper { method.invoke(this) } - fun addToRegistry(registry: PowerBlockRegistry, block: PowerBlock, blockId: String) { + fun addToRegistry( + registry: PowerBlockRegistry, + block: PowerBlock, + blockId: String, + ) { val blocksField = BlockRegistry::class.java.getDeclaredField("blocks") blocksField.isAccessible = true @Suppress("UNCHECKED_CAST") @@ -120,7 +130,11 @@ object TestHelper { blockIds[key] = blockId } - fun addToRegistry(registry: TransportBlockRegistry, block: TransportBlock, blockId: String) { + fun addToRegistry( + registry: TransportBlockRegistry, + block: TransportBlock, + blockId: String, + ) { val blocksField = BlockRegistry::class.java.getDeclaredField("blocks") blocksField.isAccessible = true @Suppress("UNCHECKED_CAST") @@ -136,7 +150,11 @@ object TestHelper { blockIds[key] = blockId } - fun addToRegistry(registry: FluidBlockRegistry, block: FluidBlock, blockId: String) { + fun addToRegistry( + registry: FluidBlockRegistry, + block: FluidBlock, + blockId: String, + ) { val blocksField = BlockRegistry::class.java.getDeclaredField("blocks") blocksField.isAccessible = true @Suppress("UNCHECKED_CAST") @@ -157,42 +175,53 @@ object TestHelper { val instanceField = PowerBlockRegistry.Companion::class.java.getDeclaredField("instance") instanceField.isAccessible = true instanceField.set(PowerBlockRegistry.Companion, null) - } catch (_: Exception) {} + } catch (_: Exception) { + } try { val instanceField = FluidBlockRegistry.Companion::class.java.getDeclaredField("instance") instanceField.isAccessible = true instanceField.set(FluidBlockRegistry.Companion, null) - } catch (_: Exception) {} + } catch (_: Exception) { + } try { val instanceField = TransportBlockRegistry.Companion::class.java.getDeclaredField("instance") instanceField.isAccessible = true instanceField.set(TransportBlockRegistry.Companion, null) - } catch (_: Exception) {} + } catch (_: Exception) { + } } fun initPowerFactory() { - PowerBlockFactory.registerFromDescriptors(listOf( - SmallSolarPanel.descriptor, SmallDrill.descriptor, - SmallBattery.descriptor, PowerCable.descriptor, - LavaGenerator.descriptor, AutoSmelter.descriptor, - MultiPowerCable.descriptor, CobblestoneFactory.descriptor, - ObsidianFactory.descriptor, PowerMerger.descriptor - )) + PowerBlockFactory.registerFromDescriptors( + listOf( + SmallSolarPanel.descriptor, SmallDrill.descriptor, + SmallBattery.descriptor, PowerCable.descriptor, + LavaGenerator.descriptor, AutoSmelter.descriptor, + MultiPowerCable.descriptor, CobblestoneFactory.descriptor, + ObsidianFactory.descriptor, PowerMerger.descriptor, + ), + ) } fun initFluidFactory() { - FluidBlockFactory.registerFromDescriptors(listOf( - FluidPump.descriptor, FluidPipe.descriptor, - FluidContainer.descriptor, FluidMerger.descriptor - )) + FluidBlockFactory.registerFromDescriptors( + listOf( + FluidPump.descriptor, + FluidPipe.descriptor, + FluidContainer.descriptor, + FluidMerger.descriptor, + ), + ) } fun initTransportFactory() { - TransportBlockFactory.registerFromDescriptors(listOf( - ConveyorBelt.descriptor - )) + TransportBlockFactory.registerFromDescriptors( + listOf( + ConveyorBelt.descriptor, + ), + ) } private fun clearFactories() { diff --git a/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockDataTest.kt b/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockDataTest.kt index a1f81d3..f594f10 100644 --- a/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockDataTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockDataTest.kt @@ -4,11 +4,14 @@ import com.coderjoe.atlas.TestHelper import com.coderjoe.atlas.fluid.block.FluidPipe import com.coderjoe.atlas.fluid.block.FluidPump import org.bukkit.block.BlockFace -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotNull +import org.junit.jupiter.api.Assertions.assertNull +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class FluidBlockDataTest { - @BeforeEach fun setup() { TestHelper.setup() diff --git a/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockDialogTest.kt b/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockDialogTest.kt index 8df9c9b..97d0187 100644 --- a/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockDialogTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockDialogTest.kt @@ -7,11 +7,15 @@ import com.coderjoe.atlas.fluid.block.FluidPump import net.kyori.adventure.text.Component import net.kyori.adventure.text.TextComponent import org.bukkit.block.BlockFace -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertDoesNotThrow +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class FluidBlockDialogTest { - @BeforeEach fun setup() { TestHelper.setup() diff --git a/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockFactoryTest.kt b/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockFactoryTest.kt index 5979da6..0e31271 100644 --- a/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockFactoryTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockFactoryTest.kt @@ -3,12 +3,16 @@ package com.coderjoe.atlas.fluid import com.coderjoe.atlas.TestHelper import com.coderjoe.atlas.fluid.block.FluidPipe import com.coderjoe.atlas.fluid.block.FluidPump -import org.bukkit.block.BlockFace -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertNotNull +import org.junit.jupiter.api.Assertions.assertNull +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class FluidBlockFactoryTest { - @BeforeEach fun setup() { TestHelper.setup() diff --git a/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockInitializerTest.kt b/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockInitializerTest.kt index 23fcd5f..f63d5b3 100644 --- a/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockInitializerTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockInitializerTest.kt @@ -4,11 +4,13 @@ import com.coderjoe.atlas.TestHelper import com.coderjoe.atlas.fluid.block.FluidPipe import com.coderjoe.atlas.fluid.block.FluidPump import org.bukkit.block.BlockFace -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* - -class FluidBlockRegistrationTest { +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +class FluidBlockInitializerTest { @BeforeEach fun setup() { TestHelper.setup() diff --git a/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockListenerTest.kt b/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockListenerTest.kt index 785c848..9bffad3 100644 --- a/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockListenerTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockListenerTest.kt @@ -4,7 +4,9 @@ import com.coderjoe.atlas.TestHelper import com.coderjoe.atlas.core.AtlasBlockListener import com.coderjoe.atlas.core.BlockSystem import com.coderjoe.atlas.fluid.block.FluidPump -import io.mockk.* +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify import org.bukkit.block.Block import org.bukkit.block.BlockFace import org.bukkit.entity.Player @@ -12,11 +14,14 @@ import org.bukkit.event.block.Action import org.bukkit.event.block.BlockBreakEvent import org.bukkit.event.block.BlockPlaceEvent import org.bukkit.event.player.PlayerInteractEvent -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertDoesNotThrow +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNull +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class FluidBlockListenerTest { - private lateinit var registry: FluidBlockRegistry private lateinit var listener: AtlasBlockListener @@ -24,13 +29,14 @@ class FluidBlockListenerTest { fun setup() { TestHelper.setup() registry = FluidBlockRegistry(TestHelper.mockPlugin) - val system = BlockSystem( - name = "fluid", - registry = registry, - factory = FluidBlockFactory, - descriptors = emptyMap(), - showDialog = { _, _ -> } - ) + val system = + BlockSystem( + name = "fluid", + registry = registry, + factory = FluidBlockFactory, + descriptors = emptyMap(), + showDialog = { _, _ -> }, + ) listener = AtlasBlockListener(TestHelper.mockPlugin, listOf(system)) } @@ -82,8 +88,9 @@ class FluidBlockListenerTest { try { listener.onBlockBreak(event) - } catch (_: NoClassDefFoundError) {} - catch (_: ExceptionInInitializerError) {} + } catch (_: NoClassDefFoundError) { + } catch (_: ExceptionInInitializerError) { + } assertNull(registry.getFluidBlock(loc)) } diff --git a/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockLogicTest.kt b/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockLogicTest.kt index 8f0e163..0a9be62 100644 --- a/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockLogicTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockLogicTest.kt @@ -12,11 +12,15 @@ import org.bukkit.Material import org.bukkit.block.Block import org.bukkit.block.BlockFace import org.bukkit.block.data.Levelled -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertNull +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class FluidBlockLogicTest { - @BeforeEach fun setup() { TestHelper.setup() diff --git a/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockPersistenceTest.kt b/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockPersistenceTest.kt index 6cf6a8e..0d62e26 100644 --- a/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockPersistenceTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockPersistenceTest.kt @@ -4,12 +4,14 @@ import com.coderjoe.atlas.TestHelper import com.coderjoe.atlas.fluid.block.FluidPipe import com.coderjoe.atlas.fluid.block.FluidPump import org.bukkit.block.BlockFace -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* -import java.io.File +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertDoesNotThrow +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class FluidBlockPersistenceTest { - private lateinit var registry: FluidBlockRegistry private lateinit var persistence: FluidBlockPersistence diff --git a/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockRegistryTest.kt b/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockRegistryTest.kt index 0af2513..4b545be 100644 --- a/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockRegistryTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/fluid/FluidBlockRegistryTest.kt @@ -4,11 +4,15 @@ import com.coderjoe.atlas.TestHelper import com.coderjoe.atlas.fluid.block.FluidPipe import com.coderjoe.atlas.fluid.block.FluidPump import org.bukkit.block.BlockFace -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNull +import org.junit.jupiter.api.Assertions.assertSame +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class FluidBlockRegistryTest { - private lateinit var registry: FluidBlockRegistry @BeforeEach diff --git a/src/test/kotlin/com/coderjoe/atlas/fluid/FluidContainerTest.kt b/src/test/kotlin/com/coderjoe/atlas/fluid/FluidContainerTest.kt index 0fa6c78..7ddd834 100644 --- a/src/test/kotlin/com/coderjoe/atlas/fluid/FluidContainerTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/fluid/FluidContainerTest.kt @@ -6,11 +6,15 @@ import com.coderjoe.atlas.fluid.block.FluidContainer import com.coderjoe.atlas.fluid.block.FluidPipe import com.coderjoe.atlas.fluid.block.FluidPump import org.bukkit.block.BlockFace -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertNull +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class FluidContainerTest { - @BeforeEach fun setup() { TestHelper.setup() diff --git a/src/test/kotlin/com/coderjoe/atlas/fluid/FluidMergerTest.kt b/src/test/kotlin/com/coderjoe/atlas/fluid/FluidMergerTest.kt index de2f041..4fb8cfd 100644 --- a/src/test/kotlin/com/coderjoe/atlas/fluid/FluidMergerTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/fluid/FluidMergerTest.kt @@ -5,11 +5,14 @@ import com.coderjoe.atlas.TestHelper.callFluidUpdate import com.coderjoe.atlas.fluid.block.FluidMerger import com.coderjoe.atlas.fluid.block.FluidPipe import org.bukkit.block.BlockFace -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class FluidMergerTest { - private lateinit var registry: FluidBlockRegistry @BeforeEach diff --git a/src/test/kotlin/com/coderjoe/atlas/fluid/FluidNetworkIntegrationTest.kt b/src/test/kotlin/com/coderjoe/atlas/fluid/FluidNetworkIntegrationTest.kt index 53bb077..f2e8489 100644 --- a/src/test/kotlin/com/coderjoe/atlas/fluid/FluidNetworkIntegrationTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/fluid/FluidNetworkIntegrationTest.kt @@ -5,11 +5,12 @@ import com.coderjoe.atlas.TestHelper.callFluidUpdate import com.coderjoe.atlas.fluid.block.FluidPipe import com.coderjoe.atlas.fluid.block.FluidPump import org.bukkit.block.BlockFace -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class FluidNetworkIntegrationTest { - private lateinit var fluidRegistry: FluidBlockRegistry @BeforeEach diff --git a/src/test/kotlin/com/coderjoe/atlas/fluid/FluidTypeTest.kt b/src/test/kotlin/com/coderjoe/atlas/fluid/FluidTypeTest.kt index 53a7160..0327076 100644 --- a/src/test/kotlin/com/coderjoe/atlas/fluid/FluidTypeTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/fluid/FluidTypeTest.kt @@ -1,10 +1,10 @@ package com.coderjoe.atlas.fluid -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test class FluidTypeTest { - @Test fun `all enum values exist`() { val values = FluidType.values() diff --git a/src/test/kotlin/com/coderjoe/atlas/guide/GuideBookListenerTest.kt b/src/test/kotlin/com/coderjoe/atlas/guide/GuideBookListenerTest.kt index af2ead0..b71bf4b 100644 --- a/src/test/kotlin/com/coderjoe/atlas/guide/GuideBookListenerTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/guide/GuideBookListenerTest.kt @@ -1,16 +1,21 @@ package com.coderjoe.atlas.guide import com.coderjoe.atlas.TestHelper -import io.mockk.* +import io.mockk.Runs +import io.mockk.every +import io.mockk.just +import io.mockk.mockk +import io.mockk.mockkObject +import io.mockk.unmockkObject +import io.mockk.verify import org.bukkit.entity.Player import org.bukkit.event.player.PlayerJoinEvent -import org.bukkit.inventory.ItemStack -import org.bukkit.inventory.PlayerInventory -import org.junit.jupiter.api.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test import java.util.UUID class GuideBookListenerTest { - @BeforeEach fun setup() { TestHelper.setup() diff --git a/src/test/kotlin/com/coderjoe/atlas/guide/GuideBookTest.kt b/src/test/kotlin/com/coderjoe/atlas/guide/GuideBookTest.kt index 177a98f..bad9624 100644 --- a/src/test/kotlin/com/coderjoe/atlas/guide/GuideBookTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/guide/GuideBookTest.kt @@ -1,17 +1,22 @@ package com.coderjoe.atlas.guide import com.coderjoe.atlas.TestHelper -import io.mockk.* +import io.mockk.every +import io.mockk.mockk +import io.mockk.mockkObject +import io.mockk.unmockkObject +import io.mockk.verify import net.kyori.adventure.text.Component +import org.bukkit.World import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack import org.bukkit.inventory.PlayerInventory -import org.bukkit.World -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class GuideBookTest { - @BeforeEach fun setup() { TestHelper.setup() diff --git a/src/test/kotlin/com/coderjoe/atlas/power/AutoSmelterTest.kt b/src/test/kotlin/com/coderjoe/atlas/power/AutoSmelterTest.kt index d81ed29..8a67fe8 100644 --- a/src/test/kotlin/com/coderjoe/atlas/power/AutoSmelterTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/power/AutoSmelterTest.kt @@ -9,13 +9,16 @@ import io.mockk.verify import org.bukkit.Location import org.bukkit.block.BlockFace import org.bukkit.entity.Item -import org.bukkit.inventory.ItemStack -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertDoesNotThrow +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNull +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test import java.util.concurrent.CompletableFuture class AutoSmelterTest { - @BeforeEach fun setup() { TestHelper.setup() @@ -150,9 +153,13 @@ class AutoSmelterTest { smelter.callPowerUpdate() - verify { mockItem.teleportAsync(match { loc -> - loc.z < 0.5 && loc.x == 0.5 - }) } + verify { + mockItem.teleportAsync( + match { loc -> + loc.z < 0.5 && loc.x == 0.5 + }, + ) + } } @Test @@ -170,9 +177,13 @@ class AutoSmelterTest { smelter.callPowerUpdate() - verify { mockItem.teleportAsync(match { loc -> - loc.x > 0.5 && loc.z == 0.5 - }) } + verify { + mockItem.teleportAsync( + match { loc -> + loc.x > 0.5 && loc.z == 0.5 + }, + ) + } } @Test @@ -192,9 +203,13 @@ class AutoSmelterTest { smelter.callPowerUpdate() // Item should still be moved forward even without smelting - verify { mockItem.teleportAsync(match { loc -> - loc.z < 0.5 && loc.x == 0.5 - }) } + verify { + mockItem.teleportAsync( + match { loc -> + loc.z < 0.5 && loc.x == 0.5 + }, + ) + } // Power should not be consumed since no recipe was found assertEquals(2, smelter.currentPower) } diff --git a/src/test/kotlin/com/coderjoe/atlas/power/CobblestoneFactoryTest.kt b/src/test/kotlin/com/coderjoe/atlas/power/CobblestoneFactoryTest.kt index d1fe953..f51bb67 100644 --- a/src/test/kotlin/com/coderjoe/atlas/power/CobblestoneFactoryTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/power/CobblestoneFactoryTest.kt @@ -7,11 +7,14 @@ import com.coderjoe.atlas.fluid.FluidType import com.coderjoe.atlas.fluid.block.FluidPipe import com.coderjoe.atlas.power.block.CobblestoneFactory import org.bukkit.block.BlockFace -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class CobblestoneFactoryTest { - @BeforeEach fun setup() { TestHelper.setup() diff --git a/src/test/kotlin/com/coderjoe/atlas/power/LavaGeneratorTest.kt b/src/test/kotlin/com/coderjoe/atlas/power/LavaGeneratorTest.kt index 8ad1aea..1112f3c 100644 --- a/src/test/kotlin/com/coderjoe/atlas/power/LavaGeneratorTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/power/LavaGeneratorTest.kt @@ -6,14 +6,16 @@ import com.coderjoe.atlas.fluid.FluidBlockRegistry import com.coderjoe.atlas.fluid.FluidType import com.coderjoe.atlas.fluid.block.FluidContainer import com.coderjoe.atlas.fluid.block.FluidPipe -import com.coderjoe.atlas.fluid.block.FluidPump import com.coderjoe.atlas.power.block.LavaGenerator import org.bukkit.block.BlockFace -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class LavaGeneratorTest { - @BeforeEach fun setup() { TestHelper.setup() diff --git a/src/test/kotlin/com/coderjoe/atlas/power/MultiPowerCableTest.kt b/src/test/kotlin/com/coderjoe/atlas/power/MultiPowerCableTest.kt index eac3b16..c95f57f 100644 --- a/src/test/kotlin/com/coderjoe/atlas/power/MultiPowerCableTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/power/MultiPowerCableTest.kt @@ -4,13 +4,16 @@ import com.coderjoe.atlas.TestHelper import com.coderjoe.atlas.TestHelper.callPowerUpdate import com.coderjoe.atlas.power.block.MultiPowerCable import com.coderjoe.atlas.power.block.SmallBattery -import org.bukkit.Location import org.bukkit.block.BlockFace -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertDoesNotThrow +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNull +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class MultiPowerCableTest { - @BeforeEach fun setup() { TestHelper.setup() diff --git a/src/test/kotlin/com/coderjoe/atlas/power/ObsidianFactoryTest.kt b/src/test/kotlin/com/coderjoe/atlas/power/ObsidianFactoryTest.kt index 11024ec..46571c6 100644 --- a/src/test/kotlin/com/coderjoe/atlas/power/ObsidianFactoryTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/power/ObsidianFactoryTest.kt @@ -7,11 +7,14 @@ import com.coderjoe.atlas.fluid.FluidType import com.coderjoe.atlas.fluid.block.FluidPipe import com.coderjoe.atlas.power.block.ObsidianFactory import org.bukkit.block.BlockFace -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class ObsidianFactoryTest { - @BeforeEach fun setup() { TestHelper.setup() diff --git a/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockDataTest.kt b/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockDataTest.kt index 22878a7..6a012eb 100644 --- a/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockDataTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockDataTest.kt @@ -6,11 +6,14 @@ import com.coderjoe.atlas.power.block.SmallBattery import com.coderjoe.atlas.power.block.SmallDrill import com.coderjoe.atlas.power.block.SmallSolarPanel import org.bukkit.block.BlockFace -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotNull +import org.junit.jupiter.api.Assertions.assertNull +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class PowerBlockDataTest { - @BeforeEach fun setup() { TestHelper.setup() diff --git a/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockDialogTest.kt b/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockDialogTest.kt index 957e575..6def8c0 100644 --- a/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockDialogTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockDialogTest.kt @@ -7,14 +7,15 @@ import com.coderjoe.atlas.power.block.SmallDrill import com.coderjoe.atlas.power.block.SmallSolarPanel import net.kyori.adventure.text.Component import net.kyori.adventure.text.TextComponent -import net.kyori.adventure.text.format.NamedTextColor import org.bukkit.block.BlockFace -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* -import java.lang.reflect.Method +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertDoesNotThrow +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class PowerBlockDialogTest { - @BeforeEach fun setup() { TestHelper.setup() diff --git a/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockFactoryTest.kt b/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockFactoryTest.kt index 08197ad..9723d3c 100644 --- a/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockFactoryTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockFactoryTest.kt @@ -4,11 +4,16 @@ import com.coderjoe.atlas.TestHelper import com.coderjoe.atlas.power.block.SmallBattery import com.coderjoe.atlas.power.block.SmallSolarPanel import org.bukkit.block.BlockFace -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertNotNull +import org.junit.jupiter.api.Assertions.assertNull +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class PowerBlockFactoryTest { - @BeforeEach fun setup() { TestHelper.setup() diff --git a/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockInitializerTest.kt b/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockInitializerTest.kt index 7132f52..27b4476 100644 --- a/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockInitializerTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockInitializerTest.kt @@ -6,11 +6,13 @@ import com.coderjoe.atlas.power.block.SmallBattery import com.coderjoe.atlas.power.block.SmallDrill import com.coderjoe.atlas.power.block.SmallSolarPanel import org.bukkit.block.BlockFace -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* - -class PowerBlockRegistrationTest { +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +class PowerBlockInitializerTest { @BeforeEach fun setup() { TestHelper.setup() diff --git a/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockListenerTest.kt b/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockListenerTest.kt index 0710a41..49650ee 100644 --- a/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockListenerTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockListenerTest.kt @@ -4,7 +4,9 @@ import com.coderjoe.atlas.TestHelper import com.coderjoe.atlas.core.AtlasBlockListener import com.coderjoe.atlas.core.BlockSystem import com.coderjoe.atlas.power.block.SmallSolarPanel -import io.mockk.* +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify import org.bukkit.block.Block import org.bukkit.block.BlockFace import org.bukkit.entity.Player @@ -12,11 +14,13 @@ import org.bukkit.event.block.Action import org.bukkit.event.block.BlockBreakEvent import org.bukkit.event.block.BlockPlaceEvent import org.bukkit.event.player.PlayerInteractEvent -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNull +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class PowerBlockListenerTest { - private lateinit var registry: PowerBlockRegistry private lateinit var listener: AtlasBlockListener @@ -24,13 +28,14 @@ class PowerBlockListenerTest { fun setup() { TestHelper.setup() registry = PowerBlockRegistry(TestHelper.mockPlugin) - val system = BlockSystem( - name = "power", - registry = registry, - factory = PowerBlockFactory, - descriptors = emptyMap(), - showDialog = { _, _ -> } - ) + val system = + BlockSystem( + name = "power", + registry = registry, + factory = PowerBlockFactory, + descriptors = emptyMap(), + showDialog = { _, _ -> }, + ) listener = AtlasBlockListener(TestHelper.mockPlugin, listOf(system)) } @@ -82,8 +87,9 @@ class PowerBlockListenerTest { try { listener.onBlockBreak(event) - } catch (_: NoClassDefFoundError) {} - catch (_: ExceptionInInitializerError) {} + } catch (_: NoClassDefFoundError) { + } catch (_: ExceptionInInitializerError) { + } assertNull(registry.getPowerBlock(loc)) } diff --git a/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockLogicTest.kt b/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockLogicTest.kt index d4b2ac4..c868554 100644 --- a/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockLogicTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockLogicTest.kt @@ -8,12 +8,15 @@ import com.coderjoe.atlas.power.block.SmallDrill import com.coderjoe.atlas.power.block.SmallSolarPanel import io.mockk.every import org.bukkit.block.BlockFace -import org.bukkit.block.BlockFace.* -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertNull +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class PowerBlockLogicTest { - @BeforeEach fun setup() { TestHelper.setup() diff --git a/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockPersistenceTest.kt b/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockPersistenceTest.kt index c6d7363..baa3887 100644 --- a/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockPersistenceTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockPersistenceTest.kt @@ -6,12 +6,16 @@ import com.coderjoe.atlas.power.block.SmallBattery import com.coderjoe.atlas.power.block.SmallDrill import com.coderjoe.atlas.power.block.SmallSolarPanel import org.bukkit.block.BlockFace -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertDoesNotThrow +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test import java.io.File class PowerBlockPersistenceTest { - private lateinit var registry: PowerBlockRegistry private lateinit var persistence: PowerBlockPersistence diff --git a/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockRegistryTest.kt b/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockRegistryTest.kt index bb5c63a..d4eec65 100644 --- a/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockRegistryTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/power/PowerBlockRegistryTest.kt @@ -4,11 +4,15 @@ import com.coderjoe.atlas.TestHelper import com.coderjoe.atlas.power.block.SmallBattery import com.coderjoe.atlas.power.block.SmallSolarPanel import org.bukkit.block.BlockFace -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNull +import org.junit.jupiter.api.Assertions.assertSame +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class PowerBlockRegistryTest { - private lateinit var registry: PowerBlockRegistry @BeforeEach @@ -71,14 +75,22 @@ class PowerBlockRegistryTest { fun `getAdjacentPowerBlocks returns blocks in all 6 directions`() { val loc = TestHelper.createLocation(0.0, 64.0, 0.0) - val offsets = listOf( - Triple(1.0, 0.0, 0.0), // east - Triple(-1.0, 0.0, 0.0), // west - Triple(0.0, 1.0, 0.0), // up - Triple(0.0, -1.0, 0.0), // down - Triple(0.0, 0.0, 1.0), // south - Triple(0.0, 0.0, -1.0) // north - ) + val east = Triple(1.0, 0.0, 0.0) + val west = Triple(-1.0, 0.0, 0.0) + val north = Triple(0.0, 0.0, -1.0) + val south = Triple(0.0, 0.0, 1.0) + val up = Triple(0.0, 1.0, 0.0) + val down = Triple(0.0, -1.0, 0.0) + + val offsets = + listOf( + east, + west, + up, + down, + south, + north, + ) for ((dx, dy, dz) in offsets) { val neighborLoc = TestHelper.createLocation(dx, 64.0 + dy, dz) diff --git a/src/test/kotlin/com/coderjoe/atlas/power/PowerMergerTest.kt b/src/test/kotlin/com/coderjoe/atlas/power/PowerMergerTest.kt index f40ce36..73f1821 100644 --- a/src/test/kotlin/com/coderjoe/atlas/power/PowerMergerTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/power/PowerMergerTest.kt @@ -5,11 +5,14 @@ import com.coderjoe.atlas.TestHelper.callPowerUpdate import com.coderjoe.atlas.power.block.PowerMerger import com.coderjoe.atlas.power.block.SmallSolarPanel import org.bukkit.block.BlockFace -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class PowerMergerTest { - private lateinit var registry: PowerBlockRegistry @BeforeEach diff --git a/src/test/kotlin/com/coderjoe/atlas/power/PowerNetworkIntegrationTest.kt b/src/test/kotlin/com/coderjoe/atlas/power/PowerNetworkIntegrationTest.kt index 8275f19..a619dde 100644 --- a/src/test/kotlin/com/coderjoe/atlas/power/PowerNetworkIntegrationTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/power/PowerNetworkIntegrationTest.kt @@ -11,11 +11,13 @@ import io.mockk.mockk import org.bukkit.Material import org.bukkit.block.Block import org.bukkit.block.BlockFace -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class PowerNetworkIntegrationTest { - private lateinit var registry: PowerBlockRegistry @BeforeEach diff --git a/src/test/kotlin/com/coderjoe/atlas/power/SmallDrillMiningTest.kt b/src/test/kotlin/com/coderjoe/atlas/power/SmallDrillMiningTest.kt index 890cec5..c2ac424 100644 --- a/src/test/kotlin/com/coderjoe/atlas/power/SmallDrillMiningTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/power/SmallDrillMiningTest.kt @@ -10,11 +10,12 @@ import io.mockk.verify import org.bukkit.Material import org.bukkit.block.Block import org.bukkit.block.BlockFace -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test class SmallDrillMiningTest { - private lateinit var registry: PowerBlockRegistry @BeforeEach @@ -28,7 +29,12 @@ class SmallDrillMiningTest { TestHelper.teardown() } - private fun mockBlockAt(x: Int, y: Int, z: Int, material: Material): Block { + private fun mockBlockAt( + x: Int, + y: Int, + z: Int, + material: Material, + ): Block { val block = mockk(relaxed = true) every { block.type } returns material every { block.getDrops() } returns emptyList() diff --git a/src/test/kotlin/com/coderjoe/atlas/transport/ConveyorBeltTest.kt b/src/test/kotlin/com/coderjoe/atlas/transport/ConveyorBeltTest.kt index 9890063..cb78bb8 100644 --- a/src/test/kotlin/com/coderjoe/atlas/transport/ConveyorBeltTest.kt +++ b/src/test/kotlin/com/coderjoe/atlas/transport/ConveyorBeltTest.kt @@ -7,16 +7,18 @@ import io.mockk.every import io.mockk.mockk import io.mockk.verify import org.bukkit.Location -import org.bukkit.World import org.bukkit.block.BlockFace import org.bukkit.entity.Item -import org.bukkit.util.BoundingBox -import org.junit.jupiter.api.* -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertDoesNotThrow +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNull +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test import java.util.concurrent.CompletableFuture class ConveyorBeltTest { - @BeforeEach fun setup() { TestHelper.setup() @@ -122,9 +124,13 @@ class ConveyorBeltTest { belt.callTransportUpdate() - verify { mockItem.teleportAsync(match { loc -> - loc.z < 0.5 && loc.x == 0.5 - }) } + verify { + mockItem.teleportAsync( + match { loc -> + loc.z < 0.5 && loc.x == 0.5 + }, + ) + } } @Test @@ -141,9 +147,13 @@ class ConveyorBeltTest { belt.callTransportUpdate() - verify { mockItem.teleportAsync(match { loc -> - loc.x > 0.5 && loc.z == 0.5 - }) } + verify { + mockItem.teleportAsync( + match { loc -> + loc.x > 0.5 && loc.z == 0.5 + }, + ) + } } @Test