Small little plugin I made for myself that I thought others might find useful.
Use
to create a tab delimited csv file in this plugins resources directory.
Then if you want, you can do
to paste it somewhere.
But if you're like me, and need to be dynamically loading the structures in a different plugin, you can copy this class and load the csv programmatically:
Spoiler: CsvLoader.java
Code (Text):
public class CsvLoader {
public static void loadCsv(World w, String pathToCsvFile, Integer startX, Integer startY, Integer startZ) {
List<List<String>> blocks;
try {
blocks = loadBlockList(new FileReader(pathToCsvFile));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
for (List<String> blockRecord : blocks) {
int xOffset = Integer.parseInt(blockRecord.get(0)), yOffset = Integer.parseInt(blockRecord.get(1)), zOffset = Integer.parseInt(blockRecord.get(2));
Material blockType = Material.getMaterial(blockRecord.get(3));
String blockDataSerialized = blockRecord.get(4);
Block block = w.getBlockAt(startX + xOffset, startY + yOffset, startZ + zOffset);
block.setType(blockType);
block.setBlockData(Bukkit.createBlockData(blockDataSerialized));
}
}
private static List<List<String>> loadBlockList(FileReader structureFileReader) {
List<List<String>> blocks = new ArrayList<>();
try (BufferedReader br = new BufferedReader(structureFileReader)) {
String line;
while ((line = br.readLine()) != null) {
String[] values = line.split("\t");
blocks.add(Arrays.asList(values));
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return blocks;
}
}
My discord:
https://discord.gg/s4F8VEHegN