2014-09-22 13:02:14 +02:00
|
|
|
/*
|
2014-10-12 09:37:36 +02:00
|
|
|
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute
|
|
|
|
* and/or monetize any of our intellectual property. IntellectualCrafters is not
|
|
|
|
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB.
|
|
|
|
*
|
|
|
|
* >> File = Claim.java >> Generated by: Citymonstret at 2014-08-09 01:41
|
2014-09-22 13:02:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.intellectualcrafters.plot.commands;
|
|
|
|
|
2014-09-29 19:05:03 +02:00
|
|
|
import net.milkbowl.vault.economy.Economy;
|
2014-10-03 04:36:30 +02:00
|
|
|
|
2014-09-22 13:02:14 +02:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2014-10-03 04:36:30 +02:00
|
|
|
import com.intellectualcrafters.plot.C;
|
2014-10-11 09:33:10 +02:00
|
|
|
import com.intellectualcrafters.plot.FlagManager;
|
2014-10-03 04:36:30 +02:00
|
|
|
import com.intellectualcrafters.plot.PlayerFunctions;
|
|
|
|
import com.intellectualcrafters.plot.Plot;
|
|
|
|
import com.intellectualcrafters.plot.PlotHelper;
|
|
|
|
import com.intellectualcrafters.plot.PlotMain;
|
|
|
|
import com.intellectualcrafters.plot.PlotWorld;
|
|
|
|
import com.intellectualcrafters.plot.SchematicHandler;
|
|
|
|
import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent;
|
|
|
|
|
2014-09-22 13:02:14 +02:00
|
|
|
/**
|
|
|
|
* @author Citymonstret
|
|
|
|
*/
|
2014-09-24 14:21:43 +02:00
|
|
|
public class Claim extends SubCommand {
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2014-10-11 09:33:10 +02:00
|
|
|
public Claim() {
|
2014-10-12 09:37:36 +02:00
|
|
|
super(Command.CLAIM, "Claim the current plot you're standing on.", "claim", CommandCategory.CLAIMING);
|
2014-10-11 09:33:10 +02:00
|
|
|
}
|
2014-09-24 14:21:43 +02:00
|
|
|
|
2014-10-11 09:33:10 +02:00
|
|
|
@Override
|
|
|
|
public boolean execute(Player plr, String... args) {
|
|
|
|
String schematic = "";
|
|
|
|
if (args.length >= 1) {
|
|
|
|
schematic = args[0];
|
|
|
|
}
|
|
|
|
if (!PlayerFunctions.isInPlot(plr)) {
|
|
|
|
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-12 09:37:36 +02:00
|
|
|
if (PlayerFunctions.getPlayerPlotCount(plr.getWorld(), plr) >= PlayerFunctions.getAllowedPlots(plr)) {
|
2014-10-11 09:33:10 +02:00
|
|
|
PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
|
|
|
if (plot.hasOwner()) {
|
|
|
|
PlayerFunctions.sendMessage(plr, C.PLOT_IS_CLAIMED);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
PlotWorld world = PlotMain.getWorldSettings(plot.getWorld());
|
|
|
|
if (PlotMain.useEconomy && world.USE_ECONOMY) {
|
|
|
|
double cost = world.PLOT_PRICE;
|
|
|
|
if (cost > 0d) {
|
|
|
|
Economy economy = PlotMain.economy;
|
|
|
|
if (economy.getBalance(plr) < cost) {
|
|
|
|
sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
economy.withdrawPlayer(plr, cost);
|
|
|
|
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!schematic.equals("")) {
|
|
|
|
if (world.SCHEMATIC_CLAIM_SPECIFY) {
|
|
|
|
if (!world.SCHEMATICS.contains(schematic.toLowerCase())) {
|
2014-10-12 09:37:36 +02:00
|
|
|
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
|
2014-10-11 09:33:10 +02:00
|
|
|
return true;
|
|
|
|
}
|
2014-10-12 09:37:36 +02:00
|
|
|
if (!plr.hasPermission("plots.claim." + schematic) && !plr.hasPermission("plots.admin")) {
|
|
|
|
PlayerFunctions.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic);
|
2014-10-11 09:33:10 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
boolean result = claimPlot(plr, plot, false, schematic);
|
|
|
|
if (result) {
|
|
|
|
PlayerFunctions.sendMessage(plr, C.PLOT_NOT_CLAIMED);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2014-10-11 09:33:10 +02:00
|
|
|
}
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2014-10-11 09:33:10 +02:00
|
|
|
public static boolean claimPlot(Player player, Plot plot, boolean teleport) {
|
|
|
|
return claimPlot(player, plot, teleport, "");
|
|
|
|
}
|
2014-09-28 10:21:18 +02:00
|
|
|
|
2014-10-12 09:37:36 +02:00
|
|
|
public static boolean claimPlot(Player player, Plot plot, boolean teleport, String schematic) {
|
2014-10-11 09:33:10 +02:00
|
|
|
PlayerClaimPlotEvent event = new PlayerClaimPlotEvent(player, plot);
|
|
|
|
Bukkit.getPluginManager().callEvent(event);
|
|
|
|
if (!event.isCancelled()) {
|
|
|
|
PlotHelper.createPlot(player, plot);
|
|
|
|
PlotHelper.setSign(player, plot);
|
|
|
|
PlayerFunctions.sendMessage(player, C.CLAIMED);
|
|
|
|
if (teleport) {
|
|
|
|
PlotMain.teleportPlayer(player, player.getLocation(), plot);
|
|
|
|
}
|
|
|
|
PlotWorld world = PlotMain.getWorldSettings(plot.getWorld());
|
|
|
|
if (world.SCHEMATIC_ON_CLAIM) {
|
|
|
|
SchematicHandler handler = new SchematicHandler();
|
|
|
|
SchematicHandler.Schematic sch;
|
|
|
|
if (schematic.equals("")) {
|
|
|
|
sch = handler.getSchematic(world.SCHEMATIC_FILE);
|
2014-10-12 09:37:36 +02:00
|
|
|
}
|
|
|
|
else {
|
2014-10-11 09:33:10 +02:00
|
|
|
sch = handler.getSchematic(schematic);
|
|
|
|
if (sch == null) {
|
|
|
|
sch = handler.getSchematic(world.SCHEMATIC_FILE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
handler.paste(player.getLocation(), sch, plot);
|
|
|
|
}
|
2014-10-12 09:37:36 +02:00
|
|
|
plot.settings.setFlags(FlagManager.parseFlags(PlotMain.getWorldSettings(player.getWorld()).DEFAULT_FLAGS));
|
2014-10-11 09:33:10 +02:00
|
|
|
}
|
|
|
|
return event.isCancelled();
|
|
|
|
}
|
2014-09-22 13:02:14 +02:00
|
|
|
}
|