More generator work

This commit is contained in:
boy0001 2015-02-18 23:09:30 +11:00
parent b95acd5d62
commit 2a8415502e
10 changed files with 269 additions and 239 deletions

View File

@ -38,6 +38,7 @@ import com.intellectualcrafters.plot.flag.FlagValue;
import com.intellectualcrafters.plot.generator.AugmentedPopulator;
import com.intellectualcrafters.plot.generator.HybridGen;
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
import com.intellectualcrafters.plot.generator.SquarePlotManager;
import com.intellectualcrafters.plot.listeners.*;
import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.titles.AbstractTitle;
@ -48,8 +49,10 @@ import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper;
import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import me.confuser.barapi.BarAPI;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.*;
import org.bukkit.Location;
import org.bukkit.command.PluginCommand;
@ -594,7 +597,6 @@ public class PlotMain extends JavaPlugin implements Listener {
*
* @param c message
*/
@SuppressWarnings("unused")
public static void sendConsoleSenderMessage(final C c) {
sendConsoleSenderMessage(c.s());
}
@ -661,7 +663,6 @@ public class PlotMain extends JavaPlugin implements Listener {
/**
* Load configuration files
*/
@SuppressWarnings("deprecation")
public static void configs() {
final File folder = new File(getMain().getDataFolder() + File.separator + "config");
if (!folder.exists() && !folder.mkdirs()) {
@ -758,7 +759,6 @@ public class PlotMain extends JavaPlugin implements Listener {
/**
* Kill all entities on roads
*/
@SuppressWarnings("deprecation")
public static void killAllEntities() {
Bukkit.getScheduler().scheduleSyncRepeatingTask(getMain(), new Runnable() {
long ticked = 0l;
@ -1000,8 +1000,8 @@ public class PlotMain extends JavaPlugin implements Listener {
} catch (final IOException e) {
e.printStackTrace();
}
if (plotWorld.TYPE == 2 && !Settings.ENABLE_CLUSTERS) {
sendConsoleSenderMessage("&c[ERROR] World '" + world + "' in settings.yml is not using PlotSquared generator! Please enable plot custers or delete this world from your settings.yml!");
if ((plotWorld.TYPE == 2 && !Settings.ENABLE_CLUSTERS) || !(plotManager instanceof SquarePlotManager)) {
sendConsoleSenderMessage("&c[ERROR] World '" + world + "' in settings.yml is not using PlotSquared generator! Please set the generator correctly or delete the world from the 'settings.yml'!");
return;
}
addPlotWorld(world, plotWorld, plotManager);

View File

@ -40,6 +40,7 @@ import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.generator.SquarePlotManager;
import com.intellectualcrafters.plot.object.PlotGenerator;
import com.intellectualcrafters.plot.util.PlayerFunctions;
@ -74,7 +75,10 @@ public class Setup extends SubCommand {
PlotMain.removePlotWorld(testWorld);
final String name = plugin.getDescription().getName();
if (generator instanceof PlotGenerator) {
generators.put(name, (PlotGenerator) generator);
PlotGenerator pgen = (PlotGenerator) generator;
if (pgen.getPlotManager() instanceof SquarePlotManager) {
generators.put(name, pgen);
}
}
}
}

View File

@ -140,6 +140,15 @@ public class Unlink extends SubCommand {
}
}
manager.finishPlotUnlink(world, plotworld, ids);
for (PlotId id : ids) {
Plot myPlot = PlotHelper.getPlot(world, id);
if (plot.hasOwner()) {
String name = UUIDHandler.getName(myPlot.owner);
if (name != null) {
PlotHelper.setSign(world, name, myPlot);
}
}
}
return true;
}
}

View File

@ -121,37 +121,6 @@ public abstract class ClassicPlotManager extends SquarePlotManager {
return true;
}
/**
* Set a plot biome
*/
@Override
public boolean setBiome(final World world, final Plot plot, final Biome biome) {
final int bottomX = PlotHelper.getPlotBottomLoc(world, plot.id).getBlockX() - 1;
final int topX = PlotHelper.getPlotTopLoc(world, plot.id).getBlockX() + 1;
final int bottomZ = PlotHelper.getPlotBottomLoc(world, plot.id).getBlockZ() - 1;
final int topZ = PlotHelper.getPlotTopLoc(world, plot.id).getBlockZ() + 1;
final Block block = world.getBlockAt(PlotHelper.getPlotBottomLoc(world, plot.id).add(1, 1, 1));
final Biome current = block.getBiome();
if (biome.equals(current)) {
return false;
}
for (int x = bottomX; x <= topX; x++) {
for (int z = bottomZ; z <= topZ; z++) {
final Block blk = world.getBlockAt(x, 0, z);
final Biome c = blk.getBiome();
if (c.equals(biome)) {
x += 15;
continue;
}
blk.setBiome(biome);
}
}
return true;
}
/**
* PLOT MERGING
*/
@ -292,14 +261,6 @@ public abstract class ClassicPlotManager extends SquarePlotManager {
return true;
}
@Override
public boolean clearPlot(final World world, final PlotWorld plotworld, final Plot plot, final boolean isDelete, Runnable whendone) {
final Location pos1 = PlotHelper.getPlotBottomLoc(world, plot.id).add(1, 0, 1);
final Location pos2 = PlotHelper.getPlotTopLoc(world, plot.id);
ChunkManager.regenerateRegion(pos1, pos2, whendone);
return true;
}
/**
* Finishing off plot merging by adding in the walls surrounding the plot (OPTIONAL)(UNFINISHED)
*/
@ -316,17 +277,11 @@ public abstract class ClassicPlotManager extends SquarePlotManager {
@Override
public boolean finishPlotUnlink(final World world, final PlotWorld plotworld, final ArrayList<PlotId> plotIds) {
PlotBlock block = ((ClassicPlotWorld) plotworld).WALL_BLOCK;
if (block.id != 0) {
for (PlotId id : plotIds) {
setWall(world, plotworld, id, new PlotBlock[] {(( ClassicPlotWorld) plotworld).WALL_BLOCK });
Plot plot = PlotHelper.getPlot(world, id);
if (plot.hasOwner()) {
String name = UUIDHandler.getName(plot.owner);
if (name != null) {
PlotHelper.setSign(world, name, plot);
}
}
PlotBlock block = ((ClassicPlotWorld) plotworld).CLAIMED_WALL_BLOCK;
PlotBlock unclaim = ((ClassicPlotWorld) plotworld).WALL_BLOCK;
for (PlotId id : plotIds) {
if (block.equals(unclaim)) {
setWall(world, plotworld, id, new PlotBlock[] {block });
}
}
return true;
@ -346,7 +301,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager {
public boolean claimPlot(World world, final PlotWorld plotworld, Plot plot) {
PlotBlock unclaim = ((ClassicPlotWorld) plotworld).WALL_BLOCK;
PlotBlock claim = ((ClassicPlotWorld) plotworld).CLAIMED_WALL_BLOCK;
if (claim != unclaim) {
if (claim.equals(unclaim)) {
setWall(world, plotworld, plot.id, new PlotBlock[] {claim});
}
return true;
@ -371,19 +326,6 @@ public abstract class ClassicPlotManager extends SquarePlotManager {
};
}
@Override
public Location getPlotTopLocAbs(final PlotWorld plotworld, final PlotId plotid) {
final ClassicPlotWorld dpw = ((ClassicPlotWorld) plotworld);
final int px = plotid.x;
final int pz = plotid.y;
final int x = (px * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH)) - ((int) Math.floor(dpw.ROAD_WIDTH / 2)) - 1;
final int z = (pz * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH)) - ((int) Math.floor(dpw.ROAD_WIDTH / 2)) - 1;
return new Location(Bukkit.getWorld(plotworld.worldname), x, 256, z);
}
/**
* Remove sign for a plot
*/
@ -392,149 +334,4 @@ public abstract class ClassicPlotManager extends SquarePlotManager {
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
return new Location(world, PlotHelper.getPlotBottomLoc(world, plot.id).getBlockX(), dpw.ROAD_HEIGHT + 1, PlotHelper.getPlotBottomLoc(world, plot.id).getBlockZ() - 1);
}
@Override
public PlotId getPlotIdAbs(final PlotWorld plotworld, final Location loc) {
final ClassicPlotWorld dpw = ((ClassicPlotWorld) plotworld);
// get x,z loc
int x = loc.getBlockX();
int z = loc.getBlockZ();
// get plot size
final int size = dpw.PLOT_WIDTH + dpw.ROAD_WIDTH;
// get size of path on bottom part, and top part of plot
// (As 0,0 is in the middle of a road, not the very start)
int pathWidthLower;
if ((dpw.ROAD_WIDTH % 2) == 0) {
pathWidthLower = (int) (Math.floor(dpw.ROAD_WIDTH / 2) - 1);
} else {
pathWidthLower = (int) Math.floor(dpw.ROAD_WIDTH / 2);
}
// calulating how many shifts need to be done
int dx = x / size;
int dz = z / size;
if (x < 0) {
dx--;
x += ((-dx) * size);
}
if (z < 0) {
dz--;
z += ((-dz) * size);
}
// reducing to first plot
final int rx = (x) % size;
final int rz = (z) % size;
// checking if road (return null if so)
final int end = pathWidthLower + dpw.PLOT_WIDTH;
final boolean northSouth = (rz <= pathWidthLower) || (rz > end);
final boolean eastWest = (rx <= pathWidthLower) || (rx > end);
if (northSouth || eastWest) {
return null;
}
// returning the plot id (based on the number of shifts required)
return new PlotId(dx + 1, dz + 1);
}
@Override
public PlotId getPlotId(final PlotWorld plotworld, final Location loc) {
final ClassicPlotWorld dpw = ((ClassicPlotWorld) plotworld);
int x = loc.getBlockX();
int z = loc.getBlockZ();
if (plotworld == null) {
return null;
}
final int size = dpw.PLOT_WIDTH + dpw.ROAD_WIDTH;
int pathWidthLower;
if ((dpw.ROAD_WIDTH % 2) == 0) {
pathWidthLower = (int) (Math.floor(dpw.ROAD_WIDTH / 2) - 1);
} else {
pathWidthLower = (int) Math.floor(dpw.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);
}
final int rx = (x) % size;
final int rz = (z) % size;
final int end = pathWidthLower + dpw.PLOT_WIDTH;
final boolean northSouth = (rz <= pathWidthLower) || (rz > end);
final boolean eastWest = (rx <= pathWidthLower) || (rx > end);
if (northSouth && eastWest) {
// This means you are in the intersection
final PlotId id = PlayerFunctions.getPlotAbs(loc.add(dpw.ROAD_WIDTH, 0, dpw.ROAD_WIDTH));
final Plot plot = PlotMain.getPlots(loc.getWorld()).get(id);
if (plot == null) {
return null;
}
if ((plot.settings.getMerged(0) && plot.settings.getMerged(3))) {
return PlayerFunctions.getBottomPlot(loc.getWorld(), plot).id;
}
return null;
}
if (northSouth) {
// You are on a road running West to East (yeah, I named the var
// poorly)
final PlotId id = PlayerFunctions.getPlotAbs(loc.add(0, 0, dpw.ROAD_WIDTH));
final Plot plot = PlotMain.getPlots(loc.getWorld()).get(id);
if (plot == null) {
return null;
}
if (plot.settings.getMerged(0)) {
return PlayerFunctions.getBottomPlot(loc.getWorld(), plot).id;
}
return null;
}
if (eastWest) {
// This is the road separating an Eastern and Western plot
final PlotId id = PlayerFunctions.getPlotAbs(loc.add(dpw.ROAD_WIDTH, 0, 0));
final Plot plot = PlotMain.getPlots(loc.getWorld()).get(id);
if (plot == null) {
return null;
}
if (plot.settings.getMerged(3)) {
return PlayerFunctions.getBottomPlot(loc.getWorld(), plot).id;
}
return null;
}
final PlotId id = new PlotId(dx + 1, dz + 1);
final Plot plot = PlotMain.getPlots(loc.getWorld()).get(id);
if (plot == null) {
return id;
}
return PlayerFunctions.getBottomPlot(loc.getWorld(), plot).id;
}
/**
* Get the bottom plot loc (some basic math)
*/
@Override
public Location getPlotBottomLocAbs(final PlotWorld plotworld, final PlotId plotid) {
final ClassicPlotWorld dpw = ((ClassicPlotWorld) plotworld);
final int px = plotid.x;
final int pz = plotid.y;
final int x = (px * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH)) - dpw.PLOT_WIDTH - ((int) Math.floor(dpw.ROAD_WIDTH / 2)) - 1;
final int z = (pz * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH)) - dpw.PLOT_WIDTH - ((int) Math.floor(dpw.ROAD_WIDTH / 2)) - 1;
return new Location(Bukkit.getWorld(plotworld.worldname), x, 1, z);
}
}

View File

@ -12,8 +12,6 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld {
public static int ROAD_HEIGHT_DEFAULT = 64;
public static int PLOT_HEIGHT_DEFAULT = 64;
public static int WALL_HEIGHT_DEFAULT = 64;
public static int PLOT_WIDTH_DEFAULT = 32;
public static int ROAD_WIDTH_DEFAULT = 7;
public static PlotBlock[] MAIN_BLOCK_DEFAULT = new PlotBlock[] { new PlotBlock((short) 1, (byte) 0) };
public static PlotBlock[] TOP_BLOCK_DEFAULT = new PlotBlock[] { new PlotBlock((short) 2, (byte) 0) };
public static PlotBlock WALL_BLOCK_DEFAULT = new PlotBlock((short) 44, (byte) 0);
@ -24,8 +22,6 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld {
public int ROAD_HEIGHT;
public int PLOT_HEIGHT;
public int WALL_HEIGHT;
public int PLOT_WIDTH;
public int ROAD_WIDTH;
public PlotBlock[] MAIN_BLOCK;
public PlotBlock[] TOP_BLOCK;
public PlotBlock WALL_BLOCK;
@ -34,11 +30,6 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld {
public PlotBlock ROAD_BLOCK;
public boolean PLOT_BEDROCK;
public short PATH_WIDTH_LOWER;
public short PATH_WIDTH_UPPER;
public short SIZE;
public short OFFSET;
/**
* CONFIG NODE | DEFAULT VALUE | DESCRIPTION | CONFIGURATION TYPE | REQUIRED FOR INITIAL SETUP
* <p/>
@ -75,14 +66,6 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld {
this.CLAIMED_WALL_BLOCK = (PlotBlock) Configuration.BLOCK.parseString(config.getString("wall.block_claimed"));
this.SIZE = (short) (this.PLOT_WIDTH + this.ROAD_WIDTH);
if ((this.ROAD_WIDTH % 2) == 0) {
PATH_WIDTH_LOWER = (short) (Math.floor(this.ROAD_WIDTH / 2) - 1);
} else {
PATH_WIDTH_LOWER = (short) (Math.floor(this.ROAD_WIDTH / 2));
}
this.PATH_WIDTH_UPPER = (short) (this.PATH_WIDTH_LOWER + this.PLOT_WIDTH + 1);
}
public ClassicPlotWorld(String worldname) {

View File

@ -3,6 +3,9 @@ package com.intellectualcrafters.plot.generator;
import com.intellectualcrafters.plot.object.PlotWorld;
public abstract class GridPlotWorld extends PlotWorld {
public short SIZE;
public GridPlotWorld(String worldname) {
super(worldname);
}

View File

@ -304,7 +304,7 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
else { condition = (!gx || !gz || !lx || !lz); }
if (condition) {
int sy = plotworld.ROAD_HEIGHT + plotworld.OFFSET;
int sy = plotworld.ROAD_HEIGHT;
ChunkLoc loc = new ChunkLoc(absX, absZ);
HashMap<Short, Short> blocks = plotworld.G_SCH.get(loc);
for (short y = (short) (plotworld.ROAD_HEIGHT + 1); y <= plotworld.ROAD_HEIGHT + plotworld.SCHEMATIC_HEIGHT; y++) {
@ -344,7 +344,7 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
Location bottom = getPlotBottomLocAbs(plotworld, id);
int sx = bottom.getBlockX() - hpw.PATH_WIDTH_LOWER;
int sz = bottom.getBlockZ() - hpw.PATH_WIDTH_LOWER;
int sy = hpw.ROAD_HEIGHT + hpw.OFFSET;
int sy = hpw.ROAD_HEIGHT;
for (ChunkLoc loc : hpw.G_SCH.keySet()) {
HashMap<Short, Short> blocks = hpw.G_SCH.get(loc);
HashMap<Short, Byte> datas = hpw.G_SCH_DATA.get(loc);
@ -420,6 +420,7 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
final PlotBlock wall_filling = dpw.WALL_FILLING;
final Block block = world.getBlockAt(new Location(world, pos1.getBlockX() - 1, 1, pos1.getBlockZ()));
if ((block.getTypeId() != wall_filling.id) || (block.getData() != wall_filling.data)) {
setWallFilling(world, dpw, plot.id, new PlotBlock[] {wall_filling});
}

View File

@ -42,6 +42,9 @@ public class HybridPlotWorld extends ClassicPlotWorld {
public boolean PLOT_SCHEMATIC = false;
public short REQUIRED_CHANGES = 0;
public short PATH_WIDTH_LOWER;
public short PATH_WIDTH_UPPER;
/*
* Here we are just calling the super method, nothing special
*/
@ -94,7 +97,6 @@ public class HybridPlotWorld extends ClassicPlotWorld {
public void setupSchematics() {
G_SCH_DATA = new HashMap<>();
G_SCH = new HashMap<>();
this.OFFSET = -1 + 1;
String schem1Str = "GEN_ROAD_SCHEMATIC/" + worldname + "/sideroad";
String schem2Str = "GEN_ROAD_SCHEMATIC/" + worldname + "/intersection";
String schem3Str = "GEN_ROAD_SCHEMATIC/" + worldname + "/plot";
@ -123,7 +125,7 @@ public class HybridPlotWorld extends ClassicPlotWorld {
short id = blocks3[index].getBlock();
byte data = blocks3[index].getData();
if (id != 0) {
addOverlayBlock((short) (x + shift + oddshift), (short) (y + this.OFFSET), (short) (z + shift + oddshift), id, data, false);
addOverlayBlock((short) (x + shift + oddshift), (short) (y), (short) (z + shift + oddshift), id, data, false);
}
}
}
@ -160,8 +162,8 @@ public class HybridPlotWorld extends ClassicPlotWorld {
byte data = blocks1[index].getData();
if (id != 0) {
addOverlayBlock((short) (x - (shift)), (short) (y + this.OFFSET), (short) (z + shift + oddshift), id, data, false);
addOverlayBlock((short) (z + shift + oddshift), (short) (y + this.OFFSET), (short) (x - shift), id, data, true);
addOverlayBlock((short) (x - (shift)), (short) (y), (short) (z + shift + oddshift), id, data, false);
addOverlayBlock((short) (z + shift + oddshift), (short) (y), (short) (x - shift), id, data, true);
}
}
}
@ -174,7 +176,7 @@ public class HybridPlotWorld extends ClassicPlotWorld {
short id = blocks2[index].getBlock();
byte data = blocks2[index].getData();
if (id != 0) {
addOverlayBlock((short) (x - shift), (short) (y + this.OFFSET), (short) (z - shift), id, data, false);
addOverlayBlock((short) (x - shift), (short) (y), (short) (z - shift), id, data, false);
}
}
}

View File

@ -1,8 +1,218 @@
package com.intellectualcrafters.plot.generator;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.PlayerFunctions;
import com.intellectualcrafters.plot.util.PlotHelper;
/**
* A plot manager with a square grid layout, with square shaped plots
*/
public abstract class SquarePlotManager extends GridPlotManager {
@Override
public boolean clearPlot(final World world, final PlotWorld plotworld, final Plot plot, final boolean isDelete, Runnable whendone) {
final Location pos1 = PlotHelper.getPlotBottomLoc(world, plot.id).add(1, 0, 1);
final Location pos2 = PlotHelper.getPlotTopLoc(world, plot.id);
ChunkManager.regenerateRegion(pos1, pos2, whendone);
return true;
}
@Override
public Location getPlotTopLocAbs(final PlotWorld plotworld, final PlotId plotid) {
final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld);
final int px = plotid.x;
final int pz = plotid.y;
final int x = (px * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH)) - ((int) Math.floor(dpw.ROAD_WIDTH / 2)) - 1;
final int z = (pz * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH)) - ((int) Math.floor(dpw.ROAD_WIDTH / 2)) - 1;
return new Location(Bukkit.getWorld(plotworld.worldname), x, 256, z);
}
@Override
public PlotId getPlotIdAbs(final PlotWorld plotworld, final Location loc) {
final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld);
// get x,z loc
int x = loc.getBlockX();
int z = loc.getBlockZ();
// get plot size
final int size = dpw.PLOT_WIDTH + dpw.ROAD_WIDTH;
// get size of path on bottom part, and top part of plot
// (As 0,0 is in the middle of a road, not the very start)
int pathWidthLower;
if ((dpw.ROAD_WIDTH % 2) == 0) {
pathWidthLower = (int) (Math.floor(dpw.ROAD_WIDTH / 2) - 1);
} else {
pathWidthLower = (int) Math.floor(dpw.ROAD_WIDTH / 2);
}
// calulating how many shifts need to be done
int dx = x / size;
int dz = z / size;
if (x < 0) {
dx--;
x += ((-dx) * size);
}
if (z < 0) {
dz--;
z += ((-dz) * size);
}
// reducing to first plot
final int rx = (x) % size;
final int rz = (z) % size;
// checking if road (return null if so)
final int end = pathWidthLower + dpw.PLOT_WIDTH;
final boolean northSouth = (rz <= pathWidthLower) || (rz > end);
final boolean eastWest = (rx <= pathWidthLower) || (rx > end);
if (northSouth || eastWest) {
return null;
}
// returning the plot id (based on the number of shifts required)
return new PlotId(dx + 1, dz + 1);
}
@Override
public PlotId getPlotId(final PlotWorld plotworld, final Location loc) {
final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld);
int x = loc.getBlockX();
int z = loc.getBlockZ();
if (plotworld == null) {
return null;
}
final int size = dpw.PLOT_WIDTH + dpw.ROAD_WIDTH;
int pathWidthLower;
if ((dpw.ROAD_WIDTH % 2) == 0) {
pathWidthLower = (int) (Math.floor(dpw.ROAD_WIDTH / 2) - 1);
} else {
pathWidthLower = (int) Math.floor(dpw.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);
}
final int rx = (x) % size;
final int rz = (z) % size;
final int end = pathWidthLower + dpw.PLOT_WIDTH;
final boolean northSouth = (rz <= pathWidthLower) || (rz > end);
final boolean eastWest = (rx <= pathWidthLower) || (rx > end);
if (northSouth && eastWest) {
// This means you are in the intersection
final PlotId id = PlayerFunctions.getPlotAbs(loc.add(dpw.ROAD_WIDTH, 0, dpw.ROAD_WIDTH));
final Plot plot = PlotMain.getPlots(loc.getWorld()).get(id);
if (plot == null) {
return null;
}
if ((plot.settings.getMerged(0) && plot.settings.getMerged(3))) {
return PlayerFunctions.getBottomPlot(loc.getWorld(), plot).id;
}
return null;
}
if (northSouth) {
// You are on a road running West to East (yeah, I named the var
// poorly)
final PlotId id = PlayerFunctions.getPlotAbs(loc.add(0, 0, dpw.ROAD_WIDTH));
final Plot plot = PlotMain.getPlots(loc.getWorld()).get(id);
if (plot == null) {
return null;
}
if (plot.settings.getMerged(0)) {
return PlayerFunctions.getBottomPlot(loc.getWorld(), plot).id;
}
return null;
}
if (eastWest) {
// This is the road separating an Eastern and Western plot
final PlotId id = PlayerFunctions.getPlotAbs(loc.add(dpw.ROAD_WIDTH, 0, 0));
final Plot plot = PlotMain.getPlots(loc.getWorld()).get(id);
if (plot == null) {
return null;
}
if (plot.settings.getMerged(3)) {
return PlayerFunctions.getBottomPlot(loc.getWorld(), plot).id;
}
return null;
}
final PlotId id = new PlotId(dx + 1, dz + 1);
final Plot plot = PlotMain.getPlots(loc.getWorld()).get(id);
if (plot == null) {
return id;
}
return PlayerFunctions.getBottomPlot(loc.getWorld(), plot).id;
}
/**
* Get the bottom plot loc (some basic math)
*/
@Override
public Location getPlotBottomLocAbs(final PlotWorld plotworld, final PlotId plotid) {
final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld);
final int px = plotid.x;
final int pz = plotid.y;
final int x = (px * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH)) - dpw.PLOT_WIDTH - ((int) Math.floor(dpw.ROAD_WIDTH / 2)) - 1;
final int z = (pz * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH)) - dpw.PLOT_WIDTH - ((int) Math.floor(dpw.ROAD_WIDTH / 2)) - 1;
return new Location(Bukkit.getWorld(plotworld.worldname), x, 1, z);
}
/**
* Set a plot biome
*/
@Override
public boolean setBiome(final World world, final Plot plot, final Biome biome) {
final int bottomX = PlotHelper.getPlotBottomLoc(world, plot.id).getBlockX() - 1;
final int topX = PlotHelper.getPlotTopLoc(world, plot.id).getBlockX() + 1;
final int bottomZ = PlotHelper.getPlotBottomLoc(world, plot.id).getBlockZ() - 1;
final int topZ = PlotHelper.getPlotTopLoc(world, plot.id).getBlockZ() + 1;
final Block block = world.getBlockAt(PlotHelper.getPlotBottomLoc(world, plot.id).add(1, 1, 1));
final Biome current = block.getBiome();
if (biome.equals(current)) {
return false;
}
for (int x = bottomX; x <= topX; x++) {
for (int z = bottomZ; z <= topZ; z++) {
final Block blk = world.getBlockAt(x, 0, z);
final Biome c = blk.getBiome();
if (c.equals(biome)) {
x += 15;
continue;
}
blk.setBiome(biome);
}
}
return true;
}
}

View File

@ -1,6 +1,27 @@
package com.intellectualcrafters.plot.generator;
import org.bukkit.configuration.ConfigurationSection;
import com.intellectualcrafters.plot.PlotMain;
public abstract class SquarePlotWorld extends GridPlotWorld {
public static int PLOT_WIDTH_DEFAULT = 42;
public static int ROAD_WIDTH_DEFAULT = 7;
public int PLOT_WIDTH;
public int ROAD_WIDTH;
@Override
public void loadConfiguration(final ConfigurationSection config) {
if (!config.contains("plot.height")) {
PlotMain.sendConsoleSenderMessage(" - &cConfiguration is null? (" + config.getCurrentPath() + ")");
}
this.PLOT_WIDTH = config.getInt("plot.size");
this.ROAD_WIDTH = config.getInt("road.width");
this.SIZE = (short) (this.PLOT_WIDTH + this.ROAD_WIDTH);
}
public SquarePlotWorld(String worldname) {
super(worldname);
}