mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 18:24:43 +02:00
Replace the R-tree library with PRTree. Fix SquirrelID shading issues. Bump the version to 5.12.0
This commit is contained in:
@ -34,6 +34,8 @@ import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.khelekore.prtree.MBR;
|
||||
import org.khelekore.prtree.SimpleMBR;
|
||||
|
||||
public class Location implements Cloneable, Comparable<Location> {
|
||||
|
||||
@ -221,6 +223,10 @@ public class Location implements Cloneable, Comparable<Location> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public MBR toMBR() {
|
||||
return new SimpleMBR(this.getX(), this.getX(), this.getY(), this.getY(), this.getZ(), this.getZ());
|
||||
}
|
||||
|
||||
@Override public boolean equals(Object o) {
|
||||
if (o == null) {
|
||||
return false;
|
||||
|
@ -25,18 +25,18 @@
|
||||
*/
|
||||
package com.plotsquared.core.plot.world;
|
||||
|
||||
import com.github.davidmoten.rtree.Entry;
|
||||
import com.github.davidmoten.rtree.RTree;
|
||||
import com.github.davidmoten.rtree.geometry.Geometries;
|
||||
import com.github.davidmoten.rtree.geometry.Geometry;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotWorld;
|
||||
import com.plotsquared.core.util.PlotAreaConverter;
|
||||
import com.plotsquared.core.util.RegionUtil;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import rx.Observable;
|
||||
import org.khelekore.prtree.MBR;
|
||||
import org.khelekore.prtree.PRTree;
|
||||
import org.khelekore.prtree.SimpleMBR;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -48,9 +48,12 @@ import java.util.List;
|
||||
*/
|
||||
public class ScatteredPlotWorld extends PlotWorld {
|
||||
|
||||
private static final PlotAreaConverter MBR_CONVERTER = new PlotAreaConverter();
|
||||
private static final int BRANCH_FACTOR = 30;
|
||||
|
||||
private final List<PlotArea> areas = new LinkedList<>();
|
||||
private final Object treeLock = new Object();
|
||||
private RTree<PlotArea, Geometry> areaTree;
|
||||
private PRTree<PlotArea> areaTree;
|
||||
|
||||
/**
|
||||
* Create a new plot world with a given world name
|
||||
@ -66,13 +69,13 @@ public class ScatteredPlotWorld extends PlotWorld {
|
||||
return null;
|
||||
}
|
||||
synchronized (this.treeLock) {
|
||||
final Observable<Entry<PlotArea, Geometry>> area =
|
||||
areaTree.search(Geometries.point(location.getX(), location.getZ()));
|
||||
if (area.isEmpty().toBlocking().first()) {
|
||||
return null;
|
||||
for (final PlotArea area : this.areaTree.find(location.toMBR())) {
|
||||
if (area.contains(location)) {
|
||||
return area;
|
||||
}
|
||||
}
|
||||
return area.toBlocking().first().value();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override @NotNull public Collection<PlotArea> getAreas() {
|
||||
@ -95,7 +98,17 @@ public class ScatteredPlotWorld extends PlotWorld {
|
||||
}
|
||||
synchronized (this.treeLock) {
|
||||
final List<PlotArea> areas = new LinkedList<>();
|
||||
this.areaTree.search(RegionUtil.toRectangle(region)).toBlocking().forEach(entry -> areas.add(entry.value()));
|
||||
|
||||
final BlockVector3 min = region.getMinimumPoint();
|
||||
final BlockVector3 max = region.getMaximumPoint();
|
||||
final MBR mbr = new SimpleMBR(min.getX(), max.getX(), min.getY(), max.getY(), min.getZ(), max.getZ());
|
||||
|
||||
for (final PlotArea area : this.areaTree.find(mbr)) {
|
||||
if (RegionUtil.intersects(area.getRegion(), region)) {
|
||||
areas.add(area);
|
||||
}
|
||||
}
|
||||
|
||||
return areas;
|
||||
}
|
||||
}
|
||||
@ -105,11 +118,8 @@ public class ScatteredPlotWorld extends PlotWorld {
|
||||
*/
|
||||
private void buildTree() {
|
||||
synchronized (this.treeLock) {
|
||||
this.areaTree = RTree.create();
|
||||
for (final PlotArea area : areas) {
|
||||
this.areaTree = this.areaTree.add(area,
|
||||
RegionUtil.toRectangle(area.getRegion()));
|
||||
}
|
||||
this.areaTree = new PRTree<>(MBR_CONVERTER, BRANCH_FACTOR);
|
||||
this.areaTree.load(this.areas);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 IntellectualSites
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.core.util;
|
||||
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import org.khelekore.prtree.MBRConverter;
|
||||
|
||||
public class PlotAreaConverter implements MBRConverter<PlotArea> {
|
||||
|
||||
public static final int AXIS_X = 0;
|
||||
public static final int AXIS_Y = 1;
|
||||
public static final int AXIS_Z = 2;
|
||||
|
||||
@Override public int getDimensions() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override public double getMin(final int axis, final PlotArea area) {
|
||||
final CuboidRegion region = area.getRegion();
|
||||
if (axis == AXIS_X) {
|
||||
return region.getMinimumPoint().getX();
|
||||
} else if (axis == AXIS_Y) {
|
||||
return region.getMinimumPoint().getY();
|
||||
} else if (axis == AXIS_Z) {
|
||||
return region.getMinimumPoint().getZ();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown axis: " + axis);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public double getMax(final int axis, final PlotArea area) {
|
||||
final CuboidRegion region = area.getRegion();
|
||||
if (axis == AXIS_X) {
|
||||
return region.getMaximumPoint().getX();
|
||||
} else if (axis == AXIS_Y) {
|
||||
return region.getMaximumPoint().getY();
|
||||
} else if (axis == AXIS_Z) {
|
||||
return region.getMaximumPoint().getZ();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown axis: " + axis);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -25,14 +25,14 @@
|
||||
*/
|
||||
package com.plotsquared.core.util;
|
||||
|
||||
import com.github.davidmoten.rtree.geometry.Geometries;
|
||||
import com.github.davidmoten.rtree.geometry.Rectangle;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
public class RegionUtil {
|
||||
public static CuboidRegion createRegion(int pos1x, int pos2x, int pos1z, int pos2z) {
|
||||
return createRegion(pos1x, pos2x, 0, Plot.MAX_HEIGHT - 1, pos1z, pos2z);
|
||||
@ -58,10 +58,10 @@ public class RegionUtil {
|
||||
.getY() && y <= max.getY();
|
||||
}
|
||||
|
||||
@NotNull public static Rectangle toRectangle(@NotNull final CuboidRegion region) {
|
||||
@NotNull public static Rectangle2D toRectangle(@NotNull final CuboidRegion region) {
|
||||
final BlockVector2 min = region.getMinimumPoint().toBlockVector2();
|
||||
final BlockVector2 max = region.getMaximumPoint().toBlockVector2();
|
||||
return Geometries.rectangle(min.getX(), min.getZ(), max.getX(), max.getZ());
|
||||
return new Rectangle2D.Double(min.getX(), min.getZ(), max.getX(), max.getZ());
|
||||
}
|
||||
|
||||
// Because WE (not fawe) lack this for CuboidRegion
|
||||
|
Reference in New Issue
Block a user