Reduced usage of static Settings accessors

This commit is contained in:
Rsl1122 2018-09-09 15:30:20 +03:00
parent 3a7b94a94f
commit 273050f1b2
14 changed files with 78 additions and 73 deletions

View File

@ -149,7 +149,7 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
@Override
public ColorScheme getColorScheme() {
return PlanColorScheme.create();
return PlanColorScheme.create(system.getConfigSystem().getConfig(), logger);
}
/**

View File

@ -150,7 +150,7 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
@Override
public ColorScheme getColorScheme() {
return PlanColorScheme.create();
return PlanColorScheme.create(system.getConfigSystem().getConfig(), logger);
}
@Override

View File

@ -92,7 +92,7 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
private Metrics metrics;
@Inject
private Logger logger;
private Logger slf4jLogger;
@Inject
@ConfigDir(sharedRoot = false)
@ -128,19 +128,19 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
system.getDatabaseSystem().getActiveDatabase()
).registerMetrics();
logger.info(locale.getString(PluginLang.ENABLED));
slf4jLogger.info(locale.getString(PluginLang.ENABLED));
} catch (AbstractMethodError e) {
logger.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart.");
slf4jLogger.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart.");
} catch (EnableException e) {
logger.error("----------------------------------------");
logger.error("Error: " + e.getMessage());
logger.error("----------------------------------------");
logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
slf4jLogger.error("----------------------------------------");
slf4jLogger.error("Error: " + e.getMessage());
slf4jLogger.error("----------------------------------------");
slf4jLogger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
onDisable();
} catch (Exception e) {
errorHandler.log(L.CRITICAL, this.getClass(), e);
logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
logger.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
slf4jLogger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
slf4jLogger.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
onDisable();
}
registerCommand("plan", component.planCommand());
@ -164,7 +164,7 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
@Override
public ColorScheme getColorScheme() {
return PlanColorScheme.create();
return PlanColorScheme.create(system.getConfigSystem().getConfig(), logger);
}
@Override
@ -179,7 +179,7 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
@Override
public Logger getLogger() {
return logger;
return slf4jLogger;
}
@Override

View File

@ -5,6 +5,8 @@ import com.djrapitops.plan.system.info.server.BungeeServerInfo;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.info.server.properties.BungeeServerProperties;
import com.djrapitops.plan.system.info.server.properties.ServerProperties;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.settings.config.PlanConfig;
import dagger.Module;
import dagger.Provides;
@ -26,7 +28,7 @@ public class BungeeInfoModule {
@Provides
@Singleton
ServerProperties provideServerProperties(PlanBungee plugin) {
return new BungeeServerProperties(plugin.getProxy());
ServerProperties provideServerProperties(PlanBungee plugin, PlanConfig config) {
return new BungeeServerProperties(plugin.getProxy(), config.getString(Settings.BUNGEE_IP));
}
}

View File

@ -1,6 +1,5 @@
package com.djrapitops.plan.system.info.server.properties;
import com.djrapitops.plan.system.settings.Settings;
import net.md_5.bungee.api.ProxyServer;
/**
@ -12,14 +11,14 @@ import net.md_5.bungee.api.ProxyServer;
*/
public class BungeeServerProperties extends ServerProperties {
public BungeeServerProperties(ProxyServer server) {
public BungeeServerProperties(ProxyServer server, String ip) {
super(
server.getServers().toString(),
"BungeeCord",
-1,
server.getVersion(),
server.getVersion(),
Settings.BUNGEE_IP::toString,
() -> ip,
server.getConfig().getPlayerLimit(),
RedisCheck.isClassAvailable() ? new RedisPlayersOnlineSupplier() : server::getOnlineCount
);

View File

@ -5,6 +5,7 @@ import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.processing.processors.Processors;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.settings.config.PlanConfig;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import org.bukkit.command.Command;
@ -23,6 +24,7 @@ import javax.inject.Inject;
public class CommandListener implements Listener {
private final Plan plugin;
private final PlanConfig config;
private final Processors processors;
private final Processing processing;
private final ErrorHandler errorHandler;
@ -30,11 +32,13 @@ public class CommandListener implements Listener {
@Inject
public CommandListener(
Plan plugin,
PlanConfig config,
Processors processors,
Processing processing,
ErrorHandler errorHandler
) {
this.plugin = plugin;
this.config = config;
this.processors = processors;
this.processing = processing;
this.errorHandler = errorHandler;
@ -57,8 +61,8 @@ public class CommandListener implements Listener {
private void actOnCommandEvent(PlayerCommandPreprocessEvent event) {
String commandName = event.getMessage().substring(1).split(" ")[0].toLowerCase();
boolean logUnknownCommands = Settings.LOG_UNKNOWN_COMMANDS.isTrue();
boolean combineCommandAliases = Settings.COMBINE_COMMAND_ALIASES.isTrue();
boolean logUnknownCommands = config.isTrue(Settings.LOG_UNKNOWN_COMMANDS);
boolean combineCommandAliases = config.isTrue(Settings.COMBINE_COMMAND_ALIASES);
if (!logUnknownCommands || combineCommandAliases) {
Command command = getBukkitCommand(commandName);

View File

@ -4,6 +4,7 @@ import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.processing.processors.Processors;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.settings.config.PlanConfig;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import org.spongepowered.api.Sponge;
@ -24,16 +25,19 @@ import java.util.Optional;
*/
public class SpongeCommandListener {
private final PlanConfig config;
private final Processors processors;
private final Processing processing;
private ErrorHandler errorHandler;
@Inject
public SpongeCommandListener(
PlanConfig config,
Processors processors,
Processing processing,
ErrorHandler errorHandler
) {
this.config = config;
this.processors = processors;
this.processing = processing;
this.errorHandler = errorHandler;
@ -55,8 +59,8 @@ public class SpongeCommandListener {
private void actOnCommandEvent(SendCommandEvent event) {
String commandName = event.getCommand();
boolean logUnknownCommands = Settings.LOG_UNKNOWN_COMMANDS.isTrue();
boolean combineCommandAliases = Settings.COMBINE_COMMAND_ALIASES.isTrue();
boolean logUnknownCommands = config.isTrue(Settings.LOG_UNKNOWN_COMMANDS);
boolean combineCommandAliases = config.isTrue(Settings.COMBINE_COMMAND_ALIASES);
if (!logUnknownCommands || combineCommandAliases) {
Optional<? extends CommandMapping> existingCommand = Sponge.getCommandManager().get(commandName);

View File

@ -8,7 +8,6 @@ import com.djrapitops.plan.data.container.GeoInfo;
import com.djrapitops.plan.system.cache.GeolocationCache;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.processing.CriticalRunnable;
import com.djrapitops.plan.system.settings.Settings;
import java.net.InetAddress;
import java.security.NoSuchAlgorithmException;
@ -39,14 +38,12 @@ public class IPUpdateProcessor implements CriticalRunnable {
@Override
public void run() {
if (Settings.DATA_GEOLOCATIONS.isTrue()) {
try {
String country = GeolocationCache.getCountry(ip.getHostAddress());
GeoInfo geoInfo = new GeoInfo(ip, country, time);
database.save().geoInfo(uuid, geoInfo);
} catch (NoSuchAlgorithmException ignore) {
// Ignored, SHA-256 should be available
}
try {
String country = GeolocationCache.getCountry(ip.getHostAddress());
GeoInfo geoInfo = new GeoInfo(ip, country, time);
database.save().geoInfo(uuid, geoInfo);
} catch (NoSuchAlgorithmException ignore) {
// Ignored, SHA-256 should be available
}
}
}

View File

@ -5,8 +5,10 @@
package com.djrapitops.plan.system.settings.theme;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plan.system.settings.config.PlanConfig;
import com.djrapitops.plugin.command.ColorScheme;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.console.PluginLogger;
/**
* ColorScheme that uses values in config settings specific to Plan or PlanBungee.
@ -19,15 +21,15 @@ public class PlanColorScheme extends ColorScheme {
super(colors);
}
public static PlanColorScheme create() {
public static PlanColorScheme create(PlanConfig config, PluginLogger logger) {
try {
String main = "§" + Settings.COLOR_MAIN.toString().charAt(1);
String secondary = "§" + Settings.COLOR_SEC.toString().charAt(1);
String tertiary = "§" + Settings.COLOR_TER.toString().charAt(1);
String main = "§" + config.getString(Settings.COLOR_MAIN).charAt(1);
String secondary = "§" + config.getString(Settings.COLOR_SEC).charAt(1);
String tertiary = "§" + config.getString(Settings.COLOR_TER).charAt(1);
return new PlanColorScheme(main, secondary, tertiary);
} catch (Exception e) {
Log.infoColor("§cCustomization, Chat colors set-up wrong, using defaults.");
logger.log(L.INFO_COLOR, "§cCustomization, Chat colors set-up wrong, using defaults.");
return new PlanColorScheme("§2", "§7", "§f");
}
}

View File

@ -3,11 +3,11 @@ package com.djrapitops.plan.system.webserver;
import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.system.SubSystem;
import com.djrapitops.plan.system.file.FileSystem;
import com.djrapitops.plan.system.info.server.properties.ServerProperties;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.PluginLang;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.settings.config.PlanConfig;
import com.djrapitops.plan.utilities.html.HtmlUtils;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.console.PluginLogger;
@ -43,6 +43,7 @@ public class WebServer implements SubSystem {
private final FileSystem fileSystem;
private final PlanConfig config;
private final ServerProperties serverProperties;
private final RequestHandler requestHandler;
private final PluginLogger logger;
@ -59,6 +60,7 @@ public class WebServer implements SubSystem {
Locale locale,
FileSystem fileSystem,
PlanConfig config,
ServerProperties serverProperties,
PluginLogger logger,
ErrorHandler errorHandler,
RequestHandler requestHandler
@ -66,6 +68,7 @@ public class WebServer implements SubSystem {
this.locale = locale;
this.fileSystem = fileSystem;
this.config = config;
this.serverProperties = serverProperties;
this.requestHandler = requestHandler;
@ -228,6 +231,12 @@ public class WebServer implements SubSystem {
}
public String getAccessAddress() {
return isEnabled() ? getProtocol() + "://" + HtmlUtils.getIP() : config.getString(Settings.EXTERNAL_WEBSERVER_LINK);
return isEnabled() ? getProtocol() + "://" + getIP() : config.getString(Settings.EXTERNAL_WEBSERVER_LINK);
}
private String getIP() {
return config.isTrue(Settings.SHOW_ALTERNATIVE_IP)
? config.getString(Settings.ALTERNATIVE_IP).replace("%port%", String.valueOf(port))
: serverProperties.getIp() + ":" + port;
}
}

View File

@ -51,17 +51,17 @@ public class HtmlExport extends SpecificExport {
@Inject
public HtmlExport(
PlanPlugin plugin,
FileSystem fileSystem,
PlanConfig config,
Theme theme,
Processing processing,
FileSystem fileSystem,
Database database,
PageFactory pageFactory,
ServerInfo serverInfo,
ConnectionSystem connectionSystem,
ErrorHandler errorHandler
) {
super(config, serverInfo);
super(fileSystem, config, serverInfo);
this.plugin = plugin;
this.theme = theme;
this.processing = processing;

View File

@ -4,7 +4,7 @@
*/
package com.djrapitops.plan.utilities.file.export;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.file.FileSystem;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.settings.config.PlanConfig;
@ -29,13 +29,19 @@ import java.util.UUID;
*/
public abstract class SpecificExport implements Runnable {
private final FileSystem fileSystem;
private final PlanConfig config;
private final ServerInfo serverInfo;
protected final File outputFolder;
private final boolean usingBungee;
protected SpecificExport(PlanConfig config, ServerInfo serverInfo) {
protected SpecificExport(
FileSystem fileSystem,
PlanConfig config,
ServerInfo serverInfo
) {
this.fileSystem = fileSystem;
this.config = config;
this.serverInfo = serverInfo;
outputFolder = getFolder();
@ -43,19 +49,20 @@ public abstract class SpecificExport implements Runnable {
}
protected File getFolder() {
String path = Settings.ANALYSIS_EXPORT_PATH.toString();
File folder;
String path = config.getString(Settings.ANALYSIS_EXPORT_PATH);
boolean isAbsolute = Paths.get(path).isAbsolute();
if (isAbsolute) {
File folder = new File(path);
if (!folder.exists() || !folder.isDirectory()) {
folder.mkdirs();
}
return folder;
folder = new File(path);
} else {
File dataFolder = fileSystem.getDataFolder();
folder = new File(dataFolder, path);
}
if (!folder.exists() || !folder.isDirectory()) {
folder.mkdirs();
}
File dataFolder = PlanPlugin.getInstance().getDataFolder();
File folder = new File(dataFolder, path);
folder.mkdirs();
return folder;
}
@ -106,7 +113,7 @@ public abstract class SpecificExport implements Runnable {
File htmlLocation;
if (usingBungee) {
if (serverUUID.equals(ServerInfo.getServerUUID_Old())) {
if (serverUUID.equals(serverInfo.getServerUUID())) {
htmlLocation = new File(outputFolder, "network");
} else {
htmlLocation = new File(getServerFolder(), serverName.replace(" ", "%20").replace(".", "%2E"));

View File

@ -1,8 +1,5 @@
package com.djrapitops.plan.utilities.html;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.settings.Settings;
/**
* @author Rsl1122
*/
@ -15,22 +12,6 @@ public class HtmlUtils {
throw new IllegalStateException("Utility class");
}
/**
* Used to get the WebServer's IP with Port.
*
* @return For example 127.0.0.1:8804
*/
public static String getIP() {
int port = Settings.WEBSERVER_PORT.getNumber();
String ip;
if (Settings.SHOW_ALTERNATIVE_IP.isTrue()) {
ip = Settings.ALTERNATIVE_IP.toString().replace("%port%", String.valueOf(port));
} else {
ip = ServerInfo.getServerProperties_Old().getIp() + ":" + port;
}
return ip;
}
/**
* Attempts to remove XSS components.
*

View File

@ -145,7 +145,7 @@ public class InspectPage implements Page {
if (allSessions.isEmpty()) {
replacer.put("accordionSessions", "<div class=\"body\">" + "<p>No Sessions</p>" + "</div>");
} else {
if (Settings.DISPLAY_SESSIONS_AS_TABLE.isTrue()) {
if (config.isTrue(Settings.DISPLAY_SESSIONS_AS_TABLE)) {
replacer.put("accordionSessions", new PlayerSessionTable(playerName, allSessions).parseHtml());
} else {
SessionAccordion sessionAccordion = SessionAccordion.forPlayer(allSessions, () -> serverNames);