mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 15:16:45 +01:00
Some work on plot clusters
This commit is contained in:
parent
ad94637c2a
commit
22997ac089
@ -351,9 +351,9 @@ public class PS {
|
|||||||
* @param message Message to log
|
* @param message Message to log
|
||||||
* @see IPlotMain#log(String)
|
* @see IPlotMain#log(String)
|
||||||
*/
|
*/
|
||||||
public static void debug(final String message) {
|
public static void debug(final Object message) {
|
||||||
if (Settings.DEBUG) {
|
if (Settings.DEBUG) {
|
||||||
get().IMP.log(message);
|
log(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ public class Auto extends SubCommand {
|
|||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
return sendMessage(plr, C.NOT_IN_PLOT);
|
return sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
final PlotCluster cluster = ClusterManager.getCluster(loc);
|
final PlotCluster cluster = plot.getCluster();
|
||||||
// Must be standing in a cluster
|
// Must be standing in a cluster
|
||||||
if (cluster == null) {
|
if (cluster == null) {
|
||||||
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||||
@ -183,7 +183,7 @@ public class Auto extends SubCommand {
|
|||||||
for (int i = 0; i <= max; i++) {
|
for (int i = 0; i <= max; i++) {
|
||||||
final PlotId currentId = new PlotId(origin.x + id.x, origin.y + id.y);
|
final PlotId currentId = new PlotId(origin.x + id.x, origin.y + id.y);
|
||||||
final Plot current = MainUtil.getPlot(worldname, currentId);
|
final Plot current = MainUtil.getPlot(worldname, currentId);
|
||||||
if (MainUtil.canClaim(plr, current) && (current.getSettings().isMerged() == false) && cluster.equals(ClusterManager.getCluster(current))) {
|
if (MainUtil.canClaim(plr, current) && (current.getSettings().isMerged() == false) && cluster.equals(current.getCluster())) {
|
||||||
Claim.claimPlot(plr, current, true, true);
|
Claim.claimPlot(plr, current, true, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -22,11 +22,14 @@ package com.intellectualcrafters.plot.commands;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
|
import com.intellectualcrafters.plot.flag.Flag;
|
||||||
|
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||||
import com.intellectualcrafters.plot.generator.PlotGenerator;
|
import com.intellectualcrafters.plot.generator.PlotGenerator;
|
||||||
import com.intellectualcrafters.plot.object.BlockLoc;
|
import com.intellectualcrafters.plot.object.BlockLoc;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
@ -123,34 +126,28 @@ public class Cluster extends SubCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//check if overlap
|
|
||||||
final PlotClusterId id = new PlotClusterId(pos1, pos2);
|
|
||||||
final HashSet<PlotCluster> intersects = ClusterManager.getIntersects(plr.getLocation().getWorld(), id);
|
|
||||||
if ((intersects.size() > 0)) {
|
|
||||||
MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, intersects.size() + "");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if ((pos2.x < pos1.x) || (pos2.y < pos1.y) ) {
|
if ((pos2.x < pos1.x) || (pos2.y < pos1.y) ) {
|
||||||
pos1 = new PlotId(Math.min(pos1.x, pos2.x), Math.min(pos1.y, pos2.y));
|
pos1 = new PlotId(Math.min(pos1.x, pos2.x), Math.min(pos1.y, pos2.y));
|
||||||
pos2 = new PlotId(Math.max(pos1.x, pos2.x), Math.max(pos1.y, pos2.y));
|
pos2 = new PlotId(Math.max(pos1.x, pos2.x), Math.max(pos1.y, pos2.y));
|
||||||
}
|
}
|
||||||
// create cluster
|
//check if overlap
|
||||||
final String world = plr.getLocation().getWorld();
|
String world = plr.getLocation().getWorld();
|
||||||
|
final PlotClusterId id = new PlotClusterId(pos1, pos2);
|
||||||
|
final HashSet<PlotCluster> intersects = ClusterManager.getIntersects(world, id);
|
||||||
|
if ((intersects.size() > 0)) {
|
||||||
|
MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, intersects.size() + "");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Check if it occupies existing plots
|
||||||
|
Set<Plot> plots = MainUtil.getPlotSelectionOwned(world, pos1, pos2);
|
||||||
|
if (plots.size() > 0) {
|
||||||
|
if (!Permissions.hasPermission(plr, "plots.cluster.create.other")) {
|
||||||
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.create.other");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Set the generator (if applicable)
|
||||||
final PlotCluster cluster = new PlotCluster(world, pos1, pos2, UUIDHandler.getUUID(plr));
|
final PlotCluster cluster = new PlotCluster(world, pos1, pos2, UUIDHandler.getUUID(plr));
|
||||||
cluster.settings.setAlias(name);
|
|
||||||
DBFunc.createCluster(world, cluster);
|
|
||||||
if (!ClusterManager.clusters.containsKey(world)) {
|
|
||||||
ClusterManager.clusters.put(world, new HashSet<PlotCluster>());
|
|
||||||
}
|
|
||||||
ClusterManager.clusters.get(world).add(cluster);
|
|
||||||
// Add any existing plots to the current cluster
|
|
||||||
for (final Plot plot : PS.get().getPlotsInWorld(plr.getLocation().getWorld())) {
|
|
||||||
final PlotCluster current = ClusterManager.getCluster(plot);
|
|
||||||
if (cluster.equals(current) && !cluster.isAdded(plot.owner)) {
|
|
||||||
cluster.invited.add(plot.owner);
|
|
||||||
DBFunc.setInvited(world, cluster, plot.owner);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PlotWorld plotworld = PS.get().getPlotWorld(world);
|
PlotWorld plotworld = PS.get().getPlotWorld(world);
|
||||||
if (plotworld == null) {
|
if (plotworld == null) {
|
||||||
PS.get().config.createSection("worlds." + world);
|
PS.get().config.createSection("worlds." + world);
|
||||||
@ -184,6 +181,24 @@ public class Cluster extends SubCommand {
|
|||||||
// }
|
// }
|
||||||
// new AugmentedPopulator(world, generator, cluster, plotworld.TERRAIN == 2, plotworld.TERRAIN != 2);
|
// new AugmentedPopulator(world, generator, cluster, plotworld.TERRAIN == 2, plotworld.TERRAIN != 2);
|
||||||
}
|
}
|
||||||
|
// create cluster
|
||||||
|
cluster.settings.setAlias(name);
|
||||||
|
DBFunc.createCluster(world, cluster);
|
||||||
|
if (!ClusterManager.clusters.containsKey(world)) {
|
||||||
|
ClusterManager.clusters.put(world, new HashSet<PlotCluster>());
|
||||||
|
}
|
||||||
|
ClusterManager.clusters.get(world).add(cluster);
|
||||||
|
// Add any existing plots to the current cluster
|
||||||
|
for (Plot plot : plots) {
|
||||||
|
if (plot.hasOwner()) {
|
||||||
|
Flag flag = new Flag(FlagManager.getFlag("cluster"), cluster);
|
||||||
|
FlagManager.addPlotFlag(plot, flag);
|
||||||
|
if (!cluster.isAdded(plot.owner)) {
|
||||||
|
cluster.invited.add(plot.owner);
|
||||||
|
DBFunc.setInvited(world, cluster, plot.owner);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
MainUtil.sendMessage(plr, C.CLUSTER_ADDED);
|
MainUtil.sendMessage(plr, C.CLUSTER_ADDED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -252,14 +267,20 @@ public class Cluster extends SubCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// check pos1 / pos2
|
// check pos1 / pos2
|
||||||
final PlotId pos1 = MainUtil.parseId(args[1]);
|
PlotId pos1 = MainUtil.parseId(args[1]);
|
||||||
final PlotId pos2 = MainUtil.parseId(args[2]);
|
PlotId pos2 = MainUtil.parseId(args[2]);
|
||||||
if ((pos1 == null) || (pos2 == null)) {
|
if ((pos1 == null) || (pos2 == null)) {
|
||||||
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if ((pos2.x < pos1.x) || (pos2.y < pos1.y) ) {
|
||||||
|
pos1 = new PlotId(Math.min(pos1.x, pos2.x), Math.min(pos1.y, pos2.y));
|
||||||
|
pos2 = new PlotId(Math.max(pos1.x, pos2.x), Math.max(pos1.y, pos2.y));
|
||||||
|
}
|
||||||
// check if in cluster
|
// check if in cluster
|
||||||
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
|
Location loc = plr.getLocation();
|
||||||
|
String world = loc.getWorld();
|
||||||
|
final PlotCluster cluster = ClusterManager.getCluster(loc);
|
||||||
if (cluster == null) {
|
if (cluster == null) {
|
||||||
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||||
return false;
|
return false;
|
||||||
@ -272,11 +293,35 @@ public class Cluster extends SubCommand {
|
|||||||
}
|
}
|
||||||
//check if overlap
|
//check if overlap
|
||||||
final PlotClusterId id = new PlotClusterId(pos1, pos2);
|
final PlotClusterId id = new PlotClusterId(pos1, pos2);
|
||||||
final HashSet<PlotCluster> intersects = ClusterManager.getIntersects(plr.getLocation().getWorld(), id);
|
final HashSet<PlotCluster> intersects = ClusterManager.getIntersects(world, id);
|
||||||
if (intersects.size() > 1) {
|
if (intersects.size() > 1) {
|
||||||
MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, (intersects.size() - 1) + "");
|
MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, (intersects.size() - 1) + "");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
HashSet<Plot> existing = MainUtil.getPlotSelectionOwned(world, cluster.getP1(), cluster.getP2());
|
||||||
|
HashSet<Plot> newplots = MainUtil.getPlotSelectionOwned(world, pos1, pos2);
|
||||||
|
HashSet<Plot> removed = ((HashSet<Plot>) existing.clone());
|
||||||
|
removed.removeAll(newplots);
|
||||||
|
// Check expand / shrink
|
||||||
|
if (removed.size() > 0) {
|
||||||
|
if (!Permissions.hasPermission(plr, "plots.cluster.resize.shrink")) {
|
||||||
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize.shrink");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newplots.removeAll(existing);
|
||||||
|
if (newplots.size() > 0) {
|
||||||
|
if (!Permissions.hasPermission(plr, "plots.cluster.resize.expand")) {
|
||||||
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize.expand");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Plot plot : removed) {
|
||||||
|
FlagManager.removePlotFlag(plot, "cluster");
|
||||||
|
}
|
||||||
|
for (Plot plot : newplots) {
|
||||||
|
FlagManager.addPlotFlag(plot, new Flag(FlagManager.getFlag("cluster"), cluster));
|
||||||
|
}
|
||||||
// resize cluster
|
// resize cluster
|
||||||
DBFunc.resizeCluster(cluster, id);
|
DBFunc.resizeCluster(cluster, id);
|
||||||
MainUtil.sendMessage(plr, C.CLUSTER_RESIZED);
|
MainUtil.sendMessage(plr, C.CLUSTER_RESIZED);
|
||||||
|
@ -43,6 +43,7 @@ import com.intellectualcrafters.plot.flag.FlagManager;
|
|||||||
import com.intellectualcrafters.plot.util.BO3Handler;
|
import com.intellectualcrafters.plot.util.BO3Handler;
|
||||||
import com.intellectualcrafters.plot.util.BlockManager;
|
import com.intellectualcrafters.plot.util.BlockManager;
|
||||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||||
|
import com.intellectualcrafters.plot.util.ClusterManager;
|
||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
@ -227,6 +228,44 @@ public class Plot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the cluster this plot is associated with
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public PlotCluster getCluster() {
|
||||||
|
if (!Settings.ENABLE_CLUSTERS) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (owner == null) {
|
||||||
|
return ClusterManager.getCluster(this);
|
||||||
|
}
|
||||||
|
Flag flag = FlagManager.getPlotFlag(this, "cluster");
|
||||||
|
if (flag != null) {
|
||||||
|
PlotCluster cluster = (PlotCluster) flag.getValue();
|
||||||
|
cluster = ClusterManager.getCluster(cluster.world, cluster.getName());
|
||||||
|
if (cluster != null) {
|
||||||
|
return cluster;
|
||||||
|
}
|
||||||
|
cluster = ClusterManager.getCluster(this);
|
||||||
|
if (cluster == null) {
|
||||||
|
FlagManager.removePlotFlag(this, "cluster");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
flag = new Flag(flag.getAbstractFlag(), cluster);
|
||||||
|
FlagManager.addPlotFlag(this, flag);
|
||||||
|
return cluster;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PlotCluster cluster = ClusterManager.getCluster(this);
|
||||||
|
if (cluster != null) {
|
||||||
|
flag = new Flag(FlagManager.getFlag("cluster"), cluster);
|
||||||
|
FlagManager.addPlotFlag(this, flag);
|
||||||
|
return cluster;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the players currently inside this plot
|
* Get the players currently inside this plot
|
||||||
* @return
|
* @return
|
||||||
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
|
@ -27,6 +27,7 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
@ -381,7 +382,7 @@ public class MainUtil {
|
|||||||
public static boolean isPlotArea(final Plot plot) {
|
public static boolean isPlotArea(final Plot plot) {
|
||||||
final PlotWorld plotworld = PS.get().getPlotWorld(plot.world);
|
final PlotWorld plotworld = PS.get().getPlotWorld(plot.world);
|
||||||
if (plotworld.TYPE == 2) {
|
if (plotworld.TYPE == 2) {
|
||||||
return ClusterManager.getCluster(plot) != null;
|
return plot.getCluster() != null;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -609,6 +610,12 @@ public class MainUtil {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of plot ids within a selection
|
||||||
|
* @param pos1
|
||||||
|
* @param pos2
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public static ArrayList<PlotId> getPlotSelectionIds(final PlotId pos1, final PlotId pos2) {
|
public static ArrayList<PlotId> getPlotSelectionIds(final PlotId pos1, final PlotId pos2) {
|
||||||
final ArrayList<PlotId> myplots = new ArrayList<>();
|
final ArrayList<PlotId> myplots = new ArrayList<>();
|
||||||
for (int x = pos1.x; x <= pos2.x; x++) {
|
for (int x = pos1.x; x <= pos2.x; x++) {
|
||||||
@ -619,6 +626,38 @@ public class MainUtil {
|
|||||||
return myplots;
|
return myplots;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a set of owned plots within a selection (chooses the best algorithm based on selection size.<br>
|
||||||
|
* i.e. A selection of billions of plots will work fine
|
||||||
|
* @param pos1
|
||||||
|
* @param pos2
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static HashSet<Plot> getPlotSelectionOwned(String world, final PlotId pos1, final PlotId pos2) {
|
||||||
|
int size = (1 + pos2.x - pos1.x) * (1 + pos2.y - pos1.y);
|
||||||
|
HashSet<Plot> result = new HashSet<>();
|
||||||
|
if (PS.get().isPlotWorld(world)) {
|
||||||
|
if (size < PS.get().getAllPlotsRaw().get(world).size()) {
|
||||||
|
for (PlotId pid : MainUtil.getPlotSelectionIds(pos1, pos2)) {
|
||||||
|
Plot plot = MainUtil.getPlot(world, pid);
|
||||||
|
if (plot.hasOwner()) {
|
||||||
|
if (plot.id.x > pos1.x || plot.id.y > pos1.y || plot.id.x < pos2.x || plot.id.y < pos2.y) {
|
||||||
|
result.add(plot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (Plot plot : PS.get().getPlotsInWorld(world)) {
|
||||||
|
if (plot.id.x > pos1.x || plot.id.y > pos1.y || plot.id.x < pos2.x || plot.id.y < pos2.y) {
|
||||||
|
result.add(plot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Completely merges a set of plots<br> <b>(There are no checks to make sure you supply the correct
|
* Completely merges a set of plots<br> <b>(There are no checks to make sure you supply the correct
|
||||||
* arguments)</b><br> - Misuse of this method can result in unusable plots<br> - the set of plots must belong to one
|
* arguments)</b><br> - Misuse of this method can result in unusable plots<br> - the set of plots must belong to one
|
||||||
@ -1333,7 +1372,7 @@ public class MainUtil {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (Settings.ENABLE_CLUSTERS) {
|
if (Settings.ENABLE_CLUSTERS) {
|
||||||
PlotCluster cluster = ClusterManager.getCluster(plot);
|
PlotCluster cluster = plot.getCluster();
|
||||||
if (cluster != null) {
|
if (cluster != null) {
|
||||||
if (!cluster.isAdded(player.getUUID()) && !Permissions.hasPermission(player, "plots.admin.command.claim")) {
|
if (!cluster.isAdded(player.getUUID()) && !Permissions.hasPermission(player, "plots.admin.command.claim")) {
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user