From 648adeb1c201ae4398ba6f1e37eacf36106c2c3a Mon Sep 17 00:00:00 2001 From: ME1312 Date: Sun, 21 Oct 2018 00:18:40 -0400 Subject: [PATCH] Update GalaxiEngine --- .../ME1312/SubServers/Bungee/SubPlugin.java | 43 +++++----------- SubServers.Host/pom.xml | 2 +- .../ME1312/SubServers/Host/SubCommand.java | 51 +++++++++++++++---- .../net/ME1312/SubServers/Sync/SubPlugin.java | 43 +++++----------- 4 files changed, 69 insertions(+), 70 deletions(-) diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubPlugin.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubPlugin.java index 97aabdd3..f39da889 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubPlugin.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubPlugin.java @@ -726,47 +726,32 @@ public final class SubPlugin extends BungeeCord implements Listener { @EventHandler(priority = Byte.MIN_VALUE) public void fallback(ServerKickEvent e) { if (e.getPlayer().getPendingConnection().getListener().isForceDefault()) { - ServerInfo next = null; + NamedContainer next = null; for (String name : e.getPlayer().getPendingConnection().getListener().getServerPriority()) { if (!e.getKickedFrom().getName().equalsIgnoreCase(name)) { ServerInfo server = getServerInfo(name); if (server != null) { - if (next == null) { - next = server; - } else { - int current = 0; - if (next instanceof Server) { - if (!((Server) next).isHidden()) current++; - if (!((Server) next).isRestricted()) current++; - if (((Server) next).getSubData() != null) current++; + int confidence = 0; + if (server instanceof Server) { + if (!((Server) server).isHidden()) confidence++; + if (!((Server) server).isRestricted()) confidence++; + if (((Server) server).getSubData() != null) confidence++; - if (next instanceof SubServer) { - if (((SubServer) next).isRunning()) current++; - } - } - - int proposed = 0; - if (server instanceof Server) { - if (!((Server) server).isHidden()) proposed++; - if (!((Server) server).isRestricted()) proposed++; - if (((Server) server).getSubData() != null) proposed++; - - if (server instanceof SubServer) { - if (((SubServer) server).isRunning()) proposed++; - } - } - - if (proposed > current) - next = server; + if (server instanceof SubServer) { + if (((SubServer) server).isRunning()) confidence++; + } else confidence++; } + + if (next == null || confidence > next.name()) + next = new NamedContainer(confidence, server); } } } if (next != null) { - e.setCancelServer(next); + e.setCancelServer(next.get()); e.setCancelled(true); - e.getPlayer().sendMessage(api.getLang("SubServers", "Bungee.Feature.Return").replace("$str$", (next instanceof Server)?((Server) next).getDisplayName():next.getName()).replace("$msg$", e.getKickReason())); + e.getPlayer().sendMessage(api.getLang("SubServers", "Bungee.Feature.Return").replace("$str$", (next.get() instanceof Server)?((Server) next.get()).getDisplayName():next.get().getName()).replace("$msg$", e.getKickReason())); } } } diff --git a/SubServers.Host/pom.xml b/SubServers.Host/pom.xml index f9ed6448..089315a5 100644 --- a/SubServers.Host/pom.xml +++ b/SubServers.Host/pom.xml @@ -20,7 +20,7 @@ net.ME1312.Galaxi GalaxiEngine - 18w42a + 18w43a compile diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/SubCommand.java b/SubServers.Host/src/net/ME1312/SubServers/Host/SubCommand.java index 4a630ab9..9ddd530b 100644 --- a/SubServers.Host/src/net/ME1312/SubServers/Host/SubCommand.java +++ b/SubServers.Host/src/net/ME1312/SubServers/Host/SubCommand.java @@ -1,13 +1,16 @@ package net.ME1312.SubServers.Host; import net.ME1312.Galaxi.Engine.GalaxiEngine; +import net.ME1312.Galaxi.Engine.PluginManager; import net.ME1312.Galaxi.Library.Util; import net.ME1312.Galaxi.Library.Version.Version; -import net.ME1312.Galaxi.Plugin.Command; +import net.ME1312.Galaxi.Plugin.Command.Command; +import net.ME1312.Galaxi.Plugin.Command.CommandSender; import net.ME1312.SubServers.Host.Library.TextColor; import net.ME1312.SubServers.Host.Network.API.*; import net.ME1312.SubServers.Host.Network.Packet.*; +import java.lang.reflect.Field; import java.util.*; /** @@ -15,10 +18,11 @@ import java.util.*; */ public class SubCommand { private SubCommand() {} + @SuppressWarnings("unchecked") protected static void load(ExHost host) { new Command(host.info) { @Override - public void command(String handle, String[] args) { + public void command(CommandSender sender, String handle, String[] args) { if (args.length > 0) { int i = 0; String str = args[0]; @@ -28,10 +32,35 @@ public class SubCommand { str = str + " " + args[i].replace(" ", "\\ "); } while ((i + 1) != args.length); } - GalaxiEngine.getInstance().getConsoleReader().runCommand(str); + GalaxiEngine.getInstance().getConsoleReader().runCommand(sender, str); } } - }.usage("", "[Args...]").description("An alias for commands").help( + }.autocomplete((sender, handle, args) -> { + if (args.length <= 1) { + String last = (args.length > 0)?args[args.length - 1].toLowerCase():""; + TreeMap commands; + try { + Field f = PluginManager.class.getDeclaredField("commands"); + f.setAccessible(true); + commands = (TreeMap) f.get(GalaxiEngine.getInstance().getPluginManager()); + f.setAccessible(false); + } catch (Exception e) { + e.printStackTrace(); + commands = new TreeMap(); + } + if (last.length() == 0) { + return commands.keySet().toArray(new String[0]); + } else { + List list = new ArrayList(); + for (String command : commands.keySet()) { + if (command.toLowerCase().startsWith(last)) list.add(command); + } + return list.toArray(new String[0]); + } + } else { + return new String[0]; + } + }).usage("", "[Args...]").description("An alias for commands").help( "This command is an alias for all registered commands for ease of use.", "", "Examples:", @@ -40,7 +69,7 @@ public class SubCommand { ).register("sub", "subserver", "subservers"); new Command(host.info) { @Override - public void command(String handle, String[] args) { + public void command(CommandSender sender, String handle, String[] args) { host.api.getGroups(groups -> host.api.getHosts(hosts -> host.api.getServers(servers -> host.api.getMasterProxy(proxymaster -> host.api.getProxies(proxies -> { int i = 0; boolean sent = false; @@ -146,7 +175,7 @@ public class SubCommand { ).register("list"); new Command(host.info) { @Override - public void command(String handle, String[] args) { + public void command(CommandSender sender, String handle, String[] args) { if (args.length > 0) { String type = (args.length > 1)?args[0]:null; String name = args[(type != null)?1:0]; @@ -285,7 +314,7 @@ public class SubCommand { ).register("info", "status"); new Command(host.info) { @Override - public void command(String handle, String[] args) { + public void command(CommandSender sender, String handle, String[] args) { if (args.length > 0) { host.subdata.sendPacket(new PacketStartServer(null, args[0], data -> { switch (data.getInt("r")) { @@ -336,7 +365,7 @@ public class SubCommand { ).register("start"); new Command(host.info) { @Override - public void command(String handle, String[] args) { + public void command(CommandSender sender, String handle, String[] args) { if (args.length > 0) { host.subdata.sendPacket(new PacketStopServer(null, args[0], false, data -> { switch (data.getInt("r")) { @@ -376,7 +405,7 @@ public class SubCommand { ).register("stop"); new Command(host.info) { @Override - public void command(String handle, String[] args) { + public void command(CommandSender sender, String handle, String[] args) { if (args.length > 0) { host.subdata.sendPacket(new PacketStopServer(null, args[0], true, data -> { switch (data.getInt("r")) { @@ -416,7 +445,7 @@ public class SubCommand { ).register("kill", "terminate"); new Command(host.info) { @Override - public void command(String handle, String[] args) { + public void command(CommandSender sender, String handle, String[] args) { if (args.length > 1) { int i = 1; String str = args[1]; @@ -467,7 +496,7 @@ public class SubCommand { ).register("cmd", "command"); new Command(host.info) { @Override - public void command(String handle, String[] args) { + public void command(CommandSender sender, String handle, String[] args) { if (args.length > 3) { if (args.length > 4 && Util.isException(() -> Integer.parseInt(args[4]))) { host.log.message.println("Invalid Port Number"); diff --git a/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubPlugin.java b/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubPlugin.java index 14d2c645..918ae2ea 100644 --- a/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubPlugin.java +++ b/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubPlugin.java @@ -255,47 +255,32 @@ public final class SubPlugin extends BungeeCord implements Listener { @EventHandler(priority = Byte.MIN_VALUE) public void fallback(ServerKickEvent e) { if (e.getPlayer().getPendingConnection().getListener().isForceDefault()) { - ServerInfo next = null; + NamedContainer next = null; for (String name : e.getPlayer().getPendingConnection().getListener().getServerPriority()) { if (!e.getKickedFrom().getName().equalsIgnoreCase(name)) { ServerInfo server = getServerInfo(name); if (server != null) { - if (next == null) { - next = server; - } else { - int current = 0; - if (next instanceof ServerContainer) { - if (!((ServerContainer) next).isHidden()) current++; - if (!((ServerContainer) next).isRestricted()) current++; - if (((ServerContainer) next).getSubData() != null) current++; + int confidence = 0; + if (server instanceof ServerContainer) { + if (!((ServerContainer) server).isHidden()) confidence++; + if (!((ServerContainer) server).isRestricted()) confidence++; + if (((ServerContainer) server).getSubData() != null) confidence++; - if (next instanceof SubServerContainer) { - if (((SubServerContainer) next).isRunning()) current++; - } - } - - int proposed = 0; - if (server instanceof ServerContainer) { - if (!((ServerContainer) server).isHidden()) proposed++; - if (!((ServerContainer) server).isRestricted()) proposed++; - if (((ServerContainer) server).getSubData() != null) proposed++; - - if (server instanceof SubServerContainer) { - if (((SubServerContainer) server).isRunning()) proposed++; - } - } - - if (proposed > current) - next = server; + if (server instanceof SubServerContainer) { + if (((SubServerContainer) server).isRunning()) confidence++; + } else confidence++; } + + if (next == null || confidence > next.name()) + next = new NamedContainer(confidence, server); } } } if (next != null) { - e.setCancelServer(next); + e.setCancelServer(next.get()); e.setCancelled(true); - e.getPlayer().sendMessage(api.getLang("SubServers", "Bungee.Feature.Return").replace("$str$", (next instanceof ServerContainer)?((ServerContainer) next).getDisplayName():next.getName()).replace("$msg$", e.getKickReason())); + e.getPlayer().sendMessage(api.getLang("SubServers", "Bungee.Feature.Return").replace("$str$", (next.get() instanceof ServerContainer)?((ServerContainer) next.get()).getDisplayName():next.get().getName()).replace("$msg$", e.getKickReason())); } } }