Don't access tree until it has been created

This commit is contained in:
Alexander Söderberg 2020-05-21 20:23:36 +02:00 committed by Alexander Söderberg
parent dd4c5014fc
commit 93619b3988

View File

@ -62,6 +62,9 @@ public class ScatteredPlotWorld extends PlotWorld {
} }
@Override @Nullable public PlotArea getArea(@NotNull final Location location) { @Override @Nullable public PlotArea getArea(@NotNull final Location location) {
if (this.areas.isEmpty()) {
return null;
}
synchronized (this.treeLock) { synchronized (this.treeLock) {
final Observable<Entry<PlotArea, Geometry>> area = final Observable<Entry<PlotArea, Geometry>> area =
areaTree.search(Geometries.point(location.getX(), location.getZ())); areaTree.search(Geometries.point(location.getX(), location.getZ()));
@ -87,6 +90,9 @@ public class ScatteredPlotWorld extends PlotWorld {
} }
@Override @NotNull public Collection<PlotArea> getAreasInRegion(@NotNull final CuboidRegion region) { @Override @NotNull public Collection<PlotArea> getAreasInRegion(@NotNull final CuboidRegion region) {
if (this.areas.isEmpty()) {
return Collections.emptyList();
}
synchronized (this.treeLock) { synchronized (this.treeLock) {
final List<PlotArea> areas = new LinkedList<>(); final List<PlotArea> areas = new LinkedList<>();
this.areaTree.search(RegionUtil.toRectangle(region)).toBlocking().forEach(entry -> areas.add(entry.value())); this.areaTree.search(RegionUtil.toRectangle(region)).toBlocking().forEach(entry -> areas.add(entry.value()));