2014-09-26 10:22:25 +10: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
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.intellectualcrafters.plot.commands;
|
|
|
|
|
2014-09-26 14:01:30 +10:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
2014-09-26 18:07:24 +10:00
|
|
|
import org.bukkit.Location;
|
2014-09-26 14:01:30 +10:00
|
|
|
import org.bukkit.World;
|
2014-09-26 10:22:25 +10:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import com.intellectualcrafters.plot.C;
|
|
|
|
import com.intellectualcrafters.plot.PlayerFunctions;
|
|
|
|
import com.intellectualcrafters.plot.Plot;
|
2014-09-26 14:01:30 +10:00
|
|
|
import com.intellectualcrafters.plot.PlotHelper;
|
|
|
|
import com.intellectualcrafters.plot.PlotId;
|
|
|
|
import com.intellectualcrafters.plot.PlotMain;
|
2014-09-26 15:18:13 +10:00
|
|
|
import com.intellectualcrafters.plot.PlotWorld;
|
2014-09-26 18:07:24 +10:00
|
|
|
import com.intellectualcrafters.plot.SetBlockFast;
|
2014-09-26 14:01:30 +10:00
|
|
|
import com.intellectualcrafters.plot.database.DBFunc;
|
2014-09-26 10:22:25 +10:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author Citymonstret
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class Merge extends SubCommand {
|
|
|
|
|
2014-09-26 14:01:30 +10:00
|
|
|
public static String[] values = new String[] { "north", "east", "south", "west" };
|
|
|
|
public static String[] aliases = new String[] { "n", "e", "s", "w"};
|
|
|
|
|
2014-09-26 10:22:25 +10:00
|
|
|
public Merge() {
|
2014-09-26 14:01:30 +10:00
|
|
|
super(Command.MERGE, "Merge the plot you are standing on with another plot.", "merge", CommandCategory.ACTIONS);
|
2014-09-26 10:22:25 +10: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);
|
2014-09-26 14:01:30 +10:00
|
|
|
if (plot==null || !plot.hasOwner()) {
|
2014-09-26 10:22:25 +10:00
|
|
|
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!plot.getOwner().equals(plr.getUniqueId())) {
|
|
|
|
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-26 14:01:30 +10:00
|
|
|
if (args.length<1) {
|
|
|
|
PlayerFunctions.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringUtils.join(values,C.BLOCK_LIST_SEPARATER.s()));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
int direction = -1;
|
|
|
|
for (int i = 0; i<values.length; i++) {
|
|
|
|
if (args[0].equalsIgnoreCase(values[i]) || args[0].equalsIgnoreCase(aliases[i])) {
|
|
|
|
direction = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int direction2 = direction > 1 ? direction-2 : direction+2;
|
|
|
|
if (direction==-1) {
|
|
|
|
PlayerFunctions.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringUtils.join(values,C.BLOCK_LIST_SEPARATER.s()));
|
|
|
|
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
|
|
|
|
plots = PlayerFunctions.getPlotSelectionIds(plr.getWorld(), new PlotId(bot.x,bot.y-1), new PlotId(top.x,bot.y-1));
|
|
|
|
break;
|
|
|
|
case 1: // east = +x
|
|
|
|
plots = PlayerFunctions.getPlotSelectionIds(plr.getWorld(), new PlotId(top.x+1,bot.y), new PlotId(top.x+1,top.y));
|
|
|
|
break;
|
|
|
|
case 2: // south = +y
|
|
|
|
plots = PlayerFunctions.getPlotSelectionIds(plr.getWorld(), new PlotId(bot.x,top.y+1), new PlotId(top.x,top.y+1));
|
|
|
|
break;
|
|
|
|
case 3: // west = -x
|
|
|
|
plots = PlayerFunctions.getPlotSelectionIds(plr.getWorld(), new PlotId(bot.x-1,bot.y), new PlotId(bot.x-1,top.y));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (PlotId myid:plots) {
|
|
|
|
Plot myplot = PlotMain.getPlots(world).get(myid);
|
|
|
|
if (myplot==null || !myplot.hasOwner() || !(myplot.getOwner().equals(plr.getUniqueId()))) {
|
|
|
|
PlayerFunctions.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString()));
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-26 18:07:24 +10:00
|
|
|
if (!PlayerFunctions.getBottomPlot(world, myplot).equals(PlayerFunctions.getTopPlot(world, myplot))) {
|
|
|
|
PlayerFunctions.sendMessage(plr, C.NO_MERGE_TO_MEGA);
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-26 14:01:30 +10:00
|
|
|
}
|
|
|
|
PlayerFunctions.sendMessage(plr, "PLOTS HAVE BEEN MERGED");
|
|
|
|
return mergePlot(world, plr, PlayerFunctions.getPlotSelectionIds(plr.getWorld(), new PlotId(bot.x,bot.y), new PlotId(top.x,top.y)), plots, direction, direction2);
|
|
|
|
}
|
|
|
|
public static boolean mergePlot(World world, Player player, ArrayList<PlotId> currentMegaPlots, ArrayList<PlotId> toMerge, int dir1, int dir2) {
|
2014-09-26 18:07:24 +10:00
|
|
|
|
|
|
|
Location pos1 = PlotHelper.getPlotBottomLoc(world, currentMegaPlots.get(0)).add(1,0,1);
|
|
|
|
Location pos2 = PlotHelper.getPlotTopLoc(world, currentMegaPlots.get(currentMegaPlots.size()-1));
|
|
|
|
|
|
|
|
for (int i = 0;i < toMerge.size(); i++) {
|
|
|
|
PlotId plotid = toMerge.get(i);
|
|
|
|
Plot plot = PlotMain.getPlots(world).get(plotid);
|
|
|
|
if (i<toMerge.size()-1) {
|
|
|
|
PlotHelper.mergePlot(world, plot, PlotMain.getPlots(world).get(toMerge.get(i+1)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
System.out.print("OLD: "+currentMegaPlots.size());
|
|
|
|
System.out.print("NEW: "+toMerge.size());
|
|
|
|
|
|
|
|
Location pos3 = PlotHelper.getPlotBottomLoc(world, toMerge.get(0)).add(1,0,1);
|
|
|
|
Location pos4 = PlotHelper.getPlotTopLoc(world, toMerge.get(toMerge.size()-1));
|
|
|
|
|
2014-09-26 14:01:30 +10:00
|
|
|
for (PlotId plotid:currentMegaPlots) {
|
2014-09-26 18:07:24 +10:00
|
|
|
Plot plot = PlotMain.getPlots(world).get(plotid);
|
2014-09-26 14:01:30 +10:00
|
|
|
plot.settings.setMerged(dir1, true);
|
|
|
|
DBFunc.setMerged(world.getName(), plot, plot.settings.getMerged());
|
|
|
|
}
|
2014-09-26 18:07:24 +10:00
|
|
|
|
2014-09-26 14:01:30 +10:00
|
|
|
for (int i = 0;i < toMerge.size(); i++) {
|
|
|
|
PlotId plotid = toMerge.get(i);
|
2014-09-26 18:07:24 +10:00
|
|
|
Plot plot = PlotMain.getPlots(world).get(plotid);
|
2014-09-26 14:01:30 +10:00
|
|
|
plot.settings.setMerged(dir2, true);
|
|
|
|
DBFunc.setMerged(world.getName(), plot, plot.settings.getMerged());
|
|
|
|
}
|
2014-09-26 10:22:25 +10:00
|
|
|
|
2014-09-26 18:07:24 +10:00
|
|
|
try {
|
|
|
|
SetBlockFast.update(player);
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-09-26 15:18:13 +10:00
|
|
|
PlotWorld plotworld = PlotMain.getWorldSettings(world);
|
|
|
|
|
2014-09-26 18:07:24 +10:00
|
|
|
int sx,sz,ex,ez;
|
|
|
|
|
|
|
|
if (dir1 == 0 || dir1 == 3) {
|
|
|
|
sx = Math.min(pos1.getBlockX(),pos2.getBlockX());
|
|
|
|
ex = Math.max(pos3.getBlockX(),pos4.getBlockX());
|
|
|
|
sz = Math.min(pos1.getBlockZ(),pos2.getBlockZ());
|
|
|
|
ez = Math.max(pos3.getBlockZ(),pos4.getBlockZ());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sx = Math.max(pos1.getBlockX(),pos2.getBlockX());
|
|
|
|
ex = Math.min(pos3.getBlockX(),pos4.getBlockX());
|
|
|
|
sz = Math.max(pos1.getBlockZ(),pos2.getBlockZ());
|
|
|
|
ez = Math.min(pos3.getBlockZ(),pos4.getBlockZ());
|
|
|
|
}
|
2014-09-26 15:18:13 +10:00
|
|
|
|
2014-09-26 10:22:25 +10:00
|
|
|
|
2014-09-26 18:07:24 +10:00
|
|
|
|
|
|
|
int startx = Math.min(sx,ex);
|
|
|
|
int startz = Math.min(sz,ez);
|
|
|
|
int endx = Math.max(sx,ex)+1;
|
|
|
|
int endz = Math.max(sz,ez)+1;
|
|
|
|
|
|
|
|
final short[] plotfloors = new short[plotworld.TOP_BLOCK.length];
|
|
|
|
final short[] plotfloors_data = new short[plotworld.TOP_BLOCK.length];
|
|
|
|
|
|
|
|
final short[] filling = new short[plotworld.MAIN_BLOCK.length];
|
|
|
|
final short[] filling_data = new short[plotworld.MAIN_BLOCK.length];
|
|
|
|
|
|
|
|
for (int i = 0; i < plotworld.TOP_BLOCK.length; i++) {
|
|
|
|
short[] result = PlotHelper.getBlock(plotworld.TOP_BLOCK[i]);
|
|
|
|
plotfloors[i] = result[0];
|
|
|
|
plotfloors_data[i] = result[1];
|
|
|
|
}
|
|
|
|
for (int i = 0; i < plotworld.MAIN_BLOCK.length; i++) {
|
|
|
|
short[] result = PlotHelper.getBlock(plotworld.MAIN_BLOCK[i]);
|
|
|
|
filling[i] = result[0];
|
|
|
|
filling_data[i] = result[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
PlotHelper.setSimpleCuboid(world, new Location(world, startx, 0, startz), new Location(world, endx, 1, endz), (short) 7);
|
|
|
|
PlotHelper.setSimpleCuboid(world, new Location(world, startx, plotworld.PLOT_HEIGHT + 1, startz), new Location(world, endx, world.getMaxHeight(), endz), (short) 0);
|
|
|
|
PlotHelper.setCuboid(world, new Location(world, startx, 1, startz), new Location(world, endx, plotworld.PLOT_HEIGHT, endz), filling, filling_data);
|
|
|
|
PlotHelper.setCuboid(world, new Location(world, startx, plotworld.PLOT_HEIGHT, startz), new Location(world, endx, plotworld.PLOT_HEIGHT + 1, endz), plotfloors, plotfloors_data);
|
|
|
|
|
|
|
|
pos1 = PlotHelper.getPlotBottomLoc(world, currentMegaPlots.get(0));
|
|
|
|
pos2 = PlotHelper.getPlotTopLoc(world, currentMegaPlots.get(0)).add(1,0,1);
|
|
|
|
|
|
|
|
short[] result_w = PlotHelper.getBlock(plotworld.WALL_BLOCK);
|
|
|
|
short w_id = result_w[0];
|
|
|
|
byte w_v = (byte) result_w[1];
|
|
|
|
|
|
|
|
for (int x = pos1.getBlockX(); x<=pos2.getBlockX(); x++) {
|
|
|
|
for (int z = pos1.getBlockZ(); z<=pos2.getBlockZ(); z++) {
|
|
|
|
if (z == pos1.getBlockZ() || z==pos2.getBlockZ() || x==pos1.getBlockX() || x==pos2.getBlockX()) {
|
|
|
|
world.getBlockAt(x, plotworld.WALL_HEIGHT+1, z).setTypeIdAndData(w_id, w_v, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-09-26 10:22:25 +10:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|