Replace the R-tree library with PRTree. Fix SquirrelID shading issues. Bump the version to 5.12.0

This commit is contained in:
Alexander Söderberg 2020-05-25 15:13:31 +02:00
parent fdf82d0d1e
commit b9b0d89b5f
No known key found for this signature in database
GPG Key ID: C0207FF7EA146678
9 changed files with 128 additions and 38 deletions

View File

@ -36,7 +36,7 @@ dependencies {
implementation("net.ess3:EssentialsX:2.17.2") implementation("net.ess3:EssentialsX:2.17.2")
implementation("net.alpenblock:BungeePerms:4.0-dev-106") implementation("net.alpenblock:BungeePerms:4.0-dev-106")
compile("se.hyperver.hyperverse:Core:0.6.0-SNAPSHOT"){ transitive = false } compile("se.hyperver.hyperverse:Core:0.6.0-SNAPSHOT"){ transitive = false }
compile 'com.github.pavog:SquirrelID:0.6.1' compile('com.sk89q:squirrelid:1.0.0-SNAPSHOT'){ transitive = false }
} }
sourceCompatibility = 1.8 sourceCompatibility = 1.8
@ -93,15 +93,14 @@ shadowJar {
include(dependency("io.papermc:paperlib:1.0.2")) include(dependency("io.papermc:paperlib:1.0.2"))
include(dependency("net.kyori:text-adapter-bukkit:3.0.3")) include(dependency("net.kyori:text-adapter-bukkit:3.0.3"))
include(dependency("org.bstats:bstats-bukkit:1.7")) include(dependency("org.bstats:bstats-bukkit:1.7"))
include(dependency("com.github.davidmoten:rtree:0.8.7")) include(dependency("org.khelekore:prtree:1.7.0-SNAPSHOT"))
include(dependency("io.reactivex:rxjava:1.3.8")) include(dependency("com.sk89q:squirrelid:1.0.0-SNAPSHOT"))
include(dependency("com.github.davidmoten:guava-mini:0.1.1"))
include(dependency("com.github.pavog:SquirrelID:0.6.1"))
} }
relocate('net.kyori.text', 'com.plotsquared.formatting.text') relocate('net.kyori.text', 'com.plotsquared.formatting.text')
relocate("io.papermc.lib", "com.plotsquared.bukkit.paperlib") relocate("io.papermc.lib", "com.plotsquared.bukkit.paperlib")
relocate("org.bstats", "com.plotsquared.metrics") relocate("org.bstats", "com.plotsquared.metrics")
relocate('com.sk89q.squirrelid', 'com.plotsquared.squirrelid') relocate('com.sk89q.squirrelid', 'com.plotsquared.squirrelid')
relocate('org.khelekore.prtree', 'com.plotsquared.prtree')
archiveFileName = "${project.name}-${parent.version}.jar" archiveFileName = "${project.name}-${parent.version}.jar"
destinationDirectory = file "../target" destinationDirectory = file "../target"
} }

View File

@ -67,10 +67,16 @@
</exclusions> </exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.pavog</groupId> <groupId>com.sk89q</groupId>
<artifactId>SquirrelID</artifactId> <artifactId>squirrelid</artifactId>
<version>0.6.1</version> <version>1.0.0-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>*</artifactId>
<groupId>*</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.sk89q.worldedit</groupId> <groupId>com.sk89q.worldedit</groupId>
@ -137,19 +143,19 @@
<dependency> <dependency>
<groupId>me.clip</groupId> <groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId> <artifactId>placeholderapi</artifactId>
<version>2.10.4</version> <version>2.10.6</version>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.luckperms</groupId> <groupId>net.luckperms</groupId>
<artifactId>api</artifactId> <artifactId>api</artifactId>
<version>5.0</version> <version>5.1</version>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.ess3</groupId> <groupId>net.ess3</groupId>
<artifactId>EssentialsX</artifactId> <artifactId>EssentialsX</artifactId>
<version>2.16.1</version> <version>2.17.2</version>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -1,5 +1,6 @@
repositories { repositories {
maven { url = "https://jitpack.io" } maven { url = "https://jitpack.io" }
maven { url = "https://mvn.intellectualsites.com/content/repositories/snapshots" }
} }
def textVersion = "3.0.2" def textVersion = "3.0.2"
@ -16,7 +17,7 @@ dependencies {
testAnnotationProcessor("org.projectlombok:lombok:1.18.8") testAnnotationProcessor("org.projectlombok:lombok:1.18.8")
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.72") implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.72")
implementation("org.jetbrains:annotations:19.0.0") implementation("org.jetbrains:annotations:19.0.0")
implementation 'com.github.davidmoten:rtree:0.8.7' implementation("org.khelekore:prtree:1.7.0-SNAPSHOT")
} }
sourceCompatibility = 1.8 sourceCompatibility = 1.8
@ -74,7 +75,7 @@ shadowJar {
include(dependency("net.kyori:text-serializer-gson:3.0.2")) include(dependency("net.kyori:text-serializer-gson:3.0.2"))
include(dependency("net.kyori:text-serializer-legacy:3.0.2")) include(dependency("net.kyori:text-serializer-legacy:3.0.2"))
include(dependency("net.kyori:text-serializer-plain:3.0.2")) include(dependency("net.kyori:text-serializer-plain:3.0.2"))
include(dependency("com.github.davidmoten:rtree:0.8.7")) include(dependency("org.khelekore:prtree:1.7.0-SNAPSHOT"))
} }
relocate('net.kyori.text', 'com.plotsquared.formatting.text') relocate('net.kyori.text', 'com.plotsquared.formatting.text')
relocate("org.json", "com.plotsquared.json") { relocate("org.json", "com.plotsquared.json") {

View File

@ -93,9 +93,9 @@
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.davidmoten</groupId> <groupId>org.khelekore</groupId>
<artifactId>rtree</artifactId> <artifactId>prtree</artifactId>
<version>0.8.7</version> <version>1.7.0-SNAPSHOT</version>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -34,6 +34,8 @@ import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.khelekore.prtree.MBR;
import org.khelekore.prtree.SimpleMBR;
public class Location implements Cloneable, Comparable<Location> { public class Location implements Cloneable, Comparable<Location> {
@ -221,6 +223,10 @@ public class Location implements Cloneable, Comparable<Location> {
return this; 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) { @Override public boolean equals(Object o) {
if (o == null) { if (o == null) {
return false; return false;

View File

@ -25,18 +25,18 @@
*/ */
package com.plotsquared.core.plot.world; 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.location.Location;
import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotWorld; import com.plotsquared.core.plot.PlotWorld;
import com.plotsquared.core.util.PlotAreaConverter;
import com.plotsquared.core.util.RegionUtil; import com.plotsquared.core.util.RegionUtil;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; 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.Collection;
import java.util.Collections; import java.util.Collections;
@ -48,9 +48,12 @@ import java.util.List;
*/ */
public class ScatteredPlotWorld extends PlotWorld { 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 List<PlotArea> areas = new LinkedList<>();
private final Object treeLock = new Object(); 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 * Create a new plot world with a given world name
@ -66,14 +69,14 @@ public class ScatteredPlotWorld extends PlotWorld {
return null; return null;
} }
synchronized (this.treeLock) { synchronized (this.treeLock) {
final Observable<Entry<PlotArea, Geometry>> area = for (final PlotArea area : this.areaTree.find(location.toMBR())) {
areaTree.search(Geometries.point(location.getX(), location.getZ())); if (area.contains(location)) {
if (area.isEmpty().toBlocking().first()) { return area;
}
}
}
return null; return null;
} }
return area.toBlocking().first().value();
}
}
@Override @NotNull public Collection<PlotArea> getAreas() { @Override @NotNull public Collection<PlotArea> getAreas() {
return Collections.unmodifiableCollection(this.areas); return Collections.unmodifiableCollection(this.areas);
@ -95,7 +98,17 @@ public class ScatteredPlotWorld extends PlotWorld {
} }
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()));
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; return areas;
} }
} }
@ -105,11 +118,8 @@ public class ScatteredPlotWorld extends PlotWorld {
*/ */
private void buildTree() { private void buildTree() {
synchronized (this.treeLock) { synchronized (this.treeLock) {
this.areaTree = RTree.create(); this.areaTree = new PRTree<>(MBR_CONVERTER, BRANCH_FACTOR);
for (final PlotArea area : areas) { this.areaTree.load(this.areas);
this.areaTree = this.areaTree.add(area,
RegionUtil.toRectangle(area.getRegion()));
}
} }
} }

View File

@ -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);
}
}
}

View File

@ -25,14 +25,14 @@
*/ */
package com.plotsquared.core.util; 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.plotsquared.core.plot.Plot;
import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.awt.geom.Rectangle2D;
public class RegionUtil { public class RegionUtil {
public static CuboidRegion createRegion(int pos1x, int pos2x, int pos1z, int pos2z) { public static CuboidRegion createRegion(int pos1x, int pos2x, int pos1z, int pos2z) {
return createRegion(pos1x, pos2x, 0, Plot.MAX_HEIGHT - 1, pos1z, pos2z); return createRegion(pos1x, pos2x, 0, Plot.MAX_HEIGHT - 1, pos1z, pos2z);
@ -58,10 +58,10 @@ public class RegionUtil {
.getY() && y <= max.getY(); .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 min = region.getMinimumPoint().toBlockVector2();
final BlockVector2 max = region.getMaximumPoint().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 // Because WE (not fawe) lack this for CuboidRegion

View File

@ -30,7 +30,7 @@ ext {
git = Grgit.open(dir: new File(rootDir.toString() + "/.git")) git = Grgit.open(dir: new File(rootDir.toString() + "/.git"))
} }
def ver = "5.11.2" def ver = "5.12.0"
def versuffix = "" def versuffix = ""
ext { ext {
if (project.hasProperty("versionsuffix")) { if (project.hasProperty("versionsuffix")) {