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-1075 Creates an abstraction for ClaimPermission
- Loading branch information
Polyana
committed
Dec 22, 2023
1 parent
a50f10b
commit ef58bd2
Showing
7 changed files
with
134 additions
and
1 deletion.
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
71 changes: 71 additions & 0 deletions
71
api/src/main/kotlin/br/com/gamemods/minecity/api/id/ClaimPermissionId.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,71 @@ | ||
package br.com.gamemods.minecity.api.id | ||
|
||
import br.com.gamemods.minecity.api.id.ClaimPermissionId.Companion.VALID_REGEX | ||
import kotlinx.serialization.Serializable | ||
|
||
/** | ||
* Represents a unique identifier for claim permissions. | ||
* This ID is used to manage and identify different types of claim permissions. | ||
* It follows a specific pattern as defined in [VALID_REGEX]. | ||
* | ||
* @property id The unique string identifier for the permission. | ||
*/ | ||
@Serializable | ||
@JvmInline | ||
public value class ClaimPermissionId(private val id: String) { | ||
|
||
init { | ||
require(id.matches(VALID_REGEX)) { | ||
"Invalid PermissionId pattern: $id (PermissionId pattern must match: $VALID_REGEX)" | ||
} | ||
} | ||
|
||
/** | ||
* Returns the string representation of the claim permission ID. | ||
* | ||
* @return The claim permission ID as a string. | ||
*/ | ||
override fun toString(): String = id | ||
|
||
public companion object { | ||
/** | ||
* 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]*)*$") | ||
|
||
/** | ||
* ClaimPermissionId instance for door-related permissions. | ||
*/ | ||
public val DOORS: ClaimPermissionId = ClaimPermissionId("minecity:doors") | ||
|
||
/** | ||
* ClaimPermissionId instance for button-related permissions. | ||
*/ | ||
public val BUTTONS: ClaimPermissionId = ClaimPermissionId("minecity:buttons") | ||
|
||
/** | ||
* ClaimPermissionId instance for computer screen-related permissions. | ||
*/ | ||
public val COMPUTER_SCREEN: ClaimPermissionId = ClaimPermissionId("minecity:computer_screen") | ||
|
||
/** | ||
* ClaimPermissionId instance for machine-related permissions. | ||
*/ | ||
public val MACHINES: ClaimPermissionId = ClaimPermissionId("minecity:machines") | ||
|
||
/** | ||
* ClaimPermissionId instance for panel-related permissions. | ||
*/ | ||
public val PANELS: ClaimPermissionId = ClaimPermissionId("minecity:panels") | ||
|
||
/** | ||
* ClaimPermissionId instance for computer-related permissions. | ||
*/ | ||
public val COMPUTERS: ClaimPermissionId = ClaimPermissionId("minecity:computers") | ||
|
||
/** | ||
* ClaimPermissionId instance for building-related permissions. | ||
*/ | ||
public val BUILD: ClaimPermissionId = ClaimPermissionId("minecity:build") | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
api/src/main/kotlin/br/com/gamemods/minecity/api/service/permission/ClaimPermission.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,17 @@ | ||
package br.com.gamemods.minecity.api.service.permission | ||
|
||
import br.com.gamemods.minecity.api.id.ClaimPermissionId | ||
import net.kyori.adventure.text.Component | ||
|
||
/** | ||
* Represents a permission that can be granted to a player in a claim. | ||
* | ||
* @property id The unique identifier for the permission. | ||
* @property name The name of the permission. | ||
* @property description The description of the permission. | ||
*/ | ||
public abstract class ClaimPermission( | ||
public val id: ClaimPermissionId, | ||
public val name: Component, | ||
public val description: Component, | ||
) |
19 changes: 19 additions & 0 deletions
19
api/src/main/kotlin/br/com/gamemods/minecity/api/service/permission/PermissionService.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,19 @@ | ||
package br.com.gamemods.minecity.api.service.permission | ||
|
||
import br.com.gamemods.minecity.api.id.ClaimPermissionId | ||
import br.com.gamemods.minecity.api.id.NamedPlayer | ||
|
||
/** | ||
* Manages the [NamedPlayer] objects. | ||
*/ | ||
public interface PermissionService { | ||
/** | ||
* Gets [ClaimPermission] for the given [id] | ||
*/ | ||
public operator fun get(id: ClaimPermissionId): ClaimPermission | ||
|
||
/** | ||
* Registers a new [ClaimPermission], the [ClaimPermission.id] must be unique. | ||
*/ | ||
public operator fun plusAssign(permission: ClaimPermission) | ||
} |
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
13 changes: 13 additions & 0 deletions
13
...in/kotlin/br/com/gamemods/minecity/fabric/service/permission/FabricDoorClaimPermission.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,13 @@ | ||
package br.com.gamemods.minecity.fabric.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 net.kyori.adventure.text.Component | ||
|
||
@InternalMineCityApi | ||
class FabricDoorClaimPermission: ClaimPermission( | ||
id = ClaimPermissionId.DOORS, | ||
name = Component.text("Doors"), | ||
description = Component.text("Allows the player to open and close doors in the claim.") | ||
) |