Removed unnecessary ConfigHelper

This commit is contained in:
Jaime Martinez Rincon 2017-02-17 15:50:36 +01:00
parent 0da4cba109
commit d37005ce3c
4 changed files with 13 additions and 105 deletions

View File

@ -1,88 +0,0 @@
package me.jaimemartz.lobbybalancer.configuration;
import me.jaimemartz.faucet.ConfigEntry;
import net.md_5.bungee.config.Configuration;
import java.util.List;
public class ConfigHelper {
public static Object get(ConfigEntry<Object> entry) {
return entry.get();
}
public static String getString(ConfigEntry<String> entry) {
return entry.get();
}
public static List<String> getStringList(ConfigEntry<List<String>> entry) {
return entry.get();
}
public static boolean getBoolean(ConfigEntry<Boolean> entry) {
return entry.get();
}
public static List<Boolean> getBooleanList(ConfigEntry<List<Boolean>> entry) {
return entry.get();
}
public static byte getByte(ConfigEntry<Byte> entry) {
return entry.get();
}
public static List<Byte> getByteList(ConfigEntry<List<Byte>> entry) {
return entry.get();
}
public static char getChar(ConfigEntry<Character> entry) {
return entry.get();
}
public static List<Character> getCharList(ConfigEntry<List<Character>> entry) {
return entry.get();
}
public static double getDouble(ConfigEntry<Double> entry) {
return entry.get();
}
public static List<Double> getDoubleList(ConfigEntry<List<Double>> entry) {
return entry.get();
}
public static float getFloat(ConfigEntry<Float> entry) {
return entry.get();
}
public static List<Float> getFloatList(ConfigEntry<List<Float>> entry) {
return entry.get();
}
public static int getInt(ConfigEntry<Integer> entry) {
return entry.get();
}
public static List<Integer> getIntList(ConfigEntry<List<Integer>> entry) {
return entry.get();
}
public static long getLong(ConfigEntry<Long> entry) {
return entry.get();
}
public static List<Long> getLongList(ConfigEntry<List<Long>> entry) {
return entry.get();
}
public static short getShort(ConfigEntry<Short> entry) {
return entry.get();
}
public static List<Short> getShortList(ConfigEntry<List<Short>> entry) {
return entry.get();
}
public static boolean isSet(Configuration config, String path) {
return config.get(path) != null;
}
}

View File

@ -6,7 +6,6 @@ import com.maxmind.geoip2.model.CountryResponse;
import com.maxmind.geoip2.record.Country;
import me.jaimemartz.lobbybalancer.LobbyBalancer;
import me.jaimemartz.lobbybalancer.configuration.ConfigEntries;
import me.jaimemartz.lobbybalancer.configuration.ConfigHelper;
import me.jaimemartz.lobbybalancer.manager.NetworkManager;
import me.jaimemartz.lobbybalancer.ping.ServerStatus;
import me.jaimemartz.lobbybalancer.section.ServerSection;
@ -36,7 +35,7 @@ public enum ProviderType {
@Override
public ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
Configuration rules = plugin.getConfig().getSection("settings.geolocation.rules");
if (ConfigEntries.GEOLOCATION_ENABLED.get() && ConfigHelper.isSet(rules, section.getName())) {
if (ConfigEntries.GEOLOCATION_ENABLED.get() && rules.contains(section.getName())) {
Configuration rule = rules.getSection(section.getName());
InetAddress address = player.getAddress().getAddress();

View File

@ -26,7 +26,7 @@ public class SectionManager {
sections.getKeys().forEach(name -> {
plugin.getLogger().info(String.format("Construction of section with name \"%s\"", name));
Configuration section = sections.getSection(name);
ServerSection object = new ServerSection(name, section, this);
ServerSection object = new ServerSection(name, section);
sectionStorage.put(name, object);
});

View File

@ -1,7 +1,6 @@
package me.jaimemartz.lobbybalancer.section;
import me.jaimemartz.lobbybalancer.LobbyBalancer;
import me.jaimemartz.lobbybalancer.configuration.ConfigHelper;
import me.jaimemartz.lobbybalancer.connection.ProviderType;
import me.jaimemartz.lobbybalancer.utils.FixedAdapter;
import net.md_5.bungee.api.config.ServerInfo;
@ -17,7 +16,6 @@ import java.util.regex.Pattern;
public class ServerSection {
private transient final Configuration section;
private transient final SectionManager manager;
private final String name;
private boolean principal;
@ -30,10 +28,9 @@ public class ServerSection {
private SectionCommand command;
private boolean valid = false;
ServerSection(String name, Configuration section, SectionManager manager) {
ServerSection(String name, Configuration section) {
this.name = name;
this.section = section;
this.manager = manager;
this.servers = new ArrayList<>();
}
@ -41,25 +38,25 @@ public class ServerSection {
principal = section.getBoolean("principal", false);
if (principal) {
ServerSection section = manager.getPrincipal();
ServerSection section = plugin.getSectionManager().getPrincipal();
if (section != null) {
throw new IllegalStateException(String.format("The section \"%s\" is already principal", section.getName()));
} else {
manager.setPrincipal(this);
plugin.getSectionManager().setPrincipal(this);
}
}
dummy = section.getBoolean("dummy", false);
if (ConfigHelper.isSet(section, "parent")) {
parent = manager.getByName(section.getString("parent"));
if (section.contains("parent")) {
parent = plugin.getSectionManager().getByName(section.getString("parent"));
if (parent == null) {
throw new IllegalArgumentException(String.format("The section \"%s\" has an invalid parent set", name));
}
}
if (ConfigHelper.isSet(section, "servers")) {
if (section.contains("servers")) {
section.getStringList("servers").forEach(entry -> {
Pattern pattern = Pattern.compile(entry);
AtomicBoolean matches = new AtomicBoolean(false);
@ -68,7 +65,7 @@ public class ServerSection {
if (matcher.matches()) {
plugin.getLogger().info(String.format("Found a match with \"%s\" for entry \"%s\"", key, entry));
servers.add(value);
manager.register(value, this);
plugin.getSectionManager().register(value, this);
matches.set(true);
}
});
@ -90,12 +87,12 @@ public class ServerSection {
throw new IllegalStateException(String.format("The section \"%s\" and \"%s\" are parents of each other", this.name, parent.name));
}
if (ConfigHelper.isSet(section, "provider")) {
if (section.contains("provider")) {
try {
provider = ProviderType.valueOf(section.getString("provider").toUpperCase());
if (provider == ProviderType.LOCALIZED) {
Configuration rules = plugin.getConfig().getSection("settings.geolocation.rules");
if (!ConfigHelper.isSet(rules, name)) {
if (!rules.contains(name)) {
throw new IllegalStateException(String.format("The section \"%s\" does not have a rule set in the geolocation section", this.name));
}
}
@ -125,7 +122,7 @@ public class ServerSection {
throw new IllegalStateException(String.format("The section \"%s\" does not have a provider", name));
}
if (ConfigHelper.isSet(section, "section-server")) {
if (section.contains("section-server")) {
int port = (int) Math.floor(Math.random() * (0xFFFF + 1)); //Get a random valid port for our fake server
server = plugin.getProxy().constructServerInfo("@" + section.getString("section-server"), new InetSocketAddress("0.0.0.0", port), String.format("Server of Section %s", name), false);
plugin.getSectionManager().register(server, this);
@ -133,7 +130,7 @@ public class ServerSection {
plugin.getProxy().getServers().put(server.getName(), server);
}
if (ConfigHelper.isSet(section, "section-command")) {
if (section.contains("section-command")) {
Configuration other = section.getSection("section-command");
String name = other.getString("name");