SubServers-2/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubCreator.java

298 lines
7.8 KiB
Java
Raw Normal View History

2016-12-24 05:55:17 +01:00
package net.ME1312.SubServers.Bungee.Host;
2016-12-05 04:21:04 +01:00
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidTemplateException;
import net.ME1312.SubServers.Bungee.Library.Util;
2016-12-24 05:55:17 +01:00
import net.ME1312.SubServers.Bungee.Library.Version.Version;
import net.ME1312.SubServers.Bungee.SubAPI;
2016-12-05 04:21:04 +01:00
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
2016-12-05 04:21:04 +01:00
import java.util.UUID;
/**
* SubCreator Layout Class
*/
public abstract class SubCreator {
public static class ServerTemplate {
private String name;
private String nick = null;
private boolean enabled;
private String icon;
private File directory;
private ServerType type;
private YAMLSection build;
private YAMLSection options;
/**
* Create a SubCreator Template
*
* @param name Template Name
* @param directory Template Directory
* @param build Build Options
* @param options Configuration Options
*/
public ServerTemplate(String name, boolean enabled, String icon, File directory, YAMLSection build, YAMLSection options) {
if (Util.isNull(name, enabled, directory, build, options)) throw new NullPointerException();
if (name.contains(" ")) throw new InvalidTemplateException("Template names cannot have spaces: " + name);
this.name = name;
this.enabled = enabled;
this.icon = icon;
this.directory = directory;
this.type = (build.contains("Server-Type"))?ServerType.valueOf(build.getRawString("Server-Type").toUpperCase()):ServerType.CUSTOM;
this.build = build;
this.options = options;
}
/**
* Get the Name of this Template
*
* @return Template Name
*/
public String getName() {
return name;
}
/**
* Get the Display Name of this Template
*
* @return Display Name
*/
public String getDisplayName() {
return (nick == null)?getName():nick;
}
/**
* Sets the Display Name for this Template
*
* @param value Value (or null to reset)
*/
public void setDisplayName(String value) {
if (value == null || value.length() == 0 || getName().equals(value)) {
this.nick = null;
} else {
this.nick = value;
}
}
/**
* Get the Enabled Status of this Template
*
* @return Enabled Status
*/
public boolean isEnabled() {
return enabled;
}
/**
* Set the Enabled Status of this Template
*
* @param value Value
*/
public void setEnabled(boolean value) {
enabled = value;
}
/**
* Get the Item Icon for this Template
*
* @return Item Icon Name/ID
*/
public String getIcon() {
return icon;
}
/**
* Set the Item Icon for this Template
*
* @param value Value
*/
public void setIcon(String value) {
icon = value;
}
/**
* Get the Directory for this Template
*
* @return Directory
*/
public File getDirectory() {
return directory;
}
/**
* Get the Type of this Template
*
* @return Template Type
*/
public ServerType getType() {
return type;
}
/**
* Get the Build Options for this Template
*
* @return Build Options
*/
public YAMLSection getBuildOptions() {
return build;
}
/**
* Get the Configuration Options for this Template
*
* @return Configuration Options
*/
public YAMLSection getConfigOptions() {
return options;
}
}
2016-12-05 04:21:04 +01:00
public enum ServerType {
SPIGOT,
VANILLA,
SPONGE,
CUSTOM;
2017-01-01 20:34:46 +01:00
@Override
public String toString() {
return super.toString().substring(0, 1).toUpperCase()+super.toString().substring(1).toLowerCase();
}
2016-12-05 04:21:04 +01:00
}
2016-12-28 01:15:36 +01:00
/**
* Create a SubServer
*
* @param player Player Creating
* @param name Server Name
* @param template Server Template
2016-12-28 01:15:36 +01:00
* @param version Server Version
* @param port Server Port Number
* @return Success Status
*/
public abstract boolean create(UUID player, String name, ServerTemplate template, Version version, int port);
2016-12-28 01:15:36 +01:00
/**
* Create a SubServer
*
* @param name Server Name
* @param template Server Template
2016-12-28 01:15:36 +01:00
* @param version Server Version
* @param port Server Port Number
* @return Success Status
*/
public boolean create(String name, ServerTemplate template, Version version, int port) {
return create(null, name, template, version, port);
2016-12-05 04:21:04 +01:00
}
2016-12-28 01:15:36 +01:00
/**
* Terminate All SubCreator Instances on this host
2016-12-28 01:15:36 +01:00
*/
public abstract void terminate();
/**
* Terminate a SubCreator Instance
*
* @param name Name of current creating server
*/
public abstract void terminate(String name);
/**
* Wait for All SubCreator Instances to Finish
2016-12-28 01:15:36 +01:00
*
* @throws InterruptedException
*/
2016-12-05 04:21:04 +01:00
public abstract void waitFor() throws InterruptedException;
/**
* Wait for SubCreator to Finish
*
* @param name Name of current creating server
* @throws InterruptedException
*/
public abstract void waitFor(String name) throws InterruptedException;
2016-12-28 01:15:36 +01:00
/**
* Gets the host this creator belongs to
*
* @return Host
*/
2016-12-05 04:21:04 +01:00
public abstract Host getHost();
2016-12-28 01:15:36 +01:00
/**
* Gets the Git Bash install directory
*
* @return Git Bash Directory
*/
2017-01-21 17:49:37 +01:00
public abstract String getBashDirectory();
/**
* Gets all loggers for All SubCreator Instances
*
* @return SubCreator Loggers
*/
public abstract List<SubLogger> getLogger();
/**
* Gets the Logger for a SubCreator Instance
*
* @param thread Thread ID
* @return SubCreator Logger
*/
public abstract SubLogger getLogger(String thread);
2016-12-28 01:15:36 +01:00
/**
* Get a list of currently reserved Server names
2016-12-28 01:15:36 +01:00
*
* @return Reserved Names
2016-12-28 01:15:36 +01:00
*/
public abstract List<String> getReservedNames();
/**
* Check if a name has been reserved
*
* @param name Name to check
* @return Reserved Status
*/
public static boolean isReserved(String name) {
boolean reserved = false;
for (List<String> list : getAllReservedNames().values()) for (String reserve : list) {
if (reserve.equalsIgnoreCase(name)) reserved = true;
}
return reserved;
}
/**
* Get a list of all currently reserved Server names across all hosts
*
* @return All Reserved Names
*/
public static Map<Host, List<String>> getAllReservedNames() {
HashMap<Host, List<String>> names = new HashMap<Host, List<String>>();
for (Host host : SubAPI.getInstance().getHosts().values()) names.put(host, host.getCreator().getReservedNames());
return names;
}
/**
* Gets the Templates that can be used in this SubCreator instance
*
* @return Template Map
*/
public abstract Map<String, ServerTemplate> getTemplates();
/**
* Gets a SubCreator Template by name
*
* @param name Template Name
* @return Template
*/
public abstract ServerTemplate getTemplate(String name);
2017-08-17 01:29:02 +02:00
/**
* Reload SubCreator
*/
public abstract void reload();
2016-12-05 04:21:04 +01:00
}