TF-PlotSquared/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java

126 lines
6.5 KiB
Java
Raw Normal View History

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-01-14 03:38:15 +11:00
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
2015-02-18 23:15:55 +11:00
import org.bukkit.World;
2015-01-14 03:38:15 +11:00
import org.bukkit.entity.Player;
2015-02-19 21:29:17 +11:00
import com.intellectualcrafters.plot.BukkitMain;
2015-02-19 19:51:10 +11:00
import com.intellectualcrafters.plot.PlotSquared;
2014-11-16 10:48:18 +01:00
import com.intellectualcrafters.plot.config.C;
2014-11-08 20:27:09 +01:00
import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent;
2014-11-16 10:48:18 +01:00
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.PlotHelper;
import com.intellectualcrafters.plot.util.SchematicHandler;
2015-02-20 17:28:21 +11:00
import com.intellectualcrafters.plot.util.bukkit.PlayerFunctions;
2014-12-28 23:02:30 +11:00
2014-09-22 13:02:14 +02:00
/**
* @author Citymonstret
*/
public class Claim extends SubCommand {
2014-11-05 14:42:08 +11:00
public Claim() {
super(Command.CLAIM, "Claim the current plot you're standing on.", "claim", CommandCategory.CLAIMING, true);
}
2015-02-20 17:34:19 +11:00
2014-12-16 16:03:20 +11:00
public static boolean claimPlot(final Player player, final Plot plot, final boolean teleport, final boolean auto) {
return claimPlot(player, plot, teleport, "", auto);
2014-11-05 14:42:08 +11:00
}
2015-02-20 17:34:19 +11:00
2014-12-16 16:03:20 +11:00
public static boolean claimPlot(final Player player, final Plot plot, final boolean teleport, final String schematic, final boolean auto) {
2015-02-20 17:34:19 +11:00
if (plot.hasOwner() || plot.settings.isMerged()) {
return false;
}
final PlayerClaimPlotEvent event = new PlayerClaimPlotEvent(player, plot, auto);
2014-11-05 14:42:08 +11:00
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
PlotHelper.createPlot(player, plot);
PlotHelper.setSign(player, plot);
PlayerFunctions.sendMessage(player, C.CLAIMED);
if (teleport) {
2015-02-19 21:29:17 +11:00
PlotSquared.teleportPlayer(player, BukkitUtil.getLocation(entity), plot);
2014-11-05 14:42:08 +11:00
}
2015-02-20 17:34:19 +11:00
final World world = plot.world;
2015-02-19 19:51:10 +11:00
final PlotWorld plotworld = PlotSquared.getWorldSettings(world);
final Plot plot2 = PlotSquared.getPlots(player.getWorld()).get(plot.id);
2015-02-18 23:15:55 +11:00
if (plotworld.SCHEMATIC_ON_CLAIM) {
2014-11-05 14:42:08 +11:00
SchematicHandler.Schematic sch;
if (schematic.equals("")) {
2015-02-18 23:15:55 +11:00
sch = SchematicHandler.getSchematic(plotworld.SCHEMATIC_FILE);
2014-12-17 20:15:11 -06:00
} else {
2014-11-05 14:42:08 +11:00
sch = SchematicHandler.getSchematic(schematic);
if (sch == null) {
2015-02-18 23:15:55 +11:00
sch = SchematicHandler.getSchematic(plotworld.SCHEMATIC_FILE);
2014-11-05 14:42:08 +11:00
}
}
2015-02-19 21:29:17 +11:00
SchematicHandler.paste(BukkitUtil.getLocation(entity), sch, plot2, 0, 0);
2014-11-05 14:42:08 +11:00
}
2015-02-19 19:51:10 +11:00
PlotSquared.getPlotManager(plot.world).claimPlot(world, plotworld, plot);
2015-02-19 21:29:17 +11:00
PlotHelper.update(BukkitUtil.getLocation(entity));
2014-11-05 14:42:08 +11:00
}
return event.isCancelled();
}
2015-02-20 17:34:19 +11:00
2014-11-16 10:48:18 +01:00
@Override
public boolean execute(final Player plr, final String... args) {
String schematic = "";
if (args.length >= 1) {
schematic = args[0];
}
if (!PlayerFunctions.isInPlot(plr)) {
return sendMessage(plr, C.NOT_IN_PLOT);
}
if (PlayerFunctions.getPlayerPlotCount(plr.getWorld(), plr) >= PlayerFunctions.getAllowedPlots(plr)) {
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
}
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
if (plot.hasOwner()) {
return sendMessage(plr, C.PLOT_IS_CLAIMED);
}
2015-02-19 22:39:23 +11:00
final PlotWorld world = PlotSquared.getWorldSettings(plot.world);
2015-02-19 19:51:10 +11:00
if (PlotSquared.useEconomy && world.USE_ECONOMY) {
2014-11-16 10:48:18 +01:00
final double cost = world.PLOT_PRICE;
if (cost > 0d) {
2015-02-19 19:51:10 +11:00
final Economy economy = PlotSquared.economy;
2014-11-16 10:48:18 +01:00
if (economy.getBalance(plr) < cost) {
return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
}
economy.withdrawPlayer(plr, cost);
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-02-19 20:04:47 +11:00
if (!BukkitMain.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);
}
}
}
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
}