Skip to content

Commit b9824a1

Browse files
committed
Implemented server position argument (replacing old section argument)
1 parent 24953e5 commit b9824a1

File tree

8 files changed

+32
-34
lines changed

8 files changed

+32
-34
lines changed

src/main/java/me/jaimemartz/lobbybalancer/commands/FallbackCommand.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import me.jaimemartz.lobbybalancer.section.ServerSection;
88
import net.md_5.bungee.api.ChatColor;
99
import net.md_5.bungee.api.CommandSender;
10+
import net.md_5.bungee.api.config.ServerInfo;
1011
import net.md_5.bungee.api.connection.ProxiedPlayer;
1112
import net.md_5.bungee.api.plugin.Command;
1213
import net.md_5.bungee.config.Configuration;
@@ -36,16 +37,6 @@ public void execute(CommandSender sender, String[] args) {
3637
return null;
3738
}
3839

39-
if (ConfigEntries.FALLBACK_COMMAND_ARGUMENTS.get() && args.length == 1) {
40-
ServerSection target = plugin.getSectionManager().getByName(args[0]);
41-
42-
if (target == null) {
43-
msgr.send(ConfigEntries.UNKNOWN_SECTION_MESSAGE.get());
44-
}
45-
46-
return target;
47-
}
48-
4940
Configuration rules = plugin.getConfig().getSection("settings.fallback-command.rules");
5041
String bind = rules.getString(section.getName());
5142
ServerSection target = plugin.getSectionManager().getByName(bind);
@@ -79,7 +70,23 @@ public void execute(CommandSender sender, String[] args) {
7970
try {
8071
ServerSection section = callable.call();
8172
if (section != null) {
82-
ConnectionIntent.simple(plugin, player, section);
73+
if (args.length == 1) {
74+
try {
75+
int number = Integer.parseInt(args[0]);
76+
if (number <= 0) {
77+
msgr.send(ConfigEntries.INVALID_INPUT_MESSAGE.get());
78+
} else if (number > section.getServers().size()) {
79+
msgr.send(ConfigEntries.FAILURE_MESSAGE.get());
80+
} else {
81+
ServerInfo server = section.getSortedServers().get(number - 1);
82+
ConnectionIntent.direct(plugin, player, server);
83+
}
84+
} catch (NumberFormatException e) {
85+
msgr.send(ConfigEntries.INVALID_INPUT_MESSAGE.get());
86+
}
87+
} else {
88+
ConnectionIntent.simple(plugin, player, section);
89+
}
8390
}
8491
} catch (Exception e) {
8592
//Nothing to do

src/main/java/me/jaimemartz/lobbybalancer/commands/ManageCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void execute(CommandSender sender, String[] args) {
3535
if (sender.hasPermission("lobbybalancer.admin")) {
3636
if (args.length != 0) {
3737
switch (args[0].toLowerCase()) {
38-
case "simple": {
38+
case "connect": {
3939
if (args.length >= 2) {
4040
String input = args[1];
4141
ServerSection section = plugin.getSectionManager().getByName(input);
@@ -191,7 +191,7 @@ public void execute(CommandSender sender, String[] args) {
191191
"&7Available commands:",
192192
"&3/section list &7- &cTells you which sections are configured in the plugin",
193193
"&3/section info <section> &7- &cTells you info about the section",
194-
"&3/section simple <section> [player] &7- &cConnects you or the specified player to that section",
194+
"&3/section connect <section> [player] &7- &cConnects you or the specified player to that section",
195195
"&7&m-----------------------------------------------------"
196196
);
197197
}

src/main/java/me/jaimemartz/lobbybalancer/configuration/ConfigEntries.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public class ConfigEntries implements ConfigEntryHolder {
3737
public static final ConfigEntry<String> FALLBACK_COMMAND_PERMISSION = new ConfigEntry<>(0, "settings.fallback-command.permission", "");
3838
public static final ConfigEntry<List<String>> FALLBACK_COMMAND_IGNORED_SECTIONS = new ConfigEntry<>(0, "settings.fallback-command.ignored", Collections.emptyList());
3939
public static final ConfigEntry<Boolean> FALLBACK_COMMAND_RESTRICTED = new ConfigEntry<>(0, "settings.fallback-command.restricted", true);
40-
public static final ConfigEntry<Boolean> FALLBACK_COMMAND_ARGUMENTS = new ConfigEntry<>(0, "settings.fallback-command.arguments", true);
4140

4241
public static final ConfigEntry<Boolean> AUTO_RELOAD_ENABLED = new ConfigEntry<>(0, "settings.auto-reload", true);
4342
public static final ConfigEntry<Boolean> REDIS_BUNGEE_ENABLED = new ConfigEntry<>(0, "settings.redis-bungee", false);

src/main/java/me/jaimemartz/lobbybalancer/connection/ConnectionIntent.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ public ConnectionIntent(LobbyBalancer plugin, ProxiedPlayer player, ProviderType
3131
if (section.getProvider() != ProviderType.NONE) {
3232
ServerInfo target = this.fetchServer(plugin, player, section, provider, servers);
3333
if (target != null) {
34-
new Messager(player).send(ConfigEntries.CONNECTING_MESSAGE.get(), new Replacement("{server}", target.getName()));
35-
this.simple(target);
34+
new Messager(player).send(ConfigEntries.CONNECTING_MESSAGE.get(),
35+
new Replacement("{server}", target.getName())
36+
);
37+
this.connect(target);
3638
} else {
3739
new Messager(player).send(ConfigEntries.FAILURE_MESSAGE.get());
38-
this.failure();
3940
}
4041
}
4142
}
@@ -84,16 +85,12 @@ private ServerInfo fetchServer(LobbyBalancer plugin, ProxiedPlayer player, Serve
8485
return null;
8586
}
8687

87-
public abstract void simple(ServerInfo server);
88-
89-
public void failure() {
90-
//Nothing to do
91-
}
88+
public abstract void connect(ServerInfo server);
9289

9390
public static void simple(LobbyBalancer plugin, ProxiedPlayer player, ServerSection section) {
9491
new ConnectionIntent(plugin, player, section) {
9592
@Override
96-
public void simple(ServerInfo server) {
93+
public void connect(ServerInfo server) {
9794
direct(plugin, player, server);
9895
}
9996
};

src/main/java/me/jaimemartz/lobbybalancer/listener/ServerConnectListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void onConnect(ServerConnectEvent event) {
6565
if (section != null) {
6666
new ConnectionIntent(plugin, player, section) {
6767
@Override
68-
public void simple(ServerInfo server) {
68+
public void connect(ServerInfo server) {
6969
if (ConfigEntries.ASSIGN_TARGETS_ENABLED.get()) {
7070
ServerAssignRegistry.assignTarget(player, section, server);
7171
}

src/main/java/me/jaimemartz/lobbybalancer/listener/ServerKickListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public void onKick(ServerKickEvent event) {
115115

116116
new ConnectionIntent(plugin, player, section, servers) {
117117
@Override
118-
public void simple(ServerInfo server) {
118+
public void connect(ServerInfo server) {
119119
PlayerLocker.lock(player);
120120
msgr.send(ConfigEntries.KICK_MESSAGE.get(),
121121
new Replacement("{from}", from.getName()),

src/main/java/me/jaimemartz/lobbybalancer/section/SectionCommand.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,15 @@ public void execute(CommandSender sender, String[] args) {
2828
Messager msgr = new Messager(sender);
2929
if (sender instanceof ProxiedPlayer) {
3030
ProxiedPlayer player = (ProxiedPlayer) sender;
31-
3231
if (args.length == 1) {
3332
try {
3433
int number = Integer.parseInt(args[0]);
35-
3634
if (number <= 0) {
3735
msgr.send(ConfigEntries.INVALID_INPUT_MESSAGE.get());
3836
} else if (number > section.getServers().size()) {
3937
msgr.send(ConfigEntries.FAILURE_MESSAGE.get());
4038
} else {
41-
ServerInfo server = section.getSortedServers().get(number);
39+
ServerInfo server = section.getSortedServers().get(number - 1);
4240
ConnectionIntent.direct(plugin, player, server);
4341
}
4442
} catch (NumberFormatException e) {

src/main/resources/config.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ settings:
1313

1414
# Pings to the servers to see if they can be accessed or not
1515
server-check:
16-
# If this is disabled the players will simple to the first server available
16+
# If this is disabled the players will connect to the first server available
1717
enabled: true
1818

1919
# Use either CUSTOM or GENERIC, the first one generally works the best
@@ -34,7 +34,7 @@ settings:
3434
# The descriptions that mark a server as non accessible
3535
marker-descs: ["Server is not accessible", "Gamemode has already started"]
3636

37-
# This will simple the player to a server of the parent of the section the player is kicked from
37+
# This will connect the player to a server of the parent of the section the player is kicked from
3838
reconnect-kick:
3939
# If this is enabled the kick reasons must still match for this to work
4040
enabled: true
@@ -66,7 +66,7 @@ settings:
6666
rules:
6767
'section-from': 'section-to'
6868

69-
# This will simple the player to a server of the parent of the section the player is currently on
69+
# This will connect the player to a server of the parent of the section the player is currently on
7070
fallback-command:
7171
# If this is disabled the command will not be registered
7272
enabled: true
@@ -86,9 +86,6 @@ settings:
8686
# If enabled, players will not be able to get back to any server in a section that is parent of the principal section
8787
restricted: true
8888

89-
# Whether the command can accept the name of a section as a target
90-
arguments: false
91-
9289
# You can override the behavior with rules, overriding the parent section
9390
# This will set the section to go when you come from the section specified
9491
rules:

0 commit comments

Comments
 (0)