generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implements door permission check (and necessary subsystems) #2
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, small typo here. You fixed ClaimPermission, but we also have another typo: "ClamFlagId"