de.epsdev.bungeeautoserver.api.EPS_API Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bungeeautoserver.api Show documentation
Show all versions of bungeeautoserver.api Show documentation
A tool used for automating bungeecord-networks.
The newest version!
package de.epsdev.bungeeautoserver.api;
import de.epsdev.bungeeautoserver.api.enums.OperationType;
import de.epsdev.bungeeautoserver.api.exeptions.NoPortDefinedException;
import de.epsdev.bungeeautoserver.api.exeptions.NoRemoteAddressException;
import de.epsdev.bungeeautoserver.api.interfaces.SyncEmitter;
import de.epsdev.bungeeautoserver.api.packages.*;
import de.epsdev.packages.Connection;
import de.epsdev.packages.Server;
import de.epsdev.packages.packages.Package;
import java.io.File;
import java.net.Socket;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class EPS_API {
public static final String PREFIX = "[Auto Bungee] ";
private final String LOGO = "\n _______ ______ \n" +
"(_______) _ / _____) \n" +
" _______ _ _ _| |_ ___( (____ _____ ____ _ _ _____ ____ \n" +
"| ___ | | | (_ _) _ \\\\____ \\| ___ |/ ___) | | | ___ |/ ___)\n" +
"| | | | |_| | | || |_| |____) ) ____| | \\ V /| ____| | \n" +
"|_| |_|____/ \\__)___(______/|_____)_| \\_/ |_____)_| \n\n";
public static String NAME = "iAmADefault";
public static String DEFAULT_SERVER = "Hub";
private final OperationType operationType;
private String remoteAddress;
public Server server;
public Connection connection;
private int port = -1;
private int max_players = 2;
public static String type = "Hub";
public static String ftpServerAddress = "";
public static int ftpServerPort = 0;
public static String ftpServerUser = "";
public static String ftpServerPassword = "";
public static String backupChannelName = "";
public static boolean backUpOutOfSync = false;
public static SyncEmitter syncEmitter = (f, content) -> {};
public static List sockets = new ArrayList<>();
public static HashMap> serverInfo = new HashMap<>();
public static String key = "";
public EPS_API(OperationType operationType){
this.operationType = operationType;
}
public void setRemoteAddress(String remoteAddress){
this.remoteAddress = remoteAddress;
}
public void setPort(int port){
this.port = port;
}
public void setMax_players(int max_players){
this.max_players = max_players;
}
public void setType(String type){
this.type = type;
}
public void init(){
System.out.print(LOGO);
Package.registerPackage("RequestRegisterServerPackage", RequestRegisterServerPackage.class);
Package.registerPackage("RequestChangePlayerServerPackage", RequestChangePlayerServerPackage.class);
Package.registerPackage("RequestServerStatusPackage", RequestServerStatusPackage.class);
Package.registerPackage("RequestServerAvailabilityChangePackage", RequestServerAvailabilityChangePackage.class);
Package.registerPackage("RequestBroadcastPackage", RequestBroadcastPackage.class);
Package.registerPackage("RequestBanPackage", RequestBanPackage.class);
Package.registerPackage("RequestUnbanPackage", RequestUnbanPackage.class);
Package.registerPackage("RequestSaveBroadcastPackage", RequestSaveBroadcastPackage.class);
Package.registerPackage("RespondRegisterPackage", RespondRegisterPackage.class);
Package.registerPackage("RespondServerStatusPackage", RespondServerStatusPackage.class);
Package.registerPackage("AnnounceBroadcastPackage", AnnounceBroadcastPackage.class);
Package.registerPackage("AnnounceRestartPackage", AnnounceRestartPackage.class);
Package.registerPackage("AnnounceSavePackage", AnnounceSavePackage.class);
if(this.operationType == OperationType.SERVER){
if(key.equals("")){
System.out.println("------------------------------------------------------------");
System.out.println("| WARNING |");
System.out.println("| |");
System.out.println("|No key used. NOT save to use in an production environment.|");
System.out.println("| |");
System.out.println("| |");
System.out.println("------------------------------------------------------------");
}
this.server = new Server(10101, 512, true);
this.server.start();
}else if(this.operationType == OperationType.CLIENT){
try {
if(this.remoteAddress.equals("")){
throw new NoRemoteAddressException();
}
if(this.port == -1){
throw new NoPortDefinedException();
}
this.connection = new Connection(remoteAddress, 10101);
this.connection.start();
this.connection.send(new RequestRegisterServerPackage(this.port, EPS_API.type, this.max_players));
} catch (NoRemoteAddressException | NoPortDefinedException e) {
e.printStackTrace();
}
}
}
public void disable(){
connection.close();
}
}