Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/kotlin/com/coderjoe/atlas/AtlasConfig.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.coderjoe.atlas

import org.bukkit.Location
import org.bukkit.plugin.java.JavaPlugin
import java.util.logging.Logger

Expand All @@ -18,3 +19,6 @@ fun Logger.atlasInfo(message: String) {
info(message)
}
}

val Location.coordinates: String
get() = "$blockX,$blockY,$blockZ"
9 changes: 5 additions & 4 deletions src/main/kotlin/com/coderjoe/atlas/core/AtlasBlock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.coderjoe.atlas.core

import com.coderjoe.atlas.Atlas
import com.coderjoe.atlas.atlasInfo
import com.coderjoe.atlas.coordinates
import net.momirealms.craftengine.bukkit.api.CraftEngineBlocks
import net.momirealms.craftengine.core.util.Key
import org.bukkit.Location
Expand Down Expand Up @@ -52,7 +53,7 @@ abstract class AtlasBlock(
currentVisualState = newState
} catch (e: Throwable) {
plugin.logger.warning(
"Failed to update visual state at ${location.blockX},${location.blockY},${location.blockZ}: ${e.message}",
"Failed to update visual state at ${location.coordinates}: ${e.message}",
)
} finally {
registry.updatingLocations.remove(key)
Expand Down Expand Up @@ -88,20 +89,20 @@ abstract class AtlasBlock(
} catch (e: Exception) {
plugin.logger.warning(
"""
Error in block tick at ${location.blockX},${location.blockY},${location.blockZ}: ${e.message}
Error in block tick at ${location.coordinates}: ${e.message}
""".trimIndent(),
)
}
},
updateIntervalTicks, updateIntervalTicks,
)

plugin.logger.atlasInfo("${this::class.simpleName} at ${location.blockX},${location.blockY},${location.blockZ} started")
plugin.logger.atlasInfo("${this::class.simpleName} at ${location.coordinates} started")
}

fun stop() {
updateTask?.cancel()
updateTask = null
plugin.logger.atlasInfo("${this::class.simpleName} at ${location.blockX},${location.blockY},${location.blockZ} stopped")
plugin.logger.atlasInfo("${this::class.simpleName} at ${location.coordinates} stopped")
}
}
7 changes: 4 additions & 3 deletions src/main/kotlin/com/coderjoe/atlas/core/BlockRegistry.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.coderjoe.atlas.core

import com.coderjoe.atlas.atlasInfo
import com.coderjoe.atlas.coordinates
import org.bukkit.Location
import org.bukkit.block.BlockFace
import org.bukkit.plugin.java.JavaPlugin
Expand All @@ -13,7 +14,7 @@ open class BlockRegistry<T : AtlasBlock>(protected val plugin: JavaPlugin) {

companion object {
fun locationKey(location: Location): String {
return "${location.world?.name}:${location.blockX},${location.blockY},${location.blockZ}"
return "${location.world?.name}:${location.coordinates}"
}
}

Expand All @@ -27,7 +28,7 @@ open class BlockRegistry<T : AtlasBlock>(protected val plugin: JavaPlugin) {
block.start()
plugin.logger.atlasInfo(
"""
Registered ${block::class.simpleName} at ${block.location.blockX},${block.location.blockY},${block.location.blockZ}
Registered ${block::class.simpleName} at ${block.location.coordinates}
""".trimIndent(),
)
}
Expand All @@ -38,7 +39,7 @@ open class BlockRegistry<T : AtlasBlock>(protected val plugin: JavaPlugin) {
blockIds.remove(key)
block?.stop()
if (block != null) {
plugin.logger.atlasInfo("Unregistered ${block::class.simpleName} at ${location.blockX},${location.blockY},${location.blockZ}")
plugin.logger.atlasInfo("Unregistered ${block::class.simpleName} at ${location.coordinates}")
}
return block
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/coderjoe/atlas/fluid/FluidBlock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract class FluidBlock(
open fun hasFluid(): Boolean = storedFluid != FluidType.NONE

protected fun updateFluidState() {
CraftEngineHelper.setStringProperty(location, "fluid", storedFluid.propertyName)
CraftEngineHelper.setStringProperty(location, "fluid", storedFluid.name.lowercase())
}

open fun canProvideFluid(requestDirection: BlockFace): Boolean = hasFluid()
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/com/coderjoe/atlas/fluid/FluidType.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.coderjoe.atlas.fluid

enum class FluidType(val propertyName: String) {
WATER("water"),
LAVA("lava"),
NONE("none"),
enum class FluidType {
WATER,
LAVA,
NONE,
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.coderjoe.atlas.fluid.block

import com.coderjoe.atlas.atlasInfo
import com.coderjoe.atlas.coordinates
import com.coderjoe.atlas.core.BlockDescriptor
import com.coderjoe.atlas.core.CraftEngineHelper
import com.coderjoe.atlas.core.PlacementType
Expand Down Expand Up @@ -91,7 +92,7 @@ class FluidContainer(location: Location, override val facing: BlockFace) : Fluid
val fluid = source.removeFluid()
if (storeFluid(fluid)) {
plugin.logger.atlasInfo(
"FluidContainer at ${location.blockX},${location.blockY},${location.blockZ} " +
"FluidContainer at ${location.coordinates} " +
"pulled ${fluid.name} from ${source::class.simpleName}",
)
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.coderjoe.atlas.fluid.block

import com.coderjoe.atlas.atlasInfo
import com.coderjoe.atlas.coordinates
import com.coderjoe.atlas.core.BlockDescriptor
import com.coderjoe.atlas.core.PlacementType
import com.coderjoe.atlas.fluid.FluidBlock
Expand Down Expand Up @@ -45,7 +46,7 @@ class FluidMerger(location: Location, override val facing: BlockFace) : FluidBlo
val fluid = source.removeFluid()
storeFluid(fluid)
plugin.logger.atlasInfo(
"FluidMerger at ${location.blockX},${location.blockY},${location.blockZ} " +
"FluidMerger at ${location.coordinates} " +
"pulled ${fluid.name} from ${source::class.simpleName} at ${face.name}",
)
updateFluidState()
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/com/coderjoe/atlas/fluid/block/FluidPipe.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.coderjoe.atlas.fluid.block

import com.coderjoe.atlas.atlasInfo
import com.coderjoe.atlas.coordinates
import com.coderjoe.atlas.core.BlockDescriptor
import com.coderjoe.atlas.core.PlacementType
import com.coderjoe.atlas.fluid.FluidBlock
Expand Down Expand Up @@ -42,7 +43,7 @@ class FluidPipe(location: Location, override val facing: BlockFace) : FluidBlock
val fluid = source.removeFluid()
storeFluid(fluid)
plugin.logger.atlasInfo(
"FluidPipe at ${location.blockX},${location.blockY},${location.blockZ} " +
"FluidPipe at ${location.coordinates} " +
"pulled ${fluid.name} from ${source::class.simpleName}",
)
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/com/coderjoe/atlas/fluid/block/FluidPump.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.coderjoe.atlas.fluid.block

import com.coderjoe.atlas.atlasInfo
import com.coderjoe.atlas.coordinates
import com.coderjoe.atlas.core.BlockDescriptor
import com.coderjoe.atlas.core.PlacementType
import com.coderjoe.atlas.fluid.FluidBlock
Expand Down Expand Up @@ -150,7 +151,7 @@ class FluidPump(location: Location) : FluidBlock(location) {
cauldronFace = foundFace
pumpStatus = PumpStatus.EXTRACTING
plugin.logger.atlasInfo(
"FluidPump at ${location.blockX},${location.blockY},${location.blockZ} extracted ${fluidType.name} from $foundFace",
"FluidPump at ${location.coordinates} extracted ${fluidType.name} from $foundFace",
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.coderjoe.atlas.fluid.block

import com.coderjoe.atlas.atlasInfo
import com.coderjoe.atlas.coordinates
import com.coderjoe.atlas.core.BlockDescriptor
import com.coderjoe.atlas.core.PlacementType
import com.coderjoe.atlas.fluid.FluidBlock
Expand Down Expand Up @@ -38,7 +39,7 @@ class FluidSplitter(location: Location, override val facing: BlockFace) : FluidB
val fluid = source.removeFluid()
storeFluid(fluid)
plugin.logger.atlasInfo(
"FluidSplitter at ${location.blockX},${location.blockY},${location.blockZ} " +
"FluidSplitter at ${location.coordinates} " +
"pulled ${fluid.name} from ${source::class.simpleName}",
)
}
Expand All @@ -54,7 +55,7 @@ class FluidSplitter(location: Location, override val facing: BlockFace) : FluidB
val fluid = removeFluid()
if (target.storeFluid(fluid)) {
plugin.logger.atlasInfo(
"FluidSplitter at ${location.blockX},${location.blockY},${location.blockZ} " +
"FluidSplitter at ${location.coordinates} " +
"pushed ${fluid.name} to ${target::class.simpleName} at ${face.name}",
)
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.coderjoe.atlas.power.block

import com.coderjoe.atlas.atlasInfo
import com.coderjoe.atlas.coordinates
import com.coderjoe.atlas.core.BlockDescriptor
import com.coderjoe.atlas.core.PlacementType
import com.coderjoe.atlas.fluid.FluidBlock
Expand Down Expand Up @@ -53,7 +54,7 @@ class LavaGenerator(location: Location) : PowerBlock(location, maxStorage = 50)
if (lava) {
val generated = addPower(POWER_PER_LAVA)
plugin.logger.atlasInfo(
"LavaGenerator at ${location.blockX},${location.blockY},${location.blockZ} " +
"LavaGenerator at ${location.coordinates} " +
"consumed 1 lava, generated $generated power (now $currentPower/$maxStorage)",
)
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/com/coderjoe/atlas/power/block/PowerCable.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.coderjoe.atlas.power.block

import com.coderjoe.atlas.atlasInfo
import com.coderjoe.atlas.coordinates
import com.coderjoe.atlas.core.BlockDescriptor
import com.coderjoe.atlas.core.PlacementType
import com.coderjoe.atlas.power.PowerBlock
Expand Down Expand Up @@ -38,7 +39,7 @@ class PowerCable(location: Location, override val facing: BlockFace) : PowerBloc
if (pulled > 0) {
addPower(pulled)
plugin.logger.atlasInfo(
"PowerCable at ${location.blockX},${location.blockY},${location.blockZ} " +
"PowerCable at ${location.coordinates} " +
"pulled $pulled power from ${source::class.simpleName} (now $currentPower/$maxStorage)",
)
}
Expand Down
7 changes: 3 additions & 4 deletions src/main/kotlin/com/coderjoe/atlas/power/block/PowerMerger.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.coderjoe.atlas.power.block

import com.coderjoe.atlas.atlasInfo
import com.coderjoe.atlas.coordinates
import com.coderjoe.atlas.core.BlockDescriptor
import com.coderjoe.atlas.core.PlacementType
import com.coderjoe.atlas.power.PowerBlock
Expand Down Expand Up @@ -32,9 +33,7 @@ class PowerMerger(location: Location, override val facing: BlockFace) : PowerBlo
override fun powerUpdate() {
val registry = PowerBlockRegistry.instance ?: return

val inputFaces =
listOf(BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST, BlockFace.UP, BlockFace.DOWN)
.filter { it != facing }
val inputFaces = ADJACENT_FACES.filter { it != facing }

for (face in inputFaces) {
if (currentPower >= maxStorage) break
Expand All @@ -44,7 +43,7 @@ class PowerMerger(location: Location, override val facing: BlockFace) : PowerBlo
if (pulled > 0) {
addPower(pulled)
plugin.logger.atlasInfo(
"PowerMerger at ${location.blockX},${location.blockY},${location.blockZ} " +
"PowerMerger at ${location.coordinates} " +
"pulled $pulled power from ${source::class.simpleName} at ${face.name} " +
"(now $currentPower/$maxStorage)",
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.coderjoe.atlas.power.block

import com.coderjoe.atlas.atlasInfo
import com.coderjoe.atlas.coordinates
import com.coderjoe.atlas.core.BlockDescriptor
import com.coderjoe.atlas.core.PlacementType
import com.coderjoe.atlas.power.PowerBlock
Expand Down Expand Up @@ -39,7 +40,7 @@ class PowerSplitter(location: Location, override val facing: BlockFace) : PowerB
if (pulled > 0) {
addPower(pulled)
plugin.logger.atlasInfo(
"PowerSplitter at ${location.blockX},${location.blockY},${location.blockZ} " +
"PowerSplitter at ${location.coordinates} " +
"pulled $pulled power (now $currentPower/$maxStorage)",
)
}
Expand All @@ -56,7 +57,7 @@ class PowerSplitter(location: Location, override val facing: BlockFace) : PowerB
if (pushed > 0) {
target.addPower(pushed)
plugin.logger.atlasInfo(
"PowerSplitter at ${location.blockX},${location.blockY},${location.blockZ} " +
"PowerSplitter at ${location.coordinates} " +
"pushed $pushed power to ${target::class.simpleName} at ${face.name}",
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.coderjoe.atlas.power.block

import com.coderjoe.atlas.atlasInfo
import com.coderjoe.atlas.coordinates
import com.coderjoe.atlas.core.BlockDescriptor
import com.coderjoe.atlas.core.PlacementType
import com.coderjoe.atlas.power.PowerBlock
Expand Down Expand Up @@ -60,7 +61,7 @@ class SmallBattery(location: Location, facing: BlockFace) : PowerBlock(location,
if (pulled > 0) {
addPower(pulled)
plugin.logger.atlasInfo(
"SmallBattery at ${location.blockX},${location.blockY},${location.blockZ} " +
"SmallBattery at ${location.coordinates} " +
"pulled $pulled power from ${source::class.simpleName} (now $currentPower/$maxStorage)",
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.coderjoe.atlas.power.block

import com.coderjoe.atlas.atlasInfo
import com.coderjoe.atlas.coordinates
import com.coderjoe.atlas.core.BlockDescriptor
import com.coderjoe.atlas.core.PlacementType
import com.coderjoe.atlas.power.PowerBlock
Expand Down Expand Up @@ -41,13 +42,13 @@ class SmallSolarPanel(location: Location) : PowerBlock(location, maxStorage = 1)
val generated = addPower(1)
if (generated > 0) {
plugin.logger.atlasInfo(
"SmallSolarPanel at ${location.blockX},${location.blockY},${location.blockZ} " +
"SmallSolarPanel at ${location.coordinates} " +
"generated $generated power (now $currentPower/$maxStorage)",
)
}
} else {
plugin.logger.atlasInfo(
"SmallSolarPanel at ${location.blockX},${location.blockY},${location.blockZ} " +
"SmallSolarPanel at ${location.coordinates} " +
"is not generating power because it is not daytime.",
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ class CobblestoneFactory(location: Location) : MaterialFactory(location, maxStor
}

override val baseBlockId: String = BLOCK_ID
override val activeBlockId: String = BLOCK_ID_ACTIVE
override val powerCost: Int = POWER_COST
override val outputMaterial: Material = Material.COBBLESTONE

override fun getVisualStateBlockId(): String =
when {
currentPower >= POWER_COST -> BLOCK_ID_ACTIVE
else -> BLOCK_ID
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.coderjoe.atlas.utility.block

import com.coderjoe.atlas.atlasInfo
import com.coderjoe.atlas.coordinates
import com.coderjoe.atlas.fluid.FluidBlock
import com.coderjoe.atlas.fluid.FluidBlockRegistry
import com.coderjoe.atlas.fluid.FluidType
Expand All @@ -19,6 +20,13 @@ abstract class MaterialFactory(

protected abstract val powerCost: Int
protected abstract val outputMaterial: Material
protected abstract val activeBlockId: String

override fun getVisualStateBlockId(): String =
when {
currentPower >= powerCost -> activeBlockId
else -> baseBlockId
}

override fun powerUpdate() {
pullPowerFromNeighbors()
Expand Down Expand Up @@ -51,7 +59,7 @@ abstract class MaterialFactory(
world.dropItem(dropLocation, ItemStack(outputMaterial))

plugin.logger.atlasInfo(
"${this::class.simpleName} at ${location.blockX},${location.blockY},${location.blockZ} " +
"${this::class.simpleName} at ${location.coordinates} " +
"produced 1 ${outputMaterial.name.lowercase()}",
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ class ObsidianFactory(location: Location) : MaterialFactory(location, maxStorage
}

override val baseBlockId: String = BLOCK_ID
override val activeBlockId: String = BLOCK_ID_ACTIVE
override val powerCost: Int = POWER_COST
override val outputMaterial: Material = Material.OBSIDIAN

override fun getVisualStateBlockId(): String =
when {
currentPower >= POWER_COST -> BLOCK_ID_ACTIVE
else -> BLOCK_ID
}
}
Loading