diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java index 4fc4d9619..7e12c08b9 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java @@ -623,7 +623,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl @Override @SuppressWarnings("deprecation") public void runEntityTask() { PlotSquared.log(Captions.PREFIX + "KillAllEntities started."); - TaskManager.runTaskRepeat(() -> PlotSquared.get().forEachPlotArea(plotArea -> { + TaskManager.runTaskRepeat(() -> PlotSquared.get().getPlotAreaManager().forEachPlotArea(plotArea -> { final World world = Bukkit.getWorld(plotArea.getWorldName()); try { if (world == null) { diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java index 0371613b8..49fe35c43 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java +++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java @@ -49,14 +49,12 @@ import com.plotsquared.core.generator.IndependentPlotGenerator; import com.plotsquared.core.listener.WESubscriber; import com.plotsquared.core.location.Location; import com.plotsquared.core.player.ConsolePlayer; -import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.BlockBucket; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotAreaTerrainType; import com.plotsquared.core.plot.PlotAreaType; import com.plotsquared.core.plot.PlotCluster; -import com.plotsquared.core.plot.PlotFilter; import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.plot.PlotManager; import com.plotsquared.core.plot.comment.CommentManager; @@ -88,7 +86,6 @@ import com.plotsquared.core.uuid.UUIDPipeline; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.math.BlockVector2; import lombok.Getter; -import lombok.NonNull; import lombok.Setter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -117,25 +114,21 @@ import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Map.Entry; import java.util.Objects; import java.util.Set; -import java.util.UUID; import java.util.concurrent.Executors; import java.util.function.Consumer; -import java.util.regex.Pattern; -import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; /** * An implementation of the core, with a static getter for easy access. */ -@SuppressWarnings({"unused", "WeakerAccess"}) +@SuppressWarnings({"WeakerAccess"}) public class PlotSquared

{ private static final Set EMPTY_SET = Collections.unmodifiableSet(Collections.emptySet()); @@ -481,18 +474,6 @@ public class PlotSquared

{ return Settings.PLATFORM; } - public PlotManager getPlotManager(Plot plot) { - return plot.getArea().getPlotManager(); - } - - @Nullable public PlotManager getPlotManager(@NotNull final Location location) { - final PlotArea plotArea = this.getPlotAreaManager().getPlotArea(location); - if (plotArea == null) { - return null; - } - return plotArea.getPlotManager(); - } - /** * Add a global reference to a plot world. * @@ -826,7 +807,7 @@ public class PlotSquared

{ // group by world // sort each HashMap> map = new HashMap<>(); - int totalSize = getPlotCount(); + int totalSize = Arrays.stream(this.plotAreaManager.getAllPlotAreas()).mapToInt(PlotArea::getPlotCount).sum(); if (plots.size() == totalSize) { for (PlotArea area : plotAreaManager.getAllPlotAreas()) { map.put(area, area.getPlots()); @@ -880,45 +861,6 @@ public class PlotSquared

{ return toReturn; } - /** - * A more generic way to filter plots - make your own method - * if you need complex filters. - * - * @param filters the filter - * @return a filtered set of plots - * @deprecated Use {@link PlotQuery} - */ - @Deprecated public Set getPlots(final PlotFilter... filters) { - final List areas = new LinkedList<>(); - for (final PlotArea plotArea : this.getPlotAreaManager().getAllPlotAreas()) { - for (final PlotFilter filter : filters) { - if (filter.allowsArea(plotArea)) { - areas.add(plotArea); - } - } - } - return PlotQuery.newQuery().inAreas(areas).thatPasses(plot -> { - for (final PlotFilter filter : filters) { - if (!filter.allowsPlot(plot)) { - return false; - } - } - return true; - }).asSet(); - } - - /** - * Gets all the plots across all plotworlds in one {@code Set}. - * - * @return all the plots on the server loaded by this plugin - */ - public Set getPlots() { - int size = getPlotCount(); - final Set result = new HashSet<>(size); - forEachPlotArea(value -> result.addAll(value.getPlots())); - return result; - } - public void setPlots(@NotNull final Map> plots) { if (this.plots_tmp == null) { this.plots_tmp = new HashMap<>(); @@ -938,129 +880,6 @@ public class PlotSquared

{ } } - /** - * Gets all the plots owned by a player name. - * - * @param world the world - * @param player the plot owner - * @return Set of Plot - */ - public Set getPlots(String world, String player) { - final UUID uuid = this.impromptuUUIDPipeline.getSingle(player, Settings.UUID.BLOCKING_TIMEOUT); - return getPlots(world, uuid); - } - - /** - * Gets all the plots owned by a player name. - * - * @param area the PlotArea - * @param player the plot owner - * @return Set of Plot - */ - public Set getPlots(PlotArea area, String player) { - final UUID uuid = this.impromptuUUIDPipeline.getSingle(player, Settings.UUID.BLOCKING_TIMEOUT); - return getPlots(area, uuid); - } - - /** - * Gets all plots by a PlotPlayer. - * - * @param world the world - * @param player the plot owner - * @return Set of plot - */ - public Set getPlots(String world, PlotPlayer player) { - return PlotQuery.newQuery().inWorld(world).ownedBy(player).asSet(); - } - - /** - * Gets all plots by a PlotPlayer. - * - * @param area the PlotArea - * @param player the plot owner - * @return Set of plot - */ - public Set getPlots(PlotArea area, PlotPlayer player) { - return PlotQuery.newQuery().inArea(area).ownedBy(player).asSet(); - } - - /** - * Gets all plots by a UUID in a world. - * - * @param world the world - * @param uuid the plot owner - * @return Set of plot - */ - public Set getPlots(String world, UUID uuid) { - return PlotQuery.newQuery().inWorld(world).ownedBy(uuid).asSet(); - } - - /** - * Gets all plots by a UUID in an area. - * - * @param area the {@code PlotArea} - * @param uuid the plot owner - * @return Set of plots - */ - public Set getPlots(PlotArea area, UUID uuid) { - return PlotQuery.newQuery().inArea(area).ownedBy(uuid).asSet(); - } - - public Collection getPlots(String world) { - return PlotQuery.newQuery().inWorld(world).asCollection(); - } - - /** - * Gets the plots for a PlotPlayer. - * - * @param player the player to retrieve the plots for - * @return Set of Plot - */ - public Set getPlots(PlotPlayer player) { - return PlotQuery.newQuery().ownedBy(player).asSet(); - } - - public Collection getPlots(PlotArea area) { - return area == null ? EMPTY_SET : area.getPlots(); - } - - public Plot getPlot(PlotArea area, PlotId id) { - return area == null ? null : id == null ? null : area.getPlot(id); - } - - public Set getBasePlots(PlotPlayer player) { - return getBasePlots(player.getUUID()); - } - - /** - * Gets the plots for a UUID. - * - * @param uuid the plot owner - * @return Set of Plot's owned by the player - */ - public Set getPlots(final UUID uuid) { - return PlotQuery.newQuery().ownedBy(uuid).asSet(); - } - - public boolean hasPlot(final UUID uuid) { - return Arrays.stream(plotAreaManager.getAllPlotAreas()) - .anyMatch(area -> area.hasPlot(uuid)); - } - - public Set getBasePlots(final UUID uuid) { - return PlotQuery.newQuery().ownedBy(uuid).whereBasePlot().asSet(); - } - - /** - * Gets the plots for a UUID. - * - * @param uuid the UUID of the owner - * @return Set of Plot - */ - public Set getPlotsAbs(final UUID uuid) { - return PlotQuery.newQuery().ownedBy(uuid).asSet(); - } - /** * Unregisters a plot from local memory without calling the database. * @@ -1464,17 +1283,6 @@ public class PlotSquared

{ return true; } - public boolean canUpdate(@NonNull final String current, @NonNull final String other) { - final String s1 = normalisedVersion(current); - final String s2 = normalisedVersion(other); - return s1.compareTo(s2) < 0; - } - - public String normalisedVersion(@NonNull final String version) { - final String[] split = Pattern.compile(".", Pattern.LITERAL).split(version); - return Arrays.stream(split).map(s -> String.format("%4s", s)).collect(Collectors.joining()); - } - /** * Copies a file from inside the jar to a location * @@ -1530,19 +1338,6 @@ public class PlotSquared

{ } } - private Map> getPlotsRaw() { - HashMap> map = new HashMap<>(); - for (PlotArea area : this.plotAreaManager.getAllPlotAreas()) { - Map map2 = map.get(area.toString()); - if (map2 == null) { - map.put(area.toString(), area.getPlotsMap()); - } else { - map2.putAll(area.getPlotsMap()); - } - } - return map; - } - /** * Safely closes the database connection. */ @@ -1885,37 +1680,6 @@ public class PlotSquared

{ } } - /** - * Gets the Java version. - * - * @return the java version - */ - private double getJavaVersion() { - return Double.parseDouble(System.getProperty("java.specification.version")); - } - - public void forEachPlotArea(Consumer action) { - for (final PlotArea area : this.plotAreaManager.getAllPlotAreas()) { - action.accept(area); - } - } - - public void forEachPlotArea(@NonNull final String world, Consumer consumer) { - final PlotArea[] array = this.plotAreaManager.getPlotAreas(world, null); - if (array == null) { - return; - } - for (final PlotArea area : array) { - consumer.accept(area); - } - } - - public void forEachPlot(Consumer consumer) { - for (final PlotArea area : this.plotAreaManager.getAllPlotAreas()) { - area.getPlots().forEach(consumer); - } - } - public void forEachPlotRaw(Consumer consumer) { for (final PlotArea area : this.plotAreaManager.getAllPlotAreas()) { area.getPlots().forEach(consumer); @@ -1927,21 +1691,6 @@ public class PlotSquared

{ } } - public void forEachBasePlot(Consumer consumer) { - for (final PlotArea area : this.plotAreaManager.getAllPlotAreas()) { - area.forEachBasePlot(consumer); - } - } - - public int getPlotAreaCount() { - return this.plotAreaManager.getAllPlotAreas().length; - } - - public int getPlotCount() { - return Arrays.stream(this.plotAreaManager.getAllPlotAreas()) - .mapToInt(PlotArea::getPlotCount).sum(); - } - /** * Check if the chunk uses vanilla/non-PlotSquared generation * @@ -1959,23 +1708,6 @@ public class PlotSquared

{ return area.getTerrain() != PlotAreaTerrainType.NONE; } - public boolean isAugmented(@NonNull final String world) { - final PlotArea[] areas = plotAreaManager.getPlotAreas(world, null); - return areas != null && (areas.length > 1 || areas[0].getType() != PlotAreaType.NORMAL); - } - - /** - * Gets Plots based on alias - * - * @param alias to search plots - * @param worldname to filter alias to a specific world [optional] null means all worlds - * @return Set<{@link Plot }> empty if nothing found - */ - public Set getPlotsByAlias(@Nullable final String alias, - @NonNull final String worldname) { - return PlotQuery.newQuery().inWorld(worldname).withAlias(alias).asSet(); - } - public YamlConfiguration getConfig() { return config; } diff --git a/Core/src/main/java/com/plotsquared/core/api/PlotAPI.java b/Core/src/main/java/com/plotsquared/core/api/PlotAPI.java index a88e404fe..fd56538fb 100644 --- a/Core/src/main/java/com/plotsquared/core/api/PlotAPI.java +++ b/Core/src/main/java/com/plotsquared/core/api/PlotAPI.java @@ -38,6 +38,7 @@ import com.plotsquared.core.util.ChunkManager; import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.SchematicHandler; +import com.plotsquared.core.util.query.PlotQuery; import lombok.NoArgsConstructor; import java.util.Collections; @@ -64,10 +65,9 @@ import java.util.UUID; * Gets all plots. * * @return all plots - * @see PlotSquared#getPlots() */ public Set getAllPlots() { - return PlotSquared.get().getPlots(); + return PlotQuery.newQuery().allPlots().asSet(); } /** @@ -76,8 +76,8 @@ import java.util.UUID; * @param player Player, whose plots to search for * @return all plots that a player owns */ - public Set getPlayerPlots(PlotPlayer player) { - return PlotSquared.get().getPlots(player); + public Set getPlayerPlots(PlotPlayer player) { + return PlotQuery.newQuery().ownedBy(player).asSet(); } /** diff --git a/Core/src/main/java/com/plotsquared/core/command/Cluster.java b/Core/src/main/java/com/plotsquared/core/command/Cluster.java index 060efdf3d..a22bfd733 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Cluster.java +++ b/Core/src/main/java/com/plotsquared/core/command/Cluster.java @@ -39,8 +39,8 @@ import com.plotsquared.core.plot.PlotCluster; import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.Permissions; +import com.plotsquared.core.util.query.PlotQuery; -import java.util.ArrayList; import java.util.HashSet; import java.util.Set; import java.util.UUID; @@ -453,8 +453,8 @@ public class Cluster extends SubCommand { MainUtil.sendMessage(player2, Captions.CLUSTER_REMOVED, cluster.getName()); } - for (Plot plot : new ArrayList<>(PlotSquared.get() - .getPlots(player2.getLocation().getWorld(), uuid))) { + for (final Plot plot : PlotQuery.newQuery().inWorld(player2.getLocation() + .getWorld()).ownedBy(uuid).asCollection()) { PlotCluster current = plot.getCluster(); if (current != null && current.equals(cluster)) { plot.unclaim(); @@ -512,8 +512,8 @@ public class Cluster extends SubCommand { cluster.invited.remove(uuid); DBFunc.removeInvited(cluster, uuid); MainUtil.sendMessage(player, Captions.CLUSTER_REMOVED, cluster.getName()); - for (Plot plot : new ArrayList<>( - PlotSquared.get().getPlots(player.getLocation().getWorld(), uuid))) { + for (final Plot plot : PlotQuery.newQuery().inWorld(player.getLocation().getWorld()) + .ownedBy(uuid).asCollection()) { PlotCluster current = plot.getCluster(); if (current != null && current.equals(cluster)) { plot.unclaim(); diff --git a/Core/src/main/java/com/plotsquared/core/command/Condense.java b/Core/src/main/java/com/plotsquared/core/command/Condense.java index 0e49ebd36..d18322888 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Condense.java +++ b/Core/src/main/java/com/plotsquared/core/command/Condense.java @@ -80,7 +80,8 @@ public class Condense extends SubCommand { return false; } int radius = Integer.parseInt(args[2]); - ArrayList plots = new ArrayList<>(PlotSquared.get().getPlots(area)); + + final List plots = new ArrayList<>(area.getPlots()); // remove non base plots Iterator iterator = plots.iterator(); int maxSize = 0; diff --git a/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java b/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java index 84f2a67f7..89f89f4e7 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java @@ -37,6 +37,7 @@ import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.plot.world.SinglePlotArea; import com.plotsquared.core.util.MainUtil; +import com.plotsquared.core.util.query.PlotQuery; import com.plotsquared.core.util.task.TaskManager; import java.io.File; @@ -85,7 +86,7 @@ public class DatabaseCommand extends SubCommand { plots = PlotSquared.get().sortPlotsByTemp(area.getPlots()); args = Arrays.copyOfRange(args, 1, args.length); } else { - plots = PlotSquared.get().sortPlotsByTemp(PlotSquared.get().getPlots()); + plots = PlotSquared.get().sortPlotsByTemp(PlotQuery.newQuery().allPlots().asList()); } if (args.length < 1) { MainUtil.sendMessage(player, getUsage()); diff --git a/Core/src/main/java/com/plotsquared/core/command/Debug.java b/Core/src/main/java/com/plotsquared/core/command/Debug.java index 28150d27c..d2bae83b2 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Debug.java +++ b/Core/src/main/java/com/plotsquared/core/command/Debug.java @@ -33,6 +33,7 @@ import com.plotsquared.core.util.RegionManager; import com.plotsquared.core.util.StringMan; import com.plotsquared.core.util.entity.EntityCategories; import com.plotsquared.core.util.entity.EntityCategory; +import com.plotsquared.core.util.query.PlotQuery; import com.plotsquared.core.util.task.TaskManager; import com.plotsquared.core.uuid.UUIDMapping; import com.sk89q.worldedit.world.entity.EntityType; @@ -119,7 +120,7 @@ public class Debug extends SubCommand { information.append(getSection(section, "PlotArea")); information.append( getLine(line, "Plot Worlds", StringMan.join(PlotSquared.get().getPlotAreaManager().getAllPlotAreas(), ", "))); - information.append(getLine(line, "Owned Plots", PlotSquared.get().getPlots().size())); + information.append(getLine(line, "Owned Plots", PlotQuery.newQuery().allPlots().count())); information.append(getSection(section, "Messages")); information.append(getLine(line, "Total Messages", Captions.values().length)); information.append(getLine(line, "View all captions", "/plot debug msg")); diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugSaveTest.java b/Core/src/main/java/com/plotsquared/core/command/DebugSaveTest.java index 7307ca185..598bf26ab 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugSaveTest.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugSaveTest.java @@ -25,13 +25,13 @@ */ package com.plotsquared.core.command; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.util.MainUtil; +import com.plotsquared.core.util.query.PlotQuery; -import java.util.ArrayList; +import java.util.List; @CommandDeclaration(command = "debugsavetest", permission = "plots.debugsavetest", @@ -42,7 +42,7 @@ import java.util.ArrayList; public class DebugSaveTest extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { - ArrayList plots = new ArrayList<>(PlotSquared.get().getPlots()); + final List plots = PlotQuery.newQuery().allPlots().asList(); MainUtil.sendMessage(player, "&6Starting `DEBUGSAVETEST`"); DBFunc.createPlotsAndData(plots, () -> MainUtil.sendMessage(player, "&6Database sync finished!")); diff --git a/Core/src/main/java/com/plotsquared/core/command/HomeCommand.java b/Core/src/main/java/com/plotsquared/core/command/HomeCommand.java index b72276026..08b150ec2 100644 --- a/Core/src/main/java/com/plotsquared/core/command/HomeCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/HomeCommand.java @@ -132,7 +132,7 @@ public class HomeCommand extends Command { break; case 2: // we assume args[0] is a plot area and args[1] an identifier - PlotArea plotArea = PlotSquared.get().getPlotAreaByString(args[0]); + PlotArea plotArea = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[0]); identifier = args[1]; if (plotArea == null) { // invalid command, therefore no plots diff --git a/Core/src/main/java/com/plotsquared/core/command/Reload.java b/Core/src/main/java/com/plotsquared/core/command/Reload.java index 0b8f4b6fe..de126cdd5 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Reload.java +++ b/Core/src/main/java/com/plotsquared/core/command/Reload.java @@ -51,7 +51,7 @@ public class Reload extends SubCommand { // loaded during startup unfortunately. PlotSquared.get().setupConfigs(); Captions.load(PlotSquared.get().translationFile); - PlotSquared.get().forEachPlotArea(area -> { + PlotSquared.get().getPlotAreaManager().forEachPlotArea(area -> { ConfigurationSection worldSection = PlotSquared.get().worlds .getConfigurationSection("worlds." + area.getWorldName()); if (worldSection == null) { diff --git a/Core/src/main/java/com/plotsquared/core/command/Target.java b/Core/src/main/java/com/plotsquared/core/command/Target.java index a70ac3451..5d1ebcd10 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Target.java +++ b/Core/src/main/java/com/plotsquared/core/command/Target.java @@ -25,13 +25,13 @@ */ package com.plotsquared.core.command; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.location.Location; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.StringMan; +import com.plotsquared.core.util.query.PlotQuery; @CommandDeclaration(command = "target", usage = "/plot target <|nearest>", @@ -54,7 +54,7 @@ public class Target extends SubCommand { Plot target = null; if (StringMan.isEqualIgnoreCaseToAny(args[0], "near", "nearest")) { int distance = Integer.MAX_VALUE; - for (Plot plot : PlotSquared.get().getPlots(location.getWorld())) { + for (Plot plot : PlotQuery.newQuery().inWorld(location.getWorld()).asCollection()) { double current = plot.getCenterSynchronous().getEuclideanDistanceSquared(location); if (current < distance) { distance = (int) current; diff --git a/Core/src/main/java/com/plotsquared/core/command/Trim.java b/Core/src/main/java/com/plotsquared/core/command/Trim.java index b156eb55b..2e454d665 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Trim.java +++ b/Core/src/main/java/com/plotsquared/core/command/Trim.java @@ -37,6 +37,7 @@ import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.RegionManager; import com.plotsquared.core.util.RegionUtil; import com.plotsquared.core.util.WorldUtil; +import com.plotsquared.core.util.query.PlotQuery; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.RunnableVal2; import com.plotsquared.core.util.task.TaskManager; @@ -52,6 +53,7 @@ import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.Set; @CommandDeclaration(command = "trim", @@ -129,7 +131,7 @@ public class Trim extends SubCommand { return false; } MainUtil.sendMessage(null, "Collecting region data..."); - ArrayList plots = new ArrayList<>(PlotSquared.get().getPlots(world)); + final List plots = PlotQuery.newQuery().inWorld(world).asList(); if (ExpireManager.IMP != null) { plots.removeAll(ExpireManager.IMP.getPendingExpired()); } @@ -206,7 +208,7 @@ public class Trim extends SubCommand { int bz = cbz << 4; CuboidRegion region = RegionUtil.createRegion(bx, bx + 511, bz, bz + 511); - for (Plot plot : PlotSquared.get().getPlots(world)) { + for (Plot plot : PlotQuery.newQuery().inWorld(world).asCollection()) { Location bot = plot.getBottomAbs(); Location top = plot.getExtendedTopAbs(); CuboidRegion plotReg = RegionUtil diff --git a/Core/src/main/java/com/plotsquared/core/command/Visit.java b/Core/src/main/java/com/plotsquared/core/command/Visit.java index 85da0a807..6b8468f93 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Visit.java +++ b/Core/src/main/java/com/plotsquared/core/command/Visit.java @@ -198,7 +198,7 @@ public class Visit extends Command { if (throwable instanceof TimeoutException) { // The request timed out MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT); - } else if (uuid != null && !PlotSquared.get().hasPlot(uuid)) { + } else if (uuid != null && !PlotQuery.newQuery().ownedBy(uuid).anyMatch()) { // It was a valid UUID but the player has no plots MainUtil.sendMessage(player, Captions.PLAYER_NO_PLOTS); } else if (uuid == null) { diff --git a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java index c25eff243..1f2533dc2 100644 --- a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java @@ -47,6 +47,7 @@ import com.plotsquared.core.plot.world.SinglePlotArea; import com.plotsquared.core.plot.world.SinglePlotAreaManager; import com.plotsquared.core.util.EconHandler; import com.plotsquared.core.util.Permissions; +import com.plotsquared.core.util.query.PlotQuery; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.TaskManager; import com.sk89q.worldedit.extension.platform.Actor; @@ -67,7 +68,6 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; /** * The abstract class supporting {@code BukkitPlayer} and {@code SpongePlayer}. @@ -270,7 +270,7 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer } final AtomicInteger count = new AtomicInteger(0); final UUID uuid = getUUID(); - PlotSquared.get().forEachPlotArea(value -> { + PlotSquared.get().getPlotAreaManager().forEachPlotArea(value -> { if (!Settings.Done.COUNTS_TOWARDS_LIMIT) { for (Plot plot : value.getPlotsAbs(uuid)) { if (!DoneFlag.isDone(plot)) { @@ -289,7 +289,7 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer return getClusterCount(getLocation().getWorld()); } final AtomicInteger count = new AtomicInteger(0); - PlotSquared.get().forEachPlotArea(value -> { + PlotSquared.get().getPlotAreaManager().forEachPlotArea(value -> { for (PlotCluster cluster : value.getClusters()) { if (cluster.isOwner(getUUID())) { count.incrementAndGet(); @@ -340,7 +340,7 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer * @see #getPlotCount() for the number of plots */ public Set getPlots() { - return PlotSquared.get().getPlots(this); + return PlotQuery.newQuery().ownedBy(this).asSet(); } /** @@ -614,7 +614,7 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer */ public int getPlayerClusterCount() { final AtomicInteger count = new AtomicInteger(); - PlotSquared.get().forEachPlotArea(value -> count.addAndGet(value.getClusters().size())); + PlotSquared.get().getPlotAreaManager().forEachPlotArea(value -> count.addAndGet(value.getClusters().size())); return count.get(); } @@ -625,9 +625,7 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer * @return a {@code Set} of plots this player owns in the provided world */ public Set getPlots(String world) { - UUID uuid = getUUID(); - return PlotSquared.get().getPlots(world).stream().filter(plot -> plot.isOwner(uuid)) - .collect(Collectors.toCollection(HashSet::new)); + return PlotQuery.newQuery().inWorld(world).ownedBy(getUUID()).asSet(); } public void populatePersistentMetaMap() { diff --git a/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java b/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java index cb6c21fa1..bb8a73291 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java +++ b/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java @@ -44,6 +44,7 @@ import com.plotsquared.core.plot.flag.implementations.KeepFlag; import com.plotsquared.core.plot.message.PlotMessage; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.StringMan; +import com.plotsquared.core.util.query.PlotQuery; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.RunnableVal3; import com.plotsquared.core.util.task.TaskManager; @@ -295,7 +296,7 @@ public class ExpireManager { } this.running = 2; final ConcurrentLinkedDeque plots = - new ConcurrentLinkedDeque<>(PlotSquared.get().getPlots()); + new ConcurrentLinkedDeque<>(PlotQuery.newQuery().allPlots().asList()); TaskManager.runTaskAsync(new Runnable() { @Override public void run() { final Runnable task = this; diff --git a/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpiryTask.java b/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpiryTask.java index a7cd1b86b..83aedbf50 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpiryTask.java +++ b/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpiryTask.java @@ -29,10 +29,12 @@ import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; -import com.plotsquared.core.plot.PlotFilter; +import com.plotsquared.core.util.query.PlotQuery; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; +import java.util.LinkedList; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -119,11 +121,13 @@ public class ExpiryTask { } public Set getPlotsToCheck() { - return PlotSquared.get().getPlots(new PlotFilter() { - @Override public boolean allowsArea(PlotArea area) { - return ExpiryTask.this.allowsArea(area); + final Collection areas = new LinkedList<>(); + for (final PlotArea plotArea : PlotSquared.get().getPlotAreaManager().getAllPlotAreas()) { + if (this.allowsArea(plotArea)) { + areas.add(plotArea); } - }); + } + return PlotQuery.newQuery().inAreas(areas).asSet(); } public boolean applies(long diff) { diff --git a/Core/src/main/java/com/plotsquared/core/plot/expiration/PlotAnalysis.java b/Core/src/main/java/com/plotsquared/core/plot/expiration/PlotAnalysis.java index f7d326411..7819aa2a7 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/expiration/PlotAnalysis.java +++ b/Core/src/main/java/com/plotsquared/core/plot/expiration/PlotAnalysis.java @@ -31,6 +31,7 @@ import com.plotsquared.core.generator.HybridUtils; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.flag.implementations.AnalysisFlag; import com.plotsquared.core.util.MathMan; +import com.plotsquared.core.util.query.PlotQuery; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.TaskManager; @@ -101,7 +102,7 @@ public class PlotAnalysis { } running = true; PlotSquared.debug(" - Fetching all plots"); - final ArrayList plots = new ArrayList<>(PlotSquared.get().getPlots()); + final List plots = PlotQuery.newQuery().allPlots().asList(); TaskManager.runTaskAsync(new Runnable() { @Override public void run() { Iterator iterator = plots.iterator(); diff --git a/Core/src/main/java/com/plotsquared/core/plot/world/PlotAreaManager.java b/Core/src/main/java/com/plotsquared/core/plot/world/PlotAreaManager.java index fbcd796c0..3023a936c 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/world/PlotAreaManager.java +++ b/Core/src/main/java/com/plotsquared/core/plot/world/PlotAreaManager.java @@ -27,14 +27,17 @@ package com.plotsquared.core.plot.world; import com.plotsquared.core.location.Location; import com.plotsquared.core.plot.PlotArea; +import com.plotsquared.core.plot.PlotAreaType; import com.plotsquared.core.util.StringMan; import com.sk89q.worldedit.regions.CuboidRegion; +import lombok.NonNull; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.HashSet; import java.util.Set; +import java.util.function.Consumer; public interface PlotAreaManager { @@ -200,4 +203,26 @@ public interface PlotAreaManager { return this.getPlotAreas(world, null).length != 0; } + /** + * Check if a given world is an augmented plot world + * + * @param world World name + * @return {@code true} if the world is augmented plot world, {@code false} if not + */ + default boolean isAugmented(@NonNull final String world) { + final PlotArea[] areas = this.getPlotAreas(world, null); + return areas != null && (areas.length > 1 || areas[0].getType() != PlotAreaType.NORMAL); + } + + /** + * Perform an action on each recognized plot area + * + * @param action Action to perform + */ + default void forEachPlotArea(@NotNull final Consumer action) { + for (final PlotArea area : this.getAllPlotAreas()) { + action.accept(area); + } + } + } diff --git a/Core/src/main/java/com/plotsquared/core/util/ChunkManager.java b/Core/src/main/java/com/plotsquared/core/util/ChunkManager.java index 3e052737a..f1e27f5f8 100644 --- a/Core/src/main/java/com/plotsquared/core/util/ChunkManager.java +++ b/Core/src/main/java/com/plotsquared/core/util/ChunkManager.java @@ -52,7 +52,7 @@ public abstract class ChunkManager { public static void setChunkInPlotArea(RunnableVal force, RunnableVal add, String world, BlockVector2 loc) { LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(world, false); - if (PlotSquared.get().isAugmented(world) && PlotSquared.get().isNonStandardGeneration(world, loc)) { + if (PlotSquared.get().getPlotAreaManager().isAugmented(world) && PlotSquared.get().isNonStandardGeneration(world, loc)) { int blockX = loc.getX() << 4; int blockZ = loc.getZ() << 4; ScopedLocalBlockQueue scoped = diff --git a/Core/src/main/java/com/plotsquared/core/util/MainUtil.java b/Core/src/main/java/com/plotsquared/core/util/MainUtil.java index 591aa3613..4286da033 100644 --- a/Core/src/main/java/com/plotsquared/core/util/MainUtil.java +++ b/Core/src/main/java/com/plotsquared/core/util/MainUtil.java @@ -47,6 +47,7 @@ import com.plotsquared.core.plot.flag.implementations.DescriptionFlag; import com.plotsquared.core.plot.flag.implementations.ServerPlotFlag; import com.plotsquared.core.plot.flag.types.DoubleFlag; import com.plotsquared.core.util.net.AbstractDelegateOutputStream; +import com.plotsquared.core.util.query.PlotQuery; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.TaskManager; import com.plotsquared.core.uuid.UUIDMapping; @@ -472,7 +473,7 @@ public class MainUtil { PlotArea area = null; String alias = null; - for (Plot plot : PlotSquared.get().getPlots()) { + for (Plot plot : PlotQuery.newQuery().allPlots().asList()) { int count = 0; if (!uuids.isEmpty()) { for (UUID uuid : uuids) { @@ -516,7 +517,7 @@ public class MainUtil { * @param message If a message should be sent to the player if a plot cannot be found * @return The plot if only 1 result is found, or null */ - @Nullable public static Plot getPlotFromString(PlotPlayer player, String arg, boolean message) { + @Nullable public static Plot getPlotFromString(PlotPlayer player, String arg, boolean message) { if (arg == null) { if (player == null) { if (message) { @@ -548,7 +549,7 @@ public class MainUtil { } else { Collection plots; if (area == null) { - plots = PlotSquared.get().getPlots(); + plots = PlotQuery.newQuery().allPlots().asList(); } else { plots = area.getPlots(); } diff --git a/Core/src/main/java/com/plotsquared/core/util/TabCompletions.java b/Core/src/main/java/com/plotsquared/core/util/TabCompletions.java index ac30a4922..fbca485cd 100644 --- a/Core/src/main/java/com/plotsquared/core/util/TabCompletions.java +++ b/Core/src/main/java/com/plotsquared/core/util/TabCompletions.java @@ -173,7 +173,7 @@ public class TabCompletions { */ @NotNull public List completeAreas(@NotNull final String input) { final List completions = new ArrayList<>(); - for (final PlotArea area : PlotSquared.get().getPlotAreas()) { + for (final PlotArea area : PlotSquared.get().getPlotAreaManager().getAllPlotAreas()) { String areaName = area.getWorldName(); if (area.getId() != null) { areaName += ";" + area.getId(); diff --git a/Core/src/main/java/com/plotsquared/core/util/query/GlobalPlotProvider.java b/Core/src/main/java/com/plotsquared/core/util/query/GlobalPlotProvider.java index 3fb2420c5..fc808cbab 100644 --- a/Core/src/main/java/com/plotsquared/core/util/query/GlobalPlotProvider.java +++ b/Core/src/main/java/com/plotsquared/core/util/query/GlobalPlotProvider.java @@ -27,13 +27,20 @@ package com.plotsquared.core.util.query; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.plot.Plot; +import com.plotsquared.core.plot.PlotArea; import java.util.Collection; +import java.util.HashSet; +import java.util.Set; class GlobalPlotProvider implements PlotProvider { @Override public Collection getPlots() { - return PlotSquared.get().getPlots(); + final Set plots = new HashSet<>(); + for (final PlotArea plotArea : PlotSquared.get().getPlotAreaManager().getAllPlotAreas()) { + plots.addAll(plotArea.getPlots()); + } + return plots; } } diff --git a/Core/src/main/java/com/plotsquared/core/util/query/PlotQuery.java b/Core/src/main/java/com/plotsquared/core/util/query/PlotQuery.java index 6d184c44b..8979bd3c9 100644 --- a/Core/src/main/java/com/plotsquared/core/util/query/PlotQuery.java +++ b/Core/src/main/java/com/plotsquared/core/util/query/PlotQuery.java @@ -45,6 +45,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; +import java.util.function.Consumer; import java.util.function.Predicate; import java.util.stream.Stream; @@ -376,6 +377,25 @@ public final class PlotQuery { return this.asList(); } + /** + * Perform an action on each plot returned by the query + * + * @param consumer Plot consumer + */ + public void forEach(@NotNull final Consumer consumer) { + Preconditions.checkNotNull(consumer, "Consumer may not be null"); + this.asCollection().forEach(consumer); + } + + /** + * Get the amount of plots contained in the query result + * + * @return Result count + */ + public int count() { + return this.asList().size(); + } + /** * Get whether any provided plot matches the given filters. * If no plot was provided, false will be returned.