diff --git a/Artifacts/SubServers.Bungee.jar b/Artifacts/SubServers.Bungee.jar index 18053539..20d24da5 100644 Binary files a/Artifacts/SubServers.Bungee.jar and b/Artifacts/SubServers.Bungee.jar differ diff --git a/Artifacts/SubServers.Client.Bukkit.jar b/Artifacts/SubServers.Client.Bukkit.jar index 90ea30d8..b0a38a68 100644 Binary files a/Artifacts/SubServers.Client.Bukkit.jar and b/Artifacts/SubServers.Client.Bukkit.jar differ diff --git a/Artifacts/SubServers.Console.jar b/Artifacts/SubServers.Console.jar index 8daaae50..f243142f 100644 Binary files a/Artifacts/SubServers.Console.jar and b/Artifacts/SubServers.Console.jar differ diff --git a/Javadoc/SubServers.Bungee/allclasses-frame.html b/Javadoc/SubServers.Bungee/allclasses-frame.html index 5abb2ffd..7ce8bfa9 100644 --- a/Javadoc/SubServers.Bungee/allclasses-frame.html +++ b/Javadoc/SubServers.Bungee/allclasses-frame.html @@ -65,6 +65,7 @@
  • SubRemoveServerEvent
  • SubSendCommandEvent
  • SubServer
  • +
  • SubServer.LoggedCommand
  • SubStartEvent
  • SubStopEvent
  • SubStoppedEvent
  • diff --git a/Javadoc/SubServers.Bungee/allclasses-noframe.html b/Javadoc/SubServers.Bungee/allclasses-noframe.html index 257ec353..4d4e9849 100644 --- a/Javadoc/SubServers.Bungee/allclasses-noframe.html +++ b/Javadoc/SubServers.Bungee/allclasses-noframe.html @@ -65,6 +65,7 @@
  • SubRemoveServerEvent
  • SubSendCommandEvent
  • SubServer
  • +
  • SubServer.LoggedCommand
  • SubStartEvent
  • SubStopEvent
  • SubStoppedEvent
  • diff --git a/Javadoc/SubServers.Bungee/index-all.html b/Javadoc/SubServers.Bungee/index-all.html index bbe73240..71e17ddf 100644 --- a/Javadoc/SubServers.Bungee/index-all.html +++ b/Javadoc/SubServers.Bungee/index-all.html @@ -88,10 +88,6 @@
    Adds a Driver for Hosts
    -
    addLang(String, String) - Method in class net.ME1312.SubServers.Bungee.SubAPI
    -
    -
    Adds to the Language Map
    -
    addServer(String, InetAddress, int, String, boolean, boolean) - Method in class net.ME1312.SubServers.Bungee.SubAPI
    Adds a Server to the Network
    @@ -497,6 +493,16 @@
    Get Remote Address
    +
    getBashDirectory() - Method in class net.ME1312.SubServers.Bungee.Host.Internal.InternalSubCreator
    +
     
    +
    getBashDirectory() - Method in class net.ME1312.SubServers.Bungee.Host.SubCreator
    +
    +
    Gets the Git Bash install directory
    +
    +
    getBetaVersion() - Method in class net.ME1312.SubServers.Bungee.SubAPI
    +
    +
    Gets the SubServers Beta Version
    +
    getBoolean(String) - Method in class net.ME1312.SubServers.Bungee.Library.Config.YAMLSection
    Get a Boolean by Handle
    @@ -545,6 +551,16 @@
    Gets the Command to Send
    +
    getCommand() - Method in class net.ME1312.SubServers.Bungee.Host.SubServer.LoggedCommand
    +
    +
    Get the command
    +
    +
    getCommandHistory() - Method in class net.ME1312.SubServers.Bungee.Host.Internal.InternalSubServer
    +
     
    +
    getCommandHistory() - Method in class net.ME1312.SubServers.Bungee.Host.SubServer
    +
    +
    Gets all the commands that were sent to this SubServer successfully
    +
    getConnection() - Method in class net.ME1312.SubServers.Bungee.Network.Client
    Get Raw Connection
    @@ -563,6 +579,10 @@
    Get the date this message was logged
    +
    getDate() - Method in class net.ME1312.SubServers.Bungee.Host.SubServer.LoggedCommand
    +
    +
    Get the date this command was logged
    +
    getDefiningSection() - Method in class net.ME1312.SubServers.Bungee.Library.Config.YAMLValue
    Get the YAML Section this Object was defined in
    @@ -627,11 +647,9 @@
    Get a Float List by Handle
    -
    getGitBashDirectory() - Method in class net.ME1312.SubServers.Bungee.Host.Internal.InternalSubCreator
    -
     
    -
    getGitBashDirectory() - Method in class net.ME1312.SubServers.Bungee.Host.SubCreator
    +
    getGameVersion() - Method in class net.ME1312.SubServers.Bungee.SubAPI
    -
    Gets the Git Bash install directory
    +
    Gets the Recommended Minecraft Version
    getHandle() - Method in class net.ME1312.SubServers.Bungee.Event.SubDataRecieveGenericInfoEvent
    @@ -709,6 +727,10 @@
    Get the Keys
    +
    getLang(String) - Method in class net.ME1312.SubServers.Bungee.SubAPI
    +
    +
    Gets a value from the SubServers Lang
    +
    getLang() - Method in class net.ME1312.SubServers.Bungee.SubAPI
    Gets the SubServers Lang
    @@ -765,9 +787,9 @@
    Get the message
    -
    getMessages() - Method in class net.ME1312.SubServers.Bungee.Host.Internal.InternalSubLogger
    +
    getMessageHistory() - Method in class net.ME1312.SubServers.Bungee.Host.Internal.InternalSubLogger
     
    -
    getMessages() - Method in class net.ME1312.SubServers.Bungee.Host.SubLogger
    +
    getMessageHistory() - Method in class net.ME1312.SubServers.Bungee.Host.SubLogger
    Gets a list of all the messages logged by this logger
    @@ -839,6 +861,10 @@
    Get the Port the Server will use
    +
    getProxyVersion() - Method in class net.ME1312.SubServers.Bungee.SubAPI
    +
    +
    Gets the BungeeCord Version
    +
    getRawString(String) - Method in class net.ME1312.SubServers.Bungee.Library.Config.YAMLSection
    Get an Unparsed String by Handle
    @@ -883,6 +909,10 @@
    Get a YAML Section List by Handle
    +
    getSender() - Method in class net.ME1312.SubServers.Bungee.Host.SubServer.LoggedCommand
    +
    +
    Get the command sender
    +
    getServer() - Method in class net.ME1312.SubServers.Bungee.Event.SubAddServerEvent
    Gets the Server to be Added
    @@ -1363,6 +1393,18 @@
    Determine if this message should be logged
    +
    LoggedCommand(String) - Constructor for class net.ME1312.SubServers.Bungee.Host.SubServer.LoggedCommand
    +
    +
    Store a Command
    +
    +
    LoggedCommand(UUID, String) - Constructor for class net.ME1312.SubServers.Bungee.Host.SubServer.LoggedCommand
    +
    +
    Store a Command
    +
    +
    LoggedCommand(Date, UUID, String) - Constructor for class net.ME1312.SubServers.Bungee.Host.SubServer.LoggedCommand
    +
    +
    Store a Command
    +
    LogMessage(String) - Constructor for class net.ME1312.SubServers.Bungee.Host.SubLogger.LogMessage
    Store a Message
    @@ -1802,6 +1844,10 @@
    Set if the server is hidden from players
    +
    setLang(String, String) - Method in class net.ME1312.SubServers.Bungee.SubAPI
    +
    +
    Adds to the Language Map
    +
    setLogging(boolean) - Method in class net.ME1312.SubServers.Bungee.Host.Internal.InternalSubServer
     
    setLogging(boolean) - Method in class net.ME1312.SubServers.Bungee.Host.SubServer
    @@ -1826,6 +1872,12 @@
    Set the Command that Stops the Server
    +
    setTemporary(boolean) - Method in class net.ME1312.SubServers.Bungee.Host.Internal.InternalSubServer
    +
     
    +
    setTemporary(boolean) - Method in class net.ME1312.SubServers.Bungee.Host.SubServer
    +
    +
    Set If the Server is Temporary (will start server if not running)
    +
    setType(SubCreator.ServerType) - Method in class net.ME1312.SubServers.Bungee.Event.SubCreateEvent
    Set the Type of Server to Create
    @@ -2014,6 +2066,10 @@
    Creates a SubServer
    +
    SubServer.LoggedCommand - Class in net.ME1312.SubServers.Bungee.Host
    +
    +
    Command Storage Class
    +
    SubStartEvent - Class in net.ME1312.SubServers.Bungee.Event
    Server Start Event
    diff --git a/Javadoc/SubServers.Bungee/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubCreator.html b/Javadoc/SubServers.Bungee/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubCreator.html index 5f39c2cc..99b6d60b 100644 --- a/Javadoc/SubServers.Bungee/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubCreator.html +++ b/Javadoc/SubServers.Bungee/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubCreator.html @@ -181,7 +181,7 @@ extends java.lang.String -getGitBashDirectory() +getBashDirectory()
    Gets the Git Bash install directory
    @@ -347,18 +347,18 @@ extends + +
  • net.ME1312.SubServers.Client.Bukkit.Graphic.InternalHandler (implements org.bukkit.event.Listener, net.ME1312.SubServers.Client.Bukkit.Graphic.UIHandler)
  • net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketAuthorization (implements net.ME1312.SubServers.Client.Bukkit.Network.PacketIn, net.ME1312.SubServers.Client.Bukkit.Network.PacketOut)
  • net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketCommandServer (implements net.ME1312.SubServers.Client.Bukkit.Network.PacketIn, net.ME1312.SubServers.Client.Bukkit.Network.PacketOut)
  • net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketCreateServer (implements net.ME1312.SubServers.Client.Bukkit.Network.PacketIn, net.ME1312.SubServers.Client.Bukkit.Network.PacketOut)
  • @@ -133,6 +134,7 @@ +
  • net.ME1312.SubServers.Client.Bukkit.SubAPI
  • net.ME1312.SubServers.Client.Bukkit.SubCommand (implements org.bukkit.command.CommandExecutor)
  • net.ME1312.SubServers.Client.Bukkit.Network.SubDataClient
  • java.lang.Throwable (implements java.io.Serializable) @@ -152,8 +154,11 @@
  • -
  • net.ME1312.SubServers.Client.Bukkit.Graphic.UIListener (implements org.bukkit.event.Listener)
  • -
  • net.ME1312.SubServers.Client.Bukkit.Graphic.UIRenderer
  • +
  • net.ME1312.SubServers.Client.Bukkit.Graphic.UIRenderer + +
  • net.ME1312.SubServers.Client.Bukkit.Graphic.UIRenderer.Options

    Enum Hierarchy

    diff --git a/SubServers.Bungee/META-INF/MANIFEST.MF b/SubServers.Bungee/META-INF/MANIFEST.MF index 1467430f..d774b954 100644 --- a/SubServers.Bungee/META-INF/MANIFEST.MF +++ b/SubServers.Bungee/META-INF/MANIFEST.MF @@ -1,5 +1,5 @@ Manifest-Version: 1.0 Class-Path: BungeeCord.jar Main-Class: net.ME1312.SubServers.Bungee.Launch -Implementation-Version: 2.11.2f +Implementation-Version: 2.11.2g Specification-Version: 0 diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubCreator.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubCreator.java index 5d2be297..6b9673a0 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubCreator.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubCreator.java @@ -243,7 +243,7 @@ public class InternalSubCreator extends SubCreator { } @Override - public String getGitBashDirectory() { + public String getBashDirectory() { return gitBash; } diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubLogger.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubLogger.java index 05fa0a7b..0fb03cc3 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubLogger.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubLogger.java @@ -188,7 +188,7 @@ public class InternalSubLogger extends SubLogger { } @Override - public List getMessages() { + public List getMessageHistory() { return new LinkedList(messages); } } diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubServer.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubServer.java index fc42adda..2bdf44b2 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubServer.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubServer.java @@ -7,11 +7,15 @@ import net.ME1312.SubServers.Bungee.Library.Container; import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException; import net.ME1312.SubServers.Bungee.Host.Host; import net.ME1312.SubServers.Bungee.Host.SubServer; +import net.ME1312.SubServers.Bungee.Library.NamedContainer; import java.io.BufferedWriter; import java.io.File; import java.io.IOException; import java.io.OutputStreamWriter; +import java.util.Calendar; +import java.util.Date; +import java.util.LinkedList; import java.util.UUID; /** @@ -25,6 +29,7 @@ public class InternalSubServer extends SubServer { private File directory; private Executable executable; private String stopcmd; + private LinkedList history; private Process process; private InternalSubLogger logger; private Thread thread; @@ -61,18 +66,16 @@ public class InternalSubServer extends SubServer { this.directory = new File(host.getDirectory(), directory); this.executable = executable; this.stopcmd = stopcmd; + this.history = new LinkedList(); this.process = null; this.logger = new InternalSubLogger(null, this, getName(), this.log, null); this.thread = null; this.command = null; this.restart = restart; - this.temporary = temporary; - - if (start || temporary) start(); + this.temporary = !((start || temporary) && !start()) && temporary; } private void run() { - allowrestart = true; try { process = Runtime.getRuntime().exec(executable.toString(), null, directory); @@ -80,8 +83,13 @@ public class InternalSubServer extends SubServer { logger.process = process; logger.start(); command = new BufferedWriter(new OutputStreamWriter(process.getOutputStream())); + for (LoggedCommand command : history) if (process.isAlive()) { + this.command.write(command.getCommand()); + this.command.newLine(); + this.command.flush(); + } - process.waitFor(); + if (process.isAlive()) process.waitFor(); } catch (IOException | InterruptedException e) { e.printStackTrace(); allowrestart = false; @@ -92,6 +100,7 @@ public class InternalSubServer extends SubServer { System.out.println("SubServers > " + getName() + " has stopped"); process = null; command = null; + history.clear(); if (isTemporary()) { try { @@ -113,11 +122,11 @@ public class InternalSubServer extends SubServer { @Override public boolean start(UUID player) { - if (isEnabled() && !isRunning()) { + if (isEnabled() && !(thread != null && thread.isAlive())) { SubStartEvent event = new SubStartEvent(player, this); host.plugin.getPluginManager().callEvent(event); if (!event.isCancelled()) { - (thread = new Thread(() -> run())).start(); + (thread = new Thread(this::run)).start(); return true; } else return false; } else return false; @@ -125,15 +134,18 @@ public class InternalSubServer extends SubServer { @Override public boolean stop(UUID player) { - if (isRunning()) { + if (thread != null && thread.isAlive()) { SubStopEvent event = new SubStopEvent(player, this, false); host.plugin.getPluginManager().callEvent(event); if (!event.isCancelled()) { try { allowrestart = false; - command.write(stopcmd); - command.newLine(); - command.flush(); + history.add(new LoggedCommand(player, stopcmd)); + if (process != null && process.isAlive()) { + command.write(stopcmd); + command.newLine(); + command.flush(); + } return true; } catch (IOException e) { e.printStackTrace(); @@ -145,12 +157,12 @@ public class InternalSubServer extends SubServer { @Override public boolean terminate(UUID player) { - if (isRunning()) { + if (thread != null && thread.isAlive()) { SubStopEvent event = new SubStopEvent(player, this, true); host.plugin.getPluginManager().callEvent(event); if (!event.isCancelled()) { allowrestart = false; - process.destroyForcibly(); + if (process != null && process.isAlive()) process.destroyForcibly(); return true; } else return false; } else return false; @@ -158,15 +170,18 @@ public class InternalSubServer extends SubServer { @Override public boolean command(UUID player, String command) { - if (isRunning()) { + if (thread != null && thread.isAlive()) { SubSendCommandEvent event = new SubSendCommandEvent(player, this, command); host.plugin.getPluginManager().callEvent(event); if (!event.isCancelled()) { try { if (event.getCommand().equalsIgnoreCase(stopcmd)) allowrestart = false; - this.command.write(event.getCommand()); - this.command.newLine(); - this.command.flush(); + history.add(new LoggedCommand(player, event.getCommand())); + if (process != null && process.isAlive()) { + this.command.write(event.getCommand()); + this.command.newLine(); + this.command.flush(); + } return true; } catch (IOException e) { e.printStackTrace(); @@ -218,6 +233,11 @@ public class InternalSubServer extends SubServer { return logger; } + @Override + public LinkedList getCommandHistory() { + return new LinkedList(history); + } + @Override public String getDirectory() { return dir; @@ -247,4 +267,9 @@ public class InternalSubServer extends SubServer { public boolean isTemporary() { return temporary; } + + @Override + public void setTemporary(boolean value) { + temporary = !(value && !isRunning() && !start()) && value; + } } diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubCreator.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubCreator.java index c152bbfb..c6db82b9 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubCreator.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubCreator.java @@ -70,7 +70,7 @@ public abstract class SubCreator { * * @return Git Bash Directory */ - public abstract String getGitBashDirectory(); + public abstract String getBashDirectory(); /** * Gets the Logger for the creator diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubLogger.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubLogger.java index 3070895e..2b3427af 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubLogger.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubLogger.java @@ -120,7 +120,7 @@ public abstract class SubLogger { * * @return Log Messages (named by log level) */ - public abstract List getMessages(); + public abstract List getMessageHistory(); /** * Register Filter diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubServer.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubServer.java index 13b3b29d..e7ca7901 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubServer.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubServer.java @@ -4,12 +4,87 @@ import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException; import net.ME1312.SubServers.Bungee.Library.NamedContainer; import java.net.InetSocketAddress; +import java.util.Calendar; +import java.util.Date; +import java.util.LinkedList; import java.util.UUID; +import java.util.logging.Level; /** * SubServer Layout Class */ public abstract class SubServer extends Server { + /** + * Command Storage Class + */ + public static class LoggedCommand { + private Date date; + private UUID sender; + private String command; + + /** + * Store a Command + * + * @param command Command + */ + public LoggedCommand(String command) { + this.date = Calendar.getInstance().getTime(); + this.sender = null; + this.command = command; + } + + /** + * Store a Command + * + * @param sender Command Sender (null for CONSOLE) + * @param command Command + */ + public LoggedCommand(UUID sender, String command) { + this.date = Calendar.getInstance().getTime(); + this.sender = sender; + this.command = command; + } + + /** + * Store a Command + * + * @param date Date + * @param sender Command Sender (null for CONSOLE) + * @param command Command + */ + public LoggedCommand(Date date, UUID sender, String command) { + this.date = Calendar.getInstance().getTime(); + this.sender = sender; + this.command = command; + } + + /** + * Get the date this command was logged + * + * @return Date + */ + public Date getDate() { + return date; + } + + /** + * Get the command sender + * + * @return Command Sender (null if CONSOLE) + */ + public UUID getSender() { + return sender; + } + + /** + * Get the command + * + * @return Command + */ + public String getCommand() { + return command; + } + } /** * Creates a SubServer @@ -149,6 +224,13 @@ public abstract class SubServer extends Server { */ public abstract SubLogger getLogger(); + /** + * Gets all the commands that were sent to this SubServer successfully + * + * @return Command History + */ + public abstract LinkedList getCommandHistory(); + /** * Get the Server Directory * @@ -191,5 +273,10 @@ public abstract class SubServer extends Server { */ public abstract boolean isTemporary(); - + /** + * Set If the Server is Temporary (will start server if not running) + * + * @param value Value + */ + public abstract void setTemporary(boolean value); } diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketDownloadHostInfo.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketDownloadHostInfo.java index e419bf58..4814e051 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketDownloadHostInfo.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketDownloadHostInfo.java @@ -57,7 +57,7 @@ public class PacketDownloadHostInfo implements PacketIn, PacketOut { JSONObject cinfo = new JSONObject(); cinfo.put("busy", host.getCreator().isBusy()); - cinfo.put("git-bash", host.getCreator().getGitBashDirectory()); + cinfo.put("git-bash", host.getCreator().getBashDirectory()); info.put("creator", cinfo); JSONObject servers = new JSONObject(); diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/SubDataServer.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/SubDataServer.java index 107f8615..dc0c92ae 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/SubDataServer.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/SubDataServer.java @@ -23,7 +23,7 @@ public final class SubDataServer { private static boolean defaults = false; private HashMap clients = new HashMap(); private ServerSocket server; - private SubPlugin plugin; + protected SubPlugin plugin; /** * SubData Server Instance diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubAPI.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubAPI.java index 52deb9ee..3173c026 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubAPI.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubAPI.java @@ -172,6 +172,26 @@ public final class SubAPI { return getSubServers().get(name.toLowerCase()); } + /** + * Adds to the Language Map + * + * @param key Key + * @param value Lang Value + */ + public void setLang(String key, String value) { + plugin.exLang.put(key, value); + } + + /** + * Gets a value from the SubServers Lang + * + * @param key Key + * @return Lang Value + */ + public String getLang(String key) { + return getLang().get(key); + } + /** * Gets the SubServers Lang * @@ -186,16 +206,6 @@ public final class SubAPI { return lang; } - /** - * Adds to the Language Map - * - * @param key Key - * @param value Lang Value - */ - public void addLang(String key, String value) { - plugin.exLang.put(key, value); - } - /** * Gets the Runtime Directory * @@ -205,6 +215,15 @@ public final class SubAPI { return plugin.dir; } + /** + * Gets the SubServers Beta Version + * + * @return SubServers Beta Version (or null if this is a release version) + */ + public Version getBetaVersion() { + return plugin.bversion; + } + /** * Gets the SubServers Version * @@ -213,4 +232,22 @@ public final class SubAPI { public Version getWrapperVersion() { return plugin.version; } + + /** + * Gets the BungeeCord Version + * + * @return BungeeCord Version + */ + public Version getProxyVersion() { + return new Version(plugin.getVersion()); + } + + /** + * Gets the Recommended Minecraft Version + * + * @return Minecraft Version + */ + public Version getGameVersion() { + return new Version(plugin.getGameVersion()); + } } diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubPlugin.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubPlugin.java index b7555ed2..3041e269 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubPlugin.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubPlugin.java @@ -175,6 +175,9 @@ public final class SubPlugin extends BungeeCord { @Override public void startListeners() { try { + long begin = Calendar.getInstance().getTime().getTime(); + + running = true; config = new YAMLConfig(new UniversalFile(dir, "SubServers:config.yml")); lang = new YAMLConfig(new UniversalFile(dir, "SubServers:lang.yml")); subdata = new SubDataServer(this, Integer.parseInt(config.get().getSection("Settings").getSection("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[1]), 10, @@ -182,7 +185,6 @@ public final class SubPlugin extends BungeeCord { System.out.println("SubServers > SubData Listening on " + subdata.getServer().getLocalSocketAddress().toString()); loop(); - long begin = Calendar.getInstance().getTime().getTime(); int hosts = 0; System.out.println("SubServers > Loading Hosts..."); for (String name : config.get().getSection("Hosts").getKeys()) { @@ -235,8 +237,6 @@ public final class SubPlugin extends BungeeCord { System.out.println("SubServers > " + hosts + " Host(s), " + servers + " Server(s), and " + subservers + " SubServer(s) loaded in " + (Calendar.getInstance().getTime().getTime() - begin) + "ms"); - running = true; - super.startListeners(); } catch (IOException e) { e.printStackTrace(); diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/UIListener.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/InternalHandler.java similarity index 96% rename from SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/UIListener.java rename to SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/InternalHandler.java index b0658e07..1b37288b 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/UIListener.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/InternalHandler.java @@ -24,44 +24,38 @@ import java.util.HashMap; import java.util.UUID; /** - * GUI Listener + * Internal GUI Listener */ -public class UIListener implements Listener { +public class InternalHandler implements UIHandler, Listener { private HashMap input = new HashMap(); - private HashMap gui = new HashMap(); + private HashMap gui = new HashMap(); + private boolean enabled = true; private SubPlugin plugin; /** - * Creates a new GUI Listener + * Creates a new Internal GUI Listener * * @param plugin Event */ - public UIListener(SubPlugin plugin) { + public InternalHandler(SubPlugin plugin) { this.plugin = plugin; Bukkit.getPluginManager().registerEvents(this, plugin); } - /** - * Grabs the current UIRenderer for the player - * - * @param player Player - * @return UIRenderer - */ - public UIRenderer getRenderer(Player player) { - if (!gui.keySet().contains(player.getUniqueId())) gui.put(player.getUniqueId(), new UIRenderer(plugin, player.getUniqueId())); + public InternalRenderer getRenderer(Player player) { + if (!gui.keySet().contains(player.getUniqueId())) gui.put(player.getUniqueId(), new InternalRenderer(plugin, player.getUniqueId())); return gui.get(player.getUniqueId()); } - /** - * Click Listener - * - * @param event Event - */ + public void disable() { + enabled = false; + } + @EventHandler(priority = EventPriority.HIGHEST) public void click(InventoryClickEvent event) { Player player = (Player) event.getWhoClicked(); - if (!event.isCancelled() && gui.keySet().contains(player.getUniqueId())) { - UIRenderer gui = this.gui.get(player.getUniqueId()); + if (!event.isCancelled() && enabled && gui.keySet().contains(player.getUniqueId())) { + InternalRenderer gui = this.gui.get(player.getUniqueId()); if (gui.open && event.getClickedInventory() != null && event.getClickedInventory().getTitle() != null) { if (plugin.subdata == null) { new IllegalStateException("SubData is not connected").printStackTrace(); @@ -212,7 +206,7 @@ public class UIListener implements Listener { } else { player.closeInventory(); Renderer plugin = null; - for (Renderer renderer : UIRenderer.hostPlugins.values()) { + for (Renderer renderer : InternalRenderer.hostPlugins.values()) { if (item.equals(renderer.getIcon().getItemMeta().getDisplayName())) plugin = renderer; } if (plugin == null) { @@ -368,7 +362,7 @@ public class UIListener implements Listener { } else { player.closeInventory(); Renderer plugin = null; - for (Renderer renderer : UIRenderer.subserverPlugins.values()) { + for (Renderer renderer : InternalRenderer.subserverPlugins.values()) { if (item.equals(renderer.getIcon().getItemMeta().getDisplayName())) plugin = renderer; } if (plugin == null) { @@ -392,7 +386,7 @@ public class UIListener implements Listener { @SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.HIGHEST) public void input(org.bukkit.event.player.PlayerChatEvent event) { - if (!event.isCancelled() && input.keySet().contains(event.getPlayer().getUniqueId())) { + if (!event.isCancelled() && enabled && input.keySet().contains(event.getPlayer().getUniqueId())) { JSONObject json = new JSONObject(); json.put("message", event.getMessage()); input.get(event.getPlayer().getUniqueId()).run(json); @@ -408,7 +402,7 @@ public class UIListener implements Listener { */ @EventHandler(priority = EventPriority.HIGHEST) public void input(PlayerCommandPreprocessEvent event) { - if (!event.isCancelled() && input.keySet().contains(event.getPlayer().getUniqueId())) { + if (!event.isCancelled() && enabled && input.keySet().contains(event.getPlayer().getUniqueId())) { JSONObject json = new JSONObject(); json.put("message", event.getMessage()); input.get(event.getPlayer().getUniqueId()).run(json); diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/InternalRenderer.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/InternalRenderer.java new file mode 100644 index 00000000..a66287ce --- /dev/null +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/InternalRenderer.java @@ -0,0 +1,943 @@ +package net.ME1312.SubServers.Client.Bukkit.Graphic; + +import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketDownloadHostInfo; +import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketDownloadServerInfo; +import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketDownloadServerList; +import net.ME1312.SubServers.Client.Bukkit.SubPlugin; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.text.DecimalFormat; +import java.util.*; + +/** + * Internal GUI Renderer Class + */ +public class InternalRenderer extends UIRenderer { + private List windowHistory = new LinkedList(); + protected Options lastUsedOptions = null; + protected String lastVistedObject = null; + protected int lastPage = 1; + protected Runnable lastMenu = null; + protected boolean open = false; + protected final UUID player; + private SubPlugin plugin; + + protected InternalRenderer(SubPlugin plugin, UUID player) { + super(plugin, player); + this.plugin = plugin; + this.player = player; + } + + public void newUI() { + clearHistory(); + if (lastMenu == null) { + hostMenu(1); + } else { + lastMenu.run(); + } + } + + public void clearHistory() { + windowHistory.clear(); + } + + public boolean hasHistory() { + return windowHistory.size() > 1; + } + + public void reopen() { + Runnable lastWindow = windowHistory.get(windowHistory.size() - 1); + windowHistory.remove(windowHistory.size() - 1); + lastWindow.run(); + } + + public void back() { + windowHistory.remove(windowHistory.size() - 1); + reopen(); + } + + public void hostMenu(final int page) { + setDownloading(ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.Title", '&'))); + plugin.subdata.sendPacket(new PacketDownloadServerList(null, UUID.randomUUID().toString(), (json) -> { + setDownloading(null); + lastVistedObject = null; + lastPage = page; + lastMenu = () -> hostMenu(1); + windowHistory.add(() -> hostMenu(page)); + List hosts = new ArrayList(); + hosts.addAll(json.getJSONObject("hosts").keySet()); + + ItemStack block; + ItemMeta blockMeta; + ItemStack div = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15); + ItemMeta divMeta = div.getItemMeta(); + divMeta.setDisplayName(ChatColor.RESET.toString()); + div.setItemMeta(divMeta); + + int i = 0; + int min = ((page - 1) * 36); + int max = (min + 35); + int count = (hosts.size() == 0)?27:((hosts.size() - min - 1 >= max)?36:hosts.size() - min); + int area = (count % 9 == 0) ? count : (int) (Math.floor(count / 9) + 1) * 9; + + Inventory inv = Bukkit.createInventory(null, 18 + area, plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.Title", '&')); + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + block.setItemMeta(divMeta); + while (i < area) { + inv.setItem(i, block); + i++; + } + ItemStack adiv = block; + i = (int) ((count < 9) ? Math.floor((9 - count) / 2) : 0); + + boolean even = (count & 1) == 0 && count < 9; + short enabled, disabled; + + for (String host : hosts) { + if (hosts.indexOf(host) >= min && hosts.indexOf(host) <= max) { + if (even && (i == 4 || i == 13 || i == 22 || i == 31)) inv.setItem(i++, adiv); + enabled = (short) (((i & 1) == 0) ? 3 : 11); + disabled = (short) (((i & 1) == 0) ? 2 : 14); + + if (json.getJSONObject("hosts").getJSONObject(host).getBoolean("enabled")) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, enabled); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.AQUA + host); + blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.Host-Server-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").keySet().size())))); + } else { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, disabled); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.RED + host); + blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.Host-Disabled", '&'))); + } + block.setItemMeta(blockMeta); + inv.setItem(i, block); + + count--; + if (count < 9 && (i == 8 || i == 17 || i == 26)) { + i += (int) Math.floor((9 - count) / 2) + 1; + even = (count & 1) == 0; + } else { + i++; + } + } + } + + if (hosts.size() == 0) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.No-Hosts", '&')); + block.setItemMeta(blockMeta); + inv.setItem(12, block); + inv.setItem(13, block); + inv.setItem(14, block); + } + + i = inv.getSize() - 18; + while (i < inv.getSize()) { + inv.setItem(i, div); + i++; + } + i = inv.getSize() - 9; + + if (min != 0) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back-Arrow", '&')); + block.setItemMeta(blockMeta); + inv.setItem(i++, block); + inv.setItem(i++, block); + } else i += 2; + i++; + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.SubServer-Menu", '&')); + block.setItemMeta(blockMeta); + inv.setItem(i++, block); + inv.setItem(i++, block); + inv.setItem(i++, block); + i++; + if (hosts.size() - 1 > max) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&')); + block.setItemMeta(blockMeta); + inv.setItem(i++, block); + inv.setItem(i, block); + } + + Bukkit.getPlayer(player).openInventory(inv); + open = true; + })); + } + + public void hostAdmin(final String host) { + setDownloading(ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Title", '&').replace("$str$", host))); + plugin.subdata.sendPacket(new PacketDownloadHostInfo(host, UUID.randomUUID().toString(), (json) -> { + windowHistory.add(() -> hostAdmin(host)); + if (!json.getBoolean("valid")) { + if (hasHistory()) back(); + } else { + setDownloading(null); + lastVistedObject = host; + + ItemStack block; + ItemMeta blockMeta; + ItemStack div = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15); + ItemMeta divMeta = div.getItemMeta(); + divMeta.setDisplayName(ChatColor.RESET.toString()); + div.setItemMeta(divMeta); + + Inventory inv = Bukkit.createInventory(null, 36, plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Title", '&').replace("$str$", host)); + + int i = 0; + while (i < inv.getSize()) { + inv.setItem(i, div); + i++; + } + + if (!(Bukkit.getPlayer(player).hasPermission("subservers.host.create.*") || Bukkit.getPlayer(player).hasPermission("subservers.host.create." + host.toLowerCase()))) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Creator", '&'))); + blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Invalid-Permission", '&').replace("$str$", "subservers.host.create." + host.toLowerCase()))); + } else if (!json.getJSONObject("host").getBoolean("enabled") || json.getJSONObject("host").getJSONObject("creator").getBoolean("busy")) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Creator", '&'))); + blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Creator-Busy", '&'))); + } else { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Creator", '&')); + + } + block.setItemMeta(blockMeta); + inv.setItem(1, block); + inv.setItem(2, block); + inv.setItem(3, block); + inv.setItem(10, block); + inv.setItem(11, block); + inv.setItem(12, block); + + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.SubServers", '&')); + block.setItemMeta(blockMeta); + inv.setItem(5, block); + inv.setItem(6, block); + inv.setItem(7, block); + inv.setItem(14, block); + inv.setItem(15, block); + inv.setItem(16, block); + + if (!json.getJSONObject("host").getBoolean("enabled")) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Plugins", '&'))); + } else { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 11); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Plugins", '&')); + } + inv.setItem(27, block); + inv.setItem(28, block); + + if (json.getJSONObject("host").getBoolean("enabled")) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 11); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.AQUA + host); + blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.Host-Server-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("host").getJSONObject("servers").keySet().size())))); + } else { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.RED + host); + blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.Host-Disabled", '&'))); + } + block.setItemMeta(blockMeta); + inv.setItem(30, block); + inv.setItem(31, block); + inv.setItem(32, block); + + + if (hasHistory()) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&')); + block.setItemMeta(blockMeta); + inv.setItem(34, block); + inv.setItem(35, block); + } + + Bukkit.getPlayer(player).openInventory(inv); + open = true; + } + })); + } + + public void hostCreator(final CreatorOptions options) { + setDownloading(ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Title", '&').replace("$str$", options.getHost()))); + lastUsedOptions = options; + if (!options.init()) { + windowHistory.add(() -> hostCreator(options)); + lastVistedObject = options.getHost(); + } + + plugin.subdata.sendPacket(new PacketDownloadHostInfo(options.getHost(), UUID.randomUUID().toString(), json -> { + if (!json.getBoolean("valid")|| !json.getJSONObject("host").getBoolean("enabled") || json.getJSONObject("host").getJSONObject("creator").getBoolean("busy")) { + lastUsedOptions = null; + if (hasHistory()) back(); + } else { + setDownloading(null); + ItemStack block; + ItemMeta blockMeta; + ItemStack div = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15); + ItemMeta divMeta = div.getItemMeta(); + divMeta.setDisplayName(ChatColor.RESET.toString()); + div.setItemMeta(divMeta); + + Inventory inv = Bukkit.createInventory(null, 54, plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Title", '&').replace("$str$", options.getHost())); + + int i = 0; + while (i < inv.getSize()) { + inv.setItem(i, div); + i++; + } + + if (options.getName() == null) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.RED + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Name", '&')); + } else { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.GREEN + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Name", '&')); + blockMeta.setLore(Arrays.asList(ChatColor.GRAY + options.getName())); + } + block.setItemMeta(blockMeta); + inv.setItem(3, block); + inv.setItem(4, block); + inv.setItem(5, block); + + if (options.getType() == null) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.RED + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Type", '&')); + } else { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.GREEN + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Type", '&')); + blockMeta.setLore(Arrays.asList(ChatColor.GRAY + options.getType().toString())); + } + block.setItemMeta(blockMeta); + inv.setItem(10, block); + inv.setItem(11, block); + + if (options.getVersion() == null) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.RED + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Version", '&')); + } else { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.GREEN + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Version", '&')); + blockMeta.setLore(Arrays.asList(ChatColor.GRAY + "v" + options.getVersion().toString())); + } + block.setItemMeta(blockMeta); + inv.setItem(15, block); + inv.setItem(16, block); + + if (options.getPort() <= 0) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.RED + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Port", '&')); + } else { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.GREEN + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Port", '&')); + blockMeta.setLore(Arrays.asList(ChatColor.GRAY.toString() + options.getPort())); + } + block.setItemMeta(blockMeta); + inv.setItem(28, block); + inv.setItem(29, block); + + if (options.getMemory() < 256) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.RED + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-RAM", '&')); + } else { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.GREEN + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-RAM", '&')); + blockMeta.setLore(Arrays.asList(ChatColor.GRAY.toString() + options.getMemory() + "MB")); + } + block.setItemMeta(blockMeta); + inv.setItem(33, block); + inv.setItem(34, block); + + if (!options.hasHistory()) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.GRAY + ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Undo", '&'))); + block.setItemMeta(blockMeta); + } else { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 1); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Undo", '&')); + block.setItemMeta(blockMeta); + } + block.setItemMeta(blockMeta); + inv.setItem(45, block); + inv.setItem(46, block); + + if (options.getName() == null || options.getType() == null || options.getVersion() == null || options.getPort() <= 0 && options.getMemory() < 256) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.GRAY + ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Submit", '&'))); + blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Form-Incomplete", '&'))); + block.setItemMeta(blockMeta); + } else { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Submit", '&')); + block.setItemMeta(blockMeta); + } + block.setItemMeta(blockMeta); + inv.setItem(48, block); + inv.setItem(49, block); + inv.setItem(50, block); + + if (hasHistory()) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&')); + block.setItemMeta(blockMeta); + inv.setItem(52, block); + inv.setItem(53, block); + } + + Bukkit.getPlayer(player).openInventory(inv); + open = true; + } + })); + } + + public void hostPlugin(final int page, final String host) { + setDownloading(ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Plugin.Title", '&').replace("$str$", host))); + plugin.subdata.sendPacket(new PacketDownloadHostInfo(host, UUID.randomUUID().toString(), (json) -> { + windowHistory.add(() -> hostPlugin(page, host)); + if (!json.getBoolean("valid")) { + if (hasHistory()) back(); + } else { + setDownloading(null); + lastVistedObject = host; + lastPage = page; + List renderers = new ArrayList(); + for (String renderer : renderers) { + if (subserverPlugins.get(renderer).isEnabled(host)) renderers.add(renderer); + } + Collections.sort(renderers); + + ItemStack block; + ItemMeta blockMeta; + ItemStack div = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15); + ItemMeta divMeta = div.getItemMeta(); + divMeta.setDisplayName(ChatColor.RESET.toString()); + div.setItemMeta(divMeta); + + int i = 0; + int min = ((page - 1) * 36); + int max = (min + 35); + int count = (renderers.size() == 0)?27:((renderers.size() - min - 1 >= max)?36:renderers.size() - min); + int area = (count % 9 == 0) ? count : (int) (Math.floor(count / 9) + 1) * 9; + + Inventory inv = Bukkit.createInventory(null, 18 + area, plugin.lang.getSection("Lang").getColoredString("Interface.Host-Plugin.Title", '&').replace("$str$", host)); + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + block.setItemMeta(divMeta); + while (i < area) { + inv.setItem(i, block); + i++; + } + ItemStack adiv = block; + i = (int) ((count < 9) ? Math.floor((9 - count) / 2) : 0); + + boolean even = (count & 1) == 0 && count < 9; + + for (String renderer : renderers) { + if (renderers.indexOf(renderer) >= min && renderers.indexOf(renderer) <= max) { + if (even && (i == 4 || i == 13 || i == 22 || i == 31)) inv.setItem(i++, adiv); + + inv.setItem(i, hostPlugins.get(renderer).getIcon()); + + count--; + if (count < 9 && (i == 8 || i == 17 || i == 26)) { + i += (int) Math.floor((9 - count) / 2) + 1; + even = (count & 1) == 0; + } else { + i++; + } + } + } + + if (renderers.size() == 0) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Plugin.No-Plugins", '&')); + block.setItemMeta(blockMeta); + inv.setItem(12, block); + inv.setItem(13, block); + inv.setItem(14, block); + } + + i = inv.getSize() - 18; + while (i < inv.getSize()) { + inv.setItem(i, div); + i++; + } + i = inv.getSize() - 9; + + if (min != 0) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back-Arrow", '&')); + block.setItemMeta(blockMeta); + inv.setItem(i++, block); + inv.setItem(i++, block); + } else i += 2; + i++; + if (hasHistory()) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&')); + block.setItemMeta(blockMeta); + inv.setItem(i++, block); + inv.setItem(i++, block); + inv.setItem(i++, block); + i++; + } + if (renderers.size() - 1 > max) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&')); + block.setItemMeta(blockMeta); + inv.setItem(i++, block); + inv.setItem(i, block); + } + + Bukkit.getPlayer(player).openInventory(inv); + open = true; + } + })); + } + + public void subserverMenu(final int page, final String host) { + setDownloading(ChatColor.stripColor((host == null)?plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.Title", '&'):plugin.lang.getSection("Lang").getColoredString("Interface.Host-SubServer.Title", '&').replace("$str$", host))); + plugin.subdata.sendPacket(new PacketDownloadServerList(host, UUID.randomUUID().toString(), json -> { + setDownloading(null); + lastPage = page; + + HashMap hosts = new HashMap(); + List subservers = new ArrayList(); + if (host != null && json.getJSONObject("hosts").keySet().contains(host)) { + lastVistedObject = host; + for (String subserver : json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").keySet()) { + hosts.put(subserver, host); + subservers.add(subserver); + } + } else { + lastVistedObject = null; + lastMenu = () -> subserverMenu(1, null); + for (String tmphost : json.getJSONObject("hosts").keySet()) { + for (String tmpsubserver : json.getJSONObject("hosts").getJSONObject(tmphost).getJSONObject("servers").keySet()) { + hosts.put(tmpsubserver, tmphost); + subservers.add(tmpsubserver); + } + } + } + Collections.sort(subservers); + windowHistory.add(() -> subserverMenu(page, host)); + + ItemStack block; + ItemMeta blockMeta; + ItemStack div = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15); + ItemMeta divMeta = div.getItemMeta(); + divMeta.setDisplayName(ChatColor.RESET.toString()); + div.setItemMeta(divMeta); + + int i = 0; + int min = ((page - 1) * 36); + int max = (min + 35); + int count = (subservers.size() == 0)?27:((subservers.size() - min - 1 >= max)?36:subservers.size() - min); + int area = (count % 9 == 0) ? count : (int) (Math.floor(count / 9) + 1) * 9; + + Inventory inv = Bukkit.createInventory(null, 18 + area, (host == null)?plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.Title", '&'):plugin.lang.getSection("Lang").getColoredString("Interface.Host-SubServer.Title", '&').replace("$str$", host)); + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + block.setItemMeta(divMeta); + while (i < area) { + inv.setItem(i, block); + i++; + } + ItemStack adiv = block; + i = (int) ((count < 9) ? Math.floor((9 - count) / 2) : 0); + + boolean even = (count & 1) == 0 && count < 9; + short online, temp, offline, disabled; + + for (String subserver : subservers) { + if (subservers.indexOf(subserver) >= min && subservers.indexOf(subserver) <= max) { + if (even && (i == 4 || i == 13 || i == 22 || i == 31)) inv.setItem(i++, adiv); + online = (short) (((i & 1) == 0) ? 5 : 13); + temp = (short) (((i & 1) == 0) ? 3 : 11); + offline = (short) (((i & 1) == 0) ? 4 : 1); + disabled = (short) (((i & 1) == 0) ? 2 : 14); + + if (json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getBoolean("temp")) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, temp); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.AQUA + subserver); + blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Player-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getJSONObject("players").keySet().size())), plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Temporary", '&'))); + } else if (json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getBoolean("running")) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, online); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.GREEN + subserver); + blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Player-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getJSONObject("players").keySet().size())))); + } else if (json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getBoolean("enabled")) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, offline); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.YELLOW + subserver); + blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Offline", '&'))); + } else { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, disabled); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.RED + subserver); + blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Disabled", '&'))); + } + block.setItemMeta(blockMeta); + inv.setItem(i, block); + + count--; + if (count < 9 && (i == 8 || i == 17 || i == 26)) { + i += (int) Math.floor((9 - count) / 2) + 1; + even = (count & 1) == 0; + } else { + i++; + } + } + } + + if (subservers.size() == 0) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.No-SubServers", '&')); + block.setItemMeta(blockMeta); + inv.setItem(12, block); + inv.setItem(13, block); + inv.setItem(14, block); + } + + i = inv.getSize() - 18; + while (i < inv.getSize()) { + inv.setItem(i, div); + i++; + } + i = inv.getSize() - 9; + + if (min != 0) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back-Arrow", '&')); + block.setItemMeta(blockMeta); + inv.setItem(i++, block); + inv.setItem(i++, block); + } else i += 2; + i++; + if (host == null || hasHistory()) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) ((host == null) ? 11 : 14)); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName((host == null) ? plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.Host-Menu", '&') : plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&')); + block.setItemMeta(blockMeta); + inv.setItem(i++, block); + inv.setItem(i++, block); + inv.setItem(i++, block); + i++; + } + if (subservers.size() - 1 > max) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&')); + block.setItemMeta(blockMeta); + inv.setItem(i++, block); + inv.setItem(i, block); + } + + Bukkit.getPlayer(player).openInventory(inv); + open = true; + })); + } + + public void subserverAdmin(final String subserver) { + setDownloading(ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Title", '&').replace("$str$", subserver))); + plugin.subdata.sendPacket(new PacketDownloadServerInfo(subserver, UUID.randomUUID().toString(), json -> { + windowHistory.add(() -> subserverAdmin(subserver)); + if (!json.getString("type").equals("subserver")) { + if (hasHistory()) back(); + } else { + setDownloading(null); + lastVistedObject = subserver; + ItemStack block; + ItemMeta blockMeta; + ItemStack div = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15); + ItemMeta divMeta = div.getItemMeta(); + divMeta.setDisplayName(ChatColor.RESET.toString()); + div.setItemMeta(divMeta); + + Inventory inv = Bukkit.createInventory(null, 36, plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Title", '&').replace("$str$", subserver)); + + int i = 0; + while (i < inv.getSize()) { + inv.setItem(i, div); + i++; + } + i = 0; + + if (json.getJSONObject("server").getBoolean("running")) { + if (!(Bukkit.getPlayer(player).hasPermission("subservers.subserver.terminate.*") || Bukkit.getPlayer(player).hasPermission("subservers.subserver.terminate." + subserver.toLowerCase()))) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Terminate", '&'))); + blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Invalid-Permission", '&').replace("$str$", "subservers.subserver.terminate." + subserver.toLowerCase()))); + } else { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Terminate", '&')); + } + + block.setItemMeta(blockMeta); + inv.setItem(1, block); + inv.setItem(10, block); + + if (!(Bukkit.getPlayer(player).hasPermission("subservers.subserver.stop.*") || Bukkit.getPlayer(player).hasPermission("subservers.subserver.stop." + subserver.toLowerCase()))) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Stop", '&'))); + blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Invalid-Permission", '&').replace("$str$", "subservers.subserver.stop." + subserver.toLowerCase()))); + } else { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 2); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Stop", '&')); + } + block.setItemMeta(blockMeta); + inv.setItem(2, block); + inv.setItem(3, block); + inv.setItem(11, block); + inv.setItem(12, block); + + if (!(Bukkit.getPlayer(player).hasPermission("subservers.subserver.command.*") || Bukkit.getPlayer(player).hasPermission("subservers.subserver.command." + subserver.toLowerCase()))) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Command", '&'))); + blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Invalid-Permission", '&').replace("$str$", "subservers.subserver.command." + subserver.toLowerCase()))); + } else { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Command", '&')); + } + block.setItemMeta(blockMeta); + inv.setItem(5, block); + inv.setItem(6, block); + inv.setItem(7, block); + inv.setItem(14, block); + inv.setItem(15, block); + inv.setItem(16, block); + } else { + if (!(Bukkit.getPlayer(player).hasPermission("subservers.subserver.start.*") || Bukkit.getPlayer(player).hasPermission("subservers.subserver.start." + subserver.toLowerCase()))) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Start", '&'))); + blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Invalid-Permission", '&').replace("$str$", "subservers.subserver.start." + subserver.toLowerCase()))); + } else if (!json.getJSONObject("server").getBoolean("enabled")) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Start", '&'))); + } else { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Start", '&')); + } + block.setItemMeta(blockMeta); + inv.setItem(3, block); + inv.setItem(4, block); + inv.setItem(5, block); + inv.setItem(12, block); + inv.setItem(13, block); + inv.setItem(14, block); + } + + if (!json.getJSONObject("server").getBoolean("enabled")) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Plugins", '&'))); + } else { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 11); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Plugins", '&')); + } + block.setItemMeta(blockMeta); + inv.setItem(27, block); + inv.setItem(28, block); + + if (json.getJSONObject("server").getBoolean("temp")) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 11); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.AQUA + subserver); + blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Player-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("server").getJSONObject("players").keySet().size())), plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Temporary", '&'))); + } else if (json.getJSONObject("server").getBoolean("running")) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.GREEN + subserver); + blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Player-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("server").getJSONObject("players").keySet().size())))); + } else if (json.getJSONObject("server").getBoolean("enabled")) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.YELLOW + subserver); + blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Offline", '&'))); + } else { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.RED + subserver); + blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Disabled", '&'))); + } + block.setItemMeta(blockMeta); + inv.setItem(30, block); + inv.setItem(31, block); + inv.setItem(32, block); + + if (hasHistory()) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&')); + block.setItemMeta(blockMeta); + inv.setItem(34, block); + inv.setItem(35, block); + } + + Bukkit.getPlayer(player).openInventory(inv); + open = true; + } + })); + + } + + public void subserverPlugin(final int page, final String subserver) { + setDownloading(ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Plugin.Title", '&').replace("$str$", subserver))); + plugin.subdata.sendPacket(new PacketDownloadServerInfo(subserver, UUID.randomUUID().toString(), json -> { + windowHistory.add(() -> subserverPlugin(page, subserver)); + if (!json.getString("type").equals("subserver")) { + if (hasHistory()) back(); + } else { + setDownloading(null); + lastVistedObject = subserver; + lastPage = page; + List renderers = new ArrayList(); + for (String renderer : renderers) { + if (subserverPlugins.get(renderer).isEnabled(subserver)) renderers.add(renderer); + } + Collections.sort(renderers); + + ItemStack block; + ItemMeta blockMeta; + ItemStack div = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15); + ItemMeta divMeta = div.getItemMeta(); + divMeta.setDisplayName(ChatColor.RESET.toString()); + div.setItemMeta(divMeta); + + int i = 0; + int min = ((page - 1) * 36); + int max = (min + 35); + int count = (renderers.size() == 0)?27:((renderers.size() - min - 1 >= max)?36:renderers.size() - min); + int area = (count % 9 == 0) ? count : (int) (Math.floor(count / 9) + 1) * 9; + + Inventory inv = Bukkit.createInventory(null, 18 + area, plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Plugin.Title", '&').replace("$str$", subserver)); + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + block.setItemMeta(divMeta); + while (i < area) { + inv.setItem(i, block); + i++; + } + ItemStack adiv = block; + i = (int) ((count < 9) ? Math.floor((9 - count) / 2) : 0); + + boolean even = (count & 1) == 0 && count < 9; + + for (String renderer : renderers) { + if (renderers.indexOf(renderer) >= min && renderers.indexOf(renderer) <= max) { + if (even && (i == 4 || i == 13 || i == 22 || i == 31)) inv.setItem(i++, adiv); + + inv.setItem(i, subserverPlugins.get(renderer).getIcon()); + + count--; + if (count < 9 && (i == 8 || i == 17 || i == 26)) { + i += (int) Math.floor((9 - count) / 2) + 1; + even = (count & 1) == 0; + } else { + i++; + } + } + } + + if (renderers.size() == 0) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Plugin.No-Plugins", '&')); + block.setItemMeta(blockMeta); + inv.setItem(12, block); + inv.setItem(13, block); + inv.setItem(14, block); + } + + i = inv.getSize() - 18; + while (i < inv.getSize()) { + inv.setItem(i, div); + i++; + } + i = inv.getSize() - 9; + + if (min != 0) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back-Arrow", '&')); + block.setItemMeta(blockMeta); + inv.setItem(i++, block); + inv.setItem(i++, block); + } else i += 2; + i++; + if (hasHistory()) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&')); + block.setItemMeta(blockMeta); + inv.setItem(i++, block); + inv.setItem(i++, block); + inv.setItem(i++, block); + i++; + } + if (renderers.size() - 1 > max) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&')); + block.setItemMeta(blockMeta); + inv.setItem(i++, block); + inv.setItem(i, block); + } + + Bukkit.getPlayer(player).openInventory(inv); + open = true; + } + })); + } +} \ No newline at end of file diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/UIHandler.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/UIHandler.java new file mode 100644 index 00000000..82336747 --- /dev/null +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/UIHandler.java @@ -0,0 +1,30 @@ +package net.ME1312.SubServers.Client.Bukkit.Graphic; + +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryClickEvent; + +/** + * GUI Listener Layout Class + */ +public interface UIHandler { + /** + * Grabs the current Renderer for the player + * + * @param player Player + * @return UIRenderer + */ + UIRenderer getRenderer(Player player); + + /** + * Disable Listener + */ + void disable(); + + /** + * Click Listener + * + * @param event Event + */ + void click(InventoryClickEvent event); + +} diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/UIRenderer.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/UIRenderer.java index ae921412..ff6fd731 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/UIRenderer.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/UIRenderer.java @@ -4,71 +4,29 @@ import net.ME1312.SubServers.Client.Bukkit.Library.Container; import net.ME1312.SubServers.Client.Bukkit.Library.NamedContainer; import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version; import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketCreateServer; -import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketDownloadHostInfo; -import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketDownloadServerInfo; -import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketDownloadServerList; import net.ME1312.SubServers.Client.Bukkit.SubPlugin; import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.scheduler.BukkitTask; -import java.text.DecimalFormat; import java.util.*; -public class UIRenderer { +/** + * GUI Renderer Layout Class + */ +public abstract class UIRenderer { protected static HashMap hostPlugins = new HashMap(); protected static HashMap subserverPlugins = new HashMap(); - private List windowHistory = new LinkedList(); - protected Options lastUsedOptions = null; - protected String lastVistedObject = null; - protected int lastPage = 1; - protected Runnable lastMenu = null; private NamedContainer downloading = null; - protected boolean open = false; - protected final UUID player; + private final UUID player; private SubPlugin plugin; /** - * Options Layout Class + * Creates a new UIRenderer + * + * @param plugin SubPlugin + * @param player Player */ - public abstract static class Options { - List history = new LinkedList(); - private boolean init = false; - - boolean init() { - if (!init) { - init = true; - return false; - } else { - return true; - } - } - - /** - * If there is any undo history - * - * @return Undo History Status - */ - public boolean hasHistory() { - return !history.isEmpty(); - } - - /** - * Reverts the last change - */ - public void undo() { - Runnable lastWindow = history.get(history.size() - 1); - history.remove(history.size() - 1); - lastWindow.run(); - } - } - - protected UIRenderer(SubPlugin plugin, UUID player) { + public UIRenderer(SubPlugin plugin, UUID player) { this.plugin = plugin; this.player = player; } @@ -76,47 +34,29 @@ public class UIRenderer { /** * Opens a new window */ - public void newUI() { - clearHistory(); - if (lastMenu == null) { - hostMenu(1); - } else { - lastMenu.run(); - } - } + public abstract void newUI(); /** * Clears the Window History */ - public void clearHistory() { - windowHistory.clear(); - } + public abstract void clearHistory(); /** * If there is any Window History * * @return Window History Status */ - public boolean hasHistory() { - return windowHistory.size() > 1; - } + public abstract boolean hasHistory(); /** * Reopens the current window */ - public void reopen() { - Runnable lastWindow = windowHistory.get(windowHistory.size() - 1); - windowHistory.remove(windowHistory.size() - 1); - lastWindow.run(); - } + public abstract void reopen(); /** * Reopens the previous window */ - public void back() { - windowHistory.remove(windowHistory.size() - 1); - reopen(); - } + public abstract void back(); /** * Attempt to send a Title Message @@ -232,6 +172,24 @@ public class UIRenderer { hostPlugins.put(handle, renderer); } + /** + * Get Host Plugins + * + * @return Host Plugins + */ + public static Map getHostPlugins() { + return new HashMap(hostPlugins); + } + + /** + * Remove Host Plugin + * + * @param handle Handle + */ + public static void removeHostPlugin(String handle) { + hostPlugins.remove(handle); + } + /** * Add SubServer Plugin * @@ -242,385 +200,107 @@ public class UIRenderer { subserverPlugins.put(handle, renderer); } + /** + * Get SubServer Plugins + * + * @return SubServer Plugins + */ + public static Map getSubServerPlugins() { + return new HashMap(subserverPlugins); + } + + /** + * Remove SubServer Plugin + * + * @param handle Handle + */ + public static void removeSubServerPlugin(String handle) { + subserverPlugins.remove(handle); + } + /** * Opens the Host Menu * * @param page Page Number (starting from page 1) */ - public void hostMenu(final Integer page) { - setDownloading(ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.Title", '&'))); - plugin.subdata.sendPacket(new PacketDownloadServerList(null, UUID.randomUUID().toString(), (json) -> { - setDownloading(null); - lastVistedObject = null; - lastPage = page; - lastMenu = () -> hostMenu(1); - windowHistory.add(() -> hostMenu(page)); - List hosts = new ArrayList(); - hosts.addAll(json.getJSONObject("hosts").keySet()); - - ItemStack block; - ItemMeta blockMeta; - ItemStack div = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15); - ItemMeta divMeta = div.getItemMeta(); - divMeta.setDisplayName(ChatColor.RESET.toString()); - div.setItemMeta(divMeta); - - int i = 0; - int min = ((page - 1) * 36); - int max = (min + 35); - int count = (hosts.size() == 0)?27:((hosts.size() - min - 1 >= max)?36:hosts.size() - min); - int area = (count % 9 == 0) ? count : (int) (Math.floor(count / 9) + 1) * 9; - - Inventory inv = Bukkit.createInventory(null, 18 + area, plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.Title", '&')); - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); - block.setItemMeta(divMeta); - while (i < area) { - inv.setItem(i, block); - i++; - } - ItemStack adiv = block; - i = (int) ((count < 9) ? Math.floor((9 - count) / 2) : 0); - - boolean even = (count & 1) == 0 && count < 9; - short enabled, disabled; - - for (String host : hosts) { - if (hosts.indexOf(host) >= min && hosts.indexOf(host) <= max) { - if (even && (i == 4 || i == 13 || i == 22 || i == 31)) inv.setItem(i++, adiv); - enabled = (short) (((i & 1) == 0) ? 3 : 11); - disabled = (short) (((i & 1) == 0) ? 2 : 14); - - if (json.getJSONObject("hosts").getJSONObject(host).getBoolean("enabled")) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, enabled); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.AQUA + host); - blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.Host-Server-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").keySet().size())))); - } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, disabled); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.RED + host); - blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.Host-Disabled", '&'))); - } - block.setItemMeta(blockMeta); - inv.setItem(i, block); - - count--; - if (count < 9 && (i == 8 || i == 17 || i == 26)) { - i += (int) Math.floor((9 - count) / 2) + 1; - even = (count & 1) == 0; - } else { - i++; - } - } - } - - if (hosts.size() == 0) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.No-Hosts", '&')); - block.setItemMeta(blockMeta); - inv.setItem(12, block); - inv.setItem(13, block); - inv.setItem(14, block); - } - - i = inv.getSize() - 18; - while (i < inv.getSize()) { - inv.setItem(i, div); - i++; - } - i = inv.getSize() - 9; - - if (min != 0) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back-Arrow", '&')); - block.setItemMeta(blockMeta); - inv.setItem(i++, block); - inv.setItem(i++, block); - } else i += 2; - i++; - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.SubServer-Menu", '&')); - block.setItemMeta(blockMeta); - inv.setItem(i++, block); - inv.setItem(i++, block); - inv.setItem(i++, block); - i++; - if (hosts.size() - 1 > max) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&')); - block.setItemMeta(blockMeta); - inv.setItem(i++, block); - inv.setItem(i, block); - } - - Bukkit.getPlayer(player).openInventory(inv); - open = true; - })); - } + public abstract void hostMenu(int page); /** * Opens Host/<name> * * @param host Host Name */ - public void hostAdmin(final String host) { - setDownloading(ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Title", '&').replace("$str$", host))); - plugin.subdata.sendPacket(new PacketDownloadHostInfo(host, UUID.randomUUID().toString(), (json) -> { - windowHistory.add(() -> hostAdmin(host)); - if (!json.getBoolean("valid")) { - if (hasHistory()) back(); - } else { - setDownloading(null); - lastVistedObject = host; - - ItemStack block; - ItemMeta blockMeta; - ItemStack div = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15); - ItemMeta divMeta = div.getItemMeta(); - divMeta.setDisplayName(ChatColor.RESET.toString()); - div.setItemMeta(divMeta); - - Inventory inv = Bukkit.createInventory(null, 36, plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Title", '&').replace("$str$", host)); - - int i = 0; - while (i < inv.getSize()) { - inv.setItem(i, div); - i++; - } - - if (!(Bukkit.getPlayer(player).hasPermission("subservers.host.create.*") || Bukkit.getPlayer(player).hasPermission("subservers.host.create." + host.toLowerCase()))) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Creator", '&'))); - blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Invalid-Permission", '&').replace("$str$", "subservers.host.create." + host.toLowerCase()))); - } else if (!json.getJSONObject("host").getBoolean("enabled") || json.getJSONObject("host").getJSONObject("creator").getBoolean("busy")) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Creator", '&'))); - blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Creator-Busy", '&'))); - } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Creator", '&')); - - } - block.setItemMeta(blockMeta); - inv.setItem(1, block); - inv.setItem(2, block); - inv.setItem(3, block); - inv.setItem(10, block); - inv.setItem(11, block); - inv.setItem(12, block); - - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.SubServers", '&')); - block.setItemMeta(blockMeta); - inv.setItem(5, block); - inv.setItem(6, block); - inv.setItem(7, block); - inv.setItem(14, block); - inv.setItem(15, block); - inv.setItem(16, block); - - if (!json.getJSONObject("host").getBoolean("enabled")) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Plugins", '&'))); - } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 11); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Plugins", '&')); - } - inv.setItem(27, block); - inv.setItem(28, block); - - if (json.getJSONObject("host").getBoolean("enabled")) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 11); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.AQUA + host); - blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.Host-Server-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("host").getJSONObject("servers").keySet().size())))); - } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.RED + host); - blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.Host-Disabled", '&'))); - } - block.setItemMeta(blockMeta); - inv.setItem(30, block); - inv.setItem(31, block); - inv.setItem(32, block); - - - if (hasHistory()) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&')); - block.setItemMeta(blockMeta); - inv.setItem(34, block); - inv.setItem(35, block); - } - - Bukkit.getPlayer(player).openInventory(inv); - open = true; - } - })); - } + public abstract void hostAdmin(String host); /** * Opens Host/<name>/Create * * @param options Creator Options */ - public void hostCreator(final CreatorOptions options) { - setDownloading(ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Title", '&').replace("$str$", options.getHost()))); - lastUsedOptions = options; - if (!options.init()) { - windowHistory.add(() -> hostCreator(options)); - lastVistedObject = options.getHost(); + public abstract void hostCreator(CreatorOptions options); + + /** + * Opens Host/<name>/Plugins + * + * @param host Host Name + */ + public abstract void hostPlugin(int page, String host); + + /** + * Opens the SubServer Menu + * + * @param page Page Number (starting from page 1) + * @param host Host Name (or null to scan all hosts) + */ + public abstract void subserverMenu(int page, String host); + + /** + * Opens SubServer/<name> + * + * @param server SubServer Name + */ + public abstract void subserverAdmin(String server); + + /** + * Opens SubServer/<name>/Plugins + * + * @param server SubServer Name + */ + public abstract void subserverPlugin(int page, String server); + + /** + * Options Layout Class + */ + public abstract static class Options { + List history = new LinkedList(); + private boolean init = false; + + public boolean init() { + if (!init) { + init = true; + return false; + } else { + return true; + } } - plugin.subdata.sendPacket(new PacketDownloadHostInfo(options.getHost(), UUID.randomUUID().toString(), json -> { - if (!json.getBoolean("valid")|| !json.getJSONObject("host").getBoolean("enabled") || json.getJSONObject("host").getJSONObject("creator").getBoolean("busy")) { - lastUsedOptions = null; - if (hasHistory()) back(); - } else { - setDownloading(null); - ItemStack block; - ItemMeta blockMeta; - ItemStack div = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15); - ItemMeta divMeta = div.getItemMeta(); - divMeta.setDisplayName(ChatColor.RESET.toString()); - div.setItemMeta(divMeta); + /** + * If there is any undo history + * + * @return Undo History Status + */ + public boolean hasHistory() { + return !history.isEmpty(); + } - Inventory inv = Bukkit.createInventory(null, 54, plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Title", '&').replace("$str$", options.getHost())); - - int i = 0; - while (i < inv.getSize()) { - inv.setItem(i, div); - i++; - } - - if (options.getName() == null) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.RED + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Name", '&')); - } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.GREEN + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Name", '&')); - blockMeta.setLore(Arrays.asList(ChatColor.GRAY + options.getName())); - } - block.setItemMeta(blockMeta); - inv.setItem(3, block); - inv.setItem(4, block); - inv.setItem(5, block); - - if (options.getType() == null) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.RED + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Type", '&')); - } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.GREEN + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Type", '&')); - blockMeta.setLore(Arrays.asList(ChatColor.GRAY + options.getType().toString())); - } - block.setItemMeta(blockMeta); - inv.setItem(10, block); - inv.setItem(11, block); - - if (options.getVersion() == null) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.RED + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Version", '&')); - } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.GREEN + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Version", '&')); - blockMeta.setLore(Arrays.asList(ChatColor.GRAY + "v" + options.getVersion().toString())); - } - block.setItemMeta(blockMeta); - inv.setItem(15, block); - inv.setItem(16, block); - - if (options.getPort() <= 0) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.RED + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Port", '&')); - } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.GREEN + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Port", '&')); - blockMeta.setLore(Arrays.asList(ChatColor.GRAY.toString() + options.getPort())); - } - block.setItemMeta(blockMeta); - inv.setItem(28, block); - inv.setItem(29, block); - - if (options.getMemory() < 256) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.RED + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-RAM", '&')); - } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.GREEN + plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-RAM", '&')); - blockMeta.setLore(Arrays.asList(ChatColor.GRAY.toString() + options.getMemory() + "MB")); - } - block.setItemMeta(blockMeta); - inv.setItem(33, block); - inv.setItem(34, block); - - if (!options.hasHistory()) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.GRAY + ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Undo", '&'))); - block.setItemMeta(blockMeta); - } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 1); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Undo", '&')); - block.setItemMeta(blockMeta); - } - block.setItemMeta(blockMeta); - inv.setItem(45, block); - inv.setItem(46, block); - - if (options.getName() == null || options.getType() == null || options.getVersion() == null || options.getPort() <= 0 && options.getMemory() < 256) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.GRAY + ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Submit", '&'))); - blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Form-Incomplete", '&'))); - block.setItemMeta(blockMeta); - } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Submit", '&')); - block.setItemMeta(blockMeta); - } - block.setItemMeta(blockMeta); - inv.setItem(48, block); - inv.setItem(49, block); - inv.setItem(50, block); - - if (hasHistory()) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&')); - block.setItemMeta(blockMeta); - inv.setItem(52, block); - inv.setItem(53, block); - } - - Bukkit.getPlayer(player).openInventory(inv); - open = true; - } - })); + /** + * Reverts the last change + */ + public void undo() { + Runnable lastWindow = history.get(history.size() - 1); + history.remove(history.size() - 1); + lastWindow.run(); + } } /** @@ -752,539 +432,4 @@ public class UIRenderer { this.port = value; } } - - /** - * Opens Host/<name>/Plugins - * - * @param host Host Name - */ - public void hostPlugin(final Integer page, final String host) { - setDownloading(ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Plugin.Title", '&').replace("$str$", host))); - plugin.subdata.sendPacket(new PacketDownloadHostInfo(host, UUID.randomUUID().toString(), (json) -> { - windowHistory.add(() -> hostPlugin(page, host)); - if (!json.getBoolean("valid")) { - if (hasHistory()) back(); - } else { - setDownloading(null); - lastVistedObject = host; - lastPage = page; - List renderers = new ArrayList(); - for (String renderer : renderers) { - if (subserverPlugins.get(renderer).isEnabled(host)) renderers.add(renderer); - } - Collections.sort(renderers); - - ItemStack block; - ItemMeta blockMeta; - ItemStack div = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15); - ItemMeta divMeta = div.getItemMeta(); - divMeta.setDisplayName(ChatColor.RESET.toString()); - div.setItemMeta(divMeta); - - int i = 0; - int min = ((page - 1) * 36); - int max = (min + 35); - int count = (renderers.size() == 0)?27:((renderers.size() - min - 1 >= max)?36:renderers.size() - min); - int area = (count % 9 == 0) ? count : (int) (Math.floor(count / 9) + 1) * 9; - - Inventory inv = Bukkit.createInventory(null, 18 + area, plugin.lang.getSection("Lang").getColoredString("Interface.Host-Plugin.Title", '&').replace("$str$", host)); - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); - block.setItemMeta(divMeta); - while (i < area) { - inv.setItem(i, block); - i++; - } - ItemStack adiv = block; - i = (int) ((count < 9) ? Math.floor((9 - count) / 2) : 0); - - boolean even = (count & 1) == 0 && count < 9; - - for (String renderer : renderers) { - if (renderers.indexOf(renderer) >= min && renderers.indexOf(renderer) <= max) { - if (even && (i == 4 || i == 13 || i == 22 || i == 31)) inv.setItem(i++, adiv); - - inv.setItem(i, hostPlugins.get(renderer).getIcon()); - - count--; - if (count < 9 && (i == 8 || i == 17 || i == 26)) { - i += (int) Math.floor((9 - count) / 2) + 1; - even = (count & 1) == 0; - } else { - i++; - } - } - } - - if (renderers.size() == 0) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Plugin.No-Plugins", '&')); - block.setItemMeta(blockMeta); - inv.setItem(12, block); - inv.setItem(13, block); - inv.setItem(14, block); - } - - i = inv.getSize() - 18; - while (i < inv.getSize()) { - inv.setItem(i, div); - i++; - } - i = inv.getSize() - 9; - - if (min != 0) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back-Arrow", '&')); - block.setItemMeta(blockMeta); - inv.setItem(i++, block); - inv.setItem(i++, block); - } else i += 2; - i++; - if (hasHistory()) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&')); - block.setItemMeta(blockMeta); - inv.setItem(i++, block); - inv.setItem(i++, block); - inv.setItem(i++, block); - i++; - } - if (renderers.size() - 1 > max) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&')); - block.setItemMeta(blockMeta); - inv.setItem(i++, block); - inv.setItem(i, block); - } - - Bukkit.getPlayer(player).openInventory(inv); - open = true; - } - })); - } - - /** - * Opens the SubServer Menu - * - * @param page Page Number (starting from page 1) - * @param host Host Name (or null to scan all hosts) - */ - public void subserverMenu(final Integer page, final String host) { - setDownloading(ChatColor.stripColor((host == null)?plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.Title", '&'):plugin.lang.getSection("Lang").getColoredString("Interface.Host-SubServer.Title", '&').replace("$str$", host))); - plugin.subdata.sendPacket(new PacketDownloadServerList(host, UUID.randomUUID().toString(), json -> { - setDownloading(null); - lastPage = page; - - HashMap hosts = new HashMap(); - List subservers = new ArrayList(); - if (host != null && json.getJSONObject("hosts").keySet().contains(host)) { - lastVistedObject = host; - for (String subserver : json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").keySet()) { - hosts.put(subserver, host); - subservers.add(subserver); - } - } else { - lastVistedObject = null; - lastMenu = () -> subserverMenu(1, null); - for (String tmphost : json.getJSONObject("hosts").keySet()) { - for (String tmpsubserver : json.getJSONObject("hosts").getJSONObject(tmphost).getJSONObject("servers").keySet()) { - hosts.put(tmpsubserver, tmphost); - subservers.add(tmpsubserver); - } - } - } - Collections.sort(subservers); - windowHistory.add(() -> subserverMenu(page, host)); - - ItemStack block; - ItemMeta blockMeta; - ItemStack div = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15); - ItemMeta divMeta = div.getItemMeta(); - divMeta.setDisplayName(ChatColor.RESET.toString()); - div.setItemMeta(divMeta); - - int i = 0; - int min = ((page - 1) * 36); - int max = (min + 35); - int count = (subservers.size() == 0)?27:((subservers.size() - min - 1 >= max)?36:subservers.size() - min); - int area = (count % 9 == 0) ? count : (int) (Math.floor(count / 9) + 1) * 9; - - Inventory inv = Bukkit.createInventory(null, 18 + area, (host == null)?plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.Title", '&'):plugin.lang.getSection("Lang").getColoredString("Interface.Host-SubServer.Title", '&').replace("$str$", host)); - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); - block.setItemMeta(divMeta); - while (i < area) { - inv.setItem(i, block); - i++; - } - ItemStack adiv = block; - i = (int) ((count < 9) ? Math.floor((9 - count) / 2) : 0); - - boolean even = (count & 1) == 0 && count < 9; - short online, temp, offline, disabled; - - for (String subserver : subservers) { - if (subservers.indexOf(subserver) >= min && subservers.indexOf(subserver) <= max) { - if (even && (i == 4 || i == 13 || i == 22 || i == 31)) inv.setItem(i++, adiv); - online = (short) (((i & 1) == 0) ? 5 : 13); - temp = (short) (((i & 1) == 0) ? 3 : 11); - offline = (short) (((i & 1) == 0) ? 4 : 1); - disabled = (short) (((i & 1) == 0) ? 2 : 14); - - if (json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getBoolean("temp")) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, temp); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.AQUA + subserver); - blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Player-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getJSONObject("players").keySet().size())), plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Temporary", '&'))); - } else if (json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getBoolean("running")) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, online); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.GREEN + subserver); - blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Player-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getJSONObject("players").keySet().size())))); - } else if (json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getBoolean("enabled")) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, offline); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.YELLOW + subserver); - blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Offline", '&'))); - } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, disabled); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.RED + subserver); - blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Disabled", '&'))); - } - block.setItemMeta(blockMeta); - inv.setItem(i, block); - - count--; - if (count < 9 && (i == 8 || i == 17 || i == 26)) { - i += (int) Math.floor((9 - count) / 2) + 1; - even = (count & 1) == 0; - } else { - i++; - } - } - } - - if (subservers.size() == 0) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.No-SubServers", '&')); - block.setItemMeta(blockMeta); - inv.setItem(12, block); - inv.setItem(13, block); - inv.setItem(14, block); - } - - i = inv.getSize() - 18; - while (i < inv.getSize()) { - inv.setItem(i, div); - i++; - } - i = inv.getSize() - 9; - - if (min != 0) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back-Arrow", '&')); - block.setItemMeta(blockMeta); - inv.setItem(i++, block); - inv.setItem(i++, block); - } else i += 2; - i++; - if (host == null || hasHistory()) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) ((host == null) ? 11 : 14)); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName((host == null) ? plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.Host-Menu", '&') : plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&')); - block.setItemMeta(blockMeta); - inv.setItem(i++, block); - inv.setItem(i++, block); - inv.setItem(i++, block); - i++; - } - if (subservers.size() - 1 > max) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&')); - block.setItemMeta(blockMeta); - inv.setItem(i++, block); - inv.setItem(i, block); - } - - Bukkit.getPlayer(player).openInventory(inv); - open = true; - })); - } - - /** - * Opens SubServer/<name> - * - * @param subserver SubServer Name - */ - public void subserverAdmin(final String subserver) { - setDownloading(ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Title", '&').replace("$str$", subserver))); - plugin.subdata.sendPacket(new PacketDownloadServerInfo(subserver, UUID.randomUUID().toString(), json -> { - windowHistory.add(() -> subserverAdmin(subserver)); - if (!json.getString("type").equals("subserver")) { - if (hasHistory()) back(); - } else { - setDownloading(null); - lastVistedObject = subserver; - ItemStack block; - ItemMeta blockMeta; - ItemStack div = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15); - ItemMeta divMeta = div.getItemMeta(); - divMeta.setDisplayName(ChatColor.RESET.toString()); - div.setItemMeta(divMeta); - - Inventory inv = Bukkit.createInventory(null, 36, plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Title", '&').replace("$str$", subserver)); - - int i = 0; - while (i < inv.getSize()) { - inv.setItem(i, div); - i++; - } - i = 0; - - if (json.getJSONObject("server").getBoolean("running")) { - if (!(Bukkit.getPlayer(player).hasPermission("subservers.subserver.terminate.*") || Bukkit.getPlayer(player).hasPermission("subservers.subserver.terminate." + subserver.toLowerCase()))) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Terminate", '&'))); - blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Invalid-Permission", '&').replace("$str$", "subservers.subserver.terminate." + subserver.toLowerCase()))); - } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Terminate", '&')); - } - - block.setItemMeta(blockMeta); - inv.setItem(1, block); - inv.setItem(10, block); - - if (!(Bukkit.getPlayer(player).hasPermission("subservers.subserver.stop.*") || Bukkit.getPlayer(player).hasPermission("subservers.subserver.stop." + subserver.toLowerCase()))) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Stop", '&'))); - blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Invalid-Permission", '&').replace("$str$", "subservers.subserver.stop." + subserver.toLowerCase()))); - } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 2); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Stop", '&')); - } - block.setItemMeta(blockMeta); - inv.setItem(2, block); - inv.setItem(3, block); - inv.setItem(11, block); - inv.setItem(12, block); - - if (!(Bukkit.getPlayer(player).hasPermission("subservers.subserver.command.*") || Bukkit.getPlayer(player).hasPermission("subservers.subserver.command." + subserver.toLowerCase()))) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Command", '&'))); - blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Invalid-Permission", '&').replace("$str$", "subservers.subserver.command." + subserver.toLowerCase()))); - } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Command", '&')); - } - block.setItemMeta(blockMeta); - inv.setItem(5, block); - inv.setItem(6, block); - inv.setItem(7, block); - inv.setItem(14, block); - inv.setItem(15, block); - inv.setItem(16, block); - } else { - if (!(Bukkit.getPlayer(player).hasPermission("subservers.subserver.start.*") || Bukkit.getPlayer(player).hasPermission("subservers.subserver.start." + subserver.toLowerCase()))) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Start", '&'))); - blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Invalid-Permission", '&').replace("$str$", "subservers.subserver.start." + subserver.toLowerCase()))); - } else if (!json.getJSONObject("server").getBoolean("enabled")) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Start", '&'))); - } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Start", '&')); - } - block.setItemMeta(blockMeta); - inv.setItem(3, block); - inv.setItem(4, block); - inv.setItem(5, block); - inv.setItem(12, block); - inv.setItem(13, block); - inv.setItem(14, block); - } - - if (!json.getJSONObject("server").getBoolean("enabled")) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Plugins", '&'))); - } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 11); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Plugins", '&')); - } - block.setItemMeta(blockMeta); - inv.setItem(27, block); - inv.setItem(28, block); - - if (json.getJSONObject("server").getBoolean("temp")) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 11); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.AQUA + subserver); - blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Player-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("server").getJSONObject("players").keySet().size())), plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Temporary", '&'))); - } else if (json.getJSONObject("server").getBoolean("running")) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.GREEN + subserver); - blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Player-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("server").getJSONObject("players").keySet().size())))); - } else if (json.getJSONObject("server").getBoolean("enabled")) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.YELLOW + subserver); - blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Offline", '&'))); - } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.RED + subserver); - blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Disabled", '&'))); - } - block.setItemMeta(blockMeta); - inv.setItem(30, block); - inv.setItem(31, block); - inv.setItem(32, block); - - if (hasHistory()) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&')); - block.setItemMeta(blockMeta); - inv.setItem(34, block); - inv.setItem(35, block); - } - - Bukkit.getPlayer(player).openInventory(inv); - open = true; - } - })); - - } - - /** - * Opens SubServer/<name>/Plugins - * - * @param subserver SubServer Name - */ - public void subserverPlugin(final Integer page, final String subserver) { - setDownloading(ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Plugin.Title", '&').replace("$str$", subserver))); - plugin.subdata.sendPacket(new PacketDownloadServerInfo(subserver, UUID.randomUUID().toString(), json -> { - windowHistory.add(() -> subserverPlugin(page, subserver)); - if (!json.getString("type").equals("subserver")) { - if (hasHistory()) back(); - } else { - setDownloading(null); - lastVistedObject = subserver; - lastPage = page; - List renderers = new ArrayList(); - for (String renderer : renderers) { - if (subserverPlugins.get(renderer).isEnabled(subserver)) renderers.add(renderer); - } - Collections.sort(renderers); - - ItemStack block; - ItemMeta blockMeta; - ItemStack div = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15); - ItemMeta divMeta = div.getItemMeta(); - divMeta.setDisplayName(ChatColor.RESET.toString()); - div.setItemMeta(divMeta); - - int i = 0; - int min = ((page - 1) * 36); - int max = (min + 35); - int count = (renderers.size() == 0)?27:((renderers.size() - min - 1 >= max)?36:renderers.size() - min); - int area = (count % 9 == 0) ? count : (int) (Math.floor(count / 9) + 1) * 9; - - Inventory inv = Bukkit.createInventory(null, 18 + area, plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Plugin.Title", '&').replace("$str$", subserver)); - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); - block.setItemMeta(divMeta); - while (i < area) { - inv.setItem(i, block); - i++; - } - ItemStack adiv = block; - i = (int) ((count < 9) ? Math.floor((9 - count) / 2) : 0); - - boolean even = (count & 1) == 0 && count < 9; - - for (String renderer : renderers) { - if (renderers.indexOf(renderer) >= min && renderers.indexOf(renderer) <= max) { - if (even && (i == 4 || i == 13 || i == 22 || i == 31)) inv.setItem(i++, adiv); - - inv.setItem(i, subserverPlugins.get(renderer).getIcon()); - - count--; - if (count < 9 && (i == 8 || i == 17 || i == 26)) { - i += (int) Math.floor((9 - count) / 2) + 1; - even = (count & 1) == 0; - } else { - i++; - } - } - } - - if (renderers.size() == 0) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Plugin.No-Plugins", '&')); - block.setItemMeta(blockMeta); - inv.setItem(12, block); - inv.setItem(13, block); - inv.setItem(14, block); - } - - i = inv.getSize() - 18; - while (i < inv.getSize()) { - inv.setItem(i, div); - i++; - } - i = inv.getSize() - 9; - - if (min != 0) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back-Arrow", '&')); - block.setItemMeta(blockMeta); - inv.setItem(i++, block); - inv.setItem(i++, block); - } else i += 2; - i++; - if (hasHistory()) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&')); - block.setItemMeta(blockMeta); - inv.setItem(i++, block); - inv.setItem(i++, block); - inv.setItem(i++, block); - i++; - } - if (renderers.size() - 1 > max) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&')); - block.setItemMeta(blockMeta); - inv.setItem(i++, block); - inv.setItem(i, block); - } - - Bukkit.getPlayer(player).openInventory(inv); - open = true; - } - })); - } -} \ No newline at end of file +} diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/Packet/PacketCreateServer.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/Packet/PacketCreateServer.java index dc4ee13b..0c873691 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/Packet/PacketCreateServer.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/Packet/PacketCreateServer.java @@ -1,5 +1,6 @@ package net.ME1312.SubServers.Client.Bukkit.Network.Packet; +import net.ME1312.SubServers.Client.Bukkit.Graphic.InternalRenderer; import net.ME1312.SubServers.Client.Bukkit.Graphic.UIRenderer; import net.ME1312.SubServers.Client.Bukkit.Library.JSONCallback; import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version; diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/SubDataClient.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/SubDataClient.java index 59077e1f..8d76c09c 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/SubDataClient.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/SubDataClient.java @@ -96,7 +96,7 @@ public final class SubDataClient { JSONObject json = new JSONObject(input); for (PacketIn packet : decodePacket(json)) { try { - packet.execute((json.keySet().contains("c")) ? json.getJSONObject("c") : null); + Bukkit.getScheduler().runTask(plugin, () -> packet.execute((json.keySet().contains("c"))?json.getJSONObject("c"):null)); } catch (Exception e) { new InvocationTargetException(e, "Exception while executing PacketIn").printStackTrace(); } diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubAPI.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubAPI.java new file mode 100644 index 00000000..589f7a26 --- /dev/null +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubAPI.java @@ -0,0 +1,133 @@ +package net.ME1312.SubServers.Client.Bukkit; + +import net.ME1312.SubServers.Client.Bukkit.Graphic.UIHandler; +import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version; +import net.ME1312.SubServers.Client.Bukkit.Network.SubDataClient; +import org.bukkit.Bukkit; + +import java.util.HashMap; +import java.util.Map; + +/** + * SubAPI Class + */ +public class SubAPI { + private SubPlugin plugin; + private static SubAPI api; + + protected SubAPI(SubPlugin plugin) { + this.plugin = plugin; + api = this; + } + + /** + * Gets the SubAPI Methods + * + * @return SubAPI + */ + public static SubAPI getInstance() { + return api; + } + + /** + * Gets the SubServers Internals + * + * @deprecated Use SubAPI Methods when available + * @return SubPlugin Internals + */ + @Deprecated + public SubPlugin getInternals() { + return plugin; + } + + /** + * Gets the SubData Network Manager + * + * @return SubData Network Manager + */ + public SubDataClient getSubDataNetwork() { + return plugin.subdata; + } + + /** + * Gets a value from the SubServers Lang + * + * @param key Key + * @return Lang Value + */ + public String getLang(String key) { + return getLang().get(key); + } + + /** + * Gets the SubServers Lang + * + * @return SubServers Lang + */ + public Map getLang() { + HashMap lang = new HashMap(); + for (String key : plugin.lang.getSection("Lang").getKeys()) { + if (plugin.lang.getSection("Lang").isString(key)) lang.put(key, plugin.lang.getSection("Lang").getString(key)); + } + return lang; + } + + /** + * Gets the Graphics Handler + * + * @return Graphics Handler + */ + public UIHandler getGraphicHandler() { + return plugin.gui; + } + + /** + * Sets the Graphics Handler for SubServers to use + * + * @param graphics Graphics Handler + */ + public void setGraphicHandler(UIHandler graphics) { + plugin.gui.disable(); + plugin.gui = graphics; + } + + /** + * Gets the SubServers Beta Version + * + * @return SubServers Beta Version (or null if this is a release version) + */ + public Version getBetaVersion() { + return plugin.bversion; + } + + /** + * Gets the SubServers Version + * + * @return SubServers Version + */ + public Version getPluginVersion() { + return plugin.version; + } + + /** + * Gets the Server Version + * + * @return Server Version + */ + public Version getServerVersion() { + return new Version(Bukkit.getServer().getVersion()); + } + + /** + * Gets the Minecraft Version + * + * @return Minecraft Version + */ + public Version getGameVersion() { + try { + return new Version(Bukkit.getServer().getVersion().split("\\(MC\\: ")[1].split("\\)")[0]); + } catch (ArrayIndexOutOfBoundsException e) { + return new Version(plugin.version.toString().substring(0, plugin.version.toString().length() - 1)); + } + } +} diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubCommand.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubCommand.java index c7d4ad78..9cfdd95c 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubCommand.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubCommand.java @@ -1,5 +1,6 @@ package net.ME1312.SubServers.Client.Bukkit; +import net.ME1312.SubServers.Client.Bukkit.Graphic.InternalRenderer; import net.ME1312.SubServers.Client.Bukkit.Graphic.UIRenderer; import net.ME1312.SubServers.Client.Bukkit.Library.Container; import net.ME1312.SubServers.Client.Bukkit.Library.Util; diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubPlugin.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubPlugin.java index 53f16235..75af2193 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubPlugin.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubPlugin.java @@ -1,6 +1,7 @@ package net.ME1312.SubServers.Client.Bukkit; -import net.ME1312.SubServers.Client.Bukkit.Graphic.UIListener; +import net.ME1312.SubServers.Client.Bukkit.Graphic.InternalHandler; +import net.ME1312.SubServers.Client.Bukkit.Graphic.UIHandler; import net.ME1312.SubServers.Client.Bukkit.Library.Config.YAMLConfig; import net.ME1312.SubServers.Client.Bukkit.Library.Config.YAMLSection; import net.ME1312.SubServers.Client.Bukkit.Library.UniversalFile; @@ -22,11 +23,10 @@ public final class SubPlugin extends JavaPlugin { public YAMLSection lang = null; public SubDataClient subdata = null; - public UIListener gui = null; + public UIHandler gui = null; public final Version version; - public final Version bversion = new Version(2); - - //public final SubAPI api = new SubAPI(this); + public final Version bversion = null; + public final SubAPI api = new SubAPI(this); public SubPlugin() { super(); @@ -55,7 +55,7 @@ public final class SubPlugin extends JavaPlugin { 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); + gui = new InternalHandler(this); SubCommand cmd = new SubCommand(this); getCommand("subservers").setExecutor(cmd); getCommand("subserver").setExecutor(cmd); @@ -71,11 +71,10 @@ public final class SubPlugin extends JavaPlugin { */ @Override public void onDisable() { - if (subdata != null) - try { - subdata.destroy(false); - } catch (IOException e) { - e.printStackTrace(); - } + if (subdata != null) try { + subdata.destroy(false); + } catch (IOException e) { + e.printStackTrace(); + } } } diff --git a/SubServers.Console/src/net/ME1312/SubServers/Console/ConsoleWindow.java b/SubServers.Console/src/net/ME1312/SubServers/Console/ConsoleWindow.java index c3d45634..1b5e8d3b 100644 --- a/SubServers.Console/src/net/ME1312/SubServers/Console/ConsoleWindow.java +++ b/SubServers.Console/src/net/ME1312/SubServers/Console/ConsoleWindow.java @@ -3,6 +3,7 @@ package net.ME1312.SubServers.Console; import net.ME1312.SubServers.Bungee.Host.SubLogFilter; import net.ME1312.SubServers.Bungee.Host.SubLogger; import net.ME1312.SubServers.Bungee.Host.SubServer; +import net.md_5.bungee.api.ProxyServer; import javax.swing.*; import javax.swing.border.Border; @@ -13,6 +14,8 @@ import java.text.SimpleDateFormat; import java.util.*; import java.util.List; import java.util.logging.Level; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class ConsoleWindow implements SubLogFilter { private ConsolePlugin plugin; @@ -122,9 +125,7 @@ public class ConsoleWindow implements SubLogFilter { item.setAccelerator(KeyStroke.getKeyStroke('R', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), true)); item.addActionListener(event -> { log.setText("\n"); - for (SubLogger.LogMessage message : logger.getMessages()) - log(message.getDate(), message.getLevel(), message.getMessage()); - SwingUtilities.invokeLater(this::hScroll); + loadContent(); }); menu.add(item); jMenu.add(menu); @@ -151,7 +152,6 @@ public class ConsoleWindow implements SubLogFilter { }); vScroll.setBorder(BorderFactory.createEmptyBorder()); new SmartScroller(vScroll, SmartScroller.VERTICAL, SmartScroller.END); - log.setText("\n"); log.setBorder(BorderFactory.createLineBorder(new Color(40, 44, 45))); new TextFieldPopup(log, false); ((AbstractDocument) log.getDocument()).setDocumentFilter(new DocumentFilter() { @@ -293,17 +293,19 @@ public class ConsoleWindow implements SubLogFilter { }); - if (!(logger.getHandler() instanceof SubServer)) { + if (logger.getHandler() instanceof SubServer) { + for (SubServer.LoggedCommand command : ((SubServer) logger.getHandler()).getCommandHistory()) popup.commands.add(command.getCommand()); + } else { input.setVisible(false); hScroll.setVisible(false); vScroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); } logger.registerFilter(this); - for (SubLogger.LogMessage message : logger.getMessages()) log(message.getDate(), message.getLevel(), message.getMessage()); + log.setText("\n"); + loadContent(); KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(keys); if (logger.isLogging() && !open) open(); - SwingUtilities.invokeLater(this::hScroll); } private void hScroll() { hScroll.setMaximum(vScroll.getHorizontalScrollBar().getMaximum()); @@ -311,6 +313,28 @@ public class ConsoleWindow implements SubLogFilter { hScroll.setVisibleAmount(vScroll.getHorizontalScrollBar().getVisibleAmount()); } + private void loadContent() { + LinkedList list = new LinkedList(); + list.addAll(logger.getMessageHistory()); + if (logger.getHandler() instanceof SubServer) list.addAll(((SubServer) logger.getHandler()).getCommandHistory()); + list.sort((A, B) -> { + Date a = null, b = null; + + if (A instanceof SubLogger.LogMessage) a = ((SubLogger.LogMessage) A).getDate(); + if (A instanceof SubServer.LoggedCommand) a = ((SubServer.LoggedCommand) A).getDate(); + + if (B instanceof SubLogger.LogMessage) b = ((SubLogger.LogMessage) B).getDate(); + if (B instanceof SubServer.LoggedCommand) b = ((SubServer.LoggedCommand) B).getDate(); + + return (a == null || b == null)?0:a.compareTo(b); + }); + for (Object obj : list) { + if (obj instanceof SubLogger.LogMessage) log(((SubLogger.LogMessage) obj).getDate(), ((SubLogger.LogMessage) obj).getLevel(), ((SubLogger.LogMessage) obj).getMessage()); + if (obj instanceof SubServer.LoggedCommand) log(((SubServer.LoggedCommand) obj).getDate(), '<' + ((((SubServer.LoggedCommand) obj).getSender() == null)?"CONSOLE":((ProxyServer.getInstance().getPlayer(((SubServer.LoggedCommand) obj).getSender()) == null)?((SubServer.LoggedCommand) obj).getSender().toString():ProxyServer.getInstance().getPlayer(((SubServer.LoggedCommand) obj).getSender()).getName())) + "> /" + ((SubServer.LoggedCommand) obj).getCommand()); + } + SwingUtilities.invokeLater(this::hScroll); + } + public SubLogger getLogger() { return logger; } @@ -356,6 +380,7 @@ public class ConsoleWindow implements SubLogFilter { @Override public void stop() { close(); + clear(); } public void close() { SwingUtilities.invokeLater(() -> {