mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-20 15:39:16 +00:00
Compare commits
329 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b34ffebb8 | ||
|
|
3eaaf75bfb | ||
|
|
c1bae96ad9 | ||
|
|
ddb6f53655 | ||
|
|
c37f52bbb1 | ||
|
|
dd805f1860 | ||
|
|
d9551f2827 | ||
|
|
1750a1bf5f | ||
|
|
d42f5ef5af | ||
|
|
2ca940a929 | ||
|
|
36f33b54af | ||
|
|
d0b4be6db8 | ||
|
|
4afa0bb538 | ||
|
|
201bcceaab | ||
|
|
92ad314ce1 | ||
|
|
b8962539e8 | ||
|
|
01db728b99 | ||
|
|
8525dda6f4 | ||
|
|
e8f7f57e0b | ||
|
|
8c62b47d5b | ||
|
|
2ab0b119e7 | ||
|
|
20d919c65e | ||
|
|
bd41c5b9ff | ||
|
|
60aaf0cff6 | ||
|
|
71c8f8171b | ||
|
|
2bc4e3dd3f | ||
|
|
302eaa13c9 | ||
|
|
23ff51bab8 | ||
|
|
96ee695521 | ||
|
|
a9a587495a | ||
|
|
0b69e20adc | ||
|
|
a08e531226 | ||
|
|
1e27933573 | ||
|
|
0b4815842f | ||
|
|
cc6aec99e0 | ||
|
|
b51bace9f5 | ||
|
|
c70223a800 | ||
|
|
36353b5693 | ||
|
|
d4fc903c14 | ||
|
|
980d2d89df | ||
|
|
c952a8ac08 | ||
|
|
a651c9b8da | ||
|
|
c695e8b2f9 | ||
|
|
ee72bc2ef5 | ||
|
|
ebd47e9b56 | ||
|
|
5cf5e7c543 | ||
|
|
7f2d62b5e5 | ||
|
|
8d07f7cf9f | ||
|
|
789db52b57 | ||
|
|
5fb3458a98 | ||
|
|
f6935ce60b | ||
|
|
b1eb592137 | ||
|
|
913f8ccdf7 | ||
|
|
3f951263b9 | ||
|
|
744fc87491 | ||
|
|
ca01a94502 | ||
|
|
879a58d1f4 | ||
|
|
aab40b68a7 | ||
|
|
9533e2ec46 | ||
|
|
7b2e767cac | ||
|
|
4bdd000917 | ||
|
|
b397ae52f9 | ||
|
|
40620f1daa | ||
|
|
4d8d43ee2a | ||
|
|
4f8a32c3e8 | ||
|
|
1d303dee71 | ||
|
|
e9659ab1e8 | ||
|
|
ee917dbf32 | ||
|
|
2a275fe503 | ||
|
|
a5631cd2e4 | ||
|
|
1ed1a2c41d | ||
|
|
c2bf0322a7 | ||
|
|
3f8f84735f | ||
|
|
2fb28dda32 | ||
|
|
6192515550 | ||
|
|
6fcf893bac | ||
|
|
d0dfa19f2d | ||
|
|
c3b4abea40 | ||
|
|
a030d1272b | ||
|
|
d6c4b51b98 | ||
|
|
a306d76c19 | ||
|
|
1d51ee0711 | ||
|
|
e340874270 | ||
|
|
093b01d7ff | ||
|
|
5b129cc254 | ||
|
|
7a32697906 | ||
|
|
2ea272ee4a | ||
|
|
9ebfc9748d | ||
|
|
d1a2b6a016 | ||
|
|
af78424b07 | ||
|
|
c35546e536 | ||
|
|
7db03a2f8a | ||
|
|
99f3765e6e | ||
|
|
fae001a48f | ||
|
|
1ccb35ad62 | ||
|
|
2b4e570172 | ||
|
|
965b6cc740 | ||
|
|
ffda4ba6f5 | ||
|
|
df2da4fc89 | ||
|
|
cea40033f9 | ||
|
|
42a01a44aa | ||
|
|
17c07d0e01 | ||
|
|
ea4d088b04 | ||
|
|
591198175a | ||
|
|
be93369a8b | ||
|
|
fd6553a52a | ||
|
|
961f460ffb | ||
|
|
eb925d9022 | ||
|
|
d05072eb2c | ||
|
|
f456ddf8a4 | ||
|
|
c395b68d6a | ||
|
|
fddd5d0311 | ||
|
|
f08c38ff1a | ||
|
|
a4bd9108b1 | ||
|
|
de1377dc8f | ||
|
|
00ce32c528 | ||
|
|
0ddcb12b31 | ||
|
|
adadecfa19 | ||
|
|
ac35ef8b5d | ||
|
|
65f1c72b8e | ||
|
|
178bff37f5 | ||
|
|
48b9d4fb41 | ||
|
|
81d6583430 | ||
|
|
0304c9ff44 | ||
|
|
bf591e708d | ||
|
|
14bbd111f9 | ||
|
|
2185c27be5 | ||
|
|
aef9e24d28 | ||
|
|
d1a35b721e | ||
|
|
17abd0c8cc | ||
|
|
a907cd51b9 | ||
|
|
9f6c7db8fd | ||
|
|
2ba83d8cc5 | ||
|
|
40bf0e173e | ||
|
|
a757292b4b | ||
|
|
b41d466546 | ||
|
|
135fdc94d4 | ||
|
|
d0092a2ffe | ||
|
|
acf31009d5 | ||
|
|
981c6155e7 | ||
|
|
2ecc86fc7b | ||
|
|
2682428354 | ||
|
|
df8ad26684 | ||
|
|
1f714c0153 | ||
|
|
0bfadad222 | ||
|
|
a1c719fc50 | ||
|
|
fe9812cd69 | ||
|
|
b9699b27c7 | ||
|
|
2c5ddb542e | ||
|
|
461642d64b | ||
|
|
37a8a2379d | ||
|
|
e698392e40 | ||
|
|
e1357b265f | ||
|
|
a5475b0268 | ||
|
|
60dba9efa6 | ||
|
|
e2d3391070 | ||
|
|
aed34ec28d | ||
|
|
ae6d88ab56 | ||
|
|
35be7283e9 | ||
|
|
224fcb83d9 | ||
|
|
98934536be | ||
|
|
5ac3712e56 | ||
|
|
2d2d4e6d44 | ||
|
|
4b1921b754 | ||
|
|
8ca1d44375 | ||
|
|
23c82cc6ed | ||
|
|
2bf5280827 | ||
|
|
475a1e0ef1 | ||
|
|
ef4d53eb85 | ||
|
|
97da4f7809 | ||
|
|
1622dac67f | ||
|
|
fce1ec5042 | ||
|
|
060bcc95e1 | ||
|
|
5aca80609a | ||
|
|
7c1da21026 | ||
|
|
52329a6de5 | ||
|
|
8cdef228e3 | ||
|
|
432d6d837a | ||
|
|
f42e8b2298 | ||
|
|
107f5b9215 | ||
|
|
d303fcc45b | ||
|
|
147be9ab7c | ||
|
|
7f91f9dbad | ||
|
|
63e538511b | ||
|
|
d0c8abc38c | ||
|
|
97a28b9e0c | ||
|
|
b5ae6e65a1 | ||
|
|
0c7e740d7a | ||
|
|
1b7462becc | ||
|
|
d508ecd4c0 | ||
|
|
601d6f8a53 | ||
|
|
44be4eceb8 | ||
|
|
8bebd57169 | ||
|
|
8f426cef31 | ||
|
|
abce477f0d | ||
|
|
985e797f83 | ||
|
|
8bc84cbdd2 | ||
|
|
894e4eef26 | ||
|
|
5995dabf6f | ||
|
|
ed647b7e5d | ||
|
|
e378732d44 | ||
|
|
74eb5dd85a | ||
|
|
c9ba396c33 | ||
|
|
3967ac4fa5 | ||
|
|
b1a35df7b5 | ||
|
|
0e1c9b3f7e | ||
|
|
0238ac8fc4 | ||
|
|
4d6baf0b0c | ||
|
|
157fab6309 | ||
|
|
0a488a6791 | ||
|
|
1c9989e64a | ||
|
|
fb8dcf53e3 | ||
|
|
17179cbe35 | ||
|
|
f589696d19 | ||
|
|
68e87cba6f | ||
|
|
63a0bdd0d5 | ||
|
|
a01f35c53d | ||
|
|
a607f2dcbd | ||
|
|
7a9a002e25 | ||
|
|
fd50cd058a | ||
|
|
970ca8227b | ||
|
|
e7fd3ac288 | ||
|
|
51214964c4 | ||
|
|
4d4be789ae | ||
|
|
f2b276a2ef | ||
|
|
cf54f2b487 | ||
|
|
bae13c2e3c | ||
|
|
004f9ebef5 | ||
|
|
ad956259d0 | ||
|
|
65cebc3154 | ||
|
|
fb79293902 | ||
|
|
b49cebdec8 | ||
|
|
00cc3eef2c | ||
|
|
42bae598a6 | ||
|
|
b182e46b28 | ||
|
|
6b6b0e385e | ||
|
|
db60046701 | ||
|
|
300e2cffba | ||
|
|
d5983d8834 | ||
|
|
9e07f728e1 | ||
|
|
dcd38d86c5 | ||
|
|
d39110af6c | ||
|
|
0f6fa3db8a | ||
|
|
5aef04dee0 | ||
|
|
a096f6c684 | ||
|
|
89825659a6 | ||
|
|
6ba078dcc4 | ||
|
|
2e32b8d9d5 | ||
|
|
941f57af35 | ||
|
|
bdb52c0a32 | ||
|
|
a7170e09cf | ||
|
|
8456d6a7ae | ||
|
|
08b28bc254 | ||
|
|
c27a9ab2ad | ||
|
|
2bf618d8d3 | ||
|
|
6eb7c9243d | ||
|
|
c2b4fade42 | ||
|
|
382eed9982 | ||
|
|
498370cc8e | ||
|
|
fef5769e31 | ||
|
|
4aa1f9451d | ||
|
|
c7730429de | ||
|
|
73ccddf628 | ||
|
|
26b5472924 | ||
|
|
5ecfb08412 | ||
|
|
8b223228ce | ||
|
|
eb03acd959 | ||
|
|
8e5b3d098c | ||
|
|
a869120b62 | ||
|
|
614892500c | ||
|
|
872282f77a | ||
|
|
c0483bfefe | ||
|
|
aecd40ba5a | ||
|
|
c3db45cfc4 | ||
|
|
99bc0a0756 | ||
|
|
e9afd6deb8 | ||
|
|
0770ac456d | ||
|
|
327d602491 | ||
|
|
65f162c89c | ||
|
|
e96d1f505e | ||
|
|
2af1deb4c1 | ||
|
|
d740989a01 | ||
|
|
fdc0004b75 | ||
|
|
a1ac0a83e1 | ||
|
|
f51ac5969f | ||
|
|
3255f744a7 | ||
|
|
dfa5e85dcb | ||
|
|
e30451e972 | ||
|
|
500b8ca0ce | ||
|
|
c52718da58 | ||
|
|
1290750028 | ||
|
|
57d5e02275 | ||
|
|
645fd25b82 | ||
|
|
4b1c15f46f | ||
|
|
b96ae68f24 | ||
|
|
3e5f698dbd | ||
|
|
88632dce3f | ||
|
|
30f25b4a92 | ||
|
|
a385b341f7 | ||
|
|
66c5fd86c5 | ||
|
|
ff4f2b6ede | ||
|
|
80eb333b39 | ||
|
|
8b2b771a9b | ||
|
|
7873b3fe04 | ||
|
|
9854e77bf5 | ||
|
|
cad78636d0 | ||
|
|
14d256feed | ||
|
|
53163feb60 | ||
|
|
caf168d29d | ||
|
|
2a7686e6b7 | ||
|
|
5309c37902 | ||
|
|
ea1b87c128 | ||
|
|
9d92ed0dda | ||
|
|
e24d5697e7 | ||
|
|
8c59b27302 | ||
|
|
df3544726d | ||
|
|
27af0a6085 | ||
|
|
1db96c38d9 | ||
|
|
d9b92d5336 | ||
|
|
0905071dd2 | ||
|
|
1804e4691b | ||
|
|
223f8bdb9c | ||
|
|
c757752038 | ||
|
|
243644301a | ||
|
|
652b20c148 | ||
|
|
6c3ffbb71e | ||
|
|
fb6e5abb8b | ||
|
|
f546500f1e | ||
|
|
044528188d |
13
.github/CONTRIBUTING.md
vendored
Normal file
13
.github/CONTRIBUTING.md
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# Contributing
|
||||||
|
|
||||||
|
If you wish to contribute to the HMCCosmetics codebase, feel free to fork the repository and [submit a pull request](https://github.com/HibiscusMC/HMCCosmetics/compare).
|
||||||
|
> **Note** Contributions to the HMCCosmetics codebase should remain consistent with current code style. Remember to keep your code clean, documented and understandable, and to avoid messy or confusing code.
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
To get ready to work on the codebase, please do the following:
|
||||||
|
|
||||||
|
1. Fork & clone the repository, and make sure you're on the **remapped** branch. (*This is the default branch*)
|
||||||
|
2. Code your heart out!
|
||||||
|
3. Run `./gradlew build` to ensure your project successfully builds. (*This may take a while*)
|
||||||
|
4. Finally, [submit a pull request](https://github.com/HibiscusMC/HMCCosmetics/compare)!
|
||||||
1
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
1
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
blank_issues_enabled: false
|
||||||
2
.github/ISSUE_TEMPLATE/feature-request.yml
vendored
2
.github/ISSUE_TEMPLATE/feature-request.yml
vendored
@@ -1,7 +1,7 @@
|
|||||||
name: Feature Request
|
name: Feature Request
|
||||||
description: Create a feature request to help us keep track of all features you want to be added
|
description: Create a feature request to help us keep track of all features you want to be added
|
||||||
title: "[FEATURE] <title>"
|
title: "[FEATURE] <title>"
|
||||||
labels: [feature]
|
labels: [enhancement]
|
||||||
|
|
||||||
body:
|
body:
|
||||||
- type: "checkboxes"
|
- type: "checkboxes"
|
||||||
|
|||||||
16
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
16
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#### Select the option(s) that best describes this PR:
|
||||||
|
- [ ] Major breaking change
|
||||||
|
- [ ] Minor change
|
||||||
|
- [ ] Bug fix
|
||||||
|
- [ ] Feature implementation
|
||||||
|
- [ ] Documentation
|
||||||
|
- [ ] Cleaning
|
||||||
|
- [ ] Refactoring
|
||||||
|
|
||||||
|
#### Please describe the changes this PR makes and why it should be merged:
|
||||||
|
|
||||||
|
#### Check that:
|
||||||
|
- [ ] *Any* new classes, public methods and/or properties are properly documented with `JavaDocs`
|
||||||
|
- [ ] Syntax and style are consistent with existing code
|
||||||
|
- [ ] *Any* replaced method isn't deleted, but rather labeled as deprecated
|
||||||
|
> **Note** In the case where the new method has the exact same signature as the method it's replacing, mention above that the old method *was* deleted.
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -23,7 +23,6 @@ atlassian-ide-plugin.xml
|
|||||||
*.ctxt
|
*.ctxt
|
||||||
|
|
||||||
# Package Files #
|
# Package Files #
|
||||||
*.jar
|
|
||||||
*.war
|
*.war
|
||||||
*.nar
|
*.nar
|
||||||
*.ear
|
*.ear
|
||||||
|
|||||||
@@ -2,14 +2,13 @@ import net.minecrell.pluginyml.bukkit.BukkitPluginDescription
|
|||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("java")
|
id("java")
|
||||||
id("maven-publish")
|
|
||||||
id("com.github.johnrengelman.shadow") version "7.1.2"
|
id("com.github.johnrengelman.shadow") version "7.1.2"
|
||||||
id("xyz.jpenilla.run-paper") version "2.0.0"
|
id("xyz.jpenilla.run-paper") version "2.0.0"
|
||||||
id("net.minecrell.plugin-yml.bukkit") version "0.5.2"
|
id("net.minecrell.plugin-yml.bukkit") version "0.5.2"
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "com.hibiscusmc"
|
group = "com.hibiscusmc"
|
||||||
version = "2.0.2"
|
version = "2.2.8"
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
apply(plugin = "java")
|
apply(plugin = "java")
|
||||||
@@ -54,38 +53,54 @@ allprojects {
|
|||||||
|
|
||||||
// UpdateChecker
|
// UpdateChecker
|
||||||
maven("https://hub.jeff-media.com/nexus/repository/jeff-media-public/")
|
maven("https://hub.jeff-media.com/nexus/repository/jeff-media-public/")
|
||||||
|
|
||||||
|
// ParticleHelper
|
||||||
|
maven("https://repo.bytecode.space/repository/maven-public/")
|
||||||
|
|
||||||
|
// PlayerAnimator
|
||||||
|
maven("https://mvn.lumine.io/repository/maven/")
|
||||||
|
|
||||||
|
// md-5 Repo
|
||||||
|
maven("https://repo.md-5.net/content/groups/public/")
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
compileOnly(fileTree("${project.rootDir}/lib") { include("*.jar") })
|
||||||
|
compileOnly("com.mojang:authlib:1.5.25")
|
||||||
|
compileOnly("org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT")
|
||||||
|
compileOnly("org.jetbrains:annotations:23.0.0")
|
||||||
|
compileOnly("com.comphenix.protocol:ProtocolLib:5.0.0-SNAPSHOT")
|
||||||
|
compileOnly("me.clip:placeholderapi:2.11.1")
|
||||||
|
compileOnly("com.ticxo.modelengine:api:R3.0.1")
|
||||||
|
compileOnly("com.github.oraxen:oraxen:-SNAPSHOT")
|
||||||
|
compileOnly("com.github.LoneDev6:API-ItemsAdder:3.2.5")
|
||||||
|
compileOnly("com.mineinabyss:idofront:0.12.111")
|
||||||
|
compileOnly("com.mineinabyss:geary-papermc-core:0.19.113")
|
||||||
|
compileOnly("com.mineinabyss:looty:0.8.67")
|
||||||
|
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.1.0-SNAPSHOT")
|
||||||
|
compileOnly("it.unimi.dsi:fastutil:8.5.11")
|
||||||
|
compileOnly("com.github.LeonMangler:SuperVanish:6.2.6-4")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(project(path = ":common"))
|
implementation(project(path = ":common"))
|
||||||
|
implementation(project(path = ":v1_17_R1", configuration = "reobf"))
|
||||||
|
implementation(project(path = ":v1_18_R2", configuration = "reobf"))
|
||||||
implementation(project(path = ":v1_19_R1", configuration = "reobf"))
|
implementation(project(path = ":v1_19_R1", configuration = "reobf"))
|
||||||
implementation(project(path = ":v1_19_R2", configuration = "reobf"))
|
implementation(project(path = ":v1_19_R2", configuration = "reobf"))
|
||||||
//implementation(files("v1_19_R1/build/libs/1_19_R1-unspecified.jar"))
|
implementation(project(path = ":v1_19_R3", configuration = "reobf"))
|
||||||
|
|
||||||
compileOnly("com.mojang:authlib:1.5.25")
|
|
||||||
compileOnly("org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT")
|
|
||||||
compileOnly("org.jetbrains:annotations:23.0.0")
|
|
||||||
compileOnly("com.comphenix.protocol:ProtocolLib:5.0.0-SNAPSHOT")
|
|
||||||
compileOnly("me.clip:placeholderapi:2.11.1")
|
|
||||||
compileOnly("com.ticxo.modelengine:api:R3.0.1")
|
|
||||||
compileOnly("com.github.oraxen:oraxen:-SNAPSHOT")
|
|
||||||
compileOnly("com.github.LoneDev6:API-ItemsAdder:3.2.5")
|
|
||||||
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.1.0-SNAPSHOT")
|
|
||||||
compileOnly("it.unimi.dsi:fastutil:8.5.11")
|
|
||||||
|
|
||||||
//compileOnly("com.github.Fisher2911:FisherLib:master-SNAPSHOT")
|
//compileOnly("com.github.Fisher2911:FisherLib:master-SNAPSHOT")
|
||||||
implementation("net.kyori:adventure-api:4.11.0")
|
implementation("net.kyori:adventure-api:4.11.0")
|
||||||
implementation ("net.kyori:adventure-text-minimessage:4.11.0")
|
implementation("net.kyori:adventure-text-minimessage:4.11.0")
|
||||||
implementation("net.kyori:adventure-platform-bukkit:4.1.2")
|
implementation("net.kyori:adventure-platform-bukkit:4.1.2")
|
||||||
implementation("dev.triumphteam:triumph-gui:3.1.3")
|
implementation("dev.triumphteam:triumph-gui:3.1.3")
|
||||||
implementation("org.spongepowered:configurate-yaml:4.1.2")
|
implementation("org.spongepowered:configurate-yaml:4.1.2")
|
||||||
implementation("org.bstats:bstats-bukkit:3.0.0")
|
implementation("org.bstats:bstats-bukkit:3.0.0")
|
||||||
implementation("com.jeff_media:SpigotUpdateChecker: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.5")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
@@ -105,12 +120,15 @@ tasks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
runServer {
|
runServer {
|
||||||
minecraftVersion("1.19.2")
|
minecraftVersion("1.19.4")
|
||||||
}
|
}
|
||||||
|
|
||||||
shadowJar {
|
shadowJar {
|
||||||
|
dependsOn(":v1_17_R1:reobfJar")
|
||||||
|
dependsOn(":v1_18_R2:reobfJar")
|
||||||
dependsOn(":v1_19_R1:reobfJar")
|
dependsOn(":v1_19_R1:reobfJar")
|
||||||
dependsOn(":v1_19_R2:reobfJar")
|
dependsOn(":v1_19_R2:reobfJar")
|
||||||
|
dependsOn(":v1_19_R3:reobfJar")
|
||||||
mergeServiceFiles()
|
mergeServiceFiles()
|
||||||
|
|
||||||
relocate("dev.triumphteam.gui", "com.hisbiscusmc.hmccosmetics.gui")
|
relocate("dev.triumphteam.gui", "com.hisbiscusmc.hmccosmetics.gui")
|
||||||
@@ -121,6 +139,8 @@ tasks {
|
|||||||
relocate("com.zaxxer.hikaricp", "com.hisbiscusmc.hmccosmetics.hikaricp")
|
relocate("com.zaxxer.hikaricp", "com.hisbiscusmc.hmccosmetics.hikaricp")
|
||||||
relocate("com.j256.ormlite", "com.hisbiscusmc.hmccosmetics.ormlite")
|
relocate("com.j256.ormlite", "com.hisbiscusmc.hmccosmetics.ormlite")
|
||||||
relocate("com.jeff_media.updatechecker", "com.hisbiscusmc.hmccosmetics.updatechecker")
|
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")
|
||||||
archiveFileName.set("HMCCosmeticsRemapped-${project.version}.jar")
|
archiveFileName.set("HMCCosmeticsRemapped-${project.version}.jar")
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -145,10 +165,10 @@ tasks {
|
|||||||
bukkit {
|
bukkit {
|
||||||
load = BukkitPluginDescription.PluginLoadOrder.POSTWORLD
|
load = BukkitPluginDescription.PluginLoadOrder.POSTWORLD
|
||||||
main = "com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin"
|
main = "com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin"
|
||||||
apiVersion = "1.19"
|
apiVersion = "1.17"
|
||||||
authors = listOf("LoJoSho")
|
authors = listOf("LoJoSho")
|
||||||
depend = listOf("ProtocolLib", "PlaceholderAPI")
|
depend = listOf("ProtocolLib")
|
||||||
softDepend = listOf("ModelEngine", "Oraxen", "ItemsAdder", "HMCColor", "WorldGuard", "MythicMobs")
|
softDepend = listOf("ModelEngine", "Oraxen", "ItemsAdder", "Looty", "HMCColor", "WorldGuard", "MythicMobs", "PlaceholderAPI", "SuperVanish", "PremiumVanish")
|
||||||
version = "${project.version}"
|
version = "${project.version}"
|
||||||
|
|
||||||
commands {
|
commands {
|
||||||
@@ -175,6 +195,21 @@ bukkit {
|
|||||||
register("hmccosmetics.cmd.menu") {
|
register("hmccosmetics.cmd.menu") {
|
||||||
default = BukkitPluginDescription.Permission.Default.TRUE
|
default = BukkitPluginDescription.Permission.Default.TRUE
|
||||||
}
|
}
|
||||||
|
register("hmccosmetics.emote.shiftrun") {
|
||||||
|
default = BukkitPluginDescription.Permission.Default.TRUE
|
||||||
|
}
|
||||||
|
register("hmccosmetics.cmd.emote") {
|
||||||
|
default = BukkitPluginDescription.Permission.Default.TRUE
|
||||||
|
}
|
||||||
|
register("hmccosmetics.cmd.playemote") {
|
||||||
|
default = BukkitPluginDescription.Permission.Default.OP
|
||||||
|
}
|
||||||
|
register("hmccosmetics.cmd.playemote.other") {
|
||||||
|
default = BukkitPluginDescription.Permission.Default.OP
|
||||||
|
}
|
||||||
|
register("hmccosmetics.cmd.emote.other") {
|
||||||
|
default = BukkitPluginDescription.Permission.Default.OP
|
||||||
|
}
|
||||||
register("hmccosmetics.cmd.setlocation") {
|
register("hmccosmetics.cmd.setlocation") {
|
||||||
default = BukkitPluginDescription.Permission.Default.OP
|
default = BukkitPluginDescription.Permission.Default.OP
|
||||||
}
|
}
|
||||||
@@ -220,17 +255,4 @@ bukkit {
|
|||||||
java {
|
java {
|
||||||
toolchain.languageVersion.set(JavaLanguageVersion.of(17
|
toolchain.languageVersion.set(JavaLanguageVersion.of(17
|
||||||
))
|
))
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
publishing {
|
|
||||||
publications {
|
|
||||||
create<MavenPublication>("maven") {
|
|
||||||
groupId = "${project.group}"
|
|
||||||
artifactId = "${project.name}"
|
|
||||||
version = "${project.version}"
|
|
||||||
|
|
||||||
from(components["java"])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,32 +1,104 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id("java")
|
id("java")
|
||||||
|
id("maven-publish")
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("com.mojang:authlib:1.5.25")
|
compileOnly("com.mojang:authlib:1.5.25")
|
||||||
compileOnly("org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT")
|
compileOnly("org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT")
|
||||||
compileOnly("org.jetbrains:annotations:23.0.0")
|
compileOnly("org.jetbrains:annotations:23.0.0")
|
||||||
compileOnly("com.comphenix.protocol:ProtocolLib:5.0.0-SNAPSHOT")
|
compileOnly("com.comphenix.protocol:ProtocolLib:5.0.0-SNAPSHOT")
|
||||||
compileOnly("me.clip:placeholderapi:2.11.1")
|
compileOnly("me.clip:placeholderapi:2.11.1")
|
||||||
compileOnly("com.ticxo.modelengine:api:R3.0.1")
|
compileOnly("com.ticxo.modelengine:api:R3.0.1")
|
||||||
compileOnly("com.github.oraxen:oraxen:-SNAPSHOT")
|
compileOnly("com.github.oraxen:oraxen:-SNAPSHOT")
|
||||||
compileOnly("com.github.LoneDev6:API-ItemsAdder:3.2.5")
|
compileOnly("com.github.LoneDev6:API-ItemsAdder:3.2.5")
|
||||||
|
compileOnly("com.mineinabyss:geary-papermc-core:0.19.113")
|
||||||
|
compileOnly("com.mineinabyss:looty:0.8.67")
|
||||||
compileOnly("com.hibiscus:hmccolor:0.3-SNAPSHOT")
|
compileOnly("com.hibiscus:hmccolor:0.3-SNAPSHOT")
|
||||||
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.1.0-SNAPSHOT")
|
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.1.0-SNAPSHOT")
|
||||||
compileOnly("it.unimi.dsi:fastutil:8.5.11")
|
compileOnly("it.unimi.dsi:fastutil:8.5.11")
|
||||||
compileOnly("io.lumine:Mythic-Dist:5.2.1")
|
compileOnly("io.lumine:Mythic-Dist:5.2.1")
|
||||||
|
compileOnly("com.github.LeonMangler:SuperVanish:6.2.6-4")
|
||||||
|
|
||||||
//compileOnly("com.github.Fisher2911:FisherLib:master-SNAPSHOT")
|
//compileOnly("com.github.Fisher2911:FisherLib:master-SNAPSHOT")
|
||||||
implementation("net.kyori:adventure-api:4.12.0")
|
implementation("net.kyori:adventure-api:4.12.0")
|
||||||
implementation ("net.kyori:adventure-text-minimessage:4.12.0")
|
implementation("net.kyori:adventure-text-minimessage:4.12.0")
|
||||||
implementation("net.kyori:adventure-platform-bukkit:4.2.0")
|
implementation("net.kyori:adventure-platform-bukkit:4.2.0")
|
||||||
implementation("dev.triumphteam:triumph-gui:3.1.3")
|
implementation("dev.triumphteam:triumph-gui:3.1.3")
|
||||||
implementation("org.spongepowered:configurate-yaml:4.1.2")
|
implementation("org.spongepowered:configurate-yaml:4.1.2")
|
||||||
implementation("org.bstats:bstats-bukkit:3.0.0")
|
implementation("org.bstats:bstats-bukkit:3.0.0")
|
||||||
implementation("com.jeff_media:SpigotUpdateChecker: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.5")
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
toolchain.languageVersion.set(JavaLanguageVersion.of(17
|
toolchain.languageVersion.set(JavaLanguageVersion.of(17
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
val publishData = PublishData(project)
|
||||||
|
publications {
|
||||||
|
create<MavenPublication>("maven") {
|
||||||
|
groupId = "${rootProject.group}"
|
||||||
|
artifactId = "${rootProject.name}"
|
||||||
|
version = "${rootProject.version}"
|
||||||
|
|
||||||
|
from(components["java"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
authentication {
|
||||||
|
credentials(PasswordCredentials::class) {
|
||||||
|
username = System.getenv("REPO_USERNAME")
|
||||||
|
password = System.getenv("REPO_PASSWORD")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
name = "HibiscusMCRepository"
|
||||||
|
url = uri(publishData.getRepository())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class PublishData(private val project: Project) {
|
||||||
|
var type: Type = getReleaseType()
|
||||||
|
var hashLength: Int = 7
|
||||||
|
|
||||||
|
private fun getReleaseType(): Type {
|
||||||
|
val branch = getCheckedOutBranch()
|
||||||
|
return when {
|
||||||
|
branch.contentEquals("master") || branch.contentEquals("local") -> Type.RELEASE
|
||||||
|
branch.startsWith("dev") -> Type.DEV
|
||||||
|
else -> Type.SNAPSHOT
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getCheckedOutGitCommitHash(): String =
|
||||||
|
System.getenv("GITHUB_SHA")?.substring(0, hashLength) ?: "local"
|
||||||
|
|
||||||
|
private fun getCheckedOutBranch(): String =
|
||||||
|
System.getenv("GITHUB_REF")?.replace("refs/heads/", "") ?: "local"
|
||||||
|
|
||||||
|
fun getVersion(): String = getVersion(false)
|
||||||
|
|
||||||
|
fun getVersion(appendCommit: Boolean): String =
|
||||||
|
type.append(getVersionString(), appendCommit, getCheckedOutGitCommitHash())
|
||||||
|
|
||||||
|
private fun getVersionString(): String =
|
||||||
|
(rootProject.version as String).replace("-SNAPSHOT", "").replace("-DEV", "")
|
||||||
|
|
||||||
|
fun getRepository(): String = type.repo
|
||||||
|
|
||||||
|
enum class Type(private val append: String, val repo: String, private val addCommit: Boolean) {
|
||||||
|
RELEASE("", "https://repo.hibiscusmc.com/releases/", false),
|
||||||
|
DEV("-DEV", "https://repo.hibiscusmc.com/development/", true),
|
||||||
|
SNAPSHOT("-SNAPSHOT", "https://repo.hibiscusmc.com/snapshots/", true);
|
||||||
|
|
||||||
|
fun append(name: String, appendCommit: Boolean, commitHash: String): String =
|
||||||
|
name.plus(append).plus(if (appendCommit && addCommit) "-".plus(commitHash) else "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,17 +12,23 @@ 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.gui.Menus;
|
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||||
import com.hibiscusmc.hmccosmetics.hooks.PAPIHook;
|
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
|
||||||
import com.hibiscusmc.hmccosmetics.hooks.items.ItemHooks;
|
|
||||||
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.PlayerConnectionListener;
|
||||||
import com.hibiscusmc.hmccosmetics.listener.PlayerGameListener;
|
import com.hibiscusmc.hmccosmetics.listener.PlayerGameListener;
|
||||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
|
||||||
import com.hibiscusmc.hmccosmetics.util.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 com.jeff_media.updatechecker.UpdateCheckSource;
|
||||||
import com.jeff_media.updatechecker.UpdateChecker;
|
import com.jeff_media.updatechecker.UpdateChecker;
|
||||||
|
import com.ticxo.playeranimator.PlayerAnimatorImpl;
|
||||||
|
import com.ticxo.playeranimator.api.PlayerAnimator;
|
||||||
|
import com.ticxo.playeranimator.api.animation.pack.AnimationPack;
|
||||||
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.bstats.bukkit.Metrics;
|
import org.bstats.bukkit.Metrics;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@@ -38,6 +44,7 @@ import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public final class HMCCosmeticsPlugin extends JavaPlugin {
|
public final class HMCCosmeticsPlugin extends JavaPlugin {
|
||||||
|
|
||||||
@@ -45,6 +52,9 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
|||||||
private static boolean disable = false;
|
private static boolean disable = false;
|
||||||
private static YamlConfigurationLoader configLoader;
|
private static YamlConfigurationLoader configLoader;
|
||||||
private static final int pluginId = 13873;
|
private static final int pluginId = 13873;
|
||||||
|
private static boolean hasModelEngine = false;
|
||||||
|
private static boolean onLatestVersion = true;
|
||||||
|
private static String latestVersion = "";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@@ -61,11 +71,24 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update Checker
|
// Update Checker
|
||||||
new UpdateChecker(this, UpdateCheckSource.POLYMART, "1879")
|
UpdateChecker checker = new UpdateChecker(this, UpdateCheckSource.POLYMART, "1879")
|
||||||
.setDownloadLink("https://polymart.org/resource/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)
|
.checkEveryXHours(24)
|
||||||
.checkNow();
|
.checkNow();
|
||||||
|
onLatestVersion = checker.isUsingLatestVersion();
|
||||||
// File setup
|
// File setup
|
||||||
if (!getDataFolder().exists()) {
|
if (!getDataFolder().exists()) {
|
||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
@@ -74,6 +97,12 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
|||||||
saveResource("cosmetics/defaultcosmetics.yml", false);
|
saveResource("cosmetics/defaultcosmetics.yml", false);
|
||||||
saveResource("menus/defaultmenu.yml", false);
|
saveResource("menus/defaultmenu.yml", false);
|
||||||
}
|
}
|
||||||
|
// Emote folder setup
|
||||||
|
File emoteFile = new File(getDataFolder().getPath() + "/emotes");
|
||||||
|
if (!emoteFile.exists()) emoteFile.mkdir();
|
||||||
|
|
||||||
|
// Player Animator
|
||||||
|
PlayerAnimatorImpl.initialize(this);
|
||||||
|
|
||||||
setup();
|
setup();
|
||||||
|
|
||||||
@@ -88,11 +117,13 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
|||||||
// Database
|
// Database
|
||||||
new Database();
|
new Database();
|
||||||
|
|
||||||
// PAPI
|
// ModelEngine
|
||||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
if (Bukkit.getPluginManager().getPlugin("ModelEngine") != null) {
|
||||||
new PAPIHook().register();
|
hasModelEngine = true;
|
||||||
}
|
}
|
||||||
if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null) {
|
|
||||||
|
// WorldGuard
|
||||||
|
if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null && Settings.isWorldGuardMoveCheckEnabled()) {
|
||||||
getServer().getPluginManager().registerEvents(new WGListener(), this);
|
getServer().getPluginManager().registerEvents(new WGListener(), this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -107,11 +138,16 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
// Plugin shutdown logic
|
||||||
disable = true;
|
disable = true;
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
Database.save(player);
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
|
if (user == null) continue;
|
||||||
|
if (user.getUserEmoteManager().isPlayingEmote()) {
|
||||||
|
player.setInvisible(false);
|
||||||
|
}
|
||||||
|
Database.save(user);
|
||||||
}
|
}
|
||||||
// Plugin shutdown logic
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HMCCosmeticsPlugin getInstance() {
|
public static HMCCosmeticsPlugin getInstance() {
|
||||||
@@ -173,8 +209,8 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ItemHooks
|
// Misc Hooks setup (like items)
|
||||||
ItemHooks.setup();
|
Hooks.setup();
|
||||||
|
|
||||||
// Cosmetics setup
|
// Cosmetics setup
|
||||||
Cosmetics.setup();
|
Cosmetics.setup();
|
||||||
@@ -205,6 +241,24 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File emoteFolder = new File(getInstance().getDataFolder().getPath() + "/emotes/");
|
||||||
|
if (emoteFolder.exists()) {
|
||||||
|
PlayerAnimator.api.getAnimationManager().clearRegistry();
|
||||||
|
File[] emotesFiles = emoteFolder.listFiles();
|
||||||
|
for (File emoteFile : emotesFiles) {
|
||||||
|
if (!emoteFile.getName().contains("bbmodel")) continue;
|
||||||
|
String animationName = FilenameUtils.removeExtension(emoteFile.getName());
|
||||||
|
PlayerAnimator.api.getAnimationManager().importAnimations(animationName, emoteFile);
|
||||||
|
MessagesUtil.sendDebugMessages("Added '" + animationName + "' to Player Animator ");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
for (Map.Entry<String, AnimationPack> packEntry : PlayerAnimator.api.getAnimationManager().getRegistry().entrySet()) {
|
||||||
|
Set<String> animationNames = packEntry.getValue().getAnimations().keySet().stream().map(animation -> packEntry.getKey().replace(":", ".") + "." + animation).collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
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");
|
||||||
@@ -229,4 +283,14 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean hasModelEngine() {
|
||||||
|
return hasModelEngine;
|
||||||
|
}
|
||||||
|
public static boolean isOnLatestVersion() {
|
||||||
|
return onLatestVersion;
|
||||||
|
}
|
||||||
|
public static String getLatestVersion() {
|
||||||
|
return latestVersion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,20 +2,21 @@ package com.hibiscusmc.hmccosmetics.api;
|
|||||||
|
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the plugin is set up and/or reloaded
|
||||||
|
*/
|
||||||
public class HMCCosmeticSetupEvent extends Event {
|
public class HMCCosmeticSetupEvent extends Event {
|
||||||
|
|
||||||
public HMCCosmeticSetupEvent() {
|
|
||||||
// Empty
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NotNull
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,51 +3,68 @@ package com.hibiscusmc.hmccosmetics.api;
|
|||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class PlayerCosmeticEquipEvent extends Event implements Cancellable {
|
/**
|
||||||
|
* Called when a player equips a cosmetic
|
||||||
private CosmeticUser user;
|
*/
|
||||||
private Cosmetic cosmetic;
|
public class PlayerCosmeticEquipEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||||
private boolean isCancelled;
|
|
||||||
|
|
||||||
public PlayerCosmeticEquipEvent(CosmeticUser user, Cosmetic cosmetic) {
|
|
||||||
this.user = user;
|
|
||||||
this.cosmetic = cosmetic;
|
|
||||||
this.isCancelled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCancelled() {
|
|
||||||
return isCancelled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setCancelled(boolean cancel) {
|
|
||||||
isCancelled = cancel;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancel = false;
|
||||||
|
private Cosmetic cosmetic;
|
||||||
|
|
||||||
@Override
|
public PlayerCosmeticEquipEvent(@NotNull CosmeticUser who, @NotNull Cosmetic cosmetic) {
|
||||||
public HandlerList getHandlers() {
|
super(who);
|
||||||
return handlers;
|
this.cosmetic = cosmetic;
|
||||||
}
|
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CosmeticUser getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the {@link Cosmetic} being equipped in this event
|
||||||
|
*
|
||||||
|
* @return The {@link Cosmetic} which is being equipped in this event
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
public Cosmetic getCosmetic() {
|
public Cosmetic getCosmetic() {
|
||||||
return cosmetic;
|
return cosmetic;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCosmetic() {
|
/**
|
||||||
|
* Sets the {@link Cosmetic} that the player will equip
|
||||||
|
*
|
||||||
|
* @param cosmetic The {@link Cosmetic} that the player will equip
|
||||||
|
*/
|
||||||
|
public void setCosmetic(@NotNull Cosmetic cosmetic) {
|
||||||
this.cosmetic = cosmetic;
|
this.cosmetic = cosmetic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the cancellation state of this event
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Canceling this event will prevent the player from equipping the cosmetic
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param cancel true if you wish to cancel this event
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.cancel = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.api;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a cosmetic user related event
|
||||||
|
*/
|
||||||
|
public abstract class PlayerCosmeticEvent extends Event {
|
||||||
|
protected CosmeticUser user;
|
||||||
|
|
||||||
|
public PlayerCosmeticEvent(@NotNull final CosmeticUser who) {
|
||||||
|
user = who;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the user involved in this event
|
||||||
|
*
|
||||||
|
* @return User who is involved in this event
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public final CosmeticUser getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,41 +2,59 @@ package com.hibiscusmc.hmccosmetics.api;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class PlayerCosmeticHideEvent extends Event implements Cancellable {
|
/**
|
||||||
|
* Called when cosmetics are hidden from a player
|
||||||
|
*/
|
||||||
|
public class PlayerCosmeticHideEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancel = false;
|
||||||
|
private final CosmeticUser.HiddenReason reason;
|
||||||
|
|
||||||
private CosmeticUser user;
|
public PlayerCosmeticHideEvent(@NotNull CosmeticUser who, @NotNull CosmeticUser.HiddenReason reason) {
|
||||||
private boolean isCancelled;
|
super(who);
|
||||||
|
this.reason = reason;
|
||||||
|
}
|
||||||
|
|
||||||
public PlayerCosmeticHideEvent(CosmeticUser user) {
|
/**
|
||||||
this.user = user;
|
* Gets the {@link CosmeticUser.HiddenReason} as to why cosmetics are being hidden for the player
|
||||||
this.isCancelled = false;
|
*
|
||||||
|
* @return The {@link CosmeticUser.HiddenReason} why cosmetics are being hidden for the player
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public CosmeticUser.HiddenReason getReason() {
|
||||||
|
return reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return isCancelled;
|
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) {
|
||||||
isCancelled = cancel;
|
this.cancel = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NotNull
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CosmeticUser getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,34 +3,52 @@ package com.hibiscusmc.hmccosmetics.api;
|
|||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class PlayerCosmeticRemoveEvent extends Event implements Cancellable {
|
/**
|
||||||
|
* Called when a player removes a cosmetic
|
||||||
|
*/
|
||||||
|
public class PlayerCosmeticRemoveEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancel = false;
|
||||||
|
private final Cosmetic cosmetic;
|
||||||
|
|
||||||
private CosmeticUser user;
|
public PlayerCosmeticRemoveEvent(@NotNull CosmeticUser who, @NotNull Cosmetic cosmetic) {
|
||||||
private Cosmetic cosmetic;
|
super(who);
|
||||||
private boolean isCancelled;
|
|
||||||
|
|
||||||
public PlayerCosmeticRemoveEvent(CosmeticUser user, Cosmetic cosmetic) {
|
|
||||||
this.user = user;
|
|
||||||
this.cosmetic = cosmetic;
|
this.cosmetic = cosmetic;
|
||||||
this.isCancelled = false;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the {@link Cosmetic} being removed in this event
|
||||||
|
*
|
||||||
|
* @return The {@link Cosmetic} which is being removed in this event
|
||||||
|
*/
|
||||||
|
public Cosmetic getCosmetic() {
|
||||||
|
return cosmetic;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return isCancelled;
|
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) {
|
||||||
isCancelled = cancel;
|
this.cancel = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NotNull
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
@@ -38,12 +56,4 @@ public class PlayerCosmeticRemoveEvent extends Event implements Cancellable {
|
|||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CosmeticUser getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Cosmetic getCosmetic() {
|
|
||||||
return cosmetic;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -2,41 +2,47 @@ package com.hibiscusmc.hmccosmetics.api;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class PlayerCosmeticShowEvent extends Event implements Cancellable {
|
/**
|
||||||
|
* Called when cosmetics are shown from a player
|
||||||
|
*/
|
||||||
|
public class PlayerCosmeticShowEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancel = false;
|
||||||
|
|
||||||
private CosmeticUser user;
|
public PlayerCosmeticShowEvent(@NotNull CosmeticUser who) {
|
||||||
private boolean isCancelled;
|
super(who);
|
||||||
|
|
||||||
public PlayerCosmeticShowEvent(CosmeticUser user) {
|
|
||||||
this.user = user;
|
|
||||||
this.isCancelled = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return isCancelled;
|
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) {
|
||||||
isCancelled = cancel;
|
this.cancel = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NotNull
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CosmeticUser getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.api;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.api;
|
||||||
|
|
||||||
|
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,28 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.api;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a menu is closed by a player
|
||||||
|
*/
|
||||||
|
public class PlayerMenuCloseEvent extends PlayerMenuEvent {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
public PlayerMenuCloseEvent(@NotNull CosmeticUser who, @NotNull Menu menu) {
|
||||||
|
super(who, menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.api;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a menu related event
|
||||||
|
*/
|
||||||
|
public abstract class PlayerMenuEvent extends PlayerCosmeticEvent {
|
||||||
|
protected Menu menu;
|
||||||
|
|
||||||
|
public PlayerMenuEvent(@NotNull CosmeticUser who, @NotNull Menu menu) {
|
||||||
|
super(who);
|
||||||
|
this.menu = menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the {@link Menu} involved with this event
|
||||||
|
*
|
||||||
|
* @return The {@link Menu} which is involved with the event
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public final Menu getMenu() {
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,47 +3,47 @@ package com.hibiscusmc.hmccosmetics.api;
|
|||||||
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.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class PlayerMenuOpenEvent extends Event implements Cancellable {
|
/**
|
||||||
|
* Called when a menu is opened by a player
|
||||||
|
*/
|
||||||
|
public class PlayerMenuOpenEvent extends PlayerMenuEvent implements Cancellable {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancel = false;
|
||||||
|
|
||||||
private CosmeticUser user;
|
public PlayerMenuOpenEvent(@NotNull CosmeticUser who, @NotNull Menu menu) {
|
||||||
private Menu menu;
|
super(who, menu);
|
||||||
private boolean isCancelled;
|
|
||||||
|
|
||||||
public PlayerMenuOpenEvent(CosmeticUser user, Menu menu) {
|
|
||||||
this.user = user;
|
|
||||||
this.menu = menu;
|
|
||||||
this.isCancelled = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return isCancelled;
|
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) {
|
||||||
isCancelled = cancel;
|
this.cancel = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NotNull
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CosmeticUser getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Menu getMenu() {
|
|
||||||
return menu;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,41 +2,47 @@ package com.hibiscusmc.hmccosmetics.api;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class PlayerWardrobeEnterEvent extends Event implements Cancellable {
|
/**
|
||||||
|
* Called when a player enters their wardrobe
|
||||||
|
*/
|
||||||
|
public class PlayerWardrobeEnterEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancel = false;
|
||||||
|
|
||||||
private CosmeticUser user;
|
public PlayerWardrobeEnterEvent(@NotNull CosmeticUser who) {
|
||||||
private boolean isCancelled;
|
super(who);
|
||||||
|
|
||||||
public PlayerWardrobeEnterEvent(CosmeticUser user) {
|
|
||||||
this.user = user;
|
|
||||||
this.isCancelled = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return isCancelled;
|
return cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the cancellation state of this event
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Canceling this event will prevent the player from entering their wardrobe
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param cancel true if you wish to cancel this event
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(boolean cancel) {
|
public void setCancelled(boolean cancel) {
|
||||||
isCancelled = cancel;
|
this.cancel = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NotNull
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CosmeticUser getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,41 +2,47 @@ package com.hibiscusmc.hmccosmetics.api;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class PlayerWardrobeLeaveEvent extends Event implements Cancellable {
|
/**
|
||||||
|
* Called when a player leaves their wardrobe
|
||||||
|
*/
|
||||||
|
public class PlayerWardrobeLeaveEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancel = false;
|
||||||
|
|
||||||
private CosmeticUser user;
|
public PlayerWardrobeLeaveEvent(@NotNull CosmeticUser who) {
|
||||||
private boolean isCancelled;
|
super(who);
|
||||||
|
|
||||||
public PlayerWardrobeLeaveEvent(CosmeticUser user) {
|
|
||||||
this.user = user;
|
|
||||||
this.isCancelled = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return isCancelled;
|
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) {
|
||||||
isCancelled = cancel;
|
this.cancel = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NotNull
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CosmeticUser getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ 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.gui.Menu;
|
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||||
@@ -14,6 +15,7 @@ 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.ServerUtils;
|
||||||
|
import com.ticxo.playeranimator.api.PlayerAnimator;
|
||||||
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.apache.commons.lang3.EnumUtils;
|
||||||
@@ -26,13 +28,17 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class CosmeticCommand implements CommandExecutor {
|
public class CosmeticCommand implements CommandExecutor {
|
||||||
|
|
||||||
// cosmetics apply cosmetics playerName
|
// cosmetics apply cosmetics playerName
|
||||||
// 0 1 2
|
// 0 1 2
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String @NotNull [] args) {
|
||||||
|
boolean silent = false;
|
||||||
|
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
if (!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
// Console
|
// Console
|
||||||
@@ -44,7 +50,7 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CosmeticUser user = CosmeticUsers.getUser(((Player) sender).getUniqueId());
|
CosmeticUser user = CosmeticUsers.getUser(((Player) sender).getUniqueId());
|
||||||
Menu menu = Menus.getMenu(Settings.getDefaultMenu());
|
Menu menu = Menus.getDefaultMenu();
|
||||||
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
MessagesUtil.sendMessage(sender, "invalid-player");
|
MessagesUtil.sendMessage(sender, "invalid-player");
|
||||||
@@ -62,49 +68,64 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
Player player = sender instanceof Player ? (Player) sender : null;
|
Player player = sender instanceof Player ? (Player) sender : null;
|
||||||
|
|
||||||
String firstArgs = args[0].toLowerCase();
|
String firstArgs = args[0].toLowerCase();
|
||||||
|
|
||||||
|
if (sender.hasPermission("HMCCosmetics.cmd.silent") || sender.isOp()) {
|
||||||
|
for (String singleArg : args) {
|
||||||
|
if (singleArg.equalsIgnoreCase("-s")) {
|
||||||
|
silent = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (firstArgs) {
|
switch (firstArgs) {
|
||||||
case ("reload") -> {
|
case ("reload") -> {
|
||||||
if (!sender.hasPermission("HMCCosmetics.cmd.reload") || !sender.isOp()) {
|
if (!sender.hasPermission("HMCCosmetics.cmd.reload") && !sender.isOp()) {
|
||||||
MessagesUtil.sendMessage(sender, "no-permission");
|
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
HMCCosmeticsPlugin.setup();
|
HMCCosmeticsPlugin.setup();
|
||||||
MessagesUtil.sendMessage(sender, "reloaded");
|
if (!silent) MessagesUtil.sendMessage(sender, "reloaded");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case ("apply") -> {
|
case ("apply") -> {
|
||||||
if (!sender.hasPermission("hmccosmetics.cmd.apply")) {
|
if (!sender.hasPermission("hmccosmetics.cmd.apply")) {
|
||||||
MessagesUtil.sendMessage(sender, "no-permission");
|
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Cosmetic cosmetic;
|
Cosmetic cosmetic;
|
||||||
|
Color color = null;
|
||||||
|
|
||||||
if (sender instanceof Player) player = ((Player) sender).getPlayer();
|
if (sender instanceof Player) player = ((Player) sender).getPlayer();
|
||||||
if (sender.hasPermission("hmccosmetics.cmd.apply.other")) {
|
if (sender.hasPermission("hmccosmetics.cmd.apply.other")) {
|
||||||
if (args.length >= 3) player = Bukkit.getPlayer(args[2]);
|
if (args.length >= 3) player = Bukkit.getPlayer(args[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sender.hasPermission("hmccosmetics.cmd.apply.color")) {
|
||||||
|
if (args.length >= 4) color = ServerUtils.hex2Rgb(args[3]);
|
||||||
|
}
|
||||||
|
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
MessagesUtil.sendMessage(player, "not-enough-args");
|
if (!silent) MessagesUtil.sendMessage(player, "not-enough-args");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
cosmetic = Cosmetics.getCosmetic(args[1]);
|
cosmetic = Cosmetics.getCosmetic(args[1]);
|
||||||
|
|
||||||
if (cosmetic == null) {
|
if (cosmetic == null) {
|
||||||
MessagesUtil.sendMessage(sender, "invalid-cosmetic");
|
if (!silent) MessagesUtil.sendMessage(sender, "invalid-cosmetic");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
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);
|
||||||
|
|
||||||
if (!user.canEquipCosmetic(cosmetic)) {
|
if (!user.canEquipCosmetic(cosmetic)) {
|
||||||
MessagesUtil.sendMessage(player, "no-cosmetic-permission");
|
if (!silent) MessagesUtil.sendMessage(player, "no-cosmetic-permission");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,56 +134,62 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
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().name())));
|
||||||
|
|
||||||
MessagesUtil.sendMessage(player, "equip-cosmetic", placeholders);
|
if (!silent) MessagesUtil.sendMessage(player, "equip-cosmetic", placeholders);
|
||||||
|
|
||||||
user.addPlayerCosmetic(cosmetic);
|
user.addPlayerCosmetic(cosmetic, color);
|
||||||
user.updateCosmetic(cosmetic.getSlot());
|
user.updateCosmetic(cosmetic.getSlot());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case ("unapply") -> {
|
case ("unapply") -> {
|
||||||
if (!sender.hasPermission("hmccosmetics.cmd.unapply")) {
|
if (!sender.hasPermission("hmccosmetics.cmd.unapply")) {
|
||||||
MessagesUtil.sendMessage(sender, "no-permission");
|
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
MessagesUtil.sendMessage(player, "not-enough-args");
|
if (!silent) MessagesUtil.sendMessage(player, "not-enough-args");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CosmeticSlot cosmeticSlot = null;
|
|
||||||
|
|
||||||
if (sender instanceof Player) player = ((Player) sender).getPlayer();
|
if (sender instanceof Player) player = ((Player) sender).getPlayer();
|
||||||
if (sender.hasPermission("hmccosmetics.cmd.unapply.other")) {
|
if (sender.hasPermission("hmccosmetics.cmd.unapply.other")) {
|
||||||
if (args.length >= 3) player = Bukkit.getPlayer(args[2]);
|
if (args.length >= 3) player = Bukkit.getPlayer(args[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!EnumUtils.isValidEnum(CosmeticSlot.class, args[1].toUpperCase())) {
|
|
||||||
MessagesUtil.sendMessage(sender, "invalid-slot");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
cosmeticSlot = CosmeticSlot.valueOf(args[1].toUpperCase());
|
|
||||||
|
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
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);
|
||||||
|
|
||||||
if (user.getCosmetic(cosmeticSlot) == null) {
|
Set<CosmeticSlot> cosmeticSlots;
|
||||||
MessagesUtil.sendMessage(sender, "no-cosmetic-slot");
|
|
||||||
return true;
|
if (args[1].equalsIgnoreCase("all")) {
|
||||||
|
cosmeticSlots = user.getSlotsWithCosmetics();
|
||||||
|
} else {
|
||||||
|
if (!EnumUtils.isValidEnum(CosmeticSlot.class, args[1].toUpperCase())) {
|
||||||
|
if (!silent) MessagesUtil.sendMessage(sender, "invalid-slot");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
cosmeticSlots = Set.of(CosmeticSlot.valueOf(args[1].toUpperCase()));
|
||||||
}
|
}
|
||||||
|
|
||||||
TagResolver placeholders =
|
for (CosmeticSlot cosmeticSlot : cosmeticSlots) {
|
||||||
TagResolver.resolver(Placeholder.parsed("cosmetic", user.getCosmetic(cosmeticSlot).getId()),
|
if (user.getCosmetic(cosmeticSlot) == null) {
|
||||||
TagResolver.resolver(Placeholder.parsed("player", player.getName())),
|
if (!silent) MessagesUtil.sendMessage(sender, "no-cosmetic-slot");
|
||||||
TagResolver.resolver(Placeholder.parsed("cosmeticslot", cosmeticSlot.name())));
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
MessagesUtil.sendMessage(player, "unequip-cosmetic", placeholders);
|
TagResolver placeholders =
|
||||||
|
TagResolver.resolver(Placeholder.parsed("cosmetic", user.getCosmetic(cosmeticSlot).getId()),
|
||||||
|
TagResolver.resolver(Placeholder.parsed("player", player.getName())),
|
||||||
|
TagResolver.resolver(Placeholder.parsed("cosmeticslot", cosmeticSlot.name())));
|
||||||
|
|
||||||
user.removeCosmeticSlot(cosmeticSlot);
|
if (!silent) MessagesUtil.sendMessage(player, "unequip-cosmetic", placeholders);
|
||||||
user.updateCosmetic(cosmeticSlot);
|
|
||||||
|
user.removeCosmeticSlot(cosmeticSlot);
|
||||||
|
user.updateCosmetic(cosmeticSlot);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case ("wardrobe") -> {
|
case ("wardrobe") -> {
|
||||||
@@ -172,12 +199,12 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!sender.hasPermission("hmccosmetics.cmd.wardrobe")) {
|
if (!sender.hasPermission("hmccosmetics.cmd.wardrobe")) {
|
||||||
MessagesUtil.sendMessage(sender, "no-permission");
|
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
MessagesUtil.sendMessage(sender, "invalid-player");
|
if (!silent) MessagesUtil.sendMessage(sender, "invalid-player");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,7 +217,7 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
case ("menu") -> {
|
case ("menu") -> {
|
||||||
if (args.length == 1) return true;
|
if (args.length == 1) return true;
|
||||||
if (!sender.hasPermission("hmccosmetics.cmd.menu")) {
|
if (!sender.hasPermission("hmccosmetics.cmd.menu")) {
|
||||||
MessagesUtil.sendMessage(sender, "no-permission");
|
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Menu menu = Menus.getMenu(args[1]);
|
Menu menu = Menus.getMenu(args[1]);
|
||||||
@@ -202,12 +229,12 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
MessagesUtil.sendMessage(sender, "invalid-player");
|
if (!silent) MessagesUtil.sendMessage(sender, "invalid-player");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (menu == null) {
|
if (menu == null) {
|
||||||
MessagesUtil.sendMessage(sender, "invalid-menu");
|
if (!silent) MessagesUtil.sendMessage(sender, "invalid-menu");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,7 +246,7 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
OfflinePlayer selectedPlayer = Bukkit.getOfflinePlayer(args[1]);
|
OfflinePlayer selectedPlayer = Bukkit.getOfflinePlayer(args[1]);
|
||||||
if (selectedPlayer == null) return true;
|
if (selectedPlayer == null) return true;
|
||||||
if (!sender.hasPermission("hmccosmetics.cmd.dataclear") && !sender.isOp()) {
|
if (!sender.hasPermission("hmccosmetics.cmd.dataclear") && !sender.isOp()) {
|
||||||
MessagesUtil.sendMessage(sender, "no-permission");
|
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Database.clearData(selectedPlayer.getUniqueId());
|
Database.clearData(selectedPlayer.getUniqueId());
|
||||||
@@ -231,30 +258,30 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
if (user == null) return true;
|
if (user == null) return true;
|
||||||
if (!sender.hasPermission("hmccosmetics.cmd.dye") && !sender.isOp()) {
|
if (!sender.hasPermission("hmccosmetics.cmd.dye") && !sender.isOp()) {
|
||||||
MessagesUtil.sendMessage(sender, "no-permission");
|
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
MessagesUtil.sendMessage(player, "not-enough-args");
|
if (!silent) MessagesUtil.sendMessage(player, "not-enough-args");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!EnumUtils.isValidEnum(CosmeticSlot.class, args[1])) {
|
if (!EnumUtils.isValidEnum(CosmeticSlot.class, args[1])) {
|
||||||
MessagesUtil.sendMessage(player, "invalid-slot");
|
if (!silent) MessagesUtil.sendMessage(player, "invalid-slot");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
CosmeticSlot slot = CosmeticSlot.valueOf(args[1]);
|
CosmeticSlot slot = CosmeticSlot.valueOf(args[1]);
|
||||||
Cosmetic cosmetic = user.getCosmetic(slot);
|
Cosmetic cosmetic = user.getCosmetic(slot);
|
||||||
|
|
||||||
if (args.length >= 3) {
|
if (args.length >= 3) {
|
||||||
if (!args[2].contains("#") || args[2].isEmpty()) {
|
if (args[2].isEmpty()) {
|
||||||
MessagesUtil.sendMessage(player, "invalid-color");
|
if (!silent) MessagesUtil.sendMessage(player, "invalid-color");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Color color = ServerUtils.hex2Rgb(args[2]);
|
Color color = ServerUtils.hex2Rgb(args[2]);
|
||||||
if (color == null) {
|
if (color == null) {
|
||||||
MessagesUtil.sendMessage(player, "invalid-color");
|
if (!silent) MessagesUtil.sendMessage(player, "invalid-color");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
user.addPlayerCosmetic(cosmetic, color); // #FFFFFF
|
user.addPlayerCosmetic(cosmetic, color); // #FFFFFF
|
||||||
@@ -264,32 +291,32 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
case ("setlocation") -> {
|
case ("setlocation") -> {
|
||||||
if (!sender.hasPermission("hmccosmetics.cmd.setlocation")) {
|
if (!sender.hasPermission("hmccosmetics.cmd.setlocation")) {
|
||||||
MessagesUtil.sendMessage(sender, "no-permission");
|
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player == null) return true;
|
if (player == null) return true;
|
||||||
|
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
MessagesUtil.sendMessage(player, "not-enough-args");
|
if (!silent) MessagesUtil.sendMessage(player, "not-enough-args");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[1].equalsIgnoreCase("wardrobelocation")) {
|
if (args[1].equalsIgnoreCase("wardrobelocation")) {
|
||||||
WardrobeSettings.setWardrobeLocation(player.getLocation());
|
WardrobeSettings.setWardrobeLocation(player.getLocation());
|
||||||
MessagesUtil.sendMessage(player, "set-wardrobe-location");
|
if (!silent) MessagesUtil.sendMessage(player, "set-wardrobe-location");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[1].equalsIgnoreCase("viewerlocation")) {
|
if (args[1].equalsIgnoreCase("viewerlocation")) {
|
||||||
WardrobeSettings.setViewerLocation(player.getLocation());
|
WardrobeSettings.setViewerLocation(player.getLocation());
|
||||||
MessagesUtil.sendMessage(player, "set-wardrobe-viewing");
|
if (!silent) MessagesUtil.sendMessage(player, "set-wardrobe-viewing");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[1].equalsIgnoreCase("leavelocation")) {
|
if (args[1].equalsIgnoreCase("leavelocation")) {
|
||||||
WardrobeSettings.setLeaveLocation(player.getLocation());
|
WardrobeSettings.setLeaveLocation(player.getLocation());
|
||||||
MessagesUtil.sendMessage(player, "set-wardrobe-leaving");
|
if (!silent) MessagesUtil.sendMessage(player, "set-wardrobe-leaving");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -298,14 +325,14 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
if (user == null) return true;
|
if (user == null) return true;
|
||||||
if (!sender.hasPermission("HMCCosmetic.cmd.dump") && !sender.isOp()) {
|
if (!sender.hasPermission("HMCCosmetic.cmd.dump") && !sender.isOp()) {
|
||||||
MessagesUtil.sendMessage(sender, "no-permission");
|
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
player.sendMessage("Passengers -> " + player.getPassengers());
|
player.sendMessage("Passengers -> " + player.getPassengers());
|
||||||
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
||||||
player.sendMessage("Backpack Location -> " + user.getBackpackEntity().getLocation());
|
player.sendMessage("Backpack Location -> " + user.getUserBackpackManager().getArmorStand().getLocation());
|
||||||
}
|
}
|
||||||
player.sendMessage("Cosmetics -> " + user.getCosmetic());
|
player.sendMessage("Cosmetics -> " + user.getCosmetics());
|
||||||
player.sendMessage("EntityId -> " + player.getEntityId());
|
player.sendMessage("EntityId -> " + player.getEntityId());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -316,19 +343,18 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!sender.hasPermission("hmccosmetics.cmd.hide")) {
|
if (!sender.hasPermission("hmccosmetics.cmd.hide")) {
|
||||||
MessagesUtil.sendMessage(sender, "no-permission");
|
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
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);
|
||||||
|
if (!silent) MessagesUtil.sendMessage(sender, "hide-cosmetic");
|
||||||
MessagesUtil.sendMessage(sender, "hide-cosmetic");
|
user.hideCosmetics(CosmeticUser.HiddenReason.COMMAND);
|
||||||
user.hideCosmetics();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case ("show") -> {
|
case ("show") -> {
|
||||||
@@ -338,36 +364,89 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!sender.hasPermission("hmccosmetics.cmd.show")) {
|
if (!sender.hasPermission("hmccosmetics.cmd.show")) {
|
||||||
MessagesUtil.sendMessage(sender, "no-permission");
|
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
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);
|
||||||
|
|
||||||
MessagesUtil.sendMessage(sender, "show-cosmetic");
|
if (!silent) MessagesUtil.sendMessage(sender, "show-cosmetic");
|
||||||
user.showCosmetics();
|
user.showCosmetics();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case ("debug") -> {
|
case ("debug") -> {
|
||||||
if (!sender.hasPermission("hmccosmetics.cmd.debug")) {
|
if (!sender.hasPermission("hmccosmetics.cmd.debug")) {
|
||||||
MessagesUtil.sendMessage(sender, "no-permission");
|
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.getDebugMode()) {
|
if (Settings.getDebugMode()) {
|
||||||
Settings.setDebugMode(false);
|
Settings.setDebugMode(false);
|
||||||
MessagesUtil.sendMessage(sender, "debug-disabled");
|
if (!silent) MessagesUtil.sendMessage(sender, "debug-disabled");
|
||||||
} else {
|
} else {
|
||||||
Settings.setDebugMode(true);
|
Settings.setDebugMode(true);
|
||||||
MessagesUtil.sendMessage(sender, "debug-enabled");
|
if (!silent) MessagesUtil.sendMessage(sender, "debug-enabled");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case ("emote") -> {
|
||||||
|
if (!sender.hasPermission("hmccosmetics.cmd.emote")) {
|
||||||
|
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (sender.hasPermission("hmccosmetics.cmd.emote.other")) {
|
||||||
|
if (args.length >= 2) player = Bukkit.getPlayer(args[1]);
|
||||||
|
}
|
||||||
|
if (player == null) {
|
||||||
|
if (!silent) MessagesUtil.sendMessage(sender, "invalid-player");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
|
if (!user.hasCosmeticInSlot(CosmeticSlot.EMOTE)) {
|
||||||
|
if (!silent) MessagesUtil.sendMessage(sender, "emote-none");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
CosmeticEmoteType cosmeticEmoteType = (CosmeticEmoteType) user.getCosmetic(CosmeticSlot.EMOTE);
|
||||||
|
cosmeticEmoteType.run(user);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ("playemote") -> {
|
||||||
|
// /cosmetic playEmote <emoteId> [playerName]
|
||||||
|
if (!sender.hasPermission("hmccosmetics.cmd.playemote")) {
|
||||||
|
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length < 2) {
|
||||||
|
if (!silent) MessagesUtil.sendMessage(player, "not-enough-args");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length >= 2) {
|
||||||
|
if (!PlayerAnimator.api.getAnimationManager().getRegistry().keySet().contains(args[1])) {
|
||||||
|
MessagesUtil.sendDebugMessages("Did not contain " + args[1]);
|
||||||
|
if (!silent) MessagesUtil.sendMessage(sender, "emote-invalid");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sender.hasPermission("hmccosmetics.cmd.playemote.other")) {
|
||||||
|
if (args.length >= 3) player = Bukkit.getPlayer(args[2]);
|
||||||
|
}
|
||||||
|
if (player == null) {
|
||||||
|
if (!silent) MessagesUtil.sendMessage(sender, "invalid-player");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
|
user.getUserEmoteManager().playEmote(args[1]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ 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 com.ticxo.playeranimator.api.PlayerAnimator;
|
||||||
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;
|
||||||
@@ -23,9 +24,9 @@ import java.util.List;
|
|||||||
public class CosmeticCommandTabComplete implements TabCompleter {
|
public class CosmeticCommandTabComplete implements TabCompleter {
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String @NotNull [] args) {
|
||||||
List<String> completions = new ArrayList<>();
|
List<String> completions = new ArrayList<>();
|
||||||
List<String> finalCompletitons = new ArrayList<>();
|
List<String> finalCompletions = new ArrayList<>();
|
||||||
|
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
if (hasPermission(sender, "hmccosmetics.cmd.apply")) completions.add("apply");
|
if (hasPermission(sender, "hmccosmetics.cmd.apply")) completions.add("apply");
|
||||||
@@ -39,8 +40,10 @@ 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.playemote")) completions.add("playemote");
|
||||||
|
|
||||||
StringUtil.copyPartialMatches(args[0], completions, finalCompletitons);
|
StringUtil.copyPartialMatches(args[0], completions, finalCompletions);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(sender instanceof Player)) return completions;
|
if (!(sender instanceof Player)) return completions;
|
||||||
@@ -53,16 +56,17 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
|||||||
completions.addAll(applyCommandComplete(user, args));
|
completions.addAll(applyCommandComplete(user, args));
|
||||||
}
|
}
|
||||||
case "unapply" -> {
|
case "unapply" -> {
|
||||||
for (Cosmetic cosmetic : user.getCosmetic()) {
|
for (Cosmetic cosmetic : user.getCosmetics()) {
|
||||||
completions.add(cosmetic.getSlot().toString().toUpperCase());
|
completions.add(cosmetic.getSlot().toString().toUpperCase());
|
||||||
}
|
}
|
||||||
|
completions.add("ALL");
|
||||||
}
|
}
|
||||||
case "menu" -> {
|
case "menu" -> {
|
||||||
for (Menu menu : Menus.getMenu()) {
|
for (Menu menu : Menus.getMenu()) {
|
||||||
if (menu.canOpen(user.getPlayer())) completions.add(menu.getId());
|
if (menu.canOpen(user.getPlayer())) completions.add(menu.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "dataclear", "wardrobe", "hide", "show" -> {
|
case "dataclear", "wardrobe", "hide", "show", "emote" -> {
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
completions.add(player.getName());
|
completions.add(player.getName());
|
||||||
}
|
}
|
||||||
@@ -77,8 +81,11 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
|||||||
completions.add("viewerlocation");
|
completions.add("viewerlocation");
|
||||||
completions.add("leavelocation");
|
completions.add("leavelocation");
|
||||||
}
|
}
|
||||||
|
case "playemote" -> {
|
||||||
|
completions.addAll(PlayerAnimator.api.getAnimationManager().getRegistry().keySet());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
StringUtil.copyPartialMatches(args[1], completions, finalCompletitons);
|
StringUtil.copyPartialMatches(args[1], completions, finalCompletions);
|
||||||
}
|
}
|
||||||
if (args.length == 3) {
|
if (args.length == 3) {
|
||||||
String subcommand = args[0].toLowerCase();
|
String subcommand = args[0].toLowerCase();
|
||||||
@@ -86,21 +93,31 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
|||||||
case "dye" -> {
|
case "dye" -> {
|
||||||
completions.add("#FFFFFF");
|
completions.add("#FFFFFF");
|
||||||
}
|
}
|
||||||
case "menu", "apply", "unapply" -> {
|
case "menu", "apply", "unapply", "playemote" -> {
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
completions.add(player.getName());
|
completions.add(player.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
StringUtil.copyPartialMatches(args[2], completions, finalCompletitons);
|
StringUtil.copyPartialMatches(args[2], completions, finalCompletions);
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(finalCompletitons);
|
if (args.length == 4) {
|
||||||
return finalCompletitons;
|
String subcommand = args[0].toLowerCase();
|
||||||
|
switch (subcommand) {
|
||||||
|
case "apply" -> {
|
||||||
|
completions.add("#FFFFFF");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
StringUtil.copyPartialMatches(args[3], completions, finalCompletions);
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(finalCompletions);
|
||||||
|
return finalCompletions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<String> applyCommandComplete(CosmeticUser user, String[] args) {
|
@NotNull
|
||||||
|
private static List<String> applyCommandComplete(CosmeticUser user, String @NotNull [] args) {
|
||||||
List<String> completitions = new ArrayList<>();
|
List<String> completitions = new ArrayList<>();
|
||||||
|
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
@@ -119,7 +136,7 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
|||||||
return completitions;
|
return completitions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasPermission(CommandSender sender, String permission) {
|
private boolean hasPermission(@NotNull CommandSender sender, String permission) {
|
||||||
if (sender.isOp()) return true;
|
if (sender.isOp()) return true;
|
||||||
if (sender.hasPermission(permission)) return true;
|
if (sender.hasPermission(permission)) return true;
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -2,10 +2,13 @@ package com.hibiscusmc.hmccosmetics.config;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
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 org.spongepowered.configurate.ConfigurationNode;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class Settings {
|
public class Settings {
|
||||||
|
|
||||||
// General Settings
|
// General Settings
|
||||||
@@ -25,12 +28,32 @@ public class Settings {
|
|||||||
private static final String PARTICLE_COUNT = "particle-count";
|
private static final String PARTICLE_COUNT = "particle-count";
|
||||||
private static final String DYE_MENU_PATH = "dye-menu";
|
private static final String DYE_MENU_PATH = "dye-menu";
|
||||||
private static final String DYE_MENU_NAME = "title";
|
private static final String DYE_MENU_NAME = "title";
|
||||||
|
private static final String DYE_MENU_INPUT_SLOT = "input-slot";
|
||||||
|
private static final String DYE_MENU_OUTPUT_SLOT = "output-slot";
|
||||||
private static final String DEBUG_ENABLE_PETH = "debug-mode";
|
private static final String DEBUG_ENABLE_PETH = "debug-mode";
|
||||||
private static final String TICK_PERIOD_PATH = "tick-period";
|
private static final String TICK_PERIOD_PATH = "tick-period";
|
||||||
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 EMOTE_DISTANCE_PATH = "emote-distance";
|
||||||
|
private static final String HOOK_SETTING_PATH = "hook-settings";
|
||||||
|
private static final String HOOK_ITEMADDER_PATH = "itemsadder";
|
||||||
|
private static final String HOOK_RELOAD_CHANGE_PATH = "reload-on-change";
|
||||||
|
private static final String HOOK_WORLDGUARD_PATH = "worldguard";
|
||||||
|
private static final String HOOK_WG_MOVE_CHECK_PATH = "player-move-check";
|
||||||
|
private static final String HOOK_WG_MOVE_CHECK_PATH_LEGACY = "player_move_check";
|
||||||
|
private static final String COSMETIC_EMOTE_CHECK_PATH = "emote-block-check";
|
||||||
|
private static final String COSMETIC_EMOTE_DAMAGE_PATH = "emote-damage-leave";
|
||||||
|
private static final String COSMETIC_EMOTE_INVINCIBLE_PATH = "emote-invincible";
|
||||||
|
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 String defaultMenu;
|
private static String defaultMenu;
|
||||||
private static String dyeMenuName;
|
private static String dyeMenuName;
|
||||||
|
private static int dyeMenuInputSlot;
|
||||||
|
private static int dyeMenuOutputSlot;
|
||||||
private static int configVersion;
|
private static int configVersion;
|
||||||
private static boolean requireEmptyHelmet;
|
private static boolean requireEmptyHelmet;
|
||||||
private static boolean requireEmptyOffHand;
|
private static boolean requireEmptyOffHand;
|
||||||
@@ -39,9 +62,21 @@ public class Settings {
|
|||||||
private static boolean requireEmptyBoots;
|
private static boolean requireEmptyBoots;
|
||||||
private static boolean debugMode;
|
private static boolean debugMode;
|
||||||
private static boolean unapplyOnDeath;
|
private static boolean unapplyOnDeath;
|
||||||
|
private static boolean forcePermissionJoin;
|
||||||
|
private static boolean itemsAdderChangeReload;
|
||||||
|
private static boolean worldGuardMoveCheck;
|
||||||
|
private static boolean cosmeticEmoteBlockCheck;
|
||||||
|
private static boolean addHelmetEnchants;
|
||||||
|
private static boolean addChestplateEnchants;
|
||||||
|
private static boolean addLeggingEnchants;
|
||||||
|
private static boolean addBootsEnchants;
|
||||||
|
private static boolean emoteDamageLeave;
|
||||||
|
private static boolean emoteInvincible;
|
||||||
|
private static boolean destroyLooseCosmetics;
|
||||||
private static int lookDownPitch;
|
private static int lookDownPitch;
|
||||||
private static int viewDistance;
|
private static int viewDistance;
|
||||||
private static int tickPeriod;
|
private static int tickPeriod;
|
||||||
|
private static double emoteDistance;
|
||||||
private static Vector balloonOffset;
|
private static Vector balloonOffset;
|
||||||
|
|
||||||
public static void load(ConfigurationNode source) {
|
public static void load(ConfigurationNode source) {
|
||||||
@@ -67,6 +102,16 @@ public class Settings {
|
|||||||
requireEmptyPants = cosmeticSettings.node(REQUIRE_EMPTY_PANTS_PATH).getBoolean();
|
requireEmptyPants = cosmeticSettings.node(REQUIRE_EMPTY_PANTS_PATH).getBoolean();
|
||||||
requireEmptyBoots = cosmeticSettings.node(REQUIRE_EMPTY_BOOTS_PATH).getBoolean();
|
requireEmptyBoots = cosmeticSettings.node(REQUIRE_EMPTY_BOOTS_PATH).getBoolean();
|
||||||
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);
|
||||||
|
emoteDistance = cosmeticSettings.node(EMOTE_DISTANCE_PATH).getDouble(-3);
|
||||||
|
cosmeticEmoteBlockCheck = cosmeticSettings.node(COSMETIC_EMOTE_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);
|
||||||
|
addHelmetEnchants = cosmeticSettings.node(COSMETIC_ADD_ENCHANTS_HELMET_PATH).getBoolean(false);
|
||||||
|
addChestplateEnchants = cosmeticSettings.node(COSMETIC_ADD_ENCHANTS_CHESTPLATE_PATH).getBoolean(false);
|
||||||
|
addLeggingEnchants = cosmeticSettings.node(COSMETIC_ADD_ENCHANTS_LEGGINGS_PATH).getBoolean(false);
|
||||||
|
addBootsEnchants = cosmeticSettings.node(COSMETIC_ADD_ENCHANTS_BOOTS_PATH).getBoolean(false);
|
||||||
|
|
||||||
tickPeriod = cosmeticSettings.node(TICK_PERIOD_PATH).getInt(-1);
|
tickPeriod = cosmeticSettings.node(TICK_PERIOD_PATH).getInt(-1);
|
||||||
lookDownPitch = cosmeticSettings.node(LOOK_DOWN_PITCH_PATH).getInt();
|
lookDownPitch = cosmeticSettings.node(LOOK_DOWN_PITCH_PATH).getInt();
|
||||||
@@ -79,6 +124,20 @@ public class Settings {
|
|||||||
ConfigurationNode dyeMenuSettings = source.node(DYE_MENU_PATH);
|
ConfigurationNode dyeMenuSettings = source.node(DYE_MENU_PATH);
|
||||||
|
|
||||||
dyeMenuName = dyeMenuSettings.node(DYE_MENU_NAME).getString("Dye Menu");
|
dyeMenuName = dyeMenuSettings.node(DYE_MENU_NAME).getString("Dye Menu");
|
||||||
|
dyeMenuInputSlot = dyeMenuSettings.node(DYE_MENU_INPUT_SLOT).getInt(19);
|
||||||
|
dyeMenuOutputSlot = dyeMenuSettings.node(DYE_MENU_OUTPUT_SLOT).getInt(25);
|
||||||
|
|
||||||
|
ConfigurationNode hookSettings = source.node(HOOK_SETTING_PATH);
|
||||||
|
ConfigurationNode itemsAdderSettings = hookSettings.node(HOOK_ITEMADDER_PATH);
|
||||||
|
itemsAdderChangeReload = itemsAdderSettings.node(HOOK_RELOAD_CHANGE_PATH).getBoolean(false);
|
||||||
|
|
||||||
|
ConfigurationNode worldGuardSettings = hookSettings.node(HOOK_WORLDGUARD_PATH);
|
||||||
|
worldGuardMoveCheck = worldGuardSettings.node(HOOK_WG_MOVE_CHECK_PATH).getBoolean(true);
|
||||||
|
// I messed up in release 2.2.6 and forgot to change player_move_check to player-move-check.
|
||||||
|
if (!worldGuardSettings.node(HOOK_WG_MOVE_CHECK_PATH_LEGACY).virtual()) {
|
||||||
|
MessagesUtil.sendDebugMessages("There is a deprecated way of using WG hook setting. Change player_move_check to player-move-check in your configuration to prevent issues in the future. ", Level.WARNING);
|
||||||
|
worldGuardMoveCheck = worldGuardSettings.node(HOOK_WG_MOVE_CHECK_PATH_LEGACY).getBoolean(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Vector loadVector(final ConfigurationNode config) {
|
private static Vector loadVector(final ConfigurationNode config) {
|
||||||
@@ -172,10 +231,15 @@ public class Settings {
|
|||||||
public static String getDyeMenuName() {
|
public static String getDyeMenuName() {
|
||||||
return dyeMenuName;
|
return dyeMenuName;
|
||||||
}
|
}
|
||||||
|
public static int getDyeMenuInputSlot() { return dyeMenuInputSlot; }
|
||||||
|
public static int getDyeMenuOutputSlot() { return dyeMenuOutputSlot; }
|
||||||
|
|
||||||
public static boolean isDebugEnabled() {
|
public static boolean isDebugEnabled() {
|
||||||
return debugMode;
|
return debugMode;
|
||||||
}
|
}
|
||||||
|
public static boolean getItemsAdderReloadChange() {
|
||||||
|
return itemsAdderChangeReload;
|
||||||
|
}
|
||||||
|
|
||||||
public static int getTickPeriod() {
|
public static int getTickPeriod() {
|
||||||
return tickPeriod;
|
return tickPeriod;
|
||||||
@@ -183,10 +247,58 @@ public class Settings {
|
|||||||
public static boolean getUnapplyOnDeath() {
|
public static boolean getUnapplyOnDeath() {
|
||||||
return unapplyOnDeath;
|
return unapplyOnDeath;
|
||||||
}
|
}
|
||||||
|
public static boolean getForcePermissionJoin() {
|
||||||
|
return forcePermissionJoin;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean getDebugMode() {
|
public static boolean getDebugMode() {
|
||||||
return debugMode;
|
return debugMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static double getEmoteDistance() {
|
||||||
|
return emoteDistance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean getCosmeticEmoteBlockCheck() {
|
||||||
|
return cosmeticEmoteBlockCheck;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isEmoteDamageLeave() {
|
||||||
|
return emoteDamageLeave;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isEmoteInvincible() {
|
||||||
|
return emoteInvincible;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isWorldGuardMoveCheckEnabled() {
|
||||||
|
return worldGuardMoveCheck;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isDestroyLooseCosmetics() {
|
||||||
|
return destroyLooseCosmetics;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean getShouldAddEnchants(EquipmentSlot slot) {
|
||||||
|
switch (slot) {
|
||||||
|
case HEAD -> {
|
||||||
|
return addHelmetEnchants;
|
||||||
|
}
|
||||||
|
case CHEST -> {
|
||||||
|
return addChestplateEnchants;
|
||||||
|
}
|
||||||
|
case LEGS -> {
|
||||||
|
return addLeggingEnchants;
|
||||||
|
}
|
||||||
|
case FEET -> {
|
||||||
|
return addBootsEnchants;
|
||||||
|
}
|
||||||
|
default -> {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void setDebugMode(boolean newSetting) {
|
public static void setDebugMode(boolean newSetting) {
|
||||||
debugMode = newSetting;
|
debugMode = newSetting;
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
|||||||
import com.hibiscusmc.hmccosmetics.util.misc.Utils;
|
import com.hibiscusmc.hmccosmetics.util.misc.Utils;
|
||||||
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.Location;
|
import org.bukkit.Location;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
import org.spongepowered.configurate.serialize.SerializationException;
|
import org.spongepowered.configurate.serialize.SerializationException;
|
||||||
@@ -29,6 +30,9 @@ public class WardrobeSettings {
|
|||||||
private static final String LEAVE_LOCATION_PATH = "leave-location";
|
private static final String LEAVE_LOCATION_PATH = "leave-location";
|
||||||
private static final String EQUIP_PUMPKIN_WARDROBE = "equip-pumpkin";
|
private static final String EQUIP_PUMPKIN_WARDROBE = "equip-pumpkin";
|
||||||
private static final String RETURN_LAST_LOCATION = "return-last-location";
|
private static final String RETURN_LAST_LOCATION = "return-last-location";
|
||||||
|
private static final String GAMEMODE_OPTIONS_PATH = "gamemode-options";
|
||||||
|
private static final String FORCE_EXIT_GAMEMODE_PATH = "exit-gamemode-enabled";
|
||||||
|
private static final String EXIT_GAMEMODE_PATH = "exit-gamemode";
|
||||||
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";
|
||||||
@@ -57,6 +61,8 @@ public class WardrobeSettings {
|
|||||||
private static boolean equipPumpkin;
|
private static boolean equipPumpkin;
|
||||||
private static boolean returnLastLocation;
|
private static boolean returnLastLocation;
|
||||||
private static boolean enabledBossbar;
|
private static boolean enabledBossbar;
|
||||||
|
private static boolean forceExitGamemode;
|
||||||
|
private static GameMode exitGamemode;
|
||||||
private static Location wardrobeLocation;
|
private static Location wardrobeLocation;
|
||||||
private static Location viewerLocation;
|
private static Location viewerLocation;
|
||||||
private static Location leaveLocation;
|
private static Location leaveLocation;
|
||||||
@@ -85,6 +91,10 @@ 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);
|
||||||
|
|
||||||
|
ConfigurationNode gamemodeNode = source.node(GAMEMODE_OPTIONS_PATH);
|
||||||
|
forceExitGamemode = gamemodeNode.node(FORCE_EXIT_GAMEMODE_PATH).getBoolean(false);
|
||||||
|
exitGamemode = GameMode.valueOf(gamemodeNode.node(EXIT_GAMEMODE_PATH).getString("SURVIVAL"));
|
||||||
|
|
||||||
ConfigurationNode bossBarNode = source.node(BOSSBAR_PATH);
|
ConfigurationNode bossBarNode = source.node(BOSSBAR_PATH);
|
||||||
enabledBossbar = bossBarNode.node(BOSSBAR_ENABLE_PATH).getBoolean(false);
|
enabledBossbar = bossBarNode.node(BOSSBAR_ENABLE_PATH).getBoolean(false);
|
||||||
bossbarProgress = bossBarNode.node(BOSSBAR_PROGRESS_PATH).getFloat(1.0f);
|
bossbarProgress = bossBarNode.node(BOSSBAR_PROGRESS_PATH).getFloat(1.0f);
|
||||||
@@ -182,7 +192,7 @@ public class WardrobeSettings {
|
|||||||
|
|
||||||
public static boolean inDistanceOfStatic(final Location location) {
|
public static boolean inDistanceOfStatic(final Location location) {
|
||||||
if (wardrobeLocation == null) return false;
|
if (wardrobeLocation == null) return false;
|
||||||
if (staticRadius == -1) return false;
|
if (staticRadius == -1) return true;
|
||||||
if (!wardrobeLocation.getWorld().equals(location.getWorld())) return false;
|
if (!wardrobeLocation.getWorld().equals(location.getWorld())) return false;
|
||||||
return wardrobeLocation.distanceSquared(location) <= staticRadius * staticRadius;
|
return wardrobeLocation.distanceSquared(location) <= staticRadius * staticRadius;
|
||||||
}
|
}
|
||||||
@@ -227,6 +237,14 @@ public class WardrobeSettings {
|
|||||||
return transitionFadeOut;
|
return transitionFadeOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isForceExitGamemode() {
|
||||||
|
return forceExitGamemode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GameMode getExitGamemode() {
|
||||||
|
return exitGamemode;
|
||||||
|
}
|
||||||
|
|
||||||
public static void setWardrobeLocation(Location newLocation) {
|
public static void setWardrobeLocation(Location newLocation) {
|
||||||
wardrobeLocation = newLocation;
|
wardrobeLocation = newLocation;
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.config.serializer;
|
package com.hibiscusmc.hmccosmetics.config.serializer;
|
||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
import com.hibiscusmc.hmccosmetics.hooks.items.ItemHooks;
|
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
|
||||||
import com.hibiscusmc.hmccosmetics.util.builder.ColorBuilder;
|
import com.hibiscusmc.hmccosmetics.util.builder.ColorBuilder;
|
||||||
import com.hibiscusmc.hmccosmetics.util.misc.StringUtils;
|
import com.hibiscusmc.hmccosmetics.util.misc.StringUtils;
|
||||||
import com.hibiscusmc.hmccosmetics.util.misc.Utils;
|
import com.hibiscusmc.hmccosmetics.util.misc.Utils;
|
||||||
|
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.Material;
|
import org.bukkit.Material;
|
||||||
@@ -71,7 +74,7 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
|
|||||||
|
|
||||||
String material = materialNode.getString();
|
String material = materialNode.getString();
|
||||||
|
|
||||||
ItemStack item = ItemHooks.getItem(material);
|
ItemStack item = Hooks.getItem(material);
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
HMCCosmeticsPlugin.getInstance().getLogger().severe("Invalid Material -> " + material);
|
HMCCosmeticsPlugin.getInstance().getLogger().severe("Invalid Material -> " + material);
|
||||||
return new ItemStack(Material.AIR);
|
return new ItemStack(Material.AIR);
|
||||||
@@ -80,15 +83,16 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
|
|||||||
|
|
||||||
ItemMeta itemMeta = item.getItemMeta();
|
ItemMeta itemMeta = item.getItemMeta();
|
||||||
if (itemMeta == null) return item;
|
if (itemMeta == null) return item;
|
||||||
if (!nameNode.virtual()) itemMeta.setDisplayName(StringUtils.parseStringToString(Utils.replaceIfNull(nameNode.getString(), "")));
|
if (!nameNode.virtual())
|
||||||
|
itemMeta.setDisplayName(StringUtils.parseStringToString(Utils.replaceIfNull(nameNode.getString(), "")));
|
||||||
if (!unbreakableNode.virtual()) itemMeta.setUnbreakable(unbreakableNode.getBoolean());
|
if (!unbreakableNode.virtual()) itemMeta.setUnbreakable(unbreakableNode.getBoolean());
|
||||||
if (!glowingNode.virtual()) {
|
if (!glowingNode.virtual()) {
|
||||||
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||||
itemMeta.addEnchant(Enchantment.LUCK, 1, true);
|
itemMeta.addEnchant(Enchantment.LUCK, 1, true);
|
||||||
}
|
}
|
||||||
if (!loreNode.virtual()) itemMeta.setLore(Utils.replaceIfNull(loreNode.getList(String.class),
|
if (!loreNode.virtual()) itemMeta.setLore(Utils.replaceIfNull(loreNode.getList(String.class),
|
||||||
new ArrayList<String>()).
|
new ArrayList<String>()).
|
||||||
stream().map(StringUtils::parseStringToString).collect(Collectors.toList()));
|
stream().map(StringUtils::parseStringToString).collect(Collectors.toList()));
|
||||||
if (!modelDataNode.virtual()) itemMeta.setCustomModelData(modelDataNode.getInt());
|
if (!modelDataNode.virtual()) itemMeta.setCustomModelData(modelDataNode.getInt());
|
||||||
|
|
||||||
if (!nbtNode.virtual()) {
|
if (!nbtNode.virtual()) {
|
||||||
@@ -104,11 +108,16 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!itemFlagsNode.virtual()) {
|
try {
|
||||||
for (ConfigurationNode flagNode : itemFlagsNode.childrenMap().values()) {
|
if (!itemFlagsNode.virtual()) {
|
||||||
if (ItemFlag.valueOf(flagNode.key().toString()) == null) continue;
|
for (String itemFlag : itemFlagsNode.getList(String.class)) {
|
||||||
itemMeta.addItemFlags(ItemFlag.valueOf(flagNode.key().toString()));
|
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) {
|
if (item.getType() == Material.PLAYER_HEAD) {
|
||||||
@@ -126,17 +135,17 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
|
|||||||
|
|
||||||
if (!colorNode.virtual()) {
|
if (!colorNode.virtual()) {
|
||||||
if (ColorBuilder.canBeColored(item.getType())) {
|
if (ColorBuilder.canBeColored(item.getType())) {
|
||||||
itemMeta = ColorBuilder.color(itemMeta, Color.fromRGB(redNode.getInt(0), greenNode.getInt(0), blueNode.getInt(0)));
|
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")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NamespacedKey key = new NamespacedKey(HMCCosmeticsPlugin.getInstance(), source.key().toString());
|
|
||||||
itemMeta.getPersistentDataContainer().set(key, PersistentDataType.STRING, source.key().toString());
|
|
||||||
|
|
||||||
item.setItemMeta(itemMeta);
|
item.setItemMeta(itemMeta);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(final Type type, @Nullable final ItemStack obj, final ConfigurationNode node) throws SerializationException {
|
public void serialize(final Type type, @Nullable final ItemStack obj, final ConfigurationNode node) throws SerializationException {
|
||||||
|
|
||||||
|
|||||||
@@ -5,13 +5,14 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
|||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
import org.spongepowered.configurate.serialize.SerializationException;
|
import org.spongepowered.configurate.serialize.SerializationException;
|
||||||
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class Cosmetic {
|
public abstract class Cosmetic {
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
private String permission;
|
private String permission;
|
||||||
@@ -19,8 +20,9 @@ public class Cosmetic {
|
|||||||
private CosmeticSlot slot;
|
private CosmeticSlot slot;
|
||||||
private boolean dyable;
|
private boolean dyable;
|
||||||
|
|
||||||
protected Cosmetic(String id, ConfigurationNode config) {
|
protected Cosmetic(String id, @NotNull ConfigurationNode config) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
if (!config.node("permission").virtual()) {
|
if (!config.node("permission").virtual()) {
|
||||||
this.permission = config.node("permission").getString();
|
this.permission = config.node("permission").getString();
|
||||||
} else {
|
} else {
|
||||||
@@ -30,20 +32,20 @@ public class Cosmetic {
|
|||||||
if (!config.node("item").virtual()) this.item = generateItemStack(config.node("item"));
|
if (!config.node("item").virtual()) this.item = generateItemStack(config.node("item"));
|
||||||
|
|
||||||
MessagesUtil.sendDebugMessages("Slot: " + config.node("slot").getString());
|
MessagesUtil.sendDebugMessages("Slot: " + config.node("slot").getString());
|
||||||
setSlot(CosmeticSlot.valueOf(config.node("slot").getString()));
|
|
||||||
|
|
||||||
|
setSlot(CosmeticSlot.valueOf(config.node("slot").getString()));
|
||||||
setDyable(config.node("dyeable").getBoolean(false));
|
setDyable(config.node("dyeable").getBoolean(false));
|
||||||
|
|
||||||
MessagesUtil.sendDebugMessages("Dyeable " + dyable);
|
MessagesUtil.sendDebugMessages("Dyeable " + dyable);
|
||||||
|
|
||||||
Cosmetics.addCosmetic(this);
|
Cosmetics.addCosmetic(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return this.id;
|
return this.id;
|
||||||
}
|
}
|
||||||
public String getPermission() {
|
|
||||||
return this.permission;
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CosmeticSlot getSlot() {
|
public CosmeticSlot getSlot() {
|
||||||
@@ -53,17 +55,17 @@ public class Cosmetic {
|
|||||||
public void setSlot(CosmeticSlot slot) {
|
public void setSlot(CosmeticSlot slot) {
|
||||||
this.slot = slot;
|
this.slot = slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPermission() {
|
||||||
|
return this.permission;
|
||||||
|
}
|
||||||
|
|
||||||
public void setPermission(String permission) {
|
public void setPermission(String permission) {
|
||||||
this.permission = permission;
|
this.permission = permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean requiresPermission() {
|
public boolean requiresPermission() {
|
||||||
if (permission == null) return false;
|
return permission != null;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDyable(boolean dyable) {
|
public void setDyable(boolean dyable) {
|
||||||
@@ -74,10 +76,7 @@ public class Cosmetic {
|
|||||||
return this.dyable;
|
return this.dyable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract void update(CosmeticUser user);
|
||||||
public void update(CosmeticUser user) {
|
|
||||||
// Override
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public ItemStack getItem() {
|
public ItemStack getItem() {
|
||||||
|
|||||||
@@ -8,5 +8,6 @@ public enum CosmeticSlot {
|
|||||||
MAINHAND,
|
MAINHAND,
|
||||||
OFFHAND,
|
OFFHAND,
|
||||||
BACKPACK,
|
BACKPACK,
|
||||||
BALLOON
|
BALLOON,
|
||||||
|
EMOTE
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,13 @@ 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.cosmetic.types.CosmeticArmorType;
|
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
|
import com.hibiscusmc.hmccosmetics.cosmetic.types.*;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticMainhandType;
|
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
|
import org.apache.commons.lang3.EnumUtils;
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||||
import org.spongepowered.configurate.ConfigurateException;
|
import org.spongepowered.configurate.ConfigurateException;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
@@ -14,10 +16,11 @@ import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class Cosmetics {
|
public class Cosmetics {
|
||||||
|
|
||||||
private static HashBiMap<String, Cosmetic> COSMETICS = HashBiMap.create();
|
private static final HashBiMap<String, Cosmetic> COSMETICS = HashBiMap.create();
|
||||||
|
|
||||||
public static void addCosmetic(Cosmetic cosmetic) {
|
public static void addCosmetic(Cosmetic cosmetic) {
|
||||||
COSMETICS.put(cosmetic.getId(), cosmetic);
|
COSMETICS.put(cosmetic.getId(), cosmetic);
|
||||||
@@ -31,14 +34,19 @@ public class Cosmetics {
|
|||||||
COSMETICS.remove(cosmetic);
|
COSMETICS.remove(cosmetic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static Cosmetic getCosmetic(String id) {
|
public static Cosmetic getCosmetic(String id) {
|
||||||
return COSMETICS.get(id);
|
return COSMETICS.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Contract(pure = true)
|
||||||
|
@NotNull
|
||||||
public static Set<Cosmetic> values() {
|
public static Set<Cosmetic> values() {
|
||||||
return COSMETICS.values();
|
return COSMETICS.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Contract(pure = true)
|
||||||
|
@NotNull
|
||||||
public static Set<String> keys() {
|
public static Set<String> keys() {
|
||||||
return COSMETICS.keySet();
|
return COSMETICS.keySet();
|
||||||
}
|
}
|
||||||
@@ -76,25 +84,30 @@ public class Cosmetics {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setupCosmetics(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();
|
try {
|
||||||
MessagesUtil.sendDebugMessages("Attempting to add " + id);
|
String id = cosmeticConfig.key().toString();
|
||||||
switch (CosmeticSlot.valueOf(cosmeticConfig.node("slot").getString())) {
|
MessagesUtil.sendDebugMessages("Attempting to add " + id);
|
||||||
case BALLOON -> {
|
ConfigurationNode slotNode = cosmeticConfig.node("slot");
|
||||||
new CosmeticBalloonType(id, cosmeticConfig);
|
if (slotNode.virtual()) {
|
||||||
|
MessagesUtil.sendDebugMessages("Unable to create " + id + " because there is no slot defined!", Level.WARNING);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
case BACKPACK -> {
|
if (!EnumUtils.isValidEnum(CosmeticSlot.class, slotNode.getString())) {
|
||||||
new CosmeticBackpackType(id, cosmeticConfig);
|
MessagesUtil.sendDebugMessages("Unable to create " + id + " because " + slotNode.getString() + " is not a valid slot!", Level.WARNING);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
case MAINHAND -> {
|
switch (CosmeticSlot.valueOf(cosmeticConfig.node("slot").getString())) {
|
||||||
new CosmeticMainhandType(id, cosmeticConfig);
|
case BALLOON -> new CosmeticBalloonType(id, cosmeticConfig);
|
||||||
}
|
case BACKPACK -> new CosmeticBackpackType(id, cosmeticConfig);
|
||||||
default -> {
|
case MAINHAND -> new CosmeticMainhandType(id, cosmeticConfig);
|
||||||
new CosmeticArmorType(id, cosmeticConfig);
|
case EMOTE -> new CosmeticEmoteType(id, cosmeticConfig);
|
||||||
|
default -> new CosmeticArmorType(id, cosmeticConfig);
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (Settings.isDebugEnabled()) e.printStackTrace();
|
||||||
}
|
}
|
||||||
//new Cosmetic(id, cosmeticConfig);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,22 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.cosmetic.types;
|
package com.hibiscusmc.hmccosmetics.cosmetic.types;
|
||||||
|
|
||||||
|
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.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
|
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
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.jetbrains.annotations.NotNull;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
|
|
||||||
public class CosmeticArmorType extends Cosmetic {
|
public class CosmeticArmorType extends Cosmetic {
|
||||||
|
|
||||||
private EquipmentSlot equipSlot;
|
private final EquipmentSlot equipSlot;
|
||||||
|
|
||||||
public CosmeticArmorType(String id, ConfigurationNode config) {
|
public CosmeticArmorType(String id, ConfigurationNode config) {
|
||||||
super(id, config);
|
super(id, config);
|
||||||
@@ -20,18 +25,23 @@ public class CosmeticArmorType extends Cosmetic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(CosmeticUser user) {
|
public void update(@NotNull CosmeticUser user) {
|
||||||
Player player = Bukkit.getPlayer(user.getUniqueId());
|
Player player = Bukkit.getPlayer(user.getUniqueId());
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
|
ItemStack cosmeticItem = user.getUserCosmeticItem(this);
|
||||||
if (equipSlot.equals(EquipmentSlot.OFF_HAND)) {
|
if (equipSlot.equals(EquipmentSlot.OFF_HAND)) {
|
||||||
if (!player.getInventory().getItemInOffHand().getType().isAir()) return;
|
if (!player.getInventory().getItemInOffHand().getType().isAir()) return;
|
||||||
}
|
}
|
||||||
PacketManager.equipmentSlotUpdate(player, getSlot(), PacketManager.getViewers(player.getLocation()));
|
ItemStack equippedItem = player.getInventory().getItem(equipSlot);
|
||||||
|
if (Settings.getShouldAddEnchants(equipSlot)) {
|
||||||
|
cosmeticItem.addUnsafeEnchantments(equippedItem.getEnchantments());
|
||||||
|
}
|
||||||
|
|
||||||
|
NMSHandlers.getHandler().equipmentSlotUpdate(player.getEntityId(), equipSlot, cosmeticItem, PacketManager.getViewers(player.getLocation()));
|
||||||
|
//PacketManager.equipmentSlotUpdate(player, getSlot(), PacketManager.getViewers(player.getLocation())); Old method
|
||||||
}
|
}
|
||||||
|
|
||||||
public EquipmentSlot getEquipSlot() {
|
public EquipmentSlot getEquipSlot() {
|
||||||
return this.equipSlot;
|
return this.equipSlot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,36 +2,65 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.manager.UserBackpackManager;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||||
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.jetbrains.annotations.NotNull;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class CosmeticBackpackType extends Cosmetic {
|
public class CosmeticBackpackType extends Cosmetic {
|
||||||
|
|
||||||
ConfigurationNode config;
|
private final String modelName;
|
||||||
|
private UserBackpackManager.BackpackType backpackType;
|
||||||
|
|
||||||
public CosmeticBackpackType(String id, ConfigurationNode config) {
|
public CosmeticBackpackType(String id, ConfigurationNode config) {
|
||||||
super(id, config);
|
super(id, config);
|
||||||
|
|
||||||
this.config = config;
|
modelName = config.node("model").getString();
|
||||||
|
backpackType = UserBackpackManager.BackpackType.valueOf(config.node("type").getString("NORMAL").toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(CosmeticUser user) {
|
public void update(@NotNull CosmeticUser user) {
|
||||||
Player player = Bukkit.getPlayer(user.getUniqueId());
|
Player player = Bukkit.getPlayer(user.getUniqueId());
|
||||||
Location loc = player.getLocation().clone();
|
if (player == null) return;
|
||||||
|
|
||||||
if (loc.getWorld() != user.getBackpackEntity().getWorld()) {
|
Location loc = player.getLocation().clone().add(0, 2, 0);
|
||||||
user.getBackpackEntity().teleport(loc);
|
|
||||||
|
if (user.isInWardrobe() || !user.isBackpackSpawned()) return;
|
||||||
|
if (!user.getUserBackpackManager().getArmorStand().isValid()) {
|
||||||
|
MessagesUtil.sendDebugMessages("Invalid Backpack detected! Respawning backpack, report this on the discord if this happens often!", Level.WARNING);
|
||||||
|
user.respawnBackpack();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (loc.getWorld() != user.getUserBackpackManager().getArmorStand().getWorld()) {
|
||||||
|
user.getUserBackpackManager().getArmorStand().teleport(loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
user.getBackpackEntity().teleport(loc);
|
user.getUserBackpackManager().getArmorStand().teleport(loc);
|
||||||
|
|
||||||
PacketManager.sendRidingPacket(player.getEntityId(), user.getBackpackEntity().getEntityId(), loc);
|
if (user.getUserBackpackManager().getBackpackType().equals(UserBackpackManager.BackpackType.FIRST_PERSON)) {
|
||||||
|
user.getUserBackpackManager().teleportEffectEntity(loc);
|
||||||
|
PacketManager.sendRidingPacket(player.getEntityId(), user.getUserBackpackManager().getAreaEffectEntityId(), loc);
|
||||||
|
PacketManager.sendRidingPacket(user.getUserBackpackManager().getAreaEffectEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), loc);
|
||||||
|
} else {
|
||||||
|
PacketManager.sendRidingPacket(player.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), loc);
|
||||||
|
}
|
||||||
|
|
||||||
user.getBackpackEntity().setRotation(loc.getYaw(), loc.getPitch());
|
user.getUserBackpackManager().getArmorStand().setRotation(loc.getYaw(), loc.getPitch());
|
||||||
user.showBackpack();
|
user.getUserBackpackManager().showBackpack();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getModelName() {
|
||||||
|
return modelName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserBackpackManager.BackpackType getBackpackType() {
|
||||||
|
return backpackType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,56 +2,94 @@ 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.entities.BalloonEntity;
|
import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||||
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.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
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 {
|
||||||
|
|
||||||
private String modelName;
|
private final String modelName;
|
||||||
|
private List<String> dyableParts;
|
||||||
|
private boolean showLead;
|
||||||
|
|
||||||
public CosmeticBalloonType(String id, ConfigurationNode config) {
|
public CosmeticBalloonType(String id, ConfigurationNode config) {
|
||||||
super(id, config);
|
super(id, config);
|
||||||
|
|
||||||
String modelId = config.node("model").getString();
|
String modelId = config.node("model").getString();
|
||||||
|
|
||||||
|
showLead = config.node("show-lead").getBoolean(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!config.node("dyable-parts").virtual()) {
|
||||||
|
dyableParts = config.node("dyable-parts").getList(String.class);
|
||||||
|
}
|
||||||
|
} catch (SerializationException e) {
|
||||||
|
// Seriously?
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
this.modelName = modelId;
|
this.modelName = modelId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(CosmeticUser user) {
|
public void update(@NotNull CosmeticUser user) {
|
||||||
Player player = Bukkit.getPlayer(user.getUniqueId());
|
Player player = Bukkit.getPlayer(user.getUniqueId());
|
||||||
Location currentLocation = user.getBalloonEntity().getLocation().clone();
|
UserBalloonManager userBalloonManager = user.getBalloonManager();
|
||||||
Location newLocation = player.getLocation().clone().add(Settings.getBalloonOffset()).clone();
|
|
||||||
if (player == null) return;
|
if (player == null || userBalloonManager == null) return;
|
||||||
if (user.isInWardrobe()) return;
|
if (user.isInWardrobe()) return;
|
||||||
|
|
||||||
|
if (!userBalloonManager.getModelEntity().isValid()) {
|
||||||
|
user.respawnBalloon();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Location newLocation = player.getLocation();
|
||||||
|
Location currentLocation = user.getBalloonManager().getLocation();
|
||||||
|
newLocation = newLocation.clone().add(Settings.getBalloonOffset());
|
||||||
|
|
||||||
List<Player> viewer = PacketManager.getViewers(player.getLocation());
|
List<Player> viewer = PacketManager.getViewers(player.getLocation());
|
||||||
viewer.add(player);
|
viewer.add(player);
|
||||||
|
|
||||||
BalloonEntity balloonEntity = user.getBalloonEntity();
|
if (player.getLocation().getWorld() != userBalloonManager.getLocation().getWorld()) {
|
||||||
|
userBalloonManager.getModelEntity().teleport(newLocation);
|
||||||
if (player.getLocation().getWorld() != balloonEntity.getLocation().getWorld()) {
|
PacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer);
|
||||||
balloonEntity.getModelEntity().teleport(newLocation);
|
|
||||||
PacketManager.sendTeleportPacket(balloonEntity.getPufferfishBalloonId(), newLocation, false, viewer);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector velocity = newLocation.clone().toVector().subtract(currentLocation.clone().toVector());
|
Vector velocity = newLocation.toVector().subtract(currentLocation.toVector());
|
||||||
balloonEntity.setLocation(newLocation);
|
userBalloonManager.setVelocity(velocity.multiply(1.1));
|
||||||
balloonEntity.setVelocity(velocity);
|
userBalloonManager.setLocation(newLocation);
|
||||||
|
|
||||||
PacketManager.sendTeleportPacket(balloonEntity.getPufferfishBalloonId(), newLocation, false, viewer);
|
PacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer);
|
||||||
if (!user.getHidden()) PacketManager.sendLeashPacket(balloonEntity.getPufferfishBalloonId(), player.getEntityId(), viewer);
|
if (!user.getHidden() && showLead) PacketManager.sendLeashPacket(userBalloonManager.getPufferfishBalloonId(), player.getEntityId(), viewer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getModelName() {
|
public String getModelName() {
|
||||||
return this.modelName;
|
return this.modelName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getDyableParts() {
|
||||||
|
return dyableParts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDyablePart(String name) {
|
||||||
|
// If player does not define parts, dye whole model
|
||||||
|
if (dyableParts == null) return true;
|
||||||
|
if (dyableParts.isEmpty()) return true;
|
||||||
|
return dyableParts.contains(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isShowLead() {
|
||||||
|
return showLead;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
public CosmeticEmoteType(String id, ConfigurationNode config) {
|
||||||
|
super(id, config);
|
||||||
|
|
||||||
|
animationId = config.node("animation").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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
|||||||
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
|
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
|
||||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
|
|
||||||
public class CosmeticMainhandType extends Cosmetic {
|
public class CosmeticMainhandType extends Cosmetic {
|
||||||
@@ -14,10 +15,9 @@ public class CosmeticMainhandType extends Cosmetic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(CosmeticUser user) {
|
public void update(@NotNull CosmeticUser user) {
|
||||||
Player player = user.getPlayer();
|
Player player = user.getPlayer();
|
||||||
|
|
||||||
PacketManager.equipmentSlotUpdate(player.getEntityId(), user, getSlot(), PlayerUtils.getNearbyPlayers(player));
|
PacketManager.equipmentSlotUpdate(player.getEntityId(), user, getSlot(), PlayerUtils.getNearbyPlayers(player));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,23 +16,23 @@ public class Database {
|
|||||||
|
|
||||||
private static Data data;
|
private static Data data;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
private static InternalData INTERNAL_DATA = new InternalData();
|
private static InternalData INTERNAL_DATA = new InternalData();
|
||||||
private static MySQLData MYSQL_DATA = new MySQLData();
|
|
||||||
private static SQLiteData SQLITE_DATA = new SQLiteData();
|
private static final MySQLData MYSQL_DATA = new MySQLData();
|
||||||
|
private static final SQLiteData SQLITE_DATA = new SQLiteData();
|
||||||
|
|
||||||
public Database() {
|
public Database() {
|
||||||
String databaseType = DatabaseSettings.getDatabaseType();
|
String databaseType = DatabaseSettings.getDatabaseType();
|
||||||
data = INTERNAL_DATA; // default
|
data = SQLITE_DATA; // default
|
||||||
if (databaseType.equalsIgnoreCase("INTERNAL")) {
|
|
||||||
data = INTERNAL_DATA;
|
|
||||||
}
|
|
||||||
if (databaseType.equalsIgnoreCase("MySQL")) {
|
if (databaseType.equalsIgnoreCase("MySQL")) {
|
||||||
data = MYSQL_DATA;
|
data = MYSQL_DATA;
|
||||||
}
|
}
|
||||||
|
/* SQLite is the default database. Might change in the future, so keep code here in case.
|
||||||
if (databaseType.equalsIgnoreCase("sqlite")) {
|
if (databaseType.equalsIgnoreCase("sqlite")) {
|
||||||
data = SQLITE_DATA;
|
data = SQLITE_DATA;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
MessagesUtil.sendDebugMessages("Database is " + data);
|
MessagesUtil.sendDebugMessages("Database is " + data);
|
||||||
|
|
||||||
setup();
|
setup();
|
||||||
|
|||||||
@@ -1,40 +1,43 @@
|
|||||||
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.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.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.bukkit.Bukkit;
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class Data {
|
public abstract class Data {
|
||||||
|
|
||||||
public void setup() {
|
public abstract void setup();
|
||||||
// Override
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save(CosmeticUser user) {
|
public abstract void save(CosmeticUser user);
|
||||||
// Override
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public CosmeticUser get(UUID uniqueId) {
|
public abstract CosmeticUser get(UUID uniqueId);
|
||||||
// Override
|
|
||||||
return null;
|
public abstract void clear(UUID uniqueId);
|
||||||
}
|
|
||||||
|
|
||||||
public void clear(UUID uniqueId) {
|
|
||||||
// Override
|
|
||||||
}
|
|
||||||
// BACKPACK=colorfulbackpack&RRGGBB,HELMET=niftyhat,BALLOON=colorfulballoon,CHESTPLATE=niftychestplate
|
// BACKPACK=colorfulbackpack&RRGGBB,HELMET=niftyhat,BALLOON=colorfulballoon,CHESTPLATE=niftychestplate
|
||||||
public String steralizeData(CosmeticUser user) {
|
@NotNull
|
||||||
|
public final String serializeData(@NotNull CosmeticUser user) {
|
||||||
String data = "";
|
String data = "";
|
||||||
for (Cosmetic cosmetic : user.getCosmetic()) {
|
if (user.getHidden()) {
|
||||||
|
if (shouldHiddenSave(user.getHiddenReason())) {
|
||||||
|
data = "HIDDEN=" + user.getHiddenReason();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Cosmetic cosmetic : user.getCosmetics()) {
|
||||||
Color color = user.getCosmeticColor(cosmetic.getSlot());
|
Color color = user.getCosmeticColor(cosmetic.getSlot());
|
||||||
String input = cosmetic.getSlot() + "=" + cosmetic.getId();
|
String input = cosmetic.getSlot() + "=" + cosmetic.getId();
|
||||||
if (color != null) input = input + "&" + color.asRGB();
|
if (color != null) input = input + "&" + color.asRGB();
|
||||||
@@ -47,8 +50,10 @@ public class Data {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<CosmeticSlot, Map<Cosmetic, Color>> desteralizedata(String raw) {
|
@NotNull
|
||||||
|
public final Map<CosmeticSlot, Map<Cosmetic, Color>> deserializeData(CosmeticUser user, @NotNull String raw) {
|
||||||
Map<CosmeticSlot, Map<Cosmetic, Color>> cosmetics = new HashMap<>();
|
Map<CosmeticSlot, Map<Cosmetic, Color>> cosmetics = new HashMap<>();
|
||||||
|
boolean checkPermission = Settings.getForcePermissionJoin();
|
||||||
|
|
||||||
String[] rawData = raw.split(",");
|
String[] rawData = raw.split(",");
|
||||||
for (String a : rawData) {
|
for (String a : rawData) {
|
||||||
@@ -57,16 +62,33 @@ public class Data {
|
|||||||
CosmeticSlot slot = null;
|
CosmeticSlot slot = null;
|
||||||
Cosmetic cosmetic = null;
|
Cosmetic cosmetic = null;
|
||||||
MessagesUtil.sendDebugMessages("First split (suppose slot) " + splitData[0]);
|
MessagesUtil.sendDebugMessages("First split (suppose slot) " + splitData[0]);
|
||||||
|
if (splitData[0].equalsIgnoreCase("HIDDEN")) {
|
||||||
|
if (EnumUtils.isValidEnum(CosmeticUser.HiddenReason.class, splitData[1])) {
|
||||||
|
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||||
|
user.hideCosmetics(CosmeticUser.HiddenReason.valueOf(splitData[1]));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (CosmeticSlot.valueOf(splitData[0]) != null) slot = CosmeticSlot.valueOf(splitData[0]);
|
if (CosmeticSlot.valueOf(splitData[0]) != null) slot = CosmeticSlot.valueOf(splitData[0]);
|
||||||
|
|
||||||
if (splitData[1].contains("&")) {
|
if (splitData[1].contains("&")) {
|
||||||
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 (cosmetic.requiresPermission() && checkPermission) {
|
||||||
|
if (!user.getPlayer().hasPermission(cosmetic.getPermission())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
cosmetics.put(slot, Map.of(cosmetic, Color.fromRGB(Integer.parseInt(colorSplitData[1]))));
|
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 (cosmetic.requiresPermission() && checkPermission) {
|
||||||
|
if (!user.getPlayer().hasPermission(cosmetic.getPermission())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
HashMap<Cosmetic, Color> cosmeticColorHashMap = new HashMap<>();
|
HashMap<Cosmetic, Color> cosmeticColorHashMap = new HashMap<>();
|
||||||
cosmeticColorHashMap.put(cosmetic, null);
|
cosmeticColorHashMap.put(cosmetic, null);
|
||||||
cosmetics.put(slot, cosmeticColorHashMap);
|
cosmetics.put(slot, cosmeticColorHashMap);
|
||||||
@@ -74,4 +96,15 @@ public class Data {
|
|||||||
}
|
}
|
||||||
return cosmetics;
|
return cosmetics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean shouldHiddenSave(CosmeticUser.@NotNull HiddenReason reason) {
|
||||||
|
switch (reason) {
|
||||||
|
case EMOTE, NONE -> {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
default -> {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import org.bukkit.persistence.PersistentDataType;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public class InternalData extends Data {
|
public class InternalData extends Data {
|
||||||
|
|
||||||
NamespacedKey key = new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "cosmetics");
|
NamespacedKey key = new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "cosmetics");
|
||||||
@@ -27,7 +28,7 @@ public class InternalData extends Data {
|
|||||||
public void save(CosmeticUser user) {
|
public void save(CosmeticUser user) {
|
||||||
Player player = Bukkit.getPlayer(user.getUniqueId());
|
Player player = Bukkit.getPlayer(user.getUniqueId());
|
||||||
|
|
||||||
player.getPersistentDataContainer().set(key, PersistentDataType.STRING, steralizeData(user));
|
player.getPersistentDataContainer().set(key, PersistentDataType.STRING, serializeData(user));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -38,7 +39,7 @@ public class InternalData extends Data {
|
|||||||
if (!player.getPersistentDataContainer().has(key, PersistentDataType.STRING)) return user;
|
if (!player.getPersistentDataContainer().has(key, PersistentDataType.STRING)) return user;
|
||||||
String rawData = player.getPersistentDataContainer().get(key, PersistentDataType.STRING);
|
String rawData = player.getPersistentDataContainer().get(key, PersistentDataType.STRING);
|
||||||
|
|
||||||
Map<CosmeticSlot, Map<Cosmetic, Color>> a = desteralizedata(rawData);
|
Map<CosmeticSlot, Map<Cosmetic, Color>> a = deserializeData(user, rawData);
|
||||||
for (Map<Cosmetic, Color> cosmeticColors : a.values()) {
|
for (Map<Cosmetic, Color> cosmeticColors : a.values()) {
|
||||||
for (Cosmetic cosmetic : cosmeticColors.keySet()) {
|
for (Cosmetic cosmetic : cosmeticColors.keySet()) {
|
||||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
|
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||||
|
|||||||
@@ -2,18 +2,15 @@ package com.hibiscusmc.hmccosmetics.database.types;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
import com.hibiscusmc.hmccosmetics.config.DatabaseSettings;
|
import com.hibiscusmc.hmccosmetics.config.DatabaseSettings;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Color;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class MySQLData extends Data {
|
public class MySQLData extends SQLData {
|
||||||
|
|
||||||
// Connection Information
|
// Connection Information
|
||||||
private String host;
|
private String host;
|
||||||
@@ -22,6 +19,7 @@ public class MySQLData extends Data {
|
|||||||
private String password;
|
private String password;
|
||||||
private int port;
|
private int port;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -35,11 +33,12 @@ public class MySQLData extends Data {
|
|||||||
HMCCosmeticsPlugin plugin = HMCCosmeticsPlugin.getInstance();
|
HMCCosmeticsPlugin plugin = HMCCosmeticsPlugin.getInstance();
|
||||||
try {
|
try {
|
||||||
openConnection();
|
openConnection();
|
||||||
|
if (connection == null) throw new NullPointerException("Connection is null");
|
||||||
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " +
|
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " +
|
||||||
"(UUID varchar(36) PRIMARY KEY, " +
|
"(UUID varchar(36) PRIMARY KEY, " +
|
||||||
"COSMETICS MEDIUMTEXT " +
|
"COSMETICS MEDIUMTEXT " +
|
||||||
");").execute();
|
");").execute();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException | NullPointerException 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.");
|
||||||
@@ -52,104 +51,58 @@ public class MySQLData extends Data {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public void save(CosmeticUser user) {
|
|
||||||
Runnable run = () -> {
|
|
||||||
try {
|
|
||||||
PreparedStatement preparedSt = preparedStatement("REPLACE INTO COSMETICDATABASE(UUID,COSMETICS) VALUES(?,?);");
|
|
||||||
preparedSt.setString(1, user.getUniqueId().toString());
|
|
||||||
preparedSt.setString(2, steralizeData(user));
|
|
||||||
preparedSt.executeUpdate();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if (!HMCCosmeticsPlugin.isDisable()) {
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), run);
|
|
||||||
} else {
|
|
||||||
run.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CosmeticUser get(UUID uniqueId) {
|
public void clear(UUID uniqueId) {
|
||||||
CosmeticUser user = new CosmeticUser(uniqueId);
|
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
|
||||||
try {
|
|
||||||
PreparedStatement preparedStatement = preparedStatement("SELECT * FROM COSMETICDATABASE WHERE UUID = ?;");
|
|
||||||
preparedStatement.setString(1, uniqueId.toString());
|
|
||||||
ResultSet rs = preparedStatement.executeQuery();
|
|
||||||
if (rs.next()) {
|
|
||||||
String rawData = rs.getString("COSMETICS");
|
|
||||||
Map<CosmeticSlot, Map<Cosmetic, Color>> cosmetics = desteralizedata(rawData);
|
|
||||||
for (Map<Cosmetic, Color> cosmeticColors : cosmetics.values()) {
|
|
||||||
for (Cosmetic cosmetic : cosmeticColors.keySet()) {
|
|
||||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
|
|
||||||
// This can not be async.
|
|
||||||
user.addPlayerCosmetic(cosmetic, cosmeticColors.get(cosmetic));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clear(UUID unqiueId) {
|
|
||||||
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, unqiueId.toString());
|
preparedSt.setString(1, uniqueId.toString());
|
||||||
preparedSt.executeUpdate();
|
preparedSt.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// TODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openConnection() throws SQLException {
|
private void openConnection() throws SQLException {
|
||||||
if (connection != null && !connection.isClosed()) {
|
// Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||||
return;
|
// ...
|
||||||
|
// });
|
||||||
|
// connection = DriverManager.getConnection("jdbc:mysql://" + DatabaseSettings.getHost() + ":" + DatabaseSettings.getPort() + "/" + DatabaseSettings.getDatabase(), setupProperties());
|
||||||
|
|
||||||
|
// Connection isn't null AND Connection isn't closed :: return
|
||||||
|
try {
|
||||||
|
if (isConnectionOpen()) {
|
||||||
|
return;
|
||||||
|
} else if (connection != null) close(); // Close connection if still active
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
e.printStackTrace(); // If isConnectionOpen() throws error
|
||||||
}
|
}
|
||||||
//Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
|
||||||
|
|
||||||
//close Connection if still active
|
// Connect to database host
|
||||||
if (connection != null) {
|
try {
|
||||||
close();
|
Class.forName("com.mysql.jdbc.Driver");
|
||||||
}
|
connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, setupProperties());
|
||||||
|
} catch (SQLException e) {
|
||||||
//connect to database host
|
System.out.println(e.getMessage());
|
||||||
try {
|
} catch (ClassNotFoundException e) {
|
||||||
Class.forName("com.mysql.jdbc.Driver");
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, setupProperties());
|
|
||||||
|
|
||||||
} catch (SQLException e) {
|
|
||||||
System.out.println(e.getMessage());
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
//});
|
|
||||||
//connection = DriverManager.getConnection("jdbc:mysql://" + DatabaseSettings.getHost() + ":" + DatabaseSettings.getPort() + "/" + DatabaseSettings.getDatabase(), setupProperties());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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");
|
||||||
connection.close();
|
connection.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException | NullPointerException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private Properties setupProperties() {
|
private Properties setupProperties() {
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
props.put("user", user);
|
props.put("user", user);
|
||||||
@@ -158,28 +111,29 @@ public class MySQLData extends Data {
|
|||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isConnectionOpen() {
|
private boolean isConnectionOpen() throws RuntimeException {
|
||||||
try {
|
try {
|
||||||
if (connection == null || connection.isClosed()) {
|
return connection != null && !connection.isClosed();
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public PreparedStatement preparedStatement(String query) {
|
public PreparedStatement preparedStatement(String query) {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
|
|
||||||
if (!isConnectionOpen()) {
|
if (!isConnectionOpen()) {
|
||||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Connection is not open");
|
HMCCosmeticsPlugin.getInstance().getLogger().info("Connection is not open");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (connection == null) throw new NullPointerException("Connection is null");
|
||||||
ps = connection.prepareStatement(query);
|
ps = connection.prepareStatement(query);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException | NullPointerException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ps;
|
return ps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.database.types;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Color;
|
||||||
|
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public abstract class SQLData extends Data {
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings({"Duplicates", "resource"}) // Duplicate is from deprecated InternalData
|
||||||
|
public CosmeticUser get(UUID uniqueId) {
|
||||||
|
CosmeticUser user = new CosmeticUser(uniqueId);
|
||||||
|
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||||
|
try {
|
||||||
|
PreparedStatement preparedStatement = preparedStatement("SELECT * FROM COSMETICDATABASE WHERE UUID = ?;");
|
||||||
|
preparedStatement.setString(1, uniqueId.toString());
|
||||||
|
ResultSet rs = preparedStatement.executeQuery();
|
||||||
|
if (rs.next()) {
|
||||||
|
String rawData = rs.getString("COSMETICS");
|
||||||
|
Map<CosmeticSlot, Map<Cosmetic, Color>> cosmetics = deserializeData(user, rawData);
|
||||||
|
for (Map<Cosmetic, Color> cosmeticColors : cosmetics.values()) {
|
||||||
|
for (Cosmetic cosmetic : cosmeticColors.keySet()) {
|
||||||
|
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||||
|
// This can not be async.
|
||||||
|
user.addPlayerCosmetic(cosmetic, cosmeticColors.get(cosmetic));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("resource")
|
||||||
|
public void save(CosmeticUser user) {
|
||||||
|
Runnable run = () -> {
|
||||||
|
try {
|
||||||
|
PreparedStatement preparedSt = preparedStatement("REPLACE INTO COSMETICDATABASE(UUID,COSMETICS) VALUES(?,?);");
|
||||||
|
preparedSt.setString(1, user.getUniqueId().toString());
|
||||||
|
preparedSt.setString(2, serializeData(user));
|
||||||
|
preparedSt.executeUpdate();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (!HMCCosmeticsPlugin.isDisable()) {
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), run);
|
||||||
|
} else {
|
||||||
|
run.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract PreparedStatement preparedStatement(String query);
|
||||||
|
}
|
||||||
@@ -1,31 +1,28 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.database.types;
|
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.CosmeticSlot;
|
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Color;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class SQLiteData extends Data {
|
public class SQLiteData extends SQLData {
|
||||||
|
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
File dataFolder = new File(HMCCosmeticsPlugin.getInstance().getDataFolder(), "database.db");
|
File dataFolder = new File(HMCCosmeticsPlugin.getInstance().getDataFolder(), "database.db");
|
||||||
|
boolean exists = dataFolder.exists();
|
||||||
|
|
||||||
if (!dataFolder.exists()){
|
if (!exists) {
|
||||||
try {
|
try {
|
||||||
dataFolder.createNewFile();
|
boolean created = dataFolder.createNewFile();
|
||||||
|
if (!created) throw new IOException("File didn't exist but now does");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
MessagesUtil.sendDebugMessages("File write error. Database will not work properly", Level.SEVERE);
|
MessagesUtil.sendDebugMessages("File write error. Database will not work properly", Level.SEVERE);
|
||||||
}
|
}
|
||||||
@@ -39,66 +36,18 @@ public class SQLiteData extends Data {
|
|||||||
"(UUID varchar(36) PRIMARY KEY, " +
|
"(UUID varchar(36) PRIMARY KEY, " +
|
||||||
"COSMETICS MEDIUMTEXT " +
|
"COSMETICS MEDIUMTEXT " +
|
||||||
");").execute();
|
");").execute();
|
||||||
|
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(CosmeticUser user) {
|
@SuppressWarnings("resource")
|
||||||
Runnable run = () -> {
|
public void clear(UUID uniqueId) {
|
||||||
try {
|
|
||||||
PreparedStatement preparedSt = preparedStatement("REPLACE INTO COSMETICDATABASE(UUID,COSMETICS) VALUES(?,?);");
|
|
||||||
preparedSt.setString(1, user.getUniqueId().toString());
|
|
||||||
preparedSt.setString(2, steralizeData(user));
|
|
||||||
preparedSt.executeUpdate();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if (!HMCCosmeticsPlugin.isDisable()) {
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), run);
|
|
||||||
} else {
|
|
||||||
run.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CosmeticUser get(UUID uniqueId) {
|
|
||||||
CosmeticUser user = new CosmeticUser(uniqueId);
|
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
|
||||||
try {
|
|
||||||
PreparedStatement preparedStatement = preparedStatement("SELECT * FROM COSMETICDATABASE WHERE UUID = ?;");
|
|
||||||
preparedStatement.setString(1, uniqueId.toString());
|
|
||||||
ResultSet rs = preparedStatement.executeQuery();
|
|
||||||
if (rs.next()) {
|
|
||||||
String rawData = rs.getString("COSMETICS");
|
|
||||||
Map<CosmeticSlot, Map<Cosmetic, Color>> cosmetics = desteralizedata(rawData);
|
|
||||||
for (Map<Cosmetic, Color> cosmeticColors : cosmetics.values()) {
|
|
||||||
for (Cosmetic cosmetic : cosmeticColors.keySet()) {
|
|
||||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
|
|
||||||
// This can not be async.
|
|
||||||
user.addPlayerCosmetic(cosmetic, cosmeticColors.get(cosmetic));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clear(UUID unqiueId) {
|
|
||||||
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, unqiueId.toString());
|
preparedSt.setString(1, uniqueId.toString());
|
||||||
preparedSt.executeUpdate();
|
preparedSt.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -106,56 +55,47 @@ public class SQLiteData extends Data {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void openConnection() throws SQLException {
|
private void openConnection() throws SQLException {
|
||||||
if (connection != null && !connection.isClosed()) {
|
// Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||||
return;
|
// ...
|
||||||
}
|
// });
|
||||||
//Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
// connection = DriverManager.getConnection("jdbc:mysql://" + DatabaseSettings.getHost() + ":" + DatabaseSettings.getPort() + "/" + DatabaseSettings.getDatabase(), setupProperties());
|
||||||
|
|
||||||
//close Connection if still active
|
if (connection != null && !connection.isClosed()) return;
|
||||||
if (connection != null) {
|
|
||||||
//close();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Close Connection if still active
|
||||||
File dataFolder = new File(HMCCosmeticsPlugin.getInstance().getDataFolder(), "database.db");
|
File dataFolder = new File(HMCCosmeticsPlugin.getInstance().getDataFolder(), "database.db");
|
||||||
|
|
||||||
//connect to database host
|
// Connect to database host
|
||||||
try {
|
try {
|
||||||
Class.forName("org.sqlite.JDBC");
|
Class.forName("org.sqlite.JDBC");
|
||||||
|
|
||||||
connection = DriverManager.getConnection("jdbc:sqlite:" + dataFolder);
|
connection = DriverManager.getConnection("jdbc:sqlite:" + dataFolder);
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
//});
|
|
||||||
//connection = DriverManager.getConnection("jdbc:mysql://" + DatabaseSettings.getHost() + ":" + DatabaseSettings.getPort() + "/" + DatabaseSettings.getDatabase(), setupProperties());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public PreparedStatement preparedStatement(String query) {
|
public PreparedStatement preparedStatement(String query) {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
if (!isConnectionOpen()) {
|
if (!isConnectionOpen()) {
|
||||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Connection is not open");
|
HMCCosmeticsPlugin.getInstance().getLogger().info("Connection is not open");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ps = connection.prepareStatement(query);
|
ps = connection.prepareStatement(query);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ps;
|
return ps;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isConnectionOpen() {
|
private boolean isConnectionOpen() {
|
||||||
try {
|
try {
|
||||||
if (connection == null || connection.isClosed()) {
|
return connection != null && !connection.isClosed();
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,121 +0,0 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.entities;
|
|
||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
|
||||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
|
||||||
import com.ticxo.modelengine.api.ModelEngineAPI;
|
|
||||||
import com.ticxo.modelengine.api.model.ActiveModel;
|
|
||||||
import com.ticxo.modelengine.api.model.ModeledEntity;
|
|
||||||
import org.bukkit.Color;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.util.Vector;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
// This includes the Pufferfish (The Pufferfish that's what the player leashes to) and the model (MEGEntity)
|
|
||||||
public class BalloonEntity {
|
|
||||||
|
|
||||||
private final int balloonID;
|
|
||||||
private final UUID uniqueID;
|
|
||||||
private final Entity modelEntity;
|
|
||||||
private ModeledEntity modeledEntity;
|
|
||||||
|
|
||||||
public BalloonEntity(Location location) {
|
|
||||||
this.uniqueID = UUID.randomUUID();
|
|
||||||
this.balloonID = NMSHandlers.getHandler().getNextEntityId();
|
|
||||||
this.modelEntity = NMSHandlers.getHandler().getMEGEntity(location.add(Settings.getBalloonOffset()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void spawnModel(final String id, Color color) {
|
|
||||||
|
|
||||||
MessagesUtil.sendDebugMessages("Attempting Spawning for " + id);
|
|
||||||
if (ModelEngineAPI.api.getModelRegistry().getBlueprint(id) == null) {
|
|
||||||
MessagesUtil.sendDebugMessages("Invalid Model Engine Blueprint " + id, Level.SEVERE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ModeledEntity modeledEntity = ModelEngineAPI.getOrCreateModeledEntity(modelEntity);
|
|
||||||
ActiveModel model = ModelEngineAPI.createActiveModel(ModelEngineAPI.getBlueprint(id));
|
|
||||||
model.setCanHurt(false);
|
|
||||||
modeledEntity.addModel(model, false);
|
|
||||||
if (color != null) {
|
|
||||||
modeledEntity.getModels().forEach((d, singleModel) -> {
|
|
||||||
singleModel.getRendererHandler().setColor(color);
|
|
||||||
singleModel.getRendererHandler().update();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
this.modeledEntity = modeledEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void remove() {
|
|
||||||
final ModeledEntity entity = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId());
|
|
||||||
|
|
||||||
if (entity == null) return;
|
|
||||||
|
|
||||||
for (final Player player : entity.getRangeManager().getPlayerInRange()) {
|
|
||||||
entity.hideFromPlayer(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
//ModelEngineAPI.removeModeledEntity(megEntity.getUniqueId());
|
|
||||||
entity.destroy();
|
|
||||||
modelEntity.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addPlayerToModel(final Player player, final String id) {
|
|
||||||
addPlayerToModel(player, id, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addPlayerToModel(final Player player, final String id, Color color) {
|
|
||||||
final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId());
|
|
||||||
if (model == null) {
|
|
||||||
spawnModel(id, color);
|
|
||||||
MessagesUtil.sendDebugMessages("model is null");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//if (model.getRangeManager().getPlayerInRange().contains(player)) return;
|
|
||||||
model.showToPlayer(player);
|
|
||||||
MessagesUtil.sendDebugMessages("Show to player");
|
|
||||||
}
|
|
||||||
public void removePlayerFromModel(final Player player) {
|
|
||||||
final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId());
|
|
||||||
|
|
||||||
if (model == null) return;
|
|
||||||
|
|
||||||
model.hideFromPlayer(player);
|
|
||||||
MessagesUtil.sendDebugMessages("Hidden from player");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Entity getModelEntity() {
|
|
||||||
return this.modelEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public int getPufferfishBalloonId() {
|
|
||||||
return balloonID;
|
|
||||||
}
|
|
||||||
public UUID getPufferfishBalloonUniqueId() {
|
|
||||||
return uniqueID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getModelUnqiueId() {
|
|
||||||
return getModelEntity().getUniqueId();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getModelId() {
|
|
||||||
return getModelEntity().getEntityId();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Location getLocation() {
|
|
||||||
return this.getModelEntity().getLocation();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLocation(Location location) {
|
|
||||||
this.getModelEntity().teleport(location);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVelocity(Vector vector) {
|
|
||||||
this.getModelEntity().setVelocity(vector);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,6 @@ import com.hibiscusmc.hmccosmetics.api.PlayerMenuOpenEvent;
|
|||||||
import com.hibiscusmc.hmccosmetics.config.serializer.ItemSerializer;
|
import com.hibiscusmc.hmccosmetics.config.serializer.ItemSerializer;
|
||||||
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.PAPIHook;
|
|
||||||
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.Adventure;
|
||||||
@@ -13,13 +12,13 @@ import com.hibiscusmc.hmccosmetics.util.misc.Placeholder;
|
|||||||
import dev.triumphteam.gui.builder.item.ItemBuilder;
|
import dev.triumphteam.gui.builder.item.ItemBuilder;
|
||||||
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 me.clip.placeholderapi.PlaceholderAPI;
|
|
||||||
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;
|
||||||
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.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
import org.spongepowered.configurate.serialize.SerializationException;
|
import org.spongepowered.configurate.serialize.SerializationException;
|
||||||
|
|
||||||
@@ -28,13 +27,13 @@ import java.util.List;
|
|||||||
|
|
||||||
public class Menu {
|
public class Menu {
|
||||||
|
|
||||||
private String id;
|
private final String id;
|
||||||
private String title;
|
private final String title;
|
||||||
private int rows;
|
private final int rows;
|
||||||
private ConfigurationNode config;
|
private final ConfigurationNode config;
|
||||||
private String permissionNode;
|
private final String permissionNode;
|
||||||
|
|
||||||
public Menu(String id, ConfigurationNode config) {
|
public Menu(String id, @NotNull ConfigurationNode config) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
|
||||||
@@ -61,7 +60,7 @@ public class Menu {
|
|||||||
openMenu(user, false);
|
openMenu(user, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openMenu(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;
|
||||||
if (!ignorePermission && !permissionNode.isEmpty()) {
|
if (!ignorePermission && !permissionNode.isEmpty()) {
|
||||||
@@ -100,7 +99,8 @@ public class Menu {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Gui getItems(CosmeticUser user, Gui gui) {
|
@Contract("_, _ -> param2")
|
||||||
|
private Gui getItems(@NotNull CosmeticUser user, Gui gui) {
|
||||||
Player player = user.getPlayer();
|
Player player = user.getPlayer();
|
||||||
|
|
||||||
for (ConfigurationNode config : config.node("items").childrenMap().values()) {
|
for (ConfigurationNode config : config.node("items").childrenMap().values()) {
|
||||||
@@ -137,8 +137,6 @@ public class Menu {
|
|||||||
MessagesUtil.sendDebugMessages("something went wrong! " + item);
|
MessagesUtil.sendDebugMessages("something went wrong! " + item);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ItemStack originalItem = item.clone();
|
|
||||||
item = updateLore(player, item);
|
|
||||||
|
|
||||||
Type type = null;
|
Type type = null;
|
||||||
|
|
||||||
@@ -147,6 +145,9 @@ public class Menu {
|
|||||||
if (Types.isType(typeId)) type = Types.getType(typeId);
|
if (Types.isType(typeId)) type = Types.getType(typeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ItemStack originalItem = item.clone();
|
||||||
|
item = updateLore(user, item, type, config);
|
||||||
|
|
||||||
GuiItem guiItem = ItemBuilder.from(item).asGuiItem();
|
GuiItem guiItem = ItemBuilder.from(item).asGuiItem();
|
||||||
|
|
||||||
Type finalType = type;
|
Type finalType = type;
|
||||||
@@ -155,7 +156,7 @@ public class Menu {
|
|||||||
if (finalType != null) finalType.run(user, config, clickType);
|
if (finalType != null) finalType.run(user, config, clickType);
|
||||||
|
|
||||||
for (int i : slots) {
|
for (int i : slots) {
|
||||||
gui.updateItem(i, updateLore(player, originalItem.clone()));
|
gui.updateItem(i, updateLore(user, originalItem.clone(), finalType, config));
|
||||||
MessagesUtil.sendDebugMessages("Updated slot " + i);
|
MessagesUtil.sendDebugMessages("Updated slot " + i);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -166,7 +167,8 @@ public class Menu {
|
|||||||
return gui;
|
return gui;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Integer> getSlots(List<String> slotString) {
|
@NotNull
|
||||||
|
private List<Integer> getSlots(@NotNull List<String> slotString) {
|
||||||
List<Integer> slots = new ArrayList<>();
|
List<Integer> slots = new ArrayList<>();
|
||||||
|
|
||||||
for (String a : slotString) {
|
for (String a : slotString) {
|
||||||
@@ -183,6 +185,7 @@ public class Menu {
|
|||||||
return slots;
|
return slots;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private List<Integer> getSlots(int small, int max) {
|
private List<Integer> getSlots(int small, int max) {
|
||||||
List<Integer> slots = new ArrayList<>();
|
List<Integer> slots = new ArrayList<>();
|
||||||
|
|
||||||
@@ -190,21 +193,11 @@ public class Menu {
|
|||||||
return slots;
|
return slots;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ItemStack updateLore(Player player, ItemStack itemStack) {
|
@Contract("_, _, _, _ -> param2")
|
||||||
|
@NotNull
|
||||||
|
private ItemStack updateLore(CosmeticUser user, @NotNull ItemStack itemStack, Type type, ConfigurationNode config) {
|
||||||
if (itemStack.hasItemMeta()) {
|
if (itemStack.hasItemMeta()) {
|
||||||
List<String> processedLore = new ArrayList<>();
|
itemStack.setItemMeta(type.setLore(user, config, itemStack.getItemMeta()));
|
||||||
|
|
||||||
if (PAPIHook.isPAPIEnabled()) {
|
|
||||||
if (itemStack.getItemMeta().hasLore()) {
|
|
||||||
for (String loreLine : itemStack.getItemMeta().getLore()) {
|
|
||||||
processedLore.add(PlaceholderAPI.setPlaceholders(player, loreLine));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
|
||||||
itemMeta.setLore(processedLore);
|
|
||||||
itemStack.setItemMeta(itemMeta);
|
|
||||||
}
|
}
|
||||||
return itemStack;
|
return itemStack;
|
||||||
}
|
}
|
||||||
@@ -215,7 +208,6 @@ public class Menu {
|
|||||||
|
|
||||||
public boolean canOpen(Player player) {
|
public boolean canOpen(Player player) {
|
||||||
if (permissionNode.isEmpty()) return true;
|
if (permissionNode.isEmpty()) return true;
|
||||||
if (player.isOp() || player.hasPermission(permissionNode)) return true;
|
return player.isOp() || player.hasPermission(permissionNode);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.gui;
|
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.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||||
import org.spongepowered.configurate.ConfigurateException;
|
import org.spongepowered.configurate.ConfigurateException;
|
||||||
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||||
@@ -12,24 +15,27 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class Menus {
|
public class Menus {
|
||||||
|
|
||||||
private static HashMap<String, Menu> MENUS = new HashMap<>();
|
private static final HashMap<String, Menu> MENUS = new HashMap<>();
|
||||||
|
|
||||||
public static void addMenu(Menu menu) {
|
public static void addMenu(Menu menu) {
|
||||||
MENUS.put(menu.getId().toUpperCase(), menu);
|
MENUS.put(menu.getId().toUpperCase(), menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Menu getMenu(String id) {
|
public static Menu getMenu(@NotNull String id) {
|
||||||
return MENUS.get(id.toUpperCase());
|
return MENUS.get(id.toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Contract(pure = true)
|
||||||
|
@NotNull
|
||||||
public static Collection<Menu> getMenu() {
|
public static Collection<Menu> getMenu() {
|
||||||
return MENUS.values();
|
return MENUS.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasMenu(String id) {
|
public static boolean hasMenu(@NotNull String id) {
|
||||||
return MENUS.containsKey(id.toUpperCase());
|
return MENUS.containsKey(id.toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,6 +43,9 @@ public class Menus {
|
|||||||
return MENUS.containsValue(menu);
|
return MENUS.containsValue(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Menu getDefaultMenu() { return Menus.getMenu(Settings.getDefaultMenu()); }
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static List<String> getMenuNames() {
|
public static List<String> getMenuNames() {
|
||||||
List<String> names = new ArrayList<>();
|
List<String> names = new ArrayList<>();
|
||||||
|
|
||||||
@@ -67,7 +76,12 @@ public class Menus {
|
|||||||
} catch (ConfigurateException e) {
|
} catch (ConfigurateException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
new Menu(FilenameUtils.removeExtension(child.getName()), root);
|
try {
|
||||||
|
new Menu(FilenameUtils.removeExtension(child.getName()), root);
|
||||||
|
} catch (Exception e) {
|
||||||
|
MessagesUtil.sendDebugMessages("Unable to create menu in " + child, Level.WARNING);
|
||||||
|
if (Settings.isDebugEnabled()) e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.gui.action;
|
package com.hibiscusmc.hmccosmetics.gui.action;
|
||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class Action {
|
public abstract class Action {
|
||||||
|
|
||||||
private String id;
|
private final String id;
|
||||||
|
|
||||||
public Action(String id) {
|
public Action(@NotNull String id) {
|
||||||
this.id = id.toUpperCase();
|
this.id = id.toUpperCase();
|
||||||
Actions.addAction(this);
|
Actions.addAction(this);
|
||||||
}
|
}
|
||||||
@@ -15,7 +16,5 @@ public class Action {
|
|||||||
return this.id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run(CosmeticUser user, String raw) {
|
public abstract void run(CosmeticUser user, String raw);
|
||||||
// Override
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,27 +4,36 @@ 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.lang.StringUtils;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class Actions {
|
public class Actions {
|
||||||
|
|
||||||
private static HashMap<String, Action> actions = new HashMap<>();
|
private static final HashMap<String, Action> actions = new HashMap<>();
|
||||||
|
|
||||||
// [ID]
|
// [ID]
|
||||||
private static ActionMessage ACTION_MESSAGE = new ActionMessage();
|
private static final ActionMessage ACTION_MESSAGE = new ActionMessage();
|
||||||
private static ActionMenu ACTION_MENU = new ActionMenu();
|
private static final ActionMenu ACTION_MENU = new ActionMenu();
|
||||||
private static ActionPlayerCommand ACTION_CONSOLE_COMMAND = new ActionPlayerCommand();
|
private static final ActionPlayerCommand ACTION_CONSOLE_COMMAND = new ActionPlayerCommand();
|
||||||
private static ActionConsoleCommand ACTION_PLAYER_COMMAND = new ActionConsoleCommand();
|
private static final ActionConsoleCommand ACTION_PLAYER_COMMAND = new ActionConsoleCommand();
|
||||||
private static ActionCloseMenu ACTION_EXIT_MENU = new ActionCloseMenu();
|
private static final ActionCloseMenu ACTION_EXIT_MENU = new ActionCloseMenu();
|
||||||
|
private static final ActionSound ACTION_SOUND = new ActionSound();
|
||||||
|
private static final ActionEquip ACTION_EQUIP = new ActionEquip();
|
||||||
|
private static final ActionUnequip ACTION_UNEQUIP = new ActionUnequip();
|
||||||
|
private static final ActionParticle ACTION_PARTICLE = new ActionParticle();
|
||||||
|
private static final ActionCosmeticShow ACTION_SHOW = new ActionCosmeticShow();
|
||||||
|
private static final ActionCosmeticHide ACTION_HIDE = new ActionCosmeticHide();
|
||||||
|
private static final ActionCosmeticToggle ACTION_TOGGLE = new ActionCosmeticToggle();
|
||||||
|
|
||||||
|
|
||||||
public static Action getAction(String id) {
|
public static Action getAction(@NotNull String id) {
|
||||||
return actions.get(id.toUpperCase());
|
return actions.get(id.toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isAction(String id) {
|
public static boolean isAction(@NotNull String id) {
|
||||||
return actions.containsKey(id.toUpperCase());
|
return actions.containsKey(id.toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,11 +41,11 @@ public class Actions {
|
|||||||
actions.put(action.getId().toUpperCase(), action);
|
actions.put(action.getId().toUpperCase(), action);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void runActions(CosmeticUser user, List<String> raw) {
|
public static void runActions(CosmeticUser user, @NotNull List<String> raw) {
|
||||||
for (String a : raw) {
|
for (String a : raw) {
|
||||||
String id = StringUtils.substringBetween(a, "[", "]").toUpperCase();
|
String id = StringUtils.substringBetween(a, "[", "]").toUpperCase();
|
||||||
String message = StringUtils.substringAfter(a, "] ");
|
String message = StringUtils.substringAfter(a, "] ");
|
||||||
MessagesUtil.sendDebugMessages("ID is " + id + " // Message is " + message);
|
MessagesUtil.sendDebugMessages("ID is " + id + " // Raw Data is " + message);
|
||||||
if (isAction(id)) {
|
if (isAction(id)) {
|
||||||
getAction(id).run(user, message);
|
getAction(id).run(user, message);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
|||||||
|
|
||||||
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.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ActionCloseMenu extends Action {
|
public class ActionCloseMenu extends Action {
|
||||||
|
|
||||||
@@ -10,7 +11,7 @@ public class ActionCloseMenu extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(CosmeticUser user, String raw) {
|
public void run(@NotNull CosmeticUser user, String raw) {
|
||||||
user.getPlayer().closeInventory();
|
user.getPlayer().closeInventory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
|||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
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.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ActionConsoleCommand extends Action {
|
public class ActionConsoleCommand extends Action {
|
||||||
|
|
||||||
@@ -11,8 +12,7 @@ public class ActionConsoleCommand extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(CosmeticUser user, String raw) {
|
public void run(@NotNull CosmeticUser user, String raw) {
|
||||||
HMCCosmeticsPlugin.getInstance().getServer().dispatchCommand(user.getPlayer(), raw);
|
HMCCosmeticsPlugin.getInstance().getServer().dispatchCommand(user.getPlayer(), raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class ActionCosmeticHide extends Action {
|
||||||
|
|
||||||
|
public ActionCosmeticHide() {
|
||||||
|
super("hide");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(@NotNull CosmeticUser user, String raw) {
|
||||||
|
if (user.getHidden()) return;
|
||||||
|
user.hideCosmetics(CosmeticUser.HiddenReason.ACTION);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class ActionCosmeticShow extends Action {
|
||||||
|
|
||||||
|
public ActionCosmeticShow() {
|
||||||
|
super("show");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(@NotNull CosmeticUser user, String raw) {
|
||||||
|
if (!user.getHidden()) return;
|
||||||
|
|
||||||
|
// Do not hide if it's already off for WG
|
||||||
|
if (user.getHiddenReason() != CosmeticUser.HiddenReason.ACTION && user.getHiddenReason() != CosmeticUser.HiddenReason.COMMAND) return;
|
||||||
|
user.showCosmetics();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class ActionCosmeticToggle extends Action {
|
||||||
|
|
||||||
|
public ActionCosmeticToggle() {
|
||||||
|
super("toggle");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(@NotNull CosmeticUser user, String raw) {
|
||||||
|
if (user.getHidden()) {
|
||||||
|
if (user.getHiddenReason() != CosmeticUser.HiddenReason.ACTION && user.getHiddenReason() != CosmeticUser.HiddenReason.COMMAND) return;
|
||||||
|
user.showCosmetics();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
user.hideCosmetics(CosmeticUser.HiddenReason.ACTION);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||||
|
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
|
||||||
|
public class ActionEquip extends Action {
|
||||||
|
|
||||||
|
public ActionEquip() {
|
||||||
|
super("equip");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(CosmeticUser user, String raw) {
|
||||||
|
Cosmetic cosmetic = Cosmetics.getCosmetic(raw);
|
||||||
|
if (cosmetic == null) return;
|
||||||
|
|
||||||
|
user.addPlayerCosmetic(cosmetic);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,9 @@ 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 java.util.logging.Level;
|
||||||
|
|
||||||
public class ActionMenu extends Action {
|
public class ActionMenu extends Action {
|
||||||
|
|
||||||
@@ -14,11 +17,22 @@ public class ActionMenu extends Action {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(CosmeticUser user, String raw) {
|
public void run(CosmeticUser user, String raw) {
|
||||||
|
boolean ignorePermission = false;
|
||||||
|
|
||||||
|
raw = raw.replaceAll(" ", ""); // Removes all spaces
|
||||||
|
|
||||||
|
if (raw.contains("-o")) {
|
||||||
|
raw = raw.replaceAll("-o", "");
|
||||||
|
ignorePermission = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!Menus.hasMenu(raw)) {
|
if (!Menus.hasMenu(raw)) {
|
||||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Invalid Action Menu -> " + raw);
|
MessagesUtil.sendDebugMessages("Invalid Action Menu -> " + raw, Level.WARNING);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Menu menu = Menus.getMenu(raw);
|
Menu menu = Menus.getMenu(raw);
|
||||||
menu.openMenu(user, true);
|
MessagesUtil.sendDebugMessages(raw + " | " + ignorePermission);
|
||||||
|
menu.openMenu(user, ignorePermission);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
|||||||
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.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ActionMessage extends Action {
|
public class ActionMessage extends Action {
|
||||||
|
|
||||||
@@ -11,7 +12,7 @@ public class ActionMessage extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(CosmeticUser user, String raw) {
|
public void run(@NotNull CosmeticUser user, String raw) {
|
||||||
MessagesUtil.sendMessageNoKey(user.getPlayer(), raw);
|
MessagesUtil.sendMessageNoKey(user.getPlayer(), raw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||||
|
import com.owen1212055.particlehelper.api.particle.types.BlockDataParticle;
|
||||||
|
import com.owen1212055.particlehelper.api.particle.types.DestinationParticle;
|
||||||
|
import com.owen1212055.particlehelper.api.particle.types.velocity.VelocityParticle;
|
||||||
|
import com.owen1212055.particlehelper.api.particle.types.vibration.VibrationParticle;
|
||||||
|
import com.owen1212055.particlehelper.api.type.ParticleType;
|
||||||
|
import com.owen1212055.particlehelper.api.type.Particles;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class ActionParticle extends Action {
|
||||||
|
|
||||||
|
public ActionParticle() {
|
||||||
|
super("particle");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("ConstantConditions")
|
||||||
|
public void run(CosmeticUser user, @NotNull String raw) {
|
||||||
|
String[] rawString = raw.split(" ");
|
||||||
|
ParticleType<?, ?> particleType = Particles.fromKey(NamespacedKey.minecraft(rawString[0].toLowerCase()));
|
||||||
|
if (particleType == null) {
|
||||||
|
MessagesUtil.sendDebugMessages("The particle " + rawString[0] + " does not exist!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// particleType.multi() should never be null, but particleType can be.
|
||||||
|
boolean multi = particleType.multi() != null;
|
||||||
|
|
||||||
|
var particle = multi ? particleType.multi() : particleType.single();
|
||||||
|
if (particle instanceof DestinationParticle || particle instanceof BlockDataParticle
|
||||||
|
|| particle instanceof VibrationParticle || particle instanceof VelocityParticle) {
|
||||||
|
MessagesUtil.sendDebugMessages("The particle " + rawString[0] + " is not supported by this action!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
particle = ServerUtils.addParticleValues(particle, rawString);
|
||||||
|
Location location = user.getPlayer().getLocation();
|
||||||
|
for (Player player : PacketManager.getViewers(location)) {
|
||||||
|
particle.compile().send(player, location);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
|||||||
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.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ActionPlayerCommand extends Action {
|
public class ActionPlayerCommand extends Action {
|
||||||
|
|
||||||
@@ -11,7 +12,7 @@ public class ActionPlayerCommand extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(CosmeticUser user, String raw) {
|
public void run(@NotNull CosmeticUser user, String raw) {
|
||||||
user.getPlayer().performCommand(MessagesUtil.processStringNoKeyString(user.getPlayer(), raw));
|
user.getPlayer().performCommand(MessagesUtil.processStringNoKeyString(user.getPlayer(), raw));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class ActionSound extends Action {
|
||||||
|
// [SOUND] minecraft:test 1 1
|
||||||
|
|
||||||
|
public ActionSound() {
|
||||||
|
super("sound");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(@NotNull CosmeticUser user, @NotNull String raw) {
|
||||||
|
Player player = user.getPlayer();
|
||||||
|
String[] processedString = raw.split(" ");
|
||||||
|
|
||||||
|
String soundName = processedString[0];
|
||||||
|
float volume = 1;
|
||||||
|
float pitch = 1;
|
||||||
|
|
||||||
|
if (processedString.length > 2) {
|
||||||
|
volume = Float.parseFloat(processedString[1]);
|
||||||
|
pitch = Float.parseFloat(processedString[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
MessagesUtil.sendDebugMessages("Attempting to play " + soundName, Level.INFO);
|
||||||
|
|
||||||
|
player.playSound(player.getLocation(), soundName, volume, pitch);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||||
|
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import org.apache.commons.lang3.EnumUtils;
|
||||||
|
|
||||||
|
public class ActionUnequip extends Action {
|
||||||
|
|
||||||
|
public ActionUnequip() {
|
||||||
|
super("unequip");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(CosmeticUser user, String raw) {
|
||||||
|
if (!EnumUtils.isValidEnum(CosmeticSlot.class, raw)) return;
|
||||||
|
|
||||||
|
CosmeticSlot slot = CosmeticSlot.valueOf(raw);
|
||||||
|
user.removeCosmeticSlot(slot);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import com.hibiscusmc.hmccolor.gui.guis.GuiItem;
|
|||||||
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.cosmetic.Cosmetic;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
|
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.util.misc.Placeholder;
|
import com.hibiscusmc.hmccosmetics.util.misc.Placeholder;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@@ -15,34 +16,39 @@ import org.bukkit.entity.Player;
|
|||||||
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.LeatherArmorMeta;
|
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||||
|
import org.bukkit.inventory.meta.MapMeta;
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class DyeMenu {
|
public class DyeMenu {
|
||||||
|
|
||||||
// Yes, I do know how tacted on this feels.
|
public static void openMenu(@NotNull CosmeticUser user, Cosmetic cosmetic) {
|
||||||
|
Player player = user.getPlayer();
|
||||||
|
if (player == null) return;
|
||||||
public static void openMenu(CosmeticUser user, Cosmetic cosmetic) {
|
if (!Hooks.isActiveHook("HMCColor")) {
|
||||||
|
addCosmetic(user, cosmetic, null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
ItemStack originalItem = user.getUserCosmeticItem(cosmetic);
|
ItemStack originalItem = user.getUserCosmeticItem(cosmetic);
|
||||||
if (originalItem == null || !cosmetic.isDyable()) return;
|
if (originalItem == null || !cosmetic.isDyable()) return;
|
||||||
|
|
||||||
Player player = user.getPlayer();
|
|
||||||
Gui gui = HMCColorApi.INSTANCE.colorMenu();
|
Gui gui = HMCColorApi.INSTANCE.colorMenu();
|
||||||
gui.updateTitle(Placeholder.applyPapiPlaceholders(player, Settings.getDyeMenuName()));
|
gui.updateTitle(Placeholder.applyPapiPlaceholders(player, Settings.getDyeMenuName()));
|
||||||
gui.setItem(19, new GuiItem(originalItem));
|
gui.setItem(Settings.getDyeMenuInputSlot(), new GuiItem(originalItem));
|
||||||
gui.setDefaultTopClickAction(event -> {
|
gui.setDefaultTopClickAction(event -> {
|
||||||
if (event.getSlot() == 25) {
|
if (event.getSlot() == Settings.getDyeMenuOutputSlot()) {
|
||||||
ItemStack item = event.getInventory().getItem(25);
|
ItemStack item = event.getInventory().getItem(Settings.getDyeMenuOutputSlot());
|
||||||
if (item == null) return;
|
if (item == null) return;
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
if (meta == null) return;
|
if (meta == null) return;
|
||||||
Color color = meta instanceof LeatherArmorMeta ? ((LeatherArmorMeta) meta).getColor() :
|
|
||||||
meta instanceof PotionMeta ? ((PotionMeta) meta).getColor() : null;
|
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;
|
if (color == null) return;
|
||||||
//user.removeCosmeticSlot(cosmetic);
|
|
||||||
user.addPlayerCosmetic(cosmetic, color);
|
addCosmetic(user, cosmetic, color);
|
||||||
player.setItemOnCursor(new ItemStack(Material.AIR));
|
event.setCancelled(true);
|
||||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), player::closeInventory, 2);
|
|
||||||
} else event.setCancelled(true);
|
} else event.setCancelled(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -50,4 +56,14 @@ public class DyeMenu {
|
|||||||
gui.setCloseGuiAction(event -> {});
|
gui.setCloseGuiAction(event -> {});
|
||||||
gui.open(player);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import org.bukkit.event.inventory.ClickType;
|
|||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
|
|
||||||
public class Type {
|
public abstract class Type {
|
||||||
|
|
||||||
private String id;
|
private final String id;
|
||||||
|
|
||||||
public Type(String id) {
|
public Type(String id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
@@ -21,12 +21,8 @@ public class Type {
|
|||||||
public void run(CosmeticUser user, ConfigurationNode config) {
|
public void run(CosmeticUser user, ConfigurationNode config) {
|
||||||
run(user, config, null);
|
run(user, config, null);
|
||||||
}
|
}
|
||||||
public void run(CosmeticUser user, ConfigurationNode config, ClickType clickType) {
|
|
||||||
// Override
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemMeta setLore(CosmeticUser user, ConfigurationNode config, ItemMeta itemMeta) {
|
public abstract void run(CosmeticUser user, ConfigurationNode config, ClickType clickType);
|
||||||
//TODO: Finish this
|
|
||||||
return null; // Override
|
public abstract ItemMeta setLore(CosmeticUser user, ConfigurationNode config, ItemMeta itemMeta);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,21 +2,22 @@ package com.hibiscusmc.hmccosmetics.gui.type;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.gui.type.types.TypeCosmetic;
|
import com.hibiscusmc.hmccosmetics.gui.type.types.TypeCosmetic;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.type.types.TypeEmpty;
|
import com.hibiscusmc.hmccosmetics.gui.type.types.TypeEmpty;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class Types {
|
public class Types {
|
||||||
|
|
||||||
private static HashMap<String, Type> types = new HashMap<>();
|
private static final HashMap<String, Type> types = new HashMap<>();
|
||||||
|
|
||||||
private static TypeCosmetic TYPE_COSMETIC = new TypeCosmetic();
|
private static TypeCosmetic TYPE_COSMETIC = new TypeCosmetic();
|
||||||
private static TypeEmpty TYPE_EMPTY = new TypeEmpty();
|
private static TypeEmpty TYPE_EMPTY = new TypeEmpty();
|
||||||
|
|
||||||
public static Type getType(String id) {
|
public static Type getType(@NotNull String id) {
|
||||||
return types.get(id.toUpperCase());
|
return types.get(id.toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isType(String id) {
|
public static boolean isType(@NotNull String id) {
|
||||||
return types.containsKey(id.toUpperCase());
|
return types.containsKey(id.toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,31 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.gui.type.types;
|
package com.hibiscusmc.hmccosmetics.gui.type.types;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
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.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.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 com.hibiscusmc.hmccosmetics.util.misc.StringUtils;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.misc.Utils;
|
||||||
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
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.meta.ItemMeta;
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
import org.spongepowered.configurate.serialize.SerializationException;
|
import org.spongepowered.configurate.serialize.SerializationException;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class TypeCosmetic extends Type {
|
public class TypeCosmetic extends Type {
|
||||||
|
|
||||||
@@ -21,17 +34,18 @@ public class TypeCosmetic extends Type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(CosmeticUser user, ConfigurationNode config, ClickType clickType) {
|
public void run(CosmeticUser user, @NotNull ConfigurationNode config, ClickType clickType) {
|
||||||
if (config.node("cosmetic").virtual()) return;
|
if (config.node("cosmetic").virtual()) return;
|
||||||
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.sendMessage(user.getPlayer(), "invalid-cosmetic");
|
MessagesUtil.sendMessage(player, "invalid-cosmetic");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!user.canEquipCosmetic(cosmetic)) {
|
if (!user.canEquipCosmetic(cosmetic)) {
|
||||||
MessagesUtil.sendMessage(user.getPlayer(), "no-cosmetic-permission");
|
MessagesUtil.sendMessage(player, "no-cosmetic-permission");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +84,84 @@ public class TypeCosmetic extends Type {
|
|||||||
} catch (SerializationException e) {
|
} catch (SerializationException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
// Fixes issue with offhand cosmetics not appearing. Yes, I know this is dumb
|
||||||
|
Runnable run = () -> user.updateCosmetic(cosmetic.getSlot());
|
||||||
|
if (cosmetic instanceof CosmeticArmorType) {
|
||||||
|
if (((CosmeticArmorType) cosmetic).getEquipSlot().equals(EquipmentSlot.OFF_HAND)) {
|
||||||
|
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), run, 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
run.run();
|
||||||
|
}
|
||||||
|
|
||||||
user.updateCosmetic(cosmetic.getSlot());
|
@Override
|
||||||
|
public ItemMeta setLore(CosmeticUser user, @NotNull ConfigurationNode config, ItemMeta itemMeta) {
|
||||||
|
List<String> processedLore = new ArrayList<>();
|
||||||
|
|
||||||
|
if (config.node("cosmetic").virtual()) return processLoreLines(user, itemMeta);;
|
||||||
|
String cosmeticName = config.node("cosmetic").getString();
|
||||||
|
Cosmetic cosmetic = Cosmetics.getCosmetic(cosmeticName);
|
||||||
|
if (cosmetic == null) {
|
||||||
|
return processLoreLines(user, itemMeta);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user.canEquipCosmetic(cosmetic)) {
|
||||||
|
return processLoreLines(user, itemMeta);
|
||||||
|
} else {
|
||||||
|
ConfigurationNode itemConfig = config.node("item");
|
||||||
|
if (itemConfig.virtual()) return itemMeta;
|
||||||
|
if (itemConfig.node("locked-name").virtual() && itemConfig.node("locked-lore").virtual()) {
|
||||||
|
return processLoreLines(user, itemMeta);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
List<String> lockedLore = itemMeta.getLore();
|
||||||
|
String lockedName = itemMeta.getDisplayName();
|
||||||
|
|
||||||
|
if (!itemConfig.node("locked-lore").virtual()) {
|
||||||
|
lockedLore = Utils.replaceIfNull(itemConfig.node("locked-lore").getList(String.class),
|
||||||
|
new ArrayList<String>()).
|
||||||
|
stream().map(StringUtils::parseStringToString).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
if (!itemConfig.node("locked-name").virtual()) {
|
||||||
|
lockedName = StringUtils.parseStringToString(Utils.replaceIfNull(itemConfig.node("locked-name").getString(), ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Hooks.isActiveHook("PlaceHolderAPI")) {
|
||||||
|
lockedName = PlaceholderAPI.setPlaceholders(user.getPlayer(), lockedName);
|
||||||
|
}
|
||||||
|
itemMeta.setDisplayName(lockedName);
|
||||||
|
if (itemMeta.hasLore()) {
|
||||||
|
itemMeta.getLore().clear();
|
||||||
|
for (String loreLine : lockedLore) {
|
||||||
|
if (Hooks.isActiveHook("PlaceHolderAPI")) loreLine = PlaceholderAPI.setPlaceholders(user.getPlayer(), loreLine);
|
||||||
|
processedLore.add(loreLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
itemMeta.setLore(processedLore);
|
||||||
|
return itemMeta;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("_, _ -> param2")
|
||||||
|
@NotNull
|
||||||
|
@SuppressWarnings("Duplicates")
|
||||||
|
private ItemMeta processLoreLines(CosmeticUser user, @NotNull ItemMeta itemMeta) {
|
||||||
|
List<String> processedLore = new ArrayList<>();
|
||||||
|
|
||||||
|
if (itemMeta.hasLore()) {
|
||||||
|
for (String loreLine : itemMeta.getLore()) {
|
||||||
|
if (Hooks.isActiveHook("PlaceholderAPI"))
|
||||||
|
loreLine = PlaceholderAPI.setPlaceholders(user.getPlayer(), loreLine);
|
||||||
|
processedLore.add(loreLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
itemMeta.setLore(processedLore);
|
||||||
|
return itemMeta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,12 @@ package com.hibiscusmc.hmccosmetics.gui.type.types;
|
|||||||
|
|
||||||
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.clip.placeholderapi.PlaceholderAPI;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
import org.spongepowered.configurate.serialize.SerializationException;
|
import org.spongepowered.configurate.serialize.SerializationException;
|
||||||
|
|
||||||
@@ -13,7 +17,6 @@ import java.util.List;
|
|||||||
public class TypeEmpty extends Type {
|
public class TypeEmpty extends Type {
|
||||||
|
|
||||||
// This can be used as an example for making your own types.
|
// This can be used as an example for making your own types.
|
||||||
|
|
||||||
public TypeEmpty() {
|
public TypeEmpty() {
|
||||||
super("empty");
|
super("empty");
|
||||||
// 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.
|
||||||
@@ -21,7 +24,7 @@ public class TypeEmpty extends Type {
|
|||||||
|
|
||||||
// This is the code that's run when the item is clicked.
|
// This is the code that's run when the item is clicked.
|
||||||
@Override
|
@Override
|
||||||
public void run(CosmeticUser user, ConfigurationNode config, ClickType clickType) {
|
public void run(CosmeticUser user, @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.
|
||||||
|
|
||||||
@@ -29,7 +32,7 @@ public class TypeEmpty extends Type {
|
|||||||
try {
|
try {
|
||||||
// This gets the actions with the item. We can add more, such as with the Cosmetic type, an equip and unequip action set.
|
// This gets the actions with the item. We can add more, such as with the Cosmetic type, an equip and unequip action set.
|
||||||
// We add that to a List of Strings, before running those actions through the server. This is not the area where we deal
|
// We add that to a List of Strings, before running those actions through the server. This is not the area where we deal
|
||||||
// with actions, mearly what should be done for each item.
|
// with actions, merely what should be done for each item.
|
||||||
if (!actionConfig.node("any").virtual()) actionStrings.addAll(actionConfig.node("any").getList(String.class));
|
if (!actionConfig.node("any").virtual()) actionStrings.addAll(actionConfig.node("any").getList(String.class));
|
||||||
|
|
||||||
if (clickType != null) {
|
if (clickType != null) {
|
||||||
@@ -48,6 +51,22 @@ public class TypeEmpty extends Type {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("Duplicates")
|
||||||
|
public ItemMeta setLore(CosmeticUser user, ConfigurationNode config, @NotNull ItemMeta itemMeta) {
|
||||||
|
List<String> processedLore = new ArrayList<>();
|
||||||
|
|
||||||
|
if (itemMeta.hasLore()) {
|
||||||
|
for (String loreLine : itemMeta.getLore()) {
|
||||||
|
if (Hooks.isActiveHook("PlaceholderAPI"))
|
||||||
|
loreLine = PlaceholderAPI.setPlaceholders(user.getPlayer(), loreLine);
|
||||||
|
processedLore.add(loreLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return itemMeta;
|
||||||
|
}
|
||||||
|
|
||||||
// That's it! Now, add it as a static in another one of your classes (such as your main class) and you are good to go.
|
// That's it! Now, add it as a static in another one of your classes (such as your main class) and you are good to go.
|
||||||
// If you need help with that, check the Types class.
|
// If you need help with that, check the Types class.
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.hooks;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
|
import com.hibiscusmc.hmccosmetics.hooks.items.*;
|
||||||
|
import com.hibiscusmc.hmccosmetics.hooks.misc.HookCMI;
|
||||||
|
import com.hibiscusmc.hmccosmetics.hooks.misc.HookHMCColor;
|
||||||
|
import com.hibiscusmc.hmccosmetics.hooks.misc.HookPremiumVanish;
|
||||||
|
import com.hibiscusmc.hmccosmetics.hooks.misc.HookSuperVanish;
|
||||||
|
import com.hibiscusmc.hmccosmetics.hooks.placeholders.HookPlaceholderAPI;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
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 HookOraxen ORAXEN_HOOK = new HookOraxen();
|
||||||
|
private static HookItemAdder ITEMADDER_HOOK = new HookItemAdder();
|
||||||
|
private static HookLooty LOOTY_HOOK = new HookLooty();
|
||||||
|
private static HookMythic MYTHIC_HOOK = new HookMythic();
|
||||||
|
private static HookHMCCosmetics HMCCOSMETIC_HOOK = new HookHMCCosmetics();
|
||||||
|
private static HookPlaceholderAPI PAPI_HOOK = new HookPlaceholderAPI();
|
||||||
|
private static HookPremiumVanish PREMIUM_VANISH_HOOK = new HookPremiumVanish();
|
||||||
|
private static HookSuperVanish SUPER_VANISH_HOOK = new HookSuperVanish();
|
||||||
|
private static HookHMCColor HMC_COLOR_HOOK = new HookHMCColor();
|
||||||
|
private static HookCMI CMI_HOOK = new HookCMI();
|
||||||
|
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isActiveHook(String id) {
|
||||||
|
Hook hook = getHook(id);
|
||||||
|
if (hook == null) return false;
|
||||||
|
return hook.isActive();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.hooks.items;
|
|
||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
public class HMCCosmeticsHook extends ItemHook implements Listener {
|
|
||||||
|
|
||||||
public HMCCosmeticsHook() {
|
|
||||||
super("HMCCosmetics");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack get(String itemid) {
|
|
||||||
Cosmetic cosmetic = Cosmetics.getCosmetic(itemid);
|
|
||||||
if (cosmetic == null) return null;
|
|
||||||
return cosmetic.getItem();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.hooks.items;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||||
|
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A hook that integrates the plugin {@link com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin HMCCosmetics} to provide cosmetic items
|
||||||
|
*/
|
||||||
|
public class HookHMCCosmetics extends Hook {
|
||||||
|
public HookHMCCosmetics() {
|
||||||
|
super("HMCCosmetics");
|
||||||
|
setEnabledItemHook(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a cosmetic {@link ItemStack} that is associated with the provided id from the plugin {@link com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin HMCCosmetics}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ItemStack getItem(@NotNull String itemId) {
|
||||||
|
Cosmetic cosmetic = Cosmetics.getCosmetic(itemId);
|
||||||
|
if (cosmetic == null) return null;
|
||||||
|
return cosmetic.getItem();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
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.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
|
||||||
|
public void onItemAdderDataLoad(ItemsAdderLoadDataEvent event) {
|
||||||
|
// By default, it will only run once at startup, if hook setting is enabled
|
||||||
|
if (enabled && !Settings.getItemsAdderReloadChange()) return;
|
||||||
|
this.enabled = true;
|
||||||
|
HMCCosmeticsPlugin.setup();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.hooks.items;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
||||||
|
import com.mineinabyss.geary.prefabs.PrefabKey;
|
||||||
|
import com.mineinabyss.looty.LootyFactory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A hook that integrates the plugin {@link com.mineinabyss.looty.LootyPlugin Looty} to provide custom items
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("SpellCheckingInspection")
|
||||||
|
public class HookLooty extends Hook {
|
||||||
|
public HookLooty() {
|
||||||
|
super("looty");
|
||||||
|
setEnabledItemHook(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a cosmetic {@link ItemStack} that is associated with the provided id from the plugin {@link com.mineinabyss.looty.LootyPlugin Looty}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ItemStack getItem(@NotNull String itemId) {
|
||||||
|
PrefabKey prefabKey = PrefabKey.Companion.ofOrNull(itemId);
|
||||||
|
if (prefabKey == null) return null;
|
||||||
|
return LootyFactory.INSTANCE.createFromPrefab(prefabKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.hooks.items;
|
|
||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
|
||||||
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.Listener;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
public class ItemAdderHook extends ItemHook implements Listener {
|
|
||||||
|
|
||||||
// I hate IA, this overcomplicate stuff is so unneeded if it just did its stuff when its needed.
|
|
||||||
|
|
||||||
private boolean enabled = false;
|
|
||||||
|
|
||||||
public ItemAdderHook() {
|
|
||||||
super("itemsadder");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack get(String itemid) {
|
|
||||||
if (enabled) {
|
|
||||||
return CustomStack.getInstance(itemid).getItemStack();
|
|
||||||
} else {
|
|
||||||
return new ItemStack(Material.AIR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onItemAdderDataLoad(ItemsAdderLoadDataEvent event) {
|
|
||||||
this.enabled = true;
|
|
||||||
HMCCosmeticsPlugin.setup();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.hooks.items;
|
|
||||||
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
public class ItemHook implements Listener {
|
|
||||||
|
|
||||||
private String id;
|
|
||||||
private boolean active;
|
|
||||||
|
|
||||||
public ItemHook(String id) {
|
|
||||||
this.id = id;
|
|
||||||
active = false;
|
|
||||||
ItemHooks.addItemHook(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack get(String itemid) {
|
|
||||||
return null;
|
|
||||||
// Override
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setActive(boolean active) {
|
|
||||||
this.active = active;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getActive() {
|
|
||||||
return this.active;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.hooks.items;
|
|
||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class ItemHooks {
|
|
||||||
|
|
||||||
private static HashMap<String, ItemHook> itemHooks = new HashMap<>();
|
|
||||||
private static OraxenHook ORAXEN_HOOK = new OraxenHook();
|
|
||||||
private static ItemAdderHook ITEMADDER_HOOK = new ItemAdderHook();
|
|
||||||
private static MythicHook MYTHIC_HOOK = new MythicHook();
|
|
||||||
private static HMCCosmeticsHook HMCCOSMETIC_HOOK = new HMCCosmeticsHook();
|
|
||||||
|
|
||||||
public static ItemHook getItemHook(String id) {
|
|
||||||
return itemHooks.get(id.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isItemHook(String id) {
|
|
||||||
return itemHooks.containsKey(id.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void addItemHook(ItemHook hook) {
|
|
||||||
itemHooks.put(hook.getId().toLowerCase(), hook);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setup() {
|
|
||||||
for (ItemHook itemHook : itemHooks.values()) {
|
|
||||||
if (Bukkit.getPluginManager().getPlugin(itemHook.getId()) != null) {
|
|
||||||
HMCCosmeticsPlugin.getInstance().getServer().getPluginManager().registerEvents(itemHook, HMCCosmeticsPlugin.getInstance());
|
|
||||||
itemHook.setActive(true);
|
|
||||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Successfully hooked into " + itemHook.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ItemStack getItem(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;
|
|
||||||
ItemHook itemHook = getItemHook(split[0]);
|
|
||||||
if (!itemHook.getActive()) return null;
|
|
||||||
ItemStack item = itemHook.get(split[1]);
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.hooks.items;
|
|
||||||
|
|
||||||
import io.lumine.mythic.bukkit.MythicBukkit;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
public class MythicHook extends ItemHook implements Listener {
|
|
||||||
public MythicHook() {
|
|
||||||
super("mythicmobs");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack get(String itemid) {
|
|
||||||
return MythicBukkit.inst().getItemManager().getItemStack(itemid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.hooks.items;
|
|
||||||
|
|
||||||
import io.th0rgal.oraxen.api.OraxenItems;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
public class OraxenHook extends ItemHook implements Listener {
|
|
||||||
|
|
||||||
public OraxenHook() {
|
|
||||||
super("oraxen");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack get(String itemid) {
|
|
||||||
return OraxenItems.getItemById(itemid).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
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.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
|
||||||
|
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
|
||||||
|
public void onPlayerShow(@NotNull CMIPlayerUnVanishEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
|
if (user == null) return;
|
||||||
|
user.showCosmetics();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
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.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
|
||||||
|
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
|
||||||
|
public void onPlayerShow(@NotNull PlayerShowEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
|
if (user == null) return;
|
||||||
|
user.showCosmetics();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
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.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
|
||||||
|
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
|
||||||
|
public void onPlayerShow(@NotNull PlayerShowEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
|
if (user == null) return;
|
||||||
|
user.showCosmetics();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.hooks;
|
package com.hibiscusmc.hmccosmetics.hooks.placeholders;
|
||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
@@ -6,41 +6,54 @@ import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
|||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||||
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.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;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PAPIHook extends PlaceholderExpansion {
|
/**
|
||||||
|
* A hook that integrates the plugin {@link me.clip.placeholderapi.PlaceholderAPIPlugin PlaceholderAPIPlugin}
|
||||||
|
*/
|
||||||
|
public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
||||||
private static boolean papiEnabled = false;
|
private static boolean papiEnabled = false;
|
||||||
|
|
||||||
public PAPIHook() {
|
public HMCPlaceholderExpansion() {
|
||||||
papiEnabled = true;
|
papiEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String getIdentifier() {
|
@NotNull
|
||||||
|
public String getIdentifier() {
|
||||||
return "HMCCosmetics";
|
return "HMCCosmetics";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String getAuthor() {
|
@NotNull
|
||||||
|
public String getAuthor() {
|
||||||
return "HibiscusMC";
|
return "HibiscusMC";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String getVersion() {
|
@NotNull
|
||||||
|
public String getVersion() {
|
||||||
return HMCCosmeticsPlugin.getInstance().getDescription().getVersion();
|
return HMCCosmeticsPlugin.getInstance().getDescription().getVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String onRequest(OfflinePlayer player, String params) {
|
public boolean persist() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String onRequest(@NotNull OfflinePlayer player, @NotNull String params) {
|
||||||
if (!player.isOnline()) return null;
|
if (!player.isOnline()) return null;
|
||||||
CosmeticUser user = CosmeticUsers.getUser(player.getPlayer());
|
CosmeticUser user = CosmeticUsers.getUser(player.getPlayer());
|
||||||
if (user == null) return null;
|
if (user == null) return null;
|
||||||
@@ -54,7 +67,10 @@ public class PAPIHook extends PlaceholderExpansion {
|
|||||||
}
|
}
|
||||||
if (placeholderArgs.get(1) != null) {
|
if (placeholderArgs.get(1) != null) {
|
||||||
Cosmetic cosmetic = Cosmetics.getCosmetic(placeholderArgs.get(1));
|
Cosmetic cosmetic = Cosmetics.getCosmetic(placeholderArgs.get(1));
|
||||||
if (user.getCosmetic(cosmetic.getSlot()).getId() == cosmetic.getId()) return "true";
|
if (cosmetic == null) return "INVALID_COSMETIC";
|
||||||
|
Cosmetic currentCosmetic = user.getCosmetic(cosmetic.getSlot());
|
||||||
|
if (currentCosmetic == null) return "false";
|
||||||
|
if (currentCosmetic.getId() == cosmetic.getId()) return "true";
|
||||||
return "false";
|
return "false";
|
||||||
}
|
}
|
||||||
case "current":
|
case "current":
|
||||||
@@ -64,10 +80,11 @@ public class PAPIHook extends PlaceholderExpansion {
|
|||||||
if (placeholderArgs.get(1) != null) {
|
if (placeholderArgs.get(1) != null) {
|
||||||
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 null;
|
||||||
if (placeholderArgs.size() == 2) return user.getCosmetic(slot).getId();
|
if (placeholderArgs.size() == 2) return user.getCosmetic(slot).getId();
|
||||||
switch (placeholderArgs.get(2).toLowerCase()) {
|
switch (placeholderArgs.get(2).toLowerCase()) {
|
||||||
case "material" -> {
|
case "material" -> {
|
||||||
return getMaterial(user.getCosmetic(slot));
|
return getMaterialName(user.getCosmetic(slot));
|
||||||
}
|
}
|
||||||
case "custommodeldata" -> {
|
case "custommodeldata" -> {
|
||||||
return getModelData(user.getCosmetic(slot));
|
return getModelData(user.getCosmetic(slot));
|
||||||
@@ -107,13 +124,29 @@ public class PAPIHook extends PlaceholderExpansion {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (placeholderArgs.get(1) != null) {
|
if (placeholderArgs.get(1) != null) {
|
||||||
Cosmetic cosmetic = Cosmetics.getCosmetic(placeholderArgs.get(1));
|
String args1 = placeholderArgs.get(1);
|
||||||
if (cosmetic == null) {
|
|
||||||
Cosmetic secondAttemptCosmetic = Cosmetics.getCosmetic(placeholderArgs.get(1) + "_" + placeholderArgs.get(2));
|
if (EnumUtils.isValidEnum(CosmeticSlot.class, args1.toUpperCase())) {
|
||||||
if (secondAttemptCosmetic == null) {
|
if (user.getCosmetic(CosmeticSlot.valueOf(args1.toUpperCase())) != null) {
|
||||||
return "INVALID_COSMETIC";
|
return "true";
|
||||||
} else {
|
} else {
|
||||||
cosmetic = secondAttemptCosmetic;
|
return "false";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MessagesUtil.sendDebugMessages(args1);
|
||||||
|
|
||||||
|
Cosmetic cosmetic = Cosmetics.getCosmetic(args1);
|
||||||
|
if (cosmetic == null) {
|
||||||
|
if (placeholderArgs.size() == 3) {
|
||||||
|
Cosmetic secondAttemptCosmetic = Cosmetics.getCosmetic(placeholderArgs.get(1) + "_" + placeholderArgs.get(2));
|
||||||
|
if (secondAttemptCosmetic == null) {
|
||||||
|
return "INVALID_COSMETIC";
|
||||||
|
} else {
|
||||||
|
cosmetic = secondAttemptCosmetic;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return "INVALID_COSMETIC";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (user.getCosmetic(cosmetic.getSlot()) == null) return "false";
|
if (user.getCosmetic(cosmetic.getSlot()) == null) return "false";
|
||||||
@@ -129,38 +162,77 @@ public class PAPIHook extends PlaceholderExpansion {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMaterial(Cosmetic cosmetic) {
|
/**
|
||||||
|
* Gets the name of the cosmetic item {@link org.bukkit.Material Material}
|
||||||
|
* @param cosmetic The cosmetic to get its {@link org.bukkit.Material Material}s name
|
||||||
|
* @return The name of the cosmetic item {@link org.bukkit.Material Material}
|
||||||
|
* @deprecated As of release 2.2.5+, use {@link #getMaterialName(Cosmetic)} instead
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
@Nullable
|
||||||
|
public String getMaterial(@NotNull Cosmetic cosmetic) {
|
||||||
ItemStack item = cosmetic.getItem();
|
ItemStack item = cosmetic.getItem();
|
||||||
if (item == null) return null;
|
if (item == null) return null;
|
||||||
return cosmetic.getItem().getType().toString();
|
return item.getType().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getModelData(Cosmetic cosmetic) {
|
/**
|
||||||
|
* Gets the name of the cosmetic item {@link org.bukkit.Material Material}
|
||||||
|
* @param cosmetic The cosmetic to get its {@link org.bukkit.Material Material}s name
|
||||||
|
* @return The name of the cosmetic item {@link org.bukkit.Material Material}
|
||||||
|
* @since 2.2.5
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public String getMaterialName(@NotNull Cosmetic cosmetic) {
|
||||||
|
ItemStack item = cosmetic.getItem();
|
||||||
|
if (item == null) return null;
|
||||||
|
return item.getType().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the cosmetic items custom model data
|
||||||
|
* @param cosmetic The cosmetic to get its custom model data
|
||||||
|
* @return The cosmetic items custom model data
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public String getModelData(@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;
|
||||||
ItemMeta itemMeta = item.getItemMeta();
|
ItemMeta itemMeta = item.getItemMeta();
|
||||||
|
if (itemMeta == null) return null;
|
||||||
return String.valueOf(itemMeta.getCustomModelData());
|
return String.valueOf(itemMeta.getCustomModelData());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getItemName(Cosmetic cosmetic) {
|
/**
|
||||||
|
* Gets the cosmetic items display name
|
||||||
|
* @param cosmetic The cosmetic to get its items display name
|
||||||
|
* @return The cosmetic items display name
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public String getItemName(@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;
|
||||||
ItemMeta itemMeta = item.getItemMeta();
|
ItemMeta itemMeta = item.getItemMeta();
|
||||||
|
if (itemMeta == null) return null;
|
||||||
return itemMeta.getDisplayName();
|
return itemMeta.getDisplayName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getItemLore(Cosmetic cosmetic) {
|
/**
|
||||||
|
* Gets the cosmetic items lore
|
||||||
|
* @param cosmetic The cosmetic to get its items lore
|
||||||
|
* @return The cosmetic items lore
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public String getItemLore(@NotNull Cosmetic cosmetic) {
|
||||||
ItemStack item = cosmetic.getItem();
|
ItemStack item = cosmetic.getItem();
|
||||||
if (item == null) return null;
|
if (item == null) return null;
|
||||||
if (item.hasItemMeta()) {
|
if (item.hasItemMeta()) {
|
||||||
return String.valueOf(item.getItemMeta().getLore());
|
ItemMeta itemMeta = item.getItemMeta();
|
||||||
|
if (itemMeta == null) return null;
|
||||||
|
return String.valueOf(itemMeta.getLore());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isPAPIEnabled() {
|
|
||||||
return papiEnabled;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,9 +9,18 @@ import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
|
|||||||
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A hook that integrates the plugin {@link com.sk89q.worldguard.WorldGuard WorldGuard}
|
||||||
|
*/
|
||||||
public class WGHook {
|
public class WGHook {
|
||||||
|
/**
|
||||||
|
* @implNote Please use {@link #getCosmeticEnableFlag()} instead
|
||||||
|
*/
|
||||||
public static StateFlag COSMETIC_ENABLE_FLAG;
|
public static StateFlag COSMETIC_ENABLE_FLAG;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @implNote Please use {@link #getCosmeticWardrobeFlag()} instead
|
||||||
|
*/
|
||||||
public static StateFlag COSMETIC_WARDROBE_FLAG;
|
public static StateFlag COSMETIC_WARDROBE_FLAG;
|
||||||
|
|
||||||
public WGHook() {
|
public WGHook() {
|
||||||
@@ -35,10 +44,18 @@ public class WGHook {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the cosmetic enable {@link StateFlag}
|
||||||
|
* @return The cosmetic enable {@link StateFlag}
|
||||||
|
*/
|
||||||
public static StateFlag getCosmeticEnableFlag() {
|
public static StateFlag getCosmeticEnableFlag() {
|
||||||
return COSMETIC_ENABLE_FLAG;
|
return COSMETIC_ENABLE_FLAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the cosmetic wardrobe {@link StateFlag}
|
||||||
|
* @return The cosmetic wardrobe {@link StateFlag}
|
||||||
|
*/
|
||||||
public static StateFlag getCosmeticWardrobeFlag() {
|
public static StateFlag getCosmeticWardrobeFlag() {
|
||||||
return COSMETIC_WARDROBE_FLAG;
|
return COSMETIC_WARDROBE_FLAG;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,11 +12,14 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains {@link com.sk89q.worldguard.WorldGuard WorldGuard} related event listeners
|
||||||
|
*/
|
||||||
public class WGListener implements Listener {
|
public class WGListener implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerMove(PlayerMoveEvent event) {
|
public void onPlayerMove(@NotNull PlayerMoveEvent event) {
|
||||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||||
if (user == null) return;
|
if (user == null) return;
|
||||||
Location location = event.getPlayer().getLocation();
|
Location location = event.getPlayer().getLocation();
|
||||||
@@ -24,16 +27,19 @@ public class WGListener implements Listener {
|
|||||||
RegionContainer region = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
RegionContainer region = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||||
RegionQuery query = region.createQuery();
|
RegionQuery query = region.createQuery();
|
||||||
ApplicableRegionSet set = query.getApplicableRegions(loc);
|
ApplicableRegionSet set = query.getApplicableRegions(loc);
|
||||||
// TODO: Add more cosmetics
|
if (user.getHidden()) {
|
||||||
if (set.getRegions().size() == 0) {
|
if (user.getHiddenReason() == CosmeticUser.HiddenReason.WORLDGUARD && set.getRegions().size() == 0) {
|
||||||
user.showCosmetics();
|
user.showCosmetics();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (ProtectedRegion protectedRegion : set.getRegions()) {
|
for (ProtectedRegion protectedRegion : set.getRegions()) {
|
||||||
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticEnableFlag())) {
|
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticEnableFlag())) {
|
||||||
user.hideCosmetics();
|
if (protectedRegion.getFlags().get(WGHook.getCosmeticEnableFlag()).toString().equalsIgnoreCase("ALLOW")) return;
|
||||||
|
user.hideCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticWardrobeFlag())) {
|
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticWardrobeFlag())) {
|
||||||
|
if (!protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString().equalsIgnoreCase("ALLOW")) return;
|
||||||
user.enterWardrobe();
|
user.enterWardrobe();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.hibiscusmc.hmccosmetics.config.DatabaseSettings;
|
|||||||
import com.hibiscusmc.hmccosmetics.database.Database;
|
import com.hibiscusmc.hmccosmetics.database.Database;
|
||||||
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.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
@@ -13,11 +14,24 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class PlayerConnectionListener implements Listener {
|
public class PlayerConnectionListener implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(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() != null)
|
||||||
|
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 = () -> {
|
Runnable run = () -> {
|
||||||
CosmeticUser user = Database.get(event.getPlayer().getUniqueId());
|
CosmeticUser user = Database.get(event.getPlayer().getUniqueId());
|
||||||
CosmeticUsers.addUser(user);
|
CosmeticUsers.addUser(user);
|
||||||
@@ -34,7 +48,7 @@ public class PlayerConnectionListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
public void onPlayerQuit(@NotNull PlayerQuitEvent event) {
|
||||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||||
if (user == null) { // Remove any passengers if a user failed to initialize. Bugs can cause this to happen
|
if (user == null) { // Remove any passengers if a user failed to initialize. Bugs can cause this to happen
|
||||||
if (!event.getPlayer().getPassengers().isEmpty()) {
|
if (!event.getPlayer().getPassengers().isEmpty()) {
|
||||||
@@ -44,8 +58,13 @@ public class PlayerConnectionListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (user.isInWardrobe()) user.leaveWardrobe();
|
if (user.isInWardrobe()) user.leaveWardrobe();
|
||||||
|
if (user.getUserEmoteManager().isPlayingEmote()) {
|
||||||
|
user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.CONNECTION);
|
||||||
|
event.getPlayer().setInvisible(false);
|
||||||
|
}
|
||||||
Database.save(user);
|
Database.save(user);
|
||||||
user.destroy();
|
user.destroy();
|
||||||
CosmeticUsers.removeUser(user.getUniqueId());
|
CosmeticUsers.removeUser(user.getUniqueId());
|
||||||
|
|||||||
@@ -13,28 +13,33 @@ 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.types.CosmeticArmorType;
|
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticEmoteType;
|
||||||
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
import com.hibiscusmc.hmccosmetics.gui.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 com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
|
||||||
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
|
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Color;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
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.entity.Pose;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.*;
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
|
||||||
import org.bukkit.event.inventory.ClickType;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.event.player.*;
|
import org.bukkit.event.player.*;
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
import org.bukkit.potion.PotionEffectType;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -47,6 +52,7 @@ public class PlayerGameListener implements Listener {
|
|||||||
registerMenuChangeListener();
|
registerMenuChangeListener();
|
||||||
registerPlayerEquipmentListener();
|
registerPlayerEquipmentListener();
|
||||||
registerPlayerArmListener();
|
registerPlayerArmListener();
|
||||||
|
registerEntityUseListener();
|
||||||
|
|
||||||
//registerLookMovement();
|
//registerLookMovement();
|
||||||
//registerMoveListener();
|
//registerMoveListener();
|
||||||
@@ -55,12 +61,20 @@ public class PlayerGameListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerClick(@NotNull InventoryClickEvent event) {
|
public void onPlayerClick(@NotNull InventoryClickEvent event) {
|
||||||
if (event.getClick() != ClickType.SHIFT_LEFT && event.getClick() != ClickType.SHIFT_RIGHT) return;
|
// || !event.getClickedInventory().getType().equals(InventoryType.PLAYER)
|
||||||
|
if (event.getClick().isShiftClick()) return;
|
||||||
|
MessagesUtil.sendDebugMessages("inventoryclickevent");
|
||||||
//if (event.getSlotType() != InventoryType.SlotType.ARMOR) return;
|
//if (event.getSlotType() != InventoryType.SlotType.ARMOR) return;
|
||||||
CosmeticUser user = CosmeticUsers.getUser(event.getWhoClicked().getUniqueId());
|
CosmeticUser user = CosmeticUsers.getUser(event.getWhoClicked().getUniqueId());
|
||||||
if (user == null) return;
|
if (user == null) return;
|
||||||
ItemStack item = event.getCurrentItem();
|
ItemStack item = event.getCurrentItem();
|
||||||
if (item == null) return;
|
if (item == null) return;
|
||||||
|
|
||||||
|
if (Settings.isDestroyLooseCosmetics() && InventoryUtils.isCosmeticItem(event.getCurrentItem())) {
|
||||||
|
MessagesUtil.sendDebugMessages("remvoe item");
|
||||||
|
event.getWhoClicked().getInventory().removeItem(event.getCurrentItem());
|
||||||
|
}
|
||||||
|
|
||||||
EquipmentSlot slot = getArmorSlot(item.getType());
|
EquipmentSlot slot = getArmorSlot(item.getType());
|
||||||
if (slot == null) return;
|
if (slot == null) return;
|
||||||
CosmeticSlot cosmeticSlot = InventoryUtils.BukkitCosmeticSlot(slot);
|
CosmeticSlot cosmeticSlot = InventoryUtils.BukkitCosmeticSlot(slot);
|
||||||
@@ -76,8 +90,12 @@ public class PlayerGameListener implements Listener {
|
|||||||
public void onPlayerShift(PlayerToggleSneakEvent event) {
|
public void onPlayerShift(PlayerToggleSneakEvent event) {
|
||||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
|
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
|
||||||
|
|
||||||
if (!event.isSneaking()) return;
|
|
||||||
if (user == null) return;
|
if (user == null) return;
|
||||||
|
if (event.isSneaking()) {
|
||||||
|
user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.SNEAK);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!event.isSneaking()) return;
|
||||||
if (!user.isInWardrobe()) return;
|
if (!user.isInWardrobe()) return;
|
||||||
|
|
||||||
user.leaveWardrobe();
|
user.leaveWardrobe();
|
||||||
@@ -93,10 +111,10 @@ public class PlayerGameListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK) && user.getUserBackpackManager() != null) {
|
||||||
user.hideBackpack();
|
user.getUserBackpackManager().hideBackpack();
|
||||||
|
|
||||||
user.getBackpackEntity().teleport(event.getTo());
|
user.getUserBackpackManager().getArmorStand().teleport(event.getTo());
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||||
user.updateCosmetic();
|
user.updateCosmetic();
|
||||||
@@ -106,10 +124,15 @@ public class PlayerGameListener implements Listener {
|
|||||||
if (event.getCause().equals(PlayerTeleportEvent.TeleportCause.NETHER_PORTAL) || event.getCause().equals(PlayerTeleportEvent.TeleportCause.END_PORTAL)) return;
|
if (event.getCause().equals(PlayerTeleportEvent.TeleportCause.NETHER_PORTAL) || event.getCause().equals(PlayerTeleportEvent.TeleportCause.END_PORTAL)) return;
|
||||||
|
|
||||||
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
||||||
|
final CosmeticBalloonType cosmeticBalloonType = (CosmeticBalloonType) user.getCosmetic(CosmeticSlot.BALLOON);
|
||||||
|
user.despawnBalloon();
|
||||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||||
user.updateCosmetic(CosmeticSlot.BALLOON);
|
user.spawnBalloon(cosmeticBalloonType);
|
||||||
}, 2);
|
}, 2);
|
||||||
}
|
}
|
||||||
|
if (user.getUserEmoteManager().isPlayingEmote()) {
|
||||||
|
user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.TELEPORT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@@ -122,14 +145,14 @@ public class PlayerGameListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Cosmetic cosmetic = user.getCosmetic(CosmeticSlot.BALLOON);
|
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
||||||
final Color color = user.getCosmeticColor(CosmeticSlot.BALLOON);
|
user.despawnBalloon();
|
||||||
user.removeCosmeticSlot(CosmeticSlot.BALLOON);
|
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||||
user.addPlayerCosmetic(cosmetic, color);
|
user.spawnBalloon((CosmeticBalloonType) user.getCosmetic(CosmeticSlot.BALLOON));
|
||||||
user.updateCosmetic();
|
user.updateCosmetic();
|
||||||
}, 4);
|
}, 4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@@ -142,16 +165,67 @@ public class PlayerGameListener implements Listener {
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerDamaged(EntityDamageEvent event) {
|
||||||
|
if (event.isCancelled()) return;
|
||||||
|
if (!(event.getEntity() instanceof Player)) return;
|
||||||
|
Player player = ((Player) event.getEntity()).getPlayer();
|
||||||
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
|
if (user == null) return;
|
||||||
|
if (user.getUserEmoteManager().isPlayingEmote()) {
|
||||||
|
if (Settings.isEmoteInvincible()) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
if (Settings.isEmoteDamageLeave()) {
|
||||||
|
user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.DAMAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (user.isInWardrobe()) {
|
||||||
|
user.leaveWardrobe();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerLook(PlayerMoveEvent event) {
|
public void onPlayerLook(PlayerMoveEvent event) {
|
||||||
|
if (event.isCancelled()) return;
|
||||||
|
Player player = event.getPlayer();
|
||||||
// TODO: Move to packets
|
// TODO: Move to packets
|
||||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
if (user == null) return;
|
if (user == null) return;
|
||||||
// Really need to look into optimization of this
|
// Really need to look into optimization of this
|
||||||
user.updateCosmetic(CosmeticSlot.BACKPACK);
|
user.updateCosmetic(CosmeticSlot.BACKPACK);
|
||||||
user.updateCosmetic(CosmeticSlot.BALLOON);
|
user.updateCosmetic(CosmeticSlot.BALLOON);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerPoseChange(EntityPoseChangeEvent event) {
|
||||||
|
if (!(event.getEntity() instanceof Player)) return;
|
||||||
|
Player player = ((Player) event.getEntity()).getPlayer();
|
||||||
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
|
if (user == null) return;
|
||||||
|
if (!user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) return;
|
||||||
|
Pose pose = event.getPose();
|
||||||
|
if (pose.equals(Pose.STANDING)) {
|
||||||
|
// #84, Riptides mess with backpacks
|
||||||
|
ItemStack currentItem = player.getInventory().getItemInMainHand();
|
||||||
|
if (currentItem != null) {
|
||||||
|
if (currentItem.hasItemMeta()) {
|
||||||
|
if (currentItem.containsEnchantment(Enchantment.RIPTIDE)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!user.isBackpackSpawned()) {
|
||||||
|
user.spawnBackpack((CosmeticBackpackType) user.getCosmetic(CosmeticSlot.BACKPACK));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (pose.equals(Pose.SLEEPING) || pose.equals(Pose.SWIMMING) || pose.equals(Pose.FALL_FLYING) || pose.equals(Pose.SPIN_ATTACK)) {
|
||||||
|
user.despawnBackpack();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerArmorDamage(PlayerItemDamageEvent event) {
|
public void onPlayerArmorDamage(PlayerItemDamageEvent event) {
|
||||||
// Possibly look into cancelling the event, then handling the damage on our own.
|
// Possibly look into cancelling the event, then handling the damage on our own.
|
||||||
@@ -191,11 +265,43 @@ public class PlayerGameListener implements Listener {
|
|||||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
|
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
|
||||||
if (user == null) return;
|
if (user == null) return;
|
||||||
// Really need to look into optimization of this
|
// Really need to look into optimization of this
|
||||||
|
if (user.hasCosmeticInSlot(CosmeticSlot.EMOTE) && event.getPlayer().isSneaking() && event.getPlayer().hasPermission("hmccosmetics.emote.shiftrun")) {
|
||||||
|
CosmeticEmoteType cosmeticEmoteType = (CosmeticEmoteType) user.getCosmetic(CosmeticSlot.EMOTE);
|
||||||
|
cosmeticEmoteType.run(user);
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||||
user.updateCosmetic(CosmeticSlot.OFFHAND);
|
user.updateCosmetic(CosmeticSlot.OFFHAND);
|
||||||
}, 2);
|
}, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerPickupItem(EntityPickupItemEvent event) {
|
||||||
|
if (!(event.getEntity() instanceof Player)) return;
|
||||||
|
CosmeticUser user = CosmeticUsers.getUser(event.getEntity().getUniqueId());
|
||||||
|
if (user == null) return;
|
||||||
|
if (user.isInWardrobe()) event.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void playerInvisibility(EntityPotionEffectEvent event) {
|
||||||
|
if (event.isCancelled()) return;
|
||||||
|
if (!event.getModifiedType().equals(PotionEffectType.INVISIBILITY)) return;
|
||||||
|
if (!event.getEntityType().equals(EntityType.PLAYER)) return;
|
||||||
|
Player player = (Player) event.getEntity();
|
||||||
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
|
if (user == null) return;
|
||||||
|
if (event.getAction().equals(EntityPotionEffectEvent.Action.ADDED)) {
|
||||||
|
user.hideCosmetics(CosmeticUser.HiddenReason.POTION);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.getAction().equals(EntityPotionEffectEvent.Action.CLEARED) || event.getAction().equals(EntityPotionEffectEvent.Action.REMOVED)) {
|
||||||
|
user.showCosmetics();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onMainHandSwitch(PlayerItemHeldEvent event) {
|
public void onMainHandSwitch(PlayerItemHeldEvent event) {
|
||||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||||
@@ -207,6 +313,14 @@ public class PlayerGameListener implements Listener {
|
|||||||
user.updateCosmetic(CosmeticSlot.MAINHAND);
|
user.updateCosmetic(CosmeticSlot.MAINHAND);
|
||||||
user.updateCosmetic(CosmeticSlot.OFFHAND);
|
user.updateCosmetic(CosmeticSlot.OFFHAND);
|
||||||
}, 2);
|
}, 2);
|
||||||
|
|
||||||
|
// #84, Riptides mess with backpacks
|
||||||
|
ItemStack currentItem = event.getPlayer().getInventory().getItem(event.getNewSlot());
|
||||||
|
if (currentItem == null) return;
|
||||||
|
if (!currentItem.hasItemMeta()) return;
|
||||||
|
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK) && currentItem.containsEnchantment(Enchantment.RIPTIDE)) {
|
||||||
|
user.despawnBackpack();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@@ -214,11 +328,27 @@ public class PlayerGameListener implements Listener {
|
|||||||
CosmeticUser user = CosmeticUsers.getUser(event.getEntity());
|
CosmeticUser user = CosmeticUsers.getUser(event.getEntity());
|
||||||
if (user == null) return;
|
if (user == null) return;
|
||||||
|
|
||||||
|
if (user.isInWardrobe()) user.leaveWardrobe();
|
||||||
|
|
||||||
if (Settings.getUnapplyOnDeath() && !event.getEntity().hasPermission("hmccosmetics.unapplydeath.bypass")) {
|
if (Settings.getUnapplyOnDeath() && !event.getEntity().hasPermission("hmccosmetics.unapplydeath.bypass")) {
|
||||||
user.removeCosmetics();
|
user.removeCosmetics();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerGamemodeSwitch(PlayerGameModeChangeEvent event) {
|
||||||
|
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||||
|
if (user == null) return;
|
||||||
|
|
||||||
|
if (Settings.isDestroyLooseCosmetics()) {
|
||||||
|
ItemStack[] equippedArmor = event.getPlayer().getInventory().getArmorContents();
|
||||||
|
if (equippedArmor.length == 0) return;
|
||||||
|
for (ItemStack armor : equippedArmor) {
|
||||||
|
if (InventoryUtils.isCosmeticItem(armor)) armor.setAmount(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void registerInventoryClickListener() {
|
private void registerInventoryClickListener() {
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.WINDOW_CLICK) {
|
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.WINDOW_CLICK) {
|
||||||
@Override
|
@Override
|
||||||
@@ -262,7 +392,7 @@ public class PlayerGameListener implements Listener {
|
|||||||
|
|
||||||
HashMap<Integer, ItemStack> items = new HashMap<>();
|
HashMap<Integer, ItemStack> items = new HashMap<>();
|
||||||
|
|
||||||
for (Cosmetic cosmetic : user.getCosmetic()) {
|
for (Cosmetic cosmetic : user.getCosmetics()) {
|
||||||
if ((cosmetic instanceof CosmeticArmorType cosmeticArmorType)) {
|
if ((cosmetic instanceof CosmeticArmorType cosmeticArmorType)) {
|
||||||
items.put(InventoryUtils.getPacketArmorSlot(cosmeticArmorType.getEquipSlot()), user.getUserCosmeticItem(cosmeticArmorType));
|
items.put(InventoryUtils.getPacketArmorSlot(cosmeticArmorType.getEquipSlot()), user.getUserCosmeticItem(cosmeticArmorType));
|
||||||
}
|
}
|
||||||
@@ -278,6 +408,7 @@ public class PlayerGameListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
packet.getItemListModifier().write(0, slotData);
|
packet.getItemListModifier().write(0, slotData);
|
||||||
|
packet.getItemModifier().write(0, event.getPacket().getItemModifier().read(0));
|
||||||
event.setPacket(packet);
|
event.setPacket(packet);
|
||||||
MessagesUtil.sendDebugMessages("Menu Fired, updated cosmetics " + " on slotdata " + windowID + " with " + slotData.size());
|
MessagesUtil.sendDebugMessages("Menu Fired, updated cosmetics " + " on slotdata " + windowID + " with " + slotData.size());
|
||||||
/*
|
/*
|
||||||
@@ -298,13 +429,11 @@ public class PlayerGameListener implements Listener {
|
|||||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.ENTITY_EQUIPMENT) {
|
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.ENTITY_EQUIPMENT) {
|
||||||
@Override
|
@Override
|
||||||
public void onPacketSending(PacketEvent event) {
|
public void onPacketSending(PacketEvent event) {
|
||||||
MessagesUtil.sendDebugMessages("equipment packet is activated");
|
|
||||||
Player player = event.getPlayer(); // Player that's sent
|
Player player = event.getPlayer(); // Player that's sent
|
||||||
int entityID = event.getPacket().getIntegers().read(0);
|
int entityID = event.getPacket().getIntegers().read(0);
|
||||||
// User
|
// User
|
||||||
CosmeticUser user = CosmeticUsers.getUser(entityID);
|
CosmeticUser user = CosmeticUsers.getUser(entityID);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
MessagesUtil.sendDebugMessages("equipment packet is activated - user null");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -331,8 +460,12 @@ public class PlayerGameListener implements Listener {
|
|||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
if (user == null) return;
|
if (user == null) return;
|
||||||
|
if (user.getUserEmoteManager().isPlayingEmote()) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!user.isInWardrobe()) return;
|
if (!user.isInWardrobe()) return;
|
||||||
Menu menu = Menus.getMenu(Settings.getDefaultMenu());
|
Menu menu = Menus.getDefaultMenu();
|
||||||
if (menu == null) return;
|
if (menu == null) return;
|
||||||
menu.openMenu(user);
|
menu.openMenu(user);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@@ -340,6 +473,21 @@ public class PlayerGameListener implements Listener {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void registerEntityUseListener() {
|
||||||
|
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.USE_ENTITY) {
|
||||||
|
@Override
|
||||||
|
public void onPacketReceiving(PacketEvent event) {
|
||||||
|
if (!(event.getPlayer() instanceof Player)) return;
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
|
if (user == null) return;
|
||||||
|
if (user.getUserEmoteManager().isPlayingEmote() || user.isInWardrobe()) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void registerLookMovement() {
|
private void registerLookMovement() {
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.LOOK) {
|
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.LOOK) {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -3,9 +3,10 @@ package com.hibiscusmc.hmccosmetics.nms;
|
|||||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
|
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
||||||
import com.hibiscusmc.hmccosmetics.entities.BalloonEntity;
|
import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.ArmorStand;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@@ -18,13 +19,15 @@ public interface NMSHandler {
|
|||||||
|
|
||||||
Entity getEntity(int entityId);
|
Entity getEntity(int entityId);
|
||||||
|
|
||||||
Entity getInvisibleArmorstand(Location loc);
|
Entity getHMCArmorStand(Location loc);
|
||||||
|
|
||||||
Entity getMEGEntity(Location loc);
|
ArmorStand getMEGEntity(Location loc);
|
||||||
|
|
||||||
Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType);
|
Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType);
|
||||||
|
|
||||||
BalloonEntity spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType);
|
Entity spawnHMCParticleCloud(Location location);
|
||||||
|
|
||||||
|
UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType);
|
||||||
|
|
||||||
void equipmentSlotUpdate(
|
void equipmentSlotUpdate(
|
||||||
int entityId,
|
int entityId,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import java.util.logging.Level;
|
|||||||
|
|
||||||
public class NMSHandlers {
|
public class NMSHandlers {
|
||||||
|
|
||||||
private static final String[] SUPPORTED_VERSION = new String[]{"v1_19_R1", "v1_19_R2"};
|
private static final String[] SUPPORTED_VERSION = new String[]{"v1_17_R1", "v1_18_R2", "v1_19_R1", "v1_19_R2", "v1_19_R3"};
|
||||||
private static NMSHandler handler;
|
private static NMSHandler handler;
|
||||||
private static String version;
|
private static String version;
|
||||||
|
|
||||||
@@ -34,10 +34,9 @@ public class NMSHandlers {
|
|||||||
if (!selectedVersion.contains(packageVersion)) {
|
if (!selectedVersion.contains(packageVersion)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
MessagesUtil.sendDebugMessages(packageVersion + " has been detected.", Level.SEVERE);
|
MessagesUtil.sendDebugMessages(packageVersion + " has been detected.", Level.INFO);
|
||||||
version = packageVersion;
|
version = packageVersion;
|
||||||
try {
|
try {
|
||||||
//Class.forName("org.bukkit.craftbukkit." + version + ".block.CraftBlock").getName();
|
|
||||||
handler = (NMSHandler) Class.forName("com.hibiscusmc.hmccosmetics.nms." + packageVersion + ".NMSHandler").getConstructor().newInstance();
|
handler = (NMSHandler) Class.forName("com.hibiscusmc.hmccosmetics.nms." + packageVersion + ".NMSHandler").getConstructor().newInstance();
|
||||||
return;
|
return;
|
||||||
} catch (ClassNotFoundException | InvocationTargetException | InstantiationException |
|
} catch (ClassNotFoundException | InvocationTargetException | InstantiationException |
|
||||||
|
|||||||
@@ -1,30 +1,28 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.user;
|
package com.hibiscusmc.hmccosmetics.user;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableCollection;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
import com.hibiscusmc.hmccosmetics.api.*;
|
import com.hibiscusmc.hmccosmetics.api.*;
|
||||||
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.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.types.CosmeticArmorType;
|
import com.hibiscusmc.hmccosmetics.cosmetic.types.*;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
|
import com.hibiscusmc.hmccosmetics.user.manager.UserBackpackManager;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticMainhandType;
|
|
||||||
import com.hibiscusmc.hmccosmetics.entities.BalloonEntity;
|
|
||||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.manager.UserWardrobeManager;
|
||||||
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
|
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
|
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
|
||||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.*;
|
||||||
import org.bukkit.Color;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.ArmorStand;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.*;
|
||||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -35,28 +33,26 @@ public class CosmeticUser {
|
|||||||
private UUID uniqueId;
|
private UUID uniqueId;
|
||||||
private int taskId;
|
private int taskId;
|
||||||
private HashMap<CosmeticSlot, Cosmetic> playerCosmetics = new HashMap<>();
|
private HashMap<CosmeticSlot, Cosmetic> playerCosmetics = new HashMap<>();
|
||||||
private Wardrobe wardrobe;
|
private UserWardrobeManager userWardrobeManager;
|
||||||
private ArmorStand invisibleArmorstand;
|
private UserBalloonManager userBalloonManager;
|
||||||
private BalloonEntity balloonEntity;
|
private UserBackpackManager userBackpackManager;
|
||||||
|
private UserEmoteManager userEmoteManager;
|
||||||
|
|
||||||
// Cosmetic Settings/Toggles
|
// Cosmetic Settings/Toggles
|
||||||
private boolean hideBackpack;
|
|
||||||
private boolean hideCosmetics;
|
private boolean hideCosmetics;
|
||||||
|
private HiddenReason hiddenReason;
|
||||||
private HashMap<CosmeticSlot, Color> colors = new HashMap<>();
|
private HashMap<CosmeticSlot, Color> colors = new HashMap<>();
|
||||||
|
|
||||||
public CosmeticUser() {
|
|
||||||
// Empty
|
|
||||||
}
|
|
||||||
|
|
||||||
public CosmeticUser(UUID uuid) {
|
public CosmeticUser(UUID uuid) {
|
||||||
this.uniqueId = uuid;
|
this.uniqueId = uuid;
|
||||||
|
userEmoteManager = new UserEmoteManager(this);
|
||||||
tick();
|
tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tick() {
|
private void tick() {
|
||||||
// Occasionally updates the entity cosmetics
|
// Occasionally updates the entity cosmetics
|
||||||
Runnable run = () -> {
|
Runnable run = () -> {
|
||||||
MessagesUtil.sendDebugMessages("tick " + uniqueId, Level.INFO);
|
MessagesUtil.sendDebugMessages("Tick[" + uniqueId + "]", Level.INFO);
|
||||||
updateCosmetic();
|
updateCosmetic();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -81,19 +77,13 @@ public class CosmeticUser {
|
|||||||
return playerCosmetics.get(slot);
|
return playerCosmetics.get(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public Collection<Cosmetic> getCosmetic() {
|
public Collection<Cosmetic> getCosmetic() {
|
||||||
return playerCosmetics.values();
|
return playerCosmetics.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getArmorstandId() {
|
public ImmutableCollection<Cosmetic> getCosmetics() {
|
||||||
return invisibleArmorstand.getEntityId();
|
return ImmutableList.copyOf(playerCosmetics.values());
|
||||||
}
|
|
||||||
|
|
||||||
public Entity getBackpackEntity() {
|
|
||||||
return this.invisibleArmorstand;
|
|
||||||
}
|
|
||||||
public BalloonEntity getBalloonEntity() {
|
|
||||||
return this.balloonEntity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPlayerCosmetic(Cosmetic cosmetic) {
|
public void addPlayerCosmetic(Cosmetic cosmetic) {
|
||||||
@@ -115,24 +105,17 @@ public class CosmeticUser {
|
|||||||
|
|
||||||
playerCosmetics.put(cosmetic.getSlot(), cosmetic);
|
playerCosmetics.put(cosmetic.getSlot(), cosmetic);
|
||||||
if (color != null) colors.put(cosmetic.getSlot(), color);
|
if (color != null) colors.put(cosmetic.getSlot(), color);
|
||||||
MessagesUtil.sendDebugMessages("addPlayerCosmetic " + cosmetic.getId());
|
MessagesUtil.sendDebugMessages("addPlayerCosmetic[id=" + cosmetic.getId() + "]");
|
||||||
if (cosmetic.getSlot() == CosmeticSlot.BACKPACK) {
|
if (cosmetic.getSlot() == CosmeticSlot.BACKPACK) {
|
||||||
CosmeticBackpackType backpackType = (CosmeticBackpackType) cosmetic;
|
CosmeticBackpackType backpackType = (CosmeticBackpackType) cosmetic;
|
||||||
spawnBackpack(backpackType);
|
spawnBackpack(backpackType);
|
||||||
MessagesUtil.sendDebugMessages("addPlayerCosmetic spawnBackpack " + cosmetic.getId());
|
MessagesUtil.sendDebugMessages("addPlayerCosmetic[spawnBackpack,id=" + cosmetic.getId() + "]");
|
||||||
}
|
}
|
||||||
if (cosmetic.getSlot() == CosmeticSlot.BALLOON) {
|
if (cosmetic.getSlot() == CosmeticSlot.BALLOON) {
|
||||||
CosmeticBalloonType balloonType = (CosmeticBalloonType) cosmetic;
|
CosmeticBalloonType balloonType = (CosmeticBalloonType) cosmetic;
|
||||||
spawnBalloon(balloonType);
|
spawnBalloon(balloonType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void toggleCosmetic(Cosmetic cosmetic) {
|
|
||||||
if (hasCosmeticInSlot(cosmetic.getSlot())) {
|
|
||||||
removeCosmeticSlot(cosmetic.getSlot());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
addPlayerCosmetic(cosmetic);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeCosmetics() {
|
public void removeCosmetics() {
|
||||||
// Small optimization could be made, but Concurrent modification prevents us from both getting and removing
|
// Small optimization could be made, but Concurrent modification prevents us from both getting and removing
|
||||||
@@ -155,6 +138,9 @@ public class CosmeticUser {
|
|||||||
}
|
}
|
||||||
if (slot == CosmeticSlot.BALLOON) {
|
if (slot == CosmeticSlot.BALLOON) {
|
||||||
despawnBalloon();
|
despawnBalloon();
|
||||||
|
}
|
||||||
|
if (slot == CosmeticSlot.EMOTE) {
|
||||||
|
|
||||||
}
|
}
|
||||||
colors.remove(slot);
|
colors.remove(slot);
|
||||||
playerCosmetics.remove(slot);
|
playerCosmetics.remove(slot);
|
||||||
@@ -170,6 +156,10 @@ public class CosmeticUser {
|
|||||||
return playerCosmetics.containsKey(slot);
|
return playerCosmetics.containsKey(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<CosmeticSlot> getSlotsWithCosmetics() {
|
||||||
|
return Set.copyOf(playerCosmetics.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
public void updateCosmetic(CosmeticSlot slot) {
|
public void updateCosmetic(CosmeticSlot slot) {
|
||||||
if (getCosmetic(slot) == null) {
|
if (getCosmetic(slot) == null) {
|
||||||
return;
|
return;
|
||||||
@@ -191,6 +181,7 @@ public class CosmeticUser {
|
|||||||
public ItemStack getUserCosmeticItem(Cosmetic cosmetic) {
|
public ItemStack getUserCosmeticItem(Cosmetic cosmetic) {
|
||||||
ItemStack item = null;
|
ItemStack item = null;
|
||||||
if (hideCosmetics) {
|
if (hideCosmetics) {
|
||||||
|
if (cosmetic instanceof CosmeticBackpackType || cosmetic instanceof CosmeticBalloonType) return new ItemStack(Material.AIR);
|
||||||
return getPlayer().getInventory().getItem(InventoryUtils.getEquipmentSlot(cosmetic.getSlot()));
|
return getPlayer().getInventory().getItem(InventoryUtils.getEquipmentSlot(cosmetic.getSlot()));
|
||||||
}
|
}
|
||||||
if (cosmetic instanceof CosmeticArmorType || cosmetic instanceof CosmeticMainhandType || cosmetic instanceof CosmeticBackpackType) {
|
if (cosmetic instanceof CosmeticArmorType || cosmetic instanceof CosmeticMainhandType || cosmetic instanceof CosmeticBackpackType) {
|
||||||
@@ -209,18 +200,50 @@ public class CosmeticUser {
|
|||||||
}
|
}
|
||||||
if (item.hasItemMeta()) {
|
if (item.hasItemMeta()) {
|
||||||
ItemMeta itemMeta = item.getItemMeta();
|
ItemMeta itemMeta = item.getItemMeta();
|
||||||
if (itemMeta instanceof LeatherArmorMeta) {
|
if (colors.containsKey(cosmetic.getSlot())) {
|
||||||
if (colors.containsKey(cosmetic.getSlot())) {
|
Color color = colors.get(cosmetic.getSlot());
|
||||||
((LeatherArmorMeta) itemMeta).setColor(colors.get(cosmetic.getSlot()));
|
if (itemMeta instanceof LeatherArmorMeta leatherMeta) {
|
||||||
|
leatherMeta.setColor(color);
|
||||||
|
} else if (itemMeta instanceof PotionMeta potionMeta) {
|
||||||
|
potionMeta.setColor(color);
|
||||||
|
} else if (itemMeta instanceof MapMeta mapMeta) {
|
||||||
|
mapMeta.setColor(color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
itemMeta.getPersistentDataContainer().set(InventoryUtils.getCosmeticKey(), PersistentDataType.STRING, cosmetic.getId());
|
||||||
|
itemMeta.getPersistentDataContainer().set(InventoryUtils.getOwnerKey(), PersistentDataType.STRING, getPlayer().getUniqueId().toString());
|
||||||
|
|
||||||
item.setItemMeta(itemMeta);
|
item.setItemMeta(itemMeta);
|
||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UserBackpackManager getUserBackpackManager() {
|
||||||
|
return userBackpackManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserBalloonManager getBalloonManager() {
|
||||||
|
return this.userBalloonManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserWardrobeManager getWardrobeManager() {
|
||||||
|
return userWardrobeManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserEmoteManager getUserEmoteManager() {
|
||||||
|
return userEmoteManager;
|
||||||
|
}
|
||||||
|
|
||||||
public void enterWardrobe() {
|
public void enterWardrobe() {
|
||||||
if (!WardrobeSettings.inDistanceOfStatic(getPlayer().getLocation())) {
|
enterWardrobe(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enterWardrobe(boolean ignoreDistance) {
|
||||||
|
enterWardrobe(ignoreDistance, WardrobeSettings.getLeaveLocation(), WardrobeSettings.getViewerLocation(), WardrobeSettings.getWardrobeLocation());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enterWardrobe(boolean ignoreDistance, Location exitLocation, Location viewingLocation, Location npcLocation) {
|
||||||
|
if (!WardrobeSettings.inDistanceOfStatic(getPlayer().getLocation()) && !ignoreDistance) {
|
||||||
MessagesUtil.sendMessage(getPlayer(), "not-near-wardrobe");
|
MessagesUtil.sendMessage(getPlayer(), "not-near-wardrobe");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -230,29 +253,43 @@ public class CosmeticUser {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wardrobe == null) {
|
if (userWardrobeManager == null) {
|
||||||
wardrobe = new Wardrobe(this);
|
userWardrobeManager = new UserWardrobeManager(this, exitLocation, viewingLocation, npcLocation);
|
||||||
wardrobe.start();
|
userWardrobeManager.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Wardrobe getWardrobe() {
|
|
||||||
return wardrobe;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void leaveWardrobe() {
|
public void leaveWardrobe() {
|
||||||
PlayerWardrobeLeaveEvent event = new PlayerWardrobeLeaveEvent(this);
|
PlayerWardrobeLeaveEvent event = new PlayerWardrobeLeaveEvent(this);
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
MessagesUtil.sendDebugMessages("Leaving Wardrobe");
|
||||||
|
if (!getWardrobeManager().getWardrobeStatus().equals(UserWardrobeManager.WardrobeStatus.RUNNING)) return;
|
||||||
|
|
||||||
wardrobe.end();
|
getWardrobeManager().setWardrobeStatus(UserWardrobeManager.WardrobeStatus.STOPPING);
|
||||||
wardrobe = null;
|
|
||||||
|
if (WardrobeSettings.isEnabledTransition()) {
|
||||||
|
MessagesUtil.sendTitle(
|
||||||
|
getPlayer(),
|
||||||
|
WardrobeSettings.getTransitionText(),
|
||||||
|
WardrobeSettings.getTransitionFadeIn(),
|
||||||
|
WardrobeSettings.getTransitionStay(),
|
||||||
|
WardrobeSettings.getTransitionFadeOut()
|
||||||
|
);
|
||||||
|
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||||
|
userWardrobeManager.end();
|
||||||
|
userWardrobeManager = null;
|
||||||
|
}, WardrobeSettings.getTransitionDelay());
|
||||||
|
} else {
|
||||||
|
userWardrobeManager.end();
|
||||||
|
userWardrobeManager = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInWardrobe() {
|
public boolean isInWardrobe() {
|
||||||
if (wardrobe == null) return false;
|
if (userWardrobeManager == null) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,45 +302,55 @@ public class CosmeticUser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void spawnBackpack(CosmeticBackpackType cosmeticBackpackType) {
|
public void spawnBackpack(CosmeticBackpackType cosmeticBackpackType) {
|
||||||
MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Start");
|
if (this.userBackpackManager != null) return;
|
||||||
Player player = Bukkit.getPlayer(getUniqueId());
|
this.userBackpackManager = new UserBackpackManager(this, cosmeticBackpackType.getBackpackType());
|
||||||
|
userBackpackManager.spawnBackpack(cosmeticBackpackType);
|
||||||
|
}
|
||||||
|
|
||||||
if (this.invisibleArmorstand != null) return;
|
public void despawnBackpack() {
|
||||||
|
if (userBackpackManager == null) return;
|
||||||
|
userBackpackManager.despawnBackpack();
|
||||||
|
userBackpackManager = null;
|
||||||
|
}
|
||||||
|
|
||||||
this.invisibleArmorstand = (ArmorStand) NMSHandlers.getHandler().spawnBackpack(this, cosmeticBackpackType);
|
public boolean isBackpackSpawned() {
|
||||||
|
if (this.userBackpackManager == null) return false;
|
||||||
MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Finish");
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void spawnBalloon(CosmeticBalloonType cosmeticBalloonType) {
|
public void spawnBalloon(CosmeticBalloonType cosmeticBalloonType) {
|
||||||
Player player = Bukkit.getPlayer(getUniqueId());
|
Player player = Bukkit.getPlayer(getUniqueId());
|
||||||
|
|
||||||
if (this.balloonEntity != null) return;
|
if (this.userBalloonManager != null) return;
|
||||||
|
|
||||||
this.balloonEntity = NMSHandlers.getHandler().spawnBalloon(this, cosmeticBalloonType);
|
this.userBalloonManager = NMSHandlers.getHandler().spawnBalloon(this, cosmeticBalloonType);
|
||||||
|
|
||||||
List<Player> viewer = PlayerUtils.getNearbyPlayers(player);
|
List<Player> viewer = PlayerUtils.getNearbyPlayers(player);
|
||||||
viewer.add(player);
|
viewer.add(player);
|
||||||
|
|
||||||
PacketManager.sendLeashPacket(getBalloonEntity().getPufferfishBalloonId(), player.getEntityId(), viewer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void despawnBalloon() {
|
public void despawnBalloon() {
|
||||||
if (this.balloonEntity == null) return;
|
if (this.userBalloonManager == null) return;
|
||||||
List<Player> sentTo = PlayerUtils.getNearbyPlayers(getPlayer().getLocation());
|
List<Player> sentTo = PlayerUtils.getNearbyPlayers(getPlayer().getLocation());
|
||||||
|
|
||||||
PacketManager.sendEntityDestroyPacket(balloonEntity.getPufferfishBalloonId(), sentTo);
|
PacketManager.sendEntityDestroyPacket(userBalloonManager.getPufferfishBalloonId(), sentTo);
|
||||||
|
|
||||||
this.balloonEntity.remove();
|
this.userBalloonManager.remove();
|
||||||
this.balloonEntity = null;
|
this.userBalloonManager = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void despawnBackpack() {
|
public void respawnBackpack() {
|
||||||
Player player = Bukkit.getPlayer(getUniqueId());
|
if (!hasCosmeticInSlot(CosmeticSlot.BACKPACK)) return;
|
||||||
if (invisibleArmorstand == null) return;
|
final Cosmetic cosmetic = getCosmetic(CosmeticSlot.BACKPACK);
|
||||||
invisibleArmorstand.setHealth(0);
|
despawnBackpack();
|
||||||
invisibleArmorstand.remove();
|
spawnBackpack((CosmeticBackpackType) cosmetic);
|
||||||
this.invisibleArmorstand = null;
|
}
|
||||||
|
|
||||||
|
public void respawnBalloon() {
|
||||||
|
if (!hasCosmeticInSlot(CosmeticSlot.BALLOON)) return;
|
||||||
|
final Cosmetic cosmetic = getCosmetic(CosmeticSlot.BALLOON);
|
||||||
|
despawnBalloon();
|
||||||
|
spawnBalloon((CosmeticBalloonType) cosmetic);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeArmor(CosmeticSlot slot) {
|
public void removeArmor(CosmeticSlot slot) {
|
||||||
@@ -321,7 +368,7 @@ public class CosmeticUser {
|
|||||||
public List<CosmeticSlot> getDyeableSlots() {
|
public List<CosmeticSlot> getDyeableSlots() {
|
||||||
ArrayList<CosmeticSlot> dyableSlots = new ArrayList();
|
ArrayList<CosmeticSlot> dyableSlots = new ArrayList();
|
||||||
|
|
||||||
for (Cosmetic cosmetic : getCosmetic()) {
|
for (Cosmetic cosmetic : getCosmetics()) {
|
||||||
if (cosmetic.isDyable()) dyableSlots.add(cosmetic.getSlot());
|
if (cosmetic.isDyable()) dyableSlots.add(cosmetic.getSlot());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,40 +399,22 @@ public class CosmeticUser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hideBackpack() {
|
public void hideCosmetics(HiddenReason reason) {
|
||||||
if (hideBackpack == true) return;
|
|
||||||
if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
|
||||||
invisibleArmorstand.getEquipment().clear();
|
|
||||||
hideBackpack = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void showBackpack() {
|
|
||||||
if (hideBackpack == false) return;
|
|
||||||
if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
|
||||||
CosmeticBackpackType cosmeticBackpackType = (CosmeticBackpackType) getCosmetic(CosmeticSlot.BACKPACK);
|
|
||||||
ItemStack item = getUserCosmeticItem(cosmeticBackpackType);
|
|
||||||
invisibleArmorstand.getEquipment().setHelmet(item);
|
|
||||||
hideBackpack = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void hideCosmetics() {
|
|
||||||
if (hideCosmetics == true) return;
|
if (hideCosmetics == true) return;
|
||||||
PlayerCosmeticHideEvent event = new PlayerCosmeticHideEvent(this);
|
PlayerCosmeticHideEvent event = new PlayerCosmeticHideEvent(this, reason);
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
hideCosmetics = true;
|
hideCosmetics = true;
|
||||||
|
hiddenReason = reason;
|
||||||
if (hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
if (hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
||||||
getBalloonEntity().removePlayerFromModel(getPlayer());
|
getBalloonManager().removePlayerFromModel(getPlayer());
|
||||||
List<Player> viewer = PlayerUtils.getNearbyPlayers(getPlayer());
|
getBalloonManager().sendRemoveLeashPacket();
|
||||||
PacketManager.sendLeashPacket(getBalloonEntity().getPufferfishBalloonId(), -1, viewer);
|
|
||||||
}
|
}
|
||||||
if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
||||||
invisibleArmorstand.getEquipment().clear();
|
userBackpackManager.clearItems();
|
||||||
}
|
}
|
||||||
updateCosmetic();
|
updateCosmetic();
|
||||||
MessagesUtil.sendDebugMessages("HideCosmetics");
|
MessagesUtil.sendDebugMessages("HideCosmetics");
|
||||||
@@ -399,17 +428,19 @@ public class CosmeticUser {
|
|||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
hideCosmetics = false;
|
hideCosmetics = false;
|
||||||
|
hiddenReason = HiddenReason.NONE;
|
||||||
if (hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
if (hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
||||||
CosmeticBalloonType balloonType = (CosmeticBalloonType) getCosmetic(CosmeticSlot.BALLOON);
|
CosmeticBalloonType balloonType = (CosmeticBalloonType) getCosmetic(CosmeticSlot.BALLOON);
|
||||||
getBalloonEntity().addPlayerToModel(getPlayer(), balloonType.getModelName());
|
getBalloonManager().addPlayerToModel(this, balloonType);
|
||||||
List<Player> viewer = PlayerUtils.getNearbyPlayers(getPlayer());
|
List<Player> viewer = PlayerUtils.getNearbyPlayers(getPlayer());
|
||||||
PacketManager.sendLeashPacket(getBalloonEntity().getPufferfishBalloonId(), getPlayer().getEntityId(), viewer);
|
PacketManager.sendLeashPacket(getBalloonManager().getPufferfishBalloonId(), getPlayer().getEntityId(), viewer);
|
||||||
}
|
}
|
||||||
if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
||||||
CosmeticBackpackType cosmeticBackpackType = (CosmeticBackpackType) getCosmetic(CosmeticSlot.BACKPACK);
|
CosmeticBackpackType cosmeticBackpackType = (CosmeticBackpackType) getCosmetic(CosmeticSlot.BACKPACK);
|
||||||
ItemStack item = getUserCosmeticItem(cosmeticBackpackType);
|
ItemStack item = getUserCosmeticItem(cosmeticBackpackType);
|
||||||
invisibleArmorstand.getEquipment().setHelmet(item);
|
userBackpackManager.setItem(item);
|
||||||
}
|
}
|
||||||
updateCosmetic();
|
updateCosmetic();
|
||||||
MessagesUtil.sendDebugMessages("ShowCosmetics");
|
MessagesUtil.sendDebugMessages("ShowCosmetics");
|
||||||
@@ -418,4 +449,18 @@ public class CosmeticUser {
|
|||||||
public boolean getHidden() {
|
public boolean getHidden() {
|
||||||
return this.hideCosmetics;
|
return this.hideCosmetics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HiddenReason getHiddenReason() {
|
||||||
|
return hiddenReason;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum HiddenReason {
|
||||||
|
NONE,
|
||||||
|
WORLDGUARD,
|
||||||
|
PLUGIN,
|
||||||
|
POTION,
|
||||||
|
ACTION,
|
||||||
|
COMMAND,
|
||||||
|
EMOTE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,270 +0,0 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.user;
|
|
||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
|
||||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
|
||||||
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
|
||||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
|
||||||
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
|
|
||||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
|
||||||
import net.kyori.adventure.audience.Audience;
|
|
||||||
import net.kyori.adventure.bossbar.BossBar;
|
|
||||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.GameMode;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
|
|
||||||
public class Wardrobe {
|
|
||||||
|
|
||||||
private int NPC_ID;
|
|
||||||
private String npcName;
|
|
||||||
private UUID WARDROBE_UUID;
|
|
||||||
private int ARMORSTAND_ID;
|
|
||||||
private GameMode originalGamemode;
|
|
||||||
private CosmeticUser VIEWER;
|
|
||||||
private Location viewingLocation;
|
|
||||||
private Location npcLocation;
|
|
||||||
private Location exitLocation;
|
|
||||||
private BossBar bossBar;
|
|
||||||
private boolean active;
|
|
||||||
|
|
||||||
public Wardrobe(CosmeticUser user) {
|
|
||||||
NPC_ID = NMSHandlers.getHandler().getNextEntityId();
|
|
||||||
ARMORSTAND_ID = NMSHandlers.getHandler().getNextEntityId();
|
|
||||||
WARDROBE_UUID = UUID.randomUUID();
|
|
||||||
VIEWER = user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void start() {
|
|
||||||
Player player = VIEWER.getPlayer();
|
|
||||||
|
|
||||||
this.originalGamemode = player.getGameMode();
|
|
||||||
if (WardrobeSettings.isReturnLastLocation()) {
|
|
||||||
this.exitLocation = player.getLocation().clone();
|
|
||||||
} else {
|
|
||||||
this.exitLocation = WardrobeSettings.getLeaveLocation();
|
|
||||||
}
|
|
||||||
|
|
||||||
viewingLocation = WardrobeSettings.getViewerLocation();
|
|
||||||
npcLocation = WardrobeSettings.getWardrobeLocation();
|
|
||||||
|
|
||||||
VIEWER.hidePlayer();
|
|
||||||
List<Player> viewer = List.of(player);
|
|
||||||
|
|
||||||
MessagesUtil.sendMessage(player, "opened-wardrobe");
|
|
||||||
|
|
||||||
Runnable run = () -> {
|
|
||||||
// Armorstand
|
|
||||||
PacketManager.sendEntitySpawnPacket(viewingLocation, ARMORSTAND_ID, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer);
|
|
||||||
PacketManager.sendInvisibilityPacket(ARMORSTAND_ID, viewer);
|
|
||||||
PacketManager.sendLookPacket(ARMORSTAND_ID, viewingLocation, viewer);
|
|
||||||
|
|
||||||
// Player
|
|
||||||
PacketManager.gamemodeChangePacket(player, 3);
|
|
||||||
PacketManager.sendCameraPacket(ARMORSTAND_ID, viewer);
|
|
||||||
|
|
||||||
// NPC
|
|
||||||
npcName = "WardrobeNPC-" + NPC_ID;
|
|
||||||
while (npcName.length() > 16) {
|
|
||||||
npcName = npcName.substring(16);
|
|
||||||
}
|
|
||||||
PacketManager.sendFakePlayerInfoPacket(player, NPC_ID, WARDROBE_UUID, npcName, viewer);
|
|
||||||
|
|
||||||
// NPC 2
|
|
||||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
|
||||||
PacketManager.sendFakePlayerSpawnPacket(npcLocation, WARDROBE_UUID, NPC_ID, viewer);
|
|
||||||
MessagesUtil.sendDebugMessages("Spawned Fake Player on " + npcLocation);
|
|
||||||
NMSHandlers.getHandler().hideNPCName(player, npcName);
|
|
||||||
}, 4);
|
|
||||||
|
|
||||||
// Location
|
|
||||||
PacketManager.sendLookPacket(NPC_ID, npcLocation, viewer);
|
|
||||||
PacketManager.sendRotationPacket(NPC_ID, npcLocation, true, viewer);
|
|
||||||
|
|
||||||
// Misc
|
|
||||||
if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
|
||||||
PacketManager.ridingMountPacket(NPC_ID, VIEWER.getBackpackEntity().getEntityId(), viewer);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
|
||||||
PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), -1, viewer);
|
|
||||||
PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), NPC_ID, viewer); // This needs a possible fix
|
|
||||||
//PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getModelId(), NPC_ID, viewer);
|
|
||||||
|
|
||||||
PacketManager.sendTeleportPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), npcLocation.clone().add(Settings.getBalloonOffset()), false, viewer);
|
|
||||||
PacketManager.sendTeleportPacket(VIEWER.getBalloonEntity().getModelId(), npcLocation.clone().add(Settings.getBalloonOffset()), false, viewer);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (WardrobeSettings.getEnabledBossbar()) {
|
|
||||||
float progress = WardrobeSettings.getBossbarProgress();
|
|
||||||
Component message = MessagesUtil.processStringNoKey(WardrobeSettings.getBossbarText());
|
|
||||||
|
|
||||||
bossBar = BossBar.bossBar(message, progress, WardrobeSettings.getBossbarColor(), WardrobeSettings.getBossbarOverlay());
|
|
||||||
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
|
|
||||||
|
|
||||||
target.showBossBar(bossBar);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.active = true;
|
|
||||||
update();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
if (WardrobeSettings.isEnabledTransition()) {
|
|
||||||
MessagesUtil.sendTitle(
|
|
||||||
VIEWER.getPlayer(),
|
|
||||||
WardrobeSettings.getTransitionText(),
|
|
||||||
WardrobeSettings.getTransitionFadeIn(),
|
|
||||||
WardrobeSettings.getTransitionStay(),
|
|
||||||
WardrobeSettings.getTransitionFadeOut()
|
|
||||||
);
|
|
||||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), run, WardrobeSettings.getTransitionDelay());
|
|
||||||
} else {
|
|
||||||
run.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void end() {
|
|
||||||
Player player = VIEWER.getPlayer();
|
|
||||||
|
|
||||||
List<Player> viewer = List.of(player);
|
|
||||||
|
|
||||||
MessagesUtil.sendMessage(player, "closed-wardrobe");
|
|
||||||
|
|
||||||
Runnable run = () -> {
|
|
||||||
this.active = false;
|
|
||||||
|
|
||||||
// NPC
|
|
||||||
if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BALLOON)) PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getModelId(), -1, viewer);
|
|
||||||
PacketManager.sendEntityDestroyPacket(NPC_ID, viewer); // Success
|
|
||||||
PacketManager.sendRemovePlayerPacket(player, WARDROBE_UUID, viewer); // Success
|
|
||||||
|
|
||||||
// Player
|
|
||||||
PacketManager.sendCameraPacket(player.getEntityId(), viewer);
|
|
||||||
PacketManager.gamemodeChangePacket(player, ServerUtils.convertGamemode(this.originalGamemode)); // Success
|
|
||||||
|
|
||||||
// Armorstand
|
|
||||||
PacketManager.sendEntityDestroyPacket(ARMORSTAND_ID, viewer); // Sucess
|
|
||||||
|
|
||||||
//PacketManager.sendEntityDestroyPacket(player.getEntityId(), viewer); // Success
|
|
||||||
player.setGameMode(this.originalGamemode);
|
|
||||||
VIEWER.showPlayer();
|
|
||||||
|
|
||||||
if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
|
||||||
PacketManager.ridingMountPacket(player.getEntityId(), VIEWER.getBackpackEntity().getEntityId(), viewer);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
|
||||||
PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), player.getEntityId(), viewer);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (exitLocation == null) {
|
|
||||||
player.teleport(player.getWorld().getSpawnLocation());
|
|
||||||
} else {
|
|
||||||
player.teleport(exitLocation);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (WardrobeSettings.isEquipPumpkin()) {
|
|
||||||
NMSHandlers.getHandler().equipmentSlotUpdate(VIEWER.getPlayer().getEntityId(), EquipmentSlot.HEAD, player.getInventory().getHelmet(), viewer);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (WardrobeSettings.getEnabledBossbar()) {
|
|
||||||
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
|
|
||||||
|
|
||||||
target.hideBossBar(bossBar);
|
|
||||||
}
|
|
||||||
|
|
||||||
VIEWER.updateCosmetic();
|
|
||||||
};
|
|
||||||
|
|
||||||
if (WardrobeSettings.isEnabledTransition()) {
|
|
||||||
MessagesUtil.sendTitle(
|
|
||||||
VIEWER.getPlayer(),
|
|
||||||
WardrobeSettings.getTransitionText(),
|
|
||||||
WardrobeSettings.getTransitionFadeIn(),
|
|
||||||
WardrobeSettings.getTransitionStay(),
|
|
||||||
WardrobeSettings.getTransitionFadeOut()
|
|
||||||
);
|
|
||||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), run, WardrobeSettings.getTransitionDelay());
|
|
||||||
} else {
|
|
||||||
run.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update() {
|
|
||||||
final AtomicInteger data = new AtomicInteger();
|
|
||||||
|
|
||||||
BukkitRunnable runnable = new BukkitRunnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (active == false) {
|
|
||||||
MessagesUtil.sendDebugMessages("Active is false");
|
|
||||||
this.cancel();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MessagesUtil.sendDebugMessages("Update ");
|
|
||||||
List<Player> viewer = List.of(VIEWER.getPlayer());
|
|
||||||
|
|
||||||
Location location = WardrobeSettings.getWardrobeLocation().clone();
|
|
||||||
int yaw = data.get();
|
|
||||||
location.setYaw(yaw);
|
|
||||||
|
|
||||||
PacketManager.sendLookPacket(NPC_ID, location, viewer);
|
|
||||||
//VIEWER.updateCosmetic();
|
|
||||||
int rotationSpeed = WardrobeSettings.getRotationSpeed();
|
|
||||||
location.setYaw(getNextYaw(yaw - 30, rotationSpeed));
|
|
||||||
PacketManager.sendRotationPacket(NPC_ID, location, true, viewer);
|
|
||||||
int nextyaw = getNextYaw(yaw, rotationSpeed);
|
|
||||||
data.set(nextyaw);
|
|
||||||
|
|
||||||
for (CosmeticSlot slot : CosmeticSlot.values()) {
|
|
||||||
PacketManager.equipmentSlotUpdate(NPC_ID, VIEWER, slot, viewer);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
|
||||||
PacketManager.sendTeleportPacket(VIEWER.getArmorstandId(), location, false, viewer);
|
|
||||||
PacketManager.ridingMountPacket(NPC_ID, VIEWER.getBackpackEntity().getEntityId(), viewer);
|
|
||||||
VIEWER.getBackpackEntity().setRotation(nextyaw, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
|
||||||
PacketManager.sendTeleportPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), WardrobeSettings.getWardrobeLocation().add(Settings.getBalloonOffset()), false, viewer);
|
|
||||||
VIEWER.getBalloonEntity().getModelEntity().teleport(WardrobeSettings.getWardrobeLocation().add(Settings.getBalloonOffset()));
|
|
||||||
//PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getModelId(), NPC_ID, viewer); // Pufferfish goes away for some reason?
|
|
||||||
}
|
|
||||||
|
|
||||||
if (WardrobeSettings.isEquipPumpkin()) {
|
|
||||||
NMSHandlers.getHandler().equipmentSlotUpdate(VIEWER.getPlayer().getEntityId(), EquipmentSlot.HEAD, new ItemStack(Material.CARVED_PUMPKIN), viewer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
runnable.runTaskTimer(HMCCosmeticsPlugin.getInstance(), 0, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int getNextYaw(final int current, final int rotationSpeed) {
|
|
||||||
int nextYaw = current + rotationSpeed;
|
|
||||||
if (nextYaw > 179) {
|
|
||||||
nextYaw = (current + rotationSpeed) - 358;
|
|
||||||
return nextYaw;
|
|
||||||
}
|
|
||||||
return nextYaw;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getArmorstandId() {
|
|
||||||
return ARMORSTAND_ID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.user.manager;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
|
||||||
|
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
|
import com.ticxo.modelengine.api.ModelEngineAPI;
|
||||||
|
import com.ticxo.modelengine.api.model.ActiveModel;
|
||||||
|
import com.ticxo.modelengine.api.model.ModeledEntity;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.AreaEffectCloud;
|
||||||
|
import org.bukkit.entity.ArmorStand;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class UserBackpackManager {
|
||||||
|
|
||||||
|
private boolean hideBackpack;
|
||||||
|
private ArmorStand invisibleArmorStand;
|
||||||
|
private AreaEffectCloud particleCloud;
|
||||||
|
private final CosmeticUser user;
|
||||||
|
private BackpackType backpackType;
|
||||||
|
|
||||||
|
public UserBackpackManager(CosmeticUser user, BackpackType backpackType) {
|
||||||
|
this.user = user;
|
||||||
|
hideBackpack = false;
|
||||||
|
this.backpackType = backpackType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getFirstArmorStandId() {
|
||||||
|
return invisibleArmorStand.getEntityId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArmorStand getArmorStand() {
|
||||||
|
return invisibleArmorStand;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void spawnBackpack(CosmeticBackpackType cosmeticBackpackType) {
|
||||||
|
MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Start");
|
||||||
|
|
||||||
|
if (getBackpackType().equals(BackpackType.NORMAL)) {
|
||||||
|
spawnNormalBackpack(cosmeticBackpackType);
|
||||||
|
}
|
||||||
|
if (getBackpackType().equals(BackpackType.FIRST_PERSON)) {
|
||||||
|
spawnFirstPersonBackpack(cosmeticBackpackType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void spawnNormalBackpack(CosmeticBackpackType cosmeticBackpackType) {
|
||||||
|
|
||||||
|
if (this.invisibleArmorStand != null) return;
|
||||||
|
|
||||||
|
this.invisibleArmorStand = (ArmorStand) NMSHandlers.getHandler().spawnBackpack(user, cosmeticBackpackType);
|
||||||
|
|
||||||
|
if (cosmeticBackpackType.getModelName() != null && HMCCosmeticsPlugin.hasModelEngine()) {
|
||||||
|
if (ModelEngineAPI.api.getModelRegistry().getBlueprint(cosmeticBackpackType.getModelName()) == null) {
|
||||||
|
MessagesUtil.sendDebugMessages("Invalid Model Engine Blueprint " + cosmeticBackpackType.getModelName(), Level.SEVERE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ModeledEntity modeledEntity = ModelEngineAPI.getOrCreateModeledEntity(invisibleArmorStand);
|
||||||
|
ActiveModel model = ModelEngineAPI.createActiveModel(ModelEngineAPI.getBlueprint(cosmeticBackpackType.getModelName()));
|
||||||
|
model.setCanHurt(false);
|
||||||
|
modeledEntity.addModel(model, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Finish");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void spawnFirstPersonBackpack(CosmeticBackpackType cosmeticBackpackType) {
|
||||||
|
|
||||||
|
if (this.invisibleArmorStand != null) return;
|
||||||
|
|
||||||
|
this.invisibleArmorStand = (ArmorStand) NMSHandlers.getHandler().spawnBackpack(user, cosmeticBackpackType);
|
||||||
|
this.particleCloud = (AreaEffectCloud) NMSHandlers.getHandler().spawnHMCParticleCloud(user.getPlayer().getLocation());
|
||||||
|
|
||||||
|
if (cosmeticBackpackType.getModelName() != null && HMCCosmeticsPlugin.hasModelEngine()) {
|
||||||
|
if (ModelEngineAPI.api.getModelRegistry().getBlueprint(cosmeticBackpackType.getModelName()) == null) {
|
||||||
|
MessagesUtil.sendDebugMessages("Invalid Model Engine Blueprint " + cosmeticBackpackType.getModelName(), Level.SEVERE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ModeledEntity modeledEntity = ModelEngineAPI.getOrCreateModeledEntity(invisibleArmorStand);
|
||||||
|
ActiveModel model = ModelEngineAPI.createActiveModel(ModelEngineAPI.getBlueprint(cosmeticBackpackType.getModelName()));
|
||||||
|
model.setCanHurt(false);
|
||||||
|
modeledEntity.addModel(model, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Finish");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void despawnBackpack() {
|
||||||
|
if (invisibleArmorStand != null) {
|
||||||
|
invisibleArmorStand.setHealth(0);
|
||||||
|
invisibleArmorStand.remove();
|
||||||
|
this.invisibleArmorStand = null;
|
||||||
|
}
|
||||||
|
if (particleCloud != null) {
|
||||||
|
particleCloud.remove();
|
||||||
|
this.particleCloud = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hideBackpack() {
|
||||||
|
if (user.getHidden()) return;
|
||||||
|
getArmorStand().getEquipment().clear();
|
||||||
|
hideBackpack = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showBackpack() {
|
||||||
|
if (!hideBackpack) return;
|
||||||
|
CosmeticBackpackType cosmeticBackpackType = (CosmeticBackpackType) user.getCosmetic(CosmeticSlot.BACKPACK);
|
||||||
|
ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType);
|
||||||
|
getArmorStand().getEquipment().setHelmet(item);
|
||||||
|
hideBackpack = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVisibility(boolean shown) {
|
||||||
|
hideBackpack = shown;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BackpackType getBackpackType() {
|
||||||
|
return backpackType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAreaEffectEntityId() {
|
||||||
|
return particleCloud.getEntityId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void teleportEffectEntity(Location location) {
|
||||||
|
particleCloud.teleport(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItem(ItemStack item) {
|
||||||
|
getArmorStand().getEquipment().setHelmet(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearItems() {
|
||||||
|
ItemStack item = new ItemStack(Material.AIR);
|
||||||
|
getArmorStand().getEquipment().setHelmet(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum BackpackType {
|
||||||
|
NORMAL,
|
||||||
|
FIRST_PERSON // First person not yet implemented
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,183 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.user.manager;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
|
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
||||||
|
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||||
|
import com.ticxo.modelengine.api.ModelEngineAPI;
|
||||||
|
import com.ticxo.modelengine.api.model.ActiveModel;
|
||||||
|
import com.ticxo.modelengine.api.model.ModeledEntity;
|
||||||
|
import org.bukkit.Color;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.ArmorStand;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class UserBalloonManager {
|
||||||
|
|
||||||
|
private BalloonType balloonType;
|
||||||
|
private CosmeticBalloonType cosmeticBalloonType;
|
||||||
|
private final int balloonID;
|
||||||
|
private final UUID uniqueID;
|
||||||
|
private final ArmorStand modelEntity;
|
||||||
|
|
||||||
|
public UserBalloonManager(@NotNull Location location) {
|
||||||
|
this.uniqueID = UUID.randomUUID();
|
||||||
|
this.balloonID = NMSHandlers.getHandler().getNextEntityId();
|
||||||
|
this.modelEntity = NMSHandlers.getHandler().getMEGEntity(location.add(Settings.getBalloonOffset()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void spawnModel(@NotNull CosmeticBalloonType cosmeticBalloonType, Color color) {
|
||||||
|
// redo this
|
||||||
|
if (cosmeticBalloonType.getModelName() != null && HMCCosmeticsPlugin.hasModelEngine()) {
|
||||||
|
balloonType = BalloonType.MODELENGINE;
|
||||||
|
} else {
|
||||||
|
if (cosmeticBalloonType.getItem() != null) {
|
||||||
|
balloonType = BalloonType.ITEM;
|
||||||
|
} else {
|
||||||
|
balloonType = BalloonType.NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.cosmeticBalloonType = cosmeticBalloonType;
|
||||||
|
MessagesUtil.sendDebugMessages("balloontype is " + balloonType);
|
||||||
|
|
||||||
|
if (balloonType == BalloonType.MODELENGINE) {
|
||||||
|
String id = cosmeticBalloonType.getModelName();
|
||||||
|
MessagesUtil.sendDebugMessages("Attempting Spawning for " + id);
|
||||||
|
if (ModelEngineAPI.api.getModelRegistry().getBlueprint(id) == null) {
|
||||||
|
MessagesUtil.sendDebugMessages("Invalid Model Engine Blueprint " + id, Level.SEVERE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ModeledEntity modeledEntity = ModelEngineAPI.getOrCreateModeledEntity(modelEntity);
|
||||||
|
ActiveModel model = ModelEngineAPI.createActiveModel(ModelEngineAPI.getBlueprint(id));
|
||||||
|
model.setCanHurt(false);
|
||||||
|
modeledEntity.addModel(model, false);
|
||||||
|
if (color != null) {
|
||||||
|
modeledEntity.getModels().forEach((d, singleModel) -> {
|
||||||
|
if (cosmeticBalloonType.isDyablePart(d)) {
|
||||||
|
singleModel.getRendererHandler().setColor(color);
|
||||||
|
singleModel.getRendererHandler().update();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (balloonType == BalloonType.ITEM) {
|
||||||
|
modelEntity.getEquipment().setHelmet(cosmeticBalloonType.getItem());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove() {
|
||||||
|
if (balloonType == BalloonType.MODELENGINE) {
|
||||||
|
final ModeledEntity entity = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId());
|
||||||
|
|
||||||
|
if (entity == null) return;
|
||||||
|
|
||||||
|
for (final Player player : entity.getRangeManager().getPlayerInRange()) {
|
||||||
|
entity.hideFromPlayer(player);
|
||||||
|
}
|
||||||
|
entity.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
modelEntity.remove();
|
||||||
|
cosmeticBalloonType = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPlayerToModel(final CosmeticUser user, final CosmeticBalloonType cosmeticBalloonType) {
|
||||||
|
addPlayerToModel(user, cosmeticBalloonType, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPlayerToModel(final CosmeticUser user, final CosmeticBalloonType cosmeticBalloonType, Color color) {
|
||||||
|
if (balloonType == BalloonType.MODELENGINE) {
|
||||||
|
final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId());
|
||||||
|
if (model == null) {
|
||||||
|
spawnModel(cosmeticBalloonType, color);
|
||||||
|
MessagesUtil.sendDebugMessages("model is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//if (model.getRangeManager().getPlayerInRange().contains(player)) return;
|
||||||
|
model.showToPlayer(user.getPlayer());
|
||||||
|
MessagesUtil.sendDebugMessages("Show to player");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (balloonType == BalloonType.ITEM) {
|
||||||
|
modelEntity.getEquipment().setHelmet(user.getUserCosmeticItem(cosmeticBalloonType));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void removePlayerFromModel(final Player player) {
|
||||||
|
if (balloonType == BalloonType.MODELENGINE) {
|
||||||
|
final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId());
|
||||||
|
|
||||||
|
if (model == null) return;
|
||||||
|
|
||||||
|
model.hideFromPlayer(player);
|
||||||
|
MessagesUtil.sendDebugMessages("Hidden from player");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (balloonType == BalloonType.ITEM) {
|
||||||
|
modelEntity.getEquipment().clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Entity getModelEntity() {
|
||||||
|
return this.modelEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int getPufferfishBalloonId() {
|
||||||
|
return balloonID;
|
||||||
|
}
|
||||||
|
public UUID getPufferfishBalloonUniqueId() {
|
||||||
|
return uniqueID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getModelUnqiueId() {
|
||||||
|
return getModelEntity().getUniqueId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getModelId() {
|
||||||
|
return getModelEntity().getEntityId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getLocation() {
|
||||||
|
return this.getModelEntity().getLocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocation(Location location) {
|
||||||
|
this.getModelEntity().teleport(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVelocity(Vector vector) {
|
||||||
|
this.getModelEntity().setVelocity(vector);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendRemoveLeashPacket(List<Player> viewer) {
|
||||||
|
PacketManager.sendLeashPacket(getPufferfishBalloonId(), -1, viewer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendRemoveLeashPacket() {
|
||||||
|
PacketManager.sendLeashPacket(getPufferfishBalloonId(), -1, getLocation());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendLeashPacket(int entityId) {
|
||||||
|
if (cosmeticBalloonType == null) return;
|
||||||
|
if (cosmeticBalloonType.isShowLead()) PacketManager.sendLeashPacket(getPufferfishBalloonId(), entityId, getLocation());
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum BalloonType {
|
||||||
|
MODELENGINE,
|
||||||
|
ITEM,
|
||||||
|
NONE
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.user.manager;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.api.PlayerEmoteStartEvent;
|
||||||
|
import com.hibiscusmc.hmccosmetics.api.PlayerEmoteStopEvent;
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticEmoteType;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class UserEmoteManager {
|
||||||
|
|
||||||
|
CosmeticUser user;
|
||||||
|
private UserEmoteModel model;
|
||||||
|
|
||||||
|
public UserEmoteManager(CosmeticUser user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void playEmote(@NotNull CosmeticEmoteType cosmeticEmoteType) {
|
||||||
|
MessagesUtil.sendDebugMessages("playEmote " + cosmeticEmoteType.getAnimationId());
|
||||||
|
playEmote(cosmeticEmoteType.getAnimationId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void playEmote(String animationId) {
|
||||||
|
if (isPlayingEmote()) return;
|
||||||
|
if (user.isInWardrobe()) return;
|
||||||
|
// API
|
||||||
|
PlayerEmoteStartEvent event = new PlayerEmoteStartEvent(user, animationId);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Internal
|
||||||
|
try {
|
||||||
|
model = new UserEmoteModel(user);
|
||||||
|
model.playAnimation(animationId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPlayingEmote() {
|
||||||
|
if (model == null) return false;
|
||||||
|
return model.isPlayingAnimation();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopEmote(StopEmoteReason emoteReason) {
|
||||||
|
if (!isPlayingEmote()) return;
|
||||||
|
// API
|
||||||
|
PlayerEmoteStopEvent event = new PlayerEmoteStopEvent(user, emoteReason);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Internal
|
||||||
|
model.stopAnimation();
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum StopEmoteReason {
|
||||||
|
SNEAK,
|
||||||
|
DAMAGE,
|
||||||
|
CONNECTION,
|
||||||
|
TELEPORT
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.user.manager;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
|
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||||
|
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||||
|
import com.ticxo.playeranimator.api.model.player.PlayerModel;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class UserEmoteModel extends PlayerModel {
|
||||||
|
|
||||||
|
private final CosmeticUser user;
|
||||||
|
private String emotePlaying;
|
||||||
|
private final int armorStandId;
|
||||||
|
private GameMode originalGamemode;
|
||||||
|
|
||||||
|
public UserEmoteModel(@NotNull CosmeticUser user) {
|
||||||
|
super(user.getPlayer());
|
||||||
|
this.user = user;
|
||||||
|
armorStandId = NMSHandlers.getHandler().getNextEntityId();
|
||||||
|
getRangeManager().setRenderDistance(Settings.getViewDistance());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void playAnimation(@NotNull String id) {
|
||||||
|
if (id.contains(":")) id = id.split(":", 2)[1]; // A:B -> B -> B.B.B
|
||||||
|
if (!id.contains(".")) id = id + "." + id + "." + id; // Make into a format that playerAnimator works with. Requires 3 splits.
|
||||||
|
|
||||||
|
super.playAnimation(id);
|
||||||
|
|
||||||
|
emotePlaying = id;
|
||||||
|
|
||||||
|
// Add config option that either allows player to move or forces them into a spot.
|
||||||
|
Player player = user.getPlayer();
|
||||||
|
List<Player> viewer = Collections.singletonList(user.getPlayer());
|
||||||
|
List<Player> outsideViewers = PacketManager.getViewers(player.getLocation());
|
||||||
|
outsideViewers.remove(player);
|
||||||
|
|
||||||
|
PacketManager.equipmentSlotUpdate(player, true, outsideViewers);
|
||||||
|
|
||||||
|
Location newLocation = player.getLocation().clone();
|
||||||
|
newLocation.setPitch(0);
|
||||||
|
|
||||||
|
double DISTANCE = Settings.getEmoteDistance();
|
||||||
|
|
||||||
|
Location thirdPersonLocation = newLocation.add(newLocation.getDirection().normalize().multiply(DISTANCE));
|
||||||
|
if (Settings.getCosmeticEmoteBlockCheck() && thirdPersonLocation.getBlock().getType().isOccluding()) {
|
||||||
|
stopAnimation();
|
||||||
|
MessagesUtil.sendMessage(player, "emote-blocked");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
user.getPlayer().setInvisible(true);
|
||||||
|
user.hideCosmetics(CosmeticUser.HiddenReason.EMOTE);
|
||||||
|
|
||||||
|
originalGamemode = player.getGameMode();
|
||||||
|
|
||||||
|
PacketManager.sendEntitySpawnPacket(thirdPersonLocation, armorStandId, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer);
|
||||||
|
PacketManager.sendInvisibilityPacket(armorStandId, viewer);
|
||||||
|
PacketManager.sendLookPacket(armorStandId, player.getLocation(), viewer);
|
||||||
|
|
||||||
|
PacketManager.gamemodeChangePacket(player, 3);
|
||||||
|
PacketManager.sendCameraPacket(armorStandId, viewer);
|
||||||
|
|
||||||
|
MessagesUtil.sendDebugMessages("playAnimation run");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean update() {
|
||||||
|
if (super.getAnimationProperty() == null) {
|
||||||
|
stopAnimation();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
boolean update = (super.update() && isPlayingAnimation());
|
||||||
|
if (!update) {
|
||||||
|
stopAnimation();
|
||||||
|
}
|
||||||
|
return update;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopAnimation() {
|
||||||
|
emotePlaying = null;
|
||||||
|
despawn();
|
||||||
|
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||||
|
Player player = user.getPlayer();
|
||||||
|
if (player == null) return;
|
||||||
|
|
||||||
|
List<Player> viewer = Collections.singletonList(player);
|
||||||
|
List<Player> outsideViewers = PacketManager.getViewers(player.getLocation());
|
||||||
|
outsideViewers.remove(player);
|
||||||
|
|
||||||
|
int entityId = player.getEntityId();
|
||||||
|
PacketManager.sendCameraPacket(entityId, viewer);
|
||||||
|
PacketManager.sendEntityDestroyPacket(armorStandId, viewer);
|
||||||
|
if (this.originalGamemode != null) {
|
||||||
|
PacketManager.gamemodeChangePacket(player, ServerUtils.convertGamemode(this.originalGamemode));
|
||||||
|
player.setGameMode(this.originalGamemode);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user.getPlayer() != null) player.setInvisible(false);
|
||||||
|
PacketManager.equipmentSlotUpdate(player, false, outsideViewers);
|
||||||
|
user.showPlayer();
|
||||||
|
user.showCosmetics();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPlayingAnimation() {
|
||||||
|
return emotePlaying != null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,296 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.user.manager;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
|
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||||
|
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||||
|
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||||
|
import net.kyori.adventure.audience.Audience;
|
||||||
|
import net.kyori.adventure.bossbar.BossBar;
|
||||||
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
public class UserWardrobeManager {
|
||||||
|
|
||||||
|
private final int NPC_ID;
|
||||||
|
private final int ARMORSTAND_ID;
|
||||||
|
private final UUID WARDROBE_UUID;
|
||||||
|
private String npcName;
|
||||||
|
private GameMode originalGamemode;
|
||||||
|
private final CosmeticUser user;
|
||||||
|
private final Location viewingLocation;
|
||||||
|
private final Location npcLocation;
|
||||||
|
private Location exitLocation;
|
||||||
|
private BossBar bossBar;
|
||||||
|
private boolean active;
|
||||||
|
private WardrobeStatus wardrobeStatus;
|
||||||
|
|
||||||
|
public UserWardrobeManager(CosmeticUser user, Location exitLocation, Location viewingLocation, Location npcLocation) {
|
||||||
|
NPC_ID = NMSHandlers.getHandler().getNextEntityId();
|
||||||
|
ARMORSTAND_ID = NMSHandlers.getHandler().getNextEntityId();
|
||||||
|
WARDROBE_UUID = UUID.randomUUID();
|
||||||
|
this.user = user;
|
||||||
|
|
||||||
|
this.exitLocation = exitLocation;
|
||||||
|
this.viewingLocation = viewingLocation;
|
||||||
|
this.npcLocation = npcLocation;
|
||||||
|
|
||||||
|
wardrobeStatus = WardrobeStatus.SETUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start() {
|
||||||
|
setWardrobeStatus(WardrobeStatus.STARTING);
|
||||||
|
Player player = user.getPlayer();
|
||||||
|
|
||||||
|
this.originalGamemode = player.getGameMode();
|
||||||
|
if (WardrobeSettings.isReturnLastLocation()) {
|
||||||
|
this.exitLocation = player.getLocation().clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
user.hidePlayer();
|
||||||
|
List<Player> viewer = Collections.singletonList(player);
|
||||||
|
List<Player> outsideViewers = PacketManager.getViewers(viewingLocation);
|
||||||
|
outsideViewers.remove(player);
|
||||||
|
|
||||||
|
MessagesUtil.sendMessage(player, "opened-wardrobe");
|
||||||
|
|
||||||
|
Runnable run = () -> {
|
||||||
|
// Armorstand
|
||||||
|
PacketManager.sendEntitySpawnPacket(viewingLocation, ARMORSTAND_ID, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer);
|
||||||
|
PacketManager.sendInvisibilityPacket(ARMORSTAND_ID, viewer);
|
||||||
|
PacketManager.sendLookPacket(ARMORSTAND_ID, viewingLocation, viewer);
|
||||||
|
|
||||||
|
// Player
|
||||||
|
PacketManager.gamemodeChangePacket(player, 3);
|
||||||
|
PacketManager.sendCameraPacket(ARMORSTAND_ID, viewer);
|
||||||
|
|
||||||
|
// NPC
|
||||||
|
npcName = "WardrobeNPC-" + NPC_ID;
|
||||||
|
while (npcName.length() > 16) {
|
||||||
|
npcName = npcName.substring(16);
|
||||||
|
}
|
||||||
|
PacketManager.sendFakePlayerInfoPacket(player, NPC_ID, WARDROBE_UUID, npcName, viewer);
|
||||||
|
|
||||||
|
// NPC 2
|
||||||
|
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||||
|
PacketManager.sendFakePlayerSpawnPacket(npcLocation, WARDROBE_UUID, NPC_ID, viewer);
|
||||||
|
MessagesUtil.sendDebugMessages("Spawned Fake Player on " + npcLocation);
|
||||||
|
NMSHandlers.getHandler().hideNPCName(player, npcName);
|
||||||
|
}, 4);
|
||||||
|
|
||||||
|
// Location
|
||||||
|
PacketManager.sendLookPacket(NPC_ID, npcLocation, viewer);
|
||||||
|
PacketManager.sendRotationPacket(NPC_ID, npcLocation, true, viewer);
|
||||||
|
|
||||||
|
// Misc
|
||||||
|
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
||||||
|
user.getUserBackpackManager().getArmorStand().teleport(npcLocation.clone().add(0, 2, 0));
|
||||||
|
PacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstArmorStandId(), viewer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
||||||
|
user.getBalloonManager().sendRemoveLeashPacket(viewer);
|
||||||
|
user.getBalloonManager().sendLeashPacket(NPC_ID);
|
||||||
|
//PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getModelId(), NPC_ID, viewer);
|
||||||
|
|
||||||
|
PacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), npcLocation.clone().add(Settings.getBalloonOffset()), false, viewer);
|
||||||
|
user.getBalloonManager().getModelEntity().teleport(npcLocation.clone().add(Settings.getBalloonOffset()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (WardrobeSettings.getEnabledBossbar()) {
|
||||||
|
float progress = WardrobeSettings.getBossbarProgress();
|
||||||
|
Component message = MessagesUtil.processStringNoKey(WardrobeSettings.getBossbarText());
|
||||||
|
|
||||||
|
bossBar = BossBar.bossBar(message, progress, WardrobeSettings.getBossbarColor(), WardrobeSettings.getBossbarOverlay());
|
||||||
|
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
|
||||||
|
|
||||||
|
target.showBossBar(bossBar);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.active = true;
|
||||||
|
update();
|
||||||
|
setWardrobeStatus(WardrobeStatus.RUNNING);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
if (WardrobeSettings.isEnabledTransition()) {
|
||||||
|
MessagesUtil.sendTitle(
|
||||||
|
user.getPlayer(),
|
||||||
|
WardrobeSettings.getTransitionText(),
|
||||||
|
WardrobeSettings.getTransitionFadeIn(),
|
||||||
|
WardrobeSettings.getTransitionStay(),
|
||||||
|
WardrobeSettings.getTransitionFadeOut()
|
||||||
|
);
|
||||||
|
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), run, WardrobeSettings.getTransitionDelay());
|
||||||
|
} else {
|
||||||
|
run.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void end() {
|
||||||
|
setWardrobeStatus(WardrobeStatus.STOPPING);
|
||||||
|
Player player = user.getPlayer();
|
||||||
|
|
||||||
|
List<Player> viewer = Collections.singletonList(player);
|
||||||
|
List<Player> outsideViewers = PacketManager.getViewers(viewingLocation);
|
||||||
|
outsideViewers.remove(player);
|
||||||
|
|
||||||
|
if (player != null) MessagesUtil.sendMessage(player, "closed-wardrobe");
|
||||||
|
|
||||||
|
Runnable run = () -> {
|
||||||
|
this.active = false;
|
||||||
|
|
||||||
|
// NPC
|
||||||
|
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) user.getBalloonManager().sendRemoveLeashPacket();
|
||||||
|
PacketManager.sendEntityDestroyPacket(NPC_ID, viewer); // Success
|
||||||
|
PacketManager.sendRemovePlayerPacket(player, WARDROBE_UUID, viewer); // Success
|
||||||
|
|
||||||
|
// Player
|
||||||
|
PacketManager.sendCameraPacket(player.getEntityId(), viewer);
|
||||||
|
|
||||||
|
// Armorstand
|
||||||
|
PacketManager.sendEntityDestroyPacket(ARMORSTAND_ID, viewer); // Sucess
|
||||||
|
|
||||||
|
//PacketManager.sendEntityDestroyPacket(player.getEntityId(), viewer); // Success
|
||||||
|
if (WardrobeSettings.isForceExitGamemode()) {
|
||||||
|
MessagesUtil.sendDebugMessages("Force Exit Gamemode " + WardrobeSettings.getExitGamemode());
|
||||||
|
player.setGameMode(WardrobeSettings.getExitGamemode());
|
||||||
|
PacketManager.gamemodeChangePacket(player, ServerUtils.convertGamemode(WardrobeSettings.getExitGamemode())); // Success
|
||||||
|
} else {
|
||||||
|
MessagesUtil.sendDebugMessages("Original Gamemode " + this.originalGamemode);
|
||||||
|
player.setGameMode(this.originalGamemode);
|
||||||
|
PacketManager.gamemodeChangePacket(player, ServerUtils.convertGamemode(this.originalGamemode)); // Success
|
||||||
|
}
|
||||||
|
user.showPlayer();
|
||||||
|
|
||||||
|
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
||||||
|
user.respawnBackpack();
|
||||||
|
//PacketManager.ridingMountPacket(player.getEntityId(), VIEWER.getBackpackEntity().getEntityId(), viewer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
||||||
|
user.respawnBalloon();
|
||||||
|
//PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), player.getEntityId(), viewer);
|
||||||
|
}
|
||||||
|
|
||||||
|
player.teleport(Objects.requireNonNullElseGet(exitLocation, () -> player.getWorld().getSpawnLocation()));
|
||||||
|
|
||||||
|
if (WardrobeSettings.isEquipPumpkin()) {
|
||||||
|
NMSHandlers.getHandler().equipmentSlotUpdate(user.getPlayer().getEntityId(), EquipmentSlot.HEAD, player.getInventory().getHelmet(), viewer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (WardrobeSettings.getEnabledBossbar()) {
|
||||||
|
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
|
||||||
|
|
||||||
|
target.hideBossBar(bossBar);
|
||||||
|
}
|
||||||
|
|
||||||
|
// For Wardrobe Temp Cosmetics
|
||||||
|
for (Cosmetic cosmetic : user.getCosmetics()) {
|
||||||
|
if (cosmetic.requiresPermission()) {
|
||||||
|
if (!player.hasPermission(cosmetic.getPermission())) user.removeCosmeticSlot(cosmetic.getSlot());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
user.updateCosmetic();
|
||||||
|
};
|
||||||
|
run.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update() {
|
||||||
|
final AtomicInteger data = new AtomicInteger();
|
||||||
|
|
||||||
|
BukkitRunnable runnable = new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Player player = user.getPlayer();
|
||||||
|
if (!active || player == null) {
|
||||||
|
MessagesUtil.sendDebugMessages("WardrobeEnd[user=" + user.getUniqueId() + ",reason=Active is false]");
|
||||||
|
this.cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MessagesUtil.sendDebugMessages("WardrobeUpdate[user= " + user.getUniqueId() + ",status=" + getWardrobeStatus() + "]");
|
||||||
|
List<Player> viewer = Collections.singletonList(player);
|
||||||
|
List<Player> outsideViewers = PacketManager.getViewers(viewingLocation);
|
||||||
|
outsideViewers.remove(player);
|
||||||
|
|
||||||
|
Location location = WardrobeSettings.getWardrobeLocation().clone();
|
||||||
|
int yaw = data.get();
|
||||||
|
location.setYaw(yaw);
|
||||||
|
|
||||||
|
PacketManager.sendLookPacket(NPC_ID, location, viewer);
|
||||||
|
user.hidePlayer();
|
||||||
|
int rotationSpeed = WardrobeSettings.getRotationSpeed();
|
||||||
|
location.setYaw(ServerUtils.getNextYaw(yaw - 30, rotationSpeed));
|
||||||
|
PacketManager.sendRotationPacket(NPC_ID, location, true, viewer);
|
||||||
|
int nextyaw = ServerUtils.getNextYaw(yaw, rotationSpeed);
|
||||||
|
data.set(nextyaw);
|
||||||
|
|
||||||
|
for (CosmeticSlot slot : CosmeticSlot.values()) {
|
||||||
|
PacketManager.equipmentSlotUpdate(NPC_ID, user, slot, viewer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
||||||
|
PacketManager.sendTeleportPacket(user.getUserBackpackManager().getFirstArmorStandId(), location, false, viewer);
|
||||||
|
PacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstArmorStandId(), viewer);
|
||||||
|
user.getUserBackpackManager().getArmorStand().setRotation(nextyaw, 0);
|
||||||
|
PacketManager.sendEntityDestroyPacket(user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
||||||
|
PacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), WardrobeSettings.getWardrobeLocation().add(Settings.getBalloonOffset()), false, viewer);
|
||||||
|
user.getBalloonManager().getModelEntity().teleport(WardrobeSettings.getWardrobeLocation().add(Settings.getBalloonOffset()));
|
||||||
|
user.getBalloonManager().sendRemoveLeashPacket(outsideViewers);
|
||||||
|
PacketManager.sendEntityDestroyPacket(user.getBalloonManager().getModelId(), outsideViewers);
|
||||||
|
user.getBalloonManager().sendLeashPacket(NPC_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (WardrobeSettings.isEquipPumpkin()) {
|
||||||
|
NMSHandlers.getHandler().equipmentSlotUpdate(user.getPlayer().getEntityId(), EquipmentSlot.HEAD, new ItemStack(Material.CARVED_PUMPKIN), viewer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
runnable.runTaskTimer(HMCCosmeticsPlugin.getInstance(), 0, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCameraId() {
|
||||||
|
return ARMORSTAND_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WardrobeStatus getWardrobeStatus() {
|
||||||
|
return wardrobeStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWardrobeStatus(WardrobeStatus status) {
|
||||||
|
this.wardrobeStatus = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum WardrobeStatus {
|
||||||
|
SETUP,
|
||||||
|
STARTING,
|
||||||
|
RUNNING,
|
||||||
|
STOPPING,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,14 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.util;
|
package com.hibiscusmc.hmccosmetics.util;
|
||||||
|
|
||||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||||
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class InventoryUtils {
|
public class InventoryUtils {
|
||||||
@@ -58,6 +64,8 @@ public class InventoryUtils {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Contract(pure = true)
|
||||||
|
@Nullable
|
||||||
public static CosmeticSlot BukkitCosmeticSlot(int slot) {
|
public static CosmeticSlot BukkitCosmeticSlot(int slot) {
|
||||||
switch (slot) {
|
switch (slot) {
|
||||||
case 36 -> {
|
case 36 -> {
|
||||||
@@ -81,6 +89,8 @@ public class InventoryUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Contract(pure = true)
|
||||||
|
@Nullable
|
||||||
public static CosmeticSlot NMSCosmeticSlot(int slot) {
|
public static CosmeticSlot NMSCosmeticSlot(int slot) {
|
||||||
switch (slot) {
|
switch (slot) {
|
||||||
case 5 -> {
|
case 5 -> {
|
||||||
@@ -104,7 +114,9 @@ public class InventoryUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EquipmentSlot getEquipmentSlot(CosmeticSlot slot) {
|
@Contract(pure = true)
|
||||||
|
@Nullable
|
||||||
|
public static EquipmentSlot getEquipmentSlot(@NotNull CosmeticSlot slot) {
|
||||||
switch (slot) {
|
switch (slot) {
|
||||||
case HELMET -> {
|
case HELMET -> {
|
||||||
return EquipmentSlot.HEAD;
|
return EquipmentSlot.HEAD;
|
||||||
@@ -129,4 +141,19 @@ public class InventoryUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isCosmeticItem(ItemStack itemStack) {
|
||||||
|
if (itemStack == null) return false;
|
||||||
|
itemStack = itemStack.clone();
|
||||||
|
if (!itemStack.hasItemMeta()) return false;
|
||||||
|
return itemStack.getItemMeta().getPersistentDataContainer().has(getCosmeticKey(), PersistentDataType.STRING);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static NamespacedKey getCosmeticKey() {
|
||||||
|
return new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "cosmetic");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static NamespacedKey getOwnerKey() {
|
||||||
|
return new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "owner");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ package com.hibiscusmc.hmccosmetics.util;
|
|||||||
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.WardrobeSettings;
|
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
||||||
import com.hibiscusmc.hmccosmetics.hooks.PAPIHook;
|
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
|
||||||
|
import com.hibiscusmc.hmccosmetics.hooks.placeholders.HMCPlaceholderExpansion;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.util.misc.Adventure;
|
import com.hibiscusmc.hmccosmetics.util.misc.Adventure;
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
@@ -14,6 +15,8 @@ import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
|||||||
import net.kyori.adventure.title.Title;
|
import net.kyori.adventure.title.Title;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
@@ -23,9 +26,9 @@ import java.util.logging.Level;
|
|||||||
public class MessagesUtil {
|
public class MessagesUtil {
|
||||||
|
|
||||||
private static String prefix;
|
private static String prefix;
|
||||||
private static HashMap<String, String> messages = new HashMap<>();
|
private static final HashMap<String, String> messages = new HashMap<>();
|
||||||
|
|
||||||
public static void setup(ConfigurationNode config) {
|
public static void setup(@NotNull ConfigurationNode config) {
|
||||||
prefix = config.node("prefix").getString("");
|
prefix = config.node("prefix").getString("");
|
||||||
for (ConfigurationNode node : config.childrenMap().values()) {
|
for (ConfigurationNode node : config.childrenMap().values()) {
|
||||||
if (node.virtual()) continue;
|
if (node.virtual()) continue;
|
||||||
@@ -34,7 +37,7 @@ public class MessagesUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendMessage(CosmeticUser user, String key) {
|
public static void sendMessage(@NotNull CosmeticUser user, String key) {
|
||||||
sendMessage(user.getPlayer(), key);
|
sendMessage(user.getPlayer(), key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,6 +50,7 @@ public class MessagesUtil {
|
|||||||
|
|
||||||
public static void sendMessage(CommandSender sender, String key) {
|
public static void sendMessage(CommandSender sender, String key) {
|
||||||
Component finalMessage = processString(null, key);
|
Component finalMessage = processString(null, key);
|
||||||
|
if (finalMessage == null) return;
|
||||||
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).sender(sender);
|
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).sender(sender);
|
||||||
|
|
||||||
target.sendMessage(finalMessage);
|
target.sendMessage(finalMessage);
|
||||||
@@ -90,11 +94,12 @@ public class MessagesUtil {
|
|||||||
return processString(player, key, null);
|
return processString(player, key, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static Component processString(Player player, String key, TagResolver placeholders) {
|
public static Component processString(Player player, String key, TagResolver placeholders) {
|
||||||
if (!messages.containsKey(key)) return null;
|
if (!messages.containsKey(key)) return null;
|
||||||
if (messages.get(key) == null) return null;
|
if (messages.get(key) == null) return null;
|
||||||
String message = messages.get(key);
|
String message = messages.get(key);
|
||||||
if (PAPIHook.isPAPIEnabled() && player != null) message = PlaceholderAPI.setPlaceholders(player, message);
|
if (Hooks.isActiveHook("PlaceholderAPI") && player != null) message = PlaceholderAPI.setPlaceholders(player, message);
|
||||||
message = message.replaceAll("%prefix%", prefix);
|
message = message.replaceAll("%prefix%", prefix);
|
||||||
if (placeholders != null ) {
|
if (placeholders != null ) {
|
||||||
return Adventure.MINI_MESSAGE.deserialize(message, placeholders);
|
return Adventure.MINI_MESSAGE.deserialize(message, placeholders);
|
||||||
@@ -102,17 +107,20 @@ public class MessagesUtil {
|
|||||||
return Adventure.MINI_MESSAGE.deserialize(message);
|
return Adventure.MINI_MESSAGE.deserialize(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static Component processStringNoKey(String message) {
|
public static Component processStringNoKey(String message) {
|
||||||
return processStringNoKey(null, message, null);
|
return processStringNoKey(null, message, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static Component processStringNoKey(Player player, String message) {
|
public static Component processStringNoKey(Player player, String message) {
|
||||||
return processStringNoKey(player, message, null);
|
return processStringNoKey(player, message, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static Component processStringNoKey(Player player, String message, TagResolver placeholders) {
|
public static Component processStringNoKey(Player player, String message, TagResolver placeholders) {
|
||||||
message = message.replaceAll("%prefix%", prefix);
|
message = message.replaceAll("%prefix%", prefix);
|
||||||
if (PAPIHook.isPAPIEnabled() && player != null) message = PlaceholderAPI.setPlaceholders(player, message);
|
if (Hooks.isActiveHook("PlaceholderAPI") && player != null) message = PlaceholderAPI.setPlaceholders(player, message);
|
||||||
if (placeholders != null ) {
|
if (placeholders != null ) {
|
||||||
return Adventure.MINI_MESSAGE.deserialize(message, placeholders);
|
return Adventure.MINI_MESSAGE.deserialize(message, placeholders);
|
||||||
}
|
}
|
||||||
@@ -121,7 +129,7 @@ public class MessagesUtil {
|
|||||||
|
|
||||||
public static String processStringNoKeyString(Player player, String message) {
|
public static String processStringNoKeyString(Player player, String message) {
|
||||||
message = message.replaceAll("%prefix%", prefix);
|
message = message.replaceAll("%prefix%", prefix);
|
||||||
if (PAPIHook.isPAPIEnabled() && player != null) message = PlaceholderAPI.setPlaceholders(player, message);
|
if (Hooks.isActiveHook("PlaceholderAPI") && player != null) message = PlaceholderAPI.setPlaceholders(player, message);
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,7 +138,7 @@ public class MessagesUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void sendDebugMessages(String message, Level level) {
|
public static void sendDebugMessages(String message, Level level) {
|
||||||
if (!Settings.isDebugEnabled() && level != Level.SEVERE) return;
|
if (!Settings.isDebugEnabled() && level == Level.INFO) return;
|
||||||
HMCCosmeticsPlugin.getInstance().getLogger().log(level, message);
|
HMCCosmeticsPlugin.getInstance().getLogger().log(level, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,15 @@ import com.hibiscusmc.hmccosmetics.config.Settings;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PlayerUtils {
|
public class PlayerUtils {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static WrappedSignedProperty getSkin(Player player) {
|
public static WrappedSignedProperty getSkin(Player player) {
|
||||||
WrappedSignedProperty skinData = WrappedGameProfile.fromPlayer(player).getProperties()
|
WrappedSignedProperty skinData = WrappedGameProfile.fromPlayer(player).getProperties()
|
||||||
.get("textures").stream().findAny().orElse(null);
|
.get("textures").stream().findAny().orElse(null);
|
||||||
@@ -22,11 +25,13 @@ public class PlayerUtils {
|
|||||||
return new WrappedSignedProperty("textures", skinData.getValue(), skinData.getSignature());
|
return new WrappedSignedProperty("textures", skinData.getValue(), skinData.getSignature());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Player> getNearbyPlayers(Player player) {
|
@NotNull
|
||||||
|
public static List<Player> getNearbyPlayers(@NotNull Player player) {
|
||||||
return getNearbyPlayers(player.getLocation());
|
return getNearbyPlayers(player.getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Player> getNearbyPlayers(Location location) {
|
@NotNull
|
||||||
|
public static List<Player> getNearbyPlayers(@NotNull Location location) {
|
||||||
List<Player> players = new ArrayList<>();
|
List<Player> players = new ArrayList<>();
|
||||||
int viewDistance = Settings.getViewDistance();
|
int viewDistance = Settings.getViewDistance();
|
||||||
for (Entity entity : location.getWorld().getNearbyEntities(location, viewDistance, viewDistance, viewDistance)) {
|
for (Entity entity : location.getWorld().getNearbyEntities(location, viewDistance, viewDistance, viewDistance)) {
|
||||||
|
|||||||
@@ -1,8 +1,18 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.util;
|
package com.hibiscusmc.hmccosmetics.util;
|
||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||||
|
import com.owen1212055.particlehelper.api.particle.MultiParticle;
|
||||||
|
import com.owen1212055.particlehelper.api.particle.Particle;
|
||||||
|
import com.owen1212055.particlehelper.api.particle.types.*;
|
||||||
|
import com.owen1212055.particlehelper.api.particle.types.dust.transition.TransitionDustParticle;
|
||||||
|
import com.owen1212055.particlehelper.api.particle.types.note.MultiNoteParticle;
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class ServerUtils {
|
public class ServerUtils {
|
||||||
|
|
||||||
@@ -27,6 +37,16 @@ public class ServerUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Color hex2Rgb(String colorStr) {
|
public static Color hex2Rgb(String colorStr) {
|
||||||
|
if (colorStr.startsWith("#")) return Color.fromRGB(Integer.valueOf(colorStr.substring(1), 16));
|
||||||
|
if (colorStr.startsWith("0x")) return Color.fromRGB(Integer.valueOf(colorStr.substring(2), 16));
|
||||||
|
if (colorStr.contains(",")) {
|
||||||
|
String[] colorString = colorStr.replace(" ", "").split(",");
|
||||||
|
for (String color : colorString) if (Integer.valueOf(color) == null) return Color.WHITE;
|
||||||
|
Color.fromRGB(Integer.valueOf(colorString[0]), Integer.valueOf(colorString[1]), Integer.valueOf(colorString[2]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Color.WHITE;
|
||||||
|
/* Old method
|
||||||
try {
|
try {
|
||||||
return Color.fromRGB(
|
return Color.fromRGB(
|
||||||
Integer.valueOf(colorStr.substring(1, 3), 16),
|
Integer.valueOf(colorStr.substring(1, 3), 16),
|
||||||
@@ -35,5 +55,95 @@ public class ServerUtils {
|
|||||||
} catch (StringIndexOutOfBoundsException e) {
|
} catch (StringIndexOutOfBoundsException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
// particle amount offsetxyz
|
||||||
|
// Ex. HEART 10 0.1 0.1 0.1
|
||||||
|
public static Particle addParticleValues(Particle particle, String[] split) {
|
||||||
|
var counter = 1;
|
||||||
|
if (particle instanceof MultiParticle multiParticle) {
|
||||||
|
multiParticle.setCount(getBigInteger(split[counter]).intValue());
|
||||||
|
counter++;
|
||||||
|
multiParticle.setXOffset(getBigInteger(split[counter]).floatValue());
|
||||||
|
counter++;
|
||||||
|
multiParticle.setYOffset(getBigInteger(split[counter]).floatValue());
|
||||||
|
counter++;
|
||||||
|
multiParticle.setZOffset(getBigInteger(split[counter]).floatValue());
|
||||||
|
counter++;
|
||||||
|
if (multiParticle instanceof MultiNoteParticle multiNoteParticle) {
|
||||||
|
multiNoteParticle.setColorMultplier(getBigInteger(split[counter]).intValue());
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (particle instanceof ColorableParticle colorableParticle && colorFromString(split[counter]) != null) {
|
||||||
|
colorableParticle.setColor(colorFromString(split[counter]));
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
if (particle instanceof TransitionDustParticle transitionDustParticle && colorFromString(split[counter]) != null) {
|
||||||
|
transitionDustParticle.setFadeColor(colorFromString(split[counter]));
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
if (particle instanceof MaterialParticle materialParticle && Material.getMaterial(split[counter]) != null) {
|
||||||
|
materialParticle.setMaterial(Material.getMaterial(split[counter]));
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
if (particle instanceof SpeedModifiableParticle speedModifiableParticle) {
|
||||||
|
speedModifiableParticle.setSpeed(getBigInteger(split[counter]).floatValue());
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
if (particle instanceof DelayableParticle delayableParticle) {
|
||||||
|
delayableParticle.setDelay(getBigInteger(split[counter]).intValue());
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
if (particle instanceof SizeableParticle sizeableParticle) {
|
||||||
|
sizeableParticle.setSize(getBigInteger(split[counter]).floatValue());
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
if (particle instanceof RollableParticle rollableParticle) {
|
||||||
|
rollableParticle.setRoll(getBigInteger(split[counter]).floatValue());
|
||||||
|
}
|
||||||
|
return particle;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BigInteger getBigInteger(String string) {
|
||||||
|
try {
|
||||||
|
return new BigInteger(string);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return BigInteger.valueOf(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse a color from a string.
|
||||||
|
* Formats: #RRGGBB; R,G,B
|
||||||
|
*
|
||||||
|
* @param color The string
|
||||||
|
* @return The color, if the string can't be parsed, null is returned
|
||||||
|
*/
|
||||||
|
public static Color colorFromString(@Nullable String color) {
|
||||||
|
if (color == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
var decodedColor = java.awt.Color.decode(color.startsWith("#") ? color : "#" + color);
|
||||||
|
return Color.fromRGB(decodedColor.getRed(), decodedColor.getGreen(), decodedColor.getBlue());
|
||||||
|
} catch (NumberFormatException invalidHex) {
|
||||||
|
try {
|
||||||
|
var rgbValues = Arrays.stream(color.split(",")).map(Integer::parseInt).toArray(Integer[]::new);
|
||||||
|
return Color.fromRGB(rgbValues[0], rgbValues[1], rgbValues[2]);
|
||||||
|
} catch (Exception invalidRgb) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getNextYaw(final int current, final int rotationSpeed) {
|
||||||
|
int nextYaw = current + rotationSpeed;
|
||||||
|
if (nextYaw > 179) {
|
||||||
|
nextYaw = (current + rotationSpeed) - 358;
|
||||||
|
return nextYaw;
|
||||||
|
}
|
||||||
|
return nextYaw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ColorBuilder {
|
public class ColorBuilder {
|
||||||
|
|
||||||
@@ -13,7 +14,7 @@ public class ColorBuilder {
|
|||||||
return canBeColored(new ItemStack(material));
|
return canBeColored(new ItemStack(material));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean canBeColored(final ItemStack itemStack) {
|
public static boolean canBeColored(final @NotNull ItemStack itemStack) {
|
||||||
final ItemMeta itemMeta = itemStack.getItemMeta();
|
final ItemMeta itemMeta = itemStack.getItemMeta();
|
||||||
|
|
||||||
return (itemMeta instanceof LeatherArmorMeta ||
|
return (itemMeta instanceof LeatherArmorMeta ||
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.inventory.ItemFlag;
|
import org.bukkit.inventory.ItemFlag;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -33,7 +35,7 @@ public class ItemBuilder {
|
|||||||
* @param itemStack builder ItemStack
|
* @param itemStack builder ItemStack
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ItemBuilder(final ItemStack itemStack) {
|
ItemBuilder(final @NotNull ItemStack itemStack) {
|
||||||
this.material = itemStack.getType();
|
this.material = itemStack.getType();
|
||||||
this.itemMeta = itemStack.hasItemMeta() ? itemStack.getItemMeta()
|
this.itemMeta = itemStack.hasItemMeta() ? itemStack.getItemMeta()
|
||||||
: Bukkit.getItemFactory().getItemMeta(this.material);
|
: Bukkit.getItemFactory().getItemMeta(this.material);
|
||||||
@@ -44,6 +46,8 @@ public class ItemBuilder {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@Contract("_ -> new")
|
||||||
|
@NotNull
|
||||||
public static ItemBuilder from(final Material material) {
|
public static ItemBuilder from(final Material material) {
|
||||||
return new ItemBuilder(material);
|
return new ItemBuilder(material);
|
||||||
}
|
}
|
||||||
@@ -52,7 +56,8 @@ public class ItemBuilder {
|
|||||||
* @param itemStack builder ItemStack
|
* @param itemStack builder ItemStack
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@Contract("_ -> new")
|
||||||
|
@NotNull
|
||||||
public static ItemBuilder from(final ItemStack itemStack) {
|
public static ItemBuilder from(final ItemStack itemStack) {
|
||||||
return new ItemBuilder(itemStack);
|
return new ItemBuilder(itemStack);
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user