From 8a4e19ab404269b48ff754a69699d39aeec0e8c7 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Thu, 16 Jul 2015 20:32:04 +1000 Subject: [PATCH] Add optional world offset --- .../plot/commands/MusicSubcommand.java | 38 +++++++++---------- .../intellectualcrafters/plot/config/C.java | 2 +- .../database/plotme/LikePlotMeConverter.java | 2 +- .../plot/generator/ClassicPlotWorld.java | 7 +--- .../plot/generator/HybridGen.java | 12 +++--- .../plot/generator/HybridPlotWorld.java | 19 +--------- .../plot/generator/HybridPop.java | 4 +- .../plot/generator/SquarePlotManager.java | 12 ++++-- .../plot/generator/SquarePlotWorld.java | 6 +++ .../plot/util/BukkitSchematicHandler.java | 1 - 10 files changed, 46 insertions(+), 57 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MusicSubcommand.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MusicSubcommand.java index e8150d205..2dae6f83a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MusicSubcommand.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MusicSubcommand.java @@ -50,26 +50,26 @@ public class MusicSubcommand extends SubCommand { sendMessage(player, C.NO_PLOT_PERMS); return true; } - PlotInventory inv = new PlotInventory(player, 2, "Plot Jukebox") { - public boolean onClick(int index) { - PlotItemStack item = getItem(index); - int id = item.id == 7 ? 0 : item.id; - if (id == 0) { - FlagManager.removePlotFlag(plot, "music"); - } - else { - FlagManager.addPlotFlag(plot, new Flag(FlagManager.getFlag("music"), id)); - } - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - PlotListener.manager.plotEntry(player, plot); - } - }, 1); - close(); - return false; +PlotInventory inv = new PlotInventory(player, 2, "Plot Jukebox") { + public boolean onClick(int index) { + PlotItemStack item = getItem(index); + int id = item.id == 7 ? 0 : item.id; + if (id == 0) { + FlagManager.removePlotFlag(plot, "music"); + } + else { + FlagManager.addPlotFlag(plot, new Flag(FlagManager.getFlag("music"), id)); + } + TaskManager.runTaskLater(new Runnable() { + @Override + public void run() { + PlotListener.manager.plotEntry(player, plot); } - }; + }, 1); + close(); + return false; + } +}; int index = 0; for (int i = 2256; i < 2268; i++) { String name = "&r&6" + BlockManager.manager.getClosestMatchingName(new PlotBlock((short) i, (byte) 0)); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java index 24d905a28..cf1d88958 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -527,7 +527,7 @@ public enum C { C(final String d, final boolean prefix, String cat) { this.d = d; if (this.s == null) { - this.s = ""; + this.s = d; } this.prefix = prefix; this.cat = cat.toLowerCase(); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/LikePlotMeConverter.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/LikePlotMeConverter.java index a776a1e68..12fd2428c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/LikePlotMeConverter.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/LikePlotMeConverter.java @@ -161,11 +161,11 @@ public class LikePlotMeConverter { connector.copyConfig(plotConfig, world, actualWorldName); PS.get().config.save(PS.get().configFile); } catch (final Exception e) { + e.printStackTrace(); sendMessage("&c-- &lFailed to save configuration for world '" + world + "'\nThis will need to be done using the setup command, or manually"); } } } - HashMap> plots = connector.getPlotMePlots(connection); for (Entry> entry : plots.entrySet()) { plotCount += entry.getValue().size(); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotWorld.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotWorld.java index 72fa18284..a87a24f68 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotWorld.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotWorld.java @@ -48,22 +48,17 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld { */ @Override public void loadConfiguration(final ConfigurationSection config) { - if (!config.contains("plot.height")) { - PS.log(" - &cConfiguration is null? (" + config.getCurrentPath() + ")"); - } + super.loadConfiguration(config); this.PLOT_BEDROCK = config.getBoolean("plot.bedrock"); this.PLOT_HEIGHT = Math.min(255, config.getInt("plot.height")); - this.PLOT_WIDTH = config.getInt("plot.size"); this.MAIN_BLOCK = (PlotBlock[]) Configuration.BLOCKLIST.parseString(StringUtils.join(config.getStringList("plot.filling"), ',')); this.TOP_BLOCK = (PlotBlock[]) Configuration.BLOCKLIST.parseString(StringUtils.join(config.getStringList("plot.floor"), ',')); this.WALL_BLOCK = (PlotBlock) Configuration.BLOCK.parseString(config.getString("wall.block")); - this.ROAD_WIDTH = config.getInt("road.width"); this.ROAD_HEIGHT = Math.min(255, config.getInt("road.height")); this.ROAD_BLOCK = (PlotBlock) Configuration.BLOCK.parseString(config.getString("road.block")); this.WALL_FILLING = (PlotBlock) Configuration.BLOCK.parseString(config.getString("wall.filling")); this.WALL_HEIGHT = Math.min(254, config.getInt("wall.height")); this.CLAIMED_WALL_BLOCK = (PlotBlock) Configuration.BLOCK.parseString(config.getString("wall.block_claimed")); - this.SIZE = (short) (this.PLOT_WIDTH + this.ROAD_WIDTH); } public ClassicPlotWorld(final String worldname) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java index 63453db53..b12f36195 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java @@ -171,8 +171,8 @@ public class HybridGen extends PlotGenerator { } } - int sx = (short) ((this.X) % this.size); - int sz = (short) ((this.Z) % this.size); + int sx = (short) ((this.X - this.plotworld.ROAD_OFFSET_X) % this.size); + int sz = (short) ((this.Z - this.plotworld.ROAD_OFFSET_Z) % this.size); if (sx < 0) { sx += this.size; } @@ -182,6 +182,7 @@ public class HybridGen extends PlotGenerator { if (region != null) { for (short x = 0; x < 16; x++) { + final int absX = ((sx + x) % this.size); for (short z = 0; z < 16; z++) { if (biomes != null) { biomes.setBiome(x, z, this.biome); @@ -191,7 +192,6 @@ public class HybridGen extends PlotGenerator { setBlock(x, y, z, this.filling); } setBlock(x, this.plotheight, z, this.plotfloors); - final int absX = ((sx + x) % this.size); final int absZ = ((sz + z) % this.size); final PlotLoc loc = new PlotLoc(absX, absZ); final HashMap blocks = plotworld.G_SCH.get(loc); @@ -207,15 +207,15 @@ public class HybridGen extends PlotGenerator { } for (short x = 0; x < 16; x++) { + final int absX = ((sx + x) % this.size); + final boolean gx = absX > this.pathWidthLower; + final boolean lx = absX < this.pathWidthUpper; for (short z = 0; z < 16; z++) { if (biomes != null) { biomes.setBiome(x, z, this.biome); } - final int absX = ((sx + x) % this.size); final int absZ = ((sz + z) % this.size); - final boolean gx = absX > this.pathWidthLower; final boolean gz = absZ > this.pathWidthLower; - final boolean lx = absX < this.pathWidthUpper; final boolean lz = absZ < this.pathWidthUpper; // inside plot if (gx && gz && lx && lz) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java index b5ae6be3d..5a0c13d24 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java @@ -62,22 +62,7 @@ public class HybridPlotWorld extends ClassicPlotWorld { */ @Override public void loadConfiguration(final ConfigurationSection config) { - if (!config.contains("plot.height")) { - PS.log(" - &cConfiguration is null? (" + config.getCurrentPath() + ")"); - } - this.PLOT_BEDROCK = config.getBoolean("plot.bedrock"); - this.PLOT_HEIGHT = Math.min(255, config.getInt("plot.height")); - this.PLOT_WIDTH = config.getInt("plot.size"); - this.MAIN_BLOCK = (PlotBlock[]) Configuration.BLOCKLIST.parseString(StringUtils.join(config.getStringList("plot.filling"), ',')); - this.TOP_BLOCK = (PlotBlock[]) Configuration.BLOCKLIST.parseString(StringUtils.join(config.getStringList("plot.floor"), ',')); - this.WALL_BLOCK = (PlotBlock) Configuration.BLOCK.parseString(config.getString("wall.block")); - this.ROAD_WIDTH = config.getInt("road.width"); - this.ROAD_HEIGHT = Math.min(255, config.getInt("road.height")); - this.ROAD_BLOCK = (PlotBlock) Configuration.BLOCK.parseString(config.getString("road.block")); - this.WALL_FILLING = (PlotBlock) Configuration.BLOCK.parseString(config.getString("wall.filling")); - this.WALL_HEIGHT = Math.min(254, config.getInt("wall.height")); - this.CLAIMED_WALL_BLOCK = (PlotBlock) Configuration.BLOCK.parseString(config.getString("wall.block_claimed")); - this.SIZE = (short) (this.PLOT_WIDTH + this.ROAD_WIDTH); + super.loadConfiguration(config); if ((this.ROAD_WIDTH % 2) == 0) { this.PATH_WIDTH_LOWER = (short) (Math.floor(this.ROAD_WIDTH / 2) - 1); } else { @@ -100,7 +85,7 @@ public class HybridPlotWorld extends ClassicPlotWorld { final Schematic schem1 = SchematicHandler.manager.getSchematic(schem1Str); final Schematic schem2 = SchematicHandler.manager.getSchematic(schem2Str); final Schematic schem3 = SchematicHandler.manager.getSchematic(schem3Str); - final int shift = (int) Math.floor(this.ROAD_WIDTH / 2); + final int shift = (int) this.ROAD_WIDTH / 2; int oddshift = 0; if ((this.ROAD_WIDTH % 2) != 0) { oddshift = 1; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPop.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPop.java index e43c193f1..8f7d5cd0c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPop.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPop.java @@ -113,8 +113,8 @@ public class HybridPop extends PlotPopulator { public void populate(World world, RegionWrapper requiredRegion, PseudoRandom random, int cx, int cz) { PS.get().getPlotManager(world.getName()); - int sx = (short) ((this.X) % this.size); - int sz = (short) ((this.Z) % this.size); + int sx = (short) ((this.X - this.plotworld.ROAD_OFFSET_X) % this.size); + int sz = (short) ((this.Z - this.plotworld.ROAD_OFFSET_Z) % this.size); if (sx < 0) { sx += this.size; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java index fdc2a6e18..f25240e67 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java @@ -26,14 +26,16 @@ public abstract class SquarePlotManager extends GridPlotManager { 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; + final int x = dpw.ROAD_OFFSET_X + (px * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH)) - ((int) Math.floor(dpw.ROAD_WIDTH / 2)) - 1; + final int z = dpw.ROAD_OFFSET_Z + (pz * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH)) - ((int) Math.floor(dpw.ROAD_WIDTH / 2)) - 1; return new Location(plotworld.worldname, x, 256, z); } @Override public PlotId getPlotIdAbs(final PlotWorld plotworld, int x, final int y, int z) { final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld); + x -= dpw.ROAD_OFFSET_X; + z -= dpw.ROAD_OFFSET_Z; int pathWidthLower; int end; if (dpw.ROAD_WIDTH == 0) { @@ -81,6 +83,8 @@ public abstract class SquarePlotManager extends GridPlotManager { if (plotworld == null) { return null; } + x -= dpw.ROAD_OFFSET_X; + z -= dpw.ROAD_OFFSET_Z; final int size = dpw.PLOT_WIDTH + dpw.ROAD_WIDTH; int pathWidthLower; final int end; @@ -173,8 +177,8 @@ public abstract class SquarePlotManager extends GridPlotManager { 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; + final int x = dpw.ROAD_OFFSET_X + (px * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH)) - dpw.PLOT_WIDTH - ((int) Math.floor(dpw.ROAD_WIDTH / 2)) - 1; + final int z = dpw.ROAD_OFFSET_Z + (pz * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH)) - dpw.PLOT_WIDTH - ((int) Math.floor(dpw.ROAD_WIDTH / 2)) - 1; return new Location(plotworld.worldname, x, 1, z); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotWorld.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotWorld.java index bb4fe2cf6..5973e1609 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotWorld.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotWorld.java @@ -6,8 +6,12 @@ import com.intellectualcrafters.plot.PS; public abstract class SquarePlotWorld extends GridPlotWorld { public static int PLOT_WIDTH_DEFAULT = 42; public static int ROAD_WIDTH_DEFAULT = 7; + public static int ROAD_OFFSET_X_DEFAULT = 0; + public static int ROAD_OFFSET__Z_DEFAULT = 0; public int PLOT_WIDTH; public int ROAD_WIDTH; + public int ROAD_OFFSET_X; + public int ROAD_OFFSET_Z; @Override public void loadConfiguration(final ConfigurationSection config) { @@ -16,6 +20,8 @@ public abstract class SquarePlotWorld extends GridPlotWorld { } this.PLOT_WIDTH = config.getInt("plot.size"); this.ROAD_WIDTH = config.getInt("road.width"); + this.ROAD_OFFSET_X = config.getInt("road.offset.x"); + this.ROAD_OFFSET_Z = config.getInt("road.offset.z"); this.SIZE = (short) (this.PLOT_WIDTH + this.ROAD_WIDTH); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BukkitSchematicHandler.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BukkitSchematicHandler.java index f1634316a..c6c6b29f6 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BukkitSchematicHandler.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BukkitSchematicHandler.java @@ -104,7 +104,6 @@ public class BukkitSchematicHandler extends SchematicHandler { int i2 = i1 + (z * width); for (int x = 0; x < width; x++) { final int index = i2 + x; - Block block = worldObj.getBlockAt(sx + x, sy + y, sz + z); int id = block.getTypeId(); switch(id) {