Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a meta to hold current process of plot merge #4038

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public void blockDestroy(BlockBreakEvent event) {
return;
}
Plot plot = area.getPlot(location);
if (plot != null) {
if (plot != null && !plot.isMerging()) {
BukkitPlayer plotPlayer = BukkitUtil.adapt(player);
// == rather than <= as we only care about the "ground level" not being destroyed
if (event.getBlock().getY() == area.getMinGenHeight()) {
Expand Down
26 changes: 26 additions & 0 deletions Core/src/main/java/com/plotsquared/core/plot/Plot.java
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,32 @@ public int addRunning() {
return value;
}

/**
* Sets the plot into merging process
*/
public void setMerging() {
for (Plot plot : this.getConnectedPlots()) {
plot.setMeta("merging", true);
}
}

/**
* @return the current state of merging process
*/
public Boolean isMerging() {
Boolean value = (Boolean) this.getMeta("merging");
return value != null && value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be enough to just return this.getMeta("merging") != null I guess?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not have a hasMeta ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that Meta-System could use some refactoring either way. A hasMetadata extension would be great, as well updating the backing Map to an EnumMap and have enum constants for each metadata key. I guess that would benefit for maintainability and documentation purposes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be great. Lets coordinate that together I will help you out.

}

/**
* Removes the merging process
*/
public void removeMerging() {
for (Plot plot : this.getConnectedPlots()) {
plot.deleteMeta("merging");
}
}

/**
* Decrement the number of tracked tasks this plot is running<br>
* - Used to track/limit the number of things a player can do on the plot at once
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,8 @@ public boolean autoMerge(
Plot other = current.getRelative(Direction.NORTH);
if (other != null && other.isOwner(uuid) && (other.getBasePlot(false).equals(current.getBasePlot(false))
|| (plots = other.getConnectedPlots()).size() <= max && frontier.addAll(plots) && (max -= plots.size()) != -1)) {
current.setMerging();
other.setMerging();
current.mergePlot(other, removeRoads, queue);
merged.add(current.getId());
merged.add(other.getId());
Expand All @@ -593,12 +595,16 @@ public boolean autoMerge(
ids.add(other.getId());
this.plot.getManager().finishPlotMerge(ids, queue);
}
current.removeMerging();
other.removeMerging();
}
}
if (max >= 0 && (dir == Direction.ALL || dir == Direction.EAST) && !current.isMerged(Direction.EAST)) {
Plot other = current.getRelative(Direction.EAST);
if (other != null && other.isOwner(uuid) && (other.getBasePlot(false).equals(current.getBasePlot(false))
|| (plots = other.getConnectedPlots()).size() <= max && frontier.addAll(plots) && (max -= plots.size()) != -1)) {
current.setMerging();
other.setMerging();
current.mergePlot(other, removeRoads, queue);
merged.add(current.getId());
merged.add(other.getId());
Expand All @@ -610,12 +616,16 @@ public boolean autoMerge(
ids.add(other.getId());
this.plot.getManager().finishPlotMerge(ids, queue);
}
current.removeMerging();
other.removeMerging();
}
}
if (max >= 0 && (dir == Direction.ALL || dir == Direction.SOUTH) && !current.isMerged(Direction.SOUTH)) {
Plot other = current.getRelative(Direction.SOUTH);
if (other != null && other.isOwner(uuid) && (other.getBasePlot(false).equals(current.getBasePlot(false))
|| (plots = other.getConnectedPlots()).size() <= max && frontier.addAll(plots) && (max -= plots.size()) != -1)) {
current.setMerging();
other.setMerging();
current.mergePlot(other, removeRoads, queue);
merged.add(current.getId());
merged.add(other.getId());
Expand All @@ -627,12 +637,16 @@ public boolean autoMerge(
ids.add(other.getId());
this.plot.getManager().finishPlotMerge(ids, queue);
}
current.removeMerging();
other.removeMerging();
}
}
if (max >= 0 && (dir == Direction.ALL || dir == Direction.WEST) && !current.isMerged(Direction.WEST)) {
Plot other = current.getRelative(Direction.WEST);
if (other != null && other.isOwner(uuid) && (other.getBasePlot(false).equals(current.getBasePlot(false))
|| (plots = other.getConnectedPlots()).size() <= max && frontier.addAll(plots) && (max -= plots.size()) != -1)) {
current.setMerging();
other.setMerging();
current.mergePlot(other, removeRoads, queue);
merged.add(current.getId());
merged.add(other.getId());
Expand All @@ -644,6 +658,8 @@ public boolean autoMerge(
ids.add(other.getId());
this.plot.getManager().finishPlotMerge(ids, queue);
}
current.removeMerging();
other.removeMerging();
}
}
}
Expand Down