From b54ed5c5d554686497917090e6526cf21727b0a9 Mon Sep 17 00:00:00 2001 From: Jaime Martinez Rincon Date: Thu, 26 Jan 2017 13:44:02 +0100 Subject: [PATCH] Now all sections types may not have a provider --- .../lobbybalancer/commands/FallbackCommand.java | 6 +----- .../lobbybalancer/listener/ServerKickListener.java | 14 +++++--------- .../lobbybalancer/section/ServerSection.java | 9 ++++----- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/main/java/me/jaimemartz/lobbybalancer/commands/FallbackCommand.java b/src/main/java/me/jaimemartz/lobbybalancer/commands/FallbackCommand.java index a673907..3d61710 100644 --- a/src/main/java/me/jaimemartz/lobbybalancer/commands/FallbackCommand.java +++ b/src/main/java/me/jaimemartz/lobbybalancer/commands/FallbackCommand.java @@ -50,11 +50,7 @@ public class FallbackCommand extends Command { String bind = rules.getString(section.getName()); ServerSection target = plugin.getSectionManager().getByName(bind); - if (target == null) { - target = section.getParent(); - } - - return target; + return target == null ? section.getParent() : target; } } else { if (ConfigEntries.FALLBACK_PRINCIPAL_ENABLED.get()) { diff --git a/src/main/java/me/jaimemartz/lobbybalancer/listener/ServerKickListener.java b/src/main/java/me/jaimemartz/lobbybalancer/listener/ServerKickListener.java index 9469084..eb029cc 100644 --- a/src/main/java/me/jaimemartz/lobbybalancer/listener/ServerKickListener.java +++ b/src/main/java/me/jaimemartz/lobbybalancer/listener/ServerKickListener.java @@ -53,14 +53,6 @@ public class ServerKickListener implements Listener { return null; } - Configuration rules = plugin.getConfig().getSection("settings.reconnect-kick.rules"); - String name = rules.getString(section.getName()); - ServerSection target = plugin.getSectionManager().getByName(name); - - if (target == null) { - target = section.getParent(); - } - AtomicBoolean matches = new AtomicBoolean(false); String reason = TextComponent.toPlainText(event.getKickReasonComponent()); for (String pattern : ConfigEntries.RECONNECT_KICK_REASONS.get()) { @@ -79,7 +71,11 @@ public class ServerKickListener implements Listener { } if (matches.get()) { - return target; + Configuration rules = plugin.getConfig().getSection("settings.reconnect-kick.rules"); + String name = rules.getString(section.getName()); + ServerSection target = plugin.getSectionManager().getByName(name); + + return target == null ? section.getParent() : target; } } else { if (ConfigEntries.FALLBACK_PRINCIPAL_ENABLED.get()) { diff --git a/src/main/java/me/jaimemartz/lobbybalancer/section/ServerSection.java b/src/main/java/me/jaimemartz/lobbybalancer/section/ServerSection.java index e1700dc..cf14dbe 100644 --- a/src/main/java/me/jaimemartz/lobbybalancer/section/ServerSection.java +++ b/src/main/java/me/jaimemartz/lobbybalancer/section/ServerSection.java @@ -56,11 +56,6 @@ public class ServerSection { if (parent == null) { throw new IllegalArgumentException(String.format("The section \"%s\" has an invalid parent set", name)); } - } else { - //Principal sections do not necessarily must have a parent section, but might - if (!principal) { - throw new IllegalArgumentException(String.format("The section \"%s\" does not have a parent set", name)); - } } if (ConfigUtils.isSet(section, "servers")) { @@ -166,6 +161,10 @@ public class ServerSection { return dummy; } + public boolean hasParent() { + return parent != null; + } + public ServerSection getParent() { return parent; }