Some more little changes

This commit is contained in:
Jaime Martínez Rincón 2017-09-14 21:28:37 +02:00
parent 3d293b1887
commit 62ebd71080
4 changed files with 28 additions and 51 deletions

View File

@ -19,6 +19,7 @@ import ninja.leaping.configurate.commented.CommentedConfigurationNode;
import ninja.leaping.configurate.hocon.HoconConfigurationLoader; import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
import ninja.leaping.configurate.loader.ConfigurationLoader; import ninja.leaping.configurate.loader.ConfigurationLoader;
import org.bstats.bungeecord.Metrics; import org.bstats.bungeecord.Metrics;
import org.bstats.bungeecord.Metrics.SingleLineChart;
import org.inventivetalent.update.bungee.BungeeUpdater; import org.inventivetalent.update.bungee.BungeeUpdater;
import java.io.File; import java.io.File;
@ -31,19 +32,24 @@ public class PlayerBalancer extends Plugin {
private boolean failed = false; private boolean failed = false;
private StatusManager statusManager; private StatusManager statusManager;
private SettingsHolder settings; private SettingsHolder settings;
private ConfigurationLoader<CommentedConfigurationNode> loader;
private SectionManager sectionManager; private SectionManager sectionManager;
private NetworkManager networkManager; private NetworkManager networkManager;
private ConfigurationLoader<CommentedConfigurationNode> loader;
private Command fallbackCommand, mainCommand, manageCommand; private Command fallbackCommand, mainCommand, manageCommand;
private Listener connectListener, kickListener, messageListener, reloadListener; private Listener connectListener, kickListener, messageListener, reloadListener;
@Override @Override
public void onEnable() { public void onEnable() {
Metrics metrics = new Metrics(this); Metrics metrics = new Metrics(this);
metrics.addCustomChart(new Metrics.SingleLineChart("configured_sections", () -> sectionManager.getSections().size())); metrics.addCustomChart(new SingleLineChart("configured_sections", () -> sectionManager.getSections().size()));
this.enable(); this.enable();
} }
@Override
public void onDisable() {
disable();
}
private void enable() { private void enable() {
if (!getDataFolder().exists()) if (!getDataFolder().exists())
getDataFolder().mkdir(); getDataFolder().mkdir();
@ -65,7 +71,6 @@ public class PlayerBalancer extends Plugin {
try { try {
CommentedConfigurationNode node = loader.load(); CommentedConfigurationNode node = loader.load();
settings = node.getValue(TypeToken.of(SettingsHolder.class)); settings = node.getValue(TypeToken.of(SettingsHolder.class));
System.out.println(settings);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -139,11 +144,6 @@ public class PlayerBalancer extends Plugin {
} }
} }
@Override
public void onDisable() {
disable();
}
private void disable() { private void disable() {
getProxy().getPluginManager().unregisterCommand(mainCommand); getProxy().getPluginManager().unregisterCommand(mainCommand);
mainCommand = null; mainCommand = null;

View File

@ -8,7 +8,6 @@ import com.jaimemartz.playerbalancer.utils.FixedAdapter;
import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.connection.Server; import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.api.scheduler.ScheduledTask;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
@ -18,7 +17,6 @@ import java.util.regex.Pattern;
public class SectionManager { public class SectionManager {
private final PlayerBalancer plugin; private final PlayerBalancer plugin;
private final BalancerProps props; private final BalancerProps props;
private ScheduledTask updateTask;
private ServerSection principal; private ServerSection principal;
private final Map<String, ServerSection> sections = Collections.synchronizedMap(new HashMap<>()); private final Map<String, ServerSection> sections = Collections.synchronizedMap(new HashMap<>());
@ -64,11 +62,6 @@ public class SectionManager {
} }
}); });
if (updateTask != null) {
updateTask.cancel();
updateTask = null;
}
principal = null; principal = null;
sections.clear(); sections.clear();
servers.clear(); servers.clear();
@ -122,9 +115,9 @@ public class SectionManager {
private final Stage[] stages = { private final Stage[] stages = {
new SectionStage("Constructing sections") { new SectionStage("Constructing sections") {
@Override @Override
public void execute(String name, SectionProps props, ServerSection section) throws RuntimeException { public void execute(String sectionName, SectionProps sectionProps, ServerSection section) throws RuntimeException {
ServerSection object = new ServerSection(name, props); ServerSection object = new ServerSection(sectionName, sectionProps);
sections.put(name, object); sections.put(sectionName, object);
} }
}, },
new GlobalStage("Processing principal section") { new GlobalStage("Processing principal section") {
@ -141,9 +134,9 @@ public class SectionManager {
}, },
new SectionStage("Processing parents") { new SectionStage("Processing parents") {
@Override @Override
public void execute(String name, SectionProps props, ServerSection section) throws RuntimeException { public void execute(String sectionName, SectionProps sectionProps, ServerSection section) throws RuntimeException {
if (props.getParentName() != null) { if (sectionProps.getParentName() != null) {
ServerSection parent = getByName(props.getParentName()); ServerSection parent = getByName(sectionProps.getParentName());
if (principal.equals(section) && parent == null) { if (principal.equals(section) && parent == null) {
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
"The section \"%s\" has an invalid parent set", "The section \"%s\" has an invalid parent set",
@ -157,7 +150,7 @@ public class SectionManager {
}, },
new SectionStage("Validating parents") { new SectionStage("Validating parents") {
@Override @Override
public void execute(String name, SectionProps props, ServerSection section) throws RuntimeException { public void execute(String sectionName, SectionProps sectionProps, ServerSection section) throws RuntimeException {
ServerSection parent = section.getParent(); ServerSection parent = section.getParent();
if (parent != null && parent.getParent() == section) { if (parent != null && parent.getParent() == section) {
throw new IllegalStateException(String.format( throw new IllegalStateException(String.format(
@ -170,8 +163,8 @@ public class SectionManager {
}, },
new SectionStage("Validating providers") { new SectionStage("Validating providers") {
@Override @Override
public void execute(String name, SectionProps props, ServerSection section) throws RuntimeException { public void execute(String sectionName, SectionProps sectionProps, ServerSection section) throws RuntimeException {
if (props.getProvider() == null) { if (sectionProps.getProvider() == null) {
ServerSection current = section.getParent(); ServerSection current = section.getParent();
if (current != null) { if (current != null) {
while (current.getExplicitProvider() == null) { while (current.getExplicitProvider() == null) {
@ -193,20 +186,20 @@ public class SectionManager {
}, },
new SectionStage("Calculating positions") { new SectionStage("Calculating positions") {
@Override @Override
public void execute(String name, SectionProps props, ServerSection section) throws RuntimeException { public void execute(String sectionName, SectionProps sectionProps, ServerSection section) throws RuntimeException {
section.setPosition(calculatePosition(section)); section.setPosition(calculatePosition(section));
} }
}, },
new SectionStage("Resolving servers") { new SectionStage("Resolving servers") {
@Override @Override
public void execute(String name, SectionProps props, ServerSection section) throws RuntimeException { public void execute(String sectionName, SectionProps sectionProps, ServerSection section) throws RuntimeException {
section.setServers(calculateServers(section)); section.setServers(calculateServers(section));
} }
}, },
new SectionStage("Section server processing") { new SectionStage("Section server processing") {
@Override @Override
public void execute(String name, SectionProps props, ServerSection section) throws RuntimeException { public void execute(String sectionName, SectionProps sectionProps, ServerSection section) throws RuntimeException {
if (props.getServerName() != null) { if (sectionProps.getServerName() != null) {
FakeServer server = new FakeServer(section); FakeServer server = new FakeServer(section);
section.setServer(server); section.setServer(server);
plugin.getSectionManager().register(server, section); plugin.getSectionManager().register(server, section);
@ -217,9 +210,9 @@ public class SectionManager {
}, },
new SectionStage("Section command processing") { new SectionStage("Section command processing") {
@Override @Override
public void execute(String name, SectionProps props, ServerSection section) throws RuntimeException { public void execute(String sectionName, SectionProps sectionProps, ServerSection section) throws RuntimeException {
if (props.getCommand() != null) { if (sectionProps.getCommand() != null) {
SectionCommand command = new SectionCommand(plugin, props.getCommand(), section); SectionCommand command = new SectionCommand(plugin, sectionProps.getCommand(), section);
section.setCommand(command); section.setCommand(command);
plugin.getProxy().getPluginManager().registerCommand(plugin, command); plugin.getProxy().getPluginManager().registerCommand(plugin, command);
} }
@ -227,10 +220,10 @@ public class SectionManager {
}, },
new SectionStage("Finishing loading sections") { new SectionStage("Finishing loading sections") {
@Override @Override
public void execute(String name, SectionProps props, ServerSection section) throws RuntimeException { public void execute(String sectionName, SectionProps sectionProps, ServerSection section) throws RuntimeException {
section.setValid(true); section.setValid(true);
} }
} },
}; };
public Set<ServerInfo> calculateServers(ServerSection section) { public Set<ServerInfo> calculateServers(ServerSection section) {
@ -345,8 +338,8 @@ public class SectionManager {
} }
public abstract void execute( public abstract void execute(
String name, String sectionName,
SectionProps props, SectionProps sectionProps,
ServerSection section ServerSection section
) throws RuntimeException; ) throws RuntimeException;
} }

View File

@ -20,9 +20,6 @@ public class GeneralProps {
@Setting(value = "fallback-principal") @Setting(value = "fallback-principal")
private boolean fallbackPrincipal; private boolean fallbackPrincipal;
@Setting(value = "auto-refresh")
private boolean autoRefresh;
public boolean isEnabled() { public boolean isEnabled() {
return enabled; return enabled;
} }
@ -63,14 +60,6 @@ public class GeneralProps {
this.fallbackPrincipal = fallbackPrincipal; this.fallbackPrincipal = fallbackPrincipal;
} }
public boolean isAutoRefresh() {
return autoRefresh;
}
public void setAutoRefresh(boolean autoRefresh) {
this.autoRefresh = autoRefresh;
}
@Override @Override
public String toString() { public String toString() {
return "GeneralProps{" + return "GeneralProps{" +
@ -79,7 +68,6 @@ public class GeneralProps {
", autoReload=" + autoReload + ", autoReload=" + autoReload +
", redisBungee=" + redisBungee + ", redisBungee=" + redisBungee +
", fallbackPrincipal=" + fallbackPrincipal + ", fallbackPrincipal=" + fallbackPrincipal +
", autoRefresh=" + autoRefresh +
'}'; '}';
} }
} }

View File

@ -8,10 +8,6 @@ general {
# IMPORTANT! Set this to true after configuring the plugin! # IMPORTANT! Set this to true after configuring the plugin!
enabled=false enabled=false
# When true, the plugin will check for new servers added to bungee
# TODO Not done yet
auto-refresh=false
# When true, the plugin will reload when you execute /greload # When true, the plugin will reload when you execute /greload
auto-reload=true auto-reload=true