2016-12-20 00:31:01 +01:00
|
|
|
package net.ME1312.SubServers.Client.Bukkit.Graphic;
|
2018-08-12 23:23:21 +02:00
|
|
|
|
2020-06-12 07:45:49 +02:00
|
|
|
import net.ME1312.Galaxi.Library.Container.Container;
|
|
|
|
import net.ME1312.Galaxi.Library.Container.NamedContainer;
|
2019-04-18 16:02:09 +02:00
|
|
|
import net.ME1312.Galaxi.Library.Util;
|
|
|
|
import net.ME1312.Galaxi.Library.Version.Version;
|
2020-11-14 06:29:29 +01:00
|
|
|
import net.ME1312.SubServers.Client.Common.Network.API.Host;
|
|
|
|
import net.ME1312.SubServers.Client.Common.Network.API.SubServer;
|
2016-12-20 00:31:01 +01:00
|
|
|
import net.ME1312.SubServers.Client.Bukkit.SubPlugin;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.ChatColor;
|
2017-12-07 18:22:36 +01:00
|
|
|
import org.bukkit.Material;
|
2020-06-26 01:47:30 +02:00
|
|
|
import org.bukkit.entity.Player;
|
2017-12-07 18:22:36 +01:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2016-12-20 00:31:01 +01:00
|
|
|
|
|
|
|
import java.util.*;
|
2017-12-07 18:22:36 +01:00
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
2016-12-20 00:31:01 +01:00
|
|
|
|
2017-01-21 17:49:37 +01:00
|
|
|
/**
|
|
|
|
* GUI Renderer Layout Class
|
|
|
|
*/
|
|
|
|
public abstract class UIRenderer {
|
2020-06-12 07:45:49 +02:00
|
|
|
static HashMap<String, PluginRenderer<Host>> hostPlugins = new HashMap<String, PluginRenderer<Host>>();
|
|
|
|
static HashMap<String, PluginRenderer<SubServer>> subserverPlugins = new HashMap<String, PluginRenderer<SubServer>>();
|
2017-04-03 19:08:00 +02:00
|
|
|
private NamedContainer<String, Integer> tdownload = null;
|
2017-12-07 18:22:36 +01:00
|
|
|
private int download = -1;
|
2017-01-21 17:49:37 +01:00
|
|
|
private final UUID player;
|
2016-12-20 00:31:01 +01:00
|
|
|
private SubPlugin plugin;
|
2017-01-08 20:42:40 +01:00
|
|
|
|
|
|
|
/**
|
2017-01-21 17:49:37 +01:00
|
|
|
* Creates a new UIRenderer
|
|
|
|
*
|
|
|
|
* @param plugin SubPlugin
|
|
|
|
* @param player Player
|
2017-01-08 20:42:40 +01:00
|
|
|
*/
|
2017-01-21 17:49:37 +01:00
|
|
|
public UIRenderer(SubPlugin plugin, UUID player) {
|
2017-01-30 21:22:36 +01:00
|
|
|
if (Util.isNull(plugin, player)) throw new NullPointerException();
|
2016-12-20 00:31:01 +01:00
|
|
|
this.plugin = plugin;
|
|
|
|
this.player = player;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens a new window
|
|
|
|
*/
|
2017-01-21 17:49:37 +01:00
|
|
|
public abstract void newUI();
|
2016-12-20 00:31:01 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears the Window History
|
|
|
|
*/
|
2017-01-21 17:49:37 +01:00
|
|
|
public abstract void clearHistory();
|
2016-12-20 00:31:01 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If there is any Window History
|
|
|
|
*
|
|
|
|
* @return Window History Status
|
|
|
|
*/
|
2017-01-21 17:49:37 +01:00
|
|
|
public abstract boolean hasHistory();
|
2016-12-20 00:31:01 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reopens the current window
|
|
|
|
*/
|
2017-01-21 17:49:37 +01:00
|
|
|
public abstract void reopen();
|
2016-12-20 00:31:01 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reopens the previous window
|
|
|
|
*/
|
2017-01-21 17:49:37 +01:00
|
|
|
public abstract void back();
|
2016-12-20 00:31:01 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt to send a Title Message
|
|
|
|
*
|
|
|
|
* @param str Message
|
|
|
|
* @return Success Status
|
|
|
|
*/
|
|
|
|
public boolean sendTitle(String str) {
|
|
|
|
return sendTitle(str, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt to send a Title Message
|
|
|
|
*
|
|
|
|
* @param str Message
|
|
|
|
* @param stay How long the message should stay
|
|
|
|
* @return Success Status
|
|
|
|
*/
|
|
|
|
public boolean sendTitle(String str, int stay) {
|
|
|
|
return sendTitle(str, -1, stay, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt to send a Title Message
|
|
|
|
*
|
|
|
|
* @param str Message
|
2017-12-07 18:22:36 +01:00
|
|
|
* @param fadein FadeIn Transition length (in ticks)
|
|
|
|
* @param stay How long the message should stay (in ticks)
|
|
|
|
* @param fadeout FadeOut Transition length (in ticks)
|
2016-12-20 00:31:01 +01:00
|
|
|
* @return Success Status
|
|
|
|
*/
|
|
|
|
public boolean sendTitle(String str, int fadein, int stay, int fadeout) {
|
2017-01-30 21:22:36 +01:00
|
|
|
if (Util.isNull(str, fadein, stay, fadeout)) throw new NullPointerException();
|
2019-04-18 16:02:09 +02:00
|
|
|
if (plugin.config.get().getMap("Settings").getBoolean("Use-Title-Messages", true)) {
|
2016-12-20 00:31:01 +01:00
|
|
|
String line1, line2;
|
|
|
|
if (!str.startsWith("\n") && str.contains("\n")) {
|
|
|
|
line1 = str.split("\\n")[0];
|
|
|
|
line2 = str.split("\\n")[1];
|
|
|
|
} else {
|
|
|
|
line1 = str.replace("\n", "");
|
|
|
|
line2 = ChatColor.RESET.toString();
|
|
|
|
}
|
|
|
|
try {
|
2020-06-26 01:47:30 +02:00
|
|
|
Player player = Bukkit.getPlayer(this.player);
|
2017-12-07 18:22:36 +01:00
|
|
|
if (plugin.api.getGameVersion().compareTo(new Version("1.11")) >= 0) {
|
|
|
|
if (ChatColor.stripColor(line1).length() == 0 && ChatColor.stripColor(line2).length() == 0) {
|
2020-06-26 01:47:30 +02:00
|
|
|
player.resetTitle();
|
2017-12-07 18:22:36 +01:00
|
|
|
} else {
|
2020-06-26 01:47:30 +02:00
|
|
|
player.sendTitle(line1, line2, (fadein >= 0)?fadein:10, (stay >= 0)?stay:70, (fadeout >= 0)?fadeout:20);
|
2017-12-07 18:22:36 +01:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else if (Bukkit.getPluginManager().getPlugin("TitleManager") != null) {
|
2020-06-26 01:47:30 +02:00
|
|
|
if (Util.isException(() -> Util.reflect(Class.forName("io.puharesource.mc.titlemanager.api.v2.TitleManagerAPI").getMethod("sendTitles", Player.class, String.class, String.class, int.class, int.class, int.class),
|
|
|
|
Bukkit.getPluginManager().getPlugin("TitleManager"), player, line1, line2, (fadein >= 0)?fadein:10, (stay >= 0)?stay:70, (fadeout >= 0)?fadeout:20))) { // Attempt TitleAPI v2
|
|
|
|
|
|
|
|
// Fallback to TitleAPI v1
|
|
|
|
io.puharesource.mc.titlemanager.api.TitleObject obj = io.puharesource.mc.titlemanager.api.TitleObject.class.getConstructor(String.class, String.class).newInstance(line1, line2);
|
|
|
|
if (fadein >= 0) obj.setFadeIn(fadein);
|
|
|
|
if (stay >= 0) obj.setStay(stay);
|
|
|
|
if (fadeout >= 0) obj.setFadeOut(fadeout);
|
|
|
|
obj.send(player);
|
|
|
|
}
|
2017-12-07 18:22:36 +01:00
|
|
|
return true;
|
|
|
|
} else return false;
|
2016-12-20 00:31:01 +01:00
|
|
|
} catch (Throwable e) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-12-07 18:22:36 +01:00
|
|
|
} else return false;
|
2016-12-20 00:31:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows/Hides the Downloading Title Message
|
|
|
|
*
|
|
|
|
* @param subtitle Subtitle to display (or null to hide)
|
|
|
|
*/
|
|
|
|
public void setDownloading(String subtitle) {
|
2019-04-18 16:02:09 +02:00
|
|
|
if (subtitle != null && !(plugin.config.get().getMap("Settings").getBoolean("Use-Title-Messages", true) && (plugin.api.getGameVersion().compareTo(new Version("1.11")) >= 0 || Bukkit.getPluginManager().getPlugin("TitleManager") != null))) {
|
2017-12-07 18:22:36 +01:00
|
|
|
if (download != -1) Bukkit.getScheduler().cancelTask(download);
|
|
|
|
download = Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> {
|
2018-01-02 23:29:25 +01:00
|
|
|
if (tdownload != null) Bukkit.getPlayer(player).sendMessage(plugin.api.getLang("SubServers", "Interface.Generic.Downloading").replace("$str$", subtitle));
|
2017-12-07 18:22:36 +01:00
|
|
|
download = -1;
|
2017-10-07 18:49:36 +02:00
|
|
|
}, 50L);
|
2017-04-03 19:08:00 +02:00
|
|
|
} if (subtitle != null && tdownload == null) {
|
|
|
|
tdownload = new NamedContainer<String, Integer>(subtitle, 0);
|
2016-12-20 00:31:01 +01:00
|
|
|
final Container<Integer> delay = new Container<Integer>(0);
|
|
|
|
Bukkit.getScheduler().runTask(plugin, new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2017-04-03 19:08:00 +02:00
|
|
|
if (tdownload != null) {
|
2018-01-02 23:29:25 +01:00
|
|
|
String word = ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Title"));
|
2016-12-20 00:31:01 +01:00
|
|
|
int i = 0;
|
2017-04-03 19:08:00 +02:00
|
|
|
int start = (tdownload.get() - 3 < 0)?0: tdownload.get()-3;
|
|
|
|
int end = (tdownload.get() >= word.length())?word.length(): tdownload.get();
|
2018-01-02 23:29:25 +01:00
|
|
|
String str = plugin.api.getLang("SubServers", (delay.get() > 7 && start == 0)?"Interface.Generic.Downloading.Title-Color-Alt":"Interface.Generic.Downloading.Title-Color");
|
2016-12-20 00:31:01 +01:00
|
|
|
delay.set(delay.get() + 1);
|
2017-04-03 19:08:00 +02:00
|
|
|
if (delay.get() > 7) tdownload.set(tdownload.get() + 1);
|
|
|
|
if (tdownload.get() >= word.length() + 3) {
|
|
|
|
tdownload.set(0);
|
2016-12-20 00:31:01 +01:00
|
|
|
delay.set(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (char c : word.toCharArray()) {
|
|
|
|
i++;
|
2018-01-02 23:29:25 +01:00
|
|
|
if (i == start) str += plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Title-Color-Alt");
|
2016-12-20 00:31:01 +01:00
|
|
|
str += c;
|
2018-01-02 23:29:25 +01:00
|
|
|
if (i == end) str += plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Title-Color");
|
2016-12-20 00:31:01 +01:00
|
|
|
}
|
|
|
|
|
2018-01-02 23:29:25 +01:00
|
|
|
str += '\n' + plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Title-Color-Alt") + tdownload.name();
|
2016-12-20 00:31:01 +01:00
|
|
|
sendTitle(str, 0, 10, 5);
|
|
|
|
Bukkit.getScheduler().runTaskLater(plugin, this, 1);
|
|
|
|
} else {
|
|
|
|
sendTitle(ChatColor.RESET.toString(), 0, 1, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (subtitle != null) {
|
2017-04-03 19:08:00 +02:00
|
|
|
tdownload.rename(subtitle);
|
2017-04-24 19:16:57 +02:00
|
|
|
} else {
|
|
|
|
if (tdownload != null) {
|
|
|
|
tdownload = null;
|
|
|
|
}
|
2017-12-07 18:22:36 +01:00
|
|
|
if (download != -1) {
|
|
|
|
Bukkit.getScheduler().cancelTask(download);
|
|
|
|
download = -1;
|
2017-04-24 19:16:57 +02:00
|
|
|
}
|
2016-12-20 00:31:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-07 18:22:36 +01:00
|
|
|
/**
|
|
|
|
* Parse an ItemStack from a String
|
|
|
|
*
|
|
|
|
* @param str String to parse
|
|
|
|
* @return ItemStack
|
|
|
|
*/
|
|
|
|
public ItemStack parseItem(String str) {
|
|
|
|
return parseItem(str, new ItemStack(Material.AIR));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse an ItemStack from a String
|
|
|
|
*
|
|
|
|
* @param str String to parse
|
|
|
|
* @param def Default to return if unable to parse
|
|
|
|
* @return ItemStack
|
|
|
|
*/
|
|
|
|
public ItemStack parseItem(String str, ItemStack def) {
|
|
|
|
final Container<String> item = new Container<String>(str);
|
|
|
|
if (plugin.api.getGameVersion().compareTo(new Version("1.13")) < 0) {
|
|
|
|
try {
|
|
|
|
// int
|
|
|
|
Matcher matcher = Pattern.compile("(?i)^(\\d+)$").matcher(item.get());
|
|
|
|
if (matcher.find()) {
|
|
|
|
return ItemStack.class.getConstructor(int.class, int.class).newInstance(Integer.parseInt(matcher.group(1)), 1);
|
|
|
|
}
|
|
|
|
// int:int
|
|
|
|
matcher.reset();
|
|
|
|
matcher = Pattern.compile("(?i)^(\\d+):(\\d+)$").matcher(item.get());
|
|
|
|
if (matcher.find()) {
|
|
|
|
return ItemStack.class.getConstructor(int.class, int.class, short.class).newInstance(Integer.parseInt(matcher.group(1)), 1, Short.parseShort(matcher.group(2)));
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// minecraft:name
|
|
|
|
if (item.get().toLowerCase().startsWith("minecraft:")) {
|
|
|
|
item.set(item.get().substring(10));
|
2018-07-15 20:07:22 +02:00
|
|
|
} else
|
|
|
|
|
|
|
|
// bukkit:name
|
|
|
|
if (item.get().toLowerCase().startsWith("bukkit:")) {
|
|
|
|
item.set(item.get().substring(7));
|
|
|
|
|
|
|
|
if (!Util.isException(() -> Material.valueOf(item.get().toUpperCase()))) {
|
|
|
|
return new ItemStack(Material.valueOf(item.get().toUpperCase()), 1);
|
|
|
|
}
|
2017-12-07 18:22:36 +01:00
|
|
|
}
|
2018-07-15 20:07:22 +02:00
|
|
|
|
|
|
|
// material name
|
|
|
|
if (plugin.api.getGameVersion().compareTo(new Version("1.13")) < 0) {
|
|
|
|
if (!Util.isException(() -> Material.valueOf(item.get().toUpperCase()))) {
|
|
|
|
return new ItemStack(Material.valueOf(item.get().toUpperCase()), 1);
|
|
|
|
}
|
|
|
|
} else try {
|
|
|
|
if (Material.class.getMethod("getMaterial", String.class, boolean.class).invoke(null, item.get().toUpperCase(), false) != null) {
|
|
|
|
return new ItemStack((Material) Material.class.getMethod("getMaterial", String.class, boolean.class).invoke(null, item.get().toUpperCase(), false), 1);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {}
|
|
|
|
|
2017-12-07 18:22:36 +01:00
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
2016-12-27 17:03:19 +01:00
|
|
|
/**
|
|
|
|
* Add Host Plugin
|
|
|
|
*
|
|
|
|
* @param handle Handle to bind
|
|
|
|
* @param renderer Renderer
|
|
|
|
*/
|
2018-08-12 23:23:21 +02:00
|
|
|
public static void addHostPlugin(String handle, PluginRenderer<Host> renderer) {
|
2017-01-30 21:22:36 +01:00
|
|
|
if (Util.isNull(handle, renderer)) throw new NullPointerException();
|
2016-12-27 17:03:19 +01:00
|
|
|
hostPlugins.put(handle, renderer);
|
|
|
|
}
|
|
|
|
|
2017-01-21 17:49:37 +01:00
|
|
|
/**
|
|
|
|
* Get Host Plugins
|
|
|
|
*
|
|
|
|
* @return Host Plugins
|
|
|
|
*/
|
2018-08-12 23:23:21 +02:00
|
|
|
public static Map<String, PluginRenderer> getHostPlugins() {
|
|
|
|
return new HashMap<String, PluginRenderer>(hostPlugins);
|
2017-01-21 17:49:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove Host Plugin
|
|
|
|
*
|
|
|
|
* @param handle Handle
|
|
|
|
*/
|
|
|
|
public static void removeHostPlugin(String handle) {
|
2017-01-30 21:22:36 +01:00
|
|
|
if (Util.isNull(handle)) throw new NullPointerException();
|
2017-01-21 17:49:37 +01:00
|
|
|
hostPlugins.remove(handle);
|
|
|
|
}
|
|
|
|
|
2016-12-27 17:03:19 +01:00
|
|
|
/**
|
|
|
|
* Add SubServer Plugin
|
|
|
|
*
|
|
|
|
* @param handle Handle to bind
|
|
|
|
* @param renderer Renderer
|
|
|
|
*/
|
2018-08-12 23:23:21 +02:00
|
|
|
public static void addSubServerPlugin(String handle, PluginRenderer<SubServer> renderer) {
|
2017-01-30 21:22:36 +01:00
|
|
|
if (Util.isNull(handle, renderer)) throw new NullPointerException();
|
2016-12-27 17:03:19 +01:00
|
|
|
subserverPlugins.put(handle, renderer);
|
|
|
|
}
|
|
|
|
|
2016-12-20 00:31:01 +01:00
|
|
|
/**
|
2017-01-21 17:49:37 +01:00
|
|
|
* Get SubServer Plugins
|
2016-12-20 00:31:01 +01:00
|
|
|
*
|
2017-01-21 17:49:37 +01:00
|
|
|
* @return SubServer Plugins
|
2016-12-20 00:31:01 +01:00
|
|
|
*/
|
2018-08-12 23:23:21 +02:00
|
|
|
public static Map<String, PluginRenderer> getSubServerPlugins() {
|
|
|
|
return new HashMap<String, PluginRenderer>(subserverPlugins);
|
2017-01-21 17:49:37 +01:00
|
|
|
}
|
2016-12-20 00:31:01 +01:00
|
|
|
|
2017-01-21 17:49:37 +01:00
|
|
|
/**
|
|
|
|
* Remove SubServer Plugin
|
|
|
|
*
|
|
|
|
* @param handle Handle
|
|
|
|
*/
|
|
|
|
public static void removeSubServerPlugin(String handle) {
|
2017-01-30 21:22:36 +01:00
|
|
|
if (Util.isNull(handle)) throw new NullPointerException();
|
2017-01-21 17:49:37 +01:00
|
|
|
subserverPlugins.remove(handle);
|
2016-12-20 00:31:01 +01:00
|
|
|
}
|
|
|
|
|
2017-01-21 17:49:37 +01:00
|
|
|
/**
|
|
|
|
* Opens the Host Menu
|
|
|
|
*
|
|
|
|
* @param page Page Number (starting from page 1)
|
|
|
|
*/
|
|
|
|
public abstract void hostMenu(int page);
|
|
|
|
|
2016-12-20 00:31:01 +01:00
|
|
|
/**
|
2016-12-24 05:55:17 +01:00
|
|
|
* Opens Host/<name>
|
2016-12-20 00:31:01 +01:00
|
|
|
*
|
|
|
|
* @param host Host Name
|
|
|
|
*/
|
2017-01-21 17:49:37 +01:00
|
|
|
public abstract void hostAdmin(String host);
|
2016-12-20 00:31:01 +01:00
|
|
|
|
|
|
|
/**
|
2016-12-24 05:55:17 +01:00
|
|
|
* Opens Host/<name>/Create
|
2016-12-20 00:31:01 +01:00
|
|
|
*
|
|
|
|
* @param options Creator Options
|
|
|
|
*/
|
2017-01-21 17:49:37 +01:00
|
|
|
public abstract void hostCreator(CreatorOptions options);
|
2016-12-20 00:31:01 +01:00
|
|
|
|
2017-01-21 17:49:37 +01:00
|
|
|
/**
|
|
|
|
* Opens Host/<name>/Plugins
|
|
|
|
*
|
|
|
|
* @param host Host Name
|
|
|
|
*/
|
|
|
|
public abstract void hostPlugin(int page, String host);
|
2016-12-20 00:31:01 +01:00
|
|
|
|
2017-08-26 07:19:59 +02:00
|
|
|
/**
|
|
|
|
* Opens the Group Menu
|
|
|
|
*
|
|
|
|
* @param page Page Number (starting from page 1)
|
|
|
|
*/
|
|
|
|
public abstract void groupMenu(int page);
|
|
|
|
|
2017-01-21 17:49:37 +01:00
|
|
|
/**
|
|
|
|
* Opens the SubServer Menu
|
|
|
|
*
|
|
|
|
* @param page Page Number (starting from page 1)
|
|
|
|
* @param host Host Name (or null to scan all hosts)
|
|
|
|
*/
|
2017-08-26 07:19:59 +02:00
|
|
|
public abstract void serverMenu(int page, String host, String group);
|
2016-12-20 00:31:01 +01:00
|
|
|
|
2017-01-21 17:49:37 +01:00
|
|
|
/**
|
|
|
|
* Opens SubServer/<name>
|
|
|
|
*
|
|
|
|
* @param server SubServer Name
|
|
|
|
*/
|
|
|
|
public abstract void subserverAdmin(String server);
|
2016-12-20 00:31:01 +01:00
|
|
|
|
2017-01-21 17:49:37 +01:00
|
|
|
/**
|
|
|
|
* Opens SubServer/<name>/Plugins
|
|
|
|
*
|
|
|
|
* @param server SubServer Name
|
|
|
|
*/
|
|
|
|
public abstract void subserverPlugin(int page, String server);
|
2016-12-20 00:31:01 +01:00
|
|
|
|
2017-01-21 17:49:37 +01:00
|
|
|
/**
|
|
|
|
* Options Layout Class
|
|
|
|
*/
|
|
|
|
public abstract static class Options {
|
|
|
|
List<Runnable> history = new LinkedList<Runnable>();
|
|
|
|
private boolean init = false;
|
2016-12-20 00:31:01 +01:00
|
|
|
|
2017-01-21 17:49:37 +01:00
|
|
|
public boolean init() {
|
|
|
|
if (!init) {
|
|
|
|
init = true;
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-12-20 00:31:01 +01:00
|
|
|
|
2017-01-21 17:49:37 +01:00
|
|
|
/**
|
|
|
|
* If there is any undo history
|
|
|
|
*
|
|
|
|
* @return Undo History Status
|
|
|
|
*/
|
|
|
|
public boolean hasHistory() {
|
|
|
|
return !history.isEmpty();
|
|
|
|
}
|
2016-12-20 00:31:01 +01:00
|
|
|
|
2017-01-21 17:49:37 +01:00
|
|
|
/**
|
|
|
|
* Reverts the last change
|
|
|
|
*/
|
|
|
|
public void undo() {
|
|
|
|
Runnable lastWindow = history.get(history.size() - 1);
|
|
|
|
history.remove(history.size() - 1);
|
|
|
|
lastWindow.run();
|
|
|
|
}
|
2016-12-20 00:31:01 +01:00
|
|
|
}
|
2017-01-08 20:42:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SubCreator Options Class
|
|
|
|
*/
|
2016-12-20 00:31:01 +01:00
|
|
|
public static class CreatorOptions extends Options {
|
|
|
|
private String host;
|
|
|
|
private String name = null;
|
2017-05-29 07:00:02 +02:00
|
|
|
private String template = null;
|
2016-12-20 00:31:01 +01:00
|
|
|
private Version version = null;
|
2018-10-08 23:07:44 +02:00
|
|
|
private Integer port = null;
|
2016-12-20 00:31:01 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Grabs a raw CreatorOptions instance
|
|
|
|
*
|
|
|
|
* @param host Host Name
|
|
|
|
*/
|
|
|
|
public CreatorOptions(String host) {
|
|
|
|
this.host = host;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the Host Name
|
|
|
|
*
|
|
|
|
* @return Host Name
|
|
|
|
*/
|
|
|
|
public String getHost() {
|
|
|
|
return this.host;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the Server Name
|
|
|
|
*
|
|
|
|
* @return Server Name
|
|
|
|
*/
|
|
|
|
public String getName() {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the Server Name
|
|
|
|
*
|
|
|
|
* @param value Value
|
|
|
|
*/
|
|
|
|
public void setName(String value) {
|
2017-01-30 21:22:36 +01:00
|
|
|
if (Util.isNull(value)) throw new NullPointerException();
|
2016-12-20 00:31:01 +01:00
|
|
|
final String name = this.name;
|
|
|
|
history.add(() -> this.name = name);
|
|
|
|
this.name = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-05-29 07:00:02 +02:00
|
|
|
* Gets the Template
|
2016-12-20 00:31:01 +01:00
|
|
|
*
|
2017-05-29 07:00:02 +02:00
|
|
|
* @return Template
|
2016-12-20 00:31:01 +01:00
|
|
|
*/
|
2017-05-29 07:00:02 +02:00
|
|
|
public String getTemplate() {
|
|
|
|
return template;
|
2016-12-20 00:31:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-05-29 07:00:02 +02:00
|
|
|
* Sets the Template
|
2016-12-20 00:31:01 +01:00
|
|
|
*
|
|
|
|
* @param value Value
|
|
|
|
*/
|
2017-05-29 07:00:02 +02:00
|
|
|
public void setTemplate(String value) {
|
2017-01-30 21:22:36 +01:00
|
|
|
if (Util.isNull(value)) throw new NullPointerException();
|
2017-05-29 07:00:02 +02:00
|
|
|
final String template = this.template;
|
|
|
|
history.add(() -> this.template = template);
|
|
|
|
this.template = value;
|
2016-12-20 00:31:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the Server Version
|
|
|
|
*
|
|
|
|
* @return Server Version
|
|
|
|
*/
|
|
|
|
public Version getVersion() {
|
|
|
|
return version;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the Server Version
|
|
|
|
*
|
|
|
|
* @param value Value
|
|
|
|
*/
|
|
|
|
public void setVersion(Version value) {
|
|
|
|
final Version version = this.version;
|
|
|
|
history.add(() -> this.version = version);
|
|
|
|
this.version = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the Port Number for the Server
|
|
|
|
*
|
2018-10-08 23:07:44 +02:00
|
|
|
* @return Server Port Number (null for auto-select)
|
2016-12-20 00:31:01 +01:00
|
|
|
*/
|
2018-10-08 23:07:44 +02:00
|
|
|
public Integer getPort() {
|
2016-12-20 00:31:01 +01:00
|
|
|
return port;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the Port Number for the Server
|
|
|
|
*
|
2018-10-08 23:07:44 +02:00
|
|
|
* @param value Value (null for auto-select)
|
2016-12-20 00:31:01 +01:00
|
|
|
*/
|
2018-10-08 23:07:44 +02:00
|
|
|
public void setPort(Integer value) {
|
2019-05-09 22:17:15 +02:00
|
|
|
final Integer port = this.port;
|
2016-12-20 00:31:01 +01:00
|
|
|
history.add(() -> this.port = port);
|
|
|
|
this.port = value;
|
|
|
|
}
|
|
|
|
}
|
2017-01-21 17:49:37 +01:00
|
|
|
}
|