Update GalaxiEngine

This commit is contained in:
ME1312 2018-10-21 00:18:40 -04:00
parent 3b9b4ac566
commit 648adeb1c2
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
4 changed files with 69 additions and 70 deletions

View File

@ -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<Integer, ServerInfo> 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++;
if (next instanceof SubServer) {
if (((SubServer) next).isRunning()) current++;
}
}
int proposed = 0;
int confidence = 0;
if (server instanceof Server) {
if (!((Server) server).isHidden()) proposed++;
if (!((Server) server).isRestricted()) proposed++;
if (((Server) server).getSubData() != null) proposed++;
if (!((Server) server).isHidden()) confidence++;
if (!((Server) server).isRestricted()) confidence++;
if (((Server) server).getSubData() != null) confidence++;
if (server instanceof SubServer) {
if (((SubServer) server).isRunning()) proposed++;
}
if (((SubServer) server).isRunning()) confidence++;
} else confidence++;
}
if (proposed > current)
next = server;
}
if (next == null || confidence > next.name())
next = new NamedContainer<Integer, ServerInfo>(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()));
}
}
}

View File

@ -20,7 +20,7 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiEngine</artifactId>
<version>18w42a</version>
<version>18w43a</version>
<scope>compile</scope>
</dependency>
<dependency>

View File

@ -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("<Command>", "[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<String, Command> commands;
try {
Field f = PluginManager.class.getDeclaredField("commands");
f.setAccessible(true);
commands = (TreeMap<String, Command>) f.get(GalaxiEngine.getInstance().getPluginManager());
f.setAccessible(false);
} catch (Exception e) {
e.printStackTrace();
commands = new TreeMap<String, Command>();
}
if (last.length() == 0) {
return commands.keySet().toArray(new String[0]);
} else {
List<String> list = new ArrayList<String>();
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("<Command>", "[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");

View File

@ -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<Integer, ServerInfo> 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++;
if (next instanceof SubServerContainer) {
if (((SubServerContainer) next).isRunning()) current++;
}
}
int proposed = 0;
int confidence = 0;
if (server instanceof ServerContainer) {
if (!((ServerContainer) server).isHidden()) proposed++;
if (!((ServerContainer) server).isRestricted()) proposed++;
if (((ServerContainer) server).getSubData() != null) proposed++;
if (!((ServerContainer) server).isHidden()) confidence++;
if (!((ServerContainer) server).isRestricted()) confidence++;
if (((ServerContainer) server).getSubData() != null) confidence++;
if (server instanceof SubServerContainer) {
if (((SubServerContainer) server).isRunning()) proposed++;
}
if (((SubServerContainer) server).isRunning()) confidence++;
} else confidence++;
}
if (proposed > current)
next = server;
}
if (next == null || confidence > next.name())
next = new NamedContainer<Integer, ServerInfo>(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()));
}
}
}