111 lines
3.6 KiB
Java
111 lines
3.6 KiB
Java
package net.krakatoaapi;
|
|
|
|
import de.dytanic.cloudnet.driver.CloudNetDriver;
|
|
import earth.krakatao.KraSocketClient;
|
|
import earth.krakatao.KraSocketClientConfig;
|
|
import earth.krakatao.events.KraSocketClientEventInitiater;
|
|
import earth.krakatao.events.KraSocketClientEventInterface;
|
|
import earth.krakatao.protocol.KraSocketClientProtocol;
|
|
import java.io.IOException;
|
|
import java.net.URISyntaxException;
|
|
import java.util.List;
|
|
import lombok.Getter;
|
|
import net.krakatoaapi.config.ConfigHandler;
|
|
import net.krakatoaapi.listener.PlayerJoinListener;
|
|
import net.krakatoaapi.listener.SocketClientMessageListener;
|
|
import net.krakatoaapi.mongo.MongoManager;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.configuration.InvalidConfigurationException;
|
|
import org.bukkit.plugin.PluginManager;
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
@Getter
|
|
public class KrakatoaAPI extends JavaPlugin {
|
|
|
|
@Getter
|
|
private static KrakatoaAPI instance;
|
|
|
|
private ConfigHandler configHandler;
|
|
private MongoManager mongoManager;
|
|
private KraSocketClientProtocol kraProtocol;
|
|
private KraSocketClient kraSocketClient;
|
|
private KraSocketClientEventInitiater kraSocketClientEventInitiater;
|
|
private KraSocketClientEventInterface kraSocketClientEventInterface;
|
|
|
|
@Override
|
|
public void onEnable() {
|
|
super.onEnable();
|
|
|
|
instance = this;
|
|
this.configHandler = new ConfigHandler();
|
|
|
|
try {
|
|
this.configHandler.load();
|
|
} catch (IOException | InvalidConfigurationException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
this.kraProtocol = new KraSocketClientProtocol();
|
|
|
|
KraSocketClientConfig kraSocketClientConfig = new KraSocketClientConfig(
|
|
this.configHandler.getWebSocketProtocol(), this.configHandler.getWebSocketHost(),
|
|
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();
|
|
|
|
try {
|
|
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();
|
|
}
|
|
|
|
this.mongoManager = new MongoManager(this.configHandler.getMongodbHost(),
|
|
this.configHandler.getMongodbPort(), this.configHandler.getMongodbUsername(),
|
|
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();
|
|
}
|
|
|
|
@Override
|
|
public void onDisable() {
|
|
super.onDisable();
|
|
|
|
//socketClient.getConnection().close();
|
|
//socketClient.getConnection().closeConnection(1, "");
|
|
|
|
instance = null;
|
|
}
|
|
|
|
public void loadListeners() {
|
|
PluginManager pluginManager = Bukkit.getPluginManager();
|
|
List.of(new PlayerJoinListener()).forEach(listener -> {
|
|
pluginManager.registerEvents(listener, this);
|
|
});
|
|
}
|
|
}
|