From 6dec0ab2ba2b2bb58d57f83f9cb585b6891e6086 Mon Sep 17 00:00:00 2001 From: IronApollo Date: Sun, 3 May 2020 19:51:48 -0400 Subject: [PATCH] Override #equals method in AbstractRegion.java This is an attempt to fix CPU spikes which do not reduce and continue mounting until the server reaches ~300%-500% usage. This override should allow prompt equality checks for regions based on the world, the minimum point, the maximum point, and area covered by the region. Issues found regarding this change should be quickly reported so this can be reverted and replaced with another appropriate solution. --- .../worldedit/regions/AbstractRegion.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java index d1afac087..03fad6968 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java @@ -218,6 +218,30 @@ public abstract class AbstractRegion extends AbstractSet implement int result = worldHash ^ (worldHash >>> 32); result = 31 * result + this.getMinimumPoint().hashCode(); result = 31 * result + this.getMaximumPoint().hashCode(); + result = 31 * result + this.getArea(); return result; } + + @Override + public boolean equals(Object o) { + if(o == this) { + return true; + } + if(!(o instanceof Region)){ + return false; + } + Region region = ((Region) o); + if(this.getWorld() != region.getWorld()){ + if(this.getWorld() == null || region.getWorld() == null){ + return false; + } + } + if(this.getWorld().equals(region.getWorld()) + && this.getMinimumPoint().equals(region.getMinimumPoint()) + && this.getMaximumPoint().equals(region.getMaximumPoint()) + && this.getArea() == region.getArea()){ + return true; + } + return false; + } }