Fix singleworlds

This commit is contained in:
dordsor21
2021-01-07 21:24:38 +00:00
committed by Alexander Söderberg
parent 7ac3f7ca03
commit 3cea734b9b
13 changed files with 71 additions and 34 deletions

View File

@ -37,6 +37,8 @@ import com.plotsquared.core.player.PlayerMetaDataKeys;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.world.SinglePlot;
import com.plotsquared.core.plot.world.SinglePlotArea;
import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.PlotExpression;
@ -250,7 +252,12 @@ public class MainCommand extends Command {
.equals(area) || Permissions.hasPermission(player, Permission.PERMISSION_ADMIN)
|| Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_AREA_SUDO))
&& !newPlot.isDenied(player.getUUID())) {
Location newLoc = newPlot.getCenterSynchronous();
final Location newLoc;
if (newPlot.getArea() instanceof SinglePlotArea) {
newLoc = newPlot.isLoaded() ? newPlot.getCenterSynchronous() : Location.at("", 0, 0, 0);
} else {
newLoc = newPlot.getCenterSynchronous();
}
if (player.canTeleport(newLoc)) {
// Save meta
try (final MetaDataAccess<Location> locationMetaDataAccess

View File

@ -293,7 +293,7 @@ public class PlotListener {
.sendTitle(TranslatableCaption.of("titles.title_entered_plot"),
TranslatableCaption.of("titles.title_entered_plot_sub"),
Templates.of("x", lastPlot.getId().getX()), Templates.of("z", lastPlot.getId().getY()),
Templates.of("world", Objects.requireNonNull(plot.getWorldName(), "Unknown")),
Templates.of("world", Objects.requireNonNull(plot.getArea().getId(), "Unknown")),
Templates.of("greeting", greeting), Templates.of("alias", plot.getAlias()),
Templates.of("owner", user));
UUID uuid = plot.getOwner();

View File

@ -40,6 +40,7 @@ import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotWeather;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.plot.world.SinglePlotAreaManager;
import com.plotsquared.core.util.EventDispatcher;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.regions.CuboidRegion;
@ -78,7 +79,7 @@ public class ConsolePlayer extends PlotPlayer<Actor> {
area = null;
}
Location location;
if (area != null) {
if (area != null && !(plotAreaManager instanceof SinglePlotAreaManager)) {
CuboidRegion region = area.getRegion();
location = Location.at(area.getWorldName(),
region.getMinimumPoint().getX() + region.getMaximumPoint().getX() / 2, 0,

View File

@ -39,6 +39,7 @@ import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.database.DBFunc;
import com.plotsquared.core.events.Result;
import com.plotsquared.core.events.TeleportCause;
import com.plotsquared.core.generator.HybridPlotWorld;
import com.plotsquared.core.listener.PlotListener;
import com.plotsquared.core.location.BlockLoc;
import com.plotsquared.core.location.Direction;
@ -58,6 +59,8 @@ import com.plotsquared.core.plot.flag.implementations.KeepFlag;
import com.plotsquared.core.plot.flag.implementations.ServerPlotFlag;
import com.plotsquared.core.plot.flag.types.DoubleFlag;
import com.plotsquared.core.plot.schematic.Schematic;
import com.plotsquared.core.plot.world.SinglePlot;
import com.plotsquared.core.plot.world.SinglePlotManager;
import com.plotsquared.core.queue.QueueCoordinator;
import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.MathMan;
@ -1285,10 +1288,6 @@ public class Plot {
Location bot = corners[1];
Location location = Location.at(this.getWorldName(), MathMan.average(bot.getX(), top.getX()), MathMan.average(bot.getY(), top.getY()),
MathMan.average(bot.getZ(), top.getZ()));
if (!isLoaded()) {
result.accept(location);
return;
}
this.worldUtil.getHighestBlock(getWorldName(), location.getX(), location.getZ(), y -> {
int height = y;
if (area.allowSigns()) {
@ -1307,11 +1306,11 @@ public class Plot {
Location[] corners = getCorners();
Location top = corners[0];
Location bot = corners[1];
if (!isLoaded()) {
return Location.at("", 0, this.getArea() instanceof HybridPlotWorld ? ((HybridPlotWorld)this.getArea()).PLOT_HEIGHT + 1 : 4, 0);
}
Location location = Location.at(this.getWorldName(), MathMan.average(bot.getX(), top.getX()), MathMan.average(bot.getY(), top.getY()),
MathMan.average(bot.getZ(), top.getZ()));
if (!isLoaded()) {
return location;
}
int y = this.worldUtil.getHighestBlockSynchronous(getWorldName(), location.getX(), location.getZ());
if (area.allowSigns()) {
y = Math.max(y, getManager().getSignLoc(this).getY());
@ -1369,12 +1368,12 @@ public class Plot {
return this.getDefaultHomeSynchronous(true);
} else {
Location bottom = this.getBottomAbs();
if (!isLoaded()) {
return Location.at("", 0, this.getArea() instanceof HybridPlotWorld ? ((HybridPlotWorld)this.getArea()).PLOT_HEIGHT + 1 : 4, 0);
}
Location location = Location
.at(bottom.getWorldName(), bottom.getX() + home.getX(), bottom.getY() + home.getY(), bottom.getZ() + home.getZ(), home.getYaw(),
home.getPitch());
if (!isLoaded()) {
return location;
}
if (!this.worldUtil.getBlockSynchronous(location).getBlockType().getMaterial().isAir()) {
location = location.withY(
Math.max(1 + this.worldUtil.getHighestBlockSynchronous(this.getWorldName(), location.getX(), location.getZ()), bottom.getY()));
@ -1393,14 +1392,14 @@ public class Plot {
if (home == null || home.getX() == 0 && home.getZ() == 0) {
this.getDefaultHome(result);
} else {
if (!isLoaded()) {
result.accept(Location.at("", 0, this.getArea() instanceof HybridPlotWorld ? ((HybridPlotWorld)this.getArea()).PLOT_HEIGHT + 1 : 4, 0));
return;
}
Location bottom = this.getBottomAbs();
Location location = Location
.at(bottom.getWorldName(), bottom.getX() + home.getX(), bottom.getY() + home.getY(), bottom.getZ() + home.getZ(), home.getYaw(),
home.getPitch());
if (!isLoaded()) {
result.accept(location);
return;
}
this.worldUtil.getBlock(location, block -> {
if (!block.getBlockType().getMaterial().isAir()) {
this.worldUtil.getHighestBlock(this.getWorldName(), location.getX(), location.getZ(),
@ -1473,6 +1472,10 @@ public class Plot {
public void getDefaultHome(boolean member, Consumer<Location> result) {
Plot plot = this.getBasePlot(false);
if (!isLoaded()) {
result.accept(Location.at("", 0, this.getArea() instanceof HybridPlotWorld ? ((HybridPlotWorld)this.getArea()).PLOT_HEIGHT + 1 : 4, 0));
return;
}
PlotLoc loc = member ? area.getDefaultHome() : area.getNonmemberHome();
if (loc != null) {
int x;

View File

@ -87,7 +87,7 @@ public final class PlotId {
* @return Plot ID, or {@code null} if none could be parsed
*/
@Nullable public static PlotId fromStringOrNull(@Nonnull final String string) {
final String[] parts = string.split("[;,.]");
final String[] parts = string.split("[;_,.]");
if (parts.length < 2) {
return null;
}
@ -221,6 +221,17 @@ public final class PlotId {
return this.getX() + ";" + this.getY();
}
/**
* Get a String representation of the plot ID where the
* components are separated by a specified string
*
* @param separator Separator
* @return {@code x + separator + y}
*/
@Nonnull public String toSeparatedString(String separator) {
return this.getX() + separator + this.getY();
}
/**
* Get a String representation of the plot ID where the
* components are separated by ","

View File

@ -60,7 +60,7 @@ public class SinglePlot extends Plot {
}
@Override public String getWorldName() {
return getId().getX() + "." + getId().getY();
return getId().toSeparatedString("_");
}
@Override public SinglePlotArea getArea() {

View File

@ -87,7 +87,7 @@ public class SinglePlotArea extends GridPlotWorld {
}
public void loadWorld(final PlotId id) {
String worldName = id.getX() + "." + id.getY();
String worldName = id.toSeparatedString("_");
if (PlotSquared.platform().worldUtil().isWorld(worldName)) {
return;
}
@ -106,12 +106,17 @@ public class SinglePlotArea extends GridPlotWorld {
File oldFile = new File(container, id.toCommaSeparatedString());
if (oldFile.exists()) {
oldFile.renameTo(destination);
} else {
oldFile = new File(container, id.toSeparatedString("."));
if (oldFile.exists()) {
oldFile.renameTo(destination);
}
}
}
// Duplicate 0;0
if (builder.plotAreaType() != PlotAreaType.NORMAL) {
if (!destination.exists()) {
File src = new File(container, "0.0");
File src = new File(container, "0_0");
if (src.exists()) {
if (!destination.exists()) {
destination.mkdirs();
@ -140,7 +145,7 @@ public class SinglePlotArea extends GridPlotWorld {
try {
TaskManager.getPlatformImplementation().sync(() -> {
final String name = id.getX() + "." + id.getY();
final String name = id.toSeparatedString("_");
if (!PlotSquared.platform().worldUtil().isWorld(name)) {
PlotSquared.platform().setupUtils().setupWorld(builder);
}

View File

@ -85,7 +85,7 @@ import javax.inject.Inject;
}
case 1:
if ((c <= '/') || (c >= ':')) {
if (c == '.') {
if (c == '_') {
mode = 2;
continue;
}

View File

@ -57,11 +57,11 @@ public class SinglePlotManager extends PlotManager {
}
@Override public Location getPlotBottomLocAbs(@Nonnull final PlotId plotId) {
return Location.at(plotId.toCommaSeparatedString(), -30000000, 0, -30000000);
return Location.at(plotId.toSeparatedString("_"), -30000000, 0, -30000000);
}
@Override public Location getPlotTopLocAbs(@Nonnull final PlotId plotId) {
return Location.at(plotId.toCommaSeparatedString(), 30000000, 0, 30000000);
return Location.at(plotId.toSeparatedString("_"), 30000000, 0, 30000000);
}
@Override public boolean clearPlot(@Nonnull Plot plot, final Runnable whenDone, @Nullable PlotPlayer<?> actor, @Nullable QueueCoordinator queue) {