Skip to content

Commit 135f109

Browse files
committed
The servers set was being reassigned to a non ordered set
1 parent dc69839 commit 135f109

File tree

5 files changed

+18
-52
lines changed

5 files changed

+18
-52
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.jaimemartz</groupId>
88
<artifactId>playerbalancer</artifactId>
9-
<version>2.1</version>
9+
<version>2.1.0.1</version>
1010
<name>PlayerBalancer</name>
1111

1212
<properties>

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

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.concurrent.atomic.AtomicBoolean;
1313
import java.util.regex.Matcher;
1414
import java.util.regex.Pattern;
15+
import java.util.stream.Stream;
1516

1617
public class SectionManager {
1718
private final PlayerBalancer plugin;
@@ -32,13 +33,7 @@ public void load() throws RuntimeException {
3233

3334
for (Stage stage : stages) {
3435
plugin.getLogger().info("Executing stage \"" + stage.title + "\"");
35-
if (stage instanceof SectionStage) {
36-
props.getSectionProps().forEach((name, props) -> {
37-
((SectionStage) stage).execute(name, props, sections.get(name));
38-
});
39-
} else {
40-
((GlobalStage) stage).execute();
41-
}
36+
stage.execute();
4237
}
4338

4439
long ending = System.currentTimeMillis() - starting;
@@ -127,7 +122,7 @@ public void execute(String sectionName, SectionProps sectionProps, ServerSection
127122
sections.put(sectionName, object);
128123
}
129124
},
130-
new GlobalStage("Processing principal section") {
125+
new Stage("Processing principal section") {
131126
@Override
132127
public void execute() {
133128
principal = sections.get(props.getPrincipalSectionName());
@@ -200,7 +195,7 @@ public void execute(String sectionName, SectionProps sectionProps, ServerSection
200195
new SectionStage("Resolving servers") {
201196
@Override
202197
public void execute(String sectionName, SectionProps sectionProps, ServerSection section) throws RuntimeException {
203-
section.setServers(calculateServers(section));
198+
section.getServers().addAll(calculateServers(section));
204199
}
205200
},
206201
new SectionStage("Section server processing") {
@@ -322,28 +317,28 @@ public Map<String, ServerSection> getSections() {
322317
return sections;
323318
}
324319

325-
private static class Stage {
320+
private abstract class Stage {
326321
private final String title;
327322

328323
private Stage(String title) {
329324
this.title = title;
330325
}
331-
}
332-
333-
private static abstract class GlobalStage extends Stage {
334-
private GlobalStage(String title) {
335-
super(title);
336-
}
337326

338-
public abstract void execute(
339-
) throws RuntimeException;
327+
public abstract void execute() throws RuntimeException;
340328
}
341329

342-
private static abstract class SectionStage extends Stage {
330+
private abstract class SectionStage extends Stage {
343331
private SectionStage(String title) {
344332
super(title);
345333
}
346334

335+
@Override
336+
public void execute() throws RuntimeException {
337+
props.getSectionProps().forEach((name, props) -> {
338+
execute(name, props, sections.get(name));
339+
});
340+
}
341+
347342
public abstract void execute(
348343
String sectionName,
349344
SectionProps sectionProps,

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,10 @@ public void setCommand(SectionCommand command) {
9898
this.command = command;
9999
}
100100

101-
public void addServer(ServerInfo server) {
102-
servers.add(server);
103-
}
104-
105101
public Set<ServerInfo> getServers() {
106102
return servers;
107103
}
108104

109-
public void setServers(Set<ServerInfo> servers) {
110-
this.servers = servers;
111-
}
112-
113105
public boolean isValid() {
114106
return valid;
115107
}

src/main/resources/default.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# LobbyBalancer Configuration (https://www.spigotmc.org/resources/10788/)
1+
# PlayerBalancer Configuration (https://www.spigotmc.org/resources/10788/)
22
# Read the comments, they are a very important part of the configuration
33
# To get support send me a private message with a description of the problem and the config file
44
# To easily paste the config file (and other relevant files) use the command /balancer paste

src/test/java/GeneralTest.java

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,8 @@
11
import org.junit.Test;
22

3-
import java.io.BufferedReader;
4-
import java.io.InputStreamReader;
5-
import java.net.HttpURLConnection;
6-
import java.net.URL;
7-
83
public class GeneralTest {
94
@Test
10-
public void test() throws Exception {
11-
//Nothing to test
12-
}
13-
14-
public String checkVersion() {
15-
try {
16-
final HttpURLConnection con = (HttpURLConnection)new URL("http://www.spigotmc.org/api/general.php").openConnection();
17-
con.setDoOutput(true);
18-
con.setRequestMethod("POST");
19-
con.getOutputStream().write("key=98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4&resource=10788".getBytes("UTF-8"));
20-
final String version = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
21-
if (version.length() <= 7) {
22-
return version;
23-
}
24-
}
25-
catch (Exception ignored) {}
26-
27-
return null;
5+
public void test() {
6+
//Test
287
}
298
}

0 commit comments

Comments
 (0)