Megaplots are pretty much done now

I still need to finish the unlinking, currently it doesn't recreate the
roads, but that's not a big deal.
This commit is contained in:
boy0001 2014-09-26 18:07:24 +10:00
parent 49f93cfb25
commit d0ec93b15c
6 changed files with 151 additions and 45 deletions

View File

@ -55,6 +55,7 @@ public enum C {
*/ */
NO_PERMISSION("&cYou don't have the permissions required to use this command."), NO_PLOT_PERMS("&cYou don't have the permissions to do that in this plot"), CANT_CLAIM_MORE_PLOTS("&cYou can't claim more plots."), YOU_BE_DENIED("&cYou are not allowed to enter this plot"), NO_PERMISSION("&cYou don't have the permissions required to use this command."), NO_PLOT_PERMS("&cYou don't have the permissions to do that in this plot"), CANT_CLAIM_MORE_PLOTS("&cYou can't claim more plots."), YOU_BE_DENIED("&cYou are not allowed to enter this plot"),
NO_PERM_MERGE("&cYou are not the owner of the plot: &6%plot%"), UNLINK_REQUIRED("&cAn unlink is required to do this."), UNLINK_IMPOSSIBLE("&cYou can only unlink a mega-plot"), NO_PERM_MERGE("&cYou are not the owner of the plot: &6%plot%"), UNLINK_REQUIRED("&cAn unlink is required to do this."), UNLINK_IMPOSSIBLE("&cYou can only unlink a mega-plot"),
NO_MERGE_TO_MEGA("&cMega plots cannot be merged into. Please merge from the desired mega plot."),
/* /*
* Commands * Commands
*/ */

View File

@ -194,7 +194,6 @@ public class PlayerFunctions {
// This is the road separating an Eastern and Western plot // This is the road separating an Eastern and Western plot
PlotId id = getPlotAbs(loc.add(plotworld.ROAD_WIDTH, 0, 0)); PlotId id = getPlotAbs(loc.add(plotworld.ROAD_WIDTH, 0, 0));
Plot plot = PlotMain.getPlots(loc.getWorld()).get(id); Plot plot = PlotMain.getPlots(loc.getWorld()).get(id);
System.out.print("IDS "+id);
if (plot==null) { if (plot==null) {
return null; return null;
} }

View File

@ -76,12 +76,24 @@ public class PlotHelper {
* @param greaterPlot * @param greaterPlot
*/ */
public static void mergePlot(World world, Plot lesserPlot, Plot greaterPlot) { public static void mergePlot(World world, Plot lesserPlot, Plot greaterPlot) {
Location pos1 = getPlotTopLoc(world, lesserPlot.id); Location pos1 = getPlotBottomLocAbs(world, lesserPlot.id).add(1,0,1);
Location pos2 = getPlotTopLoc(world, lesserPlot.id); Location pos2 = getPlotTopLocAbs(world, lesserPlot.id);
int startx = Math.min(pos1.getBlockX(),pos2.getBlockX());
int endx = Math.max(pos1.getBlockX(),pos2.getBlockX()); Location pos3 = getPlotBottomLocAbs(world, greaterPlot.id).add(1,0,1);
int startz = Math.min(pos1.getBlockZ(),pos2.getBlockZ()); Location pos4 = getPlotTopLocAbs(world, greaterPlot.id);
int endz = Math.max(pos1.getBlockZ(),pos2.getBlockZ());
int sx = Math.max(pos1.getBlockX(),pos2.getBlockX());
int ex = Math.min(pos3.getBlockX(),pos4.getBlockX());
int sz = Math.max(pos1.getBlockZ(),pos2.getBlockZ());
int ez = Math.min(pos3.getBlockZ(),pos4.getBlockZ());
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;
System.out.print("X "+startx+" | "+endx);
System.out.print("Z "+startz+" | "+endz);
PlotWorld plotworld = PlotMain.getWorldSettings(world); PlotWorld plotworld = PlotMain.getWorldSettings(world);
@ -92,40 +104,30 @@ public class PlotHelper {
final short[] filling_data = 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++) { for (int i = 0; i < plotworld.TOP_BLOCK.length; i++) {
Short[] result = getBlock(plotworld.TOP_BLOCK[i]); short[] result = getBlock(plotworld.TOP_BLOCK[i]);
plotfloors[i] = result[0]; plotfloors[i] = result[0];
plotfloors_data[i] = result[1]; plotfloors_data[i] = result[1];
} }
for (int i = 0; i < plotworld.MAIN_BLOCK.length; i++) { for (int i = 0; i < plotworld.MAIN_BLOCK.length; i++) {
Short[] result = getBlock(plotworld.MAIN_BLOCK[i]); short[] result = getBlock(plotworld.MAIN_BLOCK[i]);
filling[i] = result[0]; filling[i] = result[0];
filling_data[i] = result[1]; filling_data[i] = result[1];
} }
if (lesserPlot.id.x == greaterPlot.id.x) { if (lesserPlot.id.x == greaterPlot.id.x) {
// if (lesserPlot.id.y < greaterPlot.id.y) {
lesserPlot.settings.setMerged(2, true); lesserPlot.settings.setMerged(2, true);
greaterPlot.settings.setMerged(0, true); greaterPlot.settings.setMerged(0, true);
startz++; startx--;
endz--; endx++;
// }
// else {
// lesserPlot.settings.setMerged(0, true);
// greaterPlot.settings.setMerged(2, true);
// }
} }
else { else {
// if (lesserPlot.id.x < greaterPlot.id.x) {
lesserPlot.settings.setMerged(1, true); lesserPlot.settings.setMerged(1, true);
greaterPlot.settings.setMerged(3, true); greaterPlot.settings.setMerged(3, true);
startx++; startz--;
endx--; endz++;
// }
// else {
// lesserPlot.settings.setMerged(3, true);
// greaterPlot.settings.setMerged(1, true);
// }
} }
setSimpleCuboid(world, new Location(world, startx, 0, startz), new Location(world, endx, 1, endz), (short) 7); setSimpleCuboid(world, new Location(world, startx, 0, startz), new Location(world, endx, 1, endz), (short) 7);
setSimpleCuboid(world, new Location(world, startx, plotworld.PLOT_HEIGHT + 1, startz), new Location(world, endx, world.getMaxHeight(), endz), (short) 0); setSimpleCuboid(world, new Location(world, startx, plotworld.PLOT_HEIGHT + 1, startz), new Location(world, endx, world.getMaxHeight(), endz), (short) 0);
setCuboid(world, new Location(world, startx, 1, startz), new Location(world, endx, plotworld.PLOT_HEIGHT, endz), filling, filling_data); setCuboid(world, new Location(world, startx, 1, startz), new Location(world, endx, plotworld.PLOT_HEIGHT, endz), filling, filling_data);
@ -543,12 +545,12 @@ public class PlotHelper {
return (square(plotworld.PLOT_WIDTH)) * (world.getMaxHeight()); return (square(plotworld.PLOT_WIDTH)) * (world.getMaxHeight());
} }
public static Short[] getBlock(String block) { public static short[] getBlock(String block) {
if (block.contains(":")) { if (block.contains(":")) {
String[] split = block.split(":"); String[] split = block.split(":");
return new Short[] { Short.parseShort(split[0]), Short.parseShort(split[1]) }; return new short[] { Short.parseShort(split[0]), Short.parseShort(split[1]) };
} }
return new Short[] { Short.parseShort(block), 0 }; return new short[] { Short.parseShort(block), 0 };
} }
/** /**
@ -573,12 +575,12 @@ public class PlotHelper {
final short[] filling_data = 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++) { for (int i = 0; i < plotworld.TOP_BLOCK.length; i++) {
Short[] result = getBlock(plotworld.TOP_BLOCK[i]); short[] result = getBlock(plotworld.TOP_BLOCK[i]);
plotfloors[i] = result[0]; plotfloors[i] = result[0];
plotfloors_data[i] = result[1]; plotfloors_data[i] = result[1];
} }
for (int i = 0; i < plotworld.MAIN_BLOCK.length; i++) { for (int i = 0; i < plotworld.MAIN_BLOCK.length; i++) {
Short[] result = getBlock(plotworld.MAIN_BLOCK[i]); short[] result = getBlock(plotworld.MAIN_BLOCK[i]);
filling[i] = result[0]; filling[i] = result[0];
filling_data[i] = result[1]; filling_data[i] = result[1];
} }
@ -845,6 +847,28 @@ public class PlotHelper {
} }
} }
public static Location getPlotTopLocAbs(World world, PlotId id) {
PlotWorld plotworld = PlotMain.getWorldSettings(world);
int px = id.x;
int pz = id.y;
int x = (px * (plotworld.ROAD_WIDTH + plotworld.PLOT_WIDTH)) - ((int) Math.floor(plotworld.ROAD_WIDTH / 2)) - 1;
int z = (pz * (plotworld.ROAD_WIDTH + plotworld.PLOT_WIDTH)) - ((int) Math.floor(plotworld.ROAD_WIDTH / 2)) - 1;
return new Location(world, x, 255, z);
}
public static Location getPlotBottomLocAbs(World world, PlotId id) {
PlotWorld plotworld = PlotMain.getWorldSettings(world);
int px = id.x;
int pz = id.y;
int x = (px * (plotworld.ROAD_WIDTH + plotworld.PLOT_WIDTH)) - plotworld.PLOT_WIDTH - ((int) Math.floor(plotworld.ROAD_WIDTH / 2)) - 1;
int z = (pz * (plotworld.ROAD_WIDTH + plotworld.PLOT_WIDTH)) - plotworld.PLOT_WIDTH - ((int) Math.floor(plotworld.ROAD_WIDTH / 2)) - 1;
return new Location(world, x, 1, z);
}
public static Location getPlotTopLoc(World world, PlotId id) { public static Location getPlotTopLoc(World world, PlotId id) {
Plot plot = PlotMain.getPlots(world).get(id); Plot plot = PlotMain.getPlots(world).get(id);
if (plot!=null) { if (plot!=null) {

View File

@ -13,6 +13,7 @@ import java.util.ArrayList;
import java.util.Set; import java.util.Set;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -23,6 +24,7 @@ import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.PlotId; import com.intellectualcrafters.plot.PlotId;
import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.PlotWorld; import com.intellectualcrafters.plot.PlotWorld;
import com.intellectualcrafters.plot.SetBlockFast;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
/** /**
@ -96,33 +98,112 @@ public class Merge extends SubCommand {
PlayerFunctions.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString())); PlayerFunctions.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString()));
return false; return false;
} }
if (!PlayerFunctions.getBottomPlot(world, myplot).equals(PlayerFunctions.getTopPlot(world, myplot))) {
PlayerFunctions.sendMessage(plr, C.NO_MERGE_TO_MEGA);
return false;
}
} }
PlayerFunctions.sendMessage(plr, "PLOTS HAVE BEEN MERGED"); 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); 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) { public static boolean mergePlot(World world, Player player, ArrayList<PlotId> currentMegaPlots, ArrayList<PlotId> toMerge, int dir1, int dir2) {
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));
for (PlotId plotid:currentMegaPlots) { for (PlotId plotid:currentMegaPlots) {
Plot plot = PlotMain.getPlots(world).get(plotid); Plot plot = PlotMain.getPlots(world).get(plotid);
plot.settings.setMerged(dir1, true); plot.settings.setMerged(dir1, true);
DBFunc.setMerged(world.getName(), plot, plot.settings.getMerged()); DBFunc.setMerged(world.getName(), plot, plot.settings.getMerged());
} }
for (int i = 0;i < toMerge.size(); i++) { for (int i = 0;i < toMerge.size(); i++) {
PlotId plotid = toMerge.get(i); PlotId plotid = toMerge.get(i);
Plot plot = PlotMain.getPlots(world).get(plotid); Plot plot = PlotMain.getPlots(world).get(plotid);
plot.settings.setMerged(dir2, true); plot.settings.setMerged(dir2, true);
if (i<toMerge.size()-1) {
PlotHelper.mergePlot(world, plot, PlotMain.getPlots(world).get(toMerge.get(i+1)));
}
DBFunc.setMerged(world.getName(), plot, plot.settings.getMerged()); DBFunc.setMerged(world.getName(), plot, plot.settings.getMerged());
} }
try {
SetBlockFast.update(player);
}
catch (Exception e) {
}
PlotWorld plotworld = PlotMain.getWorldSettings(world); PlotWorld plotworld = PlotMain.getWorldSettings(world);
int pathsize = plotworld.ROAD_WIDTH;
int plotheight = 64; 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());
}
//TODO replace road sections
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);
}
}
}
return true; return true;
} }
} }

View File

@ -54,6 +54,7 @@ public class Unlink extends SubCommand {
myplot.settings.setMerged(new boolean[] {false, false, false, false} ); myplot.settings.setMerged(new boolean[] {false, false, false, false} );
DBFunc.setMerged(world.getName(), myplot, myplot.settings.getMerged()); DBFunc.setMerged(world.getName(), myplot, myplot.settings.getMerged());
} }
PlayerFunctions.sendMessage(plr, "&cPLOT UNLINKING IS NOT FINISHED (as you can see by the lack of roads appearing)");
return true; return true;
} }
} }

View File

@ -301,9 +301,9 @@ public class DBFunc {
} }
int merged_int = settings.get("merged") == null ? 0 : (int) settings.get("merged"); int merged_int = settings.get("merged") == null ? 0 : (int) settings.get("merged");
boolean[] merged = new boolean[7]; boolean[] merged = new boolean[4];
for (int i = 6; i >= 0; i--) { for (int i = 0; i < 4; i++) {
merged[i] = (merged_int & (1 << i)) != 0; merged[3-i] = (merged_int & (1 << i)) != 0;
} }
p = new Plot(plot_id, owner, plotBiome, helpers, denied, /* changeTime */false, time, rain, alias, position, flags, worldname, merged); p = new Plot(plot_id, owner, plotBiome, helpers, denied, /* changeTime */false, time, rain, alias, position, flags, worldname, merged);
if (plots.containsKey(worldname)) { if (plots.containsKey(worldname)) {
@ -352,8 +352,8 @@ public class DBFunc {
@Override @Override
public void run() { public void run() {
try { try {
int n = 0, l = merged.length; int n = 0;
for (int i = 0; i < l; ++i) { for (int i = 0; i < 4; ++i) {
n = (n << 1) + (merged[i] ? 1 : 0); n = (n << 1) + (merged[i] ? 1 : 0);
} }
PreparedStatement stmt = connection.prepareStatement("UPDATE `plot_settings` SET `merged` = ? WHERE `plot_plot_id` = ?"); PreparedStatement stmt = connection.prepareStatement("UPDATE `plot_settings` SET `merged` = ? WHERE `plot_plot_id` = ?");