mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-25 19:56:24 +01:00
Update GalaxiEngine
This commit is contained in:
parent
3b9b4ac566
commit
648adeb1c2
@ -726,47 +726,32 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
|||||||
@EventHandler(priority = Byte.MIN_VALUE)
|
@EventHandler(priority = Byte.MIN_VALUE)
|
||||||
public void fallback(ServerKickEvent e) {
|
public void fallback(ServerKickEvent e) {
|
||||||
if (e.getPlayer().getPendingConnection().getListener().isForceDefault()) {
|
if (e.getPlayer().getPendingConnection().getListener().isForceDefault()) {
|
||||||
ServerInfo next = null;
|
NamedContainer<Integer, ServerInfo> next = null;
|
||||||
for (String name : e.getPlayer().getPendingConnection().getListener().getServerPriority()) {
|
for (String name : e.getPlayer().getPendingConnection().getListener().getServerPriority()) {
|
||||||
if (!e.getKickedFrom().getName().equalsIgnoreCase(name)) {
|
if (!e.getKickedFrom().getName().equalsIgnoreCase(name)) {
|
||||||
ServerInfo server = getServerInfo(name);
|
ServerInfo server = getServerInfo(name);
|
||||||
if (server != null) {
|
if (server != null) {
|
||||||
if (next == null) {
|
int confidence = 0;
|
||||||
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;
|
|
||||||
if (server instanceof Server) {
|
if (server instanceof Server) {
|
||||||
if (!((Server) server).isHidden()) proposed++;
|
if (!((Server) server).isHidden()) confidence++;
|
||||||
if (!((Server) server).isRestricted()) proposed++;
|
if (!((Server) server).isRestricted()) confidence++;
|
||||||
if (((Server) server).getSubData() != null) proposed++;
|
if (((Server) server).getSubData() != null) confidence++;
|
||||||
|
|
||||||
if (server instanceof SubServer) {
|
if (server instanceof SubServer) {
|
||||||
if (((SubServer) server).isRunning()) proposed++;
|
if (((SubServer) server).isRunning()) confidence++;
|
||||||
}
|
} else confidence++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (proposed > current)
|
if (next == null || confidence > next.name())
|
||||||
next = server;
|
next = new NamedContainer<Integer, ServerInfo>(confidence, server);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (next != null) {
|
if (next != null) {
|
||||||
e.setCancelServer(next);
|
e.setCancelServer(next.get());
|
||||||
e.setCancelled(true);
|
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()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.ME1312.Galaxi</groupId>
|
<groupId>net.ME1312.Galaxi</groupId>
|
||||||
<artifactId>GalaxiEngine</artifactId>
|
<artifactId>GalaxiEngine</artifactId>
|
||||||
<version>18w42a</version>
|
<version>18w43a</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
package net.ME1312.SubServers.Host;
|
package net.ME1312.SubServers.Host;
|
||||||
|
|
||||||
import net.ME1312.Galaxi.Engine.GalaxiEngine;
|
import net.ME1312.Galaxi.Engine.GalaxiEngine;
|
||||||
|
import net.ME1312.Galaxi.Engine.PluginManager;
|
||||||
import net.ME1312.Galaxi.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import net.ME1312.Galaxi.Library.Version.Version;
|
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.Library.TextColor;
|
||||||
import net.ME1312.SubServers.Host.Network.API.*;
|
import net.ME1312.SubServers.Host.Network.API.*;
|
||||||
import net.ME1312.SubServers.Host.Network.Packet.*;
|
import net.ME1312.SubServers.Host.Network.Packet.*;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -15,10 +18,11 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
public class SubCommand {
|
public class SubCommand {
|
||||||
private SubCommand() {}
|
private SubCommand() {}
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
protected static void load(ExHost host) {
|
protected static void load(ExHost host) {
|
||||||
new Command(host.info) {
|
new Command(host.info) {
|
||||||
@Override
|
@Override
|
||||||
public void command(String handle, String[] args) {
|
public void command(CommandSender sender, String handle, String[] args) {
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
String str = args[0];
|
String str = args[0];
|
||||||
@ -28,10 +32,35 @@ public class SubCommand {
|
|||||||
str = str + " " + args[i].replace(" ", "\\ ");
|
str = str + " " + args[i].replace(" ", "\\ ");
|
||||||
} while ((i + 1) != args.length);
|
} 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.",
|
"This command is an alias for all registered commands for ease of use.",
|
||||||
"",
|
"",
|
||||||
"Examples:",
|
"Examples:",
|
||||||
@ -40,7 +69,7 @@ public class SubCommand {
|
|||||||
).register("sub", "subserver", "subservers");
|
).register("sub", "subserver", "subservers");
|
||||||
new Command(host.info) {
|
new Command(host.info) {
|
||||||
@Override
|
@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 -> {
|
host.api.getGroups(groups -> host.api.getHosts(hosts -> host.api.getServers(servers -> host.api.getMasterProxy(proxymaster -> host.api.getProxies(proxies -> {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
boolean sent = false;
|
boolean sent = false;
|
||||||
@ -146,7 +175,7 @@ public class SubCommand {
|
|||||||
).register("list");
|
).register("list");
|
||||||
new Command(host.info) {
|
new Command(host.info) {
|
||||||
@Override
|
@Override
|
||||||
public void command(String handle, String[] args) {
|
public void command(CommandSender sender, String handle, String[] args) {
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
String type = (args.length > 1)?args[0]:null;
|
String type = (args.length > 1)?args[0]:null;
|
||||||
String name = args[(type != null)?1:0];
|
String name = args[(type != null)?1:0];
|
||||||
@ -285,7 +314,7 @@ public class SubCommand {
|
|||||||
).register("info", "status");
|
).register("info", "status");
|
||||||
new Command(host.info) {
|
new Command(host.info) {
|
||||||
@Override
|
@Override
|
||||||
public void command(String handle, String[] args) {
|
public void command(CommandSender sender, String handle, String[] args) {
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
host.subdata.sendPacket(new PacketStartServer(null, args[0], data -> {
|
host.subdata.sendPacket(new PacketStartServer(null, args[0], data -> {
|
||||||
switch (data.getInt("r")) {
|
switch (data.getInt("r")) {
|
||||||
@ -336,7 +365,7 @@ public class SubCommand {
|
|||||||
).register("start");
|
).register("start");
|
||||||
new Command(host.info) {
|
new Command(host.info) {
|
||||||
@Override
|
@Override
|
||||||
public void command(String handle, String[] args) {
|
public void command(CommandSender sender, String handle, String[] args) {
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
host.subdata.sendPacket(new PacketStopServer(null, args[0], false, data -> {
|
host.subdata.sendPacket(new PacketStopServer(null, args[0], false, data -> {
|
||||||
switch (data.getInt("r")) {
|
switch (data.getInt("r")) {
|
||||||
@ -376,7 +405,7 @@ public class SubCommand {
|
|||||||
).register("stop");
|
).register("stop");
|
||||||
new Command(host.info) {
|
new Command(host.info) {
|
||||||
@Override
|
@Override
|
||||||
public void command(String handle, String[] args) {
|
public void command(CommandSender sender, String handle, String[] args) {
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
host.subdata.sendPacket(new PacketStopServer(null, args[0], true, data -> {
|
host.subdata.sendPacket(new PacketStopServer(null, args[0], true, data -> {
|
||||||
switch (data.getInt("r")) {
|
switch (data.getInt("r")) {
|
||||||
@ -416,7 +445,7 @@ public class SubCommand {
|
|||||||
).register("kill", "terminate");
|
).register("kill", "terminate");
|
||||||
new Command(host.info) {
|
new Command(host.info) {
|
||||||
@Override
|
@Override
|
||||||
public void command(String handle, String[] args) {
|
public void command(CommandSender sender, String handle, String[] args) {
|
||||||
if (args.length > 1) {
|
if (args.length > 1) {
|
||||||
int i = 1;
|
int i = 1;
|
||||||
String str = args[1];
|
String str = args[1];
|
||||||
@ -467,7 +496,7 @@ public class SubCommand {
|
|||||||
).register("cmd", "command");
|
).register("cmd", "command");
|
||||||
new Command(host.info) {
|
new Command(host.info) {
|
||||||
@Override
|
@Override
|
||||||
public void command(String handle, String[] args) {
|
public void command(CommandSender sender, String handle, String[] args) {
|
||||||
if (args.length > 3) {
|
if (args.length > 3) {
|
||||||
if (args.length > 4 && Util.isException(() -> Integer.parseInt(args[4]))) {
|
if (args.length > 4 && Util.isException(() -> Integer.parseInt(args[4]))) {
|
||||||
host.log.message.println("Invalid Port Number");
|
host.log.message.println("Invalid Port Number");
|
||||||
|
@ -255,47 +255,32 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
|||||||
@EventHandler(priority = Byte.MIN_VALUE)
|
@EventHandler(priority = Byte.MIN_VALUE)
|
||||||
public void fallback(ServerKickEvent e) {
|
public void fallback(ServerKickEvent e) {
|
||||||
if (e.getPlayer().getPendingConnection().getListener().isForceDefault()) {
|
if (e.getPlayer().getPendingConnection().getListener().isForceDefault()) {
|
||||||
ServerInfo next = null;
|
NamedContainer<Integer, ServerInfo> next = null;
|
||||||
for (String name : e.getPlayer().getPendingConnection().getListener().getServerPriority()) {
|
for (String name : e.getPlayer().getPendingConnection().getListener().getServerPriority()) {
|
||||||
if (!e.getKickedFrom().getName().equalsIgnoreCase(name)) {
|
if (!e.getKickedFrom().getName().equalsIgnoreCase(name)) {
|
||||||
ServerInfo server = getServerInfo(name);
|
ServerInfo server = getServerInfo(name);
|
||||||
if (server != null) {
|
if (server != null) {
|
||||||
if (next == null) {
|
int confidence = 0;
|
||||||
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;
|
|
||||||
if (server instanceof ServerContainer) {
|
if (server instanceof ServerContainer) {
|
||||||
if (!((ServerContainer) server).isHidden()) proposed++;
|
if (!((ServerContainer) server).isHidden()) confidence++;
|
||||||
if (!((ServerContainer) server).isRestricted()) proposed++;
|
if (!((ServerContainer) server).isRestricted()) confidence++;
|
||||||
if (((ServerContainer) server).getSubData() != null) proposed++;
|
if (((ServerContainer) server).getSubData() != null) confidence++;
|
||||||
|
|
||||||
if (server instanceof SubServerContainer) {
|
if (server instanceof SubServerContainer) {
|
||||||
if (((SubServerContainer) server).isRunning()) proposed++;
|
if (((SubServerContainer) server).isRunning()) confidence++;
|
||||||
}
|
} else confidence++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (proposed > current)
|
if (next == null || confidence > next.name())
|
||||||
next = server;
|
next = new NamedContainer<Integer, ServerInfo>(confidence, server);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (next != null) {
|
if (next != null) {
|
||||||
e.setCancelServer(next);
|
e.setCancelServer(next.get());
|
||||||
e.setCancelled(true);
|
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()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user