mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-10-26 22:10:22 +00:00
Catch more structure export exceptions, add more information to exception messages.
This commit is contained in:
1 parent
24c17f2ee6
commit
b0a3cf9ffe
2 files changed
+25
-6
No files matched your search
@@ -1,7 +1,22 @@
|
|||||||
package com.dfsek.terra.structure;
|
package com.dfsek.terra.structure;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class InitializationException extends Exception {
|
public class InitializationException extends Exception {
|
||||||
public InitializationException(String message) {
|
private final Location worldLoc;
|
||||||
|
public InitializationException(String message, @Nullable Location worldLoc) {
|
||||||
super(message);
|
super(message);
|
||||||
|
this.worldLoc = worldLoc == null ? null :worldLoc.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return super.getMessage() + " (at location: " + worldLoc.toString() + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Location getWorldLoc() {
|
||||||
|
return worldLoc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,6 +79,7 @@ public class Structure implements Serializable {
|
|||||||
StructureContainedBlock.Pull pull = StructureContainedBlock.Pull.NONE;
|
StructureContainedBlock.Pull pull = StructureContainedBlock.Pull.NONE;
|
||||||
int pullOffset = 0;
|
int pullOffset = 0;
|
||||||
StructureSpawnRequirement requirement = StructureSpawnRequirement.BLANK;
|
StructureSpawnRequirement requirement = StructureSpawnRequirement.BLANK;
|
||||||
|
try {
|
||||||
if(state instanceof Sign) { // Magic sign stuff
|
if(state instanceof Sign) { // Magic sign stuff
|
||||||
Sign s = (Sign) b.getState();
|
Sign s = (Sign) b.getState();
|
||||||
if(s.getLine(0).equals("[TERRA]")) {
|
if(s.getLine(0).equals("[TERRA]")) {
|
||||||
@@ -94,7 +95,7 @@ public class Structure implements Serializable {
|
|||||||
try {
|
try {
|
||||||
requirement = StructureSpawnRequirement.valueOf(spawn.toUpperCase());
|
requirement = StructureSpawnRequirement.valueOf(spawn.toUpperCase());
|
||||||
} catch(IllegalArgumentException e) {
|
} catch(IllegalArgumentException e) {
|
||||||
throw new InitializationException("Invalid spawn type: " + spawn);
|
throw new InitializationException("Invalid spawn type: " + spawn, b.getLocation());
|
||||||
}
|
}
|
||||||
} else if(s.getLine(1).startsWith("[PULL=") && s.getLine(1).endsWith("]")) {
|
} else if(s.getLine(1).startsWith("[PULL=") && s.getLine(1).endsWith("]")) {
|
||||||
String og = s.getLine(1);
|
String og = s.getLine(1);
|
||||||
@@ -103,16 +104,19 @@ public class Structure implements Serializable {
|
|||||||
try {
|
try {
|
||||||
pull = StructureContainedBlock.Pull.valueOf(spawn);
|
pull = StructureContainedBlock.Pull.valueOf(spawn);
|
||||||
} catch(IllegalArgumentException e) {
|
} catch(IllegalArgumentException e) {
|
||||||
throw new InitializationException("Invalid pull type: " + spawn);
|
throw new InitializationException("Invalid pull type: " + spawn, b.getLocation());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new InitializationException("Invalid Magic Sign: \"" + s.getLine(1) + "\"");
|
throw new InitializationException("Invalid Magic Sign: \"" + s.getLine(1) + "\"", b.getLocation());
|
||||||
}
|
}
|
||||||
} catch(IllegalArgumentException e) {
|
} catch(IllegalArgumentException e) {
|
||||||
throw new InitializationException("Invalid Block Data on sign: \"" + s.getLine(2) + s.getLine(3) + "\"");
|
throw new InitializationException("Invalid Block Data on sign: \"" + s.getLine(2) + s.getLine(3) + "\"", b.getLocation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch(StringIndexOutOfBoundsException e) {
|
||||||
|
throw new InitializationException("Invalid sign.", b.getLocation());
|
||||||
|
}
|
||||||
StructureContainedBlock block = new StructureContainedBlock(x, y, z, useState ? state : null, d, requirement, pull, pullOffset);
|
StructureContainedBlock block = new StructureContainedBlock(x, y, z, useState ? state : null, d, requirement, pull, pullOffset);
|
||||||
if(state instanceof BlockInventoryHolder) {
|
if(state instanceof BlockInventoryHolder) {
|
||||||
inventories.add(new StructureContainedInventory(((BlockInventoryHolder) state).getInventory(), block));
|
inventories.add(new StructureContainedInventory(((BlockInventoryHolder) state).getInventory(), block));
|
||||||
@@ -122,7 +126,7 @@ public class Structure implements Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(centerX < 0 || centerZ < 0) throw new InitializationException("No structure center specified.");
|
if(centerX < 0 || centerZ < 0) throw new InitializationException("No structure center specified.", null);
|
||||||
structureInfo = new StructureInfo(l2.getBlockX()-l1.getBlockX()+1, l2.getBlockY()-l1.getBlockY()+1, l2.getBlockZ()-l1.getBlockZ()+1, new Vector2(centerX, centerZ));
|
structureInfo = new StructureInfo(l2.getBlockX()-l1.getBlockX()+1, l2.getBlockY()-l1.getBlockY()+1, l2.getBlockZ()-l1.getBlockZ()+1, new Vector2(centerX, centerZ));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user