generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PC-1050 Implements door permission check and necessary subsystems
- Loading branch information
Polyana
committed
Dec 28, 2023
1 parent
7541e64
commit c10268a
Showing
13 changed files
with
192 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 25 additions & 2 deletions
27
api/src/main/kotlin/br/com/gamemods/minecity/api/claim/Claim.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,40 @@ | ||
package br.com.gamemods.minecity.api.claim | ||
|
||
import br.com.gamemods.minecity.api.MineCity | ||
import br.com.gamemods.minecity.api.annotation.internal.InternalMineCityApi | ||
import br.com.gamemods.minecity.api.id.ClaimId | ||
import br.com.gamemods.minecity.api.id.ClaimPermissionId | ||
import br.com.gamemods.minecity.api.serializer.UniqueId | ||
import br.com.gamemods.minecity.api.service.MineCityInternal | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
public data class Claim( | ||
val id: ClaimId = ClaimId(), | ||
val id: ClaimId, | ||
val shape: Set<ClaimShape>, | ||
val name: String, | ||
val parentId: ClaimId? = null, | ||
val owner: UniqueId? = null, | ||
val rent: ClaimRentContract? = null, | ||
val city: City? = null, | ||
val isAdmin: Boolean = false, | ||
val settings: ClaimSettings = ClaimSettings(), | ||
) | ||
) { | ||
@OptIn(InternalMineCityApi::class) | ||
public fun hasPermission(playerId: UniqueId, permissionId: ClaimPermissionId, silent: Boolean = false): Boolean { | ||
if (MineCity.players.isAdminMode(playerId)) { | ||
return true | ||
} | ||
if (rent != null && rent.rentedTo == playerId) { | ||
return true | ||
} else if (playerId == owner) { | ||
return true | ||
} | ||
|
||
val allow = settings.hasPermission(playerId, permissionId) | ||
if (!allow && !silent) { | ||
MineCity.players.sendMessage(playerId, MineCityInternal.permissionDeniedMessage(this, permissionId)) | ||
} | ||
return allow | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
api/src/main/kotlin/br/com/gamemods/minecity/api/id/ClamPermissionId.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 19 additions & 5 deletions
24
api/src/main/kotlin/br/com/gamemods/minecity/api/service/namedplayer/NamedPlayerService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,47 @@ | ||
package br.com.gamemods.minecity.api.service.namedplayer | ||
|
||
import br.com.gamemods.minecity.api.annotation.threading.ASyncFriendly | ||
import br.com.gamemods.minecity.api.annotation.threading.SyncFriendly | ||
import br.com.gamemods.minecity.api.id.NamedPlayer | ||
import br.com.gamemods.minecity.api.serializer.UniqueId | ||
import kotlinx.coroutines.Deferred | ||
import java.util.* | ||
import net.kyori.adventure.text.Component | ||
|
||
/** | ||
* Manages the [NamedPlayer] objects. | ||
*/ | ||
public interface NamedPlayerService { | ||
/** | ||
* Gets [NamedPlayer] for the given player [uuid], attempts to use a cached value before starting a query. | ||
* Gets [NamedPlayer] for the given player [playerId], attempts to use a cached value before starting a query. | ||
*/ | ||
public operator fun get(uuid: UUID): Deferred<NamedPlayer?> | ||
public operator fun get(playerId: UniqueId): Deferred<NamedPlayer?> | ||
|
||
/** | ||
* Gets [NamedPlayer] for the given player [name], attempts to use a cached value before starting a query. | ||
*/ | ||
public operator fun get(name: String): Deferred<NamedPlayer?> | ||
|
||
/** | ||
* Checks if the given player [uuid] has ready-to-use cached value. | ||
* Checks if the given player [playerId] has ready-to-use cached value. | ||
*/ | ||
@SyncFriendly | ||
public operator fun contains(uuid: UUID): Boolean | ||
public operator fun contains(playerId: UniqueId): Boolean | ||
|
||
/** | ||
* Checks if the given player [name] has ready-to-use cached value. | ||
*/ | ||
@SyncFriendly | ||
public operator fun contains(name: String): Boolean | ||
|
||
/** | ||
* Sends a message to the given player [playerId] if the player is online. | ||
*/ | ||
@SyncFriendly | ||
@ASyncFriendly | ||
public fun sendMessage(playerId: UniqueId, message: Component) | ||
|
||
/** | ||
* Checks if the given player [playerId] is in admin mode. | ||
*/ | ||
public fun isAdminMode(playerId: UniqueId): Boolean | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
core/src/main/kotlin/br/com/gamemods/minecity/core/service/claim/CoreClaimService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package br.com.gamemods.minecity.core.service.claim | ||
|
||
import br.com.gamemods.minecity.api.annotation.internal.InternalMineCityApi | ||
import br.com.gamemods.minecity.api.claim.Claim | ||
import br.com.gamemods.minecity.api.id.ClaimId | ||
import br.com.gamemods.minecity.api.id.WorldId | ||
import br.com.gamemods.minecity.api.math.pos.BlockGridPositioned | ||
import br.com.gamemods.minecity.api.service.claim.ClaimService | ||
import kotlinx.coroutines.CompletableDeferred | ||
import kotlinx.coroutines.Deferred | ||
|
||
@InternalMineCityApi | ||
class CoreClaimService: ClaimService { | ||
@Suppress("CanBeVal", "UnnecessaryVariable") | ||
override fun get(worldId: WorldId, pos: BlockGridPositioned): Claim? { | ||
//TODO Implement | ||
var result: Claim? = Claim( | ||
id = ClaimId(), | ||
shape = emptySet(), | ||
name = "TestClaim", | ||
) | ||
//result = null | ||
return result | ||
} | ||
|
||
override fun load(worldId: WorldId, pos: BlockGridPositioned): Deferred<Claim?> { | ||
//TODO Implement | ||
return CompletableDeferred(null) | ||
} | ||
|
||
override fun create(claim: Claim): Deferred<Claim> { | ||
//TODO Implement | ||
return CompletableDeferred(claim) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...abric/src/main/kotlin/br/com/gamemods/minecity/fabric/service/claim/FabricClaimService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package br.com.gamemods.minecity.fabric.service.claim | ||
|
||
import br.com.gamemods.minecity.api.annotation.PlatformDependent | ||
import br.com.gamemods.minecity.api.annotation.internal.InternalMineCityApi | ||
import br.com.gamemods.minecity.api.id.WorldId | ||
import br.com.gamemods.minecity.api.service.claim.ClaimService | ||
import br.com.gamemods.minecity.fabric.wrapper.FabricBlockPosWrapper.Companion.wrapper | ||
import net.minecraft.registry.RegistryKey | ||
import net.minecraft.util.math.BlockPos | ||
import net.minecraft.world.World | ||
|
||
@InternalMineCityApi | ||
class FabricClaimService { | ||
companion object { | ||
operator fun ClaimService.get(world: World, pos: BlockPos) = this[world.mineCityWorldId, pos.wrapper] | ||
|
||
@OptIn(PlatformDependent::class) | ||
val RegistryKey<World>.mineCityWorldId get() = WorldId(value.toString()) | ||
|
||
val World.mineCityWorldId get() = registryKey.mineCityWorldId | ||
} | ||
} |
Oops, something went wrong.