Progress on migrating to properties

This commit is contained in:
Jaime Martinez Rincon 2017-08-09 20:06:18 +02:00
parent 65930a7510
commit 6205a61bb0
4 changed files with 19 additions and 20 deletions

View File

@ -13,6 +13,10 @@ import com.jaimemartz.playerbalancer.ping.StatusManager;
import com.jaimemartz.playerbalancer.section.SectionManager;
import com.jaimemartz.playerbalancer.settings.Settings;
import com.jaimemartz.playerbalancer.settings.SettingsProvider;
import com.jaimemartz.playerbalancer.settings.types.CheckerProperties;
import com.jaimemartz.playerbalancer.settings.types.CommandProperties;
import com.jaimemartz.playerbalancer.settings.types.GeneralProperties;
import com.jaimemartz.playerbalancer.settings.types.ReconnectorProperties;
import lombok.Getter;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.plugin.Command;
@ -63,12 +67,12 @@ public class PlayerBalancer extends Plugin {
mainCommand = new MainCommand(this);
getProxy().getPluginManager().registerCommand(this, mainCommand);
if (ConfigEntries.PLUGIN_ENABLED.get()) {
if (ConfigEntries.SILENT_STARTUP.get()) {
if (settings.getProperty(GeneralProperties.ENABLED)) {
if (settings.getProperty(GeneralProperties.SILENT)) {
getLogger().setLevel(Level.WARNING);
}
if (ConfigEntries.AUTO_RELOAD_ENABLED.get()) {
if (settings.getProperty(GeneralProperties.AUTO_RELOAD)) {
reloadListener = new ProxyReloadListener(this);
getProxy().getPluginManager().registerListener(this, reloadListener);
}
@ -85,11 +89,11 @@ public class PlayerBalancer extends Plugin {
sectionManager.load();
statusManager = new StatusManager();
if (ConfigEntries.SERVER_CHECK_ENABLED.get()) {
if (settings.getProperty(CheckerProperties.ENABLED)) {
statusManager.start(this);
}
if (ConfigEntries.FALLBACK_COMMAND_ENABLED.get()) {
if (settings.getProperty(CommandProperties.ENABLED)) {
fallbackCommand = new FallbackCommand(this);
getProxy().getPluginManager().registerCommand(this, fallbackCommand);
}
@ -109,7 +113,7 @@ public class PlayerBalancer extends Plugin {
Stream.of(PasteHelper.values()).forEach(a -> a.setUrl(null));
if (ConfigEntries.RECONNECT_KICK_ENABLED.get()) {
if (settings.getProperty(ReconnectorProperties.ENABLED)) {
kickListener = new ServerKickListener(this);
getProxy().getPluginManager().registerListener(this, kickListener);
}
@ -139,20 +143,20 @@ public class PlayerBalancer extends Plugin {
getProxy().getPluginManager().unregisterCommand(mainCommand);
mainCommand = null;
if (ConfigEntries.PLUGIN_ENABLED.get()) {
if (settings.getProperty(GeneralProperties.ENABLED)) {
//Do not try to do anything if the plugin has not loaded correctly
if (isFailed()) return;
if (ConfigEntries.AUTO_RELOAD_ENABLED.get()) {
if (settings.getProperty(GeneralProperties.AUTO_RELOAD)) {
getProxy().getPluginManager().unregisterListener(reloadListener);
reloadListener = null;
}
if (ConfigEntries.SERVER_CHECK_ENABLED.get()) {
if (settings.getProperty(CheckerProperties.ENABLED)) {
statusManager.stop();
}
if (ConfigEntries.FALLBACK_COMMAND_ENABLED.get()) {
if (settings.getProperty(CommandProperties.ENABLED)) {
getProxy().getPluginManager().unregisterCommand(fallbackCommand);
fallbackCommand = null;
}
@ -166,14 +170,14 @@ public class PlayerBalancer extends Plugin {
getProxy().getPluginManager().unregisterCommand(manageCommand);
manageCommand = null;
if (ConfigEntries.RECONNECT_KICK_ENABLED.get()) {
if (settings.getProperty(ReconnectorProperties.ENABLED)) {
getProxy().getPluginManager().unregisterListener(kickListener);
kickListener = null;
}
sectionManager.flush();
if (ConfigEntries.ASSIGN_TARGETS_ENABLED.get()) {
if (settings.getProperty(GeneralProperties.ASSIGN_TARGETS)) {
ServerAssignRegistry.getTable().clear();
}
}

View File

@ -2,7 +2,6 @@ package com.jaimemartz.playerbalancer.ping;
import com.jaimemartz.playerbalancer.PlayerBalancer;
import com.jaimemartz.playerbalancer.section.ServerSection;
import com.jaimemartz.playerbalancer.settings.ConfigEntries;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.scheduler.ScheduledTask;

View File

@ -20,10 +20,10 @@ public class CheckerProperties implements SettingsHolder {
public static final Property<Integer> TIMEOUT = newProperty("settings.server-check.timeout", 5000);
public static final Property<Boolean> DEBUG = newProperty("settings.server-check.print-info", false);
public static final Property<List<String>> MARKER_DESCS = newListProperty("settings.server-check.print-info",
public static final Property<List<String>> MARKER_DESCS = newListProperty("settings.server-check.marker-descs",
"Sever is not accessible",
"Gamemode has already started"
);
public static final Property<Boolean> DEBUG = newProperty("settings.server-check.print-info", false);
}

View File

@ -18,12 +18,8 @@ public class ReconnectorProperties implements SettingsHolder {
public static final Property<List<String>> IGNORED_SECTIONS = newListProperty("settings.reconnect-kick.ignored");
public static final Property<Boolean> RESTRICTED = newProperty("settings.reconnect-kick.restricted", true);
//todo is it really necessary?
public static final Property<Boolean> EXCLUDE_FROM = newProperty("settings.reconnect-kick.exclude-from", true);
public static final Property<Boolean> FORCE_PRINCIPAL = newProperty("settings.reconnect-kick.force-principal", false);
public static final Property<MapBean> RULES = newBeanProperty(MapBean.class, "settings.reconnect-kick",