2020-04-16 04:52:39 +02:00
|
|
|
/*
|
|
|
|
* _____ _ _ _____ _
|
|
|
|
* | __ \| | | | / ____| | |
|
|
|
|
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
|
|
|
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
|
|
|
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
|
|
|
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
|
|
|
* | |
|
|
|
|
* |_|
|
|
|
|
* PlotSquared plot management system for Minecraft
|
|
|
|
* Copyright (C) 2020 IntellectualSites
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2020-08-15 14:59:29 +02:00
|
|
|
* 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;
|
2015-03-15 04:21:50 +01:00
|
|
|
|
2020-08-07 12:53:32 +02:00
|
|
|
import com.plotsquared.core.permissions.Permission;
|
2020-07-18 15:06:51 +02:00
|
|
|
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.location.Location;
|
|
|
|
import com.plotsquared.core.player.PlotPlayer;
|
2020-04-30 12:33:59 +02:00
|
|
|
import com.plotsquared.core.plot.Plot;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.util.Permissions;
|
2020-07-21 21:39:52 +02:00
|
|
|
import net.kyori.adventure.text.minimessage.Template;
|
2015-03-15 04:21:50 +01:00
|
|
|
|
2020-02-24 18:42:02 +01:00
|
|
|
@CommandDeclaration(command = "copy",
|
|
|
|
permission = "plots.copy",
|
|
|
|
aliases = {"copypaste"},
|
|
|
|
category = CommandCategory.CLAIMING,
|
|
|
|
description = "Copy a plot",
|
|
|
|
usage = "/plot copy <X;Z>",
|
|
|
|
requiredType = RequiredType.NONE)
|
|
|
|
public class Copy extends SubCommand {
|
2016-03-23 02:41:37 +01:00
|
|
|
|
2020-05-27 14:08:48 +02:00
|
|
|
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
2019-09-08 20:02:45 +02:00
|
|
|
Location location = player.getLocation();
|
|
|
|
Plot plot1 = location.getPlotAbs();
|
2015-09-13 06:04:31 +02:00
|
|
|
if (plot1 == null) {
|
2020-07-18 15:06:51 +02:00
|
|
|
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
|
|
|
|
return false;
|
2015-09-13 06:04:31 +02:00
|
|
|
}
|
2018-08-10 17:01:10 +02:00
|
|
|
if (!plot1.isOwner(player.getUUID()) && !Permissions
|
2020-08-07 12:53:32 +02:00
|
|
|
.hasPermission(player, Permission.PERMISSION_ADMIN.toString())) {
|
2020-07-21 21:39:52 +02:00
|
|
|
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
|
2015-03-15 04:21:50 +01:00
|
|
|
return false;
|
|
|
|
}
|
2015-10-18 14:18:45 +02:00
|
|
|
if (args.length != 1) {
|
2020-07-21 21:39:52 +02:00
|
|
|
player.sendMessage(
|
|
|
|
TranslatableCaption.of("commandconfig.command_syntax"),
|
|
|
|
Template.of("value", "/plot copy <X;Z>")
|
|
|
|
);
|
2015-10-18 14:18:45 +02:00
|
|
|
return false;
|
|
|
|
}
|
2020-07-19 14:23:55 +02:00
|
|
|
Plot plot2 = Plot.getPlotFromString(player, args[0], true);
|
2016-03-23 02:41:37 +01:00
|
|
|
if (plot2 == null) {
|
2015-03-15 04:21:50 +01:00
|
|
|
return false;
|
|
|
|
}
|
2015-09-22 15:23:28 +02:00
|
|
|
if (plot1.equals(plot2)) {
|
2020-07-21 21:39:52 +02:00
|
|
|
player.sendMessage(TranslatableCaption.of("invalid.not_valid_plot_id"));
|
|
|
|
player.sendMessage(
|
|
|
|
TranslatableCaption.of("commandconfig.command_syntax"),
|
|
|
|
Template.of("value", "/plot copy <X;Z>")
|
|
|
|
);
|
2015-03-15 04:21:50 +01:00
|
|
|
return false;
|
|
|
|
}
|
2016-02-10 19:59:51 +01:00
|
|
|
if (!plot1.getArea().isCompatible(plot2.getArea())) {
|
2020-07-21 21:39:52 +02:00
|
|
|
player.sendMessage(TranslatableCaption.of("errors.plotworld_incompatible"));
|
2015-09-22 15:23:28 +02:00
|
|
|
return false;
|
|
|
|
}
|
2020-07-21 21:39:52 +02:00
|
|
|
if (plot1.copy(plot2, () -> player.sendMessage(TranslatableCaption.of("move.copy_success")))) {
|
2015-03-15 04:21:50 +01:00
|
|
|
return true;
|
2015-09-13 06:04:31 +02:00
|
|
|
} else {
|
2020-07-21 21:39:52 +02:00
|
|
|
player.sendMessage(TranslatableCaption.of("move.requires_unowned"));
|
2015-03-15 04:21:50 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|