2014-11-08 20:27:09 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// 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 /
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
2014-09-22 13:02:14 +02:00
|
|
|
package com.intellectualcrafters.plot.commands;
|
|
|
|
|
2015-07-03 14:15:20 +02:00
|
|
|
import com.intellectualcrafters.plot.PS;
|
2014-11-16 10:48:18 +01:00
|
|
|
import com.intellectualcrafters.plot.config.C;
|
2015-04-14 15:47:12 +02:00
|
|
|
import com.intellectualcrafters.plot.config.Settings;
|
2015-07-30 16:25:16 +02:00
|
|
|
import com.intellectualcrafters.plot.object.Location;
|
|
|
|
import com.intellectualcrafters.plot.object.Plot;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
|
|
|
import com.intellectualcrafters.plot.object.RunnableVal;
|
|
|
|
import com.intellectualcrafters.plot.util.EconHandler;
|
|
|
|
import com.intellectualcrafters.plot.util.EventUtil;
|
|
|
|
import com.intellectualcrafters.plot.util.MainUtil;
|
|
|
|
import com.intellectualcrafters.plot.util.Permissions;
|
|
|
|
import com.intellectualcrafters.plot.util.SchematicHandler;
|
2015-02-25 13:25:28 +01:00
|
|
|
import com.intellectualcrafters.plot.util.SchematicHandler.Schematic;
|
2015-07-27 19:50:04 +02:00
|
|
|
import com.plotsquared.general.commands.CommandDeclaration;
|
2014-12-28 13:02:30 +01:00
|
|
|
|
2015-07-26 21:33:54 +02:00
|
|
|
@CommandDeclaration(
|
|
|
|
command = "claim",
|
|
|
|
aliases = {"c"},
|
|
|
|
description = "Claim the current plot you're standing on",
|
|
|
|
category = CommandCategory.CLAIMING,
|
2015-07-27 19:50:32 +02:00
|
|
|
requiredType = RequiredType.NONE,
|
2015-07-26 21:33:54 +02:00
|
|
|
permission = "plots.claim",
|
|
|
|
usage = "/plot claim"
|
|
|
|
)
|
2014-09-24 14:21:43 +02:00
|
|
|
public class Claim extends SubCommand {
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2015-02-21 12:38:44 +01:00
|
|
|
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final boolean auto) {
|
2014-11-19 18:05:09 +01:00
|
|
|
return claimPlot(player, plot, teleport, "", auto);
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2015-02-21 12:38:44 +01:00
|
|
|
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final String schematic, final boolean auto) {
|
2015-07-21 20:31:12 +02:00
|
|
|
if (plot.hasOwner() || plot.getSettings().isMerged()) {
|
2015-02-20 07:34:19 +01:00
|
|
|
return false;
|
|
|
|
}
|
2015-02-23 06:29:45 +01:00
|
|
|
final boolean result = EventUtil.manager.callClaim(player, plot, false);
|
|
|
|
if (result) {
|
2015-02-21 15:13:34 +01:00
|
|
|
MainUtil.createPlot(player.getUUID(), plot);
|
|
|
|
MainUtil.setSign(player.getName(), plot);
|
|
|
|
MainUtil.sendMessage(player, C.CLAIMED);
|
2015-02-23 02:32:27 +01:00
|
|
|
final Location loc = player.getLocation();
|
2014-11-05 04:42:08 +01:00
|
|
|
if (teleport) {
|
2015-02-21 15:17:31 +01:00
|
|
|
MainUtil.teleportPlayer(player, loc, plot);
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2015-02-21 15:17:31 +01:00
|
|
|
final String world = plot.world;
|
2015-07-03 14:15:20 +02:00
|
|
|
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
2015-08-06 18:05:15 +02:00
|
|
|
final Plot plot2 = PS.get().getPlot(world, plot.id);
|
2015-02-18 13:15:55 +01:00
|
|
|
if (plotworld.SCHEMATIC_ON_CLAIM) {
|
2015-02-25 13:25:28 +01:00
|
|
|
Schematic sch;
|
2014-11-05 04:42:08 +01:00
|
|
|
if (schematic.equals("")) {
|
2015-02-25 13:25:28 +01:00
|
|
|
sch = SchematicHandler.manager.getSchematic(plotworld.SCHEMATIC_FILE);
|
2014-12-18 03:15:11 +01:00
|
|
|
} else {
|
2015-02-25 13:25:28 +01:00
|
|
|
sch = SchematicHandler.manager.getSchematic(schematic);
|
2014-11-05 04:42:08 +01:00
|
|
|
if (sch == null) {
|
2015-02-25 13:25:28 +01:00
|
|
|
sch = SchematicHandler.manager.getSchematic(plotworld.SCHEMATIC_FILE);
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
|
|
|
}
|
2015-07-22 18:33:22 +02:00
|
|
|
SchematicHandler.manager.paste(sch, plot2, 0, 0, new RunnableVal<Boolean>() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (value) {
|
|
|
|
MainUtil.sendMessage(player, C.SCHEMATIC_PASTE_SUCCESS);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
MainUtil.sendMessage(player, C.SCHEMATIC_PASTE_FAILED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2015-07-03 14:15:20 +02:00
|
|
|
PS.get().getPlotManager(world).claimPlot(plotworld, plot);
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2015-02-23 06:29:45 +01:00
|
|
|
return result;
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2014-11-16 10:48:18 +01:00
|
|
|
@Override
|
2015-07-27 15:10:14 +02:00
|
|
|
public boolean onCommand(final PlotPlayer plr, final String ... args) {
|
|
|
|
|
2014-11-16 10:48:18 +01:00
|
|
|
String schematic = "";
|
|
|
|
if (args.length >= 1) {
|
|
|
|
schematic = args[0];
|
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
final Location loc = plr.getLocation();
|
|
|
|
final Plot plot = MainUtil.getPlot(loc);
|
2015-02-21 15:17:31 +01:00
|
|
|
if (plot == null) {
|
2014-11-16 10:48:18 +01:00
|
|
|
return sendMessage(plr, C.NOT_IN_PLOT);
|
|
|
|
}
|
2015-04-14 15:47:12 +02:00
|
|
|
final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(loc.getWorld(), plr);
|
2015-03-11 16:08:51 +01:00
|
|
|
if (currentPlots >= MainUtil.getAllowedPlots(plr)) {
|
2014-11-16 10:48:18 +01:00
|
|
|
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
|
|
|
|
}
|
2015-04-07 15:21:51 +02:00
|
|
|
if (!MainUtil.canClaim(plr, plot)) {
|
2014-11-16 10:48:18 +01:00
|
|
|
return sendMessage(plr, C.PLOT_IS_CLAIMED);
|
|
|
|
}
|
2015-07-03 14:15:20 +02:00
|
|
|
final PlotWorld world = PS.get().getPlotWorld(plot.world);
|
2015-06-05 14:39:48 +02:00
|
|
|
if ((EconHandler.manager != null) && world.USE_ECONOMY) {
|
2014-11-16 10:48:18 +01:00
|
|
|
final double cost = world.PLOT_PRICE;
|
|
|
|
if (cost > 0d) {
|
2015-06-05 14:39:48 +02:00
|
|
|
if (EconHandler.manager.getMoney(plr) < cost) {
|
2014-11-16 10:48:18 +01:00
|
|
|
return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
|
|
|
|
}
|
2015-06-05 14:39:48 +02:00
|
|
|
EconHandler.manager.withdrawMoney(plr, cost);
|
2014-11-16 10:48:18 +01:00
|
|
|
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!schematic.equals("")) {
|
|
|
|
if (world.SCHEMATIC_CLAIM_SPECIFY) {
|
|
|
|
if (!world.SCHEMATICS.contains(schematic.toLowerCase())) {
|
|
|
|
return sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
|
|
|
|
}
|
2015-07-10 16:08:07 +02:00
|
|
|
if (!Permissions.hasPermission(plr, "plots.claim." + schematic) && !plr.hasPermission("plots.admin.command.schematic")) {
|
2014-11-16 10:48:18 +01:00
|
|
|
return sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-23 01:58:47 +01:00
|
|
|
return claimPlot(plr, plot, false, schematic, false) || sendMessage(plr, C.PLOT_NOT_CLAIMED);
|
2014-11-16 10:48:18 +01:00
|
|
|
}
|
2014-09-22 13:02:14 +02:00
|
|
|
}
|