2016-12-24 05:55:17 +01:00
|
|
|
package net.ME1312.SubServers.Bungee.Host;
|
2016-12-05 04:21:04 +01:00
|
|
|
|
2017-05-29 07:00:02 +02:00
|
|
|
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
|
|
|
import net.ME1312.SubServers.Bungee.Library.Util;
|
2016-12-24 05:55:17 +01:00
|
|
|
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
2016-12-05 04:21:04 +01:00
|
|
|
|
2017-05-29 07:00:02 +02:00
|
|
|
import java.io.File;
|
|
|
|
import java.util.Map;
|
2016-12-05 04:21:04 +01:00
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SubCreator Layout Class
|
|
|
|
*/
|
|
|
|
public abstract class SubCreator {
|
2017-05-29 07:00:02 +02:00
|
|
|
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) {
|
|
|
|
Util.isNull(name, enabled, directory, build, options);
|
|
|
|
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,
|
2017-05-29 07:00:02 +02:00
|
|
|
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
|
2017-05-29 07:00:02 +02:00
|
|
|
* @param template Server Template
|
2016-12-28 01:15:36 +01:00
|
|
|
* @param version Server Version
|
|
|
|
* @param port Server Port Number
|
|
|
|
* @return Success Status
|
|
|
|
*/
|
2017-05-29 07:00:02 +02:00
|
|
|
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
|
2017-05-29 07:00:02 +02:00
|
|
|
* @param template Server Template
|
2016-12-28 01:15:36 +01:00
|
|
|
* @param version Server Version
|
|
|
|
* @param port Server Port Number
|
|
|
|
* @return Success Status
|
|
|
|
*/
|
2017-05-29 07:00:02 +02:00
|
|
|
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 SubCreator
|
|
|
|
*/
|
|
|
|
public abstract void terminate();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wait for SubCreator to Finish
|
|
|
|
*
|
|
|
|
* @throws InterruptedException
|
|
|
|
*/
|
2016-12-05 04:21:04 +01:00
|
|
|
public abstract void waitFor() 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();
|
2016-12-15 22:04:39 +01:00
|
|
|
|
2017-01-11 04:23:29 +01:00
|
|
|
/**
|
|
|
|
* Gets the Logger for the creator
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public abstract SubLogger getLogger();
|
|
|
|
|
2016-12-28 01:15:36 +01:00
|
|
|
/**
|
|
|
|
* Gets the status of SubCreator
|
|
|
|
*
|
|
|
|
* @return SubCreator Status
|
|
|
|
*/
|
2016-12-05 04:21:04 +01:00
|
|
|
public abstract boolean isBusy();
|
2017-05-29 07:00:02 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
2016-12-05 04:21:04 +01:00
|
|
|
}
|