mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-01 02:46:41 +00:00
Added a command to list schematics and the abilitiy to autodetect schematic format
This commit is contained in:
@ -22,6 +22,7 @@ import com.sk89q.jnbt.ByteArrayTag;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.IntTag;
|
||||
import com.sk89q.jnbt.ListTag;
|
||||
import com.sk89q.jnbt.NBTConstants;
|
||||
import com.sk89q.jnbt.NBTInputStream;
|
||||
import com.sk89q.jnbt.NBTOutputStream;
|
||||
import com.sk89q.jnbt.ShortTag;
|
||||
@ -34,6 +35,7 @@ import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.TileEntityBlock;
|
||||
import com.sk89q.worldedit.data.DataException;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
@ -244,6 +246,31 @@ public class MCEditSchematicFormat extends SchematicFormat {
|
||||
stream.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOfFormat(File file) {
|
||||
DataInputStream str = null;
|
||||
try {
|
||||
str = new DataInputStream(new GZIPInputStream(new FileInputStream(file)));
|
||||
if ((str.readByte() & 0xFF) != NBTConstants.TYPE_COMPOUND) {
|
||||
return false;
|
||||
}
|
||||
byte[] nameBytes = new byte[str.readShort() & 0xFFFF];
|
||||
str.readFully(nameBytes);
|
||||
String name = new String(nameBytes, NBTConstants.CHARSET);
|
||||
return name.equals("Schematic");
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
} finally {
|
||||
if (str != null) {
|
||||
try {
|
||||
str.close();
|
||||
} catch (IOException ignore) {
|
||||
// blargh
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get child tag of a NBT structure.
|
||||
*
|
||||
|
@ -45,6 +45,8 @@ import java.util.Set;
|
||||
*/
|
||||
public abstract class SchematicFormat {
|
||||
private static final Map<String, SchematicFormat> SCHEMATIC_FORMATS = new HashMap<String, SchematicFormat>();
|
||||
|
||||
// Built-in schematic formats
|
||||
public static final SchematicFormat MCEDIT = new MCEditSchematicFormat();
|
||||
|
||||
public static Set<SchematicFormat> getFormats() {
|
||||
@ -55,6 +57,19 @@ public abstract class SchematicFormat {
|
||||
return SCHEMATIC_FORMATS.get(lookupName.toLowerCase());
|
||||
}
|
||||
|
||||
public static SchematicFormat getFormat(File file) {
|
||||
if (!file.isFile()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (SchematicFormat format : SCHEMATIC_FORMATS.values()) {
|
||||
if (format.isOfFormat(file)) {
|
||||
return format;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private final String name;
|
||||
private final String[] lookupNames;
|
||||
|
||||
@ -137,4 +152,6 @@ public abstract class SchematicFormat {
|
||||
* @throws DataException If the clipboard has data which cannot be stored
|
||||
*/
|
||||
public abstract void save(CuboidClipboard clipboard, File file) throws IOException, DataException;
|
||||
|
||||
public abstract boolean isOfFormat(File file);
|
||||
}
|
||||
|
Reference in New Issue
Block a user