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

Compare commits

...

334 Commits

Author SHA1 Message Date
Boy
74fce41db0 refactor: remove unwanted meta properties 2024-08-01 16:13:42 +02:00
Boy
fb6f402c69 fix: separate metadata to firstPersonMetadata & thirdperson metadata 2024-08-01 15:06:56 +02:00
Boy
ed4803f36b refactor: make itemdisplay metadata configurable 2024-08-01 14:00:05 +02:00
Boy
0041f29ed7 fix: backpacks not showing up for other players 2024-08-01 03:56:33 +02:00
Boy
967668321c feat: disable backpack teleport/rotation and use billboard instead 2024-08-01 03:36:33 +02:00
Boy
1b897c390f feat: basic itemdisplay cosmetic backpack impl 2024-08-01 02:06:09 +02: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
c051b267cf version bump (2.6.1) 2023-08-25 21:51:48 -05:00
LoJoSho
d1fc84b5bc fix: non-thirdperson backpacks interactable 2023-08-25 15:27:42 -05:00
LoJoSho
b47b9d8235 clean: remove deprecated methods relating to static radius distance 2023-08-24 18:48:31 -05:00
LoJoSho
edccc844c9 fix: remove static radius from default config, it's deprecated 2023-08-24 18:42:21 -05:00
LoJoSho
5788b2cce0 version bump (2.6.1-DEV) 2023-08-24 18:39:39 -05:00
LoJoSho
627ebafb79 chore: remove description saying it supports Vanilla and ItemsAdder 2023-08-24 12:16:47 -05:00
lucian929
ef3bf3fc19 remove itemsadder info for menu shading till it works 2023-08-24 13:07:59 -04:00
LoJoSho
97c02883b8 fix: check for empty hand for offhand listener 2023-08-23 12:42:36 -05:00
LoJoSho
ad516e80d1 feat: improve handling of removing armor cosmetic 2023-08-23 11:15:01 -05:00
LoJoSho
317ee261db feat: force backpack riding packets 2023-08-23 11:04:07 -05:00
LoJoSho
5f8fb642a4 fix: deprecated and removal of usage of equipmentSlotUpdate in NMSHandler 2023-08-22 23:29:12 -05:00
LoJoSho
7f4a1bc3f2 clean: supress deprecated in getUserCosmeticItem 2023-08-22 23:28:21 -05:00
LoJoSho
e2a727864e fix: unchecked cosmetics in wardrobe showing unlocked in PAPI, resolves #123 2023-08-22 09:50:23 -05:00
LoJoSho
c0014476fd fix: wardrobe not properly spawning in backpacks 2023-08-22 09:49:19 -05:00
LoJoSho
8ec6a87b94 version bump (2.6.0) 2023-08-21 18:59:34 -05:00
LoJoSho
97cf079b63 fix: invisibility wearing off while swimming with backpack equipped causing NPE 2023-08-21 18:59:21 -05:00
LoJoSho
82f13c349f feat: packet backpacks 2023-08-19 14:30:29 -05:00
LoJoSho
f91c174b20 fix: console command not sending from console 2023-08-19 12:27:20 -05:00
LoJoSho
3ae6a11626 feat: console command now processes placeholders 2023-08-19 12:25:58 -05:00
LoJoSho
f2fab91916 feat: add option to move in emote when out of camera mode 2023-08-18 10:01:19 -05:00
LoJoSho
55890fa4ac feat: add getNMSVersion and getHMCCVersion to the API 2023-08-17 12:38:23 -05:00
LoJoSho
fa2aa2c6dc fix: spawned invalid entity trying to respawn itself after spawning itself 2023-08-17 12:28:33 -05:00
LoJoSho
0b5f986cfc fix: offhand cosmetics flickering 2023-08-17 12:27:59 -05:00
LoJoSho
26361b833f fix: shades not working between empty columns 2023-08-16 13:39:03 -05:00
LoJoSho
28a37848c8 feat: added option to disable emoting third person camera 2023-08-16 12:22:41 -05:00
LoJoSho
7131a45d9c feat: per-balloon cosmetic offsets 2023-08-16 10:30:46 -05:00
LoJoSho
6d9325ed18 feat: add ability to define height of first person backpacks 2023-08-14 12:03:31 -05:00
LoJoSho
0640b33d50 fix: update HMCColor to .8 2023-08-14 11:46:08 -05:00
Boy
8b944b8e29 fix geary 2023-08-14 15:26:03 +02:00
LoJoSho
4481fa1c12 fix: not returning causing NPE in equipped cosmetic placeholder 2023-08-11 09:36:55 -05:00
LoJoSho
de133fa288 clean: bump oraxen to 1.160.0 2023-08-11 09:15:31 -05:00
LoJoSho
20da7797c9 fix: equipped cosmetic placeholder returning untranslated string when no cosmetics is in slot 2023-08-08 20:31:33 -05:00
LoJoSho
2aed727832 fix: first person backpacks not passing color 2023-08-07 10:40:03 -05:00
LoJoSho
b6731ba21a clean: minor stuff in data 2023-08-06 10:49:14 -05:00
LoJoSho
d333527664 clean: move data strings to StringBuilder 2023-08-06 10:41:05 -05:00
LoJoSho
a82bb8183b clean: data to lombok in Database 2023-08-06 10:32:55 -05:00
LoJoSho
1eaeb8ecea clean: renames, missing priority, and ignoredCancelled in PlayerGameListener 2023-08-06 10:31:46 -05:00
LoJoSho
7a9d2f0041 clean spelled onPlayerCosmeticEquip correctly 2023-08-06 10:25:31 -05:00
LoJoSho
6d11deb9aa clean PlayerGameListener moved respawnBackpack method to lamdas 2023-08-06 10:24:53 -05:00
LoJoSho
f5f33f5fe7 clean: item null not showing the location where it occured 2023-08-06 10:21:12 -05:00
LoJoSho
62a1d04040 clean: prevent accidentally passing a null to a notnull method in menu types 2023-08-06 10:10:47 -05:00
LoJoSho
17db498e18 clean: lamdas <3 2023-08-06 10:09:26 -05:00
LoJoSho
0c11e1b1e5 clean: move title updater to StringBuilder 2023-08-06 10:08:54 -05:00
LoJoSho
d20eb11f45 clean: parameter was missing in contract getMenuItem 2023-08-06 10:06:18 -05:00
LoJoSho
51e19d3c36 clean: menu slots are never null, check if empty instead 2023-08-06 10:05:05 -05:00
LoJoSho
8e8d86b94c clean: worldguard listener moved to isEmpty from == 0 2023-08-06 10:01:36 -05:00
LoJoSho
c0caea2447 clean: make hooks final 2023-08-06 09:58:55 -05:00
LoJoSho
33356ea81d clean: move to Lombok for getters (wip) 2023-08-05 22:01:11 -05:00
LoJoSho
a486b13e7e clean: convert MenuItem to record 2023-08-05 21:57:31 -05:00
LoJoSho
938a561d25 feat: add shift left and right click events to action system, resolves #122 2023-08-05 20:04:42 -05:00
LoJoSho
1c61b72624 feat: Lombok + background item cosmetic shading 2023-08-05 19:06:33 -05:00
LoJoSho
46d82b01f0 version bump (2.5.3-DEV) 2023-08-05 10:10:59 -05:00
LoJoSho
c98f132871 version bump (2.5.2) 2023-08-03 11:01:25 -05:00
LoJoSho
554bdf91bd fix: ModelEngine not accepting uppercase 2023-08-02 16:06:03 -05:00
LoJoSho
fced771953 Merge pull request #121 from MomoPewpew/DvZ
Fixed interaction between backpack cosmetics and other passengers
2023-08-02 15:58:53 -05:00
MomoPewpew
6ec47c3f08 Fixed documentation typo 2023-08-02 22:06:45 +02:00
MomoPewpew
2df2646622 Backpack bug fixes
Putting on a backpack will no longer throw off all current riders
Acquiring a new rider will now reattach your backpack
2023-08-02 21:49:19 +02:00
MomoPewpew
e8d1dd1798 Revert "Reattach backpacks after a player is mounted or dismounted"
This reverts commit 2ab59dd2b2.
2023-08-01 20:36:57 +02:00
LoJoSho
59479fc474 clean: translation class more clear 2023-08-01 13:10:25 -05:00
LoJoSho
14b27abe92 clean: change TranslationPair to a record 2023-08-01 13:06:27 -05:00
LoJoSho
8c2c6db81b clean: better for loop 2023-08-01 13:03:14 -05:00
LoJoSho
5696039799 fix: entering wardrobe with riptide on a trident breaking wardrobe 2023-08-01 12:59:15 -05:00
LoJoSho
3068ce5a03 clean: IntelliJ complaining about missing <> 2023-08-01 12:51:28 -05:00
LoJoSho
548d0c3e9a clean: suppress deprecated warning 2023-08-01 12:47:31 -05:00
LoJoSho
a37d6d984b clean: latest version is never null 2023-08-01 12:44:51 -05:00
LoJoSho
d41b385b2a clean: handle IntelliJ warnings in PlayerGameListener 2023-08-01 12:42:58 -05:00
MomoPewpew
2ab59dd2b2 Reattach backpacks after a player is mounted or dismounted 2023-08-01 19:35:09 +02:00
LoJoSho
450083baf0 clean: replace instance check with null check 2023-08-01 12:29:14 -05:00
LoJoSho
0d3129bc3f clean: add proper event priorities 2023-08-01 12:26:08 -05:00
LoJoSho
fe68c43c1f clean: move invalid backpack message to normal debug from warning 2023-08-01 12:12:04 -05:00
LoJoSho
4aa1f412fe feat: add getAllCosmetics and getAllCosmeticUsers as API methods 2023-07-31 15:36:13 -05:00
LoJoSho
e53e0110f9 feat: require specific click type for cosmetic interactions 2023-07-31 15:29:24 -05:00
LoJoSho
f645907ed5 clean: remove unused settings 2023-07-31 15:04:41 -05:00
LoJoSho
af465180c0 version bump (2.5.2-DEV) 2023-07-31 15:04:19 -05:00
LoJoSho
210e6f61d6 version bump (2.5.1) 2023-07-30 22:06:39 -05:00
LoJoSho
14288479f4 fix: looping logic if entity is invalid 2023-07-30 22:05:51 -05:00
LoJoSho
8453a8b20d version bump (2.5.0) 2023-07-30 10:55:25 -05:00
lucian929
e59ee03ac7 feat: add hibiscus flower cosmetic 2023-07-29 19:04:41 -04:00
lucian929
01155f40dd fix: i forgot jetpack 2023-07-29 18:48:39 -04:00
lucian929
fa9f81e5e2 feat: add firstperson-items for cosmetics 2023-07-29 18:34:47 -04:00
LoJoSho
54bcef1a45 Merge pull request #120 from AverageGithub/fixes
Fixes
2023-07-28 10:55:04 -05:00
AverageGithub
8e14899397 Fix to 1.18 & 1.19.1/2 2023-07-28 14:21:30 +02:00
AverageGithub
061718a3b6 Fix title times not being used correctly 2023-07-28 13:05:24 +02:00
AverageGithub
2eea426460 Fix skin layers 2023-07-28 13:00:40 +02:00
LoJoSho
b0136d6076 Merge pull request #119 from AverageGithub/exploit-fix
fix players in wardrobe after teleporting
2023-07-27 09:01:35 -05:00
AverageGithub
d0b45b951c Fix import messup 2023-07-27 10:53:15 +02:00
AverageGithub
e42f5c8c7d Fix exploit 2023-07-27 10:48:08 +02:00
LoJoSho
5d4fb85fec fix: first-person backpack not in correct position in first seconds on join 2023-07-26 15:23:24 -05:00
LoJoSho
04b11a0830 feat: backend recode of the menu system, add refresh rate to auto-update gui 2023-07-26 15:09:25 -05:00
LoJoSho
353086b9c1 fix: not formatting minimessage in translations 2023-07-26 12:46:50 -05:00
LoJoSho
4e40a7cc96 clean: remove unused backpack type 2023-07-25 19:21:25 -05:00
LoJoSho
e2715fe631 fix: remove entities from players 2023-07-25 19:20:41 -05:00
LoJoSho
c7deb756db fix: first-person backpacks in hidden areas 2023-07-25 19:20:20 -05:00
LoJoSho
11f26f8f0a fix: first-person backpacks not showing properly in wardrobes 2023-07-25 19:12:46 -05:00
LoJoSho
6d814d86b3 feat: second iteration of first-person backpacks (focused on other player viewing the backpack) 2023-07-25 15:06:57 -05:00
LoJoSho
12f8b05469 feat: first iteration of first-person backpacks 2023-07-25 14:09:09 -05:00
LoJoSho
b5322bc10b clean: push runserver to 1.20.1 2023-07-25 10:21:37 -05:00
LoJoSho
7a4fd9a98b clean: remove unused utils 2023-07-19 13:39:27 -05:00
LoJoSho
239e13fab2 clean: annotations turned bad 2023-07-19 13:37:58 -05:00
LoJoSho
94b5a1bb3b Merge remote-tracking branch 'origin/remapped' into remapped
# Conflicts:
#	common/src/main/java/com/hibiscusmc/hmccosmetics/api/HMCCosmeticsAPI.java
2023-07-19 13:19:21 -05:00
LoJoSho
71ed820917 feat: slightly expanded api to equip and uneqip cosmetics in main API class 2023-07-19 13:19:04 -05:00
LoJoSho
20532fbaf2 feat: slightly expanded api to equip and remove cosmetics in main API class 2023-07-19 13:18:06 -05:00
LoJoSho
4068af98d2 fix: supervanish dependency 2023-07-19 12:26:50 -05:00
LoJoSho
95e83992de feat: update to gradle 8 2023-07-19 12:25:07 -05:00
LoJoSho
96817d7279 clean: update plugin-yml gradle plugin 2023-07-19 11:09:25 -05:00
LoJoSho
ba7a99247a fix: showing hidden cosmetics actionbar while playing emotes 2023-07-19 10:08:43 -05:00
LoJoSho
f1da6105c0 feat: disable playing emotes in WG region 2023-07-19 10:07:08 -05:00
LoJoSho
c06a4fcede feat: move ModelEngine integration to hook system 2023-07-19 09:54:10 -05:00
LoJoSho
afb20ea0bb clean: update PAPI dependency 2023-07-09 21:44:15 -05:00
LoJoSho
774caf8d91 version bump (2.4.11-DEV) 2023-07-09 21:25:41 -05:00
LoJoSho
a0c2c8a9aa clean: removed unused packet 2023-07-09 21:05:04 -05:00
LoJoSho
5b7f75f7a0 version bump (2.4.10) 2023-07-09 17:53:13 -05:00
LoJoSho
3f7d010dfa clean: optimize imports 2023-07-08 22:48:28 -05:00
LoJoSho
4d84bd681d clean: optimize imports 2023-07-08 22:48:17 -05:00
LoJoSho
0daff3044d feat: move placeholder processing to one method 2023-07-08 22:47:42 -05:00
LoJoSho
ee87338cd4 fix: Cosmin taking up our command >:( 2023-07-08 22:27:06 -05:00
LoJoSho
2b467e63ce feat: remove internal data (deprecated) 2023-07-08 22:11:37 -05:00
LoJoSho
6000cf9c1b clean: clean 2 am coding 2023-07-08 12:04:42 -05:00
LoJoSho
f2b0fb29d3 fix: Leads not properly disappearing teleporting into WG region with hidden cosmetics 2023-07-08 11:40:08 -05:00
LoJoSho
d2962ba5ed version bump (2.4.10-DEV) 2023-07-08 11:39:41 -05:00
LoJoSho
b37083a298 version bump (2.4.9) 2023-06-29 10:00:24 -05:00
LoJoSho
e35a29a13b feat: empty cosmetic type item name go through PAPI 2023-06-29 09:57:08 -05:00
LoJoSho
344aaf32e0 fix: PAPI placeholders not being applied in displaynames in guis 2023-06-28 18:06:58 -05:00
LoJoSho
6498cb43ea version bump (2.4.9-DEV) 2023-06-28 18:06: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
130 changed files with 2873 additions and 4927 deletions

View File

@@ -2,13 +2,13 @@ import net.minecrell.pluginyml.bukkit.BukkitPluginDescription
plugins {
id("java")
id("com.github.johnrengelman.shadow") version "7.1.2"
id("com.github.johnrengelman.shadow") version "8.1.1"
id("xyz.jpenilla.run-paper") version "2.0.0"
id("net.minecrell.plugin-yml.bukkit") version "0.5.2"
id("net.minecrell.plugin-yml.bukkit") version "0.6.0"
}
group = "com.hibiscusmc"
version = "2.4.8"
version = "2.7.3-DEV"
allprojects {
apply(plugin = "java")
@@ -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")
@@ -63,52 +60,58 @@ 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/")
// Hibiscus Commons
maven("https://repo.hibiscusmc.com/releases")
mavenLocal()
}
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.1")
compileOnly("com.ticxo:modelengine:R3.0.1")
compileOnly("com.github.oraxen:oraxen:-SNAPSHOT")
compileOnly("com.github.LoneDev6:API-ItemsAdder:3.2.5")
compileOnly("com.mineinabyss:geary-papermc:0.24-SNAPSHOT")
//compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT")
compileOnly("org.jetbrains:annotations:24.1.0")
compileOnly("com.comphenix.protocol:ProtocolLib:5.1.0")
compileOnly("me.clip:placeholderapi:2.11.6")
compileOnly("com.ticxo.modelengine:ModelEngine:R4.0.2")
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.1.0-SNAPSHOT")
compileOnly("it.unimi.dsi:fastutil:8.5.11")
compileOnly("com.github.LeonMangler:SuperVanish:6.2.6-4")
compileOnly("it.unimi.dsi:fastutil:8.5.13")
compileOnly("org.projectlombok:lombok:1.18.34")
compileOnly("me.lojosho:HibiscusCommons:0.4.7")
// Handled by Spigot Library Loader
compileOnly("net.kyori:adventure-api:4.17.0")
compileOnly("net.kyori:adventure-text-minimessage:4.17.0")
compileOnly("net.kyori:adventure-platform-bukkit:4.3.3")
annotationProcessor("org.projectlombok:lombok:1.18.34")
testCompileOnly("org.projectlombok:lombok:1.18.34")
testAnnotationProcessor("org.projectlombok:lombok:1.18.34")
implementation("dev.triumphteam:triumph-gui:3.1.10") {
exclude("net.kyori") // Already have adventure API
}
implementation("com.owen1212055:particlehelper:1.0.0-SNAPSHOT")
implementation("com.ticxo.playeranimator:PlayerAnimator:R1.2.7")
}
}
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 {
@@ -121,28 +124,15 @@ tasks {
}
runServer {
minecraftVersion("1.19.4")
minecraftVersion("1.20.6")
}
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")
archiveFileName.set("HMCCosmeticsRemapped-${project.version}.jar")
dependencies {
@@ -150,7 +140,7 @@ tasks {
}
doLast {
archiveFile.get().asFile.copyTo(layout.projectDirectory.file("run/plugins/HMCCosmeticsRemapped.jar").asFile, true)
archiveFile.get().asFile.copyTo(File("D:\\Server\\Paper1_21\\plugins\\${project.name}-${project.version}.jar"), true)
println("If you use the plugin, consider buying it for: ")
println("The custom resource pack, Oraxen + ItemAdder configurations, and Discord support!")
println("Polymart: https://polymart.org/resource/1879")
@@ -167,15 +157,19 @@ tasks {
bukkit {
load = BukkitPluginDescription.PluginLoadOrder.POSTWORLD
main = "com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin"
apiVersion = "1.18"
apiVersion = "1.19"
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("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.
)
commands {
register("cosmetic") {
description = "Base Cosmetic Command"
aliases = listOf("hmccosmetics", "cosmetics")
}
}
permissions {
@@ -251,10 +245,19 @@ 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
))
}

View File

@@ -3,40 +3,6 @@ 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.1")
compileOnly("com.ticxo:modelengine:R3.0.1")
compileOnly("com.github.oraxen:oraxen:-SNAPSHOT")
compileOnly("com.github.LoneDev6:API-ItemsAdder:3.2.5")
compileOnly("com.mineinabyss:geary-papermc:0.24-SNAPSHOT")
compileOnly("com.hibiscus:hmccolor:0.3-SNAPSHOT")
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.6-4")
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
))

View File

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

View File

@@ -1,92 +1,63 @@
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.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.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 hasModelEngine = false;
private static boolean onLatestVersion = true;
private static String latestVersion = "";
public HMCCosmeticsPlugin() {
super(13873, 1879);
new HookHMCCosmetics();
}
@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);
@@ -94,12 +65,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();
@@ -107,13 +74,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();
@@ -124,17 +94,15 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
// Listener
getServer().getPluginManager().registerEvents(new PlayerConnectionListener(), this);
getServer().getPluginManager().registerEvents(new PlayerGameListener(), this);
// Taken from PaperLib
if (HibiscusCommonsPlugin.isOnPaper()) {
getServer().getPluginManager().registerEvents(new PaperPlayerGameListener(), this);
}
// Database
new Database();
// ModelEngine
if (Bukkit.getPluginManager().getPlugin("ModelEngine") != null) {
hasModelEngine = true;
}
// WorldGuard
if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null && Settings.isWorldGuardMoveCheckEnabled()) {
if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null && Settings.isWorldGuardMoveCheck()) {
getServer().getPluginManager().registerEvents(new WGListener(), this);
}
}
@@ -148,15 +116,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);
}
}
@@ -220,9 +190,6 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
throw new RuntimeException(e);
}
// Misc Hooks setup (like items)
Hooks.setup();
// Cosmetics setup
Cosmetics.setup();
@@ -258,7 +225,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");
@@ -268,31 +235,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 hasModelEngine() {
return hasModelEngine;
}
public static boolean isOnLatestVersion() {
return onLatestVersion;
}
public static String getLatestVersion() {
return latestVersion;
}
}

View File

@@ -1,13 +1,19 @@
package com.hibiscusmc.hmccosmetics.api;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
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.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
import org.bukkit.Color;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.UUID;
public class HMCCosmeticsAPI {
@@ -19,7 +25,7 @@ public class HMCCosmeticsAPI {
* @return A {@link Cosmetic} if exists or null if it does not
*/
@Nullable
public static Cosmetic getCosmetic(String cosmetic) {
public static Cosmetic getCosmetic(@NotNull String cosmetic) {
return Cosmetics.getCosmetic(cosmetic);
}
@@ -32,7 +38,7 @@ public class HMCCosmeticsAPI {
* @return A {@link CosmeticUser} if exists or null if it does not
*/
@Nullable
public static CosmeticUser getUser(UUID uuid) {
public static CosmeticUser getUser(@NotNull UUID uuid) {
return CosmeticUsers.getUser(uuid);
}
@@ -43,7 +49,69 @@ public class HMCCosmeticsAPI {
* @return A {@link Menu} if exists or null if it does not
*/
@Nullable
public static Menu getMenu(String id) {
public static 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
*/
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
*/
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
*/
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
*/
public static 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
*/
public static 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
*/
@Nullable
public static String getNMSVersion() {
return NMSHandlers.getVersion();
}
/**
* This returns the HMCCosmetics version.
* @return The HMCCosmetics version in String format
*/
@NotNull
public static String getHMCCVersion() {
return HMCCosmeticsPlugin.getInstance().getDescription().getVersion();
}
}

View File

@@ -0,0 +1,47 @@
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 a cosmetic type not registered with HMCC default cosmetics is attempted to be registered. So if someone puts "test" in the config slot, and it's not a default cosmetic, this event will be called.
*/
public class CosmeticTypeRegisterEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private final String id;
private final ConfigurationNode config;
public CosmeticTypeRegisterEvent(String id, ConfigurationNode config) {
this.id = id;
this.config = config;
}
/**
* Returns the id of the cosmetic trying to be registered. For example, "beanie" or "test"
* @return The id. This is the key in the cosmetic config
*/
public String getId() {
return id;
}
/**
* This will already be in the nested node below the id in the config.
* @return The cosmetic config node in the cosmetic config that was attempted to get registered
*/
public ConfigurationNode getConfig() {
return config;
}
@Override
@NotNull
public HandlerList getHandlers() {
return handlers;
}
@NotNull
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@@ -2,6 +2,8 @@ package com.hibiscusmc.hmccosmetics.api.events;
import com.hibiscusmc.hmccosmetics.config.Wardrobe;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
@@ -12,6 +14,7 @@ import org.jetbrains.annotations.NotNull;
public class PlayerWardrobeEnterEvent extends PlayerCosmeticEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancel = false;
@Getter @Setter
private Wardrobe wardrobe;
public PlayerWardrobeEnterEvent(@NotNull CosmeticUser who, @NotNull Wardrobe wardrobe) {
@@ -48,12 +51,4 @@ public class PlayerWardrobeEnterEvent extends PlayerCosmeticEvent implements Can
public static HandlerList getHandlerList() {
return handlers;
}
public void setWardrobe(Wardrobe wardrobe) {
this.wardrobe = wardrobe;
}
public Wardrobe getWardrobe() {
return wardrobe;
}
}

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;
@@ -104,7 +107,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) {
@@ -262,7 +276,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;
@@ -297,7 +310,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;
@@ -334,7 +347,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,7 +365,7 @@ 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;
}
@@ -368,7 +381,7 @@ public class CosmeticCommand implements CommandExecutor {
}
player.sendMessage("Passengers -> " + player.getPassengers());
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
player.sendMessage("Backpack Location -> " + user.getUserBackpackManager().getArmorStand().getLocation());
player.sendMessage("Backpack Location -> " + user.getUserBackpackManager().getEntityManager().getLocation());
}
player.sendMessage("Cosmetics -> " + user.getCosmetics());
player.sendMessage("EntityId -> " + player.getEntityId());
@@ -414,7 +427,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") -> {
@@ -423,7 +436,7 @@ public class CosmeticCommand implements CommandExecutor {
return true;
}
if (Settings.getDebugMode()) {
if (Settings.isDebugMode()) {
Settings.setDebugMode(false);
if (!silent) MessagesUtil.sendMessage(sender, "debug-disabled");
} else {
@@ -483,6 +496,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()) {
@@ -122,6 +132,7 @@ 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");
}
}

View File

@@ -1,10 +1,10 @@
package com.hibiscusmc.hmccosmetics.config;
import org.spongepowered.configurate.ConfigurationNode;
import lombok.Getter;
import me.lojosho.shaded.configurate.ConfigurationNode;
public class DatabaseSettings {
//private static final String DATABASE_SETTINGS_PATH = "cosmetic-settings";
private static final String DATABASE_TYPE_PATH = "type";
private static final String MYSQL_DATABASE_SETTINGS = "mysql";
@@ -17,18 +17,24 @@ public class DatabaseSettings {
private static final String ENABLE_DELAY = "enabled";
private static final String DELAY_LENGTH = "delay";
@Getter
private static String databaseType;
@Getter
private static String database;
@Getter
private static String password;
@Getter
private static String host;
@Getter
private static String username;
@Getter
private static int port;
@Getter
private static boolean enabledDelay;
@Getter
private static int delayLength;
public static void load(ConfigurationNode source) {
//ConfigurationNode databaseSettings = source.node(DATABASE_SETTINGS_PATH);
databaseType = source.node(DATABASE_TYPE_PATH).getString();
ConfigurationNode mySql = source.node(MYSQL_DATABASE_SETTINGS);
@@ -44,36 +50,4 @@ public class DatabaseSettings {
enabledDelay = delay.node(ENABLE_DELAY).getBoolean(false);
delayLength = delay.node(DELAY_LENGTH).getInt(2);
}
public static String getDatabaseType() {
return databaseType;
}
public static String getDatabase() {
return database;
}
public static String getPassword() {
return password;
}
public static String getHost() {
return host;
}
public static String getUsername() {
return username;
}
public static int getPort() {
return port;
}
public static boolean isEnabledDelay() {
return enabledDelay;
}
public static int getDelayLength() {
return delayLength;
}
}

View File

@@ -1,12 +1,16 @@
package com.hibiscusmc.hmccosmetics.config;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
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 {
@@ -15,17 +19,8 @@ public class Settings {
private static final String DEFAULT_MENU = "default-menu";
private static final String CONFIG_VERSION = "config-version";
private static final String COSMETIC_SETTINGS_PATH = "cosmetic-settings";
private static final String REQUIRE_EMPTY_HELMET_PATH = "require-empty-helmet";
private static final String REQUIRE_EMPTY_OFF_HAND_PATH = "require-empty-off-hand";
private static final String REQUIRE_EMPTY_CHEST_PLATE_PATH = "require-empty-chest-plate";
private static final String REQUIRE_EMPTY_PANTS_PATH = "require-empty-pants";
private static final String REQUIRE_EMPTY_BOOTS_PATH = "require-empty-boots";
private static final String BALLOON_OFFSET = "balloon-offset";
private static final String FIRST_PERSON_BACKPACK_MODE = "first-person-backpack-mode";
private static final transient String LOOK_DOWN_PITCH_PATH = "look-down-backpack-remove";
private static final String VIEW_DISTANCE_PATH = "view-distance";
private static final String PARTICLE_COUNT = "particle-count";
private static final String DYE_MENU_PATH = "dye-menu";
private static final String DYE_MENU_NAME = "title";
private static final String DYE_MENU_INPUT_SLOT = "input-slot";
@@ -35,6 +30,8 @@ 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 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";
@@ -42,46 +39,130 @@ public class Settings {
private static final String HOOK_WORLDGUARD_PATH = "worldguard";
private static final String HOOK_WG_MOVE_CHECK_PATH = "player-move-check";
private static final String HOOK_WG_MOVE_CHECK_PATH_LEGACY = "player_move_check";
private static final String COSMETIC_EMOTE_ENABLE = "emote-enable";
private static final String COSMETIC_EMOTE_CHECK_PATH = "emote-block-check";
private static final String COSMETIC_EMOTE_AIR_CHECK_PATH = "emote-air-check";
private static final String COSMETIC_EMOTE_DAMAGE_PATH = "emote-damage-leave";
private static final String COSMETIC_EMOTE_INVINCIBLE_PATH = "emote-invincible";
private static final String COSMETIC_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_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_BACKPACK_LIGHT_EMINATION_PATH = "backpack-light-emination";
private static final String COSMETIC_BACKPACK_LIGHT_BLOCK_DETECTION = "backpack-block-detection";
private static final String COSMETIC_DESTROY_LOOSE_COSMETIC_PATH = "destroy-loose-cosmetics";
private static final String COSMETIC_BALLOON_HEAD_FORWARD_PATH = "balloon-head-forward";
private static final String MENU_SETTINGS_PATH = "menu-settings";
private static final String MENU_CLICK_COOLDOWN_PATH = "click-cooldown";
private static final String MENU_CLICK_COOLDOWN_TIME_PATH = "time";
private static final String COSMETIC_TYPE_SETTINGS_PATH = "cosmetic-type";
private static final String EQUIP_CLICK_TYPE = "equip-click";
private static final String UNEQUIP_CLICK_TYPE = "unequip-click";
private static final String SHADING_PATH = "shading";
private static final String FIRST_ROW_SHIFT_PATH = "first-row-shift";
private static final String SEQUENT_ROW_SHIFT_PATH = "sequent-row-shift";
private static final String INDIVIDUAL_COLUMN_SHIFT_PATH = "individual-column-shift";
private static final String BACKGROUND_PATH = "background";
private static final String CLEAR_BACKGROUND_PATH = "clear-background";
private static final String EQUIPPED_COSMETIC_COLOR_PATH = "equipped-cosmetic-color";
private static final String EQUIPABLE_COSMETIC_COLOR_PATH = "equipable-cosmetic-color";
private static final String LOCKED_COSMETIC_COLOR_PATH = "locked-cosmetic-color";
private static final String ENABLED_PATH = "enabled";
private static final String SLOT_OPTIONS_PATH = "slot-options";
@Getter
private static String defaultMenu;
@Getter
private static String dyeMenuName;
@Getter
private static int dyeMenuInputSlot;
@Getter
private static int dyeMenuOutputSlot;
@Getter
private static int configVersion;
private static boolean requireEmptyHelmet;
private static boolean requireEmptyOffHand;
private static boolean requireEmptyChestPlate;
private static boolean requireEmptyPants;
private static boolean requireEmptyBoots;
@Getter
private static boolean debugMode;
@Getter
private static boolean unapplyOnDeath;
@Getter
private static boolean forcePermissionJoin;
@Getter
private static boolean forceShowOnJoin;
@Getter
private static boolean itemsAdderChangeReload;
@Getter
private static boolean worldGuardMoveCheck;
@Getter
private static boolean cosmeticEmoteBlockCheck;
private static boolean addHelmetEnchants;
private static boolean addChestplateEnchants;
private static boolean addLeggingEnchants;
private static boolean addBootsEnchants;
private static final HashMap<EquipmentSlot, SlotOptionConfig> slotOptions = new HashMap<>();
@Getter
private static boolean emoteAirCheck;
@Getter
private static boolean emoteDamageLeave;
@Getter
private static boolean emoteInvincible;
@Getter
private static boolean destroyLooseCosmetics;
private static int lookDownPitch;
@Getter
private static boolean backpackForceRidingEnabled;
@Getter
private static boolean backpackLightEmination;
@Getter
private static boolean backpackBlockDetection;
@Getter
private static boolean emotesEnabled;
@Getter
private static boolean disabledGamemodesEnabled;
@Getter
private static boolean balloonHeadForward;
@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;
@Getter
private static String cosmeticEquipClickType;
@Getter
private static String cosmeticUnEquipClickType;
@Getter
private static boolean defaultShading;
@Getter
private static String firstRowShift;
@Getter
private static String sequentRowShift;
@Getter
private static String individualColumnShift;
@Getter
private static String background;
@Getter
private static String clearBackground;
@Getter
private static String equippedCosmeticColor;
@Getter
private static String equipableCosmeticColor;
@Getter
private static String lockedCosmeticColor;
@Getter
private static boolean emoteCameraEnabled;
@Getter
private static boolean emoteMoveCheck;
@Getter @Setter
private static boolean allPlayersHidden;
public static void load(ConfigurationNode source) {
@@ -100,31 +181,70 @@ public class Settings {
ConfigurationNode cosmeticSettings = source.node(COSMETIC_SETTINGS_PATH);
requireEmptyHelmet = cosmeticSettings.node(REQUIRE_EMPTY_HELMET_PATH).getBoolean();
requireEmptyOffHand = cosmeticSettings.node(REQUIRE_EMPTY_OFF_HAND_PATH).getBoolean();
requireEmptyChestPlate = cosmeticSettings.node(REQUIRE_EMPTY_CHEST_PLATE_PATH).getBoolean();
requireEmptyPants = cosmeticSettings.node(REQUIRE_EMPTY_PANTS_PATH).getBoolean();
requireEmptyBoots = cosmeticSettings.node(REQUIRE_EMPTY_BOOTS_PATH).getBoolean();
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<>();
}
unapplyOnDeath = cosmeticSettings.node(UNAPPLY_DEATH_PATH).getBoolean(false);
forcePermissionJoin = cosmeticSettings.node(FORCE_PERMISSION_JOIN_PATH).getBoolean(false);
forceShowOnJoin = cosmeticSettings.node(FORCE_SHOW_COSMETICS_PATH).getBoolean(false);
emotesEnabled = cosmeticSettings.node(COSMETIC_EMOTE_ENABLE).getBoolean(true);
emoteDistance = cosmeticSettings.node(EMOTE_DISTANCE_PATH).getDouble(-3);
cosmeticEmoteBlockCheck = cosmeticSettings.node(COSMETIC_EMOTE_CHECK_PATH).getBoolean(true);
emoteAirCheck = cosmeticSettings.node(COSMETIC_EMOTE_AIR_CHECK_PATH).getBoolean(true);
emoteDamageLeave = cosmeticSettings.node(COSMETIC_EMOTE_DAMAGE_PATH).getBoolean(false);
emoteInvincible = cosmeticSettings.node(COSMETIC_EMOTE_INVINCIBLE_PATH).getBoolean(false);
destroyLooseCosmetics = cosmeticSettings.node(COSMETIC_DESTROY_LOOSE_COSMETIC_PATH).getBoolean(false);
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);
backpackForceRidingEnabled = cosmeticSettings.node(COSMETIC_BACKPACK_FORCE_RIDING_PACKET_PATH).getBoolean(false);
backpackLightEmination = cosmeticSettings.node(COSMETIC_BACKPACK_LIGHT_EMINATION_PATH).getBoolean(true);
backpackBlockDetection = cosmeticSettings.node(COSMETIC_BACKPACK_LIGHT_BLOCK_DETECTION).getBoolean(true);
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);
lookDownPitch = cosmeticSettings.node(LOOK_DOWN_PITCH_PATH).getInt();
viewDistance = cosmeticSettings.node(VIEW_DISTANCE_PATH).getInt();
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);
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();
sequentRowShift = shadingSettings.node(SEQUENT_ROW_SHIFT_PATH).getString();
individualColumnShift = shadingSettings.node(INDIVIDUAL_COLUMN_SHIFT_PATH).getString();
background = shadingSettings.node(BACKGROUND_PATH).getString();
clearBackground = shadingSettings.node(CLEAR_BACKGROUND_PATH).getString();
equippedCosmeticColor = shadingSettings.node(EQUIPPED_COSMETIC_COLOR_PATH).getString();
equipableCosmeticColor = shadingSettings.node(EQUIPABLE_COSMETIC_COLOR_PATH).getString();
lockedCosmeticColor = shadingSettings.node(LOCKED_COSMETIC_COLOR_PATH).getString();
ConfigurationNode cosmeticTypeSettings = menuSettings.node(COSMETIC_TYPE_SETTINGS_PATH);
cosmeticEquipClickType = cosmeticTypeSettings.node(EQUIP_CLICK_TYPE).getString("ALL");
cosmeticUnEquipClickType = cosmeticTypeSettings.node(UNEQUIP_CLICK_TYPE).getString("ALL");
final var balloonSection = cosmeticSettings.node(BALLOON_OFFSET);
balloonOffset = loadVector(balloonSection);
ConfigurationNode dyeMenuSettings = source.node(DYE_MENU_PATH);
@@ -146,171 +266,13 @@ public class Settings {
}
}
private static Vector loadVector(final ConfigurationNode config) {
public static Vector loadVector(final ConfigurationNode config) {
return new Vector(config.node("x").getDouble(), config.node("y").getDouble(), config.node("z").getDouble());
}
public static boolean isRequireEmptyHelmet() {
return requireEmptyHelmet;
}
public static boolean isRequireEmptyOffHand() {
return requireEmptyOffHand;
}
public static boolean isRequireEmptyChestPlate() {
return requireEmptyChestPlate;
}
public static boolean isRequireEmptyPants() {
return requireEmptyPants;
}
public static boolean isRequireEmptyBoots() {
return requireEmptyBoots;
}
public static boolean getRequireEmpty(CosmeticSlot slot) {
switch (slot) {
case HELMET -> {
return requireEmptyHelmet;
}
case CHESTPLATE -> {
return requireEmptyChestPlate;
}
case LEGGINGS -> {
return requireEmptyPants;
}
case BOOTS -> {
return requireEmptyBoots;
}
case OFFHAND -> {
return requireEmptyOffHand;
}
}
return false;
}
public static boolean getRequireEmpty(EquipmentSlot slot) {
switch (slot) {
case HEAD -> {
return requireEmptyHelmet;
}
case CHEST -> {
return requireEmptyChestPlate;
}
case LEGS -> {
return requireEmptyPants;
}
case FEET -> {
return requireEmptyBoots;
}
case OFF_HAND -> {
return requireEmptyOffHand;
}
}
return false;
}
public static Vector getBalloonOffset() {
if (balloonOffset == null) HMCCosmeticsPlugin.getInstance().getLogger().info("Shits null");
return balloonOffset;
}
public static int getLookDownPitch() {
return lookDownPitch;
}
public static int getViewDistance() {
return viewDistance;
}
public static String getDefaultMenu() {
return defaultMenu;
}
public static int getConfigVersion() {
return configVersion;
}
public static String getDyeMenuName() {
return dyeMenuName;
}
public static int getDyeMenuInputSlot() { return dyeMenuInputSlot; }
public static int getDyeMenuOutputSlot() { return dyeMenuOutputSlot; }
public static boolean isDebugEnabled() {
return debugMode;
}
public static boolean getItemsAdderReloadChange() {
return itemsAdderChangeReload;
}
public static int getTickPeriod() {
return tickPeriod;
}
public static boolean getUnapplyOnDeath() {
return unapplyOnDeath;
}
public static boolean getForcePermissionJoin() {
return forcePermissionJoin;
}
public static boolean isForceShowOnJoin() {
return forceShowOnJoin;
}
public static boolean getDebugMode() {
return debugMode;
}
public static double getEmoteDistance() {
return emoteDistance;
}
public static boolean getCosmeticEmoteBlockCheck() {
return cosmeticEmoteBlockCheck;
}
public static boolean getEmoteAirCheck() {
return emoteAirCheck;
}
public static boolean isEmoteDamageLeave() {
return emoteDamageLeave;
}
public static boolean isEmoteInvincible() {
return emoteInvincible;
}
public static boolean isWorldGuardMoveCheckEnabled() {
return worldGuardMoveCheck;
}
public static boolean isDestroyLooseCosmetics() {
return destroyLooseCosmetics;
}
public static boolean getShouldAddEnchants(EquipmentSlot slot) {
switch (slot) {
case HEAD -> {
return addHelmetEnchants;
}
case CHEST -> {
return addChestplateEnchants;
}
case LEGS -> {
return addLeggingEnchants;
}
case FEET -> {
return addBootsEnchants;
}
default -> {
return false;
}
}
public static 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) {
@@ -322,4 +284,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,56 +1,52 @@
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.getDefaultDistance();
@Getter
private final String id;
@Getter @Setter
private int distance;
@Getter @Setter
private String permission;
@Getter @Setter
private WardrobeLocation location;
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
*/
public Wardrobe(@NotNull String id, @NotNull WardrobeLocation location, @Nullable String permission, int distance) {
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;
}
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;

View File

@@ -1,45 +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 {
@Getter @Setter
private Location npcLocation;
@Getter @Setter
private Location viewerLocation;
@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;
}
public void setNPCLocation(Location wardrobeLocation) {
this.npcLocation = wardrobeLocation;
}
public void setViewerLocation(Location viewerLocation) {
this.viewerLocation = viewerLocation;
}
public void setLeaveLocation(Location leaveLocation) {
this.leaveLocation = leaveLocation;
return npcLocation != null && viewerLocation != null && leaveLocation != null;
}
}

View File

@@ -1,26 +1,26 @@
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.*;
import java.util.Collection;
import java.util.HashMap;
import java.util.Set;
import java.util.logging.Level;
public class WardrobeSettings {
private static final String WARDROBE_PATH = "wardrobe";
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 STATIC_RADIUS_PATH = "static-radius";
private static final String ROTATION_SPEED_PATH = "rotation-speed";
private static final String SPAWN_DELAY_PATH = "spawn-delay";
private static final String DESPAWN_DELAY_PATH = "despawn-delay";
@@ -33,6 +33,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";
@@ -58,41 +60,65 @@ public class WardrobeSettings {
private static final String TRANSITION_FADE_OUT_PATH = "title-fade-out";
private static ConfigurationNode configRoot;
@Getter
private static boolean disableOnDamage;
private static int displayRadius;
@Getter
private static boolean portable;
@Getter
private static boolean alwaysDisplay;
private static int staticRadius;
@Getter
private static int rotationSpeed;
@Getter
private static int spawnDelay;
@Getter
private static int despawnDelay;
@Getter
private static float bossbarProgress;
@Getter
private static boolean applyCosmeticsOnClose;
@Getter
private static boolean tryCosmeticsInWardrobe;
@Getter
private static boolean equipPumpkin;
@Getter
private static boolean returnLastLocation;
@Getter
private static boolean enabledBossbar;
@Getter
private static boolean enterOpenMenu;
@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
private static String bossbarMessage;
@Getter
private static BossBar.Overlay bossbarOverlay;
@Getter
private static BossBar.Color bossbarColor;
@Getter
private static boolean enabledTransition;
@Getter
private static String transitionText;
@Getter
private static int transitionDelay;
@Getter
private static int transitionFadeIn;
@Getter
private static int transitionStay;
@Getter
private static int transitionFadeOut;
public static void load(ConfigurationNode source) {
configRoot = source;
disableOnDamage = source.node(DISABLE_ON_DAMAGE_PATH).getBoolean();
displayRadius = source.node(DISPLAY_RADIUS_PATH).getInt();
portable = source.node(PORTABLE_PATH).getBoolean();
staticRadius = source.node(STATIC_RADIUS_PATH).getInt();
alwaysDisplay = source.node(ALWAYS_DISPLAY_PATH).getBoolean();
rotationSpeed = source.node(ROTATION_SPEED_PATH).getInt();
spawnDelay = source.node(SPAWN_DELAY_PATH).getInt();
@@ -101,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);
@@ -145,10 +173,8 @@ public class WardrobeSettings {
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();
int distance = wardrobesNode.node(DISTANCE_PATH).getInt(-1);
Wardrobe wardrobe = new Wardrobe(id, wardrobeLocation, permission, distance);
addWardrobe(wardrobe);
@@ -156,54 +182,6 @@ public class WardrobeSettings {
MessagesUtil.sendDebugMessages("Unable to create wardrobe " + id, Level.SEVERE);
}
}
//throw new RuntimeException(e);
}
public static int getDefaultDistance() {
return staticRadius;
}
public static boolean getDisableOnDamage() {
return disableOnDamage;
}
public static int getDisplayRadius() {
return displayRadius;
}
public static boolean isPortable() {
return portable;
}
public static boolean isAlwaysDisplay() {
return alwaysDisplay;
}
public static int getStaticRadius() {
return staticRadius;
}
public static int getRotationSpeed() {
return rotationSpeed;
}
public static int getSpawnDelay() {
return spawnDelay;
}
public static int getDespawnDelay() {
return despawnDelay;
}
public static boolean isApplyCosmeticsOnClose() {
return applyCosmeticsOnClose;
}
public static boolean isEquipPumpkin() {
return equipPumpkin;
}
public static boolean isReturnLastLocation() {
return returnLastLocation;
}
public static Wardrobe getWardrobe(String key) {
@@ -226,84 +204,12 @@ public class WardrobeSettings {
wardrobes.remove(id);
}
@Deprecated
public static boolean inDistanceOfWardrobe(final Location wardrobeLocation, final Location playerLocation) {
if (displayRadius == -1) return true;
if (!wardrobeLocation.getWorld().equals(playerLocation.getWorld())) return false;
return playerLocation.distanceSquared(wardrobeLocation) <= displayRadius * displayRadius;
}
@Deprecated
public static boolean inDistanceOfStatic(Wardrobe wardrobe, final Location location) {
Location wardrobeLocation = wardrobe.getLocation().getNpcLocation();
if (wardrobeLocation == null) return false;
if (staticRadius == -1) return true;
if (!wardrobeLocation.getWorld().equals(location.getWorld())) return false;
return wardrobeLocation.distanceSquared(location) <= staticRadius * staticRadius;
}
public static boolean getEnabledBossbar() {
return enabledBossbar;
}
public static float getBossbarProgress() {
return bossbarProgress;
}
public static String getBossbarText() {
return bossbarMessage;
}
public static BossBar.Overlay getBossbarOverlay() {
return bossbarOverlay;
}
public static BossBar.Color getBossbarColor() {
return bossbarColor;
}
public static boolean isEnabledTransition() {
return enabledTransition;
}
public static String getTransitionText() {
return transitionText;
}
public static int getTransitionDelay() {
return transitionDelay;
}
public static int getTransitionFadeIn() {
return transitionFadeIn;
}
public static int getTransitionStay() {
return transitionStay;
}
public static int getTransitionFadeOut() {
return transitionFadeOut;
}
public static boolean isEnterOpenMenu() {
return enterOpenMenu;
}
public static boolean isForceExitGamemode() {
return forceExitGamemode;
}
public static GameMode getExitGamemode() {
return exitGamemode;
}
public static boolean isTryCosmeticsInWardrobe() {
return tryCosmeticsInWardrobe;
}
/**
* Sets where the NPC/Mannequin will spawn in the wardrobe
* @param newLocation
*/
public static void setNPCLocation(Wardrobe wardrobe, Location newLocation) {
wardrobe.getLocation().setNPCLocation(newLocation);
wardrobe.getLocation().setNpcLocation(newLocation);
HMCCosmeticsPlugin plugin = HMCCosmeticsPlugin.getInstance();

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,24 +1,38 @@
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 com.hibiscusmc.hmccosmetics.util.misc.ItemDisplayMetadata;
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.entity.Display;
import org.bukkit.entity.ItemDisplay;
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 org.joml.Quaternionf;
import org.joml.Vector3f;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
public abstract class Cosmetic {
@Getter @Setter
private String id;
@Getter @Setter
private String permission;
private ItemStack item;
@Getter @Setter
private String material;
@Getter @Setter
private CosmeticSlot slot;
@Getter @Setter
private boolean dyable;
protected Cosmetic(String id, @NotNull ConfigurationNode config) {
@@ -44,46 +58,10 @@ public abstract class Cosmetic {
Cosmetics.addCosmetic(this);
}
public String getId() {
return this.id;
}
public void setId(String id) {
this.id = id;
}
public CosmeticSlot getSlot() {
return this.slot;
}
public void setSlot(CosmeticSlot slot) {
this.slot = slot;
}
public String getPermission() {
return this.permission;
}
public void setPermission(String permission) {
this.permission = permission;
}
public boolean requiresPermission() {
return permission != null;
}
public void setDyable(boolean dyable) {
this.dyable = dyable;
}
public boolean isDyable() {
return this.dyable;
}
public String getMaterial() {
return material;
}
public abstract void update(CosmeticUser user);
@Nullable
@@ -105,4 +83,52 @@ public abstract class Cosmetic {
throw new RuntimeException(e);
}
}
protected ItemDisplayMetadata generateItemDisplayMetadata(ConfigurationNode config) {
ItemDisplayMetadata metadata = new ItemDisplayMetadata();
if (!config.virtual()) {
ConfigurationNode translationNode = config.node("translation");
ConfigurationNode scaleNode = config.node("scale");
ConfigurationNode rotationLeftNode = config.node("rotation-left");
ConfigurationNode rotationRightNode = config.node("rotation-right");
ConfigurationNode skyLightNode = config.node("sky-light");
ConfigurationNode viewRangeNode = config.node("viewrange");
ConfigurationNode widthNode = config.node("width");
ConfigurationNode heightNode = config.node("height");
ConfigurationNode displayTransformNode = config.node("display-transform");
ConfigurationNode itemstackNode = config.node("item");
if (!translationNode.virtual()) metadata.translation = stringToVector(translationNode.getString("0,0,0"));
if (!scaleNode.virtual()) metadata.scale = stringToVector(scaleNode.getString("1,1,1"));
if (!rotationLeftNode.virtual()) metadata.rotationLeft = stringToQuaternion(rotationLeftNode.getString("0,0,0,1"));
if (!rotationRightNode.virtual()) metadata.rotationRight = stringToQuaternion(rotationRightNode.getString("0,0,0,1"));
if (!skyLightNode.virtual()) metadata.skyLight = skyLightNode.getInt(15);
if (!viewRangeNode.virtual()) metadata.viewRange = viewRangeNode.getFloat(1);
if (!widthNode.virtual()) metadata.width = widthNode.getFloat(0);
if (!heightNode.virtual()) metadata.height = heightNode.getFloat(0);
if (!displayTransformNode.virtual()) try {
metadata.displayTransform = ItemDisplay.ItemDisplayTransform.valueOf(displayTransformNode.getString());
} catch (Exception ignored) {}
if (!itemstackNode.virtual()) try {
metadata.itemStack = ItemSerializer.INSTANCE.deserialize(ItemStack.class, itemstackNode);
} catch (Exception ignored) {}
}
return metadata;
}
protected Vector3f stringToVector(String string) {
List<String> vector = Arrays.stream(string.replace(" ", "").split(",", 3)).toList();
while (vector.size() < 3) vector.add("0");
float x = Float.parseFloat(vector.get(0)), y = Float.parseFloat(vector.get(1)), z = Float.parseFloat(vector.get(2));
return new Vector3f(x, y, z);
}
protected Quaternionf stringToQuaternion(String string) {
List<String> vector = Arrays.stream(string.replace(" ", "").split(",", 4)).toList();
while (vector.size() < 3) vector.add("0");
if (vector.size() < 4) vector.add("1");
float x = Float.parseFloat(vector.get(0)), y = Float.parseFloat(vector.get(1)), z = Float.parseFloat(vector.get(2)), w = Float.parseFloat(vector.get(3));
return new Quaternionf(x, y, z, w);
}
}

View File

@@ -9,5 +9,6 @@ public enum CosmeticSlot {
OFFHAND,
BACKPACK,
BALLOON,
EMOTE
EMOTE,
CUSTOM
}

View File

@@ -2,17 +2,18 @@ package com.hibiscusmc.hmccosmetics.cosmetic;
import com.google.common.collect.HashBiMap;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.api.events.CosmeticTypeRegisterEvent;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.types.*;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
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.apache.commons.lang3.EnumUtils;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.configurate.CommentedConfigurationNode;
import org.spongepowered.configurate.ConfigurateException;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
import java.io.File;
import java.nio.file.Files;
@@ -105,15 +106,16 @@ public class Cosmetics {
MessagesUtil.sendDebugMessages("Unable to create " + id + " because " + slotNode.getString() + " is not a valid slot!", Level.WARNING);
continue;
}
switch (CosmeticSlot.valueOf(cosmeticConfig.node("slot").getString())) {
switch (CosmeticSlot.valueOf(slotNode.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);
case HELMET, CHESTPLATE, LEGGINGS, BOOTS, OFFHAND -> new CosmeticArmorType(id, cosmeticConfig);
default -> new CosmeticTypeRegisterEvent(id, cosmeticConfig).callEvent();
}
} catch (Exception e) {
if (Settings.isDebugEnabled()) e.printStackTrace();
if (Settings.isDebugMode()) e.printStackTrace();
}
}
}

View File

@@ -2,11 +2,11 @@ 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.MessagesUtil;
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;
@@ -14,7 +14,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;
public class CosmeticArmorType extends Cosmetic {
@@ -23,26 +22,34 @@ public class CosmeticArmorType extends Cosmetic {
public CosmeticArmorType(String id, ConfigurationNode config) {
super(id, config);
this.equipSlot = InventoryUtils.getEquipmentSlot(getSlot());
this.equipSlot = HMCCInventoryUtils.getEquipmentSlot(getSlot());
}
@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 equippedItem = humanEntity.getInventory().getItem(equipSlot);
if (Settings.getShouldAddEnchants(equipSlot)) {
ItemStack item = getItem(user);
if (item == null) return;
PacketManager.equipmentSlotUpdate(entity.getEntityId(), equipSlot, item, HMCCPacketManager.getViewers(entity.getLocation()));
}
public ItemStack getItem(@NotNull CosmeticUser user) {
return getItem(user, user.getUserCosmeticItem(this));
}
public ItemStack getItem(@NotNull CosmeticUser user, ItemStack cosmeticItem) {
if (!(user.getEntity() instanceof HumanEntity humanEntity)) return null;
if (Settings.getSlotOption(equipSlot).isAddEnchantments()) {
ItemStack equippedItem = humanEntity.getInventory().getItem(equipSlot);
cosmeticItem.addUnsafeEnchantments(equippedItem.getEnchantments());
}
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;
}
public EquipmentSlot getEquipSlot() {

View File

@@ -1,29 +1,53 @@
package com.hibiscusmc.hmccosmetics.cosmetic.types;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.manager.UserBackpackManager;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import com.hibiscusmc.hmccosmetics.util.misc.ItemDisplayMetadata;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import lombok.Getter;
import lombok.Setter;
import me.lojosho.shaded.configurate.ConfigurationNode;
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.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.configurate.ConfigurationNode;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.logging.Level;
public class CosmeticBackpackType extends Cosmetic {
@Getter
private final String modelName;
private UserBackpackManager.BackpackType backpackType;
@Getter
private int height = -1;
private ItemStack firstPersonBackpack;
@Getter @Setter
private ItemDisplayMetadata metadata;
@Getter @Setter
private ItemDisplayMetadata firstPersonMetadata;
public CosmeticBackpackType(String id, ConfigurationNode config) {
super(id, config);
modelName = config.node("model").getString();
backpackType = UserBackpackManager.BackpackType.valueOf(config.node("type").getString("NORMAL").toUpperCase());
ConfigurationNode firstPersonNode = config.node("firstperson-item");
if (!firstPersonNode.virtual()) {
this.firstPersonBackpack = generateItemStack(firstPersonNode);
this.height = config.node("height").getInt(5);
}
this.firstPersonMetadata = generateItemDisplayMetadata(config.node("firstperson-metadata")).setVertical();
this.metadata = generateItemDisplayMetadata(config.node("metadata")).setFixed();
}
@Override
@@ -31,37 +55,53 @@ public class CosmeticBackpackType extends Cosmetic {
Entity entity = Bukkit.getEntity(user.getUniqueId());
if (entity == null) return;
Location loc = entity.getLocation().clone().add(0, 2, 0);
Location loc = entity.getLocation();
if (user.isInWardrobe() || !user.isBackpackSpawned()) return;
if (!user.getUserBackpackManager().IsValidBackpackEntity()) {
MessagesUtil.sendDebugMessages("Invalid Backpack Entity[owner=" + user.getUniqueId() + ",player_location=" + loc + "]!", Level.WARNING);
user.respawnBackpack();
if (user.isHidden()) {
// Sometimes the backpack is not despawned when the player is hidden (weird ass logic happening somewhere)
user.despawnBackpack();
return;
}
if (loc.getWorld() != user.getUserBackpackManager().getArmorStand().getWorld()) {
user.getUserBackpackManager().getArmorStand().teleport(loc);
List<Player> outsideViewers = user.getUserBackpackManager().getEntityManager().refreshViewers(loc);
UserBackpackManager backpackManager = user.getUserBackpackManager();
//backpackManager.getEntityManager().setRotation((int) loc.getYaw(), false);
HMCCPacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), backpackManager.getFirstItemDisplayId(), EntityType.ITEM_DISPLAY, UUID.randomUUID(), outsideViewers);
//metadata.rotationLeft.rotateY((float) Math.toRadians(loc.getYaw()));
HMCCPacketManager.sendItemDisplayMetadata(backpackManager.getFirstItemDisplayId(), metadata, user.getUserCosmeticItem(this, getItem()), outsideViewers);
// If true, it will send the riding packet to all players. If false, it will send the riding packet only to new players
if (Settings.isBackpackForceRidingEnabled()) HMCCPacketManager.sendRidingPacket(entity.getEntityId(), backpackManager.getFirstItemDisplayId(), backpackManager.getEntityManager().getViewers());
else HMCCPacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstItemDisplayId(), outsideViewers);
if (!user.isInWardrobe() && isFirstPersonCompatible() && user.getPlayer() != null) {
List<Player> owner = List.of(user.getPlayer());
ArrayList<Integer> particleCloud = backpackManager.getAreaEffectEntityId();
for (int i = 0; i < particleCloud.size(); i++) {
if (i == 0) {
HMCCPacketManager.sendRidingPacket(entity.getEntityId(), particleCloud.get(i), owner);
} else {
HMCCPacketManager.sendRidingPacket(particleCloud.get(i - 1), particleCloud.get(i) , owner);
}
}
HMCCPacketManager.sendRidingPacket(particleCloud.get(particleCloud.size() - 1), backpackManager.getFirstItemDisplayId(), owner);
if (!user.isHidden()) {
HMCCPacketManager.sendItemDisplayMetadata(backpackManager.getFirstItemDisplayId(), firstPersonMetadata, user.getUserCosmeticItem(this, firstPersonBackpack), owner);
}
MessagesUtil.sendDebugMessages("First Person Backpack Update[owner=" + user.getUniqueId() + ",player_location=" + loc + "]!", Level.INFO);
}
user.getUserBackpackManager().getArmorStand().teleport(loc);
if (user.getUserBackpackManager().getBackpackType().equals(UserBackpackManager.BackpackType.FIRST_PERSON)) {
user.getUserBackpackManager().teleportEffectEntity(loc);
PacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getAreaEffectEntityId(), loc);
PacketManager.sendRidingPacket(user.getUserBackpackManager().getAreaEffectEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), loc);
} else {
PacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), loc);
}
user.getUserBackpackManager().getArmorStand().setRotation(loc.getYaw(), loc.getPitch());
user.getUserBackpackManager().showBackpack();
//MessagesUtil.sendDebugMessages("TTTTTTT " + backpackManager.refreshBlock(backpackManager.getEntityManager().getViewers()));
backpackManager.showBackpack();
}
public String getModelName() {
return modelName;
public boolean isFirstPersonCompatible() {
return firstPersonBackpack != null;
}
public UserBackpackManager.BackpackType getBackpackType() {
return backpackType;
public ItemStack getFirstPersonBackpack() {
return firstPersonBackpack;
}
}

View File

@@ -2,34 +2,44 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager;
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;
public class CosmeticBalloonType extends Cosmetic {
@Getter
private final String modelName;
@Getter
private List<String> dyableParts;
private boolean showLead;
@Getter
private final boolean showLead;
@Getter
private Vector balloonOffset;
public CosmeticBalloonType(String id, ConfigurationNode config) {
super(id, config);
String modelId = config.node("model").getString();
showLead = config.node("show-lead").getBoolean(true);
ConfigurationNode balloonOffsetNode = config.node("balloon-offset");
if (balloonOffsetNode.virtual())
balloonOffset = Settings.getBalloonOffset();
else
balloonOffset = Settings.loadVector(balloonOffsetNode);
try {
if (!config.node("dyable-parts").virtual()) {
dyableParts = config.node("dyable-parts").getList(String.class);
@@ -38,7 +48,7 @@ public class CosmeticBalloonType extends Cosmetic {
// Seriously?
throw new RuntimeException(e);
}
if (modelId != null) modelId = modelId.toLowerCase(); // ME only accepts lowercase
this.modelName = modelId;
}
@@ -57,13 +67,14 @@ public class CosmeticBalloonType extends Cosmetic {
Location newLocation = entity.getLocation();
Location currentLocation = user.getBalloonManager().getLocation();
newLocation = newLocation.clone().add(Settings.getBalloonOffset());
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;
}
@@ -71,32 +82,23 @@ 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() && showLead) {
HMCCPacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer);
HMCCPacketManager.sendLeashPacket(userBalloonManager.getPufferfishBalloonId(), entity.getEntityId(), viewer);
if (user.isHidden()) {
userBalloonManager.getPufferfish().hidePufferfish();
return;
}
if (!user.isHidden() && showLead) {
List<Player> sendTo = userBalloonManager.getPufferfish().refreshViewers(newLocation);
if (sendTo.isEmpty()) return;
PacketManager.sendEntitySpawnPacket(newLocation, userBalloonManager.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager.getPufferfishBalloonUniqueId(), sendTo);
PacketManager.sendInvisibilityPacket(userBalloonManager.getPufferfishBalloonId(), sendTo);
user.getBalloonManager().getPufferfish().spawnPufferfish(newLocation, sendTo);
}
}
public String getModelName() {
return this.modelName;
}
public List<String> getDyableParts() {
return dyableParts;
}
public boolean isDyablePart(String name) {
// If player does not define parts, dye whole model
if (dyableParts == null) return true;
if (dyableParts.isEmpty()) return true;
return dyableParts.contains(name);
}
public boolean isShowLead() {
return showLead;
}
}

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(), HMCCPlayerUtils.getNearbyPlayers(player));
}
}

View File

@@ -2,37 +2,43 @@ package com.hibiscusmc.hmccosmetics.database;
import com.hibiscusmc.hmccosmetics.config.DatabaseSettings;
import com.hibiscusmc.hmccosmetics.database.types.Data;
import com.hibiscusmc.hmccosmetics.database.types.InternalData;
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;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import lombok.Getter;
import org.bukkit.entity.Player;
import java.util.UUID;
import java.util.logging.Level;
public class Database {
@Getter
private static Data data;
@Deprecated
private static InternalData INTERNAL_DATA = new InternalData();
private static final MySQLData MYSQL_DATA = new MySQLData();
private static final SQLiteData SQLITE_DATA = new SQLiteData();
private static final NoneData NONE_DATA = new NoneData();
public Database() {
String databaseType = DatabaseSettings.getDatabaseType();
data = SQLITE_DATA; // default
if (databaseType.equalsIgnoreCase("MySQL")) {
data = MYSQL_DATA;
data = SQLITE_DATA; // default to SQLite, then check if it's anything different
switch (databaseType.toLowerCase()) {
case "mysql":
data = MYSQL_DATA;
break;
case "sqlite":
// already the default
break;
case "none":
data = NONE_DATA;
MessagesUtil.sendDebugMessages("Database is set to none. Data will not be saved.", Level.WARNING);
break;
default:
MessagesUtil.sendDebugMessages("Invalid database type. Defaulting to SQLite.", Level.WARNING);
}
/* SQLite is the default database. Might change in the future, so keep code here in case.
if (databaseType.equalsIgnoreCase("sqlite")) {
data = SQLITE_DATA;
}
*/
MessagesUtil.sendDebugMessages("Database is " + data);
setup();
@@ -54,10 +60,6 @@ public class Database {
return data.get(uniqueId);
}
public static Data getData() {
return data;
}
public static void clearData(UUID uniqueId) {
data.clear(uniqueId);
}

View File

@@ -13,9 +13,7 @@ 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.*;
public abstract class Data {
@@ -31,27 +29,27 @@ public abstract class Data {
// BACKPACK=colorfulbackpack&RRGGBB,HELMET=niftyhat,BALLOON=colorfulballoon,CHESTPLATE=niftychestplate
@NotNull
public final String serializeData(@NotNull CosmeticUser user) {
String data = "";
if (user.getHidden()) {
if (shouldHiddenSave(user.getHiddenReason())) {
data = "HIDDEN=" + user.getHiddenReason();
StringBuilder data = new StringBuilder();
if (user.isHidden()) {
for (CosmeticUser.HiddenReason reason : user.getHiddenReasons()) {
if (shouldHiddenSave(reason)) data.append("HIDDEN=").append(reason);
}
}
for (Cosmetic cosmetic : user.getCosmetics()) {
Color color = user.getCosmeticColor(cosmetic.getSlot());
String input = cosmetic.getSlot() + "=" + cosmetic.getId();
if (color != null) input = input + "&" + color.asRGB();
if (data.length() == 0) {
data = input;
if (data.isEmpty()) {
data.append(input);
continue;
}
data = data + "," + input;
data.append(",").append(input);
}
return data;
return data.toString();
}
public final Map<CosmeticSlot, Map<Cosmetic, Color>> deserializeData(CosmeticUser user, @NotNull String raw) {
return deserializeData(user, raw, Settings.getForcePermissionJoin());
return deserializeData(user, raw, Settings.isForcePermissionJoin());
}
@NotNull
@@ -59,6 +57,7 @@ public abstract class Data {
Map<CosmeticSlot, Map<Cosmetic, Color>> 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 +67,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;
}
@@ -98,12 +95,46 @@ public abstract class Data {
cosmetics.put(slot, cosmeticColorHashMap);
}
}
MessagesUtil.sendDebugMessages("Hidden Reason: " + hiddenReason);
// if else this, if else that, if else I got to deal with this anymore i'll lose my mind
if (!hiddenReason.isEmpty()) {
for (CosmeticUser.HiddenReason reason : hiddenReason) user.silentlyAddHideFlag(reason);
} else {
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
// Handle gamemode check
if (user.getPlayer() != null && Settings.isDisabledGamemodesEnabled() && Settings.getDisabledGamemodes().contains(user.getPlayer().getGameMode().toString())) {
MessagesUtil.sendDebugMessages("Hiding Cosmetics due to gamemode");
user.hideCosmetics(CosmeticUser.HiddenReason.GAMEMODE);
return;
} else {
if (user.isHidden(CosmeticUser.HiddenReason.GAMEMODE)) {
MessagesUtil.sendDebugMessages("Join Gamemode Check: Showing Cosmetics");
user.showCosmetics(CosmeticUser.HiddenReason.GAMEMODE);
return;
}
}
// Handle world check
if (user.getPlayer() != null && Settings.getDisabledWorlds().contains(user.getPlayer().getWorld().getName())) {
MessagesUtil.sendDebugMessages("Hiding Cosmetics due to world");
user.hideCosmetics(CosmeticUser.HiddenReason.WORLD);
} else {
if (user.isHidden(CosmeticUser.HiddenReason.WORLD)) {
MessagesUtil.sendDebugMessages("Join World Check: Showing Cosmetics");
user.showCosmetics(CosmeticUser.HiddenReason.WORLD);
}
}
if (Settings.isAllPlayersHidden()) {
user.hideCosmetics(CosmeticUser.HiddenReason.DISABLED);
}
});
}
return cosmetics;
}
private boolean shouldHiddenSave(CosmeticUser.@NotNull HiddenReason reason) {
private boolean shouldHiddenSave(CosmeticUser.HiddenReason reason) {
switch (reason) {
case EMOTE, NONE -> {
case EMOTE, NONE, GAMEMODE, WORLD, DISABLED -> {
return false;
}
default -> {

View File

@@ -1,66 +0,0 @@
package com.hibiscusmc.hmccosmetics.database.types;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.NamespacedKey;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.persistence.PersistentDataType;
import java.util.Map;
import java.util.UUID;
@Deprecated
public class InternalData extends Data {
NamespacedKey key = new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "cosmetics");
@Override
public void setup() {
// Nothing
}
@Override
public void save(CosmeticUser user) {
Player player = Bukkit.getPlayer(user.getUniqueId());
player.getPersistentDataContainer().set(key, PersistentDataType.STRING, serializeData(user));
}
@Override
public CosmeticUser get(UUID uniqueId) {
Player player = Bukkit.getPlayer(uniqueId);
CosmeticUser user = new CosmeticUser(uniqueId);
if (!player.getPersistentDataContainer().has(key, PersistentDataType.STRING)) return user;
String rawData = player.getPersistentDataContainer().get(key, PersistentDataType.STRING);
Map<CosmeticSlot, Map<Cosmetic, Color>> a = deserializeData(user, rawData);
for (Map<Cosmetic, Color> cosmeticColors : a.values()) {
for (Cosmetic cosmetic : cosmeticColors.keySet()) {
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
// This can not be async.
user.addPlayerCosmetic(cosmetic, cosmeticColors.get(cosmetic));
});
}
}
return user;
}
@Override
public void clear(UUID uniqueId) {
OfflinePlayer player = Bukkit.getOfflinePlayer(uniqueId);
if (player.isOnline()) {
Player onlinePlayer = player.getPlayer();
if (onlinePlayer.getPersistentDataContainer().has(key, PersistentDataType.STRING)) {
onlinePlayer.getPersistentDataContainer().remove(key);
}
return;
}
}
}

View File

@@ -2,13 +2,18 @@ package com.hibiscusmc.hmccosmetics.database.types;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.DatabaseSettings;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
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 {
@@ -55,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) {}
}
});
}
@@ -124,7 +134,12 @@ public class MySQLData extends SQLData {
PreparedStatement ps = null;
if (!isConnectionOpen()) {
HMCCosmeticsPlugin.getInstance().getLogger().info("Connection is not open");
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 {

View File

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

View File

@@ -10,34 +10,46 @@ 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;
public abstract class SQLData extends Data {
@Override
@SuppressWarnings({"Duplicates", "resource"}) // Duplicate is from deprecated InternalData
@SuppressWarnings({"resource"}) // Duplicate is from deprecated InternalData
public CosmeticUser get(UUID uniqueId) {
CosmeticUser user = new CosmeticUser(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);
// Load cosmetics, put them into the addedCosmetic hashmap
HashMap<Cosmetic, Color> addedCosmetics = new HashMap<>();
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));
});
addedCosmetics.put(cosmetic, cosmeticColors.get(cosmetic));
}
}
// Run a task on the main thread, adding the cosmetics to the player
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
// This can not be async.
for (Cosmetic cosmetic : addedCosmetics.keySet()) {
user.addPlayerCosmetic(cosmetic, addedCosmetics.get(cosmetic));
}
});
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (preparedStatement != null) preparedStatement.close();
} catch (SQLException e) {}
}
});
@@ -48,16 +60,21 @@ public abstract class SQLData extends Data {
@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

@@ -6,7 +6,10 @@ import org.bukkit.Bukkit;
import java.io.File;
import java.io.IOException;
import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.UUID;
import java.util.logging.Level;
@@ -45,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) {}
}
});
}
@@ -71,7 +79,7 @@ public class SQLiteData extends SQLData {
Class.forName("org.sqlite.JDBC");
connection = DriverManager.getConnection("jdbc:sqlite:" + dataFolder);
} catch (SQLException e) {
System.out.println(e.getMessage());
e.printStackTrace();
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
@@ -80,9 +88,7 @@ public class SQLiteData extends SQLData {
@Override
public PreparedStatement preparedStatement(String query) {
PreparedStatement ps = null;
if (!isConnectionOpen()) {
HMCCosmeticsPlugin.getInstance().getLogger().info("Connection is not open");
}
if (!isConnectionOpen()) MessagesUtil.sendDebugMessages("Connection is not open");
try {
ps = connection.prepareStatement(query);

View File

@@ -18,7 +18,7 @@ import java.util.Set;
*/
@SuppressWarnings("SpellCheckingInspection")
public class EmoteManager {
private static final @NotNull Map<@NotNull String, @NotNull String> emotes = new HashMap<>();
private static final @NotNull Map<String, String> emotes = new HashMap<>();
/**
* Loads all BlockBench animations from the emotes folder and puts it into the animation manager registry and local registry

View File

@@ -2,16 +2,24 @@ package com.hibiscusmc.hmccosmetics.gui;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.api.events.PlayerMenuOpenEvent;
import com.hibiscusmc.hmccosmetics.config.serializer.ItemSerializer;
import com.hibiscusmc.hmccosmetics.config.Settings;
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.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.Placeholder;
import dev.triumphteam.gui.builder.item.ItemBuilder;
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;
@@ -19,19 +27,29 @@ import org.bukkit.event.inventory.ClickType;
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.List;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
public class Menu {
@Getter
private final String id;
@Getter
private final String title;
@Getter
private final int rows;
@Getter
private final Long cooldown;
@Getter
private final ConfigurationNode config;
@Getter
private final String permissionNode;
private final HashMap<Integer, List<MenuItem>> items;
@Getter
private final int refreshRate;
@Getter
private final boolean shading;
public Menu(String id, @NotNull ConfigurationNode config) {
this.id = id;
@@ -39,65 +57,18 @@ 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());
items = new HashMap<>();
setupItems();
Menus.addMenu(this);
}
public String getId() {
return id;
}
public String getTitle() {
return this.title;
}
public int getRows() {
return this.getRows();
}
public void openMenu(CosmeticUser user) {
openMenu(user, false);
}
public void openMenu(@NotNull CosmeticUser user, boolean ignorePermission) {
Player player = user.getPlayer();
if (player == null) return;
if (!ignorePermission && !permissionNode.isEmpty()) {
if (!player.hasPermission(permissionNode) && !player.isOp()) {
MessagesUtil.sendMessage(player, "no-permission");
return;
}
}
final Component component = Adventure.MINI_MESSAGE.deserialize(Placeholder.applyPapiPlaceholders(player, this.title));
Gui gui = Gui.gui().
title(component).
rows(this.rows).
create();
gui.setDefaultClickAction(event -> event.setCancelled(true));
// TODO: Redo this whole gui creation process to allow for all items, possibly implement caching
gui = getItems(user, gui);
final Gui finalGui = gui; // Need to make it final for the runtask
// API
PlayerMenuOpenEvent event = new PlayerMenuOpenEvent(user, this);
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
Bukkit.getPluginManager().callEvent(event);
});
if (event.isCancelled()) return;
// Internal
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
finalGui.open(player);
});
}
@Contract("_, _ -> param2")
private Gui getItems(@NotNull CosmeticUser user, Gui gui) {
Player player = user.getPlayer();
private void setupItems() {
for (ConfigurationNode config : config.node("items").childrenMap().values()) {
List<String> slotString;
@@ -113,8 +84,8 @@ public class Menu {
List<Integer> slots = getSlots(slotString);
if (slots == null) {
MessagesUtil.sendDebugMessages("Slot is null for " + config.key().toString());
if (slots.isEmpty()) {
MessagesUtil.sendDebugMessages("Slot is empty for " + config.key().toString());
continue;
}
@@ -122,42 +93,182 @@ 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) {
MessagesUtil.sendDebugMessages("something went wrong! " + item);
MessagesUtil.sendDebugMessages("Something went wrong with the item creation for " + config.key().toString());
continue;
}
int priority = config.node("priority").getInt(1);
Type type = null;
if (!config.node("type").virtual()) {
String typeId = config.node("type").getString();
String typeId = config.node("type").getString("");
if (Types.isType(typeId)) type = Types.getType(typeId);
}
for (int slot : slots) {
ItemStack modifiedItem = getMenuItem(user, type, config, item.clone(), slot).clone();
GuiItem guiItem = ItemBuilder.from(modifiedItem).asGuiItem();
Type finalType = type;
guiItem.setAction(event -> {
MessagesUtil.sendDebugMessages("Selected slot " + slot);
final ClickType clickType = event.getClick();
if (finalType != null) finalType.run(user, config, clickType);
// Need to delay the update by a tick so it will actually update with new values
for (int guiSlot : slots) {
gui.updateItem(guiSlot, getMenuItem(user, finalType, config, item.clone(), guiSlot));
}
MessagesUtil.sendDebugMessages("Updated slot " + slot);
});
MessagesUtil.sendDebugMessages("Added " + slots + " as " + guiItem + " in the menu");
gui.setItem(slot, guiItem);
for (Integer slot : slots) {
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)));
}
}
}
return gui;
}
public void openMenu(CosmeticUser user) {
openMenu(user, false);
}
public void openMenu(@NotNull CosmeticUser user, boolean ignorePermission) {
Player player = user.getPlayer();
if (player == null) return;
if (!ignorePermission && !permissionNode.isEmpty()) {
if (!player.hasPermission(permissionNode) && !player.isOp()) {
MessagesUtil.sendMessage(player, "no-permission");
return;
}
}
final Component component = AdventureUtils.MINI_MESSAGE.deserialize(Hooks.processPlaceholders(player, this.title));
Gui gui = Gui.gui()
.title(component)
.rows(this.rows)
.create();
gui.setDefaultClickAction(event -> event.setCancelled(true));
AtomicInteger taskid = new AtomicInteger(-1);
gui.setOpenGuiAction(event -> {
Runnable run = () -> {
if (gui.getInventory().getViewers().isEmpty() && taskid.get() != -1) {
Bukkit.getScheduler().cancelTask(taskid.get());
}
updateMenu(user, gui);
};
if (refreshRate != -1) {
taskid.set(Bukkit.getScheduler().scheduleSyncRepeatingTask(HMCCosmeticsPlugin.getInstance(), run, 0, refreshRate));
} else {
run.run();
}
});
gui.setCloseGuiAction(event -> {
if (taskid.get() != -1) Bukkit.getScheduler().cancelTask(taskid.get());
});
// API
PlayerMenuOpenEvent event = new PlayerMenuOpenEvent(user, this);
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> Bukkit.getPluginManager().callEvent(event));
if (event.isCancelled()) return;
// Internal
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
gui.open(player);
updateMenu(user, gui); // fixes shading? I know I do this twice but it's easier than writing a whole new class to deal with this shit
});
}
private void updateMenu(CosmeticUser user, Gui gui) {
StringBuilder title = new StringBuilder(this.title);
int row = 0;
if (shading) {
for (int i = 0; i < gui.getInventory().getSize(); i++) {
// Handles the title
if (i % 9 == 0) {
if (row == 0) {
title.append(Settings.getFirstRowShift()); // Goes back to the start of the gui
} else {
title.append(Settings.getSequentRowShift());
}
row += 1;
} else {
title.append(Settings.getIndividualColumnShift()); // Goes to the next slot
}
boolean occupied = false;
if (items.containsKey(i)) {
// Handles the items
List<MenuItem> menuItems = items.get(i);
MenuItem item = menuItems.get(0);
updateItem(user, gui, i);
if (item.type() instanceof TypeCosmetic) {
Cosmetic cosmetic = Cosmetics.getCosmetic(item.itemConfig().node("cosmetic").getString(""));
if (cosmetic == null) continue;
if (user.hasCosmeticInSlot(cosmetic)) {
title.append(Settings.getEquippedCosmeticColor());
} else {
if (user.canEquipCosmetic(cosmetic, true)) {
title.append(Settings.getEquipableCosmeticColor());
} else {
title.append(Settings.getLockedCosmeticColor());
}
}
occupied = true;
}
}
if (occupied) {
title.append(Settings.getBackground().replaceAll("<row>", String.valueOf(row)));
} else {
title.append(Settings.getClearBackground().replaceAll("<row>", String.valueOf(row)));
}
}
MessagesUtil.sendDebugMessages("Updated menu with title " + title);
gui.updateTitle(StringUtils.parseStringToString(Hooks.processPlaceholders(user.getPlayer(), title.toString())));
} else {
for (int i = 0; i < gui.getInventory().getSize(); i++) {
if (items.containsKey(i)) {
updateItem(user, gui, i);
}
}
}
}
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();
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 -> {
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("Set an item in slot " + slot + " in the menu of " + getId());
gui.updateItem(slot, guiItem);
break;
}
}
@NotNull
@@ -167,8 +278,8 @@ public class Menu {
for (String a : slotString) {
if (a.contains("-")) {
String[] split = a.split("-");
int min = Integer.valueOf(split[0]);
int max = Integer.valueOf(split[1]);
int min = Integer.parseInt(split[0]);
int max = Integer.parseInt(split[1]);
slots.addAll(getSlots(min, max));
} else {
slots.add(Integer.valueOf(a));
@@ -186,19 +297,17 @@ public class Menu {
return slots;
}
@Contract("_, _, _, _ -> param2")
@Contract("_, _, _, _, _ -> param2")
@NotNull
private ItemStack getMenuItem(CosmeticUser user, Type type, ConfigurationNode config, ItemStack itemStack, int slot) {
if (!itemStack.hasItemMeta()) return itemStack;
return type.setItem(user, config, itemStack, slot);
}
public String getPermissionNode() {
return permissionNode;
}
public boolean canOpen(Player player) {
if (permissionNode.isEmpty()) return true;
return player.isOp() || player.hasPermission(permissionNode);
}
public static Comparator<MenuItem> priorityCompare = Comparator.comparing(MenuItem::priority).reversed();
}

View File

@@ -0,0 +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 java.util.List;
public record MenuItem(List<Integer> slots, ItemStack item, Type type, int priority, ConfigurationNode itemConfig) {
}

View File

@@ -3,27 +3,24 @@ package com.hibiscusmc.hmccosmetics.gui;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import me.lojosho.shaded.configurate.CommentedConfigurationNode;
import me.lojosho.shaded.configurate.ConfigurateException;
import me.lojosho.shaded.configurate.yaml.YamlConfigurationLoader;
import org.apache.commons.io.FilenameUtils;
import org.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 java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
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) {
MENUS.put(menu.getId().toUpperCase(), menu);
@@ -64,8 +61,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();
@@ -87,7 +97,7 @@ public class Menus {
new Menu(FilenameUtils.removeExtension(child.getFileName().toString()), root);
} catch (Exception e) {
MessagesUtil.sendDebugMessages("Unable to create menu in " + child.getFileName().toString(), Level.WARNING);
if (Settings.isDebugEnabled()) e.printStackTrace();
if (Settings.isDebugMode()) e.printStackTrace();
}
}
});

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

@@ -3,6 +3,8 @@ package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;
public class ActionConsoleCommand extends Action {
@@ -13,6 +15,6 @@ public class ActionConsoleCommand extends Action {
@Override
public void run(@NotNull CosmeticUser user, String raw) {
HMCCosmeticsPlugin.getInstance().getServer().dispatchCommand(user.getPlayer(), raw);
HMCCosmeticsPlugin.getInstance().getServer().dispatchCommand(Bukkit.getConsoleSender(), Hooks.processPlaceholders(user.getPlayer(), raw));
}
}

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

@@ -1,6 +1,5 @@
package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.gui.Menu;
import com.hibiscusmc.hmccosmetics.gui.Menus;
import com.hibiscusmc.hmccosmetics.gui.action.Action;

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

@@ -1,25 +1,23 @@
package com.hibiscusmc.hmccosmetics.gui.special;
import com.hibiscusmc.hmccolor.HMCColorApi;
import com.hibiscusmc.hmccolor.gui.guis.Gui;
import com.hibiscusmc.hmccolor.gui.guis.GuiItem;
import com.hibiscusmc.hmccolor.shaded.gui.guis.Gui;
import com.hibiscusmc.hmccolor.shaded.gui.guis.GuiItem;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.misc.Placeholder;
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 java.util.Objects;
public class DyeMenu {
public static void openMenu(@NotNull CosmeticUser user, Cosmetic cosmetic) {
@@ -32,8 +30,8 @@ public class DyeMenu {
ItemStack originalItem = user.getUserCosmeticItem(cosmetic);
if (originalItem == null || !cosmetic.isDyable()) return;
Gui gui = HMCColorApi.INSTANCE.colorMenu();
gui.updateTitle(Placeholder.applyPapiPlaceholders(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()) {
@@ -42,9 +40,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);

View File

@@ -1,10 +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.bukkit.inventory.meta.ItemMeta;
import org.spongepowered.configurate.ConfigurationNode;
public abstract class Type {

View File

@@ -1,60 +1,83 @@
package com.hibiscusmc.hmccosmetics.gui.type.types;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.serializer.ItemSerializer;
import com.hibiscusmc.hmccosmetics.config.Settings;
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 com.hibiscusmc.hmccosmetics.util.misc.StringUtils;
import com.hibiscusmc.hmccosmetics.util.misc.Utils;
import me.clip.placeholderapi.PlaceholderAPI;
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.lang.invoke.TypeDescriptor;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class TypeCosmetic extends Type {
public TypeCosmetic(String id) {
super(id);
}
public TypeCosmetic() {
super("cosmetic");
}
@Override
public void run(CosmeticUser user, @NotNull ConfigurationNode config, ClickType clickType) {
if (config.node("cosmetic").virtual()) return;
MessagesUtil.sendDebugMessages("Running Cosmetic Click Type");
if (config.node("cosmetic").virtual()) {
MessagesUtil.sendDebugMessages("Cosmetic Config Field Virtual");
return;
}
String cosmeticName = config.node("cosmetic").getString();
Cosmetic cosmetic = Cosmetics.getCosmetic(cosmeticName);
Player player = user.getPlayer();
if (cosmetic == null) {
MessagesUtil.sendDebugMessages("No Cosmetic Found");
MessagesUtil.sendMessage(player, "invalid-cosmetic");
return;
}
if (!user.canEquipCosmetic(cosmetic)) {
MessagesUtil.sendDebugMessages("No Cosmetic Permission");
MessagesUtil.sendMessage(player, "no-cosmetic-permission");
return;
}
boolean isUnEquippingCosmetic = false;
if (user.getCosmetic(cosmetic.getSlot()) == cosmetic) isUnEquippingCosmetic = true;
String requiredClick;
if (isUnEquippingCosmetic) requiredClick = Settings.getCosmeticUnEquipClickType();
else requiredClick = Settings.getCosmeticEquipClickType();
MessagesUtil.sendDebugMessages("Required click type: " + requiredClick);
MessagesUtil.sendDebugMessages("Click type: " + clickType.name());
if (!requiredClick.equalsIgnoreCase("ANY") && !requiredClick.equalsIgnoreCase(clickType.name())) {
MessagesUtil.sendMessage(user.getPlayer(), "invalid-click-type");
return;
}
List<String> actionStrings = new ArrayList<>();
ConfigurationNode actionConfig = config.node("actions");
MessagesUtil.sendDebugMessages("Running Actions");
try {
if (!actionConfig.node("any").virtual()) actionStrings.addAll(actionConfig.node("any").getList(String.class));
@@ -65,9 +88,15 @@ public class TypeCosmetic extends Type {
if (clickType.isRightClick()) {
if (!actionConfig.node("right-click").virtual()) actionStrings.addAll(actionConfig.node("right-click").getList(String.class));
}
if (clickType.equals(ClickType.SHIFT_LEFT)) {
if (!actionConfig.node("shift-left-click").virtual()) actionStrings.addAll(actionConfig.node("shift-left-click").getList(String.class));
}
if (clickType.equals(ClickType.SHIFT_RIGHT)) {
if (!actionConfig.node("shift-right-click").virtual()) actionStrings.addAll(actionConfig.node("shift-right-click").getList(String.class));
}
}
if (user.getCosmetic(cosmetic.getSlot()) == cosmetic) {
if (isUnEquippingCosmetic) {
if (!actionConfig.node("on-unequip").virtual()) actionStrings.addAll(actionConfig.node("on-unequip").getList(String.class));
MessagesUtil.sendDebugMessages("on-unequip");
user.removeCosmeticSlot(cosmetic);
@@ -85,7 +114,7 @@ public class TypeCosmetic extends Type {
Actions.runActions(user, actionStrings);
} catch (SerializationException e) {
throw new RuntimeException(e);
e.printStackTrace();
}
// Fixes issue with offhand cosmetics not appearing. Yes, I know this is dumb
Runnable run = () -> user.updateCosmetic(cosmetic.getSlot());
@@ -95,6 +124,7 @@ public class TypeCosmetic extends Type {
}
}
run.run();
MessagesUtil.sendDebugMessages("Finished Type Click Run");
}
@Override
@@ -110,9 +140,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) {
@@ -127,7 +157,7 @@ public class TypeCosmetic extends Type {
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 {
@@ -152,10 +182,19 @@ public class TypeCosmetic extends Type {
private ItemMeta processLoreLines(CosmeticUser user, @NotNull ItemMeta itemMeta) {
List<String> processedLore = new ArrayList<>();
if (itemMeta.hasDisplayName()) {
itemMeta.setDisplayName(Hooks.processPlaceholders(user.getPlayer(), itemMeta.getDisplayName()));
}
if (itemMeta.hasLore()) {
for (String loreLine : itemMeta.getLore()) {
if (Hooks.isActiveHook("PlaceholderAPI")) loreLine = PlaceholderAPI.setPlaceholders(user.getPlayer(), loreLine);
processedLore.add(loreLine);
processedLore.add(Hooks.processPlaceholders(user.getPlayer(), loreLine));
}
}
if (itemMeta instanceof SkullMeta skullMeta) {
if (skullMeta.hasOwner()) {
skullMeta.setOwner(Hooks.processPlaceholders(user.getPlayer(), skullMeta.getOwner()));
}
}
itemMeta.setLore(processedLore);

View File

@@ -2,15 +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.clip.placeholderapi.PlaceholderAPI;
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;
@@ -43,6 +43,12 @@ public class TypeEmpty extends Type {
if (clickType.isRightClick()) {
if (!actionConfig.node("right-click").virtual()) actionStrings.addAll(actionConfig.node("right-click").getList(String.class));
}
if (clickType.equals(ClickType.SHIFT_LEFT)) {
if (!actionConfig.node("shift-left-click").virtual()) actionStrings.addAll(actionConfig.node("shift-left-click").getList(String.class));
}
if (clickType.equals(ClickType.SHIFT_RIGHT)) {
if (!actionConfig.node("shift-right-click").virtual()) actionStrings.addAll(actionConfig.node("shift-right-click").getList(String.class));
}
}
// We run the actions once we got the raw strings from the config.
@@ -58,13 +64,23 @@ public class TypeEmpty extends Type {
List<String> processedLore = new ArrayList<>();
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta.hasDisplayName()) {
itemMeta.setDisplayName(Hooks.processPlaceholders(user.getPlayer(), itemMeta.getDisplayName()));
}
if (itemMeta.hasLore()) {
for (String loreLine : itemMeta.getLore()) {
if (Hooks.isActiveHook("PlaceholderAPI"))
loreLine = PlaceholderAPI.setPlaceholders(user.getPlayer(), loreLine);
processedLore.add(loreLine);
processedLore.add(Hooks.processPlaceholders(user.getPlayer(), loreLine));
}
}
if (itemMeta instanceof SkullMeta skullMeta) {
if (skullMeta.hasOwner()) {
skullMeta.setOwner(Hooks.processPlaceholders(user.getPlayer(), skullMeta.getOwner()));
}
}
itemMeta.setLore(processedLore);
itemStack.setItemMeta(itemMeta);
return itemStack;
}

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

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,45 +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
*/
@SuppressWarnings("SpellCheckingInspection")
public class HookGeary extends Hook {
private boolean enabled = false;
public HookGeary() {
super("geary");
setEnabledItemHook(true);
}
@Override
public void load() {
GearyModuleKt.getGeary().getPipeline().intercept(GearyPhase.ENABLE, () -> {
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,7 @@ import org.jetbrains.annotations.NotNull;
*/
public class HookHMCCosmetics extends Hook {
public HookHMCCosmetics() {
super("HMCCosmetics");
setEnabledItemHook(true);
super("HMCCosmetics", HookFlag.ITEM_SUPPORT);
}
/**

View File

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

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

@@ -1,35 +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.jetbrains.annotations.NotNull;
/**
* A hook that integrates the plugin {@link com.Zrips.CMI.CMI CMI}
*/
public class HookCMI extends Hook {
public HookCMI() {
super("CMI");
}
@EventHandler
public void onPlayerVanish(@NotNull CMIPlayerVanishEvent event) {
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
user.hideCosmetics(CosmeticUser.HiddenReason.PLUGIN);
}
@EventHandler
public void onPlayerShow(@NotNull CMIPlayerUnVanishEvent event) {
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
user.showCosmetics();
}
}

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,32 +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.jetbrains.annotations.NotNull;
public class HookLibsDisguises extends Hook {
public HookLibsDisguises() {
super("LibsDisguises");
}
@EventHandler
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
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,37 +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.jetbrains.annotations.NotNull;
/**
* A hook that integrates the plugin {@link de.myzelyam.api.vanish.VanishAPI Supervanish}
*
* @implSpec Supervanish and Premium Vanish both use the same api
*/
public class HookPremiumVanish extends Hook {
public HookPremiumVanish() {
super("PremiumVanish");
}
@EventHandler
public void onPlayerVanish(@NotNull PlayerHideEvent event) {
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
user.hideCosmetics(CosmeticUser.HiddenReason.PLUGIN);
}
@EventHandler
public void onPlayerShow(@NotNull PlayerShowEvent event) {
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
user.showCosmetics();
}
}

View File

@@ -1,37 +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.jetbrains.annotations.NotNull;
/**
* A hook that integrates the plugin {@link de.myzelyam.api.vanish.VanishAPI Supervanish}
*
* @implSpec Supervanish and Premium Vanish both use the same api
*/
public class HookSuperVanish extends Hook {
public HookSuperVanish() {
super("SuperVanish");
}
@EventHandler
public void onPlayerVanish(@NotNull PlayerHideEvent event) {
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
user.hideCosmetics(CosmeticUser.HiddenReason.PLUGIN);
}
@EventHandler
public void onPlayerShow(@NotNull PlayerShowEvent event) {
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
user.showCosmetics();
}
}

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) {
@@ -124,13 +116,10 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
return "INVALID_COSMETIC";
}
}
return TranslationUtil.getTranslation("unlocked-cosmetic", String.valueOf(user.canEquipCosmetic(cosmetic)));
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())) {
@@ -152,9 +141,34 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
return "INVALID_COSMETIC";
}
}
if (user.getCosmetic(cosmetic.getSlot()) == null) return "false";
return TranslationUtil.getTranslation("equipped-cosmetic", String.valueOf(cosmetic.getId() == user.getCosmetic(cosmetic.getSlot()).getId()));
Cosmetic equippedCosmetic = user.getCosmetic(cosmetic.getSlot());
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 (!EnumUtils.isValidEnum(CosmeticSlot.class, 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()));
}
@@ -215,6 +229,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

@@ -17,21 +17,26 @@ public class WGHook {
/**
* @implNote Please use {@link #getCosmeticEnableFlag()} instead
*/
public static StateFlag COSMETIC_ENABLE_FLAG;
private static StateFlag COSMETIC_ENABLE_FLAG;
private static StateFlag EMOTES_ENABLE_FLAG;
/**
* @implNote Please use {@link #getCosmeticWardrobeFlag()} instead
*/
public static StringFlag COSMETIC_WARDROBE_FLAG;
private static StringFlag COSMETIC_WARDROBE_FLAG;
public WGHook() {
FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry();
try {
StateFlag cosmeticFlag = new StateFlag("cosmetic-enable", false);
StateFlag emoteFlag = new StateFlag("emotes-enable", false);
StringFlag wardrobeFlag = new StringFlag("cosmetic-wardrobe");
registry.register(cosmeticFlag);
registry.register(emoteFlag);
registry.register(wardrobeFlag);
COSMETIC_ENABLE_FLAG = cosmeticFlag;
EMOTES_ENABLE_FLAG = emoteFlag;
COSMETIC_WARDROBE_FLAG = wardrobeFlag;
} catch (FlagConflictException e) {
Flag<?> existing = registry.get("cosmetic-enable");
@@ -53,6 +58,14 @@ public class WGHook {
return COSMETIC_ENABLE_FLAG;
}
/**
* Gets the emotes enable {@link StateFlag}
* @return The emotes enable {@link StateFlag}
*/
public static StateFlag getEmotesEnableFlag() {
return EMOTES_ENABLE_FLAG;
}
/**
* Gets the cosmetic wardrobe {@link StateFlag}
* @return The cosmetic wardrobe {@link StateFlag}

View File

@@ -1,10 +1,10 @@
package com.hibiscusmc.hmccosmetics.hooks.worldguard;
import com.hibiscusmc.hmccosmetics.api.events.PlayerEmoteStartEvent;
import com.hibiscusmc.hmccosmetics.config.Wardrobe;
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
@@ -12,7 +12,9 @@ import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import com.sk89q.worldguard.protection.regions.RegionQuery;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
@@ -22,24 +24,21 @@ import org.jetbrains.annotations.NotNull;
* Contains {@link com.sk89q.worldguard.WorldGuard WorldGuard} related event listeners
*/
public class WGListener implements Listener {
@EventHandler
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerMove(@NotNull PlayerMoveEvent event) {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
if (user == null) return;
Location location = event.getPlayer().getLocation();
com.sk89q.worldedit.util.Location loc = BukkitAdapter.adapt(location);
RegionContainer region = WorldGuard.getInstance().getPlatform().getRegionContainer();
RegionQuery query = region.createQuery();
ApplicableRegionSet set = query.getApplicableRegions(loc);
if (user.getHidden()) {
if (user.getHiddenReason() == CosmeticUser.HiddenReason.WORLDGUARD && set.getRegions().size() == 0) {
user.showCosmetics();
ApplicableRegionSet set = getRegions(location);
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);
@@ -53,24 +52,21 @@ public class WGListener implements Listener {
}
}
@EventHandler
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerTeleport(PlayerTeleportEvent event) {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
if (user == null) return;
Location location = event.getTo();
com.sk89q.worldedit.util.Location loc = BukkitAdapter.adapt(location);
RegionContainer region = WorldGuard.getInstance().getPlatform().getRegionContainer();
RegionQuery query = region.createQuery();
ApplicableRegionSet set = query.getApplicableRegions(loc);
if (user.getHidden()) {
if (user.getHiddenReason() == CosmeticUser.HiddenReason.WORLDGUARD && set.getRegions().size() == 0) {
user.showCosmetics();
ApplicableRegionSet set = getRegions(location);
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);
@@ -83,4 +79,28 @@ public class WGListener implements Listener {
}
}
}
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerEmote(PlayerEmoteStartEvent event) {
Player player = event.getUser().getPlayer();
if (player == null) return;
Location location = player.getLocation();
ApplicableRegionSet set = getRegions(location);
for (ProtectedRegion protectedRegion : set.getRegions()) {
if (protectedRegion.getFlags().containsKey(WGHook.getEmotesEnableFlag())) {
if (protectedRegion.getFlags().get(WGHook.getEmotesEnableFlag()).toString().equalsIgnoreCase("DENY")) {
event.setCancelled(true);
return;
}
return;
}
}
}
private ApplicableRegionSet getRegions(Location location) {
com.sk89q.worldedit.util.Location loc = BukkitAdapter.adapt(location);
RegionContainer region = WorldGuard.getInstance().getPlatform().getRegionContainer();
RegionQuery query = region.createQuery();
return query.getApplicableRegions(loc);
}
}

View File

@@ -0,0 +1,39 @@
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.Listener;
public class PaperPlayerGameListener implements Listener {
@EventHandler
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
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

@@ -2,15 +2,16 @@ package com.hibiscusmc.hmccosmetics.listener;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.DatabaseSettings;
import com.hibiscusmc.hmccosmetics.config.Settings;
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;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
@@ -18,25 +19,31 @@ import org.jetbrains.annotations.NotNull;
public class PlayerConnectionListener implements Listener {
@EventHandler
@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() != null)
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>"
);
}
Runnable run = () -> {
if (!event.getPlayer().isOnline()) return; // If a player is no longer online, don't run this.
CosmeticUser user = Database.get(event.getPlayer().getUniqueId());
CosmeticUsers.addUser(user);
MessagesUtil.sendDebugMessages("Run User Join");
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> user.updateCosmetic(), 4);
// And finally, launch an update for the cosmetics they have.
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
if (user.getPlayer() == null) return;
user.updateCosmetic();
}, 4);
};
if (DatabaseSettings.isEnabledDelay()) {
@@ -47,24 +54,19 @@ public class PlayerConnectionListener implements Listener {
}
}
@EventHandler
@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();
}
}
}
return;
if (user == null) return; // Player never initialized, don't do anything
if (user.isInWardrobe()) {
user.leaveWardrobe(true);
user.getPlayer().setInvisible(false);
}
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

@@ -11,6 +11,7 @@ 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;
@@ -22,9 +23,13 @@ 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.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.hooks.items.HookItemAdder;
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -35,6 +40,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Pose;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.*;
import org.bukkit.event.inventory.InventoryClickEvent;
@@ -45,6 +51,8 @@ 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.*;
@@ -53,16 +61,18 @@ public class PlayerGameListener implements Listener {
public PlayerGameListener() {
registerInventoryClickListener();
registerMenuChangeListener();
registerEntityStatusListener();
registerPlayerEquipmentListener();
registerPlayerArmListener();
registerEntityUseListener();
registerSlotChangeListener();
//registerLookMovement();
//registerMoveListener();
//registerTeleportMovement();
}
@EventHandler
@EventHandler(priority = EventPriority.LOW)
public void onPlayerClick(@NotNull InventoryClickEvent event) {
// || !event.getClickedInventory().getType().equals(InventoryType.PLAYER)
if (event.getClick().isShiftClick()) return;
@@ -73,14 +83,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(), () -> {
@@ -89,7 +99,7 @@ public class PlayerGameListener implements Listener {
MessagesUtil.sendDebugMessages("Event fired, updated cosmetic " + cosmeticSlot);
}
@EventHandler
@EventHandler(priority = EventPriority.LOW)
public void onPlayerShift(PlayerToggleSneakEvent event) {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
@@ -104,7 +114,7 @@ public class PlayerGameListener implements Listener {
user.leaveWardrobe();
}
@EventHandler
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerTeleport(PlayerTeleportEvent event) {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
@@ -114,29 +124,34 @@ public class PlayerGameListener implements Listener {
return;
}
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK) && user.getUserBackpackManager() != null) {
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
user.respawnBackpack();
user.updateCosmetic();
}, 1);
if (user.isInWardrobe()) {
user.leaveWardrobe();
}
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
if (user.getEntity() == null || user.isInWardrobe()) return; // fixes disconnecting when in wardrobe (the entity stuff)
if (Settings.getDisabledWorlds().contains(user.getEntity().getLocation().getWorld().getName())) {
user.hideCosmetics(CosmeticUser.HiddenReason.WORLD);
} else {
user.showCosmetics(CosmeticUser.HiddenReason.WORLD);
}
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK) && user.getUserBackpackManager() != null) {
user.respawnBackpack();
}
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
user.respawnBalloon();
}
user.updateCosmetic();
}, 2);
if (event.getCause().equals(PlayerTeleportEvent.TeleportCause.NETHER_PORTAL) || event.getCause().equals(PlayerTeleportEvent.TeleportCause.END_PORTAL)) return;
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
final CosmeticBalloonType cosmeticBalloonType = (CosmeticBalloonType) user.getCosmetic(CosmeticSlot.BALLOON);
user.despawnBalloon();
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
user.spawnBalloon(cosmeticBalloonType);
}, 2);
}
if (user.getUserEmoteManager().isPlayingEmote()) {
user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.TELEPORT);
}
}
@EventHandler
public void portalTeleport(PlayerPortalEvent event) {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPortalTeleport(PlayerPortalEvent event) {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
MessagesUtil.sendDebugMessages("Player Teleport Event");
@@ -145,6 +160,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();
@@ -155,21 +176,17 @@ public class PlayerGameListener implements Listener {
}
}
@EventHandler
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerHit(EntityDamageByEntityEvent event) {
if (event.isCancelled()) return;
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);
}
@EventHandler
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerDamaged(EntityDamageEvent event) {
if (event.isCancelled()) return;
if (!(event.getEntity() instanceof Player)) return;
Player player = ((Player) event.getEntity()).getPlayer();
if (!(event.getEntity() instanceof Player player)) return;
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
if (user.getUserEmoteManager().isPlayingEmote()) {
@@ -181,41 +198,38 @@ public class PlayerGameListener implements Listener {
}
}
if (user.isInWardrobe()) {
user.leaveWardrobe();
if (WardrobeSettings.isPreventDamage()) {
event.setCancelled(true);
return;
}
if (WardrobeSettings.isDamagedKicked()) user.leaveWardrobe();
}
}
@EventHandler
public void onPlayerLook(PlayerMoveEvent event) {
if (event.isCancelled()) return;
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
// TODO: Move to packets
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
// Really need to look into optimization of this
if (!Settings.isEmoteMoveCheck() && user.getUserEmoteManager().isPlayingEmote()) {
event.setCancelled(true);
return;
}
user.updateCosmetic(CosmeticSlot.BACKPACK);
user.updateCosmetic(CosmeticSlot.BALLOON);
}
@EventHandler
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerPoseChange(EntityPoseChangeEvent event) {
if (!(event.getEntity() instanceof Player)) return;
Player player = ((Player) event.getEntity()).getPlayer();
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)) {
// #84, Riptides mess with backpacks
ItemStack currentItem = player.getInventory().getItemInMainHand();
if (currentItem != null) {
if (currentItem.hasItemMeta()) {
if (currentItem.containsEnchantment(Enchantment.RIPTIDE)) {
return;
}
}
}
if (currentItem.containsEnchantment(Enchantment.RIPTIDE)) return;
if (!user.isBackpackSpawned()) {
user.spawnBackpack((CosmeticBackpackType) user.getCosmetic(CosmeticSlot.BACKPACK));
}
@@ -226,11 +240,9 @@ public class PlayerGameListener implements Listener {
}
}
@EventHandler
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerArmorDamage(PlayerItemDamageEvent event) {
// Possibly look into cancelling the event, then handling the damage on our own.
if (event.isCancelled()) return;
MessagesUtil.sendDebugMessages("PlayerItemDamageEvent");
int slot = -1;
@@ -247,7 +259,8 @@ public class PlayerGameListener implements Listener {
if (slot == -1) return;
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
CosmeticSlot cosmeticSlot = InventoryUtils.BukkitCosmeticSlot(slot);
if (user == null) return;
CosmeticSlot cosmeticSlot = HMCCInventoryUtils.BukkitCosmeticSlot(slot);
if (!user.hasCosmeticInSlot(cosmeticSlot)) {
MessagesUtil.sendDebugMessages("No cosmetic in " + cosmeticSlot);
@@ -260,8 +273,8 @@ public class PlayerGameListener implements Listener {
}, 2);
}
@EventHandler
public void playerOffhandSwap(PlayerSwapHandItemsEvent event) {
@EventHandler(priority = EventPriority.LOW)
public void onPlayerOffhandSwap(PlayerSwapHandItemsEvent event) {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
if (user == null) return;
// Really need to look into optimization of this
@@ -272,11 +285,16 @@ public class PlayerGameListener implements Listener {
return;
}
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
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerPickupItem(EntityPickupItemEvent event) {
if (!(event.getEntity() instanceof Player)) return;
CosmeticUser user = CosmeticUsers.getUser(event.getEntity().getUniqueId());
@@ -284,9 +302,8 @@ public class PlayerGameListener implements Listener {
if (user.isInWardrobe()) event.setCancelled(true);
}
@EventHandler
public void playerInvisibility(EntityPotionEffectEvent event) {
if (event.isCancelled()) return;
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerPotionEffect(EntityPotionEffectEvent event) {
if (!event.getModifiedType().equals(PotionEffectType.INVISIBILITY)) return;
if (!event.getEntityType().equals(EntityType.PLAYER)) return;
Player player = (Player) event.getEntity();
@@ -297,22 +314,22 @@ 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;
}
}
@EventHandler
@EventHandler(priority = EventPriority.LOW)
public void onMainHandSwitch(PlayerItemHeldEvent event) {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
if (user == null) return;
event.getPlayer().getInventory().setItem(event.getPreviousSlot(), event.getPlayer().getInventory().getItem(event.getPreviousSlot()));
//NMSHandlers.getHandler().slotUpdate(event.getPlayer(), event.getPreviousSlot());
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
user.updateCosmetic(CosmeticSlot.MAINHAND);
user.updateCosmetic(CosmeticSlot.OFFHAND);
}, 2);
if (user.hasCosmeticInSlot(CosmeticSlot.MAINHAND)) {
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
user.updateCosmetic(CosmeticSlot.MAINHAND);
}, 2);
}
// #84, Riptides mess with backpacks
ItemStack currentItem = event.getPlayer().getInventory().getItem(event.getNewSlot());
@@ -323,42 +340,121 @@ public class PlayerGameListener implements Listener {
}
}
@EventHandler
@EventHandler(priority = EventPriority.LOW)
public void onPlayerDeath(PlayerDeathEvent event) {
CosmeticUser user = CosmeticUsers.getUser(event.getEntity());
if (user == null) return;
if (user.isInWardrobe()) user.leaveWardrobe();
if (Settings.getUnapplyOnDeath() && !event.getEntity().hasPermission("hmccosmetics.unapplydeath.bypass")) {
if (Settings.isUnapplyOnDeath() && !event.getEntity().hasPermission("hmccosmetics.unapplydeath.bypass")) {
user.removeCosmetics();
}
}
@EventHandler
@EventHandler(priority = EventPriority.LOW)
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);
}
}
}
@EventHandler
public void onPlayerCosemticEquip(PlayerCosmeticPostEquipEvent event) {
@EventHandler(priority = EventPriority.LOW)
public void onPlayerCosmeticEquip(PlayerCosmeticPostEquipEvent event) {
CosmeticUser user = event.getUser();
if (user.isInWardrobe() && event.getCosmetic().getSlot().equals(CosmeticSlot.BALLOON)) {
Location NPCLocation = user.getWardrobeManager().getNpcLocation();
PacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), NPCLocation.add(Settings.getBalloonOffset()), false, List.of(event.getUser().getPlayer()));
user.getBalloonManager().getModelEntity().teleport(NPCLocation.add(Settings.getBalloonOffset()));
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
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);
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerMounted(EntityMountEvent event) {
if (event.getEntity() instanceof Player player) {
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(HMCCosmeticsPlugin.getInstance(), user::respawnBackpack, 1);
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerDismounted(EntityDismountEvent event) {
if (event.getDismounted() instanceof Player player) {
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(HMCCosmeticsPlugin.getInstance(), user::respawnBackpack, 1);
}
}
@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);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onHookReload(HibiscusHookReload event) {
if (event.getHook() instanceof HookItemAdder hook) {
switch (event.getReloadType()) {
case INITIAL -> {
HMCCosmeticsPlugin.setup();
}
case RELOAD -> {
if (!Settings.isItemsAdderChangeReload()) return;
HMCCosmeticsPlugin.setup();
}
}
}
}
// 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);
}
private void registerInventoryClickListener() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.WINDOW_CLICK) {
@Override
@@ -371,11 +467,12 @@ public class PlayerGameListener implements Listener {
if (invTypeClicked != 0) return;
// -999 is when a player clicks outside their inventory. https://wiki.vg/Inventory#Player_Inventory
if (slotClicked == -999) return;
if (!(event.getPlayer() instanceof Player)) return;
if (event.getPlayer() == null) return;
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);
@@ -391,7 +488,6 @@ public class PlayerGameListener implements Listener {
MessagesUtil.sendDebugMessages("Menu Initial ");
Player player = event.getPlayer();
if (event.getPlayer() == null) return;
if (!(event.getPlayer() instanceof Player)) return;
int windowID = event.getPacket().getIntegers().read(0);
List<ItemStack> slotData = event.getPacket().getItemListModifier().read(0);
@@ -402,9 +498,15 @@ public class PlayerGameListener implements Listener {
HashMap<Integer, ItemStack> items = new HashMap<>();
for (Cosmetic cosmetic : user.getCosmetics()) {
if ((cosmetic instanceof CosmeticArmorType cosmeticArmorType)) {
items.put(InventoryUtils.getPacketArmorSlot(cosmeticArmorType.getEquipSlot()), user.getUserCosmeticItem(cosmeticArmorType));
if (!user.isInWardrobe()) {
for (Cosmetic cosmetic : user.getCosmetics()) {
if ((cosmetic instanceof CosmeticArmorType cosmeticArmorType)) {
boolean requireEmpty = Settings.getSlotOption(cosmeticArmorType.getEquipSlot()).isRequireEmpty();
boolean isAir = user.getPlayer().getInventory().getItem(cosmeticArmorType.getEquipSlot()).getType().isAir();
MessagesUtil.sendDebugMessages("Menu Fired (Checks) - " + cosmeticArmorType.getId() + " - " + requireEmpty + " - " + isAir);
if (requireEmpty && !isAir) continue;
items.put(HMCCInventoryUtils.getPacketArmorSlot(cosmeticArmorType.getEquipSlot()), user.getUserCosmeticItem(cosmeticArmorType));
}
}
}
@@ -435,6 +537,36 @@ public class PlayerGameListener implements Listener {
});
}
private void registerSlotChangeListener() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.SET_SLOT) {
@Override
public void onPacketSending(PacketEvent event) {
MessagesUtil.sendDebugMessages("SetSlot Initial ");
Player player = event.getPlayer();
if (event.getPlayer() == null) return;
int windowID = event.getPacket().getIntegers().read(0);
if (windowID != 0) return;
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
if (user.isInWardrobe()) return;
int slot = event.getPacket().getIntegers().read(2);
MessagesUtil.sendDebugMessages("SetSlot Slot " + slot);
CosmeticSlot cosmeticSlot = HMCCInventoryUtils.NMSCosmeticSlot(slot);
EquipmentSlot equipmentSlot = HMCCInventoryUtils.getPacketArmorSlot(slot);
if (cosmeticSlot == null || equipmentSlot == null) return;
if (!user.hasCosmeticInSlot(cosmeticSlot)) return;
if (Settings.getSlotOption(equipmentSlot).isRequireEmpty()) {
if (!player.getInventory().getItem(equipmentSlot).getType().isAir()) return;
}
event.getPacket().getItemModifier().write(0, user.getUserCosmeticItem(cosmeticSlot));
}
});
}
private void registerPlayerEquipmentListener() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.ENTITY_EQUIPMENT) {
@Override
@@ -443,17 +575,32 @@ 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));
if (cosmeticArmor == null) continue;
Pair<EnumWrappers.ItemSlot, ItemStack> pair = new Pair<>(InventoryUtils.itemBukkitSlot(cosmeticArmor.getEquipSlot()), cosmeticArmor.getItem());
armor.add(pair);
for (int i = 0; i < armor.size(); i++) {
com.comphenix.protocol.wrappers.Pair<EnumWrappers.ItemSlot, ItemStack> pair = armor.get(i);
switch (pair.getFirst()) {
case MAINHAND -> {
if (user.getPlayer() == event.getPlayer()) continue; // When a player scrolls real fast, it messes up the mainhand. This fixes it
armor.set(i, new Pair<>(pair.getFirst(), user.getPlayer().getInventory().getItemInMainHand()));
}
default -> {
EquipmentSlot slot = HMCCInventoryUtils.getEquipmentSlot(pair.getFirst());
CosmeticSlot cosmeticSlot = HMCCInventoryUtils.getItemSlotToCosmeticSlot(pair.getFirst());
if (slot == null || cosmeticSlot == null) continue;
if (Settings.getSlotOption(slot).isRequireEmpty()
&& !user.getPlayer().getInventory().getItem(slot).getType().isAir()) continue;
CosmeticArmorType cosmeticArmor = (CosmeticArmorType) user.getCosmetic(cosmeticSlot);
if (cosmeticArmor == null) continue;
ItemStack item = user.getUserCosmeticItem(cosmeticArmor);
if (item == null) continue;
Pair<EnumWrappers.ItemSlot, ItemStack> armorPair = new Pair<>(HMCCInventoryUtils.itemBukkitSlot(slot), item);
armor.set(i, armorPair);
}
}
}
event.getPacket().getSlotStackPairLists().write(0, armor);
@@ -462,11 +609,32 @@ 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 registerPlayerArmListener() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.ARM_ANIMATION) {
@Override
public void onPacketReceiving(PacketEvent event) {
if (!(event.getPlayer() instanceof Player)) return;
if (event.getPlayer() == null) return;
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
@@ -475,7 +643,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);
@@ -487,9 +657,8 @@ public class PlayerGameListener implements Listener {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.USE_ENTITY) {
@Override
public void onPacketReceiving(PacketEvent event) {
if (!(event.getPlayer() instanceof Player)) return;
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (event.getPlayer() == null) return;
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
if (user == null) return;
if (user.getUserEmoteManager().isPlayingEmote() || user.isInWardrobe()) {
event.setCancelled(true);
@@ -506,7 +675,11 @@ public class PlayerGameListener implements Listener {
MessagesUtil.sendDebugMessages("Look Packet ");
Player player = event.getPlayer();
if (event.getPlayer() == null) return;
if (!(event.getPlayer() instanceof Player)) return;
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
if (user.isBackpackSpawned()) {
user.getUserBackpackManager().getEntityManager().setRotation(Math.round(event.getPacket().getFloat().read(0)));
}
}
});
}
@@ -519,20 +692,29 @@ public class PlayerGameListener implements Listener {
MessagesUtil.sendDebugMessages("Position Packet ");
Player player = event.getPlayer();
if (event.getPlayer() == null) return;
if (!(event.getPlayer() instanceof Player)) return;
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
if (user.isBackpackSpawned()) {
// The yaw follows the head, which makes it look weird and do weird things when moving around
user.getUserBackpackManager().getEntityManager().teleport(new Location(player.getWorld(), event.getPacket().getDoubles().read(0), event.getPacket().getDoubles().read(1), event.getPacket().getDoubles().read(2), event.getPacket().getFloat().read(0), event.getPacket().getFloat().read(1)));
}
}
});
}
private void registerTeleportMovement() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.TELEPORT_ACCEPT) {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.POSITION_LOOK) {
@Override
public void onPacketReceiving(PacketEvent event) {
// TODO: Finish
MessagesUtil.sendDebugMessages("Teleport Packet ");
Player player = event.getPlayer();
if (event.getPlayer() == null) return;
if (!(event.getPlayer() instanceof Player)) return;
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
if (user.isBackpackSpawned()) {
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> user.updateCosmetic(CosmeticSlot.BACKPACK));
}
}
});
}

View File

@@ -1,61 +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.manager.UserBalloonManager;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import net.kyori.adventure.text.Component;
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 spawnHMCParticleCloud(Location location);
Entity spawnDisplayEntity(Location location, String text);
UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType);
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,48 +0,0 @@
package com.hibiscusmc.hmccosmetics.nms;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
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;
private static String version;
public static NMSHandler getHandler() {
if (handler != null) {
return handler;
} else {
setup();
}
return handler;
}
public static String getVersion() {
return version;
}
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

@@ -9,21 +9,31 @@ import com.hibiscusmc.hmccosmetics.config.Wardrobe;
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.cosmetic.types.*;
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
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.gui.Menus;
import com.hibiscusmc.hmccosmetics.user.manager.UserBackpackManager;
import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager;
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
import com.hibiscusmc.hmccosmetics.user.manager.UserWardrobeManager;
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.*;
import com.hibiscusmc.hmccosmetics.util.HMCCPlayerUtils;
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;
@@ -35,18 +45,21 @@ import java.util.logging.Level;
public class CosmeticUser {
@Getter
private final UUID uniqueId;
private int taskId;
private HashMap<CosmeticSlot, Cosmetic> playerCosmetics = new HashMap<>();
private final HashMap<CosmeticSlot, Cosmetic> playerCosmetics = new HashMap<>();
private UserWardrobeManager userWardrobeManager;
private UserBalloonManager userBalloonManager;
@Getter
private UserBackpackManager userBackpackManager;
private UserEmoteManager userEmoteManager;
@Getter
private final UserEmoteManager userEmoteManager;
// Cosmetic Settings/Toggles
private boolean hideCosmetics;
private HiddenReason hiddenReason;
private HashMap<CosmeticSlot, Color> colors = new HashMap<>();
private final ArrayList<HiddenReason> hiddenReason = new ArrayList<>();
private final HashMap<CosmeticSlot, ItemStack> cachedCosmeticItems = new HashMap<>();
private final HashMap<CosmeticSlot, Color> colors = new HashMap<>();
public CosmeticUser(UUID uuid) {
this.uniqueId = uuid;
@@ -59,7 +72,7 @@ public class CosmeticUser {
Runnable run = () -> {
MessagesUtil.sendDebugMessages("Tick[uuid=" + uniqueId + "]", Level.INFO);
updateCosmetic();
if (getHidden()) MessagesUtil.sendActionBar(getPlayer(), "hidden-cosmetics");
if (isHidden() && !getUserEmoteManager().isPlayingEmote() && !getCosmetics().isEmpty()) MessagesUtil.sendActionBar(getPlayer(), "hidden-cosmetics");
};
int tickPeriod = Settings.getTickPeriod();
@@ -75,19 +88,10 @@ public class CosmeticUser {
despawnBalloon();
}
public UUID getUniqueId() {
return this.uniqueId;
}
public Cosmetic getCosmetic(CosmeticSlot slot) {
return playerCosmetics.get(slot);
}
@Deprecated
public Collection<Cosmetic> getCosmetic() {
return playerCosmetics.values();
}
public ImmutableCollection<Cosmetic> getCosmetics() {
return ImmutableList.copyOf(playerCosmetics.values());
}
@@ -112,14 +116,16 @@ public class CosmeticUser {
playerCosmetics.put(cosmetic.getSlot(), cosmetic);
if (color != null) colors.put(cosmetic.getSlot(), color);
MessagesUtil.sendDebugMessages("addPlayerCosmetic[id=" + cosmetic.getId() + "]");
if (cosmetic.getSlot() == CosmeticSlot.BACKPACK) {
CosmeticBackpackType backpackType = (CosmeticBackpackType) cosmetic;
spawnBackpack(backpackType);
MessagesUtil.sendDebugMessages("addPlayerCosmetic[spawnBackpack,id=" + cosmetic.getId() + "]");
}
if (cosmetic.getSlot() == CosmeticSlot.BALLOON) {
CosmeticBalloonType balloonType = (CosmeticBalloonType) cosmetic;
spawnBalloon(balloonType);
if (!isHidden()) {
if (cosmetic.getSlot() == CosmeticSlot.BACKPACK) {
CosmeticBackpackType backpackType = (CosmeticBackpackType) cosmetic;
spawnBackpack(backpackType);
MessagesUtil.sendDebugMessages("addPlayerCosmetic[spawnBackpack,id=" + cosmetic.getId() + "]");
}
if (cosmetic.getSlot() == CosmeticSlot.BALLOON) {
CosmeticBalloonType balloonType = (CosmeticBalloonType) cosmetic;
spawnBalloon(balloonType);
}
}
// API
PlayerCosmeticPostEquipEvent postEquipEvent = new PlayerCosmeticPostEquipEvent(this, cosmetic);
@@ -151,6 +157,7 @@ public class CosmeticUser {
if (slot == CosmeticSlot.EMOTE) {
if (getUserEmoteManager().isPlayingEmote()) getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.UNEQUIP);
}
cachedCosmeticItems.remove(slot);
colors.remove(slot);
playerCosmetics.remove(slot);
removeArmor(slot);
@@ -187,18 +194,49 @@ public class CosmeticUser {
}
public void updateCosmetic() {
MessagesUtil.sendDebugMessages("updateCosmetic (All) - start");
HashMap<EquipmentSlot, ItemStack> items = new HashMap<>();
for (Cosmetic cosmetic : getCosmetics()) {
updateCosmetic(cosmetic.getSlot());
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, HMCCPlayerUtils.getNearbyPlayers(getEntity().getLocation()));
MessagesUtil.sendDebugMessages("updateCosmetic (All) - end - " + items.size());
}
public ItemStack getUserCosmeticItem(CosmeticSlot slot) {
Cosmetic cosmetic = getCosmetic(slot);
if (cosmetic == null) return new ItemStack(Material.AIR);
return getUserCosmeticItem(cosmetic);
}
public ItemStack getUserCosmeticItem(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) {
// Check if the item is cached. This helps with performance as we don't need to keep recreating the item
if (cachedCosmeticItems.containsKey(cosmetic.getSlot())) {
return cachedCosmeticItems.get(cosmetic.getSlot());
}
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) {
@@ -208,9 +246,18 @@ public class CosmeticUser {
item = cosmetic.getItem();
}
}
return getUserCosmeticItem(cosmetic, item);
}
@SuppressWarnings("deprecation")
public ItemStack getUserCosmeticItem(Cosmetic cosmetic, ItemStack item) {
if (item == null) {
MessagesUtil.sendDebugMessages("GetUserCosemticUser Item is null");
return null;
//MessagesUtil.sendDebugMessages("GetUserCosemticUser Item is null");
return new ItemStack(Material.AIR);
}
// Check if the item is cached. This helps with performance as we don't need to keep recreating the item
if (cachedCosmeticItems.containsKey(cosmetic.getSlot())) {
return cachedCosmeticItems.get(cosmetic.getSlot());
}
if (item.hasItemMeta()) {
ItemMeta itemMeta = item.getItemMeta();
@@ -220,7 +267,7 @@ public class CosmeticUser {
if (skullMeta.getPersistentDataContainer().has(InventoryUtils.getSkullOwner(), PersistentDataType.STRING)) {
String owner = skullMeta.getPersistentDataContainer().get(InventoryUtils.getSkullOwner(), PersistentDataType.STRING);
if (Hooks.isActiveHook("PlaceholderAPI")) owner = PlaceholderAPI.setPlaceholders(getPlayer(), owner);
owner = Hooks.processPlaceholders(getPlayer(), owner);
skullMeta.setOwningPlayer(Bukkit.getOfflinePlayer(owner));
//skullMeta.getPersistentDataContainer().remove(InventoryUtils.getSkullOwner()); // Don't really need this?
@@ -228,7 +275,7 @@ public class CosmeticUser {
if (skullMeta.getPersistentDataContainer().has(InventoryUtils.getSkullTexture(), PersistentDataType.STRING)) {
String texture = skullMeta.getPersistentDataContainer().get(InventoryUtils.getSkullTexture(), PersistentDataType.STRING);
if (Hooks.isActiveHook("PlaceholderAPI")) texture = PlaceholderAPI.setPlaceholders(getPlayer(), texture);
texture = Hooks.processPlaceholders(getPlayer(), texture);
Bukkit.getUnsafe().modifyItemStack(item, "{SkullOwner:{Id:[I;0,0,0,0],Properties:{textures:[{Value:\""
+ texture + "\"}]}}}");
@@ -242,14 +289,12 @@ public class CosmeticUser {
if (itemMeta.hasLore()) {
for (String loreLine : itemMeta.getLore()) {
if (Hooks.isActiveHook("PlaceholderAPI")) loreLine = PlaceholderAPI.setPlaceholders(getPlayer(), loreLine);
processedLore.add(loreLine);
processedLore.add(Hooks.processPlaceholders(getPlayer(), loreLine));
}
}
if (itemMeta.hasDisplayName()) {
String displayName = itemMeta.getDisplayName();
if (Hooks.isActiveHook("PlaceholderAPI")) displayName = PlaceholderAPI.setPlaceholders(getPlayer(), displayName);
itemMeta.setDisplayName(displayName);
itemMeta.setDisplayName(Hooks.processPlaceholders(getPlayer(), displayName));
}
itemMeta.setLore(processedLore);
@@ -261,20 +306,26 @@ 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);
}
cachedCosmeticItems.put(cosmetic.getSlot(), item);
return item;
}
public UserBackpackManager getUserBackpackManager() {
return userBackpackManager;
}
public UserBalloonManager getBalloonManager() {
return this.userBalloonManager;
}
@@ -283,10 +334,6 @@ public class CosmeticUser {
return userWardrobeManager;
}
public UserEmoteManager getUserEmoteManager() {
return userEmoteManager;
}
public void enterWardrobe(boolean ignoreDistance, Wardrobe wardrobe) {
if (wardrobe.hasPermission() && !getPlayer().hasPermission(wardrobe.getPermission())) {
MessagesUtil.sendMessage(getPlayer(), "no-permission");
@@ -314,6 +361,10 @@ public class CosmeticUser {
}
public void leaveWardrobe() {
leaveWardrobe(false);
}
public void leaveWardrobe(boolean ejected) {
PlayerWardrobeLeaveEvent event = new PlayerWardrobeLeaveEvent(this);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
@@ -323,8 +374,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(),
@@ -348,7 +400,7 @@ public class CosmeticUser {
public void spawnBackpack(CosmeticBackpackType cosmeticBackpackType) {
if (this.userBackpackManager != null) return;
this.userBackpackManager = new UserBackpackManager(this, cosmeticBackpackType.getBackpackType());
this.userBackpackManager = new UserBackpackManager(this);
userBackpackManager.spawnBackpack(cosmeticBackpackType);
}
@@ -362,16 +414,30 @@ 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);
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());
List<Player> sentTo = HMCCPlayerUtils.getNearbyPlayers(getEntity().getLocation());
PacketManager.sendEntityDestroyPacket(userBalloonManager.getPufferfishBalloonId(), sentTo);
HMCCPacketManager.sendEntityDestroyPacket(userBalloonManager.getPufferfishBalloonId(), sentTo);
this.userBalloonManager.remove();
this.userBalloonManager = null;
@@ -381,18 +447,28 @@ 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) {
PacketManager.equipmentSlotUpdate(getEntity().getEntityId(), this, slot, PlayerUtils.getNearbyPlayers(getEntity().getLocation()));
EquipmentSlot equipmentSlot = HMCCInventoryUtils.getEquipmentSlot(slot);
if (equipmentSlot == null) return;
if (getPlayer() != null) {
PacketManager.equipmentSlotUpdate(getEntity().getEntityId(), equipmentSlot, getPlayer().getInventory().getItem(equipmentSlot), HMCCPlayerUtils.getNearbyPlayers(getEntity().getLocation()));
} else {
HMCCPacketManager.equipmentSlotUpdate(getEntity().getEntityId(), this, slot, HMCCPlayerUtils.getNearbyPlayers(getEntity().getLocation()));
}
}
/**
@@ -428,8 +504,12 @@ public class CosmeticUser {
}
public boolean canEquipCosmetic(Cosmetic cosmetic) {
return canEquipCosmetic(cosmetic, false);
}
public boolean canEquipCosmetic(Cosmetic cosmetic, boolean ignoreWardrobe) {
if (!cosmetic.requiresPermission()) return true;
if (isInWardrobe()) {
if (isInWardrobe() && !ignoreWardrobe) {
if (WardrobeSettings.isTryCosmeticsInWardrobe() && userWardrobeManager.getWardrobeStatus().equals(UserWardrobeManager.WardrobeStatus.RUNNING)) return true;
}
return getPlayer().hasPermission(cosmetic.getPermission());
@@ -454,28 +534,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 == false) 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);
@@ -483,15 +570,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(getPlayer());
PacketManager.sendLeashPacket(getBalloonManager().getPufferfishBalloonId(), getPlayer().getEntityId(), viewer);
List<Player> viewer = HMCCPlayerUtils.getNearbyPlayers(getEntity().getLocation());
HMCCPacketManager.sendLeashPacket(getBalloonManager().getPufferfishBalloonId(), getPlayer().getEntityId(), viewer);
}
if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
if (!isBackpackSpawned()) respawnBackpack();
CosmeticBackpackType cosmeticBackpackType = (CosmeticBackpackType) getCosmetic(CosmeticSlot.BACKPACK);
ItemStack item = getUserCosmeticItem(cosmeticBackpackType);
userBackpackManager.setItem(item);
@@ -500,14 +589,32 @@ 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 HiddenReason getHiddenReason() {
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,
@@ -515,6 +622,9 @@ public class CosmeticUser {
POTION,
ACTION,
COMMAND,
EMOTE
EMOTE,
GAMEMODE,
WORLD,
DISABLED
}
}

View File

@@ -1,46 +1,83 @@
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;
public class CosmeticUsers {
private static HashBiMap<UUID, CosmeticUser> COSMETIC_USERS = HashBiMap.create();
private static final HashBiMap<UUID, CosmeticUser> COSMETIC_USERS = HashBiMap.create();
public static void addUser(CosmeticUser user) {
/**
* 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 vlaid 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());
}
/**
* 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();
}
}

View File

@@ -1,157 +1,190 @@
package com.hibiscusmc.hmccosmetics.user.manager;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.misc.ItemDisplayMetadata;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import com.ticxo.modelengine.api.ModelEngineAPI;
import com.ticxo.modelengine.api.model.ActiveModel;
import com.ticxo.modelengine.api.model.ModeledEntity;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import lombok.Getter;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.hibiscuscommons.util.ServerUtils;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.logging.Level;
public class UserBackpackManager {
private boolean hideBackpack;
private ArmorStand invisibleArmorStand;
private AreaEffectCloud particleCloud;
@Getter
private boolean backpackHidden;
@Getter
private int itemDisplayId;
private ArrayList<Integer> particleCloud = new ArrayList<>();
@Getter
private final CosmeticUser user;
private BackpackType backpackType;
@Getter
private UserEntity entityManager;
//@Getter @Setter
//private boolean inBlock;
public UserBackpackManager(CosmeticUser user, BackpackType backpackType) {
public UserBackpackManager(CosmeticUser user) {
this.user = user;
hideBackpack = false;
this.backpackType = backpackType;
this.backpackHidden = false;
//this.inBlock = false;
this.itemDisplayId = ServerUtils.getNextEntityId();
this.entityManager = new UserEntity(user.getUniqueId());
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() {
return invisibleArmorStand.getEntityId();
}
public ArmorStand getArmorStand() {
return invisibleArmorStand;
}
public boolean IsValidBackpackEntity() {
if (invisibleArmorStand == null) {
MessagesUtil.sendDebugMessages("InvisibleArmorStand is Null!");
return false;
}
return getArmorStand().isValid();
public int getFirstItemDisplayId() {
return itemDisplayId;
}
public void spawnBackpack(CosmeticBackpackType cosmeticBackpackType) {
MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Start");
if (getBackpackType().equals(BackpackType.NORMAL)) {
spawnNormalBackpack(cosmeticBackpackType);
}
if (getBackpackType().equals(BackpackType.FIRST_PERSON)) {
spawnFirstPersonBackpack(cosmeticBackpackType);
}
spawn(cosmeticBackpackType);
}
private void spawnNormalBackpack(CosmeticBackpackType cosmeticBackpackType) {
private void spawn(CosmeticBackpackType cosmeticBackpackType) {
Location entityLoc = user.getEntity().getLocation();
entityLoc.setPitch(0f);
getEntityManager().setIds(List.of(itemDisplayId));
getEntityManager().teleport(entityLoc);
List<Player> outsideViewers = getEntityManager().getViewers();
HMCCPacketManager.sendEntitySpawnPacket(entityLoc, getFirstItemDisplayId(), EntityType.ITEM_DISPLAY, UUID.randomUUID(), getEntityManager().getViewers());
if (this.invisibleArmorStand != null) return;
Entity entity = user.getEntity();
this.invisibleArmorStand = (ArmorStand) NMSHandlers.getHandler().spawnBackpack(user, cosmeticBackpackType);
int[] passengerIDs = new int[entity.getPassengers().size() + 1];
if (cosmeticBackpackType.getModelName() != null && HMCCosmeticsPlugin.hasModelEngine()) {
if (ModelEngineAPI.api.getModelRegistry().getBlueprint(cosmeticBackpackType.getModelName()) == null) {
for (int i = 0; i < entity.getPassengers().size(); i++) {
passengerIDs[i] = entity.getPassengers().get(i).getEntityId();
}
passengerIDs[passengerIDs.length - 1] = this.getFirstItemDisplayId();
ArrayList<Player> owner = new ArrayList<>();
if (user.getPlayer() != null) owner.add(user.getPlayer());
if (cosmeticBackpackType.isFirstPersonCompatible()) {
for (int i = particleCloud.size(); i < cosmeticBackpackType.getHeight(); i++) {
int entityId = ServerUtils.getNextEntityId();
HMCCPacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), entityId, EntityType.AREA_EFFECT_CLOUD, UUID.randomUUID());
HMCCPacketManager.sendCloudEffect(entityId, HMCCPacketManager.getViewers(user.getEntity().getLocation()));
this.particleCloud.add(entityId);
}
// Copied code from updating the backpack
for (int i = 0; i < particleCloud.size(); i++) {
if (i == 0) HMCCPacketManager.sendRidingPacket(entity.getEntityId(), particleCloud.get(i), owner);
else HMCCPacketManager.sendRidingPacket(particleCloud.get(i - 1), particleCloud.get(i) , owner);
}
HMCCPacketManager.sendRidingPacket(particleCloud.get(particleCloud.size() - 1),getFirstItemDisplayId(), owner);
if (!user.isHidden()) HMCCPacketManager.sendItemDisplayMetadata(getFirstItemDisplayId(), cosmeticBackpackType.getFirstPersonMetadata(), user.getUserCosmeticItem(cosmeticBackpackType, cosmeticBackpackType.getFirstPersonBackpack()), outsideViewers);
}
HMCCPacketManager.sendItemDisplayMetadata(getFirstItemDisplayId(), cosmeticBackpackType.getMetadata(), user.getUserCosmeticItem(cosmeticBackpackType), outsideViewers);
HMCCPacketManager.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.getBlueprint(cosmeticBackpackType.getModelName()) == null) {
MessagesUtil.sendDebugMessages("Invalid Model Engine Blueprint " + cosmeticBackpackType.getModelName(), Level.SEVERE);
return;
}
ModeledEntity modeledEntity = ModelEngineAPI.getOrCreateModeledEntity(invisibleArmorStand);
ActiveModel model = ModelEngineAPI.createActiveModel(ModelEngineAPI.getBlueprint(cosmeticBackpackType.getModelName()));
model.setCanHurt(false);
modeledEntity.addModel(model, false);
}
MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Finish");
}
public void spawnFirstPersonBackpack(CosmeticBackpackType cosmeticBackpackType) {
if (this.invisibleArmorStand != null) return;
this.invisibleArmorStand = (ArmorStand) NMSHandlers.getHandler().spawnBackpack(user, cosmeticBackpackType);
this.particleCloud = (AreaEffectCloud) NMSHandlers.getHandler().spawnHMCParticleCloud(user.getPlayer().getLocation());
if (cosmeticBackpackType.getModelName() != null && HMCCosmeticsPlugin.hasModelEngine()) {
if (ModelEngineAPI.api.getModelRegistry().getBlueprint(cosmeticBackpackType.getModelName()) == null) {
MessagesUtil.sendDebugMessages("Invalid Model Engine Blueprint " + cosmeticBackpackType.getModelName(), Level.SEVERE);
return;
}
ModeledEntity modeledEntity = ModelEngineAPI.getOrCreateModeledEntity(invisibleArmorStand);
/* 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);
*/
}
MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Finish");
}
public void despawnBackpack() {
if (invisibleArmorStand != null) {
invisibleArmorStand.setHealth(0);
invisibleArmorStand.remove();
this.invisibleArmorStand = null;
}
IntList entityIds = IntArrayList.of(itemDisplayId);
if (particleCloud != null) {
particleCloud.remove();
entityIds.addAll(particleCloud);
this.particleCloud = null;
}
HMCCPacketManager.sendEntityDestroyPacket(entityIds, getEntityManager().getViewers());
}
public void hideBackpack() {
if (user.getHidden()) return;
getArmorStand().getEquipment().clear();
hideBackpack = true;
if (user.isHidden()) return;
//getArmorStand().getEquipment().clear();
backpackHidden = true;
}
public void showBackpack() {
if (!hideBackpack) return;
if (!backpackHidden) return;
CosmeticBackpackType cosmeticBackpackType = (CosmeticBackpackType) user.getCosmetic(CosmeticSlot.BACKPACK);
ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType);
getArmorStand().getEquipment().setHelmet(item);
hideBackpack = false;
//getArmorStand().getEquipment().setHelmet(item);
backpackHidden = false;
}
public void setVisibility(boolean shown) {
hideBackpack = shown;
backpackHidden = shown;
}
public BackpackType getBackpackType() {
return backpackType;
}
public int getAreaEffectEntityId() {
return particleCloud.getEntityId();
}
public void teleportEffectEntity(Location location) {
particleCloud.teleport(location);
public ArrayList<Integer> getAreaEffectEntityId() {
return particleCloud;
}
public void setItem(ItemStack item) {
getArmorStand().getEquipment().setHelmet(item);
ItemDisplayMetadata metadata = Optional.ofNullable((CosmeticBackpackType) user.getCosmetic(CosmeticSlot.BACKPACK)).map(CosmeticBackpackType::getMetadata).orElse(new ItemDisplayMetadata());
HMCCPacketManager.sendItemDisplayMetadata(getFirstItemDisplayId(), metadata, item, getEntityManager().getViewers());
}
public void clearItems() {
ItemStack item = new ItemStack(Material.AIR);
getArmorStand().getEquipment().setHelmet(item);
//PacketManager.equipmentSlotUpdate(getFirstItemDisplayId(), EquipmentSlot.HEAD, item, getEntityManager().getViewers());
HMCCPacketManager.sendItemDisplayMetadata(getFirstItemDisplayId(), item, getEntityManager().getViewers());
}
public enum BackpackType {
NORMAL,
FIRST_PERSON // First person not yet implemented
/**
* Refreshes the block detection for the backpack
* @param outsideViewers
* @return true if the entity was updated, false if not
*//*
public boolean refreshBlock(List<Player> outsideViewers) {
if (Settings.isBackpackBlockDetection()) {
if (isInBlock() && checkBlock()) {
HMCCPacketManager.sendItemDisplayMetadata(getFirstItemDisplayId(), false, outsideViewers);
setInBlock(false);
return true;
}
if (!isInBlock() && !checkBlock()) {
HMCCPacketManager.sendItemDisplayMetadata(getFirstItemDisplayId(), true, outsideViewers);
setInBlock(true);
return true;
}
}
return false;
}
public boolean checkBlock() {
if (Settings.isBackpackBlockDetection()) {
Block block = getEntityManager().getLocation().clone().add(0, 1.5, 0).getBlock();
return block.getType().isAir();
}
return false;
}*/
}

View File

@@ -3,20 +3,24 @@ package com.hibiscusmc.hmccosmetics.user.manager;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
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 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 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.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
@@ -26,19 +30,31 @@ import java.util.logging.Level;
public class UserBalloonManager {
private CosmeticUser user;
@Getter
private BalloonType balloonType;
private CosmeticBalloonType cosmeticBalloonType;
@Getter
private UserBalloonPufferfish pufferfish;
private final ArmorStand modelEntity;
public UserBalloonManager(@NotNull Location location) {
this.pufferfish = new UserBalloonPufferfish(NMSHandlers.getHandler().getNextEntityId(), UUID.randomUUID());
this.modelEntity = NMSHandlers.getHandler().getMEGEntity(location.add(Settings.getBalloonOffset()));
public UserBalloonManager(CosmeticUser user, @NotNull Location location) {
this.user = user;
this.pufferfish = new UserBalloonPufferfish(user.getUniqueId(), NMSHandlers.getHandler().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) {
// redo this
if (cosmeticBalloonType.getModelName() != null && HMCCosmeticsPlugin.hasModelEngine()) {
if (cosmeticBalloonType.getModelName() != null && Hooks.isActiveHook("ModelEngine")) {
balloonType = BalloonType.MODELENGINE;
} else {
if (cosmeticBalloonType.getItem() != null) {
@@ -53,7 +69,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;
}
@@ -61,14 +77,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();
}
});
}
BukkitEntityData data = (BukkitEntityData) modeledEntity.getBase().getData();
data.setBlockedCullIgnoreRadius((double) Settings.getViewDistance());
data.getTracked().setPlayerPredicate(this::playerCheck);
return;
}
if (balloonType == BalloonType.ITEM) {
@@ -78,18 +99,19 @@ public class UserBalloonManager {
public void remove() {
if (balloonType == BalloonType.MODELENGINE) {
final ModeledEntity entity = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId());
if (entity == null) return;
for (final Player player : entity.getRangeManager().getPlayerInRange()) {
entity.hideFromPlayer(player);
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) {
@@ -98,14 +120,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;
}
@@ -113,13 +134,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;
}
@@ -135,7 +154,7 @@ public class UserBalloonManager {
public int getPufferfishBalloonId() {
return pufferfish.getId();
return pufferfish.getPufferFishEntityId();
}
public UUID getPufferfishBalloonUniqueId() {
return pufferfish.getUuid();
@@ -162,27 +181,39 @@ 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());
}
}
public UserBalloonPufferfish getPufferfish() {
return pufferfish;
}
public enum BalloonType {
MODELENGINE,
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,58 +1,75 @@
package com.hibiscusmc.hmccosmetics.user.manager;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
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.packets.HMCCPacketManager;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class UserBalloonPufferfish {
public class UserBalloonPufferfish extends UserEntity {
private int id;
private int pufferFishEntityId;
private UUID uuid;
private List<Player> viewers = new ArrayList<>();
private Long lastUpdate;
public UserBalloonPufferfish(int id, UUID uuid) {
this.id = id;
public UserBalloonPufferfish(UUID owner, int pufferFishEntityId, UUID uuid) {
super(owner);
this.pufferFishEntityId = pufferFishEntityId;
this.uuid = uuid;
this.lastUpdate = System.currentTimeMillis();
}
public int getId() {
return id;
public int getPufferFishEntityId() {
return pufferFishEntityId;
}
public UUID getUuid() {
return uuid;
}
public void hidePufferfish() {
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);
}
@Override
public List<Player> refreshViewers(Location location) {
if (System.currentTimeMillis() - lastUpdate <= 1000) return List.of(); //Prevents mass refreshes
if (System.currentTimeMillis() - getViewerLastUpdate() <= 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 = HMCCPlayerUtils.getNearbyPlayers(location);
for (Player player : players) {
if (!viewers.contains(player)) {
viewers.add(player);
CosmeticUser user = CosmeticUsers.getUser(player);
if (user != null && getOwner() != user.getUniqueId() && user.isInWardrobe()) { // Fixes issue where players in wardrobe would see other players cosmetics if they were not in wardrobe
removePlayers.add(player);
HMCCPacketManager.sendEntityDestroyPacket(getPufferFishEntityId(), List.of(player));
continue;
}
if (!getViewers().contains(player)) {
getViewers().add(player);
newPlayers.add(player);
continue;
}
// bad loopdy loops
for (Player viewerPlayer : viewers) {
for (Player viewerPlayer : getViewers()) {
if (!players.contains(viewerPlayer)) {
removePlayers.add(viewerPlayer);
PacketManager.sendEntityDestroyPacket(id, List.of(viewerPlayer)); // prevents random leashes
HMCCPacketManager.sendEntityDestroyPacket(getPufferFishEntityId(), List.of(viewerPlayer));
}
}
}
viewers.removeAll(removePlayers);
lastUpdate = System.currentTimeMillis();
getViewers().removeAll(removePlayers);
setViewerLastUpdate(System.currentTimeMillis());
return newPlayers;
}
}

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,16 +2,15 @@ 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;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@@ -24,13 +23,13 @@ public class UserEmoteModel extends PlayerModel {
private final CosmeticUser user;
private String emotePlaying;
private final int armorStandId;
private final int itemDisplayId;
private GameMode originalGamemode;
public UserEmoteModel(@NotNull CosmeticUser user) {
super(user.getPlayer());
this.user = user;
armorStandId = NMSHandlers.getHandler().getNextEntityId();
itemDisplayId = ServerUtils.getNextEntityId();
getRangeManager().setRenderDistance(Settings.getViewDistance());
}
@@ -43,44 +42,47 @@ 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);
Location newLocation = player.getLocation().clone();
newLocation.setPitch(0);
double DISTANCE = Settings.getEmoteDistance();
Location thirdPersonLocation = newLocation.add(newLocation.getDirection().normalize().multiply(DISTANCE));
if (DISTANCE > 0) {
MessagesUtil.sendDebugMessages("Yaw " + (int) thirdPersonLocation.getYaw());
MessagesUtil.sendDebugMessages("New Yaw " + ServerUtils.getNextYaw((int) thirdPersonLocation.getYaw(), 180));
thirdPersonLocation.setYaw(ServerUtils.getNextYaw((int) thirdPersonLocation.getYaw(), 180));
}
if (Settings.getCosmeticEmoteBlockCheck() && thirdPersonLocation.getBlock().getType().isOccluding()) {
stopAnimation();
MessagesUtil.sendMessage(player, "emote-blocked");
return;
}
// Check if block below player is an air block
if (Settings.getEmoteAirCheck() && newLocation.clone().subtract(0, 1, 0).getBlock().getType().isAir()) {
stopAnimation();
MessagesUtil.sendMessage(player, "emote-blocked");
}
user.getPlayer().setInvisible(true);
user.hideCosmetics(CosmeticUser.HiddenReason.EMOTE);
originalGamemode = player.getGameMode();
PacketManager.sendEntitySpawnPacket(thirdPersonLocation, armorStandId, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer);
PacketManager.sendInvisibilityPacket(armorStandId, viewer);
PacketManager.sendLookPacket(armorStandId, thirdPersonLocation, viewer);
if (Settings.isEmoteCameraEnabled()) {
Location newLocation = player.getLocation().clone();
newLocation.setPitch(0);
double DISTANCE = Settings.getEmoteDistance();
Location thirdPersonLocation = newLocation.add(newLocation.getDirection().normalize().multiply(DISTANCE));
if (DISTANCE > 0) {
MessagesUtil.sendDebugMessages("Yaw " + (int) thirdPersonLocation.getYaw());
MessagesUtil.sendDebugMessages("New Yaw " + ServerUtils.getNextYaw((int) thirdPersonLocation.getYaw(), 180));
thirdPersonLocation.setYaw(ServerUtils.getNextYaw((int) thirdPersonLocation.getYaw(), 180));
}
if (Settings.isCosmeticEmoteBlockCheck() && thirdPersonLocation.getBlock().getType().isOccluding()) {
stopAnimation();
MessagesUtil.sendMessage(player, "emote-blocked");
return;
}
// Check if block below player is an air block
if (Settings.isEmoteAirCheck() && newLocation.clone().subtract(0, 1, 0).getBlock().getType().isAir()) {
stopAnimation();
MessagesUtil.sendMessage(player, "emote-blocked");
}
HMCCPacketManager.sendEntitySpawnPacket(thirdPersonLocation, itemDisplayId, EntityType.ITEM_DISPLAY, UUID.randomUUID(), viewer);
//HMCCPacketManager.sendInvisibilityPacket(itemDisplayId, viewer);
HMCCPacketManager.sendLookPacket(itemDisplayId, thirdPersonLocation, viewer);
HMCCPacketManager.gamemodeChangePacket(player, 3);
HMCCPacketManager.sendCameraPacket(itemDisplayId, viewer);
}
PacketManager.gamemodeChangePacket(player, 3);
PacketManager.sendCameraPacket(armorStandId, viewer);
MessagesUtil.sendDebugMessages("playAnimation run");
}
@@ -106,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(itemDisplayId, 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

@@ -0,0 +1,100 @@
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.HMCCPlayerUtils;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class UserEntity {
@Getter
private UUID owner;
@Getter
private List<Player> viewers = new ArrayList<>();
@Getter @Setter
private Long viewerLastUpdate = 0L;
@Getter @Setter
private Long lastPositionUpdate = 0L;
@Getter @Setter
private List<Integer> ids = new ArrayList<>();
@Getter
private Location location;
public UserEntity(UUID owner) {
this.owner = owner;
}
public List<Player> refreshViewers() {
return refreshViewers(location);
}
public List<Player> refreshViewers(Location location) {
if (System.currentTimeMillis() - viewerLastUpdate <= 1000) return List.of(); //Prevents mass refreshes
ArrayList<Player> newPlayers = new ArrayList<>();
ArrayList<Player> removePlayers = new ArrayList<>();
List<Player> players = HMCCPlayerUtils.getNearbyPlayers(location);
for (Player player : players) {
CosmeticUser user = CosmeticUsers.getUser(player);
IntList ids = new IntArrayList(this.ids);
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
removePlayers.add(player);
HMCCPacketManager.sendEntityDestroyPacket(ids, List.of(player));
continue;
}
if (!viewers.contains(player)) {
viewers.add(player);
newPlayers.add(player);
continue;
}
// bad loopdy loops
for (Player viewerPlayer : viewers) {
if (!players.contains(viewerPlayer)) {
removePlayers.add(viewerPlayer);
HMCCPacketManager.sendEntityDestroyPacket(ids, List.of(viewerPlayer));
}
}
}
viewers.removeAll(removePlayers);
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) {
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) {
// 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

@@ -1,19 +1,25 @@
package com.hibiscusmc.hmccosmetics.user.manager;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.config.Wardrobe;
import com.hibiscusmc.hmccosmetics.config.WardrobeLocation;
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
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.misc.ItemDisplayMetadata;
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;
@@ -24,36 +30,51 @@ 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 {
@Getter
private final int NPC_ID;
private final int ARMORSTAND_ID;
@Getter
private final int ITEM_DISPLAY_ID;
@Getter
private final UUID WARDROBE_UUID;
@Getter
private String npcName;
@Getter
private GameMode originalGamemode;
@Getter
private final CosmeticUser user;
@Getter
private final Wardrobe wardrobe;
@Getter
private final WardrobeLocation wardrobeLocation;
@Getter
private final Location viewingLocation;
@Getter
private final Location npcLocation;
@Getter
private Location exitLocation;
@Getter
private BossBar bossBar;
@Getter
private boolean active;
@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();
ITEM_DISPLAY_ID = me.lojosho.hibiscuscommons.util.ServerUtils.getNextEntityId();
WARDROBE_UUID = UUID.randomUUID();
this.user = user;
@@ -65,6 +86,7 @@ public class UserWardrobeManager {
this.npcLocation = wardrobeLocation.getNpcLocation();
wardrobeStatus = WardrobeStatus.SETUP;
this.lastOpenMenu = Menus.getDefaultMenu();
}
public void start() {
@@ -77,59 +99,76 @@ 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 = () -> {
// Armorstand
PacketManager.sendEntitySpawnPacket(viewingLocation, ARMORSTAND_ID, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer);
PacketManager.sendInvisibilityPacket(ARMORSTAND_ID, viewer);
PacketManager.sendLookPacket(ARMORSTAND_ID, viewingLocation, viewer);
// ItemDisplay
HMCCPacketManager.sendEntitySpawnPacket(viewingLocation, ITEM_DISPLAY_ID, EntityType.ITEM_DISPLAY, UUID.randomUUID(), viewer);
HMCCPacketManager.sendItemDisplayMetadata(ITEM_DISPLAY_ID, new ItemStack(Material.AIR), viewer);
HMCCPacketManager.sendLookPacket(ITEM_DISPLAY_ID, viewingLocation, viewer);
// Player
PacketManager.gamemodeChangePacket(player, 3);
PacketManager.sendCameraPacket(ARMORSTAND_ID, viewer);
user.getPlayer().teleport(viewingLocation, PlayerTeleportEvent.TeleportCause.PLUGIN);
user.getPlayer().setInvisible(true);
HMCCPacketManager.gamemodeChangePacket(player, 3);
HMCCPacketManager.sendCameraPacket(ITEM_DISPLAY_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);
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);
}, 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)) {
user.getUserBackpackManager().getArmorStand().teleport(npcLocation.clone().add(0, 2, 0));
PacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstArmorStandId(), viewer);
// Maybe null as backpack maybe despawned before entering
UserBackpackManager userBackpackManager = user.getUserBackpackManager();
if (userBackpackManager == null) user.respawnBackpack();
if (user.isBackpackSpawned()) {
userBackpackManager.getEntityManager().teleport(npcLocation.clone());
CosmeticBackpackType backpackCosmetic = (CosmeticBackpackType) user.getCosmetic(CosmeticSlot.BACKPACK);
HMCCPacketManager.sendItemDisplayMetadata(ITEM_DISPLAY_ID, backpackCosmetic.getMetadata(), user.getUserCosmeticItem(backpackCosmetic), viewer);
HMCCPacketManager.ridingMountPacket(NPC_ID, userBackpackManager.getFirstItemDisplayId(), viewer);
}
}
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
user.getBalloonManager().sendRemoveLeashPacket(viewer);
user.getBalloonManager().sendLeashPacket(NPC_ID);
//PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getModelId(), NPC_ID, viewer);
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(Settings.getBalloonOffset());
PacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), balloonLocation , false, viewer);
user.getBalloonManager().getModelEntity().teleport(balloonLocation);
Location balloonLocation = npcLocation.clone().add(cosmetic.getBalloonOffset());
HMCCPacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), balloonLocation, false, viewer);
user.getBalloonManager().getModelEntity().teleport(balloonLocation);
user.getBalloonManager().setLocation(balloonLocation);
}
}
if (WardrobeSettings.getEnabledBossbar()) {
if (WardrobeSettings.isEnabledBossbar()) {
float progress = WardrobeSettings.getBossbarProgress();
Component message = MessagesUtil.processStringNoKey(WardrobeSettings.getBossbarText());
Component message = MessagesUtil.processStringNoKey(player, WardrobeSettings.getBossbarMessage());
bossBar = BossBar.bossBar(message, progress, WardrobeSettings.getBossbarColor(), WardrobeSettings.getBossbarOverlay());
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
@@ -168,10 +207,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;
@@ -186,25 +227,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(ITEM_DISPLAY_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();
@@ -214,17 +256,25 @@ 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.getEnabledBossbar()) {
if (WardrobeSettings.isEnabledBossbar()) {
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
target.hideBossBar(bossBar);
@@ -249,43 +299,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);
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);
user.getUserBackpackManager().getArmorStand().setRotation(nextyaw, 0);
PacketManager.sendEntityDestroyPacket(user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK) && user.getUserBackpackManager() != null) {
HMCCPacketManager.sendTeleportPacket(user.getUserBackpackManager().getFirstItemDisplayId(), location, false, viewer);
HMCCPacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstItemDisplayId(), viewer);
user.getUserBackpackManager().getEntityManager().setRotation(nextyaw);
HMCCPacketManager.sendEntityDestroyPacket(user.getUserBackpackManager().getFirstItemDisplayId(), 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
}
}
};
@@ -293,14 +347,6 @@ public class UserWardrobeManager {
runnable.runTaskTimer(HMCCosmeticsPlugin.getInstance(), 0, 2);
}
public int getCameraId() {
return ARMORSTAND_ID;
}
public WardrobeStatus getWardrobeStatus() {
return wardrobeStatus;
}
public void setWardrobeStatus(WardrobeStatus status) {
this.wardrobeStatus = status;
}
@@ -312,7 +358,4 @@ public class UserWardrobeManager {
STOPPING,
}
public Location getNpcLocation() {
return npcLocation;
}
}

View File

@@ -11,7 +11,10 @@ import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class InventoryUtils {
import java.util.Arrays;
import java.util.List;
public class HMCCInventoryUtils {
/**
* Converts from the Bukkit item slots to ProtocolLib item slots. Will produce a null if an improper bukkit item slot is sent through
@@ -52,6 +55,17 @@ public class InventoryUtils {
};
}
public static CosmeticSlot getItemSlotToCosmeticSlot(final EnumWrappers.ItemSlot slot) {
return switch (slot) {
case HEAD -> CosmeticSlot.HELMET;
case CHEST -> CosmeticSlot.CHESTPLATE;
case LEGS -> CosmeticSlot.LEGGINGS;
case FEET -> CosmeticSlot.BOOTS;
case OFFHAND -> CosmeticSlot.OFFHAND;
case MAINHAND -> CosmeticSlot.MAINHAND;
};
}
public static CosmeticSlot BukkitCosmeticSlot(EquipmentSlot slot) {
return switch (slot) {
case HAND -> CosmeticSlot.MAINHAND;
@@ -142,6 +156,32 @@ public class InventoryUtils {
}
}
public static EquipmentSlot getEquipmentSlot(@NotNull EnumWrappers.ItemSlot slot) {
switch (slot) {
case HEAD -> {
return EquipmentSlot.HEAD;
}
case CHEST -> {
return EquipmentSlot.CHEST;
}
case LEGS -> {
return EquipmentSlot.LEGS;
}
case FEET -> {
return EquipmentSlot.FEET;
}
case OFFHAND -> {
return EquipmentSlot.OFF_HAND;
}
case MAINHAND -> {
return EquipmentSlot.HAND;
}
default -> {
return null;
}
}
}
public static boolean isCosmeticItem(ItemStack itemStack) {
if (itemStack == null) return false;
itemStack = itemStack.clone();
@@ -153,15 +193,11 @@ public class InventoryUtils {
return new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "cosmetic");
}
public static NamespacedKey getOwnerKey() {
return new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "owner");
}
public static NamespacedKey getSkullOwner() {
return new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "skullowner");
}
public static NamespacedKey getSkullTexture() {
return new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "skulltexture");
/**
* This returns all the slots a player can have on them. In 1.20.6+, the enum includes BODY, which is not a valid slot for a player.
* @return A list of all the slots a player can have on them
*/
public static List<EquipmentSlot> getPlayerArmorSlots() {
return Arrays.asList(EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.LEGS, EquipmentSlot.FEET, EquipmentSlot.OFF_HAND, EquipmentSlot.HAND);
}
}

View File

@@ -3,16 +3,15 @@ package com.hibiscusmc.hmccosmetics.util;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.comphenix.protocol.wrappers.WrappedSignedProperty;
import com.hibiscusmc.hmccosmetics.config.Settings;
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
public class PlayerUtils {
public class HMCCPlayerUtils {
@Nullable
public static WrappedSignedProperty getSkin(Player player) {
@@ -32,13 +31,6 @@ public class PlayerUtils {
@NotNull
public static List<Player> getNearbyPlayers(@NotNull Location location) {
List<Player> players = new ArrayList<>();
int viewDistance = Settings.getViewDistance();
for (Entity entity : location.getWorld().getNearbyEntities(location, viewDistance, viewDistance, viewDistance)) {
if (entity instanceof Player) {
players.add((Player) entity);
}
}
return players;
return PacketManager.getViewers(location, Settings.getViewDistance());
}
}

View File

@@ -1,11 +1,11 @@
package com.hibiscusmc.hmccosmetics.util;
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
import com.owen1212055.particlehelper.api.particle.MultiParticle;
import com.owen1212055.particlehelper.api.particle.Particle;
import com.owen1212055.particlehelper.api.particle.types.*;
import com.owen1212055.particlehelper.api.particle.types.dust.transition.TransitionDustParticle;
import com.owen1212055.particlehelper.api.particle.types.note.MultiNoteParticle;
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
import org.bukkit.Color;
import org.bukkit.GameMode;
import org.bukkit.Material;
@@ -14,7 +14,7 @@ import org.jetbrains.annotations.Nullable;
import java.math.BigInteger;
import java.util.Arrays;
public class ServerUtils {
public class HMCCServerUtils {
private static String COLOR_CHAR = "&";
@@ -36,6 +36,11 @@ public class ServerUtils {
return NMSHandlers.getHandler().getEntity(entityId);
}
/**
* This takes in a string like #FFFFFF to convert it into a Bukkit color
* @param colorStr
* @return
*/
public static Color hex2Rgb(String colorStr) {
if (colorStr.startsWith("#")) return Color.fromRGB(Integer.valueOf(colorStr.substring(1), 16));
if (colorStr.startsWith("0x")) return Color.fromRGB(Integer.valueOf(colorStr.substring(2), 16));
@@ -48,6 +53,22 @@ public class ServerUtils {
return Color.WHITE;
}
/**
* This takes in a string like 55,49,181 to convert it into a Bukkit Color
* @param colorStr
* @return
*/
public static Color rgbToRgb(String colorStr) {
if (colorStr.contains(",")) {
String[] colors = colorStr.split(",", 3);
if (colors.length == 3) {
return Color.fromRGB(Integer.parseInt(colors[0]), Integer.parseInt(colors[1]), Integer.parseInt(colors[2]));
}
}
return Color.WHITE;
}
// particle amount offsetxyz
// Ex. HEART 10 0.1 0.1 0.1
public static Particle addParticleValues(Particle particle, String[] split) {
@@ -136,4 +157,13 @@ public class ServerUtils {
}
return nextYaw;
}
public static boolean hasClass(String className) {
try {
Class.forName(className);
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
}

View File

@@ -2,11 +2,10 @@ package com.hibiscusmc.hmccosmetics.util;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.misc.Adventure;
import me.clip.placeholderapi.PlaceholderAPI;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.hibiscuscommons.util.AdventureUtils;
import me.lojosho.shaded.configurate.ConfigurationNode;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.Component;
@@ -16,7 +15,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.configurate.ConfigurationNode;
import java.time.Duration;
import java.util.HashMap;
@@ -89,7 +87,7 @@ public class MessagesUtil {
public static void sendTitle(Player player, String message, int fadein, int stay, int fadeout) {
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
Title.Times times = Title.Times.times(Duration.ofMillis(WardrobeSettings.getTransitionFadeIn()), Duration.ofMillis(3000), Duration.ofMillis(1000));
Title.Times times = Title.Times.times(Duration.ofMillis(fadein), Duration.ofMillis(stay), Duration.ofMillis(fadeout));
Title title = Title.title(processStringNoKey(player, message), Component.empty(), times);
target.showTitle(title);
@@ -104,12 +102,12 @@ public class MessagesUtil {
if (!MESSAGES.containsKey(key)) return null;
if (MESSAGES.get(key) == null) return null;
String message = MESSAGES.get(key);
if (Hooks.isActiveHook("PlaceholderAPI") && player != null) message = PlaceholderAPI.setPlaceholders(player, message);
if (player != null) message = Hooks.processPlaceholders(player, message);
message = message.replaceAll("%prefix%", prefix);
if (placeholders != null ) {
return Adventure.MINI_MESSAGE.deserialize(message, placeholders);
return AdventureUtils.MINI_MESSAGE.deserialize(message, placeholders);
}
return Adventure.MINI_MESSAGE.deserialize(message);
return AdventureUtils.MINI_MESSAGE.deserialize(message);
}
@NotNull
@@ -125,16 +123,16 @@ public class MessagesUtil {
@NotNull
public static Component processStringNoKey(Player player, String message, TagResolver placeholders) {
message = message.replaceAll("%prefix%", prefix);
if (Hooks.isActiveHook("PlaceholderAPI") && player != null) message = PlaceholderAPI.setPlaceholders(player, message);
if (player != null) message = Hooks.processPlaceholders(player, message);
if (placeholders != null ) {
return Adventure.MINI_MESSAGE.deserialize(message, placeholders);
return AdventureUtils.MINI_MESSAGE.deserialize(message, placeholders);
}
return Adventure.MINI_MESSAGE.deserialize(message);
return AdventureUtils.MINI_MESSAGE.deserialize(message);
}
public static String processStringNoKeyString(Player player, String message) {
message = message.replaceAll("%prefix%", prefix);
if (Hooks.isActiveHook("PlaceholderAPI") && player != null) message = PlaceholderAPI.setPlaceholders(player, message);
if (player != null) message = Hooks.processPlaceholders(player, message);
return message;
}
@@ -143,7 +141,7 @@ public class MessagesUtil {
}
public static void sendDebugMessages(String message, Level level) {
if (!Settings.isDebugEnabled() && level == Level.INFO) return;
if (!Settings.isDebugMode() && level == Level.INFO) return;
HMCCosmeticsPlugin.getInstance().getLogger().log(level, message);
}
}

View File

@@ -1,20 +1,5 @@
package com.hibiscusmc.hmccosmetics.util;
public class TranslationPair {
public record TranslationPair(String key, String value) {
private String key;
private String value;
public TranslationPair(String key, String value) {
this.key = key;
this.value = value;
}
public String getKey() {
return key;
}
public String getValue() {
return value;
}
}

View File

@@ -1,6 +1,7 @@
package com.hibiscusmc.hmccosmetics.util;
import org.spongepowered.configurate.ConfigurationNode;
import me.lojosho.hibiscuscommons.util.StringUtils;
import me.lojosho.shaded.configurate.ConfigurationNode;
import java.util.ArrayList;
import java.util.HashMap;
@@ -9,19 +10,20 @@ import java.util.List;
public class TranslationUtil {
// unlocked-cosmetic -> true -> True
private static HashMap<String, List<TranslationPair>> keys = new HashMap<>();
private static final HashMap<String, List<TranslationPair>> keys = new HashMap<>();
public static void setup(ConfigurationNode config) {
keys.clear();
for (ConfigurationNode node : config.childrenMap().values()) {
ArrayList<TranslationPair> pairs = new ArrayList<>();
for (ConfigurationNode translatableMessage : node.childrenMap().values()) {
String key = translatableMessage.key().toString();
key.replaceAll("'", ""); // Autoupdater adds ' to it? Removes it from the key
key = key.replaceAll("'", ""); // Autoupdater adds ' to it? Removes it from the key
TranslationPair pair = new TranslationPair(key, translatableMessage.getString());
pairs.add(pair);
MessagesUtil.sendDebugMessages("setupTranslation key:" + node.key().toString() + " | " + node);
MessagesUtil.sendDebugMessages("Overall Key " + node.key().toString());
MessagesUtil.sendDebugMessages("Key '" + pair.getKey() + "' Value '" + pair.getValue() + "'");
MessagesUtil.sendDebugMessages("Key '" + pair.key() + "' Value '" + pair.value() + "'");
}
keys.put(node.key().toString().toLowerCase(), pairs);
}
@@ -30,7 +32,7 @@ public class TranslationUtil {
public static String getTranslation(String key, String message) {
List<TranslationPair> pairs = keys.get(key);
for (TranslationPair pair : pairs) {
if (pair.getKey() == message) return pair.getValue();
if (pair.key().equals(message)) return StringUtils.parseStringToString(pair.value());
}
return message;

View File

@@ -1,39 +0,0 @@
package com.hibiscusmc.hmccosmetics.util.builder;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.jetbrains.annotations.NotNull;
public class ColorBuilder {
public static boolean canBeColored(final Material material) {
return canBeColored(new ItemStack(material));
}
public static boolean canBeColored(final @NotNull ItemStack itemStack) {
final ItemMeta itemMeta = itemStack.getItemMeta();
return (itemMeta instanceof LeatherArmorMeta ||
itemMeta instanceof PotionMeta);
}
/**
* @param color armor color
* @return this
*/
public static ItemMeta color(ItemMeta itemMeta, final Color color) {
if (itemMeta instanceof final PotionMeta meta) {
meta.setColor(color);
}
if (itemMeta instanceof final LeatherArmorMeta meta) {
meta.setColor(color);
}
return itemMeta;
}
}

View File

@@ -1,215 +0,0 @@
package com.hibiscusmc.hmccosmetics.util.builder;
import com.hibiscusmc.hmccosmetics.util.misc.Placeholder;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class ItemBuilder {
protected Material material;
protected int amount;
protected ItemMeta itemMeta;
/**
* @param material builder material
*/
ItemBuilder(final Material material) {
this.material = material;
this.itemMeta = Bukkit.getItemFactory().getItemMeta(material);
}
/**
* @param itemStack builder ItemStack
*/
ItemBuilder(final @NotNull ItemStack itemStack) {
this.material = itemStack.getType();
this.itemMeta = itemStack.hasItemMeta() ? itemStack.getItemMeta()
: Bukkit.getItemFactory().getItemMeta(this.material);
}
/**
* @param material builder material
* @return
*/
@Contract("_ -> new")
@NotNull
public static ItemBuilder from(final Material material) {
return new ItemBuilder(material);
}
/**
* @param itemStack builder ItemStack
* @return
*/
@Contract("_ -> new")
@NotNull
public static ItemBuilder from(final ItemStack itemStack) {
return new ItemBuilder(itemStack);
}
/**
* @param amount ItemStack amount
* @return this
*/
public ItemBuilder amount(final int amount) {
this.amount = Math.min(Math.max(1, amount), 64);
return this;
}
/**
* @param name ItemStack name
* @return this
*/
public ItemBuilder name(final String name) {
if (this.itemMeta == null) {
return this;
}
this.itemMeta.setDisplayName(name);
return this;
}
/**
* @param lore ItemStack lore
* @return this
*/
public ItemBuilder lore(final List<String> lore) {
if (this.itemMeta == null) {
return this;
}
this.itemMeta.setLore(lore);
return this;
}
public ItemBuilder papiPlaceholders(final Player player) {
this.lorePapiPlaceholders(player);
this.namePapiPlaceholders(player);
return this;
}
private void lorePapiPlaceholders(final Player player) {
if (this.itemMeta == null) {
return;
}
final List<String> newLore = new ArrayList<>();
final List<String> lore = this.itemMeta.getLore();
if (lore == null) {
return;
}
for (final String line : this.itemMeta.getLore()) {
newLore.add(Placeholder.applyPapiPlaceholders(player, line));
}
this.itemMeta.setLore(newLore);
}
private void namePapiPlaceholders(final Player player) {
if (this.itemMeta == null) {
return;
}
this.itemMeta.setDisplayName(
Placeholder.applyPapiPlaceholders(
player,
this.itemMeta.getDisplayName()
)
);
}
/**
* @param unbreakable whether the ItemStack is unbreakable
* @return this
*/
public ItemBuilder unbreakable(final boolean unbreakable) {
if (this.itemMeta == null) {
return this;
}
this.itemMeta.setUnbreakable(unbreakable);
return this;
}
public ItemBuilder glow(final boolean glow) {
if (this.itemMeta == null) {
return this;
}
if (glow) {
this.itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
this.itemMeta.addEnchant(Enchantment.LUCK, 1, true);
}
return this;
}
/**
* @param enchantments enchants to be added to the ItemStack
* @param ignoreLeveLRestrictions whether to ignore enchantment level restrictions
* @return this
*/
public ItemBuilder enchants(final Map<Enchantment, Integer> enchantments,
boolean ignoreLeveLRestrictions) {
if (this.itemMeta == null) {
return this;
}
enchantments.forEach((enchantment, level) -> this.itemMeta.addEnchant(enchantment, level,
ignoreLeveLRestrictions));
return this;
}
/**
* @param itemFlags ItemStack ItemFlags
* @return this
*/
public ItemBuilder itemFlags(final Set<ItemFlag> itemFlags) {
if (this.itemMeta == null) {
return this;
}
this.itemMeta.addItemFlags(itemFlags.toArray(new ItemFlag[0]));
return this;
}
/**
* @param modelData ItemStack modelData
* @return this
*/
public ItemBuilder modelData(final int modelData) {
if (this.itemMeta == null) {
return this;
}
this.itemMeta.setCustomModelData(modelData);
return this;
}
/**
* @return built ItemStack
*/
public ItemStack build() {
final ItemStack itemStack = new ItemStack(this.material, Math.max(this.amount, 1));
itemStack.setItemMeta(itemMeta);
return itemStack;
}
}

View File

@@ -1,18 +0,0 @@
package com.hibiscusmc.hmccosmetics.util.misc;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
public class Adventure {
public static final LegacyComponentSerializer SERIALIZER = LegacyComponentSerializer.builder()
.hexColors()
.useUnusualXRepeatedCharacterHexFormat()
.build();
public static final MiniMessage MINI_MESSAGE = MiniMessage.builder().tags(
StandardTags.defaults()
).
build();
}

View File

@@ -0,0 +1,49 @@
package com.hibiscusmc.hmccosmetics.util.misc;
import org.bukkit.Material;
import org.bukkit.entity.Display;
import org.bukkit.entity.ItemDisplay;
import org.bukkit.inventory.ItemStack;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import java.util.HashMap;
import java.util.Map;
public class ItemDisplayMetadata {
public Vector3f translation;
public Vector3f scale;
public Quaternionf rotationLeft;
public Quaternionf rotationRight;
public Display.Billboard billboard;
public int skyLight;
public float viewRange;
public float width;
public float height;
public ItemDisplay.ItemDisplayTransform displayTransform;
public ItemStack itemStack;
public ItemDisplayMetadata() {
this.translation = new Vector3f();
this.scale = new Vector3f(1.0f, 1.0f, 1.0f);
this.rotationLeft = new Quaternionf();
this.rotationRight = new Quaternionf();
this.skyLight = 15;
this.viewRange = 1.0f;
this.width = 0.0f;
this.height = 0.0f;
this.displayTransform = ItemDisplay.ItemDisplayTransform.NONE;
this.itemStack = new ItemStack(Material.AIR);
}
public ItemDisplayMetadata setFixed() {
this.billboard = Display.Billboard.FIXED;
return this;
}
public ItemDisplayMetadata setVertical() {
this.billboard = Display.Billboard.VERTICAL;
return this;
}
}

View File

@@ -1,75 +0,0 @@
package com.hibiscusmc.hmccosmetics.util.misc;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;
public class Keys {
static HMCCosmeticsPlugin plugin = HMCCosmeticsPlugin.getInstance();
public static final NamespacedKey ITEM_KEY = new NamespacedKey(plugin, "cosmetic");
public static final NamespacedKey TOKEN_KEY = new NamespacedKey(plugin, "token-key");
public static void setKey(final @NotNull ItemStack itemStack) {
final ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null) {
return;
}
itemMeta.getPersistentDataContainer().set(ITEM_KEY, PersistentDataType.BYTE, (byte) 1);
itemStack.setItemMeta(itemMeta);
}
public static <T, Z> void setKey(
final @NotNull ItemStack itemStack,
final NamespacedKey key,
final PersistentDataType<T, Z> type,
final Z value) {
final ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null) {
return;
}
itemMeta.getPersistentDataContainer().set(key, type, value);
itemStack.setItemMeta(itemMeta);
}
public static boolean hasKey(final @NotNull ItemStack itemStack) {
final ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null) {
return false;
}
return itemMeta.getPersistentDataContainer().has(ITEM_KEY, PersistentDataType.BYTE);
}
public static <T, Z> boolean hasKey(final @NotNull ItemStack itemStack, final NamespacedKey key, final PersistentDataType<T, Z> type) {
final ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null) {
return false;
}
return itemMeta.getPersistentDataContainer().has(key, type);
}
@Nullable
public static <T, Z> Z getValue(final @NotNull ItemStack itemStack, final NamespacedKey key, final PersistentDataType<T, Z> type) {
final ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null) {
return null;
}
return itemMeta.getPersistentDataContainer().get(key, type);
}
}

View File

@@ -1,33 +0,0 @@
package com.hibiscusmc.hmccosmetics.util.misc;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
public class Placeholder {
public static final String PREFIX = "%prefix%";
public static final String TYPE = "%type%";
public static final String ITEM = "%item%";
public static final String FILE = "%file%";
public static final String PLAYER = "%player%";
public static final String ENABLED = "%enabled%";
public static final String ALLOWED = "%allowed%";
public static final String ID = "%id%";
/**
* @return message with placeholders applied
*/
public static String applyPapiPlaceholders(@Nullable final Player player,
final String message) {
/*
if (HookManager.getInstance().isEnabled(PAPIHook.class)) {
return HookManager.getInstance().getPapiHook().parse(player, message);
}
*/
return message;
}
}

View File

@@ -1,36 +0,0 @@
package com.hibiscusmc.hmccosmetics.util.misc;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;
public class StringUtils {
/**
* @param parsed message to be parsed
* @return MiniMessage parsed string
*/
@NotNull
public static Component parse(final String parsed) {
return Adventure.MINI_MESSAGE.deserialize(parsed);
}
@NotNull
public static String parseStringToString(final String parsed) {
return Adventure.SERIALIZER.serialize(Adventure.MINI_MESSAGE.deserialize(parsed));
}
@NotNull
public static String formatArmorItemType(String type) {
type = type.toLowerCase();
final String[] parts = type.split(" ");
final String firstPart = parts[0].substring(0, 1).toUpperCase() + parts[0].substring(1);
if (parts.length == 1) {
return firstPart;
}
return firstPart + parts[1].substring(0, 1).toUpperCase() + parts[1].substring(1);
}
}

View File

@@ -1,13 +0,0 @@
package com.hibiscusmc.hmccosmetics.util.packets;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import org.bukkit.entity.Player;
public class BasePacket {
public static void sendPacket(Player player, PacketContainer packet) {
if (player == null) return;
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
}
}

View File

@@ -1,35 +1,46 @@
package com.hibiscusmc.hmccosmetics.util.packets;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.*;
import com.google.common.collect.Lists;
import com.hibiscusmc.hmccosmetics.api.HMCCosmeticsAPI;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.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.PlayerUtils;
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
import com.hibiscusmc.hmccosmetics.util.HMCCPlayerUtils;
import com.hibiscusmc.hmccosmetics.util.misc.ItemDisplayMetadata;
import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerNamedEntitySpawn;
import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerPlayerInfo;
import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerRelEntityMove;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Display;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ItemDisplay;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.*;
public class PacketManager extends BasePacket {
public class HMCCPacketManager extends PacketManager {
public static void sendEntitySpawnPacket(
final @NotNull Location location,
final int entityId,
final EntityType entityType,
final UUID uuid
) {
sendEntitySpawnPacket(location, entityId, entityType, uuid, getViewers(location));
}
public static void sendEntitySpawnPacket(
final @NotNull Location location,
@@ -38,39 +49,7 @@ public class PacketManager extends BasePacket {
final UUID uuid,
final @NotNull List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
packet.getModifier().writeDefaults();
packet.getUUIDs().write(0, uuid);
packet.getIntegers().write(0, entityId);
packet.getEntityTypeModifier().write(0, entityType);
packet.getDoubles().
write(0, location.getX()).
write(1, location.getY()).
write(2, location.getZ());
for (Player p : sendTo) sendPacket(p, packet);
}
public static void gamemodeChangePacket(
Player player,
int gamemode
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.GAME_STATE_CHANGE);
packet.getGameStateIDs().write(0, 3);
// Tells what event this is. This is a change gamemode event.
packet.getFloat().write(0, (float) gamemode);
sendPacket(player, packet);
MessagesUtil.sendDebugMessages("Gamemode Change sent to " + player + " to be " + gamemode);
}
public static void ridingMountPacket(
int mountId,
int passengerId,
@NotNull List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.MOUNT);
packet.getIntegers().write(0, mountId);
packet.getIntegerArrays().write(0, new int[]{passengerId});
for (Player p : sendTo) sendPacket(p, packet);
PacketManager.sendEntitySpawnPacket(location, entityId, entityType, uuid, sendTo);
}
public static void equipmentSlotUpdate(
@@ -78,11 +57,13 @@ public class PacketManager extends BasePacket {
boolean empty,
List<Player> sendTo
) {
for (EquipmentSlot slot : EquipmentSlot.values()) {
HashMap<EquipmentSlot, ItemStack> items = new HashMap<>();
for (EquipmentSlot slot : HMCCInventoryUtils.getPlayerArmorSlots()) {
ItemStack item = player.getInventory().getItem(slot);
if (empty) item = new ItemStack(Material.AIR);
NMSHandlers.getHandler().equipmentSlotUpdate(player.getEntityId(), slot, item, sendTo);
items.put(slot, item);
}
equipmentSlotUpdate(player.getEntityId(), items, sendTo);
}
public static void equipmentSlotUpdate(
@NotNull Player player,
@@ -106,25 +87,22 @@ public class PacketManager extends BasePacket {
CosmeticSlot cosmeticSlot,
List<Player> sendTo
) {
if (cosmeticSlot == CosmeticSlot.BACKPACK || cosmeticSlot == CosmeticSlot.BALLOON || cosmeticSlot == CosmeticSlot.EMOTE) return;
if (cosmeticSlot == CosmeticSlot.BACKPACK || cosmeticSlot == CosmeticSlot.CUSTOM || cosmeticSlot == CosmeticSlot.BALLOON || cosmeticSlot == CosmeticSlot.EMOTE) return;
NMSHandlers.getHandler().equipmentSlotUpdate(entityId, user, cosmeticSlot, sendTo);
equipmentSlotUpdate(entityId, HMCCInventoryUtils.getEquipmentSlot(cosmeticSlot), user.getUserCosmeticItem(cosmeticSlot), sendTo);
}
public static void armorStandMetaPacket(
@NotNull Entity entity,
List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
packet.getModifier().writeDefaults();
packet.getIntegers().write(0, entity.getEntityId());
WrappedDataWatcher metadata = new WrappedDataWatcher();
if (metadata == null) return;
// 0x10 & 0x20
metadata.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)), (byte) 0x20);
metadata.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(15, WrappedDataWatcher.Registry.get(Byte.class)), (byte) 0x10);
packet.getWatchableCollectionModifier().write(0, metadata.getWatchableObjects());
for (Player p : sendTo) sendPacket(p, packet);
public static void sendItemDisplayMetadata(int entityId, ItemStack itemStack, List<Player> sendTo) {
ItemDisplayMetadata metadata = new ItemDisplayMetadata();
PacketManager.sendItemDisplayMetadataPacket(entityId, metadata.translation, metadata.scale, metadata.rotationLeft, metadata.rotationRight, metadata.billboard, 0, metadata.skyLight, metadata.viewRange, metadata.width, metadata.height, metadata.displayTransform, itemStack, sendTo);
}
public static void sendItemDisplayMetadata(int entityId, ItemDisplayMetadata metadata, List<Player> sendTo) {
PacketManager.sendItemDisplayMetadataPacket(entityId, metadata.translation, metadata.scale, metadata.rotationLeft, metadata.rotationRight, metadata.billboard, 0, metadata.skyLight, metadata.viewRange, metadata.width, metadata.height, metadata.displayTransform, metadata.itemStack, sendTo);
}
public static void sendItemDisplayMetadata(int entityId, ItemDisplayMetadata metadata, ItemStack itemStack, List<Player> sendTo) {
PacketManager.sendItemDisplayMetadataPacket(entityId, metadata.translation, metadata.scale, metadata.rotationLeft, metadata.rotationRight, metadata.billboard, 0, metadata.skyLight, metadata.viewRange, metadata.width, metadata.height, metadata.displayTransform, itemStack, sendTo);
}
public static void sendInvisibilityPacket(
@@ -134,28 +112,27 @@ public class PacketManager extends BasePacket {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
packet.getModifier().writeDefaults();
packet.getIntegers().write(0, entityId);
WrappedDataWatcher wrapper = new WrappedDataWatcher();
if (NMSHandlers.getVersion().contains("v1_18_R2") || NMSHandlers.getVersion().contains("v1_19_R1")) {
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)), (byte) 0x20);
packet.getWatchableCollectionModifier().write(0, wrapper.getWatchableObjects());
} else {
final List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();
wrappedDataValueList.add(new WrappedDataValue(0, WrappedDataWatcher.Registry.get(Byte.class), (byte) 0x20));
packet.getDataValueCollectionModifier().write(0, wrappedDataValueList);
}
final List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();
wrappedDataValueList.add(new WrappedDataValue(0, WrappedDataWatcher.Registry.get(Byte.class), (byte) 0x20));
packet.getDataValueCollectionModifier().write(0, wrappedDataValueList);
for (Player p : sendTo) sendPacket(p, packet);
}
public static void sendLookPacket(
public static void sendCloudEffect(
int entityId,
@NotNull Location location,
@NotNull List<Player> sendTo
List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_HEAD_ROTATION);
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
packet.getModifier().writeDefaults();
packet.getIntegers().write(0, entityId);
packet.getBytes().write(0, (byte) (location.getYaw() * 256.0F / 360.0F));
final List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();
wrappedDataValueList.add(new WrappedDataValue(0, WrappedDataWatcher.Registry.get(Byte.class), (byte) 0x20));
wrappedDataValueList.add(new WrappedDataValue(8, WrappedDataWatcher.Registry.get(Float.class), 0f));
//wrappedDataValueList.add(new WrappedDataValue(11, WrappedDataWatcher.Registry.get(Integer.class), 21));
packet.getDataValueCollectionModifier().write(0, wrappedDataValueList);
for (Player p : sendTo) sendPacket(p, packet);
}
@@ -218,6 +195,25 @@ public class PacketManager extends BasePacket {
sendRidingPacket(mountId, passengerId, getViewers(location));
}
/**
* Mostly to deal with backpacks, this deals with entities riding other entities.
* @param mountId The entity that is the "mount", ex. a player
* @param passengerIds The entities that are riding the mount, ex. a armorstand for a backpack
* @param sendTo Whom to send the packet to
*/
public static void sendRidingPacket(
final int mountId,
final int[] passengerIds,
final @NotNull List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.MOUNT);
packet.getIntegers().write(0, mountId);
packet.getIntegerArrays().write(0, passengerIds);
for (final Player p : sendTo) {
sendPacket(p, packet);
}
}
/**
* Mostly to deal with backpacks, this deals with entities riding other entities.
* @param mountId The entity that is the "mount", ex. a player
@@ -229,35 +225,7 @@ public class PacketManager extends BasePacket {
final int passengerId,
final @NotNull List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.MOUNT);
packet.getIntegers().write(0, mountId);
packet.getIntegerArrays().write(0, new int[]{passengerId});
for (final Player p : sendTo) {
sendPacket(p, packet);
}
}
/**
* Destroys an entity from a player
* @param entityId The entity to delete for a player
* @param sendTo The players the packet should be sent to
*/
public static void sendEntityDestroyPacket(final int entityId, @NotNull List<Player> sendTo) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
packet.getModifier().write(0, new IntArrayList(new int[]{entityId}));
for (final Player p : sendTo) sendPacket(p, packet);
}
/**
* Sends a camera packet
* @param entityId The Entity ID that camera will go towards
* @param sendTo The players that will be sent this packet
*/
public static void sendCameraPacket(final int entityId, @NotNull List<Player> sendTo) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.CAMERA);
packet.getIntegers().write(0, entityId);
for (final Player p : sendTo) sendPacket(p, packet);
MessagesUtil.sendDebugMessages(sendTo + " | " + entityId + " has had a camera packet on them!");
sendRidingPacket(mountId, new int[] {passengerId}, sendTo);
}
/**
@@ -273,13 +241,17 @@ public class PacketManager extends BasePacket {
final int entityId,
final @NotNull List<Player> sendTo
) {
WrapperPlayServerNamedEntitySpawn wrapper = new WrapperPlayServerNamedEntitySpawn();
wrapper.setEntityID(entityId);
wrapper.setPlayerUUID(uuid);
wrapper.setPosition(location.toVector());
wrapper.setPitch(location.getPitch());
wrapper.setYaw(location.getYaw());
for (final Player p : sendTo) sendPacket(p, wrapper.getHandle());
if (HMCCosmeticsAPI.getNMSVersion().contains("v1_19_R3") || HMCCosmeticsAPI.getNMSVersion().contains("v1_20_R1")) {
WrapperPlayServerNamedEntitySpawn wrapper = new WrapperPlayServerNamedEntitySpawn();
wrapper.setEntityID(entityId);
wrapper.setPlayerUUID(uuid);
wrapper.setPosition(location.toVector());
wrapper.setPitch(location.getPitch());
wrapper.setYaw(location.getYaw());
for (final Player p : sendTo) sendPacket(p, wrapper.getHandle());
return;
}
sendEntitySpawnPacket(location, entityId, EntityType.PLAYER, uuid);
}
/**
@@ -304,24 +276,15 @@ public class PacketManager extends BasePacket {
}
WrappedGameProfile wrappedGameProfile = new WrappedGameProfile(uuid, name);
WrappedSignedProperty skinData = PlayerUtils.getSkin(skinnedPlayer);
WrappedSignedProperty skinData = HMCCPlayerUtils.getSkin(skinnedPlayer);
if (skinData != null) wrappedGameProfile.getProperties().put("textures", skinData);
// For sor some reason <1.19.2 handles it on the 0 field index, newer versions handles it on the 1
if (NMSHandlers.getVersion().contains("v1_18_R2") || NMSHandlers.getVersion().contains("v1_19_R1")) {
info.getHandle().getPlayerInfoDataLists().write(0, Collections.singletonList(new PlayerInfoData(
wrappedGameProfile,
0,
EnumWrappers.NativeGameMode.CREATIVE,
WrappedChatComponent.fromText(name)
)));
} else {
info.getHandle().getPlayerInfoDataLists().write(1, Collections.singletonList(new PlayerInfoData(
wrappedGameProfile,
0,
EnumWrappers.NativeGameMode.CREATIVE,
WrappedChatComponent.fromText(name)
)));
}
info.getHandle().getPlayerInfoDataLists().write(1, Collections.singletonList(new PlayerInfoData(
wrappedGameProfile,
0,
EnumWrappers.NativeGameMode.CREATIVE,
WrappedChatComponent.fromText(name)
)));
for (final Player p : sendTo) sendPacket(p, info.getHandle());
}
@@ -349,13 +312,12 @@ public class PacketManager extends BasePacket {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
packet.getModifier().writeDefaults();
packet.getIntegers().write(0, playerId);
WrappedDataWatcher wrapper = new WrappedDataWatcher();
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(17, WrappedDataWatcher.Registry.get(Byte.class)), mask);
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(15, WrappedDataWatcher.Registry.get(Byte.class)), (byte) 0x10);
packet.getWatchableCollectionModifier().write(0, wrapper.getWatchableObjects());
for (final Player p : sendTo) {
sendPacket(p, packet);
}
final List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();
wrappedDataValueList.add(new WrappedDataValue(17, WrappedDataWatcher.Registry.get(Byte.class), mask));
packet.getDataValueCollectionModifier().write(0, wrappedDataValueList);
for (final Player p : sendTo) sendPacket(p, packet);
}
/**
@@ -364,25 +326,12 @@ public class PacketManager extends BasePacket {
* @param uuid What is the fake player UUID
* @param sendTo Whom to send the packet to
*/
@SuppressWarnings("deprecation")
public static void sendRemovePlayerPacket(
final Player player,
final UUID uuid,
final List<Player> sendTo
) {
if (NMSHandlers.getVersion().contains("v1_18_R2") || NMSHandlers.getVersion().contains("v1_19_R1")) {
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo();
info.setAction(EnumWrappers.PlayerInfoAction.REMOVE_PLAYER);
String name = "Mannequin-" + player.getEntityId();
while (name.length() > 16) {
name = name.substring(16);
}
info.setData(List.of(new PlayerInfoData(new WrappedGameProfile(uuid, player.getName()), 0, EnumWrappers.NativeGameMode.CREATIVE, WrappedChatComponent.fromText(name))));
for (final Player p : sendTo) sendPacket(p, info.getHandle());
return;
}
PacketContainer packet = new PacketContainer(PacketType.Play.Server.PLAYER_INFO_REMOVE);
packet.getUUIDLists().write(0, List.of(uuid));
for (final Player p : sendTo) sendPacket(p, packet);
@@ -396,51 +345,6 @@ public class PacketManager extends BasePacket {
sendLeashPacket(leashedEntity, entityId, getViewers(location));
}
/**
* Sends a leash packet, useful for balloons!
* @param leashedEntity Entity being leashed (ex. a horse)
* @param entityId Entity this is affecting (ex. a player)
* @param sendTo Whom to send the packet to
*/
public static void sendLeashPacket(
final int leashedEntity,
final int entityId,
final @NotNull List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ATTACH_ENTITY);
packet.getIntegers().write(0, leashedEntity);
packet.getIntegers().write(1, entityId);
for (final Player p : sendTo) {
sendPacket(p, packet);
}
}
/**
* Used when a player is sent 8+ blocks.
* @param entityId Entity this affects
* @param location Location a player is being teleported to
* @param onGround If the packet is on the ground
* @param sendTo Whom to send the packet to
*/
public static void sendTeleportPacket(
final int entityId,
final @NotNull Location location,
boolean onGround,
final @NotNull List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT);
packet.getIntegers().write(0, entityId);
packet.getDoubles().write(0, location.getX());
packet.getDoubles().write(1, location.getY());
packet.getDoubles().write(2, location.getZ());
packet.getBytes().write(0, (byte) (location.getYaw() * 256.0F / 360.0F));
packet.getBytes().write(1, (byte) (location.getPitch() * 256.0F / 360.0F));
packet.getBooleans().write(0, onGround);
for (final Player p : sendTo) {
sendPacket(p, packet);
}
}
/**
* Sends a movement packet from one location to another
* @param entityId Entity this will affect
@@ -468,23 +372,19 @@ public class PacketManager extends BasePacket {
}
}
public static void sendMovePacket(
final int entityId,
final Location from,
final Location to,
final boolean onGround
) {
sendMovePacket(entityId, from, to, onGround, getViewers(to));
}
@NotNull
public static List<Player> getViewers(Location location) {
ArrayList<Player> viewers = new ArrayList();
ArrayList<Player> viewers = new ArrayList<>();
if (Settings.getViewDistance() <= 0) {
viewers.addAll(location.getWorld().getPlayers());
} else {
viewers.addAll(PlayerUtils.getNearbyPlayers(location));
viewers.addAll(HMCCPlayerUtils.getNearbyPlayers(location));
}
return viewers;
}
public static void sendPacket(Player player, PacketContainer packet) {
if (player == null) return;
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, null,false);
}
}

View File

@@ -4,7 +4,7 @@ import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
import com.comphenix.protocol.wrappers.PlayerInfoData;
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
import com.hibiscusmc.hmccosmetics.api.HMCCosmeticsAPI;
import java.util.List;
import java.util.Set;
@@ -26,7 +26,7 @@ public class WrapperPlayServerPlayerInfo extends AbstractPacket {
}
public void setAction(PlayerInfoAction value) {
if (NMSHandlers.getVersion().contains("v1_17_R1") || NMSHandlers.getVersion().contains("v1_18_R2") || NMSHandlers.getVersion().contains("v1_19_R1")) {
if (HMCCosmeticsAPI.getNMSVersion().contains("v1_17_R1") || HMCCosmeticsAPI.getNMSVersion().contains("v1_18_R2") || HMCCosmeticsAPI.getNMSVersion().contains("v1_19_R1")) {
handle.getPlayerInfoAction().write(0, value);
return;
}

View File

@@ -6,7 +6,7 @@ config-version: 1
default-menu: defaultmenu
debug-mode: false
database-settings:
type: sqlite #MYSQL, SQLite, INTERNAL (not recommended!)
type: sqlite # SQLite (Default), MYSQL, NONE
mysql:
database: database
password: cherryBomb
@@ -24,16 +24,62 @@ cosmetic-settings:
force-permission-join: true # Checks a player permission if they can have a cosmetic when they join the server.
force-show-join: false # If the plugin should force show a player's cosmetics when they join the server.
# This is a list of worlds that cosmetics are hidden in. When a player enters one of these worlds, their cosmetics will be hidden.
disabled-worlds:
- "disabledworld"
disabled-gamemode:
enabled: true
# Which gamemodes should cosmetics be disabled for. This is useful for servers that have a creative world. All options are here, https://hub.spigotmc.org/javadocs/spigot/org/bukkit/GameMode.html
gamemodes:
- "SPECTATOR"
# This disables the entire internal emote system within the plugin. This option requires a restart.
emote-enable: true
emote-distance: -3 # This shows how far away the camera should be while a player is doing an emote. Negative is behind player.
emote-block-check: true # If the server should check if the block is open where the camera is placed (prevents players viewing through blocks)
emote-air-check: true # Check if there is air under a player, if there is, don't play emote
emote-damage-leave: true # If the player should leave the emote when they take damage
emote-invincible: false # If the player should not take damage while doing an emote
# If a player should be put into camera mode when looking at an emote. Highly recommend keeping it as true.
emote-camera: true
# If a player should be able to move in an emote. This option really only affects if "emote-camera" is false
emote-move: false
helmet-add-enchantments: false # If the plugin should keep enchants on helmets. This is useful as some enchantments are client side only.
chest-add-enchantments: false # If the plugin should keep enchants on chestplate. This is useful as some enchantments are client side only.
leggings-add-enchantments: false # If the plugin should keep enchants on leggings. This is useful as some enchantments are client side only.
boots-add-enchantments: false # If the plugin should keep enchants on boots. This is useful as some enchantments are client side only.
# This make it so it always sends the riding packets for the backpack. This sends more packets but is more reliable for servers which modify player passengers.
backpack-force-riding-packet: false
# This makes the plugin either (true) always have the backpack eminate light to avoid the black backpack bug or (false) turns it off.
backpack-light-emination: true
# This activates the block detection for the backpack. This allows backpacks to not appear completely black when in a block.
# Requires backpack-light-emination to be true.
backpack-block-detection: true
# This helps reduce the amount of packets sent for packet entities, but reduces accuracy of the entity. This is in milliseconds. -1 to disable.
# This is useful for servers with a lot of backpacks, as they are passengers, which means the client will update their position automatically within an area where the entity is located.
entity-cooldown-teleport-packet: 500
# This forces the offhand to always show the cosmetic. False means it will only show when the slot is empty.
slot-options:
helmet:
# If the plugin should keep enchants on helmets. This is useful as some enchantments are client side only.
add-enchantments: false
# Should the player slot be empty for the cosmetic to be applied? A cosmetic will be "hidden" if a player has an item equipped in the slot
require-empty: false
chestplate:
add-enchantments: false
require-empty: false
leggings:
add-enchantments: false
require-empty: false
boots:
add-enchantments: false
require-empty: false
offhand:
add-enchantments: false
# There is a small visual blip for a tick when you put a new item in the offhand slot, hence why its enabled by default.
require-empty: true
# This attempts to destroy cosmetics that get loose in the wild, such as through a player entering creative mode.
# Most servers who don't use creative mode and have properly set up the plugin should have no need for this and can leave it disabled.
@@ -43,17 +89,44 @@ cosmetic-settings:
# setting this to lower than the server player view distance should fix the
# bug where players see random backpacks. Put -1 to ignore and send packets to everyone.
view-distance: 32
# If the plugin should set the pitch of balloons to always be 0, to prevent players looking up affecting the balloon.
# This only applies to models that have a "head" section to them. THIS DOES NOT IMPACT THE REST OF THE ENTITY.
balloon-head-unmoving: false
# how the balloon should be positioned relative to the player
balloon-offset:
x: 0.5
y: 3
z: 0.5
menu-settings:
click-cooldown:
enabled: true
# This is the cooldown in miliseconds for the menu. This is useful for servers that have a lot of players.
# (So if a user clicks the menu, it won't spam the server with requesting it to refresh itself)
time: 1000
shading:
# Below is the shading mechanism behind cosmetic items. This is a bit complicated, but it allows for a lot of customization.
# The shading is done through the title and by shifting textures around. This is done by offsets.
# Only Oraxen is support by default. Vanilla can't properly handle it without a lot of unicodes and ItemsAdder adds weird offsets and decolors it. (This is why it is disabled by default)
enabled: false # Default of menus having shading. This can be toggled individually in menus with "shading: true/false"
first-row-shift: "<s:-169>" # Oraxen: "<s:-169>"
sequent-row-shift: " <s:-169>" # Oraxen: " <s:-169>" (Space is important here!)
individual-column-shift: "<s:-3>" # Oraxen: "<s:-3>"
background: "<g:shade_row_<row>:colorable> " # Oraxen: "<g:shade_row_<row>:colorable>
clear-background: "<g:clear_row_<row>:colorable> " # Oraxen: "<g:clear_row_<row>:colorable> "
#These use MiniMessage for color! https://docs.advntr.dev/minimessage/format.html#color
equipped-cosmetic-color: "<yellow>"
equipable-cosmetic-color: "<green>"
locked-cosmetic-color: "<red>"
cosmetic-type:
# This allows you to specify if it should require a special click type for the interaction to work.
equip-click: "ANY" # ANY or ClickType, https://jd.papermc.io/paper/1.20/org/bukkit/event/inventory/ClickType.html
unequip-click: "ANY" # ANY or ClickType, https://jd.papermc.io/paper/1.20/org/bukkit/event/inventory/ClickType.html
dye-menu:
# If you use ItemsAdder, set this to "§f:offset_-8::dye_menu:"
# If you use Oraxen, set this to "<glyph:neg_shift_8><glyph:dye_menu>"
title: "§f"
input-slot: 19
output-slot: 25
# If you use ItemsAdder, set this to "<white>:img_offset_-8::img_dye_menu:"
# If you use Oraxen, set this to "<white><s:-8><g:dye_menu>"
title: "<white>"
input-slot: 10
output-slot: 16
hook-settings:
itemsadder:
# This causes the plugin to reload itself after any ItemsAdder change. This keeps the plugin fully up to date with IA, but
@@ -64,8 +137,6 @@ hook-settings:
# Requires restart to apply changes.
player-move-check: true
wardrobe:
# spawn static wardrobe if in this radius of wardrobe-location
static-radius: 10
# how much yaw should change per tick, set to 0 for none
rotation-speed: 3
# Applies a pumpkin for an overlay of the player while in the wardrobe.
@@ -74,6 +145,10 @@ wardrobe:
return-last-location: false
# If players in wardrobes should be able to equip any cosmetic, regardless of permission (Cosmetics they do not have access to will be removed when they leave the wardrobe)
unchecked-wardrobe-cosmetics: false
# If HMCC should prevent a player from being damaged while being in the wardrobe
prevent-damage: true
# If a player is damaged in a wardrobe, and if it's set to true, it'll kick them from the wardrobe (prevent-damage must be false)
damage-kicked: false
menu-options:
enter-open-menu: false # If the menu should open when a player enters a wardrobe
@@ -100,6 +175,8 @@ wardrobe:
title-fade-out: 1000 # milliseconds
wardrobes:
default:
distance: -1 # Distance in blocks that a player can interact with the wardrobe. -1 to ignore.
permission: "hmccosmetics.wardrobe.default" # Permission required to use the wardrobe.
npc-location:
world: "world"
x: 0

View File

@@ -15,6 +15,11 @@ backpack:
model-data: 4
name: "<blue>Backpack"
amount: 1
firstperson-item:
material: PAPER
model-data: 8
name: "<white>Backpack"
amount: 1
future_wings:
slot: BACKPACK
permission: "hmccosmetics.future_wings"
@@ -23,6 +28,11 @@ future_wings:
model-data: 9
name: "<#d24c9f>Future Wings"
amount: 1
firstperson-item:
material: PAPER
model-data: 10
name: "<white>Future Wings"
amount: 1
lantern_cosmetic:
slot: OFFHAND
permission: "hmccosmetics.lantern_cosmetic"
@@ -55,6 +65,11 @@ jetpack:
model-data: 12
name: "<blue>Jetpack"
amount: 1
firstperson-item:
material: PAPER
model-data: 15
name: "<white>Jetpack"
amount: 1
hammer:
slot: OFFHAND
permission: "hmccosmetics.hammer"
@@ -111,6 +126,11 @@ explorer_backpack:
model-data: 3
name: "<white>Explorer's Backpack"
amount: 1
firstperson-item:
material: LEATHER_HORSE_ARMOR
model-data: 5
name: "<white>Explorer's Backpack"
amount: 1
garbage_truck_balloon:
slot: BALLOON
permission: "hmccosmetics.garbage_truck_balloon"
@@ -128,4 +148,13 @@ earth_day_grabber:
material: LEATHER_HORSE_ARMOR
model-data: 4
name: "<green>Earth Day Grabber"
amount: 1
amount: 1
hibiscus_flower:
slot: HELMET
dyeable: true
permission: "hmccosmetics.hibiscus_flower"
item:
material: PAPER
model-data: 16
name: "<#d24c9f>Hibiscus Flower"
amount: 1

View File

@@ -1,5 +1,6 @@
title: "<white>"
rows: 6
refresh-rate: 20 # Set to -1 or remove to disable auto-updating, leading to it only using event-based updates.
items:
beanie:
slots:
@@ -133,33 +134,34 @@ items:
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_kite%"
type: cosmetic
cosmetic: kite
handstand:
slots:
- 12
item:
material: PAPER
name: "<blue>Handstand Emote"
type: cosmetic
cosmetic: handstand
meditate:
slots:
- 13
item:
material: PAPER
name: "<blue>Meditate Emote"
type: cosmetic
cosmetic: meditate
thinking:
slots:
- 14
item:
material: PAPER
name: "<blue>Thinking Emote"
type: cosmetic
cosmetic: thinking
# EMOTES DO NOT WORK IN RECENT HMCCOSMETICS VERSIONS.
# handstand:
# slots:
# - 12
# item:
# material: PAPER
# name: "<blue>Handstand Emote"
# type: cosmetic
# cosmetic: handstand
# meditate:
# slots:
# - 13
# item:
# material: PAPER
# name: "<blue>Meditate Emote"
# type: cosmetic
# cosmetic: meditate
# thinking:
# slots:
# - 14
# item:
# material: PAPER
# name: "<blue>Thinking Emote"
# type: cosmetic
# cosmetic: thinking
explorer_backpack:
slots:
- 15
- 12
item:
material: hmccosmetics:explorer_backpack
lore:
@@ -170,7 +172,7 @@ items:
cosmetic: explorer_backpack
garbage_truck_balloon:
slots:
- 16
- 13
item:
material: hmccosmetics:garbage_truck_balloon
lore:
@@ -181,7 +183,7 @@ items:
cosmetic: garbage_truck_balloon
earth_day_grabber:
slots:
- 17
- 14
item:
material: hmccosmetics:earth_day_grabber
lore:
@@ -189,4 +191,15 @@ items:
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_earth_day_grabber%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_earth_day_grabber%"
type: cosmetic
cosmetic: earth_day_grabber
cosmetic: earth_day_grabber
hibiscus_flower:
slots:
- 15
item:
material: hmccosmetics:hibiscus_flower
lore:
- ""
- "<gray>Enabled: <#6D9DC5>%HMCCosmetics_equipped_hibiscus_flower%"
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_hibiscus_flower%"
type: cosmetic
cosmetic: hibiscus_flower

View File

@@ -9,6 +9,7 @@ not-enough-args: "%prefix% <red>Improper amount of arguments"
no-permission: "%prefix% <red>No Permission!"
no-cosmetic-permission: "%prefix% <red>You do not have permission for this cosmetic!"
no-cosmetic-slot: "%prefix% <red>There are no cosmetics in that slot!"
on-click-cooldown: "%prefix% <red>You are on cooldown!"
opened-wardrobe: "%prefix% <gradient:#6D9DC5:#45CDE9>Opened wardrobe!"
closed-wardrobe: "%prefix% <gradient:#6D9DC5:#45CDE9>Closed wardrobe!"

View File

@@ -1,3 +1,6 @@
user-cosmetic:
offline: "Offline"
invalid-user: "Invalid User"
unlocked-cosmetic:
true: "true"
false: "false"
@@ -10,6 +13,12 @@ in-wardrobe:
using-cosmetic:
true: "true"
false: "false"
current-cosmetic:
hidden:
true: "true"
false: "false"
current-cosmetic:
no-cosmetic: "No Cosmetic"
none: "none"
amount-cosmetic:
1: "1"
10: "10"

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