This commit is contained in:
Jesse Boyd 2016-09-25 18:42:05 +10:00
parent 04c011164a
commit 3b4490c1c6
4 changed files with 51 additions and 3 deletions

View File

@ -15,7 +15,6 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
@ -87,6 +86,10 @@ public class Cluster extends SubCommand {
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot cluster create <name> <id-bot> <id-top>");
return false;
}
int currentClusters = Settings.Limit.GLOBAL ? player.getClusterCount() : player.getPlotCount(player.getLocation().getWorld());
if (currentClusters >= player.getAllowedPlots()) {
return sendMessage(player, C.CANT_CLAIM_MORE_CLUSTERS);
}
// check pos1 / pos2
PlotId pos1 = PlotId.fromString(args[2]);
PlotId pos2 = PlotId.fromString(args[3]);
@ -132,9 +135,9 @@ public class Cluster extends SubCommand {
} else {
current = player.getPlayerClusterCount(player.getLocation().getWorld());
}
int allowed = Permissions.hasPermissionRange(player, "plots.cluster", Settings.Limit.MAX_PLOTS);
int allowed = Permissions.hasPermissionRange(player, "plots.cluster.size", Settings.Limit.MAX_PLOTS);
if (current + cluster.getArea() > allowed) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.cluster." + (current + cluster.getArea()));
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.cluster.size." + (current + cluster.getArea()));
return false;
}
// create cluster

View File

@ -332,6 +332,7 @@ public enum C {
NO_PERMISSION_EVENT("$2You are lacking the permission node: $1%s", "Permission"),
NO_PLOT_PERMS("$2You must be the plot owner to perform this action", "Permission"),
CANT_CLAIM_MORE_PLOTS("$2You can't claim more plots.", "Permission"),
CANT_CLAIM_MORE_CLUSTERS("$2You can't claim more clusters.", "Permission"),
CANT_TRANSFER_MORE_PLOTS("$2You can't send more plots to that user", "Permission"),
CANT_CLAIM_MORE_PLOTS_NUM("$2You can't claim more than $1%s $2plots at once", "Permission"),
YOU_BE_DENIED("$2You are not allowed to enter this plot", "Permission"),

View File

@ -63,6 +63,10 @@ public class PlotCluster {
return this.region;
}
public boolean isOwner(UUID uuid) {
return uuid.equals(owner);
}
public boolean isAdded(UUID uuid) {
return this.owner.equals(uuid) || this.invited.contains(uuid) || this.invited.contains(DBFunc.everyone) || this.helpers.contains(uuid)
|| this.helpers

View File

@ -132,6 +132,14 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
return Permissions.hasPermissionRange(this, "plots.plot", Settings.Limit.MAX_PLOTS);
}
/**
* Get the total number of allowed clusters
* @return number of allowed clusters within the scope (globally, or in the player's current world as defined in the settings.yml)
*/
public int getAllowedClusters() {
return Permissions.hasPermissionRange(this, "plots.cluster", Settings.Limit.MAX_PLOTS);
}
/**
* Get the number of plots this player owns.
*
@ -163,6 +171,25 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
return count.get();
}
public int getClusterCount() {
if (!Settings.Limit.GLOBAL) {
return getClusterCount(getLocation().getWorld());
}
final AtomicInteger count = new AtomicInteger(0);
final UUID uuid = getUUID();
PS.get().foreachPlotArea(new RunnableVal<PlotArea>() {
@Override
public void run(PlotArea value) {
for (PlotCluster cluster : value.getClusters()) {
if (cluster.isOwner(getUUID())) {
count.incrementAndGet();
}
}
}
});
return count.get();
}
/**
* Get the number of plots this player owns in the world.
* @param world the name of the plotworld to check.
@ -185,6 +212,19 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
return count;
}
public int getClusterCount(String world) {
UUID uuid = getUUID();
int count = 0;
for (PlotArea area : PS.get().getPlotAreas(world)) {
for (PlotCluster cluster : area.getClusters()) {
if (cluster.isOwner(getUUID())) {
count++;
}
}
}
return count;
}
/**
* Get a {@code Set} of plots owned by this player.
* @see PS for more searching functions