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