implement KraSocketClient
parent
0db831b697
commit
2592b5d3e5
|
@ -52,8 +52,6 @@ public class KrakatoaAPI extends JavaPlugin {
|
|||
this.configHandler.getWebSocketPort(), this.configHandler.getWebSocketAccessKey(),
|
||||
CloudNetDriver.getInstance().getComponentName());
|
||||
|
||||
System.out.println("load kraSocketClient " + CloudNetDriver.getInstance().getComponentName());
|
||||
|
||||
this.kraSocketClientEventInitiater = new KraSocketClientEventInitiater();
|
||||
this.kraSocketClientEventInterface = new SocketClientMessageListener();
|
||||
|
||||
|
@ -61,8 +59,6 @@ public class KrakatoaAPI extends JavaPlugin {
|
|||
this.kraSocketClient = new KraSocketClient(kraSocketClientConfig,
|
||||
this.kraSocketClientEventInterface, this.kraProtocol);
|
||||
|
||||
System.out.println("here " + this.kraSocketClient.sendTest());
|
||||
|
||||
this.kraSocketClient.getSocketClient().connect();
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -73,21 +69,6 @@ public class KrakatoaAPI extends JavaPlugin {
|
|||
this.configHandler.getMongodbPassword());
|
||||
this.mongoManager.connect(this.configHandler.getMongodbDatabase());
|
||||
|
||||
this.kraSocketClient.sendTest();
|
||||
|
||||
/*
|
||||
try {
|
||||
socketClient = new SocketClient(
|
||||
new URI(configHandler.getWebSocketProtocol() + "://" + configHandler.getWebSocketHost()
|
||||
+ ":" + configHandler.getWebSocketPort() + "/ws?t="
|
||||
+ configHandler.getWebSocketAccessKey() + "&s=" + CloudNetDriver.getInstance()
|
||||
.getComponentName()));
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
socketClient.connect(); */
|
||||
|
||||
loadListeners();
|
||||
}
|
||||
|
||||
|
@ -95,8 +76,8 @@ public class KrakatoaAPI extends JavaPlugin {
|
|||
public void onDisable() {
|
||||
super.onDisable();
|
||||
|
||||
//socketClient.getConnection().close();
|
||||
//socketClient.getConnection().closeConnection(1, "");
|
||||
this.kraSocketClient.getSocketClient().getConnection().close();
|
||||
this.kraSocketClient.getSocketClient().getConnection().closeConnection(1, "");
|
||||
|
||||
instance = null;
|
||||
}
|
||||
|
|
|
@ -2,29 +2,28 @@ package net.krakatoaapi.listener;
|
|||
|
||||
import earth.krakatao.events.KraSocketClientEventInterface;
|
||||
import earth.krakatao.protocol.KraSocketClientProtocolMessage;
|
||||
import net.krakatoaapi.KrakatoaAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.java_websocket.handshake.ServerHandshake;
|
||||
|
||||
public class SocketClientMessageListener implements KraSocketClientEventInterface {
|
||||
|
||||
@Override
|
||||
public void kraSocketClientOnMessage(
|
||||
KraSocketClientProtocolMessage kraSocketClientProtocolMessage) {
|
||||
public void onOpen(ServerHandshake serverHandshake) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kraSocketClientOnOpen(ServerHandshake serverHandshake) {
|
||||
System.out.println("OPEN");
|
||||
public void onMessage(KraSocketClientProtocolMessage kraSocketClientProtocolMessage) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kraSocketClientOnClose(int i, String s, boolean b) {
|
||||
System.out.println("ONCLOSE " + i + " " + b);
|
||||
public void onClose(int code, String reason, boolean remote) {
|
||||
if (code != 1) {
|
||||
Bukkit.getScheduler().runTaskLater(KrakatoaAPI.getInstance(), () -> {
|
||||
KrakatoaAPI.getInstance().getKraSocketClient().getSocketClient().Reconnect();
|
||||
}, 20);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void test(String s) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue