mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-19 15:09:19 +00:00
Compare commits
375 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a1a631557 | ||
|
|
ad282a9efe | ||
|
|
86ef4d0efa | ||
|
|
da09a542f1 | ||
|
|
62f32cc03d | ||
|
|
ff1addfd65 | ||
|
|
73f013bf1f | ||
|
|
204fee4456 | ||
|
|
e7ea62a4d2 | ||
|
|
42802e41b4 | ||
|
|
7e7d81d0f8 | ||
|
|
b07c3c9878 | ||
|
|
a19d564460 | ||
|
|
b3408143f0 | ||
|
|
3c1539285d | ||
|
|
a642d88af2 | ||
|
|
36d4009f5e | ||
|
|
bebee807bc | ||
|
|
26c579b69f | ||
|
|
ef665e7e83 | ||
|
|
7a6475c467 | ||
|
|
63963cccc3 | ||
|
|
7cf6a3c75c | ||
|
|
22a5bb4cf1 | ||
|
|
148d163d9c | ||
|
|
ef36e66c51 | ||
|
|
e5fda588c3 | ||
|
|
3baf2694be | ||
|
|
a1dafdee5b | ||
|
|
e3a42d8b4a | ||
|
|
b366f5930b | ||
|
|
45eb1fa668 | ||
|
|
c466405a81 | ||
|
|
172ffc0333 | ||
|
|
41ac857a11 | ||
|
|
737d63642c | ||
|
|
7b9b7678a3 | ||
|
|
fe88d0c608 | ||
|
|
e14935af7b | ||
|
|
3e83d370f8 | ||
|
|
874a7f5624 | ||
|
|
3af992a291 | ||
|
|
9ef7791998 | ||
|
|
1cbe17ddd4 | ||
|
|
2841742af9 | ||
|
|
6e2f333404 | ||
|
|
af8949b713 | ||
|
|
d6f7d0fcb3 | ||
|
|
a8f035bbe2 | ||
|
|
301fd6a349 | ||
|
|
90b71e7dc9 | ||
|
|
e6827cdf72 | ||
|
|
1212ab2025 | ||
|
|
e31f000de6 | ||
|
|
70028598d5 | ||
|
|
07b772d228 | ||
|
|
065e48c125 | ||
|
|
49eb1d61ef | ||
|
|
9e1a30025f | ||
|
|
76429ed041 | ||
|
|
f5a01c0104 | ||
|
|
545f258f90 | ||
|
|
720437212b | ||
|
|
d932732d9b | ||
|
|
1118be1153 | ||
|
|
1dc549d645 | ||
|
|
4136d19396 | ||
|
|
52de7425e4 | ||
|
|
f470e55142 | ||
|
|
470de3b749 | ||
|
|
ea72499826 | ||
|
|
6b19bf442a | ||
|
|
436de38102 | ||
|
|
4bb00071d4 | ||
|
|
650cf75168 | ||
|
|
0d07e8a267 | ||
|
|
b7ec587d7d | ||
|
|
e807c7e2f7 | ||
|
|
15e1f0aaa9 | ||
|
|
f1e975f940 | ||
|
|
89fba800a4 | ||
|
|
863275a2ce | ||
|
|
b516cfced4 | ||
|
|
28034318ac | ||
|
|
c2e4764ace | ||
|
|
948bfb17f5 | ||
|
|
6c98b7696a | ||
|
|
2c4638fa47 | ||
|
|
ced2fe7b03 | ||
|
|
3a56f074fa | ||
|
|
dca5abe4ec | ||
|
|
1dd54ea1cb | ||
|
|
b81af97573 | ||
|
|
74d64b16d2 | ||
|
|
2174ec6124 | ||
|
|
1de84bce6f | ||
|
|
3aa5939225 | ||
|
|
44650250c5 | ||
|
|
49fff9b650 | ||
|
|
190f66a990 | ||
|
|
8a34f100d3 | ||
|
|
79687a22fc | ||
|
|
f5fac4e048 | ||
|
|
eac0812dbb | ||
|
|
93f5bfbb2a | ||
|
|
94cba225a6 | ||
|
|
ab614d8b07 | ||
|
|
e7fd39a077 | ||
|
|
530cdb282b | ||
|
|
97534f6916 | ||
|
|
22fb52acc6 | ||
|
|
cf0da580e0 | ||
|
|
64a590b581 | ||
|
|
afb3218bc1 | ||
|
|
170911a6a1 | ||
|
|
ea5b878f74 | ||
|
|
88af1cd68e | ||
|
|
34237e0a45 | ||
|
|
a037487497 | ||
|
|
e7b1fda73e | ||
|
|
c591641754 | ||
|
|
2a0aa1593a | ||
|
|
330723a45c | ||
|
|
f6a1438299 | ||
|
|
1f0f8e5f70 | ||
|
|
216c05ed9b | ||
|
|
89fbacafac | ||
|
|
8c45bfc76b | ||
|
|
4ad3c02d88 | ||
|
|
477729242b | ||
|
|
e96d06892a | ||
|
|
5b1b91f119 | ||
|
|
446e629474 | ||
|
|
57c2cd0719 | ||
|
|
8f2a01b348 | ||
|
|
6fe5817fd7 | ||
|
|
663b3d1647 | ||
|
|
bf0a372edd | ||
|
|
5d0237e28c | ||
|
|
349311cb58 | ||
|
|
a1098641b5 | ||
|
|
8c0ca5083d | ||
|
|
c42ecadd90 | ||
|
|
735386718e | ||
|
|
95459cc2d2 | ||
|
|
fe52edd833 | ||
|
|
d659128ae4 | ||
|
|
397eebf38f | ||
|
|
e18690496f | ||
|
|
c522581d46 | ||
|
|
c31d2e1aee | ||
|
|
9879c82d40 | ||
|
|
1873f5b9b5 | ||
|
|
68d94be743 | ||
|
|
14e38e7974 | ||
|
|
5cc19ab2db | ||
|
|
93b1c20c40 | ||
|
|
49435436cb | ||
|
|
0477e801a6 | ||
|
|
5779d278a9 | ||
|
|
0a8821d3e8 | ||
|
|
e96e9e00bb | ||
|
|
217fb5d332 | ||
|
|
6636cc9548 | ||
|
|
c3fcf760d7 | ||
|
|
7116767e22 | ||
|
|
0877165f9f | ||
|
|
b43466a793 | ||
|
|
401e6170e6 | ||
|
|
782eb4c464 | ||
|
|
1ef2c6b631 | ||
|
|
c7667b2dc2 | ||
|
|
e4c4933d46 | ||
|
|
1f94192772 | ||
|
|
8ebcea5465 | ||
|
|
4c7ccc06ca | ||
|
|
667f58ff4b | ||
|
|
69d318c4b0 | ||
|
|
0414f3be90 | ||
|
|
402203b4c2 | ||
|
|
6dcaf06ebe | ||
|
|
1b6adca00e | ||
|
|
0dce5822e3 | ||
|
|
0f1b75f09e | ||
|
|
19192c46a5 | ||
|
|
62a9e7d1ac | ||
|
|
06077201f9 | ||
|
|
b2795a705e | ||
|
|
1e6734bf6f | ||
|
|
ad382e5d9e | ||
|
|
6458a1e316 | ||
|
|
279d6edc34 | ||
|
|
439dc85aa3 | ||
|
|
60e23411dc | ||
|
|
33fb680c22 | ||
|
|
536b7ebdec | ||
|
|
5da95f2f5b | ||
|
|
30f4a84241 | ||
|
|
f34e126c85 | ||
|
|
d7d0f27e49 | ||
|
|
f42937a6d0 | ||
|
|
c8b7430998 | ||
|
|
42de76d84d | ||
|
|
5102fd77b7 | ||
|
|
9c66d4ee81 | ||
|
|
7ade2d9227 | ||
|
|
7b43b42740 | ||
|
|
25f050f387 | ||
|
|
05c13e8990 | ||
|
|
34b02574b2 | ||
|
|
f81d350a2e | ||
|
|
be86314daf | ||
|
|
345f903113 | ||
|
|
3cf265f231 | ||
|
|
d26e7df2ca | ||
|
|
e5dc3f6774 | ||
|
|
fdc9893a60 | ||
|
|
e8694076b8 | ||
|
|
1acf536080 | ||
|
|
9d3ad0b54b | ||
|
|
0b2ade1598 | ||
|
|
83651b7250 | ||
|
|
6818c09a69 | ||
|
|
dc72b677de | ||
|
|
5ff1a63eaa | ||
|
|
8300a86225 | ||
|
|
9e8084194a | ||
|
|
c0ea4d5a5b | ||
|
|
5a963391f8 | ||
|
|
6c4586a6b9 | ||
|
|
4cc0a6f968 | ||
|
|
ab8656ad1a | ||
|
|
ca5e0f96c2 | ||
|
|
5cddd24097 | ||
|
|
656e539ae3 | ||
|
|
862b7c9ee6 | ||
|
|
c632174de8 | ||
|
|
1e96303765 | ||
|
|
1a6d587ee0 | ||
|
|
adcb6de5e4 | ||
|
|
c36e263a95 | ||
|
|
de1e5bf100 | ||
|
|
ea25dcf208 | ||
|
|
e3c73d0bfe | ||
|
|
91b24bfa82 | ||
|
|
28bf5ba2b6 | ||
|
|
0249d6abdb | ||
|
|
cb32f635d0 | ||
|
|
3bfdde4281 | ||
|
|
8daa2709f3 | ||
|
|
35260d4abb | ||
|
|
2d44435d53 | ||
|
|
3d785bd157 | ||
|
|
c33cfbd302 | ||
|
|
f5ed39e02c | ||
|
|
0c3af0e0cd | ||
|
|
f5a1a67e1e | ||
|
|
ddc0a504fd | ||
|
|
de108753d5 | ||
|
|
b31e8b7a4b | ||
|
|
383fdfa7f6 | ||
|
|
54e867ab0b | ||
|
|
068ed3eb70 | ||
|
|
a203c60df1 | ||
|
|
e13c3fccb4 | ||
|
|
add72e66c9 | ||
|
|
0e587feff0 | ||
|
|
27be86c419 | ||
|
|
3d940d8468 | ||
|
|
7515cdd137 | ||
|
|
8e92f3e689 | ||
|
|
7c4b833d80 | ||
|
|
b291dc4c9f | ||
|
|
60b91df843 | ||
|
|
56f380025d | ||
|
|
b3e0acbcbd | ||
|
|
e2d334db9d | ||
|
|
dffcf6213b | ||
|
|
485f5837f4 | ||
|
|
442cddb81e | ||
|
|
1f38d1aa46 | ||
|
|
ce7dc03350 | ||
|
|
9a75fcb55b | ||
|
|
5522eed2d1 | ||
|
|
1737330b87 | ||
|
|
eff25664f3 | ||
|
|
27d3a1df42 | ||
|
|
63bda02869 | ||
|
|
8c251a8c69 | ||
|
|
4b481ef3ea | ||
|
|
2d62c96d3d | ||
|
|
f8cb436c5b | ||
|
|
0de31fcd04 | ||
|
|
99edb501a5 | ||
|
|
66aaed009f | ||
|
|
4c0b86b127 | ||
|
|
155133a2a0 | ||
|
|
93062d47a8 | ||
|
|
1f0c67a805 | ||
|
|
74feb112f6 | ||
|
|
967349f5af | ||
|
|
d7fe2475ed | ||
|
|
f87bf93641 | ||
|
|
4b467b4644 | ||
|
|
15234a904f | ||
|
|
9ff6d3f60c | ||
|
|
aeba867e9e | ||
|
|
d21e148f39 | ||
|
|
51188fdeba | ||
|
|
dcf072f3de | ||
|
|
ebf09d8e0f | ||
|
|
ca5cb25331 | ||
|
|
65877bff5b | ||
|
|
4a75c7b333 | ||
|
|
be4f1d6675 | ||
|
|
55d4f9ae09 | ||
|
|
88691956ba | ||
|
|
a6133a2b45 | ||
|
|
0aa821e51a | ||
|
|
fb37ea8af9 | ||
|
|
0f36803026 | ||
|
|
2910540c26 | ||
|
|
93fb885195 | ||
|
|
2438d5385f | ||
|
|
73ce071427 | ||
|
|
e3485b7733 | ||
|
|
7ff4fbb3d7 | ||
|
|
de5b9be6ac | ||
|
|
0c6e8eb160 | ||
|
|
9b85fd2d8c | ||
|
|
a136b95451 | ||
|
|
cf5eb64029 | ||
|
|
c4591b030b | ||
|
|
9dc6eb1dfc | ||
|
|
d7c1bf39e2 | ||
|
|
ae1527fca3 | ||
|
|
d14698b282 | ||
|
|
800d3be25f | ||
|
|
27599030cf | ||
|
|
3ee959abd6 | ||
|
|
617df48cc2 | ||
|
|
9e290c2dfd | ||
|
|
f98614c4ee | ||
|
|
d28bb23f8c | ||
|
|
502cb533f8 | ||
|
|
b7fdc2087a | ||
|
|
10a42a3c96 | ||
|
|
51fc52e24b | ||
|
|
be632d8e8c | ||
|
|
a732a2b0a0 | ||
|
|
b14a0b5d16 | ||
|
|
50393c62b0 | ||
|
|
dbc4a07895 | ||
|
|
ab329e4fbf | ||
|
|
90ad700d0a | ||
|
|
56529d6111 | ||
|
|
b6a06007e8 | ||
|
|
edccc9ce4e | ||
|
|
e0b2f0f6b1 | ||
|
|
57f4d3703c | ||
|
|
8ef6692198 | ||
|
|
c48830f3ac | ||
|
|
734c04c1f4 | ||
|
|
b08b4019a9 | ||
|
|
cfb7876b6e | ||
|
|
6047d0e3c3 | ||
|
|
880c333df9 | ||
|
|
c4d7b657dd | ||
|
|
5be3ce8d21 | ||
|
|
33bba631fc | ||
|
|
775b9c299d | ||
|
|
6e02331c13 | ||
|
|
b7457cec9c | ||
|
|
e7288a1910 | ||
|
|
26b90bd8bb |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -115,3 +115,4 @@ run/
|
||||
|
||||
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
||||
!gradle-wrapper.jar
|
||||
/qodana.yaml
|
||||
|
||||
169
build.gradle.kts
169
build.gradle.kts
@@ -2,13 +2,13 @@ import net.minecrell.pluginyml.bukkit.BukkitPluginDescription
|
||||
|
||||
plugins {
|
||||
id("java")
|
||||
id("com.github.johnrengelman.shadow") version "8.1.1"
|
||||
id("xyz.jpenilla.run-paper") version "2.0.0"
|
||||
id("com.gradleup.shadow") version "8.3.2"
|
||||
id("xyz.jpenilla.run-paper") version "2.3.1"
|
||||
id("net.minecrell.plugin-yml.bukkit") version "0.6.0"
|
||||
}
|
||||
|
||||
group = "com.hibiscusmc"
|
||||
version = "2.6.4"
|
||||
version = "2.8.0${getGitCommitHash()}"
|
||||
|
||||
allprojects {
|
||||
apply(plugin = "java")
|
||||
@@ -16,25 +16,22 @@ allprojects {
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
|
||||
// Paper Repo
|
||||
maven("https://papermc.io/repo/repository/maven-public/")
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
maven("https://oss.sonatype.org/content/repositories/snapshots")
|
||||
|
||||
// Jitpack
|
||||
maven("https://jitpack.io")
|
||||
|
||||
// ProtocolLib repo
|
||||
maven("https://repo.dmulloy2.net/repository/public/") //ProtocolLib Repo, constantly down
|
||||
// Geary
|
||||
maven("https://repo.mineinabyss.com/releases/")
|
||||
maven("https://repo.mineinabyss.com/snapshots/")
|
||||
|
||||
// PlaceholderAPI
|
||||
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
|
||||
|
||||
//Hikari
|
||||
maven("https://mvnrepository.com/artifact/com.zaxxer/HikariCP")
|
||||
|
||||
// Citizens & Denizen
|
||||
maven("https://maven.citizensnpcs.co/repo")
|
||||
|
||||
@@ -52,9 +49,6 @@ allprojects {
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateChecker
|
||||
maven("https://hub.jeff-media.com/nexus/repository/jeff-media-public/")
|
||||
|
||||
// ParticleHelper
|
||||
maven("https://repo.bytecode.space/repository/maven-public/")
|
||||
|
||||
@@ -66,57 +60,73 @@ allprojects {
|
||||
|
||||
// MMOItems
|
||||
maven("https://nexus.phoenixdevt.fr/repository/maven-public/")
|
||||
|
||||
// Eco-Suite/Auxilor Repo
|
||||
maven("https://repo.auxilor.io/repository/maven-public/")
|
||||
|
||||
// Triumph GUI
|
||||
maven("https://repo.triumphteam.dev/snapshots")
|
||||
|
||||
// Hibiscus Commons
|
||||
maven("https://repo.hibiscusmc.com/releases")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(fileTree("${project.rootDir}/lib") { include("*.jar") })
|
||||
compileOnly("com.mojang:authlib:1.5.25")
|
||||
compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
|
||||
compileOnly("org.jetbrains:annotations:23.0.0")
|
||||
compileOnly("com.comphenix.protocol:ProtocolLib:5.0.0")
|
||||
compileOnly("me.clip:placeholderapi:2.11.3")
|
||||
compileOnly("com.ticxo:modelengine:R3.0.1")
|
||||
compileOnly("com.github.oraxen:oraxen:1.160.0")
|
||||
compileOnly("com.github.LoneDev6:API-ItemsAdder:3.2.5")
|
||||
compileOnly("com.mineinabyss:geary-papermc:0.24.1")
|
||||
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.1.0-SNAPSHOT")
|
||||
compileOnly("it.unimi.dsi:fastutil:8.5.11")
|
||||
compileOnly("com.github.LeonMangler:SuperVanish:6.2.17")
|
||||
compileOnly("org.projectlombok:lombok:1.18.2")
|
||||
//compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
|
||||
compileOnly("io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT")
|
||||
compileOnly("org.jetbrains:annotations:24.1.0")
|
||||
compileOnly("me.clip:placeholderapi:2.11.6")
|
||||
compileOnly("com.ticxo.modelengine:ModelEngine:R4.0.6")
|
||||
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.12") {
|
||||
exclude(group = "org.bukkit")
|
||||
exclude(group = "com.google.guava")
|
||||
exclude(group = "com.google.code.gson")
|
||||
exclude(group = "it.unimi.dsi")
|
||||
exclude(group = "com.sk89q.jnbt")
|
||||
}
|
||||
compileOnly("io.github.toxicity188:BetterHud-standard-api:1.12") //Standard api
|
||||
compileOnly("io.github.toxicity188:BetterHud-bukkit-api:1.12") //Platform api
|
||||
compileOnly("io.github.toxicity188:BetterCommand:1.3") //BetterCommand library
|
||||
//compileOnly("it.unimi.dsi:fastutil:8.5.14")
|
||||
compileOnly("org.projectlombok:lombok:1.18.34")
|
||||
compileOnly("me.lojosho:HibiscusCommons:0.7.0-d301221e")
|
||||
|
||||
annotationProcessor("org.projectlombok:lombok:1.18.28")
|
||||
testCompileOnly("org.projectlombok:lombok:1.18.28")
|
||||
testAnnotationProcessor("org.projectlombok:lombok:1.18.28")
|
||||
// Handled by Spigot Library Loader
|
||||
compileOnly("net.kyori:adventure-api:4.23.0")
|
||||
compileOnly("net.kyori:adventure-text-minimessage:4.23.0")
|
||||
compileOnly("net.kyori:adventure-platform-bukkit:4.4.0")
|
||||
|
||||
annotationProcessor("org.projectlombok:lombok:1.18.36")
|
||||
testCompileOnly("org.projectlombok:lombok:1.18.36")
|
||||
testAnnotationProcessor("org.projectlombok:lombok:1.18.36")
|
||||
|
||||
implementation("dev.triumphteam:triumph-gui:3.2.0-SNAPSHOT") {
|
||||
exclude("net.kyori") // Already have adventure API
|
||||
}
|
||||
implementation("com.owen1212055:particlehelper:1.0.0-SNAPSHOT")
|
||||
implementation("com.ticxo.playeranimator:PlayerAnimator:R1.2.7")
|
||||
}
|
||||
|
||||
tasks {
|
||||
javadoc {
|
||||
// javadoc spec has these added.
|
||||
(options as StandardJavadocDocletOptions)
|
||||
.tags("apiNote:a:API:", "implSpec:a:Implementation Requirements", "implNote:a:Implementation Note:")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(path = ":common"))
|
||||
implementation(project(path = ":v1_18_R2", configuration = "reobf"))
|
||||
implementation(project(path = ":v1_19_R1", configuration = "reobf"))
|
||||
implementation(project(path = ":v1_19_R2", configuration = "reobf"))
|
||||
implementation(project(path = ":v1_19_R3", configuration = "reobf"))
|
||||
implementation(project(path = ":v1_20_R1", configuration = "reobf"))
|
||||
|
||||
//compileOnly("com.github.Fisher2911:FisherLib:master-SNAPSHOT")
|
||||
implementation("net.kyori:adventure-api:4.11.0")
|
||||
implementation("net.kyori:adventure-text-minimessage:4.11.0")
|
||||
implementation("net.kyori:adventure-platform-bukkit:4.1.2")
|
||||
implementation("dev.triumphteam:triumph-gui:3.1.3")
|
||||
implementation("org.spongepowered:configurate-yaml:4.1.2")
|
||||
implementation("org.bstats:bstats-bukkit:3.0.0")
|
||||
implementation("com.jeff_media:SpigotUpdateChecker:3.0.0")
|
||||
implementation("com.owen1212055:particlehelper:1.0.0-SNAPSHOT")
|
||||
implementation("com.ticxo.playeranimator:PlayerAnimator:R1.2.7")
|
||||
implementation("com.github.BG-Software-LLC:CommentedConfiguration:-SNAPSHOT")
|
||||
//implementation("com.ticxo.playeranimator:PlayerAnimator:R1.2.5")
|
||||
}
|
||||
|
||||
tasks {
|
||||
|
||||
compileJava {
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
options.release.set(17)
|
||||
options.release.set(21)
|
||||
}
|
||||
|
||||
javadoc {
|
||||
@@ -129,28 +139,20 @@ tasks {
|
||||
}
|
||||
|
||||
runServer {
|
||||
minecraftVersion("1.20.1")
|
||||
minecraftVersion("1.21.6")
|
||||
|
||||
downloadPlugins {
|
||||
hangar("PlaceholderAPI", "2.11.6")
|
||||
url("https://download.luckperms.net/1593/bukkit/loader/LuckPerms-Bukkit-5.5.8.jar")
|
||||
}
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
dependsOn(":v1_18_R2:reobfJar")
|
||||
dependsOn(":v1_19_R1:reobfJar")
|
||||
dependsOn(":v1_19_R2:reobfJar")
|
||||
dependsOn(":v1_19_R3:reobfJar")
|
||||
dependsOn(":v1_20_R1:reobfJar")
|
||||
mergeServiceFiles()
|
||||
|
||||
relocate("dev.triumphteam.gui", "com.hisbiscusmc.hmccosmetics.gui")
|
||||
relocate("me.mattstudios.mf", "com.hisbiscusmc.hmccosmetics.mf")
|
||||
relocate("net.kyori.adventure", "com.hisbiscusmc.hmccosmetics.adventure")
|
||||
relocate("org.spongepowered.configurate", "com.hisbiscusmc.hmccosmetics.configurate")
|
||||
relocate("org.bstats", "com.hisbiscusmc.hmccosmetics.bstats")
|
||||
relocate("com.zaxxer.hikaricp", "com.hisbiscusmc.hmccosmetics.hikaricp")
|
||||
relocate("com.j256.ormlite", "com.hisbiscusmc.hmccosmetics.ormlite")
|
||||
relocate("com.jeff_media.updatechecker", "com.hisbiscusmc.hmccosmetics.updatechecker")
|
||||
relocate("com.owen1212055.particlehelper", "com.hisbiscusmc.hmccosmetics.particlehelper")
|
||||
relocate("com.ticxo.playeranimator", "com.hisbiscusmc.hmccosmetics.playeranimator")
|
||||
relocate("com.bgsoftware", "com.hisbiscusmc.hmccosmetics.configupdater")
|
||||
relocate("dev.triumphteam.gui", "com.hibiscusmc.hmccosmetics.shaded.gui")
|
||||
relocate("com.owen1212055.particlehelper", "com.hibiscusmc.hmccosmetics.shaded.particlehelper")
|
||||
relocate("com.ticxo.playeranimator", "com.hibiscusmc.hmccosmetics.shaded.playeranimator")
|
||||
archiveFileName.set("HMCCosmeticsRemapped-${project.version}.jar")
|
||||
|
||||
dependencies {
|
||||
@@ -175,10 +177,10 @@ tasks {
|
||||
bukkit {
|
||||
load = BukkitPluginDescription.PluginLoadOrder.POSTWORLD
|
||||
main = "com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin"
|
||||
apiVersion = "1.18"
|
||||
apiVersion = "1.20"
|
||||
authors = listOf("LoJoSho")
|
||||
depend = listOf("ProtocolLib")
|
||||
softDepend = listOf("ModelEngine", "Oraxen", "ItemsAdder", "Geary", "HMCColor", "WorldGuard", "MythicMobs", "PlaceholderAPI", "SuperVanish", "PremiumVanish", "LibsDisguises", "Denizen", "MMOItems")
|
||||
depend = listOf("HibiscusCommons")
|
||||
softDepend = listOf("Nexo", "BetterHud", "ModelEngine", "Oraxen", "ItemsAdder", "Geary", "HMCColor", "WorldGuard", "MythicMobs", "PlaceholderAPI", "SuperVanish", "PremiumVanish", "LibsDisguises", "Denizen", "MMOItems", "Eco")
|
||||
version = "${project.version}"
|
||||
loadBefore = listOf(
|
||||
"Cosmin" // Fixes an issue with Cosmin loading before and taking /cosmetic, when messing with what we do.
|
||||
@@ -263,10 +265,41 @@ bukkit {
|
||||
register("hmccosmetics.unapplydeath.bypass") {
|
||||
default = BukkitPluginDescription.Permission.Default.OP
|
||||
}
|
||||
register("hmccosmetics.cmd.disableall") {
|
||||
default = BukkitPluginDescription.Permission.Default.OP
|
||||
}
|
||||
register("hmccosmetics.cmd.hiddenreasons") {
|
||||
default = BukkitPluginDescription.Permission.Default.OP
|
||||
}
|
||||
register("hmccosmetics.cmd.clearhiddenreasons") {
|
||||
default = BukkitPluginDescription.Permission.Default.OP
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(17
|
||||
))
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
|
||||
|
||||
withJavadocJar()
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
fun getGitCommitHash(): String {
|
||||
var includeHash = true
|
||||
val includeHashVariable = System.getenv("HMCC_INCLUDE_HASH")
|
||||
|
||||
if (!includeHashVariable.isNullOrEmpty()) includeHash = includeHashVariable.toBoolean()
|
||||
|
||||
if (includeHash) {
|
||||
return try {
|
||||
val process = ProcessBuilder("git", "rev-parse", "--short", "HEAD")
|
||||
.redirectErrorStream(true)
|
||||
.start()
|
||||
|
||||
process.inputStream.bufferedReader().use { "-" + it.readLine().trim() }
|
||||
} catch (e: Exception) {
|
||||
"-unknown" // Fallback if Git is not available or an error occurs
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -3,44 +3,11 @@ plugins {
|
||||
id("maven-publish")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("com.mojang:authlib:1.5.25")
|
||||
compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
|
||||
compileOnly("org.jetbrains:annotations:23.0.0")
|
||||
compileOnly("com.comphenix.protocol:ProtocolLib:5.0.0")
|
||||
compileOnly("me.clip:placeholderapi:2.11.3")
|
||||
compileOnly("com.ticxo:modelengine:R3.0.1")
|
||||
compileOnly("com.github.oraxen:oraxen:1.160.0")
|
||||
compileOnly("com.github.LoneDev6:API-ItemsAdder:3.2.5")
|
||||
compileOnly("com.mineinabyss:geary-papermc:0.24-SNAPSHOT")
|
||||
//compileOnly("com.hibiscus:hmccolor:0.3-SNAPSHOT") USE LIB PROVIDED FILE
|
||||
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.1.0-SNAPSHOT")
|
||||
compileOnly("it.unimi.dsi:fastutil:8.5.11")
|
||||
compileOnly("io.lumine:Mythic-Dist:5.2.1")
|
||||
compileOnly("com.denizenscript:denizen:1.2.7-SNAPSHOT")
|
||||
compileOnly("com.github.LeonMangler:SuperVanish:6.2.17")
|
||||
compileOnly("net.Indyuce:MMOItems-API:6.9.4-SNAPSHOT")
|
||||
compileOnlyApi("LibsDisguises:LibsDisguises:10.0.21") {
|
||||
exclude("org.spigotmc", "spigot")
|
||||
}
|
||||
|
||||
//compileOnly("com.github.Fisher2911:FisherLib:master-SNAPSHOT")
|
||||
implementation("net.kyori:adventure-api:4.12.0")
|
||||
implementation("net.kyori:adventure-text-minimessage:4.12.0")
|
||||
implementation("net.kyori:adventure-platform-bukkit:4.2.0")
|
||||
implementation("dev.triumphteam:triumph-gui:3.1.3")
|
||||
implementation("org.spongepowered:configurate-yaml:4.1.2")
|
||||
implementation("org.bstats:bstats-bukkit:3.0.0")
|
||||
implementation("com.jeff_media:SpigotUpdateChecker:3.0.0")
|
||||
implementation("com.owen1212055:particlehelper:1.0.0-SNAPSHOT")
|
||||
implementation("com.ticxo.playeranimator:PlayerAnimator:R1.2.7")
|
||||
implementation("com.github.BG-Software-LLC:CommentedConfiguration:-SNAPSHOT")
|
||||
//implementation("com.ticxo.playeranimator:PlayerAnimator:R1.2.5")
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(17
|
||||
))
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
|
||||
|
||||
withJavadocJar()
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
publishing {
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.name = "HMCCosmetics"
|
||||
@@ -1,91 +1,64 @@
|
||||
package com.hibiscusmc.hmccosmetics;
|
||||
|
||||
import com.bgsoftware.common.config.CommentedConfiguration;
|
||||
import com.hibiscusmc.hmccosmetics.api.events.HMCCosmeticSetupEvent;
|
||||
import com.hibiscusmc.hmccosmetics.command.CosmeticCommand;
|
||||
import com.hibiscusmc.hmccosmetics.command.CosmeticCommandTabComplete;
|
||||
import com.hibiscusmc.hmccosmetics.config.DatabaseSettings;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
||||
import com.hibiscusmc.hmccosmetics.config.serializer.ItemSerializer;
|
||||
import com.hibiscusmc.hmccosmetics.config.serializer.LocationSerializer;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||
import com.hibiscusmc.hmccosmetics.database.Database;
|
||||
import com.hibiscusmc.hmccosmetics.emotes.EmoteManager;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.items.HookHMCCosmetics;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.misc.HookBetterHud;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.placeholders.HMCPlaceholderExpansion;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.worldguard.WGHook;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.worldguard.WGListener;
|
||||
import com.hibiscusmc.hmccosmetics.listener.PaperPlayerGameListener;
|
||||
import com.hibiscusmc.hmccosmetics.listener.PlayerConnectionListener;
|
||||
import com.hibiscusmc.hmccosmetics.listener.PlayerGameListener;
|
||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||
import com.hibiscusmc.hmccosmetics.listener.ServerListener;
|
||||
import com.hibiscusmc.hmccosmetics.packets.CosmeticPacketInterface;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.TranslationUtil;
|
||||
import com.jeff_media.updatechecker.UpdateCheckSource;
|
||||
import com.jeff_media.updatechecker.UpdateChecker;
|
||||
import com.ticxo.playeranimator.PlayerAnimatorImpl;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin;
|
||||
import me.lojosho.hibiscuscommons.HibiscusPlugin;
|
||||
import me.lojosho.hibiscuscommons.config.serializer.ItemSerializer;
|
||||
import me.lojosho.hibiscuscommons.config.serializer.LocationSerializer;
|
||||
import me.lojosho.shaded.configupdater.common.config.CommentedConfiguration;
|
||||
import me.lojosho.shaded.configurate.ConfigurateException;
|
||||
import me.lojosho.shaded.configurate.ConfigurationOptions;
|
||||
import me.lojosho.shaded.configurate.yaml.NodeStyle;
|
||||
import me.lojosho.shaded.configurate.yaml.YamlConfigurationLoader;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.ConfigurationOptions;
|
||||
import org.spongepowered.configurate.yaml.NodeStyle;
|
||||
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public final class HMCCosmeticsPlugin extends JavaPlugin {
|
||||
public final class HMCCosmeticsPlugin extends HibiscusPlugin {
|
||||
|
||||
private static HMCCosmeticsPlugin instance;
|
||||
private static boolean disable = false;
|
||||
private static YamlConfigurationLoader configLoader;
|
||||
private static final int pluginId = 13873;
|
||||
private static boolean onLatestVersion = true;
|
||||
private static String latestVersion = "";
|
||||
|
||||
public HMCCosmeticsPlugin() {
|
||||
super(13873, 1879);
|
||||
new HookHMCCosmetics();
|
||||
new HookBetterHud();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
public void onStart() {
|
||||
// Plugin startup logic
|
||||
instance = this;
|
||||
// bstats https://bstats.org/plugin/bukkit/HMCCosmetics/13873
|
||||
Metrics metrics = new Metrics(this, pluginId);
|
||||
|
||||
// NMS version check
|
||||
if (!NMSHandlers.getHandler().getSupported()) {
|
||||
getLogger().severe("This version is not supported! Consider switching versions?");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
// Update Checker
|
||||
UpdateChecker checker = new UpdateChecker(this, UpdateCheckSource.POLYMART, "1879")
|
||||
.onSuccess((commandSenders, latestVersion) -> {
|
||||
this.latestVersion = (String) latestVersion;
|
||||
if (!this.latestVersion.equalsIgnoreCase(getDescription().getVersion())) {
|
||||
getLogger().info("+++++++++++++++++++++++++++++++++++");
|
||||
getLogger().info("There is a new update for HMCCosmetics!");
|
||||
getLogger().info("Please download it as soon as possible for possible fixes and new features.");
|
||||
getLogger().info("Current Version " + getDescription().getVersion() + " | Latest Version " + latestVersion);
|
||||
getLogger().info("Spigot: https://www.spigotmc.org/resources/100107/");
|
||||
getLogger().info("Polymart: https://polymart.org/resource/1879");
|
||||
getLogger().info("+++++++++++++++++++++++++++++++++++");
|
||||
}
|
||||
})
|
||||
.setNotifyRequesters(false)
|
||||
.setNotifyOpsOnJoin(false)
|
||||
.checkEveryXHours(24)
|
||||
.checkNow();
|
||||
onLatestVersion = checker.isUsingLatestVersion();
|
||||
// File setup
|
||||
saveDefaultConfig();
|
||||
if (!Path.of(getDataFolder().getPath(), "messages.yml").toFile().exists()) saveResource("messages.yml", false);
|
||||
@@ -93,13 +66,6 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
||||
if (!Path.of(getDataFolder().getPath() + "/cosmetics/").toFile().exists()) saveResource("cosmetics/defaultcosmetics.yml", false);
|
||||
if (!Path.of(getDataFolder().getPath() + "/menus/").toFile().exists()) saveResource("menus/defaultmenu.yml", false);
|
||||
|
||||
// Emote folder setup
|
||||
File emoteFile = new File(getDataFolder().getPath() + "/emotes");
|
||||
if (!emoteFile.exists()) emoteFile.mkdir();
|
||||
|
||||
// Player Animator
|
||||
PlayerAnimatorImpl.initialize(this);
|
||||
|
||||
// Configuration Sync
|
||||
final File configFile = Path.of(getInstance().getDataFolder().getPath(), "config.yml").toFile();
|
||||
final File messageFile = Path.of(getInstance().getDataFolder().getPath(), "messages.yml").toFile();
|
||||
@@ -113,8 +79,12 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Move this over to Hibiscus Commons later
|
||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) new HMCPlaceholderExpansion().register();
|
||||
|
||||
// Setup
|
||||
setup();
|
||||
setPacketInterface(new CosmeticPacketInterface());
|
||||
|
||||
// Commands
|
||||
getServer().getPluginCommand("cosmetic").setExecutor(new CosmeticCommand());
|
||||
@@ -123,7 +93,11 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
||||
// Listener
|
||||
getServer().getPluginManager().registerEvents(new PlayerConnectionListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerGameListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new ServerListener(), this);
|
||||
|
||||
if (HibiscusCommonsPlugin.isOnPaper()) {
|
||||
getServer().getPluginManager().registerEvents(new PaperPlayerGameListener(), this);
|
||||
}
|
||||
// Database
|
||||
new Database();
|
||||
|
||||
@@ -142,14 +116,13 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
public void onEnd() {
|
||||
// Plugin shutdown logic
|
||||
disable = true;
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) continue;
|
||||
if (user.getUserEmoteManager().isPlayingEmote()) {
|
||||
player.setInvisible(false);
|
||||
if (user.isInWardrobe()) {
|
||||
user.leaveWardrobe(true);
|
||||
}
|
||||
Database.save(user);
|
||||
}
|
||||
@@ -214,9 +187,6 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
// Misc Hooks setup (like items)
|
||||
Hooks.setup();
|
||||
|
||||
// Cosmetics setup
|
||||
Cosmetics.setup();
|
||||
|
||||
@@ -252,8 +222,6 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
EmoteManager.loadEmotes();
|
||||
|
||||
getInstance().getLogger().info("Successfully Enabled HMCCosmetics");
|
||||
getInstance().getLogger().info(Cosmetics.values().size() + " Cosmetics Successfully Setup");
|
||||
getInstance().getLogger().info(Menus.getMenuNames().size() + " Menus Successfully Setup");
|
||||
@@ -262,28 +230,4 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
||||
|
||||
Bukkit.getPluginManager().callEvent(new HMCCosmeticSetupEvent());
|
||||
}
|
||||
|
||||
public static boolean isDisable() {
|
||||
return disable;
|
||||
}
|
||||
|
||||
public static YamlConfigurationLoader getConfigLoader() {
|
||||
return configLoader;
|
||||
}
|
||||
|
||||
public static void saveConfig(ConfigurationNode node) {
|
||||
try {
|
||||
HMCCosmeticsPlugin.getConfigLoader().save(node);
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Set new location " + node.path());
|
||||
} catch (ConfigurateException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isOnLatestVersion() {
|
||||
return onLatestVersion;
|
||||
}
|
||||
public static String getLatestVersion() {
|
||||
return latestVersion;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,116 +2,216 @@ package com.hibiscusmc.hmccosmetics.api;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticProvider;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUserProvider;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import me.lojosho.hibiscuscommons.nms.MinecraftVersion;
|
||||
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
public class HMCCosmeticsAPI {
|
||||
|
||||
/**
|
||||
* Attempts to get a cosmetic from HMCCosmetics
|
||||
*
|
||||
* @param cosmetic Cosmetic Id
|
||||
* @return A {@link Cosmetic} if exists or null if it does not
|
||||
*/
|
||||
@Nullable
|
||||
public static Cosmetic getCosmetic(@NotNull String cosmetic) {
|
||||
return Cosmetics.getCosmetic(cosmetic);
|
||||
/**
|
||||
* The main API class for HMCCosmetics. This class provides methods to interact with the plugin.
|
||||
*/
|
||||
public final class HMCCosmeticsAPI {
|
||||
private HMCCosmeticsAPI() {
|
||||
throw new UnsupportedOperationException("This class cannot be instantiated.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to get the CosmeticUser from an online user. If a player is offline it will return null.
|
||||
* A player maybe online but not have a CosmeticUser attached to them, either from delay specified in the config
|
||||
* or from a /reload. Always check if it's null!
|
||||
*
|
||||
* @param uuid Player Unique ID
|
||||
* @return A {@link CosmeticUser} if exists or null if it does not
|
||||
* Retrieves a {@link Cosmetic} associated with the specified id.
|
||||
* <p>
|
||||
* This method attempts to fetch a {@link Cosmetic} using the given id. If no {@link Cosmetic} exists
|
||||
* with the specified id, it will return {@code null}.
|
||||
* </p>
|
||||
* @param id the id of the {@link Cosmetic} to retrieve
|
||||
* @return the {@link Cosmetic} if it exists, or {@code null} if no cosmetic is associated with the given id
|
||||
*/
|
||||
@Nullable
|
||||
public static CosmeticUser getUser(@NotNull UUID uuid) {
|
||||
public static @Nullable Cosmetic getCosmetic(@NotNull String id) {
|
||||
return Cosmetics.getCosmetic(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the {@link CosmeticUser} associated with the specified player's {@link UUID}.
|
||||
* <p>
|
||||
* This method attempts to fetch a {@link CosmeticUser} for an online player. If the player is offline,
|
||||
* or if no {@link CosmeticUser} is currently associated with them, it will return {@code null}.
|
||||
* </p>
|
||||
* Note that a player may be online but not have a {@link CosmeticUser} attached due to:
|
||||
* <ul>
|
||||
* <li>A delay specified in the configuration</li>
|
||||
* <li>A recent server reload (e.g., via the {@code /reload} command)</li>
|
||||
* </ul>
|
||||
* Always perform a {@code null} check before using the returned object to ensure safe operation.
|
||||
*
|
||||
* @param uuid the {@link UUID} of the player whose {@link CosmeticUser} is being retrieved
|
||||
* @return the {@link CosmeticUser} if it exists, or {@code null} if the player is offline or unassociated
|
||||
*/
|
||||
public static @Nullable CosmeticUser getUser(@NotNull UUID uuid) {
|
||||
return CosmeticUsers.getUser(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to get a HMCCosmetics Menu. Returns null if no menu exists under that id.
|
||||
* Retrieves a {@link Menu} associated with the specified id, or {@code null} if no menu exists with the given id.
|
||||
*
|
||||
* @param id Menu ID
|
||||
* @return A {@link Menu} if exists or null if it does not
|
||||
* @param id the id of the menu to retrieve
|
||||
* @return the {@link Menu} if it exists, or {@code null} if no menu is associated with the given id
|
||||
*/
|
||||
@Nullable
|
||||
public static Menu getMenu(@NotNull String id) {
|
||||
public static @Nullable Menu getMenu(@NotNull String id) {
|
||||
return Menus.getMenu(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Equips a cosmetic to a player. You can use getUser and getCosmetic to get the CosmeticUser and Cosmetic to equip.
|
||||
* @param user CosmeticUser to equip cosmetic to
|
||||
* @param cosmetic Cosmetic to equip
|
||||
* Equips a {@link Cosmetic} to a player. To retrieve the necessary {@code CosmeticUser} and {@code Cosmetic}, use the {@link #getUser}
|
||||
* and {@link #getCosmetic} methods respectively.
|
||||
*
|
||||
* @param user the {@link CosmeticUser} to equip the cosmetic to
|
||||
* @param cosmetic the {@link Cosmetic} to equip
|
||||
*/
|
||||
public static void equipCosmetic(@NotNull CosmeticUser user, @NotNull Cosmetic cosmetic) {
|
||||
equipCosmetic(user, cosmetic, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Equips a cosmetic to a player with a color. You can use getUser and getCosmetic to get the CosmeticUser and Cosmetic to equip.
|
||||
* @param user CosmeticUser to equip cosmetic to
|
||||
* @param cosmetic Cosmetic to equip
|
||||
* @param color Color to apply to cosmetic
|
||||
* Equips a {@link Cosmetic} to a player with an optional color customization. To retrieve the necessary
|
||||
* {@code CosmeticUser} and {@code Cosmetic}, use the {@link #getUser} and {@link #getCosmetic} methods
|
||||
* respectively.
|
||||
*
|
||||
* @param user the {@link CosmeticUser} to equip the cosmetic to
|
||||
* @param cosmetic the {@link Cosmetic} to equip
|
||||
* @param color the color to apply to the cosmetic, or {@code null} if the cosmetic does not support color
|
||||
* customization
|
||||
*/
|
||||
public static void equipCosmetic(@NotNull CosmeticUser user, @NotNull Cosmetic cosmetic, @Nullable Color color) {
|
||||
user.addPlayerCosmetic(cosmetic, color);
|
||||
user.addCosmetic(cosmetic, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a cosmetic in cosmeticslot.
|
||||
* @param user The user to remove the cosmetic from
|
||||
* @param slot The slot to remove the cosmetic from
|
||||
* Removes a cosmetic from a specified slot for the given user.
|
||||
*
|
||||
* @param user the {@link CosmeticUser} from whom the cosmetic will be removed
|
||||
* @param slot the {@link CosmeticSlot} from which the cosmetic will be removed
|
||||
*/
|
||||
public static void unequipCosmetic(@NotNull CosmeticUser user, @NotNull CosmeticSlot slot) {
|
||||
user.removeCosmeticSlot(slot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all Cosmetics that are currently registered with HMCC. This list is immutable!
|
||||
* @return A list of all registered cosmetics
|
||||
* Retrieves a list of all cosmetics currently registered with HMCC.
|
||||
*
|
||||
* @return an {@code immutable} list containing all registered {@link Cosmetic} object
|
||||
*/
|
||||
public static List<Cosmetic> getAllCosmetics() {
|
||||
public static @NotNull List<Cosmetic> getAllCosmetics() {
|
||||
return List.copyOf(Cosmetics.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all CosmeticUsers that are currently registered with HMCC. This list is immutable!
|
||||
* @return A list of all registered CosmeticUsers
|
||||
* Retrieves a list of all cosmetic users currently registered with HMCC.
|
||||
*
|
||||
* @return an immutable list containing all registered {@link CosmeticUser} objects
|
||||
*/
|
||||
public static List<CosmeticUser> getAllCosmeticUsers() {
|
||||
public static @NotNull List<CosmeticUser> getAllCosmeticUsers() {
|
||||
return List.copyOf(CosmeticUsers.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns the NMS version of the server as recognized by HMCCosmetics. This will be null until HMCC setup has been completed.
|
||||
* @return The NMS version of the server in String format
|
||||
* Retrieves a map of all cosmetic slots currently registered with HMCC.
|
||||
*
|
||||
* @return an immutable {@link Map} containing all registered cosmetic slots
|
||||
*/
|
||||
@Nullable
|
||||
public static String getNMSVersion() {
|
||||
return NMSHandlers.getVersion();
|
||||
public static @NotNull Map<String, CosmeticSlot> getAllCosmeticSlots() {
|
||||
return Map.copyOf(CosmeticSlot.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns the HMCCosmetics version.
|
||||
* @return The HMCCosmetics version in String format
|
||||
* Registers a new cosmetic slot with the specified id. If a slot with the same id already exists,
|
||||
* the existing slot will be returned.
|
||||
*
|
||||
* <p>
|
||||
* The provided id will automatically be converted to uppercase when registering the slot.
|
||||
* </p>
|
||||
*
|
||||
* @param id the id for the cosmetic slot
|
||||
* @return the {@link CosmeticSlot} associated with the given id
|
||||
* @apiNote this should be done in your {@link JavaPlugin#onLoad()} or it may error.
|
||||
*/
|
||||
@NotNull
|
||||
public static String getHMCCVersion() {
|
||||
public static @NotNull CosmeticSlot registerCosmeticSlot(@NotNull String id) {
|
||||
return CosmeticSlot.register(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new cosmetic user provider to use for constructing {@link CosmeticUser} instances.
|
||||
*
|
||||
* @param provider the provider to register
|
||||
* @throws IllegalArgumentException if another plugin has already registered a provider
|
||||
* @apiNote this should be done in your {@link JavaPlugin#onLoad()} or it may error.
|
||||
*/
|
||||
public static void registerCosmeticUserProvider(@NotNull CosmeticUserProvider provider) {
|
||||
CosmeticUsers.registerProvider(provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the current {@link CosmeticUserProvider} that is in use.
|
||||
*
|
||||
* @return the current {@link CosmeticUserProvider}
|
||||
*/
|
||||
public static @NotNull CosmeticUserProvider getCosmeticUserProvider() {
|
||||
return CosmeticUsers.getProvider();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new cosmetic user provider to use for constructing {@link Cosmetic} instances.
|
||||
*
|
||||
* @param provider the provider to register
|
||||
* @throws IllegalArgumentException if another plugin has already registered a provider
|
||||
* @apiNote this should be done in your {@link JavaPlugin#onLoad()} or it may error.
|
||||
*/
|
||||
public static void registerCosmeticProvider(@NotNull CosmeticProvider provider) {
|
||||
Cosmetics.registerProvider(provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the current {@link CosmeticProvider} that is in use.
|
||||
*
|
||||
* @return the current {@link CosmeticProvider}
|
||||
*/
|
||||
public static @NotNull CosmeticProvider getCosmeticProvider() {
|
||||
return Cosmetics.getProvider();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the NMS version of the server as recognized by HMCCosmetics.
|
||||
*
|
||||
* <p>This value will be {@code null} until the HMCC setup has been completed. Ensure setup is finished
|
||||
* before attempting to access this version.</p>
|
||||
*
|
||||
* @return the NMS version of the server in string format, or {@code null} if setup is not complete.
|
||||
*/
|
||||
public static @Nullable String getNMSVersion() {
|
||||
MinecraftVersion version = NMSHandlers.getVersion();
|
||||
if (version == null) return null;
|
||||
return version.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the version of HMCCosmetics currently in use.
|
||||
*
|
||||
* @return the HMCCosmetics version in string format
|
||||
*/
|
||||
public static @NotNull String getHMCCVersion() {
|
||||
return HMCCosmeticsPlugin.getInstance().getDescription().getVersion();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.hibiscusmc.hmccosmetics.api.events;
|
||||
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when an attempt is made to register a cosmetic type that is not part of the default HMCC cosmetics.
|
||||
* <p>
|
||||
* For example, if a user specifies "test" in the config slot, and it is not a default cosmetic, this event will be
|
||||
* triggered.
|
||||
* </p>
|
||||
*/
|
||||
public class CosmeticTypeRegisterEvent extends Event {
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private final String id;
|
||||
private final ConfigurationNode config;
|
||||
|
||||
public CosmeticTypeRegisterEvent(@NotNull String id, @NotNull ConfigurationNode config) {
|
||||
this.id = id;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the id of the cosmetic attempting to be registered.
|
||||
*
|
||||
* @return the id of the cosmetic. This is the key in the cosmetic configuration.
|
||||
*/
|
||||
public @NotNull String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the {@link ConfigurationNode} for the cosmetic that was attempted to be registered.
|
||||
* <p>
|
||||
* This node is nested below the id in the configuration.
|
||||
* </p>
|
||||
*
|
||||
* @return the configuration node for the cosmetic in the cosmetic configuration
|
||||
*/
|
||||
public @NotNull ConfigurationNode getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
@@ -5,19 +5,17 @@ import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when the plugin is set up and/or reloaded
|
||||
* Called when the plugin is set up and/or reloaded.
|
||||
*/
|
||||
public class HMCCosmeticSetupEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,22 +7,24 @@ import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when a player equips a cosmetic
|
||||
* Called when a player equips a {@link Cosmetic}.
|
||||
*/
|
||||
public class PlayerCosmeticEquipEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancel = false;
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private Cosmetic cosmetic;
|
||||
|
||||
private boolean cancel = false;
|
||||
|
||||
public PlayerCosmeticEquipEvent(@NotNull CosmeticUser who, @NotNull Cosmetic cosmetic) {
|
||||
super(who);
|
||||
this.cosmetic = cosmetic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link Cosmetic} being equipped in this event
|
||||
* Gets the {@link Cosmetic} being equipped in this event.
|
||||
*
|
||||
* @return The {@link Cosmetic} which is being equipped in this event
|
||||
* @return the cosmetic which is being equipped in this event
|
||||
*/
|
||||
@NotNull
|
||||
public Cosmetic getCosmetic() {
|
||||
@@ -30,9 +32,9 @@ public class PlayerCosmeticEquipEvent extends PlayerCosmeticEvent implements Can
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link Cosmetic} that the player will equip
|
||||
* Sets the {@link Cosmetic} that the player will equip.
|
||||
*
|
||||
* @param cosmetic The {@link Cosmetic} that the player will equip
|
||||
* @param cosmetic the cosmetic that the player will equip
|
||||
*/
|
||||
public void setCosmetic(@NotNull Cosmetic cosmetic) {
|
||||
this.cosmetic = cosmetic;
|
||||
@@ -43,28 +45,17 @@ public class PlayerCosmeticEquipEvent extends PlayerCosmeticEvent implements Can
|
||||
return cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cancellation state of this event
|
||||
*
|
||||
* <p>
|
||||
* Canceling this event will prevent the player from equipping the cosmetic
|
||||
* </p>
|
||||
*
|
||||
* @param cancel true if you wish to cancel this event
|
||||
*/
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,22 +5,22 @@ import org.bukkit.event.Event;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Represents a cosmetic user related event
|
||||
* Represents an event related to a {@link CosmeticUser}.
|
||||
*/
|
||||
public abstract class PlayerCosmeticEvent extends Event {
|
||||
protected CosmeticUser user;
|
||||
public abstract class PlayerCosmeticEvent extends PlayerEvent {
|
||||
protected final CosmeticUser user;
|
||||
|
||||
public PlayerCosmeticEvent(@NotNull final CosmeticUser who) {
|
||||
public PlayerCosmeticEvent(@NotNull CosmeticUser who) {
|
||||
super(who.getUniqueId());
|
||||
user = who;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user involved in this event
|
||||
* Returns the {@link CosmeticUser} involved in this event.
|
||||
*
|
||||
* @return User who is involved in this event
|
||||
* @return the user who is involved in this event
|
||||
*/
|
||||
@NotNull
|
||||
public final CosmeticUser getUser() {
|
||||
public final @NotNull CosmeticUser getUser() {
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,25 +6,26 @@ import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when cosmetics are hidden from a player
|
||||
* Called when cosmetics are hidden from a player.
|
||||
*/
|
||||
public class PlayerCosmeticHideEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancel = false;
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private final CosmeticUser.HiddenReason reason;
|
||||
|
||||
private boolean cancel = false;
|
||||
|
||||
public PlayerCosmeticHideEvent(@NotNull CosmeticUser who, @NotNull CosmeticUser.HiddenReason reason) {
|
||||
super(who);
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link CosmeticUser.HiddenReason} as to why cosmetics are being hidden for the player
|
||||
* Gets the {@link CosmeticUser.HiddenReason} as to why cosmetics are being hidden for the player.
|
||||
*
|
||||
* @return The {@link CosmeticUser.HiddenReason} why cosmetics are being hidden for the player
|
||||
* @return the reason why cosmetics are being hidden for the player
|
||||
*/
|
||||
@NotNull
|
||||
public CosmeticUser.HiddenReason getReason() {
|
||||
public @NotNull CosmeticUser.HiddenReason getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
@@ -33,28 +34,17 @@ public class PlayerCosmeticHideEvent extends PlayerCosmeticEvent implements Canc
|
||||
return cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cancellation state of this event
|
||||
*
|
||||
* <p>
|
||||
* Canceling this event will prevent the player from hiding cosmetics
|
||||
* </p>
|
||||
*
|
||||
* @param cancel true if you wish to cancel this event
|
||||
*/
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,12 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when a player has equipped a {@link Cosmetic}.
|
||||
*/
|
||||
public class PlayerCosmeticPostEquipEvent extends PlayerCosmeticEvent {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private Cosmetic cosmetic;
|
||||
|
||||
public PlayerCosmeticPostEquipEvent(@NotNull CosmeticUser who, @NotNull Cosmetic cosmetic) {
|
||||
@@ -15,32 +19,29 @@ public class PlayerCosmeticPostEquipEvent extends PlayerCosmeticEvent {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link Cosmetic} being equipped in this event
|
||||
* Gets the {@link Cosmetic} being equipped in this event.
|
||||
*
|
||||
* @return The {@link Cosmetic} which is being equipped in this event
|
||||
* @return the cosmetic which is being equipped in this event
|
||||
*/
|
||||
@NotNull
|
||||
public Cosmetic getCosmetic() {
|
||||
public @NotNull Cosmetic getCosmetic() {
|
||||
return cosmetic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link Cosmetic} that the player will equip
|
||||
* Sets the {@link Cosmetic} that the player will equip.
|
||||
*
|
||||
* @param cosmetic The {@link Cosmetic} that the player will equip
|
||||
* @param cosmetic the cosmetic that the player will equip
|
||||
*/
|
||||
public void setCosmetic(@NotNull Cosmetic cosmetic) {
|
||||
this.cosmetic = cosmetic;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,22 +7,24 @@ import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when a player removes a cosmetic
|
||||
* Called when a player removes a {@link Cosmetic}.
|
||||
*/
|
||||
public class PlayerCosmeticRemoveEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancel = false;
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private final Cosmetic cosmetic;
|
||||
|
||||
private boolean cancel = false;
|
||||
|
||||
public PlayerCosmeticRemoveEvent(@NotNull CosmeticUser who, @NotNull Cosmetic cosmetic) {
|
||||
super(who);
|
||||
this.cosmetic = cosmetic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link Cosmetic} being removed in this event
|
||||
* Gets the {@link Cosmetic} being removed in this event.
|
||||
*
|
||||
* @return The {@link Cosmetic} which is being removed in this event
|
||||
* @return the cosmetic which is being removed in this event
|
||||
*/
|
||||
public Cosmetic getCosmetic() {
|
||||
return cosmetic;
|
||||
@@ -33,27 +35,17 @@ public class PlayerCosmeticRemoveEvent extends PlayerCosmeticEvent implements Ca
|
||||
return cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cancellation state of this event
|
||||
*
|
||||
* <p>
|
||||
* Canceling this event will prevent the player from removing the cosmetic
|
||||
* </p>
|
||||
*
|
||||
* @param cancel true if you wish to cancel this event
|
||||
*/
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,11 @@ import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when cosmetics are shown from a player
|
||||
* Called when cosmetics are shown from a player.
|
||||
*/
|
||||
public class PlayerCosmeticShowEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private boolean cancel = false;
|
||||
|
||||
public PlayerCosmeticShowEvent(@NotNull CosmeticUser who) {
|
||||
@@ -21,28 +22,17 @@ public class PlayerCosmeticShowEvent extends PlayerCosmeticEvent implements Canc
|
||||
return cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cancellation state of this event
|
||||
*
|
||||
* <p>
|
||||
* Canceling this event will prevent the player from showing cosmetics
|
||||
* </p>
|
||||
*
|
||||
* @param cancel true if you wish to cancel this event
|
||||
*/
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.api.events;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when a player starts playing an emote
|
||||
*/
|
||||
public class PlayerEmoteStartEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancel = false;
|
||||
private final String animationId;
|
||||
|
||||
public PlayerEmoteStartEvent(@NotNull CosmeticUser who, @NotNull String animationId) {
|
||||
super(who);
|
||||
this.animationId = animationId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the animation id of the emote the player started playing
|
||||
* @implNote The returned string of this method may be an invalid animation id. Make sure to validate it before use
|
||||
*
|
||||
* @return The animation id of the emote which the player started playing
|
||||
*/
|
||||
@NotNull
|
||||
public String getAnimationId() {
|
||||
return animationId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cancellation state of this event
|
||||
*
|
||||
* <p>
|
||||
* Canceling this event will prevent the player from playing the emote
|
||||
* </p>
|
||||
*
|
||||
* @param cancel true if you wish to cancel this event
|
||||
*/
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.api.events;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when a player stops playing an emote
|
||||
*/
|
||||
public class PlayerEmoteStopEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancel = false;
|
||||
private final UserEmoteManager.StopEmoteReason reason;
|
||||
|
||||
public PlayerEmoteStopEvent(@NotNull CosmeticUser who, @NotNull UserEmoteManager.StopEmoteReason reason) {
|
||||
super(who);
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link UserEmoteManager.StopEmoteReason} as to why the emote has stopped playing
|
||||
*
|
||||
* @return The {@link UserEmoteManager.StopEmoteReason} why the emote has stopped playing
|
||||
* @deprecated As of release 2.2.5+, replaced by {@link #getReason()}
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public UserEmoteManager.StopEmoteReason getStopEmoteReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link UserEmoteManager.StopEmoteReason} as to why the emote has stopped playing
|
||||
*
|
||||
* @return The {@link UserEmoteManager.StopEmoteReason} why the emote has stopped playing
|
||||
* @since 2.2.5
|
||||
*/
|
||||
@NotNull
|
||||
public UserEmoteManager.StopEmoteReason getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cancellation state of this event
|
||||
*
|
||||
* <p>
|
||||
* Canceling this event will prevent the player from stopping the emote
|
||||
* </p>
|
||||
*
|
||||
* @param cancel true if you wish to cancel this event
|
||||
*/
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.hibiscusmc.hmccosmetics.api.events;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Represents an event related to a {@link org.bukkit.entity.Player}.
|
||||
*/
|
||||
public abstract class PlayerEvent extends Event {
|
||||
protected final UUID player;
|
||||
|
||||
public PlayerEvent(@NotNull UUID uuid) {
|
||||
this.player = uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link UUID} of the player involved in this event.
|
||||
*
|
||||
* @return the UUID of the player who is involved in this event
|
||||
*/
|
||||
public final @NotNull UUID getUniqueId() {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.hibiscusmc.hmccosmetics.api.events;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when a player's cosmetic data is loaded.
|
||||
*/
|
||||
public class PlayerLoadEvent extends PlayerCosmeticEvent {
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
public PlayerLoadEvent(@NotNull CosmeticUser who) {
|
||||
super(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
@@ -3,26 +3,35 @@ package com.hibiscusmc.hmccosmetics.api.events;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when a menu is closed by a player
|
||||
* Called when a {@link Menu} is closed by a player.
|
||||
*/
|
||||
public class PlayerMenuCloseEvent extends PlayerMenuEvent {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
private final InventoryCloseEvent.Reason reason;
|
||||
|
||||
public PlayerMenuCloseEvent(@NotNull CosmeticUser who, @NotNull Menu menu) {
|
||||
public PlayerMenuCloseEvent(@NotNull CosmeticUser who, @NotNull Menu menu, @NotNull InventoryCloseEvent.Reason reason) {
|
||||
super(who, menu);
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link InventoryCloseEvent.Reason} why the menu was closed.
|
||||
* @return The reason why the menu was closed.
|
||||
*/
|
||||
public InventoryCloseEvent.Reason getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,10 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Represents a menu related event
|
||||
* Represents an event related to a player's interaction with a {@link Menu}.
|
||||
*/
|
||||
public abstract class PlayerMenuEvent extends PlayerCosmeticEvent {
|
||||
protected Menu menu;
|
||||
protected final Menu menu;
|
||||
|
||||
public PlayerMenuEvent(@NotNull CosmeticUser who, @NotNull Menu menu) {
|
||||
super(who);
|
||||
@@ -16,12 +16,11 @@ public abstract class PlayerMenuEvent extends PlayerCosmeticEvent {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link Menu} involved with this event
|
||||
* Gets the {@link Menu} involved with this event.
|
||||
*
|
||||
* @return The {@link Menu} which is involved with the event
|
||||
* @return the menu involved in this event
|
||||
*/
|
||||
@NotNull
|
||||
public final Menu getMenu() {
|
||||
public @NotNull final Menu getMenu() {
|
||||
return menu;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,11 @@ import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when a menu is opened by a player
|
||||
* Called when a {@link Menu} is opened by a player.
|
||||
*/
|
||||
public class PlayerMenuOpenEvent extends PlayerMenuEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private boolean cancel = false;
|
||||
|
||||
public PlayerMenuOpenEvent(@NotNull CosmeticUser who, @NotNull Menu menu) {
|
||||
@@ -22,28 +23,17 @@ public class PlayerMenuOpenEvent extends PlayerMenuEvent implements Cancellable
|
||||
return cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cancellation state of this event
|
||||
*
|
||||
* <p>
|
||||
* Canceling this event will prevent the player from opening a {@link Menu}
|
||||
* </p>
|
||||
*
|
||||
* @param cancel true if you wish to cancel this event
|
||||
*/
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.hibiscusmc.hmccosmetics.api.events;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Called before a player's data is loaded into the plugin.
|
||||
*
|
||||
* <p>
|
||||
* If this event is cancelled, the player's data will not be loaded,
|
||||
* and the player will not be able to interact with the plugin.
|
||||
* </p>
|
||||
*/
|
||||
public class PlayerPreLoadEvent extends PlayerEvent implements Cancellable {
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private boolean cancelled = false;
|
||||
|
||||
public PlayerPreLoadEvent(@NotNull UUID id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.hibiscusmc.hmccosmetics.api.events;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called before a player's data is un-loaded from the plugin.
|
||||
*
|
||||
* <p>
|
||||
* If this event is cancelled, the player's data will not be un-loaded,
|
||||
* and will be kept in memory.
|
||||
* </p>
|
||||
*/
|
||||
public class PlayerPreUnloadEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private boolean cancelled = false;
|
||||
|
||||
public PlayerPreUnloadEvent(@NotNull CosmeticUser who) {
|
||||
super(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.hibiscusmc.hmccosmetics.api.events;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when a players data is unloaded from the plugin. This is called when a player leaves the server.
|
||||
*/
|
||||
public class PlayerUnloadEvent extends PlayerCosmeticEvent {
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
public PlayerUnloadEvent(@NotNull CosmeticUser who) {
|
||||
super(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
@@ -2,19 +2,18 @@ package com.hibiscusmc.hmccosmetics.api.events;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.config.Wardrobe;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when a player enters their wardrobe
|
||||
* Called when a player enters their {@link Wardrobe}.
|
||||
*/
|
||||
public class PlayerWardrobeEnterEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private boolean cancel = false;
|
||||
@Getter @Setter
|
||||
|
||||
private Wardrobe wardrobe;
|
||||
|
||||
public PlayerWardrobeEnterEvent(@NotNull CosmeticUser who, @NotNull Wardrobe wardrobe) {
|
||||
@@ -22,33 +21,38 @@ public class PlayerWardrobeEnterEvent extends PlayerCosmeticEvent implements Can
|
||||
this.wardrobe = wardrobe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link Wardrobe} the player is entering.
|
||||
* @return The wardrobe being entered
|
||||
*/
|
||||
public Wardrobe getWardrobe() {
|
||||
return wardrobe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link Wardrobe} the player is entering.
|
||||
* @param wardrobe the wardrobe being entered
|
||||
*/
|
||||
public void setWardrobe(Wardrobe wardrobe) {
|
||||
this.wardrobe = wardrobe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cancellation state of this event
|
||||
*
|
||||
* <p>
|
||||
* Canceling this event will prevent the player from entering their wardrobe
|
||||
* </p>
|
||||
*
|
||||
* @param cancel true if you wish to cancel this event
|
||||
*/
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,11 @@ import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when a player leaves their wardrobe
|
||||
* Called when a player leaves their {@link com.hibiscusmc.hmccosmetics.config.Wardrobe}.
|
||||
*/
|
||||
public class PlayerWardrobeLeaveEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private boolean cancel = false;
|
||||
|
||||
public PlayerWardrobeLeaveEvent(@NotNull CosmeticUser who) {
|
||||
@@ -21,28 +22,17 @@ public class PlayerWardrobeLeaveEvent extends PlayerCosmeticEvent implements Can
|
||||
return cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cancellation state of this event
|
||||
*
|
||||
* <p>
|
||||
* Canceling this event will prevent the player from leaving their wardrobe
|
||||
* </p>
|
||||
*
|
||||
* @param cancel true if you wish to cancel this event
|
||||
*/
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.hibiscusmc.hmccosmetics.command;
|
||||
|
||||
import com.hibiscusmc.hmccolor.HMCColorConfig;
|
||||
import com.hibiscusmc.hmccolor.HMCColorContextKt;
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.config.Wardrobe;
|
||||
@@ -8,19 +10,17 @@ import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticEmoteType;
|
||||
import com.hibiscusmc.hmccosmetics.database.Database;
|
||||
import com.hibiscusmc.hmccosmetics.emotes.EmoteManager;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||
import com.hibiscusmc.hmccosmetics.gui.special.DyeMenu;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.apache.commons.lang3.EnumUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@@ -40,10 +40,14 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String @NotNull [] args) {
|
||||
boolean silent = false;
|
||||
boolean console = false;
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
console = true;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
if (!(sender instanceof Player)) {
|
||||
// Console
|
||||
if (console) {
|
||||
return true;
|
||||
}
|
||||
if (!sender.hasPermission("hmccosmetics.cmd.default")) {
|
||||
@@ -104,7 +108,18 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
if (sender.hasPermission("hmccosmetics.cmd.apply.color")) {
|
||||
if (args.length >= 4) color = ServerUtils.hex2Rgb(args[3]);
|
||||
if (args.length >= 4) {
|
||||
// TODO: Add sub-color support somehow... (and make this neater)
|
||||
String textColor = args[3];
|
||||
if (!textColor.contains("#") && Hooks.isActiveHook("HMCColor")) {
|
||||
HMCColorConfig.Colors colors = HMCColorContextKt.getHmcColor().getConfig().getColors().get(textColor);
|
||||
if (colors != null) {
|
||||
color = colors.getBaseColor().getColor();
|
||||
}
|
||||
} else {
|
||||
color = HMCCServerUtils.hex2Rgb(textColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length == 1) {
|
||||
@@ -126,7 +141,12 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
|
||||
if (!user.canEquipCosmetic(cosmetic)) {
|
||||
if (user == null) {
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "invalid-player");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!user.canEquipCosmetic(cosmetic) && !console) {
|
||||
if (!silent) MessagesUtil.sendMessage(player, "no-cosmetic-permission");
|
||||
return true;
|
||||
}
|
||||
@@ -134,11 +154,11 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
TagResolver placeholders =
|
||||
TagResolver.resolver(Placeholder.parsed("cosmetic", cosmetic.getId()),
|
||||
TagResolver.resolver(Placeholder.parsed("player", player.getName())),
|
||||
TagResolver.resolver(Placeholder.parsed("cosmeticslot", cosmetic.getSlot().name())));
|
||||
TagResolver.resolver(Placeholder.parsed("cosmeticslot", cosmetic.getSlot().toString())));
|
||||
|
||||
if (!silent) MessagesUtil.sendMessage(player, "equip-cosmetic", placeholders);
|
||||
|
||||
user.addPlayerCosmetic(cosmetic, color);
|
||||
user.addCosmetic(cosmetic, color);
|
||||
user.updateCosmetic(cosmetic.getSlot());
|
||||
return true;
|
||||
}
|
||||
@@ -169,11 +189,12 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
if (args[1].equalsIgnoreCase("all")) {
|
||||
cosmeticSlots = user.getSlotsWithCosmetics();
|
||||
} else {
|
||||
if (!EnumUtils.isValidEnum(CosmeticSlot.class, args[1].toUpperCase())) {
|
||||
String rawSlot = args[1].toUpperCase();
|
||||
if (!CosmeticSlot.contains(rawSlot)) {
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "invalid-slot");
|
||||
return true;
|
||||
}
|
||||
cosmeticSlots = Set.of(CosmeticSlot.valueOf(args[1].toUpperCase()));
|
||||
cosmeticSlots = Set.of(CosmeticSlot.valueOf(rawSlot));
|
||||
}
|
||||
|
||||
for (CosmeticSlot cosmeticSlot : cosmeticSlots) {
|
||||
@@ -185,7 +206,7 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
TagResolver placeholders =
|
||||
TagResolver.resolver(Placeholder.parsed("cosmetic", user.getCosmetic(cosmeticSlot).getId()),
|
||||
TagResolver.resolver(Placeholder.parsed("player", player.getName())),
|
||||
TagResolver.resolver(Placeholder.parsed("cosmeticslot", cosmeticSlot.name())));
|
||||
TagResolver.resolver(Placeholder.parsed("cosmeticslot", cosmeticSlot.toString())));
|
||||
|
||||
if (!silent) MessagesUtil.sendMessage(player, "unequip-cosmetic", placeholders);
|
||||
|
||||
@@ -225,20 +246,24 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
|
||||
if (user.isInWardrobe()) {
|
||||
user.leaveWardrobe();
|
||||
user.leaveWardrobe(false);
|
||||
} else {
|
||||
user.enterWardrobe(false, wardrobe);
|
||||
user.enterWardrobe(wardrobe, false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// cosmetic menu exampleMenu playerName
|
||||
case ("menu") -> {
|
||||
if (args.length == 1) return true;
|
||||
if (!sender.hasPermission("hmccosmetics.cmd.menu")) {
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
||||
return true;
|
||||
}
|
||||
Menu menu = Menus.getMenu(args[1]);
|
||||
Menu menu;
|
||||
if (args.length == 1) {
|
||||
menu = Menus.getDefaultMenu();
|
||||
} else {
|
||||
menu = Menus.getMenu(args[1]);
|
||||
}
|
||||
|
||||
if (sender instanceof Player) player = ((Player) sender).getPlayer();
|
||||
if (sender.hasPermission("hmccosmetics.cmd.menu.other")) {
|
||||
@@ -284,11 +309,12 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!EnumUtils.isValidEnum(CosmeticSlot.class, args[1])) {
|
||||
String rawSlot = args[1];
|
||||
if (!CosmeticSlot.contains(rawSlot)) {
|
||||
if (!silent) MessagesUtil.sendMessage(player, "invalid-slot");
|
||||
return true;
|
||||
}
|
||||
CosmeticSlot slot = CosmeticSlot.valueOf(args[1]);
|
||||
CosmeticSlot slot = CosmeticSlot.valueOf(rawSlot);
|
||||
Cosmetic cosmetic = user.getCosmetic(slot);
|
||||
|
||||
if (args.length >= 3) {
|
||||
@@ -296,12 +322,12 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
if (!silent) MessagesUtil.sendMessage(player, "invalid-color");
|
||||
return true;
|
||||
}
|
||||
Color color = ServerUtils.hex2Rgb(args[2]);
|
||||
Color color = HMCCServerUtils.hex2Rgb(args[2]);
|
||||
if (color == null) {
|
||||
if (!silent) MessagesUtil.sendMessage(player, "invalid-color");
|
||||
return true;
|
||||
}
|
||||
user.addPlayerCosmetic(cosmetic, color); // #FFFFFF
|
||||
user.addCosmetic(cosmetic, color); // #FFFFFF
|
||||
} else {
|
||||
DyeMenu.openMenu(user, cosmetic);
|
||||
}
|
||||
@@ -320,7 +346,7 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
}
|
||||
Wardrobe wardrobe = WardrobeSettings.getWardrobe(args[1]);
|
||||
if (wardrobe == null) {
|
||||
wardrobe = new Wardrobe(args[1], new WardrobeLocation(null, null, null), null, -1);
|
||||
wardrobe = new Wardrobe(args[1], new WardrobeLocation(null, null, null), null, -1, null);
|
||||
WardrobeSettings.addWardrobe(wardrobe);
|
||||
//MessagesUtil.sendMessage(player, "no-wardrobes");
|
||||
//return true;
|
||||
@@ -355,6 +381,11 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
if (!silent) MessagesUtil.sendMessage(player, "set-wardrobe-distance");
|
||||
return true;
|
||||
}
|
||||
if (args[2].equalsIgnoreCase("defaultmenu")) {
|
||||
WardrobeSettings.setWardrobeDefaultMenu(wardrobe, args[3]);
|
||||
if (!silent) MessagesUtil.sendMessage(player, "set-wardrobe-menu");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
case ("dump") -> {
|
||||
@@ -369,6 +400,7 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
||||
player.sendMessage("Backpack Location -> " + user.getUserBackpackManager().getEntityManager().getLocation());
|
||||
}
|
||||
player.sendMessage("Cosmetic Passengers -> " + user.getUserBackpackManager().getAreaEffectEntityId());
|
||||
player.sendMessage("Cosmetics -> " + user.getCosmetics());
|
||||
player.sendMessage("EntityId -> " + player.getEntityId());
|
||||
return true;
|
||||
@@ -413,7 +445,7 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "show-cosmetic");
|
||||
user.showCosmetics();
|
||||
user.showCosmetics(CosmeticUser.HiddenReason.COMMAND);
|
||||
return true;
|
||||
}
|
||||
case ("debug") -> {
|
||||
@@ -430,56 +462,60 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "debug-enabled");
|
||||
}
|
||||
}
|
||||
case ("emote") -> {
|
||||
if (!sender.hasPermission("hmccosmetics.cmd.emote")) {
|
||||
case "disableall" -> {
|
||||
if (!sender.hasPermission("hmccosmetics.cmd.disableall")) {
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
||||
return true;
|
||||
}
|
||||
if (sender.hasPermission("hmccosmetics.cmd.emote.other")) {
|
||||
if (args.length >= 2) player = Bukkit.getPlayer(args[1]);
|
||||
}
|
||||
if (player == null) {
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "invalid-player");
|
||||
return true;
|
||||
}
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (!user.hasCosmeticInSlot(CosmeticSlot.EMOTE)) {
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "emote-none");
|
||||
return true;
|
||||
}
|
||||
|
||||
CosmeticEmoteType cosmeticEmoteType = (CosmeticEmoteType) user.getCosmetic(CosmeticSlot.EMOTE);
|
||||
cosmeticEmoteType.run(user);
|
||||
return true;
|
||||
}
|
||||
|
||||
case ("playemote") -> {
|
||||
// /cosmetic playEmote <emoteId> [playerName]
|
||||
if (!sender.hasPermission("hmccosmetics.cmd.playemote")) {
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length < 2) {
|
||||
if (args.length == 1) {
|
||||
if (!silent) MessagesUtil.sendMessage(player, "not-enough-args");
|
||||
return true;
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("true")) {
|
||||
Settings.setAllPlayersHidden(true);
|
||||
for (CosmeticUser user : CosmeticUsers.values()) user.hideCosmetics(CosmeticUser.HiddenReason.DISABLED);
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "disabled-all");
|
||||
} else if (args[1].equalsIgnoreCase("false")) {
|
||||
Settings.setAllPlayersHidden(false);
|
||||
for (CosmeticUser user : CosmeticUsers.values()) user.showCosmetics(CosmeticUser.HiddenReason.DISABLED);
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "enabled-all");
|
||||
} else {
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "invalid-args");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!EmoteManager.has(args[1])) {
|
||||
MessagesUtil.sendDebugMessages("Did not contain " + args[1]);
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "emote-invalid");
|
||||
case "hiddenreasons" -> {
|
||||
if (!sender.hasPermission("hmccosmetics.cmd.hiddenreasons")) {
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sender.hasPermission("hmccosmetics.cmd.playemote.other")) {
|
||||
if (args.length >= 3) player = Bukkit.getPlayer(args[2]);
|
||||
if (args.length >= 2) {
|
||||
player = Bukkit.getPlayer(args[1]);
|
||||
}
|
||||
if (player == null) {
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "invalid-player");
|
||||
return true;
|
||||
}
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
user.getUserEmoteManager().playEmote(args[1]);
|
||||
sender.sendMessage(user.getHiddenReasons().toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
case "clearhiddenreasons" -> {
|
||||
if (!sender.hasPermission("hmccosmetics.cmd.clearhiddenreasons")) {
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
||||
return true;
|
||||
}
|
||||
if (args.length >= 2) {
|
||||
player = Bukkit.getPlayer(args[1]);
|
||||
}
|
||||
if (player == null) {
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "invalid-player");
|
||||
return true;
|
||||
}
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
user.clearHiddenReasons();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
package com.hibiscusmc.hmccosmetics.command;
|
||||
|
||||
import com.hibiscusmc.hmccolor.HMCColorContextKt;
|
||||
import com.hibiscusmc.hmccosmetics.config.Wardrobe;
|
||||
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||
import com.hibiscusmc.hmccosmetics.emotes.EmoteManager;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -42,14 +43,16 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
||||
if (hasPermission(sender, "hmccosmetics.cmd.hide")) completions.add("hide");
|
||||
if (hasPermission(sender, "hmccosmetics.cmd.show")) completions.add("show");
|
||||
if (hasPermission(sender, "hmccosmetics.cmd.debug")) completions.add("debug");
|
||||
if (hasPermission(sender, "hmccosmetics.cmd.emote")) completions.add("emote");
|
||||
if (hasPermission(sender, "hmccosmetics.cmd.playemote")) completions.add("playemote");
|
||||
if (hasPermission(sender, "hmccosmetics.cmd.disableall")) completions.add("disableall");
|
||||
if (hasPermission(sender, "hmccosmetics.cmd.hiddenreasons")) completions.add("hiddenreasons");
|
||||
if (hasPermission(sender, "hmccosmetics.cmd.clearhiddenreasons")) completions.add("clearhiddenreasons");
|
||||
|
||||
StringUtil.copyPartialMatches(args[0], completions, finalCompletions);
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player)) return completions;
|
||||
CosmeticUser user = CosmeticUsers.getUser(((Player) sender).getUniqueId());
|
||||
if (user == null) return completions; // User hasn't loaded in yet, can't do proper checks
|
||||
|
||||
if (args.length == 2) {
|
||||
String subcommand = args[0].toLowerCase();
|
||||
@@ -68,11 +71,15 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
||||
if (menu.canOpen(user.getPlayer())) completions.add(menu.getId());
|
||||
}
|
||||
}
|
||||
case "dataclear", "hide", "show", "emote" -> {
|
||||
case "dataclear", "hide", "show", "hiddenreasons", "clearhiddenreasons" -> {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
completions.add(player.getName());
|
||||
}
|
||||
}
|
||||
case "disableall" -> {
|
||||
completions.add("true");
|
||||
completions.add("false");
|
||||
}
|
||||
case "wardrobe" -> {
|
||||
for (Wardrobe wardrobe : WardrobeSettings.getWardrobes()) {
|
||||
if (wardrobe.hasPermission()) {
|
||||
@@ -84,7 +91,7 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
||||
}
|
||||
case "dye" -> {
|
||||
for (CosmeticSlot slot : user.getDyeableSlots()) {
|
||||
completions.add(slot.name());
|
||||
completions.add(slot.toString());
|
||||
}
|
||||
}
|
||||
case "setwardrobesetting" -> {
|
||||
@@ -92,7 +99,6 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
||||
completions.add(wardrobe.getId());
|
||||
}
|
||||
}
|
||||
case "playemote" -> completions.addAll(EmoteManager.getAllNames());
|
||||
}
|
||||
StringUtil.copyPartialMatches(args[1], completions, finalCompletions);
|
||||
}
|
||||
@@ -102,7 +108,7 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
||||
case "dye" -> {
|
||||
completions.add("#FFFFFF");
|
||||
}
|
||||
case "menu", "wardrobe", "apply", "unapply", "playemote" -> {
|
||||
case "menu", "wardrobe", "apply", "unapply" -> {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
completions.add(player.getName());
|
||||
}
|
||||
@@ -113,6 +119,7 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
||||
completions.add("leavelocation");
|
||||
completions.add("permission");
|
||||
completions.add("distance");
|
||||
completions.add("defaultmenu");
|
||||
}
|
||||
}
|
||||
StringUtil.copyPartialMatches(args[2], completions, finalCompletions);
|
||||
@@ -122,8 +129,14 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
||||
String subcommand = args[0].toLowerCase();
|
||||
switch (subcommand) {
|
||||
case "apply" -> {
|
||||
if (Hooks.isActiveHook("HMCColor")) completions.addAll(HMCColorContextKt.getHmcColor().getConfig().getColors().keySet());
|
||||
completions.add("#FFFFFF");
|
||||
}
|
||||
case "setwardrobesetting" -> {
|
||||
if (args[2].equalsIgnoreCase("defaultmenu")) {
|
||||
completions.addAll(Menus.getMenuNames());
|
||||
}
|
||||
}
|
||||
}
|
||||
StringUtil.copyPartialMatches(args[3], completions, finalCompletions);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.hibiscusmc.hmccosmetics.config;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
|
||||
public class DatabaseSettings {
|
||||
|
||||
|
||||
@@ -3,10 +3,14 @@ package com.hibiscusmc.hmccosmetics.config;
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Settings {
|
||||
@@ -26,31 +30,30 @@ public class Settings {
|
||||
private static final String UNAPPLY_DEATH_PATH = "unapply-on-death";
|
||||
private static final String FORCE_PERMISSION_JOIN_PATH = "force-permission-join";
|
||||
private static final String FORCE_SHOW_COSMETICS_PATH = "force-show-join";
|
||||
private static final String EMOTE_DISTANCE_PATH = "emote-distance";
|
||||
private static final String ITEM_PROCESSING_PATH = "item-processing";
|
||||
private static final String ITEM_PROCESS_DISPLAY_NAME_PATH = "display-name";
|
||||
private static final String ITEM_PROCESS_LORE_PATH = "lore";
|
||||
private static final String DISABLED_GAMEMODE_PATH = "disabled-gamemode";
|
||||
private static final String DISABLED_GAMEMODE_GAMEMODES_PATH = "gamemodes";
|
||||
private static final String HOOK_SETTING_PATH = "hook-settings";
|
||||
private static final String HOOK_ITEMADDER_PATH = "itemsadder";
|
||||
private static final String HOOK_NEXO_PATH = "nexo";
|
||||
private static final String HOOK_RELOAD_CHANGE_PATH = "reload-on-change";
|
||||
private static final String HOOK_WORLDGUARD_PATH = "worldguard";
|
||||
private static final String HOOK_WG_MOVE_CHECK_PATH = "player-move-check";
|
||||
private static final String HOOK_WG_MOVE_CHECK_PATH_LEGACY = "player_move_check";
|
||||
private static final String COSMETIC_EMOTE_CHECK_PATH = "emote-block-check";
|
||||
private static final String COSMETIC_EMOTE_AIR_CHECK_PATH = "emote-air-check";
|
||||
private static final String COSMETIC_EMOTE_DAMAGE_PATH = "emote-damage-leave";
|
||||
private static final String COSMETIC_EMOTE_INVINCIBLE_PATH = "emote-invincible";
|
||||
private static final String COSMETIC_EMOTE_CAMERA_PATH = "emote-camera";
|
||||
private static final String COSMETIC_EMOTE_MOVE_CHECK_PATH = "emote-move";
|
||||
private static final String COSMETIC_DISABLED_WORLDS_PATH = "disabled-worlds";
|
||||
private static final String COSMETIC_PACKET_ENTITY_TELEPORT_COOLDOWN_PATH = "entity-cooldown-teleport-packet";
|
||||
private static final String COSMETIC_BACKPACK_FORCE_RIDING_PACKET_PATH = "backpack-force-riding-packet";
|
||||
private static final String COSMETIC_FORCE_OFFHAND_COSMETIC_SHOW_PATH = "offhand-always-show";
|
||||
private static final String COSMETIC_ADD_ENCHANTS_HELMET_PATH = "helmet-add-enchantments";
|
||||
private static final String COSMETIC_ADD_ENCHANTS_CHESTPLATE_PATH = "chest-add-enchantments";
|
||||
private static final String COSMETIC_ADD_ENCHANTS_LEGGINGS_PATH = "leggings-add-enchantments";
|
||||
private static final String COSMETIC_ADD_ENCHANTS_BOOTS_PATH = "boots-add-enchantments";
|
||||
private static final String COSMETIC_DESTROY_LOOSE_COSMETIC_PATH = "destroy-loose-cosmetics";
|
||||
private static final String COSMETIC_BALLOON_HEAD_FORWARD_PATH = "balloon-head-forward";
|
||||
private static final String MENU_SETTINGS_PATH = "menu-settings";
|
||||
private static final String MENU_CLICK_COOLDOWN_PATH = "click-cooldown";
|
||||
private static final String MENU_CLICK_COOLDOWN_TIME_PATH = "time";
|
||||
private static final String COSMETIC_TYPE_SETTINGS_PATH = "cosmetic-type";
|
||||
private static final String EQUIP_CLICK_TYPE = "equip-click";
|
||||
private static final String UNEQUIP_CLICK_TYPE = "unequip-click";
|
||||
private static final String DYE_CLICK_TYPE = "dye-click";
|
||||
private static final String SHADING_PATH = "shading";
|
||||
private static final String FIRST_ROW_SHIFT_PATH = "first-row-shift";
|
||||
private static final String SEQUENT_ROW_SHIFT_PATH = "sequent-row-shift";
|
||||
@@ -61,6 +64,10 @@ public class Settings {
|
||||
private static final String EQUIPABLE_COSMETIC_COLOR_PATH = "equipable-cosmetic-color";
|
||||
private static final String LOCKED_COSMETIC_COLOR_PATH = "locked-cosmetic-color";
|
||||
private static final String ENABLED_PATH = "enabled";
|
||||
private static final String SLOT_OPTIONS_PATH = "slot-options";
|
||||
private static final String BACKPACK_PREVENT_DARKNESS_PATH = "backpack-prevent-darkness";
|
||||
private static final String BETTER_HUD_PATH = "betterhud";
|
||||
private static final String BETTER_HUD_HIDE_IN_WARDROBE_PATH = "wardrobe-hide";
|
||||
|
||||
@Getter
|
||||
private static String defaultMenu;
|
||||
@@ -81,31 +88,30 @@ public class Settings {
|
||||
@Getter
|
||||
private static boolean forceShowOnJoin;
|
||||
@Getter
|
||||
private static boolean itemProcessingDisplayName;
|
||||
@Getter
|
||||
private static boolean itemProcessingLore;
|
||||
@Getter
|
||||
private static boolean itemsAdderChangeReload;
|
||||
@Getter
|
||||
private static boolean nexoChangeReload;
|
||||
@Getter
|
||||
private static boolean worldGuardMoveCheck;
|
||||
@Getter
|
||||
private static boolean cosmeticEmoteBlockCheck;
|
||||
@Getter
|
||||
private static boolean addHelmetEnchants;
|
||||
@Getter
|
||||
private static boolean addChestplateEnchants;
|
||||
@Getter
|
||||
private static boolean addLeggingEnchants;
|
||||
@Getter
|
||||
private static boolean addBootsEnchants;
|
||||
@Getter
|
||||
private static boolean emoteAirCheck;
|
||||
@Getter
|
||||
private static boolean emoteDamageLeave;
|
||||
@Getter
|
||||
private static boolean emoteInvincible;
|
||||
private static final HashMap<EquipmentSlot, SlotOptionConfig> slotOptions = new HashMap<>();
|
||||
@Getter
|
||||
private static boolean destroyLooseCosmetics;
|
||||
@Getter
|
||||
private static boolean backpackForceRidingEnabled;
|
||||
@Getter
|
||||
private static boolean cosmeticForceOffhandCosmeticShow;
|
||||
private static boolean disabledGamemodesEnabled;
|
||||
@Getter
|
||||
private static boolean balloonHeadForward;
|
||||
@Getter
|
||||
private static boolean backpackPreventDarkness;
|
||||
@Getter
|
||||
private static List<String> disabledGamemodes;
|
||||
@Getter
|
||||
private static List<String> disabledWorlds;
|
||||
@Getter
|
||||
private static int viewDistance;
|
||||
@Getter
|
||||
@@ -113,6 +119,10 @@ public class Settings {
|
||||
@Getter
|
||||
private static int packetEntityTeleportCooldown;
|
||||
@Getter
|
||||
private static Long defaultMenuCooldown;
|
||||
@Getter
|
||||
private static boolean menuClickCooldown;
|
||||
@Getter
|
||||
private static double emoteDistance;
|
||||
@Getter
|
||||
private static Vector balloonOffset;
|
||||
@@ -121,6 +131,8 @@ public class Settings {
|
||||
@Getter
|
||||
private static String cosmeticUnEquipClickType;
|
||||
@Getter
|
||||
private static String cosmeticDyeClickType;
|
||||
@Getter
|
||||
private static boolean defaultShading;
|
||||
@Getter
|
||||
private static String firstRowShift;
|
||||
@@ -138,10 +150,10 @@ public class Settings {
|
||||
private static String equipableCosmeticColor;
|
||||
@Getter
|
||||
private static String lockedCosmeticColor;
|
||||
@Getter @Setter
|
||||
private static boolean allPlayersHidden;
|
||||
@Getter
|
||||
private static boolean emoteCameraEnabled;
|
||||
@Getter
|
||||
private static boolean emoteMoveCheck;
|
||||
private static boolean wardrobeHideHud;
|
||||
|
||||
|
||||
public static void load(ConfigurationNode source) {
|
||||
@@ -161,29 +173,49 @@ public class Settings {
|
||||
|
||||
ConfigurationNode cosmeticSettings = source.node(COSMETIC_SETTINGS_PATH);
|
||||
|
||||
ConfigurationNode disabledGamemodeSettings = cosmeticSettings.node(DISABLED_GAMEMODE_PATH);
|
||||
disabledGamemodesEnabled = disabledGamemodeSettings.node(ENABLED_PATH).getBoolean(true);
|
||||
try {
|
||||
disabledGamemodes = disabledGamemodeSettings.node(DISABLED_GAMEMODE_GAMEMODES_PATH).getList(String.class);
|
||||
disabledWorlds = cosmeticSettings.node(COSMETIC_DISABLED_WORLDS_PATH).getList(String.class);
|
||||
} catch (Exception e) {
|
||||
disabledGamemodes = new ArrayList<>();
|
||||
disabledWorlds = new ArrayList<>();
|
||||
}
|
||||
|
||||
ConfigurationNode itemProcessingSettings = cosmeticSettings.node(ITEM_PROCESSING_PATH);
|
||||
itemProcessingDisplayName = itemProcessingSettings.node(ITEM_PROCESS_DISPLAY_NAME_PATH).getBoolean(true);
|
||||
itemProcessingLore = itemProcessingSettings.node(ITEM_PROCESS_LORE_PATH).getBoolean(true);
|
||||
|
||||
unapplyOnDeath = cosmeticSettings.node(UNAPPLY_DEATH_PATH).getBoolean(false);
|
||||
forcePermissionJoin = cosmeticSettings.node(FORCE_PERMISSION_JOIN_PATH).getBoolean(false);
|
||||
forceShowOnJoin = cosmeticSettings.node(FORCE_SHOW_COSMETICS_PATH).getBoolean(false);
|
||||
emoteDistance = cosmeticSettings.node(EMOTE_DISTANCE_PATH).getDouble(-3);
|
||||
cosmeticEmoteBlockCheck = cosmeticSettings.node(COSMETIC_EMOTE_CHECK_PATH).getBoolean(true);
|
||||
emoteAirCheck = cosmeticSettings.node(COSMETIC_EMOTE_AIR_CHECK_PATH).getBoolean(true);
|
||||
emoteDamageLeave = cosmeticSettings.node(COSMETIC_EMOTE_DAMAGE_PATH).getBoolean(false);
|
||||
emoteInvincible = cosmeticSettings.node(COSMETIC_EMOTE_INVINCIBLE_PATH).getBoolean(false);
|
||||
destroyLooseCosmetics = cosmeticSettings.node(COSMETIC_DESTROY_LOOSE_COSMETIC_PATH).getBoolean(false);
|
||||
backpackForceRidingEnabled = cosmeticSettings.node(COSMETIC_BACKPACK_FORCE_RIDING_PACKET_PATH).getBoolean(false);
|
||||
addHelmetEnchants = cosmeticSettings.node(COSMETIC_ADD_ENCHANTS_HELMET_PATH).getBoolean(false);
|
||||
addChestplateEnchants = cosmeticSettings.node(COSMETIC_ADD_ENCHANTS_CHESTPLATE_PATH).getBoolean(false);
|
||||
addLeggingEnchants = cosmeticSettings.node(COSMETIC_ADD_ENCHANTS_LEGGINGS_PATH).getBoolean(false);
|
||||
addBootsEnchants = cosmeticSettings.node(COSMETIC_ADD_ENCHANTS_BOOTS_PATH).getBoolean(false);
|
||||
|
||||
cosmeticSettings.node(SLOT_OPTIONS_PATH).childrenMap().forEach((key, value) -> {
|
||||
EquipmentSlot slot = convertConfigToEquipment(key.toString().toLowerCase());
|
||||
if (slot == null) {
|
||||
MessagesUtil.sendDebugMessages("Invalid slot option: " + key, Level.WARNING);
|
||||
return;
|
||||
}
|
||||
boolean addEnchantments = value.node("add-enchantments").getBoolean(false);
|
||||
boolean requireEmpty = value.node("require-empty").getBoolean(false);
|
||||
slotOptions.put(slot, new SlotOptionConfig(slot, addEnchantments, requireEmpty));
|
||||
});
|
||||
|
||||
tickPeriod = cosmeticSettings.node(TICK_PERIOD_PATH).getInt(-1);
|
||||
viewDistance = cosmeticSettings.node(VIEW_DISTANCE_PATH).getInt(-3);
|
||||
emoteCameraEnabled = cosmeticSettings.node(COSMETIC_EMOTE_CAMERA_PATH).getBoolean(true);
|
||||
emoteMoveCheck = cosmeticSettings.node(COSMETIC_EMOTE_MOVE_CHECK_PATH).getBoolean(false);
|
||||
packetEntityTeleportCooldown = cosmeticSettings.node(COSMETIC_PACKET_ENTITY_TELEPORT_COOLDOWN_PATH).getInt(-1);
|
||||
cosmeticForceOffhandCosmeticShow = cosmeticSettings.node(COSMETIC_FORCE_OFFHAND_COSMETIC_SHOW_PATH).getBoolean(false);
|
||||
balloonHeadForward = cosmeticSettings.node(COSMETIC_BALLOON_HEAD_FORWARD_PATH).getBoolean(false);
|
||||
backpackPreventDarkness = cosmeticSettings.node(BACKPACK_PREVENT_DARKNESS_PATH).getBoolean(true);
|
||||
|
||||
ConfigurationNode menuSettings = source.node(MENU_SETTINGS_PATH);
|
||||
|
||||
ConfigurationNode clickCooldownSettings = menuSettings.node(MENU_CLICK_COOLDOWN_PATH);
|
||||
menuClickCooldown = clickCooldownSettings.node(ENABLED_PATH).getBoolean(true);
|
||||
defaultMenuCooldown = clickCooldownSettings.node(MENU_CLICK_COOLDOWN_TIME_PATH).getLong(1000L);
|
||||
|
||||
ConfigurationNode shadingSettings = menuSettings.node(SHADING_PATH);
|
||||
defaultShading = shadingSettings.node(ENABLED_PATH).getBoolean();
|
||||
firstRowShift = shadingSettings.node(FIRST_ROW_SHIFT_PATH).getString();
|
||||
@@ -196,8 +228,9 @@ public class Settings {
|
||||
lockedCosmeticColor = shadingSettings.node(LOCKED_COSMETIC_COLOR_PATH).getString();
|
||||
|
||||
ConfigurationNode cosmeticTypeSettings = menuSettings.node(COSMETIC_TYPE_SETTINGS_PATH);
|
||||
cosmeticEquipClickType = cosmeticTypeSettings.node(EQUIP_CLICK_TYPE).getString("ALL");
|
||||
cosmeticUnEquipClickType = cosmeticTypeSettings.node(UNEQUIP_CLICK_TYPE).getString("ALL");
|
||||
cosmeticEquipClickType = cosmeticTypeSettings.node(EQUIP_CLICK_TYPE).getString("ANY");
|
||||
cosmeticUnEquipClickType = cosmeticTypeSettings.node(UNEQUIP_CLICK_TYPE).getString("ANY");
|
||||
cosmeticDyeClickType = cosmeticTypeSettings.node(DYE_CLICK_TYPE).getString("ANY");
|
||||
|
||||
final var balloonSection = cosmeticSettings.node(BALLOON_OFFSET);
|
||||
balloonOffset = loadVector(balloonSection);
|
||||
@@ -209,9 +242,16 @@ public class Settings {
|
||||
dyeMenuOutputSlot = dyeMenuSettings.node(DYE_MENU_OUTPUT_SLOT).getInt(25);
|
||||
|
||||
ConfigurationNode hookSettings = source.node(HOOK_SETTING_PATH);
|
||||
|
||||
ConfigurationNode itemsAdderSettings = hookSettings.node(HOOK_ITEMADDER_PATH);
|
||||
itemsAdderChangeReload = itemsAdderSettings.node(HOOK_RELOAD_CHANGE_PATH).getBoolean(false);
|
||||
|
||||
ConfigurationNode nexoSettings = hookSettings.node(HOOK_NEXO_PATH);
|
||||
nexoChangeReload = nexoSettings.node(HOOK_RELOAD_CHANGE_PATH).getBoolean(true);
|
||||
|
||||
ConfigurationNode betterHudSettings = hookSettings.node(BETTER_HUD_PATH);
|
||||
wardrobeHideHud = betterHudSettings.node(BETTER_HUD_HIDE_IN_WARDROBE_PATH).getBoolean(true);
|
||||
|
||||
ConfigurationNode worldGuardSettings = hookSettings.node(HOOK_WORLDGUARD_PATH);
|
||||
worldGuardMoveCheck = worldGuardSettings.node(HOOK_WG_MOVE_CHECK_PATH).getBoolean(true);
|
||||
// I messed up in release 2.2.6 and forgot to change player_move_check to player-move-check.
|
||||
@@ -225,24 +265,9 @@ public class Settings {
|
||||
return new Vector(config.node("x").getDouble(), config.node("y").getDouble(), config.node("z").getDouble());
|
||||
}
|
||||
|
||||
public static boolean getShouldAddEnchants(EquipmentSlot slot) {
|
||||
switch (slot) {
|
||||
case HEAD -> {
|
||||
return addHelmetEnchants;
|
||||
}
|
||||
case CHEST -> {
|
||||
return addChestplateEnchants;
|
||||
}
|
||||
case LEGS -> {
|
||||
return addLeggingEnchants;
|
||||
}
|
||||
case FEET -> {
|
||||
return addBootsEnchants;
|
||||
}
|
||||
default -> {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static SlotOptionConfig getSlotOption(EquipmentSlot slot) {
|
||||
if (!slotOptions.containsKey(slot)) slotOptions.put(slot, new SlotOptionConfig(slot, false, false));
|
||||
return slotOptions.get(slot);
|
||||
}
|
||||
|
||||
public static void setDebugMode(boolean newSetting) {
|
||||
@@ -254,4 +279,16 @@ public class Settings {
|
||||
|
||||
plugin.saveConfig();
|
||||
}
|
||||
|
||||
private static EquipmentSlot convertConfigToEquipment(String slot) {
|
||||
return switch (slot) {
|
||||
case "helmet" -> EquipmentSlot.HEAD;
|
||||
case "chestplate" -> EquipmentSlot.CHEST;
|
||||
case "leggings" -> EquipmentSlot.LEGS;
|
||||
case "boots" -> EquipmentSlot.FEET;
|
||||
case "offhand" -> EquipmentSlot.OFF_HAND;
|
||||
case "mainhand" -> EquipmentSlot.HAND;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.hibiscusmc.hmccosmetics.config;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
|
||||
public class SlotOptionConfig {
|
||||
|
||||
@Getter
|
||||
private final EquipmentSlot slot;
|
||||
@Getter
|
||||
private final boolean addEnchantments;
|
||||
@Getter
|
||||
private final boolean requireEmpty;
|
||||
|
||||
public SlotOptionConfig(EquipmentSlot slot, boolean addEnchantments, boolean requireEmpty) {
|
||||
this.slot = slot;
|
||||
this.addEnchantments = addEnchantments;
|
||||
this.requireEmpty = requireEmpty;
|
||||
}
|
||||
}
|
||||
@@ -14,10 +14,12 @@ public class Wardrobe {
|
||||
private final String id;
|
||||
@Getter @Setter
|
||||
private int distance;
|
||||
@Getter @Setter
|
||||
@Getter @Setter @Nullable
|
||||
private String permission;
|
||||
@Getter @Setter
|
||||
private WardrobeLocation location;
|
||||
@Getter @Setter @Nullable
|
||||
private String defaultMenu;
|
||||
|
||||
/**
|
||||
* This creates a Wardrobe object with all the information that a user will need when entering.
|
||||
@@ -25,12 +27,14 @@ public class Wardrobe {
|
||||
* @param location The 3 locations of the Wardrobe, if any of these 3 locations are null, the wardrobe will not work
|
||||
* @param permission The permission required to enter the wardrobe, if null, no permission is required
|
||||
* @param distance The distance from the wardrobe that the player can be to enter, if -1, the player can enter from any distance
|
||||
* @param defaultMenu The default menu that the player will open when entering the wardrobe.
|
||||
*/
|
||||
public Wardrobe(@NotNull String id, @NotNull WardrobeLocation location, @Nullable String permission, int distance) {
|
||||
public Wardrobe(@NotNull String id, @NotNull WardrobeLocation location, @Nullable String permission, int distance, @Nullable String defaultMenu) {
|
||||
this.id = id;
|
||||
this.location = location;
|
||||
this.distance = distance;
|
||||
if (permission != null) this.permission = permission;
|
||||
if (defaultMenu != null) this.defaultMenu = defaultMenu;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,7 +54,7 @@ public class Wardrobe {
|
||||
Location wardrobeLocation = location.getNpcLocation();
|
||||
Location location = user.getEntity().getLocation();
|
||||
if (wardrobeLocation == null) return false;
|
||||
if (distance == -1) return true;
|
||||
if (distance <= 0) return true;
|
||||
if (!wardrobeLocation.getWorld().equals(location.getWorld())) return false;
|
||||
return wardrobeLocation.distanceSquared(location) <= distance * distance;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package com.hibiscusmc.hmccosmetics.config;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.serializer.LocationSerializer;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.misc.Utils;
|
||||
import lombok.Getter;
|
||||
import me.lojosho.hibiscuscommons.config.serializer.LocationSerializer;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import net.kyori.adventure.bossbar.BossBar;
|
||||
import org.apache.commons.lang3.EnumUtils;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@@ -33,6 +32,8 @@ public class WardrobeSettings {
|
||||
private static final String EQUIP_PUMPKIN_WARDROBE = "equip-pumpkin";
|
||||
private static final String TRY_COSMETICS_WARDROBE = "unchecked-wardrobe-cosmetics";
|
||||
private static final String RETURN_LAST_LOCATION = "return-last-location";
|
||||
private static final String DAMAGE_KICK_PATH = "damage-kicked";
|
||||
private static final String PREVENT_DAMAGE_PATH = "prevent-damage";
|
||||
|
||||
private static final String WARDROBE_MENU_OPTIONS = "menu-options";
|
||||
private static final String WARDROBE_ENTER_OPEN_MENU_PATH = "enter-open-menu";
|
||||
@@ -43,6 +44,7 @@ public class WardrobeSettings {
|
||||
private static final String WARDROBES_PATH = "wardrobes";
|
||||
private static final String PERMISSION_PATH = "permission";
|
||||
private static final String DISTANCE_PATH = "distance";
|
||||
private static final String WARDROBE_DEFAULT_MENU = "default-menu";
|
||||
private static final String BOSSBAR_PATH = "bossbar";
|
||||
private static final String BOSSBAR_ENABLE_PATH = "enabled";
|
||||
private static final String BOSSBAR_TEXT_PATH = "text";
|
||||
@@ -87,6 +89,10 @@ public class WardrobeSettings {
|
||||
@Getter
|
||||
private static boolean forceExitGamemode;
|
||||
@Getter
|
||||
private static boolean damagedKicked;
|
||||
@Getter
|
||||
private static boolean preventDamage;
|
||||
@Getter
|
||||
private static GameMode exitGamemode;
|
||||
private static HashMap<String, Wardrobe> wardrobes;
|
||||
@Getter
|
||||
@@ -121,6 +127,8 @@ public class WardrobeSettings {
|
||||
equipPumpkin = source.node(EQUIP_PUMPKIN_WARDROBE).getBoolean();
|
||||
returnLastLocation = source.node(RETURN_LAST_LOCATION).getBoolean(false);
|
||||
tryCosmeticsInWardrobe = source.node(TRY_COSMETICS_WARDROBE).getBoolean(false);
|
||||
damagedKicked = source.node(DAMAGE_KICK_PATH).getBoolean(false);
|
||||
preventDamage = source.node(PREVENT_DAMAGE_PATH).getBoolean(true);
|
||||
|
||||
ConfigurationNode menuOptionsNode = source.node(WARDROBE_MENU_OPTIONS);
|
||||
enterOpenMenu = menuOptionsNode.node(WARDROBE_ENTER_OPEN_MENU_PATH).getBoolean(false);
|
||||
@@ -161,14 +169,16 @@ public class WardrobeSettings {
|
||||
MessagesUtil.sendDebugMessages("Wardrobe Location: " + npcLocation);
|
||||
Location viewerLocation = LocationSerializer.INSTANCE.deserialize(Location.class, wardrobesNode.node(VIEWER_LOCATION_PATH));
|
||||
MessagesUtil.sendDebugMessages("Viewer Location: " + viewerLocation);
|
||||
Location leaveLocation = Utils.replaceIfNull(LocationSerializer.INSTANCE.deserialize(Location.class, wardrobesNode.node(LEAVE_LOCATION_PATH)), viewerLocation);
|
||||
Location leaveLocation = LocationSerializer.INSTANCE.deserialize(Location.class, wardrobesNode.node(LEAVE_LOCATION_PATH));
|
||||
if (leaveLocation == null) leaveLocation = viewerLocation;
|
||||
MessagesUtil.sendDebugMessages("Leave Location: " + leaveLocation);
|
||||
WardrobeLocation wardrobeLocation = new WardrobeLocation(npcLocation, viewerLocation, leaveLocation);
|
||||
|
||||
String permission = wardrobesNode.node(PERMISSION_PATH).getString();
|
||||
String defaultMenu = wardrobesNode.node(WARDROBE_DEFAULT_MENU).getString();
|
||||
int distance = wardrobesNode.node(DISTANCE_PATH).getInt(-1);
|
||||
|
||||
Wardrobe wardrobe = new Wardrobe(id, wardrobeLocation, permission, distance);
|
||||
Wardrobe wardrobe = new Wardrobe(id, wardrobeLocation, permission, distance, defaultMenu);
|
||||
addWardrobe(wardrobe);
|
||||
} catch (Exception e) {
|
||||
MessagesUtil.sendDebugMessages("Unable to create wardrobe " + id, Level.SEVERE);
|
||||
@@ -272,4 +282,14 @@ public class WardrobeSettings {
|
||||
|
||||
plugin.saveConfig();
|
||||
}
|
||||
|
||||
public static void setWardrobeDefaultMenu(Wardrobe wardrobe, String defaultMenu) {
|
||||
wardrobe.setDefaultMenu(defaultMenu);
|
||||
|
||||
HMCCosmeticsPlugin plugin = HMCCosmeticsPlugin.getInstance();
|
||||
|
||||
plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".default-menu", defaultMenu);
|
||||
|
||||
plugin.saveConfig();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,165 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.config.serializer;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
|
||||
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.builder.ColorBuilder;
|
||||
import com.hibiscusmc.hmccosmetics.util.misc.StringUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.misc.Utils;
|
||||
import org.apache.commons.lang3.EnumUtils;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
import org.spongepowered.configurate.serialize.TypeSerializer;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ItemSerializer implements TypeSerializer<ItemStack> {
|
||||
|
||||
public static final ItemSerializer INSTANCE = new ItemSerializer();
|
||||
private static final String MATERIAL = "material";
|
||||
private static final String AMOUNT = "amount";
|
||||
private static final String NAME = "name";
|
||||
private static final String UNBREAKABLE = "unbreakable";
|
||||
private static final String GLOWING = "glowing";
|
||||
private static final String LORE = "lore";
|
||||
private static final String MODEL_DATA = "model-data";
|
||||
private static final String NBT_TAGS = "nbt-tag";
|
||||
private static final String ENCHANTS = "enchants";
|
||||
private static final String ITEM_FLAGS = "item-flags";
|
||||
private static final String TEXTURE = "texture";
|
||||
private static final String OWNER = "owner";
|
||||
private static final String COLOR = "color";
|
||||
private static final String RED = "red";
|
||||
private static final String GREEN = "green";
|
||||
private static final String BLUE = "blue";
|
||||
|
||||
private ItemSerializer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack deserialize(final Type type, final ConfigurationNode source)
|
||||
throws SerializationException {
|
||||
final ConfigurationNode materialNode = source.node(MATERIAL);
|
||||
final ConfigurationNode amountNode = source.node(AMOUNT);
|
||||
final ConfigurationNode nameNode = source.node(NAME);
|
||||
final ConfigurationNode unbreakableNode = source.node(UNBREAKABLE);
|
||||
final ConfigurationNode glowingNode = source.node(GLOWING);
|
||||
final ConfigurationNode loreNode = source.node(LORE);
|
||||
final ConfigurationNode modelDataNode = source.node(MODEL_DATA);
|
||||
final ConfigurationNode nbtNode = source.node(NBT_TAGS);
|
||||
final ConfigurationNode enchantsNode = source.node(ENCHANTS);
|
||||
final ConfigurationNode itemFlagsNode = source.node(ITEM_FLAGS);
|
||||
final ConfigurationNode textureNode = source.node(TEXTURE);
|
||||
final ConfigurationNode ownerNode = source.node(OWNER);
|
||||
final ConfigurationNode colorNode = source.node(COLOR);
|
||||
final ConfigurationNode redNode = colorNode.node(RED);
|
||||
final ConfigurationNode greenNode = colorNode.node(GREEN);
|
||||
final ConfigurationNode blueNode = colorNode.node(BLUE);
|
||||
|
||||
if (materialNode.virtual()) return null;
|
||||
|
||||
String material = materialNode.getString();
|
||||
|
||||
ItemStack item = Hooks.getItem(material);
|
||||
if (item == null) {
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().severe("Invalid Material -> " + material);
|
||||
return new ItemStack(Material.AIR);
|
||||
}
|
||||
item.setAmount(amountNode.getInt(1));
|
||||
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
if (itemMeta == null) return item;
|
||||
if (!nameNode.virtual())
|
||||
itemMeta.setDisplayName(StringUtils.parseStringToString(Utils.replaceIfNull(nameNode.getString(), "")));
|
||||
if (!unbreakableNode.virtual()) itemMeta.setUnbreakable(unbreakableNode.getBoolean());
|
||||
if (!glowingNode.virtual()) {
|
||||
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
itemMeta.addEnchant(Enchantment.LUCK, 1, true);
|
||||
}
|
||||
if (!loreNode.virtual()) itemMeta.setLore(Utils.replaceIfNull(loreNode.getList(String.class),
|
||||
new ArrayList<String>()).
|
||||
stream().map(StringUtils::parseStringToString).collect(Collectors.toList()));
|
||||
if (!modelDataNode.virtual()) itemMeta.setCustomModelData(modelDataNode.getInt());
|
||||
|
||||
if (!nbtNode.virtual()) {
|
||||
for (ConfigurationNode nbtNodes : nbtNode.childrenMap().values()) {
|
||||
itemMeta.getPersistentDataContainer().set(NamespacedKey.minecraft(nbtNodes.key().toString()), PersistentDataType.STRING, nbtNodes.getString());
|
||||
}
|
||||
}
|
||||
|
||||
if (!enchantsNode.virtual()) {
|
||||
for (ConfigurationNode enchantNode : enchantsNode.childrenMap().values()) {
|
||||
if (Enchantment.getByKey(NamespacedKey.minecraft(enchantNode.key().toString())) == null) continue;
|
||||
itemMeta.addEnchant(Enchantment.getByKey(NamespacedKey.minecraft(enchantNode.key().toString())), enchantNode.getInt(1), true);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (!itemFlagsNode.virtual()) {
|
||||
for (String itemFlag : itemFlagsNode.getList(String.class)) {
|
||||
if (!EnumUtils.isValidEnum(ItemFlag.class, itemFlag)) continue;
|
||||
MessagesUtil.sendDebugMessages("Added " + itemFlag + " to the item!");
|
||||
itemMeta.addItemFlags(ItemFlag.valueOf(itemFlag));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (item.getType() == Material.PLAYER_HEAD) {
|
||||
SkullMeta skullMeta = (SkullMeta) itemMeta;
|
||||
if (!ownerNode.virtual()) {
|
||||
String ownerString = ownerNode.getString();
|
||||
if (ownerString.contains("%")) {
|
||||
// This means it has PAPI placeholders in it
|
||||
skullMeta.getPersistentDataContainer().set(InventoryUtils.getSkullOwner(), PersistentDataType.STRING, ownerString);
|
||||
}
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(ownerString);
|
||||
skullMeta.setOwningPlayer(player);
|
||||
}
|
||||
|
||||
if (!textureNode.virtual()) {
|
||||
String textureString = textureNode.getString();
|
||||
if (textureString.contains("%")) {
|
||||
// This means it has PAPI placeholders in it
|
||||
skullMeta.getPersistentDataContainer().set(InventoryUtils.getSkullTexture(), PersistentDataType.STRING, textureString);
|
||||
}
|
||||
Bukkit.getUnsafe().modifyItemStack(item, "{SkullOwner:{Id:[I;0,0,0,0],Properties:{textures:[{Value:\""
|
||||
+ textureString + "\"}]}}}");
|
||||
|
||||
|
||||
itemMeta = skullMeta;
|
||||
}
|
||||
}
|
||||
|
||||
if (!colorNode.virtual()) {
|
||||
if (ColorBuilder.canBeColored(item.getType())) {
|
||||
if (!redNode.virtual()) {
|
||||
itemMeta = ColorBuilder.color(itemMeta, Color.fromRGB(redNode.getInt(0), greenNode.getInt(0), blueNode.getInt(0)));
|
||||
} else {
|
||||
itemMeta = ColorBuilder.color(itemMeta, ServerUtils.hex2Rgb(colorNode.getString("#FFFFFF")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
item.setItemMeta(itemMeta);
|
||||
return item;
|
||||
}
|
||||
@Override
|
||||
public void serialize(final Type type, @Nullable final ItemStack obj, final ConfigurationNode node) throws SerializationException {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.config.serializer;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
import org.spongepowered.configurate.serialize.TypeSerializer;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class LocationSerializer implements TypeSerializer<Location> {
|
||||
|
||||
public static final LocationSerializer INSTANCE = new LocationSerializer();
|
||||
|
||||
private static final String WORLD = "world";
|
||||
private static final String X = "x";
|
||||
private static final String Y = "y";
|
||||
private static final String Z = "z";
|
||||
private static final String PITCH = "pitch";
|
||||
private static final String YAW = "yaw";
|
||||
|
||||
|
||||
private LocationSerializer() {}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Location deserialize(final Type type, final ConfigurationNode source) throws SerializationException {
|
||||
final World world = Bukkit.getWorld(source.node(WORLD).getString());
|
||||
if (world == null) return null;
|
||||
return new Location(
|
||||
world,
|
||||
source.node(X).getDouble(),
|
||||
source.node(Y).getDouble(),
|
||||
source.node(Z).getDouble(),
|
||||
source.node(YAW).getFloat(),
|
||||
source.node(PITCH).getFloat()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(final Type type, @Nullable final Location loc, final ConfigurationNode source) throws SerializationException {
|
||||
// Empty
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,62 @@
|
||||
package com.hibiscusmc.hmccosmetics.cosmetic;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.config.serializer.ItemSerializer;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.lojosho.hibiscuscommons.config.serializer.ItemSerializer;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import me.lojosho.shaded.configurate.serialize.SerializationException;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public abstract class Cosmetic {
|
||||
protected static ItemStack UNDEFINED_DISPLAY_ITEM_STACK;
|
||||
|
||||
@Getter @Setter
|
||||
static {
|
||||
UNDEFINED_DISPLAY_ITEM_STACK = new ItemStack(Material.BARRIER);
|
||||
|
||||
ItemMeta meta = UNDEFINED_DISPLAY_ITEM_STACK.getItemMeta();
|
||||
if (meta != null) {
|
||||
// Legacy methods for Spigot >:(
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&cUndefined Item Display"));
|
||||
meta.setLore(List.of(
|
||||
ChatColor.translateAlternateColorCodes('&', "&cPlease check your configurations & console to"),
|
||||
ChatColor.translateAlternateColorCodes('&', "&censure there are no errors.")));
|
||||
}
|
||||
UNDEFINED_DISPLAY_ITEM_STACK.setItemMeta(meta);
|
||||
}
|
||||
|
||||
/** Identifier of the cosmetic. */
|
||||
private String id;
|
||||
@Getter @Setter
|
||||
private String permission;
|
||||
private ItemStack item;
|
||||
@Getter @Setter
|
||||
private String material;
|
||||
@Getter @Setter
|
||||
private CosmeticSlot slot;
|
||||
@Getter @Setter
|
||||
private boolean dyable;
|
||||
|
||||
protected Cosmetic(String id, @NotNull ConfigurationNode config) {
|
||||
/** Permission to use the cosmetic. */
|
||||
private String permission;
|
||||
|
||||
/** The display {@link ItemStack} of the cosmetic. */
|
||||
@Getter(AccessLevel.NONE) @Setter(AccessLevel.NONE)
|
||||
private ItemStack item;
|
||||
|
||||
/** The material string of the cosmetic. */
|
||||
private String material;
|
||||
|
||||
/** The {@link CosmeticSlot} this cosmetic occupies. */
|
||||
private CosmeticSlot slot;
|
||||
|
||||
/** Whether the cosmetic is dyeable or not. */
|
||||
private boolean dyeable;
|
||||
|
||||
protected Cosmetic(@NotNull String id, @NotNull ConfigurationNode config) {
|
||||
this.id = id;
|
||||
|
||||
if (!config.node("permission").virtual()) {
|
||||
@@ -39,23 +67,49 @@ public abstract class Cosmetic {
|
||||
|
||||
if (!config.node("item").virtual()) {
|
||||
this.material = config.node("item", "material").getString();
|
||||
this.item = generateItemStack(config.node("item"));
|
||||
try {
|
||||
this.item = generateItemStack(config.node("item"));
|
||||
} catch(Exception ex) {
|
||||
MessagesUtil.sendDebugMessages("Forcing %s to use undefined display".formatted(getId()));
|
||||
this.item = UNDEFINED_DISPLAY_ITEM_STACK;
|
||||
}
|
||||
}
|
||||
|
||||
MessagesUtil.sendDebugMessages("Slot: " + config.node("slot").getString());
|
||||
this.slot = CosmeticSlot.valueOf(config.node("slot").getString());
|
||||
|
||||
setSlot(CosmeticSlot.valueOf(config.node("slot").getString()));
|
||||
setDyable(config.node("dyeable").getBoolean(false));
|
||||
this.dyeable = config.node("dyeable").getBoolean(false);
|
||||
MessagesUtil.sendDebugMessages("Dyeable " + dyeable);
|
||||
}
|
||||
|
||||
MessagesUtil.sendDebugMessages("Dyeable " + dyable);
|
||||
Cosmetics.addCosmetic(this);
|
||||
protected Cosmetic(String id, String permission, ItemStack item, String material, CosmeticSlot slot, boolean dyeable) {
|
||||
this.id = id;
|
||||
this.permission = permission;
|
||||
this.item = item;
|
||||
this.material = material;
|
||||
this.slot = slot;
|
||||
this.dyeable = dyeable;
|
||||
}
|
||||
|
||||
public boolean requiresPermission() {
|
||||
return permission != null;
|
||||
}
|
||||
|
||||
public abstract void update(CosmeticUser user);
|
||||
/**
|
||||
* Dispatched when an update is requested upon the cosmetic.
|
||||
* @param user the user to preform the update against
|
||||
*/
|
||||
public final void update(CosmeticUser user) {
|
||||
this.doUpdate(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Action preformed on the update.
|
||||
* @param user the user to preform the update against
|
||||
*/
|
||||
protected void doUpdate(final CosmeticUser user) {
|
||||
// NO-OP.
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ItemStack getItem() {
|
||||
@@ -63,6 +117,11 @@ public abstract class Cosmetic {
|
||||
return item.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an {@link ItemStack} from a {@link ConfigurationNode}.
|
||||
* @param config the configuration node
|
||||
* @return the {@link ItemStack}
|
||||
*/
|
||||
protected ItemStack generateItemStack(ConfigurationNode config) {
|
||||
try {
|
||||
ItemStack item = ItemSerializer.INSTANCE.deserialize(ItemStack.class, config);
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.hibiscusmc.hmccosmetics.cosmetic;
|
||||
|
||||
import com.google.common.collect.ImmutableCollection;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Represents any object that can wear/hold cosmetics,
|
||||
* users, for example.
|
||||
*/
|
||||
public interface CosmeticHolder {
|
||||
@Nullable Cosmetic getCosmetic(@NotNull CosmeticSlot slot);
|
||||
|
||||
@NotNull ImmutableCollection<Cosmetic> getCosmetics();
|
||||
|
||||
void addCosmetic(@NotNull Cosmetic cosmetic, @Nullable Color color);
|
||||
|
||||
default void addCosmetic(@NotNull Cosmetic cosmetic) {
|
||||
addCosmetic(cosmetic, null);
|
||||
}
|
||||
|
||||
default void removeCosmetics() {
|
||||
// Small optimization could be made, but Concurrent modification prevents us from both getting and removing
|
||||
for (CosmeticSlot slot : CosmeticSlot.values().values()) {
|
||||
removeCosmeticSlot(slot);
|
||||
}
|
||||
}
|
||||
|
||||
void removeCosmeticSlot(@NotNull CosmeticSlot slot);
|
||||
|
||||
default void removeCosmeticSlot(@NotNull Cosmetic cosmetic) {
|
||||
removeCosmeticSlot(cosmetic.getSlot());
|
||||
}
|
||||
|
||||
default boolean hasCosmeticInSlot(@NotNull CosmeticSlot slot) {
|
||||
return getCosmetic(slot) != null;
|
||||
}
|
||||
|
||||
default boolean hasCosmeticInSlot(@NotNull Cosmetic cosmetic) {
|
||||
final var existingCosmetic = getCosmetic(cosmetic.getSlot());
|
||||
if (existingCosmetic == null) return false;
|
||||
return Objects.equals(cosmetic.getId(), existingCosmetic.getId());
|
||||
}
|
||||
|
||||
default boolean canEquipCosmetic(@NotNull Cosmetic cosmetic) {
|
||||
return canEquipCosmetic(cosmetic, false);
|
||||
}
|
||||
|
||||
boolean canEquipCosmetic(@NotNull Cosmetic cosmetic, boolean ignoreWardrobe);
|
||||
|
||||
void updateCosmetic(@NotNull CosmeticSlot slot);
|
||||
|
||||
/**
|
||||
* Just for backwards compatibility, ensures that the given viewer and the given cosmetic holder
|
||||
* represent the same user.
|
||||
*
|
||||
* @param viewer the viewer
|
||||
* @param cosmeticHolder the cosmetic holder
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
static @NotNull CosmeticUser ensureSingleCosmeticUser(@NotNull Player viewer, @NotNull CosmeticHolder cosmeticHolder) {
|
||||
if (!(cosmeticHolder instanceof CosmeticUser user) || !user.getUniqueId().equals(viewer.getUniqueId())) {
|
||||
throw new IllegalStateException("This method does not support having a different viewer than" +
|
||||
" the same cosmetic holder. Needs to be updated to support the overload that takes a viewer and" +
|
||||
" a cosmetic holder instead of a single CosmeticUser.");
|
||||
}
|
||||
return user;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.hibiscusmc.hmccosmetics.cosmetic;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.*;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
/**
|
||||
* Allow custom implementations of a {@link Cosmetic}.
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class CosmeticProvider {
|
||||
protected static final Map<CosmeticSlot, BiFunction<String, ConfigurationNode, Cosmetic>> MAPPINGS = Map.ofEntries(
|
||||
Map.entry(CosmeticSlot.HELMET, CosmeticArmorType::new),
|
||||
Map.entry(CosmeticSlot.CHESTPLATE, CosmeticArmorType::new),
|
||||
Map.entry(CosmeticSlot.LEGGINGS, CosmeticArmorType::new),
|
||||
Map.entry(CosmeticSlot.BOOTS, CosmeticArmorType::new),
|
||||
Map.entry(CosmeticSlot.OFFHAND, CosmeticArmorType::new),
|
||||
|
||||
Map.entry(CosmeticSlot.MAINHAND, CosmeticMainhandType::new),
|
||||
|
||||
Map.entry(CosmeticSlot.BACKPACK, CosmeticBackpackType::new),
|
||||
|
||||
Map.entry(CosmeticSlot.BALLOON, CosmeticBalloonType::new)
|
||||
);
|
||||
|
||||
private static final String EXCEPTION_MESSAGE = "Unknown slot %s provided for mapping, if you registered your own CosmeticSlot please ensure that you've also registered a custom CosmeticProvider! Or if you have already registered a custom CosmeticProvider ensure it is registered in your plugins `onLoad` method instead of `onEnable`!";
|
||||
|
||||
/**
|
||||
* Construct the {@link Cosmetic}.
|
||||
* @param id the cosmetic id
|
||||
* @param config the configuration node of the cosmetic
|
||||
* @param slot the occupying slot of the cosmetic
|
||||
* @return the {@link Cosmetic}
|
||||
* @throws IllegalArgumentException if the provided cosmetic could not be mapped
|
||||
*/
|
||||
public @NotNull Cosmetic createCosmetic(String id, ConfigurationNode config, CosmeticSlot slot) throws IllegalArgumentException {
|
||||
final var mapper = MAPPINGS.get(slot);
|
||||
if(mapper == null) {
|
||||
throw new IllegalArgumentException(
|
||||
EXCEPTION_MESSAGE.formatted(slot)
|
||||
);
|
||||
}
|
||||
|
||||
return mapper.apply(id, config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the plugin that is providing this {@link CosmeticProvider}
|
||||
* @return the plugin
|
||||
*/
|
||||
public abstract Plugin getProviderPlugin();
|
||||
|
||||
/**
|
||||
* Default Implementation.
|
||||
*/
|
||||
static class Default extends CosmeticProvider {
|
||||
public static final CosmeticProvider INSTANCE = new Default();
|
||||
|
||||
@Override
|
||||
public Plugin getProviderPlugin() {
|
||||
return HMCCosmeticsPlugin.getInstance();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,81 @@
|
||||
package com.hibiscusmc.hmccosmetics.cosmetic;
|
||||
|
||||
public enum CosmeticSlot {
|
||||
HELMET,
|
||||
CHESTPLATE,
|
||||
LEGGINGS,
|
||||
BOOTS,
|
||||
MAINHAND,
|
||||
OFFHAND,
|
||||
BACKPACK,
|
||||
BALLOON,
|
||||
EMOTE
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Getter
|
||||
public class CosmeticSlot {
|
||||
private static final ConcurrentHashMap<String, CosmeticSlot> REGISTRY = new ConcurrentHashMap<>();
|
||||
|
||||
public static final CosmeticSlot HELMET = register("HELMET");
|
||||
public static final CosmeticSlot CHESTPLATE = register("CHESTPLATE");
|
||||
public static final CosmeticSlot LEGGINGS = register("LEGGINGS");
|
||||
public static final CosmeticSlot BOOTS = register("BOOTS");
|
||||
public static final CosmeticSlot MAINHAND = register("MAINHAND");
|
||||
public static final CosmeticSlot OFFHAND = register("OFFHAND");
|
||||
public static final CosmeticSlot BACKPACK = register("BACKPACK");
|
||||
public static final CosmeticSlot BALLOON = register("BALLOON");
|
||||
|
||||
private final String name;
|
||||
|
||||
private CosmeticSlot(@NotNull String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new slot with the given name. If a slot with the given name already exists, it will be returned.
|
||||
* @param name The name of the slot (This will automatically be converted into all UPPERCASE)
|
||||
* @return The slot that was registered or already exists.
|
||||
* @throws IllegalArgumentException if a cosmetic slot by that name has already been registered
|
||||
*/
|
||||
@NotNull
|
||||
public static CosmeticSlot register(@NotNull String name) {
|
||||
final String upperName = name.toUpperCase();
|
||||
if(REGISTRY.containsKey(upperName)) {
|
||||
throw new IllegalArgumentException("A cosmetic slot with name '" + name + "' is already registered.");
|
||||
}
|
||||
|
||||
final CosmeticSlot slot = new CosmeticSlot(upperName);
|
||||
REGISTRY.put(upperName, slot);
|
||||
return slot;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return An unmodifiable map of all the slots that have been registered.
|
||||
*/
|
||||
@NotNull
|
||||
public static Map<String, CosmeticSlot> values() {
|
||||
return Collections.unmodifiableMap(REGISTRY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the slot with the given name.
|
||||
* @param name The name of the slot to get. This is automatically converted to all UPPERCASE.
|
||||
* @return The slot with the given name, or null if it does not exist.
|
||||
*/
|
||||
@Nullable
|
||||
public static CosmeticSlot valueOf(@NotNull String name) {
|
||||
final String upperName = name.toUpperCase();
|
||||
return REGISTRY.get(upperName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the registry contains a slot with the given name.
|
||||
* @param name The name of the slot to check for. This is automatically converted to all UPPERCASE.
|
||||
* @return True if the slot exists, false otherwise.
|
||||
*/
|
||||
public static boolean contains(@NotNull String name) {
|
||||
final String upperName = name.toUpperCase();
|
||||
return REGISTRY.containsKey(upperName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,17 +2,15 @@ package com.hibiscusmc.hmccosmetics.cosmetic;
|
||||
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.*;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import org.apache.commons.lang3.EnumUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.lojosho.shaded.configurate.CommentedConfigurationNode;
|
||||
import me.lojosho.shaded.configurate.ConfigurateException;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import me.lojosho.shaded.configurate.yaml.YamlConfigurationLoader;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
@@ -21,10 +19,12 @@ import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Slf4j
|
||||
public class Cosmetics {
|
||||
|
||||
private static final HashBiMap<String, Cosmetic> COSMETICS = HashBiMap.create();
|
||||
|
||||
private static CosmeticProvider PROVIDER = CosmeticProvider.Default.INSTANCE;
|
||||
|
||||
public static void addCosmetic(Cosmetic cosmetic) {
|
||||
COSMETICS.put(cosmetic.getId(), cosmetic);
|
||||
}
|
||||
@@ -34,7 +34,7 @@ public class Cosmetics {
|
||||
}
|
||||
|
||||
public static void removeCosmetic(Cosmetic cosmetic) {
|
||||
COSMETICS.remove(cosmetic);
|
||||
COSMETICS.remove(cosmetic.getId());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -91,29 +91,51 @@ public class Cosmetics {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a custom {@link CosmeticProvider} to provide your own user implementation to
|
||||
* be used and queried.
|
||||
* @param provider the provider to register
|
||||
* @throws IllegalArgumentException if the provider is already registered by another plugin
|
||||
*/
|
||||
public static void registerProvider(final CosmeticProvider provider) {
|
||||
if(PROVIDER != CosmeticProvider.Default.INSTANCE) {
|
||||
throw new IllegalArgumentException("CosmeticProvider already registered by %s, this conflicts with %s attempting to register their own.".formatted(
|
||||
PROVIDER.getProviderPlugin().getName(),
|
||||
provider.getProviderPlugin().getName()
|
||||
));
|
||||
}
|
||||
|
||||
PROVIDER = provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the current {@link CosmeticProvider} being used.
|
||||
* @return the current {@link CosmeticProvider} being used
|
||||
*/
|
||||
public static CosmeticProvider getProvider() {
|
||||
return PROVIDER;
|
||||
}
|
||||
|
||||
private static void setupCosmetics(@NotNull CommentedConfigurationNode config) {
|
||||
for (ConfigurationNode cosmeticConfig : config.childrenMap().values()) {
|
||||
String id = cosmeticConfig.key().toString();
|
||||
MessagesUtil.sendDebugMessages("Attempting to add " + id);
|
||||
ConfigurationNode slotNode = cosmeticConfig.node("slot");
|
||||
if (slotNode.virtual()) {
|
||||
MessagesUtil.sendDebugMessages("Unable to create " + id + " because there is no slot defined!", Level.WARNING);
|
||||
continue;
|
||||
}
|
||||
String slot = slotNode.getString("");
|
||||
CosmeticSlot cosmeticSlot = CosmeticSlot.valueOf(slot);
|
||||
if (cosmeticSlot == null) {
|
||||
MessagesUtil.sendDebugMessages("Unable to create " + id + " because " + slotNode.getString() + " is not a valid slot!", Level.WARNING);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
String id = cosmeticConfig.key().toString();
|
||||
MessagesUtil.sendDebugMessages("Attempting to add " + id);
|
||||
ConfigurationNode slotNode = cosmeticConfig.node("slot");
|
||||
if (slotNode.virtual()) {
|
||||
MessagesUtil.sendDebugMessages("Unable to create " + id + " because there is no slot defined!", Level.WARNING);
|
||||
continue;
|
||||
}
|
||||
if (!EnumUtils.isValidEnum(CosmeticSlot.class, slotNode.getString())) {
|
||||
MessagesUtil.sendDebugMessages("Unable to create " + id + " because " + slotNode.getString() + " is not a valid slot!", Level.WARNING);
|
||||
continue;
|
||||
}
|
||||
switch (CosmeticSlot.valueOf(cosmeticConfig.node("slot").getString())) {
|
||||
case BALLOON -> new CosmeticBalloonType(id, cosmeticConfig);
|
||||
case BACKPACK -> new CosmeticBackpackType(id, cosmeticConfig);
|
||||
case MAINHAND -> new CosmeticMainhandType(id, cosmeticConfig);
|
||||
case EMOTE -> new CosmeticEmoteType(id, cosmeticConfig);
|
||||
default -> new CosmeticArmorType(id, cosmeticConfig);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (Settings.isDebugMode()) e.printStackTrace();
|
||||
addCosmetic(PROVIDER.createCosmetic(id, cosmeticConfig, cosmeticSlot));
|
||||
} catch(Exception ex) {
|
||||
log.error("Unable to construct cosmetic for {}, skipping processing it.", id, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,17 +2,18 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
|
||||
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
public class CosmeticArmorType extends Cosmetic {
|
||||
|
||||
@@ -21,24 +22,42 @@ public class CosmeticArmorType extends Cosmetic {
|
||||
public CosmeticArmorType(String id, ConfigurationNode config) {
|
||||
super(id, config);
|
||||
|
||||
this.equipSlot = InventoryUtils.getEquipmentSlot(getSlot());
|
||||
EquipmentSlot slot = HMCCInventoryUtils.getEquipmentSlot(getSlot());
|
||||
if (slot == null) {
|
||||
// Hypothetically it shouldn't be null, but it was happening on some random servers? Adding this just in case
|
||||
throw new IllegalArgumentException("Invalid slot for cosmetic armor type: " + getSlot() + " in " + id + " cosmetic config.");
|
||||
}
|
||||
this.equipSlot = slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(@NotNull CosmeticUser user) {
|
||||
protected void doUpdate(@NotNull CosmeticUser user) {
|
||||
if (user.isInWardrobe()) return;
|
||||
Entity entity = Bukkit.getEntity(user.getUniqueId());
|
||||
if (entity == null) return;
|
||||
if (user.getUserEmoteManager().isPlayingEmote()) return; // There has to be a better way of doing this...
|
||||
ItemStack cosmeticItem = user.getUserCosmeticItem(this);
|
||||
if (!(entity instanceof HumanEntity humanEntity)) return;
|
||||
ItemStack equippedItem = humanEntity.getInventory().getItem(equipSlot);
|
||||
if (Settings.getShouldAddEnchants(equipSlot)) {
|
||||
cosmeticItem.addUnsafeEnchantments(equippedItem.getEnchantments());
|
||||
if (Settings.getSlotOption(equipSlot).isRequireEmpty() && entity instanceof HumanEntity humanEntity) {
|
||||
if (!humanEntity.getInventory().getItem(equipSlot).getType().isAir()) return;
|
||||
}
|
||||
|
||||
NMSHandlers.getHandler().equipmentSlotUpdate(entity.getEntityId(), equipSlot, cosmeticItem, PacketManager.getViewers(entity.getLocation()));
|
||||
ItemStack item = getItem(user);
|
||||
if (item == null) return;
|
||||
PacketManager.equipmentSlotUpdate(entity.getEntityId(), equipSlot, item, HMCCPacketManager.getViewers(entity.getLocation()));
|
||||
}
|
||||
|
||||
public ItemStack getItem(@NotNull CosmeticUser user) {
|
||||
return getItem(user, user.getUserCosmeticItem(this));
|
||||
}
|
||||
|
||||
public ItemStack getItem(@NotNull CosmeticUser user, ItemStack cosmeticItem) {
|
||||
if (!(user.getEntity() instanceof HumanEntity humanEntity)) return null;
|
||||
if (Settings.getSlotOption(equipSlot).isAddEnchantments()) {
|
||||
ItemStack equippedItem = humanEntity.getInventory().getItem(equipSlot);
|
||||
cosmeticItem.addUnsafeEnchantments(equippedItem.getEnchantments());
|
||||
}
|
||||
// Basically, if force offhand is off AND there is no item in an offhand slot, then the equipment packet to add the cosmetic
|
||||
return cosmeticItem;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public EquipmentSlot getEquipSlot() {
|
||||
return this.equipSlot;
|
||||
}
|
||||
|
||||
@@ -2,11 +2,14 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserBackpackManager;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserEntity;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
|
||||
import lombok.Getter;
|
||||
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -15,7 +18,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -24,8 +26,6 @@ import java.util.logging.Level;
|
||||
|
||||
public class CosmeticBackpackType extends Cosmetic {
|
||||
|
||||
@Getter
|
||||
private final String modelName;
|
||||
@Getter
|
||||
private int height = -1;
|
||||
private ItemStack firstPersonBackpack;
|
||||
@@ -33,8 +33,6 @@ public class CosmeticBackpackType extends Cosmetic {
|
||||
public CosmeticBackpackType(String id, ConfigurationNode config) {
|
||||
super(id, config);
|
||||
|
||||
modelName = config.node("model").getString();
|
||||
|
||||
if (!config.node("firstperson-item").virtual()) {
|
||||
this.firstPersonBackpack = generateItemStack(config.node("firstperson-item"));
|
||||
this.height = config.node("height").getInt(5);
|
||||
@@ -42,47 +40,57 @@ public class CosmeticBackpackType extends Cosmetic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(@NotNull CosmeticUser user) {
|
||||
Entity entity = Bukkit.getEntity(user.getUniqueId());
|
||||
protected void doUpdate(@NotNull CosmeticUser user) {
|
||||
Entity entity = user.getEntity();
|
||||
if (entity == null) return;
|
||||
|
||||
Location loc = entity.getLocation().clone().add(0, 2, 0);
|
||||
Location entityLocation = entity.getLocation();
|
||||
Location loc = entityLocation.clone().add(0, 2, 0);
|
||||
|
||||
if (user.isInWardrobe() || !user.isBackpackSpawned()) return;
|
||||
// This needs to be moved to purely packet based, there are far to many plugin doing dumb stuff that prevents spawning armorstands ignoring our spawn reason.
|
||||
List<Player> outsideViewers = user.getUserBackpackManager().getEntityManager().refreshViewers(loc);
|
||||
if (user.isHidden()) {
|
||||
// Sometimes the backpack is not despawned when the player is hidden (weird ass logic happening somewhere)
|
||||
user.despawnBackpack();
|
||||
return;
|
||||
}
|
||||
|
||||
user.getUserBackpackManager().getEntityManager().teleport(loc);
|
||||
user.getUserBackpackManager().getEntityManager().setRotation((int) loc.getYaw(), isFirstPersonCompadible());
|
||||
UserBackpackManager backpackManager = user.getUserBackpackManager();
|
||||
UserEntity entityManager = backpackManager.getEntityManager();
|
||||
int firstArmorStandId = backpackManager.getFirstArmorStandId();
|
||||
|
||||
PacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), user.getUserBackpackManager().getFirstArmorStandId(), EntityType.ARMOR_STAND, UUID.randomUUID(), outsideViewers);
|
||||
PacketManager.sendArmorstandMetadata(user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
|
||||
NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(this, getItem()), outsideViewers);
|
||||
List<Player> outsideViewers = entityManager.refreshViewers(loc);
|
||||
|
||||
entityManager.teleport(loc);
|
||||
entityManager.setRotation((int) loc.getYaw(), isFirstPersonCompadible());
|
||||
|
||||
HMCCPacketManager.sendEntitySpawnPacket(entityLocation, firstArmorStandId, EntityType.ARMOR_STAND, UUID.randomUUID(), outsideViewers);
|
||||
HMCCPacketManager.sendArmorstandMetadata(firstArmorStandId, outsideViewers);
|
||||
PacketManager.equipmentSlotUpdate(firstArmorStandId, EquipmentSlot.HEAD, user.getUserCosmeticItem(this, getItem()), outsideViewers);
|
||||
// If true, it will send the riding packet to all players. If false, it will send the riding packet only to new players
|
||||
if (Settings.isBackpackForceRidingEnabled()) PacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), user.getUserBackpackManager().getEntityManager().getViewers());
|
||||
else PacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
|
||||
if (Settings.isBackpackForceRidingEnabled()) HMCCPacketManager.sendRidingPacket(entity.getEntityId(), firstArmorStandId, entityManager.getViewers());
|
||||
else HMCCPacketManager.sendRidingPacket(entity.getEntityId(), firstArmorStandId, outsideViewers);
|
||||
|
||||
if (!user.isInWardrobe() && isFirstPersonCompadible() && user.getPlayer() != null) {
|
||||
List<Player> owner = List.of(user.getPlayer());
|
||||
|
||||
ArrayList<Integer> particleCloud = user.getUserBackpackManager().getAreaEffectEntityId();
|
||||
ArrayList<Integer> particleCloud = backpackManager.getAreaEffectEntityId();
|
||||
for (int i = 0; i < particleCloud.size(); i++) {
|
||||
if (i == 0) {
|
||||
PacketManager.sendRidingPacket(entity.getEntityId(), particleCloud.get(i), owner);
|
||||
HMCCPacketManager.sendRidingPacket(entity.getEntityId(), particleCloud.get(i), owner);
|
||||
} else {
|
||||
PacketManager.sendRidingPacket(particleCloud.get(i - 1), particleCloud.get(i) , owner);
|
||||
HMCCPacketManager.sendRidingPacket(particleCloud.get(i - 1), particleCloud.get(i) , owner);
|
||||
}
|
||||
}
|
||||
PacketManager.sendRidingPacket(particleCloud.get(particleCloud.size() - 1), user.getUserBackpackManager().getFirstArmorStandId(), owner);
|
||||
if (!user.getHidden()) {
|
||||
HMCCPacketManager.sendRidingPacket(particleCloud.get(particleCloud.size() - 1), firstArmorStandId, owner);
|
||||
if (!user.isHidden()) {
|
||||
//if (loc.getPitch() < -70) NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, new ItemStack(Material.AIR), owner);
|
||||
//else NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, firstPersonBackpack, owner);
|
||||
NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(this, firstPersonBackpack), owner);
|
||||
PacketManager.equipmentSlotUpdate(firstArmorStandId, EquipmentSlot.HEAD, user.getUserCosmeticItem(this, firstPersonBackpack), owner);
|
||||
}
|
||||
MessagesUtil.sendDebugMessages("First Person Backpack Update[owner=" + user.getUniqueId() + ",player_location=" + loc + "]!", Level.INFO);
|
||||
//MessagesUtil.sendDebugMessages("First Person Backpack Update[owner=" + user.getUniqueId() + ",player_location=" + loc + "]!", Level.INFO);
|
||||
}
|
||||
|
||||
user.getUserBackpackManager().showBackpack();
|
||||
backpackManager.showBackpack();
|
||||
}
|
||||
|
||||
public boolean isFirstPersonCompadible() {
|
||||
|
||||
@@ -4,17 +4,17 @@ import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
|
||||
import lombok.Getter;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import me.lojosho.shaded.configurate.serialize.SerializationException;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -23,7 +23,7 @@ public class CosmeticBalloonType extends Cosmetic {
|
||||
@Getter
|
||||
private final String modelName;
|
||||
@Getter
|
||||
private List<String> dyableParts;
|
||||
private List<String> dyeableParts;
|
||||
@Getter
|
||||
private final boolean showLead;
|
||||
@Getter
|
||||
@@ -42,8 +42,8 @@ public class CosmeticBalloonType extends Cosmetic {
|
||||
balloonOffset = Settings.loadVector(balloonOffsetNode);
|
||||
|
||||
try {
|
||||
if (!config.node("dyable-parts").virtual()) {
|
||||
dyableParts = config.node("dyable-parts").getList(String.class);
|
||||
if (!config.node("dyeable-parts").virtual()) {
|
||||
dyeableParts = config.node("dyeable-parts").getList(String.class);
|
||||
}
|
||||
} catch (SerializationException e) {
|
||||
// Seriously?
|
||||
@@ -54,7 +54,7 @@ public class CosmeticBalloonType extends Cosmetic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(@NotNull CosmeticUser user) {
|
||||
protected void doUpdate(@NotNull CosmeticUser user) {
|
||||
Entity entity = Bukkit.getEntity(user.getUniqueId());
|
||||
UserBalloonManager userBalloonManager = user.getBalloonManager();
|
||||
|
||||
@@ -69,37 +69,42 @@ public class CosmeticBalloonType extends Cosmetic {
|
||||
Location newLocation = entity.getLocation();
|
||||
Location currentLocation = user.getBalloonManager().getLocation();
|
||||
newLocation = newLocation.clone().add(getBalloonOffset());
|
||||
if (Settings.isBalloonHeadForward()) newLocation.setPitch(0);
|
||||
|
||||
List<Player> viewer = PacketManager.getViewers(entity.getLocation());
|
||||
List<Player> viewer = HMCCPacketManager.getViewers(entity.getLocation());
|
||||
|
||||
if (entity.getLocation().getWorld() != userBalloonManager.getLocation().getWorld()) {
|
||||
userBalloonManager.getModelEntity().teleport(newLocation);
|
||||
PacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer);
|
||||
HMCCPacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer);
|
||||
return;
|
||||
}
|
||||
|
||||
Vector velocity = newLocation.toVector().subtract(currentLocation.toVector());
|
||||
userBalloonManager.setVelocity(velocity.multiply(1.1));
|
||||
userBalloonManager.setLocation(newLocation);
|
||||
userBalloonManager.setVelocity(velocity.multiply(1.1));
|
||||
|
||||
PacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer);
|
||||
PacketManager.sendLeashPacket(userBalloonManager.getPufferfishBalloonId(), entity.getEntityId(), viewer);
|
||||
if (user.getHidden()) {
|
||||
MessagesUtil.sendDebugMessages("Balloon Cosmetic Update for " + user.getEntity().getName());
|
||||
MessagesUtil.sendDebugMessages("Ballon previous location is " + currentLocation);
|
||||
MessagesUtil.sendDebugMessages("Balloon location set to " + newLocation);
|
||||
MessagesUtil.sendDebugMessages("Balloon velocity set to " + velocity);
|
||||
|
||||
HMCCPacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer);
|
||||
HMCCPacketManager.sendLeashPacket(userBalloonManager.getPufferfishBalloonId(), entity.getEntityId(), viewer);
|
||||
if (user.isHidden()) {
|
||||
userBalloonManager.getPufferfish().hidePufferfish();
|
||||
return;
|
||||
}
|
||||
if (!user.getHidden() && showLead) {
|
||||
if (!user.isHidden() && showLead) {
|
||||
List<Player> sendTo = userBalloonManager.getPufferfish().refreshViewers(newLocation);
|
||||
if (sendTo.isEmpty()) return;
|
||||
PacketManager.sendEntitySpawnPacket(newLocation, userBalloonManager.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager.getPufferfishBalloonUniqueId(), sendTo);
|
||||
PacketManager.sendInvisibilityPacket(userBalloonManager.getPufferfishBalloonId(), sendTo);
|
||||
user.getBalloonManager().getPufferfish().spawnPufferfish(newLocation, sendTo);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDyablePart(String name) {
|
||||
public boolean isDyeablePart(String name) {
|
||||
// If player does not define parts, dye whole model
|
||||
if (dyableParts == null) return true;
|
||||
if (dyableParts.isEmpty()) return true;
|
||||
return dyableParts.contains(name);
|
||||
if (dyeableParts == null) return true;
|
||||
if (dyeableParts.isEmpty()) return true;
|
||||
return dyeableParts.contains(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.cosmetic.types;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
public class CosmeticEmoteType extends Cosmetic {
|
||||
|
||||
private final String animationId;
|
||||
private final String text;
|
||||
|
||||
public CosmeticEmoteType(String id, ConfigurationNode config) {
|
||||
super(id, config);
|
||||
|
||||
animationId = config.node("animation").getString();
|
||||
text = config.node("text").getString();
|
||||
MessagesUtil.sendDebugMessages("CosmeticEmoteType Animation id " + animationId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(CosmeticUser user) {
|
||||
// Nothing
|
||||
}
|
||||
|
||||
public void run(@NotNull CosmeticUser user) {
|
||||
user.getUserEmoteManager().playEmote(this);
|
||||
}
|
||||
|
||||
public String getAnimationId() {
|
||||
return animationId;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,11 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||
import com.hibiscusmc.hmccosmetics.util.HMCCPlayerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
public class CosmeticMainhandType extends Cosmetic {
|
||||
|
||||
@@ -15,9 +15,9 @@ public class CosmeticMainhandType extends Cosmetic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(@NotNull CosmeticUser user) {
|
||||
protected void doUpdate(@NotNull CosmeticUser user) {
|
||||
Player player = user.getPlayer();
|
||||
|
||||
PacketManager.equipmentSlotUpdate(player.getEntityId(), user, getSlot(), PlayerUtils.getNearbyPlayers(player));
|
||||
HMCCPacketManager.equipmentSlotUpdate(player.getEntityId(), user, getSlot(), HMCCPacketManager.getViewers(player.getLocation()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.hibiscusmc.hmccosmetics.database;
|
||||
import com.hibiscusmc.hmccosmetics.config.DatabaseSettings;
|
||||
import com.hibiscusmc.hmccosmetics.database.types.Data;
|
||||
import com.hibiscusmc.hmccosmetics.database.types.MySQLData;
|
||||
import com.hibiscusmc.hmccosmetics.database.types.NoneData;
|
||||
import com.hibiscusmc.hmccosmetics.database.types.SQLiteData;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
@@ -11,6 +12,8 @@ import lombok.Getter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Database {
|
||||
|
||||
@@ -18,18 +21,25 @@ public class Database {
|
||||
private static Data data;
|
||||
private static final MySQLData MYSQL_DATA = new MySQLData();
|
||||
private static final SQLiteData SQLITE_DATA = new SQLiteData();
|
||||
private static final NoneData NONE_DATA = new NoneData();
|
||||
|
||||
public Database() {
|
||||
String databaseType = DatabaseSettings.getDatabaseType();
|
||||
data = SQLITE_DATA; // default
|
||||
if (databaseType.equalsIgnoreCase("MySQL")) {
|
||||
data = MYSQL_DATA;
|
||||
data = SQLITE_DATA; // default to SQLite, then check if it's anything different
|
||||
switch (databaseType.toLowerCase()) {
|
||||
case "mysql":
|
||||
data = MYSQL_DATA;
|
||||
break;
|
||||
case "sqlite":
|
||||
// already the default
|
||||
break;
|
||||
case "none":
|
||||
data = NONE_DATA;
|
||||
MessagesUtil.sendDebugMessages("Database is set to none. Data will not be saved.", Level.WARNING);
|
||||
break;
|
||||
default:
|
||||
MessagesUtil.sendDebugMessages("Invalid database type. Defaulting to SQLite.", Level.WARNING);
|
||||
}
|
||||
/* SQLite is the default database. Might change in the future, so keep code here in case.
|
||||
if (databaseType.equalsIgnoreCase("sqlite")) {
|
||||
data = SQLITE_DATA;
|
||||
}
|
||||
*/
|
||||
MessagesUtil.sendDebugMessages("Database is " + data);
|
||||
|
||||
setup();
|
||||
@@ -47,7 +57,7 @@ public class Database {
|
||||
data.save(CosmeticUsers.getUser(player));
|
||||
}
|
||||
|
||||
public static CosmeticUser get(UUID uniqueId) {
|
||||
public static CompletableFuture<UserData> get(UUID uniqueId) {
|
||||
return data.get(uniqueId);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.hibiscusmc.hmccosmetics.database;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UserData {
|
||||
|
||||
@Getter
|
||||
private UUID owner;
|
||||
@Setter
|
||||
@Getter
|
||||
private HashMap<CosmeticSlot, Map.Entry<Cosmetic, Integer>> cosmetics;
|
||||
@Getter
|
||||
private ArrayList<CosmeticUser.HiddenReason> hiddenReasons;
|
||||
|
||||
public UserData(UUID owner) {
|
||||
this.owner = owner;
|
||||
this.cosmetics = new HashMap<>();
|
||||
this.hiddenReasons = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addCosmetic(CosmeticSlot slot, Cosmetic cosmetic, Integer color) {
|
||||
cosmetics.put(slot, Map.entry(cosmetic, color));
|
||||
}
|
||||
|
||||
public void addHiddenReason(CosmeticUser.HiddenReason reason) {
|
||||
hiddenReasons.add(reason);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||
import com.hibiscusmc.hmccosmetics.database.UserData;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import org.apache.commons.lang3.EnumUtils;
|
||||
@@ -13,9 +14,8 @@ import org.bukkit.Color;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public abstract class Data {
|
||||
|
||||
@@ -24,7 +24,7 @@ public abstract class Data {
|
||||
public abstract void save(CosmeticUser user);
|
||||
|
||||
@Nullable
|
||||
public abstract CosmeticUser get(UUID uniqueId);
|
||||
public abstract CompletableFuture<UserData> get(UUID uniqueId);
|
||||
|
||||
public abstract void clear(UUID uniqueId);
|
||||
|
||||
@@ -32,9 +32,9 @@ public abstract class Data {
|
||||
@NotNull
|
||||
public final String serializeData(@NotNull CosmeticUser user) {
|
||||
StringBuilder data = new StringBuilder();
|
||||
if (user.getHidden()) {
|
||||
if (shouldHiddenSave(user.getHiddenReason())) {
|
||||
data.append("HIDDEN=").append(user.getHiddenReason());
|
||||
if (user.isHidden()) {
|
||||
for (CosmeticUser.HiddenReason reason : user.getHiddenReasons()) {
|
||||
if (shouldHiddenSave(reason)) data.append("HIDDEN=").append(reason);
|
||||
}
|
||||
}
|
||||
for (Cosmetic cosmetic : user.getCosmetics()) {
|
||||
@@ -50,15 +50,12 @@ public abstract class Data {
|
||||
return data.toString();
|
||||
}
|
||||
|
||||
public final Map<CosmeticSlot, Map<Cosmetic, Color>> deserializeData(CosmeticUser user, @NotNull String raw) {
|
||||
return deserializeData(user, raw, Settings.isForcePermissionJoin());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public final Map<CosmeticSlot, Map<Cosmetic, Color>> deserializeData(CosmeticUser user, @NotNull String raw, boolean permissionCheck) {
|
||||
Map<CosmeticSlot, Map<Cosmetic, Color>> cosmetics = new HashMap<>();
|
||||
public final HashMap<CosmeticSlot, Map.Entry<Cosmetic, Integer>> deserializeData(@NotNull String raw) {
|
||||
HashMap<CosmeticSlot, Map.Entry<Cosmetic, Integer>> cosmetics = new HashMap<>();
|
||||
|
||||
String[] rawData = raw.split(",");
|
||||
ArrayList<CosmeticUser.HiddenReason> hiddenReason = new ArrayList<>();
|
||||
for (String a : rawData) {
|
||||
if (a == null || a.isEmpty()) continue;
|
||||
String[] splitData = a.split("=");
|
||||
@@ -68,9 +65,7 @@ public abstract class Data {
|
||||
if (splitData[0].equalsIgnoreCase("HIDDEN")) {
|
||||
if (EnumUtils.isValidEnum(CosmeticUser.HiddenReason.class, splitData[1])) {
|
||||
if (Settings.isForceShowOnJoin()) continue;
|
||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
user.hideCosmetics(CosmeticUser.HiddenReason.valueOf(splitData[1]));
|
||||
});
|
||||
hiddenReason.add(CosmeticUser.HiddenReason.valueOf(splitData[1]));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -79,31 +74,20 @@ public abstract class Data {
|
||||
String[] colorSplitData = splitData[1].split("&");
|
||||
if (Cosmetics.hasCosmetic(colorSplitData[0])) cosmetic = Cosmetics.getCosmetic(colorSplitData[0]);
|
||||
if (slot == null || cosmetic == null) continue;
|
||||
if (permissionCheck && cosmetic.requiresPermission()) {
|
||||
if (user.getPlayer() != null && !user.getPlayer().hasPermission(cosmetic.getPermission())) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
cosmetics.put(slot, Map.of(cosmetic, Color.fromRGB(Integer.parseInt(colorSplitData[1]))));
|
||||
cosmetics.put(slot, Map.entry(cosmetic, Integer.parseInt(colorSplitData[1])));
|
||||
} else {
|
||||
if (Cosmetics.hasCosmetic(splitData[1])) cosmetic = Cosmetics.getCosmetic(splitData[1]);
|
||||
if (slot == null || cosmetic == null) continue;
|
||||
if (permissionCheck && cosmetic.requiresPermission()) {
|
||||
if (user.getPlayer() != null && !user.getPlayer().hasPermission(cosmetic.getPermission())) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
HashMap<Cosmetic, Color> cosmeticColorHashMap = new HashMap<>();
|
||||
cosmeticColorHashMap.put(cosmetic, null);
|
||||
cosmetics.put(slot, cosmeticColorHashMap);
|
||||
cosmetics.put(slot, Map.entry(cosmetic, -1));
|
||||
}
|
||||
}
|
||||
|
||||
return cosmetics;
|
||||
}
|
||||
|
||||
private boolean shouldHiddenSave(CosmeticUser.HiddenReason reason) {
|
||||
switch (reason) {
|
||||
case EMOTE, NONE -> {
|
||||
case EMOTE, NONE, GAMEMODE, WORLD, DISABLED -> {
|
||||
return false;
|
||||
}
|
||||
default -> {
|
||||
|
||||
@@ -13,6 +13,7 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class MySQLData extends SQLData {
|
||||
|
||||
@@ -38,10 +39,12 @@ public class MySQLData extends SQLData {
|
||||
try {
|
||||
openConnection();
|
||||
if (connection == null) throw new NullPointerException("Connection is null");
|
||||
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " +
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " +
|
||||
"(UUID varchar(36) PRIMARY KEY, " +
|
||||
"COSMETICS MEDIUMTEXT " +
|
||||
");").execute();
|
||||
");")) {
|
||||
preparedStatement.execute();
|
||||
}
|
||||
} catch (SQLException | NullPointerException e) {
|
||||
plugin.getLogger().severe("");
|
||||
plugin.getLogger().severe("");
|
||||
@@ -59,8 +62,7 @@ public class MySQLData extends SQLData {
|
||||
@Override
|
||||
public void clear(UUID uniqueId) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
try {
|
||||
PreparedStatement preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;");
|
||||
try (PreparedStatement preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;")) {
|
||||
preparedSt.setString(1, uniqueId.toString());
|
||||
preparedSt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
@@ -127,7 +129,14 @@ public class MySQLData extends SQLData {
|
||||
public PreparedStatement preparedStatement(String query) {
|
||||
PreparedStatement ps = null;
|
||||
|
||||
if (!isConnectionOpen()) MessagesUtil.sendDebugMessages("Connection is not open");
|
||||
if (!isConnectionOpen()) {
|
||||
MessagesUtil.sendDebugMessages("The MySQL database connection is not open (Could the database been idle for to long?). Reconnecting...", Level.WARNING);
|
||||
try {
|
||||
openConnection();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (connection == null) throw new NullPointerException("Connection is null");
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.hibiscusmc.hmccosmetics.database.types;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.database.UserData;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class NoneData extends Data {
|
||||
@Override
|
||||
public void setup() {
|
||||
// Nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(CosmeticUser user) {
|
||||
// Nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable CompletableFuture<UserData> get(UUID uniqueId) {
|
||||
return CompletableFuture.completedFuture(new UserData(uniqueId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear(UUID uniqueId) {
|
||||
// Nothing
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.hibiscusmc.hmccosmetics.database.types;
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.database.UserData;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
@@ -10,46 +11,39 @@ import org.bukkit.Color;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public abstract class SQLData extends Data {
|
||||
@Override
|
||||
@SuppressWarnings({"resource"}) // Duplicate is from deprecated InternalData
|
||||
public CosmeticUser get(UUID uniqueId) {
|
||||
CosmeticUser user = new CosmeticUser(uniqueId);
|
||||
public CompletableFuture<UserData> get(UUID uniqueId) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
UserData data = new UserData(uniqueId);
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
try {
|
||||
PreparedStatement preparedStatement = preparedStatement("SELECT * FROM COSMETICDATABASE WHERE UUID = ?;");
|
||||
try (PreparedStatement preparedStatement = preparedStatement("SELECT * FROM COSMETICDATABASE WHERE UUID = ?;")){
|
||||
preparedStatement.setString(1, uniqueId.toString());
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
if (rs.next()) {
|
||||
String rawData = rs.getString("COSMETICS");
|
||||
Map<CosmeticSlot, Map<Cosmetic, Color>> cosmetics = deserializeData(user, rawData);
|
||||
for (Map<Cosmetic, Color> cosmeticColors : cosmetics.values()) {
|
||||
for (Cosmetic cosmetic : cosmeticColors.keySet()) {
|
||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
// This can not be async.
|
||||
user.addPlayerCosmetic(cosmetic, cosmeticColors.get(cosmetic));
|
||||
});
|
||||
}
|
||||
try (ResultSet rs = preparedStatement.executeQuery()) {
|
||||
if (rs.next()) {
|
||||
String rawData = rs.getString("COSMETICS");
|
||||
HashMap<CosmeticSlot, Map.Entry<Cosmetic, Integer>> cosmetics = deserializeData(rawData);
|
||||
data.setCosmetics(cosmetics);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return data;
|
||||
});
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("resource")
|
||||
public void save(CosmeticUser user) {
|
||||
Runnable run = () -> {
|
||||
try {
|
||||
PreparedStatement preparedSt = preparedStatement("REPLACE INTO COSMETICDATABASE(UUID,COSMETICS) VALUES(?,?);");
|
||||
try (PreparedStatement preparedSt = preparedStatement("REPLACE INTO COSMETICDATABASE(UUID,COSMETICS) VALUES(?,?);")) {
|
||||
preparedSt.setString(1, user.getUniqueId().toString());
|
||||
preparedSt.setString(2, serializeData(user));
|
||||
preparedSt.executeUpdate();
|
||||
@@ -57,7 +51,7 @@ public abstract class SQLData extends Data {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
};
|
||||
if (!HMCCosmeticsPlugin.isDisable()) {
|
||||
if (!HMCCosmeticsPlugin.getInstance().isDisabled()) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), run);
|
||||
} else {
|
||||
run.run();
|
||||
|
||||
@@ -35,10 +35,12 @@ public class SQLiteData extends SQLData {
|
||||
connection = DriverManager.getConnection("jdbc:sqlite:" + dataFolder);
|
||||
|
||||
openConnection();
|
||||
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " +
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " +
|
||||
"(UUID varchar(36) PRIMARY KEY, " +
|
||||
"COSMETICS MEDIUMTEXT " +
|
||||
");").execute();
|
||||
");")) {
|
||||
preparedStatement.execute();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -48,8 +50,7 @@ public class SQLiteData extends SQLData {
|
||||
@SuppressWarnings("resource")
|
||||
public void clear(UUID uniqueId) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
try {
|
||||
PreparedStatement preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;");
|
||||
try (PreparedStatement preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;")){
|
||||
preparedSt.setString(1, uniqueId.toString());
|
||||
preparedSt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.emotes;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.ticxo.playeranimator.api.PlayerAnimator;
|
||||
import com.ticxo.playeranimator.api.animation.pack.AnimationPack;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Manages Emotes
|
||||
*/
|
||||
@SuppressWarnings("SpellCheckingInspection")
|
||||
public class EmoteManager {
|
||||
private static final @NotNull Map<String, String> emotes = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Loads all BlockBench animations from the emotes folder and puts it into the animation manager registry and local registry
|
||||
*/
|
||||
public static void loadEmotes() {
|
||||
// Clear the PlayerAnimator and local registries
|
||||
PlayerAnimator.api.getAnimationManager().clearRegistry();
|
||||
emotes.clear();
|
||||
|
||||
// Get the emote directory and check if it exists
|
||||
File emoteDir = new File(HMCCosmeticsPlugin.getInstance().getDataFolder().getPath() + "/emotes/");
|
||||
if (!emoteDir.exists()) return;
|
||||
|
||||
// Get all the files inside the directory and check if it isn't 0
|
||||
File[] emoteFiles = emoteDir.listFiles();
|
||||
if (emoteFiles == null || emoteFiles.length == 0) return;
|
||||
|
||||
// Remove any files that don't have the file extension ".bbmodel" and check if there are still resulting files
|
||||
emoteFiles = Arrays.stream(emoteFiles).filter(file -> file.getPath().endsWith(".bbmodel")).distinct().toArray(File[]::new);
|
||||
if (emoteFiles.length == 0) return;
|
||||
|
||||
// Loop through all files, importing all block bench animations into the registry
|
||||
for (File animationFile : emoteFiles) {
|
||||
String animationKey = FilenameUtils.removeExtension(animationFile.getName());
|
||||
PlayerAnimator.api.getAnimationManager().importAnimations(animationKey, animationFile);
|
||||
}
|
||||
|
||||
// Loops through all the entries in the registries and unpacks any animation packs to ensure if there were multiple animations
|
||||
// inside a singular file, that they are added to the local registry individually for tab completion
|
||||
for (Map.Entry<String, AnimationPack> packEntry : PlayerAnimator.api.getAnimationManager().getRegistry().entrySet()) {
|
||||
packEntry.getValue().getAnimations().keySet().forEach(animationName -> {
|
||||
// API key is the format "animationKey.animationFileName.animationName"
|
||||
String apiKey = packEntry.getKey().replace(":", ".") + "." + animationName;
|
||||
emotes.put(animationName, apiKey);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if there is an animation with the specified name
|
||||
* @param animationName Name whose presence is to be tested
|
||||
* @return True if this registry contains a mapping for the specified name
|
||||
*/
|
||||
public static boolean has(@NotNull String animationName) {
|
||||
return emotes.containsKey(animationName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@code API key} to which the specified name is mapped, or {@code null} if this map contains no mapping for the name.
|
||||
* @param animationName Name whose {@code API key} is to be fetched
|
||||
* @return The {@code API key} of the specified name or {@code null} if there was no animation name found
|
||||
*/
|
||||
public static @Nullable String get(@NotNull String animationName) {
|
||||
return emotes.get(animationName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a set of all the laoded animation names
|
||||
* @return A set of all loaded animation names
|
||||
*/
|
||||
public static @NotNull Set<String> getAllNames() {
|
||||
return emotes.keySet();
|
||||
}
|
||||
}
|
||||
@@ -1,35 +1,39 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerMenuCloseEvent;
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerMenuOpenEvent;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.config.serializer.ItemSerializer;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||
import com.hibiscusmc.hmccosmetics.gui.type.Type;
|
||||
import com.hibiscusmc.hmccosmetics.gui.type.Types;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
|
||||
import com.hibiscusmc.hmccosmetics.gui.type.types.TypeCosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.misc.Adventure;
|
||||
import com.hibiscusmc.hmccosmetics.util.misc.StringUtils;
|
||||
import dev.triumphteam.gui.builder.item.ItemBuilder;
|
||||
import dev.triumphteam.gui.components.GuiType;
|
||||
import dev.triumphteam.gui.components.InventoryProvider;
|
||||
import dev.triumphteam.gui.guis.Gui;
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import lombok.Getter;
|
||||
import me.lojosho.hibiscuscommons.config.serializer.ItemSerializer;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||
import me.lojosho.hibiscuscommons.util.AdventureUtils;
|
||||
import me.lojosho.hibiscuscommons.util.StringUtils;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import me.lojosho.shaded.configurate.serialize.SerializationException;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class Menu {
|
||||
@@ -41,21 +45,24 @@ public class Menu {
|
||||
@Getter
|
||||
private final int rows;
|
||||
@Getter
|
||||
private final Long cooldown;
|
||||
@Getter
|
||||
private final ConfigurationNode config;
|
||||
@Getter
|
||||
private final String permissionNode;
|
||||
private final HashMap<Integer, MenuItem> items;
|
||||
private final HashMap<Integer, List<MenuItem>> items;
|
||||
@Getter
|
||||
private final int refreshRate;
|
||||
@Getter
|
||||
private final boolean shading;
|
||||
|
||||
public Menu(String id, @NotNull ConfigurationNode config) {
|
||||
this.id = id;
|
||||
this.id = config.node("id").getString(id);
|
||||
this.config = config;
|
||||
|
||||
title = config.node("title").getString("chest");
|
||||
rows = config.node("rows").getInt(1);
|
||||
cooldown = config.node("click-cooldown").getLong(Settings.getDefaultMenuCooldown());
|
||||
permissionNode = config.node("permission").getString("");
|
||||
refreshRate = config.node("refresh-rate").getInt(-1);
|
||||
shading = config.node("shading").getBoolean(Settings.isDefaultShading());
|
||||
@@ -91,7 +98,8 @@ public class Menu {
|
||||
try {
|
||||
item = ItemSerializer.INSTANCE.deserialize(ItemStack.class, config.node("item"));
|
||||
} catch (SerializationException e) {
|
||||
throw new RuntimeException(e);
|
||||
MessagesUtil.sendDebugMessages("Unable to get valid item for " + config.key().toString() + " " + e.getMessage());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item == null) {
|
||||
@@ -99,15 +107,24 @@ public class Menu {
|
||||
continue;
|
||||
}
|
||||
|
||||
Type type = null;
|
||||
int priority = config.node("priority").getInt(1);
|
||||
|
||||
Type type = Types.getDefaultType();
|
||||
if (!config.node("type").virtual()) {
|
||||
String typeId = config.node("type").getString("");
|
||||
if (Types.isType(typeId)) type = Types.getType(typeId);
|
||||
}
|
||||
|
||||
for (Integer slot : slots) {
|
||||
items.put(slot, new MenuItem(slots, item, type, config));
|
||||
MenuItem menuItem = new MenuItem(slots, item, type, priority, config);
|
||||
if (items.containsKey(slot)) {
|
||||
List<MenuItem> menuItems = items.get(slot);
|
||||
menuItems.add(menuItem);
|
||||
menuItems.sort(priorityCompare);
|
||||
items.put(slot, menuItems);
|
||||
} else {
|
||||
items.put(slot, new ArrayList<>(List.of(menuItem)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,16 +136,25 @@ public class Menu {
|
||||
public void openMenu(@NotNull CosmeticUser user, boolean ignorePermission) {
|
||||
Player player = user.getPlayer();
|
||||
if (player == null) return;
|
||||
openMenu(player, user, ignorePermission);
|
||||
}
|
||||
|
||||
public void openMenu(@NotNull Player viewer, @NotNull CosmeticHolder cosmeticHolder) {
|
||||
openMenu(viewer, cosmeticHolder, false);
|
||||
}
|
||||
|
||||
public void openMenu(@NotNull Player viewer, @NotNull CosmeticHolder cosmeticHolder, boolean ignorePermission) {
|
||||
if (!ignorePermission && !permissionNode.isEmpty()) {
|
||||
if (!player.hasPermission(permissionNode) && !player.isOp()) {
|
||||
MessagesUtil.sendMessage(player, "no-permission");
|
||||
if (!viewer.hasPermission(permissionNode) && !viewer.isOp()) {
|
||||
MessagesUtil.sendMessage(viewer, "no-permission");
|
||||
return;
|
||||
}
|
||||
}
|
||||
final Component component = Adventure.MINI_MESSAGE.deserialize(Hooks.processPlaceholders(player, this.title));
|
||||
final Component component = AdventureUtils.MINI_MESSAGE.deserialize(Hooks.processPlaceholders(viewer, this.title));
|
||||
Gui gui = Gui.gui()
|
||||
.title(component)
|
||||
.rows(this.rows)
|
||||
.type(GuiType.CHEST)
|
||||
.inventory((title, owner, type) -> Bukkit.createInventory(owner, rows * 9, title))
|
||||
.create();
|
||||
|
||||
gui.setDefaultClickAction(event -> event.setCancelled(true));
|
||||
@@ -140,7 +166,7 @@ public class Menu {
|
||||
Bukkit.getScheduler().cancelTask(taskid.get());
|
||||
}
|
||||
|
||||
updateMenu(user, gui);
|
||||
updateMenu(viewer, cosmeticHolder, gui);
|
||||
};
|
||||
|
||||
if (refreshRate != -1) {
|
||||
@@ -151,22 +177,29 @@ public class Menu {
|
||||
});
|
||||
|
||||
gui.setCloseGuiAction(event -> {
|
||||
if (cosmeticHolder instanceof CosmeticUser user) {
|
||||
PlayerMenuCloseEvent closeEvent = new PlayerMenuCloseEvent(user, this, event.getReason());
|
||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> Bukkit.getPluginManager().callEvent(closeEvent));
|
||||
}
|
||||
|
||||
if (taskid.get() != -1) Bukkit.getScheduler().cancelTask(taskid.get());
|
||||
});
|
||||
|
||||
// API
|
||||
PlayerMenuOpenEvent event = new PlayerMenuOpenEvent(user, this);
|
||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> Bukkit.getPluginManager().callEvent(event));
|
||||
if (event.isCancelled()) return;
|
||||
if (cosmeticHolder instanceof CosmeticUser user) {
|
||||
PlayerMenuOpenEvent event = new PlayerMenuOpenEvent(user, this);
|
||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> Bukkit.getPluginManager().callEvent(event));
|
||||
if (event.isCancelled()) return;
|
||||
}
|
||||
// Internal
|
||||
|
||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
gui.open(player);
|
||||
updateMenu(user, gui); // fixes shading? I know I do this twice but it's easier than writing a whole new class to deal with this shit
|
||||
gui.open(viewer);
|
||||
updateMenu(viewer, cosmeticHolder, gui); // fixes shading? I know I do this twice but it's easier than writing a whole new class to deal with this shit
|
||||
});
|
||||
}
|
||||
|
||||
private void updateMenu(CosmeticUser user, Gui gui) {
|
||||
private void updateMenu(Player viewer, CosmeticHolder cosmeticHolder, Gui gui) {
|
||||
StringBuilder title = new StringBuilder(this.title);
|
||||
|
||||
int row = 0;
|
||||
@@ -188,16 +221,17 @@ public class Menu {
|
||||
|
||||
if (items.containsKey(i)) {
|
||||
// Handles the items
|
||||
MenuItem item = items.get(i);
|
||||
updateItem(user, gui, item);
|
||||
List<MenuItem> menuItems = items.get(i);
|
||||
MenuItem item = menuItems.get(0);
|
||||
updateItem(viewer, cosmeticHolder, gui, i);
|
||||
|
||||
if (item.type().getId().equalsIgnoreCase("cosmetic")) {
|
||||
if (item.type() instanceof TypeCosmetic) {
|
||||
Cosmetic cosmetic = Cosmetics.getCosmetic(item.itemConfig().node("cosmetic").getString(""));
|
||||
if (cosmetic == null) continue;
|
||||
if (user.hasCosmeticInSlot(cosmetic)) {
|
||||
if (cosmeticHolder.hasCosmeticInSlot(cosmetic)) {
|
||||
title.append(Settings.getEquippedCosmeticColor());
|
||||
} else {
|
||||
if (user.canEquipCosmetic(cosmetic, true)) {
|
||||
if (cosmeticHolder.canEquipCosmetic(cosmetic, true)) {
|
||||
title.append(Settings.getEquipableCosmeticColor());
|
||||
} else {
|
||||
title.append(Settings.getLockedCosmeticColor());
|
||||
@@ -213,28 +247,47 @@ public class Menu {
|
||||
}
|
||||
}
|
||||
MessagesUtil.sendDebugMessages("Updated menu with title " + title);
|
||||
gui.updateTitle(StringUtils.parseStringToString(Hooks.processPlaceholders(user.getPlayer(), title.toString())));
|
||||
gui.updateTitle(AdventureUtils.MINI_MESSAGE.deserialize(Hooks.processPlaceholders(viewer, title.toString())));
|
||||
} else {
|
||||
for (MenuItem item : items.values()) {
|
||||
updateItem(user, gui, item);
|
||||
for (int i = 0; i < gui.getInventory().getSize(); i++) {
|
||||
if (items.containsKey(i)) {
|
||||
updateItem(viewer, cosmeticHolder, gui, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateItem(CosmeticUser user, Gui gui, MenuItem item) {
|
||||
Type type = item.type();
|
||||
for (int slot : item.slots()) {
|
||||
ItemStack modifiedItem = getMenuItem(user, type, item.itemConfig(), item.item().clone(), slot);
|
||||
private void updateItem(Player viewer, CosmeticHolder cosmeticHolder, Gui gui, int slot) {
|
||||
if (!items.containsKey(slot)) return;
|
||||
List<MenuItem> menuItems = items.get(slot);
|
||||
if (menuItems.isEmpty()) return;
|
||||
|
||||
for (MenuItem item : menuItems) {
|
||||
Type type = item.type();
|
||||
ItemStack modifiedItem = getMenuItem(viewer, cosmeticHolder, type, item.itemConfig(), item.item().clone(), slot);
|
||||
if (modifiedItem.getType().isAir()) continue;
|
||||
GuiItem guiItem = ItemBuilder.from(modifiedItem).asGuiItem();
|
||||
guiItem.setAction(event -> {
|
||||
MessagesUtil.sendDebugMessages("Selected slot " + slot);
|
||||
UUID uuid = viewer.getUniqueId();
|
||||
if (Settings.isMenuClickCooldown()) {
|
||||
Long userCooldown = Menus.getCooldown(uuid);
|
||||
if (userCooldown != 0 && (System.currentTimeMillis() - Menus.getCooldown(uuid) <= getCooldown())) {
|
||||
MessagesUtil.sendDebugMessages("Cooldown for " + viewer.getUniqueId() + " System time: " + System.currentTimeMillis() + " Cooldown: " + Menus.getCooldown(viewer.getUniqueId()) + " Difference: " + (System.currentTimeMillis() - Menus.getCooldown(viewer.getUniqueId())));
|
||||
MessagesUtil.sendMessage(viewer, "on-click-cooldown");
|
||||
return;
|
||||
} else {
|
||||
Menus.addCooldown(uuid, System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
MessagesUtil.sendDebugMessages("Updated Menu Item in slot number " + slot);
|
||||
final ClickType clickType = event.getClick();
|
||||
if (type != null) type.run(user, item.itemConfig(), clickType);
|
||||
updateMenu(user, gui);
|
||||
if (type != null) type.run(viewer, cosmeticHolder, item.itemConfig(), clickType);
|
||||
updateMenu(viewer, cosmeticHolder, gui);
|
||||
});
|
||||
|
||||
MessagesUtil.sendDebugMessages("Added " + slot + " as " + guiItem + " in the menu");
|
||||
MessagesUtil.sendDebugMessages("Set an item in slot " + slot + " in the menu of " + getId());
|
||||
gui.updateItem(slot, guiItem);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,15 +317,17 @@ public class Menu {
|
||||
return slots;
|
||||
}
|
||||
|
||||
@Contract("_, _, _, _, _ -> param2")
|
||||
@Contract("_, _, _, _, _, _ -> param4")
|
||||
@NotNull
|
||||
private ItemStack getMenuItem(CosmeticUser user, Type type, ConfigurationNode config, ItemStack itemStack, int slot) {
|
||||
private ItemStack getMenuItem(Player viewer, CosmeticHolder cosmeticHolder, Type type, ConfigurationNode config, ItemStack itemStack, int slot) {
|
||||
if (!itemStack.hasItemMeta()) return itemStack;
|
||||
return type.setItem(user, config, itemStack, slot);
|
||||
return type.setItem(viewer, cosmeticHolder, config, itemStack, slot);
|
||||
}
|
||||
|
||||
public boolean canOpen(Player player) {
|
||||
if (permissionNode.isEmpty()) return true;
|
||||
return player.isOp() || player.hasPermission(permissionNode);
|
||||
}
|
||||
|
||||
public static Comparator<MenuItem> priorityCompare = Comparator.comparing(MenuItem::priority).reversed();
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.gui.type.Type;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record MenuItem(List<Integer> slots, ItemStack item, Type type, ConfigurationNode itemConfig) {
|
||||
public record MenuItem(@NotNull List<Integer> slots, @NotNull ItemStack item, Type type, int priority, ConfigurationNode itemConfig) {
|
||||
|
||||
}
|
||||
|
||||
@@ -3,31 +3,33 @@ package com.hibiscusmc.hmccosmetics.gui;
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.lojosho.shaded.configurate.CommentedConfigurationNode;
|
||||
import me.lojosho.shaded.configurate.ConfigurateException;
|
||||
import me.lojosho.shaded.configurate.yaml.YamlConfigurationLoader;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Menus {
|
||||
|
||||
private static final HashMap<String, Menu> MENUS = new HashMap<>();
|
||||
private static final HashMap<UUID, Long> COOLDOWNS = new HashMap<>();
|
||||
|
||||
public static void addMenu(Menu menu) {
|
||||
public static void addMenu(@NotNull Menu menu) {
|
||||
MENUS.put(menu.getId().toUpperCase(), menu);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Menu getMenu(@NotNull String id) {
|
||||
return MENUS.get(id.toUpperCase());
|
||||
}
|
||||
@@ -42,11 +44,18 @@ public class Menus {
|
||||
return MENUS.containsKey(id.toUpperCase());
|
||||
}
|
||||
|
||||
public static boolean hasMenu(Menu menu) {
|
||||
public static boolean hasMenu(@NotNull Menu menu) {
|
||||
return MENUS.containsValue(menu);
|
||||
}
|
||||
|
||||
public static Menu getDefaultMenu() { return Menus.getMenu(Settings.getDefaultMenu()); }
|
||||
public static boolean hasDefaultMenu() {
|
||||
return MENUS.containsKey(Settings.getDefaultMenu());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Menu getDefaultMenu() {
|
||||
return Menus.getMenu(Settings.getDefaultMenu());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<String> getMenuNames() {
|
||||
@@ -63,8 +72,21 @@ public class Menus {
|
||||
return MENUS.values();
|
||||
}
|
||||
|
||||
public static void addCooldown(UUID uuid, long time) {
|
||||
COOLDOWNS.put(uuid, time);
|
||||
}
|
||||
|
||||
public static Long getCooldown(UUID uuid) {
|
||||
return COOLDOWNS.getOrDefault(uuid, 0L);
|
||||
}
|
||||
|
||||
public static void removeCooldown(UUID uuid) {
|
||||
COOLDOWNS.remove(uuid);
|
||||
}
|
||||
|
||||
public static void setup() {
|
||||
MENUS.clear();
|
||||
COOLDOWNS.clear();
|
||||
|
||||
File cosmeticFolder = new File(HMCCosmeticsPlugin.getInstance().getDataFolder() + "/menus");
|
||||
if (!cosmeticFolder.exists()) cosmeticFolder.mkdir();
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class Action {
|
||||
@@ -16,5 +18,13 @@ public abstract class Action {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||
run(CosmeticHolder.ensureSingleCosmeticUser(viewer, cosmeticHolder), raw);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Override {@link #run(Player, CosmeticHolder, String)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract void run(CosmeticUser user, String raw);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.actions.*;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class Actions {
|
||||
@@ -28,7 +31,6 @@ public class Actions {
|
||||
private static final ActionCosmeticHide ACTION_HIDE = new ActionCosmeticHide();
|
||||
private static final ActionCosmeticToggle ACTION_TOGGLE = new ActionCosmeticToggle();
|
||||
|
||||
|
||||
public static Action getAction(@NotNull String id) {
|
||||
return actions.get(id.toUpperCase());
|
||||
}
|
||||
@@ -41,16 +43,20 @@ public class Actions {
|
||||
actions.put(action.getId().toUpperCase(), action);
|
||||
}
|
||||
|
||||
public static void runActions(CosmeticUser user, @NotNull List<String> raw) {
|
||||
public static void runActions(Player viewer, CosmeticHolder cosmeticHolder, @NotNull List<String> raw) {
|
||||
for (String a : raw) {
|
||||
String id = StringUtils.substringBetween(a, "[", "]").toUpperCase();
|
||||
String id = StringUtils.substringBetween(a, "[", "]");
|
||||
String message = StringUtils.substringAfter(a, "] ");
|
||||
MessagesUtil.sendDebugMessages("ID is " + id + " // Raw Data is " + message);
|
||||
if (isAction(id)) {
|
||||
getAction(id).run(user, message);
|
||||
if (id != null && isAction(id.toUpperCase())) {
|
||||
getAction(id).run(viewer, cosmeticHolder, message);
|
||||
} else {
|
||||
MessagesUtil.sendDebugMessages("Possible ids: " + actions.keySet());
|
||||
MessagesUtil.sendDebugMessages("Invalid Action ID (" + id + ") used in menus (Full raw: '" + a + "'). Make sure all actions are properly typed out. Here are all possible actions: " + actions.keySet(), Level.WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void runActions(CosmeticUser user, @NotNull List<String> raw) {
|
||||
runActions(user.getPlayer(), user, raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ActionCloseMenu extends Action {
|
||||
@@ -10,8 +12,13 @@ public class ActionCloseMenu extends Action {
|
||||
super("close");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||
viewer.closeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(@NotNull CosmeticUser user, String raw) {
|
||||
user.getPlayer().closeInventory();
|
||||
run(user.getPlayer(), user, raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ActionConsoleCommand extends Action {
|
||||
@@ -13,8 +15,15 @@ public class ActionConsoleCommand extends Action {
|
||||
super("console-command");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||
// todo: some of these generalizations may require more specific implementations, for example,
|
||||
// todo: what if we wanted to execute console commands only for the cosmetic holder?
|
||||
HMCCosmeticsPlugin.getInstance().getServer().dispatchCommand(Bukkit.getConsoleSender(), Hooks.processPlaceholders(viewer, raw));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(@NotNull CosmeticUser user, String raw) {
|
||||
HMCCosmeticsPlugin.getInstance().getServer().dispatchCommand(Bukkit.getConsoleSender(), Hooks.processPlaceholders(user.getPlayer(), raw));
|
||||
run(user.getPlayer(), user, raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ActionCosmeticHide extends Action {
|
||||
@@ -11,8 +13,14 @@ public class ActionCosmeticHide extends Action {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(@NotNull CosmeticUser user, String raw) {
|
||||
if (user.getHidden()) return;
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||
if (!(cosmeticHolder instanceof CosmeticUser user)) return;
|
||||
if (user.isHidden()) return;
|
||||
user.hideCosmetics(CosmeticUser.HiddenReason.ACTION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(@NotNull CosmeticUser user, String raw) {
|
||||
run(user.getPlayer(), user, raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ActionCosmeticShow extends Action {
|
||||
@@ -11,11 +13,17 @@ public class ActionCosmeticShow extends Action {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(@NotNull CosmeticUser user, String raw) {
|
||||
if (!user.getHidden()) return;
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||
if (!(cosmeticHolder instanceof CosmeticUser user)) return;
|
||||
if (!user.isHidden()) return;
|
||||
|
||||
// Do not hide if it's already off for WG
|
||||
if (user.getHiddenReason() != CosmeticUser.HiddenReason.ACTION && user.getHiddenReason() != CosmeticUser.HiddenReason.COMMAND) return;
|
||||
user.showCosmetics();
|
||||
if (!user.isHidden(CosmeticUser.HiddenReason.ACTION) && !user.isHidden(CosmeticUser.HiddenReason.COMMAND)) return;
|
||||
user.showCosmetics(CosmeticUser.HiddenReason.ACTION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(@NotNull CosmeticUser user, String raw) {
|
||||
run(user.getPlayer(), user, raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ActionCosmeticToggle extends Action {
|
||||
@@ -11,13 +13,19 @@ public class ActionCosmeticToggle extends Action {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(@NotNull CosmeticUser user, String raw) {
|
||||
if (user.getHidden()) {
|
||||
if (user.getHiddenReason() != CosmeticUser.HiddenReason.ACTION && user.getHiddenReason() != CosmeticUser.HiddenReason.COMMAND) return;
|
||||
user.showCosmetics();
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||
if (!(cosmeticHolder instanceof CosmeticUser user)) return;
|
||||
if (user.isHidden()) {
|
||||
if (!user.isHidden(CosmeticUser.HiddenReason.ACTION) && !user.isHidden(CosmeticUser.HiddenReason.COMMAND)) return;
|
||||
user.showCosmetics(CosmeticUser.HiddenReason.ACTION);
|
||||
return;
|
||||
}
|
||||
|
||||
user.hideCosmetics(CosmeticUser.HiddenReason.ACTION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(@NotNull CosmeticUser user, String raw) {
|
||||
run(user.getPlayer(), user, raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ActionEquip extends Action {
|
||||
|
||||
@@ -12,10 +14,15 @@ public class ActionEquip extends Action {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(CosmeticUser user, String raw) {
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||
Cosmetic cosmetic = Cosmetics.getCosmetic(raw);
|
||||
if (cosmetic == null) return;
|
||||
|
||||
user.addPlayerCosmetic(cosmetic);
|
||||
cosmeticHolder.addCosmetic(cosmetic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(CosmeticUser user, String raw) {
|
||||
run(user.getPlayer(), user, raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
@@ -15,7 +17,7 @@ public class ActionMenu extends Action {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(CosmeticUser user, String raw) {
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||
boolean ignorePermission = false;
|
||||
|
||||
raw = raw.replaceAll(" ", ""); // Removes all spaces
|
||||
@@ -32,6 +34,11 @@ public class ActionMenu extends Action {
|
||||
|
||||
Menu menu = Menus.getMenu(raw);
|
||||
MessagesUtil.sendDebugMessages(raw + " | " + ignorePermission);
|
||||
menu.openMenu(user, ignorePermission);
|
||||
menu.openMenu(viewer, cosmeticHolder, ignorePermission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(CosmeticUser user, String raw) {
|
||||
run(user.getPlayer(), user, raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ActionMessage extends Action {
|
||||
@@ -11,8 +13,13 @@ public class ActionMessage extends Action {
|
||||
super("message");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||
MessagesUtil.sendMessageNoKey(viewer, raw);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(@NotNull CosmeticUser user, String raw) {
|
||||
MessagesUtil.sendMessageNoKey(user.getPlayer(), raw);
|
||||
run(user.getPlayer(), user, raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||
import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
|
||||
import com.owen1212055.particlehelper.api.particle.types.BlockDataParticle;
|
||||
import com.owen1212055.particlehelper.api.particle.types.DestinationParticle;
|
||||
import com.owen1212055.particlehelper.api.particle.types.velocity.VelocityParticle;
|
||||
@@ -24,7 +25,7 @@ public class ActionParticle extends Action {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public void run(CosmeticUser user, @NotNull String raw) {
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||
String[] rawString = raw.split(" ");
|
||||
ParticleType<?, ?> particleType = Particles.fromKey(NamespacedKey.minecraft(rawString[0].toLowerCase()));
|
||||
if (particleType == null) {
|
||||
@@ -42,10 +43,15 @@ public class ActionParticle extends Action {
|
||||
return;
|
||||
}
|
||||
|
||||
particle = ServerUtils.addParticleValues(particle, rawString);
|
||||
Location location = user.getPlayer().getLocation();
|
||||
for (Player player : PacketManager.getViewers(location)) {
|
||||
particle = HMCCServerUtils.addParticleValues(particle, rawString);
|
||||
Location location = viewer.getLocation();
|
||||
for (Player player : HMCCPacketManager.getViewers(location)) {
|
||||
particle.compile().send(player, location);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(CosmeticUser user, @NotNull String raw) {
|
||||
run(user.getPlayer(), user, raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ActionPlayerCommand extends Action {
|
||||
@@ -12,8 +14,14 @@ public class ActionPlayerCommand extends Action {
|
||||
super("player-command");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||
// todo: what if we wanted the cosmetic holder to execute the command instead
|
||||
viewer.performCommand(MessagesUtil.processStringNoKeyString(viewer, Hooks.processPlaceholders(viewer, raw)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(@NotNull CosmeticUser user, String raw) {
|
||||
user.getPlayer().performCommand(MessagesUtil.processStringNoKeyString(user.getPlayer(), Hooks.processPlaceholders(user.getPlayer(), raw)));
|
||||
run(user.getPlayer(), user, raw);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
@@ -16,8 +17,7 @@ public class ActionSound extends Action {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(@NotNull CosmeticUser user, @NotNull String raw) {
|
||||
Player player = user.getPlayer();
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||
String[] processedString = raw.split(" ");
|
||||
|
||||
String soundName = processedString[0];
|
||||
@@ -31,6 +31,11 @@ public class ActionSound extends Action {
|
||||
|
||||
MessagesUtil.sendDebugMessages("Attempting to play " + soundName, Level.INFO);
|
||||
|
||||
player.playSound(player.getLocation(), soundName, volume, pitch);
|
||||
viewer.playSound(viewer.getLocation(), soundName, volume, pitch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(@NotNull CosmeticUser user, @NotNull String raw) {
|
||||
run(user.getPlayer(), user, raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.apache.commons.lang3.EnumUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ActionUnequip extends Action {
|
||||
|
||||
@@ -12,10 +13,15 @@ public class ActionUnequip extends Action {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(CosmeticUser user, String raw) {
|
||||
if (!EnumUtils.isValidEnum(CosmeticSlot.class, raw)) return;
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||
if (!CosmeticSlot.contains(raw)) return;
|
||||
|
||||
CosmeticSlot slot = CosmeticSlot.valueOf(raw);
|
||||
user.removeCosmeticSlot(slot);
|
||||
cosmeticHolder.removeCosmeticSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(CosmeticUser user, String raw) {
|
||||
run(user.getPlayer(), user, raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,63 +6,62 @@ import com.hibiscusmc.hmccolor.shaded.gui.guis.GuiItem;
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
||||
import me.lojosho.hibiscuscommons.util.AdventureUtils;
|
||||
import me.lojosho.hibiscuscommons.util.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import org.bukkit.inventory.meta.MapMeta;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class DyeMenu {
|
||||
|
||||
public static void openMenu(@NotNull CosmeticUser user, Cosmetic cosmetic) {
|
||||
Player player = user.getPlayer();
|
||||
if (player == null) return;
|
||||
public static void openMenu(@NotNull Player viewer, @NotNull CosmeticHolder cosmeticHolder, Cosmetic cosmetic) {
|
||||
if (!Hooks.isActiveHook("HMCColor")) {
|
||||
addCosmetic(user, cosmetic, null);
|
||||
addCosmetic(viewer, cosmeticHolder, cosmetic, null);
|
||||
return;
|
||||
}
|
||||
ItemStack originalItem = user.getUserCosmeticItem(cosmetic);
|
||||
if (originalItem == null || !cosmetic.isDyable()) return;
|
||||
ItemStack originalItem = cosmetic.getItem();
|
||||
if (originalItem == null || !cosmetic.isDyeable()) return;
|
||||
|
||||
Gui gui = HMCColorApi.INSTANCE.colorMenu();
|
||||
gui.updateTitle(Hooks.processPlaceholders(player, Settings.getDyeMenuName()));
|
||||
Gui gui = HMCColorApi.createColorMenu(viewer);
|
||||
gui.updateTitle(AdventureUtils.MINI_MESSAGE.deserialize(Hooks.processPlaceholders(viewer, Settings.getDyeMenuName())));
|
||||
gui.setItem(Settings.getDyeMenuInputSlot(), new GuiItem(originalItem));
|
||||
gui.setDefaultTopClickAction(event -> {
|
||||
if (event.getSlot() == Settings.getDyeMenuOutputSlot()) {
|
||||
ItemStack item = event.getInventory().getItem(Settings.getDyeMenuOutputSlot());
|
||||
if (item == null) return;
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta == null) return;
|
||||
|
||||
Color color = meta instanceof LeatherArmorMeta leatherMeta ? leatherMeta.getColor() :
|
||||
meta instanceof PotionMeta potionMeta ? potionMeta.getColor() :
|
||||
meta instanceof MapMeta mapMeta ? mapMeta.getColor() : null;
|
||||
Color color = NMSHandlers.getHandler().getUtilHandler().getColor(item);
|
||||
if (color == null) return;
|
||||
|
||||
addCosmetic(user, cosmetic, color);
|
||||
addCosmetic(viewer, cosmeticHolder, cosmetic, color);
|
||||
event.setCancelled(true);
|
||||
} else event.setCancelled(true);
|
||||
});
|
||||
|
||||
gui.setPlayerInventoryAction(event -> event.setCancelled(true));
|
||||
gui.setCloseGuiAction(event -> {});
|
||||
gui.open(player);
|
||||
gui.open(viewer);
|
||||
}
|
||||
|
||||
private static void addCosmetic(@NotNull CosmeticUser user, Cosmetic cosmetic, Color color) {
|
||||
public static void openMenu(@NotNull CosmeticUser user, Cosmetic cosmetic) {
|
||||
Player player = user.getPlayer();
|
||||
user.addPlayerCosmetic(cosmetic, color);
|
||||
player.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
if (player == null) return;
|
||||
openMenu(player, user, cosmetic);
|
||||
}
|
||||
|
||||
private static void addCosmetic(@NotNull Player viewer, @NotNull CosmeticHolder cosmeticHolder, @NotNull Cosmetic cosmetic, @Nullable Color color) {
|
||||
cosmeticHolder.addCosmetic(cosmetic, color);
|
||||
viewer.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
player.closeInventory();
|
||||
user.updateCosmetic(cosmetic.getSlot());
|
||||
viewer.closeInventory();
|
||||
cosmeticHolder.updateCosmetic(cosmetic.getSlot());
|
||||
}, 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,23 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.type;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Type {
|
||||
|
||||
@@ -18,11 +32,87 @@ public abstract class Type {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void run(CosmeticUser user, ConfigurationNode config) {
|
||||
run(user, config, null);
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, ConfigurationNode config) {
|
||||
run(viewer, cosmeticHolder, config, null);
|
||||
}
|
||||
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, ConfigurationNode config, ClickType clickType) {
|
||||
run(CosmeticHolder.ensureSingleCosmeticUser(viewer, cosmeticHolder), config, clickType);
|
||||
}
|
||||
|
||||
public void run(CosmeticUser user, ConfigurationNode config) {
|
||||
final var player = user.getPlayer();
|
||||
if (player == null) return;
|
||||
run(player, user, config, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Override {@link #run(Player, CosmeticHolder, ConfigurationNode, ClickType)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract void run(CosmeticUser user, ConfigurationNode config, ClickType clickType);
|
||||
|
||||
public ItemStack setItem(Player viewer, CosmeticHolder cosmeticHolder, ConfigurationNode config, ItemStack itemStack, int slot) {
|
||||
return setItem(CosmeticHolder.ensureSingleCosmeticUser(viewer, cosmeticHolder), config, itemStack, slot);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Override {@link #setItem(Player, CosmeticHolder, ConfigurationNode, ItemStack, int)} instead.
|
||||
*/
|
||||
public abstract ItemStack setItem(CosmeticUser user, ConfigurationNode config, ItemStack itemStack, int slot);
|
||||
|
||||
@Contract("_, _ -> param2")
|
||||
@NotNull
|
||||
@SuppressWarnings("Duplicates")
|
||||
protected ItemMeta processItemMeta(Player viewer, @NotNull ItemMeta itemMeta) {
|
||||
// New implementation - Paper and forks
|
||||
// I know this is a kinda batshit way to do it (with serializing and deserializing MiniMessage)
|
||||
// But currently I can't think of another good way of doing it without a big refactor. I'll come back to this
|
||||
// At a later date.
|
||||
if (HibiscusCommonsPlugin.isOnPaper()) {
|
||||
List<Component> processedLore = new ArrayList<>();
|
||||
if (itemMeta.hasDisplayName()) {
|
||||
String displayName = MiniMessage.miniMessage().serialize(itemMeta.displayName());
|
||||
displayName = Hooks.processPlaceholders(viewer, displayName);
|
||||
itemMeta.displayName(MiniMessage.miniMessage().deserialize(displayName).decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE));
|
||||
}
|
||||
|
||||
if (itemMeta.hasLore()) {
|
||||
for (Component loreLine : itemMeta.lore()) {
|
||||
String loreStringLine = MiniMessage.miniMessage().serialize(loreLine);
|
||||
loreStringLine = Hooks.processPlaceholders(viewer, loreStringLine);
|
||||
processedLore.add(MiniMessage.miniMessage().deserialize(loreStringLine).decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE));
|
||||
}
|
||||
}
|
||||
|
||||
if (itemMeta instanceof SkullMeta skullMeta) {
|
||||
if (skullMeta.hasOwner() && skullMeta.getOwner() != null) {
|
||||
skullMeta.setOwner(Hooks.processPlaceholders(viewer, skullMeta.getOwner()));
|
||||
}
|
||||
}
|
||||
|
||||
itemMeta.lore(processedLore);
|
||||
} else {
|
||||
// Legacy implementation - Spigot
|
||||
List<String> processedLore = new ArrayList<>();
|
||||
if (itemMeta.hasDisplayName()) {
|
||||
itemMeta.setDisplayName(Hooks.processPlaceholders(viewer, itemMeta.getDisplayName()));
|
||||
}
|
||||
|
||||
if (itemMeta.hasLore()) {
|
||||
for (String loreLine : itemMeta.getLore()) {
|
||||
processedLore.add(Hooks.processPlaceholders(viewer, loreLine));
|
||||
}
|
||||
}
|
||||
|
||||
if (itemMeta instanceof SkullMeta skullMeta) {
|
||||
if (skullMeta.hasOwner() && skullMeta.getOwner() != null) {
|
||||
skullMeta.setOwner(Hooks.processPlaceholders(viewer, skullMeta.getOwner()));
|
||||
}
|
||||
}
|
||||
itemMeta.setLore(processedLore);
|
||||
}
|
||||
|
||||
return itemMeta;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,18 +10,43 @@ public class Types {
|
||||
|
||||
private static final HashMap<String, Type> types = new HashMap<>();
|
||||
|
||||
private static TypeCosmetic TYPE_COSMETIC = new TypeCosmetic();
|
||||
private static TypeEmpty TYPE_EMPTY = new TypeEmpty();
|
||||
private static final TypeCosmetic TYPE_COSMETIC = new TypeCosmetic();
|
||||
private static final TypeEmpty TYPE_EMPTY = new TypeEmpty();
|
||||
|
||||
/**
|
||||
* Get's a Menu Item type. Add custom menu item types with {@link #addType(Type)}
|
||||
* @param id A non-case sensitive ID
|
||||
* @return The type of Menu Item
|
||||
*/
|
||||
public static Type getType(@NotNull String id) {
|
||||
return types.get(id.toUpperCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a type is valid. Add custom menu item types with {@link #addType(Type)}
|
||||
* @param id A non-case sensitive ID
|
||||
* @return True if exists, False if not.
|
||||
*/
|
||||
public static boolean isType(@NotNull String id) {
|
||||
return types.containsKey(id.toUpperCase());
|
||||
}
|
||||
|
||||
public static void addType(Type type) {
|
||||
types.put(type.getId().toUpperCase(), type);
|
||||
/**
|
||||
* Adds a Menu Item Type to the types HashMap for reference. Menu Types will automatically be added using this method.
|
||||
* @param type A non-null {@link Type} that'll be added. ID should be unique; can't be duplicated
|
||||
*/
|
||||
public static boolean addType(@NotNull Type type) {
|
||||
String id = type.getId().toUpperCase();
|
||||
if (types.containsKey(id)) return false;
|
||||
types.put(id, type);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default menu item; {@link TypeEmpty}
|
||||
* @return The empty menu type.
|
||||
*/
|
||||
public static TypeEmpty getDefaultType() {
|
||||
return TYPE_EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,38 +2,41 @@ package com.hibiscusmc.hmccosmetics.gui.type.types;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.config.serializer.ItemSerializer;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Actions;
|
||||
import com.hibiscusmc.hmccosmetics.gui.special.DyeMenu;
|
||||
import com.hibiscusmc.hmccosmetics.gui.type.Type;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import me.lojosho.hibiscuscommons.config.serializer.ItemSerializer;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import me.lojosho.shaded.configurate.serialize.SerializationException;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TypeCosmetic extends Type {
|
||||
|
||||
public TypeCosmetic(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public TypeCosmetic() {
|
||||
super("cosmetic");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(CosmeticUser user, @NotNull ConfigurationNode config, ClickType clickType) {
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, ConfigurationNode config, ClickType clickType) {
|
||||
MessagesUtil.sendDebugMessages("Running Cosmetic Click Type");
|
||||
if (config.node("cosmetic").virtual()) {
|
||||
MessagesUtil.sendDebugMessages("Cosmetic Config Field Virtual");
|
||||
@@ -41,32 +44,33 @@ public class TypeCosmetic extends Type {
|
||||
}
|
||||
String cosmeticName = config.node("cosmetic").getString();
|
||||
Cosmetic cosmetic = Cosmetics.getCosmetic(cosmeticName);
|
||||
Player player = user.getPlayer();
|
||||
if (cosmetic == null) {
|
||||
MessagesUtil.sendDebugMessages("No Cosmetic Found");
|
||||
MessagesUtil.sendMessage(player, "invalid-cosmetic");
|
||||
MessagesUtil.sendMessage(viewer, "invalid-cosmetic");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!user.canEquipCosmetic(cosmetic)) {
|
||||
if (!cosmeticHolder.canEquipCosmetic(cosmetic)) {
|
||||
MessagesUtil.sendDebugMessages("No Cosmetic Permission");
|
||||
MessagesUtil.sendMessage(player, "no-cosmetic-permission");
|
||||
MessagesUtil.sendMessage(viewer, "no-cosmetic-permission");
|
||||
return;
|
||||
}
|
||||
|
||||
boolean isUnEquippingCosmetic = false;
|
||||
if (user.getCosmetic(cosmetic.getSlot()) == cosmetic) isUnEquippingCosmetic = true;
|
||||
if (cosmeticHolder.getCosmetic(cosmetic.getSlot()) == cosmetic) isUnEquippingCosmetic = true;
|
||||
|
||||
String dyeClick = Settings.getCosmeticDyeClickType();
|
||||
String requiredClick;
|
||||
if (isUnEquippingCosmetic) requiredClick = Settings.getCosmeticUnEquipClickType();
|
||||
else requiredClick = Settings.getCosmeticEquipClickType();
|
||||
|
||||
MessagesUtil.sendDebugMessages("Required click type: " + requiredClick);
|
||||
MessagesUtil.sendDebugMessages("Click type: " + clickType.name());
|
||||
if (!requiredClick.equalsIgnoreCase("ANY") && !requiredClick.equalsIgnoreCase(clickType.name())) {
|
||||
MessagesUtil.sendMessage(user.getPlayer(), "invalid-click-type");
|
||||
return;
|
||||
}
|
||||
|
||||
final boolean isRequiredClick = requiredClick.equalsIgnoreCase("ANY") || requiredClick.equalsIgnoreCase(clickType.name());
|
||||
final boolean isDyeClick = dyeClick.equalsIgnoreCase("ANY") || dyeClick.equalsIgnoreCase(clickType.name());
|
||||
|
||||
if (!isRequiredClick) isUnEquippingCosmetic = false;
|
||||
|
||||
List<String> actionStrings = new ArrayList<>();
|
||||
ConfigurationNode actionConfig = config.node("actions");
|
||||
@@ -94,25 +98,25 @@ public class TypeCosmetic extends Type {
|
||||
if (isUnEquippingCosmetic) {
|
||||
if (!actionConfig.node("on-unequip").virtual()) actionStrings.addAll(actionConfig.node("on-unequip").getList(String.class));
|
||||
MessagesUtil.sendDebugMessages("on-unequip");
|
||||
user.removeCosmeticSlot(cosmetic);
|
||||
cosmeticHolder.removeCosmeticSlot(cosmetic);
|
||||
} else {
|
||||
if (!actionConfig.node("on-equip").virtual()) actionStrings.addAll(actionConfig.node("on-equip").getList(String.class));
|
||||
MessagesUtil.sendDebugMessages("on-equip");
|
||||
// TODO: Redo this
|
||||
if (cosmetic.isDyable() && Hooks.isActiveHook("HMCColor")) {
|
||||
DyeMenu.openMenu(user, cosmetic);
|
||||
} else {
|
||||
user.addPlayerCosmetic(cosmetic);
|
||||
if (cosmetic.isDyeable() && isDyeClick && Hooks.isActiveHook("HMCColor")) {
|
||||
DyeMenu.openMenu(viewer, cosmeticHolder, cosmetic);
|
||||
} else if (isRequiredClick) {
|
||||
cosmeticHolder.addCosmetic(cosmetic);
|
||||
}
|
||||
}
|
||||
|
||||
Actions.runActions(user, actionStrings);
|
||||
Actions.runActions(viewer, cosmeticHolder, actionStrings);
|
||||
|
||||
} catch (SerializationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// Fixes issue with offhand cosmetics not appearing. Yes, I know this is dumb
|
||||
Runnable run = () -> user.updateCosmetic(cosmetic.getSlot());
|
||||
Runnable run = () -> cosmeticHolder.updateCosmetic(cosmetic.getSlot());
|
||||
if (cosmetic instanceof CosmeticArmorType) {
|
||||
if (((CosmeticArmorType) cosmetic).getEquipSlot().equals(EquipmentSlot.OFF_HAND)) {
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), run, 1);
|
||||
@@ -123,8 +127,19 @@ public class TypeCosmetic extends Type {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack setItem(CosmeticUser user, @NotNull ConfigurationNode config, ItemStack itemStack, int slot) {
|
||||
itemStack.setItemMeta(processLoreLines(user, itemStack.getItemMeta()));
|
||||
public void run(CosmeticUser user, @NotNull ConfigurationNode config, ClickType clickType) {
|
||||
run(user.getPlayer(), user, config, clickType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack setItem(CosmeticUser user, ConfigurationNode config, ItemStack itemStack, int slot) {
|
||||
return setItem(user.getPlayer(), user, config, itemStack, slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack setItem(@NotNull Player viewer, @NotNull CosmeticHolder cosmeticHolder, @NotNull ConfigurationNode config, @NotNull ItemStack itemStack, int slot) {
|
||||
if (itemStack.hasItemMeta()) itemStack.setItemMeta(processItemMeta(viewer, itemStack.getItemMeta()));
|
||||
else MessagesUtil.sendDebugMessages("ItemStack has no ItemMeta?");
|
||||
|
||||
if (config.node("cosmetic").virtual()) {
|
||||
return itemStack;
|
||||
@@ -135,9 +150,9 @@ public class TypeCosmetic extends Type {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
if (user.hasCosmeticInSlot(cosmetic) && !config.node("equipped-item").virtual()) {
|
||||
if (cosmeticHolder.hasCosmeticInSlot(cosmetic) && (!config.node("equipped-item").virtual() || !config.node("locked-equipped-item").virtual())) {
|
||||
MessagesUtil.sendDebugMessages("GUI Equipped Item");
|
||||
ConfigurationNode equippedItem = config.node("equipped-item");
|
||||
ConfigurationNode equippedItem = config.node(cosmeticHolder.canEquipCosmetic(cosmetic, true) && !config.node("equipped-item").virtual() ? "equipped-item" : "locked-equipped-item");
|
||||
try {
|
||||
if (equippedItem.node("material").virtual()) equippedItem.node("material").set(config.node("item", "material").getString());
|
||||
} catch (SerializationException e) {
|
||||
@@ -148,11 +163,12 @@ public class TypeCosmetic extends Type {
|
||||
} catch (SerializationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
itemStack.setItemMeta(processLoreLines(user, itemStack.getItemMeta()));
|
||||
if (itemStack.hasItemMeta()) itemStack.setItemMeta(processItemMeta(viewer, itemStack.getItemMeta()));
|
||||
else MessagesUtil.sendDebugMessages("ItemStack has no ItemMeta in equipped item?");
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
if (!user.canEquipCosmetic(cosmetic) && !config.node("locked-item").virtual()) {
|
||||
if (!cosmeticHolder.canEquipCosmetic(cosmetic, true) && !config.node("locked-item").virtual()) {
|
||||
MessagesUtil.sendDebugMessages("GUI Locked Item");
|
||||
ConfigurationNode lockedItem = config.node("locked-item");
|
||||
try {
|
||||
@@ -165,28 +181,10 @@ public class TypeCosmetic extends Type {
|
||||
} catch (SerializationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
itemStack.setItemMeta(processLoreLines(user, itemStack.getItemMeta()));
|
||||
if (itemStack.hasItemMeta()) itemStack.setItemMeta(processItemMeta(viewer, itemStack.getItemMeta()));
|
||||
else MessagesUtil.sendDebugMessages("ItemStack has no ItemMeta in locked item?");
|
||||
return itemStack;
|
||||
}
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Contract("_, _ -> param2")
|
||||
@NotNull
|
||||
@SuppressWarnings("Duplicates")
|
||||
private ItemMeta processLoreLines(CosmeticUser user, @NotNull ItemMeta itemMeta) {
|
||||
List<String> processedLore = new ArrayList<>();
|
||||
|
||||
if (itemMeta.hasDisplayName()) {
|
||||
itemMeta.setDisplayName(Hooks.processPlaceholders(user.getPlayer(), itemMeta.getDisplayName()));
|
||||
}
|
||||
|
||||
if (itemMeta.hasLore()) {
|
||||
for (String loreLine : itemMeta.getLore()) {
|
||||
processedLore.add(Hooks.processPlaceholders(user.getPlayer(), loreLine));
|
||||
}
|
||||
}
|
||||
itemMeta.setLore(processedLore);
|
||||
return itemMeta;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.type.types;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Actions;
|
||||
import com.hibiscusmc.hmccosmetics.gui.type.Type;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import me.lojosho.shaded.configurate.serialize.SerializationException;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -22,9 +23,10 @@ public class TypeEmpty extends Type {
|
||||
// This is an empty type, meaning, when a menu item has a type of "empty" it will run the code in the method run.
|
||||
}
|
||||
|
||||
// This is the code that's run when the item is clicked.
|
||||
// This is the code that's run when the item is clicked. The item is clicked by the "viewer" player in a menu for the
|
||||
// given "cosmeticHolder". They're the same player by default, but it's not guaranteed.
|
||||
@Override
|
||||
public void run(CosmeticUser user, @NotNull ConfigurationNode config, ClickType clickType) {
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, @NotNull ConfigurationNode config, ClickType clickType) {
|
||||
List<String> actionStrings = new ArrayList<>(); // List where we keep the actions the server will execute.
|
||||
ConfigurationNode actionConfig = config.node("actions"); // Configuration node that actions are under.
|
||||
|
||||
@@ -51,28 +53,32 @@ public class TypeEmpty extends Type {
|
||||
}
|
||||
|
||||
// We run the actions once we got the raw strings from the config.
|
||||
Actions.runActions(user, actionStrings);
|
||||
Actions.runActions(viewer, cosmeticHolder, actionStrings);
|
||||
} catch (SerializationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
// backward-compatibility method, will not be required in the future
|
||||
@Override
|
||||
public void run(CosmeticUser user, ConfigurationNode config, ClickType clickType) {
|
||||
final var player = user.getPlayer();
|
||||
if (player == null) return;
|
||||
run(player, user, config, clickType);
|
||||
}
|
||||
|
||||
// backward-compatibility method, will not be required in the future
|
||||
@Override
|
||||
public ItemStack setItem(CosmeticUser user, ConfigurationNode config, ItemStack itemStack, int slot) {
|
||||
return setItem(user.getPlayer(), user, config, itemStack, slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("Duplicates")
|
||||
public ItemStack setItem(CosmeticUser user, ConfigurationNode config, @NotNull ItemStack itemStack, int slot) {
|
||||
List<String> processedLore = new ArrayList<>();
|
||||
public ItemStack setItem(Player viewer, CosmeticHolder cosmeticHolder, ConfigurationNode config, @NotNull ItemStack itemStack, int slot) {
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
if (itemMeta.hasDisplayName()) {
|
||||
itemMeta.setDisplayName(Hooks.processPlaceholders(user.getPlayer(), itemMeta.getDisplayName()));
|
||||
}
|
||||
|
||||
if (itemMeta.hasLore()) {
|
||||
for (String loreLine : itemMeta.getLore()) {
|
||||
processedLore.add(Hooks.processPlaceholders(user.getPlayer(), loreLine));
|
||||
}
|
||||
}
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
itemStack.setItemMeta(processItemMeta(viewer, itemMeta));
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.hooks;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Represents a hook into other minecraft plugins
|
||||
*/
|
||||
public abstract class Hook implements Listener {
|
||||
private final String id;
|
||||
private boolean active = false;
|
||||
private boolean itemHook = false;
|
||||
|
||||
public Hook(@NotNull String id) {
|
||||
this.id = id;
|
||||
Hooks.addHook(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads this hook
|
||||
*
|
||||
* @implNote By default, this method does nothing. It should be overridden by child classes to implement any necessary loading logic
|
||||
*/
|
||||
public void load() { }
|
||||
|
||||
/**
|
||||
* Gets an {@link ItemStack} that is associated with the provided id from the hooked plugin
|
||||
* @param itemId The id of the {@link ItemStack}
|
||||
* @return The {@link ItemStack} with the id provided. If an invalid id was provided or if the hook doesn't have any related {@link ItemStack}s then this will return null
|
||||
* @implNote By default, this method returns null. It should be overridden by child classes if you will to have your hook return a related {@link ItemStack}
|
||||
*/
|
||||
@Nullable
|
||||
public ItemStack getItem(@NotNull String itemId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id of this hook
|
||||
*
|
||||
* @return The unique id for this hook
|
||||
*/
|
||||
@NotNull
|
||||
public final String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether this hook has been activated
|
||||
* @return true if this hook is active, false otherwise
|
||||
* @deprecated As of release 2.2.5+, replaced by {@link #isActive()}
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean getActive() {
|
||||
return this.active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether this hook has been activated
|
||||
* @return true if this hook is active, false otherwise
|
||||
* @since 2.2.5
|
||||
*/
|
||||
public final boolean isActive() {
|
||||
return this.active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this hook is active
|
||||
* @param active true to activate the hook, false otherwise
|
||||
*/
|
||||
public final void setActive(boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the method {@link #getItem(String)} should return a non-null value
|
||||
* @return true if {@link #getItem(String)} should return a non-null value, false otherwise
|
||||
*
|
||||
* @apiNote Even though this method returns true does not mean that {@link #getItem(String)} won't return null, rather if this returns false then {@link #getItem(String)} should return false everytime
|
||||
*/
|
||||
public final boolean hasEnabledItemHook() {
|
||||
return itemHook;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the method {@link #getItem(String)} should return a non-null value
|
||||
* @param enabled true if {@link #getItem(String)} should return a non-null value, false otherwise
|
||||
*/
|
||||
public final void setEnabledItemHook(boolean enabled) {
|
||||
itemHook = enabled;
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.hooks;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.items.*;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.misc.*;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.placeholders.HookPlaceholderAPI;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Hooks {
|
||||
|
||||
private static final HashMap<String, Hook> hooks = new HashMap<>();
|
||||
private static final HookOraxen ORAXEN_HOOK = new HookOraxen();
|
||||
private static final HookItemAdder ITEMADDER_HOOK = new HookItemAdder();
|
||||
private static final HookGeary GEARY_HOOK = new HookGeary();
|
||||
private static final HookMythic MYTHIC_HOOK = new HookMythic();
|
||||
private static final HookDenizen DENIZEN_HOOK = new HookDenizen();
|
||||
private static final HookHMCCosmetics HMCCOSMETIC_HOOK = new HookHMCCosmetics();
|
||||
private static final HookPlaceholderAPI PAPI_HOOK = new HookPlaceholderAPI();
|
||||
private static final HookPremiumVanish PREMIUM_VANISH_HOOK = new HookPremiumVanish();
|
||||
private static final HookSuperVanish SUPER_VANISH_HOOK = new HookSuperVanish();
|
||||
private static final HookHMCColor HMC_COLOR_HOOK = new HookHMCColor();
|
||||
private static final HookCMI CMI_HOOK = new HookCMI();
|
||||
private static final HookLibsDisguises LIBS_DISGUISES_HOOK = new HookLibsDisguises();
|
||||
private static final HookModelEngine MODEL_ENGINE_HOOK = new HookModelEngine();
|
||||
private static final HookMMOItems MMO_ITEMS_HOOK = new HookMMOItems();
|
||||
|
||||
public static Hook getHook(@NotNull String id) {
|
||||
return hooks.get(id.toLowerCase());
|
||||
}
|
||||
|
||||
public static boolean isItemHook(@NotNull String id) {
|
||||
return hooks.containsKey(id.toLowerCase());
|
||||
}
|
||||
|
||||
public static void addHook(Hook hook) {
|
||||
hooks.put(hook.getId().toLowerCase(), hook);
|
||||
}
|
||||
|
||||
public static void setup() {
|
||||
for (Hook hook : hooks.values()) {
|
||||
if (Bukkit.getPluginManager().getPlugin(hook.getId()) != null) {
|
||||
HMCCosmeticsPlugin.getInstance().getServer().getPluginManager().registerEvents(hook, HMCCosmeticsPlugin.getInstance());
|
||||
hook.setActive(true);
|
||||
hook.load();
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Successfully hooked into " + hook.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ItemStack getItem(@NotNull String raw) {
|
||||
if (!raw.contains(":")) {
|
||||
Material mat = Material.getMaterial(raw.toUpperCase());
|
||||
if (mat == null) return null;
|
||||
return new ItemStack(mat);
|
||||
}
|
||||
// Ex. Oraxen:BigSword
|
||||
// split[0] is the plugin name
|
||||
// split[1] is the item name
|
||||
String[] split = raw.split(":", 2);
|
||||
|
||||
if (!isItemHook(split[0])) return null;
|
||||
Hook hook = getHook(split[0]);
|
||||
if (!hook.hasEnabledItemHook()) return null;
|
||||
if (!hook.isActive()) return null;
|
||||
return hook.getItem(split[1]);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String processPlaceholders(OfflinePlayer player, String raw) {
|
||||
if (getHook("PlaceholderAPI").isActive()) return PlaceholderAPI.setPlaceholders(player, raw);
|
||||
return raw;
|
||||
}
|
||||
|
||||
public static boolean isActiveHook(String id) {
|
||||
Hook hook = getHook(id);
|
||||
if (hook == null) return false;
|
||||
return hook.isActive();
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.hooks.items;
|
||||
|
||||
import com.denizenscript.denizen.objects.ItemTag;
|
||||
import com.denizenscript.denizencore.utilities.CoreUtilities;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A hook that integrates the plugin {@link com.denizenscript.denizen.Denizen Denizen} to provide custom items
|
||||
*/
|
||||
@SuppressWarnings("SpellCheckingInspection")
|
||||
public class HookDenizen extends Hook {
|
||||
public HookDenizen() {
|
||||
super("denizen");
|
||||
setEnabledItemHook(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a cosmetic {@link ItemStack} that is associated with the provided id from the plugin {@link com.denizenscript.denizen.Denizen Denizen}
|
||||
*/
|
||||
@Override
|
||||
public ItemStack getItem(@NotNull String itemId) {
|
||||
ItemTag item = ItemTag.valueOf(itemId, CoreUtilities.noDebugContext);
|
||||
return item == null ? null : item.getItemStack();
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.hooks.items;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
||||
import com.mineinabyss.geary.addons.GearyPhase;
|
||||
import com.mineinabyss.geary.modules.GearyModuleKt;
|
||||
import com.mineinabyss.geary.papermc.tracking.items.ItemTrackingKt;
|
||||
import com.mineinabyss.geary.prefabs.PrefabKey;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A hook that integrates the plugin {@link com.mineinabyss.geary.papermc.GearyPlugin Geary} to provide custom items
|
||||
*/
|
||||
public class HookGeary extends Hook {
|
||||
private boolean enabled = false;
|
||||
|
||||
public HookGeary() {
|
||||
super("geary");
|
||||
setEnabledItemHook(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
if (!enabled) GearyModuleKt.getGeary().getPipeline().intercept(GearyPhase.INIT_ENTITIES, () -> {
|
||||
enabled = true;
|
||||
HMCCosmeticsPlugin.setup();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a cosmetic {@link ItemStack} that is associated with the provided id from the plugin {@link com.mineinabyss.geary.papermc.GearyPlugin Geary}
|
||||
*/
|
||||
@Override
|
||||
public ItemStack getItem(@NotNull String itemId) {
|
||||
if (enabled) {
|
||||
PrefabKey prefabKey = PrefabKey.Companion.ofOrNull(itemId);
|
||||
if (prefabKey == null) return null;
|
||||
return ItemTrackingKt.getGearyItems().createItem(prefabKey, null);
|
||||
} else return new ItemStack(Material.AIR);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,8 @@ package com.hibiscusmc.hmccosmetics.hooks.items;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hook;
|
||||
import me.lojosho.hibiscuscommons.hooks.HookFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -11,8 +12,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
*/
|
||||
public class HookHMCCosmetics extends Hook {
|
||||
public HookHMCCosmetics() {
|
||||
super("HMCCosmetics");
|
||||
setEnabledItemHook(true);
|
||||
super("HMCCosmetics", HookFlag.ITEM_SUPPORT);
|
||||
setActive(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -24,5 +25,4 @@ public class HookHMCCosmetics extends Hook {
|
||||
if (cosmetic == null) return null;
|
||||
return cosmetic.getItem();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.hooks.items;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
||||
import dev.lone.itemsadder.api.CustomStack;
|
||||
import dev.lone.itemsadder.api.Events.ItemsAdderLoadDataEvent;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A hook that integrates the plugin {@link dev.lone.itemsadder.api.ItemsAdder ItemsAdder} to provide custom items
|
||||
*/
|
||||
@SuppressWarnings("SpellCheckingInspection")
|
||||
public class HookItemAdder extends Hook {
|
||||
private boolean enabled = false;
|
||||
|
||||
public HookItemAdder() {
|
||||
super("itemsadder");
|
||||
setEnabledItemHook(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a cosmetic {@link ItemStack} that is associated with the provided id from the plugin {@link dev.lone.itemsadder.api.ItemsAdder ItemsAdder}
|
||||
*/
|
||||
@Override
|
||||
public ItemStack getItem(@NotNull String itemId) {
|
||||
if (enabled) {
|
||||
CustomStack stack = CustomStack.getInstance(itemId);
|
||||
if (stack == null) return null;
|
||||
return stack.getItemStack();
|
||||
} else {
|
||||
return new ItemStack(Material.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onItemAdderDataLoad(ItemsAdderLoadDataEvent event) {
|
||||
// By default, it will only run once at startup, if hook setting is enabled
|
||||
if (enabled && !Settings.isItemsAdderChangeReload()) return;
|
||||
this.enabled = true;
|
||||
HMCCosmeticsPlugin.setup();
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.hooks.items;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class HookMMOItems extends Hook {
|
||||
public HookMMOItems() {
|
||||
super("MMOItems");
|
||||
setEnabledItemHook(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(@NotNull String itemId) {
|
||||
String[] split = itemId.split(":", 2);
|
||||
if (split.length == 2) {
|
||||
return MMOItems.plugin.getItem(split[0], split[1]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.hooks.items;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
||||
import io.lumine.mythic.bukkit.MythicBukkit;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A hook that integrates the plugin {@link io.lumine.mythic.bukkit.MythicBukkit MythicBukkit} to provide custom items
|
||||
*/
|
||||
@SuppressWarnings("SpellCheckingInspection")
|
||||
public class HookMythic extends Hook {
|
||||
public HookMythic() {
|
||||
super("mythicmobs");
|
||||
setEnabledItemHook(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a cosmetic {@link ItemStack} that is associated with the provided id from the plugin {@link io.lumine.mythic.bukkit.MythicBukkit MythicBukkit}
|
||||
*/
|
||||
@Override
|
||||
public ItemStack getItem(@NotNull String itemId) {
|
||||
return MythicBukkit.inst().getItemManager().getItemStack(itemId);
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.hooks.items;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
||||
import io.th0rgal.oraxen.api.OraxenItems;
|
||||
import io.th0rgal.oraxen.items.ItemBuilder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A hook that integrates the plugin {@link io.th0rgal.oraxen.OraxenPlugin OraxenPlugin} to provide custom items
|
||||
*/
|
||||
@SuppressWarnings("SpellCheckingInspection")
|
||||
public class HookOraxen extends Hook {
|
||||
public HookOraxen() {
|
||||
super("oraxen");
|
||||
setEnabledItemHook(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a cosmetic {@link ItemStack} that is associated with the provided id from the plugin {@link io.th0rgal.oraxen.OraxenPlugin OraxenPlugin}
|
||||
*/
|
||||
@Override
|
||||
public ItemStack getItem(@NotNull String itemId) {
|
||||
ItemBuilder builder = OraxenItems.getItemById(itemId);
|
||||
if (builder == null) return null;
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.hibiscusmc.hmccosmetics.hooks.misc;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerWardrobeEnterEvent;
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerWardrobeLeaveEvent;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import kr.toxicity.hud.api.BetterHud;
|
||||
import kr.toxicity.hud.api.player.HudPlayer;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hook;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class HookBetterHud extends Hook {
|
||||
|
||||
public HookBetterHud() {
|
||||
super("BetterHUD");
|
||||
setActive(true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||
public void onPlayerEnterWardrobe(@NotNull PlayerWardrobeEnterEvent event) {
|
||||
if (!Settings.isWardrobeHideHud()) return;
|
||||
UUID uuid = event.getUniqueId();
|
||||
HudPlayer hudPlayer = BetterHud.getInstance().getPlayerManager().getHudPlayer(uuid);
|
||||
if (hudPlayer == null) return;
|
||||
hudPlayer.setHudEnabled(false);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||
public void onPlayerLeaveWardrobe(@NotNull PlayerWardrobeLeaveEvent event) {
|
||||
if (!Settings.isWardrobeHideHud()) return;
|
||||
UUID uuid = event.getUniqueId();
|
||||
HudPlayer hudPlayer = BetterHud.getInstance().getPlayerManager().getHudPlayer(uuid);
|
||||
if (hudPlayer == null) return;
|
||||
hudPlayer.setHudEnabled(true);
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.hooks.misc;
|
||||
|
||||
import com.Zrips.CMI.events.CMIPlayerUnVanishEvent;
|
||||
import com.Zrips.CMI.events.CMIPlayerVanishEvent;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A hook that integrates the plugin {@link com.Zrips.CMI.CMI CMI}
|
||||
*/
|
||||
public class HookCMI extends Hook {
|
||||
public HookCMI() {
|
||||
super("CMI");
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerVanish(@NotNull CMIPlayerVanishEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
user.hideCosmetics(CosmeticUser.HiddenReason.PLUGIN);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerShow(@NotNull CMIPlayerUnVanishEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
user.showCosmetics();
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.hooks.misc;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
||||
|
||||
/**
|
||||
* A hook that integrates the plugin {@link com.hibiscusmc.hmccolor.HMCColor HMCColor}
|
||||
*/
|
||||
public class HookHMCColor extends Hook {
|
||||
public HookHMCColor() {
|
||||
super("HMCColor");
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.hooks.misc;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import me.libraryaddict.disguise.events.DisguiseEvent;
|
||||
import me.libraryaddict.disguise.events.UndisguiseEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class HookLibsDisguises extends Hook {
|
||||
public HookLibsDisguises() {
|
||||
super("LibsDisguises");
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerVanish(@NotNull DisguiseEvent event) {
|
||||
if (!(event.getEntity() instanceof Player player)) return;
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
user.hideCosmetics(CosmeticUser.HiddenReason.PLUGIN);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerShow(@NotNull UndisguiseEvent event) {
|
||||
if (!(event.getEntity() instanceof Player player)) return;
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
user.showCosmetics();
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.hooks.misc;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
||||
|
||||
public class HookModelEngine extends Hook {
|
||||
|
||||
public HookModelEngine() {
|
||||
super("ModelEngine");
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.hooks.misc;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import de.myzelyam.api.vanish.PlayerHideEvent;
|
||||
import de.myzelyam.api.vanish.PlayerShowEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A hook that integrates the plugin {@link de.myzelyam.api.vanish.VanishAPI Supervanish}
|
||||
*
|
||||
* @implSpec Supervanish and Premium Vanish both use the same api
|
||||
*/
|
||||
public class HookPremiumVanish extends Hook {
|
||||
public HookPremiumVanish() {
|
||||
super("PremiumVanish");
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerVanish(@NotNull PlayerHideEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
user.hideCosmetics(CosmeticUser.HiddenReason.PLUGIN);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerShow(@NotNull PlayerShowEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
user.showCosmetics();
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.hooks.misc;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import de.myzelyam.api.vanish.PlayerHideEvent;
|
||||
import de.myzelyam.api.vanish.PlayerShowEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A hook that integrates the plugin {@link de.myzelyam.api.vanish.VanishAPI Supervanish}
|
||||
*
|
||||
* @implSpec Supervanish and Premium Vanish both use the same api
|
||||
*/
|
||||
public class HookSuperVanish extends Hook {
|
||||
public HookSuperVanish() {
|
||||
super("SuperVanish");
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerVanish(@NotNull PlayerHideEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
user.hideCosmetics(CosmeticUser.HiddenReason.PLUGIN);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerShow(@NotNull PlayerShowEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
user.showCosmetics();
|
||||
}
|
||||
}
|
||||
@@ -54,18 +54,15 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
||||
|
||||
@Override
|
||||
public String onRequest(@NotNull OfflinePlayer player, @NotNull String params) {
|
||||
if (!player.isOnline()) return null;
|
||||
if (!player.isOnline()) return TranslationUtil.getTranslation("user-cosmetic", "offline");
|
||||
CosmeticUser user = CosmeticUsers.getUser(player.getPlayer());
|
||||
if (user == null) return null;
|
||||
if (user == null) return TranslationUtil.getTranslation("user-cosmetic", "invalid-user");
|
||||
|
||||
List<String> placeholderArgs = Arrays.asList(params.split("_", 3));
|
||||
|
||||
switch (placeholderArgs.get(0).toLowerCase()) {
|
||||
case "using":
|
||||
if (placeholderArgs == null) {
|
||||
return null;
|
||||
}
|
||||
if (placeholderArgs.get(1) != null) {
|
||||
if (placeholderArgs.size() >= 2) {
|
||||
Cosmetic cosmetic = Cosmetics.getCosmetic(placeholderArgs.get(1));
|
||||
if (cosmetic == null) return "INVALID_COSMETIC";
|
||||
Cosmetic currentCosmetic = user.getCosmetic(cosmetic.getSlot());
|
||||
@@ -74,13 +71,10 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
||||
return TranslationUtil.getTranslation("using-cosmetic", String.valueOf(false));
|
||||
}
|
||||
case "current":
|
||||
if (placeholderArgs == null) {
|
||||
return null;
|
||||
}
|
||||
if (placeholderArgs.get(1) != null) {
|
||||
if (placeholderArgs.size() >= 2) {
|
||||
CosmeticSlot slot = CosmeticSlot.valueOf(placeholderArgs.get(1).toUpperCase());
|
||||
if (slot == null) return null;
|
||||
if (user.getCosmetic(slot) == null) return null;
|
||||
if (user.getCosmetic(slot) == null) return TranslationUtil.getTranslation("current-cosmetic", "no-cosmetic");
|
||||
if (placeholderArgs.size() == 2) return user.getCosmetic(slot).getId();
|
||||
|
||||
String output;
|
||||
@@ -104,13 +98,11 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
||||
output = user.getCosmetic(slot).getId();
|
||||
}
|
||||
}
|
||||
return TranslationUtil.getTranslation("current-cosmetic", String.valueOf(output));
|
||||
if (output == null) output = "none";
|
||||
return TranslationUtil.getTranslation("current-cosmetic", output);
|
||||
}
|
||||
case "unlocked":
|
||||
if (placeholderArgs == null) {
|
||||
return null;
|
||||
}
|
||||
if (placeholderArgs.get(1) != null) {
|
||||
if (placeholderArgs.size() >= 2) {
|
||||
Cosmetic cosmetic = Cosmetics.getCosmetic(placeholderArgs.get(1));
|
||||
if (cosmetic == null) {
|
||||
if (placeholderArgs.size() >= 3) {
|
||||
@@ -127,13 +119,11 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
||||
return TranslationUtil.getTranslation("unlocked-cosmetic", String.valueOf(user.canEquipCosmetic(cosmetic, true)));
|
||||
}
|
||||
case "equipped":
|
||||
if (placeholderArgs == null) {
|
||||
return null;
|
||||
}
|
||||
if (placeholderArgs.get(1) != null) {
|
||||
if (placeholderArgs.size() >= 2) {
|
||||
String args1 = placeholderArgs.get(1);
|
||||
|
||||
if (EnumUtils.isValidEnum(CosmeticSlot.class, args1.toUpperCase())) {
|
||||
String rawSlot = args1.toUpperCase();
|
||||
if (CosmeticSlot.contains(rawSlot)) {
|
||||
return TranslationUtil.getTranslation("equipped-cosmetic", String.valueOf(user.getCosmetic(CosmeticSlot.valueOf(args1.toUpperCase())) != null));
|
||||
}
|
||||
|
||||
@@ -156,6 +146,30 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
||||
if (equippedCosmetic == null) return TranslationUtil.getTranslation("equipped-cosmetic", "false");
|
||||
return TranslationUtil.getTranslation("equipped-cosmetic", String.valueOf(cosmetic.getId().equals(equippedCosmetic.getId())));
|
||||
}
|
||||
// %hmccosmetics_amount_balloon_unlocked%
|
||||
case "amount":
|
||||
if (placeholderArgs.size() >= 2) {
|
||||
String args1 = placeholderArgs.get(1).toUpperCase(); // changes offhand to OFFHAND
|
||||
|
||||
if (!CosmeticSlot.contains(args1)) return null;
|
||||
|
||||
CosmeticSlot slot = CosmeticSlot.valueOf(args1);
|
||||
int amount = 0;
|
||||
boolean checkUnlocked = false;
|
||||
if (placeholderArgs.size() >= 3) if (placeholderArgs.get(2).equalsIgnoreCase("unlocked")) checkUnlocked = true;
|
||||
|
||||
for (Cosmetic cosmetic : Cosmetics.values()) {
|
||||
if (cosmetic.getSlot() != slot) continue;
|
||||
if (checkUnlocked && !user.canEquipCosmetic(cosmetic)) continue;
|
||||
amount += 1;
|
||||
}
|
||||
return TranslationUtil.getTranslation("amount-cosmetic", String.valueOf(amount));
|
||||
|
||||
} else {
|
||||
return TranslationUtil.getTranslation("amount-cosmetic", String.valueOf(Cosmetics.values().size()));
|
||||
}
|
||||
case "hidden":
|
||||
return TranslationUtil.getTranslation("hidden", String.valueOf(user.isHidden()));
|
||||
case "wardrobe-enabled":
|
||||
return TranslationUtil.getTranslation("in-wardrobe", String.valueOf(user.isInWardrobe()));
|
||||
}
|
||||
@@ -216,6 +230,7 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
||||
if (!item.hasItemMeta()) return null;
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
if (itemMeta == null) return null;
|
||||
if (!itemMeta.hasDisplayName()) return null;
|
||||
return itemMeta.getDisplayName();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.hooks.placeholders;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
||||
|
||||
/**
|
||||
* A hook that integrates the plugin {@link me.clip.placeholderapi.PlaceholderAPI PlaceholderAPI}
|
||||
*/
|
||||
public class HookPlaceholderAPI extends Hook {
|
||||
public HookPlaceholderAPI() {
|
||||
super("PlaceholderAPI");
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers HMCCosmetics Placeholder Expansion
|
||||
*/
|
||||
@Override
|
||||
public void load() {
|
||||
new HMCPlaceholderExpansion().register();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.hibiscusmc.hmccosmetics.hooks.worldguard;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerEmoteStartEvent;
|
||||
import com.hibiscusmc.hmccosmetics.config.Wardrobe;
|
||||
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
@@ -8,6 +7,7 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||
@@ -20,34 +20,45 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Contains {@link com.sk89q.worldguard.WorldGuard WorldGuard} related event listeners
|
||||
*/
|
||||
public class WGListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerMove(@NotNull PlayerMoveEvent event) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||
Player player = event.getPlayer();
|
||||
Location from = event.getFrom();
|
||||
Location to = event.getTo();
|
||||
if (from.getBlockX() == to.getBlockX() && from.getBlockY() == to.getBlockY() && from.getBlockZ() == to.getBlockZ()) return;
|
||||
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
Location location = event.getPlayer().getLocation();
|
||||
Location location = player.getLocation();
|
||||
ApplicableRegionSet set = getRegions(location);
|
||||
if (user.getHidden()) {
|
||||
if (user.getHiddenReason() == CosmeticUser.HiddenReason.WORLDGUARD && set.getRegions().isEmpty()) {
|
||||
user.showCosmetics();
|
||||
}
|
||||
if (user.isHidden() && set.getRegions().isEmpty()) {
|
||||
user.showCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
|
||||
}
|
||||
|
||||
Set<String> wardrobeNames = WardrobeSettings.getWardrobeNames();
|
||||
for (ProtectedRegion protectedRegion : set.getRegions()) {
|
||||
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticEnableFlag())) {
|
||||
if (protectedRegion.getFlags().get(WGHook.getCosmeticEnableFlag()).toString().equalsIgnoreCase("ALLOW")) {
|
||||
if (user.getHiddenReason() == CosmeticUser.HiddenReason.WORLDGUARD) user.showCosmetics();
|
||||
return;
|
||||
Map<Flag<?>, Object> flags = protectedRegion.getFlags();
|
||||
if (flags.containsKey(WGHook.getCosmeticEnableFlag())) {
|
||||
if (flags.get(WGHook.getCosmeticEnableFlag()).toString().equalsIgnoreCase("ALLOW")) {
|
||||
user.showCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
|
||||
} else {
|
||||
user.hideCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
|
||||
}
|
||||
user.hideCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
|
||||
return;
|
||||
}
|
||||
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticWardrobeFlag())) {
|
||||
if (!WardrobeSettings.getWardrobeNames().contains(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString())) return;
|
||||
Wardrobe wardrobe = WardrobeSettings.getWardrobe(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString());
|
||||
user.enterWardrobe(true, wardrobe);
|
||||
if (flags.containsKey(WGHook.getCosmeticWardrobeFlag())) {
|
||||
String wardrobeName = flags.getOrDefault(WGHook.getCosmeticWardrobeFlag(), "").toString();
|
||||
if (wardrobeName.isEmpty() || !wardrobeNames.contains(wardrobeName)) return;
|
||||
Wardrobe wardrobe = WardrobeSettings.getWardrobe(wardrobeName);
|
||||
if (wardrobe == null) return;
|
||||
user.enterWardrobe(wardrobe, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,15 +69,15 @@ public class WGListener implements Listener {
|
||||
if (user == null) return;
|
||||
Location location = event.getTo();
|
||||
ApplicableRegionSet set = getRegions(location);
|
||||
if (user.getHidden()) {
|
||||
if (user.getHiddenReason() == CosmeticUser.HiddenReason.WORLDGUARD && set.getRegions().isEmpty()) {
|
||||
user.showCosmetics();
|
||||
if (user.isHidden()) {
|
||||
if (set.getRegions().isEmpty()) {
|
||||
user.showCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
|
||||
}
|
||||
}
|
||||
for (ProtectedRegion protectedRegion : set.getRegions()) {
|
||||
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticEnableFlag())) {
|
||||
if (protectedRegion.getFlags().get(WGHook.getCosmeticEnableFlag()).toString().equalsIgnoreCase("ALLOW")) {
|
||||
if (user.getHiddenReason() == CosmeticUser.HiddenReason.WORLDGUARD) user.showCosmetics();
|
||||
user.showCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
|
||||
return;
|
||||
}
|
||||
user.hideCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
|
||||
@@ -75,24 +86,7 @@ public class WGListener implements Listener {
|
||||
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticWardrobeFlag())) {
|
||||
if (!WardrobeSettings.getWardrobeNames().contains(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString())) return;
|
||||
Wardrobe wardrobe = WardrobeSettings.getWardrobe(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString());
|
||||
user.enterWardrobe(true, wardrobe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerEmote(PlayerEmoteStartEvent event) {
|
||||
Player player = event.getUser().getPlayer();
|
||||
if (player == null) return;
|
||||
Location location = player.getLocation();
|
||||
ApplicableRegionSet set = getRegions(location);
|
||||
for (ProtectedRegion protectedRegion : set.getRegions()) {
|
||||
if (protectedRegion.getFlags().containsKey(WGHook.getEmotesEnableFlag())) {
|
||||
if (protectedRegion.getFlags().get(WGHook.getEmotesEnableFlag()).toString().equalsIgnoreCase("DENY")) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
user.enterWardrobe(wardrobe, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.hibiscusmc.hmccosmetics.listener;
|
||||
|
||||
import com.destroystokyo.paper.event.player.PlayerArmorChangeEvent;
|
||||
import com.destroystokyo.paper.event.player.PlayerPostRespawnEvent;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class PaperPlayerGameListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerArmorEquip(PlayerArmorChangeEvent event) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||
if (user == null) return;
|
||||
if (user.isInWardrobe()) return;
|
||||
user.updateCosmetic(slotTypeToCosmeticType(event.getSlotType()));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerRespawn(PlayerPostRespawnEvent event) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||
if (user == null) return;
|
||||
if (user.isInWardrobe()) return;
|
||||
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) user.respawnBackpack();
|
||||
}
|
||||
|
||||
private CosmeticSlot slotTypeToCosmeticType(PlayerArmorChangeEvent.SlotType slotType) {
|
||||
return switch (slotType) {
|
||||
case HEAD -> CosmeticSlot.HELMET;
|
||||
case FEET -> CosmeticSlot.BOOTS;
|
||||
case LEGS -> CosmeticSlot.LEGGINGS;
|
||||
case CHEST -> CosmeticSlot.CHESTPLATE;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +1,18 @@
|
||||
package com.hibiscusmc.hmccosmetics.listener;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerLoadEvent;
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerPreLoadEvent;
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerPreUnloadEvent;
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerUnloadEvent;
|
||||
import com.hibiscusmc.hmccosmetics.config.DatabaseSettings;
|
||||
import com.hibiscusmc.hmccosmetics.database.Database;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -15,48 +20,92 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PlayerConnectionListener implements Listener {
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerConnectionListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerJoin(@NotNull PlayerJoinEvent event) {
|
||||
if (event.getPlayer().isOp() || event.getPlayer().hasPermission("hmccosmetics.notifyupdate")) {
|
||||
if (!HMCCosmeticsPlugin.getLatestVersion().equalsIgnoreCase(HMCCosmeticsPlugin.getInstance().getDescription().getVersion()) && HMCCosmeticsPlugin.getLatestVersion().isEmpty())
|
||||
MessagesUtil.sendMessageNoKey(
|
||||
event.getPlayer(),
|
||||
"<br>" +
|
||||
"<GRAY>There is a new version of <light_purple><Bold>HMCCosmetics<reset><gray> available!<br>" +
|
||||
"<GRAY>Current version: <red>" + HMCCosmeticsPlugin.getInstance().getDescription().getVersion() + " <GRAY>| Latest version: <light_purple>" + HMCCosmeticsPlugin.getLatestVersion() + "<br>" +
|
||||
"<GRAY>Download it on <gold><click:OPEN_URL:'https://www.spigotmc.org/resources/100107/'>Spigot<reset> <gray>or <gold><click:OPEN_URL:'https://polymart.org/resource/1879'>Polymart<reset><gray>!" +
|
||||
"<br>"
|
||||
);
|
||||
}
|
||||
|
||||
Runnable run = () -> {
|
||||
CosmeticUser user = Database.get(event.getPlayer().getUniqueId());
|
||||
CosmeticUsers.addUser(user);
|
||||
MessagesUtil.sendDebugMessages("Run User Join");
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> user.updateCosmetic(), 4);
|
||||
};
|
||||
|
||||
if (DatabaseSettings.isEnabledDelay()) {
|
||||
MessagesUtil.sendDebugMessages("Delay Enabled with " + DatabaseSettings.getDelayLength() + " ticks");
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), run, DatabaseSettings.getDelayLength());
|
||||
Bukkit.getScheduler().runTaskLater(
|
||||
HMCCosmeticsPlugin.getInstance(),
|
||||
() -> this.loadUserData(event.getPlayer()),
|
||||
DatabaseSettings.getDelayLength()
|
||||
);
|
||||
} else {
|
||||
run.run();
|
||||
this.loadUserData(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
private void loadUserData(final Player player) {
|
||||
if(!player.isOnline()) return;
|
||||
final UUID playerId = player.getUniqueId();
|
||||
|
||||
PlayerPreLoadEvent preLoadEvent = new PlayerPreLoadEvent(playerId);
|
||||
Bukkit.getPluginManager().callEvent(preLoadEvent);
|
||||
if (preLoadEvent.isCancelled()) return;
|
||||
|
||||
Database.get(playerId).thenAccept(userData -> {
|
||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
CosmeticUser cosmeticUser = CosmeticUsers.getProvider()
|
||||
.createCosmeticUser(playerId)
|
||||
.initialize(userData);
|
||||
cosmeticUser.startTicking();
|
||||
|
||||
CosmeticUsers.addUser(cosmeticUser);
|
||||
MessagesUtil.sendDebugMessages("Run User Join for " + playerId);
|
||||
|
||||
PlayerLoadEvent playerLoadEvent = new PlayerLoadEvent(cosmeticUser);
|
||||
Bukkit.getPluginManager().callEvent(playerLoadEvent);
|
||||
|
||||
// And finally, launch an update for the cosmetics they have.
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
if (cosmeticUser.getPlayer() == null) return;
|
||||
cosmeticUser.updateCosmetic();
|
||||
}, 4);
|
||||
});
|
||||
}).exceptionally(ex -> {
|
||||
MessagesUtil.sendDebugMessages("Unable to load Cosmetic User " + playerId + ". Exception: " + ex.getMessage());
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerQuit(@NotNull PlayerQuitEvent event) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||
if (user == null) return; // Player never initialized, don't do anything
|
||||
if (user.isInWardrobe()) user.leaveWardrobe();
|
||||
if (user.getUserEmoteManager().isPlayingEmote()) {
|
||||
user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.CONNECTION);
|
||||
event.getPlayer().setInvisible(false);
|
||||
|
||||
PlayerPreUnloadEvent preUnloadEvent = new PlayerPreUnloadEvent(user);
|
||||
Bukkit.getPluginManager().callEvent(preUnloadEvent);
|
||||
if (preUnloadEvent.isCancelled()) return;
|
||||
|
||||
PlayerUnloadEvent playerUnloadEvent = new PlayerUnloadEvent(user);
|
||||
Bukkit.getPluginManager().callEvent(playerUnloadEvent);
|
||||
|
||||
if (user.isInWardrobe()) {
|
||||
user.leaveWardrobe(true);
|
||||
|
||||
final Player player = user.getPlayer();
|
||||
if(player != null) player.setInvisible(false);
|
||||
}
|
||||
Menus.removeCooldown(event.getPlayer().getUniqueId()); // Removes any menu cooldowns a player might have
|
||||
Database.save(user);
|
||||
user.destroy();
|
||||
CosmeticUsers.removeUser(user.getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void notifyAdminUpdate(final PlayerJoinEvent event) {
|
||||
if (event.getPlayer().isOp() || event.getPlayer().hasPermission("hmccosmetics.notifyupdate")) {
|
||||
if (!HMCCosmeticsPlugin.getInstance().getLatestVersion().equalsIgnoreCase(HMCCosmeticsPlugin.getInstance().getDescription().getVersion()) && HMCCosmeticsPlugin.getInstance().getLatestVersion().isEmpty())
|
||||
MessagesUtil.sendMessageNoKey(
|
||||
event.getPlayer(),
|
||||
"<br>" +
|
||||
"<GRAY>There is a new version of <light_purple><Bold>HMCCosmetics<reset><gray> available!<br>" +
|
||||
"<GRAY>Current version: <red>" + HMCCosmeticsPlugin.getInstance().getDescription().getVersion() + " <GRAY>| Latest version: <light_purple>" + HMCCosmeticsPlugin.getInstance().getLatestVersion() + "<br>" +
|
||||
"<GRAY>Download it on <gold><click:OPEN_URL:'https://www.spigotmc.org/resources/100107/'>Spigot<reset> <gray>or <gold><click:OPEN_URL:'https://polymart.org/resource/1879'>Polymart<reset><gray>!" +
|
||||
"<br>"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,26 @@
|
||||
package com.hibiscusmc.hmccosmetics.listener;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
import com.comphenix.protocol.wrappers.Pair;
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerCosmeticPostEquipEvent;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticEmoteType;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
|
||||
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserWardrobeManager;
|
||||
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
|
||||
import me.lojosho.hibiscuscommons.api.events.*;
|
||||
import me.lojosho.hibiscuscommons.nms.MinecraftVersion;
|
||||
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
||||
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@@ -47,27 +42,11 @@ import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spigotmc.event.entity.EntityDismountEvent;
|
||||
import org.spigotmc.event.entity.EntityMountEvent;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class PlayerGameListener implements Listener {
|
||||
|
||||
public PlayerGameListener() {
|
||||
registerInventoryClickListener();
|
||||
registerMenuChangeListener();
|
||||
registerEntityStatusListener();
|
||||
registerPlayerEquipmentListener();
|
||||
registerPlayerArmListener();
|
||||
registerEntityUseListener();
|
||||
registerSlotChangeListener();
|
||||
|
||||
//registerLookMovement();
|
||||
//registerMoveListener();
|
||||
//registerTeleportMovement();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerClick(@NotNull InventoryClickEvent event) {
|
||||
// || !event.getClickedInventory().getType().equals(InventoryType.PLAYER)
|
||||
@@ -79,14 +58,14 @@ public class PlayerGameListener implements Listener {
|
||||
ItemStack item = event.getCurrentItem();
|
||||
if (item == null) return;
|
||||
|
||||
if (Settings.isDestroyLooseCosmetics() && InventoryUtils.isCosmeticItem(event.getCurrentItem())) {
|
||||
if (Settings.isDestroyLooseCosmetics() && HMCCInventoryUtils.isCosmeticItem(event.getCurrentItem())) {
|
||||
MessagesUtil.sendDebugMessages("remvoe item");
|
||||
event.getWhoClicked().getInventory().removeItem(event.getCurrentItem());
|
||||
}
|
||||
|
||||
EquipmentSlot slot = getArmorSlot(item.getType());
|
||||
if (slot == null) return;
|
||||
CosmeticSlot cosmeticSlot = InventoryUtils.BukkitCosmeticSlot(slot);
|
||||
CosmeticSlot cosmeticSlot = HMCCInventoryUtils.BukkitCosmeticSlot(slot);
|
||||
if (cosmeticSlot == null) return;
|
||||
if (!user.hasCosmeticInSlot(cosmeticSlot)) return;
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
@@ -100,17 +79,13 @@ public class PlayerGameListener implements Listener {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
|
||||
|
||||
if (user == null) return;
|
||||
if (event.isSneaking()) {
|
||||
user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.SNEAK);
|
||||
}
|
||||
|
||||
if (!event.isSneaking()) return;
|
||||
if (!user.isInWardrobe()) return;
|
||||
|
||||
user.leaveWardrobe();
|
||||
user.leaveWardrobe(false);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
|
||||
|
||||
@@ -121,10 +96,16 @@ public class PlayerGameListener implements Listener {
|
||||
}
|
||||
|
||||
if (user.isInWardrobe()) {
|
||||
user.leaveWardrobe();
|
||||
user.leaveWardrobe(false);
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
if (user.getEntity() == null || user.isInWardrobe()) return; // fixes disconnecting when in wardrobe (the entity stuff)
|
||||
if (Settings.getDisabledWorlds().contains(user.getEntity().getLocation().getWorld().getName())) {
|
||||
user.hideCosmetics(CosmeticUser.HiddenReason.WORLD);
|
||||
} else {
|
||||
user.showCosmetics(CosmeticUser.HiddenReason.WORLD);
|
||||
}
|
||||
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK) && user.getUserBackpackManager() != null) {
|
||||
user.respawnBackpack();
|
||||
}
|
||||
@@ -132,15 +113,12 @@ public class PlayerGameListener implements Listener {
|
||||
user.respawnBalloon();
|
||||
}
|
||||
user.updateCosmetic();
|
||||
}, 1);
|
||||
}, 2);
|
||||
|
||||
if (event.getCause().equals(PlayerTeleportEvent.TeleportCause.NETHER_PORTAL) || event.getCause().equals(PlayerTeleportEvent.TeleportCause.END_PORTAL)) return;
|
||||
if (user.getUserEmoteManager().isPlayingEmote()) {
|
||||
user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.TELEPORT);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onPortalTeleport(PlayerPortalEvent event) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
|
||||
|
||||
@@ -150,6 +128,12 @@ public class PlayerGameListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Settings.getDisabledWorlds().contains(user.getEntity().getLocation().getWorld().getName())) {
|
||||
user.hideCosmetics(CosmeticUser.HiddenReason.WORLD);
|
||||
} else {
|
||||
user.showCosmetics(CosmeticUser.HiddenReason.WORLD);
|
||||
}
|
||||
|
||||
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
||||
user.despawnBalloon();
|
||||
|
||||
@@ -163,7 +147,6 @@ public class PlayerGameListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerHit(EntityDamageByEntityEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
if (event.getEntity().getEntityId() == event.getDamager().getEntityId()) event.setCancelled(true);
|
||||
if (!entity.getPersistentDataContainer().has(new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "cosmeticMob"), PersistentDataType.SHORT))
|
||||
return;
|
||||
event.setCancelled(true);
|
||||
@@ -174,37 +157,29 @@ public class PlayerGameListener implements Listener {
|
||||
if (!(event.getEntity() instanceof Player player)) return;
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
if (user.getUserEmoteManager().isPlayingEmote()) {
|
||||
if (Settings.isEmoteInvincible()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
if (Settings.isEmoteDamageLeave()) {
|
||||
user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.DAMAGE);
|
||||
}
|
||||
}
|
||||
if (user.isInWardrobe()) {
|
||||
user.leaveWardrobe();
|
||||
if (WardrobeSettings.isPreventDamage()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (WardrobeSettings.isDamagedKicked()) user.leaveWardrobe(false);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onPlayerLook(PlayerMoveEvent event) {
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
if (!Settings.isEmoteMoveCheck() && user.getUserEmoteManager().isPlayingEmote()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
user.updateCosmetic(CosmeticSlot.BACKPACK);
|
||||
user.updateCosmetic(CosmeticSlot.BALLOON);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerPoseChange(EntityPoseChangeEvent event) {
|
||||
if (!(event.getEntity() instanceof Player player)) return;
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
if (user == null || user.isInWardrobe()) return;
|
||||
if (!user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) return;
|
||||
Pose pose = event.getPose();
|
||||
if (pose.equals(Pose.STANDING)) {
|
||||
@@ -241,7 +216,7 @@ public class PlayerGameListener implements Listener {
|
||||
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
|
||||
if (user == null) return;
|
||||
CosmeticSlot cosmeticSlot = InventoryUtils.BukkitCosmeticSlot(slot);
|
||||
CosmeticSlot cosmeticSlot = HMCCInventoryUtils.BukkitCosmeticSlot(slot);
|
||||
|
||||
if (!user.hasCosmeticInSlot(cosmeticSlot)) {
|
||||
MessagesUtil.sendDebugMessages("No cosmetic in " + cosmeticSlot);
|
||||
@@ -259,18 +234,13 @@ public class PlayerGameListener implements Listener {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
|
||||
if (user == null) return;
|
||||
// Really need to look into optimization of this
|
||||
if (user.hasCosmeticInSlot(CosmeticSlot.EMOTE) && event.getPlayer().isSneaking() && event.getPlayer().hasPermission("hmccosmetics.emote.shiftrun")) {
|
||||
CosmeticEmoteType cosmeticEmoteType = (CosmeticEmoteType) user.getCosmetic(CosmeticSlot.EMOTE);
|
||||
cosmeticEmoteType.run(user);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
if (user.getEntity() == null) return; // Player has likely logged off
|
||||
user.updateCosmetic(CosmeticSlot.OFFHAND);
|
||||
List<Player> viewers = PacketManager.getViewers(user.getEntity().getLocation());
|
||||
List<Player> viewers = HMCCPacketManager.getViewers(user.getEntity().getLocation());
|
||||
if (viewers.isEmpty()) return;
|
||||
viewers.remove(user.getPlayer());
|
||||
NMSHandlers.getHandler().equipmentSlotUpdate(user.getEntity().getEntityId(), EquipmentSlot.HAND, event.getPlayer().getInventory().getItemInMainHand(), viewers);
|
||||
PacketManager.equipmentSlotUpdate(user.getEntity().getEntityId(), EquipmentSlot.HAND, event.getPlayer().getInventory().getItemInMainHand(), viewers);
|
||||
}, 2);
|
||||
}
|
||||
|
||||
@@ -294,7 +264,7 @@ public class PlayerGameListener implements Listener {
|
||||
return;
|
||||
}
|
||||
if (event.getAction().equals(EntityPotionEffectEvent.Action.CLEARED) || event.getAction().equals(EntityPotionEffectEvent.Action.REMOVED)) {
|
||||
user.showCosmetics();
|
||||
user.showCosmetics(CosmeticUser.HiddenReason.POTION);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -304,11 +274,12 @@ public class PlayerGameListener implements Listener {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||
if (user == null) return;
|
||||
|
||||
event.getPlayer().getInventory().setItem(event.getPreviousSlot(), event.getPlayer().getInventory().getItem(event.getPreviousSlot()));
|
||||
//NMSHandlers.getHandler().slotUpdate(event.getPlayer(), event.getPreviousSlot());
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
user.updateCosmetic(CosmeticSlot.MAINHAND);
|
||||
}, 2);
|
||||
if (user.hasCosmeticInSlot(CosmeticSlot.MAINHAND)) {
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
user.updateCosmetic(CosmeticSlot.MAINHAND);
|
||||
}, 2);
|
||||
}
|
||||
|
||||
// #84, Riptides mess with backpacks
|
||||
ItemStack currentItem = event.getPlayer().getInventory().getItem(event.getNewSlot());
|
||||
@@ -324,7 +295,7 @@ public class PlayerGameListener implements Listener {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getEntity());
|
||||
if (user == null) return;
|
||||
|
||||
if (user.isInWardrobe()) user.leaveWardrobe();
|
||||
if (user.isInWardrobe()) user.leaveWardrobe(false);
|
||||
|
||||
if (Settings.isUnapplyOnDeath() && !event.getEntity().hasPermission("hmccosmetics.unapplydeath.bypass")) {
|
||||
user.removeCosmetics();
|
||||
@@ -335,12 +306,21 @@ public class PlayerGameListener implements Listener {
|
||||
public void onPlayerGamemodeSwitch(PlayerGameModeChangeEvent event) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||
if (user == null) return;
|
||||
if (user.isInWardrobe()) user.leaveWardrobe(true);
|
||||
|
||||
if (Settings.isDisabledGamemodesEnabled()) {
|
||||
if (Settings.getDisabledGamemodes().contains(event.getNewGameMode().toString())) {
|
||||
user.hideCosmetics(CosmeticUser.HiddenReason.GAMEMODE);
|
||||
} else {
|
||||
user.showCosmetics(CosmeticUser.HiddenReason.GAMEMODE);
|
||||
}
|
||||
}
|
||||
|
||||
if (Settings.isDestroyLooseCosmetics()) {
|
||||
ItemStack[] equippedArmor = event.getPlayer().getInventory().getArmorContents();
|
||||
if (equippedArmor.length == 0) return;
|
||||
for (ItemStack armor : equippedArmor) {
|
||||
if (InventoryUtils.isCosmeticItem(armor)) armor.setAmount(0);
|
||||
if (HMCCInventoryUtils.isCosmeticItem(armor)) armor.setAmount(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -349,11 +329,18 @@ public class PlayerGameListener implements Listener {
|
||||
public void onPlayerCosmeticEquip(PlayerCosmeticPostEquipEvent event) {
|
||||
CosmeticUser user = event.getUser();
|
||||
if (user.isInWardrobe() && event.getCosmetic().getSlot().equals(CosmeticSlot.BALLOON)) {
|
||||
Location NPCLocation = user.getWardrobeManager().getNpcLocation();
|
||||
if (user.getBalloonManager() == null) {
|
||||
MessagesUtil.sendDebugMessages("Balloon Manager is null? " + user.getEntity().getName());
|
||||
return;
|
||||
}
|
||||
CosmeticBalloonType cosmetic = (CosmeticBalloonType) event.getCosmetic();
|
||||
Location npclocation = user.getWardrobeManager().getNpcLocation().clone().add(cosmetic.getBalloonOffset());
|
||||
// We know that no other entity besides a regular player will be in the wardrobe
|
||||
PacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), NPCLocation.add(cosmetic.getBalloonOffset()), false, List.of(user.getPlayer()));
|
||||
user.getBalloonManager().getModelEntity().teleport(NPCLocation.add(cosmetic.getBalloonOffset()));
|
||||
List<Player> viewer = List.of(user.getPlayer());
|
||||
user.getBalloonManager().getPufferfish().spawnPufferfish(npclocation.clone().add(cosmetic.getBalloonOffset()), viewer);
|
||||
HMCCPacketManager.sendLeashPacket(user.getBalloonManager().getPufferfishBalloonId(), user.getWardrobeManager().getNPC_ID(), viewer);
|
||||
HMCCPacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), npclocation, false, viewer);
|
||||
user.getBalloonManager().getModelEntity().teleport(npclocation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -377,268 +364,57 @@ public class PlayerGameListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private void registerInventoryClickListener() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.WINDOW_CLICK) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
int invTypeClicked = event.getPacket().getIntegers().read(0);
|
||||
int slotClicked = event.getPacket().getIntegers().read(2);
|
||||
|
||||
// Must be a player inventory.
|
||||
if (invTypeClicked != 0) return;
|
||||
// -999 is when a player clicks outside their inventory. https://wiki.vg/Inventory#Player_Inventory
|
||||
if (slotClicked == -999) return;
|
||||
if (event.getPlayer() == null) return;
|
||||
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
CosmeticSlot cosmeticSlot = InventoryUtils.NMSCosmeticSlot(slotClicked);
|
||||
if (cosmeticSlot == null) return;
|
||||
if (!user.hasCosmeticInSlot(cosmeticSlot)) return;
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> user.updateCosmetic(cosmeticSlot), 1);
|
||||
MessagesUtil.sendDebugMessages("Packet fired, updated cosmetic " + cosmeticSlot);
|
||||
}
|
||||
});
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onPlayerVanish(HibiscusPlayerVanishEvent event) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||
if (user == null) return;
|
||||
user.hideCosmetics(CosmeticUser.HiddenReason.PLUGIN);
|
||||
}
|
||||
|
||||
private void registerMenuChangeListener() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.WINDOW_ITEMS) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
MessagesUtil.sendDebugMessages("Menu Initial ");
|
||||
Player player = event.getPlayer();
|
||||
if (event.getPlayer() == null) return;
|
||||
|
||||
int windowID = event.getPacket().getIntegers().read(0);
|
||||
List<ItemStack> slotData = event.getPacket().getItemListModifier().read(0);
|
||||
if (windowID != 0) return;
|
||||
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
|
||||
HashMap<Integer, ItemStack> items = new HashMap<>();
|
||||
|
||||
for (Cosmetic cosmetic : user.getCosmetics()) {
|
||||
if ((cosmetic instanceof CosmeticArmorType cosmeticArmorType)) {
|
||||
items.put(InventoryUtils.getPacketArmorSlot(cosmeticArmorType.getEquipSlot()), user.getUserCosmeticItem(cosmeticArmorType));
|
||||
}
|
||||
}
|
||||
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.WINDOW_ITEMS);
|
||||
packet.getIntegers().write(0, 0);
|
||||
for (int slot = 0; slot < 46; slot++) {
|
||||
if ((slot >= 5 && slot <= 8) || slot == 45) {
|
||||
if (!items.containsKey(slot)) continue;
|
||||
slotData.set(slot, items.get(slot));
|
||||
MessagesUtil.sendDebugMessages("Set " + slot + " as " + items.get(slot));
|
||||
}
|
||||
}
|
||||
packet.getItemListModifier().write(0, slotData);
|
||||
packet.getItemModifier().write(0, event.getPacket().getItemModifier().read(0));
|
||||
event.setPacket(packet);
|
||||
MessagesUtil.sendDebugMessages("Menu Fired, updated cosmetics " + " on slotdata " + windowID + " with " + slotData.size());
|
||||
/*
|
||||
for (Cosmetic cosmetic : user.getCosmetic()) {
|
||||
if ((cosmetic instanceof CosmeticArmorType) || (cosmetic instanceof CosmeticMainhandType)) {
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
user.updateCosmetic(cosmetic);
|
||||
}, 1);
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
});
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onPlayerUnVanish(HibiscusPlayerUnVanishEvent event) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||
if (user == null) return;
|
||||
if (!user.isHidden()) return;
|
||||
user.showCosmetics(CosmeticUser.HiddenReason.PLUGIN);
|
||||
}
|
||||
|
||||
private void registerSlotChangeListener() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.SET_SLOT) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
MessagesUtil.sendDebugMessages("SetSlot Initial ");
|
||||
|
||||
Player player = event.getPlayer();
|
||||
if (event.getPlayer() == null) return;
|
||||
|
||||
int windowID = event.getPacket().getIntegers().read(0);
|
||||
if (windowID != 0) return;
|
||||
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
|
||||
int slot = event.getPacket().getIntegers().read(2);
|
||||
MessagesUtil.sendDebugMessages("SetSlot Slot " + slot);
|
||||
if (slot == 45 && user.hasCosmeticInSlot(CosmeticSlot.OFFHAND) && player.getInventory().getItemInOffHand().getType().isAir()) {
|
||||
event.getPacket().getItemModifier().write(0, user.getUserCosmeticItem(CosmeticSlot.OFFHAND));
|
||||
}
|
||||
}
|
||||
});
|
||||
// These emote mostly handles emotes from other plugins, such as ItemsAdder
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onPlayerPlayEmote(HibiscusPlayerEmotePlayEvent event) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||
if (user == null) return;
|
||||
user.hideCosmetics(CosmeticUser.HiddenReason.EMOTE);
|
||||
}
|
||||
|
||||
private void registerPlayerEquipmentListener() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.ENTITY_EQUIPMENT) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
Player player = event.getPlayer(); // Player that's sent
|
||||
int entityID = event.getPacket().getIntegers().read(0);
|
||||
// User
|
||||
CosmeticUser user = CosmeticUsers.getUser(entityID);
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
List<com.comphenix.protocol.wrappers.Pair<EnumWrappers.ItemSlot, ItemStack>> armor = event.getPacket().getSlotStackPairLists().read(0);
|
||||
|
||||
for (int i = 0; i < armor.size(); i++) {
|
||||
com.comphenix.protocol.wrappers.Pair<EnumWrappers.ItemSlot, ItemStack> pair = armor.get(i);
|
||||
switch (pair.getFirst()) {
|
||||
case MAINHAND -> {
|
||||
if (user.getPlayer() == event.getPlayer()) continue; // When a player scrolls real fast, it messes up the mainhand. This fixes it
|
||||
armor.set(i, new Pair<>(pair.getFirst(), user.getPlayer().getInventory().getItemInMainHand()));
|
||||
}
|
||||
case OFFHAND -> {
|
||||
if (Settings.isCosmeticForceOffhandCosmeticShow() && user.hasCosmeticInSlot(CosmeticSlot.OFFHAND)) {
|
||||
ItemStack item = user.getUserCosmeticItem(CosmeticSlot.OFFHAND);
|
||||
if (item == null) continue;
|
||||
Pair<EnumWrappers.ItemSlot, ItemStack> offhandPair = new Pair<>(EnumWrappers.ItemSlot.OFFHAND, item);
|
||||
armor.set(i, offhandPair);
|
||||
}
|
||||
}
|
||||
default -> {
|
||||
CosmeticArmorType cosmeticArmor = (CosmeticArmorType) user.getCosmetic(InventoryUtils.getItemSlotToCosmeticSlot(pair.getFirst()));
|
||||
if (cosmeticArmor == null) continue;
|
||||
ItemStack item = user.getUserCosmeticItem(cosmeticArmor);
|
||||
if (item == null) continue;
|
||||
Pair<EnumWrappers.ItemSlot, ItemStack> armorPair = new Pair<>(InventoryUtils.itemBukkitSlot(cosmeticArmor.getEquipSlot()), item);
|
||||
armor.set(i, armorPair);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
event.getPacket().getSlotStackPairLists().write(0, armor);
|
||||
MessagesUtil.sendDebugMessages("Equipment for " + user.getPlayer().getName() + " has been updated for " + player.getName());
|
||||
}
|
||||
});
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerEndEmote(HibiscusPlayerEmoteEndEvent event) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||
if (user == null) return;
|
||||
user.showCosmetics(CosmeticUser.HiddenReason.EMOTE);
|
||||
}
|
||||
|
||||
private void registerEntityStatusListener() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.ENTITY_STATUS) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
int entityid = event.getPacket().getIntegers().read(0);
|
||||
byte status = event.getPacket().getBytes().read(0);
|
||||
|
||||
MessagesUtil.sendDebugMessages("EntityStatus Initial " + entityid + " - " + status);
|
||||
if (status != 55) return;
|
||||
|
||||
CosmeticUser user = CosmeticUsers.getUser(entityid);
|
||||
if (user == null) {
|
||||
MessagesUtil.sendDebugMessages("EntityStatus User is null");
|
||||
return;
|
||||
}
|
||||
if (!user.hasCosmeticInSlot(CosmeticSlot.OFFHAND)) return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
});
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerHibiscusPose(HibiscusPlayerPoseEvent event) {
|
||||
if (event.isGettingUp()) return;
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||
if (user == null) return;
|
||||
user.hideCosmetics(CosmeticUser.HiddenReason.PLUGIN);
|
||||
}
|
||||
|
||||
private void registerPlayerArmListener() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.ARM_ANIMATION) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
if (event.getPlayer() == null) return;
|
||||
Player player = event.getPlayer();
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
if (user.getUserEmoteManager().isPlayingEmote()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (!user.isInWardrobe()) return;
|
||||
Menu menu = Menus.getDefaultMenu();
|
||||
if (menu == null) return;
|
||||
menu.openMenu(user);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
});
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerHibiscusGetUpPose(HibiscusPlayerPoseEvent event) {
|
||||
if (!event.isGettingUp()) return;
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||
if (user == null) return;
|
||||
user.showCosmetics(CosmeticUser.HiddenReason.PLUGIN);
|
||||
}
|
||||
|
||||
private void registerEntityUseListener() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.USE_ENTITY) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
if (event.getPlayer() == null) return;
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||
if (user == null) return;
|
||||
if (user.getUserEmoteManager().isPlayingEmote() || user.isInWardrobe()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void registerLookMovement() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.LOOK) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
// TODO: Finish
|
||||
MessagesUtil.sendDebugMessages("Look Packet ");
|
||||
Player player = event.getPlayer();
|
||||
if (event.getPlayer() == null) return;
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
if (user.isBackpackSpawned()) {
|
||||
user.getUserBackpackManager().getEntityManager().setRotation(Math.round(event.getPacket().getFloat().read(0)));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void registerMoveListener() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.POSITION) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
// TODO: Finish
|
||||
MessagesUtil.sendDebugMessages("Position Packet ");
|
||||
Player player = event.getPlayer();
|
||||
if (event.getPlayer() == null) return;
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
if (user.isBackpackSpawned()) {
|
||||
// The yaw follows the head, which makes it look weird and do weird things when moving around
|
||||
user.getUserBackpackManager().getEntityManager().teleport(new Location(player.getWorld(), event.getPacket().getDoubles().read(0), event.getPacket().getDoubles().read(1), event.getPacket().getDoubles().read(2), event.getPacket().getFloat().read(0), event.getPacket().getFloat().read(1)));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void registerTeleportMovement() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.POSITION_LOOK) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
// TODO: Finish
|
||||
MessagesUtil.sendDebugMessages("Teleport Packet ");
|
||||
Player player = event.getPlayer();
|
||||
if (event.getPlayer() == null) return;
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
if (user.isBackpackSpawned()) {
|
||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> user.updateCosmetic(CosmeticSlot.BACKPACK));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Nullable
|
||||
private EquipmentSlot getArmorSlot(final Material material) {
|
||||
for (final EquipmentSlot slot : EquipmentSlot.values()) {
|
||||
final Set<Material> armorItems = ARMOR_ITEMS.get(slot);
|
||||
if (armorItems == null) continue;
|
||||
if (material == null) continue;
|
||||
if (armorItems.contains(material)) return slot;
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.hibiscusmc.hmccosmetics.listener;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import me.lojosho.hibiscuscommons.api.events.HibiscusHookReload;
|
||||
import me.lojosho.hibiscuscommons.api.events.HibiscusHooksAllActiveEvent;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hook;
|
||||
import me.lojosho.hibiscuscommons.hooks.items.HookItemAdder;
|
||||
import me.lojosho.hibiscuscommons.hooks.items.HookNexo;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ServerListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onHookReload(@NotNull HibiscusHookReload event) {
|
||||
final Hook hook = event.getHook();
|
||||
final HibiscusHookReload.ReloadType reloadType = event.getReloadType();
|
||||
|
||||
if (hook instanceof HookItemAdder) {
|
||||
if (reloadType == HibiscusHookReload.ReloadType.RELOAD) {
|
||||
if (!Settings.isItemsAdderChangeReload()) return;
|
||||
HMCCosmeticsPlugin.setup();
|
||||
}
|
||||
}
|
||||
if (hook instanceof HookNexo) {
|
||||
if (reloadType == HibiscusHookReload.ReloadType.RELOAD) {
|
||||
if (!Settings.isNexoChangeReload()) return;
|
||||
HMCCosmeticsPlugin.setup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onAllHooksReady(@NotNull HibiscusHooksAllActiveEvent event) {
|
||||
HMCCosmeticsPlugin.setup();
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.nms;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface NMSHandler {
|
||||
|
||||
int getNextEntityId();
|
||||
|
||||
Entity getEntity(int entityId);
|
||||
|
||||
ArmorStand getMEGEntity(Location loc);
|
||||
|
||||
Entity spawnDisplayEntity(Location location, String text);
|
||||
|
||||
UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType);
|
||||
|
||||
void slotUpdate(
|
||||
Player player,
|
||||
int slot
|
||||
);
|
||||
|
||||
void equipmentSlotUpdate(
|
||||
int entityId,
|
||||
org.bukkit.inventory.EquipmentSlot slot,
|
||||
ItemStack item,
|
||||
List<Player> sendTo
|
||||
);
|
||||
|
||||
void hideNPCName(
|
||||
Player player,
|
||||
String NPCName);
|
||||
|
||||
default boolean getSupported () {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.nms;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class NMSHandlers {
|
||||
|
||||
private static final String[] SUPPORTED_VERSION = new String[]{"v1_18_R2", "v1_19_R1", "v1_19_R2", "v1_19_R3", "v1_20_R1"};
|
||||
private static NMSHandler handler;
|
||||
@Getter
|
||||
private static String version;
|
||||
|
||||
public static NMSHandler getHandler() {
|
||||
if (handler != null) {
|
||||
return handler;
|
||||
} else {
|
||||
setup();
|
||||
}
|
||||
return handler;
|
||||
}
|
||||
|
||||
public static void setup() {
|
||||
if (handler != null) return;
|
||||
final String packageName = HMCCosmeticsPlugin.getInstance().getServer().getClass().getPackage().getName();
|
||||
String packageVersion = packageName.substring(packageName.lastIndexOf('.') + 1);
|
||||
|
||||
for (String selectedVersion : SUPPORTED_VERSION) {
|
||||
if (!selectedVersion.contains(packageVersion)) {
|
||||
continue;
|
||||
}
|
||||
MessagesUtil.sendDebugMessages(packageVersion + " has been detected.", Level.INFO);
|
||||
version = packageVersion;
|
||||
try {
|
||||
handler = (NMSHandler) Class.forName("com.hibiscusmc.hmccosmetics.nms." + packageVersion + ".NMSHandler").getConstructor().newInstance();
|
||||
return;
|
||||
} catch (ClassNotFoundException | InvocationTargetException | InstantiationException |
|
||||
IllegalAccessException | NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user