2020-04-16 04:52:39 +02:00
|
|
|
/*
|
2022-06-15 20:17:17 +02:00
|
|
|
* PlotSquared, a land and world management plugin for Minecraft.
|
|
|
|
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
|
|
|
* Copyright (C) IntellectualSites team and contributors
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-04-16 04:52:39 +02:00
|
|
|
*/
|
2020-04-15 21:26:54 +02:00
|
|
|
package com.plotsquared.core.command;
|
2014-12-28 13:55:02 +01:00
|
|
|
|
2020-07-11 17:19:19 +02:00
|
|
|
import com.google.inject.Inject;
|
2020-07-22 19:42:22 +02:00
|
|
|
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.generator.HybridPlotManager;
|
|
|
|
import com.plotsquared.core.generator.HybridUtils;
|
2020-04-30 12:33:59 +02:00
|
|
|
import com.plotsquared.core.player.PlotPlayer;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.plot.PlotArea;
|
|
|
|
import com.plotsquared.core.plot.PlotManager;
|
2020-07-10 17:32:07 +02:00
|
|
|
import com.plotsquared.core.plot.world.PlotAreaManager;
|
2020-07-22 19:42:22 +02:00
|
|
|
import net.kyori.adventure.text.minimessage.Template;
|
2021-01-09 22:28:41 +01:00
|
|
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
2018-08-10 17:01:10 +02:00
|
|
|
|
2018-12-26 18:21:06 +01:00
|
|
|
@CommandDeclaration(command = "regenallroads",
|
2021-01-09 22:28:41 +01:00
|
|
|
aliases = {"rgar"},
|
|
|
|
usage = "/plot regenallroads <world> [height]",
|
|
|
|
category = CommandCategory.ADMINISTRATION,
|
|
|
|
requiredType = RequiredType.CONSOLE,
|
|
|
|
permission = "plots.regenallroads")
|
2020-02-24 18:42:02 +01:00
|
|
|
public class RegenAllRoads extends SubCommand {
|
2016-03-23 02:41:37 +01:00
|
|
|
|
2020-07-10 17:32:07 +02:00
|
|
|
private final PlotAreaManager plotAreaManager;
|
2020-07-11 17:19:19 +02:00
|
|
|
private final HybridUtils hybridUtils;
|
2020-07-10 17:32:07 +02:00
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Inject
|
|
|
|
public RegenAllRoads(
|
|
|
|
final @NonNull PlotAreaManager plotAreaManager,
|
|
|
|
final @NonNull HybridUtils hybridUtils
|
|
|
|
) {
|
2020-07-10 17:32:07 +02:00
|
|
|
this.plotAreaManager = plotAreaManager;
|
2020-07-11 17:19:19 +02:00
|
|
|
this.hybridUtils = hybridUtils;
|
2020-07-10 17:32:07 +02:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
2015-06-11 02:56:53 +02:00
|
|
|
int height = 0;
|
2015-09-13 06:04:31 +02:00
|
|
|
if (args.length == 2) {
|
|
|
|
try {
|
2015-06-11 02:56:53 +02:00
|
|
|
height = Integer.parseInt(args[1]);
|
2016-05-12 23:09:35 +02:00
|
|
|
} catch (NumberFormatException ignored) {
|
2020-07-22 19:42:22 +02:00
|
|
|
player.sendMessage(
|
|
|
|
TranslatableCaption.of("invalid.not_valid_number"),
|
2021-12-14 23:04:36 +01:00
|
|
|
Template.of("value", "(0, 256)")
|
2020-07-22 19:42:22 +02:00
|
|
|
);
|
|
|
|
player.sendMessage(
|
|
|
|
TranslatableCaption.of("commandconfig.command_syntax"),
|
2021-12-14 23:04:36 +01:00
|
|
|
Template.of("value", "/plot regenallroads <world> [height]")
|
2020-07-22 19:42:22 +02:00
|
|
|
);
|
2015-06-11 02:56:53 +02:00
|
|
|
return false;
|
|
|
|
}
|
2016-01-10 21:00:56 +01:00
|
|
|
} else if (args.length != 1) {
|
2020-07-22 19:42:22 +02:00
|
|
|
player.sendMessage(
|
|
|
|
TranslatableCaption.of("commandconfig.command_syntax"),
|
2021-12-14 23:04:36 +01:00
|
|
|
Template.of("value", "/plot regenallroads <world> [height]")
|
2020-07-22 19:42:22 +02:00
|
|
|
);
|
2015-11-15 03:30:52 +01:00
|
|
|
return false;
|
2015-06-11 02:56:53 +02:00
|
|
|
}
|
2020-07-10 17:32:07 +02:00
|
|
|
PlotArea area = this.plotAreaManager.getPlotAreaByString(args[0]);
|
2017-09-19 16:33:29 +02:00
|
|
|
if (area == null) {
|
2020-07-22 19:42:22 +02:00
|
|
|
player.sendMessage(
|
|
|
|
TranslatableCaption.of("errors.not_valid_plot_world"),
|
2021-12-14 23:04:36 +01:00
|
|
|
Template.of("value", args[0])
|
2020-07-22 19:42:22 +02:00
|
|
|
);
|
2016-02-10 19:59:51 +01:00
|
|
|
return false;
|
|
|
|
}
|
2016-03-23 02:41:37 +01:00
|
|
|
PlotManager manager = area.getPlotManager();
|
2016-04-28 22:38:51 +02:00
|
|
|
if (!(manager instanceof HybridPlotManager)) {
|
2020-08-17 22:26:01 +02:00
|
|
|
player.sendMessage(TranslatableCaption.of("errors.invalid_plot_world"));
|
2014-12-28 13:55:02 +01:00
|
|
|
return false;
|
|
|
|
}
|
2021-01-09 22:28:41 +01:00
|
|
|
player.sendMessage(
|
|
|
|
TranslatableCaption.of("debugroadregen.schematic"),
|
2021-12-14 23:04:36 +01:00
|
|
|
Template.of("command", "/plot createroadschematic")
|
2021-01-09 22:28:41 +01:00
|
|
|
);
|
2020-09-01 00:02:56 +02:00
|
|
|
player.sendMessage(TranslatableCaption.of("debugroadregen.regenallroads_started"));
|
2020-07-11 17:19:19 +02:00
|
|
|
boolean result = this.hybridUtils.scheduleRoadUpdate(area, height);
|
2015-09-13 06:04:31 +02:00
|
|
|
if (!result) {
|
2020-07-22 19:42:22 +02:00
|
|
|
player.sendMessage(TranslatableCaption.of("debugexec.mass_schematic_update_in_progress"));
|
2014-12-28 13:55:02 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2021-01-09 22:28:41 +01:00
|
|
|
|
2014-12-28 13:55:02 +01:00
|
|
|
}
|