mirror of
https://github.com/BGHDDevelopment/PlayerBalancer.git
synced 2024-11-04 09:59:56 +01:00
Implemented position system
This commit is contained in:
parent
5fba98449e
commit
7a49c4e31d
@ -31,13 +31,6 @@ public class FallbackCommand extends Command {
|
||||
ServerSection section = plugin.getSectionManager().getByServer(player.getServer().getInfo());
|
||||
|
||||
if (section != null) {
|
||||
/* TODO REFERENCE TO ServerKickListener
|
||||
if (ConfigEntries.FALLBACK_COMMAND_RESTRICTED.get() && section.isPrincipal()) {
|
||||
msgr.send(ConfigEntries.UNAVAILABLE_MESSAGE.get());
|
||||
return null;
|
||||
}
|
||||
*/
|
||||
|
||||
if ((ConfigEntries.FALLBACK_COMMAND_IGNORED_SECTIONS.get()).contains(section.getName())) {
|
||||
msgr.send(ConfigEntries.UNAVAILABLE_MESSAGE.get());
|
||||
return null;
|
||||
@ -56,7 +49,17 @@ public class FallbackCommand extends Command {
|
||||
String bind = rules.getString(section.getName());
|
||||
ServerSection target = plugin.getSectionManager().getByName(bind);
|
||||
|
||||
return target == null ? section.getParent() : target;
|
||||
if (target == null) {
|
||||
target = section.getParent();
|
||||
}
|
||||
|
||||
if (ConfigEntries.RECONNECT_KICK_RESTRICTED.get()) {
|
||||
if (target.getPosition() < 0) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
} else {
|
||||
if (ConfigEntries.FALLBACK_PRINCIPAL_ENABLED.get()) {
|
||||
|
@ -90,6 +90,9 @@ public class ManageCommand extends Command {
|
||||
msgr.send("&7Parent: &bNone");
|
||||
}
|
||||
|
||||
msgr.send("&7Position: &b{position}",
|
||||
new Replacement("{position}", String.valueOf(section.getPosition())));
|
||||
|
||||
msgr.send("&7Provider: &b{name} &7({relation}&7)",
|
||||
new Replacement("{name}", section.getProvider().name()),
|
||||
new Replacement("{relation}", section.hasInheritedProvider() ? "Inherited" : "Specified"));
|
||||
|
@ -83,22 +83,9 @@ public class ServerKickListener implements Listener {
|
||||
}
|
||||
|
||||
if (ConfigEntries.RECONNECT_KICK_RESTRICTED.get()) {
|
||||
//todo 0 is principal section
|
||||
//todo -1 is parent of principal
|
||||
//todo 1 is child of principal
|
||||
if (target.getPosition() < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
if (section.isPrincipal()) {
|
||||
todo: check if target is parent of section (or more parents of section)
|
||||
todo: I think that instead of checking if the player is in a principal section we should check
|
||||
todo: if the target section is above the parent section
|
||||
|
||||
return null;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
return target;
|
||||
|
@ -10,30 +10,12 @@ import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ServerSection {
|
||||
private static transient final Function<ServerSection, Integer> function = (section) -> {
|
||||
if (section.isPrincipal()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int iterations = 0;
|
||||
while (true) {
|
||||
section = section.getParent();
|
||||
iterations++;
|
||||
|
||||
if (section == null) {
|
||||
return iterations;
|
||||
} else if (section.isPrincipal()) {
|
||||
return -iterations;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private transient final Configuration section;
|
||||
|
||||
private final String name;
|
||||
@ -127,7 +109,40 @@ public class ServerSection {
|
||||
}
|
||||
|
||||
void postInit(LobbyBalancer plugin) {
|
||||
position = function.apply(this);
|
||||
Callable<Integer> callable = () -> {
|
||||
int iterations = 0;
|
||||
|
||||
//Calculate above principal
|
||||
ServerSection current = this;
|
||||
while (current != null) {
|
||||
if (current.isPrincipal()) {
|
||||
return iterations;
|
||||
}
|
||||
|
||||
current = current.getParent();
|
||||
iterations++;
|
||||
}
|
||||
|
||||
//Calculate below principal
|
||||
iterations = 0;
|
||||
current = plugin.getSectionManager().getPrincipal();
|
||||
while (current != null) {
|
||||
if (current.equals(this)) {
|
||||
return iterations;
|
||||
}
|
||||
|
||||
current = current.getParent();
|
||||
iterations--;
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
try {
|
||||
position = callable.call();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (provider == null) {
|
||||
ServerSection sect = this.parent;
|
||||
|
Loading…
Reference in New Issue
Block a user