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.plotsquared.core.configuration.caption.TranslatableCaption;
022import com.plotsquared.core.location.Location;
023import com.plotsquared.core.permissions.Permission;
024import com.plotsquared.core.player.PlotPlayer;
025import com.plotsquared.core.plot.Plot;
026import com.plotsquared.core.util.StringMan;
027import net.kyori.adventure.text.Component;
028import net.kyori.adventure.text.minimessage.tag.Tag;
029import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
030
031public abstract class SetCommand extends SubCommand {
032
033    @Override
034    public boolean onCommand(PlotPlayer<?> player, String[] args) {
035        Location location = player.getLocation();
036        Plot plot = location.getPlotAbs();
037        if (plot == null) {
038            player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
039            return false;
040        }
041        if (!plot.hasOwner()) {
042            if (!player.hasPermission(Permission.PERMISSION_ADMIN_COMMAND.format(getFullId()))) {
043                player.sendMessage(
044                        TranslatableCaption.of("permission.no_permission"),
045                        TagResolver.resolver(
046                                "node",
047                                Tag.inserting(Component.text(Permission.PERMISSION_ADMIN_COMMAND.format(getFullId())))
048                        )
049                );
050                player.sendMessage(TranslatableCaption.of("working.plot_not_claimed"));
051                return false;
052            }
053        }
054        if (!plot.isOwner(player.getUUID())) {
055            if (!player.hasPermission(Permission.PERMISSION_ADMIN_COMMAND.format(getFullId()))) {
056                player.sendMessage(
057                        TranslatableCaption.of("permission.no_permission"),
058                        TagResolver.resolver(
059                                "node",
060                                Tag.inserting(Component.text(Permission.PERMISSION_ADMIN_COMMAND.format(getFullId())))
061                        )
062                );
063                player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
064                return false;
065            }
066        }
067        if (args.length == 0) {
068            return set(player, plot, "");
069        }
070        return set(player, plot, StringMan.join(args, " "));
071    }
072
073    public abstract boolean set(PlotPlayer<?> player, Plot plot, String value);
074
075}