mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-25 11:46:50 +01:00
SubServers Release v2.11.2c
This commit is contained in:
parent
d60d6640b5
commit
ae0ce737f9
Binary file not shown.
Binary file not shown.
@ -384,6 +384,8 @@ public class InternalSubCreator extends SubCreator {
|
|||||||
config.get().getSection("Settings").getSection("SubData").set("Address", host.plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Address"));
|
config.get().getSection("Settings").getSection("SubData").set("Address", host.plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Address"));
|
||||||
config.get().getSection("Settings").getSection("SubData").set("Password", host.plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"));
|
config.get().getSection("Settings").getSection("SubData").set("Password", host.plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"));
|
||||||
config.save();
|
config.save();
|
||||||
|
System.out.println(host.getName() + "/Creator > Copying Plugins...");
|
||||||
|
copyFolder(new UniversalFile(host.plugin.dir, "SubServers:Plugin Templates:Spigot Plugins"), new UniversalFile(dir, "plugins"));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -401,6 +403,8 @@ public class InternalSubCreator extends SubCreator {
|
|||||||
try {
|
try {
|
||||||
exec = new Executable("java -Xmx" + memory + "M -jar Forge.jar");
|
exec = new Executable("java -Xmx" + memory + "M -jar Forge.jar");
|
||||||
|
|
||||||
|
new UniversalFile(dir, "config").mkdirs();
|
||||||
|
new UniversalFile(dir, "mods").mkdirs();
|
||||||
GenerateEULA(dir);
|
GenerateEULA(dir);
|
||||||
GenerateProperties(dir, port);
|
GenerateProperties(dir, port);
|
||||||
GenerateSpongeConf(dir);
|
GenerateSpongeConf(dir);
|
||||||
@ -420,7 +424,7 @@ public class InternalSubCreator extends SubCreator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (spversion == null) throw new InvalidServerException("Cannot find sponge version for Minecraft " + version.toString());
|
if (spversion == null) throw new InvalidServerException("Cannot find sponge version for Minecraft " + version.toString());
|
||||||
System.out.println(host.getName() + "/Creator > Found spongeforge-" + spversion.toString());
|
System.out.println(host.getName() + "/Creator > Found \"spongeforge-" + spversion.toString() + '"');
|
||||||
|
|
||||||
NodeList mcfnodeList = forgexml.getElementsByTagName("version");
|
NodeList mcfnodeList = forgexml.getElementsByTagName("version");
|
||||||
Version mcfversion = null;
|
Version mcfversion = null;
|
||||||
@ -433,9 +437,13 @@ public class InternalSubCreator extends SubCreator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mcfversion == null) throw new InvalidServerException("Cannot find forge version for Sponge " + spversion.toString());
|
if (mcfversion == null) throw new InvalidServerException("Cannot find forge version for Sponge " + spversion.toString());
|
||||||
System.out.println(host.getName() + "/Creator > Found forge-" + mcfversion.toString());
|
System.out.println(host.getName() + "/Creator > Found \"forge-" + mcfversion.toString() + '"');
|
||||||
|
|
||||||
version = new Version(mcfversion.toString() + "::" + spversion.toString());
|
version = new Version(mcfversion.toString() + "::" + spversion.toString());
|
||||||
|
|
||||||
|
System.out.println(host.getName() + "/Creator > Copying Mods...");
|
||||||
|
copyFolder(new UniversalFile(host.plugin.dir, "SubServers:Plugin Templates:Sponge Config"), new UniversalFile(dir, "config"));
|
||||||
|
copyFolder(new UniversalFile(host.plugin.dir, "SubServers:Plugin Templates:Sponge Mods"), new UniversalFile(dir, "mods"));
|
||||||
} catch (ParserConfigurationException | IOException | SAXException | NullPointerException e) {
|
} catch (ParserConfigurationException | IOException | SAXException | NullPointerException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -563,4 +571,48 @@ public class InternalSubCreator extends SubCreator {
|
|||||||
public boolean isBusy() {
|
public boolean isBusy() {
|
||||||
return thread != null && thread.isAlive();
|
return thread != null && thread.isAlive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void copyFolder(File source, File destination) {
|
||||||
|
if (source.isDirectory()) {
|
||||||
|
if (!destination.exists()) {
|
||||||
|
destination.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
String files[] = source.list();
|
||||||
|
|
||||||
|
for (String file : files) {
|
||||||
|
File srcFile = new File(source, file);
|
||||||
|
File destFile = new File(destination, file);
|
||||||
|
|
||||||
|
copyFolder(srcFile, destFile);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
InputStream in = null;
|
||||||
|
OutputStream out = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
in = new FileInputStream(source);
|
||||||
|
out = new FileOutputStream(destination);
|
||||||
|
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
|
||||||
|
int length;
|
||||||
|
while ((length = in.read(buffer)) > 0) {
|
||||||
|
out.write(buffer, 0, length);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
try {
|
||||||
|
in.close();
|
||||||
|
} catch (IOException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
out.close();
|
||||||
|
} catch (IOException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,15 +42,16 @@ public class InternalSubLogger {
|
|||||||
String msg = line;
|
String msg = line;
|
||||||
// REGEX Formatting
|
// REGEX Formatting
|
||||||
String type = "INFO";
|
String type = "INFO";
|
||||||
Matcher matcher = Pattern.compile("^((?:\\s*\\[?[0-9]{2}:[0-9]{2}:[0-9]{2}]?)?\\s*(?:\\[|\\[.*\\/)?(INFO|WARN|WARNING|ERROR|ERR|SEVERE)\\]:?\\s*)").matcher(msg);
|
Matcher matcher = Pattern.compile("^((?:\\s*\\[?([0-9]{2}:[0-9]{2}:[0-9]{2})]?)?[\\s\\/\\\\\\|]*(?:\\[|\\[.*\\/)?(MESSAGE|INFO|WARN|WARNING|ERROR|ERR|SEVERE)\\]?:?\\s*)").matcher(msg);
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
type = matcher.group(2);
|
type = matcher.group(3).toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
msg = msg.replaceAll("^((?:\\s*\\[?[0-9]{2}:[0-9]{2}:[0-9]{2}]?)?\\s*(?:\\[|\\[.*\\/)?(INFO|WARN|WARNING|ERROR|ERR|SEVERE)\\]:?\\s*)", "");
|
msg = msg.replaceAll("^((?:\\s*\\[?([0-9]{2}:[0-9]{2}:[0-9]{2})]?)?[\\s\\/\\\\\\|]*(?:\\[|\\[.*\\/)?(MESSAGE|INFO|WARN|WARNING|ERROR|ERR|SEVERE)\\]?:?\\s*)", "");
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "INFO":
|
case "INFO":
|
||||||
|
case "MESSAGE":
|
||||||
ProxyServer.getInstance().getLogger().info(name + " > " + msg);
|
ProxyServer.getInstance().getLogger().info(name + " > " + msg);
|
||||||
break;
|
break;
|
||||||
case "WARNING":
|
case "WARNING":
|
||||||
@ -70,8 +71,7 @@ public class InternalSubLogger {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException ioe) {
|
} catch (IOException e) {} finally {
|
||||||
} finally {
|
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
@ -83,8 +83,30 @@ public class InternalSubLogger {
|
|||||||
if (!line.startsWith(">")) {
|
if (!line.startsWith(">")) {
|
||||||
if (log.get()) {
|
if (log.get()) {
|
||||||
String msg = line;
|
String msg = line;
|
||||||
msg = msg.replaceAll("^((?:\\s*\\[?[0-9]{2}:[0-9]{2}:[0-9]{2}]?)?\\s*(?:\\[|\\[.*\\/)?(INFO|WARN|WARNING|ERROR|ERR|SEVERE)\\]:?\\s*)", "");
|
// REGEX Formatting
|
||||||
ProxyServer.getInstance().getLogger().severe(name + " > " + msg);
|
String type = "INFO";
|
||||||
|
Matcher matcher = Pattern.compile("^((?:\\s*\\[?([0-9]{2}:[0-9]{2}:[0-9]{2})]?)?[\\s\\/\\\\\\|]*(?:\\[|\\[.*\\/)?(MESSAGE|INFO|WARN|WARNING|ERROR|ERR|SEVERE)\\]?:?\\s*)").matcher(msg);
|
||||||
|
while (matcher.find()) {
|
||||||
|
type = matcher.group(3).toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
msg = msg.replaceAll("^((?:\\s*\\[?([0-9]{2}:[0-9]{2}:[0-9]{2})]?)?[\\s\\/\\\\\\|]*(?:\\[|\\[.*\\/)?(MESSAGE|INFO|WARN|WARNING|ERROR|ERR|SEVERE)\\]?:?\\s*)", "");
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case "INFO":
|
||||||
|
case "MESSAGE":
|
||||||
|
ProxyServer.getInstance().getLogger().info(name + " > " + msg);
|
||||||
|
break;
|
||||||
|
case "WARNING":
|
||||||
|
case "WARN":
|
||||||
|
ProxyServer.getInstance().getLogger().warning(name + " > " + msg);
|
||||||
|
break;
|
||||||
|
case "SEVERE":
|
||||||
|
case "ERROR":
|
||||||
|
case "ERR":
|
||||||
|
ProxyServer.getInstance().getLogger().severe(name + " > " + msg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (writer != null) {
|
if (writer != null) {
|
||||||
writer.println(line);
|
writer.println(line);
|
||||||
@ -92,8 +114,7 @@ public class InternalSubLogger {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException ioe) {
|
} catch (IOException e) {} finally {
|
||||||
} finally {
|
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
@ -18,6 +18,7 @@ public class InternalSubServer extends SubServer {
|
|||||||
private InternalHost host;
|
private InternalHost host;
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
private Container<Boolean> log;
|
private Container<Boolean> log;
|
||||||
|
private String dir;
|
||||||
private File directory;
|
private File directory;
|
||||||
private Executable executable;
|
private Executable executable;
|
||||||
private String stopcmd;
|
private String stopcmd;
|
||||||
@ -33,6 +34,7 @@ public class InternalSubServer extends SubServer {
|
|||||||
this.host = (InternalHost) host;
|
this.host = (InternalHost) host;
|
||||||
this.enabled = enabled;
|
this.enabled = enabled;
|
||||||
this.log = new Container<Boolean>(log);
|
this.log = new Container<Boolean>(log);
|
||||||
|
this.dir = directory;
|
||||||
this.directory = new File(host.getDirectory(), directory);
|
this.directory = new File(host.getDirectory(), directory);
|
||||||
this.executable = executable;
|
this.executable = executable;
|
||||||
this.stopcmd = stopcmd;
|
this.stopcmd = stopcmd;
|
||||||
@ -192,6 +194,11 @@ public class InternalSubServer extends SubServer {
|
|||||||
log.set(value);
|
log.set(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDirectory() {
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getStopCommand() {
|
public String getStopCommand() {
|
||||||
return stopcmd;
|
return stopcmd;
|
||||||
|
@ -13,7 +13,12 @@ public abstract class SubCreator {
|
|||||||
public enum ServerType {
|
public enum ServerType {
|
||||||
SPIGOT,
|
SPIGOT,
|
||||||
VANILLA,
|
VANILLA,
|
||||||
SPONGE,
|
SPONGE,;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString().substring(0, 1).toUpperCase()+super.toString().substring(1).toLowerCase();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -146,6 +146,14 @@ public abstract class SubServer extends Server {
|
|||||||
*/
|
*/
|
||||||
public abstract void setLogging(boolean value);
|
public abstract void setLogging(boolean value);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Server Directory
|
||||||
|
*
|
||||||
|
* @return Server Directory
|
||||||
|
*/
|
||||||
|
public abstract String getDirectory();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Grab the Command to Stop the Server
|
* Grab the Command to Stop the Server
|
||||||
*
|
*
|
||||||
|
@ -70,6 +70,10 @@ public class YAMLSection {
|
|||||||
|
|
||||||
public void remove(String label) {
|
public void remove(String label) {
|
||||||
map.remove(label);
|
map.remove(label);
|
||||||
|
|
||||||
|
if (this.label != null && this.up != null) {
|
||||||
|
this.up.set(this.label, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
|
@ -38,6 +38,20 @@ public final class Util {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void deleteDirectory(File folder) {
|
||||||
|
File[] files = folder.listFiles();
|
||||||
|
if(files!=null) {
|
||||||
|
for(File f: files) {
|
||||||
|
if(f.isDirectory()) {
|
||||||
|
deleteDirectory(f);
|
||||||
|
} else {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
folder.delete();
|
||||||
|
}
|
||||||
|
|
||||||
public static String unescapeJavaString(String str) {
|
public static String unescapeJavaString(String str) {
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder(str.length());
|
StringBuilder sb = new StringBuilder(str.length());
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package net.ME1312.SubServers.Bungee;
|
package net.ME1312.SubServers.Bungee;
|
||||||
|
|
||||||
|
import com.google.common.io.Files;
|
||||||
import net.ME1312.SubServers.Bungee.Host.Host;
|
import net.ME1312.SubServers.Bungee.Host.Host;
|
||||||
import net.ME1312.SubServers.Bungee.Host.Server;
|
import net.ME1312.SubServers.Bungee.Host.Server;
|
||||||
import net.ME1312.SubServers.Bungee.Host.SubCreator;
|
import net.ME1312.SubServers.Bungee.Host.SubCreator;
|
||||||
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
||||||
|
import net.ME1312.SubServers.Bungee.Library.UniversalFile;
|
||||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
@ -11,22 +13,25 @@ import net.md_5.bungee.api.CommandSender;
|
|||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
import net.md_5.bungee.api.chat.HoverEvent;
|
import net.md_5.bungee.api.chat.HoverEvent;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
|
import net.md_5.bungee.api.plugin.TabExecutor;
|
||||||
import net.md_5.bungee.command.ConsoleCommandSender;
|
import net.md_5.bungee.command.ConsoleCommandSender;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.io.File;
|
||||||
import java.util.LinkedList;
|
import java.io.FileReader;
|
||||||
import java.util.List;
|
import java.io.FileWriter;
|
||||||
import java.util.Map;
|
import java.io.IOException;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugin Command Class
|
* Plugin Command Class
|
||||||
*
|
*
|
||||||
* @author ME1312
|
* @author ME1312
|
||||||
*/
|
*/
|
||||||
public final class SubCommand extends Command {
|
@SuppressWarnings("deprecation")
|
||||||
|
public final class SubCommand extends Command implements TabExecutor {
|
||||||
private SubPlugin plugin;
|
private SubPlugin plugin;
|
||||||
private String label;
|
private String label;
|
||||||
|
|
||||||
@ -42,7 +47,6 @@ public final class SubCommand extends Command {
|
|||||||
* @param sender
|
* @param sender
|
||||||
* @param args
|
* @param args
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
if (sender instanceof ConsoleCommandSender) {
|
if (sender instanceof ConsoleCommandSender) {
|
||||||
@ -150,11 +154,65 @@ public final class SubCommand extends Command {
|
|||||||
} else if (args.length > 6 && (Util.isException(() -> Integer.parseInt(args[6])) || Integer.parseInt(args[6]) < 256)) {
|
} else if (args.length > 6 && (Util.isException(() -> Integer.parseInt(args[6])) || Integer.parseInt(args[6]) < 256)) {
|
||||||
sender.sendMessage("SubServers > Invalid Ram Amount");
|
sender.sendMessage("SubServers > Invalid Ram Amount");
|
||||||
} else {
|
} else {
|
||||||
plugin.hosts.get(args[2].toLowerCase()).getCreator().create(args[1], SubCreator.ServerType.valueOf(args[3].toUpperCase()), new Version(args[4]), (args.length > 6)?Integer.parseInt(args[6]):1024, Integer.parseInt(args[5]));
|
plugin.hosts.get(args[2].toLowerCase()).getCreator().create(args[1], SubCreator.ServerType.valueOf(args[3].toUpperCase()), new Version(args[4]), (args.length > 6) ? Integer.parseInt(args[6]) : 1024, Integer.parseInt(args[5]));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("SubServers > Usage: " + label + " " + args[0].toLowerCase() + " <Name> <Host> <Type> <Version> <Port> [RAM]");
|
sender.sendMessage("SubServers > Usage: " + label + " " + args[0].toLowerCase() + " <Name> <Host> <Type> <Version> <Port> [RAM]");
|
||||||
}
|
}
|
||||||
|
} else if (args[0].equalsIgnoreCase("del") || args[0].equalsIgnoreCase("delete")) {
|
||||||
|
if (args.length > 1) {
|
||||||
|
Map<String, Server> servers = plugin.api.getServers();
|
||||||
|
try {
|
||||||
|
if (!servers.keySet().contains(args[1].toLowerCase())) {
|
||||||
|
sender.sendMessage("SubServers > There is no server with that name");
|
||||||
|
} else if (!(servers.get(args[1].toLowerCase()) instanceof SubServer)) {
|
||||||
|
sender.sendMessage("SubServers > That Server is not a SubServer");
|
||||||
|
} else if (((SubServer) servers.get(args[1].toLowerCase())).isRunning()) {
|
||||||
|
sender.sendMessage("SubServers > That SubServer is still running");
|
||||||
|
} else if (!((SubServer) servers.get(args[1].toLowerCase())).getHost().removeSubServer(args[1])) {
|
||||||
|
sender.sendMessage("SubServers > Couldn't Remove SubServer");
|
||||||
|
} else {
|
||||||
|
new Thread(() -> {
|
||||||
|
UniversalFile to = new UniversalFile(plugin.dir, "SubServers:Recently Deleted:" + args[1].toLowerCase());
|
||||||
|
try {
|
||||||
|
File from = new File(((SubServer) servers.get(args[1].toLowerCase())).getHost().getDirectory(), ((SubServer) servers.get(args[1].toLowerCase())).getDirectory());
|
||||||
|
if (from.exists()) {
|
||||||
|
sender.sendMessage("SubServers > Removing Files...");
|
||||||
|
if (to.exists()) {
|
||||||
|
if (to.isDirectory()) Util.deleteDirectory(to);
|
||||||
|
else to.delete();
|
||||||
|
}
|
||||||
|
to.mkdirs();
|
||||||
|
Files.move(from, to);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
sender.sendMessage("SubServers > Saving...");
|
||||||
|
JSONObject json = (plugin.config.get().getSection("Servers").getKeys().contains(servers.get(args[1].toLowerCase()).getName()))?plugin.config.get().getSection("Servers").getSection(servers.get(args[1].toLowerCase()).getName()).toJSON():new JSONObject();
|
||||||
|
json.put("Name", servers.get(args[1].toLowerCase()).getName());
|
||||||
|
json.put("Timestamp", Calendar.getInstance().getTime().getTime());
|
||||||
|
try {
|
||||||
|
if (plugin.config.get().getSection("Servers").getKeys().contains(servers.get(args[1].toLowerCase()).getName())) {
|
||||||
|
plugin.config.get().getSection("Servers").remove(servers.get(args[1].toLowerCase()).getName());
|
||||||
|
plugin.config.save();
|
||||||
|
}
|
||||||
|
if (!to.exists()) to.mkdirs();
|
||||||
|
FileWriter writer = new FileWriter(new File(to, "info.json"));
|
||||||
|
json.write(writer);
|
||||||
|
writer.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
sender.sendMessage("SubServers > Done!");
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendMessage("SubServers > Usage: " + label + " " + args[0].toLowerCase() + " <SubServer>");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("SubServers > Unknown sub-command: " + args[0]);
|
sender.sendMessage("SubServers > Unknown sub-command: " + args[0]);
|
||||||
}
|
}
|
||||||
@ -162,13 +220,105 @@ public final class SubCommand extends Command {
|
|||||||
sender.sendMessages(printHelp());
|
sender.sendMessages(printHelp());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String str = "";
|
String str = label;
|
||||||
int i = -1;
|
for (String arg : args) str += ' ' + arg;
|
||||||
while ((i + 1) != args.length) {
|
((ProxiedPlayer) sender).chat(str);
|
||||||
i++;
|
}
|
||||||
str = str + " " + args[i];
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
|
||||||
|
String last = (args.length > 0)?args[args.length - 1].toLowerCase():"";
|
||||||
|
if (args.length <= 1) {
|
||||||
|
List<String> cmds = Arrays.asList("help", "list", "version", "start", "stop", "kill", "terminate", "cmd", "command", "create");
|
||||||
|
if (last.length() == 0) {
|
||||||
|
return cmds;
|
||||||
|
} else {
|
||||||
|
List<String> list = new ArrayList<String>();
|
||||||
|
for (String cmd : cmds) {
|
||||||
|
if (cmd.startsWith(last)) list.add(cmd);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (args[0].equals("start") ||
|
||||||
|
args[0].equals("stop") ||
|
||||||
|
args[0].equals("kill") || args[0].equals("terminate")) {
|
||||||
|
if (args.length == 2) {
|
||||||
|
List<String> list = new ArrayList<String>();
|
||||||
|
if (last.length() == 0) {
|
||||||
|
for (SubServer server : plugin.api.getSubServers().values()) list.add(server.getName());
|
||||||
|
} else {
|
||||||
|
for (SubServer server : plugin.api.getSubServers().values()) {
|
||||||
|
if (server.getName().toLowerCase().startsWith(last)) list.add(server.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
return Collections.emptyList();
|
||||||
|
} else if (args[0].equals("cmd") || args[0].equals("command")) {
|
||||||
|
if (args.length == 2) {
|
||||||
|
List<String> list = new ArrayList<String>();
|
||||||
|
if (last.length() == 0) {
|
||||||
|
for (SubServer server : plugin.api.getSubServers().values()) list.add(server.getName());
|
||||||
|
} else {
|
||||||
|
for (SubServer server : plugin.api.getSubServers().values()) {
|
||||||
|
if (server.getName().toLowerCase().startsWith(last)) list.add(server.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
} else if (args.length == 3) {
|
||||||
|
if (last.length() == 0) {
|
||||||
|
return Collections.singletonList("<Command>");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (last.length() == 0) {
|
||||||
|
return Collections.singletonList("[Args...]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Collections.emptyList();
|
||||||
|
} else if (args[0].equals("create")) {
|
||||||
|
if (args.length == 2) {
|
||||||
|
if (last.length() == 0) {
|
||||||
|
return Collections.singletonList("<Name>");
|
||||||
|
}
|
||||||
|
} else if (args.length == 3) {
|
||||||
|
List<String> list = new ArrayList<String>();
|
||||||
|
if (last.length() == 0) {
|
||||||
|
for (Host host : plugin.api.getHosts().values()) list.add(host.getName());
|
||||||
|
} else {
|
||||||
|
for (Host host : plugin.api.getHosts().values()) {
|
||||||
|
if (host.getName().toLowerCase().startsWith(last)) list.add(host.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
} else if (args.length == 4) {
|
||||||
|
List<String> list = new ArrayList<String>();
|
||||||
|
if (last.length() == 0) {
|
||||||
|
for (SubCreator.ServerType type : SubCreator.ServerType.values()) list.add(type.toString());
|
||||||
|
} else {
|
||||||
|
for (SubCreator.ServerType type : SubCreator.ServerType.values()) {
|
||||||
|
if (type.toString().toLowerCase().startsWith(last)) list.add(type.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
} else if (args.length == 5) {
|
||||||
|
if (last.length() == 0) {
|
||||||
|
return Collections.singletonList("<Version>");
|
||||||
|
}
|
||||||
|
} else if (args.length == 6) {
|
||||||
|
if (last.length() == 0) {
|
||||||
|
return Collections.singletonList("<Port>");
|
||||||
|
}
|
||||||
|
} else if (args.length == 7) {
|
||||||
|
if (last.length() == 0) {
|
||||||
|
return Collections.singletonList("[RAM]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Collections.emptyList();
|
||||||
|
} else {
|
||||||
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
((ProxiedPlayer) sender).chat(label + str);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,15 +333,14 @@ public final class SubCommand extends Command {
|
|||||||
" Terminate Server: /sub kill <SubServer>",
|
" Terminate Server: /sub kill <SubServer>",
|
||||||
" Command Server: /sub cmd <SubServer> <Command> [Args...]",
|
" Command Server: /sub cmd <SubServer> <Command> [Args...]",
|
||||||
" Create Server: /sub create <Name> <Host> <Type> <Version> <Port> [RAM]",
|
" Create Server: /sub create <Name> <Host> <Type> <Version> <Port> [RAM]",
|
||||||
|
" Remove Server: /sub delete <SubServer>",
|
||||||
"",
|
"",
|
||||||
" To see BungeeCord Supplied Commands, please visit:",
|
" To see BungeeCord Supplied Commands, please visit:",
|
||||||
" https://www.spigotmc.org/wiki/bungeecord-commands/"
|
" https://www.spigotmc.org/wiki/bungeecord-commands/"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class BungeeServer extends Command implements TabExecutor {
|
||||||
|
|
||||||
public static class BungeeServer extends Command {
|
|
||||||
private SubPlugin plugin;
|
private SubPlugin plugin;
|
||||||
protected BungeeServer(SubPlugin plugin, String command) {
|
protected BungeeServer(SubPlugin plugin, String command) {
|
||||||
super(command, "bungeecord.command.server");
|
super(command, "bungeecord.command.server");
|
||||||
@ -232,6 +381,24 @@ public final class SubCommand extends Command {
|
|||||||
sender.sendMessage(plugin.lang.get().getSection("Lang").getColoredString("Command.Generic.Player-Only", '&'));
|
sender.sendMessage(plugin.lang.get().getSection("Lang").getColoredString("Command.Generic.Player-Only", '&'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
|
||||||
|
if (args.length <= 1) {
|
||||||
|
String last = (args.length > 0)?args[args.length - 1].toLowerCase():"";
|
||||||
|
if (last.length() == 0) {
|
||||||
|
return plugin.getServers().keySet();
|
||||||
|
} else {
|
||||||
|
List<String> list = new ArrayList<String>();
|
||||||
|
for (String server : plugin.getServers().keySet()) {
|
||||||
|
if (server.toLowerCase().startsWith(last)) list.add(server);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class BungeeList extends Command {
|
public static class BungeeList extends Command {
|
||||||
|
@ -13,6 +13,7 @@ import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
|||||||
import net.ME1312.SubServers.Bungee.Network.SubDataServer;
|
import net.ME1312.SubServers.Bungee.Network.SubDataServer;
|
||||||
import net.md_5.bungee.BungeeCord;
|
import net.md_5.bungee.BungeeCord;
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
@ -20,6 +21,7 @@ import java.net.InetSocketAddress;
|
|||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main Plugin Class
|
* Main Plugin Class
|
||||||
@ -36,7 +38,7 @@ public final class SubPlugin extends BungeeCord {
|
|||||||
public YAMLConfig lang;
|
public YAMLConfig lang;
|
||||||
public HashMap<String, String> exLang = new HashMap<String, String>();
|
public HashMap<String, String> exLang = new HashMap<String, String>();
|
||||||
public SubDataServer subdata = null;
|
public SubDataServer subdata = null;
|
||||||
public final Version version = new Version("2.11.2b");
|
public final Version version = new Version("2.11.2c");
|
||||||
protected Version bversion = null;
|
protected Version bversion = null;
|
||||||
|
|
||||||
protected boolean running = false;
|
protected boolean running = false;
|
||||||
@ -105,6 +107,57 @@ public final class SubPlugin extends BungeeCord {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(new UniversalFile(dir, "Plugin Templates:Spigot Plugins").exists())) {
|
||||||
|
new UniversalFile(dir, "Plugin Templates:Spigot Plugins").mkdirs();
|
||||||
|
System.out.println("SubServers > Created ~/SubServers/Plugin Templates/Spigot Plugins");
|
||||||
|
}
|
||||||
|
if (!(new UniversalFile(dir, "Plugin Templates:Sponge Config").exists())) {
|
||||||
|
new UniversalFile(dir, "Plugin Templates:Sponge Config").mkdir();
|
||||||
|
System.out.println("SubServers > Created ~/SubServers/Plugin Templates/Sponge Config");
|
||||||
|
}
|
||||||
|
if (!(new UniversalFile(dir, "Plugin Templates:Sponge Mods").exists())) {
|
||||||
|
new UniversalFile(dir, "Plugin Templates:Sponge Mods").mkdir();
|
||||||
|
System.out.println("SubServers > Created ~/SubServers/Plugin Templates/Sponge Mods");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (new UniversalFile(dir, "Recently Deleted").exists()) {
|
||||||
|
int f = new UniversalFile(dir, "Recently Deleted").listFiles().length;
|
||||||
|
for (File file : new UniversalFile(dir, "Recently Deleted").listFiles()) {
|
||||||
|
try {
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
if (new UniversalFile(dir, "Recently Deleted:" + file.getName() + ":info.json").exists()) {
|
||||||
|
JSONObject json = new JSONObject(Util.readAll(new FileReader(new UniversalFile(dir, "Recently Deleted:" + file.getName() + ":info.json"))));
|
||||||
|
if (json.keySet().contains("Timestamp")) {
|
||||||
|
if (TimeUnit.MILLISECONDS.toDays(Calendar.getInstance().getTime().getTime() - json.getLong("Timestamp")) >= 7) {
|
||||||
|
Util.deleteDirectory(file);
|
||||||
|
f--;
|
||||||
|
System.out.println("SubServers > Removed ~/SubServers/Recently Deleted/" + file.getName());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Util.deleteDirectory(file);
|
||||||
|
f--;
|
||||||
|
System.out.println("SubServers > Removed ~/SubServers/Recently Deleted/" + file.getName());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Util.deleteDirectory(file);
|
||||||
|
f--;
|
||||||
|
System.out.println("SubServers > Removed ~/SubServers/Recently Deleted/" + file.getName());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Files.delete(file.toPath());
|
||||||
|
f--;
|
||||||
|
System.out.println("SubServers > Removed ~/SubServers/Recently Deleted/" + file.getName());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (f == 0) {
|
||||||
|
System.out.println("SubServers > Removed ~/SubServers/Recently Deleted");
|
||||||
|
Files.delete(new UniversalFile(dir, "Recently Deleted").toPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
hostDrivers.put("built-in", net.ME1312.SubServers.Bungee.Host.Internal.InternalHost.class);
|
hostDrivers.put("built-in", net.ME1312.SubServers.Bungee.Host.Internal.InternalHost.class);
|
||||||
|
|
||||||
System.out.println("SubServers > Loading BungeeCord Libraries...");
|
System.out.println("SubServers > Loading BungeeCord Libraries...");
|
||||||
@ -160,7 +213,7 @@ public final class SubPlugin extends BungeeCord {
|
|||||||
System.out.println("SubServers > Loading SubServers...");
|
System.out.println("SubServers > Loading SubServers...");
|
||||||
for (String name : config.get().getSection("Servers").getKeys()) {
|
for (String name : config.get().getSection("Servers").getKeys()) {
|
||||||
try {
|
try {
|
||||||
if (!this.hosts.keySet().contains(config.get().getSection("Servers").getSection(name).getString("Host").toLowerCase())) throw new InvalidServerException("There is no host with this name:" + name);
|
if (!this.hosts.keySet().contains(config.get().getSection("Servers").getSection(name).getString("Host").toLowerCase())) throw new InvalidServerException("There is no host with this name: " + config.get().getSection("Servers").getSection(name).getString("Host"));
|
||||||
if (exServers.keySet().contains(name.toLowerCase())) {
|
if (exServers.keySet().contains(name.toLowerCase())) {
|
||||||
exServers.remove(name.toLowerCase());
|
exServers.remove(name.toLowerCase());
|
||||||
servers--;
|
servers--;
|
||||||
|
@ -69,6 +69,10 @@ public class YAMLSection {
|
|||||||
|
|
||||||
public void remove(String label) {
|
public void remove(String label) {
|
||||||
map.remove(label);
|
map.remove(label);
|
||||||
|
|
||||||
|
if (this.label != null && this.up != null) {
|
||||||
|
this.up.set(this.label, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
|
@ -42,14 +42,15 @@ public final class SubPlugin extends JavaPlugin {
|
|||||||
Bukkit.getLogger().info("SubServers > Updated ~/plugins/SubServers/config.yml");
|
Bukkit.getLogger().info("SubServers > Updated ~/plugins/SubServers/config.yml");
|
||||||
}
|
}
|
||||||
pluginconf = new YAMLConfig(new UniversalFile(getDataFolder(), "config.yml"));
|
pluginconf = new YAMLConfig(new UniversalFile(getDataFolder(), "config.yml"));
|
||||||
subdata = new SubDataClient(this, pluginconf.get().getSection("Settings").getSection("SubData").getString("Name", "~no_name"),
|
subdata = new SubDataClient(this, pluginconf.get().getSection("Settings").getSection("SubData").getString("Name", "undefined"),
|
||||||
InetAddress.getByName(pluginconf.get().getSection("Settings").getSection("SubData").getString("Address", "127.0.0.1:4391").split(":")[0]),
|
InetAddress.getByName(pluginconf.get().getSection("Settings").getSection("SubData").getString("Address", "127.0.0.1:4391").split(":")[0]),
|
||||||
Integer.parseInt(pluginconf.get().getSection("Settings").getSection("SubData").getString("Address", "127.0.0.1:4391").split(":")[1]));
|
Integer.parseInt(pluginconf.get().getSection("Settings").getSection("SubData").getString("Address", "127.0.0.1:4391").split(":")[1]));
|
||||||
|
|
||||||
gui = new UIListener(this);
|
gui = new UIListener(this);
|
||||||
getCommand("subservers").setExecutor(new SubCommand(this));
|
SubCommand cmd = new SubCommand(this);
|
||||||
getCommand("subserver").setExecutor(new SubCommand(this));
|
getCommand("subservers").setExecutor(cmd);
|
||||||
getCommand("sub").setExecutor(new SubCommand(this));
|
getCommand("subserver").setExecutor(cmd);
|
||||||
|
getCommand("sub").setExecutor(cmd);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
Loading…
Reference in New Issue
Block a user