Skip to content

Commit dd04d86

Browse files
authored
Merge pull request #4 from simplecloudapp/feature/packets
Support for true custom names
2 parents 9a87e3c + af72cdd commit dd04d86

47 files changed

Lines changed: 1450 additions & 606 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.gradle.kts

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2+
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
23

34
plugins {
4-
kotlin("jvm") version "1.8.0"
5-
id("com.github.johnrengelman.shadow") version "8.1.1"
6-
java
5+
alias(libs.plugins.kotlin)
6+
alias(libs.plugins.shadow)
77
}
88

99
allprojects {
1010
group = "app.simplecloud.plugin"
11-
version = "1.0-SNAPSHOT"
12-
13-
apply {
14-
plugin("java")
15-
plugin("org.jetbrains.kotlin.jvm")
16-
plugin("com.github.johnrengelman.shadow")
17-
}
11+
version = "1.1-SNAPSHOT"
1812

1913
repositories {
2014
mavenCentral()
@@ -23,30 +17,47 @@ allprojects {
2317
maven("https://oss.sonatype.org/content/repositories/central")
2418
maven("https://repo.papermc.io/repository/maven-public/")
2519
maven("https://jitpack.io")
20+
maven("https://repo.dmulloy2.net/repository/public/")
2621
}
22+
}
2723

28-
kotlin {
29-
jvmToolchain(17)
24+
subprojects {
25+
26+
apply {
27+
plugin("org.jetbrains.kotlin.jvm")
28+
plugin("com.gradleup.shadow")
3029
}
3130

3231
dependencies {
32+
compileOnly(rootProject.libs.kotlin.jvm)
33+
compileOnly(rootProject.libs.kotlin.test)
34+
3335
compileOnly("net.luckperms:api:5.4")
36+
compileOnly("space.chunks.custom-names:custom-names-api:1.0.6")
3437
implementation("net.kyori:adventure-api:4.14.0")
3538
implementation("com.google.code.gson:gson:2.10.1")
3639
implementation("net.kyori:adventure-text-minimessage:4.14.0")
3740
}
38-
}
3941

40-
subprojects {
41-
dependencies {
42-
implementation(kotlin("stdlib"))
42+
java {
43+
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
44+
}
45+
46+
tasks.test {
47+
useJUnitPlatform()
4348
}
4449

45-
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
46-
kotlinOptions.jvmTarget = "17"
50+
kotlin {
51+
jvmToolchain(21)
52+
compilerOptions {
53+
jvmTarget = JvmTarget.JVM_21
54+
languageVersion = KotlinVersion.KOTLIN_2_0
55+
apiVersion = KotlinVersion.KOTLIN_2_0
56+
}
4757
}
4858

49-
tasks.named("shadowJar", ShadowJar::class) {
59+
tasks.shadowJar {
5060
mergeServiceFiles()
61+
archiveFileName.set("${project.name}.jar")
5162
}
5263
}

gradle/libs.versions.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[versions]
2+
kotlin = "2.0.20"
3+
shadow = "8.3.3"
4+
paper-api = "1.21.4-R0.1-SNAPSHOT"
5+
paperweight = "2.0.0-beta.12"
6+
7+
[libraries]
8+
kotlin-jvm = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
9+
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
10+
paper-api = { module = "io.papermc.paper:paper-api", version.ref = "paper-api" }
11+
12+
[plugins]
13+
paperweight-userdev = { id = "io.papermc.paperweight.userdev", version.ref = "paperweight" }
14+
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
15+
shadow = { id = "com.gradleup.shadow", version.ref = "shadow" }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
package app.simplecloud.plugin.prefixes.api
22

33
import net.kyori.adventure.text.Component
4+
import net.kyori.adventure.text.format.TextColor
45
import java.util.*
56

67
interface PrefixesActor {
7-
fun applyGroup(target: UUID, group: PrefixesGroup)
8-
9-
fun setPrefix(target: UUID, prefix: Component)
10-
11-
fun setSuffix(target: UUID, suffix: Component)
12-
13-
fun setColor(target: UUID, color: String)
14-
15-
fun formatMessage(target: UUID, format: String, message: Component): Component
16-
8+
fun registerViewer(target: UUID, api: PrefixesApi)
9+
fun hasViewer(target: UUID): Boolean
10+
fun removeViewer(target: UUID)
11+
fun applyGroup(target: UUID, group: PrefixesGroup, vararg viewers: UUID)
12+
fun setPrefix(target: UUID, prefix: Component, vararg viewers: UUID)
13+
fun setSuffix(target: UUID, suffix: Component, vararg viewers: UUID)
14+
fun setColor(target: UUID, color: TextColor, vararg viewers: UUID)
15+
fun apply(target: UUID, prefix: Component, color: TextColor, suffix: Component, priority: Int, vararg viewers: UUID)
16+
fun formatMessage(target: UUID, viewer: UUID?, format: String, message: Component): Component
1717
fun remove(target: UUID)
1818
}

prefixes-api/src/main/kotlin/app/simplecloud/plugin/prefixes/api/PrefixesApi.kt

Lines changed: 108 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,72 @@
11
package app.simplecloud.plugin.prefixes.api
22

3+
import net.kyori.adventure.audience.Audience
34
import net.kyori.adventure.text.Component
5+
import net.kyori.adventure.text.format.TextColor
46
import java.util.*
57

68
interface PrefixesApi {
79

10+
/**
11+
* Registers a player to be able to see prefixes
12+
* @param uniqueId UUID of the target player
13+
*/
14+
fun registerViewer(uniqueId: UUID)
15+
16+
/**
17+
* Returns if a viewer exists
18+
* @param uniqueId UUID of the target player
19+
*/
20+
fun hasViewer(uniqueId: UUID): Boolean
21+
22+
/**
23+
* Removes a viewer
24+
* @param uniqueId UUID of the target player
25+
*/
26+
fun removeViewer(uniqueId: UUID)
27+
828
/**
929
* Sets the prefix and suffix of a player in both Tab and Chat
1030
* @param uniqueId UUID of the target player
1131
* @param group
32+
* @param viewers A list of all viewers of this change (if empty, everyone is affected)
1233
*/
13-
fun setWholeName(uniqueId: UUID, group: PrefixesGroup)
34+
fun setWholeName(uniqueId: UUID, group: PrefixesGroup, vararg viewers: UUID)
1435

1536
/**
1637
* Sets the prefix and suffix of a player in both Tab and Chat
1738
* @param uniqueId UUID of the target player
1839
* @param groupName
40+
* @param viewers A list of all viewers of this change (if empty, everyone is affected)
41+
*/
42+
fun setWholeName(uniqueId: UUID, groupName: String, vararg viewers: UUID)
43+
44+
/**
45+
* Sets the prefix and suffix of a player in both Tab and Chat
46+
* @param uniqueId UUID of the target player
47+
* @param prefix the targets prefix
48+
* @param color the targets team color
49+
* @param suffix the targets suffix
50+
* @param priority the users Tablist priority
51+
* @param viewers A list of all viewers of this change (if empty, everyone is affected)
1952
*/
20-
fun setWholeName(uniqueId: UUID, groupName: String)
53+
fun setWholeName(uniqueId: UUID, prefix: Component, color: TextColor, suffix: Component, priority: Int, vararg viewers: UUID)
2154

2255
/**
2356
* Sets the prefix of a player in both Tab and Chat
2457
* @param uniqueId UUID of the target player
2558
* @param prefix prefix to set
59+
* @param viewers A list of all viewers of this change (if empty, everyone is affected)
2660
*/
27-
fun setPrefix(uniqueId: UUID, prefix: Component)
61+
fun setPrefix(uniqueId: UUID, prefix: Component, vararg viewers: UUID)
2862

2963
/**
3064
* Sets the prefix of a player in both Tab and Chat
3165
* @param uniqueId UUID of the target player
3266
* @param suffix suffix to set
67+
* @param viewers A list of all viewers of this change (if empty, everyone is affected)
3368
*/
34-
fun setSuffix(uniqueId: UUID, suffix: Component)
69+
fun setSuffix(uniqueId: UUID, suffix: Component, vararg viewers: UUID)
3570

3671
/**
3772
* Returns all registered [PrefixesGroup] ordered by priority
@@ -59,14 +94,81 @@ interface PrefixesApi {
5994
/**
6095
* Changes the Scoreboard Team color of the target player (Used in 1.12+ to make player names colorful)
6196
* @param uniqueId UUID of the target player
62-
* @param color Color string (ChatColor on spigot, hex colors on other server implementations)
97+
* @param color the [TextColor] of the target players team
98+
* @param viewers A list of all viewers of this change (if empty, everyone is affected)
6399
*/
64-
fun setColor(uniqueId: UUID, color: String)
100+
fun setColor(uniqueId: UUID, color: TextColor, vararg viewers: UUID)
65101

66102
/**
67103
* Sets the used PrefixesConfig
68104
* @param config Specifies the new [PrefixesConfig]
69105
*/
70106
fun setConfig(config: PrefixesConfig)
71107

108+
/**
109+
* Returns a formatted chat message of the target player that will be sent to the viewer
110+
* @param target UUID of the target player
111+
* @param viewer UUID of the viewing player (if null, only default prefix and suffix of the players group will be shown)
112+
* @param format the chat format the message should follow
113+
* @param message Message sent by the [target]
114+
*/
115+
fun formatChatMessage(target: UUID, viewer: UUID?, format: String, message: Component): Component
116+
/**
117+
* Sets the prefix and suffix of a player in both Tab and Chat
118+
* @param uniqueId UUID of the target player
119+
* @param group
120+
* @param viewers A list of all viewers of this change (if empty, everyone is affected)
121+
*/
122+
fun setWholeName(uniqueId: UUID, group: PrefixesGroup, viewers: Audience)
123+
124+
/**
125+
* Sets the prefix and suffix of a player in both Tab and Chat
126+
* @param uniqueId UUID of the target player
127+
* @param groupName
128+
* @param viewers An [Audience] of all viewers of this change (if empty, everyone is affected)
129+
*/
130+
fun setWholeName(uniqueId: UUID, groupName: String, viewers: Audience)
131+
132+
/**
133+
* Sets the prefix and suffix of a player in both Tab and Chat
134+
* @param uniqueId UUID of the target player
135+
* @param prefix the targets prefix
136+
* @param color the targets team color
137+
* @param suffix the targets suffix
138+
* @param viewers An [Audience] of all viewers of this change (if empty, everyone is affected)
139+
*/
140+
fun setWholeName(uniqueId: UUID, prefix: Component, color: TextColor, suffix: Component, priority: Int, viewers: Audience)
141+
/**
142+
* Sets the prefix of a player in both Tab and Chat
143+
* @param uniqueId UUID of the target player
144+
* @param prefix prefix to set
145+
* @param viewers A list of all viewers of this change (if empty, everyone is affected)
146+
*/
147+
fun setPrefix(uniqueId: UUID, prefix: Component, viewers: Audience)
148+
149+
/**
150+
* Sets the prefix of a player in both Tab and Chat
151+
* @param uniqueId UUID of the target player
152+
* @param suffix suffix to set
153+
* @param viewers An [Audience] of all viewers of this change (if empty, everyone is affected)
154+
*/
155+
fun setSuffix(uniqueId: UUID, suffix: Component, viewers: Audience)
156+
157+
/**
158+
* Changes the Scoreboard Team color of the target player (Used in 1.12+ to make player names colorful)
159+
* @param uniqueId UUID of the target player
160+
* @param color [TextColor] the color of the target players team
161+
* @param viewers An [Audience] of all viewers of this change (if empty, everyone is affected)
162+
*/
163+
fun setColor(uniqueId: UUID, color: TextColor, viewers: Audience)
164+
165+
/**
166+
* Returns a formatted chat message of the target player that will be sent to the viewer
167+
* @param target UUID of the target player
168+
* @param viewer An [Audience] of the viewing player (if empty, only default prefix and suffix of the targets group will be shown)
169+
* @param format the chat format the message should follow
170+
* @param message Message sent by the [target]
171+
*/
172+
fun formatChatMessage(target: UUID, viewer: Audience, format: String, message: Component): Component
173+
72174
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package app.simplecloud.plugin.prefixes.api
2+
3+
import app.simplecloud.plugin.prefixes.api.impl.PrefixesApiImpl
4+
5+
interface PrefixesChatLoader {
6+
7+
/**
8+
* Instantiates the chat provider of PrefixesApi (useful for sharding)
9+
* @param api the [PrefixesApiImpl] object the ChatLoader belongs to
10+
*/
11+
fun load(api: PrefixesApiImpl)
12+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package app.simplecloud.plugin.prefixes.api
2+
3+
import net.kyori.adventure.text.format.TextColor
4+
5+
interface PrefixesDisplay<C, P, T> {
6+
fun createTeam(id: String, priority: Int = 0): T?
7+
fun getTeam(id: String): T?
8+
fun updatePrefix(id: String, prefix: C)
9+
fun getPriority(team: T): Int?
10+
fun updateSuffix(id: String, suffix: C)
11+
12+
fun updatePriority(id: String, priority: Int): T?
13+
fun updateColor(id: String, color: TextColor)
14+
fun update(id: String, prefix: C, suffix: C, priority: Int)
15+
16+
fun toPriorityString(priority: Int): String {
17+
if (priority < 0) return "000"
18+
if (priority > 999) return "999"
19+
var result = priority.toString()
20+
for (i in 0 until 3 - result.length) {
21+
result = "0${result}"
22+
}
23+
return result
24+
}
25+
26+
fun setPlayer(id: String, player: P)
27+
fun removePlayer(player: P)
28+
fun setViewer(player: P): Boolean
29+
fun addViewer(player: P): Boolean
30+
fun removeViewer(player: P): Boolean
31+
fun getViewers(): Set<P>
32+
}

0 commit comments

Comments
 (0)