Skip to content
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

velocity. #4

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build-logic/src/main/kotlin/common-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ tasks {
relocate("org.bstats", "dev.mizule.timetriggeredperms.lib.org.bstats")
}

create("format") {
dependsOn("spotlessApply")
}

withType<JavaCompile>().configureEach {
options.isFork = true
options.isIncremental = true
Expand Down
37 changes: 37 additions & 0 deletions build-logic/src/main/kotlin/gremlin-stuff.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import org.jetbrains.kotlin.gradle.utils.extendsFrom

plugins {
id("common-conventions")
id("xyz.jpenilla.gremlin-gradle")
}

val runtimeDownloadOnlyApi by configurations.registering
val runtimeDownloadApi by configurations.registering

configurations {
compileOnlyApi.extendsFrom(runtimeDownloadOnlyApi)
runtimeDownload.extendsFrom(runtimeDownloadOnlyApi)
api.extendsFrom(runtimeDownloadApi)
runtimeDownload.extendsFrom(runtimeDownloadApi)
}

dependencies {
implementation(libs.gremlin.runtime)
}

tasks.writeDependencies {
outputFileName.set("dependencies.txt")
repos.add("https://repo.papermc.io/repository/maven-public/")
repos.add("https://repo.maven.apache.org/maven2/")
repos.add("https://maven.mizule.dev/")
}

gremlin {
defaultJarRelocatorDependencies.set(true)
defaultGremlinRuntimeDependency.set(false)
}

configurations.runtimeDownload {
exclude("org.checkerframework", "checker-qual")
exclude("org.jetbrains", "annotations")
}
2 changes: 1 addition & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies {
compileOnly(kotlin("stdlib"))
compileOnly(kotlin("reflect"))
compileOnlyApi("net.luckperms:api:5.4")
compileOnly("org.spongepowered:configurate-yaml:4.2.0-SNAPSHOT")
compileOnly("org.spongepowered:configurate-hocon:4.2.0-SNAPSHOT")
compileOnly("org.spongepowered:configurate-extra-kotlin:4.2.0-SNAPSHOT")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ interface TTPPlugin<T> {

fun config(): Config

fun reloadConfiguration()

fun plugin(): T
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ import org.spongepowered.configurate.objectmapping.meta.Setting
data class Config(

@Setting(nodeFromParent = true)
val permissions: Map<String, PermissionThing> = mapOf("example" to PermissionThing("test.permission", listOf("say example"))),
val permissions: Map<String, PermissionThing> = mapOf(
"example" to PermissionThing(
"test.permission",
listOf("say example"),
Target.USER,
),
),

)

Expand All @@ -50,4 +56,18 @@ data class PermissionThing(
"%permission% - the permission that got removed",
)
val commands: List<String>,

@Comment(
"Available options are:\n" +
"USER - If this should be called for Users only\n" +
"GROUP - If this should be called for Groups only\n" +
"ALL - If this should be called for Users and Groups",
)
val target: Target,
)

enum class Target {
USER,
GROUP,
ALL,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* This file is part of TimeTriggeredPerms, licensed under the MIT License.
*
* Copyright (c) 2023 powercas_gamer
* Copyright (c) 2023 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package dev.mizule.timetriggeredperms.core.config

import org.spongepowered.configurate.hocon.HoconConfigurationLoader
import org.spongepowered.configurate.kotlin.extensions.get
import org.spongepowered.configurate.kotlin.objectMapperFactory
import java.nio.file.Path
import kotlin.io.path.exists

object ConfigManager {

fun loadConfig(path: Path): Config {
val configLoader = HoconConfigurationLoader.builder()
.path(path)
.indent(2)
.defaultOptions { options ->
options.shouldCopyDefaults(true)
options.serializers { builder ->
builder.registerAnnotatedObjects(objectMapperFactory())
}
}
.build()
val configNode = configLoader.load()
val config = requireNotNull(configNode.get<Config>()) {
"Could not read configuration"
}

if (!path.exists()) {
configNode.set(config) // update the backing node to add defaults
configLoader.save(configNode)
}

return config
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
package dev.mizule.timetriggeredperms.core.listener

import dev.mizule.timetriggeredperms.core.TTPPlugin
import dev.mizule.timetriggeredperms.core.config.PermissionThing
import net.luckperms.api.LuckPermsProvider
import net.luckperms.api.event.node.NodeRemoveEvent

abstract class AbstractLuckPermsListener(plugin: TTPPlugin<*>) {
abstract class AbstractLuckPermsListener(private val plugin: TTPPlugin<*>) {

init {
LuckPermsProvider.get().eventBus.subscribe(plugin, NodeRemoveEvent::class.java) {
Expand All @@ -38,9 +39,13 @@ abstract class AbstractLuckPermsListener(plugin: TTPPlugin<*>) {

private fun onExpire0(event: NodeRemoveEvent) {
if (event.node.hasExpired()) {
onExpire0(event)
onExpire(event)
}
}

abstract fun onExpire(event: NodeRemoveEvent)

fun nodeFromConfig(perm: String): PermissionThing? {
return plugin.config().permissions.values.firstOrNull { it.permission == perm }
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# build-logic stuff
javadocPublishRoot=https://jd.mizule.dev/personal/imagery/
javadocPublishRoot=https://jd.mizule.dev/personal/timetriggeredperms/
githubOrg=powercasgamer
projectAuthor=powercasgamer
githubRepo=TimeTriggeredPerms
Expand Down
37 changes: 2 additions & 35 deletions paper/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
import java.util.*

plugins {
id("common-conventions")
id("kotlin-conventions")
id("paper-conventions")
id("xyz.jpenilla.gremlin-gradle")
}

fun DependencyHandler.runtimeDownloadApi(dependencyNotation: Any) {
api(dependencyNotation)
runtimeDownload(dependencyNotation)
}

fun DependencyHandler.runtimeDownloadOnlyApi(dependencyNotation: Any) {
compileOnlyApi(dependencyNotation)
runtimeDownload(dependencyNotation)
id("gremlin-stuff")
}

dependencies {
api(projects.timetriggeredpermsCore)
compileOnly("io.papermc.paper:paper-api:1.20.2-R0.1-SNAPSHOT")
compileOnly("net.luckperms:api:5.4")
implementation(libs.gremlin.runtime)

runtimeDownloadOnlyApi(kotlin("stdlib"))
runtimeDownloadOnlyApi(kotlin("reflect"))
runtimeDownloadOnlyApi("org.spongepowered:configurate-yaml:4.2.0-SNAPSHOT")
runtimeDownloadOnlyApi("org.spongepowered:configurate-hocon:4.2.0-SNAPSHOT")
runtimeDownloadOnlyApi("org.spongepowered:configurate-extra-kotlin:4.2.0-SNAPSHOT")
implementation("org.bstats:bstats-bukkit:3.0.2")
}
Expand All @@ -44,22 +30,3 @@ idea {
isDownloadSources = true
}
}

tasks.writeDependencies {
outputFileName.set("dependencies.txt")
repos.add("https://repo.papermc.io/repository/maven-public/")
repos.add("https://repo.maven.apache.org/maven2/")
repos.add("https://maven.mizule.dev/")
repos.add("https://maven.reposilite.com/snapshots/")
repos.add("https://maven.reposilite.com/releases/")
}

gremlin {
defaultJarRelocatorDependencies.set(true)
defaultGremlinRuntimeDependency.set(false)
}

configurations.runtimeDownload {
exclude("org.checkerframework", "checker-qual")
exclude("org.jetbrains", "annotations")
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,43 +26,22 @@ package dev.mizule.timetriggeredperms.paper

import dev.mizule.timetriggeredperms.core.TTPPlugin
import dev.mizule.timetriggeredperms.core.config.Config
import dev.mizule.timetriggeredperms.core.config.ConfigManager
import dev.mizule.timetriggeredperms.paper.command.ReloadCommand
import dev.mizule.timetriggeredperms.paper.listener.LuckPermsListener
import org.bstats.bukkit.Metrics
import org.bukkit.Bukkit
import org.bukkit.plugin.java.JavaPlugin
import org.spongepowered.configurate.kotlin.extensions.get
import org.spongepowered.configurate.kotlin.objectMapperFactory
import org.spongepowered.configurate.yaml.NodeStyle
import org.spongepowered.configurate.yaml.YamlConfigurationLoader

class TTP : JavaPlugin(), TTPPlugin<JavaPlugin> {

private val configPath = dataFolder.resolve("permissions.yml")
private val configPath = dataFolder.resolve("permissions.conf").toPath()
private val pluginId = 20404

val configLoader = YamlConfigurationLoader.builder()
.file(configPath)
.nodeStyle(NodeStyle.BLOCK)
.indent(2)
.defaultOptions { options ->
options.shouldCopyDefaults(true)
options.serializers { builder ->
builder.registerAnnotatedObjects(objectMapperFactory())
}
}
.build()

var configNode = configLoader.load()
var config = requireNotNull(configNode.get<Config>()) {
"Could not read configuration"
}
private lateinit var config: Config

override fun onEnable() {
if (!configPath.exists()) {
configNode.set(config) // update the backing node to add defaults
configLoader.save(configNode)
}
this.config = ConfigManager.loadConfig(configPath)
Metrics(this, pluginId)
LuckPermsListener(this)

Expand All @@ -73,6 +52,10 @@ class TTP : JavaPlugin(), TTPPlugin<JavaPlugin> {
return config
}

override fun reloadConfiguration() {
this.config = ConfigManager.loadConfig(configPath)
}

override fun plugin(): JavaPlugin {
return this
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
*/
package dev.mizule.timetriggeredperms.paper.command

import dev.mizule.timetriggeredperms.core.config.Config
import dev.mizule.timetriggeredperms.paper.TTP
import org.bukkit.command.Command
import org.bukkit.command.CommandSender
Expand All @@ -37,11 +36,7 @@ class ReloadCommand(val plugin: TTP) : Command("ttpreload") {
}

override fun execute(sender: CommandSender, commandLabel: String, args: Array<out String>?): Boolean {
var configNode = plugin.configLoader.load()
var config = requireNotNull(configNode.get<Config>()) {
"Could not read configuration"
}
plugin.config = config
plugin.reloadConfiguration()

sender.sendMessage("reloaded")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
package dev.mizule.timetriggeredperms.paper.listener

import dev.mizule.timetriggeredperms.core.TTPPlugin
import dev.mizule.timetriggeredperms.core.config.PermissionThing
import dev.mizule.timetriggeredperms.core.listener.AbstractLuckPermsListener
import net.luckperms.api.event.node.NodeRemoveEvent
import net.luckperms.api.model.user.User
Expand All @@ -39,7 +38,8 @@ class LuckPermsListener(private val plugin: TTPPlugin<JavaPlugin>) : AbstractLuc
override fun onExpire(event: NodeRemoveEvent) {
val permissionNode = event.node as PermissionNode

val configNode = nodeConfig(permissionNode.permission)
val configNode = nodeFromConfig(permissionNode.permission) ?: return

val isUser = event.isUser

sync {
Expand All @@ -56,10 +56,6 @@ class LuckPermsListener(private val plugin: TTPPlugin<JavaPlugin>) : AbstractLuc
}
}

fun nodeConfig(perm: String): PermissionThing {
return plugin.config().permissions.values.first { it.permission == perm }
}

fun sync(task: (BukkitTask) -> Unit) {
Bukkit.getScheduler().runTask(plugin.plugin(), task)
}
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ rootProject.name = "TimeTriggeredPerms"

sequenceOf(
"paper",
"velocity",
"core"
).forEach {
include("timetriggeredperms-$it")
Expand Down
Loading