mirror of
https://github.com/BGHDDevelopment/PlayerBalancer.git
synced 2024-09-19 03:01:18 +02: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 net.md_5.bungee.api.ChatColor;
|
||||
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.plugin.Command;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
@ -36,16 +37,6 @@ public class FallbackCommand extends Command {
|
||||
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");
|
||||
String bind = rules.getString(section.getName());
|
||||
ServerSection target = plugin.getSectionManager().getByName(bind);
|
||||
@ -79,8 +70,24 @@ public class FallbackCommand extends Command {
|
||||
try {
|
||||
ServerSection section = callable.call();
|
||||
if (section != null) {
|
||||
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) {
|
||||
//Nothing to do
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public class ManageCommand extends Command {
|
||||
if (sender.hasPermission("lobbybalancer.admin")) {
|
||||
if (args.length != 0) {
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "simple": {
|
||||
case "connect": {
|
||||
if (args.length >= 2) {
|
||||
String input = args[1];
|
||||
ServerSection section = plugin.getSectionManager().getByName(input);
|
||||
@ -191,7 +191,7 @@ public class ManageCommand extends Command {
|
||||
"&7Available commands:",
|
||||
"&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 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-----------------------------------------------------"
|
||||
);
|
||||
}
|
||||
|
@ -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<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_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> REDIS_BUNGEE_ENABLED = new ConfigEntry<>(0, "settings.redis-bungee", false);
|
||||
|
@ -31,11 +31,12 @@ public abstract class ConnectionIntent {
|
||||
if (section.getProvider() != ProviderType.NONE) {
|
||||
ServerInfo target = this.fetchServer(plugin, player, section, provider, servers);
|
||||
if (target != null) {
|
||||
new Messager(player).send(ConfigEntries.CONNECTING_MESSAGE.get(), new Replacement("{server}", target.getName()));
|
||||
this.simple(target);
|
||||
new Messager(player).send(ConfigEntries.CONNECTING_MESSAGE.get(),
|
||||
new Replacement("{server}", target.getName())
|
||||
);
|
||||
this.connect(target);
|
||||
} else {
|
||||
new Messager(player).send(ConfigEntries.FAILURE_MESSAGE.get());
|
||||
this.failure();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -84,16 +85,12 @@ public abstract class ConnectionIntent {
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract void simple(ServerInfo server);
|
||||
|
||||
public void failure() {
|
||||
//Nothing to do
|
||||
}
|
||||
public abstract void connect(ServerInfo server);
|
||||
|
||||
public static void simple(LobbyBalancer plugin, ProxiedPlayer player, ServerSection section) {
|
||||
new ConnectionIntent(plugin, player, section) {
|
||||
@Override
|
||||
public void simple(ServerInfo server) {
|
||||
public void connect(ServerInfo server) {
|
||||
direct(plugin, player, server);
|
||||
}
|
||||
};
|
||||
|
@ -65,7 +65,7 @@ public class ServerConnectListener implements Listener {
|
||||
if (section != null) {
|
||||
new ConnectionIntent(plugin, player, section) {
|
||||
@Override
|
||||
public void simple(ServerInfo server) {
|
||||
public void connect(ServerInfo server) {
|
||||
if (ConfigEntries.ASSIGN_TARGETS_ENABLED.get()) {
|
||||
ServerAssignRegistry.assignTarget(player, section, server);
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ public class ServerKickListener implements Listener {
|
||||
|
||||
new ConnectionIntent(plugin, player, section, servers) {
|
||||
@Override
|
||||
public void simple(ServerInfo server) {
|
||||
public void connect(ServerInfo server) {
|
||||
PlayerLocker.lock(player);
|
||||
msgr.send(ConfigEntries.KICK_MESSAGE.get(),
|
||||
new Replacement("{from}", from.getName()),
|
||||
|
@ -28,17 +28,15 @@ public class SectionCommand extends Command {
|
||||
Messager msgr = new Messager(sender);
|
||||
if (sender instanceof ProxiedPlayer) {
|
||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||
|
||||
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);
|
||||
ServerInfo server = section.getSortedServers().get(number - 1);
|
||||
ConnectionIntent.direct(plugin, player, server);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
|
@ -13,7 +13,7 @@ settings:
|
||||
|
||||
# Pings to the servers to see if they can be accessed or not
|
||||
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
|
||||
|
||||
# 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
|
||||
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:
|
||||
# If this is enabled the kick reasons must still match for this to work
|
||||
enabled: true
|
||||
@ -66,7 +66,7 @@ settings:
|
||||
rules:
|
||||
'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:
|
||||
# If this is disabled the command will not be registered
|
||||
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
|
||||
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
|
||||
# This will set the section to go when you come from the section specified
|
||||
rules:
|
||||
|
Loading…
Reference in New Issue
Block a user