more Logging and automatic config file creation
This commit is contained in:
parent
36bbd5ef97
commit
52b37d1094
@ -30,5 +30,6 @@ tasks.register<Exec>("copyJarToTestServer") {
|
|||||||
dependsOn(tasks.jar)
|
dependsOn(tasks.jar)
|
||||||
mustRunAfter(tasks.jar)
|
mustRunAfter(tasks.jar)
|
||||||
|
|
||||||
commandLine("cp", "build/libs/WorldMuseum-1.0-SNAPSHOT.jar", "/home/elias/Dokumente/mcTestServer/plugins/worldmuseum.jar")
|
commandLine("cp", "build/libs/WorldMuseum-1.0-SNAPSHOT.jar", "/Users/olischma/Desktop/paper/plugins")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -45,12 +45,18 @@ public class Main extends JavaPlugin {
|
|||||||
|
|
||||||
private void loadWorlds() {
|
private void loadWorlds() {
|
||||||
File worldFolder = new File(getDataFolder().getAbsolutePath() + "/worlds");
|
File worldFolder = new File(getDataFolder().getAbsolutePath() + "/worlds");
|
||||||
if(!worldFolder.setReadOnly()) throw new RuntimeException("Could not set Worlds to readonly. Be careful!");
|
//if(!worldFolder.setReadOnly()) throw new RuntimeException("Could not set Worlds to readonly. Be careful!");
|
||||||
|
|
||||||
//noinspection ResultOfMethodCallIgnored
|
//noinspection ResultOfMethodCallIgnored
|
||||||
worldFolder.mkdirs();
|
worldFolder.mkdirs();
|
||||||
Arrays.stream(Objects.requireNonNull(worldFolder.listFiles())).forEach(file -> this.worlds.add(new ViewableWorld(file)));
|
Arrays.stream(Objects.requireNonNull(worldFolder.listFiles())).forEach(file -> {
|
||||||
|
Bukkit.getLogger().info("[Worldmuseum] Loading world " + file.getName());
|
||||||
|
if (file.isDirectory()) this.worlds.add(new ViewableWorld(file));
|
||||||
|
else Bukkit.getLogger().info( "[Worldmuseum] " + file.getName() + " is not a valid world!");
|
||||||
|
});
|
||||||
this.worlds.forEach(ViewableWorld::loadWorld);
|
this.worlds.forEach(ViewableWorld::loadWorld);
|
||||||
|
for(ViewableWorld viewableWorld : this.worlds) viewableWorld.getWorld().setAutoSave(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Main instance() {
|
public static Main instance() {
|
||||||
|
@ -3,7 +3,7 @@ package eu.mhsl.minecraft.WorldMuseum.viewableWorld;
|
|||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.util.TriState;
|
import net.kyori.adventure.util.TriState;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.generator.ChunkGenerator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
@ -11,6 +11,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class ViewableWorld {
|
public class ViewableWorld {
|
||||||
@ -23,13 +24,24 @@ public class ViewableWorld {
|
|||||||
|
|
||||||
public ViewableWorld(File worldLocation) {
|
public ViewableWorld(File worldLocation) {
|
||||||
this.worldLocation = worldLocation;
|
this.worldLocation = worldLocation;
|
||||||
this.name = "unnamed_" + worldLocation.getName();
|
this.name = "unnamed_" + this.worldLocation.toPath().getFileName().toString();
|
||||||
File configFile = new File(this.worldLocation.getAbsolutePath() + "/config.yml");
|
File configFile = new File(this.worldLocation.getAbsolutePath() + "/config.yml");
|
||||||
if (configFile.exists()) {
|
if (configFile.exists()) {
|
||||||
ConfigurationSection config = YamlConfiguration.loadConfiguration(configFile);
|
FileConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
||||||
this.enabled = config.getBoolean("enabled");
|
this.enabled = config.getBoolean("enabled");
|
||||||
this.name = config.getString("name");
|
this.name = config.getString("name");
|
||||||
this.icon = Material.valueOf(config.getString("icon"));
|
this.icon = Material.valueOf(config.getString("icon"));
|
||||||
|
} else {
|
||||||
|
System.out.println("[WorldMuseum] Could not find config.yml");
|
||||||
|
try {
|
||||||
|
configFile.createNewFile();
|
||||||
|
FileConfiguration data = YamlConfiguration.loadConfiguration(configFile);
|
||||||
|
data.set("enabled", false);
|
||||||
|
data.set("name", this.name);
|
||||||
|
data.set("icon", this.icon.name());
|
||||||
|
data.save(configFile);
|
||||||
|
|
||||||
|
} catch (IOException e) {e.printStackTrace();}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,4 +75,8 @@ public class ViewableWorld {
|
|||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public World getWorld() {
|
||||||
|
return world;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user