Skip to content

Commit ce9df23

Browse files
committed
Add automatic supporter tagging
1 parent e9977ff commit ce9df23

5 files changed

Lines changed: 91 additions & 1 deletion

File tree

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group = "com.kruthers"
8-
version = "2.5.2"
8+
version = "2.6.0"
99
description = "The core plugin used to manage the gamemode 4 public server"
1010

1111
repositories {

src/main/kotlin/com/kruthers/gamemode4core/Gamemode4Core.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ class Gamemode4Core : JavaPlugin() {
129129
this.server.pluginManager.registerEvents(PlayerRespawnEvent(this),this)
130130
this.server.pluginManager.registerEvents(TimeEvents(this),this)
131131
this.server.pluginManager.registerEvents(GriefEvents(this),this)
132+
PermissionEvent(this, luckPermsAPI)
132133

133134
this.logger.info("Loaded events")
134135
this.server.consoleSender.sendMessage("${ChatColor.GREEN}Gamemode 4 Core is now loaded in and ready to go")
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.kruthers.gamemode4core.events
2+
3+
import com.kruthers.gamemode4core.Gamemode4Core
4+
import net.kyori.adventure.text.Component
5+
import net.luckperms.api.LuckPerms
6+
import net.luckperms.api.event.node.NodeAddEvent
7+
import net.luckperms.api.event.node.NodeRemoveEvent
8+
import net.luckperms.api.model.user.User
9+
import net.luckperms.api.node.Node
10+
import net.luckperms.api.node.NodeType
11+
import net.luckperms.api.node.types.InheritanceNode
12+
import org.bukkit.Bukkit
13+
import org.bukkit.event.EventHandler
14+
15+
class PermissionEvent(val plugin: Gamemode4Core, perms: LuckPerms) {
16+
17+
init {
18+
val eventBus = perms.eventBus
19+
20+
eventBus.subscribe(NodeAddEvent::class.java, this::onNodeAddEvent)
21+
}
22+
23+
private fun onNodeAddEvent(event: NodeAddEvent) {
24+
val target = event.target
25+
if (event.isUser && target is User) {
26+
val node = event.node
27+
if (node.type == NodeType.INHERITANCE && node is InheritanceNode) {
28+
if (this.plugin.config.getStringList("donor_tagging.groups").contains(node.groupName)) {
29+
val uuid = target.uniqueId
30+
val player = Bukkit.getOfflinePlayer(uuid)
31+
if (player.isOnline && player.player != null) {
32+
player.player!!.scoreboardTags.add(this.plugin.config.getString("donor_tagging.tag")?: "donor")
33+
}
34+
}
35+
}
36+
}
37+
}
38+
39+
private fun onNodeRemoveEvent(event: NodeRemoveEvent) {
40+
val target = event.target
41+
if (event.isUser && target is User) {
42+
val node = event.node
43+
if (node.type == NodeType.INHERITANCE && node is InheritanceNode) {
44+
val groups = this.plugin.config.getStringList("donor_tagging.groups")
45+
if (groups.contains(node.groupName)) {
46+
val uuid = target.uniqueId
47+
val player = Bukkit.getOfflinePlayer(uuid)
48+
if (player.isOnline && player.player != null) {
49+
var stillDonor = false
50+
//check if they still have any other donor roles
51+
target.getInheritedGroups(target.queryOptions).forEach { group ->
52+
if (!stillDonor && groups.contains(group.name)) stillDonor = true
53+
}
54+
55+
//if they have no donor roles, remove the donor tag
56+
if (!stillDonor) player.player!!.scoreboardTags.remove(this.plugin.config.getString("donor_tagging.tag")?: "donor")
57+
}
58+
}
59+
}
60+
}
61+
}
62+
63+
64+
}

src/main/kotlin/com/kruthers/gamemode4core/events/PlayerConnectionEvents.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,26 @@ class PlayerConnectionEvents(val plugin: Gamemode4Core): Listener {
101101
}
102102
}
103103
}
104+
105+
//check roles for donor roles
106+
Bukkit.getScheduler().runTask(this.plugin, Runnable {
107+
val user = Gamemode4Core.luckPermsAPI.userManager.loadUser(player.uniqueId).get()
108+
val groups = this.plugin.config.getStringList("donor_tagging.groups")
109+
var isDonor = false
110+
111+
//check if the user has a donor role
112+
user.getInheritedGroups(user.queryOptions).forEach { group ->
113+
if (!isDonor && groups.contains(group.name)) isDonor = true
114+
}
115+
116+
//if they are a donor, give them the tag, if not remove it
117+
val tag = this.plugin.config.getString("donor_tagging.tag")?: "donor"
118+
if (isDonor) {
119+
player.scoreboardTags.add(tag)
120+
} else {
121+
player.scoreboardTags.remove(tag)
122+
}
123+
})
104124
}
105125

106126

src/main/resources/config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ dim_sleep_bug:
3131
keep_time_in_sync:
3232
- world
3333
- world_2
34+
donor_tagging:
35+
groups:
36+
- patreon
37+
- donor
38+
tag: donor
3439
messages:
3540
prefix: '<dark_aqua>[<aqua>GM4</aqua>]</dark_aqua>'
3641
staff_prefix: '<yellow>[STAFF]</yellow>'

0 commit comments

Comments
 (0)