Skip to content

Commit

Permalink
Sanitize min max in constructor of Bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
Redned235 committed Jul 1, 2024
1 parent 18db698 commit 3eab0b9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@ public Bounds(int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
}

public Bounds(Position min, Position max) {
// Sanitize min max
if (min.blockX() > max.blockX()) {
int temp = min.blockX();
min = Position.block(max.blockX(), min.blockY(), min.blockZ());
max = Position.block(temp, max.blockY(), max.blockZ());
}

if (min.blockY() > max.blockY()) {
int temp = min.blockY();
min = Position.block(min.blockX(), max.blockY(), min.blockZ());
max = Position.block(max.blockX(), temp, max.blockZ());
}

if (min.blockZ() > max.blockZ()) {
int temp = min.blockZ();
min = Position.block(min.blockX(), min.blockY(), max.blockZ());
max = Position.block(max.blockX(), max.blockY(), temp);
}

this.minX = min.blockX();
this.minY = min.blockY();
this.minZ = min.blockZ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public final class ArenaEditorWizards {
try {
map.save();
} catch (ParseException | IOException e) {
BattleArena.getInstance().error("Failed to create map file for arena {}", ctx.getArena().getName(), e);
BattleArena.getInstance().error("Failed to save map file for arena {}", ctx.getArena().getName(), e);
Messages.MAP_FAILED_TO_SAVE.send(ctx.getPlayer(), map.getName());
return;
}
Expand All @@ -95,25 +95,6 @@ public final class ArenaEditorWizards {
Position min = ctx.getMin();
Position max = ctx.getMax();

// Sanitize min max
if (min.blockX() > max.blockX()) {
int temp = min.blockX();
min = Position.block(max.blockX(), min.blockY(), min.blockZ());
max = Position.block(temp, max.blockY(), max.blockZ());
}

if (min.blockY() > max.blockY()) {
int temp = min.blockY();
min = Position.block(min.blockX(), max.blockY(), min.blockZ());
max = Position.block(max.blockX(), temp, max.blockZ());
}

if (min.blockZ() > max.blockZ()) {
int temp = min.blockZ();
min = Position.block(min.blockX(), min.blockY(), max.blockZ());
max = Position.block(max.blockX(), max.blockY(), temp);
}

Bounds bounds = new Bounds(min, max);

Map<String, TeamSpawns> teamSpawns = new HashMap<>(ctx.getSpawns().size());
Expand Down

0 comments on commit 3eab0b9

Please sign in to comment.