schematics are just fun

This commit is contained in:
dordsor21 2020-09-26 21:56:38 +01:00
parent 1766c62278
commit 68deed1469
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B

View File

@ -24,11 +24,8 @@ import com.boydti.fawe.object.io.ResettableFileInputStream;
import com.boydti.fawe.object.schematic.MinecraftStructure; import com.boydti.fawe.object.schematic.MinecraftStructure;
import com.boydti.fawe.object.schematic.PNGWriter; import com.boydti.fawe.object.schematic.PNGWriter;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.NBTInputStream; import com.sk89q.jnbt.NBTInputStream;
import com.sk89q.jnbt.NBTOutputStream; import com.sk89q.jnbt.NBTOutputStream;
import com.sk89q.jnbt.NamedTag;
import com.sk89q.jnbt.Tag;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
@ -37,7 +34,6 @@ import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
@ -77,25 +73,7 @@ public enum BuiltInClipboardFormat implements ClipboardFormat {
@Override @Override
public boolean isFormat(File file) { public boolean isFormat(File file) {
String name = file.getName().toLowerCase(); String name = file.getName().toLowerCase();
if (name.endsWith(".schematic")) { return name.endsWith(".schematic") || name.endsWith(".mcedit") || name.endsWith(".mce");
try (NBTInputStream str = new NBTInputStream(new GZIPInputStream(new FileInputStream(file)))) {
NamedTag rootTag = str.readNamedTag();
if (!rootTag.getName().equals("Schematic")) {
return false;
}
CompoundTag schematicTag = (CompoundTag) rootTag.getTag();
// Check
Map<String, Tag> schematic = schematicTag.getValue();
if (!schematic.containsKey("Materials")) {
return false;
}
} catch (Exception e) {
return false;
}
return true;
}
return name.endsWith(".mcedit") || name.endsWith(".mce");
} }
}, },
SPONGE_SCHEMATIC("sponge", "schem") { SPONGE_SCHEMATIC("sponge", "schem") {
@ -131,24 +109,7 @@ public enum BuiltInClipboardFormat implements ClipboardFormat {
@Override @Override
public boolean isFormat(File file) { public boolean isFormat(File file) {
String name = file.getName().toLowerCase(); String name = file.getName().toLowerCase();
if (name.endsWith(".schem") || name.endsWith(".sponge")) { return name.endsWith(".schem") || name.endsWith(".sponge");
try (NBTInputStream str = new NBTInputStream(new GZIPInputStream(new FileInputStream(file)))) {
NamedTag rootTag = str.readNamedTag();
if (!rootTag.getName().equals("Schematic")) {
return false;
}
CompoundTag schematicTag = (CompoundTag) rootTag.getTag();
// Check
Map<String, Tag> schematic = schematicTag.getValue();
if (!schematic.containsKey("Version")) {
return false;
}
} catch (Exception e) {
return false;
}
}
return false;
} }
}, },