88 lines
3.3 KiB
Java
88 lines
3.3 KiB
Java
|
package de.survivalprojekt.LS.Managers;
|
||
|
|
||
|
import java.io.File;
|
||
|
import java.io.IOException;
|
||
|
import java.io.InputStream;
|
||
|
import java.nio.file.Files;
|
||
|
import java.nio.file.StandardCopyOption;
|
||
|
|
||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||
|
|
||
|
import de.survivalprojekt.LS.ServerManager;
|
||
|
|
||
|
public class MotdManager {
|
||
|
final String folderName = "serevricon";
|
||
|
final String iconName = "server-icon.png";
|
||
|
File motdFile;
|
||
|
|
||
|
public MotdManager() {
|
||
|
initFiles();
|
||
|
}
|
||
|
|
||
|
private void initFiles() {
|
||
|
ServerManager inst = ServerManager.getInst();
|
||
|
/////// SETUP CONFIG ///////
|
||
|
motdFile = new File(inst.getDataFolder(), "motd.yml");
|
||
|
if (!motdFile.exists()) {
|
||
|
try (InputStream inputStream = inst.getResource("motd.yml")) {
|
||
|
if (inputStream != null) {
|
||
|
Files.copy(inputStream, motdFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||
|
inst.getLogger().info("Die Standard-MOTD-Konfigurationsdatei wurde erstellt.");
|
||
|
} else {
|
||
|
inst.getLogger().warning("Standart MOTD-Konfigurationsdatei konnte nicht gefunden werden.");
|
||
|
}
|
||
|
} catch (IOException e) {
|
||
|
inst.getLogger().severe("Fehler beim erstellen der MOTD-Konfigurationsdatei: " + e.getMessage());
|
||
|
}
|
||
|
}
|
||
|
/////// SETUP LOGO ///////
|
||
|
// Erstelle ordner, falss noch nicht vorhanden
|
||
|
File logoFolder = new File(inst.getDataFolder() + "/" + folderName);
|
||
|
if (!logoFolder.exists()) {
|
||
|
logoFolder.mkdirs();
|
||
|
inst.getLogger().info("Der Ordner " + folderName + " wurde erstellt.");
|
||
|
}
|
||
|
File logoFile = new File(logoFolder, iconName);
|
||
|
// Kopiere das Standardlogo, falls nicht vorhanden
|
||
|
if (!logoFile.exists()) {
|
||
|
try (InputStream inputStream = inst.getResource(iconName)) {
|
||
|
if (inputStream != null) {
|
||
|
Files.copy(inputStream, logoFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||
|
inst.getLogger().info("Das Standard-Server-Icon wurde im " + folderName + " Ordner erstellt.");
|
||
|
} else {
|
||
|
inst.getLogger().warning("Standard-Logo " + iconName + " konnte nicht gefunden werden.");
|
||
|
}
|
||
|
} catch (IOException e) {
|
||
|
inst.getLogger().severe("Fehler beim Einrichten des Standard-Server-Icons: " + e.getMessage());
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void reloadMotd() {
|
||
|
ServerManager inst = ServerManager.getInst();
|
||
|
motdFile = new File(inst.getDataFolder(), "motd.yml");
|
||
|
if (!motdFile.exists()) {
|
||
|
initFiles();
|
||
|
}
|
||
|
inst.getLogger().info("MOTD-Konfiguration wurde neu geladen.");
|
||
|
}
|
||
|
|
||
|
public String getMotd() {
|
||
|
FileConfiguration motdConfig = YamlConfiguration.loadConfiguration(motdFile);
|
||
|
|
||
|
if (motdConfig.contains("motd")) {
|
||
|
return motdConfig.getString("motd");
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
public String getFolderName() {
|
||
|
return this.folderName;
|
||
|
}
|
||
|
|
||
|
public String getIconName() {
|
||
|
return this.iconName;
|
||
|
}
|
||
|
}
|