59 lines
1.5 KiB
Java
59 lines
1.5 KiB
Java
package eu.univento.core.api.schematic;
|
|
|
|
import eu.univento.core.Core;
|
|
import org.bukkit.Location;
|
|
|
|
import java.io.BufferedWriter;
|
|
import java.io.File;
|
|
import java.io.FileWriter;
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* @author joethei
|
|
* @version 0.1
|
|
*/
|
|
public class Schematic {
|
|
|
|
private String name;
|
|
private Cuboid cuboid;
|
|
|
|
public Schematic(String name) {
|
|
this.name = name;
|
|
}
|
|
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
public Cuboid getCuboid() {
|
|
return cuboid;
|
|
}
|
|
|
|
public boolean save(String name, ArrayList<String> list) {
|
|
File file = new File(Core.getInstance().getDataFolder().getAbsolutePath() + "/schematics/", name + ".building");
|
|
String line = System.getProperty("line.separator");
|
|
if(file.exists()) return false;
|
|
try {
|
|
if(!file.createNewFile()) return false;
|
|
BufferedWriter writter = new BufferedWriter(new FileWriter(file));
|
|
for(String s : list) {
|
|
writter.write(s);
|
|
writter.write(line);
|
|
}
|
|
writter.close();
|
|
return true;
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
public List<String> getBlockList(Location loc) {
|
|
return cuboid.getBlocks().stream().map(Object::toString).collect(Collectors.toCollection(ArrayList::new));
|
|
}
|
|
|
|
} |