mirror of
https://github.com/YouHaveTrouble/BlockEdit.git
synced 2026-06-29 21:46:19 +00:00
reading of schematic file
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
package me.youhavetrouble.blockedit;
|
||||
|
||||
import me.youhavetrouble.blockedit.util.Clipboard;
|
||||
import net.querz.nbt.io.NBTInputStream;
|
||||
import net.querz.nbt.io.NamedTag;
|
||||
import net.querz.nbt.tag.CompoundTag;
|
||||
import net.querz.nbt.tag.Tag;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.*;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public class SchematicHandler {
|
||||
|
||||
@@ -31,9 +36,25 @@ public class SchematicHandler {
|
||||
/**
|
||||
* Loads a schematic from the schematics directory
|
||||
* @param schematicName Name of the schematic
|
||||
* @return Clipboard object containing the schematic
|
||||
* @return Clipboard object containing the schematic. Null if schematic does not exist
|
||||
*/
|
||||
public Clipboard loadSchematic(String schematicName) {
|
||||
File schematicFile = new File(plugin.getDataFolder(), "schematics/" + schematicName + ".schematic");
|
||||
|
||||
try (DataInputStream dis = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(schematicFile))))) {
|
||||
NamedTag tag = new NBTInputStream(dis).readTag(Tag.DEFAULT_MAX_DEPTH);
|
||||
|
||||
if (tag == null) return null;
|
||||
if (!(tag.getTag() instanceof CompoundTag compoundTag)) return null;
|
||||
|
||||
plugin.getLogger().info(compoundTag.get("Width").toString());
|
||||
plugin.getLogger().info(compoundTag.get("Height").toString());
|
||||
plugin.getLogger().info(compoundTag.get("Length").toString());
|
||||
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user