Skip to content

Commit f84b6eb

Browse files
committed
Little changes to section servers set
1 parent e96640f commit f84b6eb

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

src/main/java/com/jaimemartz/playerbalancer/commands/FallbackCommand.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.jaimemartz.playerbalancer.commands;
22

3+
import com.google.common.collect.Iterables;
34
import com.jaimemartz.playerbalancer.PlayerBalancer;
45
import com.jaimemartz.playerbalancer.connection.ConnectionIntent;
56
import com.jaimemartz.playerbalancer.section.ServerSection;
@@ -41,15 +42,8 @@ public void execute(CommandSender sender, String[] args) {
4142
} else if (number > target.getServers().size()) {
4243
MessageUtils.send(player, messages.getFailureMessage());
4344
} else {
44-
int iterations = 0;
45-
for (ServerInfo server : target.getServers()) {
46-
if (iterations++ < number - 1) {
47-
continue;
48-
}
49-
50-
ConnectionIntent.direct(plugin, player, server, (response, throwable) -> { });
51-
break;
52-
}
45+
ServerInfo server = Iterables.get(target.getServers(), number - 1);
46+
ConnectionIntent.direct(plugin, player, server, (response, throwable) -> {});
5347
}
5448
} catch (NumberFormatException e) {
5549
MessageUtils.send(player, messages.getInvalidInputMessage());

src/main/java/com/jaimemartz/playerbalancer/section/SectionManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class SectionManager {
2222
private ServerSection principal;
2323
private ScheduledTask refreshTask;
2424

25-
private final Map<String, Stage> stages = Collections.synchronizedMap(new HashMap<>());
25+
private final Map<String, Stage> stages = Collections.synchronizedMap(new LinkedHashMap<>());
2626
private final Map<String, ServerSection> sections = Collections.synchronizedMap(new HashMap<>());
2727
private final Map<ServerInfo, ServerSection> servers = Collections.synchronizedMap(new HashMap<>());
2828

src/main/java/com/jaimemartz/playerbalancer/section/ServerSection.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import net.md_5.bungee.api.config.ServerInfo;
88

99
import java.util.Collections;
10+
import java.util.NavigableSet;
1011
import java.util.Set;
1112
import java.util.TreeSet;
1213

@@ -20,7 +21,7 @@ public class ServerSection {
2021

2122
private ServerInfo server;
2223
private SectionCommand command;
23-
private Set<ServerInfo> servers;
24+
private NavigableSet<ServerInfo> servers;
2425
private AbstractProvider externalProvider;
2526

2627
private boolean valid = false;
@@ -29,7 +30,7 @@ public ServerSection(String name, SectionProps props) {
2930
this.name = name;
3031
this.props = props;
3132

32-
this.servers = Collections.synchronizedSortedSet(new TreeSet<>((lhs, rhs) ->
33+
this.servers = Collections.synchronizedNavigableSet(new TreeSet<>((lhs, rhs) ->
3334
AlphanumComparator.getInstance().compare(lhs.getName(), rhs.getName())
3435
));
3536
}
@@ -108,7 +109,7 @@ public void setCommand(SectionCommand command) {
108109
this.command = command;
109110
}
110111

111-
public Set<ServerInfo> getServers() {
112+
public NavigableSet<ServerInfo> getServers() {
112113
return servers;
113114
}
114115

0 commit comments

Comments
 (0)