Added claim restrictions for clusters

This commit is contained in:
boy0001 2015-04-07 23:21:51 +10:00
parent 0c3919b365
commit 214cd1dbf8
6 changed files with 44 additions and 61 deletions

View File

@ -179,7 +179,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 ((current != null) && (current.hasOwner() == false) && (current.settings.isMerged() == false) && cluster.equals(ClusterManager.getCluster(current))) { if (MainUtil.canClaim(plr, current) && (current.settings.isMerged() == false) && cluster.equals(ClusterManager.getCluster(current))) {
Claim.claimPlot(plr, current, true, true); Claim.claimPlot(plr, current, true, true);
return true; return true;
} }
@ -193,7 +193,7 @@ public class Auto extends SubCommand {
if ((size_x == 1) && (size_z == 1)) { if ((size_x == 1) && (size_z == 1)) {
while (!br) { while (!br) {
final Plot plot = MainUtil.getPlot(worldname, getLastPlot(worldname)); final Plot plot = MainUtil.getPlot(worldname, getLastPlot(worldname));
if ((plot.owner == null)) { if (MainUtil.canClaim(plr, plot)) {
Claim.claimPlot(plr, plot, true, true); Claim.claimPlot(plr, plot, true, true);
br = true; br = true;
} }
@ -213,7 +213,7 @@ public class Auto extends SubCommand {
lastPlot = false; lastPlot = false;
} }
final PlotId end = new PlotId((start.x + size_x) - 1, (start.y + size_z) - 1); final PlotId end = new PlotId((start.x + size_x) - 1, (start.y + size_z) - 1);
if (MainUtil.isUnowned(worldname, start, end)) { if (MainUtil.canClaim(plr, worldname, start, end)) {
for (int i = start.x; i <= end.x; i++) { for (int i = start.x; i <= end.x; i++) {
for (int j = start.y; j <= end.y; j++) { for (int j = start.y; j <= end.y; j++) {
final Plot plot = MainUtil.getPlot(worldname, new PlotId(i, j)); final Plot plot = MainUtil.getPlot(worldname, new PlotId(i, j));

View File

@ -93,7 +93,7 @@ public class Claim extends SubCommand {
if (currentPlots >= MainUtil.getAllowedPlots(plr)) { if (currentPlots >= MainUtil.getAllowedPlots(plr)) {
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
} }
if (plot.hasOwner()) { if (!MainUtil.canClaim(plr, plot)) {
return sendMessage(plr, C.PLOT_IS_CLAIMED); return sendMessage(plr, C.PLOT_IS_CLAIMED);
} }
final PlotWorld world = PlotSquared.getPlotWorld(plot.world); final PlotWorld world = PlotSquared.getPlotWorld(plot.world);

View File

@ -129,7 +129,7 @@ public class Cluster extends SubCommand {
// Add any existing plots to the current cluster // Add any existing plots to the current cluster
for (final Plot plot : PlotSquared.getPlots(plr.getLocation().getWorld()).values()) { for (final Plot plot : PlotSquared.getPlots(plr.getLocation().getWorld()).values()) {
final PlotCluster current = ClusterManager.getCluster(plot); final PlotCluster current = ClusterManager.getCluster(plot);
if (cluster.equals(current) && !cluster.hasRights(plot.owner)) { if (cluster.equals(current) && !cluster.isAdded(plot.owner)) {
cluster.invited.add(plot.owner); cluster.invited.add(plot.owner);
DBFunc.setInvited(world, cluster, plot.owner); DBFunc.setInvited(world, cluster, plot.owner);
} }
@ -302,7 +302,7 @@ public class Cluster extends SubCommand {
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[1]); MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[1]);
return false; return false;
} }
if (!cluster.hasRights(uuid)) { if (!cluster.isAdded(uuid)) {
// add the user if not added // add the user if not added
cluster.invited.add(uuid); cluster.invited.add(uuid);
final String world = plr.getLocation().getWorld(); final String world = plr.getLocation().getWorld();
@ -344,7 +344,7 @@ public class Cluster extends SubCommand {
return false; return false;
} }
// Can't kick if the player is yourself, the owner, or not added to the cluster // Can't kick if the player is yourself, the owner, or not added to the cluster
if (uuid.equals(UUIDHandler.getUUID(plr)) || uuid.equals(cluster.owner) || !cluster.hasRights(uuid)) { if (uuid.equals(UUIDHandler.getUUID(plr)) || uuid.equals(cluster.owner) || !cluster.isAdded(uuid)) {
MainUtil.sendMessage(plr, C.CANNOT_KICK_PLAYER, cluster.getName()); MainUtil.sendMessage(plr, C.CANNOT_KICK_PLAYER, cluster.getName());
return false; return false;
} }
@ -393,7 +393,7 @@ public class Cluster extends SubCommand {
} }
} }
final UUID uuid = UUIDHandler.getUUID(plr); final UUID uuid = UUIDHandler.getUUID(plr);
if (!cluster.hasRights(uuid)) { if (!cluster.isAdded(uuid)) {
MainUtil.sendMessage(plr, C.CLUSTER_NOT_ADDED); MainUtil.sendMessage(plr, C.CLUSTER_NOT_ADDED);
return false; return false;
} }
@ -466,7 +466,7 @@ public class Cluster extends SubCommand {
return false; return false;
} }
final UUID uuid = UUIDHandler.getUUID(plr); final UUID uuid = UUIDHandler.getUUID(plr);
if (!cluster.hasRights(uuid)) { if (!cluster.isAdded(uuid)) {
if (!Permissions.hasPermission(plr, "plots.cluster.tp.other")) { if (!Permissions.hasPermission(plr, "plots.cluster.tp.other")) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.tp.other"); MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.tp.other");
return false; return false;
@ -508,7 +508,7 @@ public class Cluster extends SubCommand {
} }
final String name = cluster.getName(); final String name = cluster.getName();
final String size = ((cluster.getP2().x - cluster.getP1().x) + 1) + "x" + ((cluster.getP2().y - cluster.getP1().y) + 1); final String size = ((cluster.getP2().x - cluster.getP1().x) + 1) + "x" + ((cluster.getP2().y - cluster.getP1().y) + 1);
final String rights = cluster.hasRights(UUIDHandler.getUUID(plr)) + ""; final String rights = cluster.isAdded(UUIDHandler.getUUID(plr)) + "";
String message = C.CLUSTER_INFO.s(); String message = C.CLUSTER_INFO.s();
message = message.replaceAll("%id%", id); message = message.replaceAll("%id%", id);
message = message.replaceAll("%owner%", owner); message = message.replaceAll("%owner%", owner);

View File

@ -29,7 +29,7 @@ public class PlotCluster {
public void setP2(final PlotId id) { public void setP2(final PlotId id) {
this.pos2 = id; this.pos2 = id;
} }
public PlotCluster(final String world, final PlotId pos1, final PlotId pos2, final UUID owner) { public PlotCluster(final String world, final PlotId pos1, final PlotId pos2, final UUID owner) {
this.world = world; this.world = world;
this.pos1 = pos1; this.pos1 = pos1;
@ -38,7 +38,7 @@ public class PlotCluster {
this.settings = new PlotSettings(null); this.settings = new PlotSettings(null);
} }
public boolean hasRights(final UUID uuid) { public boolean isAdded(final UUID uuid) {
return (this.owner.equals(uuid) || this.invited.contains(uuid) || this.invited.contains(DBFunc.everyone) || this.helpers.contains(uuid) || this.helpers.contains(DBFunc.everyone)); return (this.owner.equals(uuid) || this.invited.contains(uuid) || this.invited.contains(DBFunc.everyone) || this.helpers.contains(uuid) || this.helpers.contains(DBFunc.everyone));
} }

View File

@ -1,49 +0,0 @@
//package com.intellectualcrafters.plot.object;
//
//import java.util.Collection;
//
//import org.bukkit.Bukkit;
//import org.bukkit.plugin.java.JavaPlugin;
//
//import com.gmail.filoghost.holographicdisplays.api.Hologram;
//import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
//import com.intellectualcrafters.plot.PlotSquared;
//import com.intellectualcrafters.plot.util.PlotHelper;
//
///**
// * Created 2015-02-14 for PlotSquared
// *
// * @author Citymonstret
// */
//public class PlotHologram {
//
// private static JavaPlugin plugin;
// private final PlotId id;
// private final String world;
// private Hologram hologram;
//
// public PlotHologram(final String world, final PlotId id) {
// this.id = id;
// this.world = world;
// this.hologram = createHologram(PlotSquared.getPlotManager(world).getSignLoc(Bukkit.getWorld(world), PlotSquared.getPlotWorld(world), PlotHelper.getPlot(Bukkit.getWorld(world), id)));
// }
//
// public static Hologram createHologram(final org.bukkit.Location location) {
// return HologramsAPI.createHologram(getPlugin(), location);
// }
//
// public static JavaPlugin getPlugin() {
// if (plugin == null) {
// plugin = JavaPlugin.getPlugin(PlotSquared.class);
// }
// return plugin;
// }
//
// public static void removeAll() {
// final Collection<Hologram> holograms = HologramsAPI.getHolograms(getPlugin());
// for (final Hologram h : holograms) {
// h.delete();
// }
// }
//
//}

View File

@ -34,6 +34,7 @@ import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
@ -753,6 +754,37 @@ public class MainUtil {
return manager.getPlotBottomLocAbs(plotworld, id); return manager.getPlotBottomLocAbs(plotworld, id);
} }
public static boolean canClaim(PlotPlayer player, String world, final PlotId pos1, final PlotId pos2) {
for (int x = pos1.x; x <= pos2.x; x++) {
for (int y = pos1.y; y <= pos2.y; y++) {
final PlotId id = new PlotId(x, y);
Plot plot = getPlot(world, id);
if (!canClaim(player, plot)) {
return false;
}
}
}
return true;
}
public static boolean canClaim(PlotPlayer player, Plot plot) {
if (plot == null) {
return false;
}
if (Settings.ENABLE_CLUSTERS) {
PlotCluster cluster = ClusterManager.getCluster(plot);
if (cluster != null) {
if (!cluster.isAdded(player.getUUID()) && !Permissions.hasPermission(player, "plots.admin.command.claim")) {
return false;
}
}
}
if (plot.owner != null) {
return false;
}
return true;
}
public static boolean isUnowned(final String world, final PlotId pos1, final PlotId pos2) { public static boolean isUnowned(final String world, final PlotId pos1, final PlotId pos2) {
for (int x = pos1.x; x <= pos2.x; x++) { for (int x = pos1.x; x <= pos2.x; x++) {
for (int y = pos1.y; y <= pos2.y; y++) { for (int y = pos1.y; y <= pos2.y; y++) {