init
commit
0e21a25546
|
@ -0,0 +1,113 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>net.krakatoaapi</groupId>
|
||||
<artifactId>KrakatoaAPI</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>14</maven.compiler.source>
|
||||
<maven.compiler.target>14</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<id>make-assembly</id>
|
||||
<phase>package</phase>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>9</source>
|
||||
<target>9</target>
|
||||
</configuration>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<!--This adds the Spigot API artifact to the build -->
|
||||
<dependency>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<scope>provided</scope>
|
||||
<version>1.18-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>gson</artifactId>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<version>2.8.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>mongodb-driver-async</artifactId>
|
||||
<groupId>org.mongodb</groupId>
|
||||
<version>3.12.10</version> <!-- 3.0.4 -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>Java-WebSocket</artifactId>
|
||||
<groupId>org.java-websocket</groupId>
|
||||
<version>1.5.2</version> <!-- 1.5.1 -->
|
||||
</dependency>
|
||||
<!--<dependency>
|
||||
<artifactId>cloudnet-driver</artifactId>
|
||||
<groupId>de.dytanic.cloudnet</groupId>
|
||||
<scope>provided</scope>
|
||||
<version>3.4.0-RELEASE</version>
|
||||
</dependency>-->
|
||||
<dependency>
|
||||
<artifactId>cloudnet</artifactId>
|
||||
<groupId>de.dytanic.cloudnet</groupId>
|
||||
<scope>provided</scope>
|
||||
<version>3.4.0-RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>lombok</artifactId>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<scope>provided</scope>
|
||||
<version>1.18.22</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
<!-- This adds the Spigot Maven repository to the build -->
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<!-- https://github.com/TooTallNate/Java-WebSocket -->
|
||||
<repository>
|
||||
<id>sonatype-nexus-snapshots</id>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>cloudnet-releases</id>
|
||||
<url>https://repo.cloudnetservice.eu/repository/releases/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
</project>
|
|
@ -0,0 +1,81 @@
|
|||
package net.krakatoaapi;
|
||||
|
||||
import de.dytanic.cloudnet.driver.CloudNetDriver;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import net.krakatoaapi.config.ConfigHandler;
|
||||
import net.krakatoaapi.listener.PlayerJoinListener;
|
||||
import net.krakatoaapi.mongo.MongoManager;
|
||||
import net.krakatoaapi.protocol.KraProtocol;
|
||||
import net.krakatoaapi.socket.SocketClient;
|
||||
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 KraProtocol kraProtocol;
|
||||
private SocketClient socketClient;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
super.onEnable();
|
||||
|
||||
instance = this;
|
||||
configHandler = new ConfigHandler();
|
||||
|
||||
try {
|
||||
configHandler.load();
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
kraProtocol = new KraProtocol();
|
||||
|
||||
mongoManager = new MongoManager(configHandler.getMongodbHost(),
|
||||
configHandler.getMongodbPort(), configHandler.getMongodbUsername(),
|
||||
configHandler.getMongodbPassword());
|
||||
mongoManager.connect(configHandler.getMongodbDatabase());
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,127 @@
|
|||
package net.krakatoaapi.builder;
|
||||
|
||||
import java.util.Arrays;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
public class ItemBuilder {
|
||||
|
||||
private final ItemStack itemStack;
|
||||
|
||||
public ItemBuilder(Material mat, int amount, short type) {
|
||||
this.itemStack = new ItemStack(mat, amount, type);
|
||||
}
|
||||
|
||||
public ItemBuilder(Material mat) {
|
||||
this.itemStack = new ItemStack(mat);
|
||||
}
|
||||
|
||||
public ItemBuilder(Material material, int amount) {
|
||||
this.itemStack = new ItemStack(material, amount);
|
||||
}
|
||||
|
||||
public ItemBuilder setDisplayname(String displayname) {
|
||||
ItemMeta im = this.itemStack.getItemMeta();
|
||||
assert im != null;
|
||||
im.setDisplayName(displayname);
|
||||
this.itemStack.setItemMeta(im);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder addEnchantment(Enchantment enchantment, Integer level) {
|
||||
ItemMeta im = this.itemStack.getItemMeta();
|
||||
assert im != null;
|
||||
im.addEnchant(enchantment, level, true);
|
||||
this.itemStack.setItemMeta(im);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder addUnsafeEnchantment(Enchantment enchantment, Integer enchantmentLevel) {
|
||||
ItemMeta itemMeta = this.itemStack.getItemMeta();
|
||||
itemStack.addUnsafeEnchantment(enchantment, enchantmentLevel);
|
||||
this.itemStack.setItemMeta(itemMeta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder setColor(int red, int green, int blue) {
|
||||
LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) this.itemStack.getItemMeta();
|
||||
assert leatherArmorMeta != null;
|
||||
leatherArmorMeta.setColor(Color.fromBGR(red, green, blue));
|
||||
this.itemStack.setItemMeta(leatherArmorMeta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder setColor(Color color) {
|
||||
LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) this.itemStack.getItemMeta();
|
||||
assert leatherArmorMeta != null;
|
||||
leatherArmorMeta.setColor(color);
|
||||
this.itemStack.setItemMeta(leatherArmorMeta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder setLore(String... lore) {
|
||||
ItemMeta im = this.itemStack.getItemMeta();
|
||||
assert im != null;
|
||||
im.setLore(Arrays.asList(lore));
|
||||
itemStack.setItemMeta(im);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder addItemFlag(ItemFlag itemFlag) {
|
||||
ItemMeta im = this.itemStack.getItemMeta();
|
||||
assert im != null;
|
||||
im.addItemFlags(itemFlag);
|
||||
itemStack.setItemMeta(im);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder setUnbreakable(boolean unbreakable) {
|
||||
ItemMeta itemMeta = this.itemStack.getItemMeta();
|
||||
assert itemMeta != null;
|
||||
itemMeta.setUnbreakable(unbreakable);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder setSkullOwner(String skullOwner) {
|
||||
SkullMeta skullMeta = (SkullMeta) this.itemStack.getItemMeta();
|
||||
assert skullMeta != null;
|
||||
skullMeta.setOwner(skullOwner);
|
||||
this.itemStack.setItemMeta(skullMeta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder hideEnchantment() {
|
||||
ItemMeta itemMeta = this.itemStack.getItemMeta();
|
||||
assert itemMeta != null;
|
||||
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
this.itemStack.setItemMeta(itemMeta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder hideAttributes() {
|
||||
ItemMeta itemMeta = this.itemStack.getItemMeta();
|
||||
assert itemMeta != null;
|
||||
itemMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||
this.itemStack.setItemMeta(itemMeta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder setGlowing() {
|
||||
ItemMeta itemMeta = this.itemStack.getItemMeta();
|
||||
assert itemMeta != null;
|
||||
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
itemMeta.addEnchant(Enchantment.DURABILITY, 1, false);
|
||||
this.itemStack.setItemMeta(itemMeta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStack build() {
|
||||
return this.itemStack;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package net.krakatoaapi.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
@Getter
|
||||
public class ConfigHandler {
|
||||
|
||||
private final String defaultConfigPath = "/home/CloudNet/kraConfigs";
|
||||
|
||||
private String webSocketAccessKey;
|
||||
private String webSocketProtocol;
|
||||
private String webSocketHost;
|
||||
private int webSocketPort;
|
||||
|
||||
private String webVoiceAddress;
|
||||
|
||||
private String mongodbHost;
|
||||
private int mongodbPort;
|
||||
private String mongodbDatabase;
|
||||
private String mongodbUsername;
|
||||
private String mongodbPassword;
|
||||
|
||||
public void load() throws IOException, InvalidConfigurationException {
|
||||
File file = new File(defaultConfigPath, "kraSettings.yaml");
|
||||
|
||||
FileConfiguration fileConfiguration = new YamlConfiguration();
|
||||
|
||||
fileConfiguration.load(file);
|
||||
|
||||
webSocketAccessKey = fileConfiguration.getString("web_socket.access_key");
|
||||
webSocketProtocol = fileConfiguration.getString("web_socket.protocol");
|
||||
webSocketHost = fileConfiguration.getString("web_socket.host");
|
||||
webSocketPort = fileConfiguration.getInt("web_socket.port");
|
||||
|
||||
webVoiceAddress = fileConfiguration.getString("web.voice_address");
|
||||
|
||||
mongodbHost = fileConfiguration.getString("mongodb.host");
|
||||
mongodbPort = fileConfiguration.getInt("mongodb.port");
|
||||
mongodbDatabase = fileConfiguration.getString("mongodb.database");
|
||||
mongodbUsername = fileConfiguration.getString("mongodb.username");
|
||||
mongodbPassword = fileConfiguration.getString("mongodb.password");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package net.krakatoaapi.listener;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class PlayerJoinListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
event.setJoinMessage(null);
|
||||
|
||||
// TODO: server != lobby -> send player to last location
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package net.krakatoaapi.mongo;
|
||||
|
||||
import com.mongodb.async.client.MongoClient;
|
||||
import com.mongodb.async.client.MongoClients;
|
||||
import com.mongodb.async.client.MongoDatabase;
|
||||
import lombok.Getter;
|
||||
|
||||
public class MongoManager {
|
||||
|
||||
private final String hostname;
|
||||
private final int port;
|
||||
private final String username;
|
||||
private final String password;
|
||||
|
||||
@Getter
|
||||
private MongoDatabase mongoDatabase;
|
||||
@Getter
|
||||
private MongoClient mongoClient;
|
||||
//@Getter
|
||||
//private MongoCollection<Document> players;
|
||||
|
||||
public MongoManager(String hostname, int port, String username, String password) {
|
||||
this.hostname = hostname;
|
||||
this.port = port;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public void connect(String database) {
|
||||
mongoClient = MongoClients.create(
|
||||
"mongodb://" + username + ":" + password + "@" + hostname + ":" + port + "/?authSource="
|
||||
+ database);
|
||||
|
||||
mongoDatabase = mongoClient.getDatabase(database);
|
||||
//players = mongoDatabase.getCollection("players");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
package net.krakatoaapi.protocol;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import net.krakatoaapi.KrakatoaAPI;
|
||||
|
||||
public class KraProtocol {
|
||||
|
||||
public void SendMessage(KraProtocolMessage kraProtocolMessage) {
|
||||
SendMessage(kraProtocolMessage.getStatus(), kraProtocolMessage.getCmdID(),
|
||||
kraProtocolMessage.getDest(), kraProtocolMessage.getUuid(),
|
||||
kraProtocolMessage.getCmdNumber(), kraProtocolMessage.getArgs());
|
||||
}
|
||||
|
||||
public void SendMessage(int status, int cmdID, int dest, String uuid, int cmdNumber,
|
||||
String args) {
|
||||
System.out.println("sendMessage: " + status + " " + cmdID + " " + dest + " " + cmdNumber);
|
||||
|
||||
int argLen = args.length();
|
||||
|
||||
byte[] raw = new byte[40 + argLen];
|
||||
|
||||
raw[0] = (byte) status;
|
||||
|
||||
raw[1] = (byte) cmdID;
|
||||
raw[2] = (byte) (cmdID >> 8);
|
||||
raw[3] = (byte) (cmdID >> 16);
|
||||
raw[4] = (byte) (cmdID >> 24);
|
||||
|
||||
raw[5] = (byte) dest;
|
||||
|
||||
byte[] uuidBytes = uuid.getBytes();
|
||||
|
||||
/* for (int i = 0; i < 32; i++) {
|
||||
raw[6 + i] = uuidBytes[i];
|
||||
}*/
|
||||
|
||||
System.arraycopy(uuidBytes, 0, raw, 6, 32);
|
||||
|
||||
raw[38] = (byte) cmdNumber;
|
||||
raw[39] = (byte) (cmdNumber >> 8);
|
||||
|
||||
if (argLen > 0) {
|
||||
for (int i = 0; i < argLen; i++) {
|
||||
raw[40 + i] = (byte) args.charAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("raw: " + Arrays.toString(raw));
|
||||
|
||||
KrakatoaAPI.getInstance().getSocketClient().SendMessage(raw);
|
||||
}
|
||||
|
||||
public KraProtocolMessage DecodeMessage(byte[] data) {
|
||||
System.out.println("start decode");
|
||||
|
||||
byte status = data[0];
|
||||
|
||||
int cmdID = Byte.toUnsignedInt(data[1]);
|
||||
|
||||
cmdID += Byte.toUnsignedInt(data[2]) * 256;
|
||||
cmdID += Byte.toUnsignedInt(data[3]) * 256 * 256;
|
||||
cmdID += Byte.toUnsignedInt(data[4]) * 256 * 256 * 256;
|
||||
|
||||
int dest = Byte.toUnsignedInt(data[5]);
|
||||
|
||||
byte[] playerUuidBytes = new byte[32];
|
||||
|
||||
System.arraycopy(data, 6, playerUuidBytes, 0, 32);
|
||||
|
||||
/* for (int i = 0; i < 32; i++) {
|
||||
playerUuidBytes[i] = data[6 + i];
|
||||
} */
|
||||
|
||||
String playerUuid = new String(playerUuidBytes, StandardCharsets.UTF_8);
|
||||
|
||||
short cmdNumber = (short) (Byte.toUnsignedInt(data[38]) + (Byte.toUnsignedInt(data[39]) * 256));
|
||||
|
||||
int argLen = data.length - 40;
|
||||
byte[] argsBytes = new byte[argLen];
|
||||
|
||||
/* for (int i = 0; i < argLen; i++) {
|
||||
argsBytes[i] = data[40 + i];
|
||||
} */
|
||||
|
||||
System.arraycopy(data, 40, argsBytes, 0, argLen);
|
||||
|
||||
String args = new String(argsBytes, StandardCharsets.UTF_8);
|
||||
|
||||
System.out.println(
|
||||
"decoded message " + status + " " + cmdID + " " + dest + " " + playerUuid + " "
|
||||
+ cmdNumber + " " + args + " ");
|
||||
|
||||
return new KraProtocolMessage(status, cmdID, dest, playerUuid, cmdNumber, args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package net.krakatoaapi.protocol;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public class KraProtocolMessage {
|
||||
|
||||
private final byte status;
|
||||
private final int cmdID; // long
|
||||
private final int dest;
|
||||
private final String uuid;
|
||||
private final short cmdNumber;
|
||||
private final String args;
|
||||
|
||||
public int getStatus() {
|
||||
return Byte.toUnsignedInt(status);
|
||||
}
|
||||
|
||||
public int getCmdNumber() {
|
||||
return Short.toUnsignedInt(cmdNumber);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package net.krakatoaapi.socket;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import net.krakatoaapi.KrakatoaAPI;
|
||||
import net.krakatoaapi.protocol.KraProtocolMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.java_websocket.client.WebSocketClient;
|
||||
import org.java_websocket.handshake.ServerHandshake;
|
||||
|
||||
public class SocketClient extends WebSocketClient {
|
||||
|
||||
public SocketClient(URI uri) {
|
||||
super(uri);
|
||||
}
|
||||
|
||||
public void SendMessage(byte[] message) {
|
||||
if (isOpen()) {
|
||||
send(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(ServerHandshake serverHandshake) {
|
||||
System.out.println("Opened connection!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(String s) {
|
||||
System.out.println("recv s: " + s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(ByteBuffer byteBuffer) {
|
||||
System.out.println("recv b: " + Arrays.toString(byteBuffer.array()));
|
||||
|
||||
KraProtocolMessage kraProtocolMessage = KrakatoaAPI.getInstance().getKraProtocol()
|
||||
.DecodeMessage(byteBuffer.array());
|
||||
|
||||
Bukkit.getScheduler().runTask(KrakatoaAPI.getInstance(),
|
||||
() -> Bukkit.getServer().getPluginManager()
|
||||
.callEvent(new SocketMessageEvent(kraProtocolMessage.getStatus(),
|
||||
kraProtocolMessage.getCmdID(), kraProtocolMessage.getDest(),
|
||||
kraProtocolMessage.getUuid(), kraProtocolMessage.getCmdNumber(),
|
||||
kraProtocolMessage.getArgs())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(int code, String reason, boolean remote) {
|
||||
System.out.println(
|
||||
"Connection! closed by " + (remote ? "remote peer" : "us") + " Code: " + code + " Reason: "
|
||||
+ reason);
|
||||
|
||||
/* 1 called on plugin disable */
|
||||
if (code != 1) {
|
||||
Bukkit.getScheduler().runTaskLater(KrakatoaAPI.getInstance(), () -> {
|
||||
System.out.println("try reconnect");
|
||||
reconnect();
|
||||
}, 20L * 3L);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception e) {
|
||||
System.out.println("Error: " + e);
|
||||
//e.printStackTrace();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package net.krakatoaapi.socket;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public class SocketMessageEvent extends Event {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
@Setter
|
||||
private boolean cancelled;
|
||||
|
||||
private final int status;
|
||||
private final int cmdID;
|
||||
private final int dest;
|
||||
private final String uuid;
|
||||
private final int commandNumber;
|
||||
private final String args;
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
name: KrakatoaAPI
|
||||
version: 1.0
|
||||
author: AlexanderRoese
|
||||
main: net.krakatoaapi.KrakatoaAPI
|
||||
api-version: '1.17'
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,5 @@
|
|||
name: KrakatoaAPI
|
||||
version: 1.0
|
||||
author: AlexanderRoese
|
||||
main: net.krakatoaapi.KrakatoaAPI
|
||||
api-version: '1.17'
|
|
@ -0,0 +1,5 @@
|
|||
#Generated by Maven
|
||||
#Sat Oct 16 15:56:37 CEST 2021
|
||||
groupId=net.krakatoaapi
|
||||
artifactId=KrakatoaAPI
|
||||
version=1.0-SNAPSHOT
|
|
@ -0,0 +1,9 @@
|
|||
net/krakatoaapi/listener/PlayerJoinListener.class
|
||||
net/krakatoaapi/mongo/MongoManager.class
|
||||
net/krakatoaapi/protocol/KraProtocolMessage.class
|
||||
net/krakatoaapi/socket/SocketClient.class
|
||||
net/krakatoaapi/builder/ItemBuilder.class
|
||||
net/krakatoaapi/KrakatoaAPI.class
|
||||
net/krakatoaapi/config/ConfigHandler.class
|
||||
net/krakatoaapi/socket/SocketMessageEvent.class
|
||||
net/krakatoaapi/protocol/KraProtocol.class
|
|
@ -0,0 +1,9 @@
|
|||
/home/alex/IdeaProjects/KrakatoaAPI/src/main/java/net/krakatoaapi/listener/PlayerJoinListener.java
|
||||
/home/alex/IdeaProjects/KrakatoaAPI/src/main/java/net/krakatoaapi/socket/SocketMessageEvent.java
|
||||
/home/alex/IdeaProjects/KrakatoaAPI/src/main/java/net/krakatoaapi/builder/ItemBuilder.java
|
||||
/home/alex/IdeaProjects/KrakatoaAPI/src/main/java/net/krakatoaapi/protocol/KraProtocol.java
|
||||
/home/alex/IdeaProjects/KrakatoaAPI/src/main/java/net/krakatoaapi/KrakatoaAPI.java
|
||||
/home/alex/IdeaProjects/KrakatoaAPI/src/main/java/net/krakatoaapi/mongo/MongoManager.java
|
||||
/home/alex/IdeaProjects/KrakatoaAPI/src/main/java/net/krakatoaapi/socket/SocketClient.java
|
||||
/home/alex/IdeaProjects/KrakatoaAPI/src/main/java/net/krakatoaapi/config/ConfigHandler.java
|
||||
/home/alex/IdeaProjects/KrakatoaAPI/src/main/java/net/krakatoaapi/protocol/KraProtocolMessage.java
|
Loading…
Reference in New Issue