Skip to content

Commit

Permalink
Defensive programming to avoid errors with schematics.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jul 15, 2017
1 parent 7e7d6fb commit d95d86f
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/com/wasteofplastic/askyblock/schematics/Schematic.java
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,14 @@ public Schematic(ASkyBlock plugin, File file) throws IOException {
List<Tag> pos = new ArrayList<Tag>();
pos = ((ListTag) entry.getValue()).getValue();
//Bukkit.getLogger().info("DEBUG pos: " + pos);
double x = (double)pos.get(0).getValue() - origin.getX();
double y = (double)pos.get(1).getValue() - origin.getY();
double z = (double)pos.get(2).getValue() - origin.getZ();
ent.setLocation(new BlockVector(x,y,z));
if (pos.size() == 3) {
double x = (double)pos.get(0).getValue() - origin.getX();
double y = (double)pos.get(1).getValue() - origin.getY();
double z = (double)pos.get(2).getValue() - origin.getZ();
ent.setLocation(new BlockVector(x,y,z));
} else {
ent.setLocation(new BlockVector(0,0,0));
}
}
} else if (entry.getKey().equals("Motion")) {
//Bukkit.getLogger().info("DEBUG Pos fond");
Expand All @@ -419,8 +423,12 @@ public Schematic(ASkyBlock plugin, File file) throws IOException {
List<Tag> pos = new ArrayList<Tag>();
pos = ((ListTag) entry.getValue()).getValue();
//Bukkit.getLogger().info("DEBUG pos: " + pos);
ent.setMotion(new Vector((double)pos.get(0).getValue(), (double)pos.get(1).getValue()
,(double)pos.get(2).getValue()));
if (pos.size() == 3) {
ent.setMotion(new Vector((double)pos.get(0).getValue(), (double)pos.get(1).getValue()
,(double)pos.get(2).getValue()));
} else {
ent.setMotion(new Vector(0,0,0));
}
}
} else if (entry.getKey().equals("Rotation")) {
//Bukkit.getLogger().info("DEBUG Pos fond");
Expand All @@ -429,8 +437,13 @@ public Schematic(ASkyBlock plugin, File file) throws IOException {
List<Tag> pos = new ArrayList<Tag>();
pos = ((ListTag) entry.getValue()).getValue();
//Bukkit.getLogger().info("DEBUG pos: " + pos);
ent.setYaw((float)pos.get(0).getValue());
ent.setPitch((float)pos.get(1).getValue());
if (pos.size() == 2) {
ent.setYaw((float)pos.get(0).getValue());
ent.setPitch((float)pos.get(1).getValue());
} else {
ent.setYaw(0F);
ent.setPitch(0F);
}
}
} else if (entry.getKey().equals("Color")) {
if (entry.getValue() instanceof ByteTag) {
Expand Down

0 comments on commit d95d86f

Please sign in to comment.