Allow running the road regeneration on a single region

The plot-based road regeneration from before does not have the same behavior as the real road regeneration code. This new debug operation will regenerate the roads within the region the player is standing using the same code that regenerates all roads. This makes it much easier to tell if things are working correctly and as expected.
This commit is contained in:
Alexander Krivács Schrøder 2019-06-01 14:45:36 +02:00 committed by Matt
parent 7f404e1cf5
commit d6401d1638
2 changed files with 81 additions and 2 deletions

View File

@ -2,6 +2,9 @@ package com.github.intellectualsites.plotsquared.plot.commands;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.generator.HybridPlotManager;
import com.github.intellectualsites.plotsquared.plot.generator.HybridPlotWorld;
import com.github.intellectualsites.plotsquared.plot.generator.HybridUtils;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
@ -9,13 +12,37 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotManager;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
@CommandDeclaration(command = "debugroadregen", usage = "/plot debugroadregen",
import java.util.Arrays;
@CommandDeclaration(command = "debugroadregen", usage = DebugRoadRegen.USAGE,
requiredType = RequiredType.NONE,
description = "Regenerate all roads based on the road schematic",
description = "Regenerate roads in the plot or region the user is, based on the road schematic",
category = CommandCategory.DEBUG, permission = "plots.debugroadregen")
public class DebugRoadRegen extends SubCommand {
public static final String USAGE = "/plot debugroadregen <plot|region [height]>";
@Override public boolean onCommand(PlotPlayer player, String[] args) {
if (args.length < 1) {
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX,
DebugRoadRegen.USAGE);
return false;
}
String kind = args[0].toLowerCase();
switch (kind) {
case "plot":
return regenPlot(player);
case "region":
return regenRegion(player, Arrays.copyOfRange(args, 1, args.length));
default:
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX,
DebugRoadRegen.USAGE);
return false;
}
}
public boolean regenPlot(PlotPlayer player) {
Location loc = player.getLocation();
PlotArea area = loc.getPlotArea();
if (area == null) {
@ -37,4 +64,46 @@ public class DebugRoadRegen extends SubCommand {
}
return true;
}
public boolean regenRegion(PlotPlayer player, String[] args) {
int height = 0;
if (args.length == 1) {
try {
height = Integer.parseInt(args[0]);
} catch (NumberFormatException ignored) {
MainUtil.sendMessage(player, Captions.NOT_VALID_NUMBER, "(0, 256)");
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX,
DebugRoadRegen.USAGE);
return false;
}
} else if (args.length != 0) {
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX,
DebugRoadRegen.USAGE);
return false;
}
Location loc = player.getLocation();
PlotArea area = loc.getPlotArea();
if (area == null) {
return sendMessage(player, Captions.NOT_IN_PLOT_WORLD);
}
Plot plot = player.getCurrentPlot();
PlotManager manager = area.getPlotManager();
if (!(manager instanceof HybridPlotManager)) {
MainUtil.sendMessage(player, Captions.NOT_VALID_PLOT_WORLD);
return true;
}
MainUtil
.sendMessage(player, "&cIf no schematic is set, the following will not do anything");
MainUtil.sendMessage(player,
"&7 - To set a schematic, stand in a plot and use &c/plot createroadschematic");
MainUtil.sendMessage(player, "&cTo regenerate all roads: /plot regenallroads");
boolean result = HybridUtils.manager.scheduleSingleRegionRoadUpdate(plot, height);
if (!result) {
MainUtil.sendMessage(player,
"&cCannot schedule mass schematic update! (Is one already in progress?)");
return false;
}
return true;
}
}

View File

@ -130,6 +130,16 @@ public abstract class HybridUtils {
return scheduleRoadUpdate(area, regions, extend);
}
public boolean scheduleSingleRegionRoadUpdate(Plot plot, int extend) {
if (HybridUtils.UPDATE) {
return false;
}
HybridUtils.UPDATE = true;
Set<ChunkLoc> regions = new HashSet<>();
regions.add(ChunkManager.manager.getChunkChunk(plot.getCenter()));
return scheduleRoadUpdate(plot.getArea(), regions, extend);
}
public boolean scheduleRoadUpdate(final PlotArea area, Set<ChunkLoc> rgs, final int extend) {
HybridUtils.regions = rgs;
HybridUtils.area = area;