Fix #879 stackoverflow in PlotHandler (from
fde845e1d8)
Fix getCorners returning last value twice
Fix getConnectedPlots only returning adjacent connections (from
c83378a91b)
other tweaks
This commit is contained in:
Jesse Boyd 2016-02-17 14:46:15 +11:00
parent 3b58e19b25
commit af9f5b5f44
8 changed files with 706 additions and 800 deletions

View File

@ -57,7 +57,6 @@ import com.intellectualcrafters.plot.object.PlotAnalysis;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotFilter;
import com.intellectualcrafters.plot.object.PlotHandler;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
@ -1204,7 +1203,7 @@ public class PS {
final ArrayList<Plot> myplots = new ArrayList<>();
for (final Plot plot : getPlots(world)) {
if (plot.hasOwner()) {
if (PlotHandler.isOwner(plot, uuid)) {
if (plot.isOwnerAbs(uuid)) {
myplots.add(plot);
}
}
@ -1222,7 +1221,7 @@ public class PS {
final ArrayList<Plot> myplots = new ArrayList<>();
for (final Plot plot : getPlots(area)) {
if (plot.hasOwner()) {
if (PlotHandler.isOwner(plot, uuid)) {
if (plot.isOwnerAbs(uuid)) {
myplots.add(plot);
}
}
@ -1301,7 +1300,7 @@ public class PS {
foreachPlot(new RunnableVal<Plot>() {
@Override
public void run(Plot value) {
if (PlotHandler.isOwner(value, uuid)) {
if (value.isOwnerAbs(uuid)) {
myplots.add(value);
}
}
@ -1319,7 +1318,7 @@ public class PS {
foreachPlot(new RunnableVal<Plot>() {
@Override
public void run(Plot value) {
if (value.isOwner(uuid)) {
if (value.isOwnerAbs(uuid)) {
myplots.add(value);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,245 +1,15 @@
package com.intellectualcrafters.plot.object;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.util.UUIDHandler;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
public class PlotHandler {
public static HashSet<UUID> getOwners(final Plot plot) {
if (plot.owner == null) {
return new HashSet<UUID>();
}
if (plot.isMerged()) {
HashSet<Plot> plots = plot.getConnectedPlots();
final HashSet<UUID> owners = new HashSet<UUID>(2);
UUID last = plot.owner;
owners.add(plot.owner);
for (Plot current : plots) {
if (last == null || current.owner.getMostSignificantBits() != last.getMostSignificantBits()) {
owners.add(current.owner);
last = current.owner;
}
}
return owners;
}
return new HashSet<>(Collections.singletonList(plot.owner));
}
public static boolean isOwner(final Plot plot, final UUID uuid) {
if (plot.owner == null) {
return false;
}
if (plot.owner.equals(uuid)) {
return true;
}
if (!plot.isMerged()) {
return false;
}
HashSet<Plot> connected = plot.getConnectedPlots();
for (Plot aConnected : connected) {
if (aConnected.isOwner(uuid)) {
return true;
}
}
return false;
}
public static boolean isOnline(final Plot plot) {
if (plot.owner == null) {
return false;
}
if (!plot.isMerged()) {
return UUIDHandler.getPlayer(plot.owner) != null;
}
for (Plot current : plot.getConnectedPlots()) {
if (current.hasOwner() && UUIDHandler.getPlayer(current.owner) != null) {
return true;
}
}
return false;
}
public static void setOwner(Plot plot, UUID owner) {
if (!plot.hasOwner()) {
plot.owner = owner;
plot.create();
return;
}
if (!plot.isMerged()) {
if (!plot.owner.equals(owner)) {
plot.owner = owner;
DBFunc.setOwner(plot, owner);
}
return;
}
for (Plot current : plot.getConnectedPlots()) {
if (!owner.equals(current.owner)) {
current.owner = owner;
DBFunc.setOwner(current, owner);
}
}
}
public static boolean sameOwners(final Plot plot1, final Plot plot2) {
if ((plot1.owner == null) || (plot2.owner == null)) {
return false;
}
final HashSet<UUID> owners = getOwners(plot1);
owners.retainAll(getOwners(plot2));
final HashSet<UUID> owners = plot1.getOwners();
owners.retainAll(plot2.getOwners());
return !owners.isEmpty();
}
public static boolean isAdded(final Plot plot, final UUID uuid) {
if (plot.owner == null) {
return false;
}
if (plot.getDenied().contains(uuid)) {
return false;
}
if (plot.getTrusted().contains(uuid) || plot.getTrusted().contains(DBFunc.everyone)) {
return true;
}
if (isOwner(plot, uuid)) {
return true;
}
if (plot.getMembers().contains(uuid) || plot.getMembers().contains(DBFunc.everyone)) {
if (PlotHandler.isOnline(plot)) {
return true;
}
}
return false;
}
public static void setDenied(Plot plot, Set<UUID> uuids) {
boolean larger = uuids.size() > plot.getDenied().size();
HashSet<UUID> intersection = new HashSet<>(larger ? plot.getDenied() : uuids);
intersection.retainAll(larger ? uuids : plot.getDenied());
uuids.removeAll(intersection);
HashSet<UUID> toRemove = new HashSet<>(plot.getDenied());
toRemove.removeAll(intersection);
for (UUID uuid : toRemove) {
plot.removeDenied(uuid);
}
for (UUID uuid : uuids) {
plot.addDenied(uuid);
}
}
public static void setTrusted(Plot plot, Set<UUID> uuids) {
boolean larger = uuids.size() > plot.getTrusted().size();
HashSet<UUID> intersection = new HashSet<>(larger ? plot.getTrusted() : uuids);
intersection.retainAll(larger ? uuids : plot.getTrusted());
uuids.removeAll(intersection);
HashSet<UUID> toRemove = new HashSet<>(plot.getTrusted());
toRemove.removeAll(intersection);
for (UUID uuid : toRemove) {
plot.removeTrusted(uuid);
}
for (UUID uuid : uuids) {
plot.addTrusted(uuid);
}
}
public static void setMembers(Plot plot, Set<UUID> uuids) {
boolean larger = uuids.size() > plot.getMembers().size();
HashSet<UUID> intersection = new HashSet<>(larger ? plot.getMembers() : uuids);
intersection.retainAll(larger ? uuids : plot.getMembers());
uuids.removeAll(intersection);
HashSet<UUID> toRemove = new HashSet<>(plot.getMembers());
toRemove.removeAll(intersection);
for (UUID uuid : toRemove) {
plot.removeMember(uuid);
}
for (UUID uuid : uuids) {
plot.addMember(uuid);
}
}
public static void set(Plot plot, Set<UUID> uuids) {
boolean larger = uuids.size() > plot.getDenied().size();
HashSet<UUID> intersection = new HashSet<>(larger ? plot.getDenied() : uuids);
intersection.retainAll(larger ? uuids : plot.getDenied());
uuids.removeAll(intersection);
HashSet<UUID> toRemove = new HashSet<>(plot.getDenied());
toRemove.removeAll(intersection);
for (UUID uuid : toRemove) {
plot.removeDenied(uuid);
}
for (UUID uuid : uuids) {
plot.addDenied(uuid);
}
}
public static void addDenied(Plot plot, UUID uuid) {
for (Plot current : plot.getConnectedPlots()) {
if (current.getDenied().add(uuid)) {
DBFunc.setDenied(current, uuid);
}
}
}
public static void addMember(Plot plot, UUID uuid) {
for (Plot current : plot.getConnectedPlots()) {
if (current.getMembers().add(uuid)) {
DBFunc.setMember(current, uuid);
}
}
}
public static void addTrusted(Plot plot, UUID uuid) {
for (Plot current : plot.getConnectedPlots()) {
if (current.getTrusted().add(uuid)) {
DBFunc.setTrusted(current, uuid);
}
}
}
public static boolean removeDenied(Plot plot, UUID uuid) {
for (Plot current : plot.getConnectedPlots()) {
if (current.getDenied().remove(uuid)) {
DBFunc.removeDenied(current, uuid);
} else {
return false;
}
}
return true;
}
public static boolean removeMember(Plot plot, UUID uuid) {
for (Plot current : plot.getConnectedPlots()) {
if (current.getMembers().remove(uuid)) {
DBFunc.removeMember(current, uuid);
} else {
return false;
}
}
return true;
}
public static boolean removeTrusted(Plot plot, UUID uuid) {
for (Plot current : plot.getConnectedPlots()) {
if (current.getTrusted().remove(uuid)) {
DBFunc.removeTrusted(current, uuid);
} else {
return false;
}
}
return true;
}
public static boolean unclaim(Plot plot) {
if (plot.owner == null) {
return false;
}
for (Plot current : plot.getConnectedPlots()) {
plot.getArea().removePlot(plot.getId());
DBFunc.delete(current);
current.settings = null;
}
return true;
}
}

View File

@ -5,7 +5,6 @@ import java.util.List;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotHandler;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.Permissions;
@ -18,7 +17,8 @@ public class InboxOwner extends CommentInbox {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.read." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.read."
return (Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (plot.isOwner(player.getUUID()) || Permissions
.hasPermission(player, "plots.inbox.read."
+ toString()
+ ".other")));
}
@ -28,7 +28,7 @@ public class InboxOwner extends CommentInbox {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.write." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.write."
return (Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.write."
+ toString()
+ ".other")));
}
@ -38,7 +38,7 @@ public class InboxOwner extends CommentInbox {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.modify." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify."
return (Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify."
+ toString()
+ ".other")));
}

View File

@ -5,7 +5,6 @@ import java.util.List;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotHandler;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.Permissions;
@ -18,7 +17,8 @@ public class InboxPublic extends CommentInbox {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.read." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.read."
return (Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (plot.isOwner(player.getUUID()) || Permissions
.hasPermission(player, "plots.inbox.read."
+ toString()
+ ".other")));
}
@ -28,7 +28,7 @@ public class InboxPublic extends CommentInbox {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.write." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.write."
return (Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.write."
+ toString()
+ ".other")));
}
@ -38,7 +38,7 @@ public class InboxPublic extends CommentInbox {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.modify." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify."
return (Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify."
+ toString()
+ ".other")));
}

View File

@ -17,7 +17,7 @@ public class InboxReport extends CommentInbox {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.read." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.read."
return (Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.read."
+ toString()
+ ".other")));
}
@ -27,7 +27,7 @@ public class InboxReport extends CommentInbox {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.write." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.write."
return (Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.write."
+ toString()
+ ".other")));
}
@ -37,7 +37,7 @@ public class InboxReport extends CommentInbox {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.modify." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify."
return (Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify."
+ toString()
+ ".other")));
}

View File

@ -1,5 +1,11 @@
package com.intellectualcrafters.plot.util;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
@ -10,16 +16,9 @@ import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotAnalysis;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotHandler;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class ExpireManager {
public static ConcurrentHashMap<String, List<Plot>> expiredPlots = new ConcurrentHashMap<>();
public static ConcurrentHashMap<String, Boolean> updatingPlots = new ConcurrentHashMap<>();
@ -196,7 +195,7 @@ public class ExpireManager {
}
public static boolean isExpired(final Plot plot) {
for (final UUID owner : PlotHandler.getOwners(plot)) {
for (final UUID owner : plot.getOwners()) {
if (!isExpired(owner)) {
return false;
}

View File

@ -20,6 +20,10 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.plotsquared.listener;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.Flag;
@ -27,7 +31,6 @@ import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotHandler;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.AbstractTitle;
@ -41,10 +44,6 @@ import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
@ -90,7 +89,7 @@ public class PlotListener {
final Flag enter = flags.get("notify-enter");
if ((enter != null) && ((Boolean) enter.getValue())) {
if (!Permissions.hasPermission(pp, "plots.flag.notify-enter.bypass")) {
for (final UUID uuid : PlotHandler.getOwners(plot)) {
for (final UUID uuid : plot.getOwners()) {
final PlotPlayer owner = UUIDHandler.getPlayer(uuid);
if ((owner != null) && !owner.getUUID().equals(pp.getUUID())) {
MainUtil.sendMessage(owner, C.NOTIFY_ENTER.s().replace("%player", pp.getName()).replace("%plot", plot.getId().toString()));
@ -214,7 +213,7 @@ public class PlotListener {
final Flag leave = FlagManager.getPlotFlagRaw(plot, "notify-leave");
if ((leave != null) && ((Boolean) leave.getValue())) {
if (!Permissions.hasPermission(pp, "plots.flag.notify-enter.bypass")) {
for (final UUID uuid : PlotHandler.getOwners(plot)) {
for (final UUID uuid : plot.getOwners()) {
final PlotPlayer owner = UUIDHandler.getPlayer(uuid);
if ((owner != null) && !owner.getUUID().equals(pp.getUUID())) {
MainUtil.sendMessage(pp, C.NOTIFY_LEAVE.s().replace("%player", pp.getName()).replace("%plot", plot.getId().toString()));