mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 15:16:45 +01:00
Fixed plot copy and move arguments
This commit is contained in:
parent
d23bfa0bde
commit
7878d0b525
@ -0,0 +1,82 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// 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 /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
|
||||
/**
|
||||
* Created 2014-08-01 for PlotSquared
|
||||
*
|
||||
* @author Empire92
|
||||
*/
|
||||
public class Copy extends SubCommand {
|
||||
public Copy() {
|
||||
super("copy", "plots.copy", "Copy a plot", "copypaste", "", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length < 1) {
|
||||
MainUtil.sendMessage(plr, C.NEED_PLOT_ID);
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy <X;Z>");
|
||||
return false;
|
||||
}
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot1 = MainUtil.getPlot(loc);
|
||||
if (plot1 == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (!plot1.isAdded(plr.getUUID()) && !plr.hasPermission(Permissions.ADMIN)) {
|
||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
final String world = loc.getWorld();
|
||||
final PlotId plot2 = MainUtil.parseId(args[0]);
|
||||
if ((plot2 == null)) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy <X;Z>");
|
||||
return false;
|
||||
}
|
||||
if (plot1.id.equals(plot2)) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy <X;Z>");
|
||||
return false;
|
||||
}
|
||||
if (MainUtil.copy(world, plot1.id, plot2, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(plr, C.COPY_SUCCESS);
|
||||
MainUtil.update(plr.getLocation());
|
||||
}
|
||||
})) {
|
||||
return true;
|
||||
} else {
|
||||
MainUtil.sendMessage(plr, C.REQUIRES_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -40,7 +40,7 @@ public class MainCommand {
|
||||
/**
|
||||
* Main Permission Node
|
||||
*/
|
||||
private final static SubCommand[] _subCommands = new SubCommand[] { new Template(), new Setup(), new DebugSaveTest(), new DebugLoadTest(), new CreateRoadSchematic(), new RegenAllRoads(), new DebugClear(), new Claim(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(), new Info(), new list(), new Help(), new Debug(), new SchematicCmd(), new plugin(), new Inventory(), new Purge(), new Reload(), new Merge(), new Unlink(), new Kick(), new Rate(), new DebugClaimTest(), new Inbox(), new Comment(), new Database(), new Unclaim(), new Swap(), new MusicSubcommand(), new DebugRoadRegen(), new Trim(), new DebugExec(), new FlagCmd(), new Target(), new DebugFixFlags(), new Move(), new Condense(), new Confirm() };
|
||||
private final static SubCommand[] _subCommands = new SubCommand[] { new Template(), new Setup(), new DebugSaveTest(), new DebugLoadTest(), new CreateRoadSchematic(), new RegenAllRoads(), new DebugClear(), new Claim(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(), new Info(), new list(), new Help(), new Debug(), new SchematicCmd(), new plugin(), new Inventory(), new Purge(), new Reload(), new Merge(), new Unlink(), new Kick(), new Rate(), new DebugClaimTest(), new Inbox(), new Comment(), new Database(), new Unclaim(), new Swap(), new MusicSubcommand(), new DebugRoadRegen(), new Trim(), new DebugExec(), new FlagCmd(), new Target(), new DebugFixFlags(), new Move(), new Condense(), new Confirm(), new Copy() };
|
||||
public final static ArrayList<SubCommand> subCommands = new ArrayList<SubCommand>() {
|
||||
{
|
||||
addAll(Arrays.asList(_subCommands));
|
||||
|
@ -55,7 +55,7 @@ public class Move extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
final String world = loc.getWorld();
|
||||
final PlotId plot2 = MainUtil.parseId(args[1]);
|
||||
final PlotId plot2 = MainUtil.parseId(args[0]);
|
||||
if ((plot2 == null)) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot move <X;Z>");
|
||||
@ -70,6 +70,7 @@ public class Move extends SubCommand {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(plr, C.MOVE_SUCCESS);
|
||||
MainUtil.update(plr.getLocation());
|
||||
}
|
||||
})) {
|
||||
return true;
|
||||
|
@ -44,6 +44,7 @@ public enum C {
|
||||
* Move
|
||||
*/
|
||||
MOVE_SUCCESS("$4Successfully moved plot."),
|
||||
COPY_SUCCESS("$4Successfully copied plot."),
|
||||
REQUIRES_UNOWNED("$2The location specified is already occupied."),
|
||||
/*
|
||||
* Compass
|
||||
|
@ -25,6 +25,7 @@ import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotSquared;
|
||||
import com.intellectualcrafters.plot.commands.Claim;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
@ -820,6 +821,61 @@ public class MainUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean copy(final String world, final PlotId current, final PlotId newPlot, final Runnable whenDone) {
|
||||
final com.intellectualcrafters.plot.object.Location bot1 = MainUtil.getPlotBottomLoc(world, current);
|
||||
final com.intellectualcrafters.plot.object.Location bot2 = MainUtil.getPlotBottomLoc(world, newPlot);
|
||||
final Location top = MainUtil.getPlotTopLoc(world, current);
|
||||
final Plot currentPlot = MainUtil.getPlot(world, current);
|
||||
if (currentPlot.owner == null) {
|
||||
TaskManager.runTaskLater(whenDone, 1);
|
||||
return false;
|
||||
}
|
||||
final Plot pos1 = getBottomPlot(currentPlot);
|
||||
final Plot pos2 = getTopPlot(currentPlot);
|
||||
final PlotId size = MainUtil.getSize(world, currentPlot);
|
||||
if (!MainUtil.isUnowned(world, newPlot, new PlotId((newPlot.x + size.x) - 1, (newPlot.y + size.y) - 1))) {
|
||||
TaskManager.runTaskLater(whenDone, 1);
|
||||
return false;
|
||||
}
|
||||
final ArrayList<PlotId> selection = getPlotSelectionIds(pos1.id, pos2.id);
|
||||
final int offset_x = newPlot.x - pos1.id.x;
|
||||
final int offset_y = newPlot.y - pos1.id.y;
|
||||
for (final PlotId id : selection) {
|
||||
int x = id.x + offset_x;
|
||||
int y = id.y + offset_y;
|
||||
Plot plot = createPlotAbs(currentPlot.owner, getPlot(world, new PlotId(x, y)));
|
||||
if (currentPlot.settings.flags != null && currentPlot.settings.flags.size() > 0) {
|
||||
plot.settings.flags = currentPlot.settings.flags;
|
||||
DBFunc.setFlags(world, plot, currentPlot.settings.flags);
|
||||
}
|
||||
if (currentPlot.settings.isMerged()) {
|
||||
plot.settings.setMerged(currentPlot.settings.getMerged());
|
||||
DBFunc.setMerged(world, plot, currentPlot.settings.getMerged());
|
||||
}
|
||||
if (currentPlot.trusted != null && currentPlot.trusted.size() > 0) {
|
||||
plot.trusted = currentPlot.trusted;
|
||||
for (UUID trusted : plot.trusted) {
|
||||
DBFunc.setTrusted(world, plot, trusted);
|
||||
}
|
||||
}
|
||||
if (currentPlot.helpers != null && currentPlot.helpers.size() > 0) {
|
||||
plot.trusted = currentPlot.helpers;
|
||||
for (UUID helpers : plot.helpers) {
|
||||
DBFunc.setHelper(world, plot, helpers);
|
||||
}
|
||||
}
|
||||
if (currentPlot.denied != null && currentPlot.denied.size() > 0) {
|
||||
plot.trusted = currentPlot.denied;
|
||||
for (UUID denied : plot.denied) {
|
||||
DBFunc.setDenied(world, plot, denied);
|
||||
}
|
||||
}
|
||||
PlotSquared.getPlots(world).put(plot.id, plot);
|
||||
}
|
||||
ChunkManager.manager.copyRegion(bot1, top, bot2, whenDone);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to the player
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user