Finalize Plot.java

This commit is contained in:
Alexander Söderberg 2020-02-18 14:39:51 +01:00
parent 5fb8530d0e
commit 7f42cbb67f
2 changed files with 19 additions and 12 deletions

View File

@ -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 * Get a collection of all recognized plot flags. Will by
* default use the values contained in {@link GlobalFlagContainer}. * default use the values contained in {@link GlobalFlagContainer}.

View File

@ -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.Configuration;
import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.database.DBFunc; 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.FlagContainer;
import com.github.intellectualsites.plotsquared.plot.flags.GlobalFlagContainer; import com.github.intellectualsites.plotsquared.plot.flags.GlobalFlagContainer;
import com.github.intellectualsites.plotsquared.plot.flags.InternalFlag; 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)<br> * Session only plot metadata (session is until the server stops)<br>
* <br> * <br>
* For persistent metadata use the flag system * For persistent metadata use the flag system
*
* @see FlagManager
*/ */
private ConcurrentHashMap<String, Object> meta; private ConcurrentHashMap<String, Object> meta;
@ -291,7 +288,6 @@ public class Plot {
* *
* @param key metadata key * @param key metadata key
* @param value metadata value * @param value metadata value
* @see FlagManager
*/ */
public void setMeta(String key, Object value) { public void setMeta(String key, Object value) {
if (this.meta == null) { if (this.meta == null) {
@ -1095,12 +1091,12 @@ public class Plot {
* @param flag Flag to set * @param flag Flag to set
*/ */
public <V> boolean setFlag(PlotFlag<V, ?> flag) { public <V> boolean setFlag(PlotFlag<V, ?> flag) {
if (flag instanceof KeepFlag && ExpireManager.IMP != null) {
ExpireManager.IMP.updateExpired(this);
}
if (!EventUtil.manager.callFlagAdd(flag, origin)) { if (!EventUtil.manager.callFlagAdd(flag, origin)) {
return false; return false;
} }
if (flag instanceof KeepFlag && ExpireManager.IMP != null) {
ExpireManager.IMP.updateExpired(this);
}
for (final Plot plot : this.getConnectedPlots()) { for (final Plot plot : this.getConnectedPlots()) {
plot.getFlagContainer().addFlag(flag); plot.getFlagContainer().addFlag(flag);
plot.reEnter(); plot.reEnter();
@ -1134,7 +1130,7 @@ public class Plot {
} }
final Map<Class<?>, PlotFlag<?, ?>> flags = new HashMap<>(); final Map<Class<?>, PlotFlag<?, ?>> flags = new HashMap<>();
if (getArea() != null && !getArea().getFlagContainer().getFlagMap().isEmpty()) { if (getArea() != null && !getArea().getFlagContainer().getFlagMap().isEmpty()) {
final Map<Class<?>, PlotFlag<?, ?>> flagMap = plot.getArea().getFlagContainer().getFlagMap(); final Map<Class<?>, PlotFlag<?, ?>> flagMap = getArea().getFlagContainer().getFlagMap();
flags.putAll(flagMap); flags.putAll(flagMap);
} }
final Map<Class<?>, PlotFlag<?, ?>> flagMap = getFlagContainer().getFlagMap(); final Map<Class<?>, PlotFlag<?, ?>> flagMap = getFlagContainer().getFlagMap();
@ -1158,6 +1154,9 @@ public class Plot {
* @return success * @return success
*/ */
public boolean removeFlag(PlotFlag<?, ?> flag) { public boolean removeFlag(PlotFlag<?, ?> flag) {
if (flag == null) {
return false;
}
boolean removed = false; boolean removed = false;
for (final Plot plot : origin.getConnectedPlots()) { for (final Plot plot : origin.getConnectedPlots()) {
final Object value = plot.getFlagContainer().removeFlag(flag); final Object value = plot.getFlagContainer().removeFlag(flag);
@ -3146,9 +3145,10 @@ public class Plot {
for (Plot plot : plots) { for (Plot plot : plots) {
Plot other = plot.getRelative(destination.getArea(), offset.x, offset.y); Plot other = plot.getRelative(destination.getArea(), offset.x, offset.y);
other.create(plot.getOwner(), false); other.create(plot.getOwner(), false);
if (!plot.getFlags().isEmpty()) { if (!plot.getFlagContainer().getFlagMap().isEmpty()) {
other.getSettings().flags = plot.getFlags(); other.getFlagContainer().clearLocal();
DBFunc.setFlags(other, plot.getFlags()); other.getFlagContainer().addAll(plot.getFlagContainer().getFlagMap().values());
DBFunc.setFlags(other, plot.getFlagContainer().getFlagMap().values());
} }
if (plot.isMerged()) { if (plot.isMerged()) {
other.setMerged(plot.getMerged()); other.setMerged(plot.getMerged());
@ -3178,7 +3178,7 @@ public class Plot {
@Override public void run() { @Override public void run() {
if (regions.isEmpty()) { if (regions.isEmpty()) {
for (Plot current : getConnectedPlots()) { for (Plot current : getConnectedPlots()) {
destination.getManager().claimPlot(destination); destination.getManager().claimPlot(current);
} }
destination.setSign(); destination.setSign();
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);