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.
This commit is contained in:
IronApollo 2020-05-03 19:51:48 -04:00
parent 65afa79c17
commit 6dec0ab2ba

View File

@ -218,6 +218,30 @@ public abstract class AbstractRegion extends AbstractSet<BlockVector3> implement
int result = worldHash ^ (worldHash >>> 32); int result = worldHash ^ (worldHash >>> 32);
result = 31 * result + this.getMinimumPoint().hashCode(); result = 31 * result + this.getMinimumPoint().hashCode();
result = 31 * result + this.getMaximumPoint().hashCode(); result = 31 * result + this.getMaximumPoint().hashCode();
result = 31 * result + this.getArea();
return result; 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;
}
} }