Initial commit: LoParkour v1.1.0
This commit is contained in:
commit
aecb03ccf8
120 changed files with 9668 additions and 0 deletions
56
src/main/java/dev/loki/loparkour/schematic/Schematics.java
Normal file
56
src/main/java/dev/loki/loparkour/schematic/Schematics.java
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
package dev.loki.loparkour.schematic;
|
||||
|
||||
import dev.loki.loparkour.LoParkour;
|
||||
import dev.loki.loparkour.config.Config;
|
||||
import dev.efnilite.vilib.util.Task;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Stores schematics, so they don't have to be read every time.
|
||||
*/
|
||||
public class Schematics {
|
||||
|
||||
private static final String[] SPAWN_SCHEMATICS = new String[]{
|
||||
"spawn-island", "spawn-island-duels"
|
||||
};
|
||||
private static final File FOLDER = LoParkour.getInFolder("schematics");
|
||||
|
||||
/**
|
||||
* Reads all files.
|
||||
*/
|
||||
public static void init() {
|
||||
Task.create(LoParkour.getPlugin()).async().execute(() -> {
|
||||
if (!FOLDER.exists()) {
|
||||
FOLDER.mkdirs();
|
||||
}
|
||||
|
||||
File[] files = FOLDER.listFiles((dir, name) -> name.contains("parkour-") || name.contains("spawn-island"));
|
||||
|
||||
if (files == null || files.length == 0) {
|
||||
download();
|
||||
init();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
dev.efnilite.vilib.schematic.Schematics.addFromFiles(LoParkour.getPlugin(), files);
|
||||
} catch (IOException | ClassNotFoundException ex) {
|
||||
LoParkour.logging().stack("Error while trying to load schematics", ex);
|
||||
}
|
||||
}).run();
|
||||
}
|
||||
|
||||
private static void download() {
|
||||
LoParkour.log("Downloading schematics");
|
||||
|
||||
List<String> schematics = new ArrayList<>();
|
||||
schematics.addAll(Arrays.asList(SPAWN_SCHEMATICS));
|
||||
schematics.addAll(Config.SCHEMATICS.getChildren("difficulty", false).stream().map("parkour-%s"::formatted).toList());
|
||||
schematics.forEach(file -> LoParkour.getPlugin().saveResource("schematics/%s".formatted(file), true));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue