mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Merge branch 'v5' into features/v5/uuid
# Conflicts: # Bukkit/build.gradle # Core/src/main/java/com/plotsquared/core/PlotSquared.java # Core/src/main/java/com/plotsquared/core/command/ListCmd.java # Core/src/main/java/com/plotsquared/core/command/Visit.java
This commit is contained in:
commit
a882555d1b
2
.github/FUNDING.yml
vendored
2
.github/FUNDING.yml
vendored
@ -9,4 +9,4 @@ community_bridge: # Replace with a single Community Bridge project-name e.g., cl
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
custom: https://www.paypal.me/AlexanderBrandes # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
|
1
.github/ISSUE_TEMPLATE.md
vendored
1
.github/ISSUE_TEMPLATE.md
vendored
@ -28,6 +28,7 @@ assignees: ''
|
||||
<!--- Issue /plot debugpaste in game or in your console and copy the supplied URL here -->
|
||||
<!--- If you cannot perform the above, we require logs/latest.log; settings.yml; worlds.yml and possibly PlotSquared.use_THIS.yml -->
|
||||
<!--- If you are unwilling to supply the information we need, we reserve the right to not assist you. Redact IP addresses if you need to. -->
|
||||
**/plot debugpaste:**
|
||||
|
||||
### Server type:
|
||||
**Select one**
|
||||
|
@ -1,101 +0,0 @@
|
||||
---
|
||||
name: Bug/Issue report for PlotSquared
|
||||
about: Bug / Issue report about this plugin
|
||||
title: ''
|
||||
labels: "[?] Testing Required"
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
<!--- READ THIS BEFORE SUBMITTING AN ISSUE REPORT!!! -->
|
||||
|
||||
<!--- ##### DO NOT REMOVE THIS TEMPLATE! YOUR ISSUE *WILL* FIT IN IT! ##### -->
|
||||
|
||||
<!--- # NOTICE:
|
||||
|
||||
**Feature requests & Suggestions are to be submitted at the [PlotSquared Suggestions tracker](https://github.com/IntellectualSites/PlotSquaredSuggestions)**
|
||||
|
||||
**Code contributions are to be done through [PRs](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request), tagging the specific issue ticket(s) if applicable.**
|
||||
|
||||
**[DISCORD INVITE LINK](https://discord.gg/KxkjDVg)**
|
||||
-->
|
||||
|
||||
# Bug Report Template:
|
||||
<!--- Incomplete reports will most likely be marked as invalid, and closed, with few exceptions.-->
|
||||
## Required Information section:
|
||||
> ALL FIELDS IN THIS SECTION ARE REQUIRED, and must contain appropriate information
|
||||
### Server config info (/plot debugpaste / file paste links):
|
||||
<!--- Issue /plot debugpaste in game or in your console and copy the supplied URL here -->
|
||||
<!--- If you cannot perform the above, we require logs/latest.log; settings.yml; worlds.yml and possibly PlotSquared.use_THIS.yml -->
|
||||
<!--- If you are unwilling to supply the information we need, we reserve the right to not assist you. Redact IP addresses if you need to. -->
|
||||
**/plot debugpaste:**
|
||||
|
||||
### Server type:
|
||||
**Select one**
|
||||
<!-- Select the type you are reporting the issue for (put an "X" between of brackets): -->
|
||||
- [] Spigot / Paper *(CraftBukkit should not be used, re-test with Spigot first!)*
|
||||
- [] Sponge
|
||||
- [] NukkitX
|
||||
|
||||
### PlotSquared version:
|
||||
<!-- Run /plot plugin in-game or in console & paste the full output here: -->
|
||||
```
|
||||
Paste the output here, between the tick marks, replacing this text
|
||||
```
|
||||
|
||||
### Minecraft Version:
|
||||
**Select one**
|
||||
<!-- Select the type you are reporting the issue for (put an "X" between of brackets) -->
|
||||
- [] Minecraft 1.15.2
|
||||
- [] Minecraft 1.14.4
|
||||
- [] Minecraft 1.13.2
|
||||
- [] Minecraft 1.12.2
|
||||
- [] Minecraft 1.11.2
|
||||
- [] Minecraft 1.10.2
|
||||
- [] Minecraft 1.9.4
|
||||
- [] Minecraft 1.8.8
|
||||
- [] Minecraft Java Edition *other versions, please specify*:
|
||||
- [] Minecraft Bedrock Edition *specify version*:
|
||||
- [] Minecraft Sponge *specify version*:
|
||||
|
||||
### Server build info:
|
||||
<!--- Run /version in-game or in console & paste the full output here: -->
|
||||
```
|
||||
Paste the output here, between the tick marks, replacing this text
|
||||
```
|
||||
|
||||
### WorldEdit/FAWE versions:
|
||||
<!--- Specify which plugin you are using, and add its version. Either use /fawe version or /we version -->
|
||||
- [] FAWE version:
|
||||
- [] WorldEdit version:
|
||||
|
||||
### Description of the problem:
|
||||
<!--- Be as specific as possible. Don't lie, redact information, or use false names/situations. -->
|
||||
<!--- Who, What, When, Where, Why, How, Expected behavior, Resultant behavior, etc -->
|
||||
|
||||
### How to replicate:
|
||||
<!--- If you can reproduce the issue please tell us as detailed as possible step by step how to do that -->
|
||||
|
||||
## Additional Information:
|
||||
> The information here is optional for you to provide, however it may help us to more readily diagnose any compatibility and bug issues.
|
||||
|
||||
### Other plugins being used on the server:
|
||||
<!--- Optional but recommended - issue "/plugins" in-game or in console and copy/paste the list -->
|
||||
|
||||
### Relevant console output, log lines, and/or screenshots:
|
||||
<!--- Please use in-line code insertion
|
||||
```
|
||||
like this
|
||||
```
|
||||
for short (20 lines or less) text blobs, or a paste service for large blobs -->
|
||||
|
||||
### Additional relevant comments/remarks:
|
||||
<!--- Use this space to give us any additional information which may be relevant to this issue, such as: if you are using a Minecraft hosting provider; unusual installation environment; etc -->
|
||||
|
||||
# AFFIRMATION OF COMPLETION:
|
||||
<!-- Make sure you have completed the following steps (put an "X" between of brackets): -->
|
||||
- [] I included all information required in the sections above
|
||||
- [] I made sure there are no duplicates of this report [(Use Search)](https://github.com/IntellectualSites/PlotSquared/issues?utf8=%E2%9C%93&q=is%3Aissue)
|
||||
- [] I made sure I am using an up-to-date version of PlotSquared
|
||||
- [] I made sure the bug/error is not caused by any other plugin
|
||||
- [x] I didn't read but checked everything above.
|
3
.github/ISSUE_TEMPLATE/config.yml
vendored
3
.github/ISSUE_TEMPLATE/config.yml
vendored
@ -1,5 +1,8 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: PlotSquared Issue Tracker
|
||||
url: https://issues.intellectualsites.com/projects/ps
|
||||
about: Click here to move to our new issue tracker
|
||||
- name: PlotSquared Suggestions
|
||||
url: https://github.com/IntellectualSites/PlotSquaredSuggestions
|
||||
about: If you want to submit feature or suggestion ideas, do that here
|
@ -91,6 +91,9 @@ 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"))
|
||||
}
|
||||
relocate('net.kyori.text', 'com.plotsquared.formatting.text')
|
||||
|
@ -16,6 +16,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'
|
||||
}
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
@ -73,6 +74,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"))
|
||||
}
|
||||
relocate('net.kyori.text', 'com.plotsquared.formatting.text')
|
||||
relocate("org.json", "com.plotsquared.json") {
|
||||
|
@ -92,6 +92,12 @@
|
||||
<version>1.3.72</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.davidmoten</groupId>
|
||||
<artifactId>rtree</artifactId>
|
||||
<version>0.8.7</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
@ -81,6 +81,7 @@ import com.plotsquared.core.util.SetupUtils;
|
||||
import com.plotsquared.core.util.StringMan;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.plotsquared.core.util.logger.ILogger;
|
||||
import com.plotsquared.core.util.query.PlotQuery;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.uuid.UUIDPipeline;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
@ -116,6 +117,7 @@ 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;
|
||||
@ -620,17 +622,7 @@ public class PlotSquared {
|
||||
* @return Set of base Plots
|
||||
*/
|
||||
public Set<Plot> getBasePlots() {
|
||||
int size = getPlotCount();
|
||||
final Set<Plot> result = new HashSet<>(size);
|
||||
forEachPlotArea(value -> {
|
||||
for (Plot plot : value.getPlots()) {
|
||||
if (!plot.isBasePlot()) {
|
||||
continue;
|
||||
}
|
||||
result.add(plot);
|
||||
}
|
||||
});
|
||||
return Collections.unmodifiableSet(result);
|
||||
return PlotQuery.newQuery().whereBasePlot().asSet();
|
||||
}
|
||||
|
||||
public List<Plot> sortPlotsByTemp(Collection<Plot> plots) {
|
||||
@ -883,27 +875,25 @@ public class PlotSquared {
|
||||
*
|
||||
* @param filters the filter
|
||||
* @return a filtered set of plots
|
||||
* @deprecated Use {@link PlotQuery}
|
||||
*/
|
||||
public Set<Plot> getPlots(final PlotFilter... filters) {
|
||||
final HashSet<Plot> set = new HashSet<>();
|
||||
forEachPlotArea(value -> {
|
||||
for (PlotFilter filter : filters) {
|
||||
if (!filter.allowsArea(value)) {
|
||||
return;
|
||||
@Deprecated public Set<Plot> getPlots(final PlotFilter... filters) {
|
||||
final List<PlotArea> areas = new LinkedList<>();
|
||||
for (final PlotArea plotArea : this.getPlotAreas()) {
|
||||
for (final PlotFilter filter : filters) {
|
||||
if (filter.allowsArea(plotArea)) {
|
||||
areas.add(plotArea);
|
||||
}
|
||||
}
|
||||
loop:
|
||||
for (Entry<PlotId, Plot> entry2 : value.getPlotEntries()) {
|
||||
Plot plot = entry2.getValue();
|
||||
for (PlotFilter filter : filters) {
|
||||
if (!filter.allowsPlot(plot)) {
|
||||
continue loop;
|
||||
}
|
||||
}
|
||||
return PlotQuery.newQuery().inAreas(areas).thatPasses(plot -> {
|
||||
for (final PlotFilter filter : filters) {
|
||||
if (!filter.allowsPlot(plot)) {
|
||||
return false;
|
||||
}
|
||||
set.add(plot);
|
||||
}
|
||||
});
|
||||
return set;
|
||||
return true;
|
||||
}).asSet();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -970,7 +960,7 @@ public class PlotSquared {
|
||||
* @return Set of plot
|
||||
*/
|
||||
public Set<Plot> getPlots(String world, PlotPlayer player) {
|
||||
return getPlots(world, player.getUUID());
|
||||
return PlotQuery.newQuery().inWorld(world).ownedBy(player).asSet();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -981,7 +971,7 @@ public class PlotSquared {
|
||||
* @return Set of plot
|
||||
*/
|
||||
public Set<Plot> getPlots(PlotArea area, PlotPlayer player) {
|
||||
return getPlots(area, player.getUUID());
|
||||
return PlotQuery.newQuery().inArea(area).ownedBy(player).asSet();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -991,14 +981,8 @@ public class PlotSquared {
|
||||
* @param uuid the plot owner
|
||||
* @return Set of plot
|
||||
*/
|
||||
public Set<Plot> getPlots(String world, @Nullable UUID uuid) {
|
||||
if (uuid == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
final Set<Plot> plots =
|
||||
getPlots(world).stream().filter(plot -> plot.hasOwner() && plot.isOwnerAbs(uuid))
|
||||
.collect(Collectors.toSet());
|
||||
return Collections.unmodifiableSet(plots);
|
||||
public Set<Plot> getPlots(String world, UUID uuid) {
|
||||
return PlotQuery.newQuery().inWorld(world).ownedBy(uuid).asSet();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1009,13 +993,7 @@ public class PlotSquared {
|
||||
* @return Set of plots
|
||||
*/
|
||||
public Set<Plot> getPlots(PlotArea area, UUID uuid) {
|
||||
final Set<Plot> plots = new HashSet<>();
|
||||
for (Plot plot : getPlots(area)) {
|
||||
if (plot.hasOwner() && plot.isOwnerAbs(uuid)) {
|
||||
plots.add(plot);
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableSet(plots);
|
||||
return PlotQuery.newQuery().inArea(area).ownedBy(uuid).asSet();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1030,9 +1008,7 @@ public class PlotSquared {
|
||||
}
|
||||
|
||||
public Collection<Plot> getPlots(String world) {
|
||||
final Set<Plot> set = new HashSet<>();
|
||||
forEachPlotArea(world, value -> set.addAll(value.getPlots()));
|
||||
return set;
|
||||
return PlotQuery.newQuery().inWorld(world).asCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1042,7 +1018,7 @@ public class PlotSquared {
|
||||
* @return Set of Plot
|
||||
*/
|
||||
public Set<Plot> getPlots(PlotPlayer player) {
|
||||
return getPlots(player.getUUID());
|
||||
return PlotQuery.newQuery().ownedBy(player).asSet();
|
||||
}
|
||||
|
||||
public Collection<Plot> getPlots(PlotArea area) {
|
||||
@ -1064,13 +1040,7 @@ public class PlotSquared {
|
||||
* @return Set of Plot's owned by the player
|
||||
*/
|
||||
public Set<Plot> getPlots(final UUID uuid) {
|
||||
final Set<Plot> plots = new HashSet<>();
|
||||
forEachPlot(value -> {
|
||||
if (value.isOwnerAbs(uuid)) {
|
||||
plots.add(value);
|
||||
}
|
||||
});
|
||||
return Collections.unmodifiableSet(plots);
|
||||
return PlotQuery.newQuery().ownedBy(uuid).asSet();
|
||||
}
|
||||
|
||||
public boolean hasPlot(final UUID uuid) {
|
||||
@ -1079,13 +1049,7 @@ public class PlotSquared {
|
||||
}
|
||||
|
||||
public Set<Plot> getBasePlots(final UUID uuid) {
|
||||
final Set<Plot> plots = new HashSet<>();
|
||||
forEachBasePlot(value -> {
|
||||
if (value.isOwner(uuid)) {
|
||||
plots.add(value);
|
||||
}
|
||||
});
|
||||
return Collections.unmodifiableSet(plots);
|
||||
return PlotQuery.newQuery().ownedBy(uuid).whereBasePlot().asSet();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1095,13 +1059,7 @@ public class PlotSquared {
|
||||
* @return Set of Plot
|
||||
*/
|
||||
public Set<Plot> getPlotsAbs(final UUID uuid) {
|
||||
final Set<Plot> plots = new HashSet<>();
|
||||
forEachPlot(value -> {
|
||||
if (value.isOwnerAbs(uuid)) {
|
||||
plots.add(value);
|
||||
}
|
||||
});
|
||||
return Collections.unmodifiableSet(plots);
|
||||
return PlotQuery.newQuery().ownedBy(uuid).asSet();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2085,16 +2043,7 @@ public class PlotSquared {
|
||||
*/
|
||||
public Set<Plot> getPlotsByAlias(@Nullable final String alias,
|
||||
@NonNull final String worldname) {
|
||||
final Set<Plot> result = new HashSet<>();
|
||||
if (alias != null) {
|
||||
for (final Plot plot : getPlots()) {
|
||||
if (alias.equals(plot.getAlias()) && (worldname == null || worldname
|
||||
.equals(plot.getWorldName()))) {
|
||||
result.add(plot);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableSet(result);
|
||||
return PlotQuery.newQuery().inWorld(worldname).withAlias(alias).asSet();
|
||||
}
|
||||
|
||||
public Set<PlotArea> getPlotAreas(final String world, final CuboidRegion region) {
|
||||
|
@ -26,14 +26,12 @@
|
||||
package com.plotsquared.core.command;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.PlotSquared.SortType;
|
||||
import com.plotsquared.core.configuration.CaptionUtility;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.Rating;
|
||||
import com.plotsquared.core.plot.expiration.ExpireManager;
|
||||
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.PriceFlag;
|
||||
@ -44,6 +42,8 @@ import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.StringComparison;
|
||||
import com.plotsquared.core.util.StringMan;
|
||||
import com.plotsquared.core.util.query.PlotQuery;
|
||||
import com.plotsquared.core.util.query.SortingStrategy;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
|
||||
@ -51,7 +51,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -140,22 +139,32 @@ public class ListCmd extends SubCommand {
|
||||
String arg = args[0].toLowerCase();
|
||||
final boolean[] sort = new boolean[] {true};
|
||||
|
||||
final Consumer<Collection<Plot>> plotConsumer = plots -> {
|
||||
if (plots == null) {
|
||||
final Consumer<PlotQuery> plotConsumer = plots -> {
|
||||
if (query == null) {
|
||||
sendMessage(player, Captions.DID_YOU_MEAN,
|
||||
new StringComparison<>(args[0], new String[] {"mine", "shared", "world", "all"})
|
||||
.getBestMatch());
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (area != null) {
|
||||
query.relativeToArea(area);
|
||||
}
|
||||
|
||||
if (sort) {
|
||||
query.withSortingStrategy(SortingStrategy.SORT_BY_CREATION);
|
||||
}
|
||||
|
||||
final List<Plot> plots = query.asList();
|
||||
|
||||
if (plots.isEmpty()) {
|
||||
MainUtil.sendMessage(player, Captions.FOUND_NO_PLOTS);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
displayPlots(player, new ArrayList<>(plots), 12, page, area, args, sort[0]);
|
||||
displayPlots(player, plots, 12, page, args);
|
||||
};
|
||||
|
||||
final List<Plot> plots = new ArrayList<>();
|
||||
switch (arg) {
|
||||
case "mine":
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_MINE)) {
|
||||
@ -164,8 +173,7 @@ public class ListCmd extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
sort[0] = false;
|
||||
plotConsumer.accept(
|
||||
PlotSquared.get().sortPlotsByTemp(PlotSquared.get().getBasePlots(player)));
|
||||
plotConsumer.accept(PlotQuery.newQuery().ownedBy(player).whereBasePlot().withSortingStrategy(SortingStrategy.SORT_BY_TEMP));
|
||||
break;
|
||||
case "shared":
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_SHARED)) {
|
||||
@ -173,13 +181,7 @@ public class ListCmd extends SubCommand {
|
||||
Captions.PERMISSION_LIST_SHARED);
|
||||
return false;
|
||||
}
|
||||
for (Plot plot : PlotSquared.get().getPlots()) {
|
||||
if (plot.getTrusted().contains(player.getUUID()) || plot.getMembers()
|
||||
.contains(player.getUUID())) {
|
||||
plots.add(plot);
|
||||
}
|
||||
}
|
||||
plotConsumer.accept(plots);
|
||||
plotConsumer.accept(PlotQuery.newQuery().withMember(player.getUUID()).thatPasses(plot -> !plot.isOwnerAbs(player.getUUID())));
|
||||
break;
|
||||
case "world":
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_WORLD)) {
|
||||
@ -194,18 +196,24 @@ public class ListCmd extends SubCommand {
|
||||
world));
|
||||
return false;
|
||||
}
|
||||
plotConsumer.accept(PlotSquared.get().getPlots(world));
|
||||
plotConsumer.accept(PlotQuery.newQuery().inWorld(world));
|
||||
break;
|
||||
plotConsumer.accept(PlotSquared.get().getPlots(world));
|
||||
case "expired":
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_EXPIRED)) {
|
||||
MainUtil.sendMessage(player, Captions.NO_PERMISSION,
|
||||
Captions.PERMISSION_LIST_EXPIRED);
|
||||
return false;
|
||||
}
|
||||
if (ExpireManager.IMP == null) {
|
||||
plotConsumer.accept(PlotQuery.newQuery().noPlots());
|
||||
} else {
|
||||
plotConsumer.accept(PlotQuery.newQuery().expiredPlots());
|
||||
}
|
||||
break;
|
||||
plotConsumer.accept(ExpireManager.IMP == null ?
|
||||
new ArrayList<>() :
|
||||
new ArrayList<>(ExpireManager.IMP.getPendingExpired()));
|
||||
break;
|
||||
case "area":
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_AREA)) {
|
||||
MainUtil
|
||||
@ -219,8 +227,11 @@ public class ListCmd extends SubCommand {
|
||||
world));
|
||||
return false;
|
||||
}
|
||||
plotConsumer.accept(
|
||||
area == null ? new ArrayList<Plot>() : new ArrayList<>(area.getPlots()));
|
||||
if (area == null) {
|
||||
plotConsumer.accept(PlotQuery.newQuery().noPlots());
|
||||
} else {
|
||||
plotConsumer.accept(PlotQuery.newQuery().inArea(area));
|
||||
}
|
||||
break;
|
||||
case "all":
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_ALL)) {
|
||||
@ -228,7 +239,7 @@ public class ListCmd extends SubCommand {
|
||||
.sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_LIST_ALL);
|
||||
return false;
|
||||
}
|
||||
plotConsumer.accept(new ArrayList<>(PlotSquared.get().getPlots()));
|
||||
plotConsumer.accept(PlotQuery().newQuery().allPlots());
|
||||
break;
|
||||
case "done":
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_DONE)) {
|
||||
@ -236,24 +247,8 @@ public class ListCmd extends SubCommand {
|
||||
.sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_LIST_DONE);
|
||||
return false;
|
||||
}
|
||||
for (Plot plot : PlotSquared.get().getPlots()) {
|
||||
if (DoneFlag.isDone(plot)) {
|
||||
plots.add(plot);
|
||||
}
|
||||
}
|
||||
plots.sort((a, b) -> {
|
||||
String va = a.getFlag(DoneFlag.class);
|
||||
String vb = b.getFlag(DoneFlag.class);
|
||||
if (MathMan.isInteger(va)) {
|
||||
if (MathMan.isInteger(vb)) {
|
||||
return Integer.parseInt(vb) - Integer.parseInt(va);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
sort[0] = false;
|
||||
plotConsumer.accept(plots);
|
||||
plotConsumer.accept(PlotQuery.newQuery().allPlots().thatPasses(DoneFlag::isDone).withSortingStrategy(SortingStrategy.SORT_BY_DONE))
|
||||
break;
|
||||
case "top":
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_TOP)) {
|
||||
@ -261,33 +256,8 @@ public class ListCmd extends SubCommand {
|
||||
.sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_LIST_TOP);
|
||||
return false;
|
||||
}
|
||||
plots.addAll(PlotSquared.get().getPlots());
|
||||
plots.sort((p1, p2) -> {
|
||||
double v1 = 0;
|
||||
int p1s = p1.getSettings().getRatings().size();
|
||||
int p2s = p2.getRatings().size();
|
||||
if (!p1.getSettings().getRatings().isEmpty()) {
|
||||
v1 = p1.getRatings().values().stream().mapToDouble(Rating::getAverageRating)
|
||||
.map(av -> av * av).sum();
|
||||
v1 /= p1s;
|
||||
v1 += p1s;
|
||||
}
|
||||
double v2 = 0;
|
||||
if (!p2.getSettings().getRatings().isEmpty()) {
|
||||
for (Entry<UUID, Rating> entry : p2.getRatings().entrySet()) {
|
||||
double av = entry.getValue().getAverageRating();
|
||||
v2 += av * av;
|
||||
}
|
||||
v2 /= p2s;
|
||||
v2 += p2s;
|
||||
}
|
||||
if (v2 == v1 && v2 != 0) {
|
||||
return p2s - p1s;
|
||||
}
|
||||
return (int) Math.signum(v2 - v1);
|
||||
});
|
||||
sort[0] = false;
|
||||
plotConsumer.accept(plots);
|
||||
plotConsumer.accept(PlotQuery.newQuery().allPlots().withSortingStrategy(SortingStrategy.SORT_BY_RATING))
|
||||
break;
|
||||
case "forsale":
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_FOR_SALE)) {
|
||||
@ -298,12 +268,7 @@ public class ListCmd extends SubCommand {
|
||||
if (EconHandler.manager == null) {
|
||||
break;
|
||||
}
|
||||
for (Plot plot : PlotSquared.get().getPlots()) {
|
||||
if (plot.getFlag(PriceFlag.class) > 0) {
|
||||
plots.add(plot);
|
||||
}
|
||||
}
|
||||
plotConsumer.accept(plots);
|
||||
plotConsumer.accept(PlotQuery.newQuery().allPlots().thatPasses(plot -> plot.getFlag(PriceFlag.class) > 0));
|
||||
break;
|
||||
case "unowned":
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_UNOWNED)) {
|
||||
@ -311,12 +276,7 @@ public class ListCmd extends SubCommand {
|
||||
Captions.PERMISSION_LIST_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
for (Plot plot : PlotSquared.get().getPlots()) {
|
||||
if (plot.getOwner() == null) {
|
||||
plots.add(plot);
|
||||
}
|
||||
}
|
||||
plotConsumer.accept(plots);
|
||||
plotConsumer.accept(PlotQuery.newQuery().allPlots().thatPasses(plot -> plot.getOwner() == null));
|
||||
break;
|
||||
case "fuzzy":
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_FUZZY)) {
|
||||
@ -335,7 +295,7 @@ public class ListCmd extends SubCommand {
|
||||
term = StringMan.join(Arrays.copyOfRange(args, 1, args.length), " ");
|
||||
}
|
||||
sort[0] = false;
|
||||
plotConsumer.accept(MainUtil.getPlotsBySearch(term));
|
||||
plotConsumer.accept(PlotQuery.newQuery().plotsBySearch(term));
|
||||
break;
|
||||
default:
|
||||
if (PlotSquared.get().hasPlotArea(args[0])) {
|
||||
@ -352,7 +312,7 @@ public class ListCmd extends SubCommand {
|
||||
args[0]));
|
||||
return false;
|
||||
}
|
||||
plotConsumer.accept(new ArrayList<>(PlotSquared.get().getPlots(args[0])));
|
||||
plotConsumer.accept(PlotQuery.newQuery().inWorld(args[0]));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -382,19 +342,33 @@ public class ListCmd extends SubCommand {
|
||||
}
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
|
||||
UUID uuid = UUIDHandler.getUUID(args[0], null);
|
||||
if (uuid == null) {
|
||||
try {
|
||||
uuid = UUID.fromString(args[0]);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
if (uuid != null) {
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_PLAYER)) {
|
||||
MainUtil.sendMessage(player, Captions.NO_PERMISSION,
|
||||
Captions.PERMISSION_LIST_PLAYER);
|
||||
return false;
|
||||
}
|
||||
sort[0] = false;
|
||||
plotConsumer.accept(PlotQuery.newQuery().ownedBy(uuid).withSortingStrategy(SortingStrategy.SORT_BY_TEMP));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void displayPlots(final PlotPlayer player, List<Plot> plots, int pageSize, int page,
|
||||
PlotArea area, String[] args, boolean sort) {
|
||||
public void displayPlots(final PlotPlayer player, List<Plot> plots, int pageSize, int page, String[] args {
|
||||
// Header
|
||||
plots.removeIf(plot -> !plot.isBasePlot());
|
||||
if (sort) {
|
||||
plots = PlotSquared.get().sortPlots(plots, SortType.CREATION_DATE, area);
|
||||
}
|
||||
this.paginate(player, plots, pageSize, page,
|
||||
new RunnableVal3<Integer, Plot, PlotMessage>() {
|
||||
@Override public void run(Integer i, Plot plot, PlotMessage message) {
|
||||
|
@ -36,6 +36,8 @@ import com.plotsquared.core.plot.flag.implementations.UntrustedVisitFlag;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.query.PlotQuery;
|
||||
import com.plotsquared.core.util.query.SortingStrategy;
|
||||
import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
|
||||
@ -75,66 +77,73 @@ public class Visit extends Command {
|
||||
args = args[0].split(":");
|
||||
}
|
||||
|
||||
final Collection<Plot> unsortedPre = new HashSet<>();
|
||||
final PlotQuery query = PlotQuery.newQuery();
|
||||
final PlotArea[] sortByArea = new PlotArea[] {player.getApplicablePlotArea()};
|
||||
final AtomicBoolean shouldSortByArea = new AtomicBoolean(Settings.Teleport.PER_WORLD_VISIT);
|
||||
final Atomicboolean shouldSortByArea = new AtomicBoolean(Settings.Teleport.PER_WORLD_VISIT);
|
||||
|
||||
final Consumer<Integer> pageConsumer = page -> {
|
||||
if (page == Integer.MIN_VALUE) {
|
||||
page = 1;
|
||||
}
|
||||
if (unsortedPre.isEmpty()) {
|
||||
// We get the query once,
|
||||
// then we get it another time further on
|
||||
final List<Plot> unsorted = query.asList();
|
||||
|
||||
if (unsorted.isEmpty()) {
|
||||
Captions.FOUND_NO_PLOTS.send(player);
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
|
||||
if (unsorted.size() > 1) {
|
||||
query.whereBasePlot();
|
||||
}
|
||||
|
||||
if (page < 1 || page > unsorted.size()) {
|
||||
Captions.NOT_VALID_NUMBER.send(player, "(1, " + unsorted.size() + ")");
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
|
||||
if (shouldSortByArea.get()) {
|
||||
query.relativeToArea(sortByArea).withSortingStrategy(SortingStrategy.SORT_BY_CREATION);
|
||||
} else {
|
||||
final Collection<Plot> unsorted = new ArrayList<>(unsortedPre);
|
||||
if (unsorted.size() > 1) {
|
||||
unsorted.removeIf(plot -> !plot.isBasePlot());
|
||||
query.withSortingStrategy(SortingStrategy.SORT_BY_TEMP);
|
||||
}
|
||||
|
||||
final List<Plot> plots = query.asList();
|
||||
|
||||
final Plot plot = plots.get(page - 1);
|
||||
if (!plot.hasOwner()) {
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_VISIT_UNOWNED)) {
|
||||
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_VISIT_UNOWNED);
|
||||
return;
|
||||
}
|
||||
if (page < 1 || page > unsorted.size()) {
|
||||
Captions.NOT_VALID_NUMBER.send(player, "(1, " + unsorted.size() + ")");
|
||||
} else {
|
||||
List<Plot> plots;
|
||||
if (shouldSortByArea.get()) {
|
||||
plots = PlotSquared.get().sortPlots(unsorted, PlotSquared.SortType.CREATION_DATE, sortByArea[0]);
|
||||
} else {
|
||||
plots = PlotSquared.get().sortPlotsByTemp(unsorted);
|
||||
}
|
||||
final Plot plot = plots.get(page - 1);
|
||||
if (!plot.hasOwner()) {
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_VISIT_UNOWNED)) {
|
||||
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_VISIT_UNOWNED);
|
||||
return;
|
||||
}
|
||||
} else if (plot.isOwner(player.getUUID())) {
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_VISIT_OWNED) && !Permissions.hasPermission(player, Captions.PERMISSION_HOME)) {
|
||||
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_VISIT_OWNED);
|
||||
return;
|
||||
}
|
||||
} else if (plot.isAdded(player.getUUID())) {
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_SHARED)) {
|
||||
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_SHARED);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_VISIT_OTHER)) {
|
||||
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_VISIT_OTHER);
|
||||
return;
|
||||
}
|
||||
if (!plot.getFlag(UntrustedVisitFlag.class) && !Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_VISIT_UNTRUSTED)) {
|
||||
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_ADMIN_VISIT_UNTRUSTED);
|
||||
return;
|
||||
}
|
||||
}
|
||||
confirm.run(this,
|
||||
() -> plot.teleportPlayer(player, TeleportCause.COMMAND, result -> {
|
||||
if (result) {
|
||||
whenDone.run(Visit.this, CommandResult.SUCCESS);
|
||||
} else {
|
||||
whenDone.run(Visit.this, CommandResult.FAILURE);
|
||||
}
|
||||
}), () -> whenDone.run(Visit.this, CommandResult.FAILURE));
|
||||
} else if (plot.isOwner(player.getUUID())) {
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_VISIT_OWNED) && !Permissions
|
||||
.hasPermission(player, Captions.PERMISSION_HOME)) {
|
||||
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_VISIT_OWNED);
|
||||
return;
|
||||
}
|
||||
} else if (plot.isAdded(player.getUUID())) {
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_SHARED)) {
|
||||
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_SHARED);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_VISIT_OTHER)) {
|
||||
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_VISIT_OTHER);
|
||||
return;
|
||||
}
|
||||
if (!plot.getFlag(UntrustedVisitFlag.class) && !Permissions
|
||||
.hasPermission(player, Captions.PERMISSION_ADMIN_VISIT_UNTRUSTED)) {
|
||||
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_ADMIN_VISIT_UNTRUSTED);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
confirm.run(this, () -> plot.teleportPlayer(player, TeleportCause.COMMAND, result -> {
|
||||
if (result) {
|
||||
whenDone.run(Visit.this, CommandResult.SUCCESS);
|
||||
} else {
|
||||
whenDone.run(Visit.this, CommandResult.FAILURE);
|
||||
}
|
||||
}), () -> whenDone.run(Visit.this, CommandResult.FAILURE));
|
||||
};
|
||||
|
||||
final int[] page = new int[]{Integer.MIN_VALUE};
|
||||
@ -162,7 +171,7 @@ public class Visit extends Command {
|
||||
} else if (throwable != null || uuids.size() != 1) {
|
||||
Captions.COMMAND_SYNTAX.send(player, getUsage());
|
||||
} else {
|
||||
unsortedPre.addAll(PlotSquared.get().getBasePlots((UUID) uuids.toArray()[0]));
|
||||
query.ownedBy(user).whereBasePlot();
|
||||
shouldSortByArea.set(true);
|
||||
pageConsumer.accept(page[0]);
|
||||
}
|
||||
@ -175,14 +184,14 @@ public class Visit extends Command {
|
||||
final Consumer<UUID> uuidConsumer = uuid -> {
|
||||
if (page[0] == Integer.MIN_VALUE && uuid == null && MathMan.isInteger(finalArgs[0])) {
|
||||
page[0] = Integer.parseInt(finalArgs[0]);
|
||||
unsortedPre.addAll(PlotSquared.get().getBasePlots(player));
|
||||
query.ownedBy(player).whereBasePlot();
|
||||
} else {
|
||||
if (uuid != null) {
|
||||
unsortedPre.addAll(PlotSquared.get().getBasePlots(uuid));
|
||||
query.ownedBy(player).whereBasePlot();
|
||||
} else {
|
||||
Plot plot = MainUtil.getPlotFromString(player, finalArgs[0], true);
|
||||
if (plot != null) {
|
||||
unsortedPre.addAll(Collections.singletonList(plot.getBasePlot(false)));
|
||||
query.withPlot(plot);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -204,12 +213,12 @@ public class Visit extends Command {
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
unsortedPre.addAll(PlotSquared.get().getPlots(player));
|
||||
query.ownedBy(player);
|
||||
pageConsumer.accept(1);
|
||||
break;
|
||||
default:
|
||||
|
||||
}
|
||||
|
||||
return CompletableFuture.completedFuture(true);
|
||||
}
|
||||
|
||||
|
@ -506,9 +506,9 @@ public class Settings extends Config {
|
||||
|
||||
@Comment("Settings relating to PlotSquared's GlobalBlockQueue")
|
||||
public static final class QUEUE {
|
||||
@Comment({"Average time per tick spent completing chunk tasks in ms. Target average TPS = 20 * 50 / TARGET_TIME.",
|
||||
@Comment({"Average time per tick spent completing chunk tasks in ms.",
|
||||
"Waits (chunk task time / target_time) ticks before completely the next task."})
|
||||
public static int TARGET_TIME = 65;
|
||||
public static int TARGET_TIME = 40;
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,7 +25,10 @@
|
||||
*/
|
||||
package com.plotsquared.core.plot;
|
||||
|
||||
public abstract class PlotFilter {
|
||||
/**
|
||||
* Use {@link com.plotsquared.core.util.query.PlotQuery} instead
|
||||
*/
|
||||
@Deprecated public abstract class PlotFilter {
|
||||
public boolean allowsArea(final PlotArea area) {
|
||||
return true;
|
||||
}
|
||||
@ -33,4 +36,5 @@ public abstract class PlotFilter {
|
||||
public boolean allowsPlot(final Plot plot) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
105
Core/src/main/java/com/plotsquared/core/plot/PlotWorld.java
Normal file
105
Core/src/main/java/com/plotsquared/core/plot/PlotWorld.java
Normal file
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.plot;
|
||||
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* A world that contains plots
|
||||
*/
|
||||
@EqualsAndHashCode
|
||||
public abstract class PlotWorld {
|
||||
|
||||
private final String world;
|
||||
|
||||
/**
|
||||
* Create a new plot world with a given world name
|
||||
*
|
||||
* @param world World name
|
||||
*/
|
||||
protected PlotWorld(@NotNull final String world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plot area that contains the given location, or null
|
||||
* if the location is not a part of a plot area.
|
||||
*
|
||||
* @param location Location
|
||||
* @return Containing plot area, or null
|
||||
*/
|
||||
@Nullable public abstract PlotArea getArea(@NotNull final Location location);
|
||||
|
||||
/**
|
||||
* Get all plot areas in the world
|
||||
*
|
||||
* @return All plot areas in the world
|
||||
*/
|
||||
@NotNull public abstract Collection<PlotArea> getAreas();
|
||||
|
||||
/**
|
||||
* Get all plot areas in a specified region
|
||||
*
|
||||
* @param region Region
|
||||
* @return All areas in the region
|
||||
*/
|
||||
@NotNull public abstract Collection<PlotArea> getAreasInRegion(
|
||||
@NotNull final CuboidRegion region);
|
||||
|
||||
/**
|
||||
* Register a new area in the world
|
||||
*
|
||||
* @param area Plot area
|
||||
*/
|
||||
public void addArea(@NotNull final PlotArea area) {
|
||||
throw new UnsupportedOperationException("This world type does not allow adding new areas");
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an area from the world
|
||||
*
|
||||
* @param area Plot area
|
||||
*/
|
||||
public void removeArea(@NotNull final PlotArea area) {
|
||||
throw new UnsupportedOperationException("This world type does not allow removing areas");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the world name
|
||||
*
|
||||
* @return World name
|
||||
*/
|
||||
public String getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
}
|
@ -25,143 +25,93 @@
|
||||
*/
|
||||
package com.plotsquared.core.plot.world;
|
||||
|
||||
import com.plotsquared.core.collection.QuadMap;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotAreaType;
|
||||
import com.plotsquared.core.plot.PlotWorld;
|
||||
import com.plotsquared.core.util.StringMan;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class DefaultPlotAreaManager implements PlotAreaManager {
|
||||
|
||||
final PlotArea[] noPlotAreas = new PlotArea[0];
|
||||
// All plot areas mapped by world
|
||||
private final HashMap<String, PlotArea[]> plotAreaMap = new HashMap<>();
|
||||
// All plot areas mapped by position
|
||||
private final HashMap<String, QuadMap<PlotArea>> plotAreaGrid = new HashMap<>();
|
||||
private final HashSet<Integer> plotAreaHashCheck = new HashSet<>();
|
||||
// All plot areas
|
||||
private PlotArea[] plotAreas = new PlotArea[0];
|
||||
// Optimization if there are no hash collisions
|
||||
private boolean plotAreaHasCollision = false;
|
||||
private String[] worlds = new String[0];
|
||||
private final Map<String, PlotWorld> plotWorlds = new HashMap<>();
|
||||
|
||||
@Override public PlotArea[] getAllPlotAreas() {
|
||||
return plotAreas;
|
||||
}
|
||||
|
||||
@Override public PlotArea getApplicablePlotArea(Location location) {
|
||||
switch (this.plotAreas.length) {
|
||||
case 0:
|
||||
return null;
|
||||
case 1:
|
||||
return this.plotAreas[0].getWorldHash() == location.getWorld().hashCode()
|
||||
&& this.plotAreas[0].contains(location) && (!this.plotAreaHasCollision
|
||||
|| location.getWorld().equals(this.plotAreas[0].getWorldName())) ?
|
||||
this.plotAreas[0] :
|
||||
null;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
String world = location.getWorld();
|
||||
int hash = world.hashCode();
|
||||
for (PlotArea area : this.plotAreas) {
|
||||
if (hash == area.getWorldHash()) {
|
||||
if (area.contains(location.getX(), location.getZ()) && (
|
||||
!this.plotAreaHasCollision || world.equals(area.getWorldName()))) {
|
||||
return area;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
default:
|
||||
PlotArea[] areas = this.plotAreaMap.get(location.getWorld());
|
||||
if (areas == null) {
|
||||
return null;
|
||||
}
|
||||
int z;
|
||||
int x;
|
||||
switch (areas.length) {
|
||||
case 1:
|
||||
return areas[0];
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
x = location.getX();
|
||||
z = location.getZ();
|
||||
for (PlotArea area : areas) {
|
||||
if (area.contains(x, z)) {
|
||||
return area;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
default:
|
||||
QuadMap<PlotArea> search = this.plotAreaGrid.get(location.getWorld());
|
||||
return search.get(location.getX(), location.getZ());
|
||||
}
|
||||
final Set<PlotArea> area = new HashSet<>();
|
||||
for (final PlotWorld world : plotWorlds.values()) {
|
||||
area.addAll(world.getAreas());
|
||||
}
|
||||
return area.toArray(new PlotArea[0]);
|
||||
}
|
||||
|
||||
@Override public void addPlotArea(PlotArea plotArea) {
|
||||
HashSet<PlotArea> localAreas =
|
||||
new HashSet<>(Arrays.asList(getPlotAreas(plotArea.getWorldName(), null)));
|
||||
HashSet<PlotArea> globalAreas = new HashSet<>(Arrays.asList(plotAreas));
|
||||
localAreas.add(plotArea);
|
||||
globalAreas.add(plotArea);
|
||||
this.plotAreas = globalAreas.toArray(new PlotArea[0]);
|
||||
this.plotAreaMap.put(plotArea.getWorldName(), localAreas.toArray(new PlotArea[0]));
|
||||
QuadMap<PlotArea> map = this.plotAreaGrid.get(plotArea.getWorldName());
|
||||
if (map == null) {
|
||||
map = new QuadMap<PlotArea>(Integer.MAX_VALUE, 0, 0) {
|
||||
@Override public CuboidRegion getRegion(PlotArea value) {
|
||||
return value.getRegion();
|
||||
}
|
||||
};
|
||||
this.plotAreaGrid.put(plotArea.getWorldName(), map);
|
||||
@Override @Nullable public PlotArea getApplicablePlotArea(final Location location) {
|
||||
if (location == null) {
|
||||
return null;
|
||||
}
|
||||
map.add(plotArea);
|
||||
final PlotWorld world = this.plotWorlds.get(location.getWorld());
|
||||
if (world == null) {
|
||||
return null;
|
||||
}
|
||||
return world.getArea(location);
|
||||
}
|
||||
|
||||
@Override public void removePlotArea(PlotArea area) {
|
||||
ArrayList<PlotArea> globalAreas = new ArrayList<>(Arrays.asList(plotAreas));
|
||||
globalAreas.remove(area);
|
||||
this.plotAreas = globalAreas.toArray(new PlotArea[0]);
|
||||
if (globalAreas.isEmpty()) {
|
||||
this.plotAreaMap.remove(area.getWorldName());
|
||||
this.plotAreaGrid.remove(area.getWorldName());
|
||||
@Override public void addPlotArea(final PlotArea plotArea) {
|
||||
PlotWorld world = this.plotWorlds.get(plotArea.getWorldName());
|
||||
if (world != null) {
|
||||
if (world instanceof StandardPlotWorld && world.getAreas().isEmpty()) {
|
||||
this.plotWorlds.remove(plotArea.getWorldName());
|
||||
} else {
|
||||
world.addArea(plotArea);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (plotArea.getType() != PlotAreaType.PARTIAL) {
|
||||
world = new StandardPlotWorld(plotArea.getWorldName(), plotArea);
|
||||
} else {
|
||||
this.plotAreaMap.put(area.getWorldName(), globalAreas.toArray(new PlotArea[0]));
|
||||
this.plotAreaGrid.get(area.getWorldName()).remove(area);
|
||||
world = new ScatteredPlotWorld(plotArea.getWorldName());
|
||||
world.addArea(plotArea);
|
||||
}
|
||||
this.plotWorlds.put(plotArea.getWorldName(), world);
|
||||
}
|
||||
|
||||
@Override public void removePlotArea(final PlotArea area) {
|
||||
final PlotWorld world = this.plotWorlds.get(area.getWorldName());
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
if (world instanceof StandardPlotWorld) {
|
||||
this.plotWorlds.remove(world.getWorld());
|
||||
} else {
|
||||
world.removeArea(area);
|
||||
if (world.getAreas().isEmpty()) {
|
||||
this.plotWorlds.remove(world.getWorld());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override public PlotArea getPlotArea(String world, String id) {
|
||||
PlotArea[] areas = this.plotAreaMap.get(world);
|
||||
if (areas == null) {
|
||||
@Override public PlotArea getPlotArea(final String world, final String id) {
|
||||
final PlotWorld plotWorld = this.plotWorlds.get(world);
|
||||
if (plotWorld == null) {
|
||||
return null;
|
||||
}
|
||||
if (areas.length == 1) {
|
||||
return areas[0];
|
||||
} else if (id == null) {
|
||||
final List<PlotArea> areas = new ArrayList<>(plotWorld.getAreas());
|
||||
if (areas.size() == 1) {
|
||||
return areas.get(0);
|
||||
}
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
for (PlotArea area : areas) {
|
||||
for (final PlotArea area : areas) {
|
||||
if (StringMan.isEqual(id, area.getId())) {
|
||||
return area;
|
||||
}
|
||||
@ -169,103 +119,37 @@ public class DefaultPlotAreaManager implements PlotAreaManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public PlotArea getPlotArea(@NotNull Location location) {
|
||||
switch (this.plotAreas.length) {
|
||||
case 0:
|
||||
return null;
|
||||
case 1:
|
||||
PlotArea pa = this.plotAreas[0];
|
||||
if (pa.contains(location)) {
|
||||
return pa;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
String world = location.getWorld();
|
||||
int hash = world.hashCode();
|
||||
for (PlotArea area : this.plotAreas) {
|
||||
if (hash == area.getWorldHash()) {
|
||||
if (area.contains(location.getX(), location.getZ()) && (
|
||||
!this.plotAreaHasCollision || world.equals(area.getWorldName()))) {
|
||||
return area;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
default:
|
||||
PlotArea[] areas = this.plotAreaMap.get(location.getWorld());
|
||||
if (areas == null) {
|
||||
return null;
|
||||
}
|
||||
int x;
|
||||
int z;
|
||||
switch (areas.length) {
|
||||
case 0:
|
||||
PlotArea a = areas[0];
|
||||
return a.contains(location.getX(), location.getZ()) ? a : null;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
x = location.getX();
|
||||
z = location.getZ();
|
||||
for (PlotArea area : areas) {
|
||||
if (area.contains(x, z)) {
|
||||
return area;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
default:
|
||||
QuadMap<PlotArea> search = this.plotAreaGrid.get(location.getWorld());
|
||||
return search.get(location.getX(), location.getZ());
|
||||
}
|
||||
}
|
||||
@Override public PlotArea getPlotArea(@NotNull final Location location) {
|
||||
return this.getApplicablePlotArea(location);
|
||||
}
|
||||
|
||||
@Override public PlotArea[] getPlotAreas(String world, CuboidRegion region) {
|
||||
if (region == null) {
|
||||
PlotArea[] areas = this.plotAreaMap.get(world);
|
||||
if (areas == null) {
|
||||
return noPlotAreas;
|
||||
}
|
||||
return areas;
|
||||
}
|
||||
QuadMap<PlotArea> areas = this.plotAreaGrid.get(world);
|
||||
if (areas == null) {
|
||||
@Override public PlotArea[] getPlotAreas(final String world, final CuboidRegion region) {
|
||||
final PlotWorld plotWorld = this.plotWorlds.get(world);
|
||||
if (plotWorld == null) {
|
||||
return noPlotAreas;
|
||||
} else {
|
||||
Set<PlotArea> found = areas.get(region);
|
||||
return found.toArray(new PlotArea[0]);
|
||||
}
|
||||
if (region == null) {
|
||||
return plotWorld.getAreas().toArray(new PlotArea[0]);
|
||||
}
|
||||
return plotWorld.getAreasInRegion(region).toArray(new PlotArea[0]);
|
||||
}
|
||||
|
||||
@Override public void addWorld(String worldName) {
|
||||
if (!this.plotAreaHasCollision && !this.plotAreaHashCheck.add(worldName.hashCode())) {
|
||||
this.plotAreaHasCollision = true;
|
||||
@Override public void addWorld(final String worldName) {
|
||||
PlotWorld world = this.plotWorlds.get(worldName);
|
||||
if (world != null) {
|
||||
return;
|
||||
}
|
||||
Set<String> tmp = new LinkedHashSet<>();
|
||||
Collections.addAll(tmp, worlds);
|
||||
tmp.add(worldName);
|
||||
worlds = tmp.toArray(new String[0]);
|
||||
// Create a new empty world. When a new area is added
|
||||
// the world will be re-recreated with the correct type
|
||||
world = new StandardPlotWorld(worldName, null);
|
||||
this.plotWorlds.put(worldName, world);
|
||||
}
|
||||
|
||||
@Override public void removeWorld(String worldName) {
|
||||
Set<String> tmp = new LinkedHashSet<>();
|
||||
Collections.addAll(tmp, worlds);
|
||||
tmp.remove(worldName);
|
||||
worlds = tmp.toArray(new String[0]);
|
||||
@Override public void removeWorld(final String worldName) {
|
||||
this.plotWorlds.remove(worldName);
|
||||
}
|
||||
|
||||
@Override public String[] getAllWorlds() {
|
||||
return worlds;
|
||||
return this.plotWorlds.keySet().toArray(new String[0]);
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface PlotAreaManager {
|
||||
|
||||
@ -44,7 +45,7 @@ public interface PlotAreaManager {
|
||||
* @param location The location
|
||||
* @return An applicable area, or null
|
||||
*/
|
||||
PlotArea getApplicablePlotArea(Location location);
|
||||
@Nullable PlotArea getApplicablePlotArea(Location location);
|
||||
|
||||
/**
|
||||
* Get the plot area, if there is any, for the given
|
||||
|
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.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.RegionUtil;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import rx.Observable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Plot world that contains several plot areas (clusters)
|
||||
*/
|
||||
public class ScatteredPlotWorld extends PlotWorld {
|
||||
|
||||
private final List<PlotArea> areas = new LinkedList<>();
|
||||
private final Object treeLock = new Object();
|
||||
private RTree<PlotArea, Geometry> areaTree;
|
||||
|
||||
/**
|
||||
* Create a new plot world with a given world name
|
||||
*
|
||||
* @param world World name
|
||||
*/
|
||||
public ScatteredPlotWorld(@NotNull final String world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
@Override @Nullable public PlotArea getArea(@NotNull final Location location) {
|
||||
if (this.areas.isEmpty()) {
|
||||
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;
|
||||
}
|
||||
return area.toBlocking().first().value();
|
||||
}
|
||||
}
|
||||
|
||||
@Override @NotNull public Collection<PlotArea> getAreas() {
|
||||
return Collections.unmodifiableCollection(this.areas);
|
||||
}
|
||||
|
||||
@Override public void addArea(@NotNull final PlotArea area) {
|
||||
this.areas.add(area);
|
||||
this.buildTree();
|
||||
}
|
||||
|
||||
@Override public void removeArea(@NotNull final PlotArea area) {
|
||||
this.areas.remove(area);
|
||||
this.buildTree();
|
||||
}
|
||||
|
||||
@Override @NotNull public Collection<PlotArea> getAreasInRegion(@NotNull final CuboidRegion region) {
|
||||
if (this.areas.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
synchronized (this.treeLock) {
|
||||
final List<PlotArea> areas = new LinkedList<>();
|
||||
this.areaTree.search(RegionUtil.toRectangle(region)).toBlocking().forEach(entry -> areas.add(entry.value()));
|
||||
return areas;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild the area tree
|
||||
*/
|
||||
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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.plot.world;
|
||||
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotWorld;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* Ordinary plot world with a single plot area
|
||||
*/
|
||||
public class StandardPlotWorld extends PlotWorld {
|
||||
|
||||
private final PlotArea area;
|
||||
|
||||
public StandardPlotWorld(@NotNull final String world, @Nullable final PlotArea area) {
|
||||
super(world);
|
||||
this.area = area;
|
||||
}
|
||||
|
||||
@Override @Nullable public PlotArea getArea(@NotNull final Location location) {
|
||||
return this.area;
|
||||
}
|
||||
|
||||
@Override @NotNull public Collection<PlotArea> getAreas() {
|
||||
if (this.area == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Collections.singletonList(this.area);
|
||||
}
|
||||
|
||||
@Override @NotNull public Collection<PlotArea> getAreasInRegion(@NotNull final CuboidRegion region) {
|
||||
return this.getAreas();
|
||||
}
|
||||
|
||||
}
|
@ -57,6 +57,7 @@ public class GlobalBlockQueue {
|
||||
private final RunnableVal2<Long, LocalBlockQueue> SET_TASK =
|
||||
new RunnableVal2<Long, LocalBlockQueue>() {
|
||||
@Override public void run(Long free, LocalBlockQueue queue) {
|
||||
long t1 = System.currentTimeMillis();
|
||||
do {
|
||||
boolean more = queue.next();
|
||||
if (!more) {
|
||||
@ -66,9 +67,9 @@ public class GlobalBlockQueue {
|
||||
}
|
||||
return;
|
||||
}
|
||||
} while ((lastPeriod =
|
||||
((GlobalBlockQueue.this.secondLast = System.currentTimeMillis())
|
||||
- GlobalBlockQueue.this.last)) < free);
|
||||
} while (((GlobalBlockQueue.this.secondLast = System.currentTimeMillis())
|
||||
- GlobalBlockQueue.this.last) < free);
|
||||
lastPeriod = System.currentTimeMillis() - t1;
|
||||
}
|
||||
};
|
||||
|
||||
@ -124,8 +125,8 @@ public class GlobalBlockQueue {
|
||||
lastPeriod -= targetTime;
|
||||
return;
|
||||
}
|
||||
SET_TASK.value1 = 50 + Math.min(
|
||||
(50 + GlobalBlockQueue.this.last) - (GlobalBlockQueue.this.last =
|
||||
SET_TASK.value1 = 30 + Math.min(
|
||||
(30 + GlobalBlockQueue.this.last) - (GlobalBlockQueue.this.last =
|
||||
System.currentTimeMillis()),
|
||||
GlobalBlockQueue.this.secondLast - System.currentTimeMillis());
|
||||
SET_TASK.value2 = GlobalBlockQueue.this.getNextQueue();
|
||||
|
@ -25,9 +25,13 @@
|
||||
*/
|
||||
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;
|
||||
|
||||
public class RegionUtil {
|
||||
public static CuboidRegion createRegion(int pos1x, int pos2x, int pos1z, int pos2z) {
|
||||
@ -54,6 +58,12 @@ public class RegionUtil {
|
||||
.getY() && y <= max.getY();
|
||||
}
|
||||
|
||||
@NotNull public static Rectangle 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());
|
||||
}
|
||||
|
||||
// Because WE (not fawe) lack this for CuboidRegion
|
||||
public static boolean intersects(CuboidRegion region, CuboidRegion other) {
|
||||
BlockVector3 regionMin = region.getMinimumPoint();
|
||||
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.query;
|
||||
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class AliasFilter implements PlotFilter {
|
||||
|
||||
private final String alias;
|
||||
|
||||
AliasFilter(@NotNull final String alias) {
|
||||
this.alias = alias;
|
||||
}
|
||||
|
||||
@Override public boolean accepts(@NotNull final Plot plot) {
|
||||
return this.alias.equalsIgnoreCase(plot.getAlias());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.query;
|
||||
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
class AreaLimitedPlotProvider implements PlotProvider {
|
||||
|
||||
private final Collection<PlotArea> areas;
|
||||
|
||||
AreaLimitedPlotProvider(Collection<PlotArea> areas) {
|
||||
this.areas = areas;
|
||||
}
|
||||
|
||||
@Override public Collection<Plot> getPlots() {
|
||||
final List<Plot> plots = new LinkedList<>();
|
||||
for (final PlotArea area : areas) {
|
||||
plots.addAll(area.getPlots());
|
||||
}
|
||||
return plots;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.query;
|
||||
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.expiration.ExpireManager;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
class ExpiredPlotProvider implements PlotProvider {
|
||||
|
||||
@Override public Collection<Plot> getPlots() {
|
||||
return ExpireManager.IMP.getPendingExpired();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.query;
|
||||
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
class FixedPlotProvider implements PlotProvider {
|
||||
|
||||
private final Plot plot;
|
||||
|
||||
FixedPlotProvider(@NotNull final Plot plot) {
|
||||
this.plot = plot;
|
||||
}
|
||||
|
||||
@Override public Collection<Plot> getPlots() {
|
||||
return Collections.singleton(plot);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.query;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
class GlobalPlotProvider implements PlotProvider {
|
||||
|
||||
@Override public Collection<Plot> getPlots() {
|
||||
return PlotSquared.get().getPlots();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.query;
|
||||
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
class MemberFilter implements PlotFilter {
|
||||
|
||||
@NotNull private final UUID uuid;
|
||||
|
||||
MemberFilter(@NotNull final UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
@Override public boolean accepts(@NotNull final Plot plot) {
|
||||
return plot.isAdded(uuid);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.query;
|
||||
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
class NullProvider implements PlotProvider {
|
||||
|
||||
@Override public Collection<Plot> getPlots() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.query;
|
||||
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
class OwnerFilter implements PlotFilter {
|
||||
|
||||
private final UUID owner;
|
||||
|
||||
OwnerFilter(@NotNull final UUID owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@Override public boolean accepts(@NotNull final Plot plot) {
|
||||
return plot.hasOwner() && Objects.equals(plot.getOwnerAbs(), this.owner);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.query;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Paginated collection of plots as a result of a {@link PlotQuery query}
|
||||
*/
|
||||
public final class PaginatedPlotResult {
|
||||
|
||||
private final List<Plot> plots;
|
||||
private final int pageSize;
|
||||
|
||||
PaginatedPlotResult(@NotNull final List<Plot> plots, final int pageSize) {
|
||||
this.plots = plots;
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plots belonging to a certain page.
|
||||
*
|
||||
* @param page Positive page number. Indexed from 1
|
||||
* @return Plots that belong to the specified page
|
||||
*/
|
||||
public List<Plot> getPage(final int page) {
|
||||
Preconditions.checkState(page >= 0, "Page must be positive");
|
||||
final int from = (page - 1) * this.pageSize;
|
||||
if (this.plots.size() < from) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
final int to = Math.max(from + pageSize, this.plots.size());
|
||||
return this.plots.subList(from, to);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of available pages
|
||||
*
|
||||
* @return Available pages
|
||||
*/
|
||||
public int getPages() {
|
||||
return (int) Math.ceil((double) plots.size() / (double) pageSize);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.query;
|
||||
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@FunctionalInterface interface PlotFilter extends Predicate<Plot> {
|
||||
|
||||
@Override default boolean test(@NotNull final Plot plot) {
|
||||
return this.accepts(plot);
|
||||
}
|
||||
|
||||
boolean accepts(@NotNull final Plot plot);
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.query;
|
||||
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@FunctionalInterface interface PlotProvider {
|
||||
|
||||
Collection<Plot> getPlots();
|
||||
|
||||
}
|
@ -0,0 +1,384 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.query;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.Rating;
|
||||
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* This represents a plot query, and can be used to
|
||||
* search for plots matching certain criteria.
|
||||
* <p>
|
||||
* The queries can be reused as no results are stored
|
||||
* in the query itself
|
||||
*/
|
||||
public final class PlotQuery {
|
||||
|
||||
private final Collection<PlotFilter> filters = new LinkedList<>();
|
||||
private PlotProvider plotProvider = new GlobalPlotProvider();
|
||||
private SortingStrategy sortingStrategy = SortingStrategy.NO_SORTING;
|
||||
private PlotArea priorityArea;
|
||||
private Comparator<Plot> plotComparator;
|
||||
|
||||
private PlotQuery() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new plot query instance
|
||||
*
|
||||
* @return New query
|
||||
*/
|
||||
public static PlotQuery newQuery() {
|
||||
return new PlotQuery();
|
||||
}
|
||||
|
||||
/**
|
||||
* Query for plots in a single area
|
||||
*
|
||||
* @param area Area
|
||||
* @return The query instance
|
||||
*/
|
||||
@NotNull public PlotQuery inArea(@NotNull final PlotArea area) {
|
||||
Preconditions.checkNotNull(area, "Area may not be null");
|
||||
this.plotProvider = new AreaLimitedPlotProvider(Collections.singletonList(area));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query for plots in all areas in a world
|
||||
*
|
||||
* @param world World name
|
||||
* @return The query instance
|
||||
*/
|
||||
@NotNull public PlotQuery inWorld(@NotNull final String world) {
|
||||
Preconditions.checkNotNull(world, "World may not be null");
|
||||
this.plotProvider = new AreaLimitedPlotProvider(PlotSquared.get().getPlotAreas(world));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query for plots in specific areas
|
||||
*
|
||||
* @param areas Plot areas
|
||||
* @return The query instance
|
||||
*/
|
||||
@NotNull public PlotQuery inAreas(@NotNull final Collection<PlotArea> areas) {
|
||||
Preconditions.checkNotNull(areas, "Areas may not be null");
|
||||
Preconditions.checkState(!areas.isEmpty(), "At least one area must be provided");
|
||||
this.plotProvider = new AreaLimitedPlotProvider(Collections.unmodifiableCollection(areas));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query for expired plots
|
||||
*
|
||||
* @return The query instance
|
||||
*/
|
||||
@NotNull public PlotQuery expiredPlots() {
|
||||
this.plotProvider = new ExpiredPlotProvider();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query for all plots
|
||||
*
|
||||
* @return The query instance
|
||||
*/
|
||||
@NotNull public PlotQuery allPlots() {
|
||||
this.plotProvider = new GlobalPlotProvider();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't query at all
|
||||
*
|
||||
* @return The query instance
|
||||
*/
|
||||
@NotNull public PlotQuery noPlots() {
|
||||
this.plotProvider = new NullProvider();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query for plots based on a search term
|
||||
*
|
||||
* @return The query instance
|
||||
*/
|
||||
@NotNull public PlotQuery plotsBySearch(@NotNull final String searchTerm) {
|
||||
Preconditions.checkNotNull(searchTerm, "Search term may not be null");
|
||||
this.plotProvider = new SearchPlotProvider(searchTerm);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query with a pre-defined result
|
||||
*
|
||||
* @return The query instance
|
||||
*/
|
||||
@NotNull public PlotQuery withPlot(@NotNull final Plot plot) {
|
||||
Preconditions.checkNotNull(plot, "Plot may not be null");
|
||||
this.plotProvider = new FixedPlotProvider(plot);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query for base plots only
|
||||
*
|
||||
* @return The query instance
|
||||
*/
|
||||
@NotNull public PlotQuery whereBasePlot() {
|
||||
return this.addFilter(new PredicateFilter(Plot::isBasePlot));
|
||||
}
|
||||
|
||||
/**
|
||||
* Query for plots owned by a specific player
|
||||
*
|
||||
* @param owner Owner UUID
|
||||
* @return The query instance
|
||||
*/
|
||||
@NotNull public PlotQuery ownedBy(@NotNull final UUID owner) {
|
||||
Preconditions.checkNotNull(owner, "Owner may not be null");
|
||||
return this.addFilter(new OwnerFilter(owner));
|
||||
}
|
||||
|
||||
/**
|
||||
* Query for plots owned by a specific player
|
||||
*
|
||||
* @param owner Owner
|
||||
* @return The query instance
|
||||
*/
|
||||
@NotNull public PlotQuery ownedBy(@NotNull final PlotPlayer owner) {
|
||||
Preconditions.checkNotNull(owner, "Owner may not be null");
|
||||
return this.addFilter(new OwnerFilter(owner.getUUID()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Query for plots with a specific alias
|
||||
*
|
||||
* @param alias Plot alias
|
||||
* @return The query instance
|
||||
*/
|
||||
@NotNull public PlotQuery withAlias(@NotNull final String alias) {
|
||||
Preconditions.checkNotNull(alias, "Alias may not be null");
|
||||
return this.addFilter(new AliasFilter(alias));
|
||||
}
|
||||
|
||||
/**
|
||||
* Query for plots with a specific member (added/trusted/owner)
|
||||
*
|
||||
* @param member Member UUID
|
||||
* @return The query instance
|
||||
*/
|
||||
@NotNull public PlotQuery withMember(@NotNull final UUID member) {
|
||||
Preconditions.checkNotNull(member, "Member may not be null");
|
||||
return this.addFilter(new MemberFilter(member));
|
||||
}
|
||||
|
||||
/**
|
||||
* Query for plots that passes a given predicate
|
||||
*
|
||||
* @param predicate Predicate
|
||||
* @return The query instance
|
||||
*/
|
||||
@NotNull public PlotQuery thatPasses(@NotNull final Predicate<Plot> predicate) {
|
||||
Preconditions.checkNotNull(predicate, "Predicate may not be null");
|
||||
return this.addFilter(new PredicateFilter(predicate));
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the sorting strategy that will decide how to
|
||||
* sort the results. This only matters if you use {@link #asList()}
|
||||
*
|
||||
* @param strategy Strategy
|
||||
* @return The query instance
|
||||
*/
|
||||
@NotNull public PlotQuery withSortingStrategy(@NotNull final SortingStrategy strategy) {
|
||||
Preconditions.checkNotNull(strategy, "Strategy may not be null");
|
||||
this.sortingStrategy = strategy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use a custom comparator to sort the results
|
||||
*
|
||||
* @param comparator Comparator
|
||||
* @return The query instance
|
||||
*/
|
||||
@NotNull public PlotQuery sorted(@NotNull final Comparator<Plot> comparator) {
|
||||
Preconditions.checkNotNull(comparator, "Comparator may not be null");
|
||||
this.sortingStrategy = SortingStrategy.COMPARATOR;
|
||||
this.plotComparator = comparator;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the area around which plots may be sorted, depending on the
|
||||
* sorting strategy
|
||||
*
|
||||
* @param plotArea Plot area
|
||||
* @return The query instance
|
||||
*/
|
||||
@NotNull public PlotQuery relativeToArea(@NotNull final PlotArea plotArea) {
|
||||
Preconditions.checkNotNull(plotArea, "Area may not be null");
|
||||
this.priorityArea = plotArea;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all plots that match the given criteria
|
||||
*
|
||||
* @return Matching plots
|
||||
*/
|
||||
@NotNull public Stream<Plot> asStream() {
|
||||
return this.asList().stream();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all plots that match the given criteria
|
||||
*
|
||||
* @return Matching plots as a mutable
|
||||
*/
|
||||
@NotNull public List<Plot> asList() {
|
||||
final List<Plot> result;
|
||||
if (this.filters.isEmpty()) {
|
||||
result = new ArrayList<>(this.plotProvider.getPlots());
|
||||
} else {
|
||||
final Collection<Plot> plots = this.plotProvider.getPlots();
|
||||
result = new ArrayList<>(plots.size());
|
||||
for (final Plot plot : plots) {
|
||||
for (final PlotFilter filter : this.filters) {
|
||||
if (filter.accepts(plot)) {
|
||||
result.add(plot);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.sortingStrategy == SortingStrategy.NO_SORTING) {
|
||||
return result;
|
||||
} else if (this.sortingStrategy == SortingStrategy.SORT_BY_TEMP) {
|
||||
return PlotSquared.get().sortPlotsByTemp(result);
|
||||
} else if (this.sortingStrategy == SortingStrategy.SORT_BY_DONE) {
|
||||
result.sort((a, b) -> {
|
||||
String va = a.getFlag(DoneFlag.class);
|
||||
String vb = b.getFlag(DoneFlag.class);
|
||||
if (MathMan.isInteger(va)) {
|
||||
if (MathMan.isInteger(vb)) {
|
||||
return Integer.parseInt(vb) - Integer.parseInt(va);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
} else if (this.sortingStrategy == SortingStrategy.SORT_BY_RATING) {
|
||||
result.sort((p1, p2) -> {
|
||||
double v1 = 0;
|
||||
int p1s = p1.getSettings().getRatings().size();
|
||||
int p2s = p2.getRatings().size();
|
||||
if (!p1.getSettings().getRatings().isEmpty()) {
|
||||
v1 = p1.getRatings().values().stream().mapToDouble(Rating::getAverageRating)
|
||||
.map(av -> av * av).sum();
|
||||
v1 /= p1s;
|
||||
v1 += p1s;
|
||||
}
|
||||
double v2 = 0;
|
||||
if (!p2.getSettings().getRatings().isEmpty()) {
|
||||
for (Map.Entry<UUID, Rating> entry : p2.getRatings().entrySet()) {
|
||||
double av = entry.getValue().getAverageRating();
|
||||
v2 += av * av;
|
||||
}
|
||||
v2 /= p2s;
|
||||
v2 += p2s;
|
||||
}
|
||||
if (v2 == v1 && v2 != 0) {
|
||||
return p2s - p1s;
|
||||
}
|
||||
return (int) Math.signum(v2 - v1);
|
||||
});
|
||||
} else if (this.sortingStrategy == SortingStrategy.SORT_BY_CREATION) {
|
||||
return PlotSquared.get().sortPlots(result, PlotSquared.SortType.CREATION_DATE, this.priorityArea);
|
||||
} else if (this.sortingStrategy == SortingStrategy.COMPARATOR) {
|
||||
result.sort(this.plotComparator);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all plots that match the given criteria
|
||||
*
|
||||
* @return Matching plots as a mutable set
|
||||
*/
|
||||
@NotNull public Set<Plot> asSet() {
|
||||
return new HashSet<>(this.asList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all plots that match the given criteria
|
||||
* in the form of a {@link PaginatedPlotResult}
|
||||
*
|
||||
* @param pageSize The size of the pages. Must be positive.
|
||||
* @return Paginated plot result
|
||||
*/
|
||||
@NotNull public PaginatedPlotResult getPaginated(final int pageSize) {
|
||||
Preconditions.checkState(pageSize > 0, "Page size must be greater than 0");
|
||||
return new PaginatedPlotResult(this.asList(), pageSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all plots that match the given criteria
|
||||
*
|
||||
* @return Matching plots as an immutable collection
|
||||
*/
|
||||
@NotNull public Collection<Plot> asCollection() {
|
||||
return this.asList();
|
||||
}
|
||||
|
||||
@NotNull private PlotQuery addFilter(@NotNull final PlotFilter filter) {
|
||||
this.filters.add(filter);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.query;
|
||||
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
class PredicateFilter implements PlotFilter {
|
||||
|
||||
private final Predicate<Plot> predicate;
|
||||
|
||||
PredicateFilter(@NotNull final Predicate<Plot> predicate) {
|
||||
this.predicate = predicate;
|
||||
}
|
||||
|
||||
@Override public boolean accepts(@NotNull final Plot plot) {
|
||||
return predicate.test(plot);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.query;
|
||||
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
class SearchPlotProvider implements PlotProvider {
|
||||
|
||||
private final String searchTerm;
|
||||
|
||||
SearchPlotProvider(@NotNull final String searchTerm) {
|
||||
this.searchTerm = searchTerm;
|
||||
}
|
||||
|
||||
@Override public Collection<Plot> getPlots() {
|
||||
return MainUtil.getPlotsBySearch(this.searchTerm);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.query;
|
||||
|
||||
/**
|
||||
* Strategy used when sorting plot results
|
||||
*/
|
||||
public enum SortingStrategy {
|
||||
/**
|
||||
* Plots won't be sorted at all
|
||||
*/
|
||||
NO_SORTING,
|
||||
/**
|
||||
* Sort by the temporary (magic) plot ID
|
||||
*/
|
||||
SORT_BY_TEMP,
|
||||
/**
|
||||
* Sort by the value in the plot's {@link com.plotsquared.core.plot.flag.implementations.DoneFlag}
|
||||
*/
|
||||
SORT_BY_DONE,
|
||||
/**
|
||||
* Sort by the plot rating
|
||||
*/
|
||||
SORT_BY_RATING,
|
||||
/**
|
||||
* Sort by creation date
|
||||
*/
|
||||
SORT_BY_CREATION,
|
||||
/**
|
||||
* Sort using a comparator
|
||||
*/
|
||||
COMPARATOR;
|
||||
}
|
@ -28,6 +28,7 @@ is to provide a lag-free and smooth experience.
|
||||
* [Download](https://www.spigotmc.org/resources/plotsquared-v5.77506/)
|
||||
* [Discord](https://discord.gg/KxkjDVg)
|
||||
* [Wiki](https://wiki.intellectualsites.com/plotsquared/home)
|
||||
* [Issues](https://issues.intellectualsites.com/projects/ps)
|
||||
|
||||
### Developer Resources
|
||||
* [API Documentation](https://wiki.intellectualsites.com/en/plotsquared/developer/development-portal)
|
||||
|
Loading…
Reference in New Issue
Block a user