2014-09-26 02:22:25 +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 = Merge.java >> Generated by: Citymonstret at 2014-08-09 01:41
|
2014-09-26 02:22:25 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.intellectualcrafters.plot.commands;
|
|
|
|
|
2014-10-11 09:33:10 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2014-09-29 19:05:03 +02:00
|
|
|
import net.milkbowl.vault.economy.Economy;
|
2014-10-11 09:33:10 +02:00
|
|
|
|
2014-09-26 06:01:30 +02:00
|
|
|
import org.apache.commons.lang.StringUtils;
|
2014-09-26 14:21:14 +02:00
|
|
|
import org.bukkit.Bukkit;
|
2014-09-26 06:01:30 +02:00
|
|
|
import org.bukkit.World;
|
2014-09-26 02:22:25 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2014-10-11 09:33:10 +02:00
|
|
|
import com.intellectualcrafters.plot.C;
|
|
|
|
import com.intellectualcrafters.plot.PlayerFunctions;
|
|
|
|
import com.intellectualcrafters.plot.Plot;
|
|
|
|
import com.intellectualcrafters.plot.PlotHelper;
|
|
|
|
import com.intellectualcrafters.plot.PlotId;
|
|
|
|
import com.intellectualcrafters.plot.PlotMain;
|
|
|
|
import com.intellectualcrafters.plot.PlotWorld;
|
|
|
|
import com.intellectualcrafters.plot.SetBlockFast;
|
|
|
|
import com.intellectualcrafters.plot.events.PlotMergeEvent;
|
2014-09-26 02:22:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Citymonstret
|
|
|
|
*/
|
|
|
|
public class Merge extends SubCommand {
|
|
|
|
|
2014-10-12 09:37:36 +02:00
|
|
|
public static String[] values = new String[] { "north", "east", "south", "west" };
|
2014-10-11 09:33:10 +02:00
|
|
|
public static String[] aliases = new String[] { "n", "e", "s", "w" };
|
2014-10-03 04:36:30 +02:00
|
|
|
|
2014-10-11 09:33:10 +02:00
|
|
|
public Merge() {
|
2014-10-18 20:06:29 +02:00
|
|
|
super(Command.MERGE, "Merge the plot you are standing on with another plot.", "merge", CommandCategory.ACTIONS, true);
|
2014-10-11 09:33:10 +02:00
|
|
|
}
|
2014-09-26 02:22:25 +02:00
|
|
|
|
2014-10-11 09:33:10 +02:00
|
|
|
public static String direction(float yaw) {
|
|
|
|
yaw = yaw / 90;
|
|
|
|
int i = Math.round(yaw);
|
|
|
|
switch (i) {
|
|
|
|
case -4:
|
|
|
|
case 0:
|
|
|
|
case 4:
|
|
|
|
return "SOUTH";
|
|
|
|
case -1:
|
|
|
|
case 3:
|
|
|
|
return "EAST";
|
|
|
|
case -2:
|
|
|
|
case 2:
|
|
|
|
return "NORTH";
|
|
|
|
case -3:
|
|
|
|
case 1:
|
|
|
|
return "WEST";
|
|
|
|
default:
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
2014-10-03 04:36:30 +02:00
|
|
|
|
2014-10-11 09:33:10 +02:00
|
|
|
@Override
|
|
|
|
public boolean execute(Player plr, String... args) {
|
|
|
|
if (!PlayerFunctions.isInPlot(plr)) {
|
|
|
|
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
|
|
|
if ((plot == null) || !plot.hasOwner()) {
|
|
|
|
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!plot.getOwner().equals(plr.getUniqueId())) {
|
|
|
|
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (args.length < 1) {
|
2014-10-12 09:37:36 +02:00
|
|
|
PlayerFunctions.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s()
|
|
|
|
+ StringUtils.join(values, C.BLOCK_LIST_SEPARATER.s()));
|
|
|
|
PlayerFunctions.sendMessage(plr, C.DIRECTION.s().replaceAll("%dir%", direction(plr.getLocation().getYaw())));
|
2014-10-11 09:33:10 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
int direction = -1;
|
|
|
|
for (int i = 0; i < values.length; i++) {
|
2014-10-12 09:37:36 +02:00
|
|
|
if (args[0].equalsIgnoreCase(values[i]) || args[0].equalsIgnoreCase(aliases[i])) {
|
2014-10-11 09:33:10 +02:00
|
|
|
direction = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (direction == -1) {
|
2014-10-12 09:37:36 +02:00
|
|
|
PlayerFunctions.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s()
|
|
|
|
+ StringUtils.join(values, C.BLOCK_LIST_SEPARATER.s()));
|
|
|
|
PlayerFunctions.sendMessage(plr, C.DIRECTION.s().replaceAll("%dir%", direction(plr.getLocation().getYaw())));
|
2014-10-11 09:33:10 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
World world = plr.getWorld();
|
|
|
|
PlotId bot = PlayerFunctions.getBottomPlot(world, plot).id;
|
|
|
|
PlotId top = PlayerFunctions.getTopPlot(world, plot).id;
|
|
|
|
ArrayList<PlotId> plots;
|
|
|
|
switch (direction) {
|
|
|
|
case 0: // north = -y
|
2014-10-12 09:37:36 +02:00
|
|
|
plots =
|
2014-10-13 08:33:37 +02:00
|
|
|
PlayerFunctions.getMaxPlotSelectionIds(plr.getWorld(), new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y));
|
2014-10-11 09:33:10 +02:00
|
|
|
break;
|
|
|
|
case 1: // east = +x
|
2014-10-12 09:37:36 +02:00
|
|
|
plots =
|
2014-10-13 08:33:37 +02:00
|
|
|
PlayerFunctions.getMaxPlotSelectionIds(plr.getWorld(), new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y));
|
2014-10-11 09:33:10 +02:00
|
|
|
break;
|
|
|
|
case 2: // south = +y
|
2014-10-12 09:37:36 +02:00
|
|
|
plots =
|
2014-10-13 08:33:37 +02:00
|
|
|
PlayerFunctions.getMaxPlotSelectionIds(plr.getWorld(), new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1));
|
2014-10-11 09:33:10 +02:00
|
|
|
break;
|
|
|
|
case 3: // west = -x
|
2014-10-12 09:37:36 +02:00
|
|
|
plots =
|
2014-10-13 08:33:37 +02:00
|
|
|
PlayerFunctions.getMaxPlotSelectionIds(plr.getWorld(), new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y));
|
2014-10-11 09:33:10 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (PlotId myid : plots) {
|
|
|
|
Plot myplot = PlotMain.getPlots(world).get(myid);
|
2014-10-12 09:37:36 +02:00
|
|
|
if ((myplot == null) || !myplot.hasOwner() || !(myplot.getOwner().equals(plr.getUniqueId()))) {
|
|
|
|
PlayerFunctions.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString()));
|
2014-10-11 09:33:10 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2014-09-29 19:05:03 +02:00
|
|
|
|
2014-10-11 09:33:10 +02:00
|
|
|
PlotWorld plotWorld = PlotMain.getWorldSettings(world);
|
|
|
|
if (PlotMain.useEconomy && plotWorld.USE_ECONOMY) {
|
|
|
|
double cost = plotWorld.MERGE_PRICE;
|
|
|
|
cost = plots.size() * cost;
|
|
|
|
if (cost > 0d) {
|
|
|
|
Economy economy = PlotMain.economy;
|
|
|
|
if (economy.getBalance(plr) < cost) {
|
|
|
|
sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + "");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
economy.withdrawPlayer(plr, cost);
|
|
|
|
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
|
|
|
|
}
|
|
|
|
}
|
2014-09-29 19:05:03 +02:00
|
|
|
|
2014-10-11 09:33:10 +02:00
|
|
|
PlotMergeEvent event = new PlotMergeEvent(world, plot, plots);
|
2014-10-03 04:36:30 +02:00
|
|
|
|
2014-10-11 09:33:10 +02:00
|
|
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
event.setCancelled(true);
|
|
|
|
PlayerFunctions.sendMessage(plr, "&cMerge has been cancelled");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
PlayerFunctions.sendMessage(plr, "&cPlots have been merged");
|
|
|
|
PlotHelper.mergePlots(world, plots);
|
|
|
|
if (PlotHelper.canSetFast) {
|
|
|
|
SetBlockFast.update(plr);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2014-09-26 02:22:25 +02:00
|
|
|
}
|