diff --git a/core/src/main/java/ch/andre601/advancedserverlist/core/AdvancedServerList.java b/core/src/main/java/ch/andre601/advancedserverlist/core/AdvancedServerList.java index 84d7c4d..f2c82bc 100644 --- a/core/src/main/java/ch/andre601/advancedserverlist/core/AdvancedServerList.java +++ b/core/src/main/java/ch/andre601/advancedserverlist/core/AdvancedServerList.java @@ -35,7 +35,6 @@ import ch.andre601.advancedserverlist.core.profiles.conditions.expressions.Expre import ch.andre601.advancedserverlist.core.profiles.players.PlayerHandler; import java.io.IOException; import java.io.InputStream; -import java.nio.file.Path; import java.util.Arrays; import java.util.List; import java.util.Properties; @@ -141,9 +140,12 @@ public class AdvancedServerList { return; } - Path folder = getPlugin().getFolderPath().resolve("favicons"); - if (!folder.toFile().exists() && folder.toFile().mkdirs()) - getPlugin().getPluginLogger().info("Successfully created favicons folder."); + if (getFileHandler().loadFavicons()) { + getPlugin().getPluginLogger().info("Successfully loaded favicons!"); + } else { + getPlugin().getPluginLogger().warn("Unable to load favicons! Check previous lines for errors."); + return; + } getPlugin().getPluginLogger().info("Loading Commands..."); plugin.loadCommands(); diff --git a/core/src/main/java/ch/andre601/advancedserverlist/core/file/FileHandler.java b/core/src/main/java/ch/andre601/advancedserverlist/core/file/FileHandler.java index 9755d5c..9f57c65 100644 --- a/core/src/main/java/ch/andre601/advancedserverlist/core/file/FileHandler.java +++ b/core/src/main/java/ch/andre601/advancedserverlist/core/file/FileHandler.java @@ -53,6 +53,7 @@ public class FileHandler { private final Path config; private final Path profilesFolder; + private final Path faviconsFolder; private final List profiles = new ArrayList<>(); @@ -64,6 +65,7 @@ public class FileHandler { this.config = core.getPlugin().getFolderPath().resolve("config.yml"); this.profilesFolder = core.getPlugin().getFolderPath().resolve("profiles"); + this.faviconsFolder = core.getPlugin().getFolderPath().resolve("favicons"); } public List getProfiles() { @@ -117,6 +119,32 @@ public class FileHandler { return reloadProfiles(); } + public boolean loadFavicons() { + logger.info("Loading favicons..."); + if (!faviconsFolder.toFile().exists() && faviconsFolder.toFile().mkdirs()) { + logger.info("Successfully created favicons folder."); + } + + Path serverIcon = faviconsFolder.resolve("server-icon.png"); + if (serverIcon.toFile().exists()) { + return true; + } + + try (InputStream stream = plugin.getClass().getResourceAsStream("/favicons/server-icon.png")) { + if (stream == null) { + logger.warn("Cannot retrieve server-icon.png from Plugin."); + return false; + } + + Files.copy(stream, serverIcon); + logger.info("Created default server-icon.png in favicons folder."); + return true; + } catch (IOException ex) { + logger.warn("Cannot create server-icon.png for plugin.", ex); + return false; + } + } + public boolean migrateConfig() { YamlConfigurationLoader loader = YamlConfigurationLoader.builder() .path(config)