001/*
002 * PlotSquared, a land and world management plugin for Minecraft.
003 * Copyright (C) IntellectualSites <https://intellectualsites.com>
004 * Copyright (C) IntellectualSites team and contributors
005 *
006 * This program is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
018 */
019package com.plotsquared.core.command;
020
021import com.google.inject.Inject;
022import com.plotsquared.core.configuration.caption.TranslatableCaption;
023import com.plotsquared.core.generator.HybridPlotWorld;
024import com.plotsquared.core.generator.HybridUtils;
025import com.plotsquared.core.location.Location;
026import com.plotsquared.core.player.PlotPlayer;
027import com.plotsquared.core.plot.Plot;
028import net.kyori.adventure.text.Component;
029import net.kyori.adventure.text.minimessage.tag.Tag;
030import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
031import org.checkerframework.checker.nullness.qual.NonNull;
032
033@CommandDeclaration(command = "createroadschematic",
034        aliases = {"crs"},
035        category = CommandCategory.ADMINISTRATION,
036        requiredType = RequiredType.PLAYER,
037        permission = "plots.createroadschematic",
038        usage = "/plot createroadschematic")
039public class CreateRoadSchematic extends SubCommand {
040
041    private final HybridUtils hybridUtils;
042
043    @Inject
044    public CreateRoadSchematic(final @NonNull HybridUtils hybridUtils) {
045        this.hybridUtils = hybridUtils;
046    }
047
048    @Override
049    public boolean onCommand(PlotPlayer<?> player, String[] args) {
050        Location location = player.getLocation();
051        Plot plot = location.getPlotAbs();
052        if (plot == null) {
053            player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
054            return false;
055        }
056        if (plot.getVolume() > Integer.MAX_VALUE) {
057            player.sendMessage(TranslatableCaption.of("schematics.schematic_too_large"));
058            return false;
059        }
060        if (!(location.getPlotArea() instanceof HybridPlotWorld)) {
061            player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world"));
062        }
063        this.hybridUtils.setupRoadSchematic(plot);
064        player.sendMessage(
065                TranslatableCaption.of("schematics.schematic_road_created"),
066                TagResolver.resolver("command", Tag.inserting(Component.text("/plot debugroadregen")))
067        );
068        return true;
069    }
070
071}