diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugRoadRegen.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugRoadRegen.java index 7d69db823..d6029186f 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugRoadRegen.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugRoadRegen.java @@ -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 "; @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; + } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridUtils.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridUtils.java index a586af012..a0b12d511 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridUtils.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridUtils.java @@ -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 regions = new HashSet<>(); + regions.add(ChunkManager.manager.getChunkChunk(plot.getCenter())); + return scheduleRoadUpdate(plot.getArea(), regions, extend); + } + public boolean scheduleRoadUpdate(final PlotArea area, Set rgs, final int extend) { HybridUtils.regions = rgs; HybridUtils.area = area;