mirror of
https://github.com/BGHDDevelopment/PlayerBalancer.git
synced 2024-11-23 11:15:30 +01:00
Fixed issues with the router
This commit is contained in:
parent
b29254fd7b
commit
25d70548c9
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
<name>PlayerBalancer Plugin</name>
|
<name>PlayerBalancer Plugin</name>
|
||||||
<artifactId>playerbalancer-plugin</artifactId>
|
<artifactId>playerbalancer-plugin</artifactId>
|
||||||
<version>2.1.5.2</version>
|
<version>2.1.5.3</version>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<finalName>PlayerBalancer</finalName>
|
<finalName>PlayerBalancer</finalName>
|
||||||
|
@ -17,20 +17,30 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import static com.jaimemartz.playerbalancer.utils.MessageUtils.safeNull;
|
import static com.jaimemartz.playerbalancer.utils.MessageUtils.safeNull;
|
||||||
|
|
||||||
public abstract class ConnectionIntent {
|
public abstract class ConnectionIntent {
|
||||||
protected final PlayerBalancer plugin;
|
private final PlayerBalancer plugin;
|
||||||
protected final ProxiedPlayer player;
|
private final ProxiedPlayer player;
|
||||||
protected final ServerSection section;
|
private final ServerSection section;
|
||||||
|
private final List<ServerInfo> exclusions;
|
||||||
|
|
||||||
public ConnectionIntent(PlayerBalancer plugin, ProxiedPlayer player, ProviderType provider, ServerSection section, List<ServerInfo> servers) {
|
public ConnectionIntent(PlayerBalancer plugin, ProxiedPlayer player, ServerSection section) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.section = tryRoute(player, section);
|
this.section = tryRoute(player, section);
|
||||||
|
this.exclusions = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ServerInfo> getExclusions() {
|
||||||
|
return exclusions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean execute() {
|
||||||
MessageUtils.send(player, plugin.getSettings().getMessagesProps().getConnectingMessage(),
|
MessageUtils.send(player, plugin.getSettings().getMessagesProps().getConnectingMessage(),
|
||||||
(str) -> str.replace("{section}", section.getName())
|
(str) -> str.replace("{section}", section.getName())
|
||||||
.replace("{alias}", safeNull(section.getProps().getAlias()))
|
.replace("{alias}", safeNull(section.getProps().getAlias()))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
List<ServerInfo> servers = new ArrayList<>(section.getServers());
|
||||||
|
|
||||||
//Prevents removing servers from the section
|
//Prevents removing servers from the section
|
||||||
if (servers == section.getServers()) {
|
if (servers == section.getServers()) {
|
||||||
throw new IllegalStateException("The servers list parameter is the same reference, this cannot happen");
|
throw new IllegalStateException("The servers list parameter is the same reference, this cannot happen");
|
||||||
@ -43,7 +53,7 @@ public abstract class ConnectionIntent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (section.getImplicitProvider() != ProviderType.NONE) {
|
if (section.getImplicitProvider() != ProviderType.NONE) {
|
||||||
ServerInfo target = this.fetchServer(player, section, provider, servers);
|
ServerInfo target = this.fetchServer(player, section, section.getImplicitProvider(), servers);
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
this.connect(target, (response, throwable) -> {
|
this.connect(target, (response, throwable) -> {
|
||||||
if (response) { //only if the connect has been executed correctly
|
if (response) { //only if the connect has been executed correctly
|
||||||
@ -58,18 +68,8 @@ public abstract class ConnectionIntent {
|
|||||||
MessageUtils.send(player, plugin.getSettings().getMessagesProps().getFailureMessage());
|
MessageUtils.send(player, plugin.getSettings().getMessagesProps().getFailureMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public ConnectionIntent(PlayerBalancer plugin, ProxiedPlayer player, ServerSection section) {
|
return false;
|
||||||
this(plugin, player, section.getImplicitProvider(), section);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConnectionIntent(PlayerBalancer plugin, ProxiedPlayer player, ProviderType type, ServerSection section) {
|
|
||||||
this(plugin, player, type, section, new ArrayList<>(section.getServers()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConnectionIntent(PlayerBalancer plugin, ProxiedPlayer player, ServerSection section, List<ServerInfo> servers) {
|
|
||||||
this(plugin, player, section.getImplicitProvider(), section, servers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ServerInfo fetchServer(ProxiedPlayer player, ServerSection section, ProviderType provider, List<ServerInfo> servers) {
|
private ServerInfo fetchServer(ProxiedPlayer player, ServerSection section, ProviderType provider, List<ServerInfo> servers) {
|
||||||
@ -104,16 +104,17 @@ public abstract class ConnectionIntent {
|
|||||||
private ServerSection tryRoute(ProxiedPlayer player, ServerSection section) {
|
private ServerSection tryRoute(ProxiedPlayer player, ServerSection section) {
|
||||||
if (plugin.getSettings().getFeaturesProps().getPermissionRouterProps().isEnabled()) {
|
if (plugin.getSettings().getFeaturesProps().getPermissionRouterProps().isEnabled()) {
|
||||||
Map<String, String> routes = plugin.getSettings().getFeaturesProps().getPermissionRouterProps().getRules().get(section.getName());
|
Map<String, String> routes = plugin.getSettings().getFeaturesProps().getPermissionRouterProps().getRules().get(section.getName());
|
||||||
|
ServerSection current = plugin.getSectionManager().getByPlayer(player);
|
||||||
|
|
||||||
if (routes != null) {
|
if (routes != null) {
|
||||||
for (Map.Entry<String, String> route : routes.entrySet()) {
|
for (Map.Entry<String, String> route : routes.entrySet()) {
|
||||||
if (player.hasPermission(route.getKey())) {
|
if (player.hasPermission(route.getKey())) {
|
||||||
ServerSection bind = plugin.getSectionManager().getByName(route.getValue());
|
ServerSection bind = plugin.getSectionManager().getByName(route.getValue());
|
||||||
ServerSection current = plugin.getSectionManager().getByPlayer(player);
|
|
||||||
|
|
||||||
if (bind != null) {
|
if (bind != null) {
|
||||||
if (current == bind)
|
if (current == bind) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return bind;
|
return bind;
|
||||||
}
|
}
|
||||||
@ -123,6 +124,7 @@ public abstract class ConnectionIntent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return section;
|
return section;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +136,7 @@ public abstract class ConnectionIntent {
|
|||||||
public void connect(ServerInfo server, Callback<Boolean> callback) {
|
public void connect(ServerInfo server, Callback<Boolean> callback) {
|
||||||
ConnectionIntent.direct(plugin, player, server, callback);
|
ConnectionIntent.direct(plugin, player, server, callback);
|
||||||
}
|
}
|
||||||
};
|
}.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void direct(PlayerBalancer plugin, ProxiedPlayer player, ServerInfo server, Callback<Boolean> callback) {
|
public static void direct(PlayerBalancer plugin, ProxiedPlayer player, ServerInfo server, Callback<Boolean> callback) {
|
||||||
@ -148,4 +150,4 @@ public abstract class ConnectionIntent {
|
|||||||
callback.done(result, throwable);
|
callback.done(result, throwable);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ public class ServerConnectListener implements Listener {
|
|||||||
event.setTarget(server);
|
event.setTarget(server);
|
||||||
callback.done(true, null);
|
callback.done(true, null);
|
||||||
}
|
}
|
||||||
};
|
}.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ServerSection getSection(ProxiedPlayer player, ServerInfo target) {
|
private ServerSection getSection(ProxiedPlayer player, ServerInfo target) {
|
||||||
|
@ -16,8 +16,6 @@ import net.md_5.bungee.api.plugin.Listener;
|
|||||||
import net.md_5.bungee.event.EventHandler;
|
import net.md_5.bungee.event.EventHandler;
|
||||||
import net.md_5.bungee.event.EventPriority;
|
import net.md_5.bungee.event.EventPriority;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class ServerKickListener implements Listener {
|
public class ServerKickListener implements Listener {
|
||||||
@ -67,11 +65,7 @@ public class ServerKickListener implements Listener {
|
|||||||
if (section == null)
|
if (section == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
List<ServerInfo> servers = new ArrayList<>();
|
ConnectionIntent intent = new ConnectionIntent(plugin, player, section) {
|
||||||
servers.addAll(section.getServers());
|
|
||||||
servers.remove(from);
|
|
||||||
|
|
||||||
new ConnectionIntent(plugin, player, section, servers) {
|
|
||||||
@Override
|
@Override
|
||||||
public void connect(ServerInfo server, Callback<Boolean> callback) {
|
public void connect(ServerInfo server, Callback<Boolean> callback) {
|
||||||
PlayerLocker.lock(player);
|
PlayerLocker.lock(player);
|
||||||
@ -87,6 +81,9 @@ public class ServerKickListener implements Listener {
|
|||||||
callback.done(true, null);
|
callback.done(true, null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
intent.getExclusions().add(from);
|
||||||
|
intent.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ServerSection getSection(ProxiedPlayer player, ServerInfo from) {
|
private ServerSection getSection(ProxiedPlayer player, ServerInfo from) {
|
||||||
|
@ -229,7 +229,7 @@ features {
|
|||||||
|
|
||||||
rules {
|
rules {
|
||||||
general-lobbies {
|
general-lobbies {
|
||||||
special.permission=other-lobby-section
|
"special.permission"=other-lobby-section
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user