mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-19 15:09:19 +00:00
Compare commits
428 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e2b2edadd | ||
|
|
7e384fcd79 | ||
|
|
e88b84610e | ||
|
|
223ffa46eb | ||
|
|
f408108682 | ||
|
|
b9f9448367 | ||
|
|
c40aca9946 | ||
|
|
98d2692def | ||
|
|
ebbc80c465 | ||
|
|
775699d9ca | ||
|
|
b0ba5fc011 | ||
|
|
af01ff600b | ||
|
|
2e4619da02 | ||
|
|
b4bd08c249 | ||
|
|
19981b33d3 | ||
|
|
c7c4c0e583 | ||
|
|
935c157421 | ||
|
|
20a3a508c2 | ||
|
|
92b75c43ab | ||
|
|
a6ad2c19aa | ||
|
|
fe8b4c97ff | ||
|
|
8c119c78db | ||
|
|
ce33a72fc2 | ||
|
|
2a8f30636d | ||
|
|
4103c2c232 | ||
|
|
fb5c9d205c | ||
|
|
126d576303 | ||
|
|
c74b76837b | ||
|
|
d2c37f8273 | ||
|
|
dbadbda82f | ||
|
|
d66aa3b79c | ||
|
|
1c5cd7b467 | ||
|
|
10f8dda150 | ||
|
|
e76aa0783e | ||
|
|
0676125f07 | ||
|
|
7aef681149 | ||
|
|
d5ac55f266 | ||
|
|
c2b787c97c | ||
|
|
732c3de0d8 | ||
|
|
3843a28804 | ||
|
|
a63494ba9f | ||
|
|
c7e6a77eb8 | ||
|
|
075d2b3182 | ||
|
|
515de7d2c8 | ||
|
|
429287c9f3 | ||
|
|
fed13b8ee6 | ||
|
|
8011dda200 | ||
|
|
7abfb0edf1 | ||
|
|
1f8c772712 | ||
|
|
7d727bb68f | ||
|
|
007f27f109 | ||
|
|
e0e0d0c997 | ||
|
|
75a1458ae1 | ||
|
|
548b15d99d | ||
|
|
50f04373b7 | ||
|
|
27a6c1bd54 | ||
|
|
bb08fb108c | ||
|
|
3907bc5839 | ||
|
|
1ef7f4759f | ||
|
|
937f66e8c5 | ||
|
|
158f3afdec | ||
|
|
38bdc01e9f | ||
|
|
797992362a | ||
|
|
9716a079be | ||
|
|
dfe51ba5b8 | ||
|
|
f5e81446a6 | ||
|
|
c99a57a6bf | ||
|
|
79630263f2 | ||
|
|
478c4280c1 | ||
|
|
4fd439acc4 | ||
|
|
58c955a00f | ||
|
|
2f9325b2fb | ||
|
|
823270648b | ||
|
|
d5e988261b | ||
|
|
13303096ec | ||
|
|
3ee79e8443 | ||
|
|
7785556967 | ||
|
|
1296ca6e92 | ||
|
|
f56d5c9093 | ||
|
|
bae04fba3f | ||
|
|
cbe5404399 | ||
|
|
dc4098782a | ||
|
|
2eb0b26fb3 | ||
|
|
22159fa9f4 | ||
|
|
539c09801c | ||
|
|
bed5cd7bbb | ||
|
|
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 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -115,3 +115,4 @@ run/
|
|||||||
|
|
||||||
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
||||||
!gradle-wrapper.jar
|
!gradle-wrapper.jar
|
||||||
|
/qodana.yaml
|
||||||
|
|||||||
173
build.gradle.kts
173
build.gradle.kts
@@ -2,13 +2,13 @@ import net.minecrell.pluginyml.bukkit.BukkitPluginDescription
|
|||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("java")
|
id("java")
|
||||||
id("com.github.johnrengelman.shadow") version "8.1.1"
|
id("com.gradleup.shadow") version "8.3.2"
|
||||||
id("xyz.jpenilla.run-paper") version "2.0.0"
|
id("xyz.jpenilla.run-paper") version "2.3.1"
|
||||||
id("net.minecrell.plugin-yml.bukkit") version "0.6.0"
|
id("net.minecrell.plugin-yml.bukkit") version "0.6.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "com.hibiscusmc"
|
group = "com.hibiscusmc"
|
||||||
version = "2.6.5"
|
version = "2.8.3${getGitCommitHash()}"
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
apply(plugin = "java")
|
apply(plugin = "java")
|
||||||
@@ -16,16 +16,16 @@ allprojects {
|
|||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
mavenLocal()
|
||||||
|
|
||||||
// Paper Repo
|
// 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")
|
maven("https://oss.sonatype.org/content/repositories/snapshots")
|
||||||
|
|
||||||
// Jitpack
|
// Jitpack
|
||||||
maven("https://jitpack.io")
|
maven("https://jitpack.io")
|
||||||
|
|
||||||
// ProtocolLib repo
|
// Geary
|
||||||
maven("https://repo.dmulloy2.net/repository/public/") //ProtocolLib Repo, constantly down
|
|
||||||
maven("https://repo.mineinabyss.com/releases/")
|
maven("https://repo.mineinabyss.com/releases/")
|
||||||
maven("https://repo.mineinabyss.com/snapshots/")
|
maven("https://repo.mineinabyss.com/snapshots/")
|
||||||
|
|
||||||
@@ -49,9 +49,6 @@ allprojects {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateChecker
|
|
||||||
maven("https://hub.jeff-media.com/nexus/repository/jeff-media-public/")
|
|
||||||
|
|
||||||
// ParticleHelper
|
// ParticleHelper
|
||||||
maven("https://repo.bytecode.space/repository/maven-public/")
|
maven("https://repo.bytecode.space/repository/maven-public/")
|
||||||
|
|
||||||
@@ -63,58 +60,75 @@ allprojects {
|
|||||||
|
|
||||||
// MMOItems
|
// MMOItems
|
||||||
maven("https://nexus.phoenixdevt.fr/repository/maven-public/")
|
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 {
|
dependencies {
|
||||||
compileOnly(fileTree("${project.rootDir}/lib") { include("*.jar") })
|
compileOnly(fileTree("${project.rootDir}/lib") { include("*.jar") })
|
||||||
compileOnly("com.mojang:authlib:1.5.25")
|
compileOnly("com.mojang:authlib:1.5.25")
|
||||||
compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
|
//compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
|
||||||
compileOnly("org.jetbrains:annotations:23.0.0")
|
compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT")
|
||||||
compileOnly("com.comphenix.protocol:ProtocolLib:5.1.0")
|
compileOnly("org.jetbrains:annotations:24.1.0")
|
||||||
compileOnly("me.clip:placeholderapi:2.11.3")
|
compileOnly("me.clip:placeholderapi:2.11.6")
|
||||||
compileOnly("com.ticxo.modelengine:ModelEngine:R4.0.2")
|
compileOnly("com.ticxo.modelengine:ModelEngine:R4.0.6")
|
||||||
compileOnly("com.github.oraxen:oraxen:1.160.0")
|
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.12") {
|
||||||
compileOnly("com.github.LoneDev6:API-ItemsAdder:3.2.5")
|
exclude(group = "org.bukkit")
|
||||||
compileOnly("com.mineinabyss:geary-papermc:0.27.0")
|
exclude(group = "com.google.guava")
|
||||||
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.1.0-SNAPSHOT")
|
exclude(group = "com.google.code.gson")
|
||||||
compileOnly("it.unimi.dsi:fastutil:8.5.11")
|
exclude(group = "it.unimi.dsi")
|
||||||
compileOnly("com.github.LeonMangler:SuperVanish:6.2.17")
|
exclude(group = "com.sk89q.jnbt")
|
||||||
compileOnly("org.projectlombok:lombok:1.18.2")
|
exclude(group = "org.enginehub.lin-bus.format")
|
||||||
|
}
|
||||||
|
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.8.1-d9fbae1d")
|
||||||
|
|
||||||
annotationProcessor("org.projectlombok:lombok:1.18.28")
|
// Handled by Spigot Library Loader ~ Deprecated as of Dec 16, 2025
|
||||||
testCompileOnly("org.projectlombok:lombok:1.18.28")
|
/*
|
||||||
testAnnotationProcessor("org.projectlombok:lombok:1.18.28")
|
compileOnly("net.kyori:adventure-api:4.24.0")
|
||||||
|
compileOnly("net.kyori:adventure-text-minimessage:4.24.0")
|
||||||
|
compileOnly("net.kyori:adventure-platform-bukkit:4.4.1")
|
||||||
|
*/
|
||||||
|
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
javadoc {
|
||||||
|
// javadoc spec has these added.
|
||||||
|
(options as StandardJavadocDocletOptions)
|
||||||
|
.tags("apiNote:a:API:", "implSpec:a:Implementation Requirements", "implNote:a:Implementation Note:")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(project(path = ":common"))
|
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"))
|
|
||||||
implementation(project(path = ":v1_20_R2", 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.2.0-SNAPSHOT")
|
|
||||||
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:bed3c46369")
|
|
||||||
//implementation("com.ticxo.playeranimator:PlayerAnimator:R1.2.5")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
|
|
||||||
compileJava {
|
compileJava {
|
||||||
options.encoding = Charsets.UTF_8.name()
|
options.encoding = Charsets.UTF_8.name()
|
||||||
options.release.set(17)
|
options.release.set(21)
|
||||||
}
|
}
|
||||||
|
|
||||||
javadoc {
|
javadoc {
|
||||||
@@ -127,29 +141,23 @@ tasks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
runServer {
|
runServer {
|
||||||
minecraftVersion("1.20.2")
|
minecraftVersion("1.21.8")
|
||||||
|
|
||||||
|
downloadPlugins {
|
||||||
|
hangar("PlaceholderAPI", "2.11.6")
|
||||||
|
hangar("Multiverse-Core", "5.3.4")
|
||||||
|
url("https://download.luckperms.net/1604/bukkit/loader/LuckPerms-Bukkit-5.5.15.jar")
|
||||||
|
github("Test-Account666", "PlugManX", "2.4.1", "PlugManX-2.4.1.jar")
|
||||||
|
//github("gecolay", "GSit", "2.4.3", "GSit-2.4.3.jar")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
shadowJar {
|
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")
|
|
||||||
dependsOn(":v1_20_R2:reobfJar")
|
|
||||||
mergeServiceFiles()
|
mergeServiceFiles()
|
||||||
|
|
||||||
relocate("dev.triumphteam.gui", "com.hisbiscusmc.hmccosmetics.gui")
|
relocate("dev.triumphteam.gui", "com.hibiscusmc.hmccosmetics.shaded.gui")
|
||||||
relocate("me.mattstudios.mf", "com.hisbiscusmc.hmccosmetics.mf")
|
relocate("com.owen1212055.particlehelper", "com.hibiscusmc.hmccosmetics.shaded.particlehelper")
|
||||||
relocate("net.kyori.adventure", "com.hisbiscusmc.hmccosmetics.adventure")
|
relocate("com.ticxo.playeranimator", "com.hibiscusmc.hmccosmetics.shaded.playeranimator")
|
||||||
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")
|
|
||||||
archiveFileName.set("HMCCosmeticsRemapped-${project.version}.jar")
|
archiveFileName.set("HMCCosmeticsRemapped-${project.version}.jar")
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -174,10 +182,10 @@ tasks {
|
|||||||
bukkit {
|
bukkit {
|
||||||
load = BukkitPluginDescription.PluginLoadOrder.POSTWORLD
|
load = BukkitPluginDescription.PluginLoadOrder.POSTWORLD
|
||||||
main = "com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin"
|
main = "com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin"
|
||||||
apiVersion = "1.18"
|
apiVersion = "1.20"
|
||||||
authors = listOf("LoJoSho")
|
authors = listOf("LoJoSho")
|
||||||
depend = listOf("ProtocolLib")
|
depend = listOf("HibiscusCommons")
|
||||||
softDepend = listOf("ModelEngine", "Oraxen", "ItemsAdder", "Geary", "HMCColor", "WorldGuard", "MythicMobs", "PlaceholderAPI", "SuperVanish", "PremiumVanish", "LibsDisguises", "Denizen", "MMOItems")
|
softDepend = listOf("Nexo", "BetterHud", "ModelEngine", "Oraxen", "ItemsAdder", "Geary", "HMCColor", "WorldGuard", "MythicMobs", "PlaceholderAPI", "SuperVanish", "PremiumVanish", "LibsDisguises", "Denizen", "MMOItems", "Eco")
|
||||||
version = "${project.version}"
|
version = "${project.version}"
|
||||||
loadBefore = listOf(
|
loadBefore = listOf(
|
||||||
"Cosmin" // Fixes an issue with Cosmin loading before and taking /cosmetic, when messing with what we do.
|
"Cosmin" // Fixes an issue with Cosmin loading before and taking /cosmetic, when messing with what we do.
|
||||||
@@ -262,10 +270,41 @@ bukkit {
|
|||||||
register("hmccosmetics.unapplydeath.bypass") {
|
register("hmccosmetics.unapplydeath.bypass") {
|
||||||
default = BukkitPluginDescription.Permission.Default.OP
|
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 {
|
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")
|
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.1.0")
|
|
||||||
compileOnly("me.clip:placeholderapi:2.11.3")
|
|
||||||
compileOnly("com.ticxo.modelengine:ModelEngine:R4.0.2")
|
|
||||||
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:bed3c46369")
|
|
||||||
//implementation("com.ticxo.playeranimator:PlayerAnimator:R1.2.5")
|
|
||||||
}
|
|
||||||
|
|
||||||
java {
|
java {
|
||||||
toolchain.languageVersion.set(JavaLanguageVersion.of(17
|
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
|
||||||
))
|
|
||||||
|
withJavadocJar()
|
||||||
|
withSourcesJar()
|
||||||
}
|
}
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
pluginManagement {
|
|
||||||
repositories {
|
|
||||||
gradlePluginPortal()
|
|
||||||
maven("https://repo.papermc.io/repository/maven-public/")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rootProject.name = "HMCCosmetics"
|
|
||||||
@@ -1,104 +1,83 @@
|
|||||||
package com.hibiscusmc.hmccosmetics;
|
package com.hibiscusmc.hmccosmetics;
|
||||||
|
|
||||||
import com.bgsoftware.common.config.CommentedConfiguration;
|
|
||||||
import com.hibiscusmc.hmccosmetics.api.events.HMCCosmeticSetupEvent;
|
import com.hibiscusmc.hmccosmetics.api.events.HMCCosmeticSetupEvent;
|
||||||
import com.hibiscusmc.hmccosmetics.command.CosmeticCommand;
|
import com.hibiscusmc.hmccosmetics.command.CosmeticCommand;
|
||||||
import com.hibiscusmc.hmccosmetics.command.CosmeticCommandTabComplete;
|
import com.hibiscusmc.hmccosmetics.command.CosmeticCommandTabComplete;
|
||||||
import com.hibiscusmc.hmccosmetics.config.DatabaseSettings;
|
import com.hibiscusmc.hmccosmetics.config.DatabaseSettings;
|
||||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||||
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
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.Cosmetic;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||||
import com.hibiscusmc.hmccosmetics.database.Database;
|
import com.hibiscusmc.hmccosmetics.database.Database;
|
||||||
import com.hibiscusmc.hmccosmetics.emotes.EmoteManager;
|
|
||||||
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||||
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
|
import com.hibiscusmc.hmccosmetics.gui.special.DyeMenuProvider;
|
||||||
|
import com.hibiscusmc.hmccosmetics.gui.special.impl.HMCColorDyeMenu;
|
||||||
|
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.WGHook;
|
||||||
import com.hibiscusmc.hmccosmetics.hooks.worldguard.WGListener;
|
import com.hibiscusmc.hmccosmetics.hooks.worldguard.WGListener;
|
||||||
import com.hibiscusmc.hmccosmetics.listener.PlayerConnectionListener;
|
import com.hibiscusmc.hmccosmetics.listener.*;
|
||||||
import com.hibiscusmc.hmccosmetics.listener.PlayerGameListener;
|
import com.hibiscusmc.hmccosmetics.packets.CosmeticPacketInterface;
|
||||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.PlayerSearchManager;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import com.hibiscusmc.hmccosmetics.util.TranslationUtil;
|
import com.hibiscusmc.hmccosmetics.util.TranslationUtil;
|
||||||
import com.jeff_media.updatechecker.UpdateCheckSource;
|
import lombok.Getter;
|
||||||
import com.jeff_media.updatechecker.UpdateChecker;
|
import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin;
|
||||||
import com.ticxo.playeranimator.PlayerAnimatorImpl;
|
import me.lojosho.hibiscuscommons.HibiscusPlugin;
|
||||||
import org.bstats.bukkit.Metrics;
|
import me.lojosho.hibiscuscommons.config.serializer.ItemSerializer;
|
||||||
|
import me.lojosho.hibiscuscommons.config.serializer.LocationSerializer;
|
||||||
|
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||||
|
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.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.permissions.Permission;
|
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.io.File;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
public final class HMCCosmeticsPlugin extends JavaPlugin {
|
public final class HMCCosmeticsPlugin extends HibiscusPlugin {
|
||||||
|
|
||||||
private static HMCCosmeticsPlugin instance;
|
private static HMCCosmeticsPlugin instance;
|
||||||
private static boolean disable = false;
|
|
||||||
private static YamlConfigurationLoader configLoader;
|
private static YamlConfigurationLoader configLoader;
|
||||||
private static final int pluginId = 13873;
|
|
||||||
private static boolean onLatestVersion = true;
|
@Getter
|
||||||
private static String latestVersion = "";
|
private PlayerSearchManager playerSearchManager;
|
||||||
|
|
||||||
|
public HMCCosmeticsPlugin() {
|
||||||
|
super(13873, 1879);
|
||||||
|
new HookHMCCosmetics();
|
||||||
|
new HookBetterHud();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onStart() {
|
||||||
// Plugin startup logic
|
// Plugin startup logic
|
||||||
instance = this;
|
instance = this;
|
||||||
// bstats https://bstats.org/plugin/bukkit/HMCCosmetics/13873
|
|
||||||
Metrics metrics = new Metrics(this, pluginId);
|
|
||||||
|
|
||||||
// NMS version check
|
// Search Service
|
||||||
if (!NMSHandlers.isVersionSupported()) {
|
this.playerSearchManager = new PlayerSearchManager(this);
|
||||||
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
|
// File setup
|
||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
if (!Path.of(getDataFolder().getPath(), "messages.yml").toFile().exists()) saveResource("messages.yml", false);
|
if (!Path.of(getDataFolder().getPath(), "messages.yml").toFile().exists()) saveResource("messages.yml", false);
|
||||||
if (!Path.of(getDataFolder().getPath(), "translations.yml").toFile().exists()) saveResource("translations.yml", false);
|
if (!Path.of(getDataFolder().getPath(), "translations.yml").toFile().exists()) saveResource("translations.yml", false);
|
||||||
if (!Path.of(getDataFolder().getPath() + "/cosmetics/").toFile().exists()) saveResource("cosmetics/defaultcosmetics.yml", false);
|
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);
|
if (!Path.of(getDataFolder().getPath() + "/menus/").toFile().exists()) {
|
||||||
|
saveResource("menus/defaultmenu_hats.yml", false);
|
||||||
// Emote folder setup
|
saveResource("menus/defaultmenu_balloons.yml", false);
|
||||||
File emoteFile = new File(getDataFolder().getPath() + "/emotes");
|
saveResource("menus/defaultmenu_hands.yml", false);
|
||||||
if (!emoteFile.exists()) emoteFile.mkdir();
|
saveResource("menus/defaultmenu_backpacks.yml", false);
|
||||||
|
}
|
||||||
// Player Animator
|
|
||||||
if (!NMSHandlers.getVersion().contains("v1_20_R2")) PlayerAnimatorImpl.initialize(this); // PlayerAnimator does not support 1.20.2 yet
|
|
||||||
|
|
||||||
// Configuration Sync
|
// Configuration Sync
|
||||||
final File configFile = Path.of(getInstance().getDataFolder().getPath(), "config.yml").toFile();
|
final File configFile = Path.of(getInstance().getDataFolder().getPath(), "config.yml").toFile();
|
||||||
@@ -113,8 +92,12 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Move this over to Hibiscus Commons later
|
||||||
|
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) new HMCPlaceholderExpansion().register();
|
||||||
|
|
||||||
// Setup
|
// Setup
|
||||||
setup();
|
setup();
|
||||||
|
setPacketInterface(new CosmeticPacketInterface());
|
||||||
|
|
||||||
// Commands
|
// Commands
|
||||||
getServer().getPluginCommand("cosmetic").setExecutor(new CosmeticCommand());
|
getServer().getPluginCommand("cosmetic").setExecutor(new CosmeticCommand());
|
||||||
@@ -123,7 +106,13 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
|||||||
// Listener
|
// Listener
|
||||||
getServer().getPluginManager().registerEvents(new PlayerConnectionListener(), this);
|
getServer().getPluginManager().registerEvents(new PlayerConnectionListener(), this);
|
||||||
getServer().getPluginManager().registerEvents(new PlayerGameListener(), this);
|
getServer().getPluginManager().registerEvents(new PlayerGameListener(), this);
|
||||||
|
getServer().getPluginManager().registerEvents(new ServerListener(), this);
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerMovementListener(), this);
|
||||||
|
getServer().getPluginManager().registerEvents(playerSearchManager, this);
|
||||||
|
|
||||||
|
if (HibiscusCommonsPlugin.isOnPaper()) {
|
||||||
|
getServer().getPluginManager().registerEvents(new PaperPlayerGameListener(), this);
|
||||||
|
}
|
||||||
// Database
|
// Database
|
||||||
new Database();
|
new Database();
|
||||||
|
|
||||||
@@ -131,6 +120,15 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
|||||||
if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null && Settings.isWorldGuardMoveCheck()) {
|
if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null && Settings.isWorldGuardMoveCheck()) {
|
||||||
getServer().getPluginManager().registerEvents(new WGListener(), this);
|
getServer().getPluginManager().registerEvents(new WGListener(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HMCColor
|
||||||
|
if (Hooks.isActiveHook("HMCColor")) {
|
||||||
|
try {
|
||||||
|
DyeMenuProvider.setDyeMenuProvider(new HMCColorDyeMenu());
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
getLogger().warning("Unable to set HMCColor as the dye menu. There is likely another plugin registering another dye menu.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -142,14 +140,13 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onEnd() {
|
||||||
// Plugin shutdown logic
|
// Plugin shutdown logic
|
||||||
disable = true;
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
if (user == null) continue;
|
if (user == null) continue;
|
||||||
if (user.getUserEmoteManager().isPlayingEmote()) {
|
if (user.isInWardrobe()) {
|
||||||
player.setInvisible(false);
|
user.leaveWardrobe(true);
|
||||||
}
|
}
|
||||||
Database.save(user);
|
Database.save(user);
|
||||||
}
|
}
|
||||||
@@ -214,9 +211,6 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Misc Hooks setup (like items)
|
|
||||||
Hooks.setup();
|
|
||||||
|
|
||||||
// Cosmetics setup
|
// Cosmetics setup
|
||||||
Cosmetics.setup();
|
Cosmetics.setup();
|
||||||
|
|
||||||
@@ -252,8 +246,6 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.isEmotesEnabled() && !NMSHandlers.getVersion().contains("v1_20_R2")) EmoteManager.loadEmotes(); // PlayerAnimator does not support 1.20.2 yet
|
|
||||||
|
|
||||||
getInstance().getLogger().info("Successfully Enabled HMCCosmetics");
|
getInstance().getLogger().info("Successfully Enabled HMCCosmetics");
|
||||||
getInstance().getLogger().info(Cosmetics.values().size() + " Cosmetics Successfully Setup");
|
getInstance().getLogger().info(Cosmetics.values().size() + " Cosmetics Successfully Setup");
|
||||||
getInstance().getLogger().info(Menus.getMenuNames().size() + " Menus Successfully Setup");
|
getInstance().getLogger().info(Menus.getMenuNames().size() + " Menus Successfully Setup");
|
||||||
@@ -262,28 +254,4 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
Bukkit.getPluginManager().callEvent(new HMCCosmeticSetupEvent());
|
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,214 @@ package com.hibiscusmc.hmccosmetics.api;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticProvider;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUserProvider;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||||
|
import me.lojosho.hibiscuscommons.nms.MinecraftVersion;
|
||||||
|
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class HMCCosmeticsAPI {
|
/**
|
||||||
|
* The main API class for HMCCosmetics. This class provides methods to interact with the plugin.
|
||||||
/**
|
*/
|
||||||
* Attempts to get a cosmetic from HMCCosmetics
|
public final class HMCCosmeticsAPI {
|
||||||
*
|
private HMCCosmeticsAPI() {
|
||||||
* @param cosmetic Cosmetic Id
|
throw new UnsupportedOperationException("This class cannot be instantiated.");
|
||||||
* @return A {@link Cosmetic} if exists or null if it does not
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public static Cosmetic getCosmetic(@NotNull String cosmetic) {
|
|
||||||
return Cosmetics.getCosmetic(cosmetic);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to get the CosmeticUser from an online user. If a player is offline it will return null.
|
* Retrieves a {@link Cosmetic} associated with the specified id.
|
||||||
* A player maybe online but not have a CosmeticUser attached to them, either from delay specified in the config
|
* <p>
|
||||||
* or from a /reload. Always check if it's null!
|
* 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}.
|
||||||
* @param uuid Player Unique ID
|
* </p>
|
||||||
* @return A {@link CosmeticUser} if exists or null if it does not
|
* @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 @Nullable Cosmetic getCosmetic(@NotNull String id) {
|
||||||
public static CosmeticUser getUser(@NotNull UUID uuid) {
|
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);
|
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
|
* @param id the id of the menu to retrieve
|
||||||
* @return A {@link Menu} if exists or null if it does not
|
* @return the {@link Menu} if it exists, or {@code null} if no menu is associated with the given id
|
||||||
*/
|
*/
|
||||||
@Nullable
|
public static @Nullable Menu getMenu(@NotNull String id) {
|
||||||
public static Menu getMenu(@NotNull String id) {
|
|
||||||
return Menus.getMenu(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.
|
* Equips a {@link Cosmetic} to a player. To retrieve the necessary {@code CosmeticUser} and {@code Cosmetic}, use the {@link #getUser}
|
||||||
* @param user CosmeticUser to equip cosmetic to
|
* and {@link #getCosmetic} methods respectively.
|
||||||
* @param cosmetic Cosmetic to equip
|
*
|
||||||
|
* @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) {
|
public static void equipCosmetic(@NotNull CosmeticUser user, @NotNull Cosmetic cosmetic) {
|
||||||
equipCosmetic(user, cosmetic, null);
|
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.
|
* Equips a {@link Cosmetic} to a player with an optional color customization. To retrieve the necessary
|
||||||
* @param user CosmeticUser to equip cosmetic to
|
* {@code CosmeticUser} and {@code Cosmetic}, use the {@link #getUser} and {@link #getCosmetic} methods
|
||||||
* @param cosmetic Cosmetic to equip
|
* respectively.
|
||||||
* @param color Color to apply to cosmetic
|
*
|
||||||
|
* @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) {
|
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.
|
* Removes a cosmetic from a specified slot for the given user.
|
||||||
* @param user The user to remove the cosmetic from
|
*
|
||||||
* @param slot The slot to remove the cosmetic from
|
* @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) {
|
public static void unequipCosmetic(@NotNull CosmeticUser user, @NotNull CosmeticSlot slot) {
|
||||||
user.removeCosmeticSlot(slot);
|
user.removeCosmeticSlot(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all Cosmetics that are currently registered with HMCC. This list is immutable!
|
* Retrieves a list of all cosmetics currently registered with HMCC.
|
||||||
* @return A list of all registered cosmetics
|
*
|
||||||
|
* @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());
|
return List.copyOf(Cosmetics.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all CosmeticUsers that are currently registered with HMCC. This list is immutable!
|
* Retrieves a list of all cosmetic users currently registered with HMCC.
|
||||||
* @return A list of all registered CosmeticUsers
|
*
|
||||||
|
* @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());
|
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.
|
* Retrieves a map of all cosmetic slots currently registered with HMCC.
|
||||||
* @return The NMS version of the server in String format
|
*
|
||||||
|
* @return an immutable {@link Map} containing all registered cosmetic slots
|
||||||
*/
|
*/
|
||||||
@Nullable
|
public static @NotNull Map<String, CosmeticSlot> getAllCosmeticSlots() {
|
||||||
public static String getNMSVersion() {
|
return Map.copyOf(CosmeticSlot.values());
|
||||||
return NMSHandlers.getVersion();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This returns the HMCCosmetics version.
|
* Registers a new cosmetic slot with the specified id. If a slot with the same id already exists,
|
||||||
* @return The HMCCosmetics version in String format
|
* 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 @NotNull CosmeticSlot registerCosmeticSlot(@NotNull String id) {
|
||||||
public static String getHMCCVersion() {
|
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();
|
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;
|
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 {
|
public class HMCCosmeticSetupEvent extends Event {
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
public @NotNull HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
return HANDLER_LIST;
|
||||||
return handlers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
public static @NotNull HandlerList getHandlerList() {
|
||||||
public static HandlerList getHandlerList() {
|
return HANDLER_LIST;
|
||||||
return handlers;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,22 +7,24 @@ import org.bukkit.event.HandlerList;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
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 {
|
public class PlayerCosmeticEquipEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||||
private boolean cancel = false;
|
|
||||||
private Cosmetic cosmetic;
|
private Cosmetic cosmetic;
|
||||||
|
|
||||||
|
private boolean cancel = false;
|
||||||
|
|
||||||
public PlayerCosmeticEquipEvent(@NotNull CosmeticUser who, @NotNull Cosmetic cosmetic) {
|
public PlayerCosmeticEquipEvent(@NotNull CosmeticUser who, @NotNull Cosmetic cosmetic) {
|
||||||
super(who);
|
super(who);
|
||||||
this.cosmetic = cosmetic;
|
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
|
@NotNull
|
||||||
public Cosmetic getCosmetic() {
|
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) {
|
public void setCosmetic(@NotNull Cosmetic cosmetic) {
|
||||||
this.cosmetic = cosmetic;
|
this.cosmetic = cosmetic;
|
||||||
@@ -43,28 +45,17 @@ public class PlayerCosmeticEquipEvent extends PlayerCosmeticEvent implements Can
|
|||||||
return cancel;
|
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
|
@Override
|
||||||
public void setCancelled(boolean cancel) {
|
public void setCancelled(boolean cancel) {
|
||||||
this.cancel = cancel;
|
this.cancel = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
public @NotNull HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
return HANDLER_LIST;
|
||||||
return handlers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
public static @NotNull HandlerList getHandlerList() {
|
||||||
public static HandlerList getHandlerList() {
|
return HANDLER_LIST;
|
||||||
return handlers;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,25 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.api.events;
|
package com.hibiscusmc.hmccosmetics.api.events;
|
||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
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 {
|
public abstract class PlayerCosmeticEvent extends PlayerEvent {
|
||||||
protected CosmeticUser user;
|
protected final CosmeticUser user;
|
||||||
|
|
||||||
public PlayerCosmeticEvent(@NotNull final CosmeticUser who) {
|
public PlayerCosmeticEvent(@NotNull CosmeticUser who) {
|
||||||
|
super(who.getUniqueId());
|
||||||
user = who;
|
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 @NotNull CosmeticUser getUser() {
|
||||||
public final CosmeticUser getUser() {
|
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,25 +6,26 @@ import org.bukkit.event.HandlerList;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
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 {
|
public class PlayerCosmeticHideEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||||
private boolean cancel = false;
|
|
||||||
private final CosmeticUser.HiddenReason reason;
|
private final CosmeticUser.HiddenReason reason;
|
||||||
|
|
||||||
|
private boolean cancel = false;
|
||||||
|
|
||||||
public PlayerCosmeticHideEvent(@NotNull CosmeticUser who, @NotNull CosmeticUser.HiddenReason reason) {
|
public PlayerCosmeticHideEvent(@NotNull CosmeticUser who, @NotNull CosmeticUser.HiddenReason reason) {
|
||||||
super(who);
|
super(who);
|
||||||
this.reason = reason;
|
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 @NotNull CosmeticUser.HiddenReason getReason() {
|
||||||
public CosmeticUser.HiddenReason getReason() {
|
|
||||||
return reason;
|
return reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,28 +34,17 @@ public class PlayerCosmeticHideEvent extends PlayerCosmeticEvent implements Canc
|
|||||||
return cancel;
|
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
|
@Override
|
||||||
public void setCancelled(boolean cancel) {
|
public void setCancelled(boolean cancel) {
|
||||||
this.cancel = cancel;
|
this.cancel = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
public @NotNull HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
return HANDLER_LIST;
|
||||||
return handlers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
public static @NotNull HandlerList getHandlerList() {
|
||||||
public static HandlerList getHandlerList() {
|
return HANDLER_LIST;
|
||||||
return handlers;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,12 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
|||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a player has equipped a {@link Cosmetic}.
|
||||||
|
*/
|
||||||
public class PlayerCosmeticPostEquipEvent extends PlayerCosmeticEvent {
|
public class PlayerCosmeticPostEquipEvent extends PlayerCosmeticEvent {
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||||
|
|
||||||
private Cosmetic cosmetic;
|
private Cosmetic cosmetic;
|
||||||
|
|
||||||
public PlayerCosmeticPostEquipEvent(@NotNull CosmeticUser who, @NotNull 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 @NotNull Cosmetic getCosmetic() {
|
||||||
public Cosmetic getCosmetic() {
|
|
||||||
return cosmetic;
|
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) {
|
public void setCosmetic(@NotNull Cosmetic cosmetic) {
|
||||||
this.cosmetic = cosmetic;
|
this.cosmetic = cosmetic;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
public @NotNull HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
return HANDLER_LIST;
|
||||||
return handlers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
public static @NotNull HandlerList getHandlerList() {
|
||||||
public static HandlerList getHandlerList() {
|
return HANDLER_LIST;
|
||||||
return handlers;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,22 +7,24 @@ import org.bukkit.event.HandlerList;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
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 {
|
public class PlayerCosmeticRemoveEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||||
private boolean cancel = false;
|
|
||||||
private final Cosmetic cosmetic;
|
private final Cosmetic cosmetic;
|
||||||
|
|
||||||
|
private boolean cancel = false;
|
||||||
|
|
||||||
public PlayerCosmeticRemoveEvent(@NotNull CosmeticUser who, @NotNull Cosmetic cosmetic) {
|
public PlayerCosmeticRemoveEvent(@NotNull CosmeticUser who, @NotNull Cosmetic cosmetic) {
|
||||||
super(who);
|
super(who);
|
||||||
this.cosmetic = cosmetic;
|
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() {
|
public Cosmetic getCosmetic() {
|
||||||
return cosmetic;
|
return cosmetic;
|
||||||
@@ -33,27 +35,17 @@ public class PlayerCosmeticRemoveEvent extends PlayerCosmeticEvent implements Ca
|
|||||||
return cancel;
|
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
|
@Override
|
||||||
public void setCancelled(boolean cancel) {
|
public void setCancelled(boolean cancel) {
|
||||||
this.cancel = cancel;
|
this.cancel = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
public @NotNull HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
return HANDLER_LIST;
|
||||||
return handlers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
public static @NotNull HandlerList getHandlerList() {
|
||||||
return handlers;
|
return HANDLER_LIST;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,10 +6,11 @@ import org.bukkit.event.HandlerList;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
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 {
|
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;
|
private boolean cancel = false;
|
||||||
|
|
||||||
public PlayerCosmeticShowEvent(@NotNull CosmeticUser who) {
|
public PlayerCosmeticShowEvent(@NotNull CosmeticUser who) {
|
||||||
@@ -21,28 +22,17 @@ public class PlayerCosmeticShowEvent extends PlayerCosmeticEvent implements Canc
|
|||||||
return cancel;
|
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
|
@Override
|
||||||
public void setCancelled(boolean cancel) {
|
public void setCancelled(boolean cancel) {
|
||||||
this.cancel = cancel;
|
this.cancel = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
public @NotNull HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
return HANDLER_LIST;
|
||||||
return handlers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
public static @NotNull HandlerList getHandlerList() {
|
||||||
public static HandlerList getHandlerList() {
|
return HANDLER_LIST;
|
||||||
return handlers;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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.gui.Menu;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||||
import org.jetbrains.annotations.NotNull;
|
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 {
|
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);
|
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
|
@Override
|
||||||
@NotNull
|
public @NotNull HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
return HANDLER_LIST;
|
||||||
return handlers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
public static @NotNull HandlerList getHandlerList() {
|
||||||
public static HandlerList getHandlerList() {
|
return HANDLER_LIST;
|
||||||
return handlers;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
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 {
|
public abstract class PlayerMenuEvent extends PlayerCosmeticEvent {
|
||||||
protected Menu menu;
|
protected final Menu menu;
|
||||||
|
|
||||||
public PlayerMenuEvent(@NotNull CosmeticUser who, @NotNull Menu menu) {
|
public PlayerMenuEvent(@NotNull CosmeticUser who, @NotNull Menu menu) {
|
||||||
super(who);
|
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 @NotNull final Menu getMenu() {
|
||||||
public final Menu getMenu() {
|
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,11 @@ import org.bukkit.event.HandlerList;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
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 {
|
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;
|
private boolean cancel = false;
|
||||||
|
|
||||||
public PlayerMenuOpenEvent(@NotNull CosmeticUser who, @NotNull Menu menu) {
|
public PlayerMenuOpenEvent(@NotNull CosmeticUser who, @NotNull Menu menu) {
|
||||||
@@ -22,28 +23,17 @@ public class PlayerMenuOpenEvent extends PlayerMenuEvent implements Cancellable
|
|||||||
return cancel;
|
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
|
@Override
|
||||||
public void setCancelled(boolean cancel) {
|
public void setCancelled(boolean cancel) {
|
||||||
this.cancel = cancel;
|
this.cancel = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
public @NotNull HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
return HANDLER_LIST;
|
||||||
return handlers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
public static @NotNull HandlerList getHandlerList() {
|
||||||
public static HandlerList getHandlerList() {
|
return HANDLER_LIST;
|
||||||
return handlers;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.config.Wardrobe;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.jetbrains.annotations.NotNull;
|
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 {
|
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;
|
private boolean cancel = false;
|
||||||
@Getter @Setter
|
|
||||||
private Wardrobe wardrobe;
|
private Wardrobe wardrobe;
|
||||||
|
|
||||||
public PlayerWardrobeEnterEvent(@NotNull CosmeticUser who, @NotNull Wardrobe wardrobe) {
|
public PlayerWardrobeEnterEvent(@NotNull CosmeticUser who, @NotNull Wardrobe wardrobe) {
|
||||||
@@ -22,33 +21,38 @@ public class PlayerWardrobeEnterEvent extends PlayerCosmeticEvent implements Can
|
|||||||
this.wardrobe = wardrobe;
|
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
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return cancel;
|
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
|
@Override
|
||||||
public void setCancelled(boolean cancel) {
|
public void setCancelled(boolean cancel) {
|
||||||
this.cancel = cancel;
|
this.cancel = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
public @NotNull HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
return HANDLER_LIST;
|
||||||
return handlers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
public static @NotNull HandlerList getHandlerList() {
|
||||||
public static HandlerList getHandlerList() {
|
return HANDLER_LIST;
|
||||||
return handlers;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,11 @@ import org.bukkit.event.HandlerList;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
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 {
|
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;
|
private boolean cancel = false;
|
||||||
|
|
||||||
public PlayerWardrobeLeaveEvent(@NotNull CosmeticUser who) {
|
public PlayerWardrobeLeaveEvent(@NotNull CosmeticUser who) {
|
||||||
@@ -21,28 +22,17 @@ public class PlayerWardrobeLeaveEvent extends PlayerCosmeticEvent implements Can
|
|||||||
return cancel;
|
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
|
@Override
|
||||||
public void setCancelled(boolean cancel) {
|
public void setCancelled(boolean cancel) {
|
||||||
this.cancel = cancel;
|
this.cancel = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
public @NotNull HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
return HANDLER_LIST;
|
||||||
return handlers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
public static @NotNull HandlerList getHandlerList() {
|
||||||
public static HandlerList getHandlerList() {
|
return HANDLER_LIST;
|
||||||
return handlers;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.command;
|
package com.hibiscusmc.hmccosmetics.command;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccolor.HMCColorConfig;
|
||||||
|
import com.hibiscusmc.hmccolor.HMCColorContextKt;
|
||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||||
import com.hibiscusmc.hmccosmetics.config.Wardrobe;
|
import com.hibiscusmc.hmccosmetics.config.Wardrobe;
|
||||||
@@ -8,19 +10,18 @@ import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
|||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticEmoteType;
|
|
||||||
import com.hibiscusmc.hmccosmetics.database.Database;
|
import com.hibiscusmc.hmccosmetics.database.Database;
|
||||||
import com.hibiscusmc.hmccosmetics.emotes.EmoteManager;
|
|
||||||
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.special.DyeMenu;
|
import com.hibiscusmc.hmccosmetics.gui.special.DyeMenu;
|
||||||
|
import com.hibiscusmc.hmccosmetics.gui.special.DyeMenuProvider;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
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.Placeholder;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import org.apache.commons.lang3.EnumUtils;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
@@ -40,10 +41,14 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String @NotNull [] args) {
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String @NotNull [] args) {
|
||||||
boolean silent = false;
|
boolean silent = false;
|
||||||
|
boolean console = false;
|
||||||
|
|
||||||
|
if (!(sender instanceof Player)) {
|
||||||
|
console = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
if (!(sender instanceof Player)) {
|
if (console) {
|
||||||
// Console
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!sender.hasPermission("hmccosmetics.cmd.default")) {
|
if (!sender.hasPermission("hmccosmetics.cmd.default")) {
|
||||||
@@ -104,7 +109,18 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sender.hasPermission("hmccosmetics.cmd.apply.color")) {
|
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) {
|
if (args.length == 1) {
|
||||||
@@ -126,7 +142,12 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
|
|
||||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
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");
|
if (!silent) MessagesUtil.sendMessage(player, "no-cosmetic-permission");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -134,11 +155,11 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
TagResolver placeholders =
|
TagResolver placeholders =
|
||||||
TagResolver.resolver(Placeholder.parsed("cosmetic", cosmetic.getId()),
|
TagResolver.resolver(Placeholder.parsed("cosmetic", cosmetic.getId()),
|
||||||
TagResolver.resolver(Placeholder.parsed("player", player.getName())),
|
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);
|
if (!silent) MessagesUtil.sendMessage(player, "equip-cosmetic", placeholders);
|
||||||
|
|
||||||
user.addPlayerCosmetic(cosmetic, color);
|
user.addCosmetic(cosmetic, color);
|
||||||
user.updateCosmetic(cosmetic.getSlot());
|
user.updateCosmetic(cosmetic.getSlot());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -169,11 +190,12 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
if (args[1].equalsIgnoreCase("all")) {
|
if (args[1].equalsIgnoreCase("all")) {
|
||||||
cosmeticSlots = user.getSlotsWithCosmetics();
|
cosmeticSlots = user.getSlotsWithCosmetics();
|
||||||
} else {
|
} 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");
|
if (!silent) MessagesUtil.sendMessage(sender, "invalid-slot");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
cosmeticSlots = Set.of(CosmeticSlot.valueOf(args[1].toUpperCase()));
|
cosmeticSlots = Set.of(CosmeticSlot.valueOf(rawSlot));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (CosmeticSlot cosmeticSlot : cosmeticSlots) {
|
for (CosmeticSlot cosmeticSlot : cosmeticSlots) {
|
||||||
@@ -185,7 +207,7 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
TagResolver placeholders =
|
TagResolver placeholders =
|
||||||
TagResolver.resolver(Placeholder.parsed("cosmetic", user.getCosmetic(cosmeticSlot).getId()),
|
TagResolver.resolver(Placeholder.parsed("cosmetic", user.getCosmetic(cosmeticSlot).getId()),
|
||||||
TagResolver.resolver(Placeholder.parsed("player", player.getName())),
|
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);
|
if (!silent) MessagesUtil.sendMessage(player, "unequip-cosmetic", placeholders);
|
||||||
|
|
||||||
@@ -225,20 +247,24 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
|
|
||||||
if (user.isInWardrobe()) {
|
if (user.isInWardrobe()) {
|
||||||
user.leaveWardrobe();
|
user.leaveWardrobe(false);
|
||||||
} else {
|
} else {
|
||||||
user.enterWardrobe(false, wardrobe);
|
user.enterWardrobe(wardrobe, false);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// cosmetic menu exampleMenu playerName
|
// cosmetic menu exampleMenu playerName
|
||||||
case ("menu") -> {
|
case ("menu") -> {
|
||||||
if (args.length == 1) return true;
|
|
||||||
if (!sender.hasPermission("hmccosmetics.cmd.menu")) {
|
if (!sender.hasPermission("hmccosmetics.cmd.menu")) {
|
||||||
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
||||||
return true;
|
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 instanceof Player) player = ((Player) sender).getPlayer();
|
||||||
if (sender.hasPermission("hmccosmetics.cmd.menu.other")) {
|
if (sender.hasPermission("hmccosmetics.cmd.menu.other")) {
|
||||||
@@ -284,26 +310,35 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!EnumUtils.isValidEnum(CosmeticSlot.class, args[1])) {
|
final String rawSlot = args[1];
|
||||||
|
if (!CosmeticSlot.contains(rawSlot)) {
|
||||||
|
if (!silent) MessagesUtil.sendMessage(player, "invalid-slot");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
final CosmeticSlot slot = CosmeticSlot.valueOf(rawSlot); // This is checked above. While IDEs may say the slot might be null, it will not be.
|
||||||
|
final Cosmetic cosmetic = user.getCosmetic(slot);
|
||||||
|
if (cosmetic == null) {
|
||||||
if (!silent) MessagesUtil.sendMessage(player, "invalid-slot");
|
if (!silent) MessagesUtil.sendMessage(player, "invalid-slot");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
CosmeticSlot slot = CosmeticSlot.valueOf(args[1]);
|
|
||||||
Cosmetic cosmetic = user.getCosmetic(slot);
|
|
||||||
|
|
||||||
if (args.length >= 3) {
|
if (args.length >= 3) {
|
||||||
if (args[2].isEmpty()) {
|
if (args[2].isEmpty()) {
|
||||||
if (!silent) MessagesUtil.sendMessage(player, "invalid-color");
|
if (!silent) MessagesUtil.sendMessage(player, "invalid-color");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Color color = ServerUtils.hex2Rgb(args[2]);
|
Color color = HMCCServerUtils.hex2Rgb(args[2]);
|
||||||
if (color == null) {
|
if (color == null) {
|
||||||
if (!silent) MessagesUtil.sendMessage(player, "invalid-color");
|
if (!silent) MessagesUtil.sendMessage(player, "invalid-color");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
user.addPlayerCosmetic(cosmetic, color); // #FFFFFF
|
user.addCosmetic(cosmetic, color); // #FFFFFF
|
||||||
} else {
|
} else {
|
||||||
DyeMenu.openMenu(user, cosmetic);
|
if (DyeMenuProvider.hasMenuProvider()) {
|
||||||
|
DyeMenuProvider.openMenu(player, user, cosmetic);
|
||||||
|
} else {
|
||||||
|
if (!silent) MessagesUtil.sendMessage(player, "invalid-color");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case ("setwardrobesetting") -> {
|
case ("setwardrobesetting") -> {
|
||||||
@@ -320,7 +355,7 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
Wardrobe wardrobe = WardrobeSettings.getWardrobe(args[1]);
|
Wardrobe wardrobe = WardrobeSettings.getWardrobe(args[1]);
|
||||||
if (wardrobe == null) {
|
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);
|
WardrobeSettings.addWardrobe(wardrobe);
|
||||||
//MessagesUtil.sendMessage(player, "no-wardrobes");
|
//MessagesUtil.sendMessage(player, "no-wardrobes");
|
||||||
//return true;
|
//return true;
|
||||||
@@ -355,6 +390,11 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
if (!silent) MessagesUtil.sendMessage(player, "set-wardrobe-distance");
|
if (!silent) MessagesUtil.sendMessage(player, "set-wardrobe-distance");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (args[2].equalsIgnoreCase("defaultmenu")) {
|
||||||
|
WardrobeSettings.setWardrobeDefaultMenu(wardrobe, args[3]);
|
||||||
|
if (!silent) MessagesUtil.sendMessage(player, "set-wardrobe-menu");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case ("dump") -> {
|
case ("dump") -> {
|
||||||
@@ -369,6 +409,7 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
||||||
player.sendMessage("Backpack Location -> " + user.getUserBackpackManager().getEntityManager().getLocation());
|
player.sendMessage("Backpack Location -> " + user.getUserBackpackManager().getEntityManager().getLocation());
|
||||||
}
|
}
|
||||||
|
player.sendMessage("Cosmetic Passengers -> " + user.getUserBackpackManager().getAreaEffectEntityId());
|
||||||
player.sendMessage("Cosmetics -> " + user.getCosmetics());
|
player.sendMessage("Cosmetics -> " + user.getCosmetics());
|
||||||
player.sendMessage("EntityId -> " + player.getEntityId());
|
player.sendMessage("EntityId -> " + player.getEntityId());
|
||||||
return true;
|
return true;
|
||||||
@@ -413,7 +454,7 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
|
|
||||||
if (!silent) MessagesUtil.sendMessage(sender, "show-cosmetic");
|
if (!silent) MessagesUtil.sendMessage(sender, "show-cosmetic");
|
||||||
user.showCosmetics();
|
user.showCosmetics(CosmeticUser.HiddenReason.COMMAND);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case ("debug") -> {
|
case ("debug") -> {
|
||||||
@@ -430,56 +471,60 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
if (!silent) MessagesUtil.sendMessage(sender, "debug-enabled");
|
if (!silent) MessagesUtil.sendMessage(sender, "debug-enabled");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case ("emote") -> {
|
case "disableall" -> {
|
||||||
if (!sender.hasPermission("hmccosmetics.cmd.emote")) {
|
if (!sender.hasPermission("hmccosmetics.cmd.disableall")) {
|
||||||
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (sender.hasPermission("hmccosmetics.cmd.emote.other")) {
|
if (args.length == 1) {
|
||||||
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 (!silent) MessagesUtil.sendMessage(player, "not-enough-args");
|
if (!silent) MessagesUtil.sendMessage(player, "not-enough-args");
|
||||||
return true;
|
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])) {
|
case "hiddenreasons" -> {
|
||||||
MessagesUtil.sendDebugMessages("Did not contain " + args[1]);
|
if (!sender.hasPermission("hmccosmetics.cmd.hiddenreasons")) {
|
||||||
if (!silent) MessagesUtil.sendMessage(sender, "emote-invalid");
|
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (args.length >= 2) {
|
||||||
if (sender.hasPermission("hmccosmetics.cmd.playemote.other")) {
|
player = Bukkit.getPlayer(args[1]);
|
||||||
if (args.length >= 3) player = Bukkit.getPlayer(args[2]);
|
|
||||||
}
|
}
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
if (!silent) MessagesUtil.sendMessage(sender, "invalid-player");
|
if (!silent) MessagesUtil.sendMessage(sender, "invalid-player");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.command;
|
package com.hibiscusmc.hmccosmetics.command;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccolor.HMCColorContextKt;
|
||||||
import com.hibiscusmc.hmccosmetics.config.Wardrobe;
|
import com.hibiscusmc.hmccosmetics.config.Wardrobe;
|
||||||
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||||
import com.hibiscusmc.hmccosmetics.emotes.EmoteManager;
|
|
||||||
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||||
|
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
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.hide")) completions.add("hide");
|
||||||
if (hasPermission(sender, "hmccosmetics.cmd.show")) completions.add("show");
|
if (hasPermission(sender, "hmccosmetics.cmd.show")) completions.add("show");
|
||||||
if (hasPermission(sender, "hmccosmetics.cmd.debug")) completions.add("debug");
|
if (hasPermission(sender, "hmccosmetics.cmd.debug")) completions.add("debug");
|
||||||
if (hasPermission(sender, "hmccosmetics.cmd.emote")) completions.add("emote");
|
if (hasPermission(sender, "hmccosmetics.cmd.disableall")) completions.add("disableall");
|
||||||
if (hasPermission(sender, "hmccosmetics.cmd.playemote")) completions.add("playemote");
|
if (hasPermission(sender, "hmccosmetics.cmd.hiddenreasons")) completions.add("hiddenreasons");
|
||||||
|
if (hasPermission(sender, "hmccosmetics.cmd.clearhiddenreasons")) completions.add("clearhiddenreasons");
|
||||||
|
|
||||||
StringUtil.copyPartialMatches(args[0], completions, finalCompletions);
|
StringUtil.copyPartialMatches(args[0], completions, finalCompletions);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(sender instanceof Player)) return completions;
|
if (!(sender instanceof Player)) return completions;
|
||||||
CosmeticUser user = CosmeticUsers.getUser(((Player) sender).getUniqueId());
|
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) {
|
if (args.length == 2) {
|
||||||
String subcommand = args[0].toLowerCase();
|
String subcommand = args[0].toLowerCase();
|
||||||
@@ -68,11 +71,15 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
|||||||
if (menu.canOpen(user.getPlayer())) completions.add(menu.getId());
|
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()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
completions.add(player.getName());
|
completions.add(player.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case "disableall" -> {
|
||||||
|
completions.add("true");
|
||||||
|
completions.add("false");
|
||||||
|
}
|
||||||
case "wardrobe" -> {
|
case "wardrobe" -> {
|
||||||
for (Wardrobe wardrobe : WardrobeSettings.getWardrobes()) {
|
for (Wardrobe wardrobe : WardrobeSettings.getWardrobes()) {
|
||||||
if (wardrobe.hasPermission()) {
|
if (wardrobe.hasPermission()) {
|
||||||
@@ -84,7 +91,7 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
|||||||
}
|
}
|
||||||
case "dye" -> {
|
case "dye" -> {
|
||||||
for (CosmeticSlot slot : user.getDyeableSlots()) {
|
for (CosmeticSlot slot : user.getDyeableSlots()) {
|
||||||
completions.add(slot.name());
|
completions.add(slot.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "setwardrobesetting" -> {
|
case "setwardrobesetting" -> {
|
||||||
@@ -92,7 +99,6 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
|||||||
completions.add(wardrobe.getId());
|
completions.add(wardrobe.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "playemote" -> completions.addAll(EmoteManager.getAllNames());
|
|
||||||
}
|
}
|
||||||
StringUtil.copyPartialMatches(args[1], completions, finalCompletions);
|
StringUtil.copyPartialMatches(args[1], completions, finalCompletions);
|
||||||
}
|
}
|
||||||
@@ -102,7 +108,7 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
|||||||
case "dye" -> {
|
case "dye" -> {
|
||||||
completions.add("#FFFFFF");
|
completions.add("#FFFFFF");
|
||||||
}
|
}
|
||||||
case "menu", "wardrobe", "apply", "unapply", "playemote" -> {
|
case "menu", "wardrobe", "apply", "unapply" -> {
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
completions.add(player.getName());
|
completions.add(player.getName());
|
||||||
}
|
}
|
||||||
@@ -113,6 +119,7 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
|||||||
completions.add("leavelocation");
|
completions.add("leavelocation");
|
||||||
completions.add("permission");
|
completions.add("permission");
|
||||||
completions.add("distance");
|
completions.add("distance");
|
||||||
|
completions.add("defaultmenu");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StringUtil.copyPartialMatches(args[2], completions, finalCompletions);
|
StringUtil.copyPartialMatches(args[2], completions, finalCompletions);
|
||||||
@@ -122,8 +129,14 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
|||||||
String subcommand = args[0].toLowerCase();
|
String subcommand = args[0].toLowerCase();
|
||||||
switch (subcommand) {
|
switch (subcommand) {
|
||||||
case "apply" -> {
|
case "apply" -> {
|
||||||
|
if (Hooks.isActiveHook("HMCColor")) completions.addAll(HMCColorContextKt.getHmcColor().getConfig().getColors().keySet());
|
||||||
completions.add("#FFFFFF");
|
completions.add("#FFFFFF");
|
||||||
}
|
}
|
||||||
|
case "setwardrobesetting" -> {
|
||||||
|
if (args[2].equalsIgnoreCase("defaultmenu")) {
|
||||||
|
completions.addAll(Menus.getMenuNames());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
StringUtil.copyPartialMatches(args[3], completions, finalCompletions);
|
StringUtil.copyPartialMatches(args[3], completions, finalCompletions);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.config;
|
package com.hibiscusmc.hmccosmetics.config;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||||
|
|
||||||
public class DatabaseSettings {
|
public class DatabaseSettings {
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package com.hibiscusmc.hmccosmetics.config;
|
|||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.GameMode;
|
import lombok.Setter;
|
||||||
|
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
@@ -29,34 +30,30 @@ public class Settings {
|
|||||||
private static final String UNAPPLY_DEATH_PATH = "unapply-on-death";
|
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_PERMISSION_JOIN_PATH = "force-permission-join";
|
||||||
private static final String FORCE_SHOW_COSMETICS_PATH = "force-show-join";
|
private static final String FORCE_SHOW_COSMETICS_PATH = "force-show-join";
|
||||||
|
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_PATH = "disabled-gamemode";
|
||||||
private static final String DISABLED_GAMEMODE_GAMEMODES_PATH = "gamemodes";
|
private static final String DISABLED_GAMEMODE_GAMEMODES_PATH = "gamemodes";
|
||||||
private static final String EMOTE_DISTANCE_PATH = "emote-distance";
|
|
||||||
private static final String HOOK_SETTING_PATH = "hook-settings";
|
private static final String HOOK_SETTING_PATH = "hook-settings";
|
||||||
private static final String HOOK_ITEMADDER_PATH = "itemsadder";
|
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_RELOAD_CHANGE_PATH = "reload-on-change";
|
||||||
private static final String HOOK_WORLDGUARD_PATH = "worldguard";
|
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 = "player-move-check";
|
||||||
private static final String HOOK_WG_MOVE_CHECK_PATH_LEGACY = "player_move_check";
|
private static final String HOOK_WG_MOVE_CHECK_PATH_LEGACY = "player_move_check";
|
||||||
private static final String COSMETIC_EMOTE_ENABLE = "emote-enable";
|
private static final String COSMETIC_DISABLED_WORLDS_PATH = "disabled-worlds";
|
||||||
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_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_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_DESTROY_LOOSE_COSMETIC_PATH = "destroy-loose-cosmetics";
|
||||||
|
private static final String COSMETIC_BALLOON_HEAD_FORWARD_PATH = "balloon-head-forward";
|
||||||
|
private static final String COSMETIC_OFFHAND_PREVENT_SWAPPING = "offhand-prevent-swapping";
|
||||||
private static final String MENU_SETTINGS_PATH = "menu-settings";
|
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 COSMETIC_TYPE_SETTINGS_PATH = "cosmetic-type";
|
||||||
private static final String EQUIP_CLICK_TYPE = "equip-click";
|
private static final String EQUIP_CLICK_TYPE = "equip-click";
|
||||||
private static final String UNEQUIP_CLICK_TYPE = "unequip-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 SHADING_PATH = "shading";
|
||||||
private static final String FIRST_ROW_SHIFT_PATH = "first-row-shift";
|
private static final String FIRST_ROW_SHIFT_PATH = "first-row-shift";
|
||||||
private static final String SEQUENT_ROW_SHIFT_PATH = "sequent-row-shift";
|
private static final String SEQUENT_ROW_SHIFT_PATH = "sequent-row-shift";
|
||||||
@@ -67,6 +64,10 @@ public class Settings {
|
|||||||
private static final String EQUIPABLE_COSMETIC_COLOR_PATH = "equipable-cosmetic-color";
|
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 LOCKED_COSMETIC_COLOR_PATH = "locked-cosmetic-color";
|
||||||
private static final String ENABLED_PATH = "enabled";
|
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
|
@Getter
|
||||||
private static String defaultMenu;
|
private static String defaultMenu;
|
||||||
@@ -87,45 +88,40 @@ public class Settings {
|
|||||||
@Getter
|
@Getter
|
||||||
private static boolean forceShowOnJoin;
|
private static boolean forceShowOnJoin;
|
||||||
@Getter
|
@Getter
|
||||||
|
private static boolean itemProcessingDisplayName;
|
||||||
|
@Getter
|
||||||
|
private static boolean itemProcessingLore;
|
||||||
|
@Getter
|
||||||
private static boolean itemsAdderChangeReload;
|
private static boolean itemsAdderChangeReload;
|
||||||
@Getter
|
@Getter
|
||||||
|
private static boolean nexoChangeReload;
|
||||||
|
@Getter
|
||||||
private static boolean worldGuardMoveCheck;
|
private static boolean worldGuardMoveCheck;
|
||||||
@Getter
|
private static final HashMap<EquipmentSlot, SlotOptionConfig> slotOptions = new HashMap<>();
|
||||||
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;
|
|
||||||
@Getter
|
@Getter
|
||||||
private static boolean destroyLooseCosmetics;
|
private static boolean destroyLooseCosmetics;
|
||||||
@Getter
|
@Getter
|
||||||
|
private static boolean preventOffhandSwapping;
|
||||||
|
@Getter
|
||||||
private static boolean backpackForceRidingEnabled;
|
private static boolean backpackForceRidingEnabled;
|
||||||
@Getter
|
@Getter
|
||||||
private static boolean cosmeticForceOffhandCosmeticShow;
|
|
||||||
@Getter
|
|
||||||
private static boolean emotesEnabled;
|
|
||||||
@Getter
|
|
||||||
private static boolean disabledGamemodesEnabled;
|
private static boolean disabledGamemodesEnabled;
|
||||||
@Getter
|
@Getter
|
||||||
|
private static boolean balloonHeadForward;
|
||||||
|
@Getter
|
||||||
|
private static boolean backpackPreventDarkness;
|
||||||
|
@Getter
|
||||||
private static List<String> disabledGamemodes;
|
private static List<String> disabledGamemodes;
|
||||||
@Getter
|
@Getter
|
||||||
|
private static List<String> disabledWorlds;
|
||||||
|
@Getter
|
||||||
private static int viewDistance;
|
private static int viewDistance;
|
||||||
@Getter
|
@Getter
|
||||||
private static int tickPeriod;
|
private static int tickPeriod;
|
||||||
@Getter
|
@Getter
|
||||||
private static int packetEntityTeleportCooldown;
|
private static Long defaultMenuCooldown;
|
||||||
@Getter
|
@Getter
|
||||||
private static double emoteDistance;
|
private static boolean menuClickCooldown;
|
||||||
@Getter
|
@Getter
|
||||||
private static Vector balloonOffset;
|
private static Vector balloonOffset;
|
||||||
@Getter
|
@Getter
|
||||||
@@ -133,6 +129,8 @@ public class Settings {
|
|||||||
@Getter
|
@Getter
|
||||||
private static String cosmeticUnEquipClickType;
|
private static String cosmeticUnEquipClickType;
|
||||||
@Getter
|
@Getter
|
||||||
|
private static String cosmeticDyeClickType;
|
||||||
|
@Getter
|
||||||
private static boolean defaultShading;
|
private static boolean defaultShading;
|
||||||
@Getter
|
@Getter
|
||||||
private static String firstRowShift;
|
private static String firstRowShift;
|
||||||
@@ -150,10 +148,10 @@ public class Settings {
|
|||||||
private static String equipableCosmeticColor;
|
private static String equipableCosmeticColor;
|
||||||
@Getter
|
@Getter
|
||||||
private static String lockedCosmeticColor;
|
private static String lockedCosmeticColor;
|
||||||
|
@Getter @Setter
|
||||||
|
private static boolean allPlayersHidden;
|
||||||
@Getter
|
@Getter
|
||||||
private static boolean emoteCameraEnabled;
|
private static boolean wardrobeHideHud;
|
||||||
@Getter
|
|
||||||
private static boolean emoteMoveCheck;
|
|
||||||
|
|
||||||
|
|
||||||
public static void load(ConfigurationNode source) {
|
public static void load(ConfigurationNode source) {
|
||||||
@@ -177,34 +175,45 @@ public class Settings {
|
|||||||
disabledGamemodesEnabled = disabledGamemodeSettings.node(ENABLED_PATH).getBoolean(true);
|
disabledGamemodesEnabled = disabledGamemodeSettings.node(ENABLED_PATH).getBoolean(true);
|
||||||
try {
|
try {
|
||||||
disabledGamemodes = disabledGamemodeSettings.node(DISABLED_GAMEMODE_GAMEMODES_PATH).getList(String.class);
|
disabledGamemodes = disabledGamemodeSettings.node(DISABLED_GAMEMODE_GAMEMODES_PATH).getList(String.class);
|
||||||
|
disabledWorlds = cosmeticSettings.node(COSMETIC_DISABLED_WORLDS_PATH).getList(String.class);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
disabledGamemodes = new ArrayList<>();
|
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);
|
unapplyOnDeath = cosmeticSettings.node(UNAPPLY_DEATH_PATH).getBoolean(false);
|
||||||
forcePermissionJoin = cosmeticSettings.node(FORCE_PERMISSION_JOIN_PATH).getBoolean(false);
|
forcePermissionJoin = cosmeticSettings.node(FORCE_PERMISSION_JOIN_PATH).getBoolean(false);
|
||||||
forceShowOnJoin = cosmeticSettings.node(FORCE_SHOW_COSMETICS_PATH).getBoolean(false);
|
forceShowOnJoin = cosmeticSettings.node(FORCE_SHOW_COSMETICS_PATH).getBoolean(false);
|
||||||
emotesEnabled = cosmeticSettings.node(COSMETIC_EMOTE_ENABLE).getBoolean(true);
|
|
||||||
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);
|
destroyLooseCosmetics = cosmeticSettings.node(COSMETIC_DESTROY_LOOSE_COSMETIC_PATH).getBoolean(false);
|
||||||
backpackForceRidingEnabled = cosmeticSettings.node(COSMETIC_BACKPACK_FORCE_RIDING_PACKET_PATH).getBoolean(false);
|
backpackForceRidingEnabled = cosmeticSettings.node(COSMETIC_BACKPACK_FORCE_RIDING_PACKET_PATH).getBoolean(false);
|
||||||
addHelmetEnchants = cosmeticSettings.node(COSMETIC_ADD_ENCHANTS_HELMET_PATH).getBoolean(false);
|
preventOffhandSwapping = cosmeticSettings.node(COSMETIC_OFFHAND_PREVENT_SWAPPING).getBoolean(false);
|
||||||
addChestplateEnchants = cosmeticSettings.node(COSMETIC_ADD_ENCHANTS_CHESTPLATE_PATH).getBoolean(false);
|
|
||||||
addLeggingEnchants = cosmeticSettings.node(COSMETIC_ADD_ENCHANTS_LEGGINGS_PATH).getBoolean(false);
|
cosmeticSettings.node(SLOT_OPTIONS_PATH).childrenMap().forEach((key, value) -> {
|
||||||
addBootsEnchants = cosmeticSettings.node(COSMETIC_ADD_ENCHANTS_BOOTS_PATH).getBoolean(false);
|
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);
|
tickPeriod = cosmeticSettings.node(TICK_PERIOD_PATH).getInt(-1);
|
||||||
viewDistance = cosmeticSettings.node(VIEW_DISTANCE_PATH).getInt(-3);
|
viewDistance = cosmeticSettings.node(VIEW_DISTANCE_PATH).getInt(-3);
|
||||||
emoteCameraEnabled = cosmeticSettings.node(COSMETIC_EMOTE_CAMERA_PATH).getBoolean(true);
|
balloonHeadForward = cosmeticSettings.node(COSMETIC_BALLOON_HEAD_FORWARD_PATH).getBoolean(false);
|
||||||
emoteMoveCheck = cosmeticSettings.node(COSMETIC_EMOTE_MOVE_CHECK_PATH).getBoolean(false);
|
backpackPreventDarkness = cosmeticSettings.node(BACKPACK_PREVENT_DARKNESS_PATH).getBoolean(true);
|
||||||
packetEntityTeleportCooldown = cosmeticSettings.node(COSMETIC_PACKET_ENTITY_TELEPORT_COOLDOWN_PATH).getInt(-1);
|
|
||||||
cosmeticForceOffhandCosmeticShow = cosmeticSettings.node(COSMETIC_FORCE_OFFHAND_COSMETIC_SHOW_PATH).getBoolean(false);
|
|
||||||
|
|
||||||
ConfigurationNode menuSettings = source.node(MENU_SETTINGS_PATH);
|
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);
|
ConfigurationNode shadingSettings = menuSettings.node(SHADING_PATH);
|
||||||
defaultShading = shadingSettings.node(ENABLED_PATH).getBoolean();
|
defaultShading = shadingSettings.node(ENABLED_PATH).getBoolean();
|
||||||
firstRowShift = shadingSettings.node(FIRST_ROW_SHIFT_PATH).getString();
|
firstRowShift = shadingSettings.node(FIRST_ROW_SHIFT_PATH).getString();
|
||||||
@@ -217,8 +226,9 @@ public class Settings {
|
|||||||
lockedCosmeticColor = shadingSettings.node(LOCKED_COSMETIC_COLOR_PATH).getString();
|
lockedCosmeticColor = shadingSettings.node(LOCKED_COSMETIC_COLOR_PATH).getString();
|
||||||
|
|
||||||
ConfigurationNode cosmeticTypeSettings = menuSettings.node(COSMETIC_TYPE_SETTINGS_PATH);
|
ConfigurationNode cosmeticTypeSettings = menuSettings.node(COSMETIC_TYPE_SETTINGS_PATH);
|
||||||
cosmeticEquipClickType = cosmeticTypeSettings.node(EQUIP_CLICK_TYPE).getString("ALL");
|
cosmeticEquipClickType = cosmeticTypeSettings.node(EQUIP_CLICK_TYPE).getString("ANY");
|
||||||
cosmeticUnEquipClickType = cosmeticTypeSettings.node(UNEQUIP_CLICK_TYPE).getString("ALL");
|
cosmeticUnEquipClickType = cosmeticTypeSettings.node(UNEQUIP_CLICK_TYPE).getString("ANY");
|
||||||
|
cosmeticDyeClickType = cosmeticTypeSettings.node(DYE_CLICK_TYPE).getString("ANY");
|
||||||
|
|
||||||
final var balloonSection = cosmeticSettings.node(BALLOON_OFFSET);
|
final var balloonSection = cosmeticSettings.node(BALLOON_OFFSET);
|
||||||
balloonOffset = loadVector(balloonSection);
|
balloonOffset = loadVector(balloonSection);
|
||||||
@@ -230,9 +240,16 @@ public class Settings {
|
|||||||
dyeMenuOutputSlot = dyeMenuSettings.node(DYE_MENU_OUTPUT_SLOT).getInt(25);
|
dyeMenuOutputSlot = dyeMenuSettings.node(DYE_MENU_OUTPUT_SLOT).getInt(25);
|
||||||
|
|
||||||
ConfigurationNode hookSettings = source.node(HOOK_SETTING_PATH);
|
ConfigurationNode hookSettings = source.node(HOOK_SETTING_PATH);
|
||||||
|
|
||||||
ConfigurationNode itemsAdderSettings = hookSettings.node(HOOK_ITEMADDER_PATH);
|
ConfigurationNode itemsAdderSettings = hookSettings.node(HOOK_ITEMADDER_PATH);
|
||||||
itemsAdderChangeReload = itemsAdderSettings.node(HOOK_RELOAD_CHANGE_PATH).getBoolean(false);
|
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);
|
ConfigurationNode worldGuardSettings = hookSettings.node(HOOK_WORLDGUARD_PATH);
|
||||||
worldGuardMoveCheck = worldGuardSettings.node(HOOK_WG_MOVE_CHECK_PATH).getBoolean(true);
|
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.
|
// I messed up in release 2.2.6 and forgot to change player_move_check to player-move-check.
|
||||||
@@ -246,24 +263,9 @@ public class Settings {
|
|||||||
return new Vector(config.node("x").getDouble(), config.node("y").getDouble(), config.node("z").getDouble());
|
return new Vector(config.node("x").getDouble(), config.node("y").getDouble(), config.node("z").getDouble());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean getShouldAddEnchants(EquipmentSlot slot) {
|
public static SlotOptionConfig getSlotOption(EquipmentSlot slot) {
|
||||||
switch (slot) {
|
if (!slotOptions.containsKey(slot)) slotOptions.put(slot, new SlotOptionConfig(slot, false, false));
|
||||||
case HEAD -> {
|
return slotOptions.get(slot);
|
||||||
return addHelmetEnchants;
|
|
||||||
}
|
|
||||||
case CHEST -> {
|
|
||||||
return addChestplateEnchants;
|
|
||||||
}
|
|
||||||
case LEGS -> {
|
|
||||||
return addLeggingEnchants;
|
|
||||||
}
|
|
||||||
case FEET -> {
|
|
||||||
return addBootsEnchants;
|
|
||||||
}
|
|
||||||
default -> {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setDebugMode(boolean newSetting) {
|
public static void setDebugMode(boolean newSetting) {
|
||||||
@@ -275,4 +277,16 @@ public class Settings {
|
|||||||
|
|
||||||
plugin.saveConfig();
|
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;
|
private final String id;
|
||||||
@Getter @Setter
|
@Getter @Setter
|
||||||
private int distance;
|
private int distance;
|
||||||
@Getter @Setter
|
@Getter @Setter @Nullable
|
||||||
private String permission;
|
private String permission;
|
||||||
@Getter @Setter
|
@Getter @Setter
|
||||||
private WardrobeLocation location;
|
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.
|
* 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 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 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 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.id = id;
|
||||||
this.location = location;
|
this.location = location;
|
||||||
this.distance = distance;
|
this.distance = distance;
|
||||||
if (permission != null) this.permission = permission;
|
if (permission != null) this.permission = permission;
|
||||||
|
if (defaultMenu != null) this.defaultMenu = defaultMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,7 +54,7 @@ public class Wardrobe {
|
|||||||
Location wardrobeLocation = location.getNpcLocation();
|
Location wardrobeLocation = location.getNpcLocation();
|
||||||
Location location = user.getEntity().getLocation();
|
Location location = user.getEntity().getLocation();
|
||||||
if (wardrobeLocation == null) return false;
|
if (wardrobeLocation == null) return false;
|
||||||
if (distance == -1) return true;
|
if (distance <= 0) return true;
|
||||||
if (!wardrobeLocation.getWorld().equals(location.getWorld())) return false;
|
if (!wardrobeLocation.getWorld().equals(location.getWorld())) return false;
|
||||||
return wardrobeLocation.distanceSquared(location) <= distance * distance;
|
return wardrobeLocation.distanceSquared(location) <= distance * distance;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.config;
|
package com.hibiscusmc.hmccosmetics.config;
|
||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
import com.hibiscusmc.hmccosmetics.config.serializer.LocationSerializer;
|
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import com.hibiscusmc.hmccosmetics.util.misc.Utils;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import me.lojosho.hibiscuscommons.config.serializer.LocationSerializer;
|
||||||
|
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||||
import net.kyori.adventure.bossbar.BossBar;
|
import net.kyori.adventure.bossbar.BossBar;
|
||||||
import org.apache.commons.lang3.EnumUtils;
|
import org.apache.commons.lang3.EnumUtils;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -33,6 +32,8 @@ public class WardrobeSettings {
|
|||||||
private static final String EQUIP_PUMPKIN_WARDROBE = "equip-pumpkin";
|
private static final String EQUIP_PUMPKIN_WARDROBE = "equip-pumpkin";
|
||||||
private static final String TRY_COSMETICS_WARDROBE = "unchecked-wardrobe-cosmetics";
|
private static final String TRY_COSMETICS_WARDROBE = "unchecked-wardrobe-cosmetics";
|
||||||
private static final String RETURN_LAST_LOCATION = "return-last-location";
|
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_MENU_OPTIONS = "menu-options";
|
||||||
private static final String WARDROBE_ENTER_OPEN_MENU_PATH = "enter-open-menu";
|
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 WARDROBES_PATH = "wardrobes";
|
||||||
private static final String PERMISSION_PATH = "permission";
|
private static final String PERMISSION_PATH = "permission";
|
||||||
private static final String DISTANCE_PATH = "distance";
|
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_PATH = "bossbar";
|
||||||
private static final String BOSSBAR_ENABLE_PATH = "enabled";
|
private static final String BOSSBAR_ENABLE_PATH = "enabled";
|
||||||
private static final String BOSSBAR_TEXT_PATH = "text";
|
private static final String BOSSBAR_TEXT_PATH = "text";
|
||||||
@@ -87,6 +89,10 @@ public class WardrobeSettings {
|
|||||||
@Getter
|
@Getter
|
||||||
private static boolean forceExitGamemode;
|
private static boolean forceExitGamemode;
|
||||||
@Getter
|
@Getter
|
||||||
|
private static boolean damagedKicked;
|
||||||
|
@Getter
|
||||||
|
private static boolean preventDamage;
|
||||||
|
@Getter
|
||||||
private static GameMode exitGamemode;
|
private static GameMode exitGamemode;
|
||||||
private static HashMap<String, Wardrobe> wardrobes;
|
private static HashMap<String, Wardrobe> wardrobes;
|
||||||
@Getter
|
@Getter
|
||||||
@@ -121,6 +127,8 @@ public class WardrobeSettings {
|
|||||||
equipPumpkin = source.node(EQUIP_PUMPKIN_WARDROBE).getBoolean();
|
equipPumpkin = source.node(EQUIP_PUMPKIN_WARDROBE).getBoolean();
|
||||||
returnLastLocation = source.node(RETURN_LAST_LOCATION).getBoolean(false);
|
returnLastLocation = source.node(RETURN_LAST_LOCATION).getBoolean(false);
|
||||||
tryCosmeticsInWardrobe = source.node(TRY_COSMETICS_WARDROBE).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);
|
ConfigurationNode menuOptionsNode = source.node(WARDROBE_MENU_OPTIONS);
|
||||||
enterOpenMenu = menuOptionsNode.node(WARDROBE_ENTER_OPEN_MENU_PATH).getBoolean(false);
|
enterOpenMenu = menuOptionsNode.node(WARDROBE_ENTER_OPEN_MENU_PATH).getBoolean(false);
|
||||||
@@ -161,14 +169,16 @@ public class WardrobeSettings {
|
|||||||
MessagesUtil.sendDebugMessages("Wardrobe Location: " + npcLocation);
|
MessagesUtil.sendDebugMessages("Wardrobe Location: " + npcLocation);
|
||||||
Location viewerLocation = LocationSerializer.INSTANCE.deserialize(Location.class, wardrobesNode.node(VIEWER_LOCATION_PATH));
|
Location viewerLocation = LocationSerializer.INSTANCE.deserialize(Location.class, wardrobesNode.node(VIEWER_LOCATION_PATH));
|
||||||
MessagesUtil.sendDebugMessages("Viewer Location: " + viewerLocation);
|
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);
|
MessagesUtil.sendDebugMessages("Leave Location: " + leaveLocation);
|
||||||
WardrobeLocation wardrobeLocation = new WardrobeLocation(npcLocation, viewerLocation, leaveLocation);
|
WardrobeLocation wardrobeLocation = new WardrobeLocation(npcLocation, viewerLocation, leaveLocation);
|
||||||
|
|
||||||
String permission = wardrobesNode.node(PERMISSION_PATH).getString();
|
String permission = wardrobesNode.node(PERMISSION_PATH).getString();
|
||||||
|
String defaultMenu = wardrobesNode.node(WARDROBE_DEFAULT_MENU).getString();
|
||||||
int distance = wardrobesNode.node(DISTANCE_PATH).getInt(-1);
|
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);
|
addWardrobe(wardrobe);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MessagesUtil.sendDebugMessages("Unable to create wardrobe " + id, Level.SEVERE);
|
MessagesUtil.sendDebugMessages("Unable to create wardrobe " + id, Level.SEVERE);
|
||||||
@@ -272,4 +282,14 @@ public class WardrobeSettings {
|
|||||||
|
|
||||||
plugin.saveConfig();
|
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,35 +1,69 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.cosmetic;
|
package com.hibiscusmc.hmccosmetics.cosmetic;
|
||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.config.serializer.ItemSerializer;
|
import com.hibiscusmc.hmccosmetics.cosmetic.behavior.CosmeticUpdateBehavior;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
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.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
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;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
public abstract class Cosmetic {
|
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;
|
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;
|
||||||
|
|
||||||
|
/** The config for the cosmetic */
|
||||||
|
private ConfigurationNode config;
|
||||||
|
|
||||||
|
protected Cosmetic(@NotNull String id, @NotNull ConfigurationNode config) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
this.config = config;
|
||||||
|
|
||||||
if (!config.node("permission").virtual()) {
|
if (!config.node("permission").virtual()) {
|
||||||
this.permission = config.node("permission").getString();
|
this.permission = config.node("permission").getString();
|
||||||
@@ -39,23 +73,54 @@ public abstract class Cosmetic {
|
|||||||
|
|
||||||
if (!config.node("item").virtual()) {
|
if (!config.node("item").virtual()) {
|
||||||
this.material = config.node("item", "material").getString();
|
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());
|
MessagesUtil.sendDebugMessages("Slot: " + config.node("slot").getString());
|
||||||
|
this.slot = CosmeticSlot.valueOf(config.node("slot").getString());
|
||||||
|
|
||||||
setSlot(CosmeticSlot.valueOf(config.node("slot").getString()));
|
this.dyeable = config.node("dyeable").getBoolean(false);
|
||||||
setDyable(config.node("dyeable").getBoolean(false));
|
MessagesUtil.sendDebugMessages("Dyeable " + dyeable);
|
||||||
|
}
|
||||||
|
|
||||||
MessagesUtil.sendDebugMessages("Dyeable " + dyable);
|
protected Cosmetic(String id, String permission, ItemStack item, String material, CosmeticSlot slot, boolean dyeable) {
|
||||||
Cosmetics.addCosmetic(this);
|
this.id = id;
|
||||||
|
this.permission = permission;
|
||||||
|
this.item = item;
|
||||||
|
this.material = material;
|
||||||
|
this.slot = slot;
|
||||||
|
this.dyeable = dyeable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean requiresPermission() {
|
public boolean requiresPermission() {
|
||||||
return permission != null;
|
return permission != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void update(CosmeticUser user);
|
/**
|
||||||
|
* Dispatched when an update is requested upon the cosmetic. Instead, you should use {@link CosmeticUser#updateCosmetic(CosmeticSlot)})}
|
||||||
|
* @param user the user to preform the update against
|
||||||
|
*/
|
||||||
|
@Deprecated(since = "2.8.2")
|
||||||
|
public void update(CosmeticUser user) {
|
||||||
|
if(this instanceof CosmeticUpdateBehavior behavior) {
|
||||||
|
behavior.dispatchUpdate(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Action preformed on the update. Instead, you should use {@link CosmeticUser#updateCosmetic(CosmeticSlot)})}
|
||||||
|
* @param user the user to preform the update against
|
||||||
|
*/
|
||||||
|
@Deprecated(since = "2.8.2")
|
||||||
|
protected void doUpdate(final CosmeticUser user) {
|
||||||
|
// #update should be the preferred way of interacting with this api now.
|
||||||
|
this.update(user);
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public ItemStack getItem() {
|
public ItemStack getItem() {
|
||||||
@@ -63,6 +128,11 @@ public abstract class Cosmetic {
|
|||||||
return item.clone();
|
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) {
|
protected ItemStack generateItemStack(ConfigurationNode config) {
|
||||||
try {
|
try {
|
||||||
ItemStack item = ItemSerializer.INSTANCE.deserialize(ItemStack.class, config);
|
ItemStack item = ItemSerializer.INSTANCE.deserialize(ItemStack.class, config);
|
||||||
@@ -76,4 +146,14 @@ public abstract class Cosmetic {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* While cosmetics registered in HMCC are made through a configuration, cosmetics registered from other plugins
|
||||||
|
* may not and instead opt for {@link Cosmetic#Cosmetic(String, String, ItemStack, String, CosmeticSlot, boolean)}, which doesn't use a config.
|
||||||
|
* This should be used only for reference.
|
||||||
|
*/
|
||||||
|
@ApiStatus.Experimental
|
||||||
|
public @Nullable ConfigurationNode getConfig() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.cosmetic;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableCollection;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.bukkit.Color;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
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);
|
||||||
|
|
||||||
|
boolean updateCosmetic(@NotNull CosmeticSlot slot);
|
||||||
|
|
||||||
|
boolean updateMovementCosmetic(@NotNull CosmeticSlot slot, final Location from, final Location to);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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,68 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.cosmetic;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.types.*;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
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.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;
|
package com.hibiscusmc.hmccosmetics.cosmetic;
|
||||||
|
|
||||||
public enum CosmeticSlot {
|
import lombok.Getter;
|
||||||
HELMET,
|
import org.jetbrains.annotations.NotNull;
|
||||||
CHESTPLATE,
|
import org.jetbrains.annotations.Nullable;
|
||||||
LEGGINGS,
|
|
||||||
BOOTS,
|
import java.util.Collections;
|
||||||
MAINHAND,
|
import java.util.Map;
|
||||||
OFFHAND,
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
BACKPACK,
|
|
||||||
BALLOON,
|
@Getter
|
||||||
EMOTE
|
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.google.common.collect.HashBiMap;
|
||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.*;
|
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
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.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
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.io.File;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@@ -21,10 +19,12 @@ import java.util.Set;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
public class Cosmetics {
|
public class Cosmetics {
|
||||||
|
|
||||||
private static final HashBiMap<String, Cosmetic> COSMETICS = HashBiMap.create();
|
private static final HashBiMap<String, Cosmetic> COSMETICS = HashBiMap.create();
|
||||||
|
|
||||||
|
private static CosmeticProvider PROVIDER = CosmeticProvider.Default.INSTANCE;
|
||||||
|
|
||||||
public static void addCosmetic(Cosmetic cosmetic) {
|
public static void addCosmetic(Cosmetic cosmetic) {
|
||||||
COSMETICS.put(cosmetic.getId(), cosmetic);
|
COSMETICS.put(cosmetic.getId(), cosmetic);
|
||||||
}
|
}
|
||||||
@@ -34,7 +34,7 @@ public class Cosmetics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void removeCosmetic(Cosmetic cosmetic) {
|
public static void removeCosmetic(Cosmetic cosmetic) {
|
||||||
COSMETICS.remove(cosmetic);
|
COSMETICS.remove(cosmetic.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@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) {
|
private static void setupCosmetics(@NotNull CommentedConfigurationNode config) {
|
||||||
for (ConfigurationNode cosmeticConfig : config.childrenMap().values()) {
|
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 {
|
try {
|
||||||
String id = cosmeticConfig.key().toString();
|
addCosmetic(PROVIDER.createCosmetic(id, cosmeticConfig, cosmeticSlot));
|
||||||
MessagesUtil.sendDebugMessages("Attempting to add " + id);
|
} catch(Exception ex) {
|
||||||
ConfigurationNode slotNode = cosmeticConfig.node("slot");
|
log.error("Unable to construct cosmetic for {}, skipping processing it.", id, ex);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.cosmetic.behavior;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates cosmetics whenever a player moves.
|
||||||
|
*/
|
||||||
|
public interface CosmeticMovementBehavior {
|
||||||
|
void dispatchMove(
|
||||||
|
@NotNull final CosmeticUser user,
|
||||||
|
@NotNull final Location from,
|
||||||
|
@NotNull final Location to
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.cosmetic.behavior;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic updates that happen every tick or when manually requested to be dispatched.
|
||||||
|
*/
|
||||||
|
public interface CosmeticUpdateBehavior {
|
||||||
|
void dispatchUpdate(
|
||||||
|
@NotNull final CosmeticUser user
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -2,10 +2,12 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
import com.hibiscusmc.hmccosmetics.cosmetic.behavior.CosmeticUpdateBehavior;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
|
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
|
||||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
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.Bukkit;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
@@ -13,36 +15,51 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
|
||||||
|
|
||||||
public class CosmeticArmorType extends Cosmetic {
|
|
||||||
|
|
||||||
|
public class CosmeticArmorType extends Cosmetic implements CosmeticUpdateBehavior {
|
||||||
private final EquipmentSlot equipSlot;
|
private final EquipmentSlot equipSlot;
|
||||||
|
|
||||||
public CosmeticArmorType(String id, ConfigurationNode config) {
|
public CosmeticArmorType(String id, ConfigurationNode config) {
|
||||||
super(id, 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
|
@Override
|
||||||
public void update(@NotNull CosmeticUser user) {
|
public void dispatchUpdate(@NotNull CosmeticUser user) {
|
||||||
|
if (user.isInWardrobe()) return;
|
||||||
Entity entity = Bukkit.getEntity(user.getUniqueId());
|
Entity entity = Bukkit.getEntity(user.getUniqueId());
|
||||||
if (entity == null) return;
|
if (entity == null) return;
|
||||||
if (user.getUserEmoteManager().isPlayingEmote()) return; // There has to be a better way of doing this...
|
if (Settings.getSlotOption(equipSlot).isRequireEmpty() && entity instanceof HumanEntity humanEntity) {
|
||||||
ItemStack cosmeticItem = user.getUserCosmeticItem(this);
|
if (!humanEntity.getInventory().getItem(equipSlot).getType().isAir()) return;
|
||||||
if (!(entity instanceof HumanEntity humanEntity)) return;
|
}
|
||||||
ItemStack equippedItem = humanEntity.getInventory().getItem(equipSlot);
|
ItemStack item = getItem(user);
|
||||||
if (Settings.getShouldAddEnchants(equipSlot)) {
|
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) {
|
||||||
|
Player player = user.getPlayer();
|
||||||
|
if (player == null) return null;
|
||||||
|
|
||||||
|
if (Settings.getSlotOption(equipSlot).isAddEnchantments()) {
|
||||||
|
ItemStack equippedItem = player.getInventory().getItem(equipSlot);
|
||||||
cosmeticItem.addUnsafeEnchantments(equippedItem.getEnchantments());
|
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
|
// Basically, if force offhand is off AND there is no item in an offhand slot, then the equipment packet to add the cosmetic
|
||||||
if (!Settings.isCosmeticForceOffhandCosmeticShow()
|
return cosmeticItem;
|
||||||
&& equipSlot.equals(EquipmentSlot.OFF_HAND)
|
|
||||||
&& ((entity instanceof Player) && !user.getPlayer().getInventory().getItemInOffHand().getType().isAir())) return;
|
|
||||||
NMSHandlers.getHandler().equipmentSlotUpdate(entity.getEntityId(), equipSlot, cosmeticItem, PacketManager.getViewers(entity.getLocation()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public EquipmentSlot getEquipSlot() {
|
public EquipmentSlot getEquipSlot() {
|
||||||
return this.equipSlot;
|
return this.equipSlot;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,39 +2,36 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
import com.hibiscusmc.hmccosmetics.cosmetic.behavior.CosmeticMovementBehavior;
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.behavior.CosmeticUpdateBehavior;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.user.manager.UserBackpackManager;
|
||||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
import com.hibiscusmc.hmccosmetics.user.manager.UserEntity;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.Bukkit;
|
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
|
||||||
|
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.attribute.Attribute;
|
||||||
|
import org.bukkit.attribute.AttributeInstance;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
public class CosmeticBackpackType extends Cosmetic {
|
@Getter
|
||||||
|
public class CosmeticBackpackType extends Cosmetic implements CosmeticUpdateBehavior, CosmeticMovementBehavior {
|
||||||
@Getter
|
|
||||||
private final String modelName;
|
|
||||||
@Getter
|
|
||||||
private int height = -1;
|
private int height = -1;
|
||||||
private ItemStack firstPersonBackpack;
|
private ItemStack firstPersonBackpack;
|
||||||
|
|
||||||
public CosmeticBackpackType(String id, ConfigurationNode config) {
|
public CosmeticBackpackType(String id, ConfigurationNode config) {
|
||||||
super(id, config);
|
super(id, config);
|
||||||
|
|
||||||
modelName = config.node("model").getString();
|
|
||||||
|
|
||||||
if (!config.node("firstperson-item").virtual()) {
|
if (!config.node("firstperson-item").virtual()) {
|
||||||
this.firstPersonBackpack = generateItemStack(config.node("firstperson-item"));
|
this.firstPersonBackpack = generateItemStack(config.node("firstperson-item"));
|
||||||
this.height = config.node("height").getInt(5);
|
this.height = config.node("height").getInt(5);
|
||||||
@@ -42,54 +39,87 @@ public class CosmeticBackpackType extends Cosmetic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(@NotNull CosmeticUser user) {
|
public void dispatchUpdate(@NotNull CosmeticUser user) {
|
||||||
Entity entity = Bukkit.getEntity(user.getUniqueId());
|
Entity entity = user.getEntity();
|
||||||
if (entity == null) return;
|
if(entity == null) {
|
||||||
|
return;
|
||||||
Location loc = entity.getLocation().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);
|
|
||||||
|
|
||||||
user.getUserBackpackManager().getEntityManager().teleport(loc);
|
|
||||||
user.getUserBackpackManager().getEntityManager().setRotation((int) loc.getYaw(), isFirstPersonCompadible());
|
|
||||||
|
|
||||||
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);
|
|
||||||
// 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 (!user.isInWardrobe() && isFirstPersonCompadible() && user.getPlayer() != null) {
|
|
||||||
List<Player> owner = List.of(user.getPlayer());
|
|
||||||
|
|
||||||
ArrayList<Integer> particleCloud = user.getUserBackpackManager().getAreaEffectEntityId();
|
|
||||||
for (int i = 0; i < particleCloud.size(); i++) {
|
|
||||||
if (i == 0) {
|
|
||||||
PacketManager.sendRidingPacket(entity.getEntityId(), particleCloud.get(i), owner);
|
|
||||||
} else {
|
|
||||||
PacketManager.sendRidingPacket(particleCloud.get(i - 1), particleCloud.get(i) , owner);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PacketManager.sendRidingPacket(particleCloud.get(particleCloud.size() - 1), user.getUserBackpackManager().getFirstArmorStandId(), owner);
|
|
||||||
if (!user.getHidden()) {
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
MessagesUtil.sendDebugMessages("First Person Backpack Update[owner=" + user.getUniqueId() + ",player_location=" + loc + "]!", Level.INFO);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
user.getUserBackpackManager().showBackpack();
|
Location entityLocation = entity.getLocation();
|
||||||
|
Location loc = entityLocation.clone().add(0, 2, 0);
|
||||||
|
|
||||||
|
UserBackpackManager backpackManager = user.getUserBackpackManager();
|
||||||
|
if(backpackManager == null) return;
|
||||||
|
|
||||||
|
UserEntity entityManager = backpackManager.getEntityManager();
|
||||||
|
if(entityManager == null) return;
|
||||||
|
|
||||||
|
entityManager.teleport(loc);
|
||||||
|
entityManager.setRotation((int) loc.getYaw(), isFirstPersonCompadible());
|
||||||
|
|
||||||
|
int firstArmorStandId = backpackManager.getFirstArmorStandId();
|
||||||
|
|
||||||
|
List<Player> newViewers = entityManager.refreshViewers(loc);
|
||||||
|
|
||||||
|
if(!newViewers.isEmpty()) {
|
||||||
|
HMCCPacketManager.spawnInvisibleArmorstand(firstArmorStandId, entityLocation, UUID.randomUUID(), newViewers);
|
||||||
|
PacketManager.equipmentSlotUpdate(firstArmorStandId, EquipmentSlot.HEAD, user.getUserCosmeticItem(this, getItem()), newViewers);
|
||||||
|
|
||||||
|
if (user.getPlayer() != null) {
|
||||||
|
AttributeInstance scaleAttribute = user.getPlayer().getAttribute(Attribute.SCALE);
|
||||||
|
if (scaleAttribute != null) {
|
||||||
|
HMCCPacketManager.sendEntityScalePacket(user.getUserBackpackManager().getFirstArmorStandId(), scaleAttribute.getValue(), newViewers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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()) HMCCPacketManager.sendRidingPacket(entity.getEntityId(), firstArmorStandId, entityManager.getViewers());
|
||||||
|
else HMCCPacketManager.sendRidingPacket(entity.getEntityId(), firstArmorStandId, newViewers);
|
||||||
|
|
||||||
|
if (isFirstPersonCompadible() && !user.isInWardrobe() && user.getPlayer() != null) {
|
||||||
|
List<Player> owner = List.of(user.getPlayer());
|
||||||
|
|
||||||
|
ArrayList<Integer> particleCloud = backpackManager.getAreaEffectEntityId();
|
||||||
|
for (int i = 0; i < particleCloud.size(); i++) {
|
||||||
|
if (i == 0) {
|
||||||
|
HMCCPacketManager.sendRidingPacket(entity.getEntityId(), particleCloud.get(i), owner);
|
||||||
|
} else {
|
||||||
|
HMCCPacketManager.sendRidingPacket(particleCloud.get(i - 1), particleCloud.get(i) , owner);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
HMCCPacketManager.sendRidingPacket(particleCloud.get(particleCloud.size() - 1), firstArmorStandId, owner);
|
||||||
|
if (!user.isHidden()) {
|
||||||
|
PacketManager.equipmentSlotUpdate(firstArmorStandId, EquipmentSlot.HEAD, user.getUserCosmeticItem(this, firstPersonBackpack), owner);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
backpackManager.showBackpack();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispatchMove(@NotNull CosmeticUser user, @NotNull Location from, @NotNull Location to) {
|
||||||
|
@SuppressWarnings("DuplicatedCode") // thanks.
|
||||||
|
Entity entity = user.getEntity();
|
||||||
|
if(entity == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Location entityLocation = entity.getLocation();
|
||||||
|
Location loc = entityLocation.clone().add(0, 2, 0);
|
||||||
|
|
||||||
|
UserBackpackManager backpackManager = user.getUserBackpackManager();
|
||||||
|
if(backpackManager == null) return;
|
||||||
|
|
||||||
|
UserEntity entityManager = backpackManager.getEntityManager();
|
||||||
|
if(entityManager == null) return;
|
||||||
|
|
||||||
|
entityManager.teleport(loc);
|
||||||
|
entityManager.setRotation((int) loc.getYaw(), isFirstPersonCompadible());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFirstPersonCompadible() {
|
public boolean isFirstPersonCompadible() {
|
||||||
return firstPersonBackpack != null;
|
return firstPersonBackpack != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getFirstPersonBackpack() {
|
|
||||||
return firstPersonBackpack;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,28 +2,30 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.behavior.CosmeticMovementBehavior;
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.behavior.CosmeticUpdateBehavior;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager;
|
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 lombok.Getter;
|
||||||
|
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||||
|
import me.lojosho.shaded.configurate.serialize.SerializationException;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
|
||||||
import org.spongepowered.configurate.serialize.SerializationException;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CosmeticBalloonType extends Cosmetic {
|
public class CosmeticBalloonType extends Cosmetic implements CosmeticUpdateBehavior, CosmeticMovementBehavior {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final String modelName;
|
private final String modelName;
|
||||||
@Getter
|
@Getter
|
||||||
private List<String> dyableParts;
|
private List<String> dyeableParts;
|
||||||
@Getter
|
@Getter
|
||||||
private final boolean showLead;
|
private final boolean showLead;
|
||||||
@Getter
|
@Getter
|
||||||
@@ -42,8 +44,8 @@ public class CosmeticBalloonType extends Cosmetic {
|
|||||||
balloonOffset = Settings.loadVector(balloonOffsetNode);
|
balloonOffset = Settings.loadVector(balloonOffsetNode);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!config.node("dyable-parts").virtual()) {
|
if (!config.node("dyeable-parts").virtual()) {
|
||||||
dyableParts = config.node("dyable-parts").getList(String.class);
|
dyeableParts = config.node("dyeable-parts").getList(String.class);
|
||||||
}
|
}
|
||||||
} catch (SerializationException e) {
|
} catch (SerializationException e) {
|
||||||
// Seriously?
|
// Seriously?
|
||||||
@@ -54,7 +56,7 @@ public class CosmeticBalloonType extends Cosmetic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(@NotNull CosmeticUser user) {
|
public void dispatchUpdate(@NotNull CosmeticUser user) {
|
||||||
Entity entity = Bukkit.getEntity(user.getUniqueId());
|
Entity entity = Bukkit.getEntity(user.getUniqueId());
|
||||||
UserBalloonManager userBalloonManager = user.getBalloonManager();
|
UserBalloonManager userBalloonManager = user.getBalloonManager();
|
||||||
|
|
||||||
@@ -67,38 +69,58 @@ public class CosmeticBalloonType extends Cosmetic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Location newLocation = entity.getLocation();
|
Location newLocation = entity.getLocation();
|
||||||
Location currentLocation = user.getBalloonManager().getLocation();
|
|
||||||
newLocation = newLocation.clone().add(getBalloonOffset());
|
newLocation = newLocation.clone().add(getBalloonOffset());
|
||||||
|
if (Settings.isBalloonHeadForward()) newLocation.setPitch(0);
|
||||||
|
|
||||||
List<Player> viewer = PacketManager.getViewers(entity.getLocation());
|
if (!user.isHidden() && showLead) {
|
||||||
|
|
||||||
if (entity.getLocation().getWorld() != userBalloonManager.getLocation().getWorld()) {
|
|
||||||
userBalloonManager.getModelEntity().teleport(newLocation);
|
|
||||||
PacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector velocity = newLocation.toVector().subtract(currentLocation.toVector());
|
|
||||||
userBalloonManager.setVelocity(velocity.multiply(1.1));
|
|
||||||
userBalloonManager.setLocation(newLocation);
|
|
||||||
|
|
||||||
PacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer);
|
|
||||||
PacketManager.sendLeashPacket(userBalloonManager.getPufferfishBalloonId(), entity.getEntityId(), viewer);
|
|
||||||
if (user.getHidden()) {
|
|
||||||
userBalloonManager.getPufferfish().hidePufferfish();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!user.getHidden() && showLead) {
|
|
||||||
List<Player> sendTo = userBalloonManager.getPufferfish().refreshViewers(newLocation);
|
List<Player> sendTo = userBalloonManager.getPufferfish().refreshViewers(newLocation);
|
||||||
if (sendTo.isEmpty()) return;
|
if (sendTo.isEmpty()) return;
|
||||||
user.getBalloonManager().getPufferfish().spawnPufferfish(newLocation, sendTo);
|
user.getBalloonManager().getPufferfish().spawnPufferfish(newLocation, sendTo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDyablePart(String name) {
|
@Override
|
||||||
|
public void dispatchMove(@NotNull CosmeticUser user, @NotNull Location from, @NotNull Location to) {
|
||||||
|
Entity entity = Bukkit.getEntity(user.getUniqueId());
|
||||||
|
UserBalloonManager userBalloonManager = user.getBalloonManager();
|
||||||
|
|
||||||
|
if (entity == null || userBalloonManager == null) return;
|
||||||
|
if (user.isInWardrobe()) return;
|
||||||
|
|
||||||
|
if (!userBalloonManager.getModelEntity().isValid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Location newLocation = entity.getLocation();
|
||||||
|
Location currentLocation = user.getBalloonManager().getLocation();
|
||||||
|
newLocation = newLocation.clone().add(getBalloonOffset());
|
||||||
|
if (Settings.isBalloonHeadForward()) newLocation.setPitch(0);
|
||||||
|
|
||||||
|
List<Player> viewer = HMCCPacketManager.getViewers(entity.getLocation());
|
||||||
|
|
||||||
|
if (entity.getLocation().getWorld() != userBalloonManager.getLocation().getWorld()) {
|
||||||
|
userBalloonManager.getModelEntity().teleport(newLocation);
|
||||||
|
HMCCPacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector velocity = newLocation.toVector().subtract(currentLocation.toVector());
|
||||||
|
userBalloonManager.setLocation(newLocation);
|
||||||
|
userBalloonManager.setVelocity(velocity.multiply(1.1));
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDyeablePart(String name) {
|
||||||
// If player does not define parts, dye whole model
|
// If player does not define parts, dye whole model
|
||||||
if (dyableParts == null) return true;
|
if (dyeableParts == null) return true;
|
||||||
if (dyableParts.isEmpty()) return true;
|
if (dyeableParts.isEmpty()) return true;
|
||||||
return dyableParts.contains(name);
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +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.PlayerUtils;
|
|
||||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
|
||||||
|
|
||||||
public class CosmeticMainhandType extends Cosmetic {
|
|
||||||
|
|
||||||
public CosmeticMainhandType(String id, ConfigurationNode config) {
|
|
||||||
super(id, config);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update(@NotNull CosmeticUser user) {
|
|
||||||
Player player = user.getPlayer();
|
|
||||||
|
|
||||||
PacketManager.equipmentSlotUpdate(player.getEntityId(), user, getSlot(), PlayerUtils.getNearbyPlayers(player));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,6 +3,7 @@ package com.hibiscusmc.hmccosmetics.database;
|
|||||||
import com.hibiscusmc.hmccosmetics.config.DatabaseSettings;
|
import com.hibiscusmc.hmccosmetics.config.DatabaseSettings;
|
||||||
import com.hibiscusmc.hmccosmetics.database.types.Data;
|
import com.hibiscusmc.hmccosmetics.database.types.Data;
|
||||||
import com.hibiscusmc.hmccosmetics.database.types.MySQLData;
|
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.database.types.SQLiteData;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||||
@@ -11,6 +12,8 @@ import lombok.Getter;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class Database {
|
public class Database {
|
||||||
|
|
||||||
@@ -18,18 +21,25 @@ public class Database {
|
|||||||
private static Data data;
|
private static Data data;
|
||||||
private static final MySQLData MYSQL_DATA = new MySQLData();
|
private static final MySQLData MYSQL_DATA = new MySQLData();
|
||||||
private static final SQLiteData SQLITE_DATA = new SQLiteData();
|
private static final SQLiteData SQLITE_DATA = new SQLiteData();
|
||||||
|
private static final NoneData NONE_DATA = new NoneData();
|
||||||
|
|
||||||
public Database() {
|
public Database() {
|
||||||
String databaseType = DatabaseSettings.getDatabaseType();
|
String databaseType = DatabaseSettings.getDatabaseType();
|
||||||
data = SQLITE_DATA; // default
|
data = SQLITE_DATA; // default to SQLite, then check if it's anything different
|
||||||
if (databaseType.equalsIgnoreCase("MySQL")) {
|
switch (databaseType.toLowerCase()) {
|
||||||
data = MYSQL_DATA;
|
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);
|
MessagesUtil.sendDebugMessages("Database is " + data);
|
||||||
|
|
||||||
setup();
|
setup();
|
||||||
@@ -47,7 +57,7 @@ public class Database {
|
|||||||
data.save(CosmeticUsers.getUser(player));
|
data.save(CosmeticUsers.getUser(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CosmeticUser get(UUID uniqueId) {
|
public static CompletableFuture<UserData> get(UUID uniqueId) {
|
||||||
return data.get(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,21 +1,19 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.database.types;
|
package com.hibiscusmc.hmccosmetics.database.types;
|
||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
|
||||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||||
|
import com.hibiscusmc.hmccosmetics.database.UserData;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import org.apache.commons.lang3.EnumUtils;
|
import org.apache.commons.lang3.EnumUtils;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public abstract class Data {
|
public abstract class Data {
|
||||||
|
|
||||||
@@ -24,7 +22,7 @@ public abstract class Data {
|
|||||||
public abstract void save(CosmeticUser user);
|
public abstract void save(CosmeticUser user);
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public abstract CosmeticUser get(UUID uniqueId);
|
public abstract CompletableFuture<UserData> get(UUID uniqueId);
|
||||||
|
|
||||||
public abstract void clear(UUID uniqueId);
|
public abstract void clear(UUID uniqueId);
|
||||||
|
|
||||||
@@ -32,9 +30,9 @@ public abstract class Data {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public final String serializeData(@NotNull CosmeticUser user) {
|
public final String serializeData(@NotNull CosmeticUser user) {
|
||||||
StringBuilder data = new StringBuilder();
|
StringBuilder data = new StringBuilder();
|
||||||
if (user.getHidden()) {
|
if (user.isHidden()) {
|
||||||
if (shouldHiddenSave(user.getHiddenReason())) {
|
for (CosmeticUser.HiddenReason reason : user.getHiddenReasons()) {
|
||||||
data.append("HIDDEN=").append(user.getHiddenReason());
|
if (shouldHiddenSave(reason)) data.append("HIDDEN=").append(reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Cosmetic cosmetic : user.getCosmetics()) {
|
for (Cosmetic cosmetic : user.getCosmetics()) {
|
||||||
@@ -50,15 +48,12 @@ public abstract class Data {
|
|||||||
return data.toString();
|
return data.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Map<CosmeticSlot, Map<Cosmetic, Color>> deserializeData(CosmeticUser user, @NotNull String raw) {
|
|
||||||
return deserializeData(user, raw, Settings.isForcePermissionJoin());
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public final Map<CosmeticSlot, Map<Cosmetic, Color>> deserializeData(CosmeticUser user, @NotNull String raw, boolean permissionCheck) {
|
public final HashMap<CosmeticSlot, Map.Entry<Cosmetic, Integer>> deserializeData(@NotNull String raw) {
|
||||||
Map<CosmeticSlot, Map<Cosmetic, Color>> cosmetics = new HashMap<>();
|
HashMap<CosmeticSlot, Map.Entry<Cosmetic, Integer>> cosmetics = new HashMap<>();
|
||||||
|
|
||||||
String[] rawData = raw.split(",");
|
String[] rawData = raw.split(",");
|
||||||
|
ArrayList<CosmeticUser.HiddenReason> hiddenReason = new ArrayList<>();
|
||||||
for (String a : rawData) {
|
for (String a : rawData) {
|
||||||
if (a == null || a.isEmpty()) continue;
|
if (a == null || a.isEmpty()) continue;
|
||||||
String[] splitData = a.split("=");
|
String[] splitData = a.split("=");
|
||||||
@@ -68,9 +63,7 @@ public abstract class Data {
|
|||||||
if (splitData[0].equalsIgnoreCase("HIDDEN")) {
|
if (splitData[0].equalsIgnoreCase("HIDDEN")) {
|
||||||
if (EnumUtils.isValidEnum(CosmeticUser.HiddenReason.class, splitData[1])) {
|
if (EnumUtils.isValidEnum(CosmeticUser.HiddenReason.class, splitData[1])) {
|
||||||
if (Settings.isForceShowOnJoin()) continue;
|
if (Settings.isForceShowOnJoin()) continue;
|
||||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
|
hiddenReason.add(CosmeticUser.HiddenReason.valueOf(splitData[1]));
|
||||||
user.hideCosmetics(CosmeticUser.HiddenReason.valueOf(splitData[1]));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -79,31 +72,20 @@ public abstract class Data {
|
|||||||
String[] colorSplitData = splitData[1].split("&");
|
String[] colorSplitData = splitData[1].split("&");
|
||||||
if (Cosmetics.hasCosmetic(colorSplitData[0])) cosmetic = Cosmetics.getCosmetic(colorSplitData[0]);
|
if (Cosmetics.hasCosmetic(colorSplitData[0])) cosmetic = Cosmetics.getCosmetic(colorSplitData[0]);
|
||||||
if (slot == null || cosmetic == null) continue;
|
if (slot == null || cosmetic == null) continue;
|
||||||
if (permissionCheck && cosmetic.requiresPermission()) {
|
cosmetics.put(slot, Map.entry(cosmetic, Integer.parseInt(colorSplitData[1])));
|
||||||
if (user.getPlayer() != null && !user.getPlayer().hasPermission(cosmetic.getPermission())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cosmetics.put(slot, Map.of(cosmetic, Color.fromRGB(Integer.parseInt(colorSplitData[1]))));
|
|
||||||
} else {
|
} else {
|
||||||
if (Cosmetics.hasCosmetic(splitData[1])) cosmetic = Cosmetics.getCosmetic(splitData[1]);
|
if (Cosmetics.hasCosmetic(splitData[1])) cosmetic = Cosmetics.getCosmetic(splitData[1]);
|
||||||
if (slot == null || cosmetic == null) continue;
|
if (slot == null || cosmetic == null) continue;
|
||||||
if (permissionCheck && cosmetic.requiresPermission()) {
|
cosmetics.put(slot, Map.entry(cosmetic, -1));
|
||||||
if (user.getPlayer() != null && !user.getPlayer().hasPermission(cosmetic.getPermission())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
HashMap<Cosmetic, Color> cosmeticColorHashMap = new HashMap<>();
|
|
||||||
cosmeticColorHashMap.put(cosmetic, null);
|
|
||||||
cosmetics.put(slot, cosmeticColorHashMap);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cosmetics;
|
return cosmetics;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldHiddenSave(CosmeticUser.HiddenReason reason) {
|
private boolean shouldHiddenSave(CosmeticUser.HiddenReason reason) {
|
||||||
switch (reason) {
|
switch (reason) {
|
||||||
case EMOTE, NONE -> {
|
case EMOTE, NONE, GAMEMODE, WORLD, DISABLED, POTION -> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
default -> {
|
default -> {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import java.sql.PreparedStatement;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class MySQLData extends SQLData {
|
public class MySQLData extends SQLData {
|
||||||
|
|
||||||
@@ -37,12 +38,14 @@ public class MySQLData extends SQLData {
|
|||||||
HMCCosmeticsPlugin plugin = HMCCosmeticsPlugin.getInstance();
|
HMCCosmeticsPlugin plugin = HMCCosmeticsPlugin.getInstance();
|
||||||
try {
|
try {
|
||||||
openConnection();
|
openConnection();
|
||||||
if (connection == null) throw new NullPointerException("Connection is null");
|
if (connection == null) throw new IllegalStateException("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, " +
|
"(UUID varchar(36) PRIMARY KEY, " +
|
||||||
"COSMETICS MEDIUMTEXT " +
|
"COSMETICS MEDIUMTEXT " +
|
||||||
");").execute();
|
");")) {
|
||||||
} catch (SQLException | NullPointerException e) {
|
preparedStatement.execute();
|
||||||
|
}
|
||||||
|
} catch (SQLException | IllegalStateException e) {
|
||||||
plugin.getLogger().severe("");
|
plugin.getLogger().severe("");
|
||||||
plugin.getLogger().severe("");
|
plugin.getLogger().severe("");
|
||||||
plugin.getLogger().severe("MySQL DATABASE CAN NOT BE REACHED.");
|
plugin.getLogger().severe("MySQL DATABASE CAN NOT BE REACHED.");
|
||||||
@@ -59,8 +62,7 @@ public class MySQLData extends SQLData {
|
|||||||
@Override
|
@Override
|
||||||
public void clear(UUID uniqueId) {
|
public void clear(UUID uniqueId) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||||
try {
|
try (PreparedStatement preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;")) {
|
||||||
PreparedStatement preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;");
|
|
||||||
preparedSt.setString(1, uniqueId.toString());
|
preparedSt.setString(1, uniqueId.toString());
|
||||||
preparedSt.executeUpdate();
|
preparedSt.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@@ -70,16 +72,10 @@ public class MySQLData extends SQLData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void openConnection() throws SQLException {
|
private void openConnection() throws SQLException {
|
||||||
// Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
|
||||||
// ...
|
|
||||||
// });
|
|
||||||
// connection = DriverManager.getConnection("jdbc:mysql://" + DatabaseSettings.getHost() + ":" + DatabaseSettings.getPort() + "/" + DatabaseSettings.getDatabase(), setupProperties());
|
|
||||||
|
|
||||||
// Connection isn't null AND Connection isn't closed :: return
|
// Connection isn't null AND Connection isn't closed :: return
|
||||||
try {
|
try {
|
||||||
if (isConnectionOpen()) {
|
if (isConnectionOpen()) return;
|
||||||
return;
|
if (connection != null) close(); // Close connection if still active
|
||||||
} else if (connection != null) close(); // Close connection if still active
|
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
e.printStackTrace(); // If isConnectionOpen() throws error
|
e.printStackTrace(); // If isConnectionOpen() throws error
|
||||||
}
|
}
|
||||||
@@ -88,17 +84,15 @@ public class MySQLData extends SQLData {
|
|||||||
try {
|
try {
|
||||||
Class.forName("com.mysql.jdbc.Driver");
|
Class.forName("com.mysql.jdbc.Driver");
|
||||||
connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, setupProperties());
|
connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, setupProperties());
|
||||||
} catch (SQLException e) {
|
} catch (SQLException | ClassNotFoundException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||||
try {
|
try {
|
||||||
if (connection == null) throw new NullPointerException("Connection is null");
|
if (connection == null) throw new IllegalStateException("Connection is null");
|
||||||
connection.close();
|
connection.close();
|
||||||
} catch (SQLException | NullPointerException e) {
|
} catch (SQLException | NullPointerException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
@@ -109,13 +103,12 @@ public class MySQLData extends SQLData {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private Properties setupProperties() {
|
private Properties setupProperties() {
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
props.put("user", user);
|
props.setProperty("user", user);
|
||||||
props.put("password", password);
|
props.setProperty("password", password);
|
||||||
props.put("autoReconnect", "true");
|
|
||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isConnectionOpen() throws RuntimeException {
|
private boolean isConnectionOpen() {
|
||||||
try {
|
try {
|
||||||
return connection != null && !connection.isClosed();
|
return connection != null && !connection.isClosed();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@@ -127,15 +120,22 @@ public class MySQLData extends SQLData {
|
|||||||
public PreparedStatement preparedStatement(String query) {
|
public PreparedStatement preparedStatement(String query) {
|
||||||
PreparedStatement ps = null;
|
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 {
|
try {
|
||||||
if (connection == null) throw new NullPointerException("Connection is null");
|
if (connection == null) throw new IllegalStateException("Connection is null");
|
||||||
ps = connection.prepareStatement(query);
|
ps = connection.prepareStatement(query);
|
||||||
} catch (SQLException | NullPointerException e) {
|
} catch (SQLException | IllegalStateException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ps;
|
return ps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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,53 +3,46 @@ package com.hibiscusmc.hmccosmetics.database.types;
|
|||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||||
|
import com.hibiscusmc.hmccosmetics.database.UserData;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Color;
|
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public abstract class SQLData extends Data {
|
public abstract class SQLData extends Data {
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings({"resource"}) // Duplicate is from deprecated InternalData
|
@SuppressWarnings({"resource"}) // Duplicate is from deprecated InternalData
|
||||||
public CosmeticUser get(UUID uniqueId) {
|
public CompletableFuture<UserData> get(UUID uniqueId) {
|
||||||
CosmeticUser user = new CosmeticUser(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());
|
preparedStatement.setString(1, uniqueId.toString());
|
||||||
ResultSet rs = preparedStatement.executeQuery();
|
try (ResultSet rs = preparedStatement.executeQuery()) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
String rawData = rs.getString("COSMETICS");
|
String rawData = rs.getString("COSMETICS");
|
||||||
Map<CosmeticSlot, Map<Cosmetic, Color>> cosmetics = deserializeData(user, rawData);
|
HashMap<CosmeticSlot, Map.Entry<Cosmetic, Integer>> cosmetics = deserializeData(rawData);
|
||||||
for (Map<Cosmetic, Color> cosmeticColors : cosmetics.values()) {
|
data.setCosmetics(cosmetics);
|
||||||
for (Cosmetic cosmetic : cosmeticColors.keySet()) {
|
|
||||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
|
|
||||||
// This can not be async.
|
|
||||||
user.addPlayerCosmetic(cosmetic, cosmeticColors.get(cosmetic));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
return data;
|
||||||
});
|
});
|
||||||
|
|
||||||
return user;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
public void save(CosmeticUser user) {
|
public void save(CosmeticUser user) {
|
||||||
Runnable run = () -> {
|
Runnable run = () -> {
|
||||||
try {
|
try (PreparedStatement preparedSt = preparedStatement("REPLACE INTO COSMETICDATABASE(UUID,COSMETICS) VALUES(?,?);")) {
|
||||||
PreparedStatement preparedSt = preparedStatement("REPLACE INTO COSMETICDATABASE(UUID,COSMETICS) VALUES(?,?);");
|
|
||||||
preparedSt.setString(1, user.getUniqueId().toString());
|
preparedSt.setString(1, user.getUniqueId().toString());
|
||||||
preparedSt.setString(2, serializeData(user));
|
preparedSt.setString(2, serializeData(user));
|
||||||
preparedSt.executeUpdate();
|
preparedSt.executeUpdate();
|
||||||
@@ -57,7 +50,7 @@ public abstract class SQLData extends Data {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (!HMCCosmeticsPlugin.isDisable()) {
|
if (!HMCCosmeticsPlugin.getInstance().isDisabled()) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), run);
|
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), run);
|
||||||
} else {
|
} else {
|
||||||
run.run();
|
run.run();
|
||||||
|
|||||||
@@ -35,10 +35,12 @@ public class SQLiteData extends SQLData {
|
|||||||
connection = DriverManager.getConnection("jdbc:sqlite:" + dataFolder);
|
connection = DriverManager.getConnection("jdbc:sqlite:" + dataFolder);
|
||||||
|
|
||||||
openConnection();
|
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, " +
|
"(UUID varchar(36) PRIMARY KEY, " +
|
||||||
"COSMETICS MEDIUMTEXT " +
|
"COSMETICS MEDIUMTEXT " +
|
||||||
");").execute();
|
");")) {
|
||||||
|
preparedStatement.execute();
|
||||||
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -48,8 +50,7 @@ public class SQLiteData extends SQLData {
|
|||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
public void clear(UUID uniqueId) {
|
public void clear(UUID uniqueId) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||||
try {
|
try (PreparedStatement preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;")){
|
||||||
PreparedStatement preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;");
|
|
||||||
preparedSt.setString(1, uniqueId.toString());
|
preparedSt.setString(1, uniqueId.toString());
|
||||||
preparedSt.executeUpdate();
|
preparedSt.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@@ -59,11 +60,6 @@ public class SQLiteData extends SQLData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void openConnection() throws SQLException {
|
private void openConnection() throws SQLException {
|
||||||
// Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
|
||||||
// ...
|
|
||||||
// });
|
|
||||||
// connection = DriverManager.getConnection("jdbc:mysql://" + DatabaseSettings.getHost() + ":" + DatabaseSettings.getPort() + "/" + DatabaseSettings.getDatabase(), setupProperties());
|
|
||||||
|
|
||||||
if (connection != null && !connection.isClosed()) return;
|
if (connection != null && !connection.isClosed()) return;
|
||||||
|
|
||||||
// Close Connection if still active
|
// Close Connection if still active
|
||||||
@@ -83,9 +79,12 @@ public class SQLiteData extends SQLData {
|
|||||||
@Override
|
@Override
|
||||||
public PreparedStatement preparedStatement(String query) {
|
public PreparedStatement preparedStatement(String query) {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
if (!isConnectionOpen()) MessagesUtil.sendDebugMessages("Connection is not open");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (!isConnectionOpen()) {
|
||||||
|
MessagesUtil.sendDebugMessages("Connection is not open");
|
||||||
|
openConnection();
|
||||||
|
}
|
||||||
ps = connection.prepareStatement(query);
|
ps = connection.prepareStatement(query);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -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,22 +1,27 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.gui;
|
package com.hibiscusmc.hmccosmetics.gui;
|
||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
|
import com.hibiscusmc.hmccosmetics.api.events.PlayerMenuCloseEvent;
|
||||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerMenuOpenEvent;
|
import com.hibiscusmc.hmccosmetics.api.events.PlayerMenuOpenEvent;
|
||||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||||
import com.hibiscusmc.hmccosmetics.config.serializer.ItemSerializer;
|
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.type.Type;
|
import com.hibiscusmc.hmccosmetics.gui.type.Type;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.type.Types;
|
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.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
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.builder.item.ItemBuilder;
|
||||||
|
import dev.triumphteam.gui.components.GuiType;
|
||||||
import dev.triumphteam.gui.guis.Gui;
|
import dev.triumphteam.gui.guis.Gui;
|
||||||
import dev.triumphteam.gui.guis.GuiItem;
|
import dev.triumphteam.gui.guis.GuiItem;
|
||||||
import lombok.Getter;
|
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.shaded.configurate.ConfigurationNode;
|
||||||
|
import me.lojosho.shaded.configurate.serialize.SerializationException;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -24,12 +29,8 @@ import org.bukkit.event.inventory.ClickType;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
|
||||||
import org.spongepowered.configurate.serialize.SerializationException;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public class Menu {
|
public class Menu {
|
||||||
@@ -41,21 +42,24 @@ public class Menu {
|
|||||||
@Getter
|
@Getter
|
||||||
private final int rows;
|
private final int rows;
|
||||||
@Getter
|
@Getter
|
||||||
|
private final Long cooldown;
|
||||||
|
@Getter
|
||||||
private final ConfigurationNode config;
|
private final ConfigurationNode config;
|
||||||
@Getter
|
@Getter
|
||||||
private final String permissionNode;
|
private final String permissionNode;
|
||||||
private final HashMap<Integer, MenuItem> items;
|
private final HashMap<Integer, List<MenuItem>> items;
|
||||||
@Getter
|
@Getter
|
||||||
private final int refreshRate;
|
private final int refreshRate;
|
||||||
@Getter
|
@Getter
|
||||||
private final boolean shading;
|
private final boolean shading;
|
||||||
|
|
||||||
public Menu(String id, @NotNull ConfigurationNode config) {
|
public Menu(String id, @NotNull ConfigurationNode config) {
|
||||||
this.id = id;
|
this.id = config.node("id").getString(id);
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
|
||||||
title = config.node("title").getString("chest");
|
title = config.node("title").getString("chest");
|
||||||
rows = config.node("rows").getInt(1);
|
rows = config.node("rows").getInt(1);
|
||||||
|
cooldown = config.node("click-cooldown").getLong(Settings.getDefaultMenuCooldown());
|
||||||
permissionNode = config.node("permission").getString("");
|
permissionNode = config.node("permission").getString("");
|
||||||
refreshRate = config.node("refresh-rate").getInt(-1);
|
refreshRate = config.node("refresh-rate").getInt(-1);
|
||||||
shading = config.node("shading").getBoolean(Settings.isDefaultShading());
|
shading = config.node("shading").getBoolean(Settings.isDefaultShading());
|
||||||
@@ -91,7 +95,8 @@ public class Menu {
|
|||||||
try {
|
try {
|
||||||
item = ItemSerializer.INSTANCE.deserialize(ItemStack.class, config.node("item"));
|
item = ItemSerializer.INSTANCE.deserialize(ItemStack.class, config.node("item"));
|
||||||
} catch (SerializationException e) {
|
} catch (SerializationException e) {
|
||||||
throw new RuntimeException(e);
|
MessagesUtil.sendDebugMessages("Unable to get valid item for " + config.key().toString() + " " + e.getMessage());
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
@@ -99,15 +104,24 @@ public class Menu {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Type type = null;
|
int priority = config.node("priority").getInt(1);
|
||||||
|
|
||||||
|
Type type = Types.getDefaultType();
|
||||||
if (!config.node("type").virtual()) {
|
if (!config.node("type").virtual()) {
|
||||||
String typeId = config.node("type").getString("");
|
String typeId = config.node("type").getString("");
|
||||||
if (Types.isType(typeId)) type = Types.getType(typeId);
|
if (Types.isType(typeId)) type = Types.getType(typeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Integer slot : slots) {
|
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 +133,25 @@ public class Menu {
|
|||||||
public void openMenu(@NotNull CosmeticUser user, boolean ignorePermission) {
|
public void openMenu(@NotNull CosmeticUser user, boolean ignorePermission) {
|
||||||
Player player = user.getPlayer();
|
Player player = user.getPlayer();
|
||||||
if (player == null) return;
|
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 (!ignorePermission && !permissionNode.isEmpty()) {
|
||||||
if (!player.hasPermission(permissionNode) && !player.isOp()) {
|
if (!viewer.hasPermission(permissionNode) && !viewer.isOp()) {
|
||||||
MessagesUtil.sendMessage(player, "no-permission");
|
MessagesUtil.sendMessage(viewer, "no-permission");
|
||||||
return;
|
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()
|
Gui gui = Gui.gui()
|
||||||
.title(component)
|
.title(component)
|
||||||
.rows(this.rows)
|
.type(GuiType.CHEST)
|
||||||
|
.inventory((title, owner, type) -> Bukkit.createInventory(owner, rows * 9, title))
|
||||||
.create();
|
.create();
|
||||||
|
|
||||||
gui.setDefaultClickAction(event -> event.setCancelled(true));
|
gui.setDefaultClickAction(event -> event.setCancelled(true));
|
||||||
@@ -140,7 +163,7 @@ public class Menu {
|
|||||||
Bukkit.getScheduler().cancelTask(taskid.get());
|
Bukkit.getScheduler().cancelTask(taskid.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
updateMenu(user, gui);
|
updateMenu(viewer, cosmeticHolder, gui);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (refreshRate != -1) {
|
if (refreshRate != -1) {
|
||||||
@@ -151,22 +174,36 @@ public class Menu {
|
|||||||
});
|
});
|
||||||
|
|
||||||
gui.setCloseGuiAction(event -> {
|
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());
|
if (taskid.get() != -1) Bukkit.getScheduler().cancelTask(taskid.get());
|
||||||
});
|
});
|
||||||
|
|
||||||
// API
|
Runnable openGuiTask = () -> {
|
||||||
PlayerMenuOpenEvent event = new PlayerMenuOpenEvent(user, this);
|
gui.open(viewer);
|
||||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> Bukkit.getPluginManager().callEvent(event));
|
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
|
||||||
if (event.isCancelled()) return;
|
};
|
||||||
// Internal
|
|
||||||
|
|
||||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
|
// API
|
||||||
gui.open(player);
|
if (cosmeticHolder instanceof CosmeticUser user) {
|
||||||
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
|
PlayerMenuOpenEvent event = new PlayerMenuOpenEvent(user, this);
|
||||||
});
|
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (!event.isCancelled()) {
|
||||||
|
openGuiTask.run();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// Internal
|
||||||
|
else {
|
||||||
|
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), openGuiTask);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateMenu(CosmeticUser user, Gui gui) {
|
private void updateMenu(Player viewer, CosmeticHolder cosmeticHolder, Gui gui) {
|
||||||
StringBuilder title = new StringBuilder(this.title);
|
StringBuilder title = new StringBuilder(this.title);
|
||||||
|
|
||||||
int row = 0;
|
int row = 0;
|
||||||
@@ -188,16 +225,17 @@ public class Menu {
|
|||||||
|
|
||||||
if (items.containsKey(i)) {
|
if (items.containsKey(i)) {
|
||||||
// Handles the items
|
// Handles the items
|
||||||
MenuItem item = items.get(i);
|
List<MenuItem> menuItems = items.get(i);
|
||||||
updateItem(user, gui, item);
|
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(""));
|
Cosmetic cosmetic = Cosmetics.getCosmetic(item.itemConfig().node("cosmetic").getString(""));
|
||||||
if (cosmetic == null) continue;
|
if (cosmetic == null) continue;
|
||||||
if (user.hasCosmeticInSlot(cosmetic)) {
|
if (cosmeticHolder.hasCosmeticInSlot(cosmetic)) {
|
||||||
title.append(Settings.getEquippedCosmeticColor());
|
title.append(Settings.getEquippedCosmeticColor());
|
||||||
} else {
|
} else {
|
||||||
if (user.canEquipCosmetic(cosmetic, true)) {
|
if (cosmeticHolder.canEquipCosmetic(cosmetic, true)) {
|
||||||
title.append(Settings.getEquipableCosmeticColor());
|
title.append(Settings.getEquipableCosmeticColor());
|
||||||
} else {
|
} else {
|
||||||
title.append(Settings.getLockedCosmeticColor());
|
title.append(Settings.getLockedCosmeticColor());
|
||||||
@@ -213,28 +251,47 @@ public class Menu {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
MessagesUtil.sendDebugMessages("Updated menu with title " + title);
|
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 {
|
} else {
|
||||||
for (MenuItem item : items.values()) {
|
for (int i = 0; i < gui.getInventory().getSize(); i++) {
|
||||||
updateItem(user, gui, item);
|
if (items.containsKey(i)) {
|
||||||
|
updateItem(viewer, cosmeticHolder, gui, i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateItem(CosmeticUser user, Gui gui, MenuItem item) {
|
private void updateItem(Player viewer, CosmeticHolder cosmeticHolder, Gui gui, int slot) {
|
||||||
Type type = item.type();
|
if (!items.containsKey(slot)) return;
|
||||||
for (int slot : item.slots()) {
|
List<MenuItem> menuItems = items.get(slot);
|
||||||
ItemStack modifiedItem = getMenuItem(user, type, item.itemConfig(), item.item().clone(), 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 guiItem = ItemBuilder.from(modifiedItem).asGuiItem();
|
||||||
guiItem.setAction(event -> {
|
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();
|
final ClickType clickType = event.getClick();
|
||||||
if (type != null) type.run(user, item.itemConfig(), clickType);
|
if (type != null) type.run(viewer, cosmeticHolder, item.itemConfig(), clickType);
|
||||||
updateMenu(user, gui);
|
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);
|
gui.updateItem(slot, guiItem);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,15 +321,17 @@ public class Menu {
|
|||||||
return slots;
|
return slots;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Contract("_, _, _, _, _ -> param2")
|
@Contract("_, _, _, _, _, _ -> param4")
|
||||||
@NotNull
|
@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;
|
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) {
|
public boolean canOpen(Player player) {
|
||||||
if (permissionNode.isEmpty()) return true;
|
if (permissionNode.isEmpty()) return true;
|
||||||
return player.isOp() || player.hasPermission(permissionNode);
|
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;
|
package com.hibiscusmc.hmccosmetics.gui;
|
||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.gui.type.Type;
|
import com.hibiscusmc.hmccosmetics.gui.type.Type;
|
||||||
|
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.List;
|
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,31 @@ package com.hibiscusmc.hmccosmetics.gui;
|
|||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
|
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.apache.commons.io.FilenameUtils;
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.spongepowered.configurate.ConfigurateException;
|
|
||||||
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class Menus {
|
public class Menus {
|
||||||
|
|
||||||
private static final HashMap<String, Menu> MENUS = new HashMap<>();
|
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);
|
MENUS.put(menu.getId().toUpperCase(), menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static Menu getMenu(@NotNull String id) {
|
public static Menu getMenu(@NotNull String id) {
|
||||||
return MENUS.get(id.toUpperCase());
|
return MENUS.get(id.toUpperCase());
|
||||||
}
|
}
|
||||||
@@ -42,11 +42,18 @@ public class Menus {
|
|||||||
return MENUS.containsKey(id.toUpperCase());
|
return MENUS.containsKey(id.toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasMenu(Menu menu) {
|
public static boolean hasMenu(@NotNull Menu menu) {
|
||||||
return MENUS.containsValue(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
|
@NotNull
|
||||||
public static List<String> getMenuNames() {
|
public static List<String> getMenuNames() {
|
||||||
@@ -63,8 +70,21 @@ public class Menus {
|
|||||||
return MENUS.values();
|
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() {
|
public static void setup() {
|
||||||
MENUS.clear();
|
MENUS.clear();
|
||||||
|
COOLDOWNS.clear();
|
||||||
|
|
||||||
File cosmeticFolder = new File(HMCCosmeticsPlugin.getInstance().getDataFolder() + "/menus");
|
File cosmeticFolder = new File(HMCCosmeticsPlugin.getInstance().getDataFolder() + "/menus");
|
||||||
if (!cosmeticFolder.exists()) cosmeticFolder.mkdir();
|
if (!cosmeticFolder.exists()) cosmeticFolder.mkdir();
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.gui.action;
|
package com.hibiscusmc.hmccosmetics.gui.action;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public abstract class Action {
|
public abstract class Action {
|
||||||
@@ -16,5 +18,13 @@ public abstract class Action {
|
|||||||
return this.id;
|
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);
|
public abstract void run(CosmeticUser user, String raw);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.gui.action;
|
package com.hibiscusmc.hmccosmetics.gui.action;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.action.actions.*;
|
import com.hibiscusmc.hmccosmetics.gui.action.actions.*;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
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 org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class Actions {
|
public class Actions {
|
||||||
@@ -28,7 +31,6 @@ public class Actions {
|
|||||||
private static final ActionCosmeticHide ACTION_HIDE = new ActionCosmeticHide();
|
private static final ActionCosmeticHide ACTION_HIDE = new ActionCosmeticHide();
|
||||||
private static final ActionCosmeticToggle ACTION_TOGGLE = new ActionCosmeticToggle();
|
private static final ActionCosmeticToggle ACTION_TOGGLE = new ActionCosmeticToggle();
|
||||||
|
|
||||||
|
|
||||||
public static Action getAction(@NotNull String id) {
|
public static Action getAction(@NotNull String id) {
|
||||||
return actions.get(id.toUpperCase());
|
return actions.get(id.toUpperCase());
|
||||||
}
|
}
|
||||||
@@ -41,16 +43,20 @@ public class Actions {
|
|||||||
actions.put(action.getId().toUpperCase(), action);
|
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) {
|
for (String a : raw) {
|
||||||
String id = StringUtils.substringBetween(a, "[", "]").toUpperCase();
|
String id = StringUtils.substringBetween(a, "[", "]");
|
||||||
String message = StringUtils.substringAfter(a, "] ");
|
String message = StringUtils.substringAfter(a, "] ");
|
||||||
MessagesUtil.sendDebugMessages("ID is " + id + " // Raw Data is " + message);
|
MessagesUtil.sendDebugMessages("ID is " + id + " // Raw Data is " + message);
|
||||||
if (isAction(id)) {
|
if (id != null && isAction(id.toUpperCase())) {
|
||||||
getAction(id).run(user, message);
|
getAction(id).run(viewer, cosmeticHolder, message);
|
||||||
} else {
|
} 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;
|
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ActionCloseMenu extends Action {
|
public class ActionCloseMenu extends Action {
|
||||||
@@ -10,8 +12,13 @@ public class ActionCloseMenu extends Action {
|
|||||||
super("close");
|
super("close");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||||
|
viewer.closeInventory();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(@NotNull CosmeticUser user, String raw) {
|
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;
|
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||||
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
|
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ActionConsoleCommand extends Action {
|
public class ActionConsoleCommand extends Action {
|
||||||
@@ -13,8 +15,15 @@ public class ActionConsoleCommand extends Action {
|
|||||||
super("console-command");
|
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
|
@Override
|
||||||
public void run(@NotNull CosmeticUser user, String raw) {
|
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;
|
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ActionCosmeticHide extends Action {
|
public class ActionCosmeticHide extends Action {
|
||||||
@@ -11,8 +13,14 @@ public class ActionCosmeticHide extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(@NotNull CosmeticUser user, String raw) {
|
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||||
if (user.getHidden()) return;
|
if (!(cosmeticHolder instanceof CosmeticUser user)) return;
|
||||||
|
if (user.isHidden()) return;
|
||||||
user.hideCosmetics(CosmeticUser.HiddenReason.ACTION);
|
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;
|
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ActionCosmeticShow extends Action {
|
public class ActionCosmeticShow extends Action {
|
||||||
@@ -11,11 +13,17 @@ public class ActionCosmeticShow extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(@NotNull CosmeticUser user, String raw) {
|
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||||
if (!user.getHidden()) return;
|
if (!(cosmeticHolder instanceof CosmeticUser user)) return;
|
||||||
|
if (!user.isHidden()) return;
|
||||||
|
|
||||||
// Do not hide if it's already off for WG
|
// Do not hide if it's already off for WG
|
||||||
if (user.getHiddenReason() != CosmeticUser.HiddenReason.ACTION && user.getHiddenReason() != CosmeticUser.HiddenReason.COMMAND) return;
|
if (!user.isHidden(CosmeticUser.HiddenReason.ACTION) && !user.isHidden(CosmeticUser.HiddenReason.COMMAND)) return;
|
||||||
user.showCosmetics();
|
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;
|
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ActionCosmeticToggle extends Action {
|
public class ActionCosmeticToggle extends Action {
|
||||||
@@ -11,13 +13,19 @@ public class ActionCosmeticToggle extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(@NotNull CosmeticUser user, String raw) {
|
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||||
if (user.getHidden()) {
|
if (!(cosmeticHolder instanceof CosmeticUser user)) return;
|
||||||
if (user.getHiddenReason() != CosmeticUser.HiddenReason.ACTION && user.getHiddenReason() != CosmeticUser.HiddenReason.COMMAND) return;
|
if (user.isHidden()) {
|
||||||
user.showCosmetics();
|
if (!user.isHidden(CosmeticUser.HiddenReason.ACTION) && !user.isHidden(CosmeticUser.HiddenReason.COMMAND)) return;
|
||||||
|
user.showCosmetics(CosmeticUser.HiddenReason.ACTION);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
user.hideCosmetics(CosmeticUser.HiddenReason.ACTION);
|
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;
|
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class ActionEquip extends Action {
|
public class ActionEquip extends Action {
|
||||||
|
|
||||||
@@ -12,10 +14,15 @@ public class ActionEquip extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(CosmeticUser user, String raw) {
|
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||||
Cosmetic cosmetic = Cosmetics.getCosmetic(raw);
|
Cosmetic cosmetic = Cosmetics.getCosmetic(raw);
|
||||||
if (cosmetic == null) return;
|
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;
|
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
@@ -15,7 +17,7 @@ public class ActionMenu extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(CosmeticUser user, String raw) {
|
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||||
boolean ignorePermission = false;
|
boolean ignorePermission = false;
|
||||||
|
|
||||||
raw = raw.replaceAll(" ", ""); // Removes all spaces
|
raw = raw.replaceAll(" ", ""); // Removes all spaces
|
||||||
@@ -32,6 +34,11 @@ public class ActionMenu extends Action {
|
|||||||
|
|
||||||
Menu menu = Menus.getMenu(raw);
|
Menu menu = Menus.getMenu(raw);
|
||||||
MessagesUtil.sendDebugMessages(raw + " | " + ignorePermission);
|
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;
|
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ActionMessage extends Action {
|
public class ActionMessage extends Action {
|
||||||
@@ -11,8 +13,13 @@ public class ActionMessage extends Action {
|
|||||||
super("message");
|
super("message");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||||
|
MessagesUtil.sendMessageNoKey(viewer, raw);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(@NotNull CosmeticUser user, String raw) {
|
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;
|
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
|
import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils;
|
||||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
|
||||||
import com.owen1212055.particlehelper.api.particle.types.BlockDataParticle;
|
import com.owen1212055.particlehelper.api.particle.types.BlockDataParticle;
|
||||||
import com.owen1212055.particlehelper.api.particle.types.DestinationParticle;
|
import com.owen1212055.particlehelper.api.particle.types.DestinationParticle;
|
||||||
import com.owen1212055.particlehelper.api.particle.types.velocity.VelocityParticle;
|
import com.owen1212055.particlehelper.api.particle.types.velocity.VelocityParticle;
|
||||||
@@ -24,7 +25,7 @@ public class ActionParticle extends Action {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("ConstantConditions")
|
@SuppressWarnings("ConstantConditions")
|
||||||
public void run(CosmeticUser user, @NotNull String raw) {
|
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||||
String[] rawString = raw.split(" ");
|
String[] rawString = raw.split(" ");
|
||||||
ParticleType<?, ?> particleType = Particles.fromKey(NamespacedKey.minecraft(rawString[0].toLowerCase()));
|
ParticleType<?, ?> particleType = Particles.fromKey(NamespacedKey.minecraft(rawString[0].toLowerCase()));
|
||||||
if (particleType == null) {
|
if (particleType == null) {
|
||||||
@@ -42,10 +43,15 @@ public class ActionParticle extends Action {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
particle = ServerUtils.addParticleValues(particle, rawString);
|
particle = HMCCServerUtils.addParticleValues(particle, rawString);
|
||||||
Location location = user.getPlayer().getLocation();
|
Location location = viewer.getLocation();
|
||||||
for (Player player : PacketManager.getViewers(location)) {
|
for (Player player : HMCCPacketManager.getViewers(location)) {
|
||||||
particle.compile().send(player, 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;
|
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||||
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
|
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
|
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ActionPlayerCommand extends Action {
|
public class ActionPlayerCommand extends Action {
|
||||||
@@ -12,8 +14,14 @@ public class ActionPlayerCommand extends Action {
|
|||||||
super("player-command");
|
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
|
@Override
|
||||||
public void run(@NotNull CosmeticUser user, String raw) {
|
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;
|
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
@@ -16,8 +17,7 @@ public class ActionSound extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(@NotNull CosmeticUser user, @NotNull String raw) {
|
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||||
Player player = user.getPlayer();
|
|
||||||
String[] processedString = raw.split(" ");
|
String[] processedString = raw.split(" ");
|
||||||
|
|
||||||
String soundName = processedString[0];
|
String soundName = processedString[0];
|
||||||
@@ -31,6 +31,11 @@ public class ActionSound extends Action {
|
|||||||
|
|
||||||
MessagesUtil.sendDebugMessages("Attempting to play " + soundName, Level.INFO);
|
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;
|
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import org.apache.commons.lang3.EnumUtils;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class ActionUnequip extends Action {
|
public class ActionUnequip extends Action {
|
||||||
|
|
||||||
@@ -12,10 +13,15 @@ public class ActionUnequip extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(CosmeticUser user, String raw) {
|
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||||
if (!EnumUtils.isValidEnum(CosmeticSlot.class, raw)) return;
|
if (!CosmeticSlot.contains(raw)) return;
|
||||||
|
|
||||||
CosmeticSlot slot = CosmeticSlot.valueOf(raw);
|
CosmeticSlot slot = CosmeticSlot.valueOf(raw);
|
||||||
user.removeCosmeticSlot(slot);
|
cosmeticHolder.removeCosmeticSlot(slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(CosmeticUser user, String raw) {
|
||||||
|
run(user.getPlayer(), user, raw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,68 +1,20 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.gui.special;
|
package com.hibiscusmc.hmccosmetics.gui.special;
|
||||||
|
|
||||||
import com.hibiscusmc.hmccolor.HMCColorApi;
|
|
||||||
import com.hibiscusmc.hmccolor.shaded.gui.guis.Gui;
|
|
||||||
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.cosmetic.Cosmetic;
|
||||||
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Color;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
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.NotNull;
|
||||||
|
|
||||||
public class DyeMenu {
|
public interface DyeMenu {
|
||||||
|
|
||||||
public static void openMenu(@NotNull CosmeticUser user, Cosmetic cosmetic) {
|
/**
|
||||||
Player player = user.getPlayer();
|
* Overrideable method that is called when a player wishing to dye a menu.
|
||||||
if (player == null) return;
|
* After the method is called, the menu plugin itself is supposed to handle everything else, including adding the cosmetic to the CosmeticHolder
|
||||||
if (!Hooks.isActiveHook("HMCColor")) {
|
*
|
||||||
addCosmetic(user, cosmetic, null);
|
* @param viewer The player that is viewing the menu
|
||||||
return;
|
* @param cosmeticHolder The CosmeticHolder that is being dyed (Can be different from the viewer)
|
||||||
}
|
* @param cosmetic (The cosmetic that is wished to be dyed)
|
||||||
ItemStack originalItem = user.getUserCosmeticItem(cosmetic);
|
*/
|
||||||
if (originalItem == null || !cosmetic.isDyable()) return;
|
void openMenu(@NotNull Player viewer, @NotNull CosmeticHolder cosmeticHolder, @NotNull Cosmetic cosmetic);
|
||||||
|
|
||||||
Gui gui = HMCColorApi.INSTANCE.colorMenu();
|
|
||||||
gui.updateTitle(Hooks.processPlaceholders(player, 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;
|
|
||||||
if (color == null) return;
|
|
||||||
|
|
||||||
addCosmetic(user, cosmetic, color);
|
|
||||||
event.setCancelled(true);
|
|
||||||
} else event.setCancelled(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
gui.setPlayerInventoryAction(event -> event.setCancelled(true));
|
|
||||||
gui.setCloseGuiAction(event -> {});
|
|
||||||
gui.open(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void addCosmetic(@NotNull CosmeticUser user, Cosmetic cosmetic, Color color) {
|
|
||||||
Player player = user.getPlayer();
|
|
||||||
user.addPlayerCosmetic(cosmetic, color);
|
|
||||||
player.setItemOnCursor(new ItemStack(Material.AIR));
|
|
||||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
|
||||||
player.closeInventory();
|
|
||||||
user.updateCosmetic(cosmetic.getSlot());
|
|
||||||
}, 2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.gui.special;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class DyeMenuProvider {
|
||||||
|
|
||||||
|
private static DyeMenu instance = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the provider of the DyeMenu. Check {@link DyeMenuProvider#hasMenuProvider()} before attempting to set this,
|
||||||
|
* it is locked once a dye menu has been set!
|
||||||
|
* @param dyeMenu The dye menu implementation that wishes to be the provider.
|
||||||
|
* @throws IllegalStateException IllegalStateException will be thrown if a dye menu provider already is set by another plugin.
|
||||||
|
*/
|
||||||
|
public static void setDyeMenuProvider(@NotNull DyeMenu dyeMenu) throws IllegalStateException {
|
||||||
|
if (instance != null) {
|
||||||
|
throw new IllegalStateException("DyeMenu Implementation has already been set by another plugin.");
|
||||||
|
}
|
||||||
|
instance = dyeMenu;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when wishing to dye a cosmetic to hand it off to the dye menu implementation
|
||||||
|
* @param viewer The viewer of the menu
|
||||||
|
* @param cosmeticHolder The cosmetic holder that the player viewer wishing to modify (could be themselves or another CosmeticHolder)
|
||||||
|
* @param cosmetic The cosmetic the user wishes to dye
|
||||||
|
* @throws IllegalStateException IllegalStateException will be thrown if the dye menu instance is null (Check {@link DyeMenuProvider#hasMenuProvider()} before calling)
|
||||||
|
*/
|
||||||
|
public static void openMenu(@NotNull Player viewer, @NotNull CosmeticHolder cosmeticHolder, @NotNull Cosmetic cosmetic) throws IllegalStateException {
|
||||||
|
if (instance == null) {
|
||||||
|
throw new IllegalStateException("Unable to open a dye menu without instance of it.");
|
||||||
|
}
|
||||||
|
instance.openMenu(viewer, cosmeticHolder, cosmetic);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does HMCC have a dye menu provider already set?
|
||||||
|
* @return True if it is already set and locked; false if none have been set.
|
||||||
|
*/
|
||||||
|
public static boolean hasMenuProvider() {
|
||||||
|
return instance != null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.gui.special.impl;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccolor.HMCColorApi;
|
||||||
|
import com.hibiscusmc.hmccolor.shaded.gui.guis.Gui;
|
||||||
|
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.cosmetic.CosmeticHolder;
|
||||||
|
import com.hibiscusmc.hmccosmetics.gui.special.DyeMenu;
|
||||||
|
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||||
|
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
||||||
|
import me.lojosho.hibiscuscommons.util.AdventureUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Color;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class HMCColorDyeMenu implements DyeMenu {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void openMenu(@NotNull Player viewer, @NotNull CosmeticHolder cosmeticHolder, @NotNull Cosmetic cosmetic) {
|
||||||
|
ItemStack originalItem = cosmetic.getItem();
|
||||||
|
if (originalItem == null || !cosmetic.isDyeable()) return;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
Color color = NMSHandlers.getHandler().getUtilHandler().getColor(item);
|
||||||
|
if (color == null) return;
|
||||||
|
|
||||||
|
addCosmetic(viewer, cosmeticHolder, cosmetic, color);
|
||||||
|
event.setCancelled(true);
|
||||||
|
} else event.setCancelled(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
gui.setPlayerInventoryAction(event -> event.setCancelled(true));
|
||||||
|
gui.setCloseGuiAction(event -> {});
|
||||||
|
gui.open(viewer);
|
||||||
|
}
|
||||||
|
|
||||||
|
private 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(), () -> {
|
||||||
|
viewer.closeInventory();
|
||||||
|
cosmeticHolder.updateCosmetic(cosmetic.getSlot());
|
||||||
|
}, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,23 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.gui.type;
|
package com.hibiscusmc.hmccosmetics.gui.type;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
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.event.inventory.ClickType;
|
||||||
import org.bukkit.inventory.ItemStack;
|
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 {
|
public abstract class Type {
|
||||||
|
|
||||||
@@ -18,11 +32,87 @@ public abstract class Type {
|
|||||||
return this.id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run(CosmeticUser user, ConfigurationNode config) {
|
public void run(Player viewer, CosmeticHolder cosmeticHolder, ConfigurationNode config) {
|
||||||
run(user, config, null);
|
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 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);
|
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 final HashMap<String, Type> types = new HashMap<>();
|
||||||
|
|
||||||
private static TypeCosmetic TYPE_COSMETIC = new TypeCosmetic();
|
private static final TypeCosmetic TYPE_COSMETIC = new TypeCosmetic();
|
||||||
private static TypeEmpty TYPE_EMPTY = new TypeEmpty();
|
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) {
|
public static Type getType(@NotNull String id) {
|
||||||
return types.get(id.toUpperCase());
|
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) {
|
public static boolean isType(@NotNull String id) {
|
||||||
return types.containsKey(id.toUpperCase());
|
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,39 +2,42 @@ package com.hibiscusmc.hmccosmetics.gui.type.types;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||||
import com.hibiscusmc.hmccosmetics.config.serializer.ItemSerializer;
|
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
|
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.action.Actions;
|
import com.hibiscusmc.hmccosmetics.gui.action.Actions;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.special.DyeMenu;
|
import com.hibiscusmc.hmccosmetics.gui.special.DyeMenu;
|
||||||
|
import com.hibiscusmc.hmccosmetics.gui.special.DyeMenuProvider;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.type.Type;
|
import com.hibiscusmc.hmccosmetics.gui.type.Type;
|
||||||
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
|
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
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.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
import org.bukkit.inventory.meta.SkullMeta;
|
|
||||||
import org.jetbrains.annotations.Contract;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
|
||||||
import org.spongepowered.configurate.serialize.SerializationException;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TypeCosmetic extends Type {
|
public class TypeCosmetic extends Type {
|
||||||
|
|
||||||
|
public TypeCosmetic(String id) {
|
||||||
|
super(id);
|
||||||
|
}
|
||||||
|
|
||||||
public TypeCosmetic() {
|
public TypeCosmetic() {
|
||||||
super("cosmetic");
|
super("cosmetic");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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");
|
MessagesUtil.sendDebugMessages("Running Cosmetic Click Type");
|
||||||
if (config.node("cosmetic").virtual()) {
|
if (config.node("cosmetic").virtual()) {
|
||||||
MessagesUtil.sendDebugMessages("Cosmetic Config Field Virtual");
|
MessagesUtil.sendDebugMessages("Cosmetic Config Field Virtual");
|
||||||
@@ -42,32 +45,33 @@ public class TypeCosmetic extends Type {
|
|||||||
}
|
}
|
||||||
String cosmeticName = config.node("cosmetic").getString();
|
String cosmeticName = config.node("cosmetic").getString();
|
||||||
Cosmetic cosmetic = Cosmetics.getCosmetic(cosmeticName);
|
Cosmetic cosmetic = Cosmetics.getCosmetic(cosmeticName);
|
||||||
Player player = user.getPlayer();
|
|
||||||
if (cosmetic == null) {
|
if (cosmetic == null) {
|
||||||
MessagesUtil.sendDebugMessages("No Cosmetic Found");
|
MessagesUtil.sendDebugMessages("No Cosmetic Found");
|
||||||
MessagesUtil.sendMessage(player, "invalid-cosmetic");
|
MessagesUtil.sendMessage(viewer, "invalid-cosmetic");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!user.canEquipCosmetic(cosmetic)) {
|
if (!cosmeticHolder.canEquipCosmetic(cosmetic)) {
|
||||||
MessagesUtil.sendDebugMessages("No Cosmetic Permission");
|
MessagesUtil.sendDebugMessages("No Cosmetic Permission");
|
||||||
MessagesUtil.sendMessage(player, "no-cosmetic-permission");
|
MessagesUtil.sendMessage(viewer, "no-cosmetic-permission");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isUnEquippingCosmetic = false;
|
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;
|
String requiredClick;
|
||||||
if (isUnEquippingCosmetic) requiredClick = Settings.getCosmeticUnEquipClickType();
|
if (isUnEquippingCosmetic) requiredClick = Settings.getCosmeticUnEquipClickType();
|
||||||
else requiredClick = Settings.getCosmeticEquipClickType();
|
else requiredClick = Settings.getCosmeticEquipClickType();
|
||||||
|
|
||||||
MessagesUtil.sendDebugMessages("Required click type: " + requiredClick);
|
MessagesUtil.sendDebugMessages("Required click type: " + requiredClick);
|
||||||
MessagesUtil.sendDebugMessages("Click type: " + clickType.name());
|
MessagesUtil.sendDebugMessages("Click type: " + clickType.name());
|
||||||
if (!requiredClick.equalsIgnoreCase("ANY") && !requiredClick.equalsIgnoreCase(clickType.name())) {
|
|
||||||
MessagesUtil.sendMessage(user.getPlayer(), "invalid-click-type");
|
final boolean isRequiredClick = requiredClick.equalsIgnoreCase("ANY") || requiredClick.equalsIgnoreCase(clickType.name());
|
||||||
return;
|
final boolean isDyeClick = dyeClick.equalsIgnoreCase("ANY") || dyeClick.equalsIgnoreCase(clickType.name());
|
||||||
}
|
|
||||||
|
if (!isRequiredClick) isUnEquippingCosmetic = false;
|
||||||
|
|
||||||
List<String> actionStrings = new ArrayList<>();
|
List<String> actionStrings = new ArrayList<>();
|
||||||
ConfigurationNode actionConfig = config.node("actions");
|
ConfigurationNode actionConfig = config.node("actions");
|
||||||
@@ -95,25 +99,27 @@ public class TypeCosmetic extends Type {
|
|||||||
if (isUnEquippingCosmetic) {
|
if (isUnEquippingCosmetic) {
|
||||||
if (!actionConfig.node("on-unequip").virtual()) actionStrings.addAll(actionConfig.node("on-unequip").getList(String.class));
|
if (!actionConfig.node("on-unequip").virtual()) actionStrings.addAll(actionConfig.node("on-unequip").getList(String.class));
|
||||||
MessagesUtil.sendDebugMessages("on-unequip");
|
MessagesUtil.sendDebugMessages("on-unequip");
|
||||||
user.removeCosmeticSlot(cosmetic);
|
cosmeticHolder.removeCosmeticSlot(cosmetic);
|
||||||
} else {
|
} else {
|
||||||
if (!actionConfig.node("on-equip").virtual()) actionStrings.addAll(actionConfig.node("on-equip").getList(String.class));
|
if (!actionConfig.node("on-equip").virtual()) actionStrings.addAll(actionConfig.node("on-equip").getList(String.class));
|
||||||
MessagesUtil.sendDebugMessages("on-equip");
|
MessagesUtil.sendDebugMessages("on-equip");
|
||||||
|
MessagesUtil.sendDebugMessages("Preparing for on-equip with the following checks:");
|
||||||
|
MessagesUtil.sendDebugMessages("CosmeticDyeable? " + cosmetic.isDyeable() + " / isDyeClick? " + isDyeClick + " / isHMCColorActive? " + Hooks.isActiveHook("HMCColor"));
|
||||||
// TODO: Redo this
|
// TODO: Redo this
|
||||||
if (cosmetic.isDyable() && Hooks.isActiveHook("HMCColor")) {
|
if (cosmetic.isDyeable() && isDyeClick && DyeMenuProvider.hasMenuProvider()) {
|
||||||
DyeMenu.openMenu(user, cosmetic);
|
DyeMenuProvider.openMenu(viewer, cosmeticHolder, cosmetic);
|
||||||
} else {
|
} else if (isRequiredClick) {
|
||||||
user.addPlayerCosmetic(cosmetic);
|
cosmeticHolder.addCosmetic(cosmetic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Actions.runActions(user, actionStrings);
|
Actions.runActions(viewer, cosmeticHolder, actionStrings);
|
||||||
|
|
||||||
} catch (SerializationException e) {
|
} catch (SerializationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
// Fixes issue with offhand cosmetics not appearing. Yes, I know this is dumb
|
// 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 (cosmetic instanceof CosmeticArmorType) {
|
||||||
if (((CosmeticArmorType) cosmetic).getEquipSlot().equals(EquipmentSlot.OFF_HAND)) {
|
if (((CosmeticArmorType) cosmetic).getEquipSlot().equals(EquipmentSlot.OFF_HAND)) {
|
||||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), run, 1);
|
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), run, 1);
|
||||||
@@ -124,8 +130,19 @@ public class TypeCosmetic extends Type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack setItem(CosmeticUser user, @NotNull ConfigurationNode config, ItemStack itemStack, int slot) {
|
public void run(CosmeticUser user, @NotNull ConfigurationNode config, ClickType clickType) {
|
||||||
itemStack.setItemMeta(processLoreLines(user, itemStack.getItemMeta()));
|
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()) {
|
if (config.node("cosmetic").virtual()) {
|
||||||
return itemStack;
|
return itemStack;
|
||||||
@@ -136,9 +153,9 @@ public class TypeCosmetic extends Type {
|
|||||||
return itemStack;
|
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");
|
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 {
|
try {
|
||||||
if (equippedItem.node("material").virtual()) equippedItem.node("material").set(config.node("item", "material").getString());
|
if (equippedItem.node("material").virtual()) equippedItem.node("material").set(config.node("item", "material").getString());
|
||||||
} catch (SerializationException e) {
|
} catch (SerializationException e) {
|
||||||
@@ -149,11 +166,12 @@ public class TypeCosmetic extends Type {
|
|||||||
} catch (SerializationException e) {
|
} catch (SerializationException e) {
|
||||||
throw new RuntimeException(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;
|
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");
|
MessagesUtil.sendDebugMessages("GUI Locked Item");
|
||||||
ConfigurationNode lockedItem = config.node("locked-item");
|
ConfigurationNode lockedItem = config.node("locked-item");
|
||||||
try {
|
try {
|
||||||
@@ -166,34 +184,10 @@ public class TypeCosmetic extends Type {
|
|||||||
} catch (SerializationException e) {
|
} catch (SerializationException e) {
|
||||||
throw new RuntimeException(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;
|
||||||
}
|
}
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (itemMeta instanceof SkullMeta skullMeta) {
|
|
||||||
if (skullMeta.hasOwner()) {
|
|
||||||
skullMeta.setOwner(Hooks.processPlaceholders(user.getPlayer(), skullMeta.getOwner()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
itemMeta.setLore(processedLore);
|
|
||||||
return itemMeta;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.gui.type.types;
|
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.action.Actions;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.type.Type;
|
import com.hibiscusmc.hmccosmetics.gui.type.Type;
|
||||||
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
|
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
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.event.inventory.ClickType;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.inventory.meta.SkullMeta;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
|
||||||
import org.spongepowered.configurate.serialize.SerializationException;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -23,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 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
|
@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.
|
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.
|
ConfigurationNode actionConfig = config.node("actions"); // Configuration node that actions are under.
|
||||||
|
|
||||||
@@ -52,36 +53,32 @@ public class TypeEmpty extends Type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We run the actions once we got the raw strings from the config.
|
// 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) {
|
} catch (SerializationException e) {
|
||||||
throw new RuntimeException(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
|
@Override
|
||||||
@SuppressWarnings("Duplicates")
|
@SuppressWarnings("Duplicates")
|
||||||
public ItemStack setItem(CosmeticUser user, ConfigurationNode config, @NotNull ItemStack itemStack, int slot) {
|
public ItemStack setItem(Player viewer, CosmeticHolder cosmeticHolder, ConfigurationNode config, @NotNull ItemStack itemStack, int slot) {
|
||||||
List<String> processedLore = new ArrayList<>();
|
|
||||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||||
|
|
||||||
if (itemMeta.hasDisplayName()) {
|
itemStack.setItemMeta(processItemMeta(viewer, itemMeta));
|
||||||
itemMeta.setDisplayName(Hooks.processPlaceholders(user.getPlayer(), itemMeta.getDisplayName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (itemMeta.hasLore()) {
|
|
||||||
for (String loreLine : itemMeta.getLore()) {
|
|
||||||
processedLore.add(Hooks.processPlaceholders(user.getPlayer(), loreLine));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (itemMeta instanceof SkullMeta skullMeta) {
|
|
||||||
if (skullMeta.hasOwner()) {
|
|
||||||
skullMeta.setOwner(Hooks.processPlaceholders(user.getPlayer(), skullMeta.getOwner()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
itemMeta.setLore(processedLore);
|
|
||||||
itemStack.setItemMeta(itemMeta);
|
|
||||||
return itemStack;
|
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,28 +0,0 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.hooks.items;
|
|
||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
|
||||||
import com.mineinabyss.geary.papermc.tracking.items.ItemTrackingKt;
|
|
||||||
import com.mineinabyss.geary.prefabs.PrefabKey;
|
|
||||||
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 {
|
|
||||||
|
|
||||||
public HookGeary() {
|
|
||||||
super("geary");
|
|
||||||
setEnabledItemHook(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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) {
|
|
||||||
PrefabKey prefabKey = PrefabKey.Companion.ofOrNull(itemId);
|
|
||||||
if (prefabKey == null) return null;
|
|
||||||
return ItemTrackingKt.getGearyItems().createItem(prefabKey, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,8 @@ package com.hibiscusmc.hmccosmetics.hooks.items;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
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.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -11,8 +12,8 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
*/
|
*/
|
||||||
public class HookHMCCosmetics extends Hook {
|
public class HookHMCCosmetics extends Hook {
|
||||||
public HookHMCCosmetics() {
|
public HookHMCCosmetics() {
|
||||||
super("HMCCosmetics");
|
super("HMCCosmetics", HookFlag.ITEM_SUPPORT);
|
||||||
setEnabledItemHook(true);
|
setActive(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,5 +25,4 @@ public class HookHMCCosmetics extends Hook {
|
|||||||
if (cosmetic == null) return null;
|
if (cosmetic == null) return null;
|
||||||
return cosmetic.getItem();
|
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,7 +9,6 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
|||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import com.hibiscusmc.hmccosmetics.util.TranslationUtil;
|
import com.hibiscusmc.hmccosmetics.util.TranslationUtil;
|
||||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
import org.apache.commons.lang3.EnumUtils;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
@@ -74,29 +73,20 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
|||||||
if (placeholderArgs.size() >= 2) {
|
if (placeholderArgs.size() >= 2) {
|
||||||
CosmeticSlot slot = CosmeticSlot.valueOf(placeholderArgs.get(1).toUpperCase());
|
CosmeticSlot slot = CosmeticSlot.valueOf(placeholderArgs.get(1).toUpperCase());
|
||||||
if (slot == null) return null;
|
if (slot == null) return null;
|
||||||
if (user.getCosmetic(slot) == null) return TranslationUtil.getTranslation("current-cosmetic", "no-cosmetic");
|
Cosmetic cosmetic = user.getCosmetic(slot);
|
||||||
|
if (cosmetic == null) return TranslationUtil.getTranslation("current-cosmetic", "no-cosmetic");
|
||||||
if (placeholderArgs.size() == 2) return user.getCosmetic(slot).getId();
|
if (placeholderArgs.size() == 2) return user.getCosmetic(slot).getId();
|
||||||
|
|
||||||
String output;
|
String output;
|
||||||
switch (placeholderArgs.get(2).toLowerCase()) {
|
switch (placeholderArgs.get(2).toLowerCase()) {
|
||||||
case "material" -> {
|
case "material" -> output = getMaterialName(cosmetic);
|
||||||
output = getMaterialName(user.getCosmetic(slot));
|
case "custommodeldata" -> output = getModelData(cosmetic);
|
||||||
}
|
case "itemmodel" -> output = getItemModel(cosmetic);
|
||||||
case "custommodeldata" -> {
|
case "itemname" -> output = getItemName(cosmetic);
|
||||||
output = getModelData(user.getCosmetic(slot));
|
case "name" -> output = getDisplayName(cosmetic);
|
||||||
}
|
case "lore" -> output = getItemLore(cosmetic);
|
||||||
case "name" -> {
|
case "permission" -> output = user.getCosmetic(slot).getPermission();
|
||||||
output = getItemName(user.getCosmetic(slot));
|
default -> output = user.getCosmetic(slot).getId();
|
||||||
}
|
|
||||||
case "lore" -> {
|
|
||||||
output = getItemLore(user.getCosmetic(slot));
|
|
||||||
}
|
|
||||||
case "permission" -> {
|
|
||||||
output = user.getCosmetic(slot).getPermission();
|
|
||||||
}
|
|
||||||
default -> {
|
|
||||||
output = user.getCosmetic(slot).getId();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (output == null) output = "none";
|
if (output == null) output = "none";
|
||||||
return TranslationUtil.getTranslation("current-cosmetic", output);
|
return TranslationUtil.getTranslation("current-cosmetic", output);
|
||||||
@@ -122,7 +112,8 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
|||||||
if (placeholderArgs.size() >= 2) {
|
if (placeholderArgs.size() >= 2) {
|
||||||
String args1 = placeholderArgs.get(1);
|
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));
|
return TranslationUtil.getTranslation("equipped-cosmetic", String.valueOf(user.getCosmetic(CosmeticSlot.valueOf(args1.toUpperCase())) != null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,6 +136,30 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
|||||||
if (equippedCosmetic == null) return TranslationUtil.getTranslation("equipped-cosmetic", "false");
|
if (equippedCosmetic == null) return TranslationUtil.getTranslation("equipped-cosmetic", "false");
|
||||||
return TranslationUtil.getTranslation("equipped-cosmetic", String.valueOf(cosmetic.getId().equals(equippedCosmetic.getId())));
|
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":
|
case "wardrobe-enabled":
|
||||||
return TranslationUtil.getTranslation("in-wardrobe", String.valueOf(user.isInWardrobe()));
|
return TranslationUtil.getTranslation("in-wardrobe", String.valueOf(user.isInWardrobe()));
|
||||||
}
|
}
|
||||||
@@ -193,13 +208,55 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
|||||||
return String.valueOf(itemMeta.getCustomModelData());
|
return String.valueOf(itemMeta.getCustomModelData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the cosmetic items item model
|
||||||
|
* @param cosmetic The cosmetic to get its item model
|
||||||
|
* @return The cosmetic items item model
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public String getItemModel(@NotNull Cosmetic cosmetic) {
|
||||||
|
try {
|
||||||
|
ItemStack item = cosmetic.getItem();
|
||||||
|
if (item == null) return null;
|
||||||
|
if (!item.hasItemMeta()) return null;
|
||||||
|
ItemMeta itemMeta = item.getItemMeta();
|
||||||
|
if (itemMeta == null && itemMeta.hasItemModel() ) return null;
|
||||||
|
return itemMeta.getItemModel().asString();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the cosmetic items item name
|
||||||
|
* @param cosmetic The cosmetic to get its items item name
|
||||||
|
* @return The cosmetic items item name
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public String getItemName(@NotNull Cosmetic cosmetic) {
|
||||||
|
try {
|
||||||
|
ItemStack item = cosmetic.getItem();
|
||||||
|
if (item == null) return null;
|
||||||
|
if (!item.hasItemMeta()) return null;
|
||||||
|
ItemMeta itemMeta = item.getItemMeta();
|
||||||
|
if (itemMeta == null || !itemMeta.hasItemName()) return null;
|
||||||
|
return itemMeta.getDisplayName();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the cosmetic items display name
|
* Gets the cosmetic items display name
|
||||||
* @param cosmetic The cosmetic to get its items display name
|
* @param cosmetic The cosmetic to get its items display name
|
||||||
* @return The cosmetic items display name
|
* @return The cosmetic items display name
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getItemName(@NotNull Cosmetic cosmetic) {
|
public String getDisplayName(@NotNull Cosmetic cosmetic) {
|
||||||
ItemStack item = cosmetic.getItem();
|
ItemStack item = cosmetic.getItem();
|
||||||
if (item == null) return null;
|
if (item == null) return null;
|
||||||
if (!item.hasItemMeta()) return null;
|
if (!item.hasItemMeta()) return null;
|
||||||
|
|||||||
@@ -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;
|
package com.hibiscusmc.hmccosmetics.hooks.worldguard;
|
||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerEmoteStartEvent;
|
|
||||||
import com.hibiscusmc.hmccosmetics.config.Wardrobe;
|
import com.hibiscusmc.hmccosmetics.config.Wardrobe;
|
||||||
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
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.worldedit.bukkit.BukkitAdapter;
|
||||||
import com.sk89q.worldguard.WorldGuard;
|
import com.sk89q.worldguard.WorldGuard;
|
||||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
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.ProtectedRegion;
|
||||||
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||||
@@ -20,34 +20,44 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
|||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains {@link com.sk89q.worldguard.WorldGuard WorldGuard} related event listeners
|
* Contains {@link com.sk89q.worldguard.WorldGuard WorldGuard} related event listeners
|
||||||
*/
|
*/
|
||||||
public class WGListener implements Listener {
|
public class WGListener implements Listener {
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onPlayerMove(@NotNull PlayerMoveEvent event) {
|
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;
|
if (user == null) return;
|
||||||
Location location = event.getPlayer().getLocation();
|
Location location = player.getLocation();
|
||||||
ApplicableRegionSet set = getRegions(location);
|
ApplicableRegionSet set = getRegions(location);
|
||||||
if (user.getHidden()) {
|
if (user.isHidden() && set.getRegions().isEmpty()) {
|
||||||
if (user.getHiddenReason() == CosmeticUser.HiddenReason.WORLDGUARD && set.getRegions().isEmpty()) {
|
user.showCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
|
||||||
user.showCosmetics();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Set<String> wardrobeNames = WardrobeSettings.getWardrobeNames();
|
||||||
for (ProtectedRegion protectedRegion : set.getRegions()) {
|
for (ProtectedRegion protectedRegion : set.getRegions()) {
|
||||||
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticEnableFlag())) {
|
Map<Flag<?>, Object> flags = protectedRegion.getFlags();
|
||||||
if (protectedRegion.getFlags().get(WGHook.getCosmeticEnableFlag()).toString().equalsIgnoreCase("ALLOW")) {
|
if (flags.containsKey(WGHook.getCosmeticEnableFlag())) {
|
||||||
if (user.getHiddenReason() == CosmeticUser.HiddenReason.WORLDGUARD) user.showCosmetics();
|
if (flags.get(WGHook.getCosmeticEnableFlag()).toString().equalsIgnoreCase("ALLOW")) {
|
||||||
return;
|
user.showCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
|
||||||
|
} else {
|
||||||
|
user.hideCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
|
||||||
}
|
}
|
||||||
user.hideCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticWardrobeFlag())) {
|
if (flags.containsKey(WGHook.getCosmeticWardrobeFlag())) {
|
||||||
if (!WardrobeSettings.getWardrobeNames().contains(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString())) return;
|
String wardrobeName = flags.getOrDefault(WGHook.getCosmeticWardrobeFlag(), "").toString();
|
||||||
Wardrobe wardrobe = WardrobeSettings.getWardrobe(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString());
|
if (wardrobeName.isEmpty() || !wardrobeNames.contains(wardrobeName)) return;
|
||||||
user.enterWardrobe(true, wardrobe);
|
Wardrobe wardrobe = WardrobeSettings.getWardrobe(wardrobeName);
|
||||||
|
if (wardrobe == null) return;
|
||||||
|
user.enterWardrobe(wardrobe, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -58,15 +68,15 @@ public class WGListener implements Listener {
|
|||||||
if (user == null) return;
|
if (user == null) return;
|
||||||
Location location = event.getTo();
|
Location location = event.getTo();
|
||||||
ApplicableRegionSet set = getRegions(location);
|
ApplicableRegionSet set = getRegions(location);
|
||||||
if (user.getHidden()) {
|
if (user.isHidden()) {
|
||||||
if (user.getHiddenReason() == CosmeticUser.HiddenReason.WORLDGUARD && set.getRegions().isEmpty()) {
|
if (set.getRegions().isEmpty()) {
|
||||||
user.showCosmetics();
|
user.showCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (ProtectedRegion protectedRegion : set.getRegions()) {
|
for (ProtectedRegion protectedRegion : set.getRegions()) {
|
||||||
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticEnableFlag())) {
|
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticEnableFlag())) {
|
||||||
if (protectedRegion.getFlags().get(WGHook.getCosmeticEnableFlag()).toString().equalsIgnoreCase("ALLOW")) {
|
if (protectedRegion.getFlags().get(WGHook.getCosmeticEnableFlag()).toString().equalsIgnoreCase("ALLOW")) {
|
||||||
if (user.getHiddenReason() == CosmeticUser.HiddenReason.WORLDGUARD) user.showCosmetics();
|
user.showCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
user.hideCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
|
user.hideCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
|
||||||
@@ -75,24 +85,7 @@ public class WGListener implements Listener {
|
|||||||
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticWardrobeFlag())) {
|
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticWardrobeFlag())) {
|
||||||
if (!WardrobeSettings.getWardrobeNames().contains(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString())) return;
|
if (!WardrobeSettings.getWardrobeNames().contains(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString())) return;
|
||||||
Wardrobe wardrobe = WardrobeSettings.getWardrobe(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString());
|
Wardrobe wardrobe = WardrobeSettings.getWardrobe(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString());
|
||||||
user.enterWardrobe(true, wardrobe);
|
user.enterWardrobe(wardrobe, true);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
package com.hibiscusmc.hmccosmetics.listener;
|
||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
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.config.DatabaseSettings;
|
||||||
import com.hibiscusmc.hmccosmetics.database.Database;
|
import com.hibiscusmc.hmccosmetics.database.Database;
|
||||||
|
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||||
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
|
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@@ -15,48 +20,92 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
|||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class PlayerConnectionListener implements Listener {
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class PlayerConnectionListener implements Listener {
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onPlayerJoin(@NotNull PlayerJoinEvent event) {
|
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()) {
|
if (DatabaseSettings.isEnabledDelay()) {
|
||||||
MessagesUtil.sendDebugMessages("Delay Enabled with " + DatabaseSettings.getDelayLength() + " ticks");
|
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 {
|
} 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)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onPlayerQuit(@NotNull PlayerQuitEvent event) {
|
public void onPlayerQuit(@NotNull PlayerQuitEvent event) {
|
||||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||||
if (user == null) return; // Player never initialized, don't do anything
|
if (user == null) return; // Player never initialized, don't do anything
|
||||||
if (user.isInWardrobe()) user.leaveWardrobe();
|
|
||||||
if (user.getUserEmoteManager().isPlayingEmote()) {
|
PlayerPreUnloadEvent preUnloadEvent = new PlayerPreUnloadEvent(user);
|
||||||
user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.CONNECTION);
|
Bukkit.getPluginManager().callEvent(preUnloadEvent);
|
||||||
event.getPlayer().setInvisible(false);
|
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);
|
Database.save(user);
|
||||||
user.destroy();
|
user.destroy();
|
||||||
CosmeticUsers.removeUser(user.getUniqueId());
|
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>"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user