19
19
20
20
import java .util .ArrayList ;
21
21
import java .util .List ;
22
+ import java .util .concurrent .Callable ;
22
23
import java .util .concurrent .Future ;
24
+ import java .util .concurrent .TimeUnit ;
23
25
24
26
@ SideOnly (Side .CLIENT )
25
27
public class ClientProxy extends CommonProxy {
@@ -34,33 +36,46 @@ public void preInit(FMLPreInitializationEvent e) {
34
36
@ Override
35
37
public void postInit (FMLPostInitializationEvent e ) {
36
38
super .postInit (e );
37
- chatFuture = Async .asyncWorker .submit (() -> {
38
- val updates = updatesFuture .get ();
39
- if (updates == null || updates .size () == 0 ) return null ;
40
- val updateText = new ArrayList <IChatComponent >(FormattedText .parse (I18n .format ("falsepatternlib.chat.updatesavailable" )).toChatText ());
41
- val mods = Loader .instance ().getIndexedModList ();
42
- for (val update : updates ) {
43
- val mod = mods .get (update .modID );
44
- updateText .addAll (FormattedText .parse (I18n .format ("falsepatternlib.chat.modname" , mod .getName ())).toChatText ());
45
- updateText .addAll (FormattedText .parse (I18n .format ("falsepatternlib.chat.currentversion" , update .currentVersion )).toChatText ());
46
- updateText .addAll (FormattedText .parse (I18n .format ("falsepatternlib.chat.latestversion" , update .latestVersion )).toChatText ());
47
- if (!update .updateURL .isEmpty ()) {
48
- val pre = FormattedText .parse (I18n .format ("falsepatternlib.chat.updateurlpre" )).toChatText ();
49
- val link = FormattedText .parse (I18n .format ("falsepatternlib.chat.updateurl" )).toChatText ();
50
- val post = FormattedText .parse (I18n .format ("falsepatternlib.chat.updateurlpost" )).toChatText ();
51
- pre .get (pre .size () - 1 ).appendSibling (link .get (0 ));
52
- link .get (link .size () - 1 ).appendSibling (post .get (0 ));
53
- for (val l : link ) {
54
- l .getChatStyle ().setChatClickEvent (new ClickEvent (ClickEvent .Action .OPEN_URL , update .updateURL ));
39
+ chatFuture = Async .asyncWorker .submit (new Callable <List <IChatComponent >>() {
40
+ @ Override
41
+ public List <IChatComponent > call () throws Exception {
42
+ //Deadlock avoidance
43
+ if (updatesFuture == null || updatesFuture .isCancelled ()) {
44
+ chatFuture = null ;
45
+ return null ;
46
+ }
47
+ if (!updatesFuture .isDone ()) {
48
+ chatFuture = Async .asyncWorker .submit (this );
49
+ return null ;
50
+ }
51
+ val updates = updatesFuture .get ();
52
+ if (updates == null || updates .size () == 0 )
53
+ return null ;
54
+ val updateText = new ArrayList <IChatComponent >(FormattedText .parse (I18n .format ("falsepatternlib.chat.updatesavailable" )).toChatText ());
55
+ val mods = Loader .instance ().getIndexedModList ();
56
+ for (val update : updates ) {
57
+ val mod = mods .get (update .modID );
58
+ updateText .addAll (FormattedText .parse (I18n .format ("falsepatternlib.chat.modname" , mod .getName ())).toChatText ());
59
+ updateText .addAll (FormattedText .parse (I18n .format ("falsepatternlib.chat.currentversion" , update .currentVersion )).toChatText ());
60
+ updateText .addAll (FormattedText .parse (I18n .format ("falsepatternlib.chat.latestversion" , update .latestVersion )).toChatText ());
61
+ if (!update .updateURL .isEmpty ()) {
62
+ val pre = FormattedText .parse (I18n .format ("falsepatternlib.chat.updateurlpre" )).toChatText ();
63
+ val link = FormattedText .parse (I18n .format ("falsepatternlib.chat.updateurl" )).toChatText ();
64
+ val post = FormattedText .parse (I18n .format ("falsepatternlib.chat.updateurlpost" )).toChatText ();
65
+ pre .get (pre .size () - 1 ).appendSibling (link .get (0 ));
66
+ link .get (link .size () - 1 ).appendSibling (post .get (0 ));
67
+ for (val l : link ) {
68
+ l .getChatStyle ().setChatClickEvent (new ClickEvent (ClickEvent .Action .OPEN_URL , update .updateURL ));
69
+ }
70
+ link .remove (0 );
71
+ post .remove (0 );
72
+ updateText .addAll (pre );
73
+ updateText .addAll (link );
74
+ updateText .addAll (post );
55
75
}
56
- link .remove (0 );
57
- post .remove (0 );
58
- updateText .addAll (pre );
59
- updateText .addAll (link );
60
- updateText .addAll (post );
61
76
}
77
+ return updateText ;
62
78
}
63
- return updateText ;
64
79
});
65
80
}
66
81
@@ -70,7 +85,7 @@ public void onSinglePlayer(EntityJoinWorldEvent e) {
70
85
!(e .entity instanceof EntityPlayerSP )) return ;
71
86
val player = (EntityPlayerSP ) e .entity ;
72
87
try {
73
- for (val line : chatFuture .get ()) {
88
+ for (val line : chatFuture .get (1 , TimeUnit . SECONDS )) {
74
89
player .addChatMessage (line );
75
90
}
76
91
chatFuture = null ;
0 commit comments