mirror of
https://github.com/BGHDDevelopment/PlayerBalancer.git
synced 2024-11-23 11:15:30 +01:00
Made the section router work on all connection types
This commit is contained in:
parent
a0c0b60c31
commit
b29254fd7b
@ -11,7 +11,7 @@
|
||||
|
||||
<name>PlayerBalancer Plugin</name>
|
||||
<artifactId>playerbalancer-plugin</artifactId>
|
||||
<version>2.1.5.1</version>
|
||||
<version>2.1.5.2</version>
|
||||
|
||||
<build>
|
||||
<finalName>PlayerBalancer</finalName>
|
||||
|
@ -11,11 +11,11 @@ import net.md_5.bungee.api.connection.Server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.jaimemartz.playerbalancer.utils.MessageUtils.safeNull;
|
||||
|
||||
//TODO I don't like this, improve it
|
||||
public abstract class ConnectionIntent {
|
||||
protected final PlayerBalancer plugin;
|
||||
protected final ProxiedPlayer player;
|
||||
@ -24,7 +24,7 @@ public abstract class ConnectionIntent {
|
||||
public ConnectionIntent(PlayerBalancer plugin, ProxiedPlayer player, ProviderType provider, ServerSection section, List<ServerInfo> servers) {
|
||||
this.plugin = plugin;
|
||||
this.player = player;
|
||||
this.section = section;
|
||||
this.section = tryRoute(player, section);
|
||||
|
||||
MessageUtils.send(player, plugin.getSettings().getMessagesProps().getConnectingMessage(),
|
||||
(str) -> str.replace("{section}", section.getName())
|
||||
@ -101,9 +101,33 @@ public abstract class ConnectionIntent {
|
||||
return null;
|
||||
}
|
||||
|
||||
private ServerSection tryRoute(ProxiedPlayer player, ServerSection section) {
|
||||
if (plugin.getSettings().getFeaturesProps().getPermissionRouterProps().isEnabled()) {
|
||||
Map<String, String> routes = plugin.getSettings().getFeaturesProps().getPermissionRouterProps().getRules().get(section.getName());
|
||||
|
||||
if (routes != null) {
|
||||
for (Map.Entry<String, String> route : routes.entrySet()) {
|
||||
if (player.hasPermission(route.getKey())) {
|
||||
ServerSection bind = plugin.getSectionManager().getByName(route.getValue());
|
||||
ServerSection current = plugin.getSectionManager().getByPlayer(player);
|
||||
|
||||
if (bind != null) {
|
||||
if (current == bind)
|
||||
break;
|
||||
|
||||
return bind;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return section;
|
||||
}
|
||||
|
||||
public abstract void connect(ServerInfo server, Callback<Boolean> callback);
|
||||
|
||||
//TODO Create this as a type
|
||||
public static void simple(PlayerBalancer plugin, ProxiedPlayer player, ServerSection section) {
|
||||
new ConnectionIntent(plugin, player, section) {
|
||||
@Override
|
||||
@ -113,7 +137,6 @@ public abstract class ConnectionIntent {
|
||||
};
|
||||
}
|
||||
|
||||
//TODO Create this as a type
|
||||
public static void direct(PlayerBalancer plugin, ProxiedPlayer player, ServerInfo server, Callback<Boolean> callback) {
|
||||
PlayerLocker.lock(player);
|
||||
player.connect(server, (result, throwable) -> {
|
||||
|
@ -5,7 +5,6 @@ import com.jaimemartz.playerbalancer.connection.ConnectionIntent;
|
||||
import com.jaimemartz.playerbalancer.connection.ServerAssignRegistry;
|
||||
import com.jaimemartz.playerbalancer.helper.PlayerLocker;
|
||||
import com.jaimemartz.playerbalancer.section.ServerSection;
|
||||
import com.jaimemartz.playerbalancer.settings.props.features.PermissionRouterProps;
|
||||
import com.jaimemartz.playerbalancer.utils.MessageUtils;
|
||||
import net.md_5.bungee.api.Callback;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
@ -15,17 +14,11 @@ import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import net.md_5.bungee.event.EventPriority;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ServerConnectListener implements Listener {
|
||||
private final PlayerBalancer plugin;
|
||||
|
||||
private final PermissionRouterProps permissionRouterProps;
|
||||
|
||||
public ServerConnectListener(PlayerBalancer plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
this.permissionRouterProps = plugin.getSettings().getFeaturesProps().getPermissionRouterProps();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@ -63,28 +56,6 @@ public class ServerConnectListener implements Listener {
|
||||
ServerSection section = plugin.getSectionManager().getByServer(target);
|
||||
|
||||
if (section != null) {
|
||||
if (permissionRouterProps.isEnabled()) {
|
||||
Map<String, String> routes = permissionRouterProps.getRules().get(section.getName());
|
||||
|
||||
if (routes != null) {
|
||||
for (Map.Entry<String, String> route : routes.entrySet()) {
|
||||
if (player.hasPermission(route.getKey())) {
|
||||
ServerSection bind = plugin.getSectionManager().getByName(route.getValue());
|
||||
ServerSection current = plugin.getSectionManager().getByPlayer(player);
|
||||
|
||||
if (bind != null) {
|
||||
if (current == bind)
|
||||
break;
|
||||
|
||||
return bind;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Checks only for servers (not the section server)
|
||||
if (!target.equals(section.getServer())) {
|
||||
if (plugin.getSectionManager().isDummy(section)) {
|
||||
|
Loading…
Reference in New Issue
Block a user