mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 01:37:37 +00:00
Added short overflow check for schematic saving.
This commit is contained in:
parent
713f23d0de
commit
414c3cf33d
@ -129,12 +129,23 @@ public class RegionClipboard {
|
||||
*
|
||||
* @param path
|
||||
* @throws IOException
|
||||
* @throws SchematicException
|
||||
*/
|
||||
public void saveSchematic(String path) throws IOException {
|
||||
public void saveSchematic(String path) throws IOException, SchematicException {
|
||||
int xs = getWidth();
|
||||
int ys = getHeight();
|
||||
int zs = getLength();
|
||||
|
||||
if (xs > 65535) {
|
||||
throw new SchematicException("Width of region too large for a .schematic");
|
||||
}
|
||||
if (ys > 65535) {
|
||||
throw new SchematicException("Height of region too large for a .schematic");
|
||||
}
|
||||
if (zs > 65535) {
|
||||
throw new SchematicException("Length of region too large for a .schematic");
|
||||
}
|
||||
|
||||
HashMap<String,Tag> schematic = new HashMap<String,Tag>();
|
||||
schematic.put("Width", new ShortTag("Width", (short)xs));
|
||||
schematic.put("Length", new ShortTag("Length", (short)zs));
|
||||
@ -174,27 +185,27 @@ public class RegionClipboard {
|
||||
* @param path
|
||||
* @param origin
|
||||
* @return
|
||||
* @throws SchematicLoadException
|
||||
* @throws SchematicException
|
||||
* @throws IOException
|
||||
*/
|
||||
public static RegionClipboard loadSchematic(String path, Point<Integer> origin)
|
||||
throws SchematicLoadException, IOException {
|
||||
throws SchematicException, IOException {
|
||||
FileInputStream stream = new FileInputStream(path);
|
||||
NBTInputStream nbtStream = new NBTInputStream(stream);
|
||||
CompoundTag schematicTag = (CompoundTag)nbtStream.readTag();
|
||||
if (!schematicTag.getName().equals("Schematic")) {
|
||||
throw new SchematicLoadException("Tag \"Schematic\" does not exist or is not first");
|
||||
throw new SchematicException("Tag \"Schematic\" does not exist or is not first");
|
||||
}
|
||||
Map<String,Tag> schematic = schematicTag.getValue();
|
||||
if (!schematic.containsKey("Blocks")) {
|
||||
throw new SchematicLoadException("Schematic file is missing a \"Blocks\" tag");
|
||||
throw new SchematicException("Schematic file is missing a \"Blocks\" tag");
|
||||
}
|
||||
short xs = (Short)getChildTag(schematic, "Width", ShortTag.class).getValue();
|
||||
short zs = (Short)getChildTag(schematic, "Length", ShortTag.class).getValue();
|
||||
short ys = (Short)getChildTag(schematic, "Height", ShortTag.class).getValue();
|
||||
String materials = (String)getChildTag(schematic, "Materials", StringTag.class).getValue();
|
||||
if (!materials.equals("Alpha")) {
|
||||
throw new SchematicLoadException("Schematic file is not an Alpha schematic");
|
||||
throw new SchematicException("Schematic file is not an Alpha schematic");
|
||||
}
|
||||
byte[] blocks = (byte[])getChildTag(schematic, "Blocks", ByteArrayTag.class).getValue();
|
||||
|
||||
@ -223,13 +234,13 @@ public class RegionClipboard {
|
||||
}
|
||||
|
||||
private static Tag getChildTag(Map<String,Tag> items, String key, Class expected)
|
||||
throws SchematicLoadException {
|
||||
throws SchematicException {
|
||||
if (!items.containsKey(key)) {
|
||||
throw new SchematicLoadException("Schematic file is missing a \"" + key + "\" tag");
|
||||
throw new SchematicException("Schematic file is missing a \"" + key + "\" tag");
|
||||
}
|
||||
Tag tag = items.get(key);
|
||||
if (!expected.isInstance(tag)) {
|
||||
throw new SchematicLoadException(
|
||||
throw new SchematicException(
|
||||
key + " tag is not of tag type " + expected.getName());
|
||||
}
|
||||
return tag;
|
||||
|
@ -467,7 +467,7 @@ public class WorldEdit extends Plugin {
|
||||
logger.log(Level.INFO, player.getName() + " loaded " + filePath);
|
||||
player.sendMessage(Colors.LightPurple + filename + " loaded.");
|
||||
}
|
||||
} catch (SchematicLoadException e) {
|
||||
} catch (SchematicException e) {
|
||||
player.sendMessage(Colors.Rose + "Load error: " + e.getMessage());
|
||||
} catch (IOException e) {
|
||||
player.sendMessage(Colors.Rose + "Schematic could not read or it does not exist.");
|
||||
@ -505,6 +505,8 @@ public class WorldEdit extends Plugin {
|
||||
logger.log(Level.INFO, player.getName() + " saved " + filePath);
|
||||
player.sendMessage(Colors.LightPurple + filename + " saved.");
|
||||
}
|
||||
} catch (SchematicException se) {
|
||||
player.sendMessage(Colors.Rose + "Save error: " + se.getMessage());
|
||||
} catch (IOException e) {
|
||||
player.sendMessage(Colors.Rose + "Schematic could not written.");
|
||||
}
|
||||
|
@ -23,8 +23,8 @@ package com.sk89q.worldedit;
|
||||
*
|
||||
* @author Albert
|
||||
*/
|
||||
public class SchematicLoadException extends WorldEditException {
|
||||
public SchematicLoadException(String error) {
|
||||
public class SchematicException extends WorldEditException {
|
||||
public SchematicException(String error) {
|
||||
super(error);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user