9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-22 16:39:21 +00:00

Compare commits

..

341 Commits

Author SHA1 Message Date
LoJoSho
6b19bf442a chore: update adventure depends to 4.19.0 2025-02-25 19:17:47 -06:00
LoJoSho
436de38102 version bump (2.7.6) 2025-02-25 19:16:45 -06:00
LoJoSho
4bb00071d4 Merge remote-tracking branch 'origin/remapped' into remapped 2025-02-25 10:45:39 -06:00
LoJoSho
650cf75168 chore: improvements to HookBetterHud 2025-02-25 10:45:25 -06:00
lucian929
0d07e8a267 chore: change Oraxen references to Nexo
Oraxen support is being deprecated
2025-02-25 11:17:17 -05:00
LoJoSho
b7ec587d7d feat: add BetterHud as a soft depend 2025-02-22 21:37:51 -06:00
LoJoSho
e807c7e2f7 fix: respect settings about HUDs 2025-02-22 21:36:47 -06:00
LoJoSho
15e1f0aaa9 fix: BetterCommand not at a proper version; moved to 1.3 2025-02-22 20:56:39 -06:00
LoJoSho
f1e975f940 feat: add BetterHUD support for huds in wardrobes 2025-02-22 20:47:34 -06:00
LoJoSho
89fba800a4 clean: do not include qodana file 2025-02-14 23:54:26 -06:00
LoJoSho
863275a2ce feat: add Nexo comments to the default config 2025-02-14 23:53:56 -06:00
LoJoSho
b516cfced4 fix: color being passed to item cosmetic from previous cosmetic 2025-01-31 12:18:02 -06:00
LoJoSho
28034318ac fix: check if player is online before running wardrobe 2025-01-30 09:35:20 -06:00
LoJoSho
c2e4764ace feat: add async listeners to WINDOW_ITEMS and WINDOW_CLICK packets 2025-01-30 09:29:25 -06:00
LoJoSho
948bfb17f5 clean: update Paper repo 2025-01-30 09:28:17 -06:00
LoJoSho
6c98b7696a Merge pull request #168 from DebitCardz/fix/tick-task
Force Tick Task to Dispatch On CosmeticUser Create
2025-01-27 15:35:10 -06:00
Tech
2c4638fa47 fix broken java doc 2025-01-27 16:27:47 -05:00
Tech
ced2fe7b03 force tick task to dispatch on create 2025-01-27 16:22:52 -05:00
LoJoSho
3a56f074fa Merge pull request #167 from DebitCardz/misc/dl-sources
Include javadoc and sources
2025-01-27 11:56:55 -06:00
Tech
dca5abe4ec include javadoc and sources 2025-01-27 12:24:21 -05:00
LoJoSho
1dd54ea1cb fix: loading user data not properly checking disabled worlds 2025-01-26 17:02:48 -06:00
LoJoSho
b81af97573 Merge pull request #166 from DebitCardz/feat/cosmetic-provider
cosmetic provider & cleanup
2025-01-26 16:33:48 -06:00
LoJoSho
74d64b16d2 fix: readd toString for CosmeticSlot 2025-01-26 11:42:06 -06:00
Tech
2174ec6124 cosmetic provider & cleanup 2025-01-26 11:57:08 -05:00
LoJoSho
1de84bce6f Merge pull request #163 from DebitCardz/refactor/initialize
Allow Custom Implementations of CosmeticUser Initialization
2025-01-25 21:30:51 -06:00
LoJoSho
3aa5939225 clean: simplify logic surrounding new initialize logic 2025-01-25 21:13:38 -06:00
Tech
44650250c5 initialize method 2025-01-25 12:18:32 -05:00
LoJoSho
49fff9b650 Merge remote-tracking branch 'origin/remapped' into remapped 2025-01-24 19:34:36 -06:00
LoJoSho
190f66a990 feat: rewrite CosmeticSlot to allow for a consumers to run 2025-01-24 19:34:21 -06:00
LoJoSho
8a34f100d3 clean: annotate Menus to be more clean about returns and arguments 2025-01-23 14:47:13 -06:00
LoJoSho
79687a22fc feat: add usage for PlayerMenuCloseEvent, closes #158 2025-01-23 13:58:51 -06:00
LoJoSho
f5fac4e048 Merge pull request #162 from Craftinators/remapped
Cleanup previous PR changes
2025-01-23 12:21:59 -06:00
Craftinators
eac0812dbb refactor(PlayerConnectionListener): change Slf4j logging for internal logger 2025-01-23 12:22:04 -05:00
Craftinators
93f5bfbb2a docs(HMCCosmeticsAPI): remove unused imports and minor javadocs changes 2025-01-23 12:21:35 -05:00
Craftinators
94cba225a6 docs(CosmeticUsers): remove unused imports and small typo 2025-01-23 12:21:09 -05:00
Craftinators
ab614d8b07 docs(CosmeticUserProvider): add nullability annotations for methods 2025-01-23 12:10:34 -05:00
LoJoSho
e7fd39a077 Merge pull request #161 from DebitCardz/docs/api-note
Add API Note
2025-01-22 18:48:12 -06:00
Tech
530cdb282b add further docs 2025-01-22 19:46:54 -05:00
LoJoSho
97534f6916 Merge pull request #160 from DebitCardz/feat/player-provider
Implement Custom Player Providers
2025-01-22 18:40:10 -06:00
Tech
22fb52acc6 create user without data 2025-01-22 17:22:05 -05:00
Tech
cf0da580e0 expose getting cosmetic user provider 2025-01-22 17:21:58 -05:00
Tech
64a590b581 check against correct provider 2025-01-22 17:09:07 -05:00
Tech
afb3218bc1 cosmetic user provider impl 2025-01-22 17:01:14 -05:00
LoJoSho
170911a6a1 Merge pull request #157 from DebitCardz/fix/recursive-register
fix recursive registration
2025-01-22 14:57:19 -06:00
LoJoSho
ea5b878f74 Merge pull request #159 from Craftinators/remapped
Javadoc changes to `api` directory
2025-01-22 14:52:54 -06:00
Craftinators
88af1cd68e Merge branch 'HibiscusMC:remapped' into remapped 2025-01-22 15:43:31 -05:00
Craftinators
34237e0a45 docs: Minor javadoc changes to most of the api directory 2025-01-22 15:28:26 -05:00
Craftinators
a037487497 docs(PlayerCosmeticPostEquipEvent): add missing period 2025-01-22 11:06:36 -05:00
Craftinators
e7b1fda73e docs(PlayerCosmeticPostEquipEvent): improve Javadocs 2025-01-22 11:05:56 -05:00
Craftinators
c591641754 docs(PlayerCosmeticHideEvent): improve Javadocs 2025-01-22 11:03:40 -05:00
Craftinators
2a0aa1593a docs(PlayerCosmeticEvent): add link to CosmeticUser 2025-01-22 11:00:10 -05:00
Craftinators
330723a45c docs(PlayerCosmeticEquipEvent): improve Javadocs 2025-01-22 10:59:00 -05:00
Craftinators
f6a1438299 docs(PlayerEvent): improve Javadocs 2025-01-22 10:55:04 -05:00
Craftinators
1f0f8e5f70 docs(PlayerCosmeticEvent): improve Javadocs 2025-01-22 10:54:52 -05:00
Craftinators
216c05ed9b docs(HMCCosmeticSetupEvent): Add missing period 2025-01-22 10:50:31 -05:00
Craftinators
89fbacafac docs(CosmeticTypeRegisterEvent): Improved Javadocs and added annotations 2025-01-22 10:48:29 -05:00
Tech
8c45bfc76b fix recursive registration 2025-01-22 05:21:59 -05:00
LoJoSho
4ad3c02d88 Merge pull request #156 from Craftinators/remapped
Additional Javadoc Changes to `HMCCosmeticsAPI`
2025-01-21 23:42:19 -06:00
Craftinators
477729242b Merge remote-tracking branch 'origin/remapped' into remapped 2025-01-22 00:41:17 -05:00
Craftinators
e96d06892a docs(HMCCosmeticsAPI): lowercase "ID" 2025-01-22 00:40:52 -05:00
Craftinators
5b1b91f119 Merge branch 'HibiscusMC:remapped' into remapped 2025-01-22 00:37:20 -05:00
Craftinators
446e629474 docs(HMCCosmeticsAPI): remove unnecessary documentation 2025-01-22 00:35:13 -05:00
LoJoSho
57c2cd0719 Merge pull request #155 from Craftinators/remapped
`HMCCosmeticsAPI` Javadoc Changes
2025-01-21 23:35:02 -06:00
Craftinators
8f2a01b348 refactor(HMCCosmeticsAPI): private constructor on HMCCosmeticsAPI 2025-01-22 00:07:38 -05:00
Craftinators
6fe5817fd7 docs(HMCCosmeticsAPI): improve javadocs for utility methods 2025-01-21 23:56:04 -05:00
LoJoSho
663b3d1647 chore: add priorities and ignore cancelled for PaperPlayerGameListener events 2025-01-21 13:36:05 -06:00
LoJoSho
bf0a372edd feat: add api events relating to loading/unloading users (PlayerLoadEvent, PlayerPreLoadEvent, PlayerUnloadEvent) 2025-01-21 13:19:48 -06:00
LoJoSho
5d0237e28c feat: add config option about backpack darkness option 2025-01-21 11:58:49 -06:00
LoJoSho
349311cb58 feat: move default-menu to defaultmenu subcommand 2025-01-21 11:51:55 -06:00
LoJoSho
a1098641b5 feat: add cosmetic slot API methods 2025-01-21 11:49:09 -06:00
LoJoSho
8c0ca5083d feat: add default menu set setting message 2025-01-21 11:40:31 -06:00
LoJoSho
c42ecadd90 Merge remote-tracking branch 'origin/remapped' into remapped 2025-01-21 11:29:22 -06:00
LoJoSho
735386718e Revert "feat: begin migrating over to the new getViewers method"
This reverts commit c31d2e1aee.
2025-01-20 16:17:39 -06:00
LoJoSho
95459cc2d2 chore: use new TriumphGUI method 2025-01-19 13:39:08 -06:00
LoJoSho
fe52edd833 clean: more documentation with the CosmeticSlot registry 2025-01-18 16:34:47 -06:00
LoJoSho
d659128ae4 feat: add set default menu to setWardrobeSetting command 2025-01-17 15:39:08 -06:00
LoJoSho
397eebf38f Merge pull request #154 from HibiscusMC/cosmeticslot_registry
Migrate CosmeticSlot to a Registry
2025-01-17 15:24:58 -06:00
LoJoSho
e18690496f clean: clean HMCCInventoryUtils with new static variables 2025-01-17 14:57:43 -06:00
LoJoSho
c522581d46 feat: migrate over to using a registry for CosmeticSlot than enums 2025-01-17 14:45:08 -06:00
LoJoSho
c31d2e1aee feat: begin migrating over to the new getViewers method 2025-01-17 14:06:40 -06:00
LoJoSho
9879c82d40 clean: minor format adjustment in build.gradle.kts 2025-01-17 13:19:45 -06:00
LoJoSho
1873f5b9b5 feat: hook into hooks to check invisibility 2025-01-16 20:53:05 -06:00
LoJoSho
68d94be743 chore: remove unused hasClass method (use HibiscusCommons method instead) 2025-01-16 13:26:59 -06:00
LoJoSho
14e38e7974 chore: remove old, unused Backpack ModelEngine 4 2025-01-16 13:19:40 -06:00
LoJoSho
5cc19ab2db chore: move getNearbyPlayers from HMCCPlayerUtils to getViewers HMCCPacketManager 2025-01-16 13:11:30 -06:00
LoJoSho
93b1c20c40 chore: remove old Utils class 2025-01-16 12:59:20 -06:00
LoJoSho
49435436cb chore: move from deprecated spigot event to bukkit event 2025-01-16 12:54:40 -06:00
LoJoSho
0477e801a6 chore: move away from internally deprecated methods 2025-01-16 12:45:53 -06:00
LoJoSho
5779d278a9 chore: update paper api (1.20.4) & lombok (1.18.36) 2025-01-16 12:11:36 -06:00
LoJoSho
0a8821d3e8 chore: update test server to 1.21.4 2025-01-14 00:03:10 -06:00
LoJoSho
e96e9e00bb feat: use HibiscusHooksAllActiveEvent for reloading plugins that active their items later 2025-01-14 00:02:37 -06:00
LoJoSho
217fb5d332 fix: HookHMCC not setting itself as active 2025-01-14 00:01:49 -06:00
LoJoSho
6636cc9548 chore: add more documentation to entering and leaving wardrobes 2025-01-10 14:14:02 -06:00
LoJoSho
c3fcf760d7 clean: move setWardrobeStatus to Lombok; make wardrobe update method private 2025-01-10 14:05:08 -06:00
LoJoSho
7116767e22 clean: remove unused caching user items 2025-01-10 14:01:35 -06:00
LoJoSho
0877165f9f clean: adjust distance check in wardrobes 2025-01-10 13:57:08 -06:00
LoJoSho
b43466a793 clean: remove old ProtocolLib code 2024-12-29 17:18:21 -06:00
LoJoSho
401e6170e6 version bump (2.7.5) 2024-12-29 15:40:22 -06:00
LoJoSho
782eb4c464 chore: update adventure dependencies 2024-12-29 15:40:09 -06:00
LoJoSho
1ef2c6b631 chore: update gradle (8.12) & run-paper (2.3.1) 2024-12-28 19:49:48 -06:00
LoJoSho
c7667b2dc2 chore: improve version handling 2024-12-28 18:20:09 -06:00
LoJoSho
e4c4933d46 chore: more debug in passenger listener 2024-12-16 13:27:13 -06:00
LoJoSho
1f94192772 chore: update LP in runServer 2024-12-16 13:26:45 -06:00
LoJoSho
8ebcea5465 feat: if player is hidden from another player, their cosmetics are no longer seen 2024-12-06 13:36:49 -06:00
LoJoSho
4c7ccc06ca feat: version now has commit hash with it 2024-12-04 08:55:39 -06:00
LoJoSho
667f58ff4b fix: mount packet has bad if test 2024-11-25 13:22:58 -06:00
LoJoSho
69d318c4b0 feat: add Nexo support 2024-11-23 20:35:19 -06:00
LoJoSho
0414f3be90 clean: remove first person backpack update message (it is spammy) 2024-11-23 20:27:21 -06:00
LoJoSho
402203b4c2 feat: add passenger listener to better ensure backpacks stay on 2024-11-23 20:26:57 -06:00
LoJoSho
6dcaf06ebe feat: add defaultmenu to specific wardrobes 2024-11-19 20:43:31 -06:00
LoJoSho
1b6adca00e fix: balloon pufferfish getting wrong viewers 2024-11-16 10:57:31 -06:00
LoJoSho
0dce5822e3 feat: overhaul of getting player data 2024-11-15 21:59:32 -06:00
LoJoSho
0f1b75f09e feat: update to Hibiscus Commons 0.5 2024-11-15 20:21:04 -06:00
LoJoSho
19192c46a5 feat: add config options to avoid certain item processing if desired 2024-10-30 10:14:29 -05:00
LoJoSho
62a9e7d1ac chore: define variable nullability for getUserCosmeticItem 2024-10-30 09:21:27 -05:00
LoJoSho
06077201f9 fix: not checking if a null variable is null before usage in balloon handling in the wardrobe 2024-10-30 09:15:14 -05:00
LoJoSho
b2795a705e fix: not checking if itemstack has meta data before modification of meta data 2024-10-27 19:54:55 -05:00
LoJoSho
1e6734bf6f feat: console can now apply any cosmetic to a player 2024-10-24 20:34:17 -05:00
LoJoSho
ad382e5d9e chore: update ProtocolLib to newest version 2024-10-21 12:28:39 -05:00
LoJoSho
6458a1e316 chore: add downloadPlugins to runServer task 2024-10-13 17:38:11 -05:00
LoJoSho
279d6edc34 fix: mainhand showing even if invisible 2024-10-12 12:34:17 -05:00
LoJoSho
439dc85aa3 feat: add Hibiscus Commons / GSit compatibility 2024-10-10 22:50:58 -05:00
LoJoSho
60e23411dc fix: fixed cosmetic applying owner skull npe? (Should have already been checked but is now fully checked) 2024-10-02 22:24:04 -05:00
LoJoSho
33fb680c22 fix: Possible null in getEquipSlot 2024-10-01 23:58:44 -05:00
LoJoSho
536b7ebdec clean: remove jeff repo (moved to Hibiscus Commons) 2024-09-20 17:54:23 -05:00
LoJoSho
5da95f2f5b fix: finish the full update to Java 21 2024-09-20 17:50:51 -05:00
LoJoSho
30f4a84241 feat: menu command not having menu id will now open default menu 2024-09-20 17:13:54 -05:00
LoJoSho
f34e126c85 chore: bring test-server to 1.21.1 2024-09-20 17:11:49 -05:00
LoJoSho
d7d0f27e49 chore: fix misspelled relocated paths 2024-08-26 13:16:33 -05:00
LoJoSho
f42937a6d0 fix: Model Engine coloring throwing class not found (version bump 2.7.4-DEV) 2024-08-26 12:57:23 -05:00
LoJoSho
c8b7430998 clean: update gradle wrapper 2024-08-16 10:11:33 -05:00
LoJoSho
42de76d84d version bump (2.7.3) 2024-08-16 09:33:26 -05:00
LoJoSho
5102fd77b7 Merge remote-tracking branch 'origin/remapped' into remapped 2024-08-09 10:03:11 -05:00
LoJoSho
9c66d4ee81 fix: entering wardrobe not activating if allow cosmetics set to allow 2024-08-09 10:02:59 -05:00
LoJoSho
7ade2d9227 fix: ProtocolLib body part changed in newest versions 2024-08-05 21:27:13 -05:00
LoJoSho
7b43b42740 Revert "feat: customize backpack light emination"
This reverts commit 3cf265f231.
2024-08-01 18:31:05 -05:00
LoJoSho
25f050f387 Revert "feat: add user cosmetic item caching"
This reverts commit 34b02574b2.
2024-08-01 18:27:38 -05:00
Boy
05c13e8990 fix: swapping hotbar-slot resetting NBT of previous-item 2024-07-22 02:24:59 +02:00
LoJoSho
34b02574b2 feat: add user cosmetic item caching 2024-07-21 11:04:06 -05:00
LoJoSho
f81d350a2e clean: update depends 2024-07-11 21:36:50 -05:00
LoJoSho
be86314daf feat: add none database type 2024-07-11 21:23:51 -05:00
LoJoSho
345f903113 clean: remove duplicate emote folder check 2024-07-11 21:14:54 -05:00
LoJoSho
3cf265f231 feat: customize backpack light emination 2024-07-08 18:03:12 -05:00
LoJoSho
d26e7df2ca Merge remote-tracking branch 'origin/remapped' into remapped 2024-07-02 19:43:17 -05:00
LoJoSho
e5dc3f6774 feat: update to Java 21 2024-07-02 19:42:45 -05:00
LoJoSho
fdc9893a60 Merge pull request #147 from MineInAbyss/tweaks
refactor: make hidden-cosmetics message only show when player has cos…
2024-06-15 21:54:15 -05:00
Boy
e8694076b8 refactor: make hidden-cosmetics message only show when player has cosmetics equipped 2024-06-16 01:11:06 +02:00
LoJoSho
1acf536080 fix: ending wardrobe getting illegal argument (same as previous commit) 2024-06-15 09:41:34 -05:00
LoJoSho
9d3ad0b54b fix: 1.20.6 shooting error illegal arguments on equipment slot update 2024-06-15 08:33:05 -05:00
LoJoSho
0b2ade1598 clean: remove old 1.18.2 and 1.19.1/2/3 old packet code 2024-06-14 17:29:03 -05:00
LoJoSho
83651b7250 clean: change our onPlayerLook to onPlayerMove to better describe what it listens to 2024-06-14 17:21:56 -05:00
LoJoSho
6818c09a69 chore: add documentation to CosmeticTypeRegisterEvent 2024-06-14 17:19:46 -05:00
LoJoSho
dc72b677de Merge pull request #144 from MineInAbyss/remapped
feat: Third-party CosmeticTypes, & minor API methods
2024-06-08 17:43:46 -05:00
Boy
5ff1a63eaa feat: add WardrobeManager#lastOpenMenu 2024-06-08 21:30:47 +02:00
LoJoSho
8300a86225 chore: update adventure dependencies 2024-06-08 14:20:21 -05:00
LoJoSho
9e8084194a chore: update triumph gui to 3.1.10 (this was not marked as the latest version) 2024-06-08 14:16:02 -05:00
LoJoSho
c0ea4d5a5b chore: update triumph gui to 3.1.8 2024-06-08 14:15:02 -05:00
Boy
5a963391f8 feat: add locked-equipped-item 2024-06-07 17:36:16 +02:00
Boy
6c4586a6b9 fix: nullpointer due to CUSTOM cosmeticslot 2024-06-07 17:36:16 +02:00
Boy
4cc0a6f968 feat: add CosmeticTypeRegisterEvent to allow for third-party CosmeticTypes 2024-06-07 17:36:16 +02:00
LoJoSho
ab8656ad1a feat: add more logic for dealing with closed connections, closes #140 2024-06-06 19:38:53 -05:00
LoJoSho
ca5e0f96c2 clean: change require-empty in default config to false 2024-06-02 19:58:31 -05:00
LoJoSho
5cddd24097 feat: add HibiscusPlayerEmote events; bumped Hibiscus Commons to 0.4.1 2024-05-29 12:51:21 -05:00
LoJoSho
656e539ae3 feat: add menu clicking cooldown 2024-05-27 21:28:31 -05:00
LoJoSho
862b7c9ee6 fix: Backpacks not appearing after respawning in a different world 2024-05-26 15:31:19 -05:00
LoJoSho
c632174de8 clean: update debug message for menu updateItem 2024-05-24 17:36:34 -05:00
LoJoSho
1e96303765 fix: second NMS check for emotes not updated 2024-05-22 20:20:28 -05:00
LoJoSho
1a6d587ee0 feat: add hidden placeholder 2024-05-22 20:11:02 -05:00
LoJoSho
adcb6de5e4 fix: lang instead of lang3 import for StringUtils 2024-05-22 20:06:03 -05:00
LoJoSho
c36e263a95 feat: bump api version to 1.19 2024-05-22 20:02:16 -05:00
LoJoSho
de1e5bf100 fix: check if entity is null after offhand swap event 2024-05-20 11:09:45 -05:00
LoJoSho
ea25dcf208 fix: dye menu not accepting fireworks 2024-05-20 09:54:11 -05:00
LoJoSho
e3c73d0bfe feat: add firework item effect support 2024-05-19 19:16:53 -05:00
LoJoSho
91b24bfa82 fix: data loading not checking disabled boolean for disabled gamemodes 2024-05-16 20:29:24 -05:00
LoJoSho
28bf5ba2b6 fix: backpacks sometimes still spawned after being hidden 2024-05-15 16:29:09 -05:00
LoJoSho
0249d6abdb fix: player animator attempting to start on 1.20.6 2024-05-12 13:43:51 -05:00
LoJoSho
cb32f635d0 feat: rework of slot options (config reworked for slot options for enchants and showing) 2024-05-11 14:33:46 -05:00
LoJoSho
3bfdde4281 fix: not checking player before checking world 2024-04-30 16:28:31 -05:00
LoJoSho
8daa2709f3 feat: process PAPI placeholders in wardrobe bossbar 2024-04-29 14:32:15 -05:00
LoJoSho
35260d4abb Merge remote-tracking branch 'origin/remapped' into remapped 2024-04-27 09:06:34 -05:00
LoJoSho
2d44435d53 fix: hmccolor dye menu not processing through minimessage 2024-04-27 09:06:21 -05:00
LoJoSho
3d785bd157 version bump (2.7.3-DEV) 2024-04-27 09:04:39 -05:00
lucian929
c33cfbd302 fix: update default config to use proper input slots for color 2024-04-25 15:24:22 -04:00
LoJoSho
f5ed39e02c Merge remote-tracking branch 'origin/remapped' into remapped 2024-04-25 14:09:44 -05:00
LoJoSho
0c3af0e0cd version bump (2.7.2) 2024-04-25 14:09:22 -05:00
lucian929
f5a1a67e1e chore: remove emotes from defaultmenu 2024-04-25 14:13:47 -04:00
LoJoSho
ddc0a504fd fix: disabled worlds not checked if player teleports through portals 2024-04-25 12:12:27 -05:00
LoJoSho
de108753d5 clean: ignore cancelled teleportations 2024-04-02 22:04:40 -05:00
LoJoSho
b31e8b7a4b chore: more documentation for CosmeticUsers class 2024-04-02 22:02:51 -05:00
LoJoSho
383fdfa7f6 fix: no entity + backpack spawning causing NPE 2024-03-16 12:13:07 -05:00
LoJoSho
54e867ab0b Merge pull request #131 from HibiscusMC/allow-flight
fix: wardrobe kicking player if allowFlight not enabled in server.pro…
2024-03-11 08:40:46 -05:00
LoJoSho
068ed3eb70 fix: backpacks not reattaching after teleporting 2024-03-05 22:26:10 -06:00
LoJoSho
a203c60df1 fix: backpacks turning black when under blocks 2024-03-05 10:58:12 -06:00
LoJoSho
e13c3fccb4 fix: hidden flags being added async causing error 2024-02-25 17:51:06 -06:00
LoJoSho
add72e66c9 feat: hidden reasons now in lists, add disableall command (hides all players cosmetics) 2024-02-25 15:20:32 -06:00
LoJoSho
0e587feff0 fix: multiple schedulers when player has multiple loaded cosmetics 2024-02-21 12:42:57 -06:00
LoJoSho
27be86c419 fix: clean resources after sql usage 2024-02-20 13:53:10 -06:00
Boy
3d940d8468 fix: wardrobe kicking player if allowFlight not enabled in server.properties 2024-02-10 13:20:36 +01:00
LoJoSho
7515cdd137 refactor: getHidden to isHidden in CosmeticUser class, deprecate old method 2024-02-04 20:07:01 -06:00
LoJoSho
8e92f3e689 fix: hidden reasons for gamemodes + world not working, spawning entity cosmetics while hidden 2024-02-04 20:04:33 -06:00
LoJoSho
7c4b833d80 fix: tab autocomplete checks attempted before user loading causing NPE 2024-02-04 19:20:37 -06:00
LoJoSho
b291dc4c9f Merge remote-tracking branch 'origin/remapped' into remapped 2024-01-28 10:57:30 -06:00
LoJoSho
60b91df843 fix: balloons with head models pitch being affected by player 2024-01-28 10:56:49 -06:00
LoJoSho
56f380025d fix: equipped armor not showing after exiting wardrobe 2024-01-17 13:07:01 -06:00
LoJoSho
b3e0acbcbd feat: add config options to prevent damage while in the wardrobe 2024-01-17 12:45:04 -06:00
LoJoSho
e2d334db9d version bump (2.7.2-DEV) 2024-01-17 12:25:03 -06:00
LoJoSho
dffcf6213b fix: check if player is not null before running end wardrobe 2024-01-17 12:24:41 -06:00
Boy
485f5837f4 fix: bump HMCColor & implement API-changes 2024-01-14 01:55:34 +01:00
LoJoSho
442cddb81e version bump (2.7.0) 2024-01-12 11:45:03 -06:00
Boy
1f38d1aa46 chore: bump hmccolor 2024-01-10 01:52:27 +01:00
LoJoSho
ce7dc03350 fix: player dying causing NPE 2024-01-06 11:09:21 -06:00
LoJoSho
9a75fcb55b fix: check if player is still online after join delay 2024-01-05 13:36:12 -06:00
LoJoSho
5522eed2d1 fix: pose changes in wardrobe causes backpack being unattached 2024-01-03 12:38:17 -06:00
LoJoSho
1737330b87 feat: balloons now disappear when hidden 2024-01-02 21:10:38 -06:00
LoJoSho
eff25664f3 clean: move gamemode and world hidden checks to player join 2024-01-02 21:10:06 -06:00
LoJoSho
27d3a1df42 feat: add disabled worlds option 2024-01-02 20:45:18 -06:00
LoJoSho
63bda02869 fix: hidden backpacks still having armorstands spawned 2024-01-02 20:34:25 -06:00
LoJoSho
8c251a8c69 clean: add debug messages for respawning of cosmetics 2024-01-02 11:10:36 -06:00
LoJoSho
4b481ef3ea clean: refactor overlapping Hibiscus Commons util class names 2023-12-29 12:19:00 -06:00
LoJoSho
2d62c96d3d Merge pull request #129 from HibiscusMC/hibiscuscommons
Refactor to Hibiscus Commons Library (2.7.0)
2023-12-29 12:13:49 -06:00
LoJoSho
f8cb436c5b fix: handle IA reloading 2023-12-28 20:49:23 -06:00
LoJoSho
0de31fcd04 chore: update hibiscus commons to 0.2.1 2023-12-28 19:07:59 -06:00
LoJoSho
99edb501a5 fix: itemsadder reload 2023-12-28 19:07:46 -06:00
LoJoSho
66aaed009f fix: players being invisible if disconnect in wardrobe 2023-12-27 10:54:08 -06:00
LoJoSho
4c0b86b127 chore: updates adventure platform to 4.3.2 2023-12-27 10:22:52 -06:00
LoJoSho
155133a2a0 fix: players opening menu in setup phase of wardrobes 2023-12-27 09:50:58 -06:00
LoJoSho
93062d47a8 fix: cosmetic armor happening in wardrobe 2023-12-27 09:46:59 -06:00
LoJoSho
1f0c67a805 clean: remove cmi jars 2023-12-24 21:30:27 -06:00
LoJoSho
74feb112f6 feat: remove nms in HMCC, update to support Hibiscus Commons 0.1.8 2023-12-23 12:37:20 -06:00
LoJoSho
967349f5af version bump (2.7.0-DEV) 2023-12-23 12:01:31 -06:00
LoJoSho
d7fe2475ed Merge branch 'remapped' into hibiscuscommons 2023-12-23 11:58:46 -06:00
Boy
f87bf93641 fix: check instance instead of id for shading 2023-12-23 18:56:17 +01:00
LoJoSho
4b467b4644 fix: check instance instead of id for shading 2023-12-23 11:54:20 -06:00
LoJoSho
15234a904f clean: remove barely used text emote feature 2023-12-22 22:09:22 -06:00
LoJoSho
9ff6d3f60c feat: balloon entities entirely through bukkit 2023-12-22 22:05:09 -06:00
LoJoSho
aeba867e9e chore: update adventure classes 2023-12-22 21:57:30 -06:00
LoJoSho
d21e148f39 chore: update HibiscusCommons to 0.1.7 2023-12-22 21:50:47 -06:00
LoJoSho
51188fdeba feat: move to Hibiscus Commmons library 2023-12-22 21:25:50 -06:00
LoJoSho
dcf072f3de fix: balloons and backpacks being respawned while in wardrobe 2023-12-20 15:38:32 -06:00
LoJoSho
ebf09d8e0f fix: check if user is still in wardrobe before spawning npc 2023-12-20 15:38:02 -06:00
LoJoSho
ca5cb25331 clean: move configurate back to being shaded 2023-12-20 14:02:58 -06:00
LoJoSho
65877bff5b clean: move nms spawn balloon method to CosmeticUser 2023-12-19 19:55:57 -06:00
LoJoSho
4a75c7b333 Merge remote-tracking branch 'origin/remapped' into remapped 2023-12-19 19:48:02 -06:00
Boy
be4f1d6675 chore: add TypeCosmetic-initializer with id-argument for extending class 2023-12-20 02:47:33 +01:00
LoJoSho
55d4f9ae09 clean: move private bulkUpdate method to updateCosmetic since it was just using that method anyways 2023-12-19 19:28:06 -06:00
LoJoSho
88691956ba fix: locked-item not appearing in wardrobes with unchecked cosmetics 2023-12-19 18:39:54 -06:00
LoJoSho
a6133a2b45 clean: remove triumph gui from library loader (was used for testing in last build) 2023-12-19 18:00:15 -06:00
LoJoSho
0aa821e51a feat: move adventure and configurate to Spigots library loader 2023-12-19 15:17:41 -06:00
LoJoSho
fb37ea8af9 clean: removed unused relocations 2023-12-19 14:49:15 -06:00
LoJoSho
0f36803026 feat: add PlayerArmorChangeEvent for Paper servers 2023-12-18 19:40:28 -06:00
LoJoSho
2910540c26 fix: enchants not being passed to cosmetics 2023-12-18 19:23:53 -06:00
LoJoSho
93fb885195 fix: further wardrobe armor fixes for Optifine clients 2023-12-18 19:04:25 -06:00
LoJoSho
2438d5385f clean: add eco as soft depend 2023-12-18 14:51:14 -06:00
LoJoSho
73ce071427 feat: add HookFlags to hooks 2023-12-18 13:35:40 -06:00
LoJoSho
e3485b7733 fix: forgot to reverse order when condensing the method 2023-12-18 13:20:02 -06:00
LoJoSho
7ff4fbb3d7 feat: add support for Eco item lookup system 2023-12-18 13:19:43 -06:00
LoJoSho
de5b9be6ac fix: server-side teleporation causing players to be stuck in wardrobe area 2023-12-18 12:52:35 -06:00
LoJoSho
0c6e8eb160 fix: bad clients failing to removing player model in wardrobe 2023-12-18 12:52:07 -06:00
LoJoSho
9b85fd2d8c feat: player teleport when entering wardrobe, allows better support for long distance wardrobes 2023-12-17 22:41:12 -06:00
LoJoSho
a136b95451 clean: remove deperecated #getCosmetic 2023-12-17 11:24:31 -06:00
LoJoSho
cf5eb64029 feat: priority system for menus 2023-12-16 18:30:58 -06:00
LoJoSho
c4591b030b feat: reduced packets for armor cosmetics 2023-12-16 16:13:52 -06:00
LoJoSho
9dc6eb1dfc version bump (2.6.7-DEV) 2023-12-16 09:52:27 -06:00
LoJoSho
d7c1bf39e2 version bump (2.6.6) 2023-12-16 09:49:40 -06:00
LoJoSho
ae1527fca3 feat: add 1.20.3/4 nms support 2023-12-10 13:02:04 -06:00
LoJoSho
d14698b282 clean: get static context correctly in main plugin class 2023-11-22 17:09:08 -06:00
LoJoSho
800d3be25f clean: removed formatArmorItemType method in StringUtils 2023-11-22 17:04:45 -06:00
LoJoSho
27599030cf clean: optimize imports 2023-11-22 16:59:49 -06:00
LoJoSho
3ee959abd6 feat: add HMCColor support in commands, resolves #114 2023-11-20 17:05:23 -06:00
LoJoSho
617df48cc2 feat: add amount placeholder, resolves #127 2023-11-20 16:09:52 -06:00
LoJoSho
9e290c2dfd version bump (2.6.6-DEV) 2023-11-20 16:07:49 -06:00
LoJoSho
f98614c4ee Merge remote-tracking branch 'origin/remapped' into remapped 2023-11-15 11:41:06 -06:00
LoJoSho
d28bb23f8c version bump (2.6.5) 2023-11-15 11:40:55 -06:00
Boy
502cb533f8 fix: drop runOnOrAfter for GearyHook 2023-11-05 01:05:38 +01:00
LoJoSho
b7fdc2087a fix: removed no longer needed entity id check on damage, caused conflicts with MythicMobs 2023-11-04 08:44:36 -05:00
LoJoSho
10a42a3c96 feat: papi placeholders now work for heads in menus 2023-10-29 14:01:28 -05:00
LoJoSho
51fc52e24b feat: add config option to disable cosmetics in certain gamemodes 2023-10-27 20:34:07 -05:00
LoJoSho
be632d8e8c fix: ME4 balloons not hiding for player 2023-10-27 19:50:34 -05:00
LoJoSho
a732a2b0a0 clean: remove hikari repo, set CommentedConfiguration to specific commit to fix Jitpack jank 2023-10-27 19:44:59 -05:00
Boy
b14a0b5d16 update geary-hook 2023-10-27 16:44:31 +02:00
LoJoSho
50393c62b0 fix: offhand cosmetics not checking if item is air 2023-10-26 13:38:48 -05:00
LoJoSho
dbc4a07895 fix: empty menu type not adding papi placeholders 2023-10-16 11:16:57 -05:00
LoJoSho
ab329e4fbf feat: define what offline and invalid player return in translations 2023-10-15 11:05:29 -05:00
LoJoSho
90ad700d0a feat: define no-cosmetic and none differently in translations 2023-10-15 10:41:45 -05:00
LoJoSho
56529d6111 Merge remote-tracking branch 'origin/remapped' into remapped 2023-10-15 10:32:29 -05:00
LoJoSho
b6a06007e8 Merge remote-tracking branch 'origin/remapped' into remapped 2023-10-15 10:31:54 -05:00
LoJoSho
edccc9ce4e fix: (last commit) forgot to reverse check 2023-10-15 10:28:54 -05:00
LoJoSho
e0b2f0f6b1 fix: improve nms version checker 2023-10-14 14:47:05 -05:00
LoJoSho
57f4d3703c fix: current placeholder returning null when no cosmetics are equipped 2023-10-13 11:47:14 -05:00
LoJoSho
8ef6692198 fix: emotes on lower versions not initializing 2023-10-13 10:41:39 -05:00
LoJoSho
c48830f3ac fix: move to configurate for full yml loading 2023-10-13 10:38:58 -05:00
LoJoSho
734c04c1f4 feat: me4 balloons working? 2023-10-11 21:46:17 -05:00
LoJoSho
b08b4019a9 clean: latest changes to try to get me4 working 2023-10-10 12:32:43 -05:00
LoJoSho
cfb7876b6e fix: player packet merged into entity packet in 1.20.2 2023-10-06 16:13:41 -05:00
LoJoSho
6047d0e3c3 clean: update me to 4.0.2 2023-10-06 15:20:59 -05:00
LoJoSho
880c333df9 Merge branch 'remapped' into me4 2023-10-06 14:56:16 -05:00
LoJoSho
c4d7b657dd feat: add option to disable emotes entirely 2023-10-06 12:44:59 -05:00
LoJoSho
5be3ce8d21 Merge remote-tracking branch 'origin/remapped' into remapped 2023-10-06 12:33:55 -05:00
LoJoSho
33bba631fc feat: model engine 4 2023-10-02 15:55:21 -05:00
LoJoSho
775b9c299d feat: basic 1.20.2 support 2023-09-24 10:59:24 -05:00
LoJoSho
6e02331c13 version bump (2.6.5-DEV) 2023-09-24 10:40:45 -05:00
LoJoSho
b7457cec9c Merge remote-tracking branch 'origin/remapped' into remapped 2023-09-15 16:40:21 -05:00
lucian929
e7288a1910 fixed config issues for vanilla rp config 2023-09-15 17:39:30 -04:00
LoJoSho
26b90bd8bb version bump (2.6.5-DEV) 2023-09-13 11:03:46 -05:00
LoJoSho
24a10b6838 version bump (2.6.4) 2023-09-13 10:58:04 -05:00
LoJoSho
af7bc0dc3f feat: add hmccosmetics and cosmetic aliases 2023-09-09 12:52:53 -05:00
LoJoSho
162d4a6ed6 fix: setting viewlocation now sets from eye level location 2023-09-09 12:34:53 -05:00
LoJoSho
41140f60c5 fix: distances referencing display radius when that no longer exists in config 2023-09-09 12:31:20 -05:00
LoJoSho
a6145a607c clean: move to integer parse 2023-09-09 11:38:52 -05:00
LoJoSho
89c6951a93 fix: getOfflinePlayer always returns a notnull object 2023-09-09 11:38:02 -05:00
LoJoSho
28c466e342 clean: remove old inheritance that no longer matters 2023-09-09 11:35:37 -05:00
LoJoSho
90caa23cd7 clean: remove unneeded if statements 2023-09-09 11:27:49 -05:00
LoJoSho
910f223151 Merge remote-tracking branch 'origin/remapped' into remapped 2023-09-01 18:11:51 -05:00
LoJoSho
ac1b50a957 clean: remove old removal passenger logic from PlayerQuitEvent 2023-08-31 18:29:59 -05:00
LoJoSho
9cb9bad3c8 fix: rework of equipment packet modification to be more vanilla-like 2023-08-30 22:10:25 -05:00
LoJoSho
f68e2633a2 version bump (2.6.4-DEV) 2023-08-30 11:50:54 -05:00
LoJoSho
c8ad5c0881 version bump (2.6.3) 2023-08-30 11:17:24 -05:00
LoJoSho
c93a718799 fix: check if item is null 2023-08-30 09:55:40 -05:00
LoJoSho
b5f781e00f fix: add wardrobe section to ignorable config updater 2023-08-29 21:48:46 -05:00
LoJoSho
f6cd73f436 clean: remove now unused NMS methods relating to backpacks 2023-08-29 21:37:43 -05:00
LoJoSho
8b0fcc5da9 fix: balloon pufferfish not properly being destroyed out of range 2023-08-29 17:41:35 -05:00
LoJoSho
b5787f22bf fix: add distance and permission to default config 2023-08-29 14:50:10 -05:00
LoJoSho
c1c431d914 fix: process PAPI placeholders on player command action 2023-08-28 21:36:06 -05:00
LoJoSho
b41dc66508 fix: hotbar visually messing up if player spun scrolled fast enough 2023-08-28 10:58:44 -05:00
LoJoSho
cfbf74257b feat: add offhand-always-show option 2023-08-27 20:59:56 -05:00
LoJoSho
9b2083b90a version bump (2.6.3-DEV) 2023-08-27 20:59:37 -05:00
LoJoSho
33437cd387 version bump (2.6.2) 2023-08-27 13:52:50 -05:00
LoJoSho
9f4e4616d4 fix: entity metadata being set incorrectly on 1.19.3+ 2023-08-27 13:44:48 -05:00
LoJoSho
01c62bc94e feat: add MMOItems hook 2023-08-27 13:31:59 -05:00
LoJoSho
3be4bdeb6f clean: optimize imports 2023-08-27 13:09:05 -05:00
LoJoSho
145aec9b7f feat: entity cooldown teleportation packet option 2023-08-27 12:44:53 -05:00
LoJoSho
4a2266bbfa clean: a bit of work on packet listeners 2023-08-27 11:51:25 -05:00
LoJoSho
7fa3cd6cb7 clean: removed unused NMS methods 2023-08-27 10:11:59 -05:00
LoJoSho
9c5fe9c426 fix: offhand cosmetic visually going into mainhand for other players when swapping 2023-08-26 14:31:02 -05:00
LoJoSho
0a9d750d3e clean: wardrobe javadocs and Lombok 2023-08-26 10:37:21 -05:00
LoJoSho
da996fb146 version bump (2.6.2-DEV) 2023-08-26 10:17:41 -05:00
LoJoSho
006319a757 Merge remote-tracking branch 'origin/remapped' into remapped 2023-05-27 10:05:33 -05:00
LoJoSho
a8ff8e6a7a Merge remote-tracking branch 'origin/remapped' into remapped 2023-05-08 09:50:55 -05:00
LoJoSho
8b20207442 Merge remote-tracking branch 'origin/remapped' into remapped 2023-04-24 10:32:56 -05:00
LoJoSho
8bbe12ed84 Merge remote-tracking branch 'origin/remapped' into remapped
# Conflicts:
#	build.gradle.kts
2023-01-30 10:40:00 -06:00
LoJoSho
d23f3e19d2 Moved ProtocolLib Repo 2022-11-16 13:38:02 -06:00
146 changed files with 3024 additions and 4276 deletions

1
.gitignore vendored
View File

@@ -115,3 +115,4 @@ run/
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar
/qodana.yaml

View File

@@ -2,13 +2,13 @@ import net.minecrell.pluginyml.bukkit.BukkitPluginDescription
plugins {
id("java")
id("com.github.johnrengelman.shadow") version "8.1.1"
id("xyz.jpenilla.run-paper") version "2.0.0"
id("com.gradleup.shadow") version "8.3.2"
id("xyz.jpenilla.run-paper") version "2.3.1"
id("net.minecrell.plugin-yml.bukkit") version "0.6.0"
}
group = "com.hibiscusmc"
version = "2.6.1"
version = "2.7.6${getGitCommitHash()}"
allprojects {
apply(plugin = "java")
@@ -18,7 +18,7 @@ allprojects {
mavenCentral()
// Paper Repo
maven("https://papermc.io/repo/repository/maven-public/")
maven("https://repo.papermc.io/repository/maven-public/")
maven("https://oss.sonatype.org/content/repositories/snapshots")
// Jitpack
@@ -32,9 +32,6 @@ allprojects {
// PlaceholderAPI
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
//Hikari
maven("https://mvnrepository.com/artifact/com.zaxxer/HikariCP")
// Citizens & Denizen
maven("https://maven.citizensnpcs.co/repo")
@@ -52,9 +49,6 @@ allprojects {
}
}
// UpdateChecker
maven("https://hub.jeff-media.com/nexus/repository/jeff-media-public/")
// ParticleHelper
maven("https://repo.bytecode.space/repository/maven-public/")
@@ -63,57 +57,71 @@ allprojects {
// md-5 Repo
maven("https://repo.md-5.net/content/groups/public/")
// MMOItems
maven("https://nexus.phoenixdevt.fr/repository/maven-public/")
// Eco-Suite/Auxilor Repo
maven("https://repo.auxilor.io/repository/maven-public/")
// Triumph GUI
maven("https://repo.triumphteam.dev/snapshots")
// Hibiscus Commons
maven("https://repo.hibiscusmc.com/releases")
}
dependencies {
compileOnly(fileTree("${project.rootDir}/lib") { include("*.jar") })
compileOnly("com.mojang:authlib:1.5.25")
compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
compileOnly("org.jetbrains:annotations:23.0.0")
compileOnly("com.comphenix.protocol:ProtocolLib:5.0.0")
compileOnly("me.clip:placeholderapi:2.11.3")
compileOnly("com.ticxo:modelengine:R3.0.1")
compileOnly("com.github.oraxen:oraxen:1.160.0")
compileOnly("com.github.LoneDev6:API-ItemsAdder:3.2.5")
compileOnly("com.mineinabyss:geary-papermc:0.24.1")
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.1.0-SNAPSHOT")
compileOnly("it.unimi.dsi:fastutil:8.5.11")
compileOnly("com.github.LeonMangler:SuperVanish:6.2.17")
compileOnly("org.projectlombok:lombok:1.18.2")
//compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.20.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("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")
annotationProcessor("org.projectlombok:lombok:1.18.28")
testCompileOnly("org.projectlombok:lombok:1.18.28")
testAnnotationProcessor("org.projectlombok:lombok:1.18.28")
// Handled by Spigot Library Loader
compileOnly("net.kyori:adventure-api:4.19.0")
compileOnly("net.kyori:adventure-text-minimessage:4.19.0")
compileOnly("net.kyori:adventure-platform-bukkit:4.3.4")
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") {
exclude("net.kyori") // Already have adventure API
}
implementation("com.owen1212055:particlehelper:1.0.0-SNAPSHOT")
implementation("com.ticxo.playeranimator:PlayerAnimator:R1.2.7")
}
tasks {
javadoc {
// javadoc spec has these added.
(options as StandardJavadocDocletOptions)
.tags("apiNote:a:API:", "implSpec:a:Implementation Requirements", "implNote:a:Implementation Note:")
}
}
}
dependencies {
implementation(project(path = ":common"))
implementation(project(path = ":v1_18_R2", configuration = "reobf"))
implementation(project(path = ":v1_19_R1", configuration = "reobf"))
implementation(project(path = ":v1_19_R2", configuration = "reobf"))
implementation(project(path = ":v1_19_R3", configuration = "reobf"))
implementation(project(path = ":v1_20_R1", configuration = "reobf"))
//compileOnly("com.github.Fisher2911:FisherLib:master-SNAPSHOT")
implementation("net.kyori:adventure-api:4.11.0")
implementation("net.kyori:adventure-text-minimessage:4.11.0")
implementation("net.kyori:adventure-platform-bukkit:4.1.2")
implementation("dev.triumphteam:triumph-gui:3.1.3")
implementation("org.spongepowered:configurate-yaml:4.1.2")
implementation("org.bstats:bstats-bukkit:3.0.0")
implementation("com.jeff_media:SpigotUpdateChecker:3.0.0")
implementation("com.owen1212055:particlehelper:1.0.0-SNAPSHOT")
implementation("com.ticxo.playeranimator:PlayerAnimator:R1.2.7")
implementation("com.github.BG-Software-LLC:CommentedConfiguration:-SNAPSHOT")
//implementation("com.ticxo.playeranimator:PlayerAnimator:R1.2.5")
}
tasks {
compileJava {
options.encoding = Charsets.UTF_8.name()
options.release.set(17)
options.release.set(21)
}
javadoc {
@@ -126,28 +134,21 @@ tasks {
}
runServer {
minecraftVersion("1.20.1")
minecraftVersion("1.21.4")
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")
}
}
shadowJar {
dependsOn(":v1_18_R2:reobfJar")
dependsOn(":v1_19_R1:reobfJar")
dependsOn(":v1_19_R2:reobfJar")
dependsOn(":v1_19_R3:reobfJar")
dependsOn(":v1_20_R1:reobfJar")
mergeServiceFiles()
relocate("dev.triumphteam.gui", "com.hisbiscusmc.hmccosmetics.gui")
relocate("me.mattstudios.mf", "com.hisbiscusmc.hmccosmetics.mf")
relocate("net.kyori.adventure", "com.hisbiscusmc.hmccosmetics.adventure")
relocate("org.spongepowered.configurate", "com.hisbiscusmc.hmccosmetics.configurate")
relocate("org.bstats", "com.hisbiscusmc.hmccosmetics.bstats")
relocate("com.zaxxer.hikaricp", "com.hisbiscusmc.hmccosmetics.hikaricp")
relocate("com.j256.ormlite", "com.hisbiscusmc.hmccosmetics.ormlite")
relocate("com.jeff_media.updatechecker", "com.hisbiscusmc.hmccosmetics.updatechecker")
relocate("com.owen1212055.particlehelper", "com.hisbiscusmc.hmccosmetics.particlehelper")
relocate("com.ticxo.playeranimator", "com.hisbiscusmc.hmccosmetics.playeranimator")
relocate("com.bgsoftware", "com.hisbiscusmc.hmccosmetics.configupdater")
relocate("dev.triumphteam.gui", "com.hibiscusmc.hmccosmetics.shaded.gui")
relocate("com.owen1212055.particlehelper", "com.hibiscusmc.hmccosmetics.shaded.particlehelper")
relocate("com.ticxo.playeranimator", "com.hibiscusmc.hmccosmetics.shaded.playeranimator")
archiveFileName.set("HMCCosmeticsRemapped-${project.version}.jar")
dependencies {
@@ -172,10 +173,10 @@ tasks {
bukkit {
load = BukkitPluginDescription.PluginLoadOrder.POSTWORLD
main = "com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin"
apiVersion = "1.18"
apiVersion = "1.20"
authors = listOf("LoJoSho")
depend = listOf("ProtocolLib")
softDepend = listOf("ModelEngine", "Oraxen", "ItemsAdder", "Geary", "HMCColor", "WorldGuard", "MythicMobs", "PlaceholderAPI", "SuperVanish", "PremiumVanish", "LibsDisguises", "Denizen")
depend = listOf("HibiscusCommons", "ProtocolLib")
softDepend = listOf("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.
@@ -184,6 +185,7 @@ bukkit {
commands {
register("cosmetic") {
description = "Base Cosmetic Command"
aliases = listOf("hmccosmetics", "cosmetics")
}
}
permissions {
@@ -259,10 +261,41 @@ bukkit {
register("hmccosmetics.unapplydeath.bypass") {
default = BukkitPluginDescription.Permission.Default.OP
}
register("hmccosmetics.cmd.disableall") {
default = BukkitPluginDescription.Permission.Default.OP
}
register("hmccosmetics.cmd.hiddenreasons") {
default = BukkitPluginDescription.Permission.Default.OP
}
register("hmccosmetics.cmd.clearhiddenreasons") {
default = BukkitPluginDescription.Permission.Default.OP
}
}
}
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17
))
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
withJavadocJar()
withSourcesJar()
}
fun getGitCommitHash(): String {
var includeHash = true
val includeHashVariable = System.getenv("HMCC_INCLUDE_HASH")
if (!includeHashVariable.isNullOrEmpty()) includeHash = includeHashVariable.toBoolean()
if (includeHash) {
return try {
val process = ProcessBuilder("git", "rev-parse", "--short", "HEAD")
.redirectErrorStream(true)
.start()
process.inputStream.bufferedReader().use { "-" + it.readLine().trim() }
} catch (e: Exception) {
"-unknown" // Fallback if Git is not available or an error occurs
}
}
return ""
}

View File

@@ -3,43 +3,11 @@ plugins {
id("maven-publish")
}
dependencies {
compileOnly("com.mojang:authlib:1.5.25")
compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
compileOnly("org.jetbrains:annotations:23.0.0")
compileOnly("com.comphenix.protocol:ProtocolLib:5.0.0")
compileOnly("me.clip:placeholderapi:2.11.3")
compileOnly("com.ticxo:modelengine:R3.0.1")
compileOnly("com.github.oraxen:oraxen:1.160.0")
compileOnly("com.github.LoneDev6:API-ItemsAdder:3.2.5")
compileOnly("com.mineinabyss:geary-papermc:0.24-SNAPSHOT")
//compileOnly("com.hibiscus:hmccolor:0.3-SNAPSHOT") USE LIB PROVIDED FILE
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.1.0-SNAPSHOT")
compileOnly("it.unimi.dsi:fastutil:8.5.11")
compileOnly("io.lumine:Mythic-Dist:5.2.1")
compileOnly("com.denizenscript:denizen:1.2.7-SNAPSHOT")
compileOnly("com.github.LeonMangler:SuperVanish:6.2.17")
compileOnlyApi("LibsDisguises:LibsDisguises:10.0.21") {
exclude("org.spigotmc", "spigot")
}
//compileOnly("com.github.Fisher2911:FisherLib:master-SNAPSHOT")
implementation("net.kyori:adventure-api:4.12.0")
implementation("net.kyori:adventure-text-minimessage:4.12.0")
implementation("net.kyori:adventure-platform-bukkit:4.2.0")
implementation("dev.triumphteam:triumph-gui:3.1.3")
implementation("org.spongepowered:configurate-yaml:4.1.2")
implementation("org.bstats:bstats-bukkit:3.0.0")
implementation("com.jeff_media:SpigotUpdateChecker:3.0.0")
implementation("com.owen1212055:particlehelper:1.0.0-SNAPSHOT")
implementation("com.ticxo.playeranimator:PlayerAnimator:R1.2.7")
implementation("com.github.BG-Software-LLC:CommentedConfiguration:-SNAPSHOT")
//implementation("com.ticxo.playeranimator:PlayerAnimator:R1.2.5")
}
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17
))
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
withJavadocJar()
withSourcesJar()
}
publishing {

View File

@@ -1,8 +0,0 @@
pluginManagement {
repositories {
gradlePluginPortal()
maven("https://repo.papermc.io/repository/maven-public/")
}
}
rootProject.name = "HMCCosmetics"

View File

@@ -1,91 +1,66 @@
package com.hibiscusmc.hmccosmetics;
import com.bgsoftware.common.config.CommentedConfiguration;
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;
import com.hibiscusmc.hmccosmetics.config.DatabaseSettings;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
import com.hibiscusmc.hmccosmetics.config.serializer.ItemSerializer;
import com.hibiscusmc.hmccosmetics.config.serializer.LocationSerializer;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
import com.hibiscusmc.hmccosmetics.database.Database;
import com.hibiscusmc.hmccosmetics.emotes.EmoteManager;
import com.hibiscusmc.hmccosmetics.gui.Menu;
import com.hibiscusmc.hmccosmetics.gui.Menus;
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
import com.hibiscusmc.hmccosmetics.hooks.items.HookHMCCosmetics;
import com.hibiscusmc.hmccosmetics.hooks.misc.HookBetterHud;
import com.hibiscusmc.hmccosmetics.hooks.placeholders.HMCPlaceholderExpansion;
import com.hibiscusmc.hmccosmetics.hooks.worldguard.WGHook;
import com.hibiscusmc.hmccosmetics.hooks.worldguard.WGListener;
import com.hibiscusmc.hmccosmetics.listener.PaperPlayerGameListener;
import com.hibiscusmc.hmccosmetics.listener.PlayerConnectionListener;
import com.hibiscusmc.hmccosmetics.listener.PlayerGameListener;
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
import com.hibiscusmc.hmccosmetics.listener.ServerListener;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.TranslationUtil;
import com.jeff_media.updatechecker.UpdateCheckSource;
import com.jeff_media.updatechecker.UpdateChecker;
import com.ticxo.playeranimator.PlayerAnimatorImpl;
import org.bstats.bukkit.Metrics;
import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin;
import me.lojosho.hibiscuscommons.HibiscusPlugin;
import me.lojosho.hibiscuscommons.config.serializer.ItemSerializer;
import me.lojosho.hibiscuscommons.config.serializer.LocationSerializer;
import me.lojosho.shaded.configupdater.common.config.CommentedConfiguration;
import me.lojosho.shaded.configurate.ConfigurateException;
import me.lojosho.shaded.configurate.ConfigurationOptions;
import me.lojosho.shaded.configurate.yaml.NodeStyle;
import me.lojosho.shaded.configurate.yaml.YamlConfigurationLoader;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.permissions.Permission;
import org.bukkit.plugin.java.JavaPlugin;
import org.spongepowered.configurate.ConfigurateException;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.ConfigurationOptions;
import org.spongepowered.configurate.yaml.NodeStyle;
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
import java.io.File;
import java.nio.file.Path;
public final class HMCCosmeticsPlugin extends JavaPlugin {
public final class HMCCosmeticsPlugin extends HibiscusPlugin {
private static HMCCosmeticsPlugin instance;
private static boolean disable = false;
private static YamlConfigurationLoader configLoader;
private static final int pluginId = 13873;
private static boolean onLatestVersion = true;
private static String latestVersion = "";
public HMCCosmeticsPlugin() {
super(13873, 1879);
new HookHMCCosmetics();
new HookBetterHud();
}
@Override
public void onEnable() {
public void onStart() {
// Plugin startup logic
instance = this;
// bstats https://bstats.org/plugin/bukkit/HMCCosmetics/13873
Metrics metrics = new Metrics(this, pluginId);
// NMS version check
if (!NMSHandlers.getHandler().getSupported()) {
getLogger().severe("This version is not supported! Consider switching versions?");
getServer().getPluginManager().disablePlugin(this);
return;
}
// Update Checker
UpdateChecker checker = new UpdateChecker(this, UpdateCheckSource.POLYMART, "1879")
.onSuccess((commandSenders, latestVersion) -> {
this.latestVersion = (String) latestVersion;
if (!this.latestVersion.equalsIgnoreCase(getDescription().getVersion())) {
getLogger().info("+++++++++++++++++++++++++++++++++++");
getLogger().info("There is a new update for HMCCosmetics!");
getLogger().info("Please download it as soon as possible for possible fixes and new features.");
getLogger().info("Current Version " + getDescription().getVersion() + " | Latest Version " + latestVersion);
getLogger().info("Spigot: https://www.spigotmc.org/resources/100107/");
getLogger().info("Polymart: https://polymart.org/resource/1879");
getLogger().info("+++++++++++++++++++++++++++++++++++");
}
})
.setNotifyRequesters(false)
.setNotifyOpsOnJoin(false)
.checkEveryXHours(24)
.checkNow();
onLatestVersion = checker.isUsingLatestVersion();
// File setup
saveDefaultConfig();
if (!Path.of(getDataFolder().getPath(), "messages.yml").toFile().exists()) saveResource("messages.yml", false);
@@ -93,12 +68,8 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
if (!Path.of(getDataFolder().getPath() + "/cosmetics/").toFile().exists()) saveResource("cosmetics/defaultcosmetics.yml", false);
if (!Path.of(getDataFolder().getPath() + "/menus/").toFile().exists()) saveResource("menus/defaultmenu.yml", false);
// Emote folder setup
File emoteFile = new File(getDataFolder().getPath() + "/emotes");
if (!emoteFile.exists()) emoteFile.mkdir();
// Player Animator
PlayerAnimatorImpl.initialize(this);
if (HMCCosmeticsAPI.getNMSVersion().contains("v1_19_R3") || HMCCosmeticsAPI.getNMSVersion().contains("v1_20_R1")) PlayerAnimatorImpl.initialize(this); // PlayerAnimator does not support 1.20.2 yet
// Configuration Sync
final File configFile = Path.of(getInstance().getDataFolder().getPath(), "config.yml").toFile();
@@ -106,13 +77,16 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
final File translationFile = Path.of(getInstance().getDataFolder().getPath(), "translations.yml").toFile();
try {
CommentedConfiguration.loadConfiguration(configFile).syncWithConfig(configFile, getInstance().getResource("config.yml"),
"database-settings", "debug-mode", "wardrobe.viewer-location", "wardrobe.npc-location", "wardrobe.wardrobe-location", "wardrobe.leave-location");
"database-settings", "wardrobe.wardrobes", "debug-mode", "wardrobe.viewer-location", "wardrobe.npc-location", "wardrobe.wardrobe-location", "wardrobe.leave-location");
CommentedConfiguration.loadConfiguration(messageFile).syncWithConfig(messageFile, getInstance().getResource("messages.yml"));
CommentedConfiguration.loadConfiguration(translationFile).syncWithConfig(translationFile, getInstance().getResource("translations.yml"));
} catch (Exception e) {
e.printStackTrace();
}
// Move this over to Hibiscus Commons later
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) new HMCPlaceholderExpansion().register();
// Setup
setup();
@@ -123,7 +97,11 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
// Listener
getServer().getPluginManager().registerEvents(new PlayerConnectionListener(), this);
getServer().getPluginManager().registerEvents(new PlayerGameListener(), this);
getServer().getPluginManager().registerEvents(new ServerListener(), this);
// Taken from PaperLib
if (HibiscusCommonsPlugin.isOnPaper()) {
getServer().getPluginManager().registerEvents(new PaperPlayerGameListener(), this);
}
// Database
new Database();
@@ -142,15 +120,17 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
}
@Override
public void onDisable() {
public void onEnd() {
// Plugin shutdown logic
disable = true;
for (Player player : Bukkit.getOnlinePlayers()) {
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) continue;
if (user.getUserEmoteManager().isPlayingEmote()) {
player.setInvisible(false);
}
if (user.isInWardrobe()) {
user.leaveWardrobe(true);
}
Database.save(user);
}
}
@@ -214,9 +194,6 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
throw new RuntimeException(e);
}
// Misc Hooks setup (like items)
Hooks.setup();
// Cosmetics setup
Cosmetics.setup();
@@ -252,7 +229,7 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
}
}
EmoteManager.loadEmotes();
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");
@@ -262,28 +239,4 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
Bukkit.getPluginManager().callEvent(new HMCCosmeticSetupEvent());
}
public static boolean isDisable() {
return disable;
}
public static YamlConfigurationLoader getConfigLoader() {
return configLoader;
}
public static void saveConfig(ConfigurationNode node) {
try {
HMCCosmeticsPlugin.getConfigLoader().save(node);
HMCCosmeticsPlugin.getInstance().getLogger().info("Set new location " + node.path());
} catch (ConfigurateException e) {
throw new RuntimeException(e);
}
}
public static boolean isOnLatestVersion() {
return onLatestVersion;
}
public static String getLatestVersion() {
return latestVersion;
}
}

View File

@@ -2,116 +2,213 @@ package com.hibiscusmc.hmccosmetics.api;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticProvider;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
import com.hibiscusmc.hmccosmetics.gui.Menu;
import com.hibiscusmc.hmccosmetics.gui.Menus;
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUserProvider;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
import me.lojosho.shaded.configurate.ConfigurationNode;
import org.bukkit.Color;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class HMCCosmeticsAPI {
import java.util.function.BiConsumer;
/**
* Attempts to get a cosmetic from HMCCosmetics
*
* @param cosmetic Cosmetic Id
* @return A {@link Cosmetic} if exists or null if it does not
* The main API class for HMCCosmetics. This class provides methods to interact with the plugin.
*/
@Nullable
public static Cosmetic getCosmetic(@NotNull String cosmetic) {
return Cosmetics.getCosmetic(cosmetic);
public final class HMCCosmeticsAPI {
private HMCCosmeticsAPI() {
throw new UnsupportedOperationException("This class cannot be instantiated.");
}
/**
* Attempts to get the CosmeticUser from an online user. If a player is offline it will return null.
* A player maybe online but not have a CosmeticUser attached to them, either from delay specified in the config
* or from a /reload. Always check if it's null!
*
* @param uuid Player Unique ID
* @return A {@link CosmeticUser} if exists or null if it does not
* Retrieves a {@link Cosmetic} associated with the specified id.
* <p>
* This method attempts to fetch a {@link Cosmetic} using the given id. If no {@link Cosmetic} exists
* with the specified id, it will return {@code null}.
* </p>
* @param id the id of the {@link Cosmetic} to retrieve
* @return the {@link Cosmetic} if it exists, or {@code null} if no cosmetic is associated with the given id
*/
@Nullable
public static CosmeticUser getUser(@NotNull UUID uuid) {
public static @Nullable Cosmetic getCosmetic(@NotNull String id) {
return Cosmetics.getCosmetic(id);
}
/**
* Retrieves the {@link CosmeticUser} associated with the specified player's {@link UUID}.
* <p>
* This method attempts to fetch a {@link CosmeticUser} for an online player. If the player is offline,
* or if no {@link CosmeticUser} is currently associated with them, it will return {@code null}.
* </p>
* Note that a player may be online but not have a {@link CosmeticUser} attached due to:
* <ul>
* <li>A delay specified in the configuration</li>
* <li>A recent server reload (e.g., via the {@code /reload} command)</li>
* </ul>
* Always perform a {@code null} check before using the returned object to ensure safe operation.
*
* @param uuid the {@link UUID} of the player whose {@link CosmeticUser} is being retrieved
* @return the {@link CosmeticUser} if it exists, or {@code null} if the player is offline or unassociated
*/
public static @Nullable CosmeticUser getUser(@NotNull UUID uuid) {
return CosmeticUsers.getUser(uuid);
}
/**
* Attempts to get a HMCCosmetics Menu. Returns null if no menu exists under that id.
* Retrieves a {@link Menu} associated with the specified id, or {@code null} if no menu exists with the given id.
*
* @param id Menu ID
* @return A {@link Menu} if exists or null if it does not
* @param id the id of the menu to retrieve
* @return the {@link Menu} if it exists, or {@code null} if no menu is associated with the given id
*/
@Nullable
public static Menu getMenu(@NotNull String id) {
public static @Nullable Menu getMenu(@NotNull String id) {
return Menus.getMenu(id);
}
/**
* Equips a cosmetic to a player. You can use getUser and getCosmetic to get the CosmeticUser and Cosmetic to equip.
* @param user CosmeticUser to equip cosmetic to
* @param cosmetic Cosmetic to equip
* Equips a {@link Cosmetic} to a player. To retrieve the necessary {@code CosmeticUser} and {@code Cosmetic}, use the {@link #getUser}
* and {@link #getCosmetic} methods respectively.
*
* @param user the {@link CosmeticUser} to equip the cosmetic to
* @param cosmetic the {@link Cosmetic} to equip
*/
public static void equipCosmetic(@NotNull CosmeticUser user, @NotNull Cosmetic cosmetic) {
equipCosmetic(user, cosmetic, null);
}
/**
* Equips a cosmetic to a player with a color. You can use getUser and getCosmetic to get the CosmeticUser and Cosmetic to equip.
* @param user CosmeticUser to equip cosmetic to
* @param cosmetic Cosmetic to equip
* @param color Color to apply to cosmetic
* Equips a {@link Cosmetic} to a player with an optional color customization. To retrieve the necessary
* {@code CosmeticUser} and {@code Cosmetic}, use the {@link #getUser} and {@link #getCosmetic} methods
* respectively.
*
* @param user the {@link CosmeticUser} to equip the cosmetic to
* @param cosmetic the {@link Cosmetic} to equip
* @param color the color to apply to the cosmetic, or {@code null} if the cosmetic does not support color
* customization
*/
public static void equipCosmetic(@NotNull CosmeticUser user, @NotNull Cosmetic cosmetic, @Nullable Color color) {
user.addPlayerCosmetic(cosmetic, color);
}
/**
* Removes a cosmetic in cosmeticslot.
* @param user The user to remove the cosmetic from
* @param slot The slot to remove the cosmetic from
* Removes a cosmetic from a specified slot for the given user.
*
* @param user the {@link CosmeticUser} from whom the cosmetic will be removed
* @param slot the {@link CosmeticSlot} from which the cosmetic will be removed
*/
public static void unequipCosmetic(@NotNull CosmeticUser user, @NotNull CosmeticSlot slot) {
user.removeCosmeticSlot(slot);
}
/**
* Gets all Cosmetics that are currently registered with HMCC. This list is immutable!
* @return A list of all registered cosmetics
* Retrieves a list of all cosmetics currently registered with HMCC.
*
* @return an {@code immutable} list containing all registered {@link Cosmetic} object
*/
public static List<Cosmetic> getAllCosmetics() {
public static @NotNull List<Cosmetic> getAllCosmetics() {
return List.copyOf(Cosmetics.values());
}
/**
* Gets all CosmeticUsers that are currently registered with HMCC. This list is immutable!
* @return A list of all registered CosmeticUsers
* Retrieves a list of all cosmetic users currently registered with HMCC.
*
* @return an immutable list containing all registered {@link CosmeticUser} objects
*/
public static List<CosmeticUser> getAllCosmeticUsers() {
public static @NotNull List<CosmeticUser> getAllCosmeticUsers() {
return List.copyOf(CosmeticUsers.values());
}
/**
* This returns the NMS version of the server as recognized by HMCCosmetics. This will be null until HMCC setup has been completed.
* @return The NMS version of the server in String format
* Retrieves a map of all cosmetic slots currently registered with HMCC.
*
* @return an immutable {@link Map} containing all registered cosmetic slots
*/
@Nullable
public static String getNMSVersion() {
public static @NotNull Map<String, CosmeticSlot> getAllCosmeticSlots() {
return Map.copyOf(CosmeticSlot.values());
}
/**
* Registers a new cosmetic slot with the specified id. If a slot with the same id already exists,
* the existing slot will be returned.
*
* <p>
* The provided id will automatically be converted to uppercase when registering the slot.
* </p>
*
* @param id the id for the cosmetic slot
* @return the {@link CosmeticSlot} associated with the given id
* @apiNote this should be done in your {@link JavaPlugin#onLoad()} or it may error.
*/
public static @NotNull CosmeticSlot registerCosmeticSlot(@NotNull String id) {
return CosmeticSlot.register(id);
}
/**
* Registers a new cosmetic user provider to use for constructing {@link CosmeticUser} instances.
*
* @param provider the provider to register
* @throws IllegalArgumentException if another plugin has already registered a provider
* @apiNote this should be done in your {@link JavaPlugin#onLoad()} or it may error.
*/
public static void registerCosmeticUserProvider(@NotNull CosmeticUserProvider provider) {
CosmeticUsers.registerProvider(provider);
}
/**
* Retrieves the current {@link CosmeticUserProvider} that is in use.
*
* @return the current {@link CosmeticUserProvider}
*/
public static @NotNull CosmeticUserProvider getCosmeticUserProvider() {
return CosmeticUsers.getProvider();
}
/**
* Registers a new cosmetic user provider to use for constructing {@link Cosmetic} instances.
*
* @param provider the provider to register
* @throws IllegalArgumentException if another plugin has already registered a provider
* @apiNote this should be done in your {@link JavaPlugin#onLoad()} or it may error.
*/
public static void registerCosmeticProvider(@NotNull CosmeticProvider provider) {
Cosmetics.registerProvider(provider);
}
/**
* Retrieves the current {@link CosmeticProvider} that is in use.
*
* @return the current {@link CosmeticProvider}
*/
public static @NotNull CosmeticProvider getCosmeticProvider() {
return Cosmetics.getProvider();
}
/**
* Retrieves the NMS version of the server as recognized by HMCCosmetics.
*
* <p>This value will be {@code null} until the HMCC setup has been completed. Ensure setup is finished
* before attempting to access this version.</p>
*
* @return the NMS version of the server in string format, or {@code null} if setup is not complete.
*/
public static @Nullable String getNMSVersion() {
return NMSHandlers.getVersion();
}
/**
* This returns the HMCCosmetics version.
* @return The HMCCosmetics version in String format
* Retrieves the version of HMCCosmetics currently in use.
*
* @return the HMCCosmetics version in string format
*/
@NotNull
public static String getHMCCVersion() {
public static @NotNull String getHMCCVersion() {
return HMCCosmeticsPlugin.getInstance().getDescription().getVersion();
}
}

View File

@@ -0,0 +1,55 @@
package com.hibiscusmc.hmccosmetics.api.events;
import me.lojosho.shaded.configurate.ConfigurationNode;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/**
* Called when an attempt is made to register a cosmetic type that is not part of the default HMCC cosmetics.
* <p>
* For example, if a user specifies "test" in the config slot, and it is not a default cosmetic, this event will be
* triggered.
* </p>
*/
public class CosmeticTypeRegisterEvent extends Event {
private static final HandlerList HANDLER_LIST = new HandlerList();
private final String id;
private final ConfigurationNode config;
public CosmeticTypeRegisterEvent(@NotNull String id, @NotNull ConfigurationNode config) {
this.id = id;
this.config = config;
}
/**
* Returns the id of the cosmetic attempting to be registered.
*
* @return the id of the cosmetic. This is the key in the cosmetic configuration.
*/
public @NotNull String getId() {
return id;
}
/**
* Retrieves the {@link ConfigurationNode} for the cosmetic that was attempted to be registered.
* <p>
* This node is nested below the id in the configuration.
* </p>
*
* @return the configuration node for the cosmetic in the cosmetic configuration
*/
public @NotNull ConfigurationNode getConfig() {
return config;
}
@Override
public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}
public static @NotNull HandlerList getHandlerList() {
return HANDLER_LIST;
}
}

View File

@@ -5,19 +5,17 @@ import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/**
* Called when the plugin is set up and/or reloaded
* Called when the plugin is set up and/or reloaded.
*/
public class HMCCosmeticSetupEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private static final HandlerList HANDLER_LIST = new HandlerList();
@Override
@NotNull
public HandlerList getHandlers() {
return handlers;
public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}
@NotNull
public static HandlerList getHandlerList() {
return handlers;
public static @NotNull HandlerList getHandlerList() {
return HANDLER_LIST;
}
}

View File

@@ -7,22 +7,24 @@ import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/**
* Called when a player equips a cosmetic
* Called when a player equips a {@link Cosmetic}.
*/
public class PlayerCosmeticEquipEvent extends PlayerCosmeticEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancel = false;
private static final HandlerList HANDLER_LIST = new HandlerList();
private Cosmetic cosmetic;
private boolean cancel = false;
public PlayerCosmeticEquipEvent(@NotNull CosmeticUser who, @NotNull Cosmetic cosmetic) {
super(who);
this.cosmetic = cosmetic;
}
/**
* Gets the {@link Cosmetic} being equipped in this event
* Gets the {@link Cosmetic} being equipped in this event.
*
* @return The {@link Cosmetic} which is being equipped in this event
* @return the cosmetic which is being equipped in this event
*/
@NotNull
public Cosmetic getCosmetic() {
@@ -30,9 +32,9 @@ public class PlayerCosmeticEquipEvent extends PlayerCosmeticEvent implements Can
}
/**
* Sets the {@link Cosmetic} that the player will equip
* Sets the {@link Cosmetic} that the player will equip.
*
* @param cosmetic The {@link Cosmetic} that the player will equip
* @param cosmetic the cosmetic that the player will equip
*/
public void setCosmetic(@NotNull Cosmetic cosmetic) {
this.cosmetic = cosmetic;
@@ -43,28 +45,17 @@ public class PlayerCosmeticEquipEvent extends PlayerCosmeticEvent implements Can
return cancel;
}
/**
* Sets the cancellation state of this event
*
* <p>
* Canceling this event will prevent the player from equipping the cosmetic
* </p>
*
* @param cancel true if you wish to cancel this event
*/
@Override
public void setCancelled(boolean cancel) {
this.cancel = cancel;
}
@Override
@NotNull
public HandlerList getHandlers() {
return handlers;
public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}
@NotNull
public static HandlerList getHandlerList() {
return handlers;
public static @NotNull HandlerList getHandlerList() {
return HANDLER_LIST;
}
}

View File

@@ -5,22 +5,22 @@ import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
/**
* Represents a cosmetic user related event
* Represents an event related to a {@link CosmeticUser}.
*/
public abstract class PlayerCosmeticEvent extends Event {
protected CosmeticUser user;
public abstract class PlayerCosmeticEvent extends PlayerEvent {
protected final CosmeticUser user;
public PlayerCosmeticEvent(@NotNull final CosmeticUser who) {
public PlayerCosmeticEvent(@NotNull CosmeticUser who) {
super(who.getUniqueId());
user = who;
}
/**
* Returns the user involved in this event
* Returns the {@link CosmeticUser} involved in this event.
*
* @return User who is involved in this event
* @return the user who is involved in this event
*/
@NotNull
public final CosmeticUser getUser() {
public final @NotNull CosmeticUser getUser() {
return user;
}
}

View File

@@ -6,25 +6,26 @@ import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/**
* Called when cosmetics are hidden from a player
* Called when cosmetics are hidden from a player.
*/
public class PlayerCosmeticHideEvent extends PlayerCosmeticEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancel = false;
private static final HandlerList HANDLER_LIST = new HandlerList();
private final CosmeticUser.HiddenReason reason;
private boolean cancel = false;
public PlayerCosmeticHideEvent(@NotNull CosmeticUser who, @NotNull CosmeticUser.HiddenReason reason) {
super(who);
this.reason = reason;
}
/**
* Gets the {@link CosmeticUser.HiddenReason} as to why cosmetics are being hidden for the player
* Gets the {@link CosmeticUser.HiddenReason} as to why cosmetics are being hidden for the player.
*
* @return The {@link CosmeticUser.HiddenReason} why cosmetics are being hidden for the player
* @return the reason why cosmetics are being hidden for the player
*/
@NotNull
public CosmeticUser.HiddenReason getReason() {
public @NotNull CosmeticUser.HiddenReason getReason() {
return reason;
}
@@ -33,28 +34,17 @@ public class PlayerCosmeticHideEvent extends PlayerCosmeticEvent implements Canc
return cancel;
}
/**
* Sets the cancellation state of this event
*
* <p>
* Canceling this event will prevent the player from hiding cosmetics
* </p>
*
* @param cancel true if you wish to cancel this event
*/
@Override
public void setCancelled(boolean cancel) {
this.cancel = cancel;
}
@Override
@NotNull
public HandlerList getHandlers() {
return handlers;
public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}
@NotNull
public static HandlerList getHandlerList() {
return handlers;
public static @NotNull HandlerList getHandlerList() {
return HANDLER_LIST;
}
}

View File

@@ -5,8 +5,12 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/**
* Called when a player has equipped a {@link Cosmetic}.
*/
public class PlayerCosmeticPostEquipEvent extends PlayerCosmeticEvent {
private static final HandlerList handlers = new HandlerList();
private static final HandlerList HANDLER_LIST = new HandlerList();
private Cosmetic cosmetic;
public PlayerCosmeticPostEquipEvent(@NotNull CosmeticUser who, @NotNull Cosmetic cosmetic) {
@@ -15,32 +19,29 @@ public class PlayerCosmeticPostEquipEvent extends PlayerCosmeticEvent {
}
/**
* Gets the {@link Cosmetic} being equipped in this event
* Gets the {@link Cosmetic} being equipped in this event.
*
* @return The {@link Cosmetic} which is being equipped in this event
* @return the cosmetic which is being equipped in this event
*/
@NotNull
public Cosmetic getCosmetic() {
public @NotNull Cosmetic getCosmetic() {
return cosmetic;
}
/**
* Sets the {@link Cosmetic} that the player will equip
* Sets the {@link Cosmetic} that the player will equip.
*
* @param cosmetic The {@link Cosmetic} that the player will equip
* @param cosmetic the cosmetic that the player will equip
*/
public void setCosmetic(@NotNull Cosmetic cosmetic) {
this.cosmetic = cosmetic;
}
@Override
@NotNull
public HandlerList getHandlers() {
return handlers;
public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}
@NotNull
public static HandlerList getHandlerList() {
return handlers;
public static @NotNull HandlerList getHandlerList() {
return HANDLER_LIST;
}
}

View File

@@ -7,22 +7,24 @@ import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/**
* Called when a player removes a cosmetic
* Called when a player removes a {@link Cosmetic}.
*/
public class PlayerCosmeticRemoveEvent extends PlayerCosmeticEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancel = false;
private static final HandlerList HANDLER_LIST = new HandlerList();
private final Cosmetic cosmetic;
private boolean cancel = false;
public PlayerCosmeticRemoveEvent(@NotNull CosmeticUser who, @NotNull Cosmetic cosmetic) {
super(who);
this.cosmetic = cosmetic;
}
/**
* Gets the {@link Cosmetic} being removed in this event
* Gets the {@link Cosmetic} being removed in this event.
*
* @return The {@link Cosmetic} which is being removed in this event
* @return the cosmetic which is being removed in this event
*/
public Cosmetic getCosmetic() {
return cosmetic;
@@ -33,27 +35,17 @@ public class PlayerCosmeticRemoveEvent extends PlayerCosmeticEvent implements Ca
return cancel;
}
/**
* Sets the cancellation state of this event
*
* <p>
* Canceling this event will prevent the player from removing the cosmetic
* </p>
*
* @param cancel true if you wish to cancel this event
*/
@Override
public void setCancelled(boolean cancel) {
this.cancel = cancel;
}
@Override
@NotNull
public HandlerList getHandlers() {
return handlers;
public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}
public static HandlerList getHandlerList() {
return handlers;
public static @NotNull HandlerList getHandlerList() {
return HANDLER_LIST;
}
}

View File

@@ -6,10 +6,11 @@ import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/**
* Called when cosmetics are shown from a player
* Called when cosmetics are shown from a player.
*/
public class PlayerCosmeticShowEvent extends PlayerCosmeticEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private static final HandlerList HANDLER_LIST = new HandlerList();
private boolean cancel = false;
public PlayerCosmeticShowEvent(@NotNull CosmeticUser who) {
@@ -21,28 +22,17 @@ public class PlayerCosmeticShowEvent extends PlayerCosmeticEvent implements Canc
return cancel;
}
/**
* Sets the cancellation state of this event
*
* <p>
* Canceling this event will prevent the player from showing cosmetics
* </p>
*
* @param cancel true if you wish to cancel this event
*/
@Override
public void setCancelled(boolean cancel) {
this.cancel = cancel;
}
@Override
@NotNull
public HandlerList getHandlers() {
return handlers;
public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}
@NotNull
public static HandlerList getHandlerList() {
return handlers;
public static @NotNull HandlerList getHandlerList() {
return HANDLER_LIST;
}
}

View File

@@ -6,23 +6,27 @@ import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/**
* Called when a player starts playing an emote
* Called when a player starts playing an emote.
*/
public class PlayerEmoteStartEvent extends PlayerCosmeticEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancel = false;
private 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
* Gets the animation id of the emote the player started playing.
*
* @return The animation id of the emote which 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() {
@@ -34,28 +38,17 @@ public class PlayerEmoteStartEvent extends PlayerCosmeticEvent implements Cancel
return cancel;
}
/**
* Sets the cancellation state of this event
*
* <p>
* Canceling this event will prevent the player from playing the emote
* </p>
*
* @param cancel true if you wish to cancel this event
*/
@Override
public void setCancelled(boolean cancel) {
this.cancel = cancel;
}
@Override
@NotNull
public HandlerList getHandlers() {
return handlers;
public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}
@NotNull
public static HandlerList getHandlerList() {
return handlers;
public static @NotNull HandlerList getHandlerList() {
return HANDLER_LIST;
}
}

View File

@@ -7,13 +7,15 @@ import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/**
* Called when a player stops playing an emote
* Called when a player stops playing an emote.
*/
public class PlayerEmoteStopEvent extends PlayerCosmeticEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancel = false;
private 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;
@@ -25,20 +27,19 @@ public class PlayerEmoteStopEvent extends PlayerCosmeticEvent implements Cancell
* @return The {@link UserEmoteManager.StopEmoteReason} why the emote has stopped playing
* @deprecated As of release 2.2.5+, replaced by {@link #getReason()}
*/
@Deprecated
@Deprecated(forRemoval = true)
@NotNull
public UserEmoteManager.StopEmoteReason getStopEmoteReason() {
return reason;
}
/**
* Gets the {@link UserEmoteManager.StopEmoteReason} as to why the emote has stopped playing
* Gets the {@link UserEmoteManager.StopEmoteReason} as to why the emote has stopped playing.
*
* @return The {@link UserEmoteManager.StopEmoteReason} why the emote has stopped playing
* @return the reason why the emote has stopped playing
* @since 2.2.5
*/
@NotNull
public UserEmoteManager.StopEmoteReason getReason() {
public @NotNull UserEmoteManager.StopEmoteReason getReason() {
return reason;
}
@@ -47,28 +48,17 @@ public class PlayerEmoteStopEvent extends PlayerCosmeticEvent implements Cancell
return cancel;
}
/**
* Sets the cancellation state of this event
*
* <p>
* Canceling this event will prevent the player from stopping the emote
* </p>
*
* @param cancel true if you wish to cancel this event
*/
@Override
public void setCancelled(boolean cancel) {
this.cancel = cancel;
}
@Override
@NotNull
public HandlerList getHandlers() {
return handlers;
public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}
@NotNull
public static HandlerList getHandlerList() {
return handlers;
public static @NotNull HandlerList getHandlerList() {
return HANDLER_LIST;
}
}

View File

@@ -0,0 +1,26 @@
package com.hibiscusmc.hmccosmetics.api.events;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
/**
* Represents an event related to a {@link org.bukkit.entity.Player}.
*/
public abstract class PlayerEvent extends Event {
protected final UUID player;
public PlayerEvent(@NotNull UUID uuid) {
this.player = uuid;
}
/**
* Returns the {@link UUID} of the player involved in this event.
*
* @return the UUID of the player who is involved in this event
*/
public final @NotNull UUID getUniqueId() {
return player;
}
}

View File

@@ -0,0 +1,25 @@
package com.hibiscusmc.hmccosmetics.api.events;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/**
* Called when a player's cosmetic data is loaded.
*/
public class PlayerLoadEvent extends PlayerCosmeticEvent {
private static final HandlerList HANDLER_LIST = new HandlerList();
public PlayerLoadEvent(@NotNull CosmeticUser who) {
super(who);
}
@Override
public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}
public static @NotNull HandlerList getHandlerList() {
return HANDLER_LIST;
}
}

View File

@@ -3,26 +3,35 @@ package com.hibiscusmc.hmccosmetics.api.events;
import com.hibiscusmc.hmccosmetics.gui.Menu;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.event.HandlerList;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.jetbrains.annotations.NotNull;
/**
* Called when a menu is closed by a player
* Called when a {@link Menu} is closed by a player.
*/
public class PlayerMenuCloseEvent extends PlayerMenuEvent {
private static final HandlerList handlers = new HandlerList();
private static final HandlerList HANDLER_LIST = new HandlerList();
private final InventoryCloseEvent.Reason reason;
public PlayerMenuCloseEvent(@NotNull CosmeticUser who, @NotNull Menu menu) {
public PlayerMenuCloseEvent(@NotNull CosmeticUser who, @NotNull Menu menu, @NotNull InventoryCloseEvent.Reason reason) {
super(who, menu);
this.reason = reason;
}
/**
* Gets the {@link InventoryCloseEvent.Reason} why the menu was closed.
* @return The reason why the menu was closed.
*/
public InventoryCloseEvent.Reason getReason() {
return reason;
}
@Override
@NotNull
public HandlerList getHandlers() {
return handlers;
public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}
@NotNull
public static HandlerList getHandlerList() {
return handlers;
public static @NotNull HandlerList getHandlerList() {
return HANDLER_LIST;
}
}

View File

@@ -5,10 +5,10 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.jetbrains.annotations.NotNull;
/**
* Represents a menu related event
* Represents an event related to a player's interaction with a {@link Menu}.
*/
public abstract class PlayerMenuEvent extends PlayerCosmeticEvent {
protected Menu menu;
protected final Menu menu;
public PlayerMenuEvent(@NotNull CosmeticUser who, @NotNull Menu menu) {
super(who);
@@ -16,12 +16,11 @@ public abstract class PlayerMenuEvent extends PlayerCosmeticEvent {
}
/**
* Gets the {@link Menu} involved with this event
* Gets the {@link Menu} involved with this event.
*
* @return The {@link Menu} which is involved with the event
* @return the menu involved in this event
*/
@NotNull
public final Menu getMenu() {
public @NotNull final Menu getMenu() {
return menu;
}
}

View File

@@ -7,10 +7,11 @@ import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/**
* Called when a menu is opened by a player
* Called when a {@link Menu} is opened by a player.
*/
public class PlayerMenuOpenEvent extends PlayerMenuEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private static final HandlerList HANDLER_LIST = new HandlerList();
private boolean cancel = false;
public PlayerMenuOpenEvent(@NotNull CosmeticUser who, @NotNull Menu menu) {
@@ -22,28 +23,17 @@ public class PlayerMenuOpenEvent extends PlayerMenuEvent implements Cancellable
return cancel;
}
/**
* Sets the cancellation state of this event
*
* <p>
* Canceling this event will prevent the player from opening a {@link Menu}
* </p>
*
* @param cancel true if you wish to cancel this event
*/
@Override
public void setCancelled(boolean cancel) {
this.cancel = cancel;
}
@Override
@NotNull
public HandlerList getHandlers() {
return handlers;
public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}
@NotNull
public static HandlerList getHandlerList() {
return handlers;
public static @NotNull HandlerList getHandlerList() {
return HANDLER_LIST;
}
}

View File

@@ -0,0 +1,44 @@
package com.hibiscusmc.hmccosmetics.api.events;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
/**
* Called before a player's data is loaded into the plugin.
*
* <p>
* If this event is cancelled, the player's data will not be loaded,
* and the player will not be able to interact with the plugin.
* </p>
*/
public class PlayerPreLoadEvent extends PlayerEvent implements Cancellable {
private static final HandlerList HANDLER_LIST = new HandlerList();
private boolean cancelled = false;
public PlayerPreLoadEvent(@NotNull UUID id) {
super(id);
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
@Override
public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}
public static @NotNull HandlerList getHandlerList() {
return HANDLER_LIST;
}
}

View File

@@ -0,0 +1,25 @@
package com.hibiscusmc.hmccosmetics.api.events;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/**
* Called when a players data is unloaded from the plugin. This is called when a player leaves the server.
*/
public class PlayerUnloadEvent extends PlayerCosmeticEvent {
private static final HandlerList HANDLER_LIST = new HandlerList();
public PlayerUnloadEvent(@NotNull CosmeticUser who) {
super(who);
}
@Override
public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}
public static @NotNull HandlerList getHandlerList() {
return HANDLER_LIST;
}
}

View File

@@ -7,11 +7,13 @@ import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/**
* Called when a player enters their wardrobe
* Called when a player enters their {@link Wardrobe}.
*/
public class PlayerWardrobeEnterEvent extends PlayerCosmeticEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private static final HandlerList HANDLER_LIST = new HandlerList();
private boolean cancel = false;
private Wardrobe wardrobe;
public PlayerWardrobeEnterEvent(@NotNull CosmeticUser who, @NotNull Wardrobe wardrobe) {
@@ -19,41 +21,38 @@ public class PlayerWardrobeEnterEvent extends PlayerCosmeticEvent implements Can
this.wardrobe = wardrobe;
}
/**
* Get the {@link Wardrobe} the player is entering.
* @return The wardrobe being entered
*/
public Wardrobe getWardrobe() {
return wardrobe;
}
/**
* Set the {@link Wardrobe} the player is entering.
* @param wardrobe the wardrobe being entered
*/
public void setWardrobe(Wardrobe wardrobe) {
this.wardrobe = wardrobe;
}
@Override
public boolean isCancelled() {
return cancel;
}
/**
* Sets the cancellation state of this event
*
* <p>
* Canceling this event will prevent the player from entering their wardrobe
* </p>
*
* @param cancel true if you wish to cancel this event
*/
@Override
public void setCancelled(boolean cancel) {
this.cancel = cancel;
}
@Override
@NotNull
public HandlerList getHandlers() {
return handlers;
public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}
@NotNull
public static HandlerList getHandlerList() {
return handlers;
}
public void setWardrobe(Wardrobe wardrobe) {
this.wardrobe = wardrobe;
}
public Wardrobe getWardrobe() {
return wardrobe;
public static @NotNull HandlerList getHandlerList() {
return HANDLER_LIST;
}
}

View File

@@ -6,10 +6,11 @@ import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/**
* Called when a player leaves their wardrobe
* Called when a player leaves their {@link com.hibiscusmc.hmccosmetics.config.Wardrobe}.
*/
public class PlayerWardrobeLeaveEvent extends PlayerCosmeticEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private static final HandlerList HANDLER_LIST = new HandlerList();
private boolean cancel = false;
public PlayerWardrobeLeaveEvent(@NotNull CosmeticUser who) {
@@ -21,28 +22,17 @@ public class PlayerWardrobeLeaveEvent extends PlayerCosmeticEvent implements Can
return cancel;
}
/**
* Sets the cancellation state of this event
*
* <p>
* Canceling this event will prevent the player from leaving their wardrobe
* </p>
*
* @param cancel true if you wish to cancel this event
*/
@Override
public void setCancelled(boolean cancel) {
this.cancel = cancel;
}
@Override
@NotNull
public HandlerList getHandlers() {
return handlers;
public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}
@NotNull
public static HandlerList getHandlerList() {
return handlers;
public static @NotNull HandlerList getHandlerList() {
return HANDLER_LIST;
}
}

View File

@@ -1,5 +1,7 @@
package com.hibiscusmc.hmccosmetics.command;
import com.hibiscusmc.hmccolor.HMCColorConfig;
import com.hibiscusmc.hmccolor.HMCColorContextKt;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.config.Wardrobe;
@@ -17,7 +19,8 @@ import com.hibiscusmc.hmccosmetics.gui.special.DyeMenu;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.apache.commons.lang3.EnumUtils;
@@ -40,10 +43,14 @@ public class CosmeticCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String @NotNull [] args) {
boolean silent = false;
boolean console = false;
if (!(sender instanceof Player)) {
console = true;
}
if (args.length == 0) {
if (!(sender instanceof Player)) {
// Console
if (console) {
return true;
}
if (!sender.hasPermission("hmccosmetics.cmd.default")) {
@@ -104,7 +111,18 @@ public class CosmeticCommand implements CommandExecutor {
}
if (sender.hasPermission("hmccosmetics.cmd.apply.color")) {
if (args.length >= 4) color = ServerUtils.hex2Rgb(args[3]);
if (args.length >= 4) {
// TODO: Add sub-color support somehow... (and make this neater)
String textColor = args[3];
if (!textColor.contains("#") && Hooks.isActiveHook("HMCColor")) {
HMCColorConfig.Colors colors = HMCColorContextKt.getHmcColor().getConfig().getColors().get(textColor);
if (colors != null) {
color = colors.getBaseColor().getColor();
}
} else {
color = HMCCServerUtils.hex2Rgb(textColor);
}
}
}
if (args.length == 1) {
@@ -126,7 +144,7 @@ public class CosmeticCommand implements CommandExecutor {
CosmeticUser user = CosmeticUsers.getUser(player);
if (!user.canEquipCosmetic(cosmetic)) {
if (!user.canEquipCosmetic(cosmetic) && !console) {
if (!silent) MessagesUtil.sendMessage(player, "no-cosmetic-permission");
return true;
}
@@ -134,7 +152,7 @@ public class CosmeticCommand implements CommandExecutor {
TagResolver placeholders =
TagResolver.resolver(Placeholder.parsed("cosmetic", cosmetic.getId()),
TagResolver.resolver(Placeholder.parsed("player", player.getName())),
TagResolver.resolver(Placeholder.parsed("cosmeticslot", cosmetic.getSlot().name())));
TagResolver.resolver(Placeholder.parsed("cosmeticslot", cosmetic.getSlot().toString())));
if (!silent) MessagesUtil.sendMessage(player, "equip-cosmetic", placeholders);
@@ -169,11 +187,12 @@ public class CosmeticCommand implements CommandExecutor {
if (args[1].equalsIgnoreCase("all")) {
cosmeticSlots = user.getSlotsWithCosmetics();
} else {
if (!EnumUtils.isValidEnum(CosmeticSlot.class, args[1].toUpperCase())) {
String rawSlot = args[1].toUpperCase();
if (!CosmeticSlot.contains(rawSlot)) {
if (!silent) MessagesUtil.sendMessage(sender, "invalid-slot");
return true;
}
cosmeticSlots = Set.of(CosmeticSlot.valueOf(args[1].toUpperCase()));
cosmeticSlots = Set.of(CosmeticSlot.valueOf(rawSlot));
}
for (CosmeticSlot cosmeticSlot : cosmeticSlots) {
@@ -185,7 +204,7 @@ public class CosmeticCommand implements CommandExecutor {
TagResolver placeholders =
TagResolver.resolver(Placeholder.parsed("cosmetic", user.getCosmetic(cosmeticSlot).getId()),
TagResolver.resolver(Placeholder.parsed("player", player.getName())),
TagResolver.resolver(Placeholder.parsed("cosmeticslot", cosmeticSlot.name())));
TagResolver.resolver(Placeholder.parsed("cosmeticslot", cosmeticSlot.toString())));
if (!silent) MessagesUtil.sendMessage(player, "unequip-cosmetic", placeholders);
@@ -225,20 +244,24 @@ public class CosmeticCommand implements CommandExecutor {
CosmeticUser user = CosmeticUsers.getUser(player);
if (user.isInWardrobe()) {
user.leaveWardrobe();
user.leaveWardrobe(false);
} else {
user.enterWardrobe(false, wardrobe);
user.enterWardrobe(wardrobe, false);
}
return true;
}
// cosmetic menu exampleMenu playerName
case ("menu") -> {
if (args.length == 1) return true;
if (!sender.hasPermission("hmccosmetics.cmd.menu")) {
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
return true;
}
Menu menu = Menus.getMenu(args[1]);
Menu menu;
if (args.length == 1) {
menu = Menus.getDefaultMenu();
} else {
menu = Menus.getMenu(args[1]);
}
if (sender instanceof Player) player = ((Player) sender).getPlayer();
if (sender.hasPermission("hmccosmetics.cmd.menu.other")) {
@@ -262,7 +285,6 @@ public class CosmeticCommand implements CommandExecutor {
case ("dataclear") -> {
if (args.length == 1) return true;
OfflinePlayer selectedPlayer = Bukkit.getOfflinePlayer(args[1]);
if (selectedPlayer == null) return true;
if (!sender.hasPermission("hmccosmetics.cmd.dataclear") && !sender.isOp()) {
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
return true;
@@ -285,11 +307,12 @@ public class CosmeticCommand implements CommandExecutor {
return true;
}
if (!EnumUtils.isValidEnum(CosmeticSlot.class, args[1])) {
String rawSlot = args[1];
if (!CosmeticSlot.contains(rawSlot)) {
if (!silent) MessagesUtil.sendMessage(player, "invalid-slot");
return true;
}
CosmeticSlot slot = CosmeticSlot.valueOf(args[1]);
CosmeticSlot slot = CosmeticSlot.valueOf(rawSlot);
Cosmetic cosmetic = user.getCosmetic(slot);
if (args.length >= 3) {
@@ -297,7 +320,7 @@ public class CosmeticCommand implements CommandExecutor {
if (!silent) MessagesUtil.sendMessage(player, "invalid-color");
return true;
}
Color color = ServerUtils.hex2Rgb(args[2]);
Color color = HMCCServerUtils.hex2Rgb(args[2]);
if (color == null) {
if (!silent) MessagesUtil.sendMessage(player, "invalid-color");
return true;
@@ -321,7 +344,7 @@ public class CosmeticCommand implements CommandExecutor {
}
Wardrobe wardrobe = WardrobeSettings.getWardrobe(args[1]);
if (wardrobe == null) {
wardrobe = new Wardrobe(args[1], new WardrobeLocation(null, null, null), null, -1);
wardrobe = new Wardrobe(args[1], new WardrobeLocation(null, null, null), null, -1, null);
WardrobeSettings.addWardrobe(wardrobe);
//MessagesUtil.sendMessage(player, "no-wardrobes");
//return true;
@@ -334,7 +357,7 @@ public class CosmeticCommand implements CommandExecutor {
}
if (args[2].equalsIgnoreCase("viewerlocation")) {
WardrobeSettings.setViewerLocation(wardrobe, player.getLocation());
WardrobeSettings.setViewerLocation(wardrobe, player.getEyeLocation());
if (!silent) MessagesUtil.sendMessage(player, "set-wardrobe-viewing");
return true;
}
@@ -352,10 +375,15 @@ public class CosmeticCommand implements CommandExecutor {
return true;
}
if (args[2].equalsIgnoreCase("distance")) {
WardrobeSettings.setWardrobeDistance(wardrobe, Integer.valueOf(args[3]));
WardrobeSettings.setWardrobeDistance(wardrobe, Integer.parseInt(args[3]));
if (!silent) MessagesUtil.sendMessage(player, "set-wardrobe-distance");
return true;
}
if (args[2].equalsIgnoreCase("defaultmenu")) {
WardrobeSettings.setWardrobeDefaultMenu(wardrobe, args[3]);
if (!silent) MessagesUtil.sendMessage(player, "set-wardrobe-menu");
return true;
}
}
}
case ("dump") -> {
@@ -414,7 +442,7 @@ public class CosmeticCommand implements CommandExecutor {
CosmeticUser user = CosmeticUsers.getUser(player);
if (!silent) MessagesUtil.sendMessage(sender, "show-cosmetic");
user.showCosmetics();
user.showCosmetics(CosmeticUser.HiddenReason.COMMAND);
return true;
}
case ("debug") -> {
@@ -483,6 +511,63 @@ public class CosmeticCommand implements CommandExecutor {
user.getUserEmoteManager().playEmote(args[1]);
return true;
}
case "disableall" -> {
if (!sender.hasPermission("hmccosmetics.cmd.disableall")) {
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
return true;
}
if (args.length == 1) {
if (!silent) MessagesUtil.sendMessage(player, "not-enough-args");
return true;
}
if (args[1].equalsIgnoreCase("true")) {
Settings.setAllPlayersHidden(true);
for (CosmeticUser user : CosmeticUsers.values()) user.hideCosmetics(CosmeticUser.HiddenReason.DISABLED);
if (!silent) MessagesUtil.sendMessage(sender, "disabled-all");
} else if (args[1].equalsIgnoreCase("false")) {
Settings.setAllPlayersHidden(false);
for (CosmeticUser user : CosmeticUsers.values()) user.showCosmetics(CosmeticUser.HiddenReason.DISABLED);
if (!silent) MessagesUtil.sendMessage(sender, "enabled-all");
} else {
if (!silent) MessagesUtil.sendMessage(sender, "invalid-args");
}
return true;
}
case "hiddenreasons" -> {
if (!sender.hasPermission("hmccosmetics.cmd.hiddenreasons")) {
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
return true;
}
if (args.length >= 2) {
player = Bukkit.getPlayer(args[1]);
}
if (player == null) {
if (!silent) MessagesUtil.sendMessage(sender, "invalid-player");
return true;
}
CosmeticUser user = CosmeticUsers.getUser(player);
sender.sendMessage(user.getHiddenReasons().toString());
return true;
}
case "clearhiddenreasons" -> {
if (!sender.hasPermission("hmccosmetics.cmd.clearhiddenreasons")) {
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
return true;
}
if (args.length >= 2) {
player = Bukkit.getPlayer(args[1]);
}
if (player == null) {
if (!silent) MessagesUtil.sendMessage(sender, "invalid-player");
return true;
}
CosmeticUser user = CosmeticUsers.getUser(player);
user.clearHiddenReasons();
return true;
}
}
return true;
}

View File

@@ -1,5 +1,6 @@
package com.hibiscusmc.hmccosmetics.command;
import com.hibiscusmc.hmccolor.HMCColorContextKt;
import com.hibiscusmc.hmccosmetics.config.Wardrobe;
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
@@ -10,6 +11,7 @@ import com.hibiscusmc.hmccosmetics.gui.Menu;
import com.hibiscusmc.hmccosmetics.gui.Menus;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -44,12 +46,16 @@ public class CosmeticCommandTabComplete implements TabCompleter {
if (hasPermission(sender, "hmccosmetics.cmd.debug")) completions.add("debug");
if (hasPermission(sender, "hmccosmetics.cmd.emote")) completions.add("emote");
if (hasPermission(sender, "hmccosmetics.cmd.playemote")) completions.add("playemote");
if (hasPermission(sender, "hmccosmetics.cmd.disableall")) completions.add("disableall");
if (hasPermission(sender, "hmccosmetics.cmd.hiddenreasons")) completions.add("hiddenreasons");
if (hasPermission(sender, "hmccosmetics.cmd.clearhiddenreasons")) completions.add("clearhiddenreasons");
StringUtil.copyPartialMatches(args[0], completions, finalCompletions);
}
if (!(sender instanceof Player)) return completions;
CosmeticUser user = CosmeticUsers.getUser(((Player) sender).getUniqueId());
if (user == null) return completions; // User hasn't loaded in yet, can't do proper checks
if (args.length == 2) {
String subcommand = args[0].toLowerCase();
@@ -68,11 +74,15 @@ public class CosmeticCommandTabComplete implements TabCompleter {
if (menu.canOpen(user.getPlayer())) completions.add(menu.getId());
}
}
case "dataclear", "hide", "show", "emote" -> {
case "dataclear", "hide", "show", "emote", "hiddenreasons", "clearhiddenreasons" -> {
for (Player player : Bukkit.getOnlinePlayers()) {
completions.add(player.getName());
}
}
case "disableall" -> {
completions.add("true");
completions.add("false");
}
case "wardrobe" -> {
for (Wardrobe wardrobe : WardrobeSettings.getWardrobes()) {
if (wardrobe.hasPermission()) {
@@ -84,7 +94,7 @@ public class CosmeticCommandTabComplete implements TabCompleter {
}
case "dye" -> {
for (CosmeticSlot slot : user.getDyeableSlots()) {
completions.add(slot.name());
completions.add(slot.toString());
}
}
case "setwardrobesetting" -> {
@@ -113,6 +123,7 @@ public class CosmeticCommandTabComplete implements TabCompleter {
completions.add("leavelocation");
completions.add("permission");
completions.add("distance");
completions.add("defaultmenu");
}
}
StringUtil.copyPartialMatches(args[2], completions, finalCompletions);
@@ -122,8 +133,14 @@ public class CosmeticCommandTabComplete implements TabCompleter {
String subcommand = args[0].toLowerCase();
switch (subcommand) {
case "apply" -> {
if (Hooks.isActiveHook("HMCColor")) completions.addAll(HMCColorContextKt.getHmcColor().getConfig().getColors().keySet());
completions.add("#FFFFFF");
}
case "setwardrobesetting" -> {
if (args[2].equalsIgnoreCase("defaultmenu")) {
completions.addAll(Menus.getMenuNames());
}
}
}
StringUtil.copyPartialMatches(args[3], completions, finalCompletions);
}

View File

@@ -1,7 +1,7 @@
package com.hibiscusmc.hmccosmetics.config;
import lombok.Getter;
import org.spongepowered.configurate.ConfigurationNode;
import me.lojosho.shaded.configurate.ConfigurationNode;
public class DatabaseSettings {

View File

@@ -3,10 +3,14 @@ package com.hibiscusmc.hmccosmetics.config;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import lombok.Getter;
import lombok.Setter;
import me.lojosho.shaded.configurate.ConfigurationNode;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.util.Vector;
import org.spongepowered.configurate.ConfigurationNode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
public class Settings {
@@ -26,26 +30,34 @@ public class Settings {
private static final String UNAPPLY_DEATH_PATH = "unapply-on-death";
private static final String FORCE_PERMISSION_JOIN_PATH = "force-permission-join";
private static final String FORCE_SHOW_COSMETICS_PATH = "force-show-join";
private static final String ITEM_PROCESSING_PATH = "item-processing";
private static final String ITEM_PROCESS_DISPLAY_NAME_PATH = "display-name";
private static final String ITEM_PROCESS_LORE_PATH = "lore";
private static final String DISABLED_GAMEMODE_PATH = "disabled-gamemode";
private static final String DISABLED_GAMEMODE_GAMEMODES_PATH = "gamemodes";
private static final String 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";
private static final String HOOK_RELOAD_CHANGE_PATH = "reload-on-change";
private static final String HOOK_WORLDGUARD_PATH = "worldguard";
private static final String HOOK_WG_MOVE_CHECK_PATH = "player-move-check";
private static final String HOOK_WG_MOVE_CHECK_PATH_LEGACY = "player_move_check";
private static final String COSMETIC_EMOTE_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_ADD_ENCHANTS_HELMET_PATH = "helmet-add-enchantments";
private static final String COSMETIC_ADD_ENCHANTS_CHESTPLATE_PATH = "chest-add-enchantments";
private static final String COSMETIC_ADD_ENCHANTS_LEGGINGS_PATH = "leggings-add-enchantments";
private static final String COSMETIC_ADD_ENCHANTS_BOOTS_PATH = "boots-add-enchantments";
private static final String COSMETIC_DESTROY_LOOSE_COSMETIC_PATH = "destroy-loose-cosmetics";
private static final String COSMETIC_BALLOON_HEAD_FORWARD_PATH = "balloon-head-forward";
private static final String MENU_SETTINGS_PATH = "menu-settings";
private static final String MENU_CLICK_COOLDOWN_PATH = "click-cooldown";
private static final String MENU_CLICK_COOLDOWN_TIME_PATH = "time";
private static final String COSMETIC_TYPE_SETTINGS_PATH = "cosmetic-type";
private static final String EQUIP_CLICK_TYPE = "equip-click";
private static final String UNEQUIP_CLICK_TYPE = "unequip-click";
@@ -59,6 +71,10 @@ public class Settings {
private static final String EQUIPABLE_COSMETIC_COLOR_PATH = "equipable-cosmetic-color";
private static final String LOCKED_COSMETIC_COLOR_PATH = "locked-cosmetic-color";
private static final String ENABLED_PATH = "enabled";
private static final String SLOT_OPTIONS_PATH = "slot-options";
private static final String BACKPACK_PREVENT_DARKNESS_PATH = "backpack-prevent-darkness";
private static final String BETTER_HUD_PATH = "betterhud";
private static final String BETTER_HUD_HIDE_IN_WARDROBE_PATH = "wardrobe-hide";
@Getter
private static String defaultMenu;
@@ -79,19 +95,18 @@ public class Settings {
@Getter
private static boolean forceShowOnJoin;
@Getter
private static boolean itemProcessingDisplayName;
@Getter
private static boolean itemProcessingLore;
@Getter
private static boolean itemsAdderChangeReload;
@Getter
private static boolean nexoChangeReload;
@Getter
private static boolean worldGuardMoveCheck;
@Getter
private static boolean cosmeticEmoteBlockCheck;
@Getter
private static boolean addHelmetEnchants;
@Getter
private static boolean addChestplateEnchants;
@Getter
private static boolean addLeggingEnchants;
@Getter
private static boolean addBootsEnchants;
private static final HashMap<EquipmentSlot, SlotOptionConfig> slotOptions = new HashMap<>();
@Getter
private static boolean emoteAirCheck;
@Getter
@@ -103,10 +118,28 @@ public class Settings {
@Getter
private static boolean backpackForceRidingEnabled;
@Getter
private static boolean emotesEnabled;
@Getter
private static boolean disabledGamemodesEnabled;
@Getter
private static boolean balloonHeadForward;
@Getter
private static boolean backpackPreventDarkness;
@Getter
private static List<String> disabledGamemodes;
@Getter
private static List<String> disabledWorlds;
@Getter
private static int viewDistance;
@Getter
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;
@@ -136,6 +169,10 @@ public class Settings {
private static boolean emoteCameraEnabled;
@Getter
private static boolean emoteMoveCheck;
@Getter @Setter
private static boolean allPlayersHidden;
@Getter
private static boolean wardrobeHideHud;
public static void load(ConfigurationNode source) {
@@ -155,9 +192,24 @@ public class Settings {
ConfigurationNode cosmeticSettings = source.node(COSMETIC_SETTINGS_PATH);
ConfigurationNode disabledGamemodeSettings = cosmeticSettings.node(DISABLED_GAMEMODE_PATH);
disabledGamemodesEnabled = disabledGamemodeSettings.node(ENABLED_PATH).getBoolean(true);
try {
disabledGamemodes = disabledGamemodeSettings.node(DISABLED_GAMEMODE_GAMEMODES_PATH).getList(String.class);
disabledWorlds = cosmeticSettings.node(COSMETIC_DISABLED_WORLDS_PATH).getList(String.class);
} catch (Exception e) {
disabledGamemodes = new ArrayList<>();
disabledWorlds = new ArrayList<>();
}
ConfigurationNode itemProcessingSettings = cosmeticSettings.node(ITEM_PROCESSING_PATH);
itemProcessingDisplayName = itemProcessingSettings.node(ITEM_PROCESS_DISPLAY_NAME_PATH).getBoolean(true);
itemProcessingLore = itemProcessingSettings.node(ITEM_PROCESS_LORE_PATH).getBoolean(true);
unapplyOnDeath = cosmeticSettings.node(UNAPPLY_DEATH_PATH).getBoolean(false);
forcePermissionJoin = cosmeticSettings.node(FORCE_PERMISSION_JOIN_PATH).getBoolean(false);
forceShowOnJoin = cosmeticSettings.node(FORCE_SHOW_COSMETICS_PATH).getBoolean(false);
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);
@@ -165,17 +217,32 @@ public class Settings {
emoteInvincible = cosmeticSettings.node(COSMETIC_EMOTE_INVINCIBLE_PATH).getBoolean(false);
destroyLooseCosmetics = cosmeticSettings.node(COSMETIC_DESTROY_LOOSE_COSMETIC_PATH).getBoolean(false);
backpackForceRidingEnabled = cosmeticSettings.node(COSMETIC_BACKPACK_FORCE_RIDING_PACKET_PATH).getBoolean(false);
addHelmetEnchants = cosmeticSettings.node(COSMETIC_ADD_ENCHANTS_HELMET_PATH).getBoolean(false);
addChestplateEnchants = cosmeticSettings.node(COSMETIC_ADD_ENCHANTS_CHESTPLATE_PATH).getBoolean(false);
addLeggingEnchants = cosmeticSettings.node(COSMETIC_ADD_ENCHANTS_LEGGINGS_PATH).getBoolean(false);
addBootsEnchants = cosmeticSettings.node(COSMETIC_ADD_ENCHANTS_BOOTS_PATH).getBoolean(false);
cosmeticSettings.node(SLOT_OPTIONS_PATH).childrenMap().forEach((key, value) -> {
EquipmentSlot slot = convertConfigToEquipment(key.toString().toLowerCase());
if (slot == null) {
MessagesUtil.sendDebugMessages("Invalid slot option: " + key, Level.WARNING);
return;
}
boolean addEnchantments = value.node("add-enchantments").getBoolean(false);
boolean requireEmpty = value.node("require-empty").getBoolean(false);
slotOptions.put(slot, new SlotOptionConfig(slot, addEnchantments, requireEmpty));
});
tickPeriod = cosmeticSettings.node(TICK_PERIOD_PATH).getInt(-1);
viewDistance = cosmeticSettings.node(VIEW_DISTANCE_PATH).getInt(-3);
emoteCameraEnabled = cosmeticSettings.node(COSMETIC_EMOTE_CAMERA_PATH).getBoolean(true);
emoteMoveCheck = cosmeticSettings.node(COSMETIC_EMOTE_MOVE_CHECK_PATH).getBoolean(false);
packetEntityTeleportCooldown = cosmeticSettings.node(COSMETIC_PACKET_ENTITY_TELEPORT_COOLDOWN_PATH).getInt(-1);
balloonHeadForward = cosmeticSettings.node(COSMETIC_BALLOON_HEAD_FORWARD_PATH).getBoolean(false);
backpackPreventDarkness = cosmeticSettings.node(BACKPACK_PREVENT_DARKNESS_PATH).getBoolean(true);
ConfigurationNode menuSettings = source.node(MENU_SETTINGS_PATH);
ConfigurationNode clickCooldownSettings = menuSettings.node(MENU_CLICK_COOLDOWN_PATH);
menuClickCooldown = clickCooldownSettings.node(ENABLED_PATH).getBoolean(true);
defaultMenuCooldown = clickCooldownSettings.node(MENU_CLICK_COOLDOWN_TIME_PATH).getLong(1000L);
ConfigurationNode shadingSettings = menuSettings.node(SHADING_PATH);
defaultShading = shadingSettings.node(ENABLED_PATH).getBoolean();
firstRowShift = shadingSettings.node(FIRST_ROW_SHIFT_PATH).getString();
@@ -201,9 +268,16 @@ public class Settings {
dyeMenuOutputSlot = dyeMenuSettings.node(DYE_MENU_OUTPUT_SLOT).getInt(25);
ConfigurationNode hookSettings = source.node(HOOK_SETTING_PATH);
ConfigurationNode itemsAdderSettings = hookSettings.node(HOOK_ITEMADDER_PATH);
itemsAdderChangeReload = itemsAdderSettings.node(HOOK_RELOAD_CHANGE_PATH).getBoolean(false);
ConfigurationNode nexoSettings = hookSettings.node(HOOK_NEXO_PATH);
nexoChangeReload = nexoSettings.node(HOOK_RELOAD_CHANGE_PATH).getBoolean(true);
ConfigurationNode betterHudSettings = hookSettings.node(BETTER_HUD_PATH);
wardrobeHideHud = betterHudSettings.node(BETTER_HUD_HIDE_IN_WARDROBE_PATH).getBoolean(true);
ConfigurationNode worldGuardSettings = hookSettings.node(HOOK_WORLDGUARD_PATH);
worldGuardMoveCheck = worldGuardSettings.node(HOOK_WG_MOVE_CHECK_PATH).getBoolean(true);
// I messed up in release 2.2.6 and forgot to change player_move_check to player-move-check.
@@ -217,24 +291,9 @@ public class Settings {
return new Vector(config.node("x").getDouble(), config.node("y").getDouble(), config.node("z").getDouble());
}
public static boolean getShouldAddEnchants(EquipmentSlot slot) {
switch (slot) {
case HEAD -> {
return addHelmetEnchants;
}
case CHEST -> {
return addChestplateEnchants;
}
case LEGS -> {
return addLeggingEnchants;
}
case FEET -> {
return addBootsEnchants;
}
default -> {
return false;
}
}
public static SlotOptionConfig getSlotOption(EquipmentSlot slot) {
if (!slotOptions.containsKey(slot)) slotOptions.put(slot, new SlotOptionConfig(slot, false, false));
return slotOptions.get(slot);
}
public static void setDebugMode(boolean newSetting) {
@@ -246,4 +305,16 @@ public class Settings {
plugin.saveConfig();
}
private static EquipmentSlot convertConfigToEquipment(String slot) {
return switch (slot) {
case "helmet" -> EquipmentSlot.HEAD;
case "chestplate" -> EquipmentSlot.CHEST;
case "leggings" -> EquipmentSlot.LEGS;
case "boots" -> EquipmentSlot.FEET;
case "offhand" -> EquipmentSlot.OFF_HAND;
case "mainhand" -> EquipmentSlot.HAND;
default -> null;
};
}
}

View File

@@ -0,0 +1,20 @@
package com.hibiscusmc.hmccosmetics.config;
import lombok.Getter;
import org.bukkit.inventory.EquipmentSlot;
public class SlotOptionConfig {
@Getter
private final EquipmentSlot slot;
@Getter
private final boolean addEnchantments;
@Getter
private final boolean requireEmpty;
public SlotOptionConfig(EquipmentSlot slot, boolean addEnchantments, boolean requireEmpty) {
this.slot = slot;
this.addEnchantments = addEnchantments;
this.requireEmpty = requireEmpty;
}
}

View File

@@ -1,60 +1,60 @@
package com.hibiscusmc.hmccosmetics.config;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Location;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
public class Wardrobe {
private String id;
private int distance = WardrobeSettings.getDisplayRadius();
@Getter
private final String id;
@Getter @Setter
private int distance;
@Getter @Setter @Nullable
private String permission;
@Getter @Setter
private WardrobeLocation location;
@Getter @Setter @Nullable
private String defaultMenu;
public Wardrobe(String id, WardrobeLocation location, @Nullable String permission, int distance) {
/**
* This creates a Wardrobe object with all the information that a user will need when entering.
* @param id The id of the wardrobe
* @param location The 3 locations of the Wardrobe, if any of these 3 locations are null, the wardrobe will not work
* @param permission The permission required to enter the wardrobe, if null, no permission is required
* @param distance The distance from the wardrobe that the player can be to enter, if -1, the player can enter from any distance
* @param defaultMenu The default menu that the player will open when entering the wardrobe.
*/
public Wardrobe(@NotNull String id, @NotNull WardrobeLocation location, @Nullable String permission, int distance, @Nullable String defaultMenu) {
this.id = id;
this.location = location;
if (permission != null) this.permission = permission;
if (distance != -1) this.distance = distance;
}
public String getId() {
return id;
}
public WardrobeLocation getLocation() {
return location;
}
public void setDistance(int distance) {
this.distance = distance;
if (permission != null) this.permission = permission;
if (defaultMenu != null) this.defaultMenu = defaultMenu;
}
public void setPermission(String permission) {
this.permission = permission;
}
/**
* This checks if the wardrobe has a permission. If it's null, no permission is required and will return false. If it's not null, it will return true.
* @return if the wardrobe has a permission
*/
public boolean hasPermission() {
return permission != null;
}
public int getDistance() {
return distance;
}
public String getPermission() {
return permission;
}
public void setLocation(WardrobeLocation location) {
this.location = location;
}
public boolean canEnter(CosmeticUser user) {
/**
* Calculates if a player can enter a wardrobe. Will return true if the player can enter, else false.
* @param user The user that is trying to enter the wardrobe
* @return if the player can enter the wardrobe
*/
public boolean canEnter(@NotNull CosmeticUser user) {
Location wardrobeLocation = location.getNpcLocation();
Location location = user.getEntity().getLocation();
if (wardrobeLocation == null) return false;
if (distance == -1) return true;
if (distance <= 0) return true;
if (!wardrobeLocation.getWorld().equals(location.getWorld())) return false;
return wardrobeLocation.distanceSquared(location) <= distance * distance;
}

View File

@@ -1,37 +1,36 @@
package com.hibiscusmc.hmccosmetics.config;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Location;
import org.jetbrains.annotations.Nullable;
public class WardrobeLocation {
@Setter
@Getter @Setter
private Location npcLocation;
@Setter
@Getter @Setter
private Location viewerLocation;
@Setter
@Getter @Setter
private Location leaveLocation;
public WardrobeLocation(Location npcLocation, Location viewerLocation, Location leaveLocation) {
/**
* This creates a WardrobeLocation object with the 3 locations that are required for a wardrobe to work
* @param npcLocation The location of the NPC
* @param viewerLocation The location of the viewer
* @param leaveLocation The location that the player will be teleported to when they leave the wardrobe if return-last-location in the config is false
*/
public WardrobeLocation(@Nullable Location npcLocation, @Nullable Location viewerLocation, @Nullable Location leaveLocation) {
this.npcLocation = npcLocation;
this.viewerLocation = viewerLocation;
this.leaveLocation = leaveLocation;
}
public Location getNpcLocation() {
return npcLocation.clone();
}
public Location getViewerLocation() {
return viewerLocation.clone();
}
public Location getLeaveLocation() {
return leaveLocation.clone();
}
/**
* Checks if any of the locations are null
* @return true if all locations are not null, else false
*/
public boolean hasAllLocations() {
if (npcLocation == null || viewerLocation == null || leaveLocation == null) return false;
return true;
return npcLocation != null && viewerLocation != null && leaveLocation != null;
}
}

View File

@@ -1,15 +1,14 @@
package com.hibiscusmc.hmccosmetics.config;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.serializer.LocationSerializer;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.misc.Utils;
import lombok.Getter;
import me.lojosho.hibiscuscommons.config.serializer.LocationSerializer;
import me.lojosho.shaded.configurate.ConfigurationNode;
import net.kyori.adventure.bossbar.BossBar;
import org.apache.commons.lang3.EnumUtils;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.spongepowered.configurate.ConfigurationNode;
import java.util.Collection;
import java.util.HashMap;
@@ -19,7 +18,6 @@ import java.util.logging.Level;
public class WardrobeSettings {
private static final String DISABLE_ON_DAMAGE_PATH = "disable-on-damage";
private static final String DISPLAY_RADIUS_PATH = "display-radius";
private static final String PORTABLE_PATH = "portable";
private static final String ALWAYS_DISPLAY_PATH = "always-display";
private static final String ROTATION_SPEED_PATH = "rotation-speed";
@@ -34,6 +32,8 @@ public class WardrobeSettings {
private static final String EQUIP_PUMPKIN_WARDROBE = "equip-pumpkin";
private static final String TRY_COSMETICS_WARDROBE = "unchecked-wardrobe-cosmetics";
private static final String RETURN_LAST_LOCATION = "return-last-location";
private static final String DAMAGE_KICK_PATH = "damage-kicked";
private static final String PREVENT_DAMAGE_PATH = "prevent-damage";
private static final String WARDROBE_MENU_OPTIONS = "menu-options";
private static final String WARDROBE_ENTER_OPEN_MENU_PATH = "enter-open-menu";
@@ -44,6 +44,7 @@ public class WardrobeSettings {
private static final String WARDROBES_PATH = "wardrobes";
private static final String PERMISSION_PATH = "permission";
private static final String DISTANCE_PATH = "distance";
private static final String WARDROBE_DEFAULT_MENU = "default-menu";
private static final String BOSSBAR_PATH = "bossbar";
private static final String BOSSBAR_ENABLE_PATH = "enabled";
private static final String BOSSBAR_TEXT_PATH = "text";
@@ -62,8 +63,6 @@ public class WardrobeSettings {
@Getter
private static boolean disableOnDamage;
@Getter
private static int displayRadius;
@Getter
private static boolean portable;
@Getter
private static boolean alwaysDisplay;
@@ -90,6 +89,10 @@ public class WardrobeSettings {
@Getter
private static boolean forceExitGamemode;
@Getter
private static boolean damagedKicked;
@Getter
private static boolean preventDamage;
@Getter
private static GameMode exitGamemode;
private static HashMap<String, Wardrobe> wardrobes;
@Getter
@@ -115,7 +118,6 @@ public class WardrobeSettings {
configRoot = source;
disableOnDamage = source.node(DISABLE_ON_DAMAGE_PATH).getBoolean();
displayRadius = source.node(DISPLAY_RADIUS_PATH).getInt();
portable = source.node(PORTABLE_PATH).getBoolean();
alwaysDisplay = source.node(ALWAYS_DISPLAY_PATH).getBoolean();
rotationSpeed = source.node(ROTATION_SPEED_PATH).getInt();
@@ -125,6 +127,8 @@ public class WardrobeSettings {
equipPumpkin = source.node(EQUIP_PUMPKIN_WARDROBE).getBoolean();
returnLastLocation = source.node(RETURN_LAST_LOCATION).getBoolean(false);
tryCosmeticsInWardrobe = source.node(TRY_COSMETICS_WARDROBE).getBoolean(false);
damagedKicked = source.node(DAMAGE_KICK_PATH).getBoolean(false);
preventDamage = source.node(PREVENT_DAMAGE_PATH).getBoolean(true);
ConfigurationNode menuOptionsNode = source.node(WARDROBE_MENU_OPTIONS);
enterOpenMenu = menuOptionsNode.node(WARDROBE_ENTER_OPEN_MENU_PATH).getBoolean(false);
@@ -165,16 +169,16 @@ public class WardrobeSettings {
MessagesUtil.sendDebugMessages("Wardrobe Location: " + npcLocation);
Location viewerLocation = LocationSerializer.INSTANCE.deserialize(Location.class, wardrobesNode.node(VIEWER_LOCATION_PATH));
MessagesUtil.sendDebugMessages("Viewer Location: " + viewerLocation);
Location leaveLocation = Utils.replaceIfNull(LocationSerializer.INSTANCE.deserialize(Location.class, wardrobesNode.node(LEAVE_LOCATION_PATH)), viewerLocation);
Location leaveLocation = LocationSerializer.INSTANCE.deserialize(Location.class, wardrobesNode.node(LEAVE_LOCATION_PATH));
if (leaveLocation == null) leaveLocation = viewerLocation;
MessagesUtil.sendDebugMessages("Leave Location: " + leaveLocation);
WardrobeLocation wardrobeLocation = new WardrobeLocation(npcLocation, viewerLocation, leaveLocation);
String permission = null;
int distance = -1;
if (!wardrobesNode.node(PERMISSION_PATH).virtual()) permission = wardrobesNode.node(PERMISSION_PATH).getString();
if (!wardrobesNode.node(DISTANCE_PATH).virtual()) distance = wardrobesNode.node(DISTANCE_PATH).getInt();
String permission = wardrobesNode.node(PERMISSION_PATH).getString();
String defaultMenu = wardrobesNode.node(WARDROBE_DEFAULT_MENU).getString();
int distance = wardrobesNode.node(DISTANCE_PATH).getInt(-1);
Wardrobe wardrobe = new Wardrobe(id, wardrobeLocation, permission, distance);
Wardrobe wardrobe = new Wardrobe(id, wardrobeLocation, permission, distance, defaultMenu);
addWardrobe(wardrobe);
} catch (Exception e) {
MessagesUtil.sendDebugMessages("Unable to create wardrobe " + id, Level.SEVERE);
@@ -278,4 +282,14 @@ public class WardrobeSettings {
plugin.saveConfig();
}
public static void setWardrobeDefaultMenu(Wardrobe wardrobe, String defaultMenu) {
wardrobe.setDefaultMenu(defaultMenu);
HMCCosmeticsPlugin plugin = HMCCosmeticsPlugin.getInstance();
plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".default-menu", defaultMenu);
plugin.saveConfig();
}
}

View File

@@ -1,165 +0,0 @@
package com.hibiscusmc.hmccosmetics.config.serializer;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
import com.hibiscusmc.hmccosmetics.util.builder.ColorBuilder;
import com.hibiscusmc.hmccosmetics.util.misc.StringUtils;
import com.hibiscusmc.hmccosmetics.util.misc.Utils;
import org.apache.commons.lang3.EnumUtils;
import org.bukkit.*;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.persistence.PersistentDataType;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.serialize.SerializationException;
import org.spongepowered.configurate.serialize.TypeSerializer;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.stream.Collectors;
public class ItemSerializer implements TypeSerializer<ItemStack> {
public static final ItemSerializer INSTANCE = new ItemSerializer();
private static final String MATERIAL = "material";
private static final String AMOUNT = "amount";
private static final String NAME = "name";
private static final String UNBREAKABLE = "unbreakable";
private static final String GLOWING = "glowing";
private static final String LORE = "lore";
private static final String MODEL_DATA = "model-data";
private static final String NBT_TAGS = "nbt-tag";
private static final String ENCHANTS = "enchants";
private static final String ITEM_FLAGS = "item-flags";
private static final String TEXTURE = "texture";
private static final String OWNER = "owner";
private static final String COLOR = "color";
private static final String RED = "red";
private static final String GREEN = "green";
private static final String BLUE = "blue";
private ItemSerializer() {
}
@Override
public ItemStack deserialize(final Type type, final ConfigurationNode source)
throws SerializationException {
final ConfigurationNode materialNode = source.node(MATERIAL);
final ConfigurationNode amountNode = source.node(AMOUNT);
final ConfigurationNode nameNode = source.node(NAME);
final ConfigurationNode unbreakableNode = source.node(UNBREAKABLE);
final ConfigurationNode glowingNode = source.node(GLOWING);
final ConfigurationNode loreNode = source.node(LORE);
final ConfigurationNode modelDataNode = source.node(MODEL_DATA);
final ConfigurationNode nbtNode = source.node(NBT_TAGS);
final ConfigurationNode enchantsNode = source.node(ENCHANTS);
final ConfigurationNode itemFlagsNode = source.node(ITEM_FLAGS);
final ConfigurationNode textureNode = source.node(TEXTURE);
final ConfigurationNode ownerNode = source.node(OWNER);
final ConfigurationNode colorNode = source.node(COLOR);
final ConfigurationNode redNode = colorNode.node(RED);
final ConfigurationNode greenNode = colorNode.node(GREEN);
final ConfigurationNode blueNode = colorNode.node(BLUE);
if (materialNode.virtual()) return null;
String material = materialNode.getString();
ItemStack item = Hooks.getItem(material);
if (item == null) {
HMCCosmeticsPlugin.getInstance().getLogger().severe("Invalid Material -> " + material);
return new ItemStack(Material.AIR);
}
item.setAmount(amountNode.getInt(1));
ItemMeta itemMeta = item.getItemMeta();
if (itemMeta == null) return item;
if (!nameNode.virtual())
itemMeta.setDisplayName(StringUtils.parseStringToString(Utils.replaceIfNull(nameNode.getString(), "")));
if (!unbreakableNode.virtual()) itemMeta.setUnbreakable(unbreakableNode.getBoolean());
if (!glowingNode.virtual()) {
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
itemMeta.addEnchant(Enchantment.LUCK, 1, true);
}
if (!loreNode.virtual()) itemMeta.setLore(Utils.replaceIfNull(loreNode.getList(String.class),
new ArrayList<String>()).
stream().map(StringUtils::parseStringToString).collect(Collectors.toList()));
if (!modelDataNode.virtual()) itemMeta.setCustomModelData(modelDataNode.getInt());
if (!nbtNode.virtual()) {
for (ConfigurationNode nbtNodes : nbtNode.childrenMap().values()) {
itemMeta.getPersistentDataContainer().set(NamespacedKey.minecraft(nbtNodes.key().toString()), PersistentDataType.STRING, nbtNodes.getString());
}
}
if (!enchantsNode.virtual()) {
for (ConfigurationNode enchantNode : enchantsNode.childrenMap().values()) {
if (Enchantment.getByKey(NamespacedKey.minecraft(enchantNode.key().toString())) == null) continue;
itemMeta.addEnchant(Enchantment.getByKey(NamespacedKey.minecraft(enchantNode.key().toString())), enchantNode.getInt(1), true);
}
}
try {
if (!itemFlagsNode.virtual()) {
for (String itemFlag : itemFlagsNode.getList(String.class)) {
if (!EnumUtils.isValidEnum(ItemFlag.class, itemFlag)) continue;
MessagesUtil.sendDebugMessages("Added " + itemFlag + " to the item!");
itemMeta.addItemFlags(ItemFlag.valueOf(itemFlag));
}
}
} catch (Exception e) {
e.printStackTrace();
}
if (item.getType() == Material.PLAYER_HEAD) {
SkullMeta skullMeta = (SkullMeta) itemMeta;
if (!ownerNode.virtual()) {
String ownerString = ownerNode.getString();
if (ownerString.contains("%")) {
// This means it has PAPI placeholders in it
skullMeta.getPersistentDataContainer().set(InventoryUtils.getSkullOwner(), PersistentDataType.STRING, ownerString);
}
OfflinePlayer player = Bukkit.getOfflinePlayer(ownerString);
skullMeta.setOwningPlayer(player);
}
if (!textureNode.virtual()) {
String textureString = textureNode.getString();
if (textureString.contains("%")) {
// This means it has PAPI placeholders in it
skullMeta.getPersistentDataContainer().set(InventoryUtils.getSkullTexture(), PersistentDataType.STRING, textureString);
}
Bukkit.getUnsafe().modifyItemStack(item, "{SkullOwner:{Id:[I;0,0,0,0],Properties:{textures:[{Value:\""
+ textureString + "\"}]}}}");
itemMeta = skullMeta;
}
}
if (!colorNode.virtual()) {
if (ColorBuilder.canBeColored(item.getType())) {
if (!redNode.virtual()) {
itemMeta = ColorBuilder.color(itemMeta, Color.fromRGB(redNode.getInt(0), greenNode.getInt(0), blueNode.getInt(0)));
} else {
itemMeta = ColorBuilder.color(itemMeta, ServerUtils.hex2Rgb(colorNode.getString("#FFFFFF")));
}
}
}
item.setItemMeta(itemMeta);
return item;
}
@Override
public void serialize(final Type type, @Nullable final ItemStack obj, final ConfigurationNode node) throws SerializationException {
}
}

View File

@@ -1,46 +0,0 @@
package com.hibiscusmc.hmccosmetics.config.serializer;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.serialize.SerializationException;
import org.spongepowered.configurate.serialize.TypeSerializer;
import java.lang.reflect.Type;
public class LocationSerializer implements TypeSerializer<Location> {
public static final LocationSerializer INSTANCE = new LocationSerializer();
private static final String WORLD = "world";
private static final String X = "x";
private static final String Y = "y";
private static final String Z = "z";
private static final String PITCH = "pitch";
private static final String YAW = "yaw";
private LocationSerializer() {}
@Override
@Nullable
public Location deserialize(final Type type, final ConfigurationNode source) throws SerializationException {
final World world = Bukkit.getWorld(source.node(WORLD).getString());
if (world == null) return null;
return new Location(
world,
source.node(X).getDouble(),
source.node(Y).getDouble(),
source.node(Z).getDouble(),
source.node(YAW).getFloat(),
source.node(PITCH).getFloat()
);
}
@Override
public void serialize(final Type type, @Nullable final Location loc, final ConfigurationNode source) throws SerializationException {
// Empty
}
}

View File

@@ -1,16 +1,16 @@
package com.hibiscusmc.hmccosmetics.cosmetic;
import com.hibiscusmc.hmccosmetics.config.serializer.ItemSerializer;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import lombok.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.Material;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.serialize.SerializationException;
import java.util.logging.Level;

View File

@@ -0,0 +1,74 @@
package com.hibiscusmc.hmccosmetics.cosmetic;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.cosmetic.types.*;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import lombok.extern.slf4j.Slf4j;
import me.lojosho.shaded.configurate.ConfigurationNode;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
import java.util.function.BiFunction;
/**
* Allow custom implementations of a {@link Cosmetic}.
*/
@Slf4j
public abstract class CosmeticProvider {
protected static final Map<CosmeticSlot, BiFunction<String, ConfigurationNode, Cosmetic>> MAPPINGS = Map.ofEntries(
Map.entry(CosmeticSlot.HELMET, CosmeticArmorType::new),
Map.entry(CosmeticSlot.CHESTPLATE, CosmeticArmorType::new),
Map.entry(CosmeticSlot.LEGGINGS, CosmeticArmorType::new),
Map.entry(CosmeticSlot.BOOTS, CosmeticArmorType::new),
Map.entry(CosmeticSlot.OFFHAND, CosmeticArmorType::new),
Map.entry(CosmeticSlot.MAINHAND, CosmeticMainhandType::new),
Map.entry(CosmeticSlot.BACKPACK, CosmeticBackpackType::new),
Map.entry(CosmeticSlot.BALLOON, CosmeticBalloonType::new),
Map.entry(CosmeticSlot.EMOTE, CosmeticEmoteType::new)
);
private static final String EXCEPTION_MESSAGE = "Unknown slot %s provided for mapping, if you registered your own CosmeticSlot please ensure that you've also registered a custom CosmeticProvider! Or if you have already registered a custom CosmeticProvider ensure it is registered in your plugins `onLoad` method instead of `onEnable`!";
/**
* Construct the {@link Cosmetic}.
* @param id the cosmetic id
* @param config the configuration node of the cosmetic
* @param slot the occupying slot of the cosmetic
* @return the {@link Cosmetic}
* @throws IllegalArgumentException if the provided cosmetic could not be mapped
*/
public @NotNull Cosmetic createCosmetic(String id, ConfigurationNode config, CosmeticSlot slot) throws IllegalArgumentException {
final var mapper = MAPPINGS.get(slot);
if(mapper == null) {
throw new IllegalArgumentException(
EXCEPTION_MESSAGE.formatted(slot)
);
}
return mapper.apply(id, config);
}
/**
* Represents the plugin that is providing this {@link CosmeticProvider}
* @return the plugin
*/
public abstract Plugin getProviderPlugin();
/**
* Default Implementation.
*/
static class Default extends CosmeticProvider {
public static final CosmeticProvider INSTANCE = new Default();
@Override
public Plugin getProviderPlugin() {
return HMCCosmeticsPlugin.getInstance();
}
}
}

View File

@@ -1,13 +1,82 @@
package com.hibiscusmc.hmccosmetics.cosmetic;
public enum CosmeticSlot {
HELMET,
CHESTPLATE,
LEGGINGS,
BOOTS,
MAINHAND,
OFFHAND,
BACKPACK,
BALLOON,
EMOTE
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@Getter
public class CosmeticSlot {
private static final ConcurrentHashMap<String, CosmeticSlot> REGISTRY = new ConcurrentHashMap<>();
public static final CosmeticSlot HELMET = register("HELMET");
public static final CosmeticSlot CHESTPLATE = register("CHESTPLATE");
public static final CosmeticSlot LEGGINGS = register("LEGGINGS");
public static final CosmeticSlot BOOTS = register("BOOTS");
public static final CosmeticSlot MAINHAND = register("MAINHAND");
public static final CosmeticSlot OFFHAND = register("OFFHAND");
public static final CosmeticSlot BACKPACK = register("BACKPACK");
public static final CosmeticSlot BALLOON = register("BALLOON");
public static final CosmeticSlot EMOTE = register("EMOTE");
private final String name;
private CosmeticSlot(@NotNull String name) {
this.name = name;
}
/**
* Registers a new slot with the given name. If a slot with the given name already exists, it will be returned.
* @param name The name of the slot (This will automatically be converted into all UPPERCASE)
* @return The slot that was registered or already exists.
* @throws IllegalArgumentException if a cosmetic slot by that name has already been registered
*/
@NotNull
public static CosmeticSlot register(@NotNull String name) {
final String upperName = name.toUpperCase();
if(REGISTRY.containsKey(upperName)) {
throw new IllegalArgumentException("A cosmetic slot with name '" + name + "' is already registered.");
}
final CosmeticSlot slot = new CosmeticSlot(upperName);
REGISTRY.put(upperName, slot);
return slot;
}
/**
* @return An unmodifiable map of all the slots that have been registered.
*/
@NotNull
public static Map<String, CosmeticSlot> values() {
return Collections.unmodifiableMap(REGISTRY);
}
/**
* Gets the slot with the given name.
* @param name The name of the slot to get. This is automatically converted to all UPPERCASE.
* @return The slot with the given name, or null if it does not exist.
*/
@Nullable
public static CosmeticSlot valueOf(@NotNull String name) {
final String upperName = name.toUpperCase();
return REGISTRY.get(upperName);
}
/**
* Checks if the registry contains a slot with the given name.
* @param name The name of the slot to check for. This is automatically converted to all UPPERCASE.
* @return True if the slot exists, false otherwise.
*/
public static boolean contains(@NotNull String name) {
final String upperName = name.toUpperCase();
return REGISTRY.containsKey(upperName);
}
@Override
public String toString() {
return name;
}
}

View File

@@ -2,17 +2,15 @@ package com.hibiscusmc.hmccosmetics.cosmetic;
import com.google.common.collect.HashBiMap;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.types.*;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.apache.commons.lang3.EnumUtils;
import lombok.extern.slf4j.Slf4j;
import me.lojosho.shaded.configurate.CommentedConfigurationNode;
import me.lojosho.shaded.configurate.ConfigurateException;
import me.lojosho.shaded.configurate.ConfigurationNode;
import me.lojosho.shaded.configurate.yaml.YamlConfigurationLoader;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.configurate.CommentedConfigurationNode;
import org.spongepowered.configurate.ConfigurateException;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
import java.io.File;
import java.nio.file.Files;
@@ -21,10 +19,12 @@ import java.util.Set;
import java.util.logging.Level;
import java.util.stream.Stream;
@Slf4j
public class Cosmetics {
private static final HashBiMap<String, Cosmetic> COSMETICS = HashBiMap.create();
private static CosmeticProvider PROVIDER = CosmeticProvider.Default.INSTANCE;
public static void addCosmetic(Cosmetic cosmetic) {
COSMETICS.put(cosmetic.getId(), cosmetic);
}
@@ -34,7 +34,7 @@ public class Cosmetics {
}
public static void removeCosmetic(Cosmetic cosmetic) {
COSMETICS.remove(cosmetic);
COSMETICS.remove(cosmetic.getId());
}
@Nullable
@@ -91,9 +91,33 @@ public class Cosmetics {
}
}
/**
* Register a custom {@link CosmeticProvider} to provide your own user implementation to
* be used and queried.
* @param provider the provider to register
* @throws IllegalArgumentException if the provider is already registered by another plugin
*/
public static void registerProvider(final CosmeticProvider provider) {
if(PROVIDER != CosmeticProvider.Default.INSTANCE) {
throw new IllegalArgumentException("CosmeticProvider already registered by %s, this conflicts with %s attempting to register their own.".formatted(
PROVIDER.getProviderPlugin().getName(),
provider.getProviderPlugin().getName()
));
}
PROVIDER = provider;
}
/**
* Fetch the current {@link CosmeticProvider} being used.
* @return the current {@link CosmeticProvider} being used
*/
public static CosmeticProvider getProvider() {
return PROVIDER;
}
private static void setupCosmetics(@NotNull CommentedConfigurationNode config) {
for (ConfigurationNode cosmeticConfig : config.childrenMap().values()) {
try {
String id = cosmeticConfig.key().toString();
MessagesUtil.sendDebugMessages("Attempting to add " + id);
ConfigurationNode slotNode = cosmeticConfig.node("slot");
@@ -101,19 +125,17 @@ public class Cosmetics {
MessagesUtil.sendDebugMessages("Unable to create " + id + " because there is no slot defined!", Level.WARNING);
continue;
}
if (!EnumUtils.isValidEnum(CosmeticSlot.class, slotNode.getString())) {
String slot = slotNode.getString("");
CosmeticSlot cosmeticSlot = CosmeticSlot.valueOf(slot);
if (cosmeticSlot == null) {
MessagesUtil.sendDebugMessages("Unable to create " + id + " because " + slotNode.getString() + " is not a valid slot!", Level.WARNING);
continue;
}
switch (CosmeticSlot.valueOf(cosmeticConfig.node("slot").getString())) {
case BALLOON -> new CosmeticBalloonType(id, cosmeticConfig);
case BACKPACK -> new CosmeticBackpackType(id, cosmeticConfig);
case MAINHAND -> new CosmeticMainhandType(id, cosmeticConfig);
case EMOTE -> new CosmeticEmoteType(id, cosmeticConfig);
default -> new CosmeticArmorType(id, cosmeticConfig);
}
} catch (Exception e) {
if (Settings.isDebugMode()) e.printStackTrace();
try {
addCosmetic(PROVIDER.createCosmetic(id, cosmeticConfig, cosmeticSlot));
} catch(Exception ex) {
log.error("Unable to construct cosmetic for {}, skipping processing it.", id, ex);
}
}
}

View File

@@ -2,17 +2,18 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
import me.lojosho.shaded.configurate.ConfigurationNode;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.configurate.ConfigurationNode;
public class CosmeticArmorType extends Cosmetic {
@@ -21,28 +22,42 @@ public class CosmeticArmorType extends Cosmetic {
public CosmeticArmorType(String id, ConfigurationNode config) {
super(id, config);
this.equipSlot = InventoryUtils.getEquipmentSlot(getSlot());
EquipmentSlot slot = HMCCInventoryUtils.getEquipmentSlot(getSlot());
if (slot == null) {
// Hypothetically it shouldn't be null, but it was happening on some random servers? Adding this just in case
throw new IllegalArgumentException("Invalid slot for cosmetic armor type: " + getSlot() + " in " + id + " cosmetic config.");
}
this.equipSlot = slot;
}
@Override
public void update(@NotNull CosmeticUser user) {
if (user.getUserEmoteManager().isPlayingEmote() || user.isInWardrobe()) return;
Entity entity = Bukkit.getEntity(user.getUniqueId());
if (entity == null) return;
if (user.getUserEmoteManager().isPlayingEmote()) return; // There has to be a better way of doing this...
ItemStack cosmeticItem = user.getUserCosmeticItem(this);
if (!(entity instanceof HumanEntity humanEntity)) return;
if (equipSlot.equals(EquipmentSlot.OFF_HAND)) {
if (!humanEntity.getInventory().getItemInOffHand().getType().isAir()) return;
if (Settings.getSlotOption(equipSlot).isRequireEmpty() && entity instanceof HumanEntity humanEntity) {
if (!humanEntity.getInventory().getItem(equipSlot).getType().isAir()) return;
}
ItemStack item = getItem(user);
if (item == null) return;
PacketManager.equipmentSlotUpdate(entity.getEntityId(), equipSlot, item, HMCCPacketManager.getViewers(entity.getLocation()));
}
public ItemStack getItem(@NotNull CosmeticUser user) {
return getItem(user, user.getUserCosmeticItem(this));
}
public ItemStack getItem(@NotNull CosmeticUser user, ItemStack cosmeticItem) {
if (!(user.getEntity() instanceof HumanEntity humanEntity)) return null;
if (Settings.getSlotOption(equipSlot).isAddEnchantments()) {
ItemStack equippedItem = humanEntity.getInventory().getItem(equipSlot);
if (Settings.getShouldAddEnchants(equipSlot)) {
cosmeticItem.addUnsafeEnchantments(equippedItem.getEnchantments());
}
NMSHandlers.getHandler().equipmentSlotUpdate(entity.getEntityId(), equipSlot, cosmeticItem, PacketManager.getViewers(entity.getLocation()));
//PacketManager.equipmentSlotUpdate(player, getSlot(), PacketManager.getViewers(player.getLocation())); Old method
// Basically, if force offhand is off AND there is no item in an offhand slot, then the equipment packet to add the cosmetic
return cosmeticItem;
}
@NotNull
public EquipmentSlot getEquipSlot() {
return this.equipSlot;
}

View File

@@ -2,11 +2,12 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import lombok.Getter;
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
import me.lojosho.shaded.configurate.ConfigurationNode;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
@@ -15,7 +16,6 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.configurate.ConfigurationNode;
import java.util.ArrayList;
import java.util.List;
@@ -24,8 +24,6 @@ import java.util.logging.Level;
public class CosmeticBackpackType extends Cosmetic {
@Getter
private final String modelName;
@Getter
private int height = -1;
private ItemStack firstPersonBackpack;
@@ -33,8 +31,6 @@ public class CosmeticBackpackType extends Cosmetic {
public CosmeticBackpackType(String id, ConfigurationNode config) {
super(id, config);
modelName = config.node("model").getString();
if (!config.node("firstperson-item").virtual()) {
this.firstPersonBackpack = generateItemStack(config.node("firstperson-item"));
this.height = config.node("height").getInt(5);
@@ -49,18 +45,22 @@ public class CosmeticBackpackType extends Cosmetic {
Location loc = entity.getLocation().clone().add(0, 2, 0);
if (user.isInWardrobe() || !user.isBackpackSpawned()) return;
// This needs to be moved to purely packet based, there are far to many plugin doing dumb stuff that prevents spawning armorstands ignoring our spawn reason.
if (user.isHidden()) {
// Sometimes the backpack is not despawned when the player is hidden (weird ass logic happening somewhere)
user.despawnBackpack();
return;
}
List<Player> outsideViewers = user.getUserBackpackManager().getEntityManager().refreshViewers(loc);
user.getUserBackpackManager().getEntityManager().teleport(loc);
user.getUserBackpackManager().getEntityManager().setRotation((int) loc.getYaw());
user.getUserBackpackManager().getEntityManager().setRotation((int) loc.getYaw(), isFirstPersonCompadible());
PacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), user.getUserBackpackManager().getFirstArmorStandId(), EntityType.ARMOR_STAND, UUID.randomUUID(), outsideViewers);
PacketManager.sendArmorstandMetadata(user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(this, getItem()), outsideViewers);
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()) PacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), user.getUserBackpackManager().getEntityManager().getViewers());
else PacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
if (Settings.isBackpackForceRidingEnabled()) HMCCPacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), user.getUserBackpackManager().getEntityManager().getViewers());
else HMCCPacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
if (!user.isInWardrobe() && isFirstPersonCompadible() && user.getPlayer() != null) {
List<Player> owner = List.of(user.getPlayer());
@@ -68,18 +68,18 @@ public class CosmeticBackpackType extends Cosmetic {
ArrayList<Integer> particleCloud = user.getUserBackpackManager().getAreaEffectEntityId();
for (int i = 0; i < particleCloud.size(); i++) {
if (i == 0) {
PacketManager.sendRidingPacket(entity.getEntityId(), particleCloud.get(i), owner);
HMCCPacketManager.sendRidingPacket(entity.getEntityId(), particleCloud.get(i), owner);
} else {
PacketManager.sendRidingPacket(particleCloud.get(i - 1), particleCloud.get(i) , owner);
HMCCPacketManager.sendRidingPacket(particleCloud.get(i - 1), particleCloud.get(i) , owner);
}
}
PacketManager.sendRidingPacket(particleCloud.get(particleCloud.size() - 1), user.getUserBackpackManager().getFirstArmorStandId(), owner);
if (!user.getHidden()) {
HMCCPacketManager.sendRidingPacket(particleCloud.get(particleCloud.size() - 1), user.getUserBackpackManager().getFirstArmorStandId(), owner);
if (!user.isHidden()) {
//if (loc.getPitch() < -70) NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, new ItemStack(Material.AIR), owner);
//else NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, firstPersonBackpack, owner);
NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(this, firstPersonBackpack), owner);
PacketManager.equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(this, firstPersonBackpack), owner);
}
MessagesUtil.sendDebugMessages("First Person Backpack Update[owner=" + user.getUniqueId() + ",player_location=" + loc + "]!", Level.INFO);
//MessagesUtil.sendDebugMessages("First Person Backpack Update[owner=" + user.getUniqueId() + ",player_location=" + loc + "]!", Level.INFO);
}
user.getUserBackpackManager().showBackpack();

View File

@@ -4,17 +4,16 @@ import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import lombok.Getter;
import me.lojosho.shaded.configurate.ConfigurationNode;
import me.lojosho.shaded.configurate.serialize.SerializationException;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.serialize.SerializationException;
import java.util.List;
@@ -69,12 +68,13 @@ public class CosmeticBalloonType extends Cosmetic {
Location newLocation = entity.getLocation();
Location currentLocation = user.getBalloonManager().getLocation();
newLocation = newLocation.clone().add(getBalloonOffset());
if (Settings.isBalloonHeadForward()) newLocation.setPitch(0);
List<Player> viewer = PacketManager.getViewers(entity.getLocation());
List<Player> viewer = HMCCPacketManager.getViewers(entity.getLocation());
if (entity.getLocation().getWorld() != userBalloonManager.getLocation().getWorld()) {
userBalloonManager.getModelEntity().teleport(newLocation);
PacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer);
HMCCPacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer);
return;
}
@@ -82,17 +82,16 @@ public class CosmeticBalloonType extends Cosmetic {
userBalloonManager.setVelocity(velocity.multiply(1.1));
userBalloonManager.setLocation(newLocation);
PacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer);
PacketManager.sendLeashPacket(userBalloonManager.getPufferfishBalloonId(), entity.getEntityId(), viewer);
if (user.getHidden()) {
HMCCPacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer);
HMCCPacketManager.sendLeashPacket(userBalloonManager.getPufferfishBalloonId(), entity.getEntityId(), viewer);
if (user.isHidden()) {
userBalloonManager.getPufferfish().hidePufferfish();
return;
}
if (!user.getHidden() && showLead) {
if (!user.isHidden() && showLead) {
List<Player> sendTo = userBalloonManager.getPufferfish().refreshViewers(newLocation);
if (sendTo.isEmpty()) return;
PacketManager.sendEntitySpawnPacket(newLocation, userBalloonManager.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager.getPufferfishBalloonUniqueId(), sendTo);
PacketManager.sendInvisibilityPacket(userBalloonManager.getPufferfishBalloonId(), sendTo);
user.getBalloonManager().getPufferfish().spawnPufferfish(newLocation, sendTo);
}
}

View File

@@ -3,8 +3,8 @@ 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;
import org.spongepowered.configurate.ConfigurationNode;
public class CosmeticEmoteType extends Cosmetic {

View File

@@ -2,11 +2,11 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import com.hibiscusmc.hmccosmetics.util.HMCCPlayerUtils;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import me.lojosho.shaded.configurate.ConfigurationNode;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.configurate.ConfigurationNode;
public class CosmeticMainhandType extends Cosmetic {
@@ -18,6 +18,6 @@ public class CosmeticMainhandType extends Cosmetic {
public void update(@NotNull CosmeticUser user) {
Player player = user.getPlayer();
PacketManager.equipmentSlotUpdate(player.getEntityId(), user, getSlot(), PlayerUtils.getNearbyPlayers(player));
HMCCPacketManager.equipmentSlotUpdate(player.getEntityId(), user, getSlot(), HMCCPacketManager.getViewers(player.getLocation()));
}
}

View File

@@ -3,6 +3,7 @@ package com.hibiscusmc.hmccosmetics.database;
import com.hibiscusmc.hmccosmetics.config.DatabaseSettings;
import com.hibiscusmc.hmccosmetics.database.types.Data;
import com.hibiscusmc.hmccosmetics.database.types.MySQLData;
import com.hibiscusmc.hmccosmetics.database.types.NoneData;
import com.hibiscusmc.hmccosmetics.database.types.SQLiteData;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
@@ -11,6 +12,8 @@ import lombok.Getter;
import org.bukkit.entity.Player;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;
public class Database {
@@ -18,18 +21,25 @@ public class Database {
private static Data data;
private static final MySQLData MYSQL_DATA = new MySQLData();
private static final SQLiteData SQLITE_DATA = new SQLiteData();
private static final NoneData NONE_DATA = new NoneData();
public Database() {
String databaseType = DatabaseSettings.getDatabaseType();
data = SQLITE_DATA; // default
if (databaseType.equalsIgnoreCase("MySQL")) {
data = SQLITE_DATA; // default to SQLite, then check if it's anything different
switch (databaseType.toLowerCase()) {
case "mysql":
data = MYSQL_DATA;
break;
case "sqlite":
// already the default
break;
case "none":
data = NONE_DATA;
MessagesUtil.sendDebugMessages("Database is set to none. Data will not be saved.", Level.WARNING);
break;
default:
MessagesUtil.sendDebugMessages("Invalid database type. Defaulting to SQLite.", Level.WARNING);
}
/* SQLite is the default database. Might change in the future, so keep code here in case.
if (databaseType.equalsIgnoreCase("sqlite")) {
data = SQLITE_DATA;
}
*/
MessagesUtil.sendDebugMessages("Database is " + data);
setup();
@@ -47,7 +57,7 @@ public class Database {
data.save(CosmeticUsers.getUser(player));
}
public static CosmeticUser get(UUID uniqueId) {
public static CompletableFuture<UserData> get(UUID uniqueId) {
return data.get(uniqueId);
}

View File

@@ -0,0 +1,37 @@
package com.hibiscusmc.hmccosmetics.database;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class UserData {
@Getter
private UUID owner;
@Setter
@Getter
private HashMap<CosmeticSlot, Map.Entry<Cosmetic, Integer>> cosmetics;
@Getter
private ArrayList<CosmeticUser.HiddenReason> hiddenReasons;
public UserData(UUID owner) {
this.owner = owner;
this.cosmetics = new HashMap<>();
this.hiddenReasons = new ArrayList<>();
}
public void addCosmetic(CosmeticSlot slot, Cosmetic cosmetic, Integer color) {
cosmetics.put(slot, Map.entry(cosmetic, color));
}
public void addHiddenReason(CosmeticUser.HiddenReason reason) {
hiddenReasons.add(reason);
}
}

View File

@@ -5,6 +5,7 @@ import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
import com.hibiscusmc.hmccosmetics.database.UserData;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.apache.commons.lang3.EnumUtils;
@@ -13,9 +14,8 @@ import org.bukkit.Color;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.CompletableFuture;
public abstract class Data {
@@ -24,7 +24,7 @@ public abstract class Data {
public abstract void save(CosmeticUser user);
@Nullable
public abstract CosmeticUser get(UUID uniqueId);
public abstract CompletableFuture<UserData> get(UUID uniqueId);
public abstract void clear(UUID uniqueId);
@@ -32,9 +32,9 @@ public abstract class Data {
@NotNull
public final String serializeData(@NotNull CosmeticUser user) {
StringBuilder data = new StringBuilder();
if (user.getHidden()) {
if (shouldHiddenSave(user.getHiddenReason())) {
data.append("HIDDEN=").append(user.getHiddenReason());
if (user.isHidden()) {
for (CosmeticUser.HiddenReason reason : user.getHiddenReasons()) {
if (shouldHiddenSave(reason)) data.append("HIDDEN=").append(reason);
}
}
for (Cosmetic cosmetic : user.getCosmetics()) {
@@ -50,15 +50,12 @@ public abstract class Data {
return data.toString();
}
public final Map<CosmeticSlot, Map<Cosmetic, Color>> deserializeData(CosmeticUser user, @NotNull String raw) {
return deserializeData(user, raw, Settings.isForcePermissionJoin());
}
@NotNull
public final Map<CosmeticSlot, Map<Cosmetic, Color>> deserializeData(CosmeticUser user, @NotNull String raw, boolean permissionCheck) {
Map<CosmeticSlot, Map<Cosmetic, Color>> cosmetics = new HashMap<>();
public final HashMap<CosmeticSlot, Map.Entry<Cosmetic, Integer>> deserializeData(@NotNull String raw) {
HashMap<CosmeticSlot, Map.Entry<Cosmetic, Integer>> cosmetics = new HashMap<>();
String[] rawData = raw.split(",");
ArrayList<CosmeticUser.HiddenReason> hiddenReason = new ArrayList<>();
for (String a : rawData) {
if (a == null || a.isEmpty()) continue;
String[] splitData = a.split("=");
@@ -68,9 +65,7 @@ public abstract class Data {
if (splitData[0].equalsIgnoreCase("HIDDEN")) {
if (EnumUtils.isValidEnum(CosmeticUser.HiddenReason.class, splitData[1])) {
if (Settings.isForceShowOnJoin()) continue;
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
user.hideCosmetics(CosmeticUser.HiddenReason.valueOf(splitData[1]));
});
hiddenReason.add(CosmeticUser.HiddenReason.valueOf(splitData[1]));
}
continue;
}
@@ -79,31 +74,20 @@ public abstract class Data {
String[] colorSplitData = splitData[1].split("&");
if (Cosmetics.hasCosmetic(colorSplitData[0])) cosmetic = Cosmetics.getCosmetic(colorSplitData[0]);
if (slot == null || cosmetic == null) continue;
if (permissionCheck && cosmetic.requiresPermission()) {
if (user.getPlayer() != null && !user.getPlayer().hasPermission(cosmetic.getPermission())) {
continue;
}
}
cosmetics.put(slot, Map.of(cosmetic, Color.fromRGB(Integer.parseInt(colorSplitData[1]))));
cosmetics.put(slot, Map.entry(cosmetic, Integer.parseInt(colorSplitData[1])));
} else {
if (Cosmetics.hasCosmetic(splitData[1])) cosmetic = Cosmetics.getCosmetic(splitData[1]);
if (slot == null || cosmetic == null) continue;
if (permissionCheck && cosmetic.requiresPermission()) {
if (user.getPlayer() != null && !user.getPlayer().hasPermission(cosmetic.getPermission())) {
continue;
}
}
HashMap<Cosmetic, Color> cosmeticColorHashMap = new HashMap<>();
cosmeticColorHashMap.put(cosmetic, null);
cosmetics.put(slot, cosmeticColorHashMap);
cosmetics.put(slot, Map.entry(cosmetic, -1));
}
}
return cosmetics;
}
private boolean shouldHiddenSave(CosmeticUser.HiddenReason reason) {
switch (reason) {
case EMOTE, NONE -> {
case EMOTE, NONE, GAMEMODE, WORLD, DISABLED -> {
return false;
}
default -> {

View File

@@ -13,6 +13,7 @@ import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Properties;
import java.util.UUID;
import java.util.logging.Level;
public class MySQLData extends SQLData {
@@ -59,12 +60,17 @@ public class MySQLData extends SQLData {
@Override
public void clear(UUID uniqueId) {
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
PreparedStatement preparedSt = null;
try {
PreparedStatement preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;");
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) {}
}
});
}
@@ -127,7 +133,14 @@ public class MySQLData extends SQLData {
public PreparedStatement preparedStatement(String query) {
PreparedStatement ps = null;
if (!isConnectionOpen()) MessagesUtil.sendDebugMessages("Connection is not open");
if (!isConnectionOpen()) {
MessagesUtil.sendDebugMessages("The MySQL database connection is not open (Could the database been idle for to long?). Reconnecting...", Level.WARNING);
try {
openConnection();
} catch (SQLException e) {
e.printStackTrace();
}
}
try {
if (connection == null) throw new NullPointerException("Connection is null");

View File

@@ -0,0 +1,30 @@
package com.hibiscusmc.hmccosmetics.database.types;
import com.hibiscusmc.hmccosmetics.database.UserData;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
public class NoneData extends Data {
@Override
public void setup() {
// Nothing
}
@Override
public void save(CosmeticUser user) {
// Nothing
}
@Override
public @Nullable CompletableFuture<UserData> get(UUID uniqueId) {
return CompletableFuture.completedFuture(new UserData(uniqueId));
}
@Override
public void clear(UUID uniqueId) {
// Nothing
}
}

View File

@@ -3,6 +3,7 @@ package com.hibiscusmc.hmccosmetics.database.types;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.database.UserData;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.Bukkit;
import org.bukkit.Color;
@@ -10,54 +11,58 @@ import org.bukkit.Color;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
public abstract class SQLData extends Data {
@Override
@SuppressWarnings({"resource"}) // Duplicate is from deprecated InternalData
public CosmeticUser get(UUID uniqueId) {
CosmeticUser user = new CosmeticUser(uniqueId);
public CompletableFuture<UserData> get(UUID uniqueId) {
return CompletableFuture.supplyAsync(() -> {
UserData data = new UserData(uniqueId);
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
PreparedStatement preparedStatement = null;
try {
PreparedStatement preparedStatement = preparedStatement("SELECT * FROM COSMETICDATABASE WHERE UUID = ?;");
preparedStatement = preparedStatement("SELECT * FROM COSMETICDATABASE WHERE UUID = ?;");
preparedStatement.setString(1, uniqueId.toString());
ResultSet rs = preparedStatement.executeQuery();
if (rs.next()) {
String rawData = rs.getString("COSMETICS");
Map<CosmeticSlot, Map<Cosmetic, Color>> cosmetics = deserializeData(user, rawData);
for (Map<Cosmetic, Color> cosmeticColors : cosmetics.values()) {
for (Cosmetic cosmetic : cosmeticColors.keySet()) {
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
// This can not be async.
user.addPlayerCosmetic(cosmetic, cosmeticColors.get(cosmetic));
});
}
}
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;
});
return user;
}
@Override
@SuppressWarnings("resource")
public void save(CosmeticUser user) {
Runnable run = () -> {
PreparedStatement preparedSt = null;
try {
PreparedStatement preparedSt = preparedStatement("REPLACE INTO COSMETICDATABASE(UUID,COSMETICS) VALUES(?,?);");
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.isDisable()) {
if (!HMCCosmeticsPlugin.getInstance().isDisabled()) {
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), run);
} else {
run.run();

View File

@@ -48,12 +48,17 @@ public class SQLiteData extends SQLData {
@SuppressWarnings("resource")
public void clear(UUID uniqueId) {
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
PreparedStatement preparedSt = null;
try {
PreparedStatement preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;");
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) {}
}
});
}

View File

@@ -1,35 +1,38 @@
package com.hibiscusmc.hmccosmetics.gui;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.api.events.PlayerMenuCloseEvent;
import com.hibiscusmc.hmccosmetics.api.events.PlayerMenuOpenEvent;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.config.serializer.ItemSerializer;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
import com.hibiscusmc.hmccosmetics.gui.type.Type;
import com.hibiscusmc.hmccosmetics.gui.type.Types;
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
import com.hibiscusmc.hmccosmetics.gui.type.types.TypeCosmetic;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.misc.Adventure;
import com.hibiscusmc.hmccosmetics.util.misc.StringUtils;
import dev.triumphteam.gui.builder.item.ItemBuilder;
import dev.triumphteam.gui.components.GuiType;
import dev.triumphteam.gui.components.InventoryProvider;
import dev.triumphteam.gui.guis.Gui;
import dev.triumphteam.gui.guis.GuiItem;
import lombok.Getter;
import me.lojosho.hibiscuscommons.config.serializer.ItemSerializer;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.hibiscuscommons.util.AdventureUtils;
import me.lojosho.hibiscuscommons.util.StringUtils;
import me.lojosho.shaded.configurate.ConfigurationNode;
import me.lojosho.shaded.configurate.serialize.SerializationException;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.serialize.SerializationException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
public class Menu {
@@ -41,10 +44,12 @@ public class Menu {
@Getter
private final int rows;
@Getter
private final Long cooldown;
@Getter
private final ConfigurationNode config;
@Getter
private final String permissionNode;
private final HashMap<Integer, MenuItem> items;
private final HashMap<Integer, List<MenuItem>> items;
@Getter
private final int refreshRate;
@Getter
@@ -56,6 +61,7 @@ public class Menu {
title = config.node("title").getString("chest");
rows = config.node("rows").getInt(1);
cooldown = config.node("click-cooldown").getLong(Settings.getDefaultMenuCooldown());
permissionNode = config.node("permission").getString("");
refreshRate = config.node("refresh-rate").getInt(-1);
shading = config.node("shading").getBoolean(Settings.isDefaultShading());
@@ -91,7 +97,8 @@ public class Menu {
try {
item = ItemSerializer.INSTANCE.deserialize(ItemStack.class, config.node("item"));
} catch (SerializationException e) {
throw new RuntimeException(e);
MessagesUtil.sendDebugMessages("Unable to get valid item for " + config.key().toString() + " " + e.getMessage());
continue;
}
if (item == null) {
@@ -99,6 +106,8 @@ public class Menu {
continue;
}
int priority = config.node("priority").getInt(1);
Type type = null;
if (!config.node("type").virtual()) {
@@ -107,7 +116,15 @@ public class Menu {
}
for (Integer slot : slots) {
items.put(slot, new MenuItem(slots, item, type, config));
MenuItem menuItem = new MenuItem(slots, item, type, priority, config);
if (items.containsKey(slot)) {
List<MenuItem> menuItems = items.get(slot);
menuItems.add(menuItem);
menuItems.sort(priorityCompare);
items.put(slot, menuItems);
} else {
items.put(slot, new ArrayList<>(Arrays.asList(menuItem)));
}
}
}
}
@@ -125,10 +142,12 @@ public class Menu {
return;
}
}
final Component component = Adventure.MINI_MESSAGE.deserialize(Hooks.processPlaceholders(player, this.title));
final Component component = AdventureUtils.MINI_MESSAGE.deserialize(Hooks.processPlaceholders(player, this.title));
Gui gui = Gui.gui()
.title(component)
.type(GuiType.CHEST)
.rows(this.rows)
.inventory((title, owner, rows) -> Bukkit.createInventory(owner, rows, title))
.create();
gui.setDefaultClickAction(event -> event.setCancelled(true));
@@ -151,6 +170,9 @@ public class Menu {
});
gui.setCloseGuiAction(event -> {
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());
});
@@ -188,10 +210,11 @@ public class Menu {
if (items.containsKey(i)) {
// Handles the items
MenuItem item = items.get(i);
updateItem(user, gui, item);
List<MenuItem> menuItems = items.get(i);
MenuItem item = menuItems.get(0);
updateItem(user, gui, i);
if (item.type().getId().equalsIgnoreCase("cosmetic")) {
if (item.type() instanceof TypeCosmetic) {
Cosmetic cosmetic = Cosmetics.getCosmetic(item.itemConfig().node("cosmetic").getString(""));
if (cosmetic == null) continue;
if (user.hasCosmeticInSlot(cosmetic)) {
@@ -215,26 +238,45 @@ public class Menu {
MessagesUtil.sendDebugMessages("Updated menu with title " + title);
gui.updateTitle(StringUtils.parseStringToString(Hooks.processPlaceholders(user.getPlayer(), title.toString())));
} else {
for (MenuItem item : items.values()) {
updateItem(user, gui, item);
for (int i = 0; i < gui.getInventory().getSize(); i++) {
if (items.containsKey(i)) {
updateItem(user, gui, i);
}
}
}
}
private void updateItem(CosmeticUser user, Gui gui, MenuItem item) {
private void updateItem(CosmeticUser user, 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();
for (int slot : item.slots()) {
ItemStack modifiedItem = getMenuItem(user, type, item.itemConfig(), item.item().clone(), slot);
if (modifiedItem.getType().isAir()) continue;
GuiItem guiItem = ItemBuilder.from(modifiedItem).asGuiItem();
guiItem.setAction(event -> {
MessagesUtil.sendDebugMessages("Selected slot " + slot);
UUID uuid = user.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");
return;
} else {
Menus.addCooldown(user.getUniqueId(), 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);
});
MessagesUtil.sendDebugMessages("Added " + slot + " as " + guiItem + " in the menu");
MessagesUtil.sendDebugMessages("Set an item in slot " + slot + " in the menu of " + getId());
gui.updateItem(slot, guiItem);
break;
}
}
@@ -275,4 +317,6 @@ public class Menu {
if (permissionNode.isEmpty()) return true;
return player.isOp() || player.hasPermission(permissionNode);
}
public static Comparator<MenuItem> priorityCompare = Comparator.comparing(MenuItem::priority).reversed();
}

View File

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

View File

@@ -3,31 +3,33 @@ package com.hibiscusmc.hmccosmetics.gui;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import lombok.Getter;
import lombok.Setter;
import me.lojosho.shaded.configurate.CommentedConfigurationNode;
import me.lojosho.shaded.configurate.ConfigurateException;
import me.lojosho.shaded.configurate.yaml.YamlConfigurationLoader;
import org.apache.commons.io.FilenameUtils;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.configurate.CommentedConfigurationNode;
import org.spongepowered.configurate.ConfigurateException;
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.*;
import java.util.logging.Level;
import java.util.stream.Stream;
public class Menus {
private static final HashMap<String, Menu> MENUS = new HashMap<>();
private static final HashMap<UUID, Long> COOLDOWNS = new HashMap<>();
public static void addMenu(Menu menu) {
public static void addMenu(@NotNull Menu menu) {
MENUS.put(menu.getId().toUpperCase(), menu);
}
@Nullable
public static Menu getMenu(@NotNull String id) {
return MENUS.get(id.toUpperCase());
}
@@ -42,11 +44,18 @@ public class Menus {
return MENUS.containsKey(id.toUpperCase());
}
public static boolean hasMenu(Menu menu) {
public static boolean hasMenu(@NotNull Menu menu) {
return MENUS.containsValue(menu);
}
public static Menu getDefaultMenu() { return Menus.getMenu(Settings.getDefaultMenu()); }
public static boolean hasDefaultMenu() {
return MENUS.containsKey(Settings.getDefaultMenu());
}
@Nullable
public static Menu getDefaultMenu() {
return Menus.getMenu(Settings.getDefaultMenu());
}
@NotNull
public static List<String> getMenuNames() {
@@ -63,8 +72,21 @@ public class Menus {
return MENUS.values();
}
public static void addCooldown(UUID uuid, long time) {
COOLDOWNS.put(uuid, time);
}
public static Long getCooldown(UUID uuid) {
return COOLDOWNS.getOrDefault(uuid, 0L);
}
public static void removeCooldown(UUID uuid) {
COOLDOWNS.remove(uuid);
}
public static void setup() {
MENUS.clear();
COOLDOWNS.clear();
File cosmeticFolder = new File(HMCCosmeticsPlugin.getInstance().getDataFolder() + "/menus");
if (!cosmeticFolder.exists()) cosmeticFolder.mkdir();

View File

@@ -3,7 +3,7 @@ package com.hibiscusmc.hmccosmetics.gui.action;
import com.hibiscusmc.hmccosmetics.gui.action.actions.*;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;

View File

@@ -2,8 +2,8 @@ package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;

View File

@@ -12,7 +12,7 @@ public class ActionCosmeticHide extends Action {
@Override
public void run(@NotNull CosmeticUser user, String raw) {
if (user.getHidden()) return;
if (user.isHidden()) return;
user.hideCosmetics(CosmeticUser.HiddenReason.ACTION);
}
}

View File

@@ -12,10 +12,10 @@ public class ActionCosmeticShow extends Action {
@Override
public void run(@NotNull CosmeticUser user, String raw) {
if (!user.getHidden()) return;
if (!user.isHidden()) return;
// Do not hide if it's already off for WG
if (user.getHiddenReason() != CosmeticUser.HiddenReason.ACTION && user.getHiddenReason() != CosmeticUser.HiddenReason.COMMAND) return;
user.showCosmetics();
if (!user.isHidden(CosmeticUser.HiddenReason.ACTION) && !user.isHidden(CosmeticUser.HiddenReason.COMMAND)) return;
user.showCosmetics(CosmeticUser.HiddenReason.ACTION);
}
}

View File

@@ -12,9 +12,9 @@ public class ActionCosmeticToggle extends Action {
@Override
public void run(@NotNull CosmeticUser user, String raw) {
if (user.getHidden()) {
if (user.getHiddenReason() != CosmeticUser.HiddenReason.ACTION && user.getHiddenReason() != CosmeticUser.HiddenReason.COMMAND) return;
user.showCosmetics();
if (user.isHidden()) {
if (!user.isHidden(CosmeticUser.HiddenReason.ACTION) && !user.isHidden(CosmeticUser.HiddenReason.COMMAND)) return;
user.showCosmetics(CosmeticUser.HiddenReason.ACTION);
return;
}

View File

@@ -3,8 +3,8 @@ package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import com.owen1212055.particlehelper.api.particle.types.BlockDataParticle;
import com.owen1212055.particlehelper.api.particle.types.DestinationParticle;
import com.owen1212055.particlehelper.api.particle.types.velocity.VelocityParticle;
@@ -42,9 +42,9 @@ public class ActionParticle extends Action {
return;
}
particle = ServerUtils.addParticleValues(particle, rawString);
particle = HMCCServerUtils.addParticleValues(particle, rawString);
Location location = user.getPlayer().getLocation();
for (Player player : PacketManager.getViewers(location)) {
for (Player player : HMCCPacketManager.getViewers(location)) {
particle.compile().send(player, location);
}
}

View File

@@ -3,6 +3,7 @@ package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import org.jetbrains.annotations.NotNull;
public class ActionPlayerCommand extends Action {
@@ -13,6 +14,6 @@ public class ActionPlayerCommand extends Action {
@Override
public void run(@NotNull CosmeticUser user, String raw) {
user.getPlayer().performCommand(MessagesUtil.processStringNoKeyString(user.getPlayer(), raw));
user.getPlayer().performCommand(MessagesUtil.processStringNoKeyString(user.getPlayer(), Hooks.processPlaceholders(user.getPlayer(), raw)));
}
}

View File

@@ -13,7 +13,7 @@ public class ActionUnequip extends Action {
@Override
public void run(CosmeticUser user, String raw) {
if (!EnumUtils.isValidEnum(CosmeticSlot.class, raw)) return;
if (!CosmeticSlot.contains(raw)) return;
CosmeticSlot slot = CosmeticSlot.valueOf(raw);
user.removeCosmeticSlot(slot);

View File

@@ -6,18 +6,16 @@ import com.hibiscusmc.hmccolor.shaded.gui.guis.GuiItem;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Material;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.hibiscuscommons.util.ColorBuilder;
import me.lojosho.hibiscuscommons.util.StringUtils;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.MapMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.inventory.meta.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class DyeMenu {
@@ -28,11 +26,11 @@ public class DyeMenu {
addCosmetic(user, cosmetic, null);
return;
}
ItemStack originalItem = user.getUserCosmeticItem(cosmetic);
ItemStack originalItem = cosmetic.getItem();
if (originalItem == null || !cosmetic.isDyable()) return;
Gui gui = HMCColorApi.INSTANCE.colorMenu();
gui.updateTitle(Hooks.processPlaceholders(player, Settings.getDyeMenuName()));
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()) {
@@ -41,9 +39,19 @@ public class DyeMenu {
ItemMeta meta = item.getItemMeta();
if (meta == null) return;
Color color = meta instanceof LeatherArmorMeta leatherMeta ? leatherMeta.getColor() :
meta instanceof PotionMeta potionMeta ? potionMeta.getColor() :
meta instanceof MapMeta mapMeta ? mapMeta.getColor() : null;
Color color = 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);
@@ -56,7 +64,7 @@ public class DyeMenu {
gui.open(player);
}
private static void addCosmetic(@NotNull CosmeticUser user, Cosmetic cosmetic, Color color) {
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));

View File

@@ -1,9 +1,9 @@
package com.hibiscusmc.hmccosmetics.gui.type;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import me.lojosho.shaded.configurate.ConfigurationNode;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.spongepowered.configurate.ConfigurationNode;
public abstract class Type {

View File

@@ -2,32 +2,37 @@ package com.hibiscusmc.hmccosmetics.gui.type.types;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.config.serializer.ItemSerializer;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
import com.hibiscusmc.hmccosmetics.gui.action.Actions;
import com.hibiscusmc.hmccosmetics.gui.special.DyeMenu;
import com.hibiscusmc.hmccosmetics.gui.type.Type;
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import me.lojosho.hibiscuscommons.config.serializer.ItemSerializer;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.shaded.configurate.ConfigurationNode;
import me.lojosho.shaded.configurate.serialize.SerializationException;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.serialize.SerializationException;
import java.util.ArrayList;
import java.util.List;
public class TypeCosmetic extends Type {
public TypeCosmetic(String id) {
super(id);
}
public TypeCosmetic() {
super("cosmetic");
}
@@ -123,8 +128,9 @@ public class TypeCosmetic extends Type {
}
@Override
public ItemStack setItem(CosmeticUser user, @NotNull ConfigurationNode config, ItemStack itemStack, int slot) {
itemStack.setItemMeta(processLoreLines(user, itemStack.getItemMeta()));
public ItemStack setItem(@NotNull CosmeticUser user, @NotNull ConfigurationNode config, @NotNull ItemStack itemStack, int slot) {
if (itemStack.hasItemMeta()) itemStack.setItemMeta(processLoreLines(user, itemStack.getItemMeta()));
else MessagesUtil.sendDebugMessages("ItemStack has no ItemMeta?");
if (config.node("cosmetic").virtual()) {
return itemStack;
@@ -135,9 +141,9 @@ public class TypeCosmetic extends Type {
return itemStack;
}
if (user.hasCosmeticInSlot(cosmetic) && !config.node("equipped-item").virtual()) {
if (user.hasCosmeticInSlot(cosmetic) && (!config.node("equipped-item").virtual() || !config.node("locked-equipped-item").virtual())) {
MessagesUtil.sendDebugMessages("GUI Equipped Item");
ConfigurationNode equippedItem = config.node("equipped-item");
ConfigurationNode equippedItem = config.node(user.canEquipCosmetic(cosmetic, true) && !config.node("equipped-item").virtual() ? "equipped-item" : "locked-equipped-item");
try {
if (equippedItem.node("material").virtual()) equippedItem.node("material").set(config.node("item", "material").getString());
} catch (SerializationException e) {
@@ -148,11 +154,12 @@ public class TypeCosmetic extends Type {
} catch (SerializationException e) {
throw new RuntimeException(e);
}
itemStack.setItemMeta(processLoreLines(user, itemStack.getItemMeta()));
if (itemStack.hasItemMeta()) itemStack.setItemMeta(processLoreLines(user, itemStack.getItemMeta()));
else MessagesUtil.sendDebugMessages("ItemStack has no ItemMeta in equipped item?");
return itemStack;
}
if (!user.canEquipCosmetic(cosmetic) && !config.node("locked-item").virtual()) {
if (!user.canEquipCosmetic(cosmetic, true) && !config.node("locked-item").virtual()) {
MessagesUtil.sendDebugMessages("GUI Locked Item");
ConfigurationNode lockedItem = config.node("locked-item");
try {
@@ -165,7 +172,8 @@ public class TypeCosmetic extends Type {
} catch (SerializationException e) {
throw new RuntimeException(e);
}
itemStack.setItemMeta(processLoreLines(user, itemStack.getItemMeta()));
if (itemStack.hasItemMeta()) itemStack.setItemMeta(processLoreLines(user, itemStack.getItemMeta()));
else MessagesUtil.sendDebugMessages("ItemStack has no ItemMeta in locked item?");
return itemStack;
}
return itemStack;
@@ -186,6 +194,12 @@ public class TypeCosmetic extends Type {
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

@@ -2,14 +2,15 @@ package com.hibiscusmc.hmccosmetics.gui.type.types;
import com.hibiscusmc.hmccosmetics.gui.action.Actions;
import com.hibiscusmc.hmccosmetics.gui.type.Type;
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.shaded.configurate.ConfigurationNode;
import me.lojosho.shaded.configurate.serialize.SerializationException;
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 org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.serialize.SerializationException;
import java.util.ArrayList;
import java.util.List;
@@ -72,6 +73,14 @@ public class TypeEmpty extends Type {
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);
return itemStack;
}

View File

@@ -1,93 +0,0 @@
package com.hibiscusmc.hmccosmetics.hooks;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Represents a hook into other minecraft plugins
*/
public abstract class Hook implements Listener {
private final String id;
private boolean active = false;
private boolean itemHook = false;
public Hook(@NotNull String id) {
this.id = id;
Hooks.addHook(this);
}
/**
* Loads this hook
*
* @implNote By default, this method does nothing. It should be overridden by child classes to implement any necessary loading logic
*/
public void load() { }
/**
* Gets an {@link ItemStack} that is associated with the provided id from the hooked plugin
* @param itemId The id of the {@link ItemStack}
* @return The {@link ItemStack} with the id provided. If an invalid id was provided or if the hook doesn't have any related {@link ItemStack}s then this will return null
* @implNote By default, this method returns null. It should be overridden by child classes if you will to have your hook return a related {@link ItemStack}
*/
@Nullable
public ItemStack getItem(@NotNull String itemId) {
return null;
}
/**
* Gets the id of this hook
*
* @return The unique id for this hook
*/
@NotNull
public final String getId() {
return id;
}
/**
* Gets whether this hook has been activated
* @return true if this hook is active, false otherwise
* @deprecated As of release 2.2.5+, replaced by {@link #isActive()}
*/
@Deprecated
public boolean getActive() {
return this.active;
}
/**
* Gets whether this hook has been activated
* @return true if this hook is active, false otherwise
* @since 2.2.5
*/
public final boolean isActive() {
return this.active;
}
/**
* Sets whether this hook is active
* @param active true to activate the hook, false otherwise
*/
public final void setActive(boolean active) {
this.active = active;
}
/**
* Whether the method {@link #getItem(String)} should return a non-null value
* @return true if {@link #getItem(String)} should return a non-null value, false otherwise
*
* @apiNote Even though this method returns true does not mean that {@link #getItem(String)} won't return null, rather if this returns false then {@link #getItem(String)} should return false everytime
*/
public final boolean hasEnabledItemHook() {
return itemHook;
}
/**
* Sets whether the method {@link #getItem(String)} should return a non-null value
* @param enabled true if {@link #getItem(String)} should return a non-null value, false otherwise
*/
public final void setEnabledItemHook(boolean enabled) {
itemHook = enabled;
}
}

View File

@@ -1,87 +0,0 @@
package com.hibiscusmc.hmccosmetics.hooks;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.hooks.items.*;
import com.hibiscusmc.hmccosmetics.hooks.misc.*;
import com.hibiscusmc.hmccosmetics.hooks.placeholders.HookPlaceholderAPI;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
public class Hooks {
private static final HashMap<String, Hook> hooks = new HashMap<>();
private static final HookOraxen ORAXEN_HOOK = new HookOraxen();
private static final HookItemAdder ITEMADDER_HOOK = new HookItemAdder();
private static final HookGeary GEARY_HOOK = new HookGeary();
private static final HookMythic MYTHIC_HOOK = new HookMythic();
private static final HookDenizen DENIZEN_HOOK = new HookDenizen();
private static final HookHMCCosmetics HMCCOSMETIC_HOOK = new HookHMCCosmetics();
private static final HookPlaceholderAPI PAPI_HOOK = new HookPlaceholderAPI();
private static final HookPremiumVanish PREMIUM_VANISH_HOOK = new HookPremiumVanish();
private static final HookSuperVanish SUPER_VANISH_HOOK = new HookSuperVanish();
private static final HookHMCColor HMC_COLOR_HOOK = new HookHMCColor();
private static final HookCMI CMI_HOOK = new HookCMI();
private static final HookLibsDisguises LIBS_DISGUISES_HOOK = new HookLibsDisguises();
private static final HookModelEngine MODEL_ENGINE_HOOK = new HookModelEngine();
public static Hook getHook(@NotNull String id) {
return hooks.get(id.toLowerCase());
}
public static boolean isItemHook(@NotNull String id) {
return hooks.containsKey(id.toLowerCase());
}
public static void addHook(Hook hook) {
hooks.put(hook.getId().toLowerCase(), hook);
}
public static void setup() {
for (Hook hook : hooks.values()) {
if (Bukkit.getPluginManager().getPlugin(hook.getId()) != null) {
HMCCosmeticsPlugin.getInstance().getServer().getPluginManager().registerEvents(hook, HMCCosmeticsPlugin.getInstance());
hook.setActive(true);
hook.load();
HMCCosmeticsPlugin.getInstance().getLogger().info("Successfully hooked into " + hook.getId());
}
}
}
@Nullable
public static ItemStack getItem(@NotNull String raw) {
if (!raw.contains(":")) {
Material mat = Material.getMaterial(raw.toUpperCase());
if (mat == null) return null;
return new ItemStack(mat);
}
// Ex. Oraxen:BigSword
// split[0] is the plugin name
// split[1] is the item name
String[] split = raw.split(":", 2);
if (!isItemHook(split[0])) return null;
Hook hook = getHook(split[0]);
if (!hook.hasEnabledItemHook()) return null;
if (!hook.isActive()) return null;
return hook.getItem(split[1]);
}
@NotNull
public static String processPlaceholders(OfflinePlayer player, String raw) {
if (getHook("PlaceholderAPI").isActive()) return PlaceholderAPI.setPlaceholders(player, raw);
return raw;
}
public static boolean isActiveHook(String id) {
Hook hook = getHook(id);
if (hook == null) return false;
return hook.isActive();
}
}

View File

@@ -1,27 +0,0 @@
package com.hibiscusmc.hmccosmetics.hooks.items;
import com.denizenscript.denizen.objects.ItemTag;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.hibiscusmc.hmccosmetics.hooks.Hook;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
/**
* A hook that integrates the plugin {@link com.denizenscript.denizen.Denizen Denizen} to provide custom items
*/
@SuppressWarnings("SpellCheckingInspection")
public class HookDenizen extends Hook {
public HookDenizen() {
super("denizen");
setEnabledItemHook(true);
}
/**
* Gets a cosmetic {@link ItemStack} that is associated with the provided id from the plugin {@link com.denizenscript.denizen.Denizen Denizen}
*/
@Override
public ItemStack getItem(@NotNull String itemId) {
ItemTag item = ItemTag.valueOf(itemId, CoreUtilities.noDebugContext);
return item == null ? null : item.getItemStack();
}
}

View File

@@ -1,44 +0,0 @@
package com.hibiscusmc.hmccosmetics.hooks.items;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.hooks.Hook;
import com.mineinabyss.geary.addons.GearyPhase;
import com.mineinabyss.geary.modules.GearyModuleKt;
import com.mineinabyss.geary.papermc.tracking.items.ItemTrackingKt;
import com.mineinabyss.geary.prefabs.PrefabKey;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
/**
* A hook that integrates the plugin {@link com.mineinabyss.geary.papermc.GearyPlugin Geary} to provide custom items
*/
public class HookGeary extends Hook {
private boolean enabled = false;
public HookGeary() {
super("geary");
setEnabledItemHook(true);
}
@Override
public void load() {
if (!enabled) GearyModuleKt.getGeary().getPipeline().intercept(GearyPhase.INIT_ENTITIES, () -> {
enabled = true;
HMCCosmeticsPlugin.setup();
return null;
});
}
/**
* Gets a cosmetic {@link ItemStack} that is associated with the provided id from the plugin {@link com.mineinabyss.geary.papermc.GearyPlugin Geary}
*/
@Override
public ItemStack getItem(@NotNull String itemId) {
if (enabled) {
PrefabKey prefabKey = PrefabKey.Companion.ofOrNull(itemId);
if (prefabKey == null) return null;
return ItemTrackingKt.getGearyItems().createItem(prefabKey, null);
} else return new ItemStack(Material.AIR);
}
}

View File

@@ -2,7 +2,8 @@ package com.hibiscusmc.hmccosmetics.hooks.items;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
import com.hibiscusmc.hmccosmetics.hooks.Hook;
import me.lojosho.hibiscuscommons.hooks.Hook;
import me.lojosho.hibiscuscommons.hooks.HookFlag;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@@ -11,8 +12,8 @@ import org.jetbrains.annotations.NotNull;
*/
public class HookHMCCosmetics extends Hook {
public HookHMCCosmetics() {
super("HMCCosmetics");
setEnabledItemHook(true);
super("HMCCosmetics", HookFlag.ITEM_SUPPORT);
setActive(true);
}
/**
@@ -25,4 +26,3 @@ public class HookHMCCosmetics extends Hook {
return cosmetic.getItem();
}
}

View File

@@ -1,47 +0,0 @@
package com.hibiscusmc.hmccosmetics.hooks.items;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.hooks.Hook;
import dev.lone.itemsadder.api.CustomStack;
import dev.lone.itemsadder.api.Events.ItemsAdderLoadDataEvent;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
/**
* A hook that integrates the plugin {@link dev.lone.itemsadder.api.ItemsAdder ItemsAdder} to provide custom items
*/
@SuppressWarnings("SpellCheckingInspection")
public class HookItemAdder extends Hook {
private boolean enabled = false;
public HookItemAdder() {
super("itemsadder");
setEnabledItemHook(true);
}
/**
* Gets a cosmetic {@link ItemStack} that is associated with the provided id from the plugin {@link dev.lone.itemsadder.api.ItemsAdder ItemsAdder}
*/
@Override
public ItemStack getItem(@NotNull String itemId) {
if (enabled) {
CustomStack stack = CustomStack.getInstance(itemId);
if (stack == null) return null;
return stack.getItemStack();
} else {
return new ItemStack(Material.AIR);
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onItemAdderDataLoad(ItemsAdderLoadDataEvent event) {
// By default, it will only run once at startup, if hook setting is enabled
if (enabled && !Settings.isItemsAdderChangeReload()) return;
this.enabled = true;
HMCCosmeticsPlugin.setup();
}
}

View File

@@ -1,25 +0,0 @@
package com.hibiscusmc.hmccosmetics.hooks.items;
import com.hibiscusmc.hmccosmetics.hooks.Hook;
import io.lumine.mythic.bukkit.MythicBukkit;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
/**
* A hook that integrates the plugin {@link io.lumine.mythic.bukkit.MythicBukkit MythicBukkit} to provide custom items
*/
@SuppressWarnings("SpellCheckingInspection")
public class HookMythic extends Hook {
public HookMythic() {
super("mythicmobs");
setEnabledItemHook(true);
}
/**
* Gets a cosmetic {@link ItemStack} that is associated with the provided id from the plugin {@link io.lumine.mythic.bukkit.MythicBukkit MythicBukkit}
*/
@Override
public ItemStack getItem(@NotNull String itemId) {
return MythicBukkit.inst().getItemManager().getItemStack(itemId);
}
}

View File

@@ -1,28 +0,0 @@
package com.hibiscusmc.hmccosmetics.hooks.items;
import com.hibiscusmc.hmccosmetics.hooks.Hook;
import io.th0rgal.oraxen.api.OraxenItems;
import io.th0rgal.oraxen.items.ItemBuilder;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
/**
* A hook that integrates the plugin {@link io.th0rgal.oraxen.OraxenPlugin OraxenPlugin} to provide custom items
*/
@SuppressWarnings("SpellCheckingInspection")
public class HookOraxen extends Hook {
public HookOraxen() {
super("oraxen");
setEnabledItemHook(true);
}
/**
* Gets a cosmetic {@link ItemStack} that is associated with the provided id from the plugin {@link io.th0rgal.oraxen.OraxenPlugin OraxenPlugin}
*/
@Override
public ItemStack getItem(@NotNull String itemId) {
ItemBuilder builder = OraxenItems.getItemById(itemId);
if (builder == null) return null;
return builder.build();
}
}

View File

@@ -0,0 +1,39 @@
package com.hibiscusmc.hmccosmetics.hooks.misc;
import com.hibiscusmc.hmccosmetics.api.events.PlayerWardrobeEnterEvent;
import com.hibiscusmc.hmccosmetics.api.events.PlayerWardrobeLeaveEvent;
import com.hibiscusmc.hmccosmetics.config.Settings;
import kr.toxicity.hud.api.BetterHud;
import kr.toxicity.hud.api.player.HudPlayer;
import me.lojosho.hibiscuscommons.hooks.Hook;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public class HookBetterHud extends Hook {
public HookBetterHud() {
super("BetterHUD");
setActive(true);
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerEnterWardrobe(@NotNull PlayerWardrobeEnterEvent event) {
if (!Settings.isWardrobeHideHud()) return;
UUID uuid = event.getUniqueId();
HudPlayer hudPlayer = BetterHud.getInstance().getPlayerManager().getHudPlayer(uuid);
if (hudPlayer == null) return;
hudPlayer.setHudEnabled(false);
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerLeaveWardrobe(@NotNull PlayerWardrobeLeaveEvent event) {
if (!Settings.isWardrobeHideHud()) return;
UUID uuid = event.getUniqueId();
HudPlayer hudPlayer = BetterHud.getInstance().getPlayerManager().getHudPlayer(uuid);
if (hudPlayer == null) return;
hudPlayer.setHudEnabled(true);
}
}

View File

@@ -1,36 +0,0 @@
package com.hibiscusmc.hmccosmetics.hooks.misc;
import com.Zrips.CMI.events.CMIPlayerUnVanishEvent;
import com.Zrips.CMI.events.CMIPlayerVanishEvent;
import com.hibiscusmc.hmccosmetics.hooks.Hook;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.jetbrains.annotations.NotNull;
/**
* A hook that integrates the plugin {@link com.Zrips.CMI.CMI CMI}
*/
public class HookCMI extends Hook {
public HookCMI() {
super("CMI");
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerVanish(@NotNull CMIPlayerVanishEvent event) {
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
user.hideCosmetics(CosmeticUser.HiddenReason.PLUGIN);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerShow(@NotNull CMIPlayerUnVanishEvent event) {
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
user.showCosmetics();
}
}

View File

@@ -1,12 +0,0 @@
package com.hibiscusmc.hmccosmetics.hooks.misc;
import com.hibiscusmc.hmccosmetics.hooks.Hook;
/**
* A hook that integrates the plugin {@link com.hibiscusmc.hmccolor.HMCColor HMCColor}
*/
public class HookHMCColor extends Hook {
public HookHMCColor() {
super("HMCColor");
}
}

View File

@@ -1,33 +0,0 @@
package com.hibiscusmc.hmccosmetics.hooks.misc;
import com.hibiscusmc.hmccosmetics.hooks.Hook;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import me.libraryaddict.disguise.events.DisguiseEvent;
import me.libraryaddict.disguise.events.UndisguiseEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.jetbrains.annotations.NotNull;
public class HookLibsDisguises extends Hook {
public HookLibsDisguises() {
super("LibsDisguises");
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerVanish(@NotNull DisguiseEvent event) {
if (!(event.getEntity() instanceof Player player)) return;
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
user.hideCosmetics(CosmeticUser.HiddenReason.PLUGIN);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerShow(@NotNull UndisguiseEvent event) {
if (!(event.getEntity() instanceof Player player)) return;
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
user.showCosmetics();
}
}

View File

@@ -1,10 +0,0 @@
package com.hibiscusmc.hmccosmetics.hooks.misc;
import com.hibiscusmc.hmccosmetics.hooks.Hook;
public class HookModelEngine extends Hook {
public HookModelEngine() {
super("ModelEngine");
}
}

View File

@@ -1,38 +0,0 @@
package com.hibiscusmc.hmccosmetics.hooks.misc;
import com.hibiscusmc.hmccosmetics.hooks.Hook;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import de.myzelyam.api.vanish.PlayerHideEvent;
import de.myzelyam.api.vanish.PlayerShowEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.jetbrains.annotations.NotNull;
/**
* A hook that integrates the plugin {@link de.myzelyam.api.vanish.VanishAPI Supervanish}
*
* @implSpec Supervanish and Premium Vanish both use the same api
*/
public class HookPremiumVanish extends Hook {
public HookPremiumVanish() {
super("PremiumVanish");
}
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerVanish(@NotNull PlayerHideEvent event) {
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
user.hideCosmetics(CosmeticUser.HiddenReason.PLUGIN);
}
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerShow(@NotNull PlayerShowEvent event) {
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
user.showCosmetics();
}
}

View File

@@ -1,38 +0,0 @@
package com.hibiscusmc.hmccosmetics.hooks.misc;
import com.hibiscusmc.hmccosmetics.hooks.Hook;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import de.myzelyam.api.vanish.PlayerHideEvent;
import de.myzelyam.api.vanish.PlayerShowEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.jetbrains.annotations.NotNull;
/**
* A hook that integrates the plugin {@link de.myzelyam.api.vanish.VanishAPI Supervanish}
*
* @implSpec Supervanish and Premium Vanish both use the same api
*/
public class HookSuperVanish extends Hook {
public HookSuperVanish() {
super("SuperVanish");
}
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerVanish(@NotNull PlayerHideEvent event) {
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
user.hideCosmetics(CosmeticUser.HiddenReason.PLUGIN);
}
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerShow(@NotNull PlayerShowEvent event) {
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
user.showCosmetics();
}
}

View File

@@ -54,18 +54,15 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
@Override
public String onRequest(@NotNull OfflinePlayer player, @NotNull String params) {
if (!player.isOnline()) return null;
if (!player.isOnline()) return TranslationUtil.getTranslation("user-cosmetic", "offline");
CosmeticUser user = CosmeticUsers.getUser(player.getPlayer());
if (user == null) return null;
if (user == null) return TranslationUtil.getTranslation("user-cosmetic", "invalid-user");
List<String> placeholderArgs = Arrays.asList(params.split("_", 3));
switch (placeholderArgs.get(0).toLowerCase()) {
case "using":
if (placeholderArgs == null) {
return null;
}
if (placeholderArgs.get(1) != null) {
if (placeholderArgs.size() >= 2) {
Cosmetic cosmetic = Cosmetics.getCosmetic(placeholderArgs.get(1));
if (cosmetic == null) return "INVALID_COSMETIC";
Cosmetic currentCosmetic = user.getCosmetic(cosmetic.getSlot());
@@ -74,13 +71,10 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
return TranslationUtil.getTranslation("using-cosmetic", String.valueOf(false));
}
case "current":
if (placeholderArgs == null) {
return null;
}
if (placeholderArgs.get(1) != null) {
if (placeholderArgs.size() >= 2) {
CosmeticSlot slot = CosmeticSlot.valueOf(placeholderArgs.get(1).toUpperCase());
if (slot == null) return null;
if (user.getCosmetic(slot) == null) return null;
if (user.getCosmetic(slot) == null) return TranslationUtil.getTranslation("current-cosmetic", "no-cosmetic");
if (placeholderArgs.size() == 2) return user.getCosmetic(slot).getId();
String output;
@@ -104,13 +98,11 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
output = user.getCosmetic(slot).getId();
}
}
return TranslationUtil.getTranslation("current-cosmetic", String.valueOf(output));
if (output == null) output = "none";
return TranslationUtil.getTranslation("current-cosmetic", output);
}
case "unlocked":
if (placeholderArgs == null) {
return null;
}
if (placeholderArgs.get(1) != null) {
if (placeholderArgs.size() >= 2) {
Cosmetic cosmetic = Cosmetics.getCosmetic(placeholderArgs.get(1));
if (cosmetic == null) {
if (placeholderArgs.size() >= 3) {
@@ -127,13 +119,11 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
return TranslationUtil.getTranslation("unlocked-cosmetic", String.valueOf(user.canEquipCosmetic(cosmetic, true)));
}
case "equipped":
if (placeholderArgs == null) {
return null;
}
if (placeholderArgs.get(1) != null) {
if (placeholderArgs.size() >= 2) {
String args1 = placeholderArgs.get(1);
if (EnumUtils.isValidEnum(CosmeticSlot.class, args1.toUpperCase())) {
String rawSlot = args1.toUpperCase();
if (CosmeticSlot.contains(rawSlot)) {
return TranslationUtil.getTranslation("equipped-cosmetic", String.valueOf(user.getCosmetic(CosmeticSlot.valueOf(args1.toUpperCase())) != null));
}
@@ -156,6 +146,30 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
if (equippedCosmetic == null) return TranslationUtil.getTranslation("equipped-cosmetic", "false");
return TranslationUtil.getTranslation("equipped-cosmetic", String.valueOf(cosmetic.getId().equals(equippedCosmetic.getId())));
}
// %hmccosmetics_amount_balloon_unlocked%
case "amount":
if (placeholderArgs.size() >= 2) {
String args1 = placeholderArgs.get(1).toUpperCase(); // changes offhand to OFFHAND
if (!CosmeticSlot.contains(args1)) return null;
CosmeticSlot slot = CosmeticSlot.valueOf(args1);
int amount = 0;
boolean checkUnlocked = false;
if (placeholderArgs.size() >= 3) if (placeholderArgs.get(2).equalsIgnoreCase("unlocked")) checkUnlocked = true;
for (Cosmetic cosmetic : Cosmetics.values()) {
if (cosmetic.getSlot() != slot) continue;
if (checkUnlocked && !user.canEquipCosmetic(cosmetic)) continue;
amount += 1;
}
return TranslationUtil.getTranslation("amount-cosmetic", String.valueOf(amount));
} else {
return TranslationUtil.getTranslation("amount-cosmetic", String.valueOf(Cosmetics.values().size()));
}
case "hidden":
return TranslationUtil.getTranslation("hidden", String.valueOf(user.isHidden()));
case "wardrobe-enabled":
return TranslationUtil.getTranslation("in-wardrobe", String.valueOf(user.isInWardrobe()));
}
@@ -216,6 +230,7 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
if (!item.hasItemMeta()) return null;
ItemMeta itemMeta = item.getItemMeta();
if (itemMeta == null) return null;
if (!itemMeta.hasDisplayName()) return null;
return itemMeta.getDisplayName();
}

View File

@@ -1,20 +0,0 @@
package com.hibiscusmc.hmccosmetics.hooks.placeholders;
import com.hibiscusmc.hmccosmetics.hooks.Hook;
/**
* A hook that integrates the plugin {@link me.clip.placeholderapi.PlaceholderAPI PlaceholderAPI}
*/
public class HookPlaceholderAPI extends Hook {
public HookPlaceholderAPI() {
super("PlaceholderAPI");
}
/**
* Registers HMCCosmetics Placeholder Expansion
*/
@Override
public void load() {
new HMCPlaceholderExpansion().register();
}
}

View File

@@ -30,24 +30,23 @@ public class WGListener implements Listener {
if (user == null) return;
Location location = event.getPlayer().getLocation();
ApplicableRegionSet set = getRegions(location);
if (user.getHidden()) {
if (user.getHiddenReason() == CosmeticUser.HiddenReason.WORLDGUARD && set.getRegions().isEmpty()) {
user.showCosmetics();
if (user.isHidden()) {
if (set.getRegions().isEmpty()) {
user.showCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
}
}
for (ProtectedRegion protectedRegion : set.getRegions()) {
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticEnableFlag())) {
if (protectedRegion.getFlags().get(WGHook.getCosmeticEnableFlag()).toString().equalsIgnoreCase("ALLOW")) {
if (user.getHiddenReason() == CosmeticUser.HiddenReason.WORLDGUARD) user.showCosmetics();
return;
}
user.showCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
} else {
user.hideCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
return;
}
}
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticWardrobeFlag())) {
if (!WardrobeSettings.getWardrobeNames().contains(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString())) return;
Wardrobe wardrobe = WardrobeSettings.getWardrobe(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString());
user.enterWardrobe(true, wardrobe);
user.enterWardrobe(wardrobe, true);
}
}
}
@@ -58,15 +57,15 @@ public class WGListener implements Listener {
if (user == null) return;
Location location = event.getTo();
ApplicableRegionSet set = getRegions(location);
if (user.getHidden()) {
if (user.getHiddenReason() == CosmeticUser.HiddenReason.WORLDGUARD && set.getRegions().isEmpty()) {
user.showCosmetics();
if (user.isHidden()) {
if (set.getRegions().isEmpty()) {
user.showCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
}
}
for (ProtectedRegion protectedRegion : set.getRegions()) {
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticEnableFlag())) {
if (protectedRegion.getFlags().get(WGHook.getCosmeticEnableFlag()).toString().equalsIgnoreCase("ALLOW")) {
if (user.getHiddenReason() == CosmeticUser.HiddenReason.WORLDGUARD) user.showCosmetics();
user.showCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
return;
}
user.hideCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
@@ -75,7 +74,7 @@ public class WGListener implements Listener {
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticWardrobeFlag())) {
if (!WardrobeSettings.getWardrobeNames().contains(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString())) return;
Wardrobe wardrobe = WardrobeSettings.getWardrobe(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString());
user.enterWardrobe(true, wardrobe);
user.enterWardrobe(wardrobe, true);
}
}
}

View File

@@ -0,0 +1,40 @@
package com.hibiscusmc.hmccosmetics.listener;
import com.destroystokyo.paper.event.player.PlayerArmorChangeEvent;
import com.destroystokyo.paper.event.player.PlayerPostRespawnEvent;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
public class PaperPlayerGameListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerArmorEquip(PlayerArmorChangeEvent event) {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
if (user == null) return;
if (user.isInWardrobe()) return;
user.updateCosmetic(slotTypeToCosmeticType(event.getSlotType()));
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerRespawn(PlayerPostRespawnEvent event) {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
if (user == null) return;
if (user.isInWardrobe()) return;
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) user.respawnBackpack();
}
private CosmeticSlot slotTypeToCosmeticType(PlayerArmorChangeEvent.SlotType slotType) {
return switch (slotType) {
case HEAD -> CosmeticSlot.HELMET;
case FEET -> CosmeticSlot.BOOTS;
case LEGS -> CosmeticSlot.LEGGINGS;
case CHEST -> CosmeticSlot.CHESTPLATE;
default -> null;
};
}
}

View File

@@ -1,15 +1,17 @@
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.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.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@@ -17,27 +19,60 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
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.getLatestVersion().equalsIgnoreCase(HMCCosmeticsPlugin.getInstance().getDescription().getVersion()) && HMCCosmeticsPlugin.getLatestVersion().isEmpty())
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.getLatestVersion() + "<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>"
);
}
// This literally makes me want to end it all but I can't do that so I'll just cry instead
Runnable run = () -> {
CosmeticUser user = Database.get(event.getPlayer().getUniqueId());
CosmeticUsers.addUser(user);
MessagesUtil.sendDebugMessages("Run User Join");
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> user.updateCosmetic(), 4);
if (!event.getPlayer().isOnline()) return; // If a player is no longer online, don't run this.
UUID uuid = event.getPlayer().getUniqueId();
PlayerPreLoadEvent preLoadEvent = new PlayerPreLoadEvent(uuid);
Bukkit.getPluginManager().callEvent(preLoadEvent);
if (preLoadEvent.isCancelled()) return;
Database.get(uuid).thenAccept(userData -> {
if (userData == null) {
return;
}
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
CosmeticUser cosmeticUser = CosmeticUsers.getProvider()
.createCosmeticUser(uuid)
.initialize(userData);
cosmeticUser.startTicking();
CosmeticUsers.addUser(cosmeticUser);
MessagesUtil.sendDebugMessages("Run User Join for " + uuid);
PlayerLoadEvent playerLoadEvent = new PlayerLoadEvent(cosmeticUser);
Bukkit.getPluginManager().callEvent(playerLoadEvent);
// And finally, launch an update for the cosmetics they have.
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
if (cosmeticUser.getPlayer() == null) return;
cosmeticUser.updateCosmetic();
}, 4);
});
}).exceptionally(ex -> {
MessagesUtil.sendDebugMessages("Unable to load Cosmetic User " + uuid + ". Exception: " + ex.getMessage());
return null;
});
};
if (DatabaseSettings.isEnabledDelay()) {
@@ -51,21 +86,20 @@ public class PlayerConnectionListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(@NotNull PlayerQuitEvent event) {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
if (user == null) { // Remove any passengers if a user failed to initialize. Bugs can cause this to happen
if (!event.getPlayer().getPassengers().isEmpty()) {
for (Entity entity : event.getPlayer().getPassengers()) {
if (entity.getType() == EntityType.ARMOR_STAND) {
entity.remove();
if (user == null) return; // Player never initialized, don't do anything
PlayerUnloadEvent playerUnloadEvent = new PlayerUnloadEvent(user);
Bukkit.getPluginManager().callEvent(playerUnloadEvent);
if (user.isInWardrobe()) {
user.leaveWardrobe(true);
user.getPlayer().setInvisible(false);
}
}
}
return;
}
if (user.isInWardrobe()) user.leaveWardrobe();
if (user.getUserEmoteManager().isPlayingEmote()) {
user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.CONNECTION);
event.getPlayer().setInvisible(false);
}
Menus.removeCooldown(event.getPlayer().getUniqueId()); // Removes any menu cooldowns a player might have
Database.save(user);
user.destroy();
CosmeticUsers.removeUser(user.getUniqueId());

View File

@@ -2,15 +2,13 @@ package com.hibiscusmc.hmccosmetics.listener;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.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;
@@ -18,13 +16,16 @@ import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticEmoteType;
import com.hibiscusmc.hmccosmetics.gui.Menu;
import com.hibiscusmc.hmccosmetics.gui.Menus;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
import com.hibiscusmc.hmccosmetics.user.manager.UserWardrobeManager;
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import me.lojosho.hibiscuscommons.api.events.*;
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -46,8 +47,6 @@ import org.bukkit.persistence.PersistentDataType;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.spigotmc.event.entity.EntityDismountEvent;
import org.spigotmc.event.entity.EntityMountEvent;
import java.util.*;
@@ -56,14 +55,12 @@ public class PlayerGameListener implements Listener {
public PlayerGameListener() {
registerInventoryClickListener();
registerMenuChangeListener();
registerEntityStatusListener();
registerPlayerEquipmentListener();
registerPlayerArmListener();
registerEntityUseListener();
registerSlotChangeListener();
//registerLookMovement();
//registerMoveListener();
//registerTeleportMovement();
registerPassengerSetListener();
}
@EventHandler(priority = EventPriority.LOW)
@@ -77,14 +74,14 @@ public class PlayerGameListener implements Listener {
ItemStack item = event.getCurrentItem();
if (item == null) return;
if (Settings.isDestroyLooseCosmetics() && InventoryUtils.isCosmeticItem(event.getCurrentItem())) {
if (Settings.isDestroyLooseCosmetics() && HMCCInventoryUtils.isCosmeticItem(event.getCurrentItem())) {
MessagesUtil.sendDebugMessages("remvoe item");
event.getWhoClicked().getInventory().removeItem(event.getCurrentItem());
}
EquipmentSlot slot = getArmorSlot(item.getType());
if (slot == null) return;
CosmeticSlot cosmeticSlot = InventoryUtils.BukkitCosmeticSlot(slot);
CosmeticSlot cosmeticSlot = HMCCInventoryUtils.BukkitCosmeticSlot(slot);
if (cosmeticSlot == null) return;
if (!user.hasCosmeticInSlot(cosmeticSlot)) return;
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
@@ -105,10 +102,10 @@ public class PlayerGameListener implements Listener {
if (!event.isSneaking()) return;
if (!user.isInWardrobe()) return;
user.leaveWardrobe();
user.leaveWardrobe(false);
}
@EventHandler(priority = EventPriority.LOW)
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerTeleport(PlayerTeleportEvent event) {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
@@ -119,10 +116,16 @@ public class PlayerGameListener implements Listener {
}
if (user.isInWardrobe()) {
user.leaveWardrobe();
user.leaveWardrobe(false);
}
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
if (user.getEntity() == null || user.isInWardrobe()) return; // fixes disconnecting when in wardrobe (the entity stuff)
if (Settings.getDisabledWorlds().contains(user.getEntity().getLocation().getWorld().getName())) {
user.hideCosmetics(CosmeticUser.HiddenReason.WORLD);
} else {
user.showCosmetics(CosmeticUser.HiddenReason.WORLD);
}
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK) && user.getUserBackpackManager() != null) {
user.respawnBackpack();
}
@@ -130,7 +133,7 @@ public class PlayerGameListener implements Listener {
user.respawnBalloon();
}
user.updateCosmetic();
}, 1);
}, 2);
if (event.getCause().equals(PlayerTeleportEvent.TeleportCause.NETHER_PORTAL) || event.getCause().equals(PlayerTeleportEvent.TeleportCause.END_PORTAL)) return;
if (user.getUserEmoteManager().isPlayingEmote()) {
@@ -138,7 +141,7 @@ public class PlayerGameListener implements Listener {
}
}
@EventHandler(priority = EventPriority.LOW)
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPortalTeleport(PlayerPortalEvent event) {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
@@ -148,6 +151,12 @@ public class PlayerGameListener implements Listener {
return;
}
if (Settings.getDisabledWorlds().contains(user.getEntity().getLocation().getWorld().getName())) {
user.hideCosmetics(CosmeticUser.HiddenReason.WORLD);
} else {
user.showCosmetics(CosmeticUser.HiddenReason.WORLD);
}
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
user.despawnBalloon();
@@ -161,7 +170,6 @@ public class PlayerGameListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerHit(EntityDamageByEntityEvent event) {
Entity entity = event.getEntity();
if (event.getEntity().getEntityId() == event.getDamager().getEntityId()) event.setCancelled(true);
if (!entity.getPersistentDataContainer().has(new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "cosmeticMob"), PersistentDataType.SHORT))
return;
event.setCancelled(true);
@@ -181,12 +189,16 @@ public class PlayerGameListener implements Listener {
}
}
if (user.isInWardrobe()) {
user.leaveWardrobe();
if (WardrobeSettings.isPreventDamage()) {
event.setCancelled(true);
return;
}
if (WardrobeSettings.isDamagedKicked()) user.leaveWardrobe(false);
}
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerLook(PlayerMoveEvent event) {
public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
@@ -198,11 +210,11 @@ public class PlayerGameListener implements Listener {
user.updateCosmetic(CosmeticSlot.BALLOON);
}
@EventHandler(priority = EventPriority.MONITOR)
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerPoseChange(EntityPoseChangeEvent event) {
if (!(event.getEntity() instanceof Player player)) return;
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
if (user == null || user.isInWardrobe()) return;
if (!user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) return;
Pose pose = event.getPose();
if (pose.equals(Pose.STANDING)) {
@@ -239,7 +251,7 @@ public class PlayerGameListener implements Listener {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
if (user == null) return;
CosmeticSlot cosmeticSlot = InventoryUtils.BukkitCosmeticSlot(slot);
CosmeticSlot cosmeticSlot = HMCCInventoryUtils.BukkitCosmeticSlot(slot);
if (!user.hasCosmeticInSlot(cosmeticSlot)) {
MessagesUtil.sendDebugMessages("No cosmetic in " + cosmeticSlot);
@@ -263,7 +275,14 @@ public class PlayerGameListener implements Listener {
event.setCancelled(true);
return;
}
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> user.updateCosmetic(CosmeticSlot.OFFHAND), 2);
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
if (user.getEntity() == null) return; // Player has likely logged off
user.updateCosmetic(CosmeticSlot.OFFHAND);
List<Player> viewers = HMCCPacketManager.getViewers(user.getEntity().getLocation());
if (viewers.isEmpty()) return;
viewers.remove(user.getPlayer());
PacketManager.equipmentSlotUpdate(user.getEntity().getEntityId(), EquipmentSlot.HAND, event.getPlayer().getInventory().getItemInMainHand(), viewers);
}, 2);
}
@EventHandler(priority = EventPriority.NORMAL)
@@ -286,7 +305,7 @@ public class PlayerGameListener implements Listener {
return;
}
if (event.getAction().equals(EntityPotionEffectEvent.Action.CLEARED) || event.getAction().equals(EntityPotionEffectEvent.Action.REMOVED)) {
user.showCosmetics();
user.showCosmetics(CosmeticUser.HiddenReason.POTION);
return;
}
}
@@ -296,11 +315,12 @@ public class PlayerGameListener implements Listener {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
if (user == null) return;
event.getPlayer().getInventory().setItem(event.getPreviousSlot(), event.getPlayer().getInventory().getItem(event.getPreviousSlot()));
//NMSHandlers.getHandler().slotUpdate(event.getPlayer(), event.getPreviousSlot());
if (user.hasCosmeticInSlot(CosmeticSlot.MAINHAND)) {
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
user.updateCosmetic(CosmeticSlot.MAINHAND);
}, 2);
}
// #84, Riptides mess with backpacks
ItemStack currentItem = event.getPlayer().getInventory().getItem(event.getNewSlot());
@@ -316,7 +336,7 @@ public class PlayerGameListener implements Listener {
CosmeticUser user = CosmeticUsers.getUser(event.getEntity());
if (user == null) return;
if (user.isInWardrobe()) user.leaveWardrobe();
if (user.isInWardrobe()) user.leaveWardrobe(false);
if (Settings.isUnapplyOnDeath() && !event.getEntity().hasPermission("hmccosmetics.unapplydeath.bypass")) {
user.removeCosmetics();
@@ -327,12 +347,21 @@ public class PlayerGameListener implements Listener {
public void onPlayerGamemodeSwitch(PlayerGameModeChangeEvent event) {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
if (user == null) return;
if (user.isInWardrobe()) user.leaveWardrobe(true);
if (Settings.isDisabledGamemodesEnabled()) {
if (Settings.getDisabledGamemodes().contains(event.getNewGameMode().toString())) {
user.hideCosmetics(CosmeticUser.HiddenReason.GAMEMODE);
} else {
user.showCosmetics(CosmeticUser.HiddenReason.GAMEMODE);
}
}
if (Settings.isDestroyLooseCosmetics()) {
ItemStack[] equippedArmor = event.getPlayer().getInventory().getArmorContents();
if (equippedArmor.length == 0) return;
for (ItemStack armor : equippedArmor) {
if (InventoryUtils.isCosmeticItem(armor)) armor.setAmount(0);
if (HMCCInventoryUtils.isCosmeticItem(armor)) armor.setAmount(0);
}
}
}
@@ -341,11 +370,18 @@ public class PlayerGameListener implements Listener {
public void onPlayerCosmeticEquip(PlayerCosmeticPostEquipEvent event) {
CosmeticUser user = event.getUser();
if (user.isInWardrobe() && event.getCosmetic().getSlot().equals(CosmeticSlot.BALLOON)) {
Location NPCLocation = user.getWardrobeManager().getNpcLocation();
if (user.getBalloonManager() == null) {
MessagesUtil.sendDebugMessages("Balloon Manager is null? " + user.getEntity().getName());
return;
}
CosmeticBalloonType cosmetic = (CosmeticBalloonType) event.getCosmetic();
Location npclocation = user.getWardrobeManager().getNpcLocation().clone().add(cosmetic.getBalloonOffset());
// We know that no other entity besides a regular player will be in the wardrobe
PacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), NPCLocation.add(cosmetic.getBalloonOffset()), false, List.of(user.getPlayer()));
user.getBalloonManager().getModelEntity().teleport(NPCLocation.add(cosmetic.getBalloonOffset()));
List<Player> viewer = List.of(user.getPlayer());
user.getBalloonManager().getPufferfish().spawnPufferfish(npclocation.clone().add(cosmetic.getBalloonOffset()), viewer);
HMCCPacketManager.sendLeashPacket(user.getBalloonManager().getPufferfishBalloonId(), user.getWardrobeManager().getNPC_ID(), viewer);
HMCCPacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), npclocation, false, viewer);
user.getBalloonManager().getModelEntity().teleport(npclocation);
}
}
@@ -369,8 +405,54 @@ public class PlayerGameListener implements Listener {
}
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerVanish(HibiscusPlayerVanishEvent event) {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
if (user == null) return;
user.hideCosmetics(CosmeticUser.HiddenReason.PLUGIN);
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerUnVanish(HibiscusPlayerUnVanishEvent event) {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
if (user == null) return;
if (!user.isHidden()) return;
user.showCosmetics(CosmeticUser.HiddenReason.PLUGIN);
}
// These emote mostly handles emotes from other plugins, such as ItemsAdder
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerPlayEmote(HibiscusPlayerEmotePlayEvent event) {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
if (user == null) return;
user.hideCosmetics(CosmeticUser.HiddenReason.EMOTE);
}
@EventHandler(priority = EventPriority.LOW)
public void onPlayerEndEmote(HibiscusPlayerEmoteEndEvent event) {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
if (user == null) return;
user.showCosmetics(CosmeticUser.HiddenReason.EMOTE);
}
@EventHandler(priority = EventPriority.LOW)
public void onPlayerHibiscusPose(HibiscusPlayerPoseEvent event) {
if (event.isGettingUp()) return;
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
if (user == null) return;
user.hideCosmetics(CosmeticUser.HiddenReason.PLUGIN);
}
@EventHandler(priority = EventPriority.LOW)
public void onPlayerHibiscusGetUpPose(HibiscusPlayerPoseEvent event) {
if (!event.isGettingUp()) return;
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
if (user == null) return;
user.showCosmetics(CosmeticUser.HiddenReason.PLUGIN);
}
private void registerInventoryClickListener() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.WINDOW_CLICK) {
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();
@@ -385,7 +467,8 @@ public class PlayerGameListener implements Listener {
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
CosmeticSlot cosmeticSlot = InventoryUtils.NMSCosmeticSlot(slotClicked);
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);
@@ -395,7 +478,7 @@ public class PlayerGameListener implements Listener {
}
private void registerMenuChangeListener() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.WINDOW_ITEMS) {
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 ");
@@ -411,9 +494,15 @@ public class PlayerGameListener implements Listener {
HashMap<Integer, ItemStack> items = new HashMap<>();
if (!user.isInWardrobe()) {
for (Cosmetic cosmetic : user.getCosmetics()) {
if ((cosmetic instanceof CosmeticArmorType cosmeticArmorType)) {
items.put(InventoryUtils.getPacketArmorSlot(cosmeticArmorType.getEquipSlot()), user.getUserCosmeticItem(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));
}
}
}
@@ -423,7 +512,7 @@ public class PlayerGameListener implements Listener {
if ((slot >= 5 && slot <= 8) || slot == 45) {
if (!items.containsKey(slot)) continue;
slotData.set(slot, items.get(slot));
MessagesUtil.sendDebugMessages("Set " + slot + " as " + items.get(slot));
if (Settings.isDebugMode()) MessagesUtil.sendDebugMessages("Set " + slot + " as " + items.get(slot));
}
}
packet.getItemListModifier().write(0, slotData);
@@ -458,12 +547,18 @@ public class PlayerGameListener implements Listener {
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);
if (slot == 45 && user.hasCosmeticInSlot(CosmeticSlot.OFFHAND) && player.getInventory().getItemInOffHand().getType().isAir()) {
event.getPacket().getItemModifier().write(0, user.getUserCosmeticItem(CosmeticSlot.OFFHAND));
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));
}
});
}
@@ -476,17 +571,33 @@ public class PlayerGameListener implements Listener {
int entityID = event.getPacket().getIntegers().read(0);
// User
CosmeticUser user = CosmeticUsers.getUser(entityID);
if (user == null) {
return;
}
if (user == null) return;
if (user.isInWardrobe()) return;
List<com.comphenix.protocol.wrappers.Pair<EnumWrappers.ItemSlot, ItemStack>> armor = event.getPacket().getSlotStackPairLists().read(0);
for (EquipmentSlot equipmentSlot : EquipmentSlot.values()) {
CosmeticArmorType cosmeticArmor = (CosmeticArmorType) user.getCosmetic(InventoryUtils.BukkitCosmeticSlot(equipmentSlot));
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;
Pair<EnumWrappers.ItemSlot, ItemStack> pair = new Pair<>(InventoryUtils.itemBukkitSlot(cosmeticArmor.getEquipSlot()), cosmeticArmor.getItem());
armor.add(pair);
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);
@@ -495,6 +606,58 @@ public class PlayerGameListener implements Listener {
});
}
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
@@ -508,7 +671,9 @@ public class PlayerGameListener implements Listener {
return;
}
if (!user.isInWardrobe()) return;
Menu menu = Menus.getDefaultMenu();
if (!user.getWardrobeManager().getWardrobeStatus().equals(UserWardrobeManager.WardrobeStatus.RUNNING)) return;
Menu menu = user.getWardrobeManager().getLastOpenMenu();
if (menu == null) return;
menu.openMenu(user);
event.setCancelled(true);
@@ -530,49 +695,6 @@ public class PlayerGameListener implements Listener {
});
}
private void registerLookMovement() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.LOOK) {
@Override
public void onPacketReceiving(PacketEvent event) {
// TODO: Finish
MessagesUtil.sendDebugMessages("Look Packet ");
Player player = event.getPlayer();
if (event.getPlayer() == null) return;
if (!(event.getPlayer() instanceof Player)) return;
}
});
}
private void registerMoveListener() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.POSITION) {
@Override
public void onPacketReceiving(PacketEvent event) {
// TODO: Finish
MessagesUtil.sendDebugMessages("Position Packet ");
Player player = event.getPlayer();
if (event.getPlayer() == null) return;
if (!(event.getPlayer() instanceof Player)) return;
}
});
}
private void registerTeleportMovement() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.TELEPORT_ACCEPT) {
@Override
public void onPacketReceiving(PacketEvent event) {
// TODO: Finish
MessagesUtil.sendDebugMessages("Teleport Packet ");
Player player = event.getPlayer();
if (event.getPlayer() == null) return;
if (!(event.getPlayer() instanceof Player)) return;
}
});
}
@Nullable
private EquipmentSlot getArmorSlot(final Material material) {
for (final EquipmentSlot slot : EquipmentSlot.values()) {

View File

@@ -0,0 +1,38 @@
package com.hibiscusmc.hmccosmetics.listener;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import me.lojosho.hibiscuscommons.api.events.HibiscusHookReload;
import me.lojosho.hibiscuscommons.api.events.HibiscusHooksAllActiveEvent;
import me.lojosho.hibiscuscommons.hooks.Hook;
import me.lojosho.hibiscuscommons.hooks.items.HookItemAdder;
import me.lojosho.hibiscuscommons.hooks.items.HookNexo;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
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();
if (hook instanceof HookItemAdder) {
if (reloadType == HibiscusHookReload.ReloadType.RELOAD) {
if (!Settings.isItemsAdderChangeReload()) return;
HMCCosmeticsPlugin.setup();
}
}
if (hook instanceof HookNexo) {
if (reloadType == HibiscusHookReload.ReloadType.RELOAD) {
if (!Settings.isNexoChangeReload()) return;
HMCCosmeticsPlugin.setup();
}
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onAllHooksReady(HibiscusHooksAllActiveEvent event) {
HMCCosmeticsPlugin.setup();
}
}

View File

@@ -1,59 +0,0 @@
package com.hibiscusmc.hmccosmetics.nms;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager;
import org.bukkit.Location;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.List;
public interface NMSHandler {
int getNextEntityId();
Entity getEntity(int entityId);
Entity getHMCArmorStand(Location loc);
ArmorStand getMEGEntity(Location loc);
Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType);
Entity spawnDisplayEntity(Location location, String text);
UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType);
@Deprecated(since = "2.6.0")
void equipmentSlotUpdate(
int entityId,
CosmeticUser user,
CosmeticSlot cosmeticSlot,
List<Player> sendTo
);
void slotUpdate(
Player player,
int slot
);
void equipmentSlotUpdate(
int entityId,
org.bukkit.inventory.EquipmentSlot slot,
ItemStack item,
List<Player> sendTo
);
void hideNPCName(
Player player,
String NPCName);
default boolean getSupported () {
return false;
}
}

View File

@@ -1,46 +0,0 @@
package com.hibiscusmc.hmccosmetics.nms;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import lombok.Getter;
import java.lang.reflect.InvocationTargetException;
import java.util.logging.Level;
public class NMSHandlers {
private static final String[] SUPPORTED_VERSION = new String[]{"v1_18_R2", "v1_19_R1", "v1_19_R2", "v1_19_R3", "v1_20_R1"};
private static NMSHandler handler;
@Getter
private static String version;
public static NMSHandler getHandler() {
if (handler != null) {
return handler;
} else {
setup();
}
return handler;
}
public static void setup() {
if (handler != null) return;
final String packageName = HMCCosmeticsPlugin.getInstance().getServer().getClass().getPackage().getName();
String packageVersion = packageName.substring(packageName.lastIndexOf('.') + 1);
for (String selectedVersion : SUPPORTED_VERSION) {
if (!selectedVersion.contains(packageVersion)) {
continue;
}
MessagesUtil.sendDebugMessages(packageVersion + " has been detected.", Level.INFO);
version = packageVersion;
try {
handler = (NMSHandler) Class.forName("com.hibiscusmc.hmccosmetics.nms." + packageVersion + ".NMSHandler").getConstructor().newInstance();
return;
} catch (ClassNotFoundException | InvocationTargetException | InstantiationException |
IllegalAccessException | NoSuchMethodException e) {
throw new RuntimeException(e);
}
}
}
}

View File

@@ -13,37 +13,41 @@ 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.hooks.Hooks;
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
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.InventoryUtils;
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import lombok.Getter;
import me.lojosho.hibiscuscommons.hooks.Hooks;
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.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.*;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.logging.Level;
public class CosmeticUser {
@Getter
private final UUID uniqueId;
private int taskId;
private int taskId = -1;
private final HashMap<CosmeticSlot, Cosmetic> playerCosmetics = new HashMap<>();
private UserWardrobeManager userWardrobeManager;
private UserBalloonManager userBalloonManager;
@@ -53,34 +57,152 @@ public class CosmeticUser {
private final UserEmoteManager userEmoteManager;
// Cosmetic Settings/Toggles
private boolean hideCosmetics;
@Getter
private HiddenReason hiddenReason;
private final ArrayList<HiddenReason> hiddenReason = new ArrayList<>();
private final HashMap<CosmeticSlot, Color> colors = new HashMap<>();
public CosmeticUser(UUID uuid) {
this.uniqueId = uuid;
userEmoteManager = new UserEmoteManager(this);
tick();
/**
* Use {@link #CosmeticUser(UUID)} instead and use {@link #initialize(UserData)} to populate the user with data.
* @param uuid
* @param data
*/
@Deprecated(forRemoval = true, since = "2.7.5")
public CosmeticUser(UUID uuid, UserData data) {
this(uuid);
initialize(data);
}
private void tick() {
// Occasionally updates the entity cosmetics
Runnable run = () -> {
MessagesUtil.sendDebugMessages("Tick[uuid=" + uniqueId + "]", Level.INFO);
updateCosmetic();
if (getHidden() && !getUserEmoteManager().isPlayingEmote()) MessagesUtil.sendActionBar(getPlayer(), "hidden-cosmetics");
};
public CosmeticUser(@NotNull UUID uuid) {
this.uniqueId = uuid;
this.userEmoteManager = new UserEmoteManager(this);
}
/**
* Initialize the {@link CosmeticUser}.
* @param userData the associated {@link UserData}
* @return the {@link CosmeticUser}
* @apiNote Initialize is called after {@link CosmeticUserProvider#createCosmeticUser(UUID)} so it is possible to
* populate an extending version of {@link CosmeticUser} with data then override this method to apply your
* own state.
*/
public CosmeticUser initialize(final @Nullable UserData userData) {
if(userData != null) {
// CosmeticSlot -> Entry<Cosmetic, Integer>
for(final Map.Entry<CosmeticSlot, Map.Entry<Cosmetic, Integer>> entry : userData.getCosmetics().entrySet()) {
final Cosmetic cosmetic = entry.getValue().getKey();
final Integer colorRGBInt = entry.getValue().getValue();
if (!this.canApplyCosmetic(cosmetic)) {
MessagesUtil.sendDebugMessages("Cannot apply cosmetic[id=" + cosmetic.getId() + "]");
continue;
}
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.applyHiddenState(userData.getHiddenReasons());
}
return this;
}
/**
* This method is only called from {@link #initialize(UserData)} and can't be called directly.
* 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);
return true;
}
/**
* This method is only called from {@link #initialize(UserData)} and can't be called directly.
* This is used to help hooking plugins apply custom logic to the user.
*/
protected boolean canApplyCosmetic(@NotNull Cosmetic cosmetic) {
return canEquipCosmetic(cosmetic, false);
}
/**
* This method is only called from {@link #initialize(UserData)} and can't be called directly.
* This is used to help hooking plugins apply custom logic to the user.
*/
protected void applyHiddenState(@NotNull List<HiddenReason> hiddenReasons) {
if(!hiddenReason.isEmpty()) {
for(final HiddenReason reason : this.hiddenReason) {
this.silentlyAddHideFlag(reason);
}
return;
}
Player bukkitPlayer = getPlayer();
if (bukkitPlayer != null && Settings.isDisabledGamemodesEnabled() && Settings.getDisabledGamemodes().contains(bukkitPlayer.getGameMode().toString())) {
MessagesUtil.sendDebugMessages("Hiding cosmetics due to gamemode");
hideCosmetics(HiddenReason.GAMEMODE);
} else if (this.isHidden(HiddenReason.GAMEMODE)) {
MessagesUtil.sendDebugMessages("Showing cosmetics for gamemode");
showCosmetics(HiddenReason.GAMEMODE);
}
if (bukkitPlayer != null && Settings.getDisabledWorlds().contains(getEntity().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 (Settings.isAllPlayersHidden()) {
hideCosmetics(HiddenReason.DISABLED);
}
for (final HiddenReason reason : hiddenReasons) {
this.silentlyAddHideFlag(reason);
}
}
/**
* Start ticking against the {@link CosmeticUser}.
* @implNote The tick-rate is determined by the tick period specified in the configuration, if it is less-than or equal to 0
* there will be no {@link BukkitTask} created, and the {@link CosmeticUser#taskId} will be -1
*/
public final void startTicking() {
int tickPeriod = Settings.getTickPeriod();
if (tickPeriod > 0) {
BukkitTask task = Bukkit.getScheduler().runTaskTimer(HMCCosmeticsPlugin.getInstance(), run, 0, tickPeriod);
taskId = task.getTaskId();
if(tickPeriod <= 0) {
MessagesUtil.sendDebugMessages("CosmeticUser tick is disabled.");
return;
}
final BukkitTask task = Bukkit.getScheduler().runTaskTimer(HMCCosmeticsPlugin.getInstance(), this::tick, 0, tickPeriod);
this.taskId = task.getTaskId();
}
/**
* Dispatch an operation to happen against this {@link CosmeticUser}
* at a pre-determined tick-rate.
* The tick-rate is determined by the tick period specified in the configuration.
*/
protected void tick() {
MessagesUtil.sendDebugMessages("Tick[uuid=" + uniqueId + "]", Level.INFO);
if (Hooks.isInvisible(uniqueId)) {
this.hideCosmetics(HiddenReason.VANISH);
} else {
this.showCosmetics(HiddenReason.VANISH);
}
this.updateCosmetic();
if(isHidden() && !getUserEmoteManager().isPlayingEmote() && !getCosmetics().isEmpty()) {
MessagesUtil.sendActionBar(getPlayer(), "hidden-cosmetics");
}
}
public void destroy() {
if(this.taskId != -1) { // ensure we're actually ticking this user.
Bukkit.getScheduler().cancelTask(taskId);
}
despawnBackpack();
despawnBalloon();
}
@@ -89,20 +211,15 @@ public class CosmeticUser {
return playerCosmetics.get(slot);
}
@Deprecated
public Collection<Cosmetic> getCosmetic() {
return playerCosmetics.values();
}
public ImmutableCollection<Cosmetic> getCosmetics() {
return ImmutableList.copyOf(playerCosmetics.values());
}
public void addPlayerCosmetic(Cosmetic cosmetic) {
public void addPlayerCosmetic(@NotNull Cosmetic cosmetic) {
addPlayerCosmetic(cosmetic, null);
}
public void addPlayerCosmetic(Cosmetic cosmetic, Color color) {
public void addPlayerCosmetic(@NotNull Cosmetic cosmetic, @Nullable Color color) {
// API
PlayerCosmeticEquipEvent event = new PlayerCosmeticEquipEvent(this, cosmetic);
Bukkit.getPluginManager().callEvent(event);
@@ -118,6 +235,7 @@ public class CosmeticUser {
playerCosmetics.put(cosmetic.getSlot(), cosmetic);
if (color != null) colors.put(cosmetic.getSlot(), color);
MessagesUtil.sendDebugMessages("addPlayerCosmetic[id=" + cosmetic.getId() + "]");
if (!isHidden()) {
if (cosmetic.getSlot() == CosmeticSlot.BACKPACK) {
CosmeticBackpackType backpackType = (CosmeticBackpackType) cosmetic;
spawnBackpack(backpackType);
@@ -127,6 +245,7 @@ public class CosmeticUser {
CosmeticBalloonType balloonType = (CosmeticBalloonType) cosmetic;
spawnBalloon(balloonType);
}
}
// API
PlayerCosmeticPostEquipEvent postEquipEvent = new PlayerCosmeticPostEquipEvent(this, cosmetic);
Bukkit.getPluginManager().callEvent(postEquipEvent);
@@ -134,12 +253,11 @@ public class CosmeticUser {
public void removeCosmetics() {
// Small optimization could be made, but Concurrent modification prevents us from both getting and removing
for (CosmeticSlot slot : CosmeticSlot.values()) {
for (CosmeticSlot slot : CosmeticSlot.values().values()) {
removeCosmeticSlot(slot);
}
}
public void removeCosmeticSlot(CosmeticSlot slot) {
// API
PlayerCosmeticRemoveEvent event = new PlayerCosmeticRemoveEvent(this, getCosmetic(slot));
@@ -162,7 +280,6 @@ public class CosmeticUser {
removeArmor(slot);
}
public void removeCosmeticSlot(Cosmetic cosmetic) {
removeCosmeticSlot(cosmetic.getSlot());
}
@@ -193,22 +310,45 @@ public class CosmeticUser {
}
public void updateCosmetic() {
MessagesUtil.sendDebugMessages("updateCosmetic (All) - start");
HashMap<EquipmentSlot, ItemStack> items = new HashMap<>();
for (Cosmetic cosmetic : getCosmetics()) {
if (cosmetic instanceof CosmeticArmorType armorType) {
if (getUserEmoteManager().isPlayingEmote() || isInWardrobe()) return;
if (!(getEntity() instanceof HumanEntity humanEntity)) return;
boolean requireEmpty = Settings.getSlotOption(armorType.getEquipSlot()).isRequireEmpty();
boolean isAir = humanEntity.getInventory().getItem(armorType.getEquipSlot()).getType().isAir();
MessagesUtil.sendDebugMessages("updateCosmetic (All) - " + armorType.getId() + " - " + requireEmpty + " - " + isAir);
if (requireEmpty && !isAir) continue;
items.put(HMCCInventoryUtils.getEquipmentSlot(armorType.getSlot()), armorType.getItem(this));
} else {
updateCosmetic(cosmetic.getSlot());
}
}
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) {
return getUserCosmeticItem(getCosmetic(slot));
Cosmetic cosmetic = getCosmetic(slot);
if (cosmetic == null) return new ItemStack(Material.AIR);
return getUserCosmeticItem(cosmetic);
}
public ItemStack getUserCosmeticItem(Cosmetic cosmetic) {
public ItemStack getUserCosmeticItem(@NotNull Cosmetic cosmetic) {
ItemStack item = null;
if (hideCosmetics) {
if (!hiddenReason.isEmpty()) {
if (cosmetic instanceof CosmeticBackpackType || cosmetic instanceof CosmeticBalloonType) return new ItemStack(Material.AIR);
return getPlayer().getInventory().getItem(InventoryUtils.getEquipmentSlot(cosmetic.getSlot()));
return getPlayer().getInventory().getItem(HMCCInventoryUtils.getEquipmentSlot(cosmetic.getSlot()));
}
if (cosmetic instanceof CosmeticArmorType || cosmetic instanceof CosmeticMainhandType || cosmetic instanceof CosmeticBackpackType) {
if (cosmetic instanceof CosmeticArmorType armorType) {
item = armorType.getItem(this, cosmetic.getItem());
}
if (cosmetic instanceof CosmeticBackpackType || cosmetic instanceof CosmeticMainhandType) {
item = cosmetic.getItem();
}
if (cosmetic instanceof CosmeticBalloonType) {
@@ -218,15 +358,15 @@ public class CosmeticUser {
item = cosmetic.getItem();
}
}
if (item == null) {
MessagesUtil.sendDebugMessages("GetUserCosemticUser Item is null");
return null;
}
return getUserCosmeticItem(cosmetic, item);
}
@SuppressWarnings("deprecation")
public ItemStack getUserCosmeticItem(Cosmetic cosmetic, ItemStack item) {
public ItemStack getUserCosmeticItem(@NotNull Cosmetic cosmetic, @Nullable ItemStack item) {
if (item == null) {
//MessagesUtil.sendDebugMessages("GetUserCosemticUser Item is null");
return new ItemStack(Material.AIR);
}
if (item.hasItemMeta()) {
ItemMeta itemMeta = item.getItemMeta();
@@ -253,18 +393,22 @@ public class CosmeticUser {
itemMeta = skullMeta;
}
if (Settings.isItemProcessingDisplayName()) {
if (itemMeta.hasDisplayName()) {
String displayName = itemMeta.getDisplayName();
itemMeta.setDisplayName(Hooks.processPlaceholders(getPlayer(), displayName));
}
}
if (Settings.isItemProcessingLore()) {
List<String> processedLore = new ArrayList<>();
if (itemMeta.hasLore()) {
for (String loreLine : itemMeta.getLore()) {
processedLore.add(Hooks.processPlaceholders(getPlayer(), loreLine));
}
}
if (itemMeta.hasDisplayName()) {
String displayName = itemMeta.getDisplayName();
itemMeta.setDisplayName(Hooks.processPlaceholders(getPlayer(), displayName));
}
itemMeta.setLore(processedLore);
}
if (colors.containsKey(cosmetic.getSlot())) {
Color color = colors.get(cosmetic.getSlot());
@@ -274,9 +418,18 @@ public class CosmeticUser {
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(InventoryUtils.getCosmeticKey(), PersistentDataType.STRING, cosmetic.getId());
itemMeta.getPersistentDataContainer().set(HMCCInventoryUtils.getCosmeticKey(), PersistentDataType.STRING, cosmetic.getId());
itemMeta.getPersistentDataContainer().set(InventoryUtils.getOwnerKey(), PersistentDataType.STRING, getEntity().getUniqueId().toString());
item.setItemMeta(itemMeta);
@@ -292,7 +445,22 @@ public class CosmeticUser {
return userWardrobeManager;
}
public void enterWardrobe(boolean ignoreDistance, Wardrobe wardrobe) {
/**
* Use {@link #enterWardrobe(Wardrobe, boolean)} instead.
* @param ignoreDistance
* @param wardrobe
*/
@Deprecated(forRemoval = true, since = "2.7.5")
public void enterWardrobe(boolean ignoreDistance, @NotNull Wardrobe wardrobe) {
enterWardrobe(wardrobe, ignoreDistance);
}
/**
* This method is used to enter a wardrobe. You can listen to the {@link PlayerWardrobeEnterEvent} to cancel the event or modify any data.
* @param wardrobe The wardrobe to enter. Use {@link WardrobeSettings#getWardrobe(String)} to get pre-existing wardrobe or use your own by {@link Wardrobe}.
* @param ignoreDistance If true, the player can enter the wardrobe from any distance. If false, the player must be within the distance set in the wardrobe (If wardrobe has a distance of 0 or lower, the player can enter from any distance).
*/
public void enterWardrobe(@NotNull Wardrobe wardrobe, boolean ignoreDistance) {
if (wardrobe.hasPermission() && !getPlayer().hasPermission(wardrobe.getPermission())) {
MessagesUtil.sendMessage(getPlayer(), "no-permission");
return;
@@ -318,7 +486,19 @@ public class CosmeticUser {
}
}
/**
* Use {@link #leaveWardrobe(boolean)} instead.
*/
@Deprecated(forRemoval = true, since = "2.7.5")
public void leaveWardrobe() {
leaveWardrobe(false);
}
/**
* Causes the player to leave the wardrobe. If a player is not in the wardrobe, this will do nothing, use (@{@link #isInWardrobe()} to check if they are).
* @param ejected If true, the player was ejected from the wardrobe (Skips transition). If false, the player left the wardrobe normally.
*/
public void leaveWardrobe(boolean ejected) {
PlayerWardrobeLeaveEvent event = new PlayerWardrobeLeaveEvent(this);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
@@ -328,8 +508,9 @@ public class CosmeticUser {
if (!getWardrobeManager().getWardrobeStatus().equals(UserWardrobeManager.WardrobeStatus.RUNNING)) return;
getWardrobeManager().setWardrobeStatus(UserWardrobeManager.WardrobeStatus.STOPPING);
getWardrobeManager().setLastOpenMenu(Menus.getDefaultMenu());
if (WardrobeSettings.isEnabledTransition()) {
if (WardrobeSettings.isEnabledTransition() && !ejected) {
MessagesUtil.sendTitle(
getPlayer(),
WardrobeSettings.getTransitionText(),
@@ -347,6 +528,10 @@ public class CosmeticUser {
}
}
/**
* This checks if the player is in a wardrobe. If they are, it will return true, else false. See {@link #getWardrobeManager()} to get the wardrobe manager.
* @return If the player is in a wardrobe.
*/
public boolean isInWardrobe() {
return userWardrobeManager != null;
}
@@ -367,18 +552,27 @@ public class CosmeticUser {
return this.userBackpackManager != null;
}
public boolean isBalloonSpawned() {
return this.userBalloonManager != null;
}
public void spawnBalloon(CosmeticBalloonType cosmeticBalloonType) {
if (this.userBalloonManager != null) return;
this.userBalloonManager = NMSHandlers.getHandler().spawnBalloon(this, cosmeticBalloonType);
//updateCosmetic(cosmeticBalloonType);
org.bukkit.entity.Entity entity = getEntity();
UserBalloonManager userBalloonManager1 = new UserBalloonManager(this, entity.getLocation());
userBalloonManager1.getModelEntity().teleport(entity.getLocation().add(cosmeticBalloonType.getBalloonOffset()));
userBalloonManager1.spawnModel(cosmeticBalloonType, getCosmeticColor(cosmeticBalloonType.getSlot()));
userBalloonManager1.addPlayerToModel(this, cosmeticBalloonType, getCosmeticColor(cosmeticBalloonType.getSlot()));
this.userBalloonManager = userBalloonManager1;
//this.userBalloonManager = NMSHandlers.getHandler().spawnBalloon(this, cosmeticBalloonType);
}
public void despawnBalloon() {
if (this.userBalloonManager == null) return;
List<Player> sentTo = PlayerUtils.getNearbyPlayers(getEntity().getLocation());
PacketManager.sendEntityDestroyPacket(userBalloonManager.getPufferfishBalloonId(), sentTo);
this.userBalloonManager.remove();
this.userBalloonManager = null;
}
@@ -387,23 +581,27 @@ public class CosmeticUser {
if (!hasCosmeticInSlot(CosmeticSlot.BACKPACK)) return;
final Cosmetic cosmetic = getCosmetic(CosmeticSlot.BACKPACK);
despawnBackpack();
if (!hiddenReason.isEmpty()) return;
spawnBackpack((CosmeticBackpackType) cosmetic);
MessagesUtil.sendDebugMessages("Respawned Backpack for " + getEntity().getName());
}
public void respawnBalloon() {
if (!hasCosmeticInSlot(CosmeticSlot.BALLOON)) return;
final Cosmetic cosmetic = getCosmetic(CosmeticSlot.BALLOON);
despawnBalloon();
if (!hiddenReason.isEmpty()) return;
spawnBalloon((CosmeticBalloonType) cosmetic);
MessagesUtil.sendDebugMessages("Respawned Balloon for " + getEntity().getName());
}
public void removeArmor(CosmeticSlot slot) {
EquipmentSlot equipmentSlot = InventoryUtils.getEquipmentSlot(slot);
EquipmentSlot equipmentSlot = HMCCInventoryUtils.getEquipmentSlot(slot);
if (equipmentSlot == null) return;
if (getPlayer() != null) {
NMSHandlers.getHandler().equipmentSlotUpdate(getEntity().getEntityId(), equipmentSlot, getPlayer().getInventory().getItem(equipmentSlot), PlayerUtils.getNearbyPlayers(getEntity().getLocation()));
PacketManager.equipmentSlotUpdate(getEntity().getEntityId(), equipmentSlot, getPlayer().getInventory().getItem(equipmentSlot), HMCCPacketManager.getViewers(getEntity().getLocation()));
} else {
PacketManager.equipmentSlotUpdate(getEntity().getEntityId(), this, slot, PlayerUtils.getNearbyPlayers(getEntity().getLocation()));
HMCCPacketManager.equipmentSlotUpdate(getEntity().getEntityId(), this, slot, HMCCPacketManager.getViewers(getEntity().getLocation()));
}
}
@@ -470,28 +668,35 @@ public class CosmeticUser {
}
public void hideCosmetics(HiddenReason reason) {
if (hideCosmetics) return;
PlayerCosmeticHideEvent event = new PlayerCosmeticHideEvent(this, reason);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
hideCosmetics = true;
hiddenReason = reason;
if (!hiddenReason.contains(reason)) hiddenReason.add(reason);
if (hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
getBalloonManager().removePlayerFromModel(getPlayer());
getBalloonManager().sendRemoveLeashPacket();
despawnBalloon();
//getBalloonManager().removePlayerFromModel(getPlayer());
//getBalloonManager().sendRemoveLeashPacket();
}
if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
userBackpackManager.clearItems();
despawnBackpack();
}
updateCosmetic();
MessagesUtil.sendDebugMessages("HideCosmetics");
}
public void showCosmetics() {
if (!hideCosmetics) return;
/**
* This is used to silently add a hidden flag to the user. This will not trigger any events or checks, nor do anything else
* @param reason
*/
public void silentlyAddHideFlag(HiddenReason reason) {
if (!hiddenReason.contains(reason)) hiddenReason.add(reason);
}
public void showCosmetics(HiddenReason reason) {
if (hiddenReason.isEmpty()) return;
PlayerCosmeticShowEvent event = new PlayerCosmeticShowEvent(this);
Bukkit.getPluginManager().callEvent(event);
@@ -499,15 +704,17 @@ public class CosmeticUser {
return;
}
hideCosmetics = false;
hiddenReason = HiddenReason.NONE;
hiddenReason.remove(reason);
if (isHidden()) return;
if (hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
if (!isBalloonSpawned()) respawnBalloon();
CosmeticBalloonType balloonType = (CosmeticBalloonType) getCosmetic(CosmeticSlot.BALLOON);
getBalloonManager().addPlayerToModel(this, balloonType);
List<Player> viewer = PlayerUtils.getNearbyPlayers(getEntity().getLocation());
PacketManager.sendLeashPacket(getBalloonManager().getPufferfishBalloonId(), getPlayer().getEntityId(), viewer);
List<Player> viewer = HMCCPacketManager.getViewers(getEntity().getLocation());
HMCCPacketManager.sendLeashPacket(getBalloonManager().getPufferfishBalloonId(), getPlayer().getEntityId(), viewer);
}
if (hasCosmeticInSlot(CosmeticSlot.BACKPACK) && isBackpackSpawned()) {
if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
if (!isBackpackSpawned()) respawnBackpack();
CosmeticBackpackType cosmeticBackpackType = (CosmeticBackpackType) getCosmetic(CosmeticSlot.BACKPACK);
ItemStack item = getUserCosmeticItem(cosmeticBackpackType);
userBackpackManager.setItem(item);
@@ -516,17 +723,43 @@ public class CosmeticUser {
MessagesUtil.sendDebugMessages("ShowCosmetics");
}
/**
* This method is deprecated and will be removed in the future. Use {@link #isHidden()} instead.
* @return
*/
@Deprecated(since = "2.7.2-DEV", forRemoval = true)
public boolean getHidden() {
return this.hideCosmetics;
return !hiddenReason.isEmpty();
}
public boolean isHidden() {
return !hiddenReason.isEmpty();
}
public boolean isHidden(HiddenReason reason) {
return hiddenReason.contains(reason);
}
public List<HiddenReason> getHiddenReasons() {
return hiddenReason;
}
public void clearHiddenReasons() {
hiddenReason.clear();
}
public enum HiddenReason {
NONE,
WORLDGUARD,
PLUGIN,
VANISH,
POTION,
ACTION,
COMMAND,
EMOTE
EMOTE,
GAMEMODE,
WORLD,
DISABLED
}
}

View File

@@ -0,0 +1,44 @@
package com.hibiscusmc.hmccosmetics.user;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
/**
* Allow custom implementations of a {@link CosmeticUser}.
*/
public abstract class CosmeticUserProvider {
/**
* Construct the custom {@link CosmeticUser}.
* @param playerId the player uuid
* @return the {@link CosmeticUser}
* @apiNote This method is called during the {@link PlayerJoinEvent}.
*/
public abstract @NotNull CosmeticUser createCosmeticUser(@NotNull UUID playerId);
/**
* Represents the plugin that is providing this {@link CosmeticUserProvider}
* @return the plugin
*/
public abstract Plugin getProviderPlugin();
/**
* Default implementation.
*/
static class Default extends CosmeticUserProvider {
public static CosmeticUserProvider INSTANCE = new Default();
@Override
public @NotNull CosmeticUser createCosmeticUser(@NotNull UUID playerId) {
return new CosmeticUser(playerId);
}
@Override
public Plugin getProviderPlugin() {
return HMCCosmeticsPlugin.getInstance();
}
}
}

View File

@@ -1,51 +1,111 @@
package com.hibiscusmc.hmccosmetics.user;
import com.google.common.collect.HashBiMap;
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class CosmeticUsers {
private static HashBiMap<UUID, CosmeticUser> COSMETIC_USERS = HashBiMap.create();
private static final ConcurrentHashMap<UUID, CosmeticUser> COSMETIC_USERS = new ConcurrentHashMap<>();
public static void addUser(CosmeticUser user) {
private static CosmeticUserProvider PROVIDER = CosmeticUserProvider.Default.INSTANCE;
/**
* Adds a user to the Hashmap of stored CosmeticUsers. This will not override an entry if it already exists. If you need to override, delete then add.
* @param user The user to add to the HashMap.
*/
public static void addUser(@NotNull CosmeticUser user) {
if (COSMETIC_USERS.containsKey(user.getUniqueId())) return; // do not add if already exists
COSMETIC_USERS.put(user.getUniqueId(), user);
}
/**
* Removes a CosmeticUser from the Hashmap
* @param uuid The UUID to remove.
*/
public static void removeUser(UUID uuid) {
COSMETIC_USERS.remove(uuid);
}
public static void removeUser(CosmeticUser user) {
COSMETIC_USERS.remove(user);
/**
* Removes a CosmeticUser from the hashmap by their CosmeticUser method
* @param user The user to be removed (will get their UUID from this class)
*/
public static void removeUser(@NotNull CosmeticUser user) {
COSMETIC_USERS.remove(user.getUniqueId());
}
/**
* This method allows you to get a CosmeticUser from their UUID. If you are using not internally, HIGHLY recommend to use the API implementation of this.
* @param uuid The UUID of the user that you wish to lookup.
* @return Returns the user if there is a valid user, returns null if not.
*/
@Nullable
public static CosmeticUser getUser(UUID uuid) {
return COSMETIC_USERS.get(uuid);
}
/**
* This method allows you to get a CosmeticUser from just using the player class. This just allows you to have a bit less boilerplate.
* @param player The player to lookup (will take their UUID from the class)
* @return Returns the user if there is a valid user, returns null if not.
*/
@Nullable
public static CosmeticUser getUser(Player player) {
public static CosmeticUser getUser(@NotNull Player player) {
return COSMETIC_USERS.get(player.getUniqueId());
}
/**
* This method gets the CosmeticUser from an entity id (said entity must be a player). This is not ideal, as it requires the plugin to go through all entities, but it's a possibility.
* @param entityId The entity ID in an integer.
* @return The cosmetic user if there is an entity id associated with that.
*/
@Nullable
public static CosmeticUser getUser(int entityId) {
Entity entity = ServerUtils.getEntity(entityId);
Entity entity = HMCCServerUtils.getEntity(entityId);
if (entity == null) return null;
if (entity.getType().equals(EntityType.PLAYER)) return null;
return COSMETIC_USERS.get(entity.getUniqueId());
if (!(entity instanceof Player player)) return null;
return COSMETIC_USERS.get(player.getUniqueId());
}
/**
* Register a custom {@link CosmeticUserProvider} to provide your own user implementation to
* be used and queried.
* @param provider the provider to register
* @throws IllegalArgumentException if the provider is already registered by another plugin
*/
public static void registerProvider(final CosmeticUserProvider provider) {
if(PROVIDER != CosmeticUserProvider.Default.INSTANCE) {
throw new IllegalArgumentException("CosmeticUserProvider already registered by %s, this conflicts with %s attempting to register their own.".formatted(
PROVIDER.getProviderPlugin().getName(),
provider.getProviderPlugin().getName()
));
}
PROVIDER = provider;
}
/**
* Fetch the current {@link CosmeticUserProvider} being used.
* @return the current {@link CosmeticUserProvider} being used
*/
public static CosmeticUserProvider getProvider() {
return PROVIDER;
}
/**
* Gets all the values for CosmeticUsers to allow you to iterate over everyone.
* @return CosmeticUsers in a set. This will never be null, but might be empty.
*/
@NotNull
public static Set<CosmeticUser> values() {
return COSMETIC_USERS.values();
// fix this later; this is a temporary fix. It was originally a set, now it's a collection
return Set.copyOf(COSMETIC_USERS.values());
}
}

View File

@@ -2,13 +2,14 @@ package com.hibiscusmc.hmccosmetics.user.manager;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
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.entity.Entity;
import org.bukkit.entity.EntityType;
@@ -36,9 +37,9 @@ public class UserBackpackManager {
public UserBackpackManager(CosmeticUser user) {
this.user = user;
this.backpackHidden = false;
this.invisibleArmorStand = NMSHandlers.getHandler().getNextEntityId();
this.invisibleArmorStand = ServerUtils.getNextEntityId();
this.entityManager = new UserEntity(user.getUniqueId());
this.entityManager.refreshViewers(user.getEntity().getLocation());
if (user.getEntity() != null) this.entityManager.refreshViewers(user.getEntity().getLocation()); // Fixes an issue where a player, who somehow removes their potions, but doesn't have an entity produces an NPE (it's dumb)
}
public int getFirstArmorStandId() {
@@ -55,8 +56,8 @@ public class UserBackpackManager {
getEntityManager().setIds(List.of(invisibleArmorStand));
getEntityManager().teleport(user.getEntity().getLocation());
List<Player> outsideViewers = getEntityManager().getViewers();
PacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), getFirstArmorStandId(), EntityType.ARMOR_STAND, UUID.randomUUID(), getEntityManager().getViewers());
PacketManager.sendArmorstandMetadata(getFirstArmorStandId(), outsideViewers);
HMCCPacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), getFirstArmorStandId(), EntityType.ARMOR_STAND, UUID.randomUUID(), getEntityManager().getViewers());
HMCCPacketManager.sendArmorstandMetadata(getFirstArmorStandId(), outsideViewers);
Entity entity = user.getEntity();
@@ -73,51 +74,37 @@ public class UserBackpackManager {
if (cosmeticBackpackType.isFirstPersonCompadible()) {
for (int i = particleCloud.size(); i < cosmeticBackpackType.getHeight(); i++) {
int entityId = NMSHandlers.getHandler().getNextEntityId();
PacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), entityId, EntityType.AREA_EFFECT_CLOUD, UUID.randomUUID());
PacketManager.sendCloudEffect(entityId, PacketManager.getViewers(user.getEntity().getLocation()));
int entityId = ServerUtils.getNextEntityId();
HMCCPacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), entityId, EntityType.AREA_EFFECT_CLOUD, UUID.randomUUID());
HMCCPacketManager.sendCloudEffect(entityId, HMCCPacketManager.getViewers(user.getEntity().getLocation()));
this.particleCloud.add(entityId);
}
// Copied code from updating the backpack
for (int i = 0; i < particleCloud.size(); i++) {
if (i == 0) PacketManager.sendRidingPacket(entity.getEntityId(), particleCloud.get(i), owner);
else PacketManager.sendRidingPacket(particleCloud.get(i - 1), particleCloud.get(i) , owner);
if (i == 0) HMCCPacketManager.sendRidingPacket(entity.getEntityId(), particleCloud.get(i), owner);
else HMCCPacketManager.sendRidingPacket(particleCloud.get(i - 1), particleCloud.get(i) , owner);
}
PacketManager.sendRidingPacket(particleCloud.get(particleCloud.size() - 1), user.getUserBackpackManager().getFirstArmorStandId(), owner);
if (!user.getHidden()) NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(cosmeticBackpackType, cosmeticBackpackType.getFirstPersonBackpack()), owner);
}
NMSHandlers.getHandler().equipmentSlotUpdate(getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(cosmeticBackpackType), outsideViewers);
PacketManager.sendRidingPacket(entity.getEntityId(), passengerIDs, outsideViewers);
// No one should be using ME because it barely works but some still use it, so it's here
if (cosmeticBackpackType.getModelName() != null && Hooks.isActiveHook("ModelEngine")) {
if (ModelEngineAPI.api.getModelRegistry().getBlueprint(cosmeticBackpackType.getModelName()) == null) {
MessagesUtil.sendDebugMessages("Invalid Model Engine Blueprint " + cosmeticBackpackType.getModelName(), Level.SEVERE);
return;
}
/* TODO: Readd ModelEngine support
ModeledEntity modeledEntity = ModelEngineAPI.createModeledEntity(new PacketBaseEntity(getFirstArmorStandId(), UUID.randomUUID(), entity.getLocation()));
ActiveModel model = ModelEngineAPI.createActiveModel(ModelEngineAPI.getBlueprint(cosmeticBackpackType.getModelName()));
model.setCanHurt(false);
modeledEntity.addModel(model, false);
*/
HMCCPacketManager.sendRidingPacket(particleCloud.get(particleCloud.size() - 1), 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);
HMCCPacketManager.sendRidingPacket(entity.getEntityId(), passengerIDs, outsideViewers);
MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Finish");
}
public void despawnBackpack() {
PacketManager.sendEntityDestroyPacket(invisibleArmorStand, getEntityManager().getViewers());
HMCCPacketManager.sendEntityDestroyPacket(invisibleArmorStand, getEntityManager().getViewers());
if (particleCloud != null) {
for (Integer entityId : particleCloud) {
PacketManager.sendEntityDestroyPacket(entityId, getEntityManager().getViewers());
HMCCPacketManager.sendEntityDestroyPacket(entityId, getEntityManager().getViewers());
}
this.particleCloud = null;
}
}
public void hideBackpack() {
if (user.getHidden()) return;
if (user.isHidden()) return;
//getArmorStand().getEquipment().clear();
backpackHidden = true;
}
@@ -139,11 +126,11 @@ public class UserBackpackManager {
}
public void setItem(ItemStack item) {
NMSHandlers.getHandler().equipmentSlotUpdate(getFirstArmorStandId(), EquipmentSlot.HEAD, item, getEntityManager().getViewers());
PacketManager.equipmentSlotUpdate(getFirstArmorStandId(), EquipmentSlot.HEAD, item, getEntityManager().getViewers());
}
public void clearItems() {
ItemStack item = new ItemStack(Material.AIR);
NMSHandlers.getHandler().equipmentSlotUpdate(getFirstArmorStandId(), EquipmentSlot.HEAD, item, getEntityManager().getViewers());
PacketManager.equipmentSlotUpdate(getFirstArmorStandId(), EquipmentSlot.HEAD, item, getEntityManager().getViewers());
}
}

View File

@@ -3,20 +3,25 @@ package com.hibiscusmc.hmccosmetics.user.manager;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
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;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
@@ -26,6 +31,8 @@ import java.util.logging.Level;
public class UserBalloonManager {
private final CosmeticUser user;
@Getter
private BalloonType balloonType;
private CosmeticBalloonType cosmeticBalloonType;
@Getter
@@ -33,8 +40,18 @@ public class UserBalloonManager {
private final ArmorStand modelEntity;
public UserBalloonManager(CosmeticUser user, @NotNull Location location) {
this.pufferfish = new UserBalloonPufferfish(user.getUniqueId(), NMSHandlers.getHandler().getNextEntityId(), UUID.randomUUID());
this.modelEntity = NMSHandlers.getHandler().getMEGEntity(location.add(Settings.getBalloonOffset()));
this.user = user;
this.pufferfish = new UserBalloonPufferfish(user.getUniqueId(), NMSHandlers.getHandler().getUtilHandler().getNextEntityId(), UUID.randomUUID());
this.modelEntity = location.getWorld().spawn(location, ArmorStand.class, (e) -> {
e.setInvisible(true);
e.setGravity(false);
e.setSilent(true);
e.setInvulnerable(true);
e.setSmall(true);
e.setMarker(true);
e.setPersistent(false);
e.getPersistentDataContainer().set(new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "cosmeticMob"), PersistentDataType.SHORT, Short.valueOf("1"));
});
}
public void spawnModel(@NotNull CosmeticBalloonType cosmeticBalloonType, Color color) {
@@ -54,7 +71,7 @@ public class UserBalloonManager {
if (balloonType == BalloonType.MODELENGINE) {
String id = cosmeticBalloonType.getModelName();
MessagesUtil.sendDebugMessages("Attempting Spawning for " + id);
if (ModelEngineAPI.api.getModelRegistry().getBlueprint(id) == null) {
if (ModelEngineAPI.getBlueprint(id) == null) {
MessagesUtil.sendDebugMessages("Invalid Model Engine Blueprint " + id, Level.SEVERE);
return;
}
@@ -62,14 +79,19 @@ public class UserBalloonManager {
ActiveModel model = ModelEngineAPI.createActiveModel(ModelEngineAPI.getBlueprint(id));
model.setCanHurt(false);
modeledEntity.addModel(model, false);
if (color != null) {
modeledEntity.getModels().forEach((d, singleModel) -> {
if (cosmeticBalloonType.isDyablePart(d)) {
singleModel.getRendererHandler().setColor(color);
singleModel.getRendererHandler().update();
singleModel.setDefaultTint(color);
singleModel.getModelRenderer().sendToClient(ModelEngineAPI.getNMSHandler().createParsers());
}
});
}
BukkitEntityData data = (BukkitEntityData) modeledEntity.getBase().getData();
data.setBlockedCullIgnoreRadius((double) Settings.getViewDistance());
data.getTracked().setPlayerPredicate(this::playerCheck);
return;
}
if (balloonType == BalloonType.ITEM) {
@@ -78,19 +100,21 @@ public class UserBalloonManager {
}
public void remove() {
pufferfish.destroyPufferfish();
if (balloonType == BalloonType.MODELENGINE) {
final ModeledEntity entity = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId());
if (entity == null) return;
for (final Player player : entity.getRangeManager().getPlayerInRange()) {
entity.hideFromPlayer(player);
final ModeledEntity entity = ModelEngineAPI.getModeledEntity(modelEntity);
if (entity == null) {
MessagesUtil.sendDebugMessages("Balloon Removal Failed - Model Entity is Null");
return;
}
entity.destroy();
MessagesUtil.sendDebugMessages("Balloon Model Engine Removal");
}
modelEntity.remove();
cosmeticBalloonType = null;
MessagesUtil.sendDebugMessages("Balloon Entity Removed");
}
public void addPlayerToModel(final CosmeticUser user, final CosmeticBalloonType cosmeticBalloonType) {
@@ -99,14 +123,13 @@ public class UserBalloonManager {
public void addPlayerToModel(final CosmeticUser user, final CosmeticBalloonType cosmeticBalloonType, Color color) {
if (balloonType == BalloonType.MODELENGINE) {
final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId());
final ModeledEntity model = ModelEngineAPI.getModeledEntity(modelEntity);
if (model == null) {
spawnModel(cosmeticBalloonType, color);
MessagesUtil.sendDebugMessages("model is null");
return;
}
//if (model.getRangeManager().getPlayerInRange().contains(player)) return;
model.showToPlayer(user.getPlayer());
MessagesUtil.sendDebugMessages("Show to player");
return;
}
@@ -114,13 +137,11 @@ public class UserBalloonManager {
modelEntity.getEquipment().setHelmet(user.getUserCosmeticItem(cosmeticBalloonType));
}
}
public void removePlayerFromModel(final Player player) {
public void removePlayerFromModel(final Player viewer) {
if (balloonType == BalloonType.MODELENGINE) {
final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId());
final ModeledEntity model = ModelEngineAPI.getModeledEntity(modelEntity);
if (model == null) return;
model.hideFromPlayer(player);
MessagesUtil.sendDebugMessages("Hidden from player");
return;
}
@@ -136,8 +157,9 @@ public class UserBalloonManager {
public int getPufferfishBalloonId() {
return pufferfish.getId();
return pufferfish.getPufferFishEntityId();
}
public UUID getPufferfishBalloonUniqueId() {
return pufferfish.getUuid();
}
@@ -163,17 +185,16 @@ public class UserBalloonManager {
}
public void sendRemoveLeashPacket(List<Player> viewer) {
PacketManager.sendLeashPacket(getPufferfishBalloonId(), -1, viewer);
HMCCPacketManager.sendLeashPacket(getPufferfishBalloonId(), -1, viewer);
}
public void sendRemoveLeashPacket() {
PacketManager.sendLeashPacket(getPufferfishBalloonId(), -1, getLocation());
HMCCPacketManager.sendLeashPacket(getPufferfishBalloonId(), -1, getLocation());
}
public void sendLeashPacket(int entityId) {
if (cosmeticBalloonType == null) return;
if (cosmeticBalloonType.isShowLead()) {
PacketManager.sendLeashPacket(getPufferfishBalloonId(), entityId, getLocation());
HMCCPacketManager.sendLeashPacket(getPufferfishBalloonId(), entityId, getLocation());
}
}
@@ -182,4 +203,21 @@ public class UserBalloonManager {
ITEM,
NONE
}
private boolean playerCheck(final Player player) {
MessagesUtil.sendDebugMessages("playerCheck");
CosmeticUser viewer = CosmeticUsers.getUser(player.getUniqueId());
if (user.getPlayer() == player) {
return (!user.isHidden());
} else {
if (user.isInWardrobe()) return false;
MessagesUtil.sendDebugMessages("playerCheck - Not Same Player");
if (viewer != null && viewer.isInWardrobe()) {
MessagesUtil.sendDebugMessages("playerCheck - Viewer in Wardrobe");
return false;
}
}
return (!user.isHidden());
}
}

View File

@@ -1,8 +1,14 @@
package com.hibiscusmc.hmccosmetics.user.manager;
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
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 org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import java.util.ArrayList;
@@ -11,25 +17,37 @@ import java.util.UUID;
public class UserBalloonPufferfish extends UserEntity {
private int id;
private UUID uuid;
@Getter
private final int pufferFishEntityId;
@Getter
private final UUID uuid;
private boolean destroyed = false;
public UserBalloonPufferfish(UUID owner, int id, UUID uuid) {
public UserBalloonPufferfish(UUID owner, int pufferFishEntityId, UUID uuid) {
super(owner);
this.id = id;
this.pufferFishEntityId = pufferFishEntityId;
this.uuid = uuid;
}
public int getId() {
return id;
}
public UUID getUuid() {
return uuid;
}
public void hidePufferfish() {
PacketManager.sendEntityDestroyPacket(id, getViewers());
HMCCPacketManager.sendEntityDestroyPacket(pufferFishEntityId, getViewers());
getViewers().clear();
}
public void spawnPufferfish(Location location, List<Player> sendTo) {
HMCCPacketManager.sendEntitySpawnPacket(location, pufferFishEntityId, EntityType.PUFFERFISH, uuid, sendTo);
HMCCPacketManager.sendInvisibilityPacket(pufferFishEntityId, sendTo);
}
public void destroyPufferfish() {
HMCCPacketManager.sendEntityDestroyPacket(pufferFishEntityId, getViewers());
getViewers().clear();
destroyed = true;
}
@Override
public List<Player> refreshViewers(Location location) {
if (destroyed) return List.of(); //Prevents refreshing a destroyed entity
return super.refreshViewers(location);
}
}

View File

@@ -4,7 +4,6 @@ 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.nms.NMSHandlers;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.bukkit.Bukkit;
@@ -49,7 +48,8 @@ public class UserEmoteManager {
}
// Show the text
if (text != null && textEntity == null) {
textEntity = NMSHandlers.getHandler().spawnDisplayEntity(user.getPlayer().getLocation().add(0, 3, 0), text);
// removed in 2.7.0
//textEntity = HMCCNMSHandlers.getHandler().spawnDisplayEntity(user.getPlayer().getLocation().add(0, 3, 0), text);
}
} catch (Exception e) {
e.printStackTrace();

View File

@@ -2,12 +2,12 @@ package com.hibiscusmc.hmccosmetics.user.manager;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
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;
@@ -29,7 +29,7 @@ public class UserEmoteModel extends PlayerModel {
public UserEmoteModel(@NotNull CosmeticUser user) {
super(user.getPlayer());
this.user = user;
armorStandId = NMSHandlers.getHandler().getNextEntityId();
armorStandId = ServerUtils.getNextEntityId();
getRangeManager().setRenderDistance(Settings.getViewDistance());
}
@@ -42,9 +42,9 @@ public class UserEmoteModel extends PlayerModel {
// Add config option that either allows player to move or forces them into a spot.
Player player = user.getPlayer();
List<Player> viewer = Collections.singletonList(user.getPlayer());
List<Player> outsideViewers = PacketManager.getViewers(player.getLocation());
List<Player> outsideViewers = HMCCPacketManager.getViewers(player.getLocation());
// Send equipment packet to the player as well (Fixes Optifine still rendering armor when emoting)
PacketManager.equipmentSlotUpdate(player, true, outsideViewers);
HMCCPacketManager.equipmentSlotUpdate(player, true, outsideViewers);
outsideViewers.remove(player);
user.getPlayer().setInvisible(true);
@@ -75,12 +75,12 @@ public class UserEmoteModel extends PlayerModel {
MessagesUtil.sendMessage(player, "emote-blocked");
}
PacketManager.sendEntitySpawnPacket(thirdPersonLocation, armorStandId, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer);
PacketManager.sendInvisibilityPacket(armorStandId, viewer);
PacketManager.sendLookPacket(armorStandId, thirdPersonLocation, viewer);
HMCCPacketManager.sendEntitySpawnPacket(thirdPersonLocation, armorStandId, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer);
HMCCPacketManager.sendInvisibilityPacket(armorStandId, viewer);
HMCCPacketManager.sendLookPacket(armorStandId, thirdPersonLocation, viewer);
PacketManager.gamemodeChangePacket(player, 3);
PacketManager.sendCameraPacket(armorStandId, viewer);
HMCCPacketManager.gamemodeChangePacket(player, 3);
HMCCPacketManager.sendCameraPacket(armorStandId, viewer);
}
@@ -108,23 +108,23 @@ public class UserEmoteModel extends PlayerModel {
if (player == null) return;
List<Player> viewer = Collections.singletonList(player);
List<Player> outsideViewers = PacketManager.getViewers(player.getLocation());
List<Player> outsideViewers = HMCCPacketManager.getViewers(player.getLocation());
// Send Equipment packet to all (Fixes Optifine Issue)
PacketManager.equipmentSlotUpdate(player, false, outsideViewers);
HMCCPacketManager.equipmentSlotUpdate(player, false, outsideViewers);
outsideViewers.remove(player);
int entityId = player.getEntityId();
PacketManager.sendCameraPacket(entityId, viewer);
PacketManager.sendEntityDestroyPacket(armorStandId, viewer);
HMCCPacketManager.sendCameraPacket(entityId, viewer);
HMCCPacketManager.sendEntityDestroyPacket(armorStandId, viewer);
if (this.originalGamemode != null) {
PacketManager.gamemodeChangePacket(player, ServerUtils.convertGamemode(this.originalGamemode));
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();
user.showCosmetics(CosmeticUser.HiddenReason.EMOTE);
});
}

View File

@@ -1,11 +1,14 @@
package com.hibiscusmc.hmccosmetics.user.manager;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
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.Player;
@@ -20,7 +23,9 @@ public class UserEntity {
@Getter
private List<Player> viewers = new ArrayList<>();
@Getter @Setter
private Long lastUpdate = 0L;
private Long viewerLastUpdate = 0L;
@Getter @Setter
private Long lastPositionUpdate = 0L;
@Getter @Setter
private List<Integer> ids = new ArrayList<>();
@Getter
@@ -35,16 +40,21 @@ public class UserEntity {
}
public List<Player> refreshViewers(Location location) {
if (System.currentTimeMillis() - lastUpdate <= 1000) return List.of(); //Prevents mass refreshes
if (System.currentTimeMillis() - viewerLastUpdate <= 1000) return List.of(); //Prevents mass refreshes
ArrayList<Player> newPlayers = new ArrayList<>();
ArrayList<Player> removePlayers = new ArrayList<>();
List<Player> players = PlayerUtils.getNearbyPlayers(location);
List<Player> players = HMCCPacketManager.getViewers(location);
Player ownerPlayer = Bukkit.getPlayer(owner);
if (ownerPlayer == null) {
MessagesUtil.sendDebugMessages("Owner is null (refreshViewers), returning empty list");
return List.of();
}
for (Player player : players) {
CosmeticUser user = CosmeticUsers.getUser(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
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);
PacketManager.sendEntityDestroyPacket(ids, List.of(player));
HMCCPacketManager.sendEntityDestroyPacket(ids, List.of(player));
continue;
}
if (!viewers.contains(player)) {
@@ -56,26 +66,39 @@ public class UserEntity {
for (Player viewerPlayer : viewers) {
if (!players.contains(viewerPlayer)) {
removePlayers.add(viewerPlayer);
PacketManager.sendEntityDestroyPacket(ids, List.of(viewerPlayer));
HMCCPacketManager.sendEntityDestroyPacket(ids, List.of(viewerPlayer));
}
}
}
viewers.removeAll(removePlayers);
lastUpdate = System.currentTimeMillis();
setViewerLastUpdate(System.currentTimeMillis());
return newPlayers;
}
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;
}
this.location = location;
for (Integer entity : ids) {
PacketManager.sendTeleportPacket(entity, location, false, getViewers());
HMCCPacketManager.sendTeleportPacket(entity, location, false, getViewers());
}
setLastPositionUpdate(System.currentTimeMillis());
}
public void setRotation(int yaw) {
setRotation(yaw, false);
}
public void setRotation(int yaw, boolean additonalPacket) {
location.setYaw(yaw);
for (Integer entity : ids) {
PacketManager.sendLookPacket(entity, location, getViewers());
// 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());
}
}
}

View File

@@ -9,12 +9,15 @@ import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
import com.hibiscusmc.hmccosmetics.gui.Menu;
import com.hibiscusmc.hmccosmetics.gui.Menus;
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import lombok.Getter;
import lombok.Setter;
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;
@@ -25,14 +28,12 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
public class UserWardrobeManager {
@@ -63,12 +64,16 @@ public class UserWardrobeManager {
private BossBar bossBar;
@Getter
private boolean active;
@Setter
@Getter
private WardrobeStatus wardrobeStatus;
@Getter
@Setter
private Menu lastOpenMenu;
public UserWardrobeManager(CosmeticUser user, Wardrobe wardrobe) {
NPC_ID = NMSHandlers.getHandler().getNextEntityId();
ARMORSTAND_ID = NMSHandlers.getHandler().getNextEntityId();
NPC_ID = me.lojosho.hibiscuscommons.util.ServerUtils.getNextEntityId();
ARMORSTAND_ID = me.lojosho.hibiscuscommons.util.ServerUtils.getNextEntityId();
WARDROBE_UUID = UUID.randomUUID();
this.user = user;
@@ -79,6 +84,10 @@ public class UserWardrobeManager {
this.viewingLocation = wardrobeLocation.getViewerLocation();
this.npcLocation = wardrobeLocation.getNpcLocation();
String defaultMenu = wardrobe.getDefaultMenu();
if (defaultMenu != null && Menus.hasMenu(defaultMenu)) this.lastOpenMenu = Menus.getMenu(defaultMenu);
else this.lastOpenMenu = Menus.getDefaultMenu();
wardrobeStatus = WardrobeStatus.SETUP;
}
@@ -92,64 +101,79 @@ public class UserWardrobeManager {
}
user.hidePlayer();
if (!Bukkit.getServer().getAllowFlight()) player.setAllowFlight(true);
List<Player> viewer = Collections.singletonList(player);
List<Player> outsideViewers = PacketManager.getViewers(viewingLocation);
List<Player> outsideViewers = HMCCPacketManager.getViewers(viewingLocation);
outsideViewers.remove(player);
MessagesUtil.sendMessage(player, "opened-wardrobe");
Runnable run = () -> {
if (!player.isOnline()) {
end();
return;
}
// Armorstand
PacketManager.sendEntitySpawnPacket(viewingLocation, ARMORSTAND_ID, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer);
PacketManager.sendArmorstandMetadata(ARMORSTAND_ID, viewer);
PacketManager.sendLookPacket(ARMORSTAND_ID, viewingLocation, viewer);
HMCCPacketManager.sendEntitySpawnPacket(viewingLocation, ARMORSTAND_ID, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer);
HMCCPacketManager.sendArmorstandMetadata(ARMORSTAND_ID, viewer);
HMCCPacketManager.sendLookPacket(ARMORSTAND_ID, viewingLocation, viewer);
// Player
PacketManager.gamemodeChangePacket(player, 3);
PacketManager.sendCameraPacket(ARMORSTAND_ID, viewer);
player.teleport(viewingLocation, PlayerTeleportEvent.TeleportCause.PLUGIN);
player.setInvisible(true);
HMCCPacketManager.gamemodeChangePacket(player, 3);
HMCCPacketManager.sendCameraPacket(ARMORSTAND_ID, viewer);
// NPC
npcName = "WardrobeNPC-" + NPC_ID;
while (npcName.length() > 16) {
npcName = npcName.substring(16);
}
PacketManager.sendFakePlayerInfoPacket(player, NPC_ID, WARDROBE_UUID, npcName, viewer);
HMCCPacketManager.sendFakePlayerInfoPacket(player, NPC_ID, WARDROBE_UUID, npcName, viewer);
// NPC 2
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
PacketManager.sendFakePlayerSpawnPacket(npcLocation, WARDROBE_UUID, NPC_ID, viewer);
PacketManager.sendPlayerOverlayPacket(NPC_ID, viewer);
if (!user.isInWardrobe()) return; // If a player exits the wardrobe right away, no need to spawn the NPC
HMCCPacketManager.sendFakePlayerSpawnPacket(npcLocation, WARDROBE_UUID, NPC_ID, viewer);
HMCCPacketManager.sendPlayerOverlayPacket(NPC_ID, viewer);
MessagesUtil.sendDebugMessages("Spawned Fake Player on " + npcLocation);
NMSHandlers.getHandler().hideNPCName(player, npcName);
NMSHandlers.getHandler().getPacketHandler().sendScoreboardHideNamePacket(player, npcName);
}, 4);
// Location
PacketManager.sendLookPacket(NPC_ID, npcLocation, viewer);
PacketManager.sendRotationPacket(NPC_ID, npcLocation, true, viewer);
HMCCPacketManager.sendLookPacket(NPC_ID, npcLocation, viewer);
HMCCPacketManager.sendRotationPacket(NPC_ID, npcLocation, true, viewer);
// Misc
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
// Maybe null as backpack maybe despawned before entering
if (user.getUserBackpackManager() == null) user.respawnBackpack();
if (user.isBackpackSpawned()) {
user.getUserBackpackManager().getEntityManager().teleport(npcLocation.clone().add(0, 2, 0));
NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(user.getCosmetic(CosmeticSlot.BACKPACK)), viewer);
PacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstArmorStandId(), viewer);
PacketManager.equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(user.getCosmetic(CosmeticSlot.BACKPACK)), viewer);
HMCCPacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstArmorStandId(), viewer);
}
}
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
if (user.getBalloonManager() == null) user.respawnBalloon();
if (user.isBalloonSpawned()) {
CosmeticBalloonType cosmetic = (CosmeticBalloonType) user.getCosmetic(CosmeticSlot.BALLOON);
user.getBalloonManager().sendRemoveLeashPacket(viewer);
user.getBalloonManager().sendLeashPacket(NPC_ID);
//PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getModelId(), NPC_ID, viewer);
Location balloonLocation = npcLocation.clone().add(cosmetic.getBalloonOffset());
PacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), balloonLocation , false, viewer);
HMCCPacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), balloonLocation, false, viewer);
user.getBalloonManager().getModelEntity().teleport(balloonLocation);
user.getBalloonManager().setLocation(balloonLocation);
}
}
if (WardrobeSettings.isEnabledBossbar()) {
float progress = WardrobeSettings.getBossbarProgress();
Component message = MessagesUtil.processStringNoKey(WardrobeSettings.getBossbarMessage());
Component message = MessagesUtil.processStringNoKey(player, WardrobeSettings.getBossbarMessage());
bossBar = BossBar.bossBar(message, progress, WardrobeSettings.getBossbarColor(), WardrobeSettings.getBossbarOverlay());
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
@@ -188,10 +212,12 @@ public class UserWardrobeManager {
Player player = user.getPlayer();
List<Player> viewer = Collections.singletonList(player);
List<Player> outsideViewers = PacketManager.getViewers(viewingLocation);
List<Player> outsideViewers = HMCCPacketManager.getViewers(viewingLocation);
outsideViewers.remove(player);
if (player != null) MessagesUtil.sendMessage(player, "closed-wardrobe");
if (player == null) return;
if (!Bukkit.getServer().getAllowFlight()) player.setAllowFlight(false);
MessagesUtil.sendMessage(player, "closed-wardrobe");
Runnable run = () -> {
this.active = false;
@@ -206,25 +232,26 @@ public class UserWardrobeManager {
}
// NPC
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) user.getBalloonManager().sendRemoveLeashPacket();
PacketManager.sendEntityDestroyPacket(NPC_ID, viewer); // Success
PacketManager.sendRemovePlayerPacket(player, WARDROBE_UUID, viewer); // Success
if (user.isBalloonSpawned()) user.getBalloonManager().sendRemoveLeashPacket();
HMCCPacketManager.sendEntityDestroyPacket(NPC_ID, viewer); // Success
HMCCPacketManager.sendRemovePlayerPacket(player, WARDROBE_UUID, viewer); // Success
// Player
PacketManager.sendCameraPacket(player.getEntityId(), viewer);
HMCCPacketManager.sendCameraPacket(player.getEntityId(), viewer);
user.getPlayer().setInvisible(false);
// Armorstand
PacketManager.sendEntityDestroyPacket(ARMORSTAND_ID, viewer); // Sucess
HMCCPacketManager.sendEntityDestroyPacket(ARMORSTAND_ID, viewer); // Sucess
//PacketManager.sendEntityDestroyPacket(player.getEntityId(), viewer); // Success
if (WardrobeSettings.isForceExitGamemode()) {
MessagesUtil.sendDebugMessages("Force Exit Gamemode " + WardrobeSettings.getExitGamemode());
player.setGameMode(WardrobeSettings.getExitGamemode());
PacketManager.gamemodeChangePacket(player, ServerUtils.convertGamemode(WardrobeSettings.getExitGamemode())); // Success
HMCCPacketManager.gamemodeChangePacket(player, HMCCServerUtils.convertGamemode(WardrobeSettings.getExitGamemode())); // Success
} else {
MessagesUtil.sendDebugMessages("Original Gamemode " + this.originalGamemode);
player.setGameMode(this.originalGamemode);
PacketManager.gamemodeChangePacket(player, ServerUtils.convertGamemode(this.originalGamemode)); // Success
HMCCPacketManager.gamemodeChangePacket(player, HMCCServerUtils.convertGamemode(this.originalGamemode)); // Success
}
user.showPlayer();
@@ -234,15 +261,23 @@ public class UserWardrobeManager {
}
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
user.respawnBalloon();
//user.respawnBalloon();
//PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), player.getEntityId(), viewer);
}
player.teleport(Objects.requireNonNullElseGet(exitLocation, () -> player.getWorld().getSpawnLocation()));
player.teleport(Objects.requireNonNullElseGet(exitLocation, () -> player.getWorld().getSpawnLocation()), PlayerTeleportEvent.TeleportCause.PLUGIN);
if (WardrobeSettings.isEquipPumpkin()) {
NMSHandlers.getHandler().equipmentSlotUpdate(user.getPlayer().getEntityId(), EquipmentSlot.HEAD, player.getInventory().getHelmet(), viewer);
HashMap<EquipmentSlot, ItemStack> items = new HashMap<>();
for (EquipmentSlot slot : HMCCInventoryUtils.getPlayerArmorSlots()) {
ItemStack item = player.getInventory().getItem(slot);
items.put(slot, item);
}
/*
if (WardrobeSettings.isEquipPumpkin()) {
items.put(EquipmentSlot.HEAD, player.getInventory().getHelmet());
}
*/
HMCCPacketManager.equipmentSlotUpdate(player.getEntityId(), items, viewer);
if (WardrobeSettings.isEnabledBossbar()) {
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
@@ -255,7 +290,7 @@ public class UserWardrobeManager {
run.run();
}
public void update() {
private void update() {
final AtomicInteger data = new AtomicInteger();
BukkitRunnable runnable = new BukkitRunnable() {
@@ -269,43 +304,47 @@ public class UserWardrobeManager {
}
MessagesUtil.sendDebugMessages("WardrobeUpdate[user=" + user.getUniqueId() + ",status=" + getWardrobeStatus() + "]");
List<Player> viewer = Collections.singletonList(player);
List<Player> outsideViewers = PacketManager.getViewers(viewingLocation);
List<Player> outsideViewers = HMCCPacketManager.getViewers(viewingLocation);
outsideViewers.remove(player);
Location location = npcLocation;
int yaw = data.get();
location.setYaw(yaw);
PacketManager.sendLookPacket(NPC_ID, location, viewer);
HMCCPacketManager.sendLookPacket(NPC_ID, location, viewer);
user.hidePlayer();
int rotationSpeed = WardrobeSettings.getRotationSpeed();
location.setYaw(ServerUtils.getNextYaw(yaw - 30, rotationSpeed));
PacketManager.sendRotationPacket(NPC_ID, location, true, viewer);
int nextyaw = ServerUtils.getNextYaw(yaw, rotationSpeed);
location.setYaw(HMCCServerUtils.getNextYaw(yaw - 30, rotationSpeed));
HMCCPacketManager.sendRotationPacket(NPC_ID, location, true, viewer);
int nextyaw = HMCCServerUtils.getNextYaw(yaw, rotationSpeed);
data.set(nextyaw);
for (CosmeticSlot slot : CosmeticSlot.values()) {
PacketManager.equipmentSlotUpdate(NPC_ID, user, slot, viewer);
for (CosmeticSlot slot : CosmeticSlot.values().values()) {
HMCCPacketManager.equipmentSlotUpdate(NPC_ID, user, slot, viewer);
}
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
PacketManager.sendTeleportPacket(user.getUserBackpackManager().getFirstArmorStandId(), location, false, viewer);
PacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstArmorStandId(), viewer);
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK) && user.getUserBackpackManager() != null) {
HMCCPacketManager.sendTeleportPacket(user.getUserBackpackManager().getFirstArmorStandId(), location, false, viewer);
HMCCPacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstArmorStandId(), viewer);
user.getUserBackpackManager().getEntityManager().setRotation(nextyaw);
PacketManager.sendEntityDestroyPacket(user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
HMCCPacketManager.sendEntityDestroyPacket(user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
}
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON) && user.isBalloonSpawned()) {
// The two lines below broke, solved by listening to PlayerCosmeticPostEquipEvent
//PacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), npcLocation.add(Settings.getBalloonOffset()), false, viewer);
//user.getBalloonManager().getModelEntity().teleport(npcLocation.add(Settings.getBalloonOffset()));
user.getBalloonManager().sendRemoveLeashPacket(outsideViewers);
PacketManager.sendEntityDestroyPacket(user.getBalloonManager().getModelId(), outsideViewers);
if (user.getBalloonManager().getBalloonType() != UserBalloonManager.BalloonType.MODELENGINE) {
HMCCPacketManager.sendEntityDestroyPacket(user.getBalloonManager().getModelId(), outsideViewers);
}
user.getBalloonManager().sendLeashPacket(NPC_ID);
}
if (WardrobeSettings.isEquipPumpkin()) {
NMSHandlers.getHandler().equipmentSlotUpdate(user.getPlayer().getEntityId(), EquipmentSlot.HEAD, new ItemStack(Material.CARVED_PUMPKIN), viewer);
PacketManager.equipmentSlotUpdate(user.getPlayer().getEntityId(), EquipmentSlot.HEAD, new ItemStack(Material.CARVED_PUMPKIN), viewer);
} else {
HMCCPacketManager.equipmentSlotUpdate(user.getPlayer(), true, viewer); // Optifine dumbassery
}
}
};
@@ -313,10 +352,6 @@ public class UserWardrobeManager {
runnable.runTaskTimer(HMCCosmeticsPlugin.getInstance(), 0, 2);
}
public void setWardrobeStatus(WardrobeStatus status) {
this.wardrobeStatus = status;
}
public enum WardrobeStatus {
SETUP,
STARTING,

Some files were not shown because too many files have changed in this diff Show More