Potential fix for #1930

This commit is contained in:
MattBDev 2019-08-13 18:06:10 -04:00
parent 9642777750
commit 265f0c6615
5 changed files with 80 additions and 18 deletions

View File

@ -356,8 +356,8 @@ import java.util.Set;
} }
if (PaperLib.getMinecraftVersion() == 13) { if (PaperLib.getMinecraftVersion() == 13) {
block.setType(Material.valueOf("WALL_SIGN"), false); block.setType(Material.valueOf("WALL_SIGN"), false);
} else { } else if (PaperLib.getMinecraftVersion() == 14) {
block.setType(Material.valueOf("OAK_WALL_SIGN"), false); block.setType(Material.OAK_WALL_SIGN, false);
} }
final Directional sign = (Directional) block.getBlockData(); final Directional sign = (Directional) block.getBlockData();
sign.setFacing(facing); sign.setFacing(facing);

View File

@ -5,7 +5,11 @@ import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.*; import com.github.intellectualsites.plotsquared.plot.util.CmdConfirm;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.Permissions;
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
@CommandDeclaration(command = "unlink", aliases = {"u", "unmerge"}, @CommandDeclaration(command = "unlink", aliases = {"u", "unmerge"},
description = "Unlink a mega-plot", usage = "/plot unlink [createroads]", description = "Unlink a mega-plot", usage = "/plot unlink [createroads]",
@ -14,8 +18,8 @@ public class Unlink extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) { @Override public boolean onCommand(final PlotPlayer player, String[] args) {
Location loc = player.getLocation(); Location location = player.getLocation();
final Plot plot = loc.getPlotAbs(); final Plot plot = location.getPlotAbs();
if (plot == null) { if (plot == null) {
return !sendMessage(player, Captions.NOT_IN_PLOT); return !sendMessage(player, Captions.NOT_IN_PLOT);
} }

View File

@ -1,9 +1,9 @@
package com.github.intellectualsites.plotsquared.plot.object; package com.github.intellectualsites.plotsquared.plot.object;
public enum Direction { public enum Direction {
NORTH(0, "north"), EAST(1, "east"), SOUTH(2, "south"), WEST(3, "west"), NORTHEAST(4, ALL(-1, "all"), NORTH(0, "north"), EAST(1, "east"), SOUTH(2, "south"), WEST(3,
"northeast"), SOUTHEAST(5, "southeast"), SOUTHWEST(6, "southwest"), NORTHWEST(7, "west"), NORTHEAST(4, "northeast"), SOUTHEAST(5, "southeast"), SOUTHWEST(6,
"northwest"), "southwest"), NORTHWEST(7, "northwest"),
; ;

View File

@ -1003,7 +1003,7 @@ public class Plot {
} }
PlotManager manager = this.area.getPlotManager(); PlotManager manager = this.area.getPlotManager();
if (this.area.ALLOW_SIGNS) { if (this.area.ALLOW_SIGNS) {
Location loc = manager.getSignLoc(this); Location location = manager.getSignLoc(this);
String id = this.id.x + ";" + this.id.y; String id = this.id.x + ";" + this.id.y;
String[] lines = String[] lines =
new String[] {Captions.OWNER_SIGN_LINE_1.formatted().replaceAll("%id%", id), new String[] {Captions.OWNER_SIGN_LINE_1.formatted().replaceAll("%id%", id),
@ -1013,7 +1013,9 @@ public class Plot {
"%plr%", name), "%plr%", name),
Captions.OWNER_SIGN_LINE_4.formatted().replaceAll("%id%", id).replaceAll( Captions.OWNER_SIGN_LINE_4.formatted().replaceAll("%id%", id).replaceAll(
"%plr%", name)}; "%plr%", name)};
WorldUtil.IMP.setSign(this.getWorldName(), loc.getX(), loc.getY(), loc.getZ(), lines); WorldUtil.IMP
.setSign(this.getWorldName(), location.getX(), location.getY(), location.getZ(),
lines);
} }
} }
@ -2054,6 +2056,44 @@ public class Plot {
} }
} }
/**
* Sets the raw merge data<br>
* - Updates DB<br>
* - Does not modify terrain<br>
* ----------<br>
* 0 = north<br>
* 1 = east<br>
* 2 = south<br>
* 3 = west<br>
* ----------<br>
*
* @param direction
* @param value
*/
public void setMerged(Direction direction, boolean value) {
if (this.getSettings().setMerged(direction.getIndex(), value)) {
if (value) {
Plot other = this.getRelative(direction).getBasePlot(false);
if (!other.equals(this.getBasePlot(false))) {
Plot base = other.id.y < this.id.y
|| other.id.y == this.id.y && other.id.x < this.id.x ? other : this.origin;
this.origin.origin = base;
other.origin = base;
this.origin = base;
connected_cache = null;
}
} else {
if (this.origin != null) {
this.origin.origin = null;
this.origin = null;
}
connected_cache = null;
}
DBFunc.setMerged(this, this.getSettings().getMerged());
regions_cache = null;
}
}
/** /**
* Gets the merged array. * Gets the merged array.
* *
@ -2219,7 +2259,7 @@ public class Plot {
* 3 = west<br> * 3 = west<br>
* @param max The max number of merges to do * @param max The max number of merges to do
* @param uuid The UUID it is allowed to merge with * @param uuid The UUID it is allowed to merge with
* @param removeRoads Whether to remove roads * @param removeRoads whether to remove roads
* @return true if a merge takes place * @return true if a merge takes place
*/ */
public boolean autoMerge(int dir, int max, UUID uuid, boolean removeRoads) { public boolean autoMerge(int dir, int max, UUID uuid, boolean removeRoads) {
@ -2852,7 +2892,7 @@ public class Plot {
} }
/** /**
* Merges 2 plots Removes the road in-between <br>- Assumes plots are directly next to each other <br> - saves to DB * Merges two plots. <br>- Assumes plots are directly next to each other <br> - saves to DB
* *
* @param lesserPlot * @param lesserPlot
* @param removeRoads * @param removeRoads
@ -2868,10 +2908,11 @@ public class Plot {
if (!lesserPlot.getMerged(Direction.SOUTH)) { if (!lesserPlot.getMerged(Direction.SOUTH)) {
lesserPlot.clearRatings(); lesserPlot.clearRatings();
greaterPlot.clearRatings(); greaterPlot.clearRatings();
lesserPlot.setMerged(2, true); lesserPlot.setMerged(Direction.SOUTH, true);
greaterPlot.setMerged(0, true); greaterPlot.setMerged(Direction.NORTH, true);
lesserPlot.mergeData(greaterPlot); lesserPlot.mergeData(greaterPlot);
if (removeRoads) { if (removeRoads) {
lesserPlot.removeSign();
lesserPlot.removeRoadSouth(); lesserPlot.removeRoadSouth();
Plot diagonal = greaterPlot.getRelative(Direction.EAST); Plot diagonal = greaterPlot.getRelative(Direction.EAST);
if (diagonal.getMerged(Direction.NORTHWEST)) { if (diagonal.getMerged(Direction.NORTHWEST)) {
@ -2892,10 +2933,11 @@ public class Plot {
if (!lesserPlot.getMerged(Direction.EAST)) { if (!lesserPlot.getMerged(Direction.EAST)) {
lesserPlot.clearRatings(); lesserPlot.clearRatings();
greaterPlot.clearRatings(); greaterPlot.clearRatings();
lesserPlot.setMerged(1, true); lesserPlot.setMerged(Direction.EAST, true);
greaterPlot.setMerged(3, true); greaterPlot.setMerged(Direction.WEST, true);
lesserPlot.mergeData(greaterPlot); lesserPlot.mergeData(greaterPlot);
if (removeRoads) { if (removeRoads) {
lesserPlot.removeSign();
Plot diagonal = greaterPlot.getRelative(Direction.SOUTH); Plot diagonal = greaterPlot.getRelative(Direction.SOUTH);
if (diagonal.getMerged(Direction.NORTHWEST)) { if (diagonal.getMerged(Direction.NORTHWEST)) {
lesserPlot.removeRoadSouthEast(); lesserPlot.removeRoadSouthEast();

View File

@ -5,7 +5,12 @@ import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.object.comment.PlotComment; import com.github.intellectualsites.plotsquared.plot.object.comment.PlotComment;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.util.*; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/** /**
* Generic settings class. * Generic settings class.
@ -80,6 +85,17 @@ public class PlotSettings {
return false; return false;
} }
public boolean setMerged(Direction direction, boolean merged) {
if (Direction.ALL == direction) {
throw new IllegalArgumentException("You cannot use Direction.ALL in this method!");
}
if (this.merged[direction.getIndex()] != merged) {
this.merged[direction.getIndex()] = merged;
return true;
}
return false;
}
public BlockLoc getPosition() { public BlockLoc getPosition() {
if (this.position == null) { if (this.position == null) {
return new BlockLoc(0, 0, 0); return new BlockLoc(0, 0, 0);