mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 09:47:38 +00:00
Don't read the entire file to check the format
This commit is contained in:
parent
55dad5a972
commit
7a9adacc32
@ -71,27 +71,13 @@ public enum BuiltInClipboardFormat implements ClipboardFormat {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClipboardWriter getWriter(OutputStream outputStream) throws IOException {
|
public ClipboardWriter getWriter(OutputStream outputStream) throws IOException {
|
||||||
throw new IOException("This format does not support saving, use `schem` as format");
|
throw new IOException("This format does not support saving, use `.schem` as format");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFormat(File file) {
|
public boolean isFormat(File file) {
|
||||||
try (NBTInputStream str = new NBTInputStream(new GZIPInputStream(new FileInputStream(file)))) {
|
String name = file.getName().toLowerCase();
|
||||||
NamedTag rootTag = str.readNamedTag();
|
return name.endsWith(".schematic") || name.endsWith(".mcedit") || name.endsWith(".mce");
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
SPONGE_SCHEMATIC("sponge", "schem") {
|
SPONGE_SCHEMATIC("sponge", "schem") {
|
||||||
@ -126,23 +112,8 @@ public enum BuiltInClipboardFormat implements ClipboardFormat {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFormat(File file) {
|
public boolean isFormat(File file) {
|
||||||
try (NBTInputStream str = new NBTInputStream(new GZIPInputStream(new FileInputStream(file)))) {
|
String name = file.getName().toLowerCase();
|
||||||
NamedTag rootTag = str.readNamedTag();
|
return name.endsWith(".schem") || name.endsWith(".sponge");
|
||||||
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 true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
@ -174,7 +145,7 @@ public enum BuiltInClipboardFormat implements ClipboardFormat {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFormat(File file) {
|
public boolean isFormat(File file) {
|
||||||
return file.getName().endsWith(".nbt");
|
return file.getName().toLowerCase().endsWith(".nbt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user