9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-19 15:09:19 +00:00

Compare commits

...

157 Commits

Author SHA1 Message Date
Logan
0e2b2edadd chore: fix not importing annotation in CosmeticBackpackType 2025-12-17 13:03:08 -06:00
Logan
7e384fcd79 Merge pull request #204 from HibiscusMC/itemmodel-placeholder
feat: add itemmodel & itemname placeholders, bump api to 1.21.4 with …
2025-12-17 11:09:09 -06:00
Logan
e88b84610e version bump (2.8.3) 2025-12-17 11:06:30 -06:00
lucian929
223ffa46eb chore: change references to glyphs 2025-12-17 11:48:44 -05:00
Logan
f408108682 chore: remove emote distance still variable in Settings 2025-12-17 10:13:26 -06:00
Logan
b9f9448367 chore: move some comments around 2025-12-16 13:08:56 -06:00
Logan
c40aca9946 feat: remove entity-cooldown-teleport-packet option as it is no longer used 2025-12-16 13:07:03 -06:00
Logan
98d2692def fix: dispatch update also updates location for viewers 2025-12-16 13:03:54 -06:00
Logan
ebbc80c465 chore: add what usage api users should use in javadocs in cosmetic deprecated methods 2025-12-16 12:54:48 -06:00
Logan
775699d9ca chore: define nullability of behavior impl 2025-12-16 12:52:41 -06:00
Logan
b0ba5fc011 chore: CosmeticUser move to non-deprecated internal methods to add cosmetics (and indicate nullability of update movement variables) 2025-12-16 12:49:44 -06:00
Logan
af01ff600b chore: move to paper advneture impl 2025-12-16 12:14:02 -06:00
Logan
2e4619da02 fix: import proper nullable in UserBackpackManager 2025-12-16 12:12:06 -06:00
Logan
b4bd08c249 chore: refactor UserSearchManager to PlayerSearchManager 2025-12-16 12:06:21 -06:00
Logan
19981b33d3 fix: better teleport listening 2025-12-16 12:00:24 -06:00
Logan
c7c4c0e583 chore: add multiverse to test server 2025-12-16 11:59:22 -06:00
Logan
935c157421 chore: remove player animator being implemented? 2025-12-14 13:07:21 -06:00
Boy0000
20a3a508c2 refactor: remove AttributeWrapper 2025-11-11 02:40:25 +01:00
Boy0000
92b75c43ab feat: add itemmodel & itemname placeholders, bump api to 1.21.4 with attribute wrapper 2025-11-11 01:39:33 +01:00
Logan
a6ad2c19aa fix: fix client crashes for wardrobe on 1.21.10 2025-11-10 16:49:41 -06:00
Logan
fe8b4c97ff Merge pull request #201 from SolaraGames/fix-api
fix api
2025-10-13 14:29:51 -05:00
Tech
8c119c78db fix api 2025-10-13 14:58:02 -04:00
Logan
ce33a72fc2 chore: update Hibiscus Commons 2025-10-13 11:25:45 -05:00
Tech
2a8f30636d nullability checks (#200) 2025-10-13 18:06:00 +02:00
Logan
4103c2c232 Merge pull request #199 from SolaraGames/fix-memory-leak
fix memory leak
2025-10-12 15:01:13 -05:00
Tech
fb5c9d205c fix memory leak 2025-10-12 16:00:08 -04:00
Logan
126d576303 Merge pull request #198 from SolaraGames/optimize-viewer
Optimize Cosmetics
2025-10-12 14:37:17 -05:00
Tech
c74b76837b fix npe 2025-10-12 01:49:17 -04:00
Tech
d2c37f8273 optimize movement cosmetics 2025-10-12 01:42:32 -04:00
Logan
dbadbda82f chore: disable passenger packet 2025-10-11 22:22:23 -05:00
Logan
d66aa3b79c chore: update luckperms on test server 2025-10-04 22:53:38 -05:00
Logan
1c5cd7b467 chore: minor refactoring of db code 2025-09-25 20:03:05 -05:00
Logan
10f8dda150 fix: dye menu through command not checking if there is a provider available 2025-09-21 15:00:03 -05:00
Logan
e76aa0783e chore: refactor passenger content code 2025-09-12 19:31:19 -05:00
Logan
0676125f07 chore: refactor backpacks files 2025-09-08 14:58:15 -05:00
Logan
7aef681149 feat: refactor UserEntity refreshViewers 2025-09-07 21:44:44 -05:00
Logan
d5ac55f266 chore: update hibiscus commons 2025-09-07 21:38:11 -05:00
Logan
c2b787c97c feat: tomfollery with backpacks, external and regular backpacks appear to work now, but first-person backpacks are still experiencing jank 2025-09-07 21:35:37 -05:00
Logan
732c3de0d8 feat: use new hibiscus commons method for pufferfish spawning 2025-09-07 21:34:38 -05:00
Logan
3843a28804 feat: reenable passenger packet listener 2025-09-07 14:51:36 -05:00
Logan
a63494ba9f feat: make prevent offhand swapping configurable and is now disabled by default, resolves #192 2025-09-07 14:05:29 -05:00
Logan
c7e6a77eb8 chore: remove ai from balloon armorstand 2025-09-07 13:46:11 -05:00
Logan
075d2b3182 fix: move mob key to be a public value and be more specific 2025-09-07 13:36:31 -05:00
Logan
515de7d2c8 feat: add event for cancelling interactions with balloon armorstand 2025-09-07 09:44:53 -05:00
Logan
429287c9f3 feat: only try running spawning invisible armorstands when there is outside viewers to send it to 2025-09-06 23:44:49 -05:00
Logan
fed13b8ee6 feat: wardrobe npc now respects scale 2025-09-06 23:25:56 -05:00
Logan
8011dda200 feat: use new Hibiscus Commons methods for packets 2025-09-06 23:19:31 -05:00
Logan
7abfb0edf1 chore: turn item processing off by default 2025-09-06 23:18:48 -05:00
Logan
1f8c772712 chore: bump to latest Hibiscus Commons 2025-09-06 23:18:24 -05:00
Logan
7d727bb68f Merge pull request #191 from NoltoxGit/remapped
Reformat config.yml
2025-08-28 16:20:56 -05:00
Logan
007f27f109 chore: nexo reload on change 2025-08-28 16:20:47 -05:00
Poy
e0e0d0c997 Add quotes to string values in config.yml
Updated YAML configuration to use quotes for string values.
2025-08-28 21:56:42 +02:00
Poy
75a1458ae1 Fix config (jd.papermc.io) 2025-08-28 21:55:12 +02:00
Logan
548b15d99d chore: bump HibiscusCommons 2025-08-27 10:56:56 -05:00
Logan
50f04373b7 chore: add gsit to the test server 2025-08-24 12:25:06 -05:00
Logan
27a6c1bd54 feat: better handling of invalid cosmetics for dye subcommand 2025-08-18 20:44:16 -05:00
Logan
bb08fb108c feat: better handling of custom dye implementations with HMCColor 2025-08-18 20:41:26 -05:00
Logan
3907bc5839 version bump (2.8.2) 2025-08-18 20:36:53 -05:00
Logan
1ef7f4759f fix: balloon lead not properly disappearing when you unapply a balloon cosmetic 2025-08-17 16:22:32 -05:00
Logan
937f66e8c5 version bump (2.8.1) 2025-08-17 14:43:59 -05:00
Logan
158f3afdec chore: update test server 2025-08-17 14:43:44 -05:00
Logan
38bdc01e9f Merge remote-tracking branch 'origin/remapped' into remapped 2025-08-16 13:30:16 -05:00
Logan
797992362a feat: allow custom dye menu implementations 2025-08-16 13:30:10 -05:00
Logan
9716a079be Merge pull request #189 from Catnies/dev
fix PlayerMenuOpenEvent can't cancel
2025-08-06 16:30:24 -05:00
LoJoSho
dfe51ba5b8 fix: user initialization not checking potion effects 2025-08-06 16:27:27 -05:00
Catnies
f5e81446a6 fix PlayerMenuOpenEvent can't cancel 2025-08-05 14:34:07 +08:00
LoJoSho
c99a57a6bf chore: update adventure dependencies 2025-08-01 22:01:31 -05:00
LoJoSho
79630263f2 chore: exclude lin-bus from worldguard depend 2025-08-01 21:59:30 -05:00
LoJoSho
478c4280c1 feat: finally fully remove mainhand cosmetic 2025-07-19 15:36:11 -05:00
LoJoSho
4fd439acc4 chore: backpack force riding backpack set on by default 2025-07-12 10:32:38 -05:00
LoJoSho
58c955a00f feat: expose the config for a cosmetic if available 2025-07-09 18:06:22 -05:00
Oak
2f9325b2fb Added scale attribute support to backpacks (#186) 2025-07-05 16:15:01 -05:00
LoJoSho
823270648b Merge remote-tracking branch 'origin/remapped' into remapped 2025-07-04 11:59:44 -05:00
LoJoSho
d5e988261b chore: update to 1.21.7 on test server 2025-07-04 11:59:35 -05:00
Logan
13303096ec chore: shading should be off by default 2025-07-04 10:27:20 -05:00
LoJoSho
3ee79e8443 fix: passenger packet interceptor appears to cause instability, disabling for now 2025-07-01 14:50:42 -05:00
LoJoSho
7785556967 chore: remove unused variable 2025-07-01 14:49:39 -05:00
LoJoSho
1296ca6e92 fix: calculating yaw twice causing bad yaw to be sent in rotations 2025-07-01 13:47:50 -05:00
LoJoSho
f56d5c9093 chore: more debug messages on equip 2025-06-28 17:59:23 -05:00
LoJoSho
bae04fba3f chore: update to latest hibiscus commons 2025-06-28 15:30:47 -05:00
LoJoSho
cbe5404399 fix: hibiscus commons version 2025-06-27 15:47:49 -05:00
LoJoSho
dc4098782a fix: latest crash fixes (with latest hibiscus commons) 2025-06-27 15:44:17 -05:00
LoJoSho
2eb0b26fb3 fix: plugin not properly saving resources 2025-06-27 15:15:48 -05:00
LoJoSho
22159fa9f4 fix: duplicate entity ids in passengers 2025-06-27 10:18:35 -05:00
LoJoSho
539c09801c chore: remove cooldown on teleport packet 2025-06-27 08:53:58 -05:00
Logan
bed5cd7bbb Merge pull request #185 from HibiscusMC/commons07
feat: overhaul to new Hibiscus commons packet system
2025-06-26 15:43:12 -05:00
LoJoSho
4a1a631557 chore: update HibiscusCommons 2025-06-26 15:42:58 -05:00
LoJoSho
ad282a9efe feat: overhaul to new Hibiscus commons system 2025-06-26 15:24:54 -05:00
LoJoSho
86ef4d0efa chore: update test server to 1.21.6 2025-06-24 14:23:19 -05:00
LoJoSho
da09a542f1 chore: update luckperms on test server 2025-06-24 14:14:45 -05:00
LoJoSho
62f32cc03d version bump (2.7.10) 2025-06-24 11:14:37 -05:00
lucian929
ff1addfd65 chore: change defaultmenu configurations for new gui 2025-06-24 11:57:38 -04:00
lucian929
73f013bf1f chore: change defaultmenu for new gui 2025-06-24 08:46:48 -04:00
lucian929
204fee4456 chore: change shading pattern for new gui 2025-06-24 08:43:31 -04:00
LoJoSho
e7ea62a4d2 chore: update adventure dependencies 2025-06-22 14:02:58 -05:00
LoJoSho
42802e41b4 fix: dyeable dye click not defaulting to correct value 2025-06-10 10:08:20 -05:00
LoJoSho
7e7d81d0f8 fix: CosmeticUser not handling null entities 2025-06-10 09:21:37 -05:00
LoJoSho
b07c3c9878 fix: Actions not handling nulls properly 2025-06-09 10:53:27 -05:00
LoJoSho
a19d564460 fix: UNDEFINED DISPLAY ITEM using paper-only methods 2025-06-08 10:21:31 -05:00
LoJoSho
b3408143f0 fix: HMCColor integrate (remove legacy formatting, clean dyeclicktype) 2025-05-31 10:22:30 -05:00
LoJoSho
3c1539285d feat: translations no longer go through legacy formatting 2025-05-31 09:35:41 -05:00
LoJoSho
a642d88af2 chore: update luckperms on test server 2025-05-31 09:11:24 -05:00
LoJoSho
36d4009f5e version bump (2.7.9) 2025-05-31 09:07:45 -05:00
LoJoSho
bebee807bc fix: fix possible database memory leak (as well as improvements in code) 2025-05-29 14:59:57 -05:00
LoJoSho
26c579b69f chore: add cosmetic passengers to dump command 2025-05-25 14:02:04 -05:00
LoJoSho
ef665e7e83 fix: improper call to getEntity when not needed 2025-05-23 13:22:29 -05:00
LoJoSho
7a6475c467 chore: update LuckPerms 2025-05-22 21:07:12 -05:00
LoJoSho
63963cccc3 clean: server listener priorities 2025-05-21 23:56:30 -05:00
Logan
7cf6a3c75c Merge pull request #182 from HibiscusMC/refactorio
refactor: improve worldguard listener
2025-05-18 08:33:37 -05:00
Boy0000
22a5bb4cf1 refactor: improve worldguard listener 2025-05-18 13:22:38 +02:00
Logan
148d163d9c Merge pull request #181 from DebitCardz/fix-add-user
add user to pre unload
2025-05-16 14:50:22 -05:00
Tech
ef36e66c51 add user to pre unload 2025-05-16 15:13:38 -04:00
Logan
e5fda588c3 Merge pull request #179 from DebitCardz/constructor
expose constructor
2025-05-11 18:46:12 -05:00
Logan
3baf2694be Merge pull request #177 from DebitCardz/connection-update
add unload
2025-05-11 15:08:25 -05:00
Tech
a1dafdee5b expose constructor 2025-05-11 14:40:08 -04:00
Tech
e3a42d8b4a add unload 2025-05-10 10:40:30 -04:00
Boy0000
b366f5930b fix: dyed cosmetic item not updated 2025-05-10 00:07:19 +02:00
lojosho
45eb1fa668 chore: update HibiscusCommons 2025-05-09 11:35:13 -05:00
Logan
c466405a81 Merge pull request #176 from HibiscusMC/le-epic-minor-tweaks-again-we-love-it
feat: dyeable click-type & color changes
2025-05-09 10:56:31 -05:00
Boy0000
172ffc0333 refactor: swap to commons color api 2025-05-09 16:00:26 +02:00
Boy0000
41ac857a11 feat: determine color based on new HMCColor API to allow any Material to be dyable 2025-05-09 14:32:29 +02:00
Boy0000
737d63642c feat: add dye-click to settings 2025-05-09 13:46:12 +02:00
Boy
7b9b7678a3 chore: crucial typo fix 2025-05-09 11:42:45 +02:00
Boy
fe88d0c608 fix: bump hmccolor 2025-05-09 11:42:45 +02:00
lojosho
e14935af7b feat: add new processItemMeta implementation that respects MiniMessage/Components as best it can 2025-05-07 22:22:16 -05:00
lojosho
3e83d370f8 chore: update HibiscusCommons 2025-05-03 09:55:01 -05:00
lojosho
874a7f5624 fix: menu packet changes in 1.21.5 2025-05-02 10:50:21 -05:00
lojosho
3af992a291 chore: remove default emote in defaultcosmetics.yml 2025-05-02 10:43:17 -05:00
Logan
9ef7791998 Merge pull request #174 from HibiscusMC/minor-tweaks
Minor tweaks
2025-04-26 09:39:00 -05:00
Boy
1cbe17ddd4 chore: bump triumph-gui 2025-04-26 13:53:09 +02:00
Boy
2841742af9 fix: allow id to be specified in menu-config, default to filename 2025-04-26 12:16:41 +02:00
LoJoSho
6e2f333404 chore: add more debugging for balloon updating 2025-04-19 16:44:03 -05:00
lojosho
af8949b713 chore: remove emotes 2025-04-14 16:35:25 -05:00
lojosho
d6f7d0fcb3 version bump (2.7.8) 2025-04-14 16:34:48 -05:00
lojosho
a8f035bbe2 chore: update API equipCosmetic to use addCosmetic method 2025-03-20 15:29:22 -05:00
lojosho
301fd6a349 chore: move console commands to addCosmetic 2025-03-20 15:27:30 -05:00
lojosho
90b71e7dc9 clean: mark addPlayerCosmetic for removal 2025-03-20 15:27:06 -05:00
lojosho
e6827cdf72 clean: remove version checks on startup for deprecated emotes 2025-03-20 15:22:23 -05:00
lojosho
1212ab2025 chore: update to latest HibiscusCommons; getNMSVersion api adjusted to new enums 2025-03-18 20:42:23 -05:00
lojosho
e31f000de6 chore: add javadocs to MenuTypes; ids menu item types must now be unique 2025-03-17 12:44:13 -05:00
lojosho
70028598d5 fix: menu type not defaulting to empty when not provided 2025-03-17 12:37:49 -05:00
Andre Roldan
07b772d228 Merge pull request #172 from yusshu/remapped
Micro-optimization on methods that are called a lot of times
2025-03-14 09:46:04 -05:00
Andre Roldan
065e48c125 Merge branch 'HibiscusMC:remapped' into remapped 2025-03-11 02:32:34 -05:00
yusshu
49eb1d61ef perf: remove repeated logic when getting location viewers
PacketManager#getViewers already performs the distance <= 0 check
2025-03-10 20:02:55 -05:00
yusshu
9e1a30025f perf: cache some variables in CosmeticBackpackType#update 2025-03-10 19:57:21 -05:00
yusshu
76429ed041 perf: avoid creating unnecessary collection copies 2025-03-10 19:48:30 -05:00
yusshu
f5a01c0104 perf: remove unnecessary null-check 2025-03-10 19:46:02 -05:00
yusshu
545f258f90 perf: avoid creating an ImmutableCollection copy every time updateCosmetics() is called
micro-optimizations, also we avoid calling Map#get again and using cosmetic.update(this) instead
2025-03-10 19:30:00 -05:00
yusshu
720437212b perf: do not double call Map get (microoptimization) 2025-03-10 19:26:50 -05:00
yusshu
d932732d9b feat: add getVelocity() method to UserBalloonManager 2025-03-10 19:24:30 -05:00
yusshu
1118be1153 fix: set velocity after setting the location
otherwise the velocity would be set to zero after teleporting the balloon
2025-03-10 19:24:12 -05:00
Logan
1dc549d645 Merge pull request #171 from yusshu/remapped
feat(api): add CosmeticHolder interface
2025-03-02 23:09:12 -06:00
yusshu
4136d19396 *: go back to 2.7.7, add @NotNull and @Nullable annotations for CosmeticHolder interface 2025-03-03 00:05:19 -05:00
yusshu
52de7425e4 fix: fix compiling error 2025-03-01 18:14:25 -05:00
yusshu
f470e55142 chore: bump up minor version 2025-03-01 18:12:27 -05:00
yusshu
470de3b749 feat(api): add CosmeticHolder interface
allows plugins to implement their custom cosmetic holders and open menus for them, will also allow to open the cosmetics menu of a player to another player (for administration purposes maybe)
2025-03-01 18:05:54 -05:00
LoJoSho
ea72499826 fix: adjust several methods to properly use entity rather than assuming all entities are players 2025-02-28 11:34:21 -06:00
86 changed files with 2475 additions and 2575 deletions

View File

@@ -8,7 +8,7 @@ plugins {
}
group = "com.hibiscusmc"
version = "2.7.6${getGitCommitHash()}"
version = "2.8.3${getGitCommitHash()}"
allprojects {
apply(plugin = "java")
@@ -16,6 +16,7 @@ allprojects {
repositories {
mavenCentral()
mavenLocal()
// Paper Repo
maven("https://repo.papermc.io/repository/maven-public/")
@@ -24,8 +25,7 @@ allprojects {
// Jitpack
maven("https://jitpack.io")
// ProtocolLib repo
maven("https://repo.dmulloy2.net/repository/public/") //ProtocolLib Repo, constantly down
// Geary
maven("https://repo.mineinabyss.com/releases/")
maven("https://repo.mineinabyss.com/snapshots/")
@@ -75,33 +75,40 @@ allprojects {
compileOnly(fileTree("${project.rootDir}/lib") { include("*.jar") })
compileOnly("com.mojang:authlib:1.5.25")
//compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT")
compileOnly("org.jetbrains:annotations:24.1.0")
compileOnly("com.comphenix.protocol:ProtocolLib:5.3.0")
compileOnly("me.clip:placeholderapi:2.11.6")
compileOnly("com.ticxo.modelengine:ModelEngine:R4.0.6")
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.12")
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.12") {
exclude(group = "org.bukkit")
exclude(group = "com.google.guava")
exclude(group = "com.google.code.gson")
exclude(group = "it.unimi.dsi")
exclude(group = "com.sk89q.jnbt")
exclude(group = "org.enginehub.lin-bus.format")
}
compileOnly("io.github.toxicity188:BetterHud-standard-api:1.12") //Standard api
compileOnly("io.github.toxicity188:BetterHud-bukkit-api:1.12") //Platform api
compileOnly("io.github.toxicity188:BetterCommand:1.3") //BetterCommand library
//compileOnly("it.unimi.dsi:fastutil:8.5.14")
compileOnly("org.projectlombok:lombok:1.18.34")
compileOnly("me.lojosho:HibiscusCommons:0.6.0-85d65299")
compileOnly("me.lojosho:HibiscusCommons:0.8.1-d9fbae1d")
// Handled by Spigot Library Loader
compileOnly("net.kyori:adventure-api:4.19.0")
compileOnly("net.kyori:adventure-text-minimessage:4.19.0")
compileOnly("net.kyori:adventure-platform-bukkit:4.3.4")
// Handled by Spigot Library Loader ~ Deprecated as of Dec 16, 2025
/*
compileOnly("net.kyori:adventure-api:4.24.0")
compileOnly("net.kyori:adventure-text-minimessage:4.24.0")
compileOnly("net.kyori:adventure-platform-bukkit:4.4.1")
*/
annotationProcessor("org.projectlombok:lombok:1.18.36")
testCompileOnly("org.projectlombok:lombok:1.18.36")
testAnnotationProcessor("org.projectlombok:lombok:1.18.36")
implementation("dev.triumphteam:triumph-gui:3.1.12-SNAPSHOT") {
implementation("dev.triumphteam:triumph-gui:3.2.0-SNAPSHOT") {
exclude("net.kyori") // Already have adventure API
}
implementation("com.owen1212055:particlehelper:1.0.0-SNAPSHOT")
implementation("com.ticxo.playeranimator:PlayerAnimator:R1.2.7")
}
tasks {
@@ -134,12 +141,14 @@ tasks {
}
runServer {
minecraftVersion("1.21.4")
minecraftVersion("1.21.8")
downloadPlugins {
hangar("PlaceholderAPI", "2.11.6")
url("https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/build/libs/ProtocolLib.jar")
url("https://download.luckperms.net/1567/bukkit/loader/LuckPerms-Bukkit-5.4.150.jar")
hangar("Multiverse-Core", "5.3.4")
url("https://download.luckperms.net/1604/bukkit/loader/LuckPerms-Bukkit-5.5.15.jar")
github("Test-Account666", "PlugManX", "2.4.1", "PlugManX-2.4.1.jar")
//github("gecolay", "GSit", "2.4.3", "GSit-2.4.3.jar")
}
}
@@ -175,8 +184,8 @@ bukkit {
main = "com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin"
apiVersion = "1.20"
authors = listOf("LoJoSho")
depend = listOf("HibiscusCommons", "ProtocolLib")
softDepend = listOf("BetterHud", "ModelEngine", "Oraxen", "ItemsAdder", "Geary", "HMCColor", "WorldGuard", "MythicMobs", "PlaceholderAPI", "SuperVanish", "PremiumVanish", "LibsDisguises", "Denizen", "MMOItems", "Eco")
depend = listOf("HibiscusCommons")
softDepend = listOf("Nexo", "BetterHud", "ModelEngine", "Oraxen", "ItemsAdder", "Geary", "HMCColor", "WorldGuard", "MythicMobs", "PlaceholderAPI", "SuperVanish", "PremiumVanish", "LibsDisguises", "Denizen", "MMOItems", "Eco")
version = "${project.version}"
loadBefore = listOf(
"Cosmin" // Fixes an issue with Cosmin loading before and taking /cosmetic, when messing with what we do.

View File

@@ -1,6 +1,5 @@
package com.hibiscusmc.hmccosmetics;
import com.hibiscusmc.hmccosmetics.api.HMCCosmeticsAPI;
import com.hibiscusmc.hmccosmetics.api.events.HMCCosmeticSetupEvent;
import com.hibiscusmc.hmccosmetics.command.CosmeticCommand;
import com.hibiscusmc.hmccosmetics.command.CosmeticCommandTabComplete;
@@ -10,27 +9,28 @@ import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
import com.hibiscusmc.hmccosmetics.database.Database;
import com.hibiscusmc.hmccosmetics.emotes.EmoteManager;
import com.hibiscusmc.hmccosmetics.gui.Menu;
import com.hibiscusmc.hmccosmetics.gui.Menus;
import com.hibiscusmc.hmccosmetics.gui.special.DyeMenuProvider;
import com.hibiscusmc.hmccosmetics.gui.special.impl.HMCColorDyeMenu;
import com.hibiscusmc.hmccosmetics.hooks.items.HookHMCCosmetics;
import com.hibiscusmc.hmccosmetics.hooks.misc.HookBetterHud;
import com.hibiscusmc.hmccosmetics.hooks.placeholders.HMCPlaceholderExpansion;
import com.hibiscusmc.hmccosmetics.hooks.worldguard.WGHook;
import com.hibiscusmc.hmccosmetics.hooks.worldguard.WGListener;
import com.hibiscusmc.hmccosmetics.listener.PaperPlayerGameListener;
import com.hibiscusmc.hmccosmetics.listener.PlayerConnectionListener;
import com.hibiscusmc.hmccosmetics.listener.PlayerGameListener;
import com.hibiscusmc.hmccosmetics.listener.ServerListener;
import com.hibiscusmc.hmccosmetics.listener.*;
import com.hibiscusmc.hmccosmetics.packets.CosmeticPacketInterface;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.util.PlayerSearchManager;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.TranslationUtil;
import com.ticxo.playeranimator.PlayerAnimatorImpl;
import lombok.Getter;
import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin;
import me.lojosho.hibiscuscommons.HibiscusPlugin;
import me.lojosho.hibiscuscommons.config.serializer.ItemSerializer;
import me.lojosho.hibiscuscommons.config.serializer.LocationSerializer;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.shaded.configupdater.common.config.CommentedConfiguration;
import me.lojosho.shaded.configurate.ConfigurateException;
import me.lojosho.shaded.configurate.ConfigurationOptions;
@@ -50,6 +50,9 @@ public final class HMCCosmeticsPlugin extends HibiscusPlugin {
private static HMCCosmeticsPlugin instance;
private static YamlConfigurationLoader configLoader;
@Getter
private PlayerSearchManager playerSearchManager;
public HMCCosmeticsPlugin() {
super(13873, 1879);
new HookHMCCosmetics();
@@ -61,15 +64,20 @@ public final class HMCCosmeticsPlugin extends HibiscusPlugin {
// Plugin startup logic
instance = this;
// Search Service
this.playerSearchManager = new PlayerSearchManager(this);
// File setup
saveDefaultConfig();
if (!Path.of(getDataFolder().getPath(), "messages.yml").toFile().exists()) saveResource("messages.yml", false);
if (!Path.of(getDataFolder().getPath(), "translations.yml").toFile().exists()) saveResource("translations.yml", false);
if (!Path.of(getDataFolder().getPath() + "/cosmetics/").toFile().exists()) saveResource("cosmetics/defaultcosmetics.yml", false);
if (!Path.of(getDataFolder().getPath() + "/menus/").toFile().exists()) saveResource("menus/defaultmenu.yml", false);
// Player Animator
if (HMCCosmeticsAPI.getNMSVersion().contains("v1_19_R3") || HMCCosmeticsAPI.getNMSVersion().contains("v1_20_R1")) PlayerAnimatorImpl.initialize(this); // PlayerAnimator does not support 1.20.2 yet
if (!Path.of(getDataFolder().getPath() + "/menus/").toFile().exists()) {
saveResource("menus/defaultmenu_hats.yml", false);
saveResource("menus/defaultmenu_balloons.yml", false);
saveResource("menus/defaultmenu_hands.yml", false);
saveResource("menus/defaultmenu_backpacks.yml", false);
}
// Configuration Sync
final File configFile = Path.of(getInstance().getDataFolder().getPath(), "config.yml").toFile();
@@ -89,6 +97,7 @@ public final class HMCCosmeticsPlugin extends HibiscusPlugin {
// Setup
setup();
setPacketInterface(new CosmeticPacketInterface());
// Commands
getServer().getPluginCommand("cosmetic").setExecutor(new CosmeticCommand());
@@ -98,7 +107,9 @@ public final class HMCCosmeticsPlugin extends HibiscusPlugin {
getServer().getPluginManager().registerEvents(new PlayerConnectionListener(), this);
getServer().getPluginManager().registerEvents(new PlayerGameListener(), this);
getServer().getPluginManager().registerEvents(new ServerListener(), this);
// Taken from PaperLib
getServer().getPluginManager().registerEvents(new PlayerMovementListener(), this);
getServer().getPluginManager().registerEvents(playerSearchManager, this);
if (HibiscusCommonsPlugin.isOnPaper()) {
getServer().getPluginManager().registerEvents(new PaperPlayerGameListener(), this);
}
@@ -109,6 +120,15 @@ public final class HMCCosmeticsPlugin extends HibiscusPlugin {
if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null && Settings.isWorldGuardMoveCheck()) {
getServer().getPluginManager().registerEvents(new WGListener(), this);
}
// HMCColor
if (Hooks.isActiveHook("HMCColor")) {
try {
DyeMenuProvider.setDyeMenuProvider(new HMCColorDyeMenu());
} catch (IllegalStateException e) {
getLogger().warning("Unable to set HMCColor as the dye menu. There is likely another plugin registering another dye menu.");
}
}
}
@Override
@@ -125,9 +145,6 @@ public final class HMCCosmeticsPlugin extends HibiscusPlugin {
for (Player player : Bukkit.getOnlinePlayers()) {
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) continue;
if (user.getUserEmoteManager().isPlayingEmote()) {
player.setInvisible(false);
}
if (user.isInWardrobe()) {
user.leaveWardrobe(true);
}
@@ -229,8 +246,6 @@ public final class HMCCosmeticsPlugin extends HibiscusPlugin {
}
}
if (Settings.isEmotesEnabled() && (HMCCosmeticsAPI.getNMSVersion().contains("v1_19_R3") || HMCCosmeticsAPI.getNMSVersion().contains("v1_20_R1"))) EmoteManager.loadEmotes(); // PlayerAnimator does not support 1.20.2 yet
getInstance().getLogger().info("Successfully Enabled HMCCosmetics");
getInstance().getLogger().info(Cosmetics.values().size() + " Cosmetics Successfully Setup");
getInstance().getLogger().info(Menus.getMenuNames().size() + " Menus Successfully Setup");

View File

@@ -10,8 +10,8 @@ import com.hibiscusmc.hmccosmetics.gui.Menus;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUserProvider;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import me.lojosho.hibiscuscommons.nms.MinecraftVersion;
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
import me.lojosho.shaded.configurate.ConfigurationNode;
import org.bukkit.Color;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
@@ -20,7 +20,6 @@ import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.function.BiConsumer;
/**
* The main API class for HMCCosmetics. This class provides methods to interact with the plugin.
@@ -95,7 +94,7 @@ public final class HMCCosmeticsAPI {
* customization
*/
public static void equipCosmetic(@NotNull CosmeticUser user, @NotNull Cosmetic cosmetic, @Nullable Color color) {
user.addPlayerCosmetic(cosmetic, color);
user.addCosmetic(cosmetic, color);
}
/**
@@ -200,7 +199,9 @@ public final class HMCCosmeticsAPI {
* @return the NMS version of the server in string format, or {@code null} if setup is not complete.
*/
public static @Nullable String getNMSVersion() {
return NMSHandlers.getVersion();
MinecraftVersion version = NMSHandlers.getVersion();
if (version == null) return null;
return version.toString();
}
/**

View File

@@ -1,7 +1,6 @@
package com.hibiscusmc.hmccosmetics.api.events;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
/**

View File

@@ -1,54 +0,0 @@
package com.hibiscusmc.hmccosmetics.api.events;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/**
* Called when a player starts playing an emote.
*/
public class PlayerEmoteStartEvent extends PlayerCosmeticEvent implements Cancellable {
private static final HandlerList HANDLER_LIST = new HandlerList();
private final String animationId;
private boolean cancel = false;
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 by calling {@link com.hibiscusmc.hmccosmetics.emotes.EmoteManager#get(String)}.
*
* @return the animation id of the emote which the player started playing
*/
@NotNull
public String getAnimationId() {
return animationId;
}
@Override
public boolean isCancelled() {
return cancel;
}
@Override
public void setCancelled(boolean cancel) {
this.cancel = cancel;
}
@Override
public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}
public static @NotNull HandlerList getHandlerList() {
return HANDLER_LIST;
}
}

View File

@@ -1,64 +0,0 @@
package com.hibiscusmc.hmccosmetics.api.events;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/**
* Called when a player stops playing an emote.
*/
public class PlayerEmoteStopEvent extends PlayerCosmeticEvent implements Cancellable {
private static final HandlerList HANDLER_LIST = new HandlerList();
private final UserEmoteManager.StopEmoteReason reason;
private boolean cancel = false;
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(forRemoval = true)
@NotNull
public UserEmoteManager.StopEmoteReason getStopEmoteReason() {
return reason;
}
/**
* Gets the {@link UserEmoteManager.StopEmoteReason} as to why the emote has stopped playing.
*
* @return the reason why the emote has stopped playing
* @since 2.2.5
*/
public @NotNull UserEmoteManager.StopEmoteReason getReason() {
return reason;
}
@Override
public boolean isCancelled() {
return cancel;
}
@Override
public void setCancelled(boolean cancel) {
this.cancel = cancel;
}
@Override
public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}
public static @NotNull HandlerList getHandlerList() {
return HANDLER_LIST;
}
}

View File

@@ -0,0 +1,43 @@
package com.hibiscusmc.hmccosmetics.api.events;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/**
* Called before a player's data is un-loaded from the plugin.
*
* <p>
* If this event is cancelled, the player's data will not be un-loaded,
* and will be kept in memory.
* </p>
*/
public class PlayerPreUnloadEvent extends PlayerCosmeticEvent implements Cancellable {
private static final HandlerList HANDLER_LIST = new HandlerList();
private boolean cancelled = false;
public PlayerPreUnloadEvent(@NotNull CosmeticUser who) {
super(who);
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
@Override
public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}
public static @NotNull HandlerList getHandlerList() {
return HANDLER_LIST;
}
}

View File

@@ -10,12 +10,11 @@ import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticEmoteType;
import com.hibiscusmc.hmccosmetics.database.Database;
import com.hibiscusmc.hmccosmetics.emotes.EmoteManager;
import com.hibiscusmc.hmccosmetics.gui.Menu;
import com.hibiscusmc.hmccosmetics.gui.Menus;
import com.hibiscusmc.hmccosmetics.gui.special.DyeMenu;
import com.hibiscusmc.hmccosmetics.gui.special.DyeMenuProvider;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
@@ -23,7 +22,6 @@ import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.apache.commons.lang3.EnumUtils;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.OfflinePlayer;
@@ -144,6 +142,11 @@ public class CosmeticCommand implements CommandExecutor {
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) {
if (!silent) MessagesUtil.sendMessage(sender, "invalid-player");
return true;
}
if (!user.canEquipCosmetic(cosmetic) && !console) {
if (!silent) MessagesUtil.sendMessage(player, "no-cosmetic-permission");
return true;
@@ -156,7 +159,7 @@ public class CosmeticCommand implements CommandExecutor {
if (!silent) MessagesUtil.sendMessage(player, "equip-cosmetic", placeholders);
user.addPlayerCosmetic(cosmetic, color);
user.addCosmetic(cosmetic, color);
user.updateCosmetic(cosmetic.getSlot());
return true;
}
@@ -307,13 +310,17 @@ public class CosmeticCommand implements CommandExecutor {
return true;
}
String rawSlot = args[1];
final String rawSlot = args[1];
if (!CosmeticSlot.contains(rawSlot)) {
if (!silent) MessagesUtil.sendMessage(player, "invalid-slot");
return true;
}
CosmeticSlot slot = CosmeticSlot.valueOf(rawSlot);
Cosmetic cosmetic = user.getCosmetic(slot);
final CosmeticSlot slot = CosmeticSlot.valueOf(rawSlot); // This is checked above. While IDEs may say the slot might be null, it will not be.
final Cosmetic cosmetic = user.getCosmetic(slot);
if (cosmetic == null) {
if (!silent) MessagesUtil.sendMessage(player, "invalid-slot");
return true;
}
if (args.length >= 3) {
if (args[2].isEmpty()) {
@@ -325,9 +332,13 @@ public class CosmeticCommand implements CommandExecutor {
if (!silent) MessagesUtil.sendMessage(player, "invalid-color");
return true;
}
user.addPlayerCosmetic(cosmetic, color); // #FFFFFF
user.addCosmetic(cosmetic, color); // #FFFFFF
} else {
DyeMenu.openMenu(user, cosmetic);
if (DyeMenuProvider.hasMenuProvider()) {
DyeMenuProvider.openMenu(player, user, cosmetic);
} else {
if (!silent) MessagesUtil.sendMessage(player, "invalid-color");
}
}
}
case ("setwardrobesetting") -> {
@@ -398,6 +409,7 @@ public class CosmeticCommand implements CommandExecutor {
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
player.sendMessage("Backpack Location -> " + user.getUserBackpackManager().getEntityManager().getLocation());
}
player.sendMessage("Cosmetic Passengers -> " + user.getUserBackpackManager().getAreaEffectEntityId());
player.sendMessage("Cosmetics -> " + user.getCosmetics());
player.sendMessage("EntityId -> " + player.getEntityId());
return true;
@@ -459,59 +471,6 @@ public class CosmeticCommand implements CommandExecutor {
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 (!EmoteManager.has(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;
}
case "disableall" -> {
if (!sender.hasPermission("hmccosmetics.cmd.disableall")) {
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");

View File

@@ -6,7 +6,6 @@ import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
import com.hibiscusmc.hmccosmetics.emotes.EmoteManager;
import com.hibiscusmc.hmccosmetics.gui.Menu;
import com.hibiscusmc.hmccosmetics.gui.Menus;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
@@ -44,8 +43,6 @@ public class CosmeticCommandTabComplete implements TabCompleter {
if (hasPermission(sender, "hmccosmetics.cmd.hide")) completions.add("hide");
if (hasPermission(sender, "hmccosmetics.cmd.show")) completions.add("show");
if (hasPermission(sender, "hmccosmetics.cmd.debug")) completions.add("debug");
if (hasPermission(sender, "hmccosmetics.cmd.emote")) completions.add("emote");
if (hasPermission(sender, "hmccosmetics.cmd.playemote")) completions.add("playemote");
if (hasPermission(sender, "hmccosmetics.cmd.disableall")) completions.add("disableall");
if (hasPermission(sender, "hmccosmetics.cmd.hiddenreasons")) completions.add("hiddenreasons");
if (hasPermission(sender, "hmccosmetics.cmd.clearhiddenreasons")) completions.add("clearhiddenreasons");
@@ -74,7 +71,7 @@ public class CosmeticCommandTabComplete implements TabCompleter {
if (menu.canOpen(user.getPlayer())) completions.add(menu.getId());
}
}
case "dataclear", "hide", "show", "emote", "hiddenreasons", "clearhiddenreasons" -> {
case "dataclear", "hide", "show", "hiddenreasons", "clearhiddenreasons" -> {
for (Player player : Bukkit.getOnlinePlayers()) {
completions.add(player.getName());
}
@@ -102,7 +99,6 @@ public class CosmeticCommandTabComplete implements TabCompleter {
completions.add(wardrobe.getId());
}
}
case "playemote" -> completions.addAll(EmoteManager.getAllNames());
}
StringUtil.copyPartialMatches(args[1], completions, finalCompletions);
}
@@ -112,7 +108,7 @@ public class CosmeticCommandTabComplete implements TabCompleter {
case "dye" -> {
completions.add("#FFFFFF");
}
case "menu", "wardrobe", "apply", "unapply", "playemote" -> {
case "menu", "wardrobe", "apply", "unapply" -> {
for (Player player : Bukkit.getOnlinePlayers()) {
completions.add(player.getName());
}

View File

@@ -35,7 +35,6 @@ public class Settings {
private static final String ITEM_PROCESS_LORE_PATH = "lore";
private static final String DISABLED_GAMEMODE_PATH = "disabled-gamemode";
private static final String DISABLED_GAMEMODE_GAMEMODES_PATH = "gamemodes";
private static final String 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_NEXO_PATH = "nexo";
@@ -43,24 +42,18 @@ public class Settings {
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_ENABLE = "emote-enable";
private static final String COSMETIC_EMOTE_CHECK_PATH = "emote-block-check";
private static final String COSMETIC_EMOTE_AIR_CHECK_PATH = "emote-air-check";
private static final String COSMETIC_EMOTE_DAMAGE_PATH = "emote-damage-leave";
private static final String COSMETIC_EMOTE_INVINCIBLE_PATH = "emote-invincible";
private static final String COSMETIC_EMOTE_CAMERA_PATH = "emote-camera";
private static final String COSMETIC_EMOTE_MOVE_CHECK_PATH = "emote-move";
private static final String COSMETIC_DISABLED_WORLDS_PATH = "disabled-worlds";
private static final String COSMETIC_PACKET_ENTITY_TELEPORT_COOLDOWN_PATH = "entity-cooldown-teleport-packet";
private static final String COSMETIC_BACKPACK_FORCE_RIDING_PACKET_PATH = "backpack-force-riding-packet";
private static final String COSMETIC_DESTROY_LOOSE_COSMETIC_PATH = "destroy-loose-cosmetics";
private static final String COSMETIC_BALLOON_HEAD_FORWARD_PATH = "balloon-head-forward";
private static final String COSMETIC_OFFHAND_PREVENT_SWAPPING = "offhand-prevent-swapping";
private static final String MENU_SETTINGS_PATH = "menu-settings";
private static final String MENU_CLICK_COOLDOWN_PATH = "click-cooldown";
private static final String MENU_CLICK_COOLDOWN_TIME_PATH = "time";
private static final String COSMETIC_TYPE_SETTINGS_PATH = "cosmetic-type";
private static final String EQUIP_CLICK_TYPE = "equip-click";
private static final String UNEQUIP_CLICK_TYPE = "unequip-click";
private static final String DYE_CLICK_TYPE = "dye-click";
private static final String SHADING_PATH = "shading";
private static final String FIRST_ROW_SHIFT_PATH = "first-row-shift";
private static final String SEQUENT_ROW_SHIFT_PATH = "sequent-row-shift";
@@ -104,21 +97,13 @@ public class Settings {
private static boolean nexoChangeReload;
@Getter
private static boolean worldGuardMoveCheck;
@Getter
private static boolean cosmeticEmoteBlockCheck;
private static final HashMap<EquipmentSlot, SlotOptionConfig> slotOptions = new HashMap<>();
@Getter
private static boolean emoteAirCheck;
@Getter
private static boolean emoteDamageLeave;
@Getter
private static boolean emoteInvincible;
@Getter
private static boolean destroyLooseCosmetics;
@Getter
private static boolean backpackForceRidingEnabled;
private static boolean preventOffhandSwapping;
@Getter
private static boolean emotesEnabled;
private static boolean backpackForceRidingEnabled;
@Getter
private static boolean disabledGamemodesEnabled;
@Getter
@@ -134,20 +119,18 @@ public class Settings {
@Getter
private static int tickPeriod;
@Getter
private static int packetEntityTeleportCooldown;
@Getter
private static Long defaultMenuCooldown;
@Getter
private static boolean menuClickCooldown;
@Getter
private static double emoteDistance;
@Getter
private static Vector balloonOffset;
@Getter
private static String cosmeticEquipClickType;
@Getter
private static String cosmeticUnEquipClickType;
@Getter
private static String cosmeticDyeClickType;
@Getter
private static boolean defaultShading;
@Getter
private static String firstRowShift;
@@ -165,10 +148,6 @@ public class Settings {
private static String equipableCosmeticColor;
@Getter
private static String lockedCosmeticColor;
@Getter
private static boolean emoteCameraEnabled;
@Getter
private static boolean emoteMoveCheck;
@Getter @Setter
private static boolean allPlayersHidden;
@Getter
@@ -209,14 +188,9 @@ public class Settings {
unapplyOnDeath = cosmeticSettings.node(UNAPPLY_DEATH_PATH).getBoolean(false);
forcePermissionJoin = cosmeticSettings.node(FORCE_PERMISSION_JOIN_PATH).getBoolean(false);
forceShowOnJoin = cosmeticSettings.node(FORCE_SHOW_COSMETICS_PATH).getBoolean(false);
emotesEnabled = cosmeticSettings.node(COSMETIC_EMOTE_ENABLE).getBoolean(true);
emoteDistance = cosmeticSettings.node(EMOTE_DISTANCE_PATH).getDouble(-3);
cosmeticEmoteBlockCheck = cosmeticSettings.node(COSMETIC_EMOTE_CHECK_PATH).getBoolean(true);
emoteAirCheck = cosmeticSettings.node(COSMETIC_EMOTE_AIR_CHECK_PATH).getBoolean(true);
emoteDamageLeave = cosmeticSettings.node(COSMETIC_EMOTE_DAMAGE_PATH).getBoolean(false);
emoteInvincible = cosmeticSettings.node(COSMETIC_EMOTE_INVINCIBLE_PATH).getBoolean(false);
destroyLooseCosmetics = cosmeticSettings.node(COSMETIC_DESTROY_LOOSE_COSMETIC_PATH).getBoolean(false);
backpackForceRidingEnabled = cosmeticSettings.node(COSMETIC_BACKPACK_FORCE_RIDING_PACKET_PATH).getBoolean(false);
preventOffhandSwapping = cosmeticSettings.node(COSMETIC_OFFHAND_PREVENT_SWAPPING).getBoolean(false);
cosmeticSettings.node(SLOT_OPTIONS_PATH).childrenMap().forEach((key, value) -> {
EquipmentSlot slot = convertConfigToEquipment(key.toString().toLowerCase());
@@ -231,9 +205,6 @@ public class Settings {
tickPeriod = cosmeticSettings.node(TICK_PERIOD_PATH).getInt(-1);
viewDistance = cosmeticSettings.node(VIEW_DISTANCE_PATH).getInt(-3);
emoteCameraEnabled = cosmeticSettings.node(COSMETIC_EMOTE_CAMERA_PATH).getBoolean(true);
emoteMoveCheck = cosmeticSettings.node(COSMETIC_EMOTE_MOVE_CHECK_PATH).getBoolean(false);
packetEntityTeleportCooldown = cosmeticSettings.node(COSMETIC_PACKET_ENTITY_TELEPORT_COOLDOWN_PATH).getInt(-1);
balloonHeadForward = cosmeticSettings.node(COSMETIC_BALLOON_HEAD_FORWARD_PATH).getBoolean(false);
backpackPreventDarkness = cosmeticSettings.node(BACKPACK_PREVENT_DARKNESS_PATH).getBoolean(true);
@@ -255,8 +226,9 @@ public class Settings {
lockedCosmeticColor = shadingSettings.node(LOCKED_COSMETIC_COLOR_PATH).getString();
ConfigurationNode cosmeticTypeSettings = menuSettings.node(COSMETIC_TYPE_SETTINGS_PATH);
cosmeticEquipClickType = cosmeticTypeSettings.node(EQUIP_CLICK_TYPE).getString("ALL");
cosmeticUnEquipClickType = cosmeticTypeSettings.node(UNEQUIP_CLICK_TYPE).getString("ALL");
cosmeticEquipClickType = cosmeticTypeSettings.node(EQUIP_CLICK_TYPE).getString("ANY");
cosmeticUnEquipClickType = cosmeticTypeSettings.node(UNEQUIP_CLICK_TYPE).getString("ANY");
cosmeticDyeClickType = cosmeticTypeSettings.node(DYE_CLICK_TYPE).getString("ANY");
final var balloonSection = cosmeticSettings.node(BALLOON_OFFSET);
balloonOffset = loadVector(balloonSection);

View File

@@ -1,35 +1,69 @@
package com.hibiscusmc.hmccosmetics.cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.behavior.CosmeticUpdateBehavior;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import me.lojosho.hibiscuscommons.config.serializer.ItemSerializer;
import me.lojosho.shaded.configurate.ConfigurationNode;
import me.lojosho.shaded.configurate.serialize.SerializationException;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.logging.Level;
@Getter
@Setter
public abstract class Cosmetic {
protected static ItemStack UNDEFINED_DISPLAY_ITEM_STACK;
@Getter @Setter
static {
UNDEFINED_DISPLAY_ITEM_STACK = new ItemStack(Material.BARRIER);
ItemMeta meta = UNDEFINED_DISPLAY_ITEM_STACK.getItemMeta();
if (meta != null) {
// Legacy methods for Spigot >:(
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&cUndefined Item Display"));
meta.setLore(List.of(
ChatColor.translateAlternateColorCodes('&', "&cPlease check your configurations & console to"),
ChatColor.translateAlternateColorCodes('&', "&censure there are no errors.")));
}
UNDEFINED_DISPLAY_ITEM_STACK.setItemMeta(meta);
}
/** Identifier of the cosmetic. */
private String id;
@Getter @Setter
private String permission;
private ItemStack item;
@Getter @Setter
private String material;
@Getter @Setter
private CosmeticSlot slot;
@Getter @Setter
private boolean dyable;
protected Cosmetic(String id, @NotNull ConfigurationNode config) {
/** Permission to use the cosmetic. */
private String permission;
/** The display {@link ItemStack} of the cosmetic. */
@Getter(AccessLevel.NONE) @Setter(AccessLevel.NONE)
private ItemStack item;
/** The material string of the cosmetic. */
private String material;
/** The {@link CosmeticSlot} this cosmetic occupies. */
private CosmeticSlot slot;
/** Whether the cosmetic is dyeable or not. */
private boolean dyeable;
/** The config for the cosmetic */
private ConfigurationNode config;
protected Cosmetic(@NotNull String id, @NotNull ConfigurationNode config) {
this.id = id;
this.config = config;
if (!config.node("permission").virtual()) {
this.permission = config.node("permission").getString();
@@ -39,23 +73,54 @@ public abstract class Cosmetic {
if (!config.node("item").virtual()) {
this.material = config.node("item", "material").getString();
try {
this.item = generateItemStack(config.node("item"));
} catch(Exception ex) {
MessagesUtil.sendDebugMessages("Forcing %s to use undefined display".formatted(getId()));
this.item = UNDEFINED_DISPLAY_ITEM_STACK;
}
}
MessagesUtil.sendDebugMessages("Slot: " + config.node("slot").getString());
this.slot = CosmeticSlot.valueOf(config.node("slot").getString());
setSlot(CosmeticSlot.valueOf(config.node("slot").getString()));
setDyable(config.node("dyeable").getBoolean(false));
this.dyeable = config.node("dyeable").getBoolean(false);
MessagesUtil.sendDebugMessages("Dyeable " + dyeable);
}
MessagesUtil.sendDebugMessages("Dyeable " + dyable);
Cosmetics.addCosmetic(this);
protected Cosmetic(String id, String permission, ItemStack item, String material, CosmeticSlot slot, boolean dyeable) {
this.id = id;
this.permission = permission;
this.item = item;
this.material = material;
this.slot = slot;
this.dyeable = dyeable;
}
public boolean requiresPermission() {
return permission != null;
}
public abstract void update(CosmeticUser user);
/**
* Dispatched when an update is requested upon the cosmetic. Instead, you should use {@link CosmeticUser#updateCosmetic(CosmeticSlot)})}
* @param user the user to preform the update against
*/
@Deprecated(since = "2.8.2")
public void update(CosmeticUser user) {
if(this instanceof CosmeticUpdateBehavior behavior) {
behavior.dispatchUpdate(user);
}
}
/**
* Action preformed on the update. Instead, you should use {@link CosmeticUser#updateCosmetic(CosmeticSlot)})}
* @param user the user to preform the update against
*/
@Deprecated(since = "2.8.2")
protected void doUpdate(final CosmeticUser user) {
// #update should be the preferred way of interacting with this api now.
this.update(user);
}
@Nullable
public ItemStack getItem() {
@@ -63,6 +128,11 @@ public abstract class Cosmetic {
return item.clone();
}
/**
* Generate an {@link ItemStack} from a {@link ConfigurationNode}.
* @param config the configuration node
* @return the {@link ItemStack}
*/
protected ItemStack generateItemStack(ConfigurationNode config) {
try {
ItemStack item = ItemSerializer.INSTANCE.deserialize(ItemStack.class, config);
@@ -76,4 +146,14 @@ public abstract class Cosmetic {
throw new RuntimeException(e);
}
}
/**
* While cosmetics registered in HMCC are made through a configuration, cosmetics registered from other plugins
* may not and instead opt for {@link Cosmetic#Cosmetic(String, String, ItemStack, String, CosmeticSlot, boolean)}, which doesn't use a config.
* This should be used only for reference.
*/
@ApiStatus.Experimental
public @Nullable ConfigurationNode getConfig() {
return config;
}
}

View File

@@ -0,0 +1,78 @@
package com.hibiscusmc.hmccosmetics.cosmetic;
import com.google.common.collect.ImmutableCollection;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Objects;
/**
* Represents any object that can wear/hold cosmetics,
* users, for example.
*/
public interface CosmeticHolder {
@Nullable Cosmetic getCosmetic(@NotNull CosmeticSlot slot);
@NotNull ImmutableCollection<Cosmetic> getCosmetics();
void addCosmetic(@NotNull Cosmetic cosmetic, @Nullable Color color);
default void addCosmetic(@NotNull Cosmetic cosmetic) {
addCosmetic(cosmetic, null);
}
default void removeCosmetics() {
// Small optimization could be made, but Concurrent modification prevents us from both getting and removing
for (CosmeticSlot slot : CosmeticSlot.values().values()) {
removeCosmeticSlot(slot);
}
}
void removeCosmeticSlot(@NotNull CosmeticSlot slot);
default void removeCosmeticSlot(@NotNull Cosmetic cosmetic) {
removeCosmeticSlot(cosmetic.getSlot());
}
default boolean hasCosmeticInSlot(@NotNull CosmeticSlot slot) {
return getCosmetic(slot) != null;
}
default boolean hasCosmeticInSlot(@NotNull Cosmetic cosmetic) {
final var existingCosmetic = getCosmetic(cosmetic.getSlot());
if (existingCosmetic == null) return false;
return Objects.equals(cosmetic.getId(), existingCosmetic.getId());
}
default boolean canEquipCosmetic(@NotNull Cosmetic cosmetic) {
return canEquipCosmetic(cosmetic, false);
}
boolean canEquipCosmetic(@NotNull Cosmetic cosmetic, boolean ignoreWardrobe);
boolean updateCosmetic(@NotNull CosmeticSlot slot);
boolean updateMovementCosmetic(@NotNull CosmeticSlot slot, final Location from, final Location to);
/**
* Just for backwards compatibility, ensures that the given viewer and the given cosmetic holder
* represent the same user.
*
* @param viewer the viewer
* @param cosmeticHolder the cosmetic holder
*/
@ApiStatus.Internal
static @NotNull CosmeticUser ensureSingleCosmeticUser(@NotNull Player viewer, @NotNull CosmeticHolder cosmeticHolder) {
if (!(cosmeticHolder instanceof CosmeticUser user) || !user.getUniqueId().equals(viewer.getUniqueId())) {
throw new IllegalStateException("This method does not support having a different viewer than" +
" the same cosmetic holder. Needs to be updated to support the overload that takes a viewer and" +
" a cosmetic holder instead of a single CosmeticUser.");
}
return user;
}
}

View File

@@ -2,12 +2,10 @@ package com.hibiscusmc.hmccosmetics.cosmetic;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.cosmetic.types.*;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import lombok.extern.slf4j.Slf4j;
import me.lojosho.shaded.configurate.ConfigurationNode;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
import java.util.function.BiFunction;
@@ -24,13 +22,9 @@ public abstract class CosmeticProvider {
Map.entry(CosmeticSlot.BOOTS, CosmeticArmorType::new),
Map.entry(CosmeticSlot.OFFHAND, CosmeticArmorType::new),
Map.entry(CosmeticSlot.MAINHAND, CosmeticMainhandType::new),
Map.entry(CosmeticSlot.BACKPACK, CosmeticBackpackType::new),
Map.entry(CosmeticSlot.BALLOON, CosmeticBalloonType::new),
Map.entry(CosmeticSlot.EMOTE, CosmeticEmoteType::new)
Map.entry(CosmeticSlot.BALLOON, CosmeticBalloonType::new)
);
private static final String EXCEPTION_MESSAGE = "Unknown slot %s provided for mapping, if you registered your own CosmeticSlot please ensure that you've also registered a custom CosmeticProvider! Or if you have already registered a custom CosmeticProvider ensure it is registered in your plugins `onLoad` method instead of `onEnable`!";

View File

@@ -20,7 +20,6 @@ public class CosmeticSlot {
public static final CosmeticSlot OFFHAND = register("OFFHAND");
public static final CosmeticSlot BACKPACK = register("BACKPACK");
public static final CosmeticSlot BALLOON = register("BALLOON");
public static final CosmeticSlot EMOTE = register("EMOTE");
private final String name;

View File

@@ -0,0 +1,16 @@
package com.hibiscusmc.hmccosmetics.cosmetic.behavior;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.Location;
import org.jetbrains.annotations.NotNull;
/**
* Updates cosmetics whenever a player moves.
*/
public interface CosmeticMovementBehavior {
void dispatchMove(
@NotNull final CosmeticUser user,
@NotNull final Location from,
@NotNull final Location to
);
}

View File

@@ -0,0 +1,13 @@
package com.hibiscusmc.hmccosmetics.cosmetic.behavior;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.jetbrains.annotations.NotNull;
/**
* Generic updates that happen every tick or when manually requested to be dispatched.
*/
public interface CosmeticUpdateBehavior {
void dispatchUpdate(
@NotNull final CosmeticUser user
);
}

View File

@@ -2,6 +2,7 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.behavior.CosmeticUpdateBehavior;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
@@ -15,8 +16,7 @@ import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class CosmeticArmorType extends Cosmetic {
public class CosmeticArmorType extends Cosmetic implements CosmeticUpdateBehavior {
private final EquipmentSlot equipSlot;
public CosmeticArmorType(String id, ConfigurationNode config) {
@@ -31,8 +31,8 @@ public class CosmeticArmorType extends Cosmetic {
}
@Override
public void update(@NotNull CosmeticUser user) {
if (user.getUserEmoteManager().isPlayingEmote() || user.isInWardrobe()) return;
public void dispatchUpdate(@NotNull CosmeticUser user) {
if (user.isInWardrobe()) return;
Entity entity = Bukkit.getEntity(user.getUniqueId());
if (entity == null) return;
if (Settings.getSlotOption(equipSlot).isRequireEmpty() && entity instanceof HumanEntity humanEntity) {
@@ -48,9 +48,11 @@ public class CosmeticArmorType extends Cosmetic {
}
public ItemStack getItem(@NotNull CosmeticUser user, ItemStack cosmeticItem) {
if (!(user.getEntity() instanceof HumanEntity humanEntity)) return null;
Player player = user.getPlayer();
if (player == null) return null;
if (Settings.getSlotOption(equipSlot).isAddEnchantments()) {
ItemStack equippedItem = humanEntity.getInventory().getItem(equipSlot);
ItemStack equippedItem = player.getInventory().getItem(equipSlot);
cosmeticItem.addUnsafeEnchantments(equippedItem.getEnchantments());
}
// Basically, if force offhand is off AND there is no item in an offhand slot, then the equipment packet to add the cosmetic

View File

@@ -2,16 +2,19 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.behavior.CosmeticMovementBehavior;
import com.hibiscusmc.hmccosmetics.cosmetic.behavior.CosmeticUpdateBehavior;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.user.manager.UserBackpackManager;
import com.hibiscusmc.hmccosmetics.user.manager.UserEntity;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import lombok.Getter;
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
import me.lojosho.shaded.configurate.ConfigurationNode;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
@@ -20,11 +23,9 @@ import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.logging.Level;
public class CosmeticBackpackType extends Cosmetic {
@Getter
public class CosmeticBackpackType extends Cosmetic implements CosmeticUpdateBehavior, CosmeticMovementBehavior {
private int height = -1;
private ItemStack firstPersonBackpack;
@@ -38,34 +39,48 @@ public class CosmeticBackpackType extends Cosmetic {
}
@Override
public void update(@NotNull CosmeticUser user) {
Entity entity = Bukkit.getEntity(user.getUniqueId());
if (entity == null) return;
Location loc = entity.getLocation().clone().add(0, 2, 0);
if (user.isInWardrobe() || !user.isBackpackSpawned()) return;
if (user.isHidden()) {
// Sometimes the backpack is not despawned when the player is hidden (weird ass logic happening somewhere)
user.despawnBackpack();
public void dispatchUpdate(@NotNull CosmeticUser user) {
Entity entity = user.getEntity();
if(entity == null) {
return;
}
List<Player> outsideViewers = user.getUserBackpackManager().getEntityManager().refreshViewers(loc);
user.getUserBackpackManager().getEntityManager().teleport(loc);
user.getUserBackpackManager().getEntityManager().setRotation((int) loc.getYaw(), isFirstPersonCompadible());
Location entityLocation = entity.getLocation();
Location loc = entityLocation.clone().add(0, 2, 0);
UserBackpackManager backpackManager = user.getUserBackpackManager();
if(backpackManager == null) return;
UserEntity entityManager = backpackManager.getEntityManager();
if(entityManager == null) return;
entityManager.teleport(loc);
entityManager.setRotation((int) loc.getYaw(), isFirstPersonCompadible());
int firstArmorStandId = backpackManager.getFirstArmorStandId();
List<Player> newViewers = entityManager.refreshViewers(loc);
if(!newViewers.isEmpty()) {
HMCCPacketManager.spawnInvisibleArmorstand(firstArmorStandId, entityLocation, UUID.randomUUID(), newViewers);
PacketManager.equipmentSlotUpdate(firstArmorStandId, EquipmentSlot.HEAD, user.getUserCosmeticItem(this, getItem()), newViewers);
if (user.getPlayer() != null) {
AttributeInstance scaleAttribute = user.getPlayer().getAttribute(Attribute.SCALE);
if (scaleAttribute != null) {
HMCCPacketManager.sendEntityScalePacket(user.getUserBackpackManager().getFirstArmorStandId(), scaleAttribute.getValue(), newViewers);
}
}
}
HMCCPacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), user.getUserBackpackManager().getFirstArmorStandId(), EntityType.ARMOR_STAND, UUID.randomUUID(), outsideViewers);
HMCCPacketManager.sendArmorstandMetadata(user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
PacketManager.equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(this, getItem()), outsideViewers);
// If true, it will send the riding packet to all players. If false, it will send the riding packet only to new players
if (Settings.isBackpackForceRidingEnabled()) HMCCPacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), user.getUserBackpackManager().getEntityManager().getViewers());
else HMCCPacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
if (Settings.isBackpackForceRidingEnabled()) HMCCPacketManager.sendRidingPacket(entity.getEntityId(), firstArmorStandId, entityManager.getViewers());
else HMCCPacketManager.sendRidingPacket(entity.getEntityId(), firstArmorStandId, newViewers);
if (!user.isInWardrobe() && isFirstPersonCompadible() && user.getPlayer() != null) {
if (isFirstPersonCompadible() && !user.isInWardrobe() && user.getPlayer() != null) {
List<Player> owner = List.of(user.getPlayer());
ArrayList<Integer> particleCloud = user.getUserBackpackManager().getAreaEffectEntityId();
ArrayList<Integer> particleCloud = backpackManager.getAreaEffectEntityId();
for (int i = 0; i < particleCloud.size(); i++) {
if (i == 0) {
HMCCPacketManager.sendRidingPacket(entity.getEntityId(), particleCloud.get(i), owner);
@@ -73,23 +88,38 @@ public class CosmeticBackpackType extends Cosmetic {
HMCCPacketManager.sendRidingPacket(particleCloud.get(i - 1), particleCloud.get(i) , owner);
}
}
HMCCPacketManager.sendRidingPacket(particleCloud.get(particleCloud.size() - 1), user.getUserBackpackManager().getFirstArmorStandId(), owner);
HMCCPacketManager.sendRidingPacket(particleCloud.get(particleCloud.size() - 1), firstArmorStandId, owner);
if (!user.isHidden()) {
//if (loc.getPitch() < -70) NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, new ItemStack(Material.AIR), owner);
//else NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, firstPersonBackpack, owner);
PacketManager.equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(this, firstPersonBackpack), owner);
PacketManager.equipmentSlotUpdate(firstArmorStandId, EquipmentSlot.HEAD, user.getUserCosmeticItem(this, firstPersonBackpack), owner);
}
//MessagesUtil.sendDebugMessages("First Person Backpack Update[owner=" + user.getUniqueId() + ",player_location=" + loc + "]!", Level.INFO);
}
user.getUserBackpackManager().showBackpack();
backpackManager.showBackpack();
}
@Override
public void dispatchMove(@NotNull CosmeticUser user, @NotNull Location from, @NotNull Location to) {
@SuppressWarnings("DuplicatedCode") // thanks.
Entity entity = user.getEntity();
if(entity == null) {
return;
}
Location entityLocation = entity.getLocation();
Location loc = entityLocation.clone().add(0, 2, 0);
UserBackpackManager backpackManager = user.getUserBackpackManager();
if(backpackManager == null) return;
UserEntity entityManager = backpackManager.getEntityManager();
if(entityManager == null) return;
entityManager.teleport(loc);
entityManager.setRotation((int) loc.getYaw(), isFirstPersonCompadible());
}
public boolean isFirstPersonCompadible() {
return firstPersonBackpack != null;
}
public ItemStack getFirstPersonBackpack() {
return firstPersonBackpack;
}
}

View File

@@ -2,8 +2,11 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.behavior.CosmeticMovementBehavior;
import com.hibiscusmc.hmccosmetics.cosmetic.behavior.CosmeticUpdateBehavior;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import lombok.Getter;
import me.lojosho.shaded.configurate.ConfigurationNode;
@@ -17,12 +20,12 @@ import org.jetbrains.annotations.NotNull;
import java.util.List;
public class CosmeticBalloonType extends Cosmetic {
public class CosmeticBalloonType extends Cosmetic implements CosmeticUpdateBehavior, CosmeticMovementBehavior {
@Getter
private final String modelName;
@Getter
private List<String> dyableParts;
private List<String> dyeableParts;
@Getter
private final boolean showLead;
@Getter
@@ -41,8 +44,8 @@ public class CosmeticBalloonType extends Cosmetic {
balloonOffset = Settings.loadVector(balloonOffsetNode);
try {
if (!config.node("dyable-parts").virtual()) {
dyableParts = config.node("dyable-parts").getList(String.class);
if (!config.node("dyeable-parts").virtual()) {
dyeableParts = config.node("dyeable-parts").getList(String.class);
}
} catch (SerializationException e) {
// Seriously?
@@ -53,7 +56,7 @@ public class CosmeticBalloonType extends Cosmetic {
}
@Override
public void update(@NotNull CosmeticUser user) {
public void dispatchUpdate(@NotNull CosmeticUser user) {
Entity entity = Bukkit.getEntity(user.getUniqueId());
UserBalloonManager userBalloonManager = user.getBalloonManager();
@@ -65,6 +68,29 @@ public class CosmeticBalloonType extends Cosmetic {
return;
}
Location newLocation = entity.getLocation();
newLocation = newLocation.clone().add(getBalloonOffset());
if (Settings.isBalloonHeadForward()) newLocation.setPitch(0);
if (!user.isHidden() && showLead) {
List<Player> sendTo = userBalloonManager.getPufferfish().refreshViewers(newLocation);
if (sendTo.isEmpty()) return;
user.getBalloonManager().getPufferfish().spawnPufferfish(newLocation, sendTo);
}
}
@Override
public void dispatchMove(@NotNull CosmeticUser user, @NotNull Location from, @NotNull Location to) {
Entity entity = Bukkit.getEntity(user.getUniqueId());
UserBalloonManager userBalloonManager = user.getBalloonManager();
if (entity == null || userBalloonManager == null) return;
if (user.isInWardrobe()) return;
if (!userBalloonManager.getModelEntity().isValid()) {
return;
}
Location newLocation = entity.getLocation();
Location currentLocation = user.getBalloonManager().getLocation();
newLocation = newLocation.clone().add(getBalloonOffset());
@@ -79,26 +105,22 @@ public class CosmeticBalloonType extends Cosmetic {
}
Vector velocity = newLocation.toVector().subtract(currentLocation.toVector());
userBalloonManager.setVelocity(velocity.multiply(1.1));
userBalloonManager.setLocation(newLocation);
userBalloonManager.setVelocity(velocity.multiply(1.1));
MessagesUtil.sendDebugMessages("Balloon Cosmetic Update for " + user.getEntity().getName());
MessagesUtil.sendDebugMessages("Ballon previous location is " + currentLocation);
MessagesUtil.sendDebugMessages("Balloon location set to " + newLocation);
MessagesUtil.sendDebugMessages("Balloon velocity set to " + velocity);
HMCCPacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer);
HMCCPacketManager.sendLeashPacket(userBalloonManager.getPufferfishBalloonId(), entity.getEntityId(), viewer);
if (user.isHidden()) {
userBalloonManager.getPufferfish().hidePufferfish();
return;
}
if (!user.isHidden() && showLead) {
List<Player> sendTo = userBalloonManager.getPufferfish().refreshViewers(newLocation);
if (sendTo.isEmpty()) return;
user.getBalloonManager().getPufferfish().spawnPufferfish(newLocation, sendTo);
}
}
public boolean isDyablePart(String name) {
public boolean isDyeablePart(String name) {
// If player does not define parts, dye whole model
if (dyableParts == null) return true;
if (dyableParts.isEmpty()) return true;
return dyableParts.contains(name);
if (dyeableParts == null) return true;
if (dyeableParts.isEmpty()) return true;
return dyeableParts.contains(name);
}
}

View File

@@ -1,38 +0,0 @@
package com.hibiscusmc.hmccosmetics.cosmetic.types;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import me.lojosho.shaded.configurate.ConfigurationNode;
import org.jetbrains.annotations.NotNull;
public class CosmeticEmoteType extends Cosmetic {
private final String animationId;
private final String text;
public CosmeticEmoteType(String id, ConfigurationNode config) {
super(id, config);
animationId = config.node("animation").getString();
text = config.node("text").getString();
MessagesUtil.sendDebugMessages("CosmeticEmoteType Animation id " + animationId);
}
@Override
public void update(CosmeticUser user) {
// Nothing
}
public void run(@NotNull CosmeticUser user) {
user.getUserEmoteManager().playEmote(this);
}
public String getAnimationId() {
return animationId;
}
public String getText() {
return text;
}
}

View File

@@ -1,23 +0,0 @@
package com.hibiscusmc.hmccosmetics.cosmetic.types;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.HMCCPlayerUtils;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import me.lojosho.shaded.configurate.ConfigurationNode;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class CosmeticMainhandType extends Cosmetic {
public CosmeticMainhandType(String id, ConfigurationNode config) {
super(id, config);
}
@Override
public void update(@NotNull CosmeticUser user) {
Player player = user.getPlayer();
HMCCPacketManager.equipmentSlotUpdate(player.getEntityId(), user, getSlot(), HMCCPacketManager.getViewers(player.getLocation()));
}
}

View File

@@ -1,6 +1,5 @@
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.CosmeticSlot;
@@ -9,7 +8,6 @@ import com.hibiscusmc.hmccosmetics.database.UserData;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.apache.commons.lang3.EnumUtils;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -87,7 +85,7 @@ public abstract class Data {
private boolean shouldHiddenSave(CosmeticUser.HiddenReason reason) {
switch (reason) {
case EMOTE, NONE, GAMEMODE, WORLD, DISABLED -> {
case EMOTE, NONE, GAMEMODE, WORLD, DISABLED, POTION -> {
return false;
}
default -> {

View File

@@ -38,12 +38,14 @@ public class MySQLData extends SQLData {
HMCCosmeticsPlugin plugin = HMCCosmeticsPlugin.getInstance();
try {
openConnection();
if (connection == null) throw new NullPointerException("Connection is null");
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " +
if (connection == null) throw new IllegalStateException("Connection is null");
try (PreparedStatement preparedStatement = connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " +
"(UUID varchar(36) PRIMARY KEY, " +
"COSMETICS MEDIUMTEXT " +
");").execute();
} catch (SQLException | NullPointerException e) {
");")) {
preparedStatement.execute();
}
} catch (SQLException | IllegalStateException e) {
plugin.getLogger().severe("");
plugin.getLogger().severe("");
plugin.getLogger().severe("MySQL DATABASE CAN NOT BE REACHED.");
@@ -60,32 +62,20 @@ public class MySQLData extends SQLData {
@Override
public void clear(UUID uniqueId) {
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
PreparedStatement preparedSt = null;
try {
preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;");
try (PreparedStatement preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;")) {
preparedSt.setString(1, uniqueId.toString());
preparedSt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (preparedSt != null) preparedSt.close();
} catch (SQLException e) {}
}
});
}
private void openConnection() throws SQLException {
// Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
// ...
// });
// connection = DriverManager.getConnection("jdbc:mysql://" + DatabaseSettings.getHost() + ":" + DatabaseSettings.getPort() + "/" + DatabaseSettings.getDatabase(), setupProperties());
// Connection isn't null AND Connection isn't closed :: return
try {
if (isConnectionOpen()) {
return;
} else if (connection != null) close(); // Close connection if still active
if (isConnectionOpen()) return;
if (connection != null) close(); // Close connection if still active
} catch (RuntimeException e) {
e.printStackTrace(); // If isConnectionOpen() throws error
}
@@ -94,17 +84,15 @@ public class MySQLData extends SQLData {
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, setupProperties());
} catch (SQLException e) {
} catch (SQLException | ClassNotFoundException e) {
System.out.println(e.getMessage());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
public void close() {
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
try {
if (connection == null) throw new NullPointerException("Connection is null");
if (connection == null) throw new IllegalStateException("Connection is null");
connection.close();
} catch (SQLException | NullPointerException e) {
System.out.println(e.getMessage());
@@ -115,13 +103,12 @@ public class MySQLData extends SQLData {
@NotNull
private Properties setupProperties() {
Properties props = new Properties();
props.put("user", user);
props.put("password", password);
props.put("autoReconnect", "true");
props.setProperty("user", user);
props.setProperty("password", password);
return props;
}
private boolean isConnectionOpen() throws RuntimeException {
private boolean isConnectionOpen() {
try {
return connection != null && !connection.isClosed();
} catch (SQLException e) {
@@ -143,9 +130,9 @@ public class MySQLData extends SQLData {
}
try {
if (connection == null) throw new NullPointerException("Connection is null");
if (connection == null) throw new IllegalStateException("Connection is null");
ps = connection.prepareStatement(query);
} catch (SQLException | NullPointerException e) {
} catch (SQLException | IllegalStateException e) {
e.printStackTrace();
}

View File

@@ -6,7 +6,6 @@ import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.database.UserData;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -23,22 +22,17 @@ public abstract class SQLData extends Data {
return CompletableFuture.supplyAsync(() -> {
UserData data = new UserData(uniqueId);
PreparedStatement preparedStatement = null;
try {
preparedStatement = preparedStatement("SELECT * FROM COSMETICDATABASE WHERE UUID = ?;");
try (PreparedStatement preparedStatement = preparedStatement("SELECT * FROM COSMETICDATABASE WHERE UUID = ?;")){
preparedStatement.setString(1, uniqueId.toString());
ResultSet rs = preparedStatement.executeQuery();
try (ResultSet rs = preparedStatement.executeQuery()) {
if (rs.next()) {
String rawData = rs.getString("COSMETICS");
HashMap<CosmeticSlot, Map.Entry<Cosmetic, Integer>> cosmetics = deserializeData(rawData);
data.setCosmetics(cosmetics);
}
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (preparedStatement != null) preparedStatement.close();
} catch (SQLException e) {}
}
return data;
});
@@ -48,18 +42,12 @@ public abstract class SQLData extends Data {
@SuppressWarnings("resource")
public void save(CosmeticUser user) {
Runnable run = () -> {
PreparedStatement preparedSt = null;
try {
preparedSt = preparedStatement("REPLACE INTO COSMETICDATABASE(UUID,COSMETICS) VALUES(?,?);");
try (PreparedStatement preparedSt = preparedStatement("REPLACE INTO COSMETICDATABASE(UUID,COSMETICS) VALUES(?,?);")) {
preparedSt.setString(1, user.getUniqueId().toString());
preparedSt.setString(2, serializeData(user));
preparedSt.executeUpdate();
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
try {
if (preparedSt != null) preparedSt.close();
} catch (SQLException e) {}
}
};
if (!HMCCosmeticsPlugin.getInstance().isDisabled()) {

View File

@@ -35,10 +35,12 @@ public class SQLiteData extends SQLData {
connection = DriverManager.getConnection("jdbc:sqlite:" + dataFolder);
openConnection();
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " +
try (PreparedStatement preparedStatement = connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " +
"(UUID varchar(36) PRIMARY KEY, " +
"COSMETICS MEDIUMTEXT " +
");").execute();
");")) {
preparedStatement.execute();
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
@@ -48,27 +50,16 @@ public class SQLiteData extends SQLData {
@SuppressWarnings("resource")
public void clear(UUID uniqueId) {
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
PreparedStatement preparedSt = null;
try {
preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;");
try (PreparedStatement preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;")){
preparedSt.setString(1, uniqueId.toString());
preparedSt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (preparedSt != null) preparedSt.close();
} catch (SQLException e) {}
}
});
}
private void openConnection() throws SQLException {
// Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
// ...
// });
// connection = DriverManager.getConnection("jdbc:mysql://" + DatabaseSettings.getHost() + ":" + DatabaseSettings.getPort() + "/" + DatabaseSettings.getDatabase(), setupProperties());
if (connection != null && !connection.isClosed()) return;
// Close Connection if still active
@@ -88,9 +79,12 @@ public class SQLiteData extends SQLData {
@Override
public PreparedStatement preparedStatement(String query) {
PreparedStatement ps = null;
if (!isConnectionOpen()) MessagesUtil.sendDebugMessages("Connection is not open");
try {
if (!isConnectionOpen()) {
MessagesUtil.sendDebugMessages("Connection is not open");
openConnection();
}
ps = connection.prepareStatement(query);
} catch (SQLException e) {
e.printStackTrace();

View File

@@ -1,85 +0,0 @@
package com.hibiscusmc.hmccosmetics.emotes;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.ticxo.playeranimator.api.PlayerAnimator;
import com.ticxo.playeranimator.api.animation.pack.AnimationPack;
import org.apache.commons.io.FilenameUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* Manages Emotes
*/
@SuppressWarnings("SpellCheckingInspection")
public class EmoteManager {
private static final @NotNull Map<String, String> emotes = new HashMap<>();
/**
* Loads all BlockBench animations from the emotes folder and puts it into the animation manager registry and local registry
*/
public static void loadEmotes() {
// Clear the PlayerAnimator and local registries
PlayerAnimator.api.getAnimationManager().clearRegistry();
emotes.clear();
// Get the emote directory and check if it exists
File emoteDir = new File(HMCCosmeticsPlugin.getInstance().getDataFolder().getPath() + "/emotes/");
if (!emoteDir.exists()) return;
// Get all the files inside the directory and check if it isn't 0
File[] emoteFiles = emoteDir.listFiles();
if (emoteFiles == null || emoteFiles.length == 0) return;
// Remove any files that don't have the file extension ".bbmodel" and check if there are still resulting files
emoteFiles = Arrays.stream(emoteFiles).filter(file -> file.getPath().endsWith(".bbmodel")).distinct().toArray(File[]::new);
if (emoteFiles.length == 0) return;
// Loop through all files, importing all block bench animations into the registry
for (File animationFile : emoteFiles) {
String animationKey = FilenameUtils.removeExtension(animationFile.getName());
PlayerAnimator.api.getAnimationManager().importAnimations(animationKey, animationFile);
}
// Loops through all the entries in the registries and unpacks any animation packs to ensure if there were multiple animations
// inside a singular file, that they are added to the local registry individually for tab completion
for (Map.Entry<String, AnimationPack> packEntry : PlayerAnimator.api.getAnimationManager().getRegistry().entrySet()) {
packEntry.getValue().getAnimations().keySet().forEach(animationName -> {
// API key is the format "animationKey.animationFileName.animationName"
String apiKey = packEntry.getKey().replace(":", ".") + "." + animationName;
emotes.put(animationName, apiKey);
});
}
}
/**
* Returns true if there is an animation with the specified name
* @param animationName Name whose presence is to be tested
* @return True if this registry contains a mapping for the specified name
*/
public static boolean has(@NotNull String animationName) {
return emotes.containsKey(animationName);
}
/**
* Returns the {@code API key} to which the specified name is mapped, or {@code null} if this map contains no mapping for the name.
* @param animationName Name whose {@code API key} is to be fetched
* @return The {@code API key} of the specified name or {@code null} if there was no animation name found
*/
public static @Nullable String get(@NotNull String animationName) {
return emotes.get(animationName);
}
/**
* Gets a set of all the laoded animation names
* @return A set of all loaded animation names
*/
public static @NotNull Set<String> getAllNames() {
return emotes.keySet();
}
}

View File

@@ -5,6 +5,7 @@ import com.hibiscusmc.hmccosmetics.api.events.PlayerMenuCloseEvent;
import com.hibiscusmc.hmccosmetics.api.events.PlayerMenuOpenEvent;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
import com.hibiscusmc.hmccosmetics.gui.type.Type;
import com.hibiscusmc.hmccosmetics.gui.type.Types;
@@ -13,21 +14,18 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import dev.triumphteam.gui.builder.item.ItemBuilder;
import dev.triumphteam.gui.components.GuiType;
import dev.triumphteam.gui.components.InventoryProvider;
import dev.triumphteam.gui.guis.Gui;
import dev.triumphteam.gui.guis.GuiItem;
import lombok.Getter;
import me.lojosho.hibiscuscommons.config.serializer.ItemSerializer;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.hibiscuscommons.util.AdventureUtils;
import me.lojosho.hibiscuscommons.util.StringUtils;
import me.lojosho.shaded.configurate.ConfigurationNode;
import me.lojosho.shaded.configurate.serialize.SerializationException;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
@@ -56,7 +54,7 @@ public class Menu {
private final boolean shading;
public Menu(String id, @NotNull ConfigurationNode config) {
this.id = id;
this.id = config.node("id").getString(id);
this.config = config;
title = config.node("title").getString("chest");
@@ -108,8 +106,7 @@ public class Menu {
int priority = config.node("priority").getInt(1);
Type type = null;
Type type = Types.getDefaultType();
if (!config.node("type").virtual()) {
String typeId = config.node("type").getString("");
if (Types.isType(typeId)) type = Types.getType(typeId);
@@ -123,7 +120,7 @@ public class Menu {
menuItems.sort(priorityCompare);
items.put(slot, menuItems);
} else {
items.put(slot, new ArrayList<>(Arrays.asList(menuItem)));
items.put(slot, new ArrayList<>(List.of(menuItem)));
}
}
}
@@ -136,18 +133,25 @@ public class Menu {
public void openMenu(@NotNull CosmeticUser user, boolean ignorePermission) {
Player player = user.getPlayer();
if (player == null) return;
openMenu(player, user, ignorePermission);
}
public void openMenu(@NotNull Player viewer, @NotNull CosmeticHolder cosmeticHolder) {
openMenu(viewer, cosmeticHolder, false);
}
public void openMenu(@NotNull Player viewer, @NotNull CosmeticHolder cosmeticHolder, boolean ignorePermission) {
if (!ignorePermission && !permissionNode.isEmpty()) {
if (!player.hasPermission(permissionNode) && !player.isOp()) {
MessagesUtil.sendMessage(player, "no-permission");
if (!viewer.hasPermission(permissionNode) && !viewer.isOp()) {
MessagesUtil.sendMessage(viewer, "no-permission");
return;
}
}
final Component component = AdventureUtils.MINI_MESSAGE.deserialize(Hooks.processPlaceholders(player, this.title));
final Component component = AdventureUtils.MINI_MESSAGE.deserialize(Hooks.processPlaceholders(viewer, this.title));
Gui gui = Gui.gui()
.title(component)
.type(GuiType.CHEST)
.rows(this.rows)
.inventory((title, owner, rows) -> Bukkit.createInventory(owner, rows, title))
.inventory((title, owner, type) -> Bukkit.createInventory(owner, rows * 9, title))
.create();
gui.setDefaultClickAction(event -> event.setCancelled(true));
@@ -159,7 +163,7 @@ public class Menu {
Bukkit.getScheduler().cancelTask(taskid.get());
}
updateMenu(user, gui);
updateMenu(viewer, cosmeticHolder, gui);
};
if (refreshRate != -1) {
@@ -170,25 +174,36 @@ public class Menu {
});
gui.setCloseGuiAction(event -> {
if (cosmeticHolder instanceof CosmeticUser user) {
PlayerMenuCloseEvent closeEvent = new PlayerMenuCloseEvent(user, this, event.getReason());
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> Bukkit.getPluginManager().callEvent(closeEvent));
}
if (taskid.get() != -1) Bukkit.getScheduler().cancelTask(taskid.get());
});
// API
PlayerMenuOpenEvent event = new PlayerMenuOpenEvent(user, this);
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> Bukkit.getPluginManager().callEvent(event));
if (event.isCancelled()) return;
// Internal
Runnable openGuiTask = () -> {
gui.open(viewer);
updateMenu(viewer, cosmeticHolder, gui); // fixes shading? I know I do this twice but it's easier than writing a whole new class to deal with this shit
};
// API
if (cosmeticHolder instanceof CosmeticUser user) {
PlayerMenuOpenEvent event = new PlayerMenuOpenEvent(user, this);
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
gui.open(player);
updateMenu(user, gui); // fixes shading? I know I do this twice but it's easier than writing a whole new class to deal with this shit
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
openGuiTask.run();
}
});
}
// Internal
else {
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), openGuiTask);
}
}
private void updateMenu(CosmeticUser user, Gui gui) {
private void updateMenu(Player viewer, CosmeticHolder cosmeticHolder, Gui gui) {
StringBuilder title = new StringBuilder(this.title);
int row = 0;
@@ -212,15 +227,15 @@ public class Menu {
// Handles the items
List<MenuItem> menuItems = items.get(i);
MenuItem item = menuItems.get(0);
updateItem(user, gui, i);
updateItem(viewer, cosmeticHolder, gui, i);
if (item.type() instanceof TypeCosmetic) {
Cosmetic cosmetic = Cosmetics.getCosmetic(item.itemConfig().node("cosmetic").getString(""));
if (cosmetic == null) continue;
if (user.hasCosmeticInSlot(cosmetic)) {
if (cosmeticHolder.hasCosmeticInSlot(cosmetic)) {
title.append(Settings.getEquippedCosmeticColor());
} else {
if (user.canEquipCosmetic(cosmetic, true)) {
if (cosmeticHolder.canEquipCosmetic(cosmetic, true)) {
title.append(Settings.getEquipableCosmeticColor());
} else {
title.append(Settings.getLockedCosmeticColor());
@@ -236,42 +251,42 @@ public class Menu {
}
}
MessagesUtil.sendDebugMessages("Updated menu with title " + title);
gui.updateTitle(StringUtils.parseStringToString(Hooks.processPlaceholders(user.getPlayer(), title.toString())));
gui.updateTitle(AdventureUtils.MINI_MESSAGE.deserialize(Hooks.processPlaceholders(viewer, title.toString())));
} else {
for (int i = 0; i < gui.getInventory().getSize(); i++) {
if (items.containsKey(i)) {
updateItem(user, gui, i);
updateItem(viewer, cosmeticHolder, gui, i);
}
}
}
}
private void updateItem(CosmeticUser user, Gui gui, int slot) {
private void updateItem(Player viewer, CosmeticHolder cosmeticHolder, Gui gui, int slot) {
if (!items.containsKey(slot)) return;
List<MenuItem> menuItems = items.get(slot);
if (menuItems.isEmpty()) return;
for (MenuItem item : menuItems) {
Type type = item.type();
ItemStack modifiedItem = getMenuItem(user, type, item.itemConfig(), item.item().clone(), slot);
ItemStack modifiedItem = getMenuItem(viewer, cosmeticHolder, type, item.itemConfig(), item.item().clone(), slot);
if (modifiedItem.getType().isAir()) continue;
GuiItem guiItem = ItemBuilder.from(modifiedItem).asGuiItem();
guiItem.setAction(event -> {
UUID uuid = user.getUniqueId();
UUID uuid = viewer.getUniqueId();
if (Settings.isMenuClickCooldown()) {
Long userCooldown = Menus.getCooldown(uuid);
if (userCooldown != 0 && (System.currentTimeMillis() - Menus.getCooldown(uuid) <= getCooldown())) {
MessagesUtil.sendDebugMessages("Cooldown for " + user.getUniqueId() + " System time: " + System.currentTimeMillis() + " Cooldown: " + Menus.getCooldown(user.getUniqueId()) + " Difference: " + (System.currentTimeMillis() - Menus.getCooldown(user.getUniqueId())));
MessagesUtil.sendMessage(user.getPlayer(), "on-click-cooldown");
MessagesUtil.sendDebugMessages("Cooldown for " + viewer.getUniqueId() + " System time: " + System.currentTimeMillis() + " Cooldown: " + Menus.getCooldown(viewer.getUniqueId()) + " Difference: " + (System.currentTimeMillis() - Menus.getCooldown(viewer.getUniqueId())));
MessagesUtil.sendMessage(viewer, "on-click-cooldown");
return;
} else {
Menus.addCooldown(user.getUniqueId(), System.currentTimeMillis());
Menus.addCooldown(uuid, System.currentTimeMillis());
}
}
MessagesUtil.sendDebugMessages("Updated Menu Item in slot number " + slot);
final ClickType clickType = event.getClick();
if (type != null) type.run(user, item.itemConfig(), clickType);
updateMenu(user, gui);
if (type != null) type.run(viewer, cosmeticHolder, item.itemConfig(), clickType);
updateMenu(viewer, cosmeticHolder, gui);
});
MessagesUtil.sendDebugMessages("Set an item in slot " + slot + " in the menu of " + getId());
@@ -306,11 +321,11 @@ public class Menu {
return slots;
}
@Contract("_, _, _, _, _ -> param2")
@Contract("_, _, _, _, _, _ -> param4")
@NotNull
private ItemStack getMenuItem(CosmeticUser user, Type type, ConfigurationNode config, ItemStack itemStack, int slot) {
private ItemStack getMenuItem(Player viewer, CosmeticHolder cosmeticHolder, Type type, ConfigurationNode config, ItemStack itemStack, int slot) {
if (!itemStack.hasItemMeta()) return itemStack;
return type.setItem(user, config, itemStack, slot);
return type.setItem(viewer, cosmeticHolder, config, itemStack, slot);
}
public boolean canOpen(Player player) {

View File

@@ -3,9 +3,10 @@ package com.hibiscusmc.hmccosmetics.gui;
import com.hibiscusmc.hmccosmetics.gui.type.Type;
import me.lojosho.shaded.configurate.ConfigurationNode;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public record MenuItem(List<Integer> slots, ItemStack item, Type type, int priority, ConfigurationNode itemConfig) {
public record MenuItem(@NotNull List<Integer> slots, @NotNull ItemStack item, Type type, int priority, ConfigurationNode itemConfig) {
}

View File

@@ -3,8 +3,6 @@ package com.hibiscusmc.hmccosmetics.gui;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import lombok.Getter;
import lombok.Setter;
import me.lojosho.shaded.configurate.CommentedConfigurationNode;
import me.lojosho.shaded.configurate.ConfigurateException;
import me.lojosho.shaded.configurate.yaml.YamlConfigurationLoader;

View File

@@ -1,6 +1,8 @@
package com.hibiscusmc.hmccosmetics.gui.action;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public abstract class Action {
@@ -16,5 +18,13 @@ public abstract class Action {
return this.id;
}
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
run(CosmeticHolder.ensureSingleCosmeticUser(viewer, cosmeticHolder), raw);
}
/**
* @deprecated Override {@link #run(Player, CosmeticHolder, String)} instead.
*/
@Deprecated
public abstract void run(CosmeticUser user, String raw);
}

View File

@@ -1,13 +1,16 @@
package com.hibiscusmc.hmccosmetics.gui.action;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
import com.hibiscusmc.hmccosmetics.gui.action.actions.*;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
@SuppressWarnings("unused")
public class Actions {
@@ -28,7 +31,6 @@ public class Actions {
private static final ActionCosmeticHide ACTION_HIDE = new ActionCosmeticHide();
private static final ActionCosmeticToggle ACTION_TOGGLE = new ActionCosmeticToggle();
public static Action getAction(@NotNull String id) {
return actions.get(id.toUpperCase());
}
@@ -41,16 +43,20 @@ public class Actions {
actions.put(action.getId().toUpperCase(), action);
}
public static void runActions(CosmeticUser user, @NotNull List<String> raw) {
public static void runActions(Player viewer, CosmeticHolder cosmeticHolder, @NotNull List<String> raw) {
for (String a : raw) {
String id = StringUtils.substringBetween(a, "[", "]").toUpperCase();
String id = StringUtils.substringBetween(a, "[", "]");
String message = StringUtils.substringAfter(a, "] ");
MessagesUtil.sendDebugMessages("ID is " + id + " // Raw Data is " + message);
if (isAction(id)) {
getAction(id).run(user, message);
if (id != null && isAction(id.toUpperCase())) {
getAction(id).run(viewer, cosmeticHolder, message);
} else {
MessagesUtil.sendDebugMessages("Possible ids: " + actions.keySet());
MessagesUtil.sendDebugMessages("Invalid Action ID (" + id + ") used in menus (Full raw: '" + a + "'). Make sure all actions are properly typed out. Here are all possible actions: " + actions.keySet(), Level.WARNING);
}
}
}
public static void runActions(CosmeticUser user, @NotNull List<String> raw) {
runActions(user.getPlayer(), user, raw);
}
}

View File

@@ -1,7 +1,9 @@
package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class ActionCloseMenu extends Action {
@@ -10,8 +12,13 @@ public class ActionCloseMenu extends Action {
super("close");
}
@Override
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
viewer.closeInventory();
}
@Override
public void run(@NotNull CosmeticUser user, String raw) {
user.getPlayer().closeInventory();
run(user.getPlayer(), user, raw);
}
}

View File

@@ -1,10 +1,12 @@
package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class ActionConsoleCommand extends Action {
@@ -13,8 +15,15 @@ public class ActionConsoleCommand extends Action {
super("console-command");
}
@Override
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
// todo: some of these generalizations may require more specific implementations, for example,
// todo: what if we wanted to execute console commands only for the cosmetic holder?
HMCCosmeticsPlugin.getInstance().getServer().dispatchCommand(Bukkit.getConsoleSender(), Hooks.processPlaceholders(viewer, raw));
}
@Override
public void run(@NotNull CosmeticUser user, String raw) {
HMCCosmeticsPlugin.getInstance().getServer().dispatchCommand(Bukkit.getConsoleSender(), Hooks.processPlaceholders(user.getPlayer(), raw));
run(user.getPlayer(), user, raw);
}
}

View File

@@ -1,7 +1,9 @@
package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class ActionCosmeticHide extends Action {
@@ -11,8 +13,14 @@ public class ActionCosmeticHide extends Action {
}
@Override
public void run(@NotNull CosmeticUser user, String raw) {
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
if (!(cosmeticHolder instanceof CosmeticUser user)) return;
if (user.isHidden()) return;
user.hideCosmetics(CosmeticUser.HiddenReason.ACTION);
}
@Override
public void run(@NotNull CosmeticUser user, String raw) {
run(user.getPlayer(), user, raw);
}
}

View File

@@ -1,7 +1,9 @@
package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class ActionCosmeticShow extends Action {
@@ -11,11 +13,17 @@ public class ActionCosmeticShow extends Action {
}
@Override
public void run(@NotNull CosmeticUser user, String raw) {
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
if (!(cosmeticHolder instanceof CosmeticUser user)) return;
if (!user.isHidden()) return;
// Do not hide if it's already off for WG
if (!user.isHidden(CosmeticUser.HiddenReason.ACTION) && !user.isHidden(CosmeticUser.HiddenReason.COMMAND)) return;
user.showCosmetics(CosmeticUser.HiddenReason.ACTION);
}
@Override
public void run(@NotNull CosmeticUser user, String raw) {
run(user.getPlayer(), user, raw);
}
}

View File

@@ -1,7 +1,9 @@
package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class ActionCosmeticToggle extends Action {
@@ -11,7 +13,8 @@ public class ActionCosmeticToggle extends Action {
}
@Override
public void run(@NotNull CosmeticUser user, String raw) {
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
if (!(cosmeticHolder instanceof CosmeticUser user)) return;
if (user.isHidden()) {
if (!user.isHidden(CosmeticUser.HiddenReason.ACTION) && !user.isHidden(CosmeticUser.HiddenReason.COMMAND)) return;
user.showCosmetics(CosmeticUser.HiddenReason.ACTION);
@@ -20,4 +23,9 @@ public class ActionCosmeticToggle extends Action {
user.hideCosmetics(CosmeticUser.HiddenReason.ACTION);
}
@Override
public void run(@NotNull CosmeticUser user, String raw) {
run(user.getPlayer(), user, raw);
}
}

View File

@@ -1,9 +1,11 @@
package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.entity.Player;
public class ActionEquip extends Action {
@@ -12,10 +14,15 @@ public class ActionEquip extends Action {
}
@Override
public void run(CosmeticUser user, String raw) {
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
Cosmetic cosmetic = Cosmetics.getCosmetic(raw);
if (cosmetic == null) return;
user.addPlayerCosmetic(cosmetic);
cosmeticHolder.addCosmetic(cosmetic);
}
@Override
public void run(CosmeticUser user, String raw) {
run(user.getPlayer(), user, raw);
}
}

View File

@@ -1,10 +1,12 @@
package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
import com.hibiscusmc.hmccosmetics.gui.Menu;
import com.hibiscusmc.hmccosmetics.gui.Menus;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.bukkit.entity.Player;
import java.util.logging.Level;
@@ -15,7 +17,7 @@ public class ActionMenu extends Action {
}
@Override
public void run(CosmeticUser user, String raw) {
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
boolean ignorePermission = false;
raw = raw.replaceAll(" ", ""); // Removes all spaces
@@ -32,6 +34,11 @@ public class ActionMenu extends Action {
Menu menu = Menus.getMenu(raw);
MessagesUtil.sendDebugMessages(raw + " | " + ignorePermission);
menu.openMenu(user, ignorePermission);
menu.openMenu(viewer, cosmeticHolder, ignorePermission);
}
@Override
public void run(CosmeticUser user, String raw) {
run(user.getPlayer(), user, raw);
}
}

View File

@@ -1,8 +1,10 @@
package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class ActionMessage extends Action {
@@ -11,8 +13,13 @@ public class ActionMessage extends Action {
super("message");
}
@Override
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
MessagesUtil.sendMessageNoKey(viewer, raw);
}
@Override
public void run(@NotNull CosmeticUser user, String raw) {
MessagesUtil.sendMessageNoKey(user.getPlayer(), raw);
run(user.getPlayer(), user, raw);
}
}

View File

@@ -1,5 +1,6 @@
package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
@@ -24,7 +25,7 @@ public class ActionParticle extends Action {
@Override
@SuppressWarnings("ConstantConditions")
public void run(CosmeticUser user, @NotNull String raw) {
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
String[] rawString = raw.split(" ");
ParticleType<?, ?> particleType = Particles.fromKey(NamespacedKey.minecraft(rawString[0].toLowerCase()));
if (particleType == null) {
@@ -43,9 +44,14 @@ public class ActionParticle extends Action {
}
particle = HMCCServerUtils.addParticleValues(particle, rawString);
Location location = user.getPlayer().getLocation();
Location location = viewer.getLocation();
for (Player player : HMCCPacketManager.getViewers(location)) {
particle.compile().send(player, location);
}
}
@Override
public void run(CosmeticUser user, @NotNull String raw) {
run(user.getPlayer(), user, raw);
}
}

View File

@@ -1,9 +1,11 @@
package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class ActionPlayerCommand extends Action {
@@ -12,8 +14,14 @@ public class ActionPlayerCommand extends Action {
super("player-command");
}
@Override
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
// todo: what if we wanted the cosmetic holder to execute the command instead
viewer.performCommand(MessagesUtil.processStringNoKeyString(viewer, Hooks.processPlaceholders(viewer, raw)));
}
@Override
public void run(@NotNull CosmeticUser user, String raw) {
user.getPlayer().performCommand(MessagesUtil.processStringNoKeyString(user.getPlayer(), Hooks.processPlaceholders(user.getPlayer(), raw)));
run(user.getPlayer(), user, raw);
}
}

View File

@@ -1,5 +1,6 @@
package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
@@ -16,8 +17,7 @@ public class ActionSound extends Action {
}
@Override
public void run(@NotNull CosmeticUser user, @NotNull String raw) {
Player player = user.getPlayer();
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
String[] processedString = raw.split(" ");
String soundName = processedString[0];
@@ -31,6 +31,11 @@ public class ActionSound extends Action {
MessagesUtil.sendDebugMessages("Attempting to play " + soundName, Level.INFO);
player.playSound(player.getLocation(), soundName, volume, pitch);
viewer.playSound(viewer.getLocation(), soundName, volume, pitch);
}
@Override
public void run(@NotNull CosmeticUser user, @NotNull String raw) {
run(user.getPlayer(), user, raw);
}
}

View File

@@ -1,9 +1,10 @@
package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.apache.commons.lang3.EnumUtils;
import org.bukkit.entity.Player;
public class ActionUnequip extends Action {
@@ -12,10 +13,15 @@ public class ActionUnequip extends Action {
}
@Override
public void run(CosmeticUser user, String raw) {
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
if (!CosmeticSlot.contains(raw)) return;
CosmeticSlot slot = CosmeticSlot.valueOf(raw);
user.removeCosmeticSlot(slot);
cosmeticHolder.removeCosmeticSlot(slot);
}
@Override
public void run(CosmeticUser user, String raw) {
run(user.getPlayer(), user, raw);
}
}

View File

@@ -1,76 +1,20 @@
package com.hibiscusmc.hmccosmetics.gui.special;
import com.hibiscusmc.hmccolor.HMCColorApi;
import com.hibiscusmc.hmccolor.shaded.gui.guis.Gui;
import com.hibiscusmc.hmccolor.shaded.gui.guis.GuiItem;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.hibiscuscommons.util.ColorBuilder;
import me.lojosho.hibiscuscommons.util.StringUtils;
import org.bukkit.*;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class DyeMenu {
public interface DyeMenu {
/**
* Overrideable method that is called when a player wishing to dye a menu.
* After the method is called, the menu plugin itself is supposed to handle everything else, including adding the cosmetic to the CosmeticHolder
*
* @param viewer The player that is viewing the menu
* @param cosmeticHolder The CosmeticHolder that is being dyed (Can be different from the viewer)
* @param cosmetic (The cosmetic that is wished to be dyed)
*/
void openMenu(@NotNull Player viewer, @NotNull CosmeticHolder cosmeticHolder, @NotNull Cosmetic cosmetic);
public static void openMenu(@NotNull CosmeticUser user, Cosmetic cosmetic) {
Player player = user.getPlayer();
if (player == null) return;
if (!Hooks.isActiveHook("HMCColor")) {
addCosmetic(user, cosmetic, null);
return;
}
ItemStack originalItem = cosmetic.getItem();
if (originalItem == null || !cosmetic.isDyable()) return;
Gui gui = HMCColorApi.createColorMenu(player);
gui.updateTitle(Hooks.processPlaceholders(player, StringUtils.parseStringToString(Settings.getDyeMenuName())));
gui.setItem(Settings.getDyeMenuInputSlot(), new GuiItem(originalItem));
gui.setDefaultTopClickAction(event -> {
if (event.getSlot() == Settings.getDyeMenuOutputSlot()) {
ItemStack item = event.getInventory().getItem(Settings.getDyeMenuOutputSlot());
if (item == null) return;
ItemMeta meta = item.getItemMeta();
if (meta == null) return;
Color color = null;
if (meta instanceof LeatherArmorMeta leatherMeta) {
color = leatherMeta.getColor();
} else if (meta instanceof PotionMeta potionMeta) {
color = potionMeta.getColor();
} else if (meta instanceof MapMeta mapMeta) {
color = mapMeta.getColor();
} else if (meta instanceof FireworkEffectMeta fireworkEffectMeta) {
FireworkEffect effect = fireworkEffectMeta.getEffect();
if (effect != null) {
color = effect.getColors().stream().findFirst().isPresent() ? effect.getColors().stream().findFirst().get() : null;
}
}
if (color == null) return;
addCosmetic(user, cosmetic, color);
event.setCancelled(true);
} else event.setCancelled(true);
});
gui.setPlayerInventoryAction(event -> event.setCancelled(true));
gui.setCloseGuiAction(event -> {});
gui.open(player);
}
private static void addCosmetic(@NotNull CosmeticUser user, @NotNull Cosmetic cosmetic, @Nullable 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);
}
}

View File

@@ -0,0 +1,46 @@
package com.hibiscusmc.hmccosmetics.gui.special;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class DyeMenuProvider {
private static DyeMenu instance = null;
/**
* Sets the provider of the DyeMenu. Check {@link DyeMenuProvider#hasMenuProvider()} before attempting to set this,
* it is locked once a dye menu has been set!
* @param dyeMenu The dye menu implementation that wishes to be the provider.
* @throws IllegalStateException IllegalStateException will be thrown if a dye menu provider already is set by another plugin.
*/
public static void setDyeMenuProvider(@NotNull DyeMenu dyeMenu) throws IllegalStateException {
if (instance != null) {
throw new IllegalStateException("DyeMenu Implementation has already been set by another plugin.");
}
instance = dyeMenu;
}
/**
* Called when wishing to dye a cosmetic to hand it off to the dye menu implementation
* @param viewer The viewer of the menu
* @param cosmeticHolder The cosmetic holder that the player viewer wishing to modify (could be themselves or another CosmeticHolder)
* @param cosmetic The cosmetic the user wishes to dye
* @throws IllegalStateException IllegalStateException will be thrown if the dye menu instance is null (Check {@link DyeMenuProvider#hasMenuProvider()} before calling)
*/
public static void openMenu(@NotNull Player viewer, @NotNull CosmeticHolder cosmeticHolder, @NotNull Cosmetic cosmetic) throws IllegalStateException {
if (instance == null) {
throw new IllegalStateException("Unable to open a dye menu without instance of it.");
}
instance.openMenu(viewer, cosmeticHolder, cosmetic);
}
/**
* Does HMCC have a dye menu provider already set?
* @return True if it is already set and locked; false if none have been set.
*/
public static boolean hasMenuProvider() {
return instance != null;
}
}

View File

@@ -0,0 +1,58 @@
package com.hibiscusmc.hmccosmetics.gui.special.impl;
import com.hibiscusmc.hmccolor.HMCColorApi;
import com.hibiscusmc.hmccolor.shaded.gui.guis.Gui;
import com.hibiscusmc.hmccolor.shaded.gui.guis.GuiItem;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
import com.hibiscusmc.hmccosmetics.gui.special.DyeMenu;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
import me.lojosho.hibiscuscommons.util.AdventureUtils;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class HMCColorDyeMenu implements DyeMenu {
@Override
public void openMenu(@NotNull Player viewer, @NotNull CosmeticHolder cosmeticHolder, @NotNull Cosmetic cosmetic) {
ItemStack originalItem = cosmetic.getItem();
if (originalItem == null || !cosmetic.isDyeable()) return;
Gui gui = HMCColorApi.createColorMenu(viewer);
gui.updateTitle(AdventureUtils.MINI_MESSAGE.deserialize(Hooks.processPlaceholders(viewer, Settings.getDyeMenuName())));
gui.setItem(Settings.getDyeMenuInputSlot(), new GuiItem(originalItem));
gui.setDefaultTopClickAction(event -> {
if (event.getSlot() == Settings.getDyeMenuOutputSlot()) {
ItemStack item = event.getInventory().getItem(Settings.getDyeMenuOutputSlot());
if (item == null) return;
Color color = NMSHandlers.getHandler().getUtilHandler().getColor(item);
if (color == null) return;
addCosmetic(viewer, cosmeticHolder, cosmetic, color);
event.setCancelled(true);
} else event.setCancelled(true);
});
gui.setPlayerInventoryAction(event -> event.setCancelled(true));
gui.setCloseGuiAction(event -> {});
gui.open(viewer);
}
private void addCosmetic(@NotNull Player viewer, @NotNull CosmeticHolder cosmeticHolder, @NotNull Cosmetic cosmetic, @Nullable Color color) {
cosmeticHolder.addCosmetic(cosmetic, color);
viewer.setItemOnCursor(new ItemStack(Material.AIR));
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
viewer.closeInventory();
cosmeticHolder.updateCosmetic(cosmetic.getSlot());
}, 2);
}
}

View File

@@ -1,9 +1,23 @@
package com.hibiscusmc.hmccosmetics.gui.type;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.shaded.configurate.ConfigurationNode;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public abstract class Type {
@@ -18,11 +32,87 @@ public abstract class Type {
return this.id;
}
public void run(CosmeticUser user, ConfigurationNode config) {
run(user, config, null);
public void run(Player viewer, CosmeticHolder cosmeticHolder, ConfigurationNode config) {
run(viewer, cosmeticHolder, config, null);
}
public void run(Player viewer, CosmeticHolder cosmeticHolder, ConfigurationNode config, ClickType clickType) {
run(CosmeticHolder.ensureSingleCosmeticUser(viewer, cosmeticHolder), config, clickType);
}
public void run(CosmeticUser user, ConfigurationNode config) {
final var player = user.getPlayer();
if (player == null) return;
run(player, user, config, null);
}
/**
* @deprecated Override {@link #run(Player, CosmeticHolder, ConfigurationNode, ClickType)} instead.
*/
@Deprecated
public abstract void run(CosmeticUser user, ConfigurationNode config, ClickType clickType);
public abstract ItemStack setItem(CosmeticUser user, ConfigurationNode config, ItemStack itemStack, int slot);
public ItemStack setItem(Player viewer, CosmeticHolder cosmeticHolder, ConfigurationNode config, ItemStack itemStack, int slot) {
return setItem(CosmeticHolder.ensureSingleCosmeticUser(viewer, cosmeticHolder), config, itemStack, slot);
}
/**
* @deprecated Override {@link #setItem(Player, CosmeticHolder, ConfigurationNode, ItemStack, int)} instead.
*/
public abstract ItemStack setItem(CosmeticUser user, ConfigurationNode config, ItemStack itemStack, int slot);
@Contract("_, _ -> param2")
@NotNull
@SuppressWarnings("Duplicates")
protected ItemMeta processItemMeta(Player viewer, @NotNull ItemMeta itemMeta) {
// New implementation - Paper and forks
// I know this is a kinda batshit way to do it (with serializing and deserializing MiniMessage)
// But currently I can't think of another good way of doing it without a big refactor. I'll come back to this
// At a later date.
if (HibiscusCommonsPlugin.isOnPaper()) {
List<Component> processedLore = new ArrayList<>();
if (itemMeta.hasDisplayName()) {
String displayName = MiniMessage.miniMessage().serialize(itemMeta.displayName());
displayName = Hooks.processPlaceholders(viewer, displayName);
itemMeta.displayName(MiniMessage.miniMessage().deserialize(displayName).decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE));
}
if (itemMeta.hasLore()) {
for (Component loreLine : itemMeta.lore()) {
String loreStringLine = MiniMessage.miniMessage().serialize(loreLine);
loreStringLine = Hooks.processPlaceholders(viewer, loreStringLine);
processedLore.add(MiniMessage.miniMessage().deserialize(loreStringLine).decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE));
}
}
if (itemMeta instanceof SkullMeta skullMeta) {
if (skullMeta.hasOwner() && skullMeta.getOwner() != null) {
skullMeta.setOwner(Hooks.processPlaceholders(viewer, skullMeta.getOwner()));
}
}
itemMeta.lore(processedLore);
} else {
// Legacy implementation - Spigot
List<String> processedLore = new ArrayList<>();
if (itemMeta.hasDisplayName()) {
itemMeta.setDisplayName(Hooks.processPlaceholders(viewer, itemMeta.getDisplayName()));
}
if (itemMeta.hasLore()) {
for (String loreLine : itemMeta.getLore()) {
processedLore.add(Hooks.processPlaceholders(viewer, loreLine));
}
}
if (itemMeta instanceof SkullMeta skullMeta) {
if (skullMeta.hasOwner() && skullMeta.getOwner() != null) {
skullMeta.setOwner(Hooks.processPlaceholders(viewer, skullMeta.getOwner()));
}
}
itemMeta.setLore(processedLore);
}
return itemMeta;
}
}

View File

@@ -10,18 +10,43 @@ public class Types {
private static final HashMap<String, Type> types = new HashMap<>();
private static TypeCosmetic TYPE_COSMETIC = new TypeCosmetic();
private static TypeEmpty TYPE_EMPTY = new TypeEmpty();
private static final TypeCosmetic TYPE_COSMETIC = new TypeCosmetic();
private static final TypeEmpty TYPE_EMPTY = new TypeEmpty();
/**
* Get's a Menu Item type. Add custom menu item types with {@link #addType(Type)}
* @param id A non-case sensitive ID
* @return The type of Menu Item
*/
public static Type getType(@NotNull String id) {
return types.get(id.toUpperCase());
}
/**
* Checks if a type is valid. Add custom menu item types with {@link #addType(Type)}
* @param id A non-case sensitive ID
* @return True if exists, False if not.
*/
public static boolean isType(@NotNull String id) {
return types.containsKey(id.toUpperCase());
}
public static void addType(Type type) {
types.put(type.getId().toUpperCase(), type);
/**
* Adds a Menu Item Type to the types HashMap for reference. Menu Types will automatically be added using this method.
* @param type A non-null {@link Type} that'll be added. ID should be unique; can't be duplicated
*/
public static boolean addType(@NotNull Type type) {
String id = type.getId().toUpperCase();
if (types.containsKey(id)) return false;
types.put(id, type);
return true;
}
/**
* Gets the default menu item; {@link TypeEmpty}
* @return The empty menu type.
*/
public static TypeEmpty getDefaultType() {
return TYPE_EMPTY;
}
}

View File

@@ -3,10 +3,12 @@ package com.hibiscusmc.hmccosmetics.gui.type.types;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
import com.hibiscusmc.hmccosmetics.gui.action.Actions;
import com.hibiscusmc.hmccosmetics.gui.special.DyeMenu;
import com.hibiscusmc.hmccosmetics.gui.special.DyeMenuProvider;
import com.hibiscusmc.hmccosmetics.gui.type.Type;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
@@ -19,9 +21,6 @@ import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
@@ -38,7 +37,7 @@ public class TypeCosmetic extends Type {
}
@Override
public void run(CosmeticUser user, @NotNull ConfigurationNode config, ClickType clickType) {
public void run(Player viewer, CosmeticHolder cosmeticHolder, ConfigurationNode config, ClickType clickType) {
MessagesUtil.sendDebugMessages("Running Cosmetic Click Type");
if (config.node("cosmetic").virtual()) {
MessagesUtil.sendDebugMessages("Cosmetic Config Field Virtual");
@@ -46,32 +45,33 @@ public class TypeCosmetic extends Type {
}
String cosmeticName = config.node("cosmetic").getString();
Cosmetic cosmetic = Cosmetics.getCosmetic(cosmeticName);
Player player = user.getPlayer();
if (cosmetic == null) {
MessagesUtil.sendDebugMessages("No Cosmetic Found");
MessagesUtil.sendMessage(player, "invalid-cosmetic");
MessagesUtil.sendMessage(viewer, "invalid-cosmetic");
return;
}
if (!user.canEquipCosmetic(cosmetic)) {
if (!cosmeticHolder.canEquipCosmetic(cosmetic)) {
MessagesUtil.sendDebugMessages("No Cosmetic Permission");
MessagesUtil.sendMessage(player, "no-cosmetic-permission");
MessagesUtil.sendMessage(viewer, "no-cosmetic-permission");
return;
}
boolean isUnEquippingCosmetic = false;
if (user.getCosmetic(cosmetic.getSlot()) == cosmetic) isUnEquippingCosmetic = true;
if (cosmeticHolder.getCosmetic(cosmetic.getSlot()) == cosmetic) isUnEquippingCosmetic = true;
String dyeClick = Settings.getCosmeticDyeClickType();
String requiredClick;
if (isUnEquippingCosmetic) requiredClick = Settings.getCosmeticUnEquipClickType();
else requiredClick = Settings.getCosmeticEquipClickType();
MessagesUtil.sendDebugMessages("Required click type: " + requiredClick);
MessagesUtil.sendDebugMessages("Click type: " + clickType.name());
if (!requiredClick.equalsIgnoreCase("ANY") && !requiredClick.equalsIgnoreCase(clickType.name())) {
MessagesUtil.sendMessage(user.getPlayer(), "invalid-click-type");
return;
}
final boolean isRequiredClick = requiredClick.equalsIgnoreCase("ANY") || requiredClick.equalsIgnoreCase(clickType.name());
final boolean isDyeClick = dyeClick.equalsIgnoreCase("ANY") || dyeClick.equalsIgnoreCase(clickType.name());
if (!isRequiredClick) isUnEquippingCosmetic = false;
List<String> actionStrings = new ArrayList<>();
ConfigurationNode actionConfig = config.node("actions");
@@ -99,25 +99,27 @@ public class TypeCosmetic extends Type {
if (isUnEquippingCosmetic) {
if (!actionConfig.node("on-unequip").virtual()) actionStrings.addAll(actionConfig.node("on-unequip").getList(String.class));
MessagesUtil.sendDebugMessages("on-unequip");
user.removeCosmeticSlot(cosmetic);
cosmeticHolder.removeCosmeticSlot(cosmetic);
} else {
if (!actionConfig.node("on-equip").virtual()) actionStrings.addAll(actionConfig.node("on-equip").getList(String.class));
MessagesUtil.sendDebugMessages("on-equip");
MessagesUtil.sendDebugMessages("Preparing for on-equip with the following checks:");
MessagesUtil.sendDebugMessages("CosmeticDyeable? " + cosmetic.isDyeable() + " / isDyeClick? " + isDyeClick + " / isHMCColorActive? " + Hooks.isActiveHook("HMCColor"));
// TODO: Redo this
if (cosmetic.isDyable() && Hooks.isActiveHook("HMCColor")) {
DyeMenu.openMenu(user, cosmetic);
} else {
user.addPlayerCosmetic(cosmetic);
if (cosmetic.isDyeable() && isDyeClick && DyeMenuProvider.hasMenuProvider()) {
DyeMenuProvider.openMenu(viewer, cosmeticHolder, cosmetic);
} else if (isRequiredClick) {
cosmeticHolder.addCosmetic(cosmetic);
}
}
Actions.runActions(user, actionStrings);
Actions.runActions(viewer, cosmeticHolder, actionStrings);
} catch (SerializationException e) {
e.printStackTrace();
}
// Fixes issue with offhand cosmetics not appearing. Yes, I know this is dumb
Runnable run = () -> user.updateCosmetic(cosmetic.getSlot());
Runnable run = () -> cosmeticHolder.updateCosmetic(cosmetic.getSlot());
if (cosmetic instanceof CosmeticArmorType) {
if (((CosmeticArmorType) cosmetic).getEquipSlot().equals(EquipmentSlot.OFF_HAND)) {
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), run, 1);
@@ -128,8 +130,18 @@ public class TypeCosmetic extends Type {
}
@Override
public ItemStack setItem(@NotNull CosmeticUser user, @NotNull ConfigurationNode config, @NotNull ItemStack itemStack, int slot) {
if (itemStack.hasItemMeta()) itemStack.setItemMeta(processLoreLines(user, itemStack.getItemMeta()));
public void run(CosmeticUser user, @NotNull ConfigurationNode config, ClickType clickType) {
run(user.getPlayer(), user, config, clickType);
}
@Override
public ItemStack setItem(CosmeticUser user, ConfigurationNode config, ItemStack itemStack, int slot) {
return setItem(user.getPlayer(), user, config, itemStack, slot);
}
@Override
public ItemStack setItem(@NotNull Player viewer, @NotNull CosmeticHolder cosmeticHolder, @NotNull ConfigurationNode config, @NotNull ItemStack itemStack, int slot) {
if (itemStack.hasItemMeta()) itemStack.setItemMeta(processItemMeta(viewer, itemStack.getItemMeta()));
else MessagesUtil.sendDebugMessages("ItemStack has no ItemMeta?");
if (config.node("cosmetic").virtual()) {
@@ -141,9 +153,9 @@ public class TypeCosmetic extends Type {
return itemStack;
}
if (user.hasCosmeticInSlot(cosmetic) && (!config.node("equipped-item").virtual() || !config.node("locked-equipped-item").virtual())) {
if (cosmeticHolder.hasCosmeticInSlot(cosmetic) && (!config.node("equipped-item").virtual() || !config.node("locked-equipped-item").virtual())) {
MessagesUtil.sendDebugMessages("GUI Equipped Item");
ConfigurationNode equippedItem = config.node(user.canEquipCosmetic(cosmetic, true) && !config.node("equipped-item").virtual() ? "equipped-item" : "locked-equipped-item");
ConfigurationNode equippedItem = config.node(cosmeticHolder.canEquipCosmetic(cosmetic, true) && !config.node("equipped-item").virtual() ? "equipped-item" : "locked-equipped-item");
try {
if (equippedItem.node("material").virtual()) equippedItem.node("material").set(config.node("item", "material").getString());
} catch (SerializationException e) {
@@ -154,12 +166,12 @@ public class TypeCosmetic extends Type {
} catch (SerializationException e) {
throw new RuntimeException(e);
}
if (itemStack.hasItemMeta()) itemStack.setItemMeta(processLoreLines(user, itemStack.getItemMeta()));
if (itemStack.hasItemMeta()) itemStack.setItemMeta(processItemMeta(viewer, itemStack.getItemMeta()));
else MessagesUtil.sendDebugMessages("ItemStack has no ItemMeta in equipped item?");
return itemStack;
}
if (!user.canEquipCosmetic(cosmetic, true) && !config.node("locked-item").virtual()) {
if (!cosmeticHolder.canEquipCosmetic(cosmetic, true) && !config.node("locked-item").virtual()) {
MessagesUtil.sendDebugMessages("GUI Locked Item");
ConfigurationNode lockedItem = config.node("locked-item");
try {
@@ -172,35 +184,10 @@ public class TypeCosmetic extends Type {
} catch (SerializationException e) {
throw new RuntimeException(e);
}
if (itemStack.hasItemMeta()) itemStack.setItemMeta(processLoreLines(user, itemStack.getItemMeta()));
if (itemStack.hasItemMeta()) itemStack.setItemMeta(processItemMeta(viewer, itemStack.getItemMeta()));
else MessagesUtil.sendDebugMessages("ItemStack has no ItemMeta in locked item?");
return itemStack;
}
return itemStack;
}
@Contract("_, _ -> param2")
@NotNull
@SuppressWarnings("Duplicates")
private ItemMeta processLoreLines(CosmeticUser user, @NotNull ItemMeta itemMeta) {
List<String> processedLore = new ArrayList<>();
if (itemMeta.hasDisplayName()) {
itemMeta.setDisplayName(Hooks.processPlaceholders(user.getPlayer(), itemMeta.getDisplayName()));
}
if (itemMeta.hasLore()) {
for (String loreLine : itemMeta.getLore()) {
processedLore.add(Hooks.processPlaceholders(user.getPlayer(), loreLine));
}
}
if (itemMeta instanceof SkullMeta skullMeta) {
if (skullMeta.hasOwner() && skullMeta.getOwner() != null) {
skullMeta.setOwner(Hooks.processPlaceholders(user.getPlayer(), skullMeta.getOwner()));
}
}
itemMeta.setLore(processedLore);
return itemMeta;
}
}

View File

@@ -1,15 +1,15 @@
package com.hibiscusmc.hmccosmetics.gui.type.types;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
import com.hibiscusmc.hmccosmetics.gui.action.Actions;
import com.hibiscusmc.hmccosmetics.gui.type.Type;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.shaded.configurate.ConfigurationNode;
import me.lojosho.shaded.configurate.serialize.SerializationException;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
@@ -23,9 +23,10 @@ public class TypeEmpty extends Type {
// This is an empty type, meaning, when a menu item has a type of "empty" it will run the code in the method run.
}
// This is the code that's run when the item is clicked.
// This is the code that's run when the item is clicked. The item is clicked by the "viewer" player in a menu for the
// given "cosmeticHolder". They're the same player by default, but it's not guaranteed.
@Override
public void run(CosmeticUser user, @NotNull ConfigurationNode config, ClickType clickType) {
public void run(Player viewer, CosmeticHolder cosmeticHolder, @NotNull ConfigurationNode config, ClickType clickType) {
List<String> actionStrings = new ArrayList<>(); // List where we keep the actions the server will execute.
ConfigurationNode actionConfig = config.node("actions"); // Configuration node that actions are under.
@@ -52,36 +53,32 @@ public class TypeEmpty extends Type {
}
// We run the actions once we got the raw strings from the config.
Actions.runActions(user, actionStrings);
Actions.runActions(viewer, cosmeticHolder, actionStrings);
} catch (SerializationException e) {
throw new RuntimeException(e);
}
}
// backward-compatibility method, will not be required in the future
@Override
public void run(CosmeticUser user, ConfigurationNode config, ClickType clickType) {
final var player = user.getPlayer();
if (player == null) return;
run(player, user, config, clickType);
}
// backward-compatibility method, will not be required in the future
@Override
public ItemStack setItem(CosmeticUser user, ConfigurationNode config, ItemStack itemStack, int slot) {
return setItem(user.getPlayer(), user, config, itemStack, slot);
}
@Override
@SuppressWarnings("Duplicates")
public ItemStack setItem(CosmeticUser user, ConfigurationNode config, @NotNull ItemStack itemStack, int slot) {
List<String> processedLore = new ArrayList<>();
public ItemStack setItem(Player viewer, CosmeticHolder cosmeticHolder, ConfigurationNode config, @NotNull ItemStack itemStack, int slot) {
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta.hasDisplayName()) {
itemMeta.setDisplayName(Hooks.processPlaceholders(user.getPlayer(), itemMeta.getDisplayName()));
}
if (itemMeta.hasLore()) {
for (String loreLine : itemMeta.getLore()) {
processedLore.add(Hooks.processPlaceholders(user.getPlayer(), loreLine));
}
}
if (itemMeta instanceof SkullMeta skullMeta) {
if (skullMeta.hasOwner() && skullMeta.getOwner() != null) {
skullMeta.setOwner(Hooks.processPlaceholders(user.getPlayer(), skullMeta.getOwner()));
}
}
itemMeta.setLore(processedLore);
itemStack.setItemMeta(itemMeta);
itemStack.setItemMeta(processItemMeta(viewer, itemMeta));
return itemStack;
}

View File

@@ -9,7 +9,6 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.TranslationUtil;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.apache.commons.lang3.EnumUtils;
import org.bukkit.OfflinePlayer;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@@ -74,29 +73,20 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
if (placeholderArgs.size() >= 2) {
CosmeticSlot slot = CosmeticSlot.valueOf(placeholderArgs.get(1).toUpperCase());
if (slot == null) return null;
if (user.getCosmetic(slot) == null) return TranslationUtil.getTranslation("current-cosmetic", "no-cosmetic");
Cosmetic cosmetic = user.getCosmetic(slot);
if (cosmetic == null) return TranslationUtil.getTranslation("current-cosmetic", "no-cosmetic");
if (placeholderArgs.size() == 2) return user.getCosmetic(slot).getId();
String output;
switch (placeholderArgs.get(2).toLowerCase()) {
case "material" -> {
output = getMaterialName(user.getCosmetic(slot));
}
case "custommodeldata" -> {
output = getModelData(user.getCosmetic(slot));
}
case "name" -> {
output = getItemName(user.getCosmetic(slot));
}
case "lore" -> {
output = getItemLore(user.getCosmetic(slot));
}
case "permission" -> {
output = user.getCosmetic(slot).getPermission();
}
default -> {
output = user.getCosmetic(slot).getId();
}
case "material" -> output = getMaterialName(cosmetic);
case "custommodeldata" -> output = getModelData(cosmetic);
case "itemmodel" -> output = getItemModel(cosmetic);
case "itemname" -> output = getItemName(cosmetic);
case "name" -> output = getDisplayName(cosmetic);
case "lore" -> output = getItemLore(cosmetic);
case "permission" -> output = user.getCosmetic(slot).getPermission();
default -> output = user.getCosmetic(slot).getId();
}
if (output == null) output = "none";
return TranslationUtil.getTranslation("current-cosmetic", output);
@@ -218,13 +208,55 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
return String.valueOf(itemMeta.getCustomModelData());
}
/**
* Gets the cosmetic items item model
* @param cosmetic The cosmetic to get its item model
* @return The cosmetic items item model
*/
@Nullable
public String getItemModel(@NotNull Cosmetic cosmetic) {
try {
ItemStack item = cosmetic.getItem();
if (item == null) return null;
if (!item.hasItemMeta()) return null;
ItemMeta itemMeta = item.getItemMeta();
if (itemMeta == null && itemMeta.hasItemModel() ) return null;
return itemMeta.getItemModel().asString();
} catch (Exception e) {
return null;
}
}
/**
* Gets the cosmetic items item name
* @param cosmetic The cosmetic to get its items item name
* @return The cosmetic items item name
*/
@Nullable
public String getItemName(@NotNull Cosmetic cosmetic) {
try {
ItemStack item = cosmetic.getItem();
if (item == null) return null;
if (!item.hasItemMeta()) return null;
ItemMeta itemMeta = item.getItemMeta();
if (itemMeta == null || !itemMeta.hasItemName()) return null;
return itemMeta.getDisplayName();
} catch (Exception e) {
return null;
}
}
/**
* Gets the cosmetic items display name
* @param cosmetic The cosmetic to get its items display name
* @return The cosmetic items display name
*/
@Nullable
public String getItemName(@NotNull Cosmetic cosmetic) {
public String getDisplayName(@NotNull Cosmetic cosmetic) {
ItemStack item = cosmetic.getItem();
if (item == null) return null;
if (!item.hasItemMeta()) return null;

View File

@@ -1,6 +1,5 @@
package com.hibiscusmc.hmccosmetics.hooks.worldguard;
import com.hibiscusmc.hmccosmetics.api.events.PlayerEmoteStartEvent;
import com.hibiscusmc.hmccosmetics.config.Wardrobe;
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
@@ -8,6 +7,7 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import com.sk89q.worldguard.protection.regions.RegionQuery;
@@ -20,32 +20,43 @@ import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
import java.util.Set;
/**
* Contains {@link com.sk89q.worldguard.WorldGuard WorldGuard} related event listeners
*/
public class WGListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerMove(@NotNull PlayerMoveEvent event) {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
Player player = event.getPlayer();
Location from = event.getFrom();
Location to = event.getTo();
if (from.getBlockX() == to.getBlockX() && from.getBlockY() == to.getBlockY() && from.getBlockZ() == to.getBlockZ()) return;
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
Location location = event.getPlayer().getLocation();
Location location = player.getLocation();
ApplicableRegionSet set = getRegions(location);
if (user.isHidden()) {
if (set.getRegions().isEmpty()) {
if (user.isHidden() && set.getRegions().isEmpty()) {
user.showCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
}
}
Set<String> wardrobeNames = WardrobeSettings.getWardrobeNames();
for (ProtectedRegion protectedRegion : set.getRegions()) {
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticEnableFlag())) {
if (protectedRegion.getFlags().get(WGHook.getCosmeticEnableFlag()).toString().equalsIgnoreCase("ALLOW")) {
Map<Flag<?>, Object> flags = protectedRegion.getFlags();
if (flags.containsKey(WGHook.getCosmeticEnableFlag())) {
if (flags.get(WGHook.getCosmeticEnableFlag()).toString().equalsIgnoreCase("ALLOW")) {
user.showCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
} else {
user.hideCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
}
}
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticWardrobeFlag())) {
if (!WardrobeSettings.getWardrobeNames().contains(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString())) return;
Wardrobe wardrobe = WardrobeSettings.getWardrobe(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString());
if (flags.containsKey(WGHook.getCosmeticWardrobeFlag())) {
String wardrobeName = flags.getOrDefault(WGHook.getCosmeticWardrobeFlag(), "").toString();
if (wardrobeName.isEmpty() || !wardrobeNames.contains(wardrobeName)) return;
Wardrobe wardrobe = WardrobeSettings.getWardrobe(wardrobeName);
if (wardrobe == null) return;
user.enterWardrobe(wardrobe, true);
}
}
@@ -79,23 +90,6 @@ public class WGListener implements Listener {
}
}
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerEmote(PlayerEmoteStartEvent event) {
Player player = event.getUser().getPlayer();
if (player == null) return;
Location location = player.getLocation();
ApplicableRegionSet set = getRegions(location);
for (ProtectedRegion protectedRegion : set.getRegions()) {
if (protectedRegion.getFlags().containsKey(WGHook.getEmotesEnableFlag())) {
if (protectedRegion.getFlags().get(WGHook.getEmotesEnableFlag()).toString().equalsIgnoreCase("DENY")) {
event.setCancelled(true);
return;
}
return;
}
}
}
private ApplicableRegionSet getRegions(Location location) {
com.sk89q.worldedit.util.Location loc = BukkitAdapter.adapt(location);
RegionContainer region = WorldGuard.getInstance().getPlatform().getRegionContainer();

View File

@@ -3,15 +3,16 @@ package com.hibiscusmc.hmccosmetics.listener;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.api.events.PlayerLoadEvent;
import com.hibiscusmc.hmccosmetics.api.events.PlayerPreLoadEvent;
import com.hibiscusmc.hmccosmetics.api.events.PlayerPreUnloadEvent;
import com.hibiscusmc.hmccosmetics.api.events.PlayerUnloadEvent;
import com.hibiscusmc.hmccosmetics.config.DatabaseSettings;
import com.hibiscusmc.hmccosmetics.database.Database;
import com.hibiscusmc.hmccosmetics.gui.Menus;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@@ -22,43 +23,37 @@ import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public class PlayerConnectionListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(@NotNull PlayerJoinEvent event) {
if (event.getPlayer().isOp() || event.getPlayer().hasPermission("hmccosmetics.notifyupdate")) {
if (!HMCCosmeticsPlugin.getInstance().getLatestVersion().equalsIgnoreCase(HMCCosmeticsPlugin.getInstance().getDescription().getVersion()) && HMCCosmeticsPlugin.getInstance().getLatestVersion().isEmpty())
MessagesUtil.sendMessageNoKey(
event.getPlayer(),
"<br>" +
"<GRAY>There is a new version of <light_purple><Bold>HMCCosmetics<reset><gray> available!<br>" +
"<GRAY>Current version: <red>" + HMCCosmeticsPlugin.getInstance().getDescription().getVersion() + " <GRAY>| Latest version: <light_purple>" + HMCCosmeticsPlugin.getInstance().getLatestVersion() + "<br>" +
"<GRAY>Download it on <gold><click:OPEN_URL:'https://www.spigotmc.org/resources/100107/'>Spigot<reset> <gray>or <gold><click:OPEN_URL:'https://polymart.org/resource/1879'>Polymart<reset><gray>!" +
"<br>"
if (DatabaseSettings.isEnabledDelay()) {
MessagesUtil.sendDebugMessages("Delay Enabled with " + DatabaseSettings.getDelayLength() + " ticks");
Bukkit.getScheduler().runTaskLater(
HMCCosmeticsPlugin.getInstance(),
() -> this.loadUserData(event.getPlayer()),
DatabaseSettings.getDelayLength()
);
} else {
this.loadUserData(event.getPlayer());
}
}
// This literally makes me want to end it all but I can't do that so I'll just cry instead
Runnable run = () -> {
if (!event.getPlayer().isOnline()) return; // If a player is no longer online, don't run this.
UUID uuid = event.getPlayer().getUniqueId();
private void loadUserData(final Player player) {
if(!player.isOnline()) return;
final UUID playerId = player.getUniqueId();
PlayerPreLoadEvent preLoadEvent = new PlayerPreLoadEvent(uuid);
PlayerPreLoadEvent preLoadEvent = new PlayerPreLoadEvent(playerId);
Bukkit.getPluginManager().callEvent(preLoadEvent);
if (preLoadEvent.isCancelled()) return;
Database.get(uuid).thenAccept(userData -> {
if (userData == null) {
return;
}
Database.get(playerId).thenAccept(userData -> {
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
CosmeticUser cosmeticUser = CosmeticUsers.getProvider()
.createCosmeticUser(uuid)
.createCosmeticUser(playerId)
.initialize(userData);
cosmeticUser.startTicking();
CosmeticUsers.addUser(cosmeticUser);
MessagesUtil.sendDebugMessages("Run User Join for " + uuid);
MessagesUtil.sendDebugMessages("Run User Join for " + playerId);
PlayerLoadEvent playerLoadEvent = new PlayerLoadEvent(cosmeticUser);
Bukkit.getPluginManager().callEvent(playerLoadEvent);
@@ -70,17 +65,9 @@ public class PlayerConnectionListener implements Listener {
}, 4);
});
}).exceptionally(ex -> {
MessagesUtil.sendDebugMessages("Unable to load Cosmetic User " + uuid + ". Exception: " + ex.getMessage());
MessagesUtil.sendDebugMessages("Unable to load Cosmetic User " + playerId + ". Exception: " + ex.getMessage());
return null;
});
};
if (DatabaseSettings.isEnabledDelay()) {
MessagesUtil.sendDebugMessages("Delay Enabled with " + DatabaseSettings.getDelayLength() + " ticks");
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), run, DatabaseSettings.getDelayLength());
} else {
run.run();
}
}
@EventHandler(priority = EventPriority.MONITOR)
@@ -88,20 +75,37 @@ public class PlayerConnectionListener implements Listener {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
if (user == null) return; // Player never initialized, don't do anything
PlayerPreUnloadEvent preUnloadEvent = new PlayerPreUnloadEvent(user);
Bukkit.getPluginManager().callEvent(preUnloadEvent);
if (preUnloadEvent.isCancelled()) return;
PlayerUnloadEvent playerUnloadEvent = new PlayerUnloadEvent(user);
Bukkit.getPluginManager().callEvent(playerUnloadEvent);
if (user.isInWardrobe()) {
user.leaveWardrobe(true);
user.getPlayer().setInvisible(false);
}
if (user.getUserEmoteManager().isPlayingEmote()) {
user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.CONNECTION);
event.getPlayer().setInvisible(false);
final Player player = user.getPlayer();
if(player != null) player.setInvisible(false);
}
Menus.removeCooldown(event.getPlayer().getUniqueId()); // Removes any menu cooldowns a player might have
Database.save(user);
user.destroy();
CosmeticUsers.removeUser(user.getUniqueId());
}
@EventHandler(priority = EventPriority.MONITOR)
public void notifyAdminUpdate(final PlayerJoinEvent event) {
if (event.getPlayer().isOp() || event.getPlayer().hasPermission("hmccosmetics.notifyupdate")) {
if (!HMCCosmeticsPlugin.getInstance().getLatestVersion().equalsIgnoreCase(HMCCosmeticsPlugin.getInstance().getDescription().getVersion()) && HMCCosmeticsPlugin.getInstance().getLatestVersion().isEmpty())
MessagesUtil.sendMessageNoKey(
event.getPlayer(),
"<br>" +
"<GRAY>There is a new version of <light_purple><Bold>HMCCosmetics<reset><gray> available!<br>" +
"<GRAY>Current version: <red>" + HMCCosmeticsPlugin.getInstance().getDescription().getVersion() + " <GRAY>| Latest version: <light_purple>" + HMCCosmeticsPlugin.getInstance().getLatestVersion() + "<br>" +
"<GRAY>Download it on <gold><click:OPEN_URL:'https://www.spigotmc.org/resources/100107/'>Spigot<reset> <gray>or <gold><click:OPEN_URL:'https://polymart.org/resource/1879'>Polymart<reset><gray>!" +
"<br>"
);
}
}
}

View File

@@ -1,25 +1,14 @@
package com.hibiscusmc.hmccosmetics.listener;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.*;
import com.comphenix.protocol.wrappers.EnumWrappers;
import com.comphenix.protocol.wrappers.Pair;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.api.events.PlayerCosmeticPostEquipEvent;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticEmoteType;
import com.hibiscusmc.hmccosmetics.gui.Menu;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
import com.hibiscusmc.hmccosmetics.user.manager.UserWardrobeManager;
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
@@ -51,18 +40,6 @@ import org.jetbrains.annotations.Nullable;
import java.util.*;
public class PlayerGameListener implements Listener {
public PlayerGameListener() {
registerInventoryClickListener();
registerMenuChangeListener();
registerEntityStatusListener();
registerPlayerEquipmentListener();
registerPlayerArmListener();
registerEntityUseListener();
registerSlotChangeListener();
registerPassengerSetListener();
}
@EventHandler(priority = EventPriority.LOW)
public void onPlayerClick(@NotNull InventoryClickEvent event) {
// || !event.getClickedInventory().getType().equals(InventoryType.PLAYER)
@@ -95,10 +72,6 @@ public class PlayerGameListener implements Listener {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
if (user == null) return;
if (event.isSneaking()) {
user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.SNEAK);
}
if (!event.isSneaking()) return;
if (!user.isInWardrobe()) return;
@@ -121,24 +94,19 @@ public class PlayerGameListener implements Listener {
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
if (user.getEntity() == null || user.isInWardrobe()) return; // fixes disconnecting when in wardrobe (the entity stuff)
if (Settings.getDisabledWorlds().contains(user.getEntity().getLocation().getWorld().getName())) {
user.hideCosmetics(CosmeticUser.HiddenReason.WORLD);
} else {
user.showCosmetics(CosmeticUser.HiddenReason.WORLD);
}
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK) && user.getUserBackpackManager() != null) {
user.respawnBackpack();
}
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
user.respawnBalloon();
}
user.updateCosmetic();
}, 2);
}, 4);
if (event.getCause().equals(PlayerTeleportEvent.TeleportCause.NETHER_PORTAL) || event.getCause().equals(PlayerTeleportEvent.TeleportCause.END_PORTAL)) return;
if (user.getUserEmoteManager().isPlayingEmote()) {
user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.TELEPORT);
}
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
@@ -170,8 +138,7 @@ public class PlayerGameListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerHit(EntityDamageByEntityEvent event) {
Entity entity = event.getEntity();
if (!entity.getPersistentDataContainer().has(new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "cosmeticMob"), PersistentDataType.SHORT))
return;
if (!entity.getPersistentDataContainer().has(HMCCServerUtils.getCosmemeticMobKey(), PersistentDataType.BOOLEAN)) return;
event.setCancelled(true);
}
@@ -180,14 +147,6 @@ public class PlayerGameListener implements Listener {
if (!(event.getEntity() instanceof Player player)) return;
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
if (user.getUserEmoteManager().isPlayingEmote()) {
if (Settings.isEmoteInvincible()) {
event.setCancelled(true);
}
if (Settings.isEmoteDamageLeave()) {
user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.DAMAGE);
}
}
if (user.isInWardrobe()) {
if (WardrobeSettings.isPreventDamage()) {
event.setCancelled(true);
@@ -197,19 +156,6 @@ public class PlayerGameListener implements Listener {
}
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
if (!Settings.isEmoteMoveCheck() && user.getUserEmoteManager().isPlayingEmote()) {
event.setCancelled(true);
return;
}
user.updateCosmetic(CosmeticSlot.BACKPACK);
user.updateCosmetic(CosmeticSlot.BALLOON);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerPoseChange(EntityPoseChangeEvent event) {
if (!(event.getEntity() instanceof Player player)) return;
@@ -269,12 +215,6 @@ public class PlayerGameListener implements Listener {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
if (user == null) return;
// Really need to look into optimization of this
if (user.hasCosmeticInSlot(CosmeticSlot.EMOTE) && event.getPlayer().isSneaking() && event.getPlayer().hasPermission("hmccosmetics.emote.shiftrun")) {
CosmeticEmoteType cosmeticEmoteType = (CosmeticEmoteType) user.getCosmetic(CosmeticSlot.EMOTE);
cosmeticEmoteType.run(user);
event.setCancelled(true);
return;
}
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
if (user.getEntity() == null) return; // Player has likely logged off
user.updateCosmetic(CosmeticSlot.OFFHAND);
@@ -405,6 +345,15 @@ public class PlayerGameListener implements Listener {
}
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEntityEvent event) {
final Player player = event.getPlayer();
final Entity entity = event.getRightClicked();
// Balloons are technically actual entities, so we need to cancel any interactions with them
if (!entity.getPersistentDataContainer().has(HMCCServerUtils.getCosmemeticMobKey(), PersistentDataType.BOOLEAN)) return;
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerVanish(HibiscusPlayerVanishEvent event) {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
@@ -451,256 +400,11 @@ public class PlayerGameListener implements Listener {
user.showCosmetics(CosmeticUser.HiddenReason.PLUGIN);
}
private void registerInventoryClickListener() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, List.of(PacketType.Play.Client.WINDOW_CLICK), ListenerOptions.ASYNC) {
@Override
public void onPacketReceiving(PacketEvent event) {
Player player = event.getPlayer();
int invTypeClicked = event.getPacket().getIntegers().read(0);
int slotClicked = event.getPacket().getIntegers().read(2);
// Must be a player inventory.
if (invTypeClicked != 0) return;
// -999 is when a player clicks outside their inventory. https://wiki.vg/Inventory#Player_Inventory
if (slotClicked == -999) return;
if (event.getPlayer() == null) return;
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
if (user.isInWardrobe()) return;
CosmeticSlot cosmeticSlot = HMCCInventoryUtils.NMSCosmeticSlot(slotClicked);
if (cosmeticSlot == null) return;
if (!user.hasCosmeticInSlot(cosmeticSlot)) return;
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> user.updateCosmetic(cosmeticSlot), 1);
MessagesUtil.sendDebugMessages("Packet fired, updated cosmetic " + cosmeticSlot);
}
});
}
private void registerMenuChangeListener() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, List.of(PacketType.Play.Server.WINDOW_ITEMS), ListenerOptions.ASYNC) {
@Override
public void onPacketSending(PacketEvent event) {
MessagesUtil.sendDebugMessages("Menu Initial ");
Player player = event.getPlayer();
if (event.getPlayer() == null) return;
int windowID = event.getPacket().getIntegers().read(0);
List<ItemStack> slotData = event.getPacket().getItemListModifier().read(0);
if (windowID != 0) return;
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
HashMap<Integer, ItemStack> items = new HashMap<>();
if (!user.isInWardrobe()) {
for (Cosmetic cosmetic : user.getCosmetics()) {
if ((cosmetic instanceof CosmeticArmorType cosmeticArmorType)) {
boolean requireEmpty = Settings.getSlotOption(cosmeticArmorType.getEquipSlot()).isRequireEmpty();
boolean isAir = user.getPlayer().getInventory().getItem(cosmeticArmorType.getEquipSlot()).getType().isAir();
MessagesUtil.sendDebugMessages("Menu Fired (Checks) - " + cosmeticArmorType.getId() + " - " + requireEmpty + " - " + isAir);
if (requireEmpty && !isAir) continue;
items.put(HMCCInventoryUtils.getPacketArmorSlot(cosmeticArmorType.getEquipSlot()), user.getUserCosmeticItem(cosmeticArmorType));
}
}
}
PacketContainer packet = new PacketContainer(PacketType.Play.Server.WINDOW_ITEMS);
packet.getIntegers().write(0, 0);
for (int slot = 0; slot < 46; slot++) {
if ((slot >= 5 && slot <= 8) || slot == 45) {
if (!items.containsKey(slot)) continue;
slotData.set(slot, items.get(slot));
if (Settings.isDebugMode()) MessagesUtil.sendDebugMessages("Set " + slot + " as " + items.get(slot));
}
}
packet.getItemListModifier().write(0, slotData);
packet.getItemModifier().write(0, event.getPacket().getItemModifier().read(0));
event.setPacket(packet);
MessagesUtil.sendDebugMessages("Menu Fired, updated cosmetics " + " on slotdata " + windowID + " with " + slotData.size());
/*
for (Cosmetic cosmetic : user.getCosmetic()) {
if ((cosmetic instanceof CosmeticArmorType) || (cosmetic instanceof CosmeticMainhandType)) {
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
user.updateCosmetic(cosmetic);
}, 1);
}
}
*/
}
});
}
private void registerSlotChangeListener() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.SET_SLOT) {
@Override
public void onPacketSending(PacketEvent event) {
MessagesUtil.sendDebugMessages("SetSlot Initial ");
Player player = event.getPlayer();
if (event.getPlayer() == null) return;
int windowID = event.getPacket().getIntegers().read(0);
if (windowID != 0) return;
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
if (user.isInWardrobe()) return;
int slot = event.getPacket().getIntegers().read(2);
MessagesUtil.sendDebugMessages("SetSlot Slot " + slot);
CosmeticSlot cosmeticSlot = HMCCInventoryUtils.NMSCosmeticSlot(slot);
EquipmentSlot equipmentSlot = HMCCInventoryUtils.getPacketArmorSlot(slot);
if (cosmeticSlot == null || equipmentSlot == null) return;
if (!user.hasCosmeticInSlot(cosmeticSlot)) return;
if (Settings.getSlotOption(equipmentSlot).isRequireEmpty()) {
if (!player.getInventory().getItem(equipmentSlot).getType().isAir()) return;
}
event.getPacket().getItemModifier().write(0, user.getUserCosmeticItem(cosmeticSlot));
}
});
}
private void registerPlayerEquipmentListener() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.ENTITY_EQUIPMENT) {
@Override
public void onPacketSending(PacketEvent event) {
Player player = event.getPlayer(); // Player that's sent
int entityID = event.getPacket().getIntegers().read(0);
// User
CosmeticUser user = CosmeticUsers.getUser(entityID);
if (user == null) return;
if (user.isInWardrobe()) return;
List<com.comphenix.protocol.wrappers.Pair<EnumWrappers.ItemSlot, ItemStack>> armor = event.getPacket().getSlotStackPairLists().read(0);
for (int i = 0; i < armor.size(); i++) {
com.comphenix.protocol.wrappers.Pair<EnumWrappers.ItemSlot, ItemStack> pair = armor.get(i);
switch (pair.getFirst()) {
case MAINHAND -> {
if (user.getPlayer() == event.getPlayer()) continue; // When a player scrolls real fast, it messes up the mainhand. This fixes it
if (user.getPlayer() != null && user.getPlayer().isInvisible()) continue; // Fixes integration with GSit still showing mainhand even when hidden
armor.set(i, new Pair<>(pair.getFirst(), user.getPlayer().getInventory().getItemInMainHand()));
}
default -> {
EquipmentSlot slot = HMCCInventoryUtils.getEquipmentSlot(pair.getFirst());
CosmeticSlot cosmeticSlot = HMCCInventoryUtils.getItemSlotToCosmeticSlot(pair.getFirst());
if (slot == null || cosmeticSlot == null) continue;
if (Settings.getSlotOption(slot).isRequireEmpty()
&& !user.getPlayer().getInventory().getItem(slot).getType().isAir()) continue;
CosmeticArmorType cosmeticArmor = (CosmeticArmorType) user.getCosmetic(cosmeticSlot);
if (cosmeticArmor == null) continue;
ItemStack item = user.getUserCosmeticItem(cosmeticArmor);
if (item == null) continue;
Pair<EnumWrappers.ItemSlot, ItemStack> armorPair = new Pair<>(HMCCInventoryUtils.itemBukkitSlot(slot), item);
armor.set(i, armorPair);
}
}
}
event.getPacket().getSlotStackPairLists().write(0, armor);
MessagesUtil.sendDebugMessages("Equipment for " + user.getPlayer().getName() + " has been updated for " + player.getName());
}
});
}
private void registerEntityStatusListener() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.ENTITY_STATUS) {
@Override
public void onPacketSending(PacketEvent event) {
int entityid = event.getPacket().getIntegers().read(0);
byte status = event.getPacket().getBytes().read(0);
MessagesUtil.sendDebugMessages("EntityStatus Initial " + entityid + " - " + status);
if (status != 55) return;
CosmeticUser user = CosmeticUsers.getUser(entityid);
if (user == null) {
MessagesUtil.sendDebugMessages("EntityStatus User is null");
return;
}
if (!user.hasCosmeticInSlot(CosmeticSlot.OFFHAND)) return;
event.setCancelled(true);
}
});
}
private void registerPassengerSetListener() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.MOUNT) {
@Override
public void onPacketSending(PacketEvent event) {
CosmeticUser viewerUser = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
if (viewerUser == null) return;
if (viewerUser.isInWardrobe()) return;
int ownerId = event.getPacket().getIntegers().read(0);
MessagesUtil.sendDebugMessages("Mount Packet Sent - Read - EntityID: " + ownerId);
Entity entity = HMCCServerUtils.getEntity(ownerId);
if (entity == null) return;
CosmeticUser user = CosmeticUsers.getUser(entity.getUniqueId());
if (user == null) return;
MessagesUtil.sendDebugMessages("Mount Packet Sent - " + user.getUniqueId());
if (!user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) return;
if (user.getUserBackpackManager() == null) return;
// Basically, take the original passengers and "bump" them to the end of the list
int[] originalPassengers = event.getPacket().getIntegerArrays().read(0);
List<Integer> passengers = new ArrayList<>(user.getUserBackpackManager().getEntityManager().getIds());
passengers.addAll(Arrays.stream(originalPassengers).boxed().toList());
event.getPacket().getIntegerArrays().write(0, passengers.stream().mapToInt(Integer::intValue).toArray());
}
});
}
private void registerPlayerArmListener() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.ARM_ANIMATION) {
@Override
public void onPacketReceiving(PacketEvent event) {
if (event.getPlayer() == null) return;
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
if (user.getUserEmoteManager().isPlayingEmote()) {
event.setCancelled(true);
return;
}
if (!user.isInWardrobe()) return;
if (!user.getWardrobeManager().getWardrobeStatus().equals(UserWardrobeManager.WardrobeStatus.RUNNING)) return;
Menu menu = user.getWardrobeManager().getLastOpenMenu();
if (menu == null) return;
menu.openMenu(user);
event.setCancelled(true);
}
});
}
private void registerEntityUseListener() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.USE_ENTITY) {
@Override
public void onPacketReceiving(PacketEvent event) {
if (event.getPlayer() == null) return;
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
if (user == null) return;
if (user.getUserEmoteManager().isPlayingEmote() || user.isInWardrobe()) {
event.setCancelled(true);
}
}
});
}
@Nullable
private EquipmentSlot getArmorSlot(final Material material) {
for (final EquipmentSlot slot : EquipmentSlot.values()) {
final Set<Material> armorItems = ARMOR_ITEMS.get(slot);
if (armorItems == null) continue;
if (material == null) continue;
if (armorItems.contains(material)) return slot;
}
return null;

View File

@@ -0,0 +1,101 @@
package com.hibiscusmc.hmccosmetics.listener;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import lombok.extern.slf4j.Slf4j;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@Slf4j
public class PlayerMovementListener implements Listener {
private static final List<CosmeticSlot> MOVEMENT_COSMETICS = List.of(
CosmeticSlot.BACKPACK,
CosmeticSlot.BALLOON
);
// Player Id -> Small Location
private final Map<UUID, SmallLocation> locations = new HashMap<>();
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent ev) {
final Player player = ev.getPlayer();
final CosmeticUser user = CosmeticUsers.getUser(player);
if(user == null) {
return;
}
if(!updateDirtyLocation(ev.getPlayer(), ev.getTo())) {
return;
}
for(final CosmeticSlot slot : MOVEMENT_COSMETICS) {
user.updateMovementCosmetic(slot, ev.getFrom(), ev.getTo());
}
}
private boolean updateDirtyLocation(final Player player, final Location nextLoc) {
final SmallLocation previous = locations.computeIfAbsent(
player.getUniqueId(),
$ -> SmallLocation.fromLocation(nextLoc)
);
final SmallLocation next = SmallLocation.fromLocation(nextLoc);
if(next.distanceTo(previous) > 0.25) {
this.locations.put(player.getUniqueId(), next);
return true;
}
if(next.yawDistanceTo(previous) > 5) {
this.locations.put(player.getUniqueId(), next);
return true;
}
return false;
}
@EventHandler(priority = EventPriority.NORMAL)
public void onWorldChange(final PlayerChangedWorldEvent ev) {
this.locations.remove(ev.getPlayer().getUniqueId());
}
@EventHandler
public void onPlayerQuit(final PlayerQuitEvent ev) {
locations.remove(ev.getPlayer().getUniqueId());
}
record SmallLocation(
double x,
double y,
double z,
float yaw
) {
public double distanceTo(SmallLocation other) {
double dx = this.x - other.x;
double dy = this.y - other.y;
double dz = this.z - other.z;
return Math.sqrt(dx * dx + dy * dy + dz * dz);
}
public float yawDistanceTo(SmallLocation other) {
float diff = Math.abs(this.yaw - other.yaw) % 360;
return diff > 180 ? 360 - diff : diff;
}
public static SmallLocation fromLocation(final Location location) {
return new SmallLocation(location.getX(), location.getY(), location.getZ(), location.getYaw());
}
}
}

View File

@@ -10,13 +10,15 @@ import me.lojosho.hibiscuscommons.hooks.items.HookNexo;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;
public class ServerListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onHookReload(HibiscusHookReload event) {
Hook hook = event.getHook();
HibiscusHookReload.ReloadType reloadType = event.getReloadType();
@EventHandler(priority = EventPriority.LOW)
public void onHookReload(@NotNull HibiscusHookReload event) {
final Hook hook = event.getHook();
final HibiscusHookReload.ReloadType reloadType = event.getReloadType();
if (hook instanceof HookItemAdder) {
if (reloadType == HibiscusHookReload.ReloadType.RELOAD) {
if (!Settings.isItemsAdderChangeReload()) return;
@@ -31,8 +33,8 @@ public class ServerListener implements Listener {
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onAllHooksReady(HibiscusHooksAllActiveEvent event) {
@EventHandler(priority = EventPriority.NORMAL)
public void onAllHooksReady(@NotNull HibiscusHooksAllActiveEvent event) {
HMCCosmeticsPlugin.setup();
}
}

View File

@@ -0,0 +1,229 @@
package com.hibiscusmc.hmccosmetics.packets;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
import com.hibiscusmc.hmccosmetics.gui.Menu;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.user.manager.UserBackpackManager;
import com.hibiscusmc.hmccosmetics.user.manager.UserWardrobeManager;
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import me.lojosho.hibiscuscommons.packets.PacketAction;
import me.lojosho.hibiscuscommons.packets.PacketInterface;
import me.lojosho.hibiscuscommons.packets.wrapper.*;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.*;
public class CosmeticPacketInterface implements PacketInterface {
@Override
public @NotNull PacketAction writeContainerContent(@NotNull Player player, @NotNull ContainerContentWrapper wrapper) {
int windowId = wrapper.getWindowId();
MessagesUtil.sendDebugMessages("writeContainerContent (windowid: " + windowId + " )");
if (windowId != 0) return PacketAction.NOTHING;
List<ItemStack> slotData = wrapper.getSlotData();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return PacketAction.NOTHING;
HashMap<Integer, ItemStack> cosmeticItems = new HashMap<>();
if (!user.isInWardrobe()) {
for (Cosmetic cosmetic : user.getCosmetics()) {
if (cosmetic instanceof CosmeticArmorType armorType) {
boolean requireEmpty = Settings.getSlotOption(armorType.getEquipSlot()).isRequireEmpty();
boolean isAir = user.getPlayer().getInventory().getItem(armorType.getEquipSlot()).getType().isAir();
MessagesUtil.sendDebugMessages("Menu Fired (Checks) - " + armorType.getId() + " - " + requireEmpty + " - " + isAir);
if (requireEmpty && !isAir) continue;
cosmeticItems.put(HMCCInventoryUtils.getPacketArmorSlot(armorType.getEquipSlot()), user.getUserCosmeticItem(armorType));
}
}
}
for (int slot = 0; slot < 46; slot++) {
if ((slot >= 5 && slot <= 8) || slot == 45) {
if (!cosmeticItems.containsKey(slot)) continue;
slotData.set(slot, cosmeticItems.get(slot));
if (Settings.isDebugMode()) MessagesUtil.sendDebugMessages("Set " + slot + " as " + cosmeticItems.get(slot));
}
}
wrapper.setSlotData(slotData);
MessagesUtil.sendDebugMessages("Menu Fired, updated cosmetics " + " on slotdata " + windowId + " with " + slotData.size());
return PacketAction.CHANGED;
}
@Override
public @NotNull PacketAction writeSlotContent(@NotNull Player player, @NotNull SlotContentWrapper wrapper) {
int windowId = wrapper.getWindowId();
int slot = wrapper.getSlot();
ItemStack itemStack = wrapper.getItemStack();
MessagesUtil.sendDebugMessages("SetSlot Initial ");
if (windowId != 0) return PacketAction.NOTHING;
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null || user.isInWardrobe()) return PacketAction.NOTHING;
MessagesUtil.sendDebugMessages("SetSlot Slot " + slot);
CosmeticSlot cosmeticSlot = HMCCInventoryUtils.NMSCosmeticSlot(slot);
EquipmentSlot equipmentSlot = HMCCInventoryUtils.getPacketArmorSlot(slot);
if (cosmeticSlot == null || equipmentSlot == null) return PacketAction.NOTHING;
if (!user.hasCosmeticInSlot(cosmeticSlot)) return PacketAction.NOTHING;
if (Settings.getSlotOption(equipmentSlot).isRequireEmpty()) {
if (!player.getInventory().getItem(equipmentSlot).getType().isAir()) return PacketAction.NOTHING;
}
wrapper.setItemStack(user.getUserCosmeticItem(cosmeticSlot));
return PacketAction.CHANGED;
}
@Override
public @NotNull PacketAction writeEquipmentContent(@NotNull Player player, @NotNull EntityEquipmentWrapper wrapper) {
if (player.getEntityId() != wrapper.getEntityId()) return PacketAction.NOTHING;
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null || user.isInWardrobe()) return PacketAction.NOTHING;
Map<EquipmentSlot, ItemStack> armor = wrapper.getArmor();
for (Map.Entry<EquipmentSlot, ItemStack> armorSlot : armor.entrySet()) {
EquipmentSlot slot = armorSlot.getKey();
if (slot == EquipmentSlot.HAND) {
if (user.getPlayer().getUniqueId() == player.getUniqueId())
continue; // When a player scrolls real fast, it messes up the mainhand. This fixes it
if (user.getPlayer() != null && user.getPlayer().isInvisible())
continue; // Fixes integration with GSit still showing mainhand even when hidden
armor.put(slot, player.getInventory().getItemInMainHand());
} else {
CosmeticSlot cosmeticSlot = HMCCInventoryUtils.BukkitCosmeticSlot(slot);
if (cosmeticSlot == null) continue;
if (Settings.getSlotOption(slot).isRequireEmpty() && player.getInventory().getItem(slot).getType().isAir())
continue;
CosmeticArmorType cosmeticArmor = (CosmeticArmorType) user.getCosmetic(cosmeticSlot);
if (cosmeticArmor == null) continue;
ItemStack item = user.getUserCosmeticItem(cosmeticSlot);
if (item == null) continue;
armor.put(slot, item);
}
}
wrapper.setArmor(armor);
MessagesUtil.sendDebugMessages("Equipment for " + user.getPlayer().getName() + " has been updated for " + player.getName());
return PacketAction.CHANGED;
}
@Override
public @NotNull PacketAction writePassengerContent(@NotNull Player player, @NotNull PassengerWrapper wrapper) {
// TODO: Figure out what to do with this, because with it in, it ruins backpacks (they keep getting thrown to random locations).
return PacketAction.NOTHING;
/*
CosmeticUser viewerUser = CosmeticUsers.getUser(player);
if (viewerUser == null || viewerUser.isInWardrobe()) return PacketAction.NOTHING;
int ownerId = wrapper.getOwner();
Optional<CosmeticUser> optionalCosmeticUser = CosmeticUsers.values().stream().filter(user -> user.getPlayer() != null).filter(user -> ownerId == user.getPlayer().getEntityId()).findFirst();
if (optionalCosmeticUser.isEmpty()) return PacketAction.NOTHING;
CosmeticUser user = optionalCosmeticUser.get();
Cosmetic backpackCosmetic = user.getCosmetic(CosmeticSlot.BACKPACK);
if (backpackCosmetic == null) return PacketAction.NOTHING;
if (!(backpackCosmetic instanceof CosmeticBackpackType cosmeticBackpackType)) return PacketAction.NOTHING;
if (user.getUniqueId().equals(viewerUser.getUniqueId())) {
if (cosmeticBackpackType.isFirstPersonCompadible()) return PacketAction.NOTHING;
}
if (user.getUserBackpackManager() == null) return PacketAction.NOTHING;
List<Integer> originalPassengers = wrapper.getPassengers();
List<Integer> passengers = new ArrayList<>(user.getUserBackpackManager().getEntityManager().getIds());
passengers.addAll(originalPassengers);
wrapper.setPassengers(passengers);
return PacketAction.CHANGED;
*/
}
@Override
public PacketAction readPlayerScale(@NotNull Player player, @NotNull PlayerScaleWrapper wrapper) {
int entityId = wrapper.getEntityId();
Player changedPlayer = Bukkit.getOnlinePlayers().stream()
.filter(onlinePlayer -> onlinePlayer.getEntityId() == entityId)
.findFirst()
.orElse(null);
if (changedPlayer == null) return PacketAction.NOTHING;
CosmeticUser cosmeticUser = CosmeticUsers.getUser(changedPlayer.getUniqueId());
if (cosmeticUser == null || cosmeticUser.isInWardrobe()) return PacketAction.NOTHING;
UserBackpackManager backpack = cosmeticUser.getUserBackpackManager();
if (backpack != null) {
for (int cosmeticId : backpack.getEntityManager().getIds()) {
HMCCPacketManager.sendEntityScalePacket(cosmeticId, wrapper.getScale(), Collections.singletonList(player));
}
}
return PacketAction.NOTHING;
}
@Override
public @NotNull PacketAction readInventoryClick(@NotNull Player player, @NotNull InventoryClickWrapper wrapper) {
int clickType = wrapper.getClickType();
int slotNumber = wrapper.getSlotNumber();
if (clickType != 0 || slotNumber == -999) return PacketAction.NOTHING;
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null || user.isInWardrobe()) return PacketAction.NOTHING;
CosmeticSlot cosmeticSlot = HMCCInventoryUtils.NMSCosmeticSlot(slotNumber);
if (cosmeticSlot == null || !user.hasCosmeticInSlot(cosmeticSlot)) return PacketAction.NOTHING;
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> user.updateCosmetic(cosmeticSlot), 1);
MessagesUtil.sendDebugMessages("Packet fired, updated cosmetic " + cosmeticSlot);
return PacketAction.NOTHING;
}
@Override
public @NotNull PacketAction readPlayerAction(@NotNull Player player, @NotNull PlayerActionWrapper wrapper) {
if (!Settings.isPreventOffhandSwapping()) return PacketAction.NOTHING;
String actionType = wrapper.getActionType();
MessagesUtil.sendDebugMessages("EntityStatus Initial " + player.getEntityId() + " - " + actionType);
// If it's not SWAP_ITEM_WITH_OFFHAND, ignore
if (!actionType.equalsIgnoreCase("SWAP_ITEM_WITH_OFFHAND")) return PacketAction.NOTHING;
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) {
MessagesUtil.sendDebugMessages("EntityStatus User is null");
return PacketAction.NOTHING;
}
if (!user.hasCosmeticInSlot(CosmeticSlot.OFFHAND)) return PacketAction.NOTHING;
return PacketAction.CANCELLED;
}
@Override
public @NotNull PacketAction readPlayerArm(@NotNull Player player, @NotNull PlayerSwingWrapper wrapper) {
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null || !user.isInWardrobe() || !user.getWardrobeManager().getWardrobeStatus().equals(UserWardrobeManager.WardrobeStatus.RUNNING)) return PacketAction.NOTHING;
Menu menu = user.getWardrobeManager().getLastOpenMenu();
if (menu == null) return PacketAction.NOTHING;
menu.openMenu(user);
return PacketAction.CANCELLED;
}
@Override
public @NotNull PacketAction readEntityHandle(@NotNull Player player, @NotNull PlayerInteractWrapper wrapper) {
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null || !user.isInWardrobe()) return PacketAction.NOTHING;
else return PacketAction.CANCELLED;
}
}

View File

@@ -8,27 +8,29 @@ import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.config.Wardrobe;
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.cosmetic.behavior.CosmeticMovementBehavior;
import com.hibiscusmc.hmccosmetics.cosmetic.behavior.CosmeticUpdateBehavior;
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.CosmeticMainhandType;
import com.hibiscusmc.hmccosmetics.database.UserData;
import com.hibiscusmc.hmccosmetics.gui.Menus;
import com.hibiscusmc.hmccosmetics.user.manager.UserBackpackManager;
import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager;
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
import com.hibiscusmc.hmccosmetics.user.manager.UserWardrobeManager;
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import lombok.Getter;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
import me.lojosho.hibiscuscommons.util.InventoryUtils;
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.HumanEntity;
@@ -37,6 +39,7 @@ import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.*;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -44,17 +47,15 @@ import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.logging.Level;
public class CosmeticUser {
public class CosmeticUser implements CosmeticHolder {
@Getter
private final UUID uniqueId;
private int taskId = -1;
private final HashMap<CosmeticSlot, Cosmetic> playerCosmetics = new HashMap<>();
private UserWardrobeManager userWardrobeManager;
private UserBalloonManager userBalloonManager;
@Getter
@Getter @Nullable
private UserBackpackManager userBackpackManager;
@Getter
private final UserEmoteManager userEmoteManager;
// Cosmetic Settings/Toggles
private final ArrayList<HiddenReason> hiddenReason = new ArrayList<>();
@@ -73,7 +74,6 @@ public class CosmeticUser {
public CosmeticUser(@NotNull UUID uuid) {
this.uniqueId = uuid;
this.userEmoteManager = new UserEmoteManager(this);
}
/**
@@ -99,7 +99,7 @@ public class CosmeticUser {
Color color = null;
if (colorRGBInt != -1) color = Color.fromRGB(colorRGBInt); // -1 is defined as no color; anything else is a color
this.addPlayerCosmetic(cosmetic, color);
this.addCosmetic(cosmetic, color);
}
this.applyHiddenState(userData.getHiddenReasons());
}
@@ -112,7 +112,7 @@ public class CosmeticUser {
* This is used to help hooking plugins apply custom logic to the user.
*/
protected boolean applyCosmetic(@NotNull Cosmetic cosmetic, @Nullable Color color) {
this.addPlayerCosmetic(cosmetic, color);
this.addCosmetic(cosmetic, color);
return true;
}
@@ -145,13 +145,18 @@ public class CosmeticUser {
showCosmetics(HiddenReason.GAMEMODE);
}
if (bukkitPlayer != null && Settings.getDisabledWorlds().contains(getEntity().getLocation().getWorld().getName())) {
if (bukkitPlayer != null && Settings.getDisabledWorlds().contains(bukkitPlayer.getLocation().getWorld().getName())) {
MessagesUtil.sendDebugMessages("Hiding Cosmetics due to world");
hideCosmetics(CosmeticUser.HiddenReason.WORLD);
} else if (this.isHidden(HiddenReason.WORLD)) {
MessagesUtil.sendDebugMessages("Showing Cosmetics due to world");
showCosmetics(HiddenReason.WORLD);
}
if (bukkitPlayer != null && bukkitPlayer.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
hideCosmetics(HiddenReason.POTION);
}
if (Settings.isAllPlayersHidden()) {
hideCosmetics(HiddenReason.DISABLED);
}
@@ -193,7 +198,7 @@ public class CosmeticUser {
this.updateCosmetic();
if(isHidden() && !getUserEmoteManager().isPlayingEmote() && !getCosmetics().isEmpty()) {
if(isHidden() && !playerCosmetics.isEmpty()) {
MessagesUtil.sendActionBar(getPlayer(), "hidden-cosmetics");
}
}
@@ -207,19 +212,18 @@ public class CosmeticUser {
despawnBalloon();
}
public Cosmetic getCosmetic(CosmeticSlot slot) {
@Override
public Cosmetic getCosmetic(@NotNull CosmeticSlot slot) {
return playerCosmetics.get(slot);
}
public ImmutableCollection<Cosmetic> getCosmetics() {
@Override
public @NotNull ImmutableCollection<Cosmetic> getCosmetics() {
return ImmutableList.copyOf(playerCosmetics.values());
}
public void addPlayerCosmetic(@NotNull Cosmetic cosmetic) {
addPlayerCosmetic(cosmetic, null);
}
public void addPlayerCosmetic(@NotNull Cosmetic cosmetic, @Nullable Color color) {
@Override
public void addCosmetic(@NotNull Cosmetic cosmetic, @Nullable Color color) {
// API
PlayerCosmeticEquipEvent event = new PlayerCosmeticEquipEvent(this, cosmetic);
Bukkit.getPluginManager().callEvent(event);
@@ -251,14 +255,24 @@ public class CosmeticUser {
Bukkit.getPluginManager().callEvent(postEquipEvent);
}
public void removeCosmetics() {
// Small optimization could be made, but Concurrent modification prevents us from both getting and removing
for (CosmeticSlot slot : CosmeticSlot.values().values()) {
removeCosmeticSlot(slot);
}
/**
* @deprecated Use {@link #addCosmetic(Cosmetic)} instead
*/
@Deprecated(since = "2.7.7", forRemoval = true)
public void addPlayerCosmetic(@NotNull Cosmetic cosmetic) {
addCosmetic(cosmetic);
}
public void removeCosmeticSlot(CosmeticSlot slot) {
/**
* @deprecated Use {@link #addCosmetic(Cosmetic, Color)} instead
*/
@Deprecated(since = "2.7.7", forRemoval = true)
public void addPlayerCosmetic(@NotNull Cosmetic cosmetic, @Nullable Color color) {
addCosmetic(cosmetic, color);
}
@Override
public void removeCosmeticSlot(@NotNull CosmeticSlot slot) {
// API
PlayerCosmeticRemoveEvent event = new PlayerCosmeticRemoveEvent(this, getCosmetic(slot));
Bukkit.getPluginManager().callEvent(event);
@@ -272,50 +286,68 @@ public class CosmeticUser {
if (slot == CosmeticSlot.BALLOON) {
despawnBalloon();
}
if (slot == CosmeticSlot.EMOTE) {
if (getUserEmoteManager().isPlayingEmote()) getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.UNEQUIP);
}
colors.remove(slot);
playerCosmetics.remove(slot);
removeArmor(slot);
}
public void removeCosmeticSlot(Cosmetic cosmetic) {
removeCosmeticSlot(cosmetic.getSlot());
}
public boolean hasCosmeticInSlot(CosmeticSlot slot) {
@Override
public boolean hasCosmeticInSlot(@NotNull CosmeticSlot slot) {
return playerCosmetics.containsKey(slot);
}
public boolean hasCosmeticInSlot(Cosmetic cosmetic) {
if (getCosmetic(cosmetic.getSlot()) == null) return false;
return Objects.equals(cosmetic.getId(), getCosmetic(cosmetic.getSlot()).getId());
}
public Set<CosmeticSlot> getSlotsWithCosmetics() {
return Set.copyOf(playerCosmetics.keySet());
}
public void updateCosmetic(CosmeticSlot slot) {
if (getCosmetic(slot) == null) {
return;
}
getCosmetic(slot).update(this);
return;
@Override
public boolean updateCosmetic(@NotNull CosmeticSlot slot) {
final Cosmetic cosmetic = playerCosmetics.get(slot);
if(cosmetic == null) {
return false;
}
public void updateCosmetic(Cosmetic cosmetic) {
updateCosmetic(cosmetic.getSlot());
if(!(cosmetic instanceof CosmeticUpdateBehavior behavior)) {
MessagesUtil.sendDebugMessages("Attempted to update cosmetic that does not implement CosmeticUpdateBehavior");
return false;
}
behavior.dispatchUpdate(this);
return true;
}
@Override
public boolean updateMovementCosmetic(@NotNull CosmeticSlot slot, @NotNull final Location from, @NotNull final Location to) {
final Cosmetic cosmetic = playerCosmetics.get(slot);
if(cosmetic == null) {
return false;
}
if(!(cosmetic instanceof CosmeticMovementBehavior behavior)) {
MessagesUtil.sendDebugMessages("Attempted to update cosmetic that does not implement CosmeticMovementBehavior");
return false;
}
behavior.dispatchMove(this, from, to);
return true;
}
public boolean updateCosmetic(@NotNull final Cosmetic cosmetic) {
return updateCosmetic(cosmetic.getSlot());
}
public void updateCosmetic() {
MessagesUtil.sendDebugMessages("updateCosmetic (All) - start");
HashMap<EquipmentSlot, ItemStack> items = new HashMap<>();
final HashMap<EquipmentSlot, ItemStack> items = new HashMap<>();
for (Cosmetic cosmetic : getCosmetics()) {
for(final Cosmetic cosmetic : playerCosmetics.values()) {
if(!(cosmetic instanceof CosmeticUpdateBehavior behavior)) {
continue;
}
// defers item updates to end of operation
if(cosmetic instanceof CosmeticArmorType armorType) {
if (getUserEmoteManager().isPlayingEmote() || isInWardrobe()) return;
if (isInWardrobe()) return;
if (!(getEntity() instanceof HumanEntity humanEntity)) return;
boolean requireEmpty = Settings.getSlotOption(armorType.getEquipSlot()).isRequireEmpty();
@@ -325,15 +357,22 @@ public class CosmeticUser {
items.put(HMCCInventoryUtils.getEquipmentSlot(armorType.getSlot()), armorType.getItem(this));
} else {
updateCosmetic(cosmetic.getSlot());
behavior.dispatchUpdate(this);
}
}
if (items.isEmpty() || getEntity() == null) return;
PacketManager.equipmentSlotUpdate(getEntity().getEntityId(), items, HMCCPacketManager.getViewers(getEntity().getLocation()));
MessagesUtil.sendDebugMessages("updateCosmetic (All) - end - " + items.size());
}
public ItemStack getUserCosmeticItem(CosmeticSlot slot) {
final Entity entity = this.getEntity();
if(!items.isEmpty() && entity != null) {
PacketManager.equipmentSlotUpdate(
entity.getEntityId(),
items,
HMCCPacketManager.getViewers(entity.getLocation())
);
MessagesUtil.sendDebugMessages("updateCosmetic (All) - end - " + items.size());
}
}
public ItemStack getUserCosmeticItem(@NotNull CosmeticSlot slot) {
Cosmetic cosmetic = getCosmetic(slot);
if (cosmetic == null) return new ItemStack(Material.AIR);
return getUserCosmeticItem(cosmetic);
@@ -348,7 +387,7 @@ public class CosmeticUser {
if (cosmetic instanceof CosmeticArmorType armorType) {
item = armorType.getItem(this, cosmetic.getItem());
}
if (cosmetic instanceof CosmeticBackpackType || cosmetic instanceof CosmeticMainhandType) {
if (cosmetic instanceof CosmeticBackpackType) {
item = cosmetic.getItem();
}
if (cosmetic instanceof CosmeticBalloonType) {
@@ -410,29 +449,15 @@ public class CosmeticUser {
}
if (colors.containsKey(cosmetic.getSlot())) {
Color color = 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);
} else if (itemMeta instanceof FireworkEffectMeta fireworkMeta) {
fireworkMeta.setEffect(
FireworkEffect.builder()
.with(FireworkEffect.Type.BALL)
.withColor(color)
.trail(false)
.flicker(false)
.build()
);
}
}
itemMeta.getPersistentDataContainer().set(HMCCInventoryUtils.getCosmeticKey(), PersistentDataType.STRING, cosmetic.getId());
itemMeta.getPersistentDataContainer().set(InventoryUtils.getOwnerKey(), PersistentDataType.STRING, getEntity().getUniqueId().toString());
item.setItemMeta(itemMeta);
if (colors.containsKey(cosmetic.getSlot())) {
Color color = colors.get(cosmetic.getSlot());
item = NMSHandlers.getHandler().getUtilHandler().setColor(item, color);
}
}
return item;
}
@@ -620,7 +645,7 @@ public class CosmeticUser {
* @return Entity
*/
public Entity getEntity() {
return Bukkit.getEntity(uniqueId);
return getPlayer();
}
public Color getCosmeticColor(CosmeticSlot slot) {
@@ -628,25 +653,27 @@ public class CosmeticUser {
}
public List<CosmeticSlot> getDyeableSlots() {
ArrayList<CosmeticSlot> dyableSlots = new ArrayList<>();
ArrayList<CosmeticSlot> dyeableSlots = new ArrayList<>();
for (Cosmetic cosmetic : getCosmetics()) {
if (cosmetic.isDyable()) dyableSlots.add(cosmetic.getSlot());
for (Cosmetic cosmetic : playerCosmetics.values()) {
if (cosmetic.isDyeable()) dyeableSlots.add(cosmetic.getSlot());
}
return dyableSlots;
return dyeableSlots;
}
public boolean canEquipCosmetic(Cosmetic cosmetic) {
return canEquipCosmetic(cosmetic, false);
}
public boolean canEquipCosmetic(Cosmetic cosmetic, boolean ignoreWardrobe) {
@Override
public boolean canEquipCosmetic(@NotNull Cosmetic cosmetic, boolean ignoreWardrobe) {
if (!cosmetic.requiresPermission()) return true;
if (isInWardrobe() && !ignoreWardrobe) {
if (WardrobeSettings.isTryCosmeticsInWardrobe() && userWardrobeManager.getWardrobeStatus().equals(UserWardrobeManager.WardrobeStatus.RUNNING)) return true;
}
return getPlayer().hasPermission(cosmetic.getPermission());
final Player player = getPlayer();
if (player != null) return player.hasPermission(cosmetic.getPermission());
// This sucks, but basically if we can find a player, use that. If not, try to find the entity. If it can't find the entity, just return false.
final Entity entity = getEntity();
if (entity != null) return entity.hasPermission(cosmetic.getPermission());
return false;
}
public void hidePlayer() {

View File

@@ -5,33 +5,32 @@ import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import com.ticxo.modelengine.api.ModelEngineAPI;
import lombok.Getter;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.hibiscuscommons.util.ServerUtils;
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.logging.Level;
public class UserBackpackManager {
@Getter
private boolean backpackHidden;
@Getter
private int invisibleArmorStand;
private final int invisibleArmorStand;
private ArrayList<Integer> particleCloud = new ArrayList<>();
@Getter
private final CosmeticUser user;
@Getter
@Getter @Nullable
private UserEntity entityManager;
public UserBackpackManager(CosmeticUser user) {
@@ -56,8 +55,15 @@ public class UserBackpackManager {
getEntityManager().setIds(List.of(invisibleArmorStand));
getEntityManager().teleport(user.getEntity().getLocation());
List<Player> outsideViewers = getEntityManager().getViewers();
HMCCPacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), getFirstArmorStandId(), EntityType.ARMOR_STAND, UUID.randomUUID(), getEntityManager().getViewers());
HMCCPacketManager.sendArmorstandMetadata(getFirstArmorStandId(), outsideViewers);
HMCCPacketManager.spawnInvisibleArmorstand(getFirstArmorStandId(), user.getEntity().getLocation(), UUID.randomUUID(), outsideViewers);
if (user.getPlayer() != null) {
AttributeInstance scaleAttribute = user.getPlayer().getAttribute(Attribute.SCALE);
if (scaleAttribute != null) {
HMCCPacketManager.sendEntityScalePacket(getFirstArmorStandId(), scaleAttribute.getValue(), outsideViewers);
}
}
Entity entity = user.getEntity();
@@ -75,8 +81,7 @@ public class UserBackpackManager {
if (cosmeticBackpackType.isFirstPersonCompadible()) {
for (int i = particleCloud.size(); i < cosmeticBackpackType.getHeight(); i++) {
int entityId = ServerUtils.getNextEntityId();
HMCCPacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), entityId, EntityType.AREA_EFFECT_CLOUD, UUID.randomUUID());
HMCCPacketManager.sendCloudEffect(entityId, HMCCPacketManager.getViewers(user.getEntity().getLocation()));
HMCCPacketManager.spawnCloudAndHandleEffect(entityId, user.getEntity().getLocation(), UUID.randomUUID(), HMCCPacketManager.getViewers(user.getEntity().getLocation()));
this.particleCloud.add(entityId);
}
// Copied code from updating the backpack
@@ -84,7 +89,7 @@ public class UserBackpackManager {
if (i == 0) HMCCPacketManager.sendRidingPacket(entity.getEntityId(), particleCloud.get(i), owner);
else HMCCPacketManager.sendRidingPacket(particleCloud.get(i - 1), particleCloud.get(i) , owner);
}
HMCCPacketManager.sendRidingPacket(particleCloud.get(particleCloud.size() - 1), user.getUserBackpackManager().getFirstArmorStandId(), owner);
HMCCPacketManager.sendRidingPacket(particleCloud.getLast(), user.getUserBackpackManager().getFirstArmorStandId(), owner);
if (!user.isHidden()) PacketManager.equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(cosmeticBackpackType, cosmeticBackpackType.getFirstPersonBackpack()), owner);
}
PacketManager.equipmentSlotUpdate(getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(cosmeticBackpackType), outsideViewers);

View File

@@ -5,13 +5,13 @@ import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import com.ticxo.modelengine.api.ModelEngineAPI;
import com.ticxo.modelengine.api.entity.data.BukkitEntityData;
import com.ticxo.modelengine.api.model.ActiveModel;
import com.ticxo.modelengine.api.model.ModeledEntity;
import com.ticxo.modelengine.api.nms.RenderParsers;
import lombok.Getter;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
@@ -50,7 +50,8 @@ public class UserBalloonManager {
e.setSmall(true);
e.setMarker(true);
e.setPersistent(false);
e.getPersistentDataContainer().set(new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "cosmeticMob"), PersistentDataType.SHORT, Short.valueOf("1"));
e.setAI(false);
e.getPersistentDataContainer().set(HMCCServerUtils.getCosmemeticMobKey(), PersistentDataType.BOOLEAN, true);
});
}
@@ -82,7 +83,7 @@ public class UserBalloonManager {
if (color != null) {
modeledEntity.getModels().forEach((d, singleModel) -> {
if (cosmeticBalloonType.isDyablePart(d)) {
if (cosmeticBalloonType.isDyeablePart(d)) {
singleModel.setDefaultTint(color);
singleModel.getModelRenderer().sendToClient(ModelEngineAPI.getNMSHandler().createParsers());
}
@@ -100,7 +101,12 @@ public class UserBalloonManager {
}
public void remove() {
pufferfish.destroyPufferfish();
// This code is like a brick road, always bumpy.
// Basically, the balloon viewers ignore people in wardrobe, which well, if your the user in the wardrobe, ain't including you.
// This manually passes in the viewers for it to destroy, which includes the person in the wardrobe
if (user.getPlayer() != null && user.isInWardrobe()) pufferfish.destroyPufferfish(List.of(user.getPlayer()));
else pufferfish.destroyPufferfish();
if (balloonType == BalloonType.MODELENGINE) {
final ModeledEntity entity = ModelEngineAPI.getModeledEntity(modelEntity);
if (entity == null) {
@@ -180,6 +186,10 @@ public class UserBalloonManager {
this.getModelEntity().teleport(location);
}
public Vector getVelocity() {
return getModelEntity().getVelocity();
}
public void setVelocity(Vector vector) {
this.getModelEntity().setVelocity(vector);
}

View File

@@ -1,17 +1,12 @@
package com.hibiscusmc.hmccosmetics.user.manager;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.util.HMCCPlayerUtils;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import lombok.Getter;
import org.bukkit.Bukkit;
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@@ -26,6 +21,7 @@ public class UserBalloonPufferfish extends UserEntity {
public UserBalloonPufferfish(UUID owner, int pufferFishEntityId, UUID uuid) {
super(owner);
this.pufferFishEntityId = pufferFishEntityId;
setIds(List.of(pufferFishEntityId));
this.uuid = uuid;
}
@@ -35,8 +31,11 @@ public class UserBalloonPufferfish extends UserEntity {
}
public void spawnPufferfish(Location location, List<Player> sendTo) {
NMSHandlers.getHandler().getPacketHandler().sendInvisibleEntity(pufferFishEntityId, EntityType.PUFFERFISH, location, uuid, sendTo);
/*
HMCCPacketManager.sendEntitySpawnPacket(location, pufferFishEntityId, EntityType.PUFFERFISH, uuid, sendTo);
HMCCPacketManager.sendInvisibilityPacket(pufferFishEntityId, sendTo);
*/
}
public void destroyPufferfish() {
@@ -45,6 +44,12 @@ public class UserBalloonPufferfish extends UserEntity {
destroyed = true;
}
public void destroyPufferfish(List<Player> viewers) {
HMCCPacketManager.sendEntityDestroyPacket(pufferFishEntityId, viewers);
//getViewers().clear();
destroyed = true;
}
@Override
public List<Player> refreshViewers(Location location) {
if (destroyed) return List.of(); //Prevents refreshing a destroyed entity

View File

@@ -1,94 +0,0 @@
package com.hibiscusmc.hmccosmetics.user.manager;
import com.hibiscusmc.hmccosmetics.api.events.PlayerEmoteStartEvent;
import com.hibiscusmc.hmccosmetics.api.events.PlayerEmoteStopEvent;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticEmoteType;
import com.hibiscusmc.hmccosmetics.emotes.EmoteManager;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
public class UserEmoteManager {
private CosmeticUser user;
private UserEmoteModel model;
private Entity textEntity;
public UserEmoteManager(CosmeticUser user) {
this.user = user;
}
public void playEmote(String animationId) {
MessagesUtil.sendDebugMessages("playEmote " + animationId);
playEmote(EmoteManager.get(animationId), null);
}
public void playEmote(@NotNull CosmeticEmoteType cosmeticEmoteType) {
MessagesUtil.sendDebugMessages("playEmote " + cosmeticEmoteType.getAnimationId());
playEmote(EmoteManager.get(cosmeticEmoteType.getAnimationId()), cosmeticEmoteType.getText());
}
public void playEmote(String emoteAnimation, String text) {
if (isPlayingEmote()) return;
if (user.isInWardrobe()) return;
// API
PlayerEmoteStartEvent event = new PlayerEmoteStartEvent(user, emoteAnimation);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
// Internal
try {
model = new UserEmoteModel(user);
// Play animation id
if (emoteAnimation != null) {
model.playAnimation(emoteAnimation);
}
// Show the text
if (text != null && textEntity == null) {
// removed in 2.7.0
//textEntity = HMCCNMSHandlers.getHandler().spawnDisplayEntity(user.getPlayer().getLocation().add(0, 3, 0), text);
}
} 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();
if (textEntity != null) {
textEntity.remove();
textEntity = null;
}
}
public void despawnTextEntity() {
if (textEntity != null) {
textEntity.remove();
textEntity = null;
}
}
public enum StopEmoteReason {
SNEAK,
DAMAGE,
CONNECTION,
TELEPORT,
UNEQUIP
}
}

View File

@@ -1,134 +0,0 @@
package com.hibiscusmc.hmccosmetics.user.manager;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import com.ticxo.playeranimator.api.model.player.PlayerModel;
import me.lojosho.hibiscuscommons.util.ServerUtils;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
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 = ServerUtils.getNextEntityId();
getRangeManager().setRenderDistance(Settings.getViewDistance());
}
@Override
public void playAnimation(@NotNull String id) {
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 = HMCCPacketManager.getViewers(player.getLocation());
// Send equipment packet to the player as well (Fixes Optifine still rendering armor when emoting)
HMCCPacketManager.equipmentSlotUpdate(player, true, outsideViewers);
outsideViewers.remove(player);
user.getPlayer().setInvisible(true);
user.hideCosmetics(CosmeticUser.HiddenReason.EMOTE);
originalGamemode = player.getGameMode();
if (Settings.isEmoteCameraEnabled()) {
Location newLocation = player.getLocation().clone();
newLocation.setPitch(0);
double DISTANCE = Settings.getEmoteDistance();
Location thirdPersonLocation = newLocation.add(newLocation.getDirection().normalize().multiply(DISTANCE));
if (DISTANCE > 0) {
MessagesUtil.sendDebugMessages("Yaw " + (int) thirdPersonLocation.getYaw());
MessagesUtil.sendDebugMessages("New Yaw " + ServerUtils.getNextYaw((int) thirdPersonLocation.getYaw(), 180));
thirdPersonLocation.setYaw(ServerUtils.getNextYaw((int) thirdPersonLocation.getYaw(), 180));
}
if (Settings.isCosmeticEmoteBlockCheck() && thirdPersonLocation.getBlock().getType().isOccluding()) {
stopAnimation();
MessagesUtil.sendMessage(player, "emote-blocked");
return;
}
// Check if block below player is an air block
if (Settings.isEmoteAirCheck() && newLocation.clone().subtract(0, 1, 0).getBlock().getType().isAir()) {
stopAnimation();
MessagesUtil.sendMessage(player, "emote-blocked");
}
HMCCPacketManager.sendEntitySpawnPacket(thirdPersonLocation, armorStandId, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer);
HMCCPacketManager.sendInvisibilityPacket(armorStandId, viewer);
HMCCPacketManager.sendLookPacket(armorStandId, thirdPersonLocation, viewer);
HMCCPacketManager.gamemodeChangePacket(player, 3);
HMCCPacketManager.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 = HMCCPacketManager.getViewers(player.getLocation());
// Send Equipment packet to all (Fixes Optifine Issue)
HMCCPacketManager.equipmentSlotUpdate(player, false, outsideViewers);
outsideViewers.remove(player);
int entityId = player.getEntityId();
HMCCPacketManager.sendCameraPacket(entityId, viewer);
HMCCPacketManager.sendEntityDestroyPacket(armorStandId, viewer);
if (this.originalGamemode != null) {
HMCCPacketManager.gamemodeChangePacket(player, HMCCServerUtils.convertGamemode(this.originalGamemode));
player.setGameMode(this.originalGamemode);
}
if (user.getPlayer() != null) player.setInvisible(false);
user.getUserEmoteManager().despawnTextEntity();
user.showPlayer();
user.showCosmetics(CosmeticUser.HiddenReason.EMOTE);
});
}
public boolean isPlayingAnimation() {
return emotePlaying != null;
}
}

View File

@@ -1,20 +1,19 @@
package com.hibiscusmc.hmccosmetics.user.manager;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.util.HMCCPlayerUtils;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.*;
public class UserEntity {
@@ -40,46 +39,73 @@ public class UserEntity {
}
public List<Player> refreshViewers(Location location) {
if (System.currentTimeMillis() - viewerLastUpdate <= 1000) return List.of(); //Prevents mass refreshes
ArrayList<Player> newPlayers = new ArrayList<>();
ArrayList<Player> removePlayers = new ArrayList<>();
List<Player> players = HMCCPacketManager.getViewers(location);
Player ownerPlayer = Bukkit.getPlayer(owner);
//Prevents mass refreshes
//if(System.currentTimeMillis() - viewerLastUpdate <= 3000) {
// return List.of();
//}
Entity ownerPlayer = Bukkit.getEntity(owner);
if (ownerPlayer == null) {
MessagesUtil.sendDebugMessages("Owner is null (refreshViewers), returning empty list");
return List.of();
}
final List<Player> players = HMCCosmeticsPlugin.getInstance()
.getPlayerSearchManager()
.getPlayersInRange(location, Settings.getViewDistance());
final ArrayList<UUID> newPlayerIds = new ArrayList<>();
final ArrayList<UUID> removePlayerIds = new ArrayList<>();
// Go through all nearby players, check if they are new to the viewers list.
for (Player player : players) {
CosmeticUser user = CosmeticUsers.getUser(player);
if (user != null && owner != user.getUniqueId() && user.isInWardrobe() && !player.canSee(ownerPlayer)) { // Fixes issue where players in wardrobe would see other players cosmetics if they were not in wardrobe
removePlayers.add(player);
HMCCPacketManager.sendEntityDestroyPacket(ids, List.of(player));
if(
user != null
&& owner != user.getUniqueId()
&& user.isInWardrobe()
// Fixes issue where players in wardrobe would see other players cosmetics if they were not in wardrobe
&& !player.canSee(ownerPlayer)
) {
removePlayerIds.add(player.getUniqueId());
continue;
}
if (!viewers.contains(player)) {
viewers.add(player);
newPlayers.add(player);
continue;
newPlayerIds.add(player.getUniqueId());
}
// bad loopdy loops
}
// Basically, if they are not nearby, they are still in the viewers and we need to kick em to the curb
for (Player viewerPlayer : viewers) {
if (!players.contains(viewerPlayer)) {
removePlayers.add(viewerPlayer);
HMCCPacketManager.sendEntityDestroyPacket(ids, List.of(viewerPlayer));
}
removePlayerIds.add(viewerPlayer.getUniqueId());
}
}
// If there are players for removal, send the packets to them
if (!removePlayerIds.isEmpty()) {
final List<Player> removePlayers = removePlayerIds.stream()
.map(Bukkit::getPlayer)
.filter(Objects::nonNull)
.toList();
HMCCPacketManager.sendEntityDestroyPacket(ids, removePlayers);
viewers.removeAll(removePlayers);
setViewerLastUpdate(System.currentTimeMillis());
return newPlayers;
}
this.setViewerLastUpdate(System.currentTimeMillis());
return newPlayerIds.stream()
.map(Bukkit::getPlayer)
.filter(Objects::nonNull)
.toList();
}
public void teleport(Location location) {
if (this.getLocation() != null && this.getLocation().getWorld() == location.getWorld()) {
// Was thinking about using schedulers to just send the packet later... but that would be a lot of tasks and
// would probably cause more lag. Furthermore, the server "ticks" the cosmetics every second by defualt. So it's fine like this.
if (System.currentTimeMillis() - getLastPositionUpdate() <= Settings.getPacketEntityTeleportCooldown()) return;
//if (System.currentTimeMillis() - getLastPositionUpdate() <= Settings.getPacketEntityTeleportCooldown()) return;
}
this.location = location;
for (Integer entity : ids) {
@@ -98,7 +124,7 @@ public class UserEntity {
// First person backpacks need both packets to rotate properly, otherwise they look off
// Regular backpacks just need the look packet
if (additonalPacket) HMCCPacketManager.sendRotationPacket(entity, yaw, false, getViewers());
HMCCPacketManager.sendLookPacket(entity, location, getViewers());
HMCCPacketManager.sendRotateHeadPacket(entity, location, getViewers());
}
}
}

View File

@@ -20,12 +20,13 @@ import me.lojosho.hibiscuscommons.nms.NMSHandlers;
import me.lojosho.hibiscuscommons.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.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent;
@@ -117,12 +118,14 @@ public class UserWardrobeManager {
// Armorstand
HMCCPacketManager.sendEntitySpawnPacket(viewingLocation, ARMORSTAND_ID, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer);
HMCCPacketManager.sendArmorstandMetadata(ARMORSTAND_ID, viewer);
HMCCPacketManager.sendLookPacket(ARMORSTAND_ID, viewingLocation, viewer);
NMSHandlers.getHandler().getPacketHandler().sendTeleportPacket(ARMORSTAND_ID, viewingLocation.getX(), viewingLocation.getY(), viewingLocation.getZ(), viewingLocation.getYaw(), viewingLocation.getPitch(), false, viewer);
//NMSHandlers.getHandler().getPacketHandler().sendLookAtPacket(ARMORSTAND_ID, viewingLocation, viewer);
HMCCPacketManager.sendRotateHeadPacket(ARMORSTAND_ID, viewingLocation, viewer);
// Player
player.teleport(viewingLocation, PlayerTeleportEvent.TeleportCause.PLUGIN);
player.setInvisible(true);
HMCCPacketManager.gamemodeChangePacket(player, 3);
HMCCPacketManager.gamemodeChangePacket(player, GameMode.SPECTATOR);
HMCCPacketManager.sendCameraPacket(ARMORSTAND_ID, viewer);
// NPC
@@ -139,10 +142,14 @@ public class UserWardrobeManager {
HMCCPacketManager.sendPlayerOverlayPacket(NPC_ID, viewer);
MessagesUtil.sendDebugMessages("Spawned Fake Player on " + npcLocation);
NMSHandlers.getHandler().getPacketHandler().sendScoreboardHideNamePacket(player, npcName);
AttributeInstance scaleAttribute = user.getPlayer().getAttribute(Attribute.SCALE);
if (scaleAttribute != null) {
HMCCPacketManager.sendEntityScalePacket(NPC_ID, scaleAttribute.getValue(), viewer);
}
}, 4);
// Location
HMCCPacketManager.sendLookPacket(NPC_ID, npcLocation, viewer);
HMCCPacketManager.sendRotateHeadPacket(NPC_ID, npcLocation, viewer);
HMCCPacketManager.sendRotationPacket(NPC_ID, npcLocation, true, viewer);
// Misc
@@ -176,9 +183,9 @@ public class UserWardrobeManager {
Component message = MessagesUtil.processStringNoKey(player, WardrobeSettings.getBossbarMessage());
bossBar = BossBar.bossBar(message, progress, WardrobeSettings.getBossbarColor(), WardrobeSettings.getBossbarOverlay());
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
//Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
target.showBossBar(bossBar);
player.showBossBar(bossBar);
}
if (WardrobeSettings.isEnterOpenMenu()) {
@@ -247,11 +254,11 @@ public class UserWardrobeManager {
if (WardrobeSettings.isForceExitGamemode()) {
MessagesUtil.sendDebugMessages("Force Exit Gamemode " + WardrobeSettings.getExitGamemode());
player.setGameMode(WardrobeSettings.getExitGamemode());
HMCCPacketManager.gamemodeChangePacket(player, HMCCServerUtils.convertGamemode(WardrobeSettings.getExitGamemode())); // Success
HMCCPacketManager.gamemodeChangePacket(player, WardrobeSettings.getExitGamemode()); // Success
} else {
MessagesUtil.sendDebugMessages("Original Gamemode " + this.originalGamemode);
player.setGameMode(this.originalGamemode);
HMCCPacketManager.gamemodeChangePacket(player, HMCCServerUtils.convertGamemode(this.originalGamemode)); // Success
HMCCPacketManager.gamemodeChangePacket(player, this.originalGamemode); // Success
}
user.showPlayer();
@@ -280,9 +287,8 @@ public class UserWardrobeManager {
HMCCPacketManager.equipmentSlotUpdate(player.getEntityId(), items, viewer);
if (WardrobeSettings.isEnabledBossbar()) {
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
target.hideBossBar(bossBar);
//Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
player.hideBossBar(bossBar);
}
user.updateCosmetic();
@@ -311,11 +317,13 @@ public class UserWardrobeManager {
int yaw = data.get();
location.setYaw(yaw);
HMCCPacketManager.sendLookPacket(NPC_ID, location, viewer);
HMCCPacketManager.sendRotateHeadPacket(NPC_ID, location, viewer);
user.hidePlayer();
int rotationSpeed = WardrobeSettings.getRotationSpeed();
location.setYaw(HMCCServerUtils.getNextYaw(yaw - 30, rotationSpeed));
HMCCPacketManager.sendRotationPacket(NPC_ID, location, true, viewer);
int newYaw = HMCCServerUtils.getNextYaw(yaw - 30, rotationSpeed);
location.setYaw(newYaw);
NMSHandlers.getHandler().getPacketHandler().sendRotationPacket(NPC_ID, newYaw, 0, false, viewer);
HMCCPacketManager.sendRotationPacket(NPC_ID, newYaw, true, viewer);
int nextyaw = HMCCServerUtils.getNextYaw(yaw, rotationSpeed);
data.set(nextyaw);

View File

@@ -1,6 +1,5 @@
package com.hibiscusmc.hmccosmetics.util;
import com.comphenix.protocol.wrappers.EnumWrappers;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import org.bukkit.NamespacedKey;
@@ -28,22 +27,6 @@ public class HMCCInventoryUtils {
SLOT_MAP.put(CosmeticSlot.MAINHAND, EquipmentSlot.HAND);
}
/**
* Converts from the Bukkit item slots to ProtocolLib item slots. Will produce a null if an improper bukkit item slot is sent through
* @param slot The BUKKIT item slot to convert.
* @return The ProtocolLib item slot that is returned
*/
public static EnumWrappers.ItemSlot itemBukkitSlot(final EquipmentSlot slot) {
return switch (slot) {
case HEAD -> EnumWrappers.ItemSlot.HEAD;
case CHEST -> EnumWrappers.ItemSlot.CHEST;
case LEGS -> EnumWrappers.ItemSlot.LEGS;
case FEET -> EnumWrappers.ItemSlot.FEET;
case HAND -> EnumWrappers.ItemSlot.MAINHAND;
case OFF_HAND -> EnumWrappers.ItemSlot.OFFHAND;
};
}
public static int getPacketArmorSlot(final EquipmentSlot slot) {
return switch (slot) {
case HEAD -> 5;
@@ -67,18 +50,6 @@ public class HMCCInventoryUtils {
};
}
public static CosmeticSlot getItemSlotToCosmeticSlot(final EnumWrappers.ItemSlot slot) {
return switch (slot) {
case HEAD -> CosmeticSlot.HELMET;
case CHEST -> CosmeticSlot.CHESTPLATE;
case LEGS -> CosmeticSlot.LEGGINGS;
case FEET -> CosmeticSlot.BOOTS;
case OFFHAND -> CosmeticSlot.OFFHAND;
case MAINHAND -> CosmeticSlot.MAINHAND;
default -> null;
};
}
public static CosmeticSlot BukkitCosmeticSlot(EquipmentSlot slot) {
return switch (slot) {
case HAND -> CosmeticSlot.MAINHAND;
@@ -147,32 +118,6 @@ public class HMCCInventoryUtils {
return SLOT_MAP.get(slot);
}
public static EquipmentSlot getEquipmentSlot(@NotNull EnumWrappers.ItemSlot slot) {
switch (slot) {
case HEAD -> {
return EquipmentSlot.HEAD;
}
case CHEST -> {
return EquipmentSlot.CHEST;
}
case LEGS -> {
return EquipmentSlot.LEGS;
}
case FEET -> {
return EquipmentSlot.FEET;
}
case OFFHAND -> {
return EquipmentSlot.OFF_HAND;
}
case MAINHAND -> {
return EquipmentSlot.HAND;
}
default -> {
return null;
}
}
}
public static boolean isCosmeticItem(ItemStack itemStack) {
if (itemStack == null) return false;
itemStack = itemStack.clone();

View File

@@ -1,29 +1,15 @@
package com.hibiscusmc.hmccosmetics.util;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.comphenix.protocol.wrappers.WrappedSignedProperty;
import com.hibiscusmc.hmccosmetics.config.Settings;
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class HMCCPlayerUtils {
@Nullable
public static WrappedSignedProperty getSkin(Player player) {
WrappedSignedProperty skinData = WrappedGameProfile.fromPlayer(player).getProperties()
.get("textures").stream().findAny().orElse(null);
if (skinData == null) {
return null;
}
return new WrappedSignedProperty("textures", skinData.getValue(), skinData.getSignature());
}
/**
* Get nearby players. {@link com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager#getViewers(Location)}
* @param player

View File

@@ -1,5 +1,6 @@
package com.hibiscusmc.hmccosmetics.util;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.owen1212055.particlehelper.api.particle.MultiParticle;
import com.owen1212055.particlehelper.api.particle.Particle;
import com.owen1212055.particlehelper.api.particle.types.*;
@@ -9,6 +10,8 @@ import me.lojosho.hibiscuscommons.nms.NMSHandlers;
import org.bukkit.Color;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.Nullable;
import java.math.BigInteger;
@@ -157,4 +160,8 @@ public class HMCCServerUtils {
}
return nextYaw;
}
public static NamespacedKey getCosmemeticMobKey() {
return new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "cosmeticmob");
}
}

View File

@@ -7,7 +7,6 @@ import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.hibiscuscommons.util.AdventureUtils;
import me.lojosho.shaded.configurate.ConfigurationNode;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.kyori.adventure.title.Title;
@@ -43,41 +42,35 @@ public class MessagesUtil {
public static void sendMessage(Player player, String key) {
Component finalMessage = processString(player, key);
if (finalMessage == null) return;
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
target.sendMessage(finalMessage);
player.sendMessage(finalMessage);
}
public static void sendMessage(CommandSender sender, String key) {
Component finalMessage = processString(null, key);
if (finalMessage == null) return;
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).sender(sender);
target.sendMessage(finalMessage);
sender.sendMessage(finalMessage);
}
public static void sendMessage(Player player, String key, TagResolver placeholder) {
Component finalMessage = processString(player, key, placeholder);
if (finalMessage == null) return;
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
target.sendMessage(finalMessage);
player.sendMessage(finalMessage);
}
public static void sendMessageNoKey(Player player, String message) {
Component finalMessage = processStringNoKey(player, message);
if (finalMessage == null) return;
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
target.sendMessage(finalMessage);
player.sendMessage(finalMessage);
}
public static void sendActionBar(Player player, String key) {
Component finalMessage = processString(player, key);
if (finalMessage == null) return;
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
target.sendActionBar(finalMessage);
player.sendActionBar(finalMessage);
}
public static void sendTitle(Player player, String message) {
@@ -85,12 +78,10 @@ public class MessagesUtil {
}
public static void sendTitle(Player player, String message, int fadein, int stay, int fadeout) {
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
Title.Times times = Title.Times.times(Duration.ofMillis(fadein), Duration.ofMillis(stay), Duration.ofMillis(fadeout));
Title title = Title.title(processStringNoKey(player, message), Component.empty(), times);
target.showTitle(title);
player.showTitle(title);
}
public static Component processString(Player player, String key) {

View File

@@ -0,0 +1,148 @@
package com.hibiscusmc.hmccosmetics.util;
import java.util.ArrayList;
import java.util.List;
public class Octree<T> {
private static final int MAX_CAPACITY = 8;
private BoundingBox boundary;
private List<Entry> points;
private Octree<T>[] children;
private boolean isDivided;
public Octree(BoundingBox boundary) {
this.boundary = boundary;
this.points = new ArrayList<>();
this.isDivided = false;
}
public boolean insert(Point3D position, T data) {
if (!boundary.contains(position)) {
return false;
}
if (points.size() < MAX_CAPACITY && !isDivided) {
points.add(new Entry(position, data));
return true;
}
if (!isDivided) {
subdivide();
}
for (Octree<T> child : children) {
if (child.insert(position, data)) {
return true;
}
}
return false;
}
public boolean remove(Point3D point, T player) {
if (!boundary.contains(point)) {
return false;
}
if (points.size() < MAX_CAPACITY && !isDivided) {
points.removeIf(entry -> entry.position.equals(point) && entry.data.equals(player));
return true;
}
if (!isDivided) {
return false;
}
for (Octree<T> child : children) {
if (child.remove(point, player)) {
return true;
}
}
return false;
}
public List<T> queryRange(BoundingBox range) {
List<T> found = new ArrayList<>();
if (!boundary.intersects(range)) {
return found;
}
for (Entry entry : points) {
if (range.contains(entry.position)) {
found.add(entry.data);
}
}
if (isDivided) {
for (Octree<T> child : children) {
found.addAll(child.queryRange(range));
}
}
return found;
}
private void subdivide() {
double x = boundary.center.x;
double y = boundary.center.y;
double z = boundary.center.z;
double newHalfSize = boundary.halfSize / 2.0;
children = new Octree[8];
children[0] = new Octree<>(new BoundingBox(new Point3D(x - newHalfSize, y - newHalfSize, z - newHalfSize), newHalfSize));
children[1] = new Octree<>(new BoundingBox(new Point3D(x + newHalfSize, y - newHalfSize, z - newHalfSize), newHalfSize));
children[2] = new Octree<>(new BoundingBox(new Point3D(x - newHalfSize, y + newHalfSize, z - newHalfSize), newHalfSize));
children[3] = new Octree<>(new BoundingBox(new Point3D(x + newHalfSize, y + newHalfSize, z - newHalfSize), newHalfSize));
children[4] = new Octree<>(new BoundingBox(new Point3D(x - newHalfSize, y - newHalfSize, z + newHalfSize), newHalfSize));
children[5] = new Octree<>(new BoundingBox(new Point3D(x + newHalfSize, y - newHalfSize, z + newHalfSize), newHalfSize));
children[6] = new Octree<>(new BoundingBox(new Point3D(x - newHalfSize, y + newHalfSize, z + newHalfSize), newHalfSize));
children[7] = new Octree<>(new BoundingBox(new Point3D(x + newHalfSize, y + newHalfSize, z + newHalfSize), newHalfSize));
isDivided = true;
}
public static class Point3D {
double x, y, z;
public Point3D(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
}
public static class BoundingBox {
Point3D center;
double halfSize;
public BoundingBox(Point3D center, double halfSize) {
this.center = center;
this.halfSize = halfSize;
}
public boolean contains(Point3D point) {
return Math.abs(point.x - center.x) <= halfSize &&
Math.abs(point.y - center.y) <= halfSize &&
Math.abs(point.z - center.z) <= halfSize;
}
public boolean intersects(BoundingBox other) {
return Math.abs(center.x - other.center.x) <= halfSize + other.halfSize &&
Math.abs(center.y - other.center.y) <= halfSize + other.halfSize &&
Math.abs(center.z - other.center.z) <= halfSize + other.halfSize;
}
}
private class Entry {
Point3D position;
T data;
Entry(Point3D position, T data) {
this.position = position;
this.data = data;
}
}
}

View File

@@ -0,0 +1,105 @@
package com.hibiscusmc.hmccosmetics.util;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.jetbrains.annotations.NotNull;
import java.util.*;
public class PlayerSearchManager implements Listener {
private final Map<UUID, Octree<Player>> worldOctrees = new HashMap<>();
private final Map<UUID, Octree.Point3D> playerPositions = new HashMap<>();
//private static final double WORLD_HALF_SIZE = 30_000_000; // Previous built in value
private final double WORLD_HALF_SIZE;
public PlayerSearchManager(@NotNull HMCCosmeticsPlugin plugin) {
WORLD_HALF_SIZE = (double) plugin.getServer().getMaxWorldSize() / 2;
}
private Octree<Player> getOrCreateOctree(World world) {
return worldOctrees.computeIfAbsent(world.getUID(), $ -> {
Octree.BoundingBox worldBoundary = new Octree.BoundingBox(
new Octree.Point3D(0, 160, 0), WORLD_HALF_SIZE
);
return new Octree<>(worldBoundary);
});
}
private Octree.Point3D toPoint3D(Location location) {
return new Octree.Point3D(location.getX(), location.getY(), location.getZ());
}
public boolean addPlayer(Player player) {
Octree<Player> octree = getOrCreateOctree(player.getWorld());
Octree.Point3D point = toPoint3D(player.getLocation());
if(octree.insert(point, player)) {
playerPositions.put(player.getUniqueId(), point);
return true;
}
return false;
}
public boolean removePlayer(Player player) {
Octree<Player> octree = worldOctrees.get(player.getWorld().getUID());
if (octree == null) return false;
Octree.Point3D point = playerPositions.remove(player.getUniqueId());
if (point != null) return octree.remove(point, player);
return false;
}
public void updatePlayerPosition(Player player) {
removePlayer(player);
addPlayer(player);
}
public List<Player> getPlayersInRange(Location location, double range) {
Octree<Player> octree = worldOctrees.get(location.getWorld().getUID());
if (octree == null) return Collections.emptyList();
Octree.Point3D point = toPoint3D(location);
Octree.BoundingBox searchArea = new Octree.BoundingBox(point, range);
return octree.queryRange(searchArea)
.stream()
.filter(Objects::nonNull)
.toList();
}
public void clear() {
worldOctrees.clear();
playerPositions.clear();
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent event) {
if (event.hasChangedBlock()) updatePlayerPosition(event.getPlayer());
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerTeleport(PlayerTeleportEvent event) {
updatePlayerPosition(event.getPlayer());
}
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerQuit(PlayerQuitEvent event) {
removePlayer(event.getPlayer());
}
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerJoin(PlayerJoinEvent event) {
addPlayer(event.getPlayer());
}
}

View File

@@ -1,6 +1,5 @@
package com.hibiscusmc.hmccosmetics.util;
import me.lojosho.hibiscuscommons.util.StringUtils;
import me.lojosho.shaded.configurate.ConfigurationNode;
import java.util.ArrayList;
@@ -32,7 +31,7 @@ public class TranslationUtil {
public static String getTranslation(String key, String message) {
List<TranslationPair> pairs = keys.get(key);
for (TranslationPair pair : pairs) {
if (pair.key().equals(message)) return StringUtils.parseStringToString(pair.value());
if (pair.key().equals(message)) return pair.value();
}
return message;

View File

@@ -1,33 +1,33 @@
package com.hibiscusmc.hmccosmetics.util.packets;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.*;
import com.google.common.collect.Lists;
import com.hibiscusmc.hmccosmetics.api.HMCCosmeticsAPI;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
import com.hibiscusmc.hmccosmetics.util.HMCCPlayerUtils;
import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerNamedEntitySpawn;
import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerPlayerInfo;
import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerRelEntityMove;
import me.lojosho.hibiscuscommons.nms.MinecraftVersion;
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Display;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ItemDisplay;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class HMCCPacketManager extends PacketManager {
// The cloud effect map, in case it gets lost: Map<Integer, Number> dataValues = Map.of(0, (byte) 0x20, 8, 0f);
private static final List<CosmeticSlot> EQUIPMENT_SLOTS = List.of(CosmeticSlot.HELMET, CosmeticSlot.CHESTPLATE, CosmeticSlot.LEGGINGS, CosmeticSlot.BOOTS, CosmeticSlot.MAINHAND, CosmeticSlot.OFFHAND);
public static void sendEntitySpawnPacket(
@@ -46,16 +46,7 @@ public class HMCCPacketManager extends PacketManager {
final UUID uuid,
final @NotNull List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
packet.getModifier().writeDefaults();
packet.getUUIDs().write(0, uuid);
packet.getIntegers().write(0, entityId);
packet.getEntityTypeModifier().write(0, entityType);
packet.getDoubles().
write(0, location.getX()).
write(1, location.getY()).
write(2, location.getZ());
for (Player p : sendTo) sendPacket(p, packet);
NMSHandlers.getHandler().getPacketHandler().sendSpawnEntityPacket(entityId, uuid, entityType, location, sendTo);
}
public static void equipmentSlotUpdate(
@@ -97,53 +88,55 @@ public class HMCCPacketManager extends PacketManager {
equipmentSlotUpdate(entityId, HMCCInventoryUtils.getEquipmentSlot(cosmeticSlot), user.getUserCosmeticItem(cosmeticSlot), sendTo);
}
public static void sendArmorstandMetadata(
int entityId,
List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
packet.getModifier().writeDefaults();
packet.getIntegers().write(0, entityId);
final List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();
// 0x21 = Invisible + Fire (Aka, burns to make it not take the light of the block its in, avoiding turning it black)
byte mask = 0x20;
if (Settings.isBackpackPreventDarkness()) mask = 0x21;
wrappedDataValueList.add(new WrappedDataValue(0, WrappedDataWatcher.Registry.get(Byte.class), mask));
wrappedDataValueList.add(new WrappedDataValue(15, WrappedDataWatcher.Registry.get(Byte.class), (byte) 0x10));
packet.getDataValueCollectionModifier().write(0, wrappedDataValueList);
for (Player p : sendTo) sendPacket(p, packet);
}
public static void sendInvisibilityPacket(
int entityId,
List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
packet.getModifier().writeDefaults();
packet.getIntegers().write(0, entityId);
final List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();
wrappedDataValueList.add(new WrappedDataValue(0, WrappedDataWatcher.Registry.get(Byte.class), (byte) 0x20));
packet.getDataValueCollectionModifier().write(0, wrappedDataValueList);
for (Player p : sendTo) sendPacket(p, packet);
NMSHandlers.getHandler().getPacketHandler().sendSharedEntityData(entityId, Map.of(0, (byte) 0x20), sendTo);
}
public static void sendCloudEffect(
public static void spawnCloudAndHandleEffect(
int entityId,
Location location,
UUID uuid,
List<Player> sendTo
) {
NMSHandlers.getHandler().getPacketHandler().sendInvisibleParticleCloud(entityId, location, uuid, sendTo);
}
/**
* This handles both spawn + metadata in a bundle packet
* @param entityId
* @param location
* @param uuid
* @param sendTo
*/
public static void spawnInvisibleArmorstand(
int entityId,
Location location,
UUID uuid,
List<Player> sendTo
) {
byte mask = getMask();
NMSHandlers.getHandler().getPacketHandler().sendInvisibleArmorstand(entityId, location, uuid, mask, sendTo);
}
/**
* This is just a normal meta data packet (non-bundled)
* @param entityId
* @param sendTo
*/
public static void sendArmorstandMetadata(
int entityId,
List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
packet.getModifier().writeDefaults();
packet.getIntegers().write(0, entityId);
byte mask = getMask();
Map<Integer, Number> dataValues = Map.of(0, mask, 15, (byte) 0x10);
NMSHandlers.getHandler().getPacketHandler().sendSharedEntityData(entityId, dataValues, sendTo);
}
final List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();
wrappedDataValueList.add(new WrappedDataValue(0, WrappedDataWatcher.Registry.get(Byte.class), (byte) 0x20));
wrappedDataValueList.add(new WrappedDataValue(8, WrappedDataWatcher.Registry.get(Float.class), 0f));
//wrappedDataValueList.add(new WrappedDataValue(11, WrappedDataWatcher.Registry.get(Integer.class), 21));
packet.getDataValueCollectionModifier().write(0, wrappedDataValueList);
for (Player p : sendTo) sendPacket(p, packet);
private static byte getMask() {
return (byte) (Settings.isBackpackPreventDarkness() ? 0x21 : 0x20);
}
public static void sendRotationPacket(
@@ -160,17 +153,7 @@ public class HMCCPacketManager extends PacketManager {
boolean onGround,
@NotNull List<Player> sendTo
) {
float ROTATION_FACTOR = 256.0F / 360.0F;
float yaw = location.getYaw() * ROTATION_FACTOR;
float pitch = location.getPitch() * ROTATION_FACTOR;
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_LOOK);
packet.getIntegers().write(0, entityId);
packet.getBytes().write(0, (byte) yaw);
packet.getBytes().write(1, (byte) pitch);
//Bukkit.getLogger().info("DEBUG: Yaw: " + (location.getYaw() * ROTATION_FACTOR) + " | Original Yaw: " + location.getYaw());
packet.getBooleans().write(0, onGround);
for (Player p : sendTo) sendPacket(p, packet);
NMSHandlers.getHandler().getPacketHandler().sendRotationPacket(entityId, location.getYaw(), location.getPitch(), onGround, sendTo);
}
public static void sendRotationPacket(
@@ -179,19 +162,9 @@ public class HMCCPacketManager extends PacketManager {
boolean onGround,
@NotNull List<Player> sendTo
) {
float ROTATION_FACTOR = 256.0F / 360.0F;
float yaw2 = yaw * ROTATION_FACTOR;
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_LOOK);
packet.getIntegers().write(0, entityId);
packet.getBytes().write(0, (byte) yaw2);
packet.getBytes().write(1, (byte) 0);
//Bukkit.getLogger().info("DEBUG: Yaw: " + (location.getYaw() * ROTATION_FACTOR) + " | Original Yaw: " + location.getYaw());
packet.getBooleans().write(0, onGround);
for (Player p : sendTo) sendPacket(p, packet);
NMSHandlers.getHandler().getPacketHandler().sendRotationPacket(entityId, yaw, 0, onGround, sendTo);
}
/**
* Mostly to deal with backpacks, this deals with entities riding other entities.
* @param mountId The entity that is the "mount", ex. a player
@@ -216,12 +189,7 @@ public class HMCCPacketManager extends PacketManager {
final int[] passengerIds,
final @NotNull List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.MOUNT);
packet.getIntegers().write(0, mountId);
packet.getIntegerArrays().write(0, passengerIds);
for (final Player p : sendTo) {
sendPacket(p, packet);
}
NMSHandlers.getHandler().getPacketHandler().sendMountPacket(mountId, passengerIds, sendTo);
}
/**
@@ -238,32 +206,6 @@ public class HMCCPacketManager extends PacketManager {
sendRidingPacket(mountId, new int[] {passengerId}, sendTo);
}
/**
*
* @param location Location of the fake player.
* @param uuid UUID of the fake player. Should be random.
* @param entityId The entityID that the entity will take on.
* @param sendTo Who should it send the packet to?
*/
public static void sendFakePlayerSpawnPacket(
final @NotNull Location location,
final UUID uuid,
final int entityId,
final @NotNull List<Player> sendTo
) {
if (HMCCosmeticsAPI.getNMSVersion().contains("v1_19_R3") || HMCCosmeticsAPI.getNMSVersion().contains("v1_20_R1")) {
WrapperPlayServerNamedEntitySpawn wrapper = new WrapperPlayServerNamedEntitySpawn();
wrapper.setEntityID(entityId);
wrapper.setPlayerUUID(uuid);
wrapper.setPosition(location.toVector());
wrapper.setPitch(location.getPitch());
wrapper.setYaw(location.getYaw());
for (final Player p : sendTo) sendPacket(p, wrapper.getHandle());
return;
}
sendEntitySpawnPacket(location, entityId, EntityType.PLAYER, uuid);
}
/**
* Creates a fake player entity.
* @param skinnedPlayer The original player it bases itself off of.
@@ -274,28 +216,10 @@ public class HMCCPacketManager extends PacketManager {
final Player skinnedPlayer,
final int entityId,
final UUID uuid,
final String NPCName,
final String npcName,
final List<Player> sendTo
) {
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo();
info.setAction(EnumWrappers.PlayerInfoAction.ADD_PLAYER);
String name = NPCName;
while (name.length() > 16) {
name = name.substring(16);
}
WrappedGameProfile wrappedGameProfile = new WrappedGameProfile(uuid, name);
WrappedSignedProperty skinData = HMCCPlayerUtils.getSkin(skinnedPlayer);
if (skinData != null) wrappedGameProfile.getProperties().put("textures", skinData);
info.getHandle().getPlayerInfoDataLists().write(1, Collections.singletonList(new PlayerInfoData(
wrappedGameProfile,
0,
EnumWrappers.NativeGameMode.CREATIVE,
WrappedChatComponent.fromText(name)
)));
for (final Player p : sendTo) sendPacket(p, info.getHandle());
NMSHandlers.getHandler().getPacketHandler().sendFakePlayerInfoPacket(skinnedPlayer, entityId, uuid, npcName, sendTo);
}
/**
@@ -307,27 +231,10 @@ public class HMCCPacketManager extends PacketManager {
final int playerId,
final @NotNull List<Player> sendTo
) {
/*
0x01 = Is on fire
0x02 = Is courching
0x04 = Unusued
0x08 = Sprinting
0x10 = Is swimming
0x20 = Invisibile
0x40 = Is Glowing
0x80 = Is flying with an elytra
https://wiki.vg/Entity_metadata#Entity
*/
// https://minecraft.wiki/w/Java_Edition_protocol/Entity_metadata#Avatar
final byte mask = 0x01 | 0x02 | 0x04 | 0x08 | 0x010 | 0x020 | 0x40;
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
packet.getModifier().writeDefaults();
packet.getIntegers().write(0, playerId);
final List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();
wrappedDataValueList.add(new WrappedDataValue(17, WrappedDataWatcher.Registry.get(Byte.class), mask));
packet.getDataValueCollectionModifier().write(0, wrappedDataValueList);
for (final Player p : sendTo) sendPacket(p, packet);
if (NMSHandlers.getVersion().isLowerOrEqual(MinecraftVersion.v1_21_8)) NMSHandlers.getHandler().getPacketHandler().sendSharedEntityData(playerId, Map.of(17, mask), sendTo);
else NMSHandlers.getHandler().getPacketHandler().sendSharedEntityData(playerId, Map.of(16, mask), sendTo);
}
/**
@@ -342,9 +249,7 @@ public class HMCCPacketManager extends PacketManager {
final UUID uuid,
final List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.PLAYER_INFO_REMOVE);
packet.getUUIDLists().write(0, List.of(uuid));
for (final Player p : sendTo) sendPacket(p, packet);
NMSHandlers.getHandler().getPacketHandler().sendPlayerInfoRemovePacket(uuid, sendTo);
}
public static void sendLeashPacket(
@@ -370,16 +275,51 @@ public class HMCCPacketManager extends PacketManager {
final boolean onGround,
@NotNull List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.REL_ENTITY_MOVE);
WrapperPlayServerRelEntityMove wrapper = new WrapperPlayServerRelEntityMove(packet);
wrapper.setEntityID(entityId);
wrapper.setDx(to.getX() - from.getX());
wrapper.setDy(to.getY() - from.getY());
wrapper.setDz(to.getZ() - from.getZ());
wrapper.setOnGround(onGround);
for (final Player p : sendTo) {
sendPacket(p, wrapper.getHandle());
NMSHandlers.getHandler().getPacketHandler().sendMovePacket(entityId, from, to, onGround, sendTo);
}
public static void sendEntityScalePacket(
int entityId,
double scale,
List<Player> sendTo
) {
NMSHandlers.getHandler().getPacketHandler().sendEntityScalePacket(entityId, scale, sendTo);
}
// For future transition to display entities
public static void sendDisplayEntityMetadataPacket(
int entityid,
ItemStack backpackItem,
List<Player> sendTo) {
// TODO: Make the default values adjustable
Vector3f translation = new Vector3f(0, 3, 0);
Vector3f scale = new Vector3f(1, 1, 1);
Quaternionf rotationLeft = new Quaternionf();
Quaternionf rotationRight = new Quaternionf();
Display.Billboard billboard = Display.Billboard.FIXED;
int blockLight = 15;
int skylight = 15;
int viewRange = Settings.getViewDistance();
int width = 0;
int height = 0;
ItemDisplay.ItemDisplayTransform transform = ItemDisplay.ItemDisplayTransform.HEAD;
NMSHandlers.getHandler().getPacketHandler().sendItemDisplayMetadata(
entityid,
translation,
scale,
rotationLeft,
rotationRight,
billboard,
blockLight,
skylight,
viewRange,
width,
height,
transform,
backpackItem,
sendTo
);
}
/**
@@ -389,17 +329,6 @@ public class HMCCPacketManager extends PacketManager {
*/
@NotNull
public static List<Player> getViewers(@NotNull Location location) {
ArrayList<Player> viewers = new ArrayList<>();
if (Settings.getViewDistance() <= 0) {
viewers.addAll(location.getWorld().getPlayers());
} else {
viewers.addAll(PacketManager.getViewers(location, Settings.getViewDistance()));
}
return viewers;
}
public static void sendPacket(Player player, PacketContainer packet) {
if (player == null) return;
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, null,false);
return PacketManager.getViewers(location, Settings.getViewDistance());
}
}

View File

@@ -1,92 +0,0 @@
package com.hibiscusmc.hmccosmetics.util.packets.wrappers;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.google.common.base.Objects;
import org.bukkit.entity.Player;
// Courtesy of Packet Wrapper
public class AbstractPacket {
// The packet we will be modifying
protected PacketContainer handle;
/**
* Constructs a new strongly typed wrapper for the given packet.
*
* @param handle - handle to the raw packet data.
* @param type - the packet type.
*/
protected AbstractPacket(PacketContainer handle, PacketType type) {
// Make sure we're given a valid packet
if (handle == null)
throw new IllegalArgumentException("Packet handle cannot be NULL.");
if (!Objects.equal(handle.getType(), type))
throw new IllegalArgumentException(handle.getHandle()
+ " is not a packet of type " + type);
this.handle = handle;
}
/**
* Retrieve a handle to the raw packet data.
*
* @return Raw packet data.
*/
public PacketContainer getHandle() {
return handle;
}
/**
* Send the current packet to the given receiver.
*
* @param receiver - the receiver.
* @throws RuntimeException If the packet cannot be sent.
*/
public void sendPacket(Player receiver) {
ProtocolLibrary.getProtocolManager().sendServerPacket(receiver,
getHandle());
}
/**
* Send the current packet to all online players.
*/
public void broadcastPacket() {
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getHandle());
}
/**
* Simulate receiving the current packet from the given sender.
*
* @param sender - the sender.
* @throws RuntimeException If the packet cannot be received.
* @deprecated Misspelled. recieve to receive
* @see #receivePacket(Player)
*/
@Deprecated
public void recievePacket(Player sender) {
try {
ProtocolLibrary.getProtocolManager().receiveClientPacket(sender,
getHandle());
} catch (Exception e) {
throw new RuntimeException("Cannot recieve packet.", e);
}
}
/**
* Simulate receiving the current packet from the given sender.
*
* @param sender - the sender.
* @throws RuntimeException if the packet cannot be received.
*/
public void receivePacket(Player sender) {
try {
ProtocolLibrary.getProtocolManager().receiveClientPacket(sender,
getHandle());
} catch (Exception e) {
throw new RuntimeException("Cannot receive packet.", e);
}
}
}

View File

@@ -1,165 +0,0 @@
package com.hibiscusmc.hmccosmetics.util.packets.wrappers;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public class WrapperPlayServerNamedEntitySpawn extends AbstractPacket {
public static final PacketType TYPE =
PacketType.Play.Server.NAMED_ENTITY_SPAWN;
public WrapperPlayServerNamedEntitySpawn() {
super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults();
}
public WrapperPlayServerNamedEntitySpawn(PacketContainer packet) {
super(packet, TYPE);
}
/**
* Retrieve Entity ID.
* <p>
* Notes: entity's ID
*
* @return The current Entity ID
*/
public int getEntityID() {
return handle.getIntegers().read(0);
}
/**
* Set Entity ID.
*
* @param value - new value.
*/
public void setEntityID(int value) {
handle.getIntegers().write(0, value);
}
/**
* Retrieve the entity of the painting that will be spawned.
*
* @param world - the current world of the entity.
* @return The spawned entity.
*/
public Entity getEntity(World world) {
return handle.getEntityModifier(world).read(0);
}
/**
* Retrieve the entity of the painting that will be spawned.
*
* @param event - the packet event.
* @return The spawned entity.
*/
public Entity getEntity(@NotNull PacketEvent event) {
return getEntity(event.getPlayer().getWorld());
}
/**
* Retrieve Player UUID.
* <p>
* Notes: player's UUID
*
* @return The current Player UUID
*/
public UUID getPlayerUUID() {
return handle.getUUIDs().read(0);
}
/**
* Set Player UUID.
*
* @param value - new value.
*/
public void setPlayerUUID(UUID value) {
handle.getUUIDs().write(0, value);
}
/**
* Retrieve the position of the spawned entity as a vector.
*
* @return The position as a vector.
*/
public Vector getPosition() {
return new Vector(getX(), getY(), getZ());
}
/**
* Set the position of the spawned entity using a vector.
*
* @param position - the new position.
*/
public void setPosition(@NotNull Vector position) {
setX(position.getX());
setY(position.getY());
setZ(position.getZ());
}
public double getX() {
return handle.getDoubles().read(0);
}
public void setX(double value) {
handle.getDoubles().write(0, value);
}
public double getY() {
return handle.getDoubles().read(1);
}
public void setY(double value) {
handle.getDoubles().write(1, value);
}
public double getZ() {
return handle.getDoubles().read(2);
}
public void setZ(double value) {
handle.getDoubles().write(2, value);
}
/**
* Retrieve the yaw of the spawned entity.
*
* @return The current Yaw
*/
public float getYaw() {
return (handle.getBytes().read(0) * 360.F) / 256.0F;
}
/**
* Set the yaw of the spawned entity.
*
* @param value - new yaw.
*/
public void setYaw(float value) {
handle.getBytes().write(0, (byte) (value * 256.0F / 360.0F));
}
/**
* Retrieve the pitch of the spawned entity.
*
* @return The current pitch
*/
public float getPitch() {
return (handle.getBytes().read(1) * 360.F) / 256.0F;
}
/**
* Set the pitch of the spawned entity.
*
* @param value - new pitch.
*/
public void setPitch(float value) {
handle.getBytes().write(1, (byte) (value * 256.0F / 360.0F));
}
}

View File

@@ -1,44 +0,0 @@
package com.hibiscusmc.hmccosmetics.util.packets.wrappers;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
import com.comphenix.protocol.wrappers.PlayerInfoData;
import com.hibiscusmc.hmccosmetics.api.HMCCosmeticsAPI;
import java.util.List;
import java.util.Set;
public class WrapperPlayServerPlayerInfo extends AbstractPacket {
public static final PacketType TYPE = PacketType.Play.Server.PLAYER_INFO;
public WrapperPlayServerPlayerInfo() {
super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults();
}
public WrapperPlayServerPlayerInfo(PacketContainer packet) {
super(packet, TYPE);
}
public PlayerInfoAction getAction() {
return handle.getPlayerInfoAction().read(0);
}
public void setAction(PlayerInfoAction value) {
if (HMCCosmeticsAPI.getNMSVersion().contains("v1_17_R1") || HMCCosmeticsAPI.getNMSVersion().contains("v1_18_R2") || HMCCosmeticsAPI.getNMSVersion().contains("v1_19_R1")) {
handle.getPlayerInfoAction().write(0, value);
return;
}
// New way of handling it 1.19.3+
handle.getPlayerInfoActions().write(0, Set.of(value));
}
public List<PlayerInfoData> getData() {
return handle.getPlayerInfoDataLists().read(0);
}
public void setData(List<PlayerInfoData> value) {
handle.getPlayerInfoDataLists().write(0, value);
}
}

View File

@@ -1,170 +0,0 @@
package com.hibiscusmc.hmccosmetics.util.packets.wrappers;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
public class WrapperPlayServerRelEntityMove extends AbstractPacket {
public static final PacketType TYPE =
PacketType.Play.Server.REL_ENTITY_MOVE;
public WrapperPlayServerRelEntityMove() {
super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults();
}
public WrapperPlayServerRelEntityMove(PacketContainer packet) {
super(packet, TYPE);
}
/**
* Retrieve Entity ID.
* <p>
* Notes: entity's ID
*
* @return The current Entity ID
*/
public int getEntityID() {
return handle.getIntegers().read(0);
}
/**
* Set Entity ID.
*
* @param value - new value.
*/
public void setEntityID(int value) {
handle.getIntegers().write(0, value);
}
/**
* Retrieve the entity of the painting that will be spawned.
*
* @param world - the current world of the entity.
* @return The spawned entity.
*/
public Entity getEntity(World world) {
return handle.getEntityModifier(world).read(0);
}
/**
* Retrieve the entity of the painting that will be spawned.
*
* @param event - the packet event.
* @return The spawned entity.
*/
public Entity getEntity(@NotNull PacketEvent event) {
return getEntity(event.getPlayer().getWorld());
}
/**
* Retrieve DX.
*
* @return The current DX
*/
public double getDx() {
return handle.getShorts().read(0) / 4096D;
}
/**
* Set DX.
*
* @param value - new value.
*/
public void setDx(double value) {
handle.getShorts().write(0, (short) (value * 4096));
}
/**
* Retrieve DY.
*
* @return The current DY
*/
public double getDy() {
return handle.getShorts().read(1) / 4096D;
}
/**
* Set DY.
*
* @param value - new value.
*/
public void setDy(double value) {
handle.getShorts().write(1, (short) (value * 4096));
}
/**
* Retrieve DZ.
*
* @return The current DZ
*/
public double getDz() {
return handle.getShorts().read(2) / 4096D;
}
/**
* Set DZ.
*
* @param value - new value.
*/
public void setDz(double value) {
handle.getShorts().write(2, (short) (value * 4096));
}
/**
* Retrieve the yaw of the current entity.
*
* @return The current Yaw
*/
public float getYaw() {
return (handle.getBytes().read(0) * 360.F) / 256.0F;
}
/**
* Set the yaw of the current entity.
*
* @param value - new yaw.
*/
public void setYaw(float value) {
handle.getBytes().write(0, (byte) (value * 256.0F / 360.0F));
}
/**
* Retrieve the pitch of the current entity.
*
* @return The current pitch
*/
public float getPitch() {
return (handle.getBytes().read(1) * 360.F) / 256.0F;
}
/**
* Set the pitch of the current entity.
*
* @param value - new pitch.
*/
public void setPitch(float value) {
handle.getBytes().write(1, (byte) (value * 256.0F / 360.0F));
}
/**
* Retrieve On Ground.
*
* @return The current On Ground
*/
public boolean getOnGround() {
return handle.getBooleans().read(0);
}
/**
* Set On Ground.
*
* @param value - new value.
*/
public void setOnGround(boolean value) {
handle.getBooleans().write(0, value);
}
}

View File

@@ -3,32 +3,42 @@
#
config-version: 1
default-menu: defaultmenu
default-menu: defaultmenu_hats
debug-mode: false
database-settings:
type: sqlite # SQLite (Default), MYSQL, NONE
# SQLite (Default), MYSQL, NONE
type: sqlite
mysql:
database: database
password: cherryBomb
database: "database"
password: "cherryBomb"
port: 3306
host: localhost
user: username
host: "localhost"
user: "username"
delay:
enabled: false # This is for if other plugins need to handle certain aspects of a player first.
delay: 20 # In ticks
# This is for if other plugins need to handle certain aspects of a player first.
enabled: false
# Delay in ticks from when a player joins
delay: 20
cosmetic-settings:
tick-period: 20 # In ticks, determines how many times a player cosmetics should be updated. -1 to disable.
# In ticks, determines how many times a player cosmetics should be updated. -1 to disable.
# Ticking periods is something that ensures new players near a player get the packets to actually apply to the user.
tick-period: 20
unapply-on-death: false # If when a player dies, their cosmetics should be unapplied. If this is true, use hmccosmetics.unapplydeath.bypass to bypass
force-permission-join: true # Checks a player permission if they can have a cosmetic when they join the server.
force-show-join: false # If the plugin should force show a player's cosmetics when they join the server.
# If when a player dies, their cosmetics should be unapplied. If this is true, use hmccosmetics.unapplydeath.bypass to bypass
unapply-on-death: false
# Checks a player permission if they can have a cosmetic when they join the server.
force-permission-join: true
# If the plugin should attempt to force show a player's cosmetics when they join the server by removing all hidden flags.
force-show-join: false
# This determines what to process what areas to process placeholders when displaying the item to the user.
# This can be heavy on servers with a lot of players, so if experiencing lag issues relating to setting display/lores of items, disable this.
item-processing:
display-name: true
lore: true
display-name: false
lore: false
# This prevents the offhand from being swapped with the mainhand. Only affects if a user has a cosmetic in their offhand
offhand-prevent-swapping: false
# This is a list of worlds that cosmetics are hidden in. When a player enters one of these worlds, their cosmetics will be hidden.
disabled-worlds:
@@ -40,25 +50,10 @@ cosmetic-settings:
gamemodes:
- "SPECTATOR"
# This disables the entire internal emote system within the plugin. This option requires a restart.
emote-enable: true
emote-distance: -3 # This shows how far away the camera should be while a player is doing an emote. Negative is behind player.
emote-block-check: true # If the server should check if the block is open where the camera is placed (prevents players viewing through blocks)
emote-air-check: true # Check if there is air under a player, if there is, don't play emote
emote-damage-leave: true # If the player should leave the emote when they take damage
emote-invincible: false # If the player should not take damage while doing an emote
# If a player should be put into camera mode when looking at an emote. Highly recommend keeping it as true.
emote-camera: true
# If a player should be able to move in an emote. This option really only affects if "emote-camera" is false
emote-move: false
# This make it so it always sends the riding packets for the backpack. This sends more packets but is more reliable for servers which modify player passengers.
backpack-force-riding-packet: false
backpack-force-riding-packet: true
# This prevents the backpack from being dark when the player is below a block at the expense of making the backpack bright
backpack-prevent-darkness: true
# This helps reduce the amount of packets sent for packet entities, but reduces accuracy of the entity. This is in milliseconds. -1 to disable.
# This is useful for servers with a lot of backpacks, as they are passengers, which means the client will update their position automatically within an area where the entity is located.
entity-cooldown-teleport-packet: 500
# This forces the offhand to always show the cosmetic. False means it will only show when the slot is empty.
slot-options:
helmet:
@@ -96,6 +91,7 @@ cosmetic-settings:
x: 0.5
y: 3
z: 0.5
menu-settings:
click-cooldown:
enabled: true
@@ -107,23 +103,23 @@ menu-settings:
# The shading is done through the title and by shifting textures around. This is done by offsets.
# Only Nexo is support by default. Vanilla can't properly handle it without a lot of unicodes and ItemsAdder adds weird offsets and decolors it. (This is why it is disabled by default)
enabled: false # Default of menus having shading. This can be toggled individually in menus with "shading: true/false"
first-row-shift: "<shift:-169>" # Nexo: "<shift:-169>"
sequent-row-shift: " <shift:-169>" # Nexo: " <shift:-169>" (Space is important here!)
first-row-shift: "<shift:-153>" # Nexo: "<shift:-153>"
sequent-row-shift: " <shift:-153>" # Nexo: " <shift:-153>" (Space is important here!)
individual-column-shift: "<shift:-3>" # Nexo: "<shift:-3>"
background: "<glyph:shade_row_<row>:colorable> " # Nexo: "<glyph:shade_row_<row>:colorable>
clear-background: "<glyph:clear_row_<row>:colorable> " # Nexo: "<glyph:clear_row_<row>:colorable> "
background: "<glyph:hmcc_shade_row_<row>:colorable> " # Nexo: "<glyph:shade_row_<row>:colorable>
clear-background: "<glyph:hmcc_clear_row_<row>:colorable> " # Nexo: "<glyph:clear_row_<row>:colorable> "
#These use MiniMessage for color! https://docs.advntr.dev/minimessage/format.html#color
equipped-cosmetic-color: "<yellow>"
equipable-cosmetic-color: "<green>"
locked-cosmetic-color: "<red>"
cosmetic-type:
# This allows you to specify if it should require a special click type for the interaction to work.
equip-click: "ANY" # ANY or ClickType, https://jd.papermc.io/paper/1.20/org/bukkit/event/inventory/ClickType.html
unequip-click: "ANY" # ANY or ClickType, https://jd.papermc.io/paper/1.20/org/bukkit/event/inventory/ClickType.html
equip-click: "ANY" # ANY or ClickType, https://jd.papermc.io/paper/org/bukkit/event/inventory/ClickType.html
unequip-click: "ANY" # ANY or ClickType, https://jd.papermc.io/paper/org/bukkit/event/inventory/ClickType.html
dye-menu:
# If you use ItemsAdder, set this to "<white>:img_offset_-8::img_dye_menu:"
# If you use Oraxen, set this to "<white><s:-8><g:dye_menu>"
# If you use Nexo, set this to "<white><shift:-8><glyph:dye_menu>"
# If you use ItemsAdder, set this to "<white>:img_offset_-8::img_hmcc_dye_menu:"
# If you use Oraxen, set this to "<white><s:-8><g:hmcc_dye_menu>"
# If you use Nexo, set this to "<white><shift:-8><glyph:hmcc_dye_menu>"
title: "<white>"
input-slot: 10
output-slot: 16
@@ -133,7 +129,8 @@ hook-settings:
# could cause console spam as HMCCosmetics has to reload itself as well.
reload-on-change: false
nexo:
# This causes the plugin to reload itself after any Nexo change. This keeps the plugin fully up to date with Nexo
# This causes the plugin to reload itself after any Nexo change. This keeps the plugin fully up to date with Nexo, but
# could cause console spam as HMCCosmetics has to reload itself as well.
reload-on-change: true
worldguard:
# Checks worldguard regions for HMCC flags. If set to false, flags will not work properly.
@@ -181,8 +178,10 @@ wardrobe:
title-fade-out: 1000 # milliseconds
wardrobes:
default:
distance: -1 # Distance in blocks that a player can interact with the wardrobe. -1 to ignore.
permission: "hmccosmetics.wardrobe.default" # Permission required to use the wardrobe.
# Distance in blocks that a player can interact with the wardrobe. -1 to ignore.
distance: -1
# Permission required to use the wardrobe.
permission: "hmccosmetics.wardrobe.default"
default-menu: defaultmenu
npc-location:
world: "world"

View File

@@ -108,15 +108,6 @@ kite:
model-data: 7
name: "<blue>Kite"
amount: 1
handstand:
slot: EMOTE
animation: handstand
meditate:
slot: EMOTE
animation: meditate
thinking:
slot: EMOTE
animation: thinking
explorer_backpack:
slot: BACKPACK
permission: "hmccosmetics.explorer_backpack"

View File

@@ -1,205 +0,0 @@
title: "<white>"
rows: 6
refresh-rate: 20 # Set to -1 or remove to disable auto-updating, leading to it only using event-based updates.
items:
beanie:
slots:
- 0
item:
material: hmccosmetics:beanie
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_beanie%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_beanie%"
type: cosmetic
cosmetic: beanie
backpack:
slots:
- 1
item:
material: hmccosmetics:backpack
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_backpack%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_backpack%"
type: cosmetic
cosmetic: backpack
future_wings:
slots:
- 2
item:
material: hmccosmetics:future_wings
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_future_wings%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_future_wings%"
type: cosmetic
cosmetic: future_wings
lantern_cosmetic:
slots:
- 3
item:
material: hmccosmetics:lantern_cosmetic
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_lantern_cosmetic%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_lantern_cosmetic%"
type: cosmetic
cosmetic: lantern_cosmetic
baseball_hat:
slots:
- 4
item:
material: hmccosmetics:baseball_hat
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_baseball_hat%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_baseball_hat%"
type: cosmetic
cosmetic: baseball_hat
frog_hat:
slots:
- 5
item:
material: hmccosmetics:frog_hat
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_frog_hat%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_frog_hat%"
type: cosmetic
cosmetic: frog_hat
jetpack:
slots:
- 6
item:
material: hmccosmetics:jetpack
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_jetpack%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_jetpack%"
type: cosmetic
cosmetic: jetpack
hammer:
slots:
- 7
item:
material: hmccosmetics:hammer
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_hammer%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_hammer%"
type: cosmetic
cosmetic: hammer
chestplate:
slots:
- 8
item:
material: hmccosmetics:chestplate
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_chestplate%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_chestplate%"
type: cosmetic
cosmetic: chestplate
pants:
slots:
- 9
item:
material: hmccosmetics:pants
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_pants%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_pants%"
type: cosmetic
cosmetic: pants
boots:
slots:
- 10
item:
material: hmccosmetics:boots
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_boots%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_boots%"
type: cosmetic
cosmetic: boots
kite:
slots:
- 11
item:
material: hmccosmetics:kite
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_kite%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_kite%"
type: cosmetic
cosmetic: kite
# EMOTES DO NOT WORK IN RECENT HMCCOSMETICS VERSIONS.
# handstand:
# slots:
# - 12
# item:
# material: PAPER
# name: "<blue>Handstand Emote"
# type: cosmetic
# cosmetic: handstand
# meditate:
# slots:
# - 13
# item:
# material: PAPER
# name: "<blue>Meditate Emote"
# type: cosmetic
# cosmetic: meditate
# thinking:
# slots:
# - 14
# item:
# material: PAPER
# name: "<blue>Thinking Emote"
# type: cosmetic
# cosmetic: thinking
explorer_backpack:
slots:
- 12
item:
material: hmccosmetics:explorer_backpack
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_explorer_backpack%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_explorer_backpack%"
type: cosmetic
cosmetic: explorer_backpack
garbage_truck_balloon:
slots:
- 13
item:
material: hmccosmetics:garbage_truck_balloon
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_garbage_truck_balloon%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_garbage_truck_balloon%"
type: cosmetic
cosmetic: garbage_truck_balloon
earth_day_grabber:
slots:
- 14
item:
material: hmccosmetics:earth_day_grabber
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_earth_day_grabber%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_earth_day_grabber%"
type: cosmetic
cosmetic: earth_day_grabber
hibiscus_flower:
slots:
- 15
item:
material: hmccosmetics:hibiscus_flower
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_hibiscus_flower%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_hibiscus_flower%"
type: cosmetic
cosmetic: hibiscus_flower

View File

@@ -0,0 +1,99 @@
title: "<white>"
rows: 6
items:
backpack:
slots:
- 1
item:
material: hmccosmetics:backpack
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_backpack%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_backpack%"
type: cosmetic
cosmetic: backpack
future_wings:
slots:
- 2
item:
material: hmccosmetics:future_wings
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_future_wings%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_future_wings%"
type: cosmetic
cosmetic: future_wings
jetpack:
slots:
- 3
item:
material: hmccosmetics:jetpack
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_jetpack%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_jetpack%"
type: cosmetic
cosmetic: jetpack
explorer_backpack:
slots:
- 4
item:
material: hmccosmetics:explorer_backpack
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_explorer_backpack%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_explorer_backpack%"
type: cosmetic
cosmetic: explorer_backpack
button_backpacks_menu:
slots:
- 0
item:
material: PAPER
model-data: 18
name: "<blue>Backpack Cosmetics"
amount: 1
type: empty
actions:
any:
- "[MENU] defaultmenu_backpacks"
- "[SOUND] minecraft:ui.button.click 1 1"
button_hand_menu:
slots:
- 18
item:
material: PAPER
model-data: 19
name: "<blue>Hand Cosmetics"
amount: 1
type: empty
actions:
any:
- "[MENU] defaultmenu_hands"
- "[SOUND] minecraft:ui.button.click 1 1"
button_balloon_menu:
slots:
- 27
item:
material: PAPER
model-data: 20
name: "<blue>Balloon Cosmetics"
amount: 1
type: empty
actions:
any:
- "[MENU] defaultmenu_balloons"
- "[SOUND] minecraft:ui.button.click 1 1"
button_hats_menu:
slots:
- 36
item:
material: PAPER
model-data: 17
name: "<blue>Hat Cosmetics"
amount: 1
type: empty
actions:
any:
- "[MENU] defaultmenu_hats"
- "[SOUND] minecraft:ui.button.click 1 1"

View File

@@ -0,0 +1,77 @@
title: "<white>"
rows: 6
items:
garbage_truck_balloon:
slots:
- 1
item:
material: hmccosmetics:garbage_truck_balloon
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_garbage_truck_balloon%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_garbage_truck_balloon%"
type: cosmetic
cosmetic: garbage_truck_balloon
kite:
slots:
- 2
item:
material: hmccosmetics:kite
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_kite%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_kite%"
type: cosmetic
cosmetic: kite
button_backpacks_menu:
slots:
- 27
item:
material: PAPER
model-data: 18
name: "<blue>Backpack Cosmetics"
amount: 1
type: empty
actions:
any:
- "[MENU] defaultmenu_backpacks"
- "[SOUND] minecraft:ui.button.click 1 1"
button_hand_menu:
slots:
- 36
item:
material: PAPER
model-data: 19
name: "<blue>Hand Cosmetics"
amount: 1
type: empty
actions:
any:
- "[MENU] defaultmenu_hands"
- "[SOUND] minecraft:ui.button.click 1 1"
button_balloon_menu:
slots:
- 0
item:
material: PAPER
model-data: 20
name: "<blue>Balloon Cosmetics"
amount: 1
type: empty
actions:
any:
- "[MENU] defaultmenu_balloons"
- "[SOUND] minecraft:ui.button.click 1 1"
button_hats_menu:
slots:
- 18
item:
material: PAPER
model-data: 17
name: "<blue>Hat Cosmetics"
amount: 1
type: empty
actions:
any:
- "[MENU] defaultmenu_hats"
- "[SOUND] minecraft:ui.button.click 1 1"

View File

@@ -0,0 +1,99 @@
title: "<white>"
rows: 6
items:
lantern_cosmetic:
slots:
- 1
item:
material: hmccosmetics:lantern_cosmetic
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_lantern_cosmetic%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_lantern_cosmetic%"
type: cosmetic
cosmetic: lantern_cosmetic
hammer:
slots:
- 2
item:
material: hmccosmetics:hammer
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_hammer%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_hammer%"
type: cosmetic
cosmetic: hammer
earth_day_grabber:
slots:
- 3
item:
material: hmccosmetics:earth_day_grabber
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_earth_day_grabber%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_earth_day_grabber%"
type: cosmetic
cosmetic: earth_day_grabber
hibiscus_flower:
slots:
- 4
item:
material: hmccosmetics:hibiscus_flower
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_hibiscus_flower%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_hibiscus_flower%"
type: cosmetic
cosmetic: hibiscus_flower
button_backpacks_menu:
slots:
- 36
item:
material: PAPER
model-data: 18
name: "<blue>Backpack Cosmetics"
amount: 1
type: empty
actions:
any:
- "[MENU] defaultmenu_backpacks"
- "[SOUND] minecraft:ui.button.click 1 1"
button_hand_menu:
slots:
- 0
item:
material: PAPER
model-data: 19
name: "<blue>Hand Cosmetics"
amount: 1
type: empty
actions:
any:
- "[MENU] defaultmenu_hands"
- "[SOUND] minecraft:ui.button.click 1 1"
button_balloon_menu:
slots:
- 18
item:
material: PAPER
model-data: 20
name: "<blue>Balloon Cosmetics"
amount: 1
type: empty
actions:
any:
- "[MENU] defaultmenu_balloons"
- "[SOUND] minecraft:ui.button.click 1 1"
button_hats_menu:
slots:
- 27
item:
material: PAPER
model-data: 17
name: "<blue>Hat Cosmetics"
amount: 1
type: empty
actions:
any:
- "[MENU] defaultmenu_hats"
- "[SOUND] minecraft:ui.button.click 1 1"

View File

@@ -0,0 +1,88 @@
title: "<white>"
rows: 6
items:
beanie:
slots:
- 1
item:
material: hmccosmetics:beanie
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_beanie%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_beanie%"
type: cosmetic
cosmetic: beanie
baseball_hat:
slots:
- 2
item:
material: hmccosmetics:baseball_hat
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_baseball_hat%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_baseball_hat%"
type: cosmetic
cosmetic: baseball_hat
frog_hat:
slots:
- 3
item:
material: hmccosmetics:frog_hat
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_frog_hat%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_frog_hat%"
type: cosmetic
cosmetic: frog_hat
button_hats_menu:
slots:
- 0
item:
material: PAPER
model-data: 17
name: "<blue>Hat Cosmetics"
amount: 1
type: empty
actions:
any:
- "[MENU] defaultmenu_hats"
- "[SOUND] minecraft:ui.button.click 1 1"
button_backpacks_menu:
slots:
- 18
item:
material: PAPER
model-data: 18
name: "<blue>Backpack Cosmetics"
amount: 1
type: empty
actions:
any:
- "[MENU] defaultmenu_backpacks"
- "[SOUND] minecraft:ui.button.click 1 1"
button_hand_menu:
slots:
- 27
item:
material: PAPER
model-data: 19
name: "<blue>Hand Cosmetics"
amount: 1
type: empty
actions:
any:
- "[MENU] defaultmenu_hands"
- "[SOUND] minecraft:ui.button.click 1 1"
button_balloon_menu:
slots:
- 36
item:
material: PAPER
model-data: 20
name: "<blue>Balloon Cosmetics"
amount: 1
type: empty
actions:
any:
- "[MENU] defaultmenu_balloons"
- "[SOUND] minecraft:ui.button.click 1 1"

Binary file not shown.

BIN
lib/HMCColor-2.4-all.jar Normal file

Binary file not shown.