From b9b0d89b5f759354a684cd7a6539ae7e4b883ba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Mon, 25 May 2020 15:13:31 +0200 Subject: [PATCH] Replace the R-tree library with PRTree. Fix SquirrelID shading issues. Bump the version to 5.12.0 --- Bukkit/build.gradle | 9 ++- Bukkit/pom.xml | 18 +++-- Core/build.gradle | 5 +- Core/pom.xml | 6 +- .../plotsquared/core/location/Location.java | 6 ++ .../core/plot/world/ScatteredPlotWorld.java | 44 +++++++----- .../core/util/PlotAreaConverter.java | 68 +++++++++++++++++++ .../com/plotsquared/core/util/RegionUtil.java | 8 +-- build.gradle | 2 +- 9 files changed, 128 insertions(+), 38 deletions(-) create mode 100644 Core/src/main/java/com/plotsquared/core/util/PlotAreaConverter.java diff --git a/Bukkit/build.gradle b/Bukkit/build.gradle index 9cdb65d18..6995d9034 100644 --- a/Bukkit/build.gradle +++ b/Bukkit/build.gradle @@ -36,7 +36,7 @@ dependencies { implementation("net.ess3:EssentialsX:2.17.2") implementation("net.alpenblock:BungeePerms:4.0-dev-106") 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 @@ -93,15 +93,14 @@ shadowJar { include(dependency("io.papermc:paperlib:1.0.2")) include(dependency("net.kyori:text-adapter-bukkit:3.0.3")) include(dependency("org.bstats:bstats-bukkit:1.7")) - include(dependency("com.github.davidmoten:rtree:0.8.7")) - include(dependency("io.reactivex:rxjava:1.3.8")) - include(dependency("com.github.davidmoten:guava-mini:0.1.1")) - include(dependency("com.github.pavog:SquirrelID:0.6.1")) + include(dependency("org.khelekore:prtree:1.7.0-SNAPSHOT")) + include(dependency("com.sk89q:squirrelid:1.0.0-SNAPSHOT")) } relocate('net.kyori.text', 'com.plotsquared.formatting.text') relocate("io.papermc.lib", "com.plotsquared.bukkit.paperlib") relocate("org.bstats", "com.plotsquared.metrics") relocate('com.sk89q.squirrelid', 'com.plotsquared.squirrelid') + relocate('org.khelekore.prtree', 'com.plotsquared.prtree') archiveFileName = "${project.name}-${parent.version}.jar" destinationDirectory = file "../target" } diff --git a/Bukkit/pom.xml b/Bukkit/pom.xml index 42fce3d0a..c2e002a06 100644 --- a/Bukkit/pom.xml +++ b/Bukkit/pom.xml @@ -67,10 +67,16 @@ - com.github.pavog - SquirrelID - 0.6.1 + com.sk89q + squirrelid + 1.0.0-SNAPSHOT compile + + + * + * + + com.sk89q.worldedit @@ -137,19 +143,19 @@ me.clip placeholderapi - 2.10.4 + 2.10.6 runtime net.luckperms api - 5.0 + 5.1 runtime net.ess3 EssentialsX - 2.16.1 + 2.17.2 runtime diff --git a/Core/build.gradle b/Core/build.gradle index 8581a39a4..51f56e187 100644 --- a/Core/build.gradle +++ b/Core/build.gradle @@ -1,5 +1,6 @@ repositories { maven { url = "https://jitpack.io" } + maven { url = "https://mvn.intellectualsites.com/content/repositories/snapshots" } } def textVersion = "3.0.2" @@ -16,7 +17,7 @@ dependencies { testAnnotationProcessor("org.projectlombok:lombok:1.18.8") implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.72") 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 @@ -74,7 +75,7 @@ shadowJar { 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-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("org.json", "com.plotsquared.json") { diff --git a/Core/pom.xml b/Core/pom.xml index 4e53e831a..3260d86a8 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -93,9 +93,9 @@ runtime - com.github.davidmoten - rtree - 0.8.7 + org.khelekore + prtree + 1.7.0-SNAPSHOT runtime diff --git a/Core/src/main/java/com/plotsquared/core/location/Location.java b/Core/src/main/java/com/plotsquared/core/location/Location.java index a6f2c812b..0505137b1 100644 --- a/Core/src/main/java/com/plotsquared/core/location/Location.java +++ b/Core/src/main/java/com/plotsquared/core/location/Location.java @@ -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 { @@ -221,6 +223,10 @@ public class Location implements Cloneable, Comparable { 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; diff --git a/Core/src/main/java/com/plotsquared/core/plot/world/ScatteredPlotWorld.java b/Core/src/main/java/com/plotsquared/core/plot/world/ScatteredPlotWorld.java index 9f245a5ba..40707a8e5 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/world/ScatteredPlotWorld.java +++ b/Core/src/main/java/com/plotsquared/core/plot/world/ScatteredPlotWorld.java @@ -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 areas = new LinkedList<>(); private final Object treeLock = new Object(); - private RTree areaTree; + private PRTree 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> 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 getAreas() { @@ -95,7 +98,17 @@ public class ScatteredPlotWorld extends PlotWorld { } synchronized (this.treeLock) { final List 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); } } diff --git a/Core/src/main/java/com/plotsquared/core/util/PlotAreaConverter.java b/Core/src/main/java/com/plotsquared/core/util/PlotAreaConverter.java new file mode 100644 index 000000000..b80195c02 --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/util/PlotAreaConverter.java @@ -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 . + */ +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 { + + 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); + } + } + +} diff --git a/Core/src/main/java/com/plotsquared/core/util/RegionUtil.java b/Core/src/main/java/com/plotsquared/core/util/RegionUtil.java index 59b14651a..6c16c4a9e 100644 --- a/Core/src/main/java/com/plotsquared/core/util/RegionUtil.java +++ b/Core/src/main/java/com/plotsquared/core/util/RegionUtil.java @@ -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 diff --git a/build.gradle b/build.gradle index 2b26caee7..4d875660b 100644 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,7 @@ ext { git = Grgit.open(dir: new File(rootDir.toString() + "/.git")) } -def ver = "5.11.2" +def ver = "5.12.0" def versuffix = "" ext { if (project.hasProperty("versionsuffix")) {