/
BungeeSupport.java
66 lines (56 loc) · 2.31 KB
/
BungeeSupport.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.denizenscript.depenizen.sponge.support.bungee;
import com.denizenscript.depenizen.common.socket.client.SocketClient;
import com.denizenscript.depenizen.sponge.Depenizen2Sponge;
import com.denizenscript.depenizen.sponge.Settings;
import java.io.IOException;
public class BungeeSupport {
private static SocketClient socketClient;
public static void startSocket() {
if (Settings.socketEnabled()) {
String ipAddress = Settings.socketIpAddress();
if (ipAddress == null) {
Depenizen2Sponge.instance.debugError("BungeeCord Socket is enabled, but no IP address is specified.");
return;
}
String password = Settings.socketPassword();
if (password == null) {
Depenizen2Sponge.instance.debugError("BungeeCord Socket is enabled, but no password is specified.");
return;
}
String name = Settings.socketName();
if (name == null) {
Depenizen2Sponge.instance.debugError("BungeeCord Socket is enabled, but no registration name is specified.");
return;
}
try {
socketClient = new SpongeSocketClient(ipAddress, Settings.socketPort(), name, password.toCharArray());
socketClient.connect();
}
catch (IOException e) {
Depenizen2Sponge.instance.debugError("BungeeCord Socket is not online.");
socketClient.attemptReconnect();
}
catch (Exception e) {
Depenizen2Sponge.instance.debugError("BungeeCord Socket failed to connect due to an exception.");
Depenizen2Sponge.instance.debugException(e);
}
}
}
public static SocketClient getSocketClient() {
return socketClient;
}
public static boolean isSocketConnected() {
return socketClient != null && socketClient.isConnected();
}
public static boolean isSocketReconnecting() {
return socketClient != null && socketClient.isReconnecting();
}
public static void attemptReconnect() {
socketClient.attemptReconnect();
}
public static void closeSocket() {
if (isSocketConnected()) {
socketClient.close("Closed.", false);
}
}
}