Copy default server icon into favicons folder
This commit is contained in:
1 parent
fb397c56b4
commit
6d1ee2acb2
2 files changed
+34
-4
No files matched your search
@@ -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<F> {
|
||||
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();
|
||||
|
||||
@@ -53,6 +53,7 @@ public class FileHandler {
|
||||
|
||||
private final Path config;
|
||||
private final Path profilesFolder;
|
||||
private final Path faviconsFolder;
|
||||
|
||||
private final List<ServerListProfile> 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<ServerListProfile> 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)
|
||||
|
||||
Reference in new issue
Block a user