File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed
AdvancedCore/src/com/bencodez/advancedcore/bungeeapi/sockets Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change 22package com .bencodez .advancedcore .bungeeapi .sockets ;
33
44import java .io .DataOutputStream ;
5- import java .io .IOException ;
65import java .net .Socket ;
76
87import com .bencodez .advancedcore .api .misc .encryption .EncryptionHandler ;
@@ -43,23 +42,26 @@ public void sendMessage(boolean debug, String... msgs) {
4342 if (debug ) {
4443 System .out .println ("Socket Sending: " + ArrayUtils .makeStringList (ArrayUtils .convert (msgs )));
4544 }
46- connect ();
45+
4746 String msg = msgs [0 ];
4847 for (int i = 1 ; i < msgs .length ; i ++) {
4948 msg += "%line%" ;
5049 msg += msgs [i ];
5150 }
52- if (clientSocket == null ) {
51+
52+ connect ();
53+ if (clientSocket == null || clientSocket .isClosed ()) {
5354 System .out .println ("Failed to connect to " + host + ":" + port + " to send message: " + msg );
5455 return ;
5556 }
5657 String encrypted = encryptionHandler .encrypt (msg );
5758 try (DataOutputStream ds = new DataOutputStream (clientSocket .getOutputStream ())) {
5859 ds .writeUTF (encrypted );
59- } catch (IOException e1 ) {
60+ } catch (Exception e1 ) {
6061 e1 .printStackTrace ();
62+ } finally {
63+ stopConnection ();
6164 }
62- stopConnection ();
6365 }
6466
6567 public void sendMessage (String ... msgs ) {
@@ -70,6 +72,7 @@ public void stopConnection() {
7072 try {
7173 if (clientSocket != null ) {
7274 clientSocket .close ();
75+ clientSocket = null ;
7376 }
7477 } catch (Exception e ) {
7578 e .printStackTrace ();
You can’t perform that action at this time.
0 commit comments