From da9c4ad543ead33b41d64057b1a9b5b3bedde844 Mon Sep 17 00:00:00 2001 From: Hazel Trinity Date: Sat, 15 Aug 2020 09:21:33 -0700 Subject: [PATCH] Handle null case in equality checking BlockVector3+DFSNode --- .../main/java/com/boydti/fawe/object/brush/SplineBrush.java | 2 +- .../java/com/boydti/fawe/object/brush/sweep/SweepBrush.java | 2 +- .../java/com/boydti/fawe/object/visitor/DFSVisitor.java | 6 +++++- .../main/java/com/sk89q/worldedit/math/BlockVector3.java | 4 ++++ .../worldedit/regions/selector/CuboidRegionSelector.java | 4 ++-- .../regions/selector/ExtendingCuboidRegionSelector.java | 2 +- 6 files changed, 14 insertions(+), 6 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java index aa1151639..9e750d140 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java @@ -59,7 +59,7 @@ public class SplineBrush implements Brush, ResettableTool { return; } int originalSize = numSplines; - boolean newPos = this.position == null || !position.equals(this.position); + boolean newPos = !position.equals(this.position); this.position = position; if (newPos) { if (positionSets.size() >= MAX_POINTS) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/sweep/SweepBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/sweep/SweepBrush.java index f8b387512..e2d05508f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/sweep/SweepBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/sweep/SweepBrush.java @@ -46,7 +46,7 @@ public class SweepBrush implements Brush, ResettableTool { return; } - boolean newPos = this.position == null || !position.equals(this.position); + boolean newPos = !position.equals(this.position); this.position = position; Player player = editSession.getPlayer(); if (player == null) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/DFSVisitor.java b/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/DFSVisitor.java index 4d2d8861f..5d6b9d05d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/DFSVisitor.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/DFSVisitor.java @@ -104,7 +104,7 @@ public abstract class DFSVisitor implements Operation { from.getZ() + direction.getZ()); if (isVisitable(bv, bv2)) { Node adjacent = new Node(bv2.getBlockX(), bv2.getBlockY(), bv2.getBlockZ()); - if (current.from == null || !adjacent.equals(current.from)) { + if (!adjacent.equals(current.from)) { AtomicInteger adjacentCount = visited.get(adjacent); if (adjacentCount == null) { if (countAdd++ < maxBranch) { @@ -200,6 +200,10 @@ public abstract class DFSVisitor implements Operation { @Override public boolean equals(Object obj) { + if (obj == null) { + return false; + } + Node other = (Node) obj; return other.x == x && other.z == z && other.y == y; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java index 6656bf67a..49cd531c5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java @@ -775,6 +775,10 @@ public abstract class BlockVector3 { } public final boolean equals(BlockVector3 other) { + if (other == null) { + return false; + } + return other.getX() == this.getX() && other.getY() == this.getY() && other.getZ() == this.getZ(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java index 003ba8a7c..47f22c27d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java @@ -128,7 +128,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion { public boolean selectPrimary(BlockVector3 position, SelectorLimits limits) { checkNotNull(position); - if (position1 != null && position.equals(position1)) { + if (position.equals(position1)) { return false; } @@ -141,7 +141,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion { public boolean selectSecondary(BlockVector3 position, SelectorLimits limits) { checkNotNull(position); - if (position2 != null && position.equals(position2)) { + if (position.equals(position2)) { return false; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ExtendingCuboidRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ExtendingCuboidRegionSelector.java index 7a8c7b2ec..606603709 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ExtendingCuboidRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ExtendingCuboidRegionSelector.java @@ -87,7 +87,7 @@ public class ExtendingCuboidRegionSelector extends CuboidRegionSelector { @Override public boolean selectPrimary(BlockVector3 position, SelectorLimits limits) { - if (position1 != null && position2 != null && position.equals(position1) && position.equals(position2)) { + if (position.equals(position1) && position.equals(position2)) { return false; }