The servers set was being reassigned to a non ordered set

This commit is contained in:
Jaime Martínez Rincón 2017-09-18 18:07:36 +02:00
parent dc69839366
commit 135f109782
5 changed files with 18 additions and 52 deletions

View File

@ -6,7 +6,7 @@
<groupId>com.jaimemartz</groupId>
<artifactId>playerbalancer</artifactId>
<version>2.1</version>
<version>2.1.0.1</version>
<name>PlayerBalancer</name>
<properties>

View File

@ -12,6 +12,7 @@ import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
public class SectionManager {
private final PlayerBalancer plugin;
@ -32,13 +33,7 @@ public class SectionManager {
for (Stage stage : stages) {
plugin.getLogger().info("Executing stage \"" + stage.title + "\"");
if (stage instanceof SectionStage) {
props.getSectionProps().forEach((name, props) -> {
((SectionStage) stage).execute(name, props, sections.get(name));
});
} else {
((GlobalStage) stage).execute();
}
stage.execute();
}
long ending = System.currentTimeMillis() - starting;
@ -127,7 +122,7 @@ public class SectionManager {
sections.put(sectionName, object);
}
},
new GlobalStage("Processing principal section") {
new Stage("Processing principal section") {
@Override
public void execute() {
principal = sections.get(props.getPrincipalSectionName());
@ -200,7 +195,7 @@ public class SectionManager {
new SectionStage("Resolving servers") {
@Override
public void execute(String sectionName, SectionProps sectionProps, ServerSection section) throws RuntimeException {
section.setServers(calculateServers(section));
section.getServers().addAll(calculateServers(section));
}
},
new SectionStage("Section server processing") {
@ -322,28 +317,28 @@ public class SectionManager {
return sections;
}
private static class Stage {
private abstract class Stage {
private final String title;
private Stage(String title) {
this.title = title;
}
public abstract void execute() throws RuntimeException;
}
private static abstract class GlobalStage extends Stage {
private GlobalStage(String title) {
super(title);
}
public abstract void execute(
) throws RuntimeException;
}
private static abstract class SectionStage extends Stage {
private abstract class SectionStage extends Stage {
private SectionStage(String title) {
super(title);
}
@Override
public void execute() throws RuntimeException {
props.getSectionProps().forEach((name, props) -> {
execute(name, props, sections.get(name));
});
}
public abstract void execute(
String sectionName,
SectionProps sectionProps,

View File

@ -98,18 +98,10 @@ public class ServerSection {
this.command = command;
}
public void addServer(ServerInfo server) {
servers.add(server);
}
public Set<ServerInfo> getServers() {
return servers;
}
public void setServers(Set<ServerInfo> servers) {
this.servers = servers;
}
public boolean isValid() {
return valid;
}

View File

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

View File

@ -1,29 +1,8 @@
import org.junit.Test;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class GeneralTest {
@Test
public void test() throws Exception {
//Nothing to test
}
public String checkVersion() {
try {
final HttpURLConnection con = (HttpURLConnection)new URL("http://www.spigotmc.org/api/general.php").openConnection();
con.setDoOutput(true);
con.setRequestMethod("POST");
con.getOutputStream().write("key=98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4&resource=10788".getBytes("UTF-8"));
final String version = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
if (version.length() <= 7) {
return version;
}
}
catch (Exception ignored) {}
return null;
public void test() {
//Test
}
}