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("Password", host.plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"));
|
||||
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) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -401,6 +403,8 @@ public class InternalSubCreator extends SubCreator {
|
||||
try {
|
||||
exec = new Executable("java -Xmx" + memory + "M -jar Forge.jar");
|
||||
|
||||
new UniversalFile(dir, "config").mkdirs();
|
||||
new UniversalFile(dir, "mods").mkdirs();
|
||||
GenerateEULA(dir);
|
||||
GenerateProperties(dir, port);
|
||||
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());
|
||||
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");
|
||||
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());
|
||||
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());
|
||||
|
||||
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) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -563,4 +571,48 @@ public class InternalSubCreator extends SubCreator {
|
||||
public boolean isBusy() {
|
||||
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;
|
||||
// REGEX Formatting
|
||||
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()) {
|
||||
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) {
|
||||
case "INFO":
|
||||
case "MESSAGE":
|
||||
ProxyServer.getInstance().getLogger().info(name + " > " + msg);
|
||||
break;
|
||||
case "WARNING":
|
||||
@ -70,8 +71,7 @@ public class InternalSubLogger {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
} finally {
|
||||
} catch (IOException e) {} finally {
|
||||
stop();
|
||||
}
|
||||
}).start();
|
||||
@ -83,8 +83,30 @@ public class InternalSubLogger {
|
||||
if (!line.startsWith(">")) {
|
||||
if (log.get()) {
|
||||
String msg = line;
|
||||
msg = msg.replaceAll("^((?:\\s*\\[?[0-9]{2}:[0-9]{2}:[0-9]{2}]?)?\\s*(?:\\[|\\[.*\\/)?(INFO|WARN|WARNING|ERROR|ERR|SEVERE)\\]:?\\s*)", "");
|
||||
ProxyServer.getInstance().getLogger().severe(name + " > " + msg);
|
||||
// REGEX Formatting
|
||||
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) {
|
||||
writer.println(line);
|
||||
@ -92,8 +114,7 @@ public class InternalSubLogger {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
} finally {
|
||||
} catch (IOException e) {} finally {
|
||||
stop();
|
||||
}
|
||||
}).start();
|
||||
|
@ -18,6 +18,7 @@ public class InternalSubServer extends SubServer {
|
||||
private InternalHost host;
|
||||
private boolean enabled;
|
||||
private Container<Boolean> log;
|
||||
private String dir;
|
||||
private File directory;
|
||||
private Executable executable;
|
||||
private String stopcmd;
|
||||
@ -33,6 +34,7 @@ public class InternalSubServer extends SubServer {
|
||||
this.host = (InternalHost) host;
|
||||
this.enabled = enabled;
|
||||
this.log = new Container<Boolean>(log);
|
||||
this.dir = directory;
|
||||
this.directory = new File(host.getDirectory(), directory);
|
||||
this.executable = executable;
|
||||
this.stopcmd = stopcmd;
|
||||
@ -192,6 +194,11 @@ public class InternalSubServer extends SubServer {
|
||||
log.set(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDirectory() {
|
||||
return dir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStopCommand() {
|
||||
return stopcmd;
|
||||
|
@ -13,7 +13,12 @@ public abstract class SubCreator {
|
||||
public enum ServerType {
|
||||
SPIGOT,
|
||||
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);
|
||||
|
||||
|
||||
/**
|
||||
* Get the Server Directory
|
||||
*
|
||||
* @return Server Directory
|
||||
*/
|
||||
public abstract String getDirectory();
|
||||
|
||||
/**
|
||||
* Grab the Command to Stop the Server
|
||||
*
|
||||
|
@ -70,6 +70,10 @@ public class YAMLSection {
|
||||
|
||||
public void remove(String label) {
|
||||
map.remove(label);
|
||||
|
||||
if (this.label != null && this.up != null) {
|
||||
this.up.set(this.label, this);
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
StringBuilder sb = new StringBuilder(str.length());
|
||||
|
@ -1,9 +1,11 @@
|
||||
package net.ME1312.SubServers.Bungee;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import net.ME1312.SubServers.Bungee.Host.Host;
|
||||
import net.ME1312.SubServers.Bungee.Host.Server;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubCreator;
|
||||
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.Version.Version;
|
||||
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.HoverEvent;
|
||||
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.plugin.Command;
|
||||
import net.md_5.bungee.api.plugin.TabExecutor;
|
||||
import net.md_5.bungee.command.ConsoleCommandSender;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Plugin Command Class
|
||||
*
|
||||
* @author ME1312
|
||||
*/
|
||||
public final class SubCommand extends Command {
|
||||
@SuppressWarnings("deprecation")
|
||||
public final class SubCommand extends Command implements TabExecutor {
|
||||
private SubPlugin plugin;
|
||||
private String label;
|
||||
|
||||
@ -42,7 +47,6 @@ public final class SubCommand extends Command {
|
||||
* @param sender
|
||||
* @param args
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
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)) {
|
||||
sender.sendMessage("SubServers > Invalid Ram Amount");
|
||||
} 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 {
|
||||
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 {
|
||||
sender.sendMessage("SubServers > Unknown sub-command: " + args[0]);
|
||||
}
|
||||
@ -162,13 +220,105 @@ public final class SubCommand extends Command {
|
||||
sender.sendMessages(printHelp());
|
||||
}
|
||||
} else {
|
||||
String str = "";
|
||||
int i = -1;
|
||||
while ((i + 1) != args.length) {
|
||||
i++;
|
||||
str = str + " " + args[i];
|
||||
String str = label;
|
||||
for (String arg : args) str += ' ' + arg;
|
||||
((ProxiedPlayer) sender).chat(str);
|
||||
}
|
||||
}
|
||||
|
||||
@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>",
|
||||
" Command Server: /sub cmd <SubServer> <Command> [Args...]",
|
||||
" Create Server: /sub create <Name> <Host> <Type> <Version> <Port> [RAM]",
|
||||
" Remove Server: /sub delete <SubServer>",
|
||||
"",
|
||||
" To see BungeeCord Supplied Commands, please visit:",
|
||||
" https://www.spigotmc.org/wiki/bungeecord-commands/"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static class BungeeServer extends Command {
|
||||
public static class BungeeServer extends Command implements TabExecutor {
|
||||
private SubPlugin plugin;
|
||||
protected BungeeServer(SubPlugin plugin, String command) {
|
||||
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", '&'));
|
||||
}
|
||||
}
|
||||
|
||||
@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 {
|
||||
|
@ -13,6 +13,7 @@ import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.SubDataServer;
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.InetAddress;
|
||||
@ -20,6 +21,7 @@ import java.net.InetSocketAddress;
|
||||
import java.net.SocketException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Main Plugin Class
|
||||
@ -36,7 +38,7 @@ public final class SubPlugin extends BungeeCord {
|
||||
public YAMLConfig lang;
|
||||
public HashMap<String, String> exLang = new HashMap<String, String>();
|
||||
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 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);
|
||||
|
||||
System.out.println("SubServers > Loading BungeeCord Libraries...");
|
||||
@ -160,7 +213,7 @@ public final class SubPlugin extends BungeeCord {
|
||||
System.out.println("SubServers > Loading SubServers...");
|
||||
for (String name : config.get().getSection("Servers").getKeys()) {
|
||||
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())) {
|
||||
exServers.remove(name.toLowerCase());
|
||||
servers--;
|
||||
|
@ -69,6 +69,10 @@ public class YAMLSection {
|
||||
|
||||
public void remove(String label) {
|
||||
map.remove(label);
|
||||
|
||||
if (this.label != null && this.up != null) {
|
||||
this.up.set(this.label, this);
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
|
@ -42,14 +42,15 @@ public final class SubPlugin extends JavaPlugin {
|
||||
Bukkit.getLogger().info("SubServers > Updated ~/plugins/SubServers/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]),
|
||||
Integer.parseInt(pluginconf.get().getSection("Settings").getSection("SubData").getString("Address", "127.0.0.1:4391").split(":")[1]));
|
||||
|
||||
gui = new UIListener(this);
|
||||
getCommand("subservers").setExecutor(new SubCommand(this));
|
||||
getCommand("subserver").setExecutor(new SubCommand(this));
|
||||
getCommand("sub").setExecutor(new SubCommand(this));
|
||||
SubCommand cmd = new SubCommand(this);
|
||||
getCommand("subservers").setExecutor(cmd);
|
||||
getCommand("subserver").setExecutor(cmd);
|
||||
getCommand("sub").setExecutor(cmd);
|
||||
} catch (IOException e) {
|
||||
setEnabled(false);
|
||||
e.printStackTrace();
|
||||
|
Loading…
Reference in New Issue
Block a user