Skip to content

Commit

Permalink
add stuff for mutliple platforms support
Browse files Browse the repository at this point in the history
  • Loading branch information
powercasgamer committed Nov 27, 2023
1 parent ddba8ea commit 9ba8541
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 15 deletions.
11 changes: 11 additions & 0 deletions build-logic/src/main/kotlin/common-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ tasks {
withType<ProcessResources>().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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<T> {

fun config(): Config

fun plugin(): T
}
Original file line number Diff line number Diff line change
@@ -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)
}
17 changes: 11 additions & 6 deletions paper/src/main/kotlin/dev/mizule/timetriggeredperms/paper/TTP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,18 @@
*/
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
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<JavaPlugin> {

private val configPath = dataFolder.resolve("permissions.yml")

Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<JavaPlugin>) : AbstractLuckPermsListener(plugin) {

override fun onExpire(event: NodeRemoveEvent) {
val permissionNode = event.node as PermissionNode

val configNode = nodeConfig(permissionNode.permission)
Expand All @@ -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)
}
}

0 comments on commit 9ba8541

Please sign in to comment.