From 9ba8541cf3341750b43257283972027f8f40eff7 Mon Sep 17 00:00:00 2001 From: powercas_gamer Date: Mon, 27 Nov 2023 16:13:12 +0100 Subject: [PATCH] add stuff for mutliple platforms support --- .../main/kotlin/common-conventions.gradle.kts | 11 +++++ .../timetriggeredperms/core/TTPPlugin.kt | 34 ++++++++++++++ .../listener/AbstractLuckPermsListener.kt | 46 +++++++++++++++++++ .../mizule/timetriggeredperms/paper/TTP.kt | 17 ++++--- .../paper/listener/LuckPermsListener.kt | 16 +++---- 5 files changed, 109 insertions(+), 15 deletions(-) create mode 100644 core/src/main/kotlin/dev/mizule/timetriggeredperms/core/TTPPlugin.kt create mode 100644 core/src/main/kotlin/dev/mizule/timetriggeredperms/core/listener/AbstractLuckPermsListener.kt diff --git a/build-logic/src/main/kotlin/common-conventions.gradle.kts b/build-logic/src/main/kotlin/common-conventions.gradle.kts index 63dd7c7..db80155 100644 --- a/build-logic/src/main/kotlin/common-conventions.gradle.kts +++ b/build-logic/src/main/kotlin/common-conventions.gradle.kts @@ -103,6 +103,17 @@ tasks { withType().configureEach { filteringCharset = "UTF-8" duplicatesStrategy = DuplicatesStrategy.INCLUDE + + val praps = mapOf( + "pluginVersion" to project.versionString(), + "pluginAuthor" to providers.gradleProperty("projectAuthor").getOrElse("template"), + "pluginName" to providers.gradleProperty("projectName").getOrElse("template"), + "pluginDescription" to (project.description ?: "A template project") + ) + + filesMatching(setOf("paper-plugin.yml", "plugin.yml", "velocity-plugin.json")) { + expand(praps) + } } javadoc { diff --git a/core/src/main/kotlin/dev/mizule/timetriggeredperms/core/TTPPlugin.kt b/core/src/main/kotlin/dev/mizule/timetriggeredperms/core/TTPPlugin.kt new file mode 100644 index 0000000..5e7b63a --- /dev/null +++ b/core/src/main/kotlin/dev/mizule/timetriggeredperms/core/TTPPlugin.kt @@ -0,0 +1,34 @@ +/* + * 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 + +import dev.mizule.timetriggeredperms.core.config.Config + +interface TTPPlugin { + + fun config(): Config + + fun plugin(): T +} diff --git a/core/src/main/kotlin/dev/mizule/timetriggeredperms/core/listener/AbstractLuckPermsListener.kt b/core/src/main/kotlin/dev/mizule/timetriggeredperms/core/listener/AbstractLuckPermsListener.kt new file mode 100644 index 0000000..646b52e --- /dev/null +++ b/core/src/main/kotlin/dev/mizule/timetriggeredperms/core/listener/AbstractLuckPermsListener.kt @@ -0,0 +1,46 @@ +/* + * 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.listener + +import dev.mizule.timetriggeredperms.core.TTPPlugin +import net.luckperms.api.LuckPermsProvider +import net.luckperms.api.event.node.NodeRemoveEvent + +abstract class AbstractLuckPermsListener(plugin: TTPPlugin<*>) { + + init { + LuckPermsProvider.get().eventBus.subscribe(plugin, NodeRemoveEvent::class.java) { + onExpire0(it) + } + } + + private fun onExpire0(event: NodeRemoveEvent) { + if (event.node.hasExpired()) { + onExpire0(event) + } + } + + abstract fun onExpire(event: NodeRemoveEvent) +} diff --git a/paper/src/main/kotlin/dev/mizule/timetriggeredperms/paper/TTP.kt b/paper/src/main/kotlin/dev/mizule/timetriggeredperms/paper/TTP.kt index 1e43e4c..d811626 100644 --- a/paper/src/main/kotlin/dev/mizule/timetriggeredperms/paper/TTP.kt +++ b/paper/src/main/kotlin/dev/mizule/timetriggeredperms/paper/TTP.kt @@ -24,11 +24,10 @@ */ package dev.mizule.timetriggeredperms.paper +import dev.mizule.timetriggeredperms.core.TTPPlugin import dev.mizule.timetriggeredperms.core.config.Config import dev.mizule.timetriggeredperms.paper.command.ReloadCommand import dev.mizule.timetriggeredperms.paper.listener.LuckPermsListener -import net.luckperms.api.LuckPermsProvider -import net.luckperms.api.event.node.NodeRemoveEvent import org.bukkit.Bukkit import org.bukkit.plugin.java.JavaPlugin import org.spongepowered.configurate.kotlin.extensions.get @@ -36,7 +35,7 @@ import org.spongepowered.configurate.kotlin.objectMapperFactory import org.spongepowered.configurate.yaml.NodeStyle import org.spongepowered.configurate.yaml.YamlConfigurationLoader -class TTP : JavaPlugin() { +class TTP : JavaPlugin(), TTPPlugin { private val configPath = dataFolder.resolve("permissions.yml") @@ -62,10 +61,16 @@ class TTP : JavaPlugin() { configNode.set(config) // update the backing node to add defaults configLoader.save(configNode) } - LuckPermsProvider.get().eventBus.subscribe(this, NodeRemoveEvent::class.java) { - LuckPermsListener(this).onExpire(it) - } + LuckPermsListener(this) Bukkit.getCommandMap().register("timetriggeredperms", ReloadCommand(this)) } + + override fun config(): Config { + return config + } + + override fun plugin(): JavaPlugin { + return this + } } diff --git a/paper/src/main/kotlin/dev/mizule/timetriggeredperms/paper/listener/LuckPermsListener.kt b/paper/src/main/kotlin/dev/mizule/timetriggeredperms/paper/listener/LuckPermsListener.kt index 7577116..755dd07 100644 --- a/paper/src/main/kotlin/dev/mizule/timetriggeredperms/paper/listener/LuckPermsListener.kt +++ b/paper/src/main/kotlin/dev/mizule/timetriggeredperms/paper/listener/LuckPermsListener.kt @@ -24,21 +24,19 @@ */ package dev.mizule.timetriggeredperms.paper.listener +import dev.mizule.timetriggeredperms.core.TTPPlugin import dev.mizule.timetriggeredperms.core.config.PermissionThing -import dev.mizule.timetriggeredperms.paper.TTP +import dev.mizule.timetriggeredperms.core.listener.AbstractLuckPermsListener import net.luckperms.api.event.node.NodeRemoveEvent import net.luckperms.api.model.user.User import net.luckperms.api.node.types.PermissionNode import org.bukkit.Bukkit +import org.bukkit.plugin.java.JavaPlugin import org.bukkit.scheduler.BukkitTask -class LuckPermsListener(val plugin: TTP) { - - fun onExpire(event: NodeRemoveEvent) { - val node = event.node - - if (!node.hasExpired()) return +class LuckPermsListener(private val plugin: TTPPlugin) : AbstractLuckPermsListener(plugin) { + override fun onExpire(event: NodeRemoveEvent) { val permissionNode = event.node as PermissionNode val configNode = nodeConfig(permissionNode.permission) @@ -59,10 +57,10 @@ class LuckPermsListener(val plugin: TTP) { } fun nodeConfig(perm: String): PermissionThing { - return plugin.config.permissions.values.first { it.permission == perm } + return plugin.config().permissions.values.first { it.permission == perm } } fun sync(task: (BukkitTask) -> Unit) { - Bukkit.getScheduler().runTask(plugin, task) + Bukkit.getScheduler().runTask(plugin.plugin(), task) } }