mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 21:26:45 +01:00
Per player plot cluster limits
This commit is contained in:
parent
22997ac089
commit
1e8bdb17f8
@ -27,6 +27,7 @@ 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.config.Settings;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.flag.Flag;
|
import com.intellectualcrafters.plot.flag.Flag;
|
||||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||||
@ -142,12 +143,30 @@ public class Cluster extends SubCommand {
|
|||||||
Set<Plot> plots = MainUtil.getPlotSelectionOwned(world, pos1, pos2);
|
Set<Plot> plots = MainUtil.getPlotSelectionOwned(world, pos1, pos2);
|
||||||
if (plots.size() > 0) {
|
if (plots.size() > 0) {
|
||||||
if (!Permissions.hasPermission(plr, "plots.cluster.create.other")) {
|
if (!Permissions.hasPermission(plr, "plots.cluster.create.other")) {
|
||||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.create.other");
|
UUID uuid = plr.getUUID();
|
||||||
return false;
|
for (Plot plot : plots) {
|
||||||
|
if (!plot.isOwner(uuid)) {
|
||||||
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.create.other");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Set the generator (if applicable)
|
// Check allowed cluster size
|
||||||
final PlotCluster cluster = new PlotCluster(world, pos1, pos2, UUIDHandler.getUUID(plr));
|
final PlotCluster cluster = new PlotCluster(world, pos1, pos2, UUIDHandler.getUUID(plr));
|
||||||
|
int current;
|
||||||
|
if (Settings.GLOBAL_LIMIT) {
|
||||||
|
current = ClusterManager.getPlayerClusterCount(plr);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
current = ClusterManager.getPlayerClusterCount(world, plr);
|
||||||
|
}
|
||||||
|
int allowed = Permissions.hasPermissionRange(plr, "plots.cluster", Settings.MAX_PLOTS);
|
||||||
|
if (current + cluster.getArea() > allowed) {
|
||||||
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster." + (current + cluster.getArea()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Set the generator (if applicable)
|
||||||
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);
|
||||||
@ -316,6 +335,20 @@ public class Cluster extends SubCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Check allowed cluster size
|
||||||
|
int current;
|
||||||
|
if (Settings.GLOBAL_LIMIT) {
|
||||||
|
current = ClusterManager.getPlayerClusterCount(plr);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
current = ClusterManager.getPlayerClusterCount(world, plr);
|
||||||
|
}
|
||||||
|
current -= cluster.getArea() + (1 + pos2.x - pos1.x) * (1 + pos2.y - pos1.y);
|
||||||
|
int allowed = Permissions.hasPermissionRange(plr, "plots.cluster", Settings.MAX_PLOTS);
|
||||||
|
if (current + cluster.getArea() > allowed) {
|
||||||
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster." + (current + cluster.getArea()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
for (Plot plot : removed) {
|
for (Plot plot : removed) {
|
||||||
FlagManager.removePlotFlag(plot, "cluster");
|
FlagManager.removePlotFlag(plot, "cluster");
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,14 @@ public class PlotCluster {
|
|||||||
return this.settings.getAlias();
|
return this.settings.getAlias();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the area (in plots)
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getArea() {
|
||||||
|
return (1 + pos2.x - pos1.x) * (1 + pos2.y - pos1.y);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return this.pos1.hashCode();
|
return this.pos1.hashCode();
|
||||||
|
@ -5,6 +5,7 @@ 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 java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
@ -13,6 +14,7 @@ import org.bukkit.generator.BlockPopulator;
|
|||||||
|
|
||||||
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.config.Settings;
|
||||||
import com.intellectualcrafters.plot.object.BlockLoc;
|
import com.intellectualcrafters.plot.object.BlockLoc;
|
||||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
@ -45,6 +47,25 @@ public class ClusterManager {
|
|||||||
return new HashSet<>();
|
return new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getPlayerClusterCount(String world, PlotPlayer player) {
|
||||||
|
final UUID uuid = player.getUUID();
|
||||||
|
int count = 0;
|
||||||
|
for (PlotCluster cluster : ClusterManager.getClusters(world)) {
|
||||||
|
if (uuid.equals(cluster.owner)) {
|
||||||
|
count += cluster.getArea();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getPlayerClusterCount(final PlotPlayer plr) {
|
||||||
|
int count = 0;
|
||||||
|
for (final String world : PS.get().getPlotWorldsString()) {
|
||||||
|
count += getPlayerClusterCount(world, plr);
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
public static Location getHome(final PlotCluster cluster) {
|
public static Location getHome(final PlotCluster cluster) {
|
||||||
final BlockLoc home = cluster.settings.getPosition();
|
final BlockLoc home = cluster.settings.getPosition();
|
||||||
Location toReturn;
|
Location toReturn;
|
||||||
|
@ -449,6 +449,11 @@ public class MainUtil {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a player's total number of plots that count towards their limit
|
||||||
|
* @param plr
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public static int getPlayerPlotCount(final PlotPlayer plr) {
|
public static int getPlayerPlotCount(final PlotPlayer plr) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (final String world : PS.get().getPlotWorldsString()) {
|
for (final String world : PS.get().getPlotWorldsString()) {
|
||||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user