I'm making progress

This commit is contained in:
Jesse Boyd 2014-10-10 22:19:33 -07:00
parent 882c427d2b
commit b50dfcb423
5 changed files with 191 additions and 696 deletions

View File

@ -95,104 +95,21 @@ public class PlayerFunctions {
public static PlotId getPlotAbs(Location loc) { public static PlotId getPlotAbs(Location loc) {
String world = loc.getWorld().getName(); String world = loc.getWorld().getName();
PlotManager manager = PlotMain.getPlotManager(world); PlotManager manager = PlotMain.getPlotManager(world);
PlotWorld plotworld = PlotMain.getWorldSettings(world); if (manager == null) {
PlotId id = manager.getPlotIdAbs(plotworld, loc); return null;
if (id.x == null || id.y == null) {
return null;
} }
PlotWorld plotworld = PlotMain.getWorldSettings(world);
return id; return manager.getPlotIdAbs(plotworld, loc);
} }
public static PlotId getPlot(Location loc) { public static PlotId getPlot(Location loc) {
String world = loc.getWorld().getName();
PlotId plotid = getPlotAbs(loc); PlotManager manager = PlotMain.getPlotManager(world);
if (manager == null) {
if (plotid == null) { return null;
} }
return plotid;
int x = loc.getBlockX();
int z = loc.getBlockZ();
String world = loc.getWorld().getName();
PlotWorld plotworld = PlotMain.getWorldSettings(world); PlotWorld plotworld = PlotMain.getWorldSettings(world);
if (plotworld == null) { return manager.getPlotId(plotworld, loc);
return null;
}
int size = plotworld.PLOT_WIDTH + plotworld.ROAD_WIDTH;
int pathWidthLower;
if ((plotworld.ROAD_WIDTH % 2) == 0) {
pathWidthLower = (int) (Math.floor(plotworld.ROAD_WIDTH / 2) - 1);
} else {
pathWidthLower = (int) Math.floor(plotworld.ROAD_WIDTH / 2);
}
int dx = x / size;
int dz = z / size;
if (x < 0) {
dx--;
x += ((-dx) * size);
}
if (z < 0) {
dz--;
z += ((-dz) * size);
}
int rx = (x) % size;
int rz = (z) % size;
int end = pathWidthLower + plotworld.PLOT_WIDTH;
boolean northSouth = (rz <= pathWidthLower) || (rz > end);
boolean eastWest = (rx <= pathWidthLower) || (rx > end);
if (northSouth && eastWest) {
// This means you are in the intersection
PlotId id = getPlotAbs(loc.add(plotworld.ROAD_WIDTH, 0, plotworld.ROAD_WIDTH));
Plot plot = PlotMain.getPlots(loc.getWorld()).get(id);
if (plot == null) {
return null;
}
if ((plot.settings.getMerged(0) && plot.settings.getMerged(3))) {
return getBottomPlot(loc.getWorld(), plot).id;
}
return null;
}
if (northSouth) {
// You are on a road running West to East (yeah, I named the var
// poorly)
PlotId id = getPlotAbs(loc.add(0, 0, plotworld.ROAD_WIDTH));
Plot plot = PlotMain.getPlots(loc.getWorld()).get(id);
if (plot == null) {
return null;
}
if (plot.settings.getMerged(0)) {
return getBottomPlot(loc.getWorld(), plot).id;
}
return null;
}
if (eastWest) {
// This is the road separating an Eastern and Western plot
PlotId id = getPlotAbs(loc.add(plotworld.ROAD_WIDTH, 0, 0));
Plot plot = PlotMain.getPlots(loc.getWorld()).get(id);
if (plot == null) {
return null;
}
if (plot.settings.getMerged(3)) {
return getBottomPlot(loc.getWorld(), plot).id;
}
return null;
}
PlotId id = new PlotId(dx + 1, dz + 1);
Plot plot = PlotMain.getPlots(loc.getWorld()).get(id);
if (plot == null) {
return id;
}
return getBottomPlot(loc.getWorld(), plot).id;
} }
/** /**
@ -218,7 +135,6 @@ public class PlayerFunctions {
* @param player * @param player
* @return * @return
*/ */
@SuppressWarnings("deprecation")
public static Plot getCurrentPlot(Player player) { public static Plot getCurrentPlot(Player player) {
if (!PlotMain.isPlotWorld(player.getWorld())) { if (!PlotMain.isPlotWorld(player.getWorld())) {
return null; return null;

View File

@ -10,7 +10,9 @@
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -89,34 +91,15 @@ public class PlotHelper {
* @return boolean (success) * @return boolean (success)
*/ */
public static boolean mergePlots(World world, ArrayList<PlotId> plotIds) { public static boolean mergePlots(World world, ArrayList<PlotId> plotIds) {
PlotWorld plotworld = PlotMain.getWorldSettings(world);
int pathsize = plotworld.ROAD_WIDTH;
int plotheight = plotworld.PLOT_HEIGHT;
if (plotIds.size() < 2) { if (plotIds.size() < 2) {
return false; return false;
} }
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 = 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 = getBlock(plotworld.MAIN_BLOCK[i]);
filling[i] = result[0];
filling_data[i] = result[1];
}
PlotId pos1 = plotIds.get(0); PlotId pos1 = plotIds.get(0);
PlotId pos2 = plotIds.get(plotIds.size() - 1); PlotId pos2 = plotIds.get(plotIds.size() - 1);
PlotManager manager = PlotMain.getPlotManager(world);
PlotWorld plotworld = PlotMain.getWorldSettings(world);
for (int x = pos1.x; x <= pos2.x; x++) { for (int x = pos1.x; x <= pos2.x; x++) {
for (int y = pos1.y; y <= pos2.y; y++) { for (int y = pos1.y; y <= pos2.y; y++) {
@ -129,17 +112,7 @@ public class PlotHelper {
if (lx) { if (lx) {
if (ly) { if (ly) {
if (!plot.settings.getMerged(1) || !plot.settings.getMerged(2)) { if (!plot.settings.getMerged(1) || !plot.settings.getMerged(2)) {
Location loc = getPlotTopLocAbs(world, id); manager.createRoadSouthEast(plotworld, plot);
int sx = loc.getBlockX() + 1;
int ex = (sx + pathsize) - 1;
int sz = loc.getBlockZ() + 1;
int ez = (sz + pathsize) - 1;
PlotHelper.setSimpleCuboid(world, new Location(world, sx, plotheight + 1, sz), new Location(world, ex + 1, 257 + 1, ez + 1), (short) 0);
PlotHelper.setCuboid(world, new Location(world, sx + 1, 1, sz + 1), new Location(world, ex, plotheight, ez), filling, filling_data);
PlotHelper.setCuboid(world, new Location(world, sx + 1, plotheight, sz + 1), new Location(world, ex, plotheight + 1, ez), plotfloors, plotfloors_data);
} }
} }
if (!plot.settings.getMerged(1)) { if (!plot.settings.getMerged(1)) {
@ -160,22 +133,8 @@ public class PlotHelper {
} }
} }
Location megaPlotBot = getPlotBottomLoc(world, pos1); manager.finishPlotMerge(world, plotworld, plotIds);
Location megaPlotTop = getPlotTopLoc(world, pos2).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 = megaPlotBot.getBlockX(); x <= megaPlotTop.getBlockX(); x++) {
for (int z = megaPlotBot.getBlockZ(); z <= megaPlotTop.getBlockZ(); z++) {
if ((z == megaPlotBot.getBlockZ()) || (z == megaPlotTop.getBlockZ()) || (x == megaPlotBot.getBlockX()) || (x == megaPlotTop.getBlockX())) {
world.getBlockAt(x, plotworld.WALL_HEIGHT + 1, z).setTypeIdAndData(w_id, w_v, false);
}
}
}
return true; return true;
} }
@ -191,67 +150,21 @@ 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 = getPlotBottomLocAbs(world, lesserPlot.id).add(1, 0, 1); PlotManager manager = PlotMain.getPlotManager(world);
Location pos2 = getPlotTopLocAbs(world, lesserPlot.id);
Location pos3 = getPlotBottomLocAbs(world, greaterPlot.id).add(1, 0, 1);
Location pos4 = getPlotTopLocAbs(world, greaterPlot.id);
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;
PlotWorld plotworld = PlotMain.getWorldSettings(world); PlotWorld plotworld = PlotMain.getWorldSettings(world);
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 = 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 = getBlock(plotworld.MAIN_BLOCK[i]);
filling[i] = result[0];
filling_data[i] = result[1];
}
boolean noMerge = false;
if (lesserPlot.id.x == greaterPlot.id.x) { if (lesserPlot.id.x == greaterPlot.id.x) {
if (!lesserPlot.settings.getMerged(2)) {
noMerge = lesserPlot.settings.getMerged(2); lesserPlot.settings.setMerged(2, true);
greaterPlot.settings.setMerged(0, true);
lesserPlot.settings.setMerged(2, true); manager.createRoadSouth(plotworld, lesserPlot);
greaterPlot.settings.setMerged(0, true); }
startx--;
endx++;
} else { } else {
if (!lesserPlot.settings.getMerged(1)) {
noMerge = lesserPlot.settings.getMerged(1); lesserPlot.settings.setMerged(1, true);
greaterPlot.settings.setMerged(3, true);
lesserPlot.settings.setMerged(1, true); manager.createRoadSouth(plotworld, lesserPlot);
greaterPlot.settings.setMerged(3, true); }
startz--;
endz++;
}
if (!noMerge) {
DBFunc.setMerged(world.getName(), lesserPlot, lesserPlot.settings.getMerged());
DBFunc.setMerged(world.getName(), greaterPlot, greaterPlot.settings.getMerged());
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);
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, plotworld.PLOT_HEIGHT, startz), new Location(world, endx, plotworld.PLOT_HEIGHT + 1, endz), plotfloors, plotfloors_data);
} }
} }
@ -277,18 +190,20 @@ public class PlotHelper {
} }
public static void removeSign(Player plr, Plot p) { public static void removeSign(Player plr, Plot p) {
PlotWorld plotworld = PlotMain.getWorldSettings(Bukkit.getWorld(p.world)); World world = plr.getWorld();
Location pl = new Location(plr.getWorld(), getPlotBottomLoc(plr.getWorld(), p.id).getBlockX(), plotworld.ROAD_HEIGHT + 1, getPlotBottomLoc(plr.getWorld(), p.id).getBlockZ()); PlotManager manager = PlotMain.getPlotManager(world);
Block bs = pl.add(0, 0, -1).getBlock(); PlotWorld plotworld = PlotMain.getWorldSettings(world);
bs.setType(Material.AIR); Location loc = manager.getSignLoc(plr, plotworld, p);
loc.getBlock().setType(Material.AIR);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static void setSign(Player plr, Plot p) { public static void setSign(Player plr, Plot p) {
World world = Bukkit.getWorld(p.world); World world = plr.getWorld();
PlotManager manager = PlotMain.getPlotManager(world);
PlotWorld plotworld = PlotMain.getWorldSettings(world); PlotWorld plotworld = PlotMain.getWorldSettings(world);
Location pl = new Location(world, getPlotBottomLoc(world, p.id).getBlockX(), plotworld.ROAD_HEIGHT + 1, getPlotBottomLoc(world, p.id).getBlockZ()); Location loc = manager.getSignLoc(plr, plotworld, p);
Block bs = pl.add(0, 0, -1).getBlock(); Block bs = loc.getBlock();
bs.setType(Material.AIR); bs.setType(Material.AIR);
bs.setTypeIdAndData(Material.WALL_SIGN.getId(), (byte) 2, false); bs.setTypeIdAndData(Material.WALL_SIGN.getId(), (byte) 2, false);
String id = p.id.y + ";" + p.id.x; String id = p.id.y + ";" + p.id.x;
@ -317,48 +232,40 @@ public class PlotHelper {
} }
return string; return string;
} }
public static void setBlock(Block block, PlotBlock plotblock) {
if (canSetFast) {
if (block.getTypeId() != plotblock.id && plotblock.data != block.getData()) {
try {
SetBlockFast.set(block.getWorld(), block.getX(), block.getY(), block.getZ(), plotblock.id, plotblock.data);
return;
} catch (NoSuchMethodException e) {
canSetFast = false;
}
}
}
if (block.getData() == plotblock.data) {
if (block.getTypeId() != plotblock.id) {
block.setTypeId(plotblock.id);
}
}
else {
if (block.getTypeId() == plotblock.id) {
block.setData(plotblock.data);
}
else {
block.setTypeIdAndData(plotblock.id, plotblock.data, false);
}
}
}
public static void adjustWall(World w, Plot plot, short id, byte data) { public static void adjustWall(Player player, World w, Plot plot, short id, byte data) {
World world = player.getWorld();
PlotWorld plotworld = PlotMain.getWorldSettings(Bukkit.getWorld(plot.world)); PlotManager manager = PlotMain.getPlotManager(world);
PlotWorld plotworld = PlotMain.getWorldSettings(world);
List<String> wallIds = new ArrayList<String>();
manager.setWall(player, plotworld, plot.id, new PlotBlock(id,data));
wallIds.add("" + id + ":" + data);
Location bottom = getPlotBottomLoc(w, plot.id);
Location top = getPlotTopLoc(w, plot.id);
int x, z;
Block block;
for (x = bottom.getBlockX(); x < (top.getBlockX() + 1); x++) {
z = bottom.getBlockZ();
block = w.getBlockAt(x, plotworld.ROAD_HEIGHT + 1, z);
setWall(block, "" + id + ":" + data);
}
for (z = bottom.getBlockZ(); z < (top.getBlockZ() + 1); z++) {
x = top.getBlockX() + 1;
block = w.getBlockAt(x, plotworld.ROAD_HEIGHT + 1, z);
setWall(block, "" + id + ":" + data);
}
for (x = top.getBlockX() + 1; x > (bottom.getBlockX() - 1); x--) {
z = top.getBlockZ() + 1;
block = w.getBlockAt(x, plotworld.ROAD_HEIGHT + 1, z);
setWall(block, "" + id + ":" + data);
}
for (z = top.getBlockZ() + 1; z > (bottom.getBlockZ() - 1); z--) {
x = bottom.getBlockX();
block = w.getBlockAt(x, plotworld.ROAD_HEIGHT + 1, z);
setWall(block, "" + id + ":" + data);
}
} }
public static void autoMerge(World world, Plot plot, Player player) { public static void autoMerge(World world, Plot plot, Player player) {
@ -629,114 +536,38 @@ public class PlotHelper {
public static ArrayList<String> runners_p = new ArrayList<String>(); public static ArrayList<String> runners_p = new ArrayList<String>();
public static HashMap<Plot, Integer> runners = new HashMap<Plot, Integer>(); public static HashMap<Plot, Integer> runners = new HashMap<Plot, Integer>();
public static void adjustWallFilling(final Player requester, final World w, final Plot plot, final short id, final byte data) { public static void adjustWallFilling(final Player requester, final World w, final Plot plot, PlotBlock block) {
if (runners.containsKey(plot)) { if (runners.containsKey(plot)) {
PlayerFunctions.sendMessage(requester, C.WAIT_FOR_TIMER); PlayerFunctions.sendMessage(requester, C.WAIT_FOR_TIMER);
return; return;
} }
PlayerFunctions.sendMessage(requester, C.GENERATING_WALL_FILLING); PlayerFunctions.sendMessage(requester, C.GENERATING_WALL_FILLING);
final PlotWorld plotworld = PlotMain.getWorldSettings(w); World world = requester.getWorld();
runners.put(plot, Bukkit.getScheduler().scheduleSyncRepeatingTask(PlotMain.getMain(), new Runnable() { PlotManager manager = PlotMain.getPlotManager(world);
Location bottom = getPlotBottomLoc(w, plot.id); PlotWorld plotworld = PlotMain.getWorldSettings(world);
Location top = getPlotTopLoc(w, plot.id);
int y = plotworld.ROAD_HEIGHT; manager.setWall(requester, plotworld, plot.id, block);
int x, z; PlayerFunctions.sendMessage(requester, C.SET_BLOCK_ACTION_FINISHED);
@Override
public void run() {
for (this.x = this.bottom.getBlockX(); this.x < (this.top.getBlockX() + 1); this.x++) {
this.z = this.bottom.getBlockZ();
setWall(w.getBlockAt(this.x, this.y, this.z), "" + id + ":" + data);
}
for (this.z = this.bottom.getBlockZ(); this.z < (this.top.getBlockZ() + 1); this.z++) {
this.x = this.top.getBlockX() + 1;
setWall(w.getBlockAt(this.x, this.y, this.z), "" + id + ":" + data);
}
for (this.x = this.top.getBlockX() + 1; this.x > (this.bottom.getBlockX() - 1); this.x--) {
this.z = this.top.getBlockZ() + 1;
setWall(w.getBlockAt(this.x, this.y, this.z), "" + id + ":" + data);
}
for (this.z = this.top.getBlockZ() + 1; this.z > (this.bottom.getBlockZ() - 1); this.z--) {
this.x = this.bottom.getBlockX();
setWall(w.getBlockAt(this.x, this.y, this.z), "" + id + ":" + data);
}
this.y--;
if (this.y < 1) {
int runner = runners.get(plot);
runners.remove(plot);
PlayerFunctions.sendMessage(requester, C.SET_BLOCK_ACTION_FINISHED);
Bukkit.getScheduler().cancelTask(runner);
}
}
}, 0l, 5l));
} }
public static void setFloor(final Player requester, final Plot plot, final Material material[], final byte data[]) { public static void setFloor(final Player requester, final Plot plot, PlotBlock[] blocks) {
final PlotWorld plotworld = PlotMain.getWorldSettings(Bukkit.getWorld(plot.world));
if (runners.containsKey(plot)) { if (runners.containsKey(plot)) {
PlayerFunctions.sendMessage(requester, C.WAIT_FOR_TIMER); PlayerFunctions.sendMessage(requester, C.WAIT_FOR_TIMER);
return; return;
} }
String time = RUtils.formatTime(calculateNeededTime(square(plotworld.PLOT_WIDTH), 2 * plotworld.PLOT_WIDTH));
String send = C.GENERATING_FLOOR.s().replaceAll("%time%", time); PlayerFunctions.sendMessage(requester, C.GENERATING_FLOOR);
PlayerFunctions.sendMessage(requester, send); World world = requester.getWorld();
runners.put(plot, Bukkit.getScheduler().scheduleSyncRepeatingTask(PlotMain.getMain(), new Runnable() { PlotManager manager = PlotMain.getPlotManager(world);
World world = Bukkit.getWorld(plot.world); PlotWorld plotworld = PlotMain.getWorldSettings(world);
int x1 = getPlotBottomLoc(this.world, plot.id).getBlockX(); PlayerFunctions.sendMessage(requester, C.SET_BLOCK_ACTION_FINISHED);
int x2 = this.x1 + plotworld.PLOT_WIDTH; manager.setFloor(requester, plotworld, plot.id, blocks);
int z1 = getPlotBottomLoc(this.world, plot.id).getBlockZ();
int z2 = this.z1 + plotworld.PLOT_WIDTH;
int xMin = Math.min(this.x1, this.x2) + 1;
int xMax = Math.max(this.x1, this.x2);
int zMin = Math.min(this.z1, this.z2) + 1;
int zMax = Math.max(this.z1, this.z2);
Random random = new Random();
int x = this.xMin;
@SuppressWarnings("deprecation")
@Override
public void run() {
for (int z = this.zMin; z <= this.zMax; z++) {
int y = plotworld.PLOT_HEIGHT;
byte d;
short id;
if (material.length > 1) {
int index = this.random.nextInt(material.length);
d = data[index];
id = (short) material[index].getId();
} else {
d = data[0];
id = (short) material[0].getId();
}
this.world.getBlockAt(this.x, y, z).setTypeIdAndData(id, d, true);
}
this.x++;
if (this.x > this.xMax) {
int runner = runners.get(plot);
runners.remove(plot);
PlayerFunctions.sendMessage(requester, C.SET_BLOCK_ACTION_FINISHED);
Bukkit.getScheduler().cancelTask(runner);
}
}
}, 0l, 10l));
} }
public static int square(int x) { public static int square(int x) {
return x * x; return x * x;
} }
public static int getPlotSize(World world) {
PlotWorld plotworld = PlotMain.getWorldSettings(world);
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(":");
@ -778,6 +609,11 @@ public class PlotHelper {
*/ */
public static void clear(final Player requester, final Plot plot) { public static void clear(final Player requester, final Plot plot) {
if (runners.containsKey(plot)) {
PlayerFunctions.sendMessage(requester, C.WAIT_FOR_TIMER);
return;
}
final long start = System.nanoTime(); final long start = System.nanoTime();
final World world = requester.getWorld(); final World world = requester.getWorld();
@ -785,160 +621,28 @@ public class PlotHelper {
* keep * keep
*/ */
clearAllEntities(world, plot, false); clearAllEntities(world, plot, false);
final PlotWorld plotworld = PlotMain.getWorldSettings(world); PlotManager manager = PlotMain.getPlotManager(world);
PlotHelper.setBiome(requester.getWorld(), plot, Biome.FOREST);
PlayerFunctions.sendMessage(requester, C.CLEARING_PLOT);
Location pos1 = PlotHelper.getPlotBottomLoc(world, plot.id).add(1, 0, 1);
final Location pos1 = getPlotBottomLoc(world, plot.id).add(1, 0, 1);
final Location pos2 = getPlotTopLoc(world, plot.id);
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 = 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 = getBlock(plotworld.MAIN_BLOCK[i]);
filling[i] = result[0];
filling_data[i] = result[1];
}
/*
* keep
*/
final int prime = 31; final int prime = 31;
int h = 1; int h = 1;
h = (prime * h) + pos1.getBlockX(); h = (prime * h) + pos1.getBlockX();
h = (prime * h) + pos1.getBlockZ(); h = (prime * h) + pos1.getBlockZ();
state = h; state = h;
if ((pos2.getBlockX() - pos1.getBlockX()) < 16) {
setSimpleCuboid(world, new Location(world, pos1.getBlockX(), 0, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, 1, pos2.getBlockZ() + 1), (short) 7);
setSimpleCuboid(world, new Location(world, pos1.getBlockX(), plotworld.PLOT_HEIGHT + 1, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, world.getMaxHeight() + 1, pos2.getBlockZ() + 1), (short) 0);
setCuboid(world, new Location(world, pos1.getBlockX(), 1, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, plotworld.PLOT_HEIGHT, pos2.getBlockZ() + 1), filling, filling_data);
setCuboid(world, new Location(world, pos1.getBlockX(), plotworld.PLOT_HEIGHT, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, plotworld.PLOT_HEIGHT + 1, pos2.getBlockZ() + 1), plotfloors, plotfloors_data);
PlayerFunctions.sendMessage(requester, "&c(depreciated) &r" + C.CLEARING_DONE.s().replaceAll("%time%", "" + ((System.nanoTime() - start) / 1000000.0)));
return;
}
int startX = (pos1.getBlockX() / 16) * 16;
int startZ = (pos1.getBlockZ() / 16) * 16;
int chunkX = 16 + pos2.getBlockX();
int chunkZ = 16 + pos2.getBlockZ();
Location l1 = getPlotBottomLoc(world, plot.id);
Location l2 = getPlotTopLoc(world, plot.id);
int plotMinX = l1.getBlockX() + 1;
int plotMinZ = l1.getBlockZ() + 1;
int plotMaxX = l2.getBlockX();
int plotMaxZ = l2.getBlockZ();
Location min = null;
Location max = null;
for (int i = startX; i < chunkX; i += 16) {
for (int j = startZ; j < chunkZ; j += 16) {
Plot plot1 = getCurrentPlot(new Location(world, i, 0, j));
if ((plot1 != null) && (plot1.getId() != plot.getId()) && plot1.hasOwner()) {
break;
}
Plot plot2 = getCurrentPlot(new Location(world, i + 15, 0, j));
if ((plot2 != null) && (plot2.getId() != plot.getId()) && plot2.hasOwner()) {
break;
}
Plot plot3 = getCurrentPlot(new Location(world, i + 15, 0, j + 15));
if ((plot3 != null) && (plot3.getId() != plot.getId()) && plot3.hasOwner()) {
break;
}
Plot plot4 = getCurrentPlot(new Location(world, i, 0, j + 15));
if ((plot4 != null) && (plot4.getId() != plot.getId()) && plot4.hasOwner()) {
break;
}
Plot plot5 = getCurrentPlot(new Location(world, i + 15, 0, j + 15));
if ((plot5 != null) && (plot5.getId() != plot.getId()) && plot5.hasOwner()) {
break;
}
if (min == null) {
min = new Location(world, Math.max(i - 1, plotMinX), 0, Math.max(j - 1, plotMinZ));
max = new Location(world, Math.min(i + 16, plotMaxX), 0, Math.min(j + 16, plotMaxZ));
} else if ((max.getBlockZ() < (j + 15)) || (max.getBlockX() < (i + 15))) {
max = new Location(world, Math.min(i + 16, plotMaxX), 0, Math.min(j + 16, plotMaxZ));
}
world.regenerateChunk(i / 16, j / 16);
}
}
if (min == null) {
setSimpleCuboid(world, new Location(world, pos1.getBlockX(), 0, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, 1, pos2.getBlockZ() + 1), (short) 7);
setSimpleCuboid(world, new Location(world, pos1.getBlockX(), plotworld.PLOT_HEIGHT + 1, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, world.getMaxHeight() + 1, pos2.getBlockZ() + 1), (short) 0);
setCuboid(world, new Location(world, pos1.getBlockX(), 1, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, plotworld.PLOT_HEIGHT, pos2.getBlockZ() + 1), filling, filling_data);
setCuboid(world, new Location(world, pos1.getBlockX(), plotworld.PLOT_HEIGHT, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, plotworld.PLOT_HEIGHT + 1, pos2.getBlockZ() + 1), plotfloors, plotfloors_data);
} else {
if (min.getBlockX() < plotMinX) {
min.setX(plotMinX);
}
if (min.getBlockZ() < plotMinZ) {
min.setZ(plotMinZ);
}
if (max.getBlockX() > plotMaxX) {
max.setX(plotMaxX);
}
if (max.getBlockZ() > plotMaxZ) {
max.setZ(plotMaxZ);
}
setSimpleCuboid(world, new Location(world, plotMinX, 0, plotMinZ), new Location(world, min.getBlockX() + 1, 1, min.getBlockZ() + 1), (short) 7);
setSimpleCuboid(world, new Location(world, plotMinX, plotworld.PLOT_HEIGHT + 1, plotMinZ), new Location(world, min.getBlockX() + 1, world.getMaxHeight() + 1, min.getBlockZ() + 1), (short) 0);
setCuboid(world, new Location(world, plotMinX, 1, plotMinZ), new Location(world, min.getBlockX() + 1, plotworld.PLOT_HEIGHT + 1, min.getBlockZ() + 1), filling, filling_data);
setCuboid(world, new Location(world, plotMinX, plotworld.PLOT_HEIGHT, plotMinZ), new Location(world, min.getBlockX() + 1, plotworld.PLOT_HEIGHT + 1, min.getBlockZ() + 1), plotfloors, plotfloors_data);
setSimpleCuboid(world, new Location(world, min.getBlockX(), 0, plotMinZ), new Location(world, max.getBlockX() + 1, 1, min.getBlockZ() + 1), (short) 7);
setSimpleCuboid(world, new Location(world, min.getBlockX(), plotworld.PLOT_HEIGHT + 1, plotMinZ), new Location(world, max.getBlockX() + 1, world.getMaxHeight() + 1, min.getBlockZ() + 1), (short) 0);
setCuboid(world, new Location(world, min.getBlockX(), 1, plotMinZ), new Location(world, max.getBlockX() + 1, plotworld.PLOT_HEIGHT, min.getBlockZ() + 1), filling, filling_data);
setCuboid(world, new Location(world, min.getBlockX(), plotworld.PLOT_HEIGHT, plotMinZ), new Location(world, max.getBlockX() + 1, plotworld.PLOT_HEIGHT + 1, min.getBlockZ() + 1), plotfloors, plotfloors_data);
setSimpleCuboid(world, new Location(world, max.getBlockX(), 0, plotMinZ), new Location(world, plotMaxX + 1, 1, min.getBlockZ() + 1), (short) 7);
setSimpleCuboid(world, new Location(world, max.getBlockX(), plotworld.PLOT_HEIGHT + 1, plotMinZ), new Location(world, plotMaxX + 1, world.getMaxHeight() + 1, min.getBlockZ() + 1), (short) 0);
setCuboid(world, new Location(world, max.getBlockX(), 1, plotMinZ), new Location(world, plotMaxX + 1, plotworld.PLOT_HEIGHT, min.getBlockZ() + 1), filling, filling_data);
setCuboid(world, new Location(world, max.getBlockX(), plotworld.PLOT_HEIGHT, plotMinZ), new Location(world, plotMaxX + 1, plotworld.PLOT_HEIGHT + 1, min.getBlockZ() + 1), plotfloors, plotfloors_data);
setSimpleCuboid(world, new Location(world, plotMinX, 0, min.getBlockZ()), new Location(world, min.getBlockX() + 1, 1, max.getBlockZ() + 1), (short) 7);
setSimpleCuboid(world, new Location(world, plotMinX, plotworld.PLOT_HEIGHT + 1, min.getBlockZ()), new Location(world, min.getBlockX() + 1, world.getMaxHeight() + 1, max.getBlockZ() + 1), (short) 0);
setCuboid(world, new Location(world, plotMinX, 1, min.getBlockZ()), new Location(world, min.getBlockX() + 1, plotworld.PLOT_HEIGHT, max.getBlockZ() + 1), filling, filling_data);
setCuboid(world, new Location(world, plotMinX, plotworld.PLOT_HEIGHT, min.getBlockZ()), new Location(world, min.getBlockX() + 1, plotworld.PLOT_HEIGHT + 1, max.getBlockZ() + 1), plotfloors, plotfloors_data);
setSimpleCuboid(world, new Location(world, plotMinX, 0, max.getBlockZ()), new Location(world, min.getBlockX() + 1, 1, plotMaxZ + 1), (short) 7);
setSimpleCuboid(world, new Location(world, plotMinX, plotworld.PLOT_HEIGHT + 1, max.getBlockZ()), new Location(world, min.getBlockX() + 1, world.getMaxHeight() + 1, plotMaxZ + 1), (short) 0);
setCuboid(world, new Location(world, plotMinX, 1, max.getBlockZ()), new Location(world, min.getBlockX() + 1, plotworld.PLOT_HEIGHT, plotMaxZ + 1), filling, filling_data);
setCuboid(world, new Location(world, plotMinX, plotworld.PLOT_HEIGHT, max.getBlockZ()), new Location(world, min.getBlockX() + 1, plotworld.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloors, plotfloors_data);
setSimpleCuboid(world, new Location(world, min.getBlockX(), 0, max.getBlockZ()), new Location(world, max.getBlockX() + 1, 1, plotMaxZ + 1), (short) 7);
setSimpleCuboid(world, new Location(world, min.getBlockX(), plotworld.PLOT_HEIGHT + 1, max.getBlockZ()), new Location(world, max.getBlockX() + 1, world.getMaxHeight() + 1, plotMaxZ + 1), (short) 0);
setCuboid(world, new Location(world, min.getBlockX(), 1, max.getBlockZ()), new Location(world, max.getBlockX() + 1, plotworld.PLOT_HEIGHT, plotMaxZ + 1), filling, filling_data);
setCuboid(world, new Location(world, min.getBlockX(), plotworld.PLOT_HEIGHT, max.getBlockZ()), new Location(world, max.getBlockX() + 1, plotworld.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloors, plotfloors_data);
setSimpleCuboid(world, new Location(world, max.getBlockX(), 0, min.getBlockZ()), new Location(world, plotMaxX + 1, 1, max.getBlockZ() + 1), (short) 7);
setSimpleCuboid(world, new Location(world, max.getBlockX(), plotworld.PLOT_HEIGHT + 1, max.getBlockZ()), new Location(world, plotMaxX + 1, world.getMaxHeight() + 1, plotMaxZ + 1), (short) 0);
setCuboid(world, new Location(world, max.getBlockX(), 1, min.getBlockZ()), new Location(world, plotMaxX + 1, plotworld.PLOT_HEIGHT, max.getBlockZ() + 1), filling, filling_data);
setCuboid(world, new Location(world, max.getBlockX(), plotworld.PLOT_HEIGHT, min.getBlockZ()), new Location(world, plotMaxX + 1, plotworld.PLOT_HEIGHT + 1, max.getBlockZ() + 1), plotfloors, plotfloors_data);
setSimpleCuboid(world, new Location(world, max.getBlockX(), 0, max.getBlockZ()), new Location(world, plotMaxX + 1, 1, plotMaxZ + 1), (short) 7);
setSimpleCuboid(world, new Location(world, max.getBlockX(), plotworld.PLOT_HEIGHT + 1, max.getBlockZ()), new Location(world, plotMaxX + 1, world.getMaxHeight() + 1, plotMaxZ + 1), (short) 0);
setCuboid(world, new Location(world, max.getBlockX(), 1, max.getBlockZ()), new Location(world, plotMaxX + 1, plotworld.PLOT_HEIGHT, plotMaxZ + 1), filling, filling_data);
setCuboid(world, new Location(world, max.getBlockX(), plotworld.PLOT_HEIGHT, max.getBlockZ()), new Location(world, plotMaxX + 1, plotworld.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloors, plotfloors_data);
}
PlotHelper.setBiome(requester.getWorld(), plot, Biome.FOREST);
PlayerFunctions.sendMessage(requester, C.CLEARING_PLOT);
manager.clearPlot(requester, plot);
removeSign(requester, plot);
setSign(requester, plot);
/*
* keep
*/
PlayerFunctions.sendMessage(requester, C.CLEARING_DONE.s().replaceAll("%time%", "" + ((System.nanoTime() - start) / 1000000.0))); PlayerFunctions.sendMessage(requester, C.CLEARING_DONE.s().replaceAll("%time%", "" + ((System.nanoTime() - start) / 1000000.0)));
if (canSetFast) { if (canSetFast) {
SetBlockFast.update(requester); refreshPlotChunks(world, plot);
// SetBlockFast.update(requester);
} }
return; return;
} }
@ -1023,54 +727,29 @@ public class PlotHelper {
refreshPlotChunks(world, plot); refreshPlotChunks(world, plot);
} }
public static Location getPlotHome(World w, Plot plot) { public static Location getPlotHome(World w, PlotId plotid) {
PlotWorld plotworld = PlotMain.getWorldSettings(w); PlotMain.getWorldSettings(w);
if (plot.settings.getPosition() == PlotHomePosition.DEFAULT) { if (getPlot(w, plotid).settings.getPosition() == PlotHomePosition.DEFAULT) {
int x = getPlotBottomLoc(w, plot.id).getBlockX() + (getPlotTopLoc(w, plot.id).getBlockX() - getPlotBottomLoc(w, plot.id).getBlockX()); int x = getPlotBottomLoc(w, plotid).getBlockX() + (getPlotTopLoc(w, plotid).getBlockX() - getPlotBottomLoc(w, plotid).getBlockX());
int z = getPlotBottomLoc(w, plot.id).getBlockZ() - 2; int z = getPlotBottomLoc(w, plotid).getBlockZ() - 2;
return new Location(w, x, plotworld.ROAD_HEIGHT + 2, z); int y = w.getHighestBlockYAt(x, z);
return new Location(w, x, y + 2, z);
} else { } else {
World world = w; World world = w;
int x1 = getPlotBottomLoc(world, plot.id).getBlockX();
int x2 = x1 + plotworld.PLOT_WIDTH; Location bot, top;
int z1 = getPlotBottomLoc(world, plot.id).getBlockZ(); bot = getPlotBottomLoc(world, plotid);
int z2 = z1 + plotworld.PLOT_WIDTH; top = getPlotTopLoc(world, plotid);
int xMin = Math.min(x1, x2) + 1; int x = top.getBlockX()-bot.getBlockX();
// int xMax = Math.max(x1, x2); int z = top.getBlockZ()-bot.getBlockZ();
int y = w.getHighestBlockYAt(x, z);
int zMin = Math.min(z1, z2) + 1; return new Location(w, x, y + 2, z);
// int zMax = Math.max(z1, z2);
double adder = (plotworld.PLOT_WIDTH / 2);
double x = (xMin + adder), y = plotworld.ROAD_HEIGHT + 3, z = (zMin + adder);
return new Location(world, x, y, z);
} }
} }
public static Location getPlotHome(World w, PlotId id) { public static Location getPlotHome(World w, Plot plot) {
PlotWorld plotworld = PlotMain.getWorldSettings(w); return getPlotBottomLoc(w, plot.id);
if (getPlot(w, id).settings.getPosition() == PlotHomePosition.DEFAULT) {
int x = getPlotBottomLoc(w, id).getBlockX() + (getPlotTopLoc(w, id).getBlockX() - getPlotBottomLoc(w, id).getBlockX());
int z = getPlotBottomLoc(w, id).getBlockZ() - 2;
return new Location(w, x, plotworld.ROAD_HEIGHT + 2, z);
} else {
World world = w;
int x1 = getPlotBottomLoc(world, id).getBlockX();
int x2 = x1 + plotworld.PLOT_WIDTH;
int z1 = getPlotBottomLoc(world, id).getBlockZ();
int z2 = z1 + plotworld.PLOT_WIDTH;
int xMin = Math.min(x1, x2) + 1;
Math.max(x1, x2);
int zMin = Math.min(z1, z2) + 1;
Math.max(z1, z2);
double adder = (plotworld.PLOT_WIDTH / 2);
double x = (xMin + adder), y = plotworld.ROAD_HEIGHT + 3, z = (zMin + adder);
return new Location(world, x, y, z);
}
} }
public static void refreshPlotChunks(World world, Plot plot) { public static void refreshPlotChunks(World world, Plot plot) {
@ -1092,25 +771,15 @@ public class PlotHelper {
} }
public static Location getPlotTopLocAbs(World world, PlotId id) { public static Location getPlotTopLocAbs(World world, PlotId id) {
PlotWorld plotworld = PlotMain.getWorldSettings(world); PlotWorld plotworld = PlotMain.getWorldSettings(world);
int px = id.x; PlotManager manager = PlotMain.getPlotManager(world);
int pz = id.y; return manager.getPlotTopLocAbs(plotworld, id);
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) { public static Location getPlotBottomLocAbs(World world, PlotId id) {
PlotWorld plotworld = PlotMain.getWorldSettings(world); PlotWorld plotworld = PlotMain.getWorldSettings(world);
int px = id.x; PlotManager manager = PlotMain.getPlotManager(world);
int pz = id.y; return manager.getPlotBottomLocAbs(plotworld, id);
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) {
@ -1119,13 +788,8 @@ public class PlotHelper {
id = PlayerFunctions.getTopPlot(world, plot).id; id = PlayerFunctions.getTopPlot(world, plot).id;
} }
PlotWorld plotworld = PlotMain.getWorldSettings(world); PlotWorld plotworld = PlotMain.getWorldSettings(world);
int px = id.x; PlotManager manager = PlotMain.getPlotManager(world);
int pz = id.y; return manager.getPlotTopLocAbs(plotworld, id);
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 getPlotBottomLoc(World world, PlotId id) { public static Location getPlotBottomLoc(World world, PlotId id) {
@ -1134,13 +798,8 @@ public class PlotHelper {
id = PlayerFunctions.getBottomPlot(world, plot).id; id = PlayerFunctions.getBottomPlot(world, plot).id;
} }
PlotWorld plotworld = PlotMain.getWorldSettings(world); PlotWorld plotworld = PlotMain.getWorldSettings(world);
int px = id.x; PlotManager manager = PlotMain.getPlotManager(world);
int pz = id.y; return manager.getPlotBottomLocAbs(plotworld, id);
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 Plot getPlot(World world, PlotId id) { public static Plot getPlot(World world, PlotId id) {
@ -1154,11 +813,6 @@ public class PlotHelper {
} }
public static Plot getCurrentPlot(Location loc) { public static Plot getCurrentPlot(Location loc) {
/*
* Vector vector = player.getLocation().toVector(); for(plot plot :
* getPlots()) if(vector.isInAABB(plot.l1.toVector(),
* plot.l2.toVector())) return plot; return null;
*/
PlotId id = PlayerFunctions.getPlot(loc); PlotId id = PlayerFunctions.getPlot(loc);
if (id == null) { if (id == null) {
return null; return null;

View File

@ -9,90 +9,6 @@
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
import static org.bukkit.Material.ACACIA_STAIRS;
import static org.bukkit.Material.BEACON;
import static org.bukkit.Material.BEDROCK;
import static org.bukkit.Material.BIRCH_WOOD_STAIRS;
import static org.bukkit.Material.BOOKSHELF;
import static org.bukkit.Material.BREWING_STAND;
import static org.bukkit.Material.BRICK;
import static org.bukkit.Material.BRICK_STAIRS;
import static org.bukkit.Material.BURNING_FURNACE;
import static org.bukkit.Material.CAKE_BLOCK;
import static org.bukkit.Material.CAULDRON;
import static org.bukkit.Material.CLAY;
import static org.bukkit.Material.CLAY_BRICK;
import static org.bukkit.Material.COAL_BLOCK;
import static org.bukkit.Material.COAL_ORE;
import static org.bukkit.Material.COBBLESTONE;
import static org.bukkit.Material.COBBLESTONE_STAIRS;
import static org.bukkit.Material.COBBLE_WALL;
import static org.bukkit.Material.COMMAND;
import static org.bukkit.Material.DARK_OAK_STAIRS;
import static org.bukkit.Material.DAYLIGHT_DETECTOR;
import static org.bukkit.Material.DIAMOND_BLOCK;
import static org.bukkit.Material.DIAMOND_ORE;
import static org.bukkit.Material.DIRT;
import static org.bukkit.Material.DISPENSER;
import static org.bukkit.Material.DROPPER;
import static org.bukkit.Material.EMERALD_BLOCK;
import static org.bukkit.Material.EMERALD_ORE;
import static org.bukkit.Material.ENCHANTMENT_TABLE;
import static org.bukkit.Material.ENDER_PORTAL_FRAME;
import static org.bukkit.Material.ENDER_STONE;
import static org.bukkit.Material.FURNACE;
import static org.bukkit.Material.GLASS;
import static org.bukkit.Material.GLOWSTONE;
import static org.bukkit.Material.GOLD_BLOCK;
import static org.bukkit.Material.GOLD_ORE;
import static org.bukkit.Material.GRASS;
import static org.bukkit.Material.GRAVEL;
import static org.bukkit.Material.HARD_CLAY;
import static org.bukkit.Material.HAY_BLOCK;
import static org.bukkit.Material.HUGE_MUSHROOM_1;
import static org.bukkit.Material.HUGE_MUSHROOM_2;
import static org.bukkit.Material.IRON_BLOCK;
import static org.bukkit.Material.IRON_ORE;
import static org.bukkit.Material.JACK_O_LANTERN;
import static org.bukkit.Material.JUKEBOX;
import static org.bukkit.Material.JUNGLE_WOOD_STAIRS;
import static org.bukkit.Material.LAPIS_BLOCK;
import static org.bukkit.Material.LAPIS_ORE;
import static org.bukkit.Material.LEAVES;
import static org.bukkit.Material.LEAVES_2;
import static org.bukkit.Material.LOG;
import static org.bukkit.Material.LOG_2;
import static org.bukkit.Material.MELON_BLOCK;
import static org.bukkit.Material.MOB_SPAWNER;
import static org.bukkit.Material.MOSSY_COBBLESTONE;
import static org.bukkit.Material.MYCEL;
import static org.bukkit.Material.NETHERRACK;
import static org.bukkit.Material.NETHER_BRICK;
import static org.bukkit.Material.NETHER_BRICK_STAIRS;
import static org.bukkit.Material.NOTE_BLOCK;
import static org.bukkit.Material.OBSIDIAN;
import static org.bukkit.Material.PACKED_ICE;
import static org.bukkit.Material.PUMPKIN;
import static org.bukkit.Material.QUARTZ_BLOCK;
import static org.bukkit.Material.QUARTZ_ORE;
import static org.bukkit.Material.QUARTZ_STAIRS;
import static org.bukkit.Material.REDSTONE_BLOCK;
import static org.bukkit.Material.SAND;
import static org.bukkit.Material.SANDSTONE;
import static org.bukkit.Material.SANDSTONE_STAIRS;
import static org.bukkit.Material.SMOOTH_BRICK;
import static org.bukkit.Material.SMOOTH_STAIRS;
import static org.bukkit.Material.SNOW_BLOCK;
import static org.bukkit.Material.SOUL_SAND;
import static org.bukkit.Material.SPONGE;
import static org.bukkit.Material.SPRUCE_WOOD_STAIRS;
import static org.bukkit.Material.STONE;
import static org.bukkit.Material.WOOD;
import static org.bukkit.Material.WOOD_STAIRS;
import static org.bukkit.Material.WOOL;
import static org.bukkit.Material.WORKBENCH;
import static org.bukkit.Material.getMaterial;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
@ -101,7 +17,6 @@ import java.sql.DatabaseMetaData;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -117,7 +32,6 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;

View File

@ -24,26 +24,25 @@ public abstract class PlotManager {
public abstract Location getPlotBottomLocAbs(PlotWorld plotworld, PlotId plotid); public abstract Location getPlotBottomLocAbs(PlotWorld plotworld, PlotId plotid);
// the same applies here // the same applies here
public abstract Location getPlotTopLocAbs(PlotWorld plotworld, PlotId plotid); public abstract Location getPlotTopLocAbs(PlotWorld plotworld, PlotId plotid);
/* /*
* Plot clearing (return false if you do not support some method) * Plot clearing (return false if you do not support some method)
* *
* *
*/ */
public abstract boolean clearPlot(Player player, Plot plot, boolean mega); public abstract boolean clearPlot(Player player, Plot plot);
public abstract boolean clearSign(Player player, Plot plot, boolean mega); public abstract Location getSignLoc(Player player, PlotWorld plotworld, Plot plot);
// clearEntities also needs to clear Player entities (e.g. teleport them to the surface)
public abstract boolean clearEntities(Player player, Plot plot, boolean mega);
/* /*
* Plot set functions (return false if you do not support the specific set * Plot set functions (return false if you do not support the specific set
* method) * method)
*/ */
public abstract boolean setWall(Player player, Plot plot, Block block, PlotBlock newBlock); public abstract boolean setWall(Player player, PlotWorld plotworld, PlotId plotid, PlotBlock block);
public abstract boolean setFloor(Player player, PlotWorld plotworld, PlotId plotid, PlotBlock[] block);
public abstract boolean setBiome(Player player, Plot plot, Biome biome); public abstract boolean setBiome(Player player, Plot plot, Biome biome);

View File

@ -1,19 +1,13 @@
package com.intellectualcrafters.plot.generator; package com.intellectualcrafters.plot.generator;
import java.util.ArrayList; import java.util.ArrayList;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.Configuration;
import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot; import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotBlock; import com.intellectualcrafters.plot.PlotBlock;
@ -96,7 +90,6 @@ public class DefaultPlotManager extends PlotManager {
int x = loc.getBlockX(); int x = loc.getBlockX();
int z = loc.getBlockZ(); int z = loc.getBlockZ();
String world = loc.getWorld().getName();
if (plotworld == null) { if (plotworld == null) {
return null; return null;
} }
@ -228,7 +221,7 @@ public class DefaultPlotManager extends PlotManager {
* *
*/ */
@Override @Override
public boolean clearPlot(Player player, Plot plot, boolean mega) { public boolean clearPlot(Player player, Plot plot) {
World world = player.getWorld(); World world = player.getWorld();
DefaultPlotWorld dpw = ((DefaultPlotWorld) PlotMain.getWorldSettings(world)); DefaultPlotWorld dpw = ((DefaultPlotWorld) PlotMain.getWorldSettings(world));
@ -356,47 +349,63 @@ public class DefaultPlotManager extends PlotManager {
* Remove sign for a plot * Remove sign for a plot
*/ */
@Override @Override
public boolean clearSign(Player player, Plot plot, boolean mega) { public Location getSignLoc(Player player, PlotWorld plotworld, Plot plot) {
DefaultPlotWorld dpw = (DefaultPlotWorld) plotworld;
World world = player.getWorld(); World world = player.getWorld();
DefaultPlotWorld plotworld = (DefaultPlotWorld) PlotMain.getWorldSettings(world); return new Location(world, PlotHelper.getPlotBottomLoc(world, plot.id).getBlockX(), dpw.ROAD_HEIGHT + 1, PlotHelper.getPlotBottomLoc(world, plot.id).getBlockZ() - 1);
Location pl = new Location(world, PlotHelper.getPlotBottomLoc(world, plot.id).getBlockX(), plotworld.ROAD_HEIGHT + 1, PlotHelper.getPlotBottomLoc(world, plot.id).getBlockZ());
Block bs = pl.add(0, 0, -1).getBlock();
bs.setType(Material.AIR);
return true;
}
/*
* Remove any entities, and teleport players inside a plot being cleared
*/
@Override
public boolean clearEntities(Player player, Plot plot, boolean mega) {
World world = Bukkit.getWorld(plot.world);
Location pos1 = PlotHelper.getPlotBottomLoc(world, plot.id).add(1, 0, 1);
Location pos2 = PlotHelper.getPlotTopLoc(world, plot.id);
for (int i = (pos1.getBlockX() / 16) * 16; i < (16 + ((pos2.getBlockX() / 16) * 16)); i += 16) {
for (int j = (pos1.getBlockZ() / 16) * 16; j < (16 + ((pos2.getBlockZ() / 16) * 16)); j += 16) {
Chunk chunk = world.getChunkAt(i, j);
for (Entity entity : chunk.getEntities()) {
Location eloc = entity.getLocation();
if (eloc.getBlockX() >= pos1.getBlockX() && eloc.getBlockZ() >= pos1.getBlockZ() && eloc.getBlockX() <= pos2.getBlockX() && eloc.getBlockZ() <= pos2.getBlockZ()) {
if (entity instanceof Player) {
PlotMain.teleportPlayer((Player) entity, entity.getLocation(), plot);
} else {
entity.remove();
}
}
}
}
}
return true;
} }
@Override
public boolean setFloor(Player player, PlotWorld plotworld, PlotId plotid, PlotBlock[] blocks) {
World world = player.getWorld();
final Location pos1 = PlotHelper.getPlotBottomLoc(world, plotid).add(1, 0, 1);
final Location pos2 = PlotHelper.getPlotTopLoc(world, plotid);
PlotHelper.setCuboid(world, pos1, pos2, blocks);
return true;
}
@Override @Override
public boolean setWall(Player player, Plot plot, Block block, PlotBlock newblock) { public boolean setWall(Player player, PlotWorld plotworld, PlotId plotid, PlotBlock plotblock) {
DefaultPlotWorld dpw = (DefaultPlotWorld) plotworld;
World w = player.getWorld();
Location bottom = PlotHelper.getPlotBottomLoc(w, plotid);
Location top = PlotHelper.getPlotTopLoc(w, plotid);
int x, z;
Block block;
// CURRENTLY NOT IMPLEMENTED // TODO use PlotHelper.setSimpleCuboid rather than this for loop
return false; for (x = bottom.getBlockX(); x < (top.getBlockX() + 1); x++) {
z = bottom.getBlockZ();
block = w.getBlockAt(x, dpw.ROAD_HEIGHT + 1, z);
PlotHelper.setBlock(block, plotblock);
}
for (z = bottom.getBlockZ(); z < (top.getBlockZ() + 1); z++) {
x = top.getBlockX() + 1;
block = w.getBlockAt(x, dpw.ROAD_HEIGHT + 1, z);
PlotHelper.setBlock(block, plotblock);
}
for (x = top.getBlockX() + 1; x > (bottom.getBlockX() - 1); x--) {
z = top.getBlockZ() + 1;
block = w.getBlockAt(x, dpw.ROAD_HEIGHT + 1, z);
PlotHelper.setBlock(block, plotblock);
}
for (z = top.getBlockZ() + 1; z > (bottom.getBlockZ() - 1); z--) {
x = bottom.getBlockX();
block = w.getBlockAt(x, dpw.ROAD_HEIGHT + 1, z);
PlotHelper.setBlock(block, plotblock);
}
return true;
} }
/* /*
@ -564,6 +573,9 @@ public class DefaultPlotManager extends PlotManager {
*/ */
@Override @Override
public boolean finishPlotMerge(World world, PlotWorld plotworld, ArrayList<PlotId> plotIds) { public boolean finishPlotMerge(World world, PlotWorld plotworld, ArrayList<PlotId> plotIds) {
// TODO set plot wall
DefaultPlotWorld dpw = (DefaultPlotWorld) plotworld; DefaultPlotWorld dpw = (DefaultPlotWorld) plotworld;
PlotId pos1 = plotIds.get(0); PlotId pos1 = plotIds.get(0);