Rewrite the SubServers.Console commands

This commit is contained in:
ME1312 2019-01-06 20:32:53 -05:00
parent 3635fea2f5
commit 06898964ce
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
6 changed files with 239 additions and 186 deletions

View File

@ -0,0 +1,217 @@
package net.ME1312.SubServers.Console;
import net.ME1312.SubServers.Bungee.Host.Host;
import net.ME1312.SubServers.Bungee.Host.SubServer;
import net.ME1312.SubServers.Bungee.Library.Callback;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.command.ConsoleCommandSender;
import java.util.List;
import java.util.Map;
@SuppressWarnings("unchecked")
public final class ConsoleCommand {
private ConsoleCommand() {}
public static class POPOUT extends Command {
private ConsolePlugin plugin;
private String label;
public POPOUT(ConsolePlugin plugin, String command) {
super(command);
this.plugin = plugin;
this.label = command;
}
@Override
public void execute(final CommandSender sender, String[] args) {
if (sender instanceof ConsoleCommandSender) {
if (args.length > 0) {
final String type = (args.length > 1)?args[0]:null;
final String name = args[(type != null)?1:0];
final Runnable forServer = new Runnable() {
@Override
public void run() {
SubServer server = plugin.getProxy().api.getSubServer(name);
if (server != null) {
if (server.isRunning()) {
System.out.println("SubConsole > Opening console window...");
if (!plugin.sCurrent.keySet().contains(name.toLowerCase())) {
ConsoleWindow window = new ConsoleWindow(plugin, server.getLogger());
plugin.sCurrent.put(name.toLowerCase(), window);
window.open();
} else {
plugin.sCurrent.get(name.toLowerCase()).open();
}
} else {
sender.sendMessage("SubConsole > That SubServer is not running right now");
}
} else {
if (type == null) {
sender.sendMessage("SubServers > There is no object with that name");
} else {
sender.sendMessage("SubServers > There is no subserver with that name");
}
}
}
};
final Runnable forCreator = new Runnable() {
@Override
public void run() {
Host host = plugin.getProxy().api.getHost(name);
if (host != null) {
if (host.getCreator().getReservedNames().size() > 0) {
sender.sendMessage("SubConsole > Opening console window" + ((host.getCreator().getReservedNames().size() == 1)?"":"s") + "...");
for (String reserved : host.getCreator().getReservedNames()) {
if (!plugin.cCurrent.keySet().contains(reserved.toLowerCase())) {
ConsoleWindow window = new ConsoleWindow(plugin, host.getCreator().getLogger(reserved));
plugin.cCurrent.put(reserved.toLowerCase(), window);
window.open();
} else {
plugin.cCurrent.get(reserved.toLowerCase()).open();
}
}
} else {
sender.sendMessage("SubConsole > That Host is not running SubCreator right now");
}
} else {
if (type == null) {
forServer.run();
} else {
sender.sendMessage("SubConsole > There is no host with that name");
}
}
}
};
if (type == null) {
forCreator.run();
} else {
switch (type.toLowerCase()) {
case "h":
case "host":
case "c":
case "creator":
case "subcreator":
forCreator.run();
break;
case "s":
case "server":
case "subserver":
forServer.run();
break;
default:
sender.sendMessage("SubConsole > There is no object type with that name");
}
}
} else {
System.out.println("SubConsole > Usage: /" + label + " [host|server] <Name>");
}
} else {
String str = label;
for (String arg : args) str += ' ' + arg;
((ProxiedPlayer) sender).chat(str);
}
}
}
public static class AUTO_POPOUT extends Command {
private ConsolePlugin plugin;
private String label;
public AUTO_POPOUT(ConsolePlugin plugin, String command) {
super(command);
this.plugin = plugin;
this.label = command;
}
@Override
public void execute(final CommandSender sender, String[] args) {
if (sender instanceof ConsoleCommandSender) {
if (args.length > 0) {
final String type = (args.length > 1)?args[0]:null;
final String name = args[(type != null)?1:0];
final Runnable forServer = new Runnable() {
@Override
public void run() {
SubServer server = plugin.getProxy().api.getSubServer(name);
List<String> list = plugin.config.get().getStringList("Enabled-Servers");
if (!plugin.config.get().getStringList("Enabled-Servers").contains(name.toLowerCase())) {
list.add(name.toLowerCase());
if (server == null) plugin.getProxy().getLogger().warning("SubConsole > SubServer with name \"" + name + "\" does not exist");
sender.sendMessage("SubConsole > " + ((server == null)?name:server.getName()) + " will now popout its console by default");
} else {
list.remove(name.toLowerCase());
sender.sendMessage("SubConsole > " + ((server == null)?name:server.getName()) + " will no longer popout its console by default");
}
plugin.config.get().set("Enabled-Servers", list);
try {
plugin.config.save();
} catch (Exception e) {
e.printStackTrace();
}
}
};
final Callback<Boolean> forCreator = new Callback<Boolean>() {
@Override
public void run(Boolean force) {
Host host = plugin.getProxy().api.getHost(name);
if (force || host != null) {
List<String> list = plugin.config.get().getStringList("Enabled-Creators");
if (!plugin.config.get().getStringList("Enabled-Creators").contains(name.toLowerCase())) {
list.add(name.toLowerCase());
if (host == null) plugin.getProxy().getLogger().warning("SubConsole > Host with name \"" + name + "\" does not exist");
sender.sendMessage("SubConsole > " + ((host == null)?name:host.getName()) + " will now popout SubCreator's console by default");
} else {
list.remove(name.toLowerCase());
sender.sendMessage("SubConsole > " + ((host == null)?name:host.getName()) + " will no longer popout SubCreator's console by default");
}
plugin.config.get().set("Enabled-Creators", list);
try {
plugin.config.save();
} catch (Exception e) {
e.printStackTrace();
}
} else {
forServer.run();
}
}
};
if (type == null) {
forCreator.run(false);
} else {
switch (type.toLowerCase()) {
case "h":
case "host":
case "c":
case "creator":
case "subcreator":
forCreator.run(true);
break;
case "s":
case "server":
case "subserver":
forServer.run();
break;
default:
sender.sendMessage("SubConsole > There is no object type with that name");
}
}
} else {
System.out.println("SubConsole > Usage: /" + label + " [host|server] <Name>");
}
} else {
String str = label;
for (String arg : args) str += ' ' + arg;
((ProxiedPlayer) sender).chat(str);
}
}
}
}

View File

Before

Width:  |  Height:  |  Size: 79 KiB

After

Width:  |  Height:  |  Size: 79 KiB

View File

@ -55,9 +55,9 @@ public final class ConsolePlugin extends Plugin implements Listener {
if (save) config.save();
getProxy().getPluginManager().registerListener(this, this);
getProxy().getPluginManager().registerCommand(this, new PopoutCommand.SERVER(this, "popout"));
getProxy().getPluginManager().registerCommand(this, new PopoutCommand.SERVER(this, "popouts"));
getProxy().getPluginManager().registerCommand(this, new PopoutCommand.CREATOR(this, "popoutc"));
getProxy().getPluginManager().registerCommand(this, new ConsoleCommand.POPOUT(this, "popout"));
getProxy().getPluginManager().registerCommand(this, new ConsoleCommand.AUTO_POPOUT(this, "apopout"));
getProxy().getPluginManager().registerCommand(this, new ConsoleCommand.AUTO_POPOUT(this, "autopopout"));
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
@ -72,23 +72,29 @@ public final class ConsolePlugin extends Plugin implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onServerCreate(SubCreateEvent event) {
if (!event.isCancelled() && config.get().getStringList("Enabled-Creators").contains(event.getHost().getName().toLowerCase())) {
if (!event.isCancelled()) {
if (!cCurrent.keySet().contains(event.getHost().getName().toLowerCase())) {
cCurrent.put(event.getName().toLowerCase(), new ConsoleWindow(this, event.getHost().getCreator().getLogger(event.getName().toLowerCase())));
} else {
cCurrent.get(event.getName().toLowerCase()).clear();
}
if (config.get().getStringList("Enabled-Creators").contains(event.getHost().getName().toLowerCase()))
cCurrent.get(event.getName().toLowerCase()).open();
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onServerStart(SubStartEvent event) {
if (!event.isCancelled() && config.get().getStringList("Enabled-Servers").contains(event.getServer().getName().toLowerCase())) {
if (!event.isCancelled()) {
if (!sCurrent.keySet().contains(event.getServer().getName().toLowerCase())) {
sCurrent.put(event.getServer().getName().toLowerCase(), new ConsoleWindow(this, event.getServer().getLogger()));
} else {
sCurrent.get(event.getServer().getName().toLowerCase()).clear();
}
if (config.get().getStringList("Enabled-Servers").contains(event.getServer().getName().toLowerCase()))
sCurrent.get(event.getServer().getName().toLowerCase()).open();
}
}
@ -102,16 +108,12 @@ public final class ConsolePlugin extends Plugin implements Listener {
public void onClose(ConsoleWindow window) {
if (window.getLogger().getHandler() instanceof SubServer) {
SubServer server = (SubServer) window.getLogger().getHandler();
if (!config.get().getStringList("Enabled-Servers").contains(server.getName().toLowerCase())) {
window.destroy();
sCurrent.remove(server.getName().toLowerCase());
}
window.destroy();
sCurrent.remove(server.getName().toLowerCase());
} else if (window.getLogger().getHandler() instanceof SubCreator) {
Host host = ((SubCreator) window.getLogger().getHandler()).getHost();
if (!config.get().getStringList("Enabled-Creators").contains(host.getName().toLowerCase())) {
window.destroy();
sCurrent.remove(host.getName().toLowerCase());
}
window.destroy();
sCurrent.remove(host.getName().toLowerCase());
} else {
window.destroy();
}

View File

@ -24,7 +24,7 @@ import java.util.List;
import java.util.logging.Level;
public final class ConsoleWindow implements SubLogFilter {
private static final int MAX_SCROLLBACK = (Integer.getInteger("subservers.console.max_scrollback", 15000) >= 128)?Integer.getInteger("subservers.console.max_scrollback", 15000):15000;
private static final int MAX_SCROLLBACK = (Integer.getInteger("subservers.console.max_scrollback", 0) >= 128)?Integer.getInteger("subservers.console.max_scrollback"):15000;
private static final String RESET_VALUE = "\n\u00A0\n\u00A0";
private ConsolePlugin plugin;
private JFrame window;
@ -326,7 +326,7 @@ public final class ConsoleWindow implements SubLogFilter {
Util.isException(new Util.ExceptionRunnable() {
@Override
public void run() throws Throwable {
window.setIconImage(ImageIO.read(ConsolePlugin.class.getResourceAsStream("/SubServers.png")));
window.setIconImage(ImageIO.read(ConsolePlugin.class.getResourceAsStream("/net/ME1312/SubServers/Console/ConsoleIcon.png")));
}
});
window.setTitle(logger.getName() + " \u2014 SubServers 2");
@ -558,7 +558,6 @@ public final class ConsoleWindow implements SubLogFilter {
log.setText(RESET_VALUE);
loadContent();
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(keys);
if (logger.isLogging() && !open) open();
}
private void hScroll() {
hScroll.setMaximum(vScroll.getHorizontalScrollBar().getMaximum());
@ -597,10 +596,6 @@ public final class ConsoleWindow implements SubLogFilter {
hScroll();
}
@Override
public void start() {
open();
}
public void open() {
if (!open) {
window.setVisible(true);
@ -613,6 +608,8 @@ public final class ConsoleWindow implements SubLogFilter {
return open;
}
@Override
public void start() {}
private void loadContent() {
if (file != null) {
try (FileInputStream reader = new FileInputStream(file)) {
@ -629,18 +626,9 @@ public final class ConsoleWindow implements SubLogFilter {
@Override
public void stop() {
close();
clear();
if (filewriter != null) try {
filewriter.close();
} catch (Exception e) {}
if (file != null) try {
filewriter = new FileOutputStream(file, false);
} catch (Exception e) {
e.printStackTrace();
}
plugin.onClose(this);
}
public void close() {
if (open) {
this.open = false;
@ -650,7 +638,6 @@ public final class ConsoleWindow implements SubLogFilter {
findO = 0;
}
window.setVisible(false);
plugin.onClose(this);
}
}

View File

@ -1,153 +0,0 @@
package net.ME1312.SubServers.Console;
import net.ME1312.SubServers.Bungee.Host.Host;
import net.ME1312.SubServers.Bungee.Host.SubServer;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.command.ConsoleCommandSender;
import java.util.List;
import java.util.Map;
public final class PopoutCommand {
private PopoutCommand() {}
public static class SERVER extends Command {
private ConsolePlugin plugin;
private String label;
public SERVER(ConsolePlugin plugin, String command) {
super(command);
this.plugin = plugin;
this.label = command;
}
@Override
public void execute(CommandSender sender, String[] args) {
if (sender instanceof ConsoleCommandSender) {
if (args.length > 0) {
Map<String, SubServer> servers = plugin.getProxy().api.getSubServers();
if (servers.keySet().contains(args[0].toLowerCase())) {
boolean success = false;
if (servers.get(args[0].toLowerCase()).isRunning()) {
if (!plugin.sCurrent.keySet().contains(args[0].toLowerCase())) {
ConsoleWindow window = new ConsoleWindow(plugin, servers.get(args[0].toLowerCase()).getLogger());
plugin.sCurrent.put(args[0].toLowerCase(), window);
window.open();
} else {
plugin.sCurrent.get(args[0].toLowerCase()).open();
}
System.out.println("SubConsole > Opening Window...");
success = true;
}
try {
if (args.length > 1) {
if (args[1].equalsIgnoreCase("true")) {
if (!plugin.config.get().getStringList("Enabled-Servers").contains(args[0].toLowerCase())) {
List<String> list = plugin.config.get().getStringList("Enabled-Servers");
list.add(args[0].toLowerCase());
plugin.config.get().set("Enabled-Servers", list);
plugin.config.save();
}
if (!success) System.out.println("SubConsole > " + servers.get(args[0].toLowerCase()).getName() + " was added to the enabled list");
success = true;
} else if (args[1].equalsIgnoreCase("false")) {
List<String> list = plugin.config.get().getStringList("Enabled-Servers");
list.remove(args[0].toLowerCase());
plugin.config.get().set("Enabled-Servers", list);
if (plugin.sCurrent.keySet().contains(args[0].toLowerCase()) && !plugin.sCurrent.get(args[0].toLowerCase()).isOpen()) plugin.onClose(plugin.sCurrent.get(args[0].toLowerCase()));
plugin.config.save();
if (!success) System.out.println("SubConsole > " + servers.get(args[0].toLowerCase()).getName() + " was removed from the enabled list");
success = true;
}
}
} catch (Exception e) {
e.printStackTrace();
}
if (!success) System.out.println("SubConsole > That SubServer is not running right now.");
} else {
System.out.println("SubConsole > There is no SubServer with that name.");
}
} else {
System.out.println("SubConsole > Usage: /" + label + " <SubServer> [Remember]");
}
} else {
String str = label;
for (String arg : args) str += ' ' + arg;
((ProxiedPlayer) sender).chat(str);
}
}
}
public static class CREATOR extends Command {
private ConsolePlugin plugin;
private String label;
public CREATOR(ConsolePlugin plugin, String command) {
super(command);
this.plugin = plugin;
this.label = command;
}
@Override
public void execute(CommandSender sender, String[] args) {
if (sender instanceof ConsoleCommandSender) {
if (args.length > 0) {
Map<String, Host> hosts = plugin.getProxy().api.getHosts();
if (hosts.keySet().contains(args[0].toLowerCase())) {
boolean success = false;
if (hosts.get(args[0].toLowerCase()).getCreator().getReservedNames().size() > 0) {
if (!plugin.cCurrent.keySet().contains(args[0].toLowerCase())) {
for (String reserved : hosts.get(args[0].toLowerCase()).getCreator().getReservedNames()) {
ConsoleWindow window = new ConsoleWindow(plugin, hosts.get(args[0].toLowerCase()).getCreator().getLogger(reserved));
plugin.cCurrent.put(reserved.toLowerCase(), window);
window.open();
}
} else {
plugin.cCurrent.get(args[0].toLowerCase()).open();
}
System.out.println("SubConsole > Opening Windows...");
success = true;
}
try {
if (args.length > 1) {
if (args[1].equalsIgnoreCase("true")) {
if (!plugin.config.get().getStringList("Enabled-Creators").contains(args[0].toLowerCase())) {
List<String> list = plugin.config.get().getStringList("Enabled-Creators");
list.add(args[0].toLowerCase());
plugin.config.get().set("Enabled-Creators", list);
plugin.config.save();
}
if (!success) System.out.println("SubConsole > " + hosts.get(args[0].toLowerCase()).getName() + "/Creator was added to the enabled list");
success = true;
} else if (args[1].equalsIgnoreCase("false")) {
List<String> list = plugin.config.get().getStringList("Enabled-Creators");
list.remove(args[0].toLowerCase());
plugin.config.get().set("Enabled-Creators", list);
if (plugin.cCurrent.keySet().contains(args[0].toLowerCase()) && !plugin.cCurrent.get(args[0].toLowerCase()).isOpen()) plugin.onClose(plugin.cCurrent.get(args[0].toLowerCase()));
plugin.config.save();
if (!success) System.out.println("SubConsole > " + hosts.get(args[0].toLowerCase()).getName() + "/Creator was removed from the enabled list");
success = true;
}
}
} catch (Exception e) {
e.printStackTrace();
}
if (!success) System.out.println("SubConsole > That Host's Creator is not running right now.");
} else {
System.out.println("SubConsole > There is no Host with that name.");
}
} else {
System.out.println("SubConsole > Usage: /" + label + " <Host> [Remember]");
}
} else {
String str = label;
for (String arg : args) str += ' ' + arg;
((ProxiedPlayer) sender).chat(str);
}
}
}
}

View File

@ -20,7 +20,7 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiEngine</artifactId>
<version>19w02c</version>
<version>19w02d</version>
<scope>compile</scope>
</dependency>
<dependency>