From d37005ce3c65834f08da26cea41148524a924323 Mon Sep 17 00:00:00 2001 From: Jaime Martinez Rincon Date: Fri, 17 Feb 2017 15:50:36 +0100 Subject: [PATCH] Removed unnecessary ConfigHelper --- .../configuration/ConfigHelper.java | 88 ------------------- .../connection/ProviderType.java | 3 +- .../lobbybalancer/section/SectionManager.java | 2 +- .../lobbybalancer/section/ServerSection.java | 25 +++--- 4 files changed, 13 insertions(+), 105 deletions(-) delete mode 100644 src/main/java/me/jaimemartz/lobbybalancer/configuration/ConfigHelper.java diff --git a/src/main/java/me/jaimemartz/lobbybalancer/configuration/ConfigHelper.java b/src/main/java/me/jaimemartz/lobbybalancer/configuration/ConfigHelper.java deleted file mode 100644 index d60d4cc..0000000 --- a/src/main/java/me/jaimemartz/lobbybalancer/configuration/ConfigHelper.java +++ /dev/null @@ -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 entry) { - return entry.get(); - } - - public static String getString(ConfigEntry entry) { - return entry.get(); - } - - public static List getStringList(ConfigEntry> entry) { - return entry.get(); - } - - public static boolean getBoolean(ConfigEntry entry) { - return entry.get(); - } - - public static List getBooleanList(ConfigEntry> entry) { - return entry.get(); - } - - public static byte getByte(ConfigEntry entry) { - return entry.get(); - } - - public static List getByteList(ConfigEntry> entry) { - return entry.get(); - } - - public static char getChar(ConfigEntry entry) { - return entry.get(); - } - - public static List getCharList(ConfigEntry> entry) { - return entry.get(); - } - - public static double getDouble(ConfigEntry entry) { - return entry.get(); - } - - public static List getDoubleList(ConfigEntry> entry) { - return entry.get(); - } - - public static float getFloat(ConfigEntry entry) { - return entry.get(); - } - - public static List getFloatList(ConfigEntry> entry) { - return entry.get(); - } - - public static int getInt(ConfigEntry entry) { - return entry.get(); - } - - public static List getIntList(ConfigEntry> entry) { - return entry.get(); - } - - public static long getLong(ConfigEntry entry) { - return entry.get(); - } - - public static List getLongList(ConfigEntry> entry) { - return entry.get(); - } - - public static short getShort(ConfigEntry entry) { - return entry.get(); - } - - public static List getShortList(ConfigEntry> entry) { - return entry.get(); - } - - public static boolean isSet(Configuration config, String path) { - return config.get(path) != null; - } -} diff --git a/src/main/java/me/jaimemartz/lobbybalancer/connection/ProviderType.java b/src/main/java/me/jaimemartz/lobbybalancer/connection/ProviderType.java index 9782d3c..9d4482e 100644 --- a/src/main/java/me/jaimemartz/lobbybalancer/connection/ProviderType.java +++ b/src/main/java/me/jaimemartz/lobbybalancer/connection/ProviderType.java @@ -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 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(); diff --git a/src/main/java/me/jaimemartz/lobbybalancer/section/SectionManager.java b/src/main/java/me/jaimemartz/lobbybalancer/section/SectionManager.java index f864a1b..8399308 100644 --- a/src/main/java/me/jaimemartz/lobbybalancer/section/SectionManager.java +++ b/src/main/java/me/jaimemartz/lobbybalancer/section/SectionManager.java @@ -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); }); diff --git a/src/main/java/me/jaimemartz/lobbybalancer/section/ServerSection.java b/src/main/java/me/jaimemartz/lobbybalancer/section/ServerSection.java index 13c6ff7..df21267 100644 --- a/src/main/java/me/jaimemartz/lobbybalancer/section/ServerSection.java +++ b/src/main/java/me/jaimemartz/lobbybalancer/section/ServerSection.java @@ -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");