mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
Move permissions to common yml
This commit is contained in:
5 files changed
+95
-98
No files matched your search
@@ -4,6 +4,7 @@ plugins {
|
||||
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
mavenCentral()
|
||||
maven("https://repo.stellardrift.ca/repository/snapshots/")
|
||||
}
|
||||
|
||||
@@ -12,6 +13,7 @@ dependencies {
|
||||
implementation(libs.indraCommon)
|
||||
implementation(libs.indraLicenseHeader)
|
||||
implementation(libs.licenser)
|
||||
implementation("org.spongepowered:configurate-yaml:4.0.0")
|
||||
|
||||
// https://github.com/gradle/gradle/issues/15383#issuecomment-779893192
|
||||
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import io.leangen.geantyref.TypeToken
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.model.ObjectFactory
|
||||
import org.gradle.api.provider.ListProperty
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.kotlin.dsl.listProperty
|
||||
import org.spongepowered.configurate.ConfigurationNode
|
||||
import org.spongepowered.configurate.yaml.NodeStyle
|
||||
import org.spongepowered.configurate.yaml.YamlConfigurationLoader
|
||||
import javax.inject.Inject
|
||||
|
||||
abstract class CarbonPermissionsExtension @Inject constructor(private val objects: ObjectFactory) {
|
||||
abstract val yaml: RegularFileProperty
|
||||
|
||||
val permissions: Provider<List<Permission>> = create()
|
||||
|
||||
private fun create(): ListProperty<Permission> = objects.listProperty<Permission>().also {
|
||||
it.set(yaml.map { file ->
|
||||
val loader = YamlConfigurationLoader.builder()
|
||||
.path(file.asFile.toPath())
|
||||
.nodeStyle(NodeStyle.BLOCK)
|
||||
.build()
|
||||
loader.load().childrenMap().map { (name, child) ->
|
||||
loadPermission(name as String, child)
|
||||
}
|
||||
})
|
||||
it.disallowChanges()
|
||||
it.finalizeValueOnRead()
|
||||
}
|
||||
|
||||
private fun loadPermission(name: String, node: ConfigurationNode): Permission {
|
||||
return if (node.isMap) {
|
||||
Permission(
|
||||
name,
|
||||
node.node("description").string,
|
||||
node.node("children").takeIf { c -> !c.virtual() }
|
||||
?.get(object : TypeToken<HashMap<String, Boolean>>() {})
|
||||
)
|
||||
} else {
|
||||
Permission(name, node.string, null)
|
||||
}
|
||||
}
|
||||
|
||||
data class Permission(
|
||||
val string: String,
|
||||
val description: String?,
|
||||
val children: Map<String, Boolean>?
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
val ext = extensions.create("carbonPermission", CarbonPermissionsExtension::class.java)
|
||||
ext.yaml.convention(rootProject.layout.projectDirectory.file("common/src/main/resources/carbon-permissions.yml"))
|
||||
@@ -0,0 +1,35 @@
|
||||
carbon.clearchat:
|
||||
description: "Clears the chat for all players except those with carbon.chearchat.exempt."
|
||||
children:
|
||||
carbon.clearchat.clear: true
|
||||
carbon.clearchat.clear: "Clears the chat for all players except those with carbon.chearchat.exempt."
|
||||
carbon.clearchat.exempt: "Exempts the player from having their chat cleared when /clearchat is executed."
|
||||
carbon.debug: "Allows the sender to quickly check what carbon think's the player's primary and non-primary groups are."
|
||||
carbon.help: "Shows Carbon's help menu, detailing each part of Carbon's commands."
|
||||
carbon.hideidentity: "Prevents messages from the player from being blocked clientside."
|
||||
carbon.ignore: "Ignores the player, hiding messages they send in chat and in whispers."
|
||||
carbon.ignore.exempt: "Prevents the player from being ignored."
|
||||
carbon.ignore.unignore: "Removes the player from the sender's ignore list."
|
||||
carbon.itemlink: "Shows the player's held or equipped item in chat."
|
||||
carbon.mute: "Mutes the player, preventing them from sending messages or whispers."
|
||||
carbon.mute.exempt: "Prevents the player from being muted."
|
||||
carbon.mute.info: "Shows if the player is muted or now."
|
||||
carbon.mute.notify: "Notifies the player when someone else has been mute."
|
||||
carbon.mute.unmute: "Unmutes the player, allowing them to use chat and send whispers."
|
||||
carbon.nickname: "Checks your nickname."
|
||||
carbon.nickname.set: "Set or remove your nickname."
|
||||
carbon.nickname.others: "Checks other player's nicknames."
|
||||
carbon.nickname.others.set: "Set or remove other player's nicknames."
|
||||
carbon.nickname.style.color: "Allows the use of colors in nicknames."
|
||||
carbon.nickname.style.gradient: "Allows the use of gradients in nicknames."
|
||||
carbon.nickname.style.decorations: "Allows the use of decorations in nicknames."
|
||||
carbon.nickname.style.hoverEvent: "Allows the use of hover events in nicknames."
|
||||
carbon.nickname.style.clickEvent: "Allows the use of click events in nicknames."
|
||||
carbon.nickname.style.insertion: "Allows the use of insertions in nicknames."
|
||||
carbon.nickname.style.rainbow: "Allows the use of the rainbow tag in nicknames."
|
||||
carbon.nickname.style.reset: "Allows the use of the reset tag in nicknames."
|
||||
carbon.reload: "Reloads Carbon's config, channel settings, and translations."
|
||||
carbon.whisper: "Sends private messages to other players."
|
||||
carbon.whisper.continue: "Sends a message to the last player you whispered."
|
||||
carbon.whisper.reply: "Sends a message to the last player who messaged you."
|
||||
carbon.whisper.vanished: "Allows the player to send messages to vanished players."
|
||||
+7
-98
@@ -2,6 +2,7 @@ plugins {
|
||||
id("carbon.shadow-platform")
|
||||
id("net.minecrell.plugin-yml.bukkit")
|
||||
id("xyz.jpenilla.run-paper")
|
||||
id("carbon.permissions")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -47,103 +48,11 @@ bukkit {
|
||||
depend = listOf("LuckPerms")
|
||||
softDepend = listOf("PlaceholderAPI", "EssentialsDiscord", "DiscordSRV")
|
||||
website = GITHUB_REPO_URL
|
||||
permissions {
|
||||
register("carbon.clearchat") {
|
||||
description = "Clears the chat for all players except those with carbon.chearchat.exempt."
|
||||
childrenMap = mapOf("carbon.clearchat.clear" to true)
|
||||
}
|
||||
register("carbon.clearchat.clear") {
|
||||
description = "Clears the chat for all players except those with carbon.chearchat.exempt."
|
||||
}
|
||||
register("carbon.clearchat.exempt") {
|
||||
description = "Exempts the player from having their chat cleared when /clearchat is executed."
|
||||
}
|
||||
register("carbon.debug") {
|
||||
description = "Allows the sender to quickly check what carbon think's the player's primary and non-primary groups are."
|
||||
}
|
||||
register("carbon.help") {
|
||||
description = "Shows Carbon's help menu, detailing each part of Carbon's commands."
|
||||
}
|
||||
register("carbon.hideidentity") {
|
||||
description = "Prevents messages from the player from being blocked clientside."
|
||||
}
|
||||
register("carbon.ignore") {
|
||||
description = "Ignores the player, hiding messages they send in chat and in whispers."
|
||||
}
|
||||
register("carbon.ignore.exempt") {
|
||||
description = "Prevents the player from being ignored."
|
||||
}
|
||||
register("carbon.ignore.unignore") {
|
||||
description = "Removes the player from the sender's ignore list."
|
||||
}
|
||||
register("carbon.itemlink") {
|
||||
description = "Shows the player's held or equipped item in chat."
|
||||
}
|
||||
register("carbon.mute") {
|
||||
description = "Mutes the player, preventing them from sending messages or whispers."
|
||||
}
|
||||
register("carbon.mute.exempt") {
|
||||
description = "Prevents the player from being muted."
|
||||
}
|
||||
register("carbon.mute.info") {
|
||||
description = "Shows if the player is muted or now."
|
||||
}
|
||||
register("carbon.mute.notify") {
|
||||
description = "Notifies the player when someone else has been mute."
|
||||
}
|
||||
register("carbon.mute.unmute") {
|
||||
description = "Unmutes the player, allowing them to use chat and send whispers."
|
||||
}
|
||||
register("carbon.nickname") {
|
||||
description = "Checks your nickname."
|
||||
}
|
||||
register("carbon.nickname.set") {
|
||||
description = "Set or remove your nickname."
|
||||
}
|
||||
register("carbon.nickname.others") {
|
||||
description = "Checks other player's nicknames."
|
||||
}
|
||||
register("carbon.nickname.others.set") {
|
||||
description = "Set or remove other player's nicknames."
|
||||
}
|
||||
register("carbon.nickname.style.color") {
|
||||
description = "Allows the use of colors in nicknames."
|
||||
}
|
||||
register("carbon.nickname.style.gradient") {
|
||||
description = "Allows the use of gradients in nicknames."
|
||||
}
|
||||
register("carbon.nickname.style.decorations") {
|
||||
description = "Allows the use of decorations in nicknames."
|
||||
}
|
||||
register("carbon.nickname.style.hoverEvent") {
|
||||
description = "Allows the use of hover events in nicknames."
|
||||
}
|
||||
register("carbon.nickname.style.clickEvent") {
|
||||
description = "Allows the use of click events in nicknames."
|
||||
}
|
||||
register("carbon.nickname.style.insertion") {
|
||||
description = "Allows the use of insertions in nicknames."
|
||||
}
|
||||
register("carbon.nickname.style.rainbow") {
|
||||
description = "Allows the use of the rainbow tag in nicknames."
|
||||
}
|
||||
register("carbon.nickname.style.reset") {
|
||||
description = "Allows the use of the reset tag in nicknames."
|
||||
}
|
||||
register("carbon.reload") {
|
||||
description = "Reloads Carbon's config, channel settings, and translations."
|
||||
}
|
||||
register("carbon.whisper") {
|
||||
description = "Sends private messages to other players."
|
||||
}
|
||||
register("carbon.whisper.continue") {
|
||||
description = "Sends a message to the last player you whispered."
|
||||
}
|
||||
register("carbon.whisper.reply") {
|
||||
description = "Sends a message to the last player who messaged you."
|
||||
}
|
||||
register("carbon.whisper.vanished") {
|
||||
description = "Allows the player to send messages to vanished players."
|
||||
}
|
||||
}
|
||||
|
||||
carbonPermission.permissions.get().forEach {
|
||||
bukkit.permissions.register(it.string) {
|
||||
description = it.description
|
||||
childrenMap = it.children
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user