Moves project to intellij structure
The project now has folders made to work under intellij. Packages are also a thing.
This commit is contained in:
parent
9e8fcc7425
commit
80a04c946a
5
.gitignore
vendored
5
.gitignore
vendored
@ -22,4 +22,7 @@
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
hs_err_pid*
|
||||
|
||||
*.xml
|
||||
*.iml
|
57
Server.java
57
Server.java
@ -1,57 +0,0 @@
|
||||
import java.util.ArrayList;
|
||||
//Contains all necessary information to create, run and manage a Minecraft server.
|
||||
public class Server {
|
||||
private static String[] ramList = {"512M", "1G", "2G", "3G", "4G", "5G", "6G", "7G", "8G", "9G", "10G", "11G", "12G", "13G", "14G", "15G", "16G"};
|
||||
private String name;
|
||||
private String path;
|
||||
private boolean enabled;
|
||||
private ArrayList<String> playerList;
|
||||
private ServerType type;
|
||||
private String serverVersion;
|
||||
private String maxRam;
|
||||
private long pid;
|
||||
|
||||
public Server(String name) {
|
||||
this.name = name;
|
||||
this.path = "";
|
||||
this.enabled = false;
|
||||
this.playerList = new ArrayList<String>();
|
||||
this.type = null;
|
||||
this.serverVersion = null;
|
||||
this.maxRam = ramList[0];
|
||||
this.pid = -1;
|
||||
}
|
||||
|
||||
public void addPlayer(String name) {
|
||||
this.playerList.add(name);
|
||||
}
|
||||
|
||||
public void removePlayer(String name) {
|
||||
for (int i = 0; i < playerList.size(); i++) {
|
||||
if (name.equals(playerList.get(i))) {
|
||||
playerList.remove(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return this.type.getName() + this.serverVersion;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public String maxRam() {
|
||||
return this.maxRam;
|
||||
}
|
||||
|
||||
public void updatePid(long pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
import serverlauncher.server.Server;
|
||||
import serverlauncher.server.ServerType;
|
||||
import serverlauncher.server.*;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.lang.Runtime;
|
||||
|
124
src/serverlauncher/serverlauncher/server/Server.java
Normal file
124
src/serverlauncher/serverlauncher/server/Server.java
Normal file
@ -0,0 +1,124 @@
|
||||
package serverlauncher.server;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.Scanner;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.nio.file.*;
|
||||
import java.util.ArrayList;
|
||||
import java.io.FileNotFoundException;
|
||||
//Contains all necessary information to create, run and manage a Minecraft server.
|
||||
public class Server {
|
||||
private final String BASEURL = "https://knarcraft.net/Api/Download/bungeeminecraftserverlauncher/jars"; //The url we download jar files from.
|
||||
private final String BUKKITURL = BASEURL + "/Bukkit/";
|
||||
private final String MCPCURL = BASEURL + "/MCPC+/";
|
||||
private final String SPIGOT = BASEURL + "/Spigot/";
|
||||
private static String[] ramList = {"512M", "1G", "2G", "3G", "4G", "5G", "6G", "7G", "8G", "9G", "10G", "11G", "12G", "13G", "14G", "15G", "16G"};
|
||||
private String name;
|
||||
private String path;
|
||||
private boolean enabled;
|
||||
private ArrayList<String> playerList;
|
||||
private serverlauncher.server.ServerType type;
|
||||
private String serverVersion;
|
||||
private String maxRam;
|
||||
private long pid;
|
||||
|
||||
public Server(String name) {
|
||||
this.name = name;
|
||||
this.path = "";
|
||||
this.enabled = false;
|
||||
this.playerList = new ArrayList<>();
|
||||
this.type = null;
|
||||
this.serverVersion = null;
|
||||
this.maxRam = ramList[0];
|
||||
this.pid = -1;
|
||||
}
|
||||
|
||||
public void addPlayer(String name) {
|
||||
this.playerList.add(name);
|
||||
}
|
||||
|
||||
public void removePlayer(String name) {
|
||||
for (int i = 0; i < playerList.size(); i++) {
|
||||
if (name.equals(playerList.get(i))) {
|
||||
playerList.remove(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return this.type.getName() + this.serverVersion + ".jar";
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public String maxRam() {
|
||||
return this.maxRam;
|
||||
}
|
||||
|
||||
public void updatePid(long pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloads necessary .jar file for the server.
|
||||
* All server versions are downloaded if missing.
|
||||
* Newest server versions (snapshot, vanilla and bungee) need to be checked against an online json file and downloaded if outdated.
|
||||
* Custom files must exist, or trigger a message.
|
||||
*/
|
||||
public void downloadJar() throws FileNotFoundException {
|
||||
if (!new File(this.path + "\\" + this.type.getName() + this.serverVersion).isFile()) {
|
||||
//TODO: Download a jar file based on version and type. Return true if the file was downloaded and ready to run.
|
||||
throw new FileNotFoundException("");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the first line of a file from a website.
|
||||
* This is used to find the newest version of the software.
|
||||
*
|
||||
* @param path The full url of the file to read.
|
||||
* @return True if successfull. False otherwise.
|
||||
*/
|
||||
public static boolean readFile(String path) {
|
||||
//We might need to change this to look for specific lines in the file to find vanilla and snapshot versions.
|
||||
//The version should probably be returned. Empty or null on failiure.
|
||||
try {
|
||||
URL url = new URL(path);
|
||||
Scanner s = new Scanner(url.openStream());
|
||||
System.out.println(s.next());
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloads a file from a website.
|
||||
*
|
||||
* @param path The full url of the file to download.
|
||||
* @param outfile The file to save to.
|
||||
* @return True if successful. False otherwise.
|
||||
*/
|
||||
public static boolean downloadFile(String path, Path outfile) {
|
||||
try {
|
||||
URL url = new URL("https://knarcraft.net/Api/View/Jawns/Jawns%20instructions.txt");
|
||||
InputStream in = url.openStream();
|
||||
Files.copy(in, outfile, StandardCopyOption.REPLACE_EXISTING);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
package serverlauncher.server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
/**
|
||||
* Has a name and contains a list of valid server versions.
|
Loading…
Reference in New Issue
Block a user