From 7f42cbb67f40d2e8b6fed34ef9968c4ca7244a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Tue, 18 Feb 2020 14:39:51 +0100 Subject: [PATCH] Finalize Plot.java --- .../plotsquared/plot/flags/FlagContainer.java | 7 ++++++ .../plotsquared/plot/object/Plot.java | 24 +++++++++---------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/FlagContainer.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/FlagContainer.java index 97fd2b78f..3773a27be 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/FlagContainer.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/FlagContainer.java @@ -96,6 +96,13 @@ import java.util.Map; } } + /** + * Clears the local flag map + */ + public void clearLocal() { + this.flagMap.clear(); + } + /** * Get a collection of all recognized plot flags. Will by * default use the values contained in {@link GlobalFlagContainer}. diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java index 0935ae3c3..20d0af40e 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java @@ -5,7 +5,6 @@ import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Configuration; import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.database.DBFunc; -import com.github.intellectualsites.plotsquared.plot.flag.FlagManager; import com.github.intellectualsites.plotsquared.plot.flags.FlagContainer; import com.github.intellectualsites.plotsquared.plot.flags.GlobalFlagContainer; import com.github.intellectualsites.plotsquared.plot.flags.InternalFlag; @@ -142,8 +141,6 @@ public class Plot { * Session only plot metadata (session is until the server stops)
*
* For persistent metadata use the flag system - * - * @see FlagManager */ private ConcurrentHashMap meta; @@ -291,7 +288,6 @@ public class Plot { * * @param key metadata key * @param value metadata value - * @see FlagManager */ public void setMeta(String key, Object value) { if (this.meta == null) { @@ -1095,12 +1091,12 @@ public class Plot { * @param flag Flag to set */ public boolean setFlag(PlotFlag flag) { - if (flag instanceof KeepFlag && ExpireManager.IMP != null) { - ExpireManager.IMP.updateExpired(this); - } if (!EventUtil.manager.callFlagAdd(flag, origin)) { return false; } + if (flag instanceof KeepFlag && ExpireManager.IMP != null) { + ExpireManager.IMP.updateExpired(this); + } for (final Plot plot : this.getConnectedPlots()) { plot.getFlagContainer().addFlag(flag); plot.reEnter(); @@ -1134,7 +1130,7 @@ public class Plot { } final Map, PlotFlag> flags = new HashMap<>(); if (getArea() != null && !getArea().getFlagContainer().getFlagMap().isEmpty()) { - final Map, PlotFlag> flagMap = plot.getArea().getFlagContainer().getFlagMap(); + final Map, PlotFlag> flagMap = getArea().getFlagContainer().getFlagMap(); flags.putAll(flagMap); } final Map, PlotFlag> flagMap = getFlagContainer().getFlagMap(); @@ -1158,6 +1154,9 @@ public class Plot { * @return success */ public boolean removeFlag(PlotFlag flag) { + if (flag == null) { + return false; + } boolean removed = false; for (final Plot plot : origin.getConnectedPlots()) { final Object value = plot.getFlagContainer().removeFlag(flag); @@ -3146,9 +3145,10 @@ public class Plot { for (Plot plot : plots) { Plot other = plot.getRelative(destination.getArea(), offset.x, offset.y); other.create(plot.getOwner(), false); - if (!plot.getFlags().isEmpty()) { - other.getSettings().flags = plot.getFlags(); - DBFunc.setFlags(other, plot.getFlags()); + if (!plot.getFlagContainer().getFlagMap().isEmpty()) { + other.getFlagContainer().clearLocal(); + other.getFlagContainer().addAll(plot.getFlagContainer().getFlagMap().values()); + DBFunc.setFlags(other, plot.getFlagContainer().getFlagMap().values()); } if (plot.isMerged()) { other.setMerged(plot.getMerged()); @@ -3178,7 +3178,7 @@ public class Plot { @Override public void run() { if (regions.isEmpty()) { for (Plot current : getConnectedPlots()) { - destination.getManager().claimPlot(destination); + destination.getManager().claimPlot(current); } destination.setSign(); TaskManager.runTask(whenDone);