Skip to content

Commit

Permalink
PC-1070 Fixes initialization error
Browse files Browse the repository at this point in the history
  • Loading branch information
Polyana committed Dec 22, 2023
1 parent ef58bd2 commit 9507f21
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 16 deletions.
16 changes: 4 additions & 12 deletions api/src/main/kotlin/br/com/gamemods/minecity/api/MineCity.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package br.com.gamemods.minecity.api

import br.com.gamemods.minecity.api.annotation.internal.InternalMineCityApi
import br.com.gamemods.minecity.api.service.MineCityInternal
import br.com.gamemods.minecity.api.service.namedplayer.NamedPlayerService
import br.com.gamemods.minecity.api.service.permission.PermissionService

private lateinit var currentInstance: MineCity

/**
* Interface that allows other mods to interact with MineCity.
Expand All @@ -27,16 +27,8 @@ public interface MineCity {

/**
* This companion object allows MineCity interface to be used directly in kotlin delegating all API calls to
* the instance that is set at [instance].
*
* @property instance Access to the MineCity API implementation, must be modified only by MineCity itself, can be accessed freely.
* the instance that is set at [MineCityInternal.implementation].
*/
public companion object: MineCity by currentInstance {
public var instance: MineCity
get() = currentInstance
@InternalMineCityApi
set(value) {
currentInstance = value
}
}
@OptIn(InternalMineCityApi::class)
public companion object: MineCity by MineCityInternal.implementation
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public value class ClaimPermissionId(private val id: String) {
/**
* The regex pattern that valid ClaimPermissionId instances must match.
*/
private val VALID_REGEX = Regex("^([a-z][a-z0-9]*)(_[a-z][a-z0-9]*)*:/([a-z][a-z0-9]*)(_[a-z][a-z0-9]*)*$")
private val VALID_REGEX = Regex("^([a-z][a-z0-9]*)(_[a-z][a-z0-9]*)*:([a-z][a-z0-9]*)(_[a-z][a-z0-9]*)*$")

/**
* ClaimPermissionId instance for door-related permissions.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package br.com.gamemods.minecity.api.service

import br.com.gamemods.minecity.api.MineCity
import br.com.gamemods.minecity.api.annotation.internal.InternalMineCityApi

/**
* Internal MineCity states and services, should not be used by API users.
*/
@InternalMineCityApi
public object MineCityInternal {
/**
* Access to the MineCity API implementation, must be modified only by MineCity itself, can be accessed freely.
*/
public lateinit var implementation: MineCity
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import br.com.gamemods.minecity.api.MineCityPlatform
import br.com.gamemods.minecity.api.annotation.internal.InternalMineCityApi
import br.com.gamemods.minecity.api.annotation.side.ServerSideOnly
import br.com.gamemods.minecity.api.service.namedplayer.NamedPlayerService
import br.com.gamemods.minecity.api.service.permission.PermissionService
import br.com.gamemods.minecity.core.service.world.WorldService
import com.github.michaelbull.logging.InlineLogger

Expand All @@ -21,6 +22,7 @@ class MineCityCore(
override val platform: MineCityPlatform,
val worlds: WorldService,
override val players: NamedPlayerService,
override val permission: PermissionService,
): MineCity {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package br.com.gamemods.minecity.core.service.permission

import br.com.gamemods.minecity.api.annotation.internal.InternalMineCityApi
import br.com.gamemods.minecity.api.id.ClaimPermissionId
import br.com.gamemods.minecity.api.service.permission.ClaimPermission
import br.com.gamemods.minecity.api.service.permission.PermissionService

@InternalMineCityApi
class CorePermissionService: PermissionService {
private val permissions = mutableMapOf<ClaimPermissionId, ClaimPermission>()

override fun get(id: ClaimPermissionId): ClaimPermission = permissions[id] ?: error("Unknown permission $id")

override fun plusAssign(permission: ClaimPermission) {
permissions.compute(permission.id) { _, old ->
if(old == null) permission
else error("Permission ${permission.id} already registered")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import br.com.gamemods.minecity.api.annotation.internal.InternalMineCityApi
import br.com.gamemods.minecity.api.annotation.side.ServerSideOnly
import br.com.gamemods.minecity.api.client.MineCityClient
import br.com.gamemods.minecity.api.math.pos.*
import br.com.gamemods.minecity.api.service.MineCityInternal
import br.com.gamemods.minecity.core.MineCityCore
import br.com.gamemods.minecity.core.dispatchers.Async
import br.com.gamemods.minecity.core.dispatchers.Sync
import br.com.gamemods.minecity.core.service.permission.CorePermissionService
import br.com.gamemods.minecity.fabric.math.pos.FabricBlockLocation
import br.com.gamemods.minecity.fabric.math.pos.FabricChunkLocation
import br.com.gamemods.minecity.fabric.math.pos.FabricEntityLocation
Expand All @@ -25,6 +27,8 @@ import com.github.michaelbull.logging.InlineLogger
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.asCoroutineDispatcher
import net.fabricmc.api.ModInitializer
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerChunkEvents
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents
import net.minecraft.server.MinecraftServer
import net.minecraft.server.world.ServerWorld
import net.minecraft.world.chunk.WorldChunk
Expand Down Expand Up @@ -58,16 +62,16 @@ object MineCityFabric : ModInitializer, MineCityPlatform {
platform = this,
worlds = FabricWorldService(this),
players = FabricNamedPlayerService(this),
permission = CorePermissionService(),
)
//FIXME
/*MineCity.instance = core
MineCityInternal.implementation = core
core.onInitialize()
ServerLifecycleEvents.SERVER_STARTING.register(this::handleServerStarting)
ServerLifecycleEvents.SERVER_STARTED.register(this::handleServerStarted)
ServerLifecycleEvents.SERVER_STOPPING.register(this::handleServerStopping)
ServerLifecycleEvents.SERVER_STOPPED.register(this::handleServerStopped)
ServerChunkEvents.CHUNK_LOAD.register(this::handleChunkLoad)
ServerChunkEvents.CHUNK_UNLOAD.register(this::handleChunkUnload)*/
ServerChunkEvents.CHUNK_UNLOAD.register(this::handleChunkUnload)

registerPermissions()
}
Expand Down

0 comments on commit 9507f21

Please sign in to comment.