mirror of
https://github.com/BGHDDevelopment/PlayerBalancer.git
synced 2024-11-09 12:30:03 +01:00
Implemented server position argument (replacing old section argument)
This commit is contained in:
parent
24953e5ff3
commit
b9824a1f81
@ -7,6 +7,7 @@ import me.jaimemartz.lobbybalancer.connection.ConnectionIntent;
|
|||||||
import me.jaimemartz.lobbybalancer.section.ServerSection;
|
import me.jaimemartz.lobbybalancer.section.ServerSection;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
import net.md_5.bungee.config.Configuration;
|
import net.md_5.bungee.config.Configuration;
|
||||||
@ -36,16 +37,6 @@ public class FallbackCommand extends Command {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ConfigEntries.FALLBACK_COMMAND_ARGUMENTS.get() && args.length == 1) {
|
|
||||||
ServerSection target = plugin.getSectionManager().getByName(args[0]);
|
|
||||||
|
|
||||||
if (target == null) {
|
|
||||||
msgr.send(ConfigEntries.UNKNOWN_SECTION_MESSAGE.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
return target;
|
|
||||||
}
|
|
||||||
|
|
||||||
Configuration rules = plugin.getConfig().getSection("settings.fallback-command.rules");
|
Configuration rules = plugin.getConfig().getSection("settings.fallback-command.rules");
|
||||||
String bind = rules.getString(section.getName());
|
String bind = rules.getString(section.getName());
|
||||||
ServerSection target = plugin.getSectionManager().getByName(bind);
|
ServerSection target = plugin.getSectionManager().getByName(bind);
|
||||||
@ -79,7 +70,23 @@ public class FallbackCommand extends Command {
|
|||||||
try {
|
try {
|
||||||
ServerSection section = callable.call();
|
ServerSection section = callable.call();
|
||||||
if (section != null) {
|
if (section != null) {
|
||||||
ConnectionIntent.simple(plugin, player, section);
|
if (args.length == 1) {
|
||||||
|
try {
|
||||||
|
int number = Integer.parseInt(args[0]);
|
||||||
|
if (number <= 0) {
|
||||||
|
msgr.send(ConfigEntries.INVALID_INPUT_MESSAGE.get());
|
||||||
|
} else if (number > section.getServers().size()) {
|
||||||
|
msgr.send(ConfigEntries.FAILURE_MESSAGE.get());
|
||||||
|
} else {
|
||||||
|
ServerInfo server = section.getSortedServers().get(number - 1);
|
||||||
|
ConnectionIntent.direct(plugin, player, server);
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
msgr.send(ConfigEntries.INVALID_INPUT_MESSAGE.get());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ConnectionIntent.simple(plugin, player, section);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//Nothing to do
|
//Nothing to do
|
||||||
|
@ -35,7 +35,7 @@ public class ManageCommand extends Command {
|
|||||||
if (sender.hasPermission("lobbybalancer.admin")) {
|
if (sender.hasPermission("lobbybalancer.admin")) {
|
||||||
if (args.length != 0) {
|
if (args.length != 0) {
|
||||||
switch (args[0].toLowerCase()) {
|
switch (args[0].toLowerCase()) {
|
||||||
case "simple": {
|
case "connect": {
|
||||||
if (args.length >= 2) {
|
if (args.length >= 2) {
|
||||||
String input = args[1];
|
String input = args[1];
|
||||||
ServerSection section = plugin.getSectionManager().getByName(input);
|
ServerSection section = plugin.getSectionManager().getByName(input);
|
||||||
@ -191,7 +191,7 @@ public class ManageCommand extends Command {
|
|||||||
"&7Available commands:",
|
"&7Available commands:",
|
||||||
"&3/section list &7- &cTells you which sections are configured in the plugin",
|
"&3/section list &7- &cTells you which sections are configured in the plugin",
|
||||||
"&3/section info <section> &7- &cTells you info about the section",
|
"&3/section info <section> &7- &cTells you info about the section",
|
||||||
"&3/section simple <section> [player] &7- &cConnects you or the specified player to that section",
|
"&3/section connect <section> [player] &7- &cConnects you or the specified player to that section",
|
||||||
"&7&m-----------------------------------------------------"
|
"&7&m-----------------------------------------------------"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,6 @@ public class ConfigEntries implements ConfigEntryHolder {
|
|||||||
public static final ConfigEntry<String> FALLBACK_COMMAND_PERMISSION = new ConfigEntry<>(0, "settings.fallback-command.permission", "");
|
public static final ConfigEntry<String> FALLBACK_COMMAND_PERMISSION = new ConfigEntry<>(0, "settings.fallback-command.permission", "");
|
||||||
public static final ConfigEntry<List<String>> FALLBACK_COMMAND_IGNORED_SECTIONS = new ConfigEntry<>(0, "settings.fallback-command.ignored", Collections.emptyList());
|
public static final ConfigEntry<List<String>> FALLBACK_COMMAND_IGNORED_SECTIONS = new ConfigEntry<>(0, "settings.fallback-command.ignored", Collections.emptyList());
|
||||||
public static final ConfigEntry<Boolean> FALLBACK_COMMAND_RESTRICTED = new ConfigEntry<>(0, "settings.fallback-command.restricted", true);
|
public static final ConfigEntry<Boolean> FALLBACK_COMMAND_RESTRICTED = new ConfigEntry<>(0, "settings.fallback-command.restricted", true);
|
||||||
public static final ConfigEntry<Boolean> FALLBACK_COMMAND_ARGUMENTS = new ConfigEntry<>(0, "settings.fallback-command.arguments", true);
|
|
||||||
|
|
||||||
public static final ConfigEntry<Boolean> AUTO_RELOAD_ENABLED = new ConfigEntry<>(0, "settings.auto-reload", true);
|
public static final ConfigEntry<Boolean> AUTO_RELOAD_ENABLED = new ConfigEntry<>(0, "settings.auto-reload", true);
|
||||||
public static final ConfigEntry<Boolean> REDIS_BUNGEE_ENABLED = new ConfigEntry<>(0, "settings.redis-bungee", false);
|
public static final ConfigEntry<Boolean> REDIS_BUNGEE_ENABLED = new ConfigEntry<>(0, "settings.redis-bungee", false);
|
||||||
|
@ -31,11 +31,12 @@ public abstract class ConnectionIntent {
|
|||||||
if (section.getProvider() != ProviderType.NONE) {
|
if (section.getProvider() != ProviderType.NONE) {
|
||||||
ServerInfo target = this.fetchServer(plugin, player, section, provider, servers);
|
ServerInfo target = this.fetchServer(plugin, player, section, provider, servers);
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
new Messager(player).send(ConfigEntries.CONNECTING_MESSAGE.get(), new Replacement("{server}", target.getName()));
|
new Messager(player).send(ConfigEntries.CONNECTING_MESSAGE.get(),
|
||||||
this.simple(target);
|
new Replacement("{server}", target.getName())
|
||||||
|
);
|
||||||
|
this.connect(target);
|
||||||
} else {
|
} else {
|
||||||
new Messager(player).send(ConfigEntries.FAILURE_MESSAGE.get());
|
new Messager(player).send(ConfigEntries.FAILURE_MESSAGE.get());
|
||||||
this.failure();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,16 +85,12 @@ public abstract class ConnectionIntent {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void simple(ServerInfo server);
|
public abstract void connect(ServerInfo server);
|
||||||
|
|
||||||
public void failure() {
|
|
||||||
//Nothing to do
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void simple(LobbyBalancer plugin, ProxiedPlayer player, ServerSection section) {
|
public static void simple(LobbyBalancer plugin, ProxiedPlayer player, ServerSection section) {
|
||||||
new ConnectionIntent(plugin, player, section) {
|
new ConnectionIntent(plugin, player, section) {
|
||||||
@Override
|
@Override
|
||||||
public void simple(ServerInfo server) {
|
public void connect(ServerInfo server) {
|
||||||
direct(plugin, player, server);
|
direct(plugin, player, server);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -65,7 +65,7 @@ public class ServerConnectListener implements Listener {
|
|||||||
if (section != null) {
|
if (section != null) {
|
||||||
new ConnectionIntent(plugin, player, section) {
|
new ConnectionIntent(plugin, player, section) {
|
||||||
@Override
|
@Override
|
||||||
public void simple(ServerInfo server) {
|
public void connect(ServerInfo server) {
|
||||||
if (ConfigEntries.ASSIGN_TARGETS_ENABLED.get()) {
|
if (ConfigEntries.ASSIGN_TARGETS_ENABLED.get()) {
|
||||||
ServerAssignRegistry.assignTarget(player, section, server);
|
ServerAssignRegistry.assignTarget(player, section, server);
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ public class ServerKickListener implements Listener {
|
|||||||
|
|
||||||
new ConnectionIntent(plugin, player, section, servers) {
|
new ConnectionIntent(plugin, player, section, servers) {
|
||||||
@Override
|
@Override
|
||||||
public void simple(ServerInfo server) {
|
public void connect(ServerInfo server) {
|
||||||
PlayerLocker.lock(player);
|
PlayerLocker.lock(player);
|
||||||
msgr.send(ConfigEntries.KICK_MESSAGE.get(),
|
msgr.send(ConfigEntries.KICK_MESSAGE.get(),
|
||||||
new Replacement("{from}", from.getName()),
|
new Replacement("{from}", from.getName()),
|
||||||
|
@ -28,17 +28,15 @@ public class SectionCommand extends Command {
|
|||||||
Messager msgr = new Messager(sender);
|
Messager msgr = new Messager(sender);
|
||||||
if (sender instanceof ProxiedPlayer) {
|
if (sender instanceof ProxiedPlayer) {
|
||||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||||
|
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
try {
|
try {
|
||||||
int number = Integer.parseInt(args[0]);
|
int number = Integer.parseInt(args[0]);
|
||||||
|
|
||||||
if (number <= 0) {
|
if (number <= 0) {
|
||||||
msgr.send(ConfigEntries.INVALID_INPUT_MESSAGE.get());
|
msgr.send(ConfigEntries.INVALID_INPUT_MESSAGE.get());
|
||||||
} else if (number > section.getServers().size()) {
|
} else if (number > section.getServers().size()) {
|
||||||
msgr.send(ConfigEntries.FAILURE_MESSAGE.get());
|
msgr.send(ConfigEntries.FAILURE_MESSAGE.get());
|
||||||
} else {
|
} else {
|
||||||
ServerInfo server = section.getSortedServers().get(number);
|
ServerInfo server = section.getSortedServers().get(number - 1);
|
||||||
ConnectionIntent.direct(plugin, player, server);
|
ConnectionIntent.direct(plugin, player, server);
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
|
@ -13,7 +13,7 @@ settings:
|
|||||||
|
|
||||||
# Pings to the servers to see if they can be accessed or not
|
# Pings to the servers to see if they can be accessed or not
|
||||||
server-check:
|
server-check:
|
||||||
# If this is disabled the players will simple to the first server available
|
# If this is disabled the players will connect to the first server available
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
||||||
# Use either CUSTOM or GENERIC, the first one generally works the best
|
# Use either CUSTOM or GENERIC, the first one generally works the best
|
||||||
@ -34,7 +34,7 @@ settings:
|
|||||||
# The descriptions that mark a server as non accessible
|
# The descriptions that mark a server as non accessible
|
||||||
marker-descs: ["Server is not accessible", "Gamemode has already started"]
|
marker-descs: ["Server is not accessible", "Gamemode has already started"]
|
||||||
|
|
||||||
# This will simple the player to a server of the parent of the section the player is kicked from
|
# This will connect the player to a server of the parent of the section the player is kicked from
|
||||||
reconnect-kick:
|
reconnect-kick:
|
||||||
# If this is enabled the kick reasons must still match for this to work
|
# If this is enabled the kick reasons must still match for this to work
|
||||||
enabled: true
|
enabled: true
|
||||||
@ -66,7 +66,7 @@ settings:
|
|||||||
rules:
|
rules:
|
||||||
'section-from': 'section-to'
|
'section-from': 'section-to'
|
||||||
|
|
||||||
# This will simple the player to a server of the parent of the section the player is currently on
|
# This will connect the player to a server of the parent of the section the player is currently on
|
||||||
fallback-command:
|
fallback-command:
|
||||||
# If this is disabled the command will not be registered
|
# If this is disabled the command will not be registered
|
||||||
enabled: true
|
enabled: true
|
||||||
@ -86,9 +86,6 @@ settings:
|
|||||||
# If enabled, players will not be able to get back to any server in a section that is parent of the principal section
|
# If enabled, players will not be able to get back to any server in a section that is parent of the principal section
|
||||||
restricted: true
|
restricted: true
|
||||||
|
|
||||||
# Whether the command can accept the name of a section as a target
|
|
||||||
arguments: false
|
|
||||||
|
|
||||||
# You can override the behavior with rules, overriding the parent section
|
# You can override the behavior with rules, overriding the parent section
|
||||||
# This will set the section to go when you come from the section specified
|
# This will set the section to go when you come from the section specified
|
||||||
rules:
|
rules:
|
||||||
|
Loading…
Reference in New Issue
Block a user