mirror of
				https://github.com/IntellectualSites/PlotSquared.git
				synced 2025-11-04 03:03:43 +01:00 
			
		
		
		
	Per player plot cluster limits
This commit is contained in:
		@@ -27,6 +27,7 @@ import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
import com.intellectualcrafters.plot.PS;
 | 
			
		||||
import com.intellectualcrafters.plot.config.C;
 | 
			
		||||
import com.intellectualcrafters.plot.config.Settings;
 | 
			
		||||
import com.intellectualcrafters.plot.database.DBFunc;
 | 
			
		||||
import com.intellectualcrafters.plot.flag.Flag;
 | 
			
		||||
import com.intellectualcrafters.plot.flag.FlagManager;
 | 
			
		||||
@@ -142,12 +143,30 @@ public class Cluster extends SubCommand {
 | 
			
		||||
                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;
 | 
			
		||||
                        UUID uuid = plr.getUUID();
 | 
			
		||||
                        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));
 | 
			
		||||
                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);
 | 
			
		||||
                if (plotworld == null) {
 | 
			
		||||
                    PS.get().config.createSection("worlds." + world);
 | 
			
		||||
@@ -316,6 +335,20 @@ public class Cluster extends SubCommand {
 | 
			
		||||
                        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) {
 | 
			
		||||
                    FlagManager.removePlotFlag(plot, "cluster");
 | 
			
		||||
                }
 | 
			
		||||
 
 | 
			
		||||
@@ -49,6 +49,14 @@ public class PlotCluster {
 | 
			
		||||
    public String getName() {
 | 
			
		||||
        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
 | 
			
		||||
    public int hashCode() {
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,7 @@ import java.util.HashMap;
 | 
			
		||||
import java.util.HashSet;
 | 
			
		||||
import java.util.Random;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.Chunk;
 | 
			
		||||
@@ -13,6 +14,7 @@ import org.bukkit.generator.BlockPopulator;
 | 
			
		||||
 | 
			
		||||
import com.intellectualcrafters.plot.PS;
 | 
			
		||||
import com.intellectualcrafters.plot.config.C;
 | 
			
		||||
import com.intellectualcrafters.plot.config.Settings;
 | 
			
		||||
import com.intellectualcrafters.plot.object.BlockLoc;
 | 
			
		||||
import com.intellectualcrafters.plot.object.ChunkLoc;
 | 
			
		||||
import com.intellectualcrafters.plot.object.Location;
 | 
			
		||||
@@ -45,6 +47,25 @@ public class ClusterManager {
 | 
			
		||||
        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) {
 | 
			
		||||
        final BlockLoc home = cluster.settings.getPosition();
 | 
			
		||||
        Location toReturn;
 | 
			
		||||
 
 | 
			
		||||
@@ -449,6 +449,11 @@ public class MainUtil {
 | 
			
		||||
        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) {
 | 
			
		||||
        int count = 0;
 | 
			
		||||
        for (final String world : PS.get().getPlotWorldsString()) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user