[IN PROGRESS] multi-owner mega plots

This commit is contained in:
boy0001 2015-03-20 13:13:27 +11:00
parent 657c1a1d54
commit bdbebfa29d
19 changed files with 283 additions and 100 deletions

View File

@ -52,6 +52,7 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotGenerator;
import com.intellectualcrafters.plot.object.PlotHandler;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
@ -206,7 +207,7 @@ public class PlotSquared {
final ArrayList<Plot> myplots = new ArrayList<>();
for (final Plot plot : getPlots(world).values()) {
if (plot.hasOwner()) {
if (plot.getOwner().equals(uuid)) {
if (PlotHandler.isOwner(plot, uuid)) {
myplots.add(plot);
}
}
@ -247,7 +248,7 @@ public class PlotSquared {
if (isPlotWorld(world)) {
for (final Plot plot : plots.get(world).values()) {
if (plot.hasOwner()) {
if (plot.getOwner().equals(uuid)) {
if (PlotHandler.isOwner(plot, uuid)) {
myplots.add(plot);
}
}

View File

@ -474,7 +474,7 @@ import com.intellectualcrafters.plot.uuid.UUIDWrapper;
final ArrayList<Plot> pPlots = new ArrayList<>();
for (final Plot plot : PlotSquared.getPlots(world.getName()).values()) {
if (just_owner) {
if ((plot.owner != null) && (plot.owner == UUIDHandler.getUUID(BukkitUtil.getPlayer(plr)))) {
if ((plot.owner_ != null) && (plot.owner_ == UUIDHandler.getUUID(BukkitUtil.getPlayer(plr)))) {
pPlots.add(plot);
}
} else {

View File

@ -193,7 +193,7 @@ public class Auto extends SubCommand {
if ((size_x == 1) && (size_z == 1)) {
while (!br) {
final Plot plot = MainUtil.getPlot(worldname, getLastPlot(worldname));
if ((plot.owner == null)) {
if ((plot.owner_ == null)) {
Claim.claimPlot(plr, plot, true, true);
br = true;
}
@ -207,7 +207,7 @@ public class Auto extends SubCommand {
MainUtil.lastPlot.put(worldname, start);
if (lastPlot) {
}
if ((PlotSquared.getPlots(worldname).get(start) != null) && (PlotSquared.getPlots(worldname).get(start).owner != null)) {
if ((PlotSquared.getPlots(worldname).get(start) != null) && (PlotSquared.getPlots(worldname).get(start).owner_ != null)) {
continue;
} else {
lastPlot = false;

View File

@ -27,6 +27,7 @@ import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotHandler;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
@ -74,7 +75,7 @@ public class Buy extends SubCommand {
if (!plot.hasOwner()) {
return sendMessage(plr, C.PLOT_UNOWNED);
}
if (plot.owner.equals(plr.getUUID())) {
if (PlotHandler.isOwner(plot, plr.getUUID())) {
return sendMessage(plr, C.CANNOT_BUY_OWN);
}
final Flag flag = FlagManager.getPlotFlag(plot, "price");
@ -97,15 +98,20 @@ public class Buy extends SubCommand {
}
EconHandler.withdrawPlayer(plr, price);
sendMessage(plr, C.REMOVED_BALANCE, price + "");
EconHandler.depositPlayer(UUIDHandler.uuidWrapper.getOfflinePlayer(plot.owner), initPrice);
final PlotPlayer owner = UUIDHandler.getPlayer(plot.owner);
EconHandler.depositPlayer(UUIDHandler.uuidWrapper.getOfflinePlayer(plot.owner_), initPrice);
final PlotPlayer owner = UUIDHandler.getPlayer(plot.owner_);
if (owner != null) {
sendMessage(plr, C.PLOT_SOLD, plot.id + "", plr.getName(), initPrice + "");
}
FlagManager.removePlotFlag(plot, "price");
}
plot.owner = plr.getUUID();
DBFunc.setOwner(plot, plot.owner);
Plot top = MainUtil.getTopPlot(plot);
for (PlotId myId : MainUtil.getPlotSelectionIds(plot.id, top.id)) {
Plot myPlot = MainUtil.getPlot(plot.world, myId);
myPlot.owner_ = plr.getUUID();
DBFunc.setOwner(plot, myPlot.owner_);
}
MainUtil.sendMessage(plr, C.CLAIMED);
return true;
}

View File

@ -44,7 +44,7 @@ public class Confirm extends SubCommand {
return false;
}
CmdConfirm.removePending(plr);
if (System.currentTimeMillis() - command.timestamp > 10000) {
if (System.currentTimeMillis() - command.timestamp > 20000) {
MainUtil.sendMessage(plr, C.FAILED_CONFIRM);
return false;
}

View File

@ -21,6 +21,8 @@
package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.UUID;
import org.apache.commons.lang.StringUtils;
@ -31,6 +33,7 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.CmdConfirm;
import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil;
@ -105,39 +108,96 @@ public class Merge extends SubCommand {
}
PlotId bot = MainUtil.getBottomPlot(plot).id;
PlotId top = MainUtil.getTopPlot(plot).id;
ArrayList<PlotId> plots;
ArrayList<PlotId> selPlots;
final String world = loc.getWorld();
switch (direction) {
case 0: // north = -y
plots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y));
selPlots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y));
break;
case 1: // east = +x
plots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y));
selPlots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y));
break;
case 2: // south = +y
plots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1));
selPlots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1));
break;
case 3: // west = -x
plots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y));
selPlots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y));
break;
default:
return false;
}
final PlotId botId = plots.get(0);
final PlotId topId = plots.get(plots.size() - 1);
final PlotId botId = selPlots.get(0);
final PlotId topId = selPlots.get(selPlots.size() - 1);
final PlotId bot1 = MainUtil.getBottomPlot(MainUtil.getPlot(world, botId)).id;
final PlotId bot2 = MainUtil.getBottomPlot(MainUtil.getPlot(world, topId)).id;
final PlotId top1 = MainUtil.getTopPlot(MainUtil.getPlot(world, topId)).id;
final PlotId top2 = MainUtil.getTopPlot(MainUtil.getPlot(world, botId)).id;
bot = new PlotId(Math.min(bot1.x, bot2.x), Math.min(bot1.y, bot2.y));
top = new PlotId(Math.max(top1.x, top2.x), Math.max(top1.y, top2.y));
plots = MainUtil.getMaxPlotSelectionIds(world, bot, top);
final ArrayList<PlotId> plots = MainUtil.getMaxPlotSelectionIds(world, bot, top);
boolean multiMerge = false;
final HashSet<UUID> multiUUID = new HashSet<UUID>();
HashSet<PlotId> multiPlots = new HashSet<>();
final UUID u1 = plot.getOwner();
for (final PlotId myid : plots) {
final Plot myplot = PlotSquared.getPlots(world).get(myid);
if ((myplot == null) || !myplot.hasOwner() || !(myplot.getOwner().equals(UUIDHandler.getUUID(plr)) || admin)) {
UUID u2 = myplot.getOwner();
if (myplot == null || u2 == null) {
MainUtil.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString()));
return false;
}
if (u2.equals(u1)) {
continue;
}
PlotPlayer p2 = UUIDHandler.getPlayer(u2);
if (p2 == null) {
MainUtil.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString()));
return false;
}
multiMerge = true;
multiPlots.add(myid);
}
if (multiMerge) {
for (final UUID uuid : multiUUID) {
CmdConfirm.addPending(UUIDHandler.getPlayer(uuid), "merge request", new Runnable() {
@Override
public void run() {
PlotPlayer accepter = UUIDHandler.getPlayer(uuid);
multiUUID.remove(uuid);
if (multiUUID.size() == 0) {
PlotPlayer pp = UUIDHandler.getPlayer(u1);
if (pp == null) {
sendMessage(plr, C.MERGE_NOT_VALID);
return;
}
final PlotWorld plotWorld = PlotSquared.getPlotWorld(world);
if ((PlotSquared.economy != null) && plotWorld.USE_ECONOMY) {
double cost = plotWorld.MERGE_PRICE;
cost = plots.size() * cost;
if (cost > 0d) {
if (EconHandler.getBalance(plr) < cost) {
sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + "");
return;
}
EconHandler.withdrawPlayer(plr, cost);
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
}
}
final boolean result = EventUtil.manager.callMerge(world, plot, plots);
if (!result) {
MainUtil.sendMessage(plr, "&cMerge has been cancelled");
return;
}
MainUtil.sendMessage(plr, C.SUCCESS_MERGE);
MainUtil.mergePlots(world, plots, true);
MainUtil.setSign(UUIDHandler.getName(plot.owner), plot);
MainUtil.update(loc);
}
MainUtil.sendMessage(accepter, C.MERGE_ACCEPTED);
}
});
}
return true;
}
final PlotWorld plotWorld = PlotSquared.getPlotWorld(world);
if ((PlotSquared.economy != null) && plotWorld.USE_ECONOMY) {
@ -157,7 +217,7 @@ public class Merge extends SubCommand {
MainUtil.sendMessage(plr, "&cMerge has been cancelled");
return false;
}
MainUtil.sendMessage(plr, "&cPlots have been merged");
MainUtil.sendMessage(plr, C.SUCCESS_MERGE);
MainUtil.mergePlots(world, plots, true);
MainUtil.setSign(UUIDHandler.getName(plot.owner), plot);
MainUtil.update(loc);

View File

@ -216,6 +216,9 @@ public enum C {
UNLINK_IMPOSSIBLE("$2You can only unlink a mega-plot"),
UNLINK_SUCCESS("$2Successfully unlinked plots."),
NO_MERGE_TO_MEGA("$2Mega plots cannot be merged into. Please merge from the desired mega plot."),
MERGE_NOT_VALID("$2This merge request is no longer valid."),
MERGE_ACCEPTED("$2The merge request has been accepted"),
SUCCESS_MERGE("$2Plots have been merged!"),
/*
* Commands
*/

View File

@ -263,7 +263,7 @@ public class SQLManager implements AbstractDB {
stmt.setInt((i * 4) + 1, plot.id.x);
stmt.setInt((i * 4) + 2, plot.id.y);
try {
stmt.setString((i * 4) + 3, plot.owner.toString());
stmt.setString((i * 4) + 3, plot.owner_.toString());
} catch (final Exception e) {
stmt.setString((i * 4) + 3, DBFunc.everyone.toString());
}
@ -299,7 +299,7 @@ public class SQLManager implements AbstractDB {
stmt.setInt((i * 6) + 2, plot.id.x);
stmt.setInt((i * 6) + 3, plot.id.y);
try {
stmt.setString((i * 6) + 4, plot.owner.toString());
stmt.setString((i * 6) + 4, plot.owner_.toString());
} catch (final Exception e1) {
stmt.setString((i * 6) + 4, DBFunc.everyone.toString());
}
@ -344,7 +344,7 @@ public class SQLManager implements AbstractDB {
stmt = SQLManager.this.connection.prepareStatement(SQLManager.this.CREATE_PLOT);
stmt.setInt(1, plot.id.x);
stmt.setInt(2, plot.id.y);
stmt.setString(3, plot.owner.toString());
stmt.setString(3, plot.owner_.toString());
stmt.setString(4, plot.world);
stmt.executeUpdate();
stmt.close();
@ -366,7 +366,7 @@ public class SQLManager implements AbstractDB {
stmt = SQLManager.this.connection.prepareStatement(SQLManager.this.CREATE_PLOT);
stmt.setInt(1, plot.id.x);
stmt.setInt(2, plot.id.y);
stmt.setString(3, plot.owner.toString());
stmt.setString(3, plot.owner_.toString());
stmt.setString(4, plot.world);
stmt.executeUpdate();
stmt.close();

View File

@ -84,6 +84,7 @@ import com.intellectualcrafters.plot.object.BukkitPlayer;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotHandler;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
@ -124,7 +125,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
}
Location sLoc = BukkitUtil.getLocation(((BlockProjectileSource) shooter).getBlock().getLocation());
Plot sPlot = MainUtil.getPlot(sLoc);
if (sPlot == null || sPlot.owner.equals(plot.owner)) {
if (sPlot == null || !PlotHandler.sameOwners(plot, sPlot)) {
entity.remove();
return;
}

View File

@ -180,7 +180,7 @@ public class PlotListener {
}
if ((booleanFlag(plot, "titles", Settings.TITLES)) && (C.TITLE_ENTERED_PLOT.s().length() > 2)) {
final String sTitleMain = C.TITLE_ENTERED_PLOT.s().replaceAll("%x%", plot.id.x + "").replaceAll("%z%", plot.id.y + "").replaceAll("%world%", plot.world + "");
final String sTitleSub = C.TITLE_ENTERED_PLOT_SUB.s().replaceFirst("%s", getName(plot.owner));
final String sTitleSub = C.TITLE_ENTERED_PLOT_SUB.s().replaceFirst("%s", getName(plot.owner_));
if (AbstractTitle.TITLE_CLASS != null) {
AbstractTitle.TITLE_CLASS.sendTitle(player, sTitleMain, sTitleSub, ChatColor.valueOf(C.TITLE_ENTERED_PLOT_COLOR.s()), ChatColor.valueOf(C.TITLE_ENTERED_PLOT_SUB_COLOR.s()));
}

View File

@ -53,6 +53,7 @@ import com.intellectualcrafters.plot.events.PlayerEnterPlotEvent;
import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotHandler;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
@ -64,7 +65,7 @@ import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
*
* @author Citymonstret
*/
@SuppressWarnings({ "deprecation", "unused" })
@SuppressWarnings({ "deprecation"})
public class PlotPlusListener extends PlotListener implements Listener {
private final static HashMap<String, Interval> feedRunnable = new HashMap<>();
private final static HashMap<String, Interval> healRunnable = new HashMap<>();
@ -214,21 +215,23 @@ public class PlotPlusListener extends PlotListener implements Listener {
event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', C.PREFIX_GREETING.s().replaceAll("%id%", plot.id + "") + FlagManager.getPlotFlag(plot, "greeting").getValueString()));
}
if (booleanFlag(plot, "notify-enter", false)) {
final Player trespasser = event.getPlayer();
final PlotPlayer pt = BukkitUtil.getPlayer(trespasser);
if (Permissions.hasPermission(pt, "plots.flag.notify-enter.bypass")) {
return;
}
if (plot.hasOwner()) {
final PlotPlayer pp = UUIDHandler.getPlayer(plot.getOwner());
if (pp == null) {
return;
}
final Player trespasser = event.getPlayer();
final PlotPlayer pt = BukkitUtil.getPlayer(trespasser);
if (pp.getUUID().equals(pt.getUUID())) {
return;
}
if (Permissions.hasPermission(pt, "plots.flag.notify-enter.bypass")) {
return;
}
if (pp.isOnline()) {
MainUtil.sendMessage(pp, C.NOTIFY_ENTER.s().replace("%player", trespasser.getName()).replace("%plot", plot.getId().toString()));
for (UUID owner : PlotHandler.getOwners(plot)) {
final PlotPlayer pp = UUIDHandler.getPlayer(owner);
if (pp == null) {
return;
}
if (pp.getUUID().equals(pt.getUUID())) {
return;
}
if (pp.isOnline()) {
MainUtil.sendMessage(pp, C.NOTIFY_ENTER.s().replace("%player", trespasser.getName()).replace("%plot", plot.getId().toString()));
}
}
}
}
@ -263,19 +266,21 @@ public class PlotPlusListener extends PlotListener implements Listener {
healRunnable.remove(leaver);
}
if (booleanFlag(plot, "notify-leave", false)) {
if (Permissions.hasPermission(pl, "plots.flag.notify-leave.bypass")) {
return;
}
if (plot.hasOwner()) {
final PlotPlayer pp = UUIDHandler.getPlayer(plot.getOwner());
if (pp == null) {
return;
}
if (pp.getUUID().equals(pl.getUUID())) {
return;
}
if (Permissions.hasPermission(pl, "plots.flag.notify-leave.bypass")) {
return;
}
if (pp.isOnline()) {
MainUtil.sendMessage(pp, C.NOTIFY_LEAVE.s().replace("%player", pl.getName()).replace("%plot", plot.getId().toString()));
for (UUID owner : PlotHandler.getOwners(plot)) {
final PlotPlayer pp = UUIDHandler.getPlayer(owner);
if (pp == null) {
return;
}
if (pp.getUUID().equals(pl.getUUID())) {
return;
}
if (pp.isOnline()) {
MainUtil.sendMessage(pp, C.NOTIFY_LEAVE.s().replace("%player", leaver.getName()).replace("%plot", plot.getId().toString()));
}
}
}
}

View File

@ -24,6 +24,7 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.Material;
@ -45,6 +46,7 @@ import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.events.PlotDeleteEvent;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotHandler;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
@ -75,20 +77,27 @@ public class WorldEditListener implements Listener {
final String world = e.getWorld();
final PlotId id = e.getPlotId();
final Plot plot = PlotSquared.getPlots(world).get(id);
if ((plot == null) || (plot.owner == null)) {
if (plot == null) {
return;
}
final PlotPlayer player = UUIDHandler.getPlayer(plot.owner);
if (player == null) {
HashSet<UUID> members = PlotHandler.getOwners(plot);
if (members == null) {
return;
}
if (!world.equals(player.getLocation().getWorld())) {
return;
members.addAll(plot.helpers);
for (UUID member : members) {
final PlotPlayer player = UUIDHandler.getPlayer(member);
if (player == null) {
continue;
}
if (!world.equals(player.getLocation().getWorld())) {
return;
}
if (Permissions.hasPermission(player, "plots.worldedit.bypass")) {
return;
}
PWE.setNoMask(player);
}
if (Permissions.hasPermission(player, "plots.worldedit.bypass")) {
return;
}
PWE.setNoMask(player);
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)

View File

@ -43,7 +43,7 @@ public class InfoInventory implements InventoryHolder {
}
public String getName(final UUID uuid) {
final String name = UUIDHandler.getName(this.plot.getOwner());
final String name = UUIDHandler.getName(this.plot.owner_);
if (name == null) {
return "unknown";
}
@ -52,7 +52,7 @@ public class InfoInventory implements InventoryHolder {
public InfoInventory build() {
final UUID uuid = UUIDHandler.getUUID(BukkitUtil.getPlayer(this.player));
final ItemStack generalInfo = getItem(Material.EMERALD, "&cPlot Info", "&cID: &6" + this.plot.getId().toString(), "&cOwner: &6" + getName(this.plot.getOwner()), "&cAlias: &6" + this.plot.settings.getAlias(), "&cBiome: &6" + this.plot.settings.getBiome().toString().replaceAll("_", "").toLowerCase(), "&cCan Build: &6" + this.plot.isAdded(uuid), "&cIs Denied: &6" + this.plot.isDenied(uuid));
final ItemStack generalInfo = getItem(Material.EMERALD, "&cPlot Info", "&cID: &6" + this.plot.getId().toString(), "&cOwner: &6" + getName(this.plot.owner_), "&cAlias: &6" + this.plot.settings.getAlias(), "&cBiome: &6" + this.plot.settings.getBiome().toString().replaceAll("_", "").toLowerCase(), "&cCan Build: &6" + this.plot.isAdded(uuid), "&cIs Denied: &6" + this.plot.isDenied(uuid));
final ItemStack helpers = getItem(Material.EMERALD, "&cHelpers", "&cAmount: &6" + this.plot.helpers.size(), "&8Click to view a list of the plot helpers");
final ItemStack trusted = getItem(Material.EMERALD, "&cTrusted", "&cAmount: &6" + this.plot.trusted.size(), "&8Click to view a list of trusted players");
final ItemStack denied = getItem(Material.EMERALD, "&cDenied", "&cAmount: &6" + this.plot.denied.size(), "&8Click to view a list of denied players");

View File

@ -48,7 +48,7 @@ public class Plot implements Cloneable {
/**
* plot owner
*/
public UUID owner;
public UUID owner_;
/**
* Deny Entry
*/
@ -90,8 +90,8 @@ public class Plot implements Cloneable {
public Plot(final PlotId id, final UUID owner, final ArrayList<UUID> helpers, final ArrayList<UUID> denied, final String world) {
this.id = id;
this.settings = new PlotSettings(this);
this.owner = owner;
this.deny_entry = this.owner == null;
this.owner_ = owner;
this.deny_entry = this.owner_ == null;
this.helpers = helpers;
this.denied = denied;
this.trusted = new ArrayList<>();
@ -113,8 +113,8 @@ public class Plot implements Cloneable {
public Plot(final PlotId id, final UUID owner, final ArrayList<UUID> helpers, final ArrayList<UUID> trusted, final ArrayList<UUID> denied, final String alias, final BlockLoc position, final Set<Flag> flags, final String world, final boolean[] merged) {
this.id = id;
this.settings = new PlotSettings(this);
this.owner = owner;
this.deny_entry = this.owner != null;
this.owner_ = owner;
this.deny_entry = this.owner_ != null;
this.trusted = trusted;
this.helpers = helpers;
this.denied = denied;
@ -136,7 +136,7 @@ public class Plot implements Cloneable {
* @return false if there is no owner
*/
public boolean hasOwner() {
return this.owner != null;
return this.owner_ != null;
}
/**
@ -147,7 +147,21 @@ public class Plot implements Cloneable {
* @return true if the player is added as a helper or is the owner
*/
public boolean isAdded(final UUID uuid) {
return ((this.helpers != null) && this.helpers.contains(DBFunc.everyone)) || ((this.helpers != null) && this.helpers.contains(uuid)) || ((this.owner != null) && this.owner.equals(uuid)) || ((this.owner != null) && (this.trusted != null) && (UUIDHandler.getPlayer(this.owner) != null) && (this.trusted.contains(uuid) || this.trusted.contains(DBFunc.everyone)));
if (this.owner_ == null) {
return false;
}
if (this.denied.contains(uuid)) {
return false;
}
if (this.helpers.contains(uuid) || this.helpers.contains(DBFunc.everyone)) {
return true;
}
if (this.trusted.contains(uuid) || this.trusted.contains(DBFunc.everyone)) {
if (PlotHandler.isOnline(this)) {
return true;
}
}
return PlotHandler.isOwner(this, uuid);
}
/**
@ -164,18 +178,18 @@ public class Plot implements Cloneable {
/**
* Get the UUID of the owner
*/
public UUID getOwner() {
return this.owner;
}
// public UUID getOwner() {
// return this.owner_;
// }
/**
* Set the owner
*
* @param uuid
*/
public void setOwner(final UUID uuid) {
this.owner = uuid;
}
// public void setOwner(final UUID uuid) {
// this.owner_ = uuid;
// }
/**
* Get the plot ID
@ -193,7 +207,7 @@ public class Plot implements Cloneable {
public Object clone() throws CloneNotSupportedException {
final Plot p = (Plot) super.clone();
if (!p.equals(this) || (p != this)) {
return new Plot(this.id, this.owner, this.helpers, this.trusted, this.denied, this.settings.getAlias(), this.settings.getPosition(), this.settings.flags, this.world, this.settings.getMerged());
return new Plot(this.id, this.owner_, this.helpers, this.trusted, this.denied, this.settings.getAlias(), this.settings.getPosition(), this.settings.flags, this.world, this.settings.getMerged());
}
return p;
}

View File

@ -0,0 +1,76 @@
package com.intellectualcrafters.plot.object;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.UUID;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
public class PlotHandler {
public static HashSet<UUID> getOwners(Plot plot) {
if (plot.owner_ == null) {
return new HashSet<UUID>();
}
if (plot.settings.isMerged()) {
HashSet<UUID> owners = new HashSet<UUID>();
Plot top = MainUtil.getTopPlot(plot);
ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(plot.id, top.id);
for (PlotId id : ids) {
UUID owner = MainUtil.getPlot(plot.world, id).owner_;
if (owner != null) {
owners.add(owner);
}
}
return owners;
}
return new HashSet<>(Arrays.asList(plot.owner_));
}
public static boolean isOwner(Plot plot, UUID uuid) {
if (plot.owner_ == null) {
return false;
}
if (plot.settings.isMerged()) {
Plot top = MainUtil.getTopPlot(plot);
ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(plot.id, top.id);
for (PlotId id : ids) {
UUID owner = MainUtil.getPlot(plot.world, id).owner_;
if (owner != null && owner.equals(uuid)) {
return true;
}
}
}
return plot.owner_.equals(uuid);
}
public static boolean isOnline(Plot plot) {
if (plot.owner_ == null) {
return false;
}
if (plot.settings.isMerged()) {
Plot top = MainUtil.getTopPlot(plot);
ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(plot.id, top.id);
for (PlotId id : ids) {
UUID owner = MainUtil.getPlot(plot.world, id).owner_;
if (owner != null) {
if (UUIDHandler.getPlayer(owner) != null) {
return true;
}
}
}
return false;
}
return UUIDHandler.getPlayer(plot.owner_) != null;
}
public static boolean sameOwners(Plot plot1, Plot plot2) {
if (plot1.owner_ == null || plot2.owner_ == null) {
return false;
}
HashSet<UUID> owners = getOwners(plot1);
owners.retainAll(getOwners(plot2));
return owners.size() > 0;
}
}

View File

@ -20,6 +20,7 @@ import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.events.PlotDeleteEvent;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotHandler;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
@ -85,13 +86,7 @@ public class ExpireManager {
continue;
}
final Plot plot = plots.iterator().next();
if (plot.owner != null) {
if (UUIDHandler.getPlayer(plot.owner) != null) {
expiredPlots.get(world).remove(plot);
return;
}
}
if (!isExpired(plot.owner)) {
if (!isExpired(plot)) {
expiredPlots.get(world).remove(plot);
return;
}
@ -121,7 +116,7 @@ public class ExpireManager {
PlotSquared.log("&cDeleted expired plot: " + plot.id);
PlotSquared.log("&3 - World: " + plot.world);
if (plot.hasOwner()) {
PlotSquared.log("&3 - Owner: " + UUIDHandler.getName(plot.owner));
PlotSquared.log("&3 - Owner: " + UUIDHandler.getName(plot.owner_));
} else {
PlotSquared.log("&3 - Owner: Unowned");
}
@ -132,6 +127,9 @@ public class ExpireManager {
}
public static boolean isExpired(final UUID uuid) {
if (UUIDHandler.getPlayer(uuid) != null) {
return false;
}
final String name = UUIDHandler.getName(uuid);
if (name != null) {
final OfflinePlayer op = Bukkit.getOfflinePlayer(name);
@ -145,6 +143,15 @@ public class ExpireManager {
}
return false;
}
public static boolean isExpired(Plot plot) {
for (UUID owner : PlotHandler.getOwners(plot)) {
if (!isExpired(owner)) {
return false;
}
}
return true;
}
public static HashMap<Plot, Long> getOldPlots(final String world) {
final Collection<Plot> plots = PlotSquared.getPlots(world).values();
@ -152,7 +159,7 @@ public class ExpireManager {
final HashMap<UUID, Long> remove = new HashMap<>();
final Set<UUID> keep = new HashSet<>();
for (final Plot plot : plots) {
final UUID uuid = plot.owner;
final UUID uuid = plot.owner_;
if ((uuid == null) || remove.containsKey(uuid)) {
Long stamp;
if (uuid == null) {

View File

@ -90,7 +90,7 @@ public class MainUtil {
final UUID uuid = plr.getUUID();
int count = 0;
for (final Plot plot : PlotSquared.getPlots(world).values()) {
if (plot.hasOwner() && plot.owner.equals(uuid) && plot.countsTowardsMax) {
if (plot.hasOwner() && plot.owner_.equals(uuid) && plot.countsTowardsMax) {
count++;
}
}
@ -369,10 +369,10 @@ public class MainUtil {
if (plot == null) {
return;
}
if (plot.owner == null) {
if (plot.owner_ == null) {
return;
}
if (!plot.owner.equals(uuid)) {
if (!plot.owner_.equals(uuid)) {
return;
}
ArrayList<PlotId> plots;
@ -427,7 +427,7 @@ public class MainUtil {
final PlotId id_max = plots.get(plots.size() - 1);
for (final PlotId myid : plots) {
final Plot myplot = PlotSquared.getPlots(world).get(myid);
if ((myplot == null) || !myplot.hasOwner() || !(myplot.getOwner().equals(uuid))) {
if ((myplot == null) || myplot.owner_ == null || !(myplot.owner_.equals(uuid))) {
return false;
}
final PlotId top = getTopPlot(myplot).id;
@ -770,7 +770,7 @@ public class MainUtil {
for (int y = pos1.y; y <= pos2.y; y++) {
final PlotId id = new PlotId(x, y);
if (PlotSquared.getPlots(world).get(id) != null) {
if (PlotSquared.getPlots(world).get(id).owner != null) {
if (PlotSquared.getPlots(world).get(id).owner_ != null) {
return false;
}
}
@ -782,7 +782,7 @@ public class MainUtil {
public static boolean swap(final String world, final PlotId current, final PlotId newPlot, final Runnable whenDone) {
Plot p1 = PlotSquared.getPlots(world).get(current);
Plot p2 = PlotSquared.getPlots(world).get(newPlot);
if (p1==null || p2 == null || p1.owner == null || !p1.owner.equals(p2.owner)) {
if (p1==null || p2 == null || p1.owner_ == null || !p1.owner_.equals(p2.owner_)) {
return false;
}
// Swap blocks
@ -807,7 +807,7 @@ public class MainUtil {
final com.intellectualcrafters.plot.object.Location bot2 = MainUtil.getPlotBottomLoc(world, newPlot);
final Location top = MainUtil.getPlotTopLoc(world, current);
final Plot currentPlot = MainUtil.getPlot(world, current);
if (currentPlot.owner == null) {
if (currentPlot.owner_ == null) {
TaskManager.runTaskLater(whenDone, 1);
return false;
}
@ -845,7 +845,7 @@ public class MainUtil {
final com.intellectualcrafters.plot.object.Location bot2 = MainUtil.getPlotBottomLoc(world, newPlot);
final Location top = MainUtil.getPlotTopLoc(world, current);
final Plot currentPlot = MainUtil.getPlot(world, current);
if (currentPlot.owner == null) {
if (currentPlot.owner_ == null) {
TaskManager.runTaskLater(whenDone, 1);
return false;
}
@ -862,7 +862,7 @@ public class MainUtil {
for (final PlotId id : selection) {
int x = id.x + offset_x;
int y = id.y + offset_y;
Plot plot = createPlotAbs(currentPlot.owner, getPlot(world, new PlotId(x, y)));
Plot plot = createPlotAbs(currentPlot.owner_, getPlot(world, new PlotId(x, y)));
if (currentPlot.settings.flags != null && currentPlot.settings.flags.size() > 0) {
plot.settings.flags = currentPlot.settings.flags;
DBFunc.setFlags(world, plot, currentPlot.settings.flags);

View File

@ -115,12 +115,12 @@ public class BukkitChunkManager extends ChunkManager {
final Location bot = new Location(world, x1, 0, z1);
Plot plot;
plot = MainUtil.getPlot(bot);
if ((plot != null) && (plot.owner != null)) {
if ((plot != null) && (plot.owner_ != null)) {
return plot;
}
final Location top = new Location(world, x2, 0, z2);
plot = MainUtil.getPlot(top);
if ((plot != null) && (plot.owner != null)) {
if ((plot != null) && (plot.owner_ != null)) {
return plot;
}
return null;

View File

@ -26,6 +26,7 @@ import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.BukkitPlayer;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotHandler;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
@ -64,7 +65,7 @@ public class PWE {
if (FlagManager.isPlotFlagTrue(plot, "no-worldedit")) {
return;
}
final boolean r = ((plot.getOwner() != null) && plot.getOwner().equals(p.getUUID())) || plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(p.getUUID());
final boolean r = (PlotHandler.isOwner(plot, p.getUUID())) || plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(p.getUUID());
if (r) {
final String w = l.getWorld();
final Location bloc = MainUtil.getPlotBottomLoc(w, plot.id);