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.minimessage.Template;
028
029public abstract class SetCommand extends SubCommand {
030
031    @Override
032    public boolean onCommand(PlotPlayer<?> player, String[] args) {
033        Location location = player.getLocation();
034        Plot plot = location.getPlotAbs();
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                        Template.of("node", Permission.PERMISSION_ADMIN_COMMAND.format(getFullId()))
044                );
045                player.sendMessage(TranslatableCaption.of("working.plot_not_claimed"));
046                return false;
047            }
048        }
049        if (!plot.isOwner(player.getUUID())) {
050            if (!player.hasPermission(Permission.PERMISSION_ADMIN_COMMAND.format(getFullId()))) {
051                player.sendMessage(
052                        TranslatableCaption.of("permission.no_permission"),
053                        Template.of("node", Permission.PERMISSION_ADMIN_COMMAND.format(getFullId()))
054                );
055                player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
056                return false;
057            }
058        }
059        if (args.length == 0) {
060            return set(player, plot, "");
061        }
062        return set(player, plot, StringMan.join(args, " "));
063    }
064
065    public abstract boolean set(PlotPlayer<?> player, Plot plot, String value);
066
067}