diff --git a/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java b/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java index 60106a244..895d168ab 100644 --- a/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java +++ b/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java @@ -27,7 +27,7 @@ public abstract class SquarePlotManager extends GridPlotManager { final int pz = plotid.y; 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, 255, z); + return new Location(plotworld.worldname, x, Math.min(plotworld.MAX_BUILD_HEIGHT, 255), z); } @Override @@ -178,6 +178,6 @@ public abstract class SquarePlotManager extends GridPlotManager { final int pz = plotid.y; 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); + return new Location(plotworld.worldname, x, plotworld.MIN_BUILD_HEIGHT, z); } } diff --git a/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/src/main/java/com/intellectualcrafters/plot/object/Plot.java index 905d4daf0..c447c21bd 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -718,7 +718,7 @@ public class Plot { * Get the biome (String) */ public String getBiome() { - final Location loc = getBottom().add(1, 0, 1); + final Location loc = getBottom(); return BlockManager.manager.getBiome(loc.getWorld(), loc.getX(), loc.getZ()); } @@ -735,7 +735,7 @@ public class Plot { * @return */ public Location getBottom() { - return MainUtil.getPlotBottomLoc(world, id); + return MainUtil.getPlotBottomLoc(world, id).add(1, 0, 1); } /** diff --git a/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java b/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java index d3c9958ef..181abcf24 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java +++ b/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java @@ -61,6 +61,7 @@ public abstract class PlotWorld { public final static boolean WORLD_BORDER_DEFAULT = false; public final static int MAX_PLOT_MEMBERS_DEFAULT = 128; public final static int MAX_BUILD_HEIGHT_DEFAULT = 256; + public final static int MIN_BUILD_HEIGHT_DEFAULT = 1; public final static PlotGamemode GAMEMODE_DEFAULT = PlotGamemode.CREATIVE; // are plot clusters enabled // require claim in cluster @@ -97,6 +98,7 @@ public abstract class PlotWorld { public boolean HOME_ALLOW_NONMEMBER; public PlotLoc DEFAULT_HOME; public int MAX_BUILD_HEIGHT; + public int MIN_BUILD_HEIGHT; public PlotGamemode GAMEMODE = PlotGamemode.CREATIVE; public PlotWorld(final String worldname) { @@ -154,6 +156,7 @@ public abstract class PlotWorld { this.PLOT_CHAT = config.getBoolean("chat.enabled"); this.WORLD_BORDER = config.getBoolean("world.border"); this.MAX_BUILD_HEIGHT = config.getInt("world.max_height"); + this.MIN_BUILD_HEIGHT = config.getInt("min.max_height"); switch (config.getString("world.gamemode").toLowerCase()) { case "survival": @@ -260,6 +263,7 @@ public abstract class PlotWorld { options.put("home.default", "side"); options.put("home.allow-nonmembers", false); options.put("world.max_height", PlotWorld.MAX_BUILD_HEIGHT_DEFAULT); + options.put("world.min_height", PlotWorld.MIN_BUILD_HEIGHT_DEFAULT); options.put("world.gamemode", PlotWorld.GAMEMODE_DEFAULT.name().toLowerCase()); if (Settings.ENABLE_CLUSTERS && (this.TYPE != 0)) { diff --git a/src/main/java/com/intellectualcrafters/plot/object/RegionWrapper.java b/src/main/java/com/intellectualcrafters/plot/object/RegionWrapper.java index e536145e0..533fcd4f6 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/RegionWrapper.java +++ b/src/main/java/com/intellectualcrafters/plot/object/RegionWrapper.java @@ -3,6 +3,8 @@ package com.intellectualcrafters.plot.object; public class RegionWrapper { public final int minX; public final int maxX; + public final int minY; + public final int maxY; public final int minZ; public final int maxZ; @@ -11,6 +13,21 @@ public class RegionWrapper { this.minX = minX; this.maxZ = maxZ; this.minZ = minZ; + this.minY = 0; + this.maxY = 256; + } + + public RegionWrapper(final int minX, final int maxX, final int minY, final int maxY, final int minZ, final int maxZ) { + this.maxX = maxX; + this.minX = minX; + this.maxZ = maxZ; + this.minZ = minZ; + this.minY = minY; + this.maxY = maxY; + } + + public boolean isIn(final int x, final int y, final int z) { + return ((x >= this.minX) && (x <= this.maxX) && (z >= this.minZ) && (z <= this.maxZ) && (y >= this.minY) && (y <= this.maxY)); } public boolean isIn(final int x, final int z) { diff --git a/src/main/java/com/intellectualcrafters/plot/util/BO3Handler.java b/src/main/java/com/intellectualcrafters/plot/util/BO3Handler.java index a03e2d4fd..cb39d437a 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/BO3Handler.java +++ b/src/main/java/com/intellectualcrafters/plot/util/BO3Handler.java @@ -46,7 +46,7 @@ public class BO3Handler { return false; } String alias = plot.toString(); - Location pos1 = plot.getBottom().add(1, 0, 1); + Location pos1 = plot.getBottom(); Location pos2 = plot.getTop(); ClassicPlotWorld cpw = (ClassicPlotWorld) plotworld; int height = cpw.PLOT_HEIGHT; diff --git a/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index ea165d30b..62efdb258 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -1076,7 +1076,7 @@ public class MainUtil { return false; } long start = System.currentTimeMillis(); - ChunkManager.manager.clearAllEntities(plot.getBottom().add(1, 0, 1), plot.getTop()); + ChunkManager.manager.clearAllEntities(plot.getBottom(), plot.getTop()); if (isDelete) { removeSign(plot); } @@ -1200,7 +1200,7 @@ public class MainUtil { } public static void setBiome(final Plot plot, final String biome, final Runnable whenDone) { - Location pos1 = plot.getBottom().add(1, 0, 1); + Location pos1 = plot.getBottom(); Location pos2 = plot.getTop(); ChunkManager.chunkTask(pos1, pos2, new RunnableVal() { @Override @@ -1348,7 +1348,11 @@ public class MainUtil { * @param id * * @return Location bottom of mega plot + * + * @deprecated Incorrect offset / legacy / use plot.getBottom() + * */ + @Deprecated public static Location getPlotBottomLoc(final String world, PlotId id) { final Plot plot = PS.get().getPlot(world, id); if (plot != null) { diff --git a/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java b/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java index 45223eb68..1ef4db388 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java +++ b/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java @@ -164,7 +164,7 @@ public abstract class SchematicHandler { // Validate dimensions Location bottom = plot.getBottom(); Location top = plot.getTop(); - if (top.getX() - bottom.getX() < WIDTH || top.getZ() - bottom.getZ() < LENGTH || HEIGHT > 256) { + if (top.getX() - bottom.getX() + 1 < WIDTH || top.getZ() - bottom.getZ() + 1 < LENGTH || HEIGHT > 256) { PS.debug("Schematic is too large"); TaskManager.runTask(whenDone); return; diff --git a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index f2e9269d8..b82cb8287 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -2101,7 +2101,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen } } PlotWorld pw = PS.get().getPlotWorld(loc.getWorld()); - if (loc.getY() >= pw.MAX_BUILD_HEIGHT && !Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_HEIGHTLIMIT)) { + if ((loc.getY() > pw.MAX_BUILD_HEIGHT && loc.getY() < pw.MIN_BUILD_HEIGHT) && !Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_HEIGHTLIMIT)) { event.setCancelled(true); MainUtil.sendMessage(pp, C.HEIGHT_LIMIT.s().replace("{limit}", "" + pw.MAX_BUILD_HEIGHT)); } diff --git a/src/main/java/com/plotsquared/bukkit/listeners/worldedit/HeightLimitExtent.java b/src/main/java/com/plotsquared/bukkit/listeners/worldedit/HeightLimitExtent.java new file mode 100644 index 000000000..6e928b124 --- /dev/null +++ b/src/main/java/com/plotsquared/bukkit/listeners/worldedit/HeightLimitExtent.java @@ -0,0 +1,31 @@ +package com.plotsquared.bukkit.listeners.worldedit; + +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.extent.AbstractDelegateExtent; +import com.sk89q.worldedit.extent.Extent; + +public class HeightLimitExtent extends AbstractDelegateExtent { + + private int max; + private int min; + + public HeightLimitExtent(int min, int max, Extent child) { + super(child); + this.min = min; + this.max = max; + } + + + @Override + public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException { + int y = location.getBlockY(); + if (y < min || y > max) { + return false; + } + return super.setBlock(location, block); + } + + +} diff --git a/src/main/java/com/plotsquared/bukkit/listeners/worldedit/ProcessedWEExtent.java b/src/main/java/com/plotsquared/bukkit/listeners/worldedit/ProcessedWEExtent.java index af64ef1a7..c2aa6b9b9 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/worldedit/ProcessedWEExtent.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/worldedit/ProcessedWEExtent.java @@ -91,7 +91,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { BSblocked = true; PS.debug("&cPlotSquared detected unsafe WorldEdit: " + (location.getBlockX()) + "," + (location.getBlockZ())); } - if (WEManager.maskContains(mask, location.getBlockX(), location.getBlockZ())) { + if (WEManager.maskContains(mask, location.getBlockX(), location.getBlockY(), location.getBlockZ())) { if (count++ > max) { if (parent != null) { try { @@ -113,7 +113,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { int x = location.getBlockX(); int y = location.getBlockY(); int z = location.getBlockZ(); - if (WEManager.maskContains(mask, location.getBlockX(), location.getBlockZ())) { + if (WEManager.maskContains(mask, location.getBlockX(), location.getBlockY(), location.getBlockZ())) { if (count++ > max) { if (parent != null) { try { @@ -251,7 +251,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { Eblocked = true; PS.debug("&cPlotSquared detected unsafe WorldEdit: " + (location.getBlockX()) + "," + (location.getBlockZ())); } - if (WEManager.maskContains(mask, location.getBlockX(), location.getBlockZ())) { + if (WEManager.maskContains(mask, location.getBlockX(), location.getBlockY(), location.getBlockZ())) { return super.createEntity(location, entity); } return null; diff --git a/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEExtent.java b/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEExtent.java index 4656409fe..4afccf2a8 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEExtent.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEExtent.java @@ -24,7 +24,7 @@ public class WEExtent extends AbstractDelegateExtent { @Override public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException { - if (WEManager.maskContains(mask, location.getBlockX(), location.getBlockZ())) { + if (WEManager.maskContains(mask, location.getBlockX(), location.getBlockY(), location.getBlockZ())) { return super.setBlock(location, block); } return false; @@ -32,7 +32,7 @@ public class WEExtent extends AbstractDelegateExtent { @Override public Entity createEntity(Location location, BaseEntity entity) { - if (WEManager.maskContains(mask, location.getBlockX(), location.getBlockZ())) { + if (WEManager.maskContains(mask, location.getBlockX(), location.getBlockY(), location.getBlockZ())) { return super.createEntity(location, entity); } return null; diff --git a/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEListener.java b/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEListener.java index 42f6990b9..fa0f091a4 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEListener.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEListener.java @@ -115,10 +115,10 @@ public class WEListener implements Listener { if (!WEManager.regionContains(region, mask)) { arg = "pos1 + pos2"; } - else if (!WEManager.maskContains(mask, pos1.getBlockX(), pos1.getBlockZ())) { + else if (!WEManager.maskContains(mask, pos1.getBlockX(), pos1.getBlockY(), pos1.getBlockZ())) { arg = "pos1"; } - else if (!WEManager.maskContains(mask, pos2.getBlockX(), pos2.getBlockZ())) { + else if (!WEManager.maskContains(mask, pos2.getBlockX(), pos2.getBlockY(), pos2.getBlockZ())) { arg = "pos2"; } if (arg != null) { diff --git a/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEManager.java b/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEManager.java index 0a977429c..ee552b243 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEManager.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEManager.java @@ -15,9 +15,18 @@ import com.intellectualcrafters.plot.util.MainUtil; public class WEManager { // public static HashSet bypass = new HashSet<>(); + public static boolean maskContains(HashSet mask, int x, int y, int z) { + for (RegionWrapper region : mask) { + if (region.isIn(x, y, z)) { + return true; + } + } + return false; + } + public static boolean maskContains(HashSet mask, int x, int z) { for (RegionWrapper region : mask) { - if ((x >= region.minX) && (x <= region.maxX) && (z >= region.minZ) && (z <= region.maxZ)) { + if (region.isIn(x, z)) { return true; } } @@ -40,7 +49,7 @@ public class WEManager { if (Settings.WE_ALLOW_HELPER ? plot.isAdded(uuid) : (plot.isOwner(uuid) || plot.getTrusted().contains(uuid))) { Location pos1 = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1); Location pos2 = MainUtil.getPlotTopLoc(plot.world, plot.id); - regions.add(new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ())); + regions.add(new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getY(), pos2.getY(), pos1.getZ(), pos2.getZ())); } } return regions; diff --git a/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WESubscriber.java b/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WESubscriber.java index 70db49bee..e1f590b08 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WESubscriber.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WESubscriber.java @@ -10,6 +10,7 @@ import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; @@ -62,14 +63,19 @@ public class WESubscriber { PlotPlayer player = UUIDHandler.getPlayer(actor.getName()); HashSet mask = WEManager.getMask(player); + PlotWorld plotworld = PS.get().getPlotWorld(world); if (mask.size() == 0) { if (Permissions.hasPermission(player, "plots.worldedit.bypass")) { MainUtil.sendMessage(player, C.WORLDEDIT_BYPASS); } - if (PS.get().isPlotWorld(world)) { + if (plotworld != null) { event.setExtent(new NullExtent()); } return; + } + HeightLimitExtent heightLimit = null; + if (plotworld != null) { + } if (Settings.CHUNK_PROCESSOR) { if (Settings.EXPERIMENTAL_FAST_ASYNC_WORLDEDIT) { diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java b/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java index 92938804e..314d282cc 100644 --- a/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java +++ b/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java @@ -1016,8 +1016,8 @@ public class BukkitChunkManager extends ChunkManager { // TODO clear all entities - clearAllEntities(plot1.getBottom().add(1, 0, 1), plot1.getTop()); - clearAllEntities(plot2.getBottom().add(1, 0, 1), plot2.getTop()); + clearAllEntities(plot1.getBottom(), plot1.getTop()); + clearAllEntities(plot2.getBottom(), plot2.getTop()); } @Override diff --git a/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java b/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java index 47f42e9c0..3340f5907 100644 --- a/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java +++ b/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java @@ -33,7 +33,7 @@ public class SpongeChunkManager extends ChunkManager { @Override public int[] countEntities(Plot plot) { - Location pos1 = plot.getBottom().add(1, 0, 1); + Location pos1 = plot.getBottom(); Location pos2 = plot.getTop(); String worldname = pos1.getWorld();