@@ -24,7 +24,7 @@ public static CompletableFuture<RequestPacks> requestPacks(Minemoji p, SpriteEmo
2424 emojiManager .customPacks .values ().parallelStream ()
2525 .map (e -> ResourcePackInfo .resourcePackInfo ()
2626 .uri (e .url )
27- .id (UUID .fromString (e .prefix ))
27+ .id (UUID .nameUUIDFromBytes (e .prefix . getBytes () ))
2828 .computeHashAndBuild ()
2929 ).collect (Collectors .toCollection (ArrayList ::new ));
3030
@@ -35,7 +35,7 @@ public static CompletableFuture<RequestPacks> requestPacks(Minemoji p, SpriteEmo
3535 futures .add (
3636 ResourcePackInfo .resourcePackInfo ()
3737 .uri (uri )
38- .id (UUID .fromString ("unicode-emojis" ))
38+ .id (UUID .nameUUIDFromBytes ("unicode-emojis" . getBytes () ))
3939 .computeHashAndBuild ()
4040 );
4141 }
@@ -47,7 +47,7 @@ public static CompletableFuture<RequestPacks> requestPacks(Minemoji p, SpriteEmo
4747 Collections .emptyList ()
4848 ));
4949 }
50- return CompletableFuture .allOf (( CompletableFuture < ResourcePackInfo >[]) futures .toArray ( ))
50+ return CompletableFuture .allOf (futures . toArray ( new CompletableFuture [ futures .size ()] ))
5151 .thenApply (_v -> new RequestPacks (
5252 p , emojiManager ,
5353 futures .stream ()
@@ -56,61 +56,68 @@ public static CompletableFuture<RequestPacks> requestPacks(Minemoji p, SpriteEmo
5656 ));
5757 }
5858
59- private final ResourcePackRequest request ;
6059 private final Minemoji p ;
60+ private final List <ResourcePackInfo > packs ;
61+ private final Component joinPrompt ;
6162 protected RequestPacks (Minemoji p , SpriteEmojiManager emojiManager , List <ResourcePackInfo > packs ) {
6263 this .p = p ;
63- Component joinPrompt ; {
64- String miniMessage = p .getConfig ().getString ("join-prompt" );
65- if (miniMessage != null && !miniMessage .isEmpty ()) {
66- MiniMessage mm = MiniMessage .miniMessage ();
67- joinPrompt = mm .deserialize (miniMessage );
68- } else {
69- joinPrompt = null ;
70- }
64+ this .packs = packs ;
65+ String miniMessage = p .getConfig ().getString ("join-prompt" );
66+ if (miniMessage != null && !miniMessage .isEmpty ()) {
67+ MiniMessage mm = MiniMessage .miniMessage ();
68+ joinPrompt = mm .deserialize (miniMessage );
69+ } else {
70+ joinPrompt = null ;
7171 }
7272
73- request = ResourcePackRequest .resourcePackRequest ()
73+
74+
75+ }
76+
77+ private final HashMap <UUID , CountDownLatch > waitingConfigurationThreads = new HashMap <>();
78+
79+ @ EventHandler
80+ public void serveEmojiPacks (AsyncPlayerConnectionConfigureEvent e ) throws InterruptedException {
81+ UUID uuid = e .getConnection ().getProfile ().getId ();
82+ // latch is put in a map so it's accessible from other events too.
83+ CountDownLatch latch = waitingConfigurationThreads
84+ .computeIfAbsent (uuid , _u -> new CountDownLatch (packs .size ()));
85+
86+ ResourcePackRequest request = ResourcePackRequest .resourcePackRequest ()
7487 .packs (packs )
7588 .replace (false )
7689 .required (p .getConfig ().getBoolean ("enforce-packs" , false ))
7790 .prompt (joinPrompt )
7891 .callback (ResourcePackCallback .onTerminal (
79- (uuid , audience ) -> { // success
80- waitingConfigurationThreads .computeIfPresent (uuid , (_uuid , latch ) -> {
81- latch .countDown ();
82- return latch ;
92+ (packUuid , audience ) -> { // success
93+ waitingConfigurationThreads .computeIfPresent (uuid , (_uuid , l ) -> {
94+ l .countDown ();
95+ return l ;
8396 });
8497 p .getLogger ().info ("Successfully sent resource packs to " + uuid .toString ());
85- }, (uuid , audience ) -> {
86- waitingConfigurationThreads .computeIfPresent (uuid , (_uuid , latch ) -> {
87- latch .countDown ();
88- return latch ;
98+ }, (packUuid , audience ) -> {
99+ waitingConfigurationThreads .computeIfPresent (uuid , (_uuid , l ) -> {
100+ l .countDown ();
101+ return l ;
89102 });
90- audience .sendMessage (Component .text ("We use resource packs to serve emojis too ! :(" ));
103+ audience .sendMessage (Component .text ("We use resource packs to serve emojis! :(" ));
91104 }
92105 )).build ();
93106
94- }
95-
96- private final HashMap <UUID , CountDownLatch > waitingConfigurationThreads = new HashMap <>();
97-
98- @ EventHandler
99- public void serveEmojiPacks (AsyncPlayerConnectionConfigureEvent e ) throws InterruptedException {
100- CountDownLatch latch = waitingConfigurationThreads
101- .computeIfAbsent (e .getConnection ().getProfile ().getId (), _u -> new CountDownLatch (1 ));
102-
103107 e .getConnection ().getAudience ().sendResourcePacks (request );
104108
105- latch .await (15L , TimeUnit .SECONDS );
109+ latch .await (30L , TimeUnit .SECONDS );
106110 //event.getConnection().getAudience()
107111 // .sendResourcePacks()
108112 }
109113
110114 public void onConnectionDrop (PlayerConnectionCloseEvent e ) {
111115 CountDownLatch latch = waitingConfigurationThreads .get (e .getPlayerUniqueId ());
112116 if (latch == null ) { return ; }
113- latch .countDown ();
117+
118+ while (latch .getCount () > 0 ) { // janky just drain the latch so we can drop this thread
119+ latch .countDown ();
120+ }
114121 p .getServer ().getScheduler ()
115122 .runTaskLaterAsynchronously (p , () -> waitingConfigurationThreads .remove (e .getPlayerUniqueId ()), 5L );
116123 }
0 commit comments