mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-02-17 17:00:45 +08:00
Fixed config shenanigans
This commit is contained in:
parent
09a0b47bc8
commit
beb04c3f9c
@ -136,20 +136,27 @@ public class Plan extends BukkitPlugin implements IPlan {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
super.onEnable();
|
||||
Log.setDebugMode(Settings.DEBUG.toString());
|
||||
String currentVersion = getVersion();
|
||||
String githubVersionUrl = "https://raw.githubusercontent.com/Rsl1122/Plan-PlayerAnalytics/master/Plan/src/main/resources/plugin.yml";
|
||||
String spigotUrl = "https://www.spigotmc.org/resources/plan-player-analytics.32536/";
|
||||
try {
|
||||
if (Version.checkVersion(currentVersion, githubVersionUrl) || Version.checkVersion(currentVersion, spigotUrl)) {
|
||||
Log.infoColor("§a----------------------------------------");
|
||||
Log.infoColor("§aNew version is available at https://www.spigotmc.org/resources/plan-player-analytics.32536/");
|
||||
Log.infoColor("§a----------------------------------------");
|
||||
File configFile = new File(getDataFolder(), "config.yml");
|
||||
config = new Config(configFile);
|
||||
config.copyDefaults(FileUtil.lines(this, "config.yml"));
|
||||
config.save();
|
||||
|
||||
Log.setDebugMode(Settings.DEBUG.toString());
|
||||
|
||||
String currentVersion = getVersion();
|
||||
String githubVersionUrl = "https://raw.githubusercontent.com/Rsl1122/Plan-PlayerAnalytics/master/Plan/src/main/resources/plugin.yml";
|
||||
String spigotUrl = "https://www.spigotmc.org/resources/plan-player-analytics.32536/";
|
||||
try {
|
||||
if (Version.checkVersion(currentVersion, githubVersionUrl) || Version.checkVersion(currentVersion, spigotUrl)) {
|
||||
Log.infoColor("§a----------------------------------------");
|
||||
Log.infoColor("§aNew version is available at https://www.spigotmc.org/resources/plan-player-analytics.32536/");
|
||||
Log.infoColor("§a----------------------------------------");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.error("Failed to check newest version number");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.error("Failed to check newest version number");
|
||||
}
|
||||
try {
|
||||
|
||||
Benchmark.start("Enable");
|
||||
|
||||
GeolocationCache.checkDB();
|
||||
@ -158,19 +165,12 @@ public class Plan extends BukkitPlugin implements IPlan {
|
||||
|
||||
Benchmark.start("Reading server variables");
|
||||
serverVariableHolder = new ServerVariableHolder(getServer());
|
||||
Log.logDebug("Enable", Benchmark.stopAndFormat("Reading server variables"));
|
||||
|
||||
Benchmark.start("Copy default config");
|
||||
File configFile = new File(getDataFolder(), "config.yml");
|
||||
config = new Config(configFile, FileUtil.lines(this, configFile, "config.yml"));
|
||||
config.save();
|
||||
Log.logDebug("Enable", Benchmark.stopAndFormat("Copy default config"));
|
||||
|
||||
Benchmark.stop("Enable", "Reading server variables");
|
||||
|
||||
Benchmark.start("Init Database");
|
||||
Log.info(Locale.get(Msg.ENABLE_DB_INIT).toString());
|
||||
initDatabase();
|
||||
Log.logDebug("Enable", Benchmark.stopAndFormat("Init Database"));
|
||||
Benchmark.stop("Enable", "Init Database");
|
||||
|
||||
Benchmark.start("WebServer Initialization");
|
||||
webServer = new WebServer(this);
|
||||
@ -186,7 +186,7 @@ public class Plan extends BukkitPlugin implements IPlan {
|
||||
}
|
||||
serverInfoManager.updateServerInfo();
|
||||
|
||||
Log.logDebug("Enable", Benchmark.stopAndFormat("WebServer Initialization"));
|
||||
Benchmark.stop("Enable", "WebServer Initialization");
|
||||
|
||||
if (!reloading) {
|
||||
registerListeners();
|
||||
@ -210,7 +210,7 @@ public class Plan extends BukkitPlugin implements IPlan {
|
||||
|
||||
Benchmark.start("Hook to 3rd party plugins");
|
||||
hookHandler = new HookHandler(this);
|
||||
Log.logDebug("Enable", Benchmark.stopAndFormat("Hook to 3rd party plugins"));
|
||||
Benchmark.stop("Enable", "Hook to 3rd party plugins");
|
||||
|
||||
ImporterManager.registerImporter(new OfflinePlayerImporter());
|
||||
|
||||
@ -218,7 +218,8 @@ public class Plan extends BukkitPlugin implements IPlan {
|
||||
bStats.registerMetrics();
|
||||
|
||||
Log.debug("Verbose debug messages are enabled.");
|
||||
Log.logDebug("Enable", Benchmark.stopAndFormat("Enable"));
|
||||
Benchmark.stop("Enable", "Enable");
|
||||
Log.logDebug("Enable");
|
||||
Log.info(Locale.get(Msg.ENABLED).toString());
|
||||
new ShutdownHook(this);
|
||||
} catch (Exception e) {
|
||||
@ -270,7 +271,7 @@ public class Plan extends BukkitPlugin implements IPlan {
|
||||
}
|
||||
}).runTaskTimerAsynchronously(TimeAmount.SECOND.ticks(), TimeAmount.MINUTE.ticks() * 5L);
|
||||
|
||||
Log.logDebug("Enable", Benchmark.stopAndFormat("Task Registration"));
|
||||
Benchmark.stop("Enable", "Task Registration");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -339,7 +340,7 @@ public class Plan extends BukkitPlugin implements IPlan {
|
||||
registerListener(new PlanWorldChangeListener(this));
|
||||
registerListener(new PlanCommandPreprocessListener(this));
|
||||
registerListener(new PlanDeathEventListener(this));
|
||||
Log.logDebug("Enable", Benchmark.stopAndFormat("Register Listeners"));
|
||||
Benchmark.stop("Enable", "Register Listeners");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -475,7 +476,7 @@ public class Plan extends BukkitPlugin implements IPlan {
|
||||
|
||||
@Override
|
||||
public Config getMainConfig() {
|
||||
return null;
|
||||
return config;
|
||||
}
|
||||
|
||||
public InformationManager getInfoManager() {
|
||||
|
@ -29,8 +29,10 @@ import main.java.com.djrapitops.plan.systems.processing.Processor;
|
||||
import main.java.com.djrapitops.plan.systems.queue.ProcessingQueue;
|
||||
import main.java.com.djrapitops.plan.systems.tasks.TPSCountTimer;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.WebServer;
|
||||
import main.java.com.djrapitops.plan.utilities.file.FileUtil;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.SQLException;
|
||||
@ -56,20 +58,26 @@ public class PlanBungee extends BungeePlugin implements IPlan {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
super.onEnable();
|
||||
Log.setDebugMode(Settings.DEBUG.toString());
|
||||
String currentVersion = getVersion();
|
||||
String githubVersionUrl = "https://raw.githubusercontent.com/Rsl1122/Plan-PlayerAnalytics/master/Plan/src/main/resources/plugin.yml";
|
||||
String spigotUrl = "https://www.spigotmc.org/resources/plan-player-analytics.32536/";
|
||||
try {
|
||||
if (Version.checkVersion(currentVersion, githubVersionUrl) || Version.checkVersion(currentVersion, spigotUrl)) {
|
||||
Log.infoColor("§a----------------------------------------");
|
||||
Log.infoColor("§aNew version is available at https://www.spigotmc.org/resources/plan-player-analytics.32536/");
|
||||
Log.infoColor("§a----------------------------------------");
|
||||
File configFile = new File(getDataFolder(), "config.yml");
|
||||
config = new Config(configFile);
|
||||
config.copyDefaults(FileUtil.lines(this, "bungeeconfig.yml"));
|
||||
config.save();
|
||||
|
||||
Log.setDebugMode(Settings.DEBUG.toString());
|
||||
|
||||
String currentVersion = getVersion();
|
||||
String githubVersionUrl = "https://raw.githubusercontent.com/Rsl1122/Plan-PlayerAnalytics/master/Plan/src/main/resources/plugin.yml";
|
||||
String spigotUrl = "https://www.spigotmc.org/resources/plan-player-analytics.32536/";
|
||||
try {
|
||||
if (Version.checkVersion(currentVersion, githubVersionUrl) || Version.checkVersion(currentVersion, spigotUrl)) {
|
||||
Log.infoColor("§a----------------------------------------");
|
||||
Log.infoColor("§aNew version is available at https://www.spigotmc.org/resources/plan-player-analytics.32536/");
|
||||
Log.infoColor("§a----------------------------------------");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.error("Failed to check newest version number");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.error("Failed to check newest version number");
|
||||
}
|
||||
try {
|
||||
variableHolder = new ServerVariableHolder(getProxy());
|
||||
|
||||
new Locale(this).loadLocale();
|
||||
|
@ -123,7 +123,7 @@ public enum Settings {
|
||||
if (value != null) {
|
||||
return value;
|
||||
}
|
||||
return getConfig().getConfigNode(configPath).getBoolean();
|
||||
return getConfig().getBoolean(configPath);
|
||||
}
|
||||
|
||||
public boolean isFalse() {
|
||||
@ -141,7 +141,7 @@ public enum Settings {
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return getConfig().getConfigNode(configPath).getString();
|
||||
return getConfig().getString(configPath);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -150,11 +150,11 @@ public enum Settings {
|
||||
* @return Integer value of the config setting
|
||||
*/
|
||||
public int getNumber() {
|
||||
return getConfig().getConfigNode(configPath).getInt();
|
||||
return getConfig().getInt(configPath);
|
||||
}
|
||||
|
||||
public List<String> getStringList() {
|
||||
return getConfig().getConfigNode(configPath).getStringList();
|
||||
return getConfig().getStringList(configPath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,7 +16,7 @@ import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.file.FileUtil;
|
||||
import main.java.com.djrapitops.plan.utilities.html.HtmlUtils;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Used for parsing a Html String out of AnalysisData and the html file.
|
||||
@ -45,7 +45,7 @@ public class AnalysisPageParser extends PageParser {
|
||||
addValue("playersOnline", getPlayersOnline());
|
||||
try {
|
||||
return HtmlUtils.replacePlaceholders(FileUtil.getStringFromResource("server.html"), placeHolders);
|
||||
} catch (FileNotFoundException e) {
|
||||
} catch (IOException e) {
|
||||
throw new ParseException(e);
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,8 @@ import main.java.com.djrapitops.plan.utilities.file.FileUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Manages local server info file.
|
||||
@ -25,35 +25,20 @@ import java.util.*;
|
||||
*/
|
||||
public class ServerInfoFile extends Config {
|
||||
public ServerInfoFile(Plan plugin) throws IOException {
|
||||
this(plugin, new File(plugin.getDataFolder(), "ServerInfoFile.yml"));
|
||||
}
|
||||
|
||||
ServerInfoFile(Plan plugin, File file) throws IOException {
|
||||
super(file, FileUtil.lines(file));
|
||||
List<String> defaults = new ArrayList<>();
|
||||
defaults.add("Server:");
|
||||
defaults.add(" UUID:");
|
||||
defaults.add("Bungee:");
|
||||
defaults.add(" WebAddress:");
|
||||
defaults.add(" Fail:");
|
||||
copyDefaults(defaults);
|
||||
super(new File(plugin.getDataFolder(), "ServerInfoFile.yml"));
|
||||
copyDefaults(FileUtil.lines(plugin, "DefaultServerInfoFile.yml"));
|
||||
save();
|
||||
}
|
||||
|
||||
public void saveInfo(ServerInfo thisServer, ServerInfo bungee) throws IOException {
|
||||
Map<String, Serializable> serverMap = new HashMap<>();
|
||||
Map<String, Serializable> bungeeMap = new HashMap<>();
|
||||
|
||||
serverMap.put("UUID", thisServer.getUuid().toString());
|
||||
set("Server", serverMap);
|
||||
set("Server.UUID", thisServer.getUuid().toString());
|
||||
|
||||
String oldAddress = getString("Bungee.WebAddress");
|
||||
String newAddress = bungee.getWebAddress();
|
||||
|
||||
if (!newAddress.equals(oldAddress)) {
|
||||
bungeeMap.put("Fail", 0);
|
||||
bungeeMap.put("WebAddress", newAddress);
|
||||
set("Bungee", bungeeMap);
|
||||
set("Bungee.Fail", 0);
|
||||
set("Bungee.WebAddress", newAddress);
|
||||
}
|
||||
save();
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.file.FileUtil;
|
||||
import org.apache.commons.lang3.text.StrSubstitutor;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -27,7 +27,7 @@ public class ErrorResponse extends Response {
|
||||
public ErrorResponse() {
|
||||
try {
|
||||
setContent(Theme.replaceColors(FileUtil.getStringFromResource("error.html")));
|
||||
} catch (FileNotFoundException e) {
|
||||
} catch (IOException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ package main.java.com.djrapitops.plan.systems.webserver.response;
|
||||
|
||||
import main.java.com.djrapitops.plan.utilities.file.FileUtil;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Response class for returning file contents.
|
||||
@ -22,7 +22,7 @@ public class FileResponse extends Response {
|
||||
super.setHeader("HTTP/1.1 200 OK");
|
||||
try {
|
||||
super.setContent(FileUtil.getStringFromResource(fileName));
|
||||
} catch (FileNotFoundException e) {
|
||||
} catch (IOException e) {
|
||||
super.setContent(new NotFoundResponse(fileName + " was not found inside the .jar or /plugins/Plan/ folder").getContent());
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import main.java.com.djrapitops.plan.utilities.file.FileUtil;
|
||||
import main.java.com.djrapitops.plan.utilities.html.Html;
|
||||
import org.apache.commons.lang3.text.StrSubstitutor;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
@ -28,7 +28,7 @@ public class PlayersPageResponse extends Response {
|
||||
replace.put("content", buildContent(names));
|
||||
replace.put("version", plugin.getVersion());
|
||||
super.setContent(Theme.replaceColors(StrSubstitutor.replace(FileUtil.getStringFromResource("players.html"), replace)));
|
||||
} catch (SQLException | FileNotFoundException e) {
|
||||
} catch (SQLException | IOException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
setContent(new InternalErrorResponse(e, "/players").getContent());
|
||||
}
|
||||
|
@ -23,29 +23,14 @@ public class FileUtil {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
public static String getStringFromResource(String fileName) throws FileNotFoundException {
|
||||
InputStream resourceStream = null;
|
||||
Scanner scanner = null;
|
||||
try {
|
||||
IPlan plugin = MiscUtils.getIPlan();
|
||||
File localFile = new File(plugin.getDataFolder(), fileName);
|
||||
|
||||
if (localFile.exists()) {
|
||||
scanner = new Scanner(localFile, "UTF-8");
|
||||
} else {
|
||||
resourceStream = plugin.getResource(fileName);
|
||||
scanner = new Scanner(resourceStream);
|
||||
}
|
||||
|
||||
StringBuilder html = new StringBuilder();
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
html.append(line).append("\r\n");
|
||||
}
|
||||
return html.toString();
|
||||
} finally {
|
||||
MiscUtils.close(resourceStream, scanner);
|
||||
}
|
||||
public static String getStringFromResource(String fileName) throws IOException {
|
||||
StringBuilder html = new StringBuilder();
|
||||
IPlan plugin = MiscUtils.getIPlan();
|
||||
lines(MiscUtils.getIPlan(), new File(plugin.getDataFolder(), fileName), fileName)
|
||||
.forEach(line -> {
|
||||
html.append(line).append("\r\n");
|
||||
});
|
||||
return html.toString();
|
||||
}
|
||||
|
||||
public static List<String> lines(IPlan plugin, File savedFile, String defaults) throws IOException {
|
||||
|
5
Plan/src/main/resources/DefaultServerInfoFile.yml
Normal file
5
Plan/src/main/resources/DefaultServerInfoFile.yml
Normal file
@ -0,0 +1,5 @@
|
||||
Server:
|
||||
UUID:
|
||||
Bungee:
|
||||
WebAddress: ''
|
||||
Fail: 1
|
Loading…
Reference in New Issue
Block a user