From 25355f4906c7c33aa775a85bb318293d23a6d63b Mon Sep 17 00:00:00 2001 From: boy0001 Date: Sat, 31 Jan 2015 18:09:48 +1100 Subject: [PATCH] Added cluster regeneration --- .../intellectualcrafters/plot/PlotMain.java | 17 +- .../plot/commands/Auto.java | 6 +- .../plot/commands/Cluster.java | 110 ++++++++-- .../intellectualcrafters/plot/config/C.java | 3 +- .../plot/database/SQLManager.java | 2 +- .../plot/generator/AugmentedPopulator.java | 103 ++++++--- .../plot/generator/HybridGen.java | 12 +- .../plot/listeners/PlayerEvents.java | 205 ++++++++---------- .../plot/listeners/PlotListener.java | 23 +- .../plot/object/PlotWorld.java | 8 +- .../plot/util/ClusterManager.java | 83 ++++++- .../plot/util/PlayerFunctions.java | 2 +- .../plot/util/TaskManager.java | 4 + 13 files changed, 390 insertions(+), 188 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java index f3551b5c6..bad683125 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java @@ -82,6 +82,7 @@ import com.intellectualcrafters.plot.events.PlotDeleteEvent; import com.intellectualcrafters.plot.flag.AbstractFlag; import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagValue; +import com.intellectualcrafters.plot.generator.AugmentedPopulator; import com.intellectualcrafters.plot.generator.HybridGen; import com.intellectualcrafters.plot.generator.HybridPlotManager; import com.intellectualcrafters.plot.generator.HybridPlotWorld; @@ -93,6 +94,7 @@ import com.intellectualcrafters.plot.listeners.PlotPlusListener; import com.intellectualcrafters.plot.listeners.WorldEditListener; import com.intellectualcrafters.plot.listeners.WorldGuardListener; import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotGenerator; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotManager; @@ -277,7 +279,7 @@ public class PlotMain extends JavaPlugin implements Listener { final String[] nodes = perm.split("\\."); final StringBuilder n = new StringBuilder(); for (int i = 0; i < (nodes.length - 1); i++) { - n.append(nodes[i]).append("."); + n.append(nodes[i] + (".")); if (player.hasPermission(n + "*")) { return true; } @@ -915,7 +917,7 @@ public class PlotMain extends JavaPlugin implements Listener { } } } - + public static void loadWorld(final String world, final ChunkGenerator generator) { if (getWorldSettings(world) != null) { return; @@ -967,13 +969,22 @@ public class PlotMain extends JavaPlugin implements Listener { PlotWorld.REQUIRE_CLAIM_IN_CLUSTER_DEFAULT = true; plotWorld.saveConfiguration(config.getConfigurationSection(path)); - plotWorld.loadConfiguration(config.getConfigurationSection(path)); + plotWorld.loadDefaultConfiguration(config.getConfigurationSection(path)); PlotWorld.REQUIRE_CLAIM_IN_CLUSTER_DEFAULT = false; try { config.save(configFile); } catch (final IOException e) { e.printStackTrace(); } + if (plotWorld.REQUIRE_CLUSTER) { + if (ClusterManager.getClusters(world).size() > 0) { + HybridGen gen = new HybridGen(world); + gen.plotworld = (HybridPlotWorld) plotWorld; + for (PlotCluster cluster : ClusterManager.getClusters(world)) { + new AugmentedPopulator(world, gen, cluster); + } + } + } // Now add it :p addPlotWorld(world, plotWorld, plotManager); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java index ff5196e61..4619b1a82 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java @@ -177,14 +177,14 @@ public class Auto extends SubCommand { PlotId top = cluster.getP2(); PlotId origin = new PlotId((bot.x + top.x) / 2, (bot.y + top.y) / 2); PlotId id = new PlotId(0, 0); - int width = Math.max(top.x - bot.x, top.y - bot.y); + int width = Math.max(top.x - bot.x + 1, top.y - bot.y + 1); int max = width * width; // for (int i = 0; i <= max; i++) { PlotId currentId = new PlotId(origin.x + id.x, origin.y + id.y); Plot current = PlotHelper.getPlot(world, currentId); - if (current != null && !current.hasOwner() && cluster.equals(ClusterManager.getCluster(current))) { - Claim.claimPlot(plr, plot, true, true); + if (current != null && (current.hasOwner() == false) && (current.settings.isMerged() == false) && cluster.equals(ClusterManager.getCluster(current))) { + Claim.claimPlot(plr, current, true, true); return true; } id = getNextPlot(id, 1); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java index 950400a89..39c4e568e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java @@ -21,16 +21,21 @@ package com.intellectualcrafters.plot.commands; +import java.util.ArrayList; import java.util.HashSet; +import java.util.Iterator; import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; +import org.bukkit.generator.BlockPopulator; import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.generator.AugmentedPopulator; +import com.intellectualcrafters.plot.generator.HybridPlotWorld; import com.intellectualcrafters.plot.object.BlockLoc; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotCluster; @@ -59,6 +64,7 @@ public class Cluster extends SubCommand { } String sub = args[0].toLowerCase(); switch (sub) { + case "l": case "list": { if (!PlotMain.hasPermission(plr, "plots.cluster.list")) { PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.list"); @@ -88,6 +94,7 @@ public class Cluster extends SubCommand { } return true; } + case "c": case "create": { if (!PlotMain.hasPermission(plr, "plots.cluster.create")) { PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.create"); @@ -115,7 +122,7 @@ public class Cluster extends SubCommand { //check if overlap PlotClusterId id = new PlotClusterId(pos1, pos2); HashSet intersects = ClusterManager.getIntersects(plr.getWorld().getName(), id); - if (intersects.size() > 0) { + if (intersects.size() > 0 || pos2.x < pos1.x || pos2.y < pos1.y) { PlayerFunctions.sendMessage(plr, C.CLUSTER_INTERSECTION, intersects.size() + ""); return false; } @@ -136,9 +143,15 @@ public class Cluster extends SubCommand { DBFunc.setInvited(world, cluster, plot.owner); } } + if (!PlotMain.isPlotWorld(world)) { + PlotMain.config.createSection("worlds." + world); + PlotMain.loadWorld(plr.getWorld()); + } PlayerFunctions.sendMessage(plr, C.CLUSTER_ADDED); return true; } + case "disband": + case "del": case "delete": { if (!PlotMain.hasPermission(plr, "plots.cluster.delete")) { PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.delete"); @@ -163,10 +176,6 @@ public class Cluster extends SubCommand { return false; } } - if (cluster == null) { - PlayerFunctions.sendMessage(plr, C.NOT_IN_CLUSTER); - return false; - } if (!cluster.owner.equals(UUIDHandler.getUUID(plr))) { if (!PlotMain.hasPermission(plr, "plots.cluster.delete.other")) { PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.delete.other"); @@ -175,20 +184,37 @@ public class Cluster extends SubCommand { } PlotWorld plotworld = PlotMain.getWorldSettings(plr.getWorld()); if (plotworld.REQUIRE_CLUSTER) { + ArrayList toRemove = new ArrayList<>(); for (Plot plot : PlotMain.getPlots(plr.getWorld()).values()) { PlotCluster other = ClusterManager.getCluster(plot); if (cluster.equals(other)) { - String world = plr.getWorld().getName(); - DBFunc.delete(world, plot); + toRemove.add(plot); + } + } + for (Plot plot : toRemove) { + DBFunc.delete(plot.world, plot); + } + } + DBFunc.delete(cluster); + if (plotworld.REQUIRE_CLUSTER) { + for (Iterator iterator = plr.getWorld().getPopulators().iterator(); iterator.hasNext();) { + BlockPopulator populator = iterator.next(); + if (populator instanceof AugmentedPopulator) { + if (((AugmentedPopulator) populator).cluster.equals(cluster)) { + iterator.remove(); + } } } } - String world_delete = plr.getWorld().getName(); - ClusterManager.clusters.get(world_delete).remove(cluster); - DBFunc.delete(cluster); + for (String set : ClusterManager.clusters.keySet()) { + } + ClusterManager.last = null; + ClusterManager.clusters.get(cluster.world).remove(cluster); + ClusterManager.regenCluster(cluster); PlayerFunctions.sendMessage(plr, C.CLUSTER_DELETED); return true; } + case "res": case "resize": { if (!PlotMain.hasPermission(plr, "plots.cluster.resize")) { PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize"); @@ -199,8 +225,8 @@ public class Cluster extends SubCommand { return false; } // check pos1 / pos2 - PlotId pos1 = PlotHelper.parseId(args[2]); - PlotId pos2 = PlotHelper.parseId(args[3]); + PlotId pos1 = PlotHelper.parseId(args[1]); + PlotId pos2 = PlotHelper.parseId(args[2]); if (pos1 == null || pos2 == null) { PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_ID); return false; @@ -220,8 +246,8 @@ public class Cluster extends SubCommand { //check if overlap PlotClusterId id = new PlotClusterId(pos1, pos2); HashSet intersects = ClusterManager.getIntersects(plr.getWorld().getName(), id); - if (intersects.size() > 0) { - PlayerFunctions.sendMessage(plr, C.CLUSTER_INTERSECTION, intersects.size() + ""); + if (intersects.size() > 1) { + PlayerFunctions.sendMessage(plr, C.CLUSTER_INTERSECTION, (intersects.size() - 1) + ""); return false; } // resize cluster @@ -229,6 +255,44 @@ public class Cluster extends SubCommand { PlayerFunctions.sendMessage(plr, C.CLUSTER_RESIZED); return true; } + case "reg": + case "regenerate": + case "regen": { + if (!PlotMain.hasPermission(plr, "plots.cluster.delete")) { + PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.regen"); + return false; + } + if (args.length != 1 && args.length != 2) { + PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster regen [name]"); + return false; + } + PlotCluster cluster; + if (args.length == 2) { + cluster = ClusterManager.getCluster(plr.getWorld().getName(), args[1]); + if (cluster == null) { + PlayerFunctions.sendMessage(plr, C.INVALID_CLUSTER, args[1]); + return false; + } + } + else { + cluster = ClusterManager.getCluster(plr.getLocation()); + if (cluster == null) { + PlayerFunctions.sendMessage(plr, C.NOT_IN_CLUSTER); + return false; + } + } + if (!cluster.owner.equals(UUIDHandler.getUUID(plr))) { + if (!PlotMain.hasPermission(plr, "plots.cluster.regen.other")) { + PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.regen.other"); + return false; + } + } + ClusterManager.regenCluster(cluster); + PlayerFunctions.sendMessage(plr, C.CLUSTER_REGENERATED); + return true; + } + case "add": + case "inv": case "invite": { if (!PlotMain.hasPermission(plr, "plots.cluster.invite")) { PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.invite"); @@ -269,6 +333,8 @@ public class Cluster extends SubCommand { PlayerFunctions.sendMessage(plr, C.CLUSTER_ADDED_USER); return true; } + case "k": + case "remove": case "kick": { if (!PlotMain.hasPermission(plr, "plots.cluster.kick")) { PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.kick"); @@ -320,6 +386,7 @@ public class Cluster extends SubCommand { PlayerFunctions.sendMessage(plr, C.CLUSTER_KICKED_USER); return true; } + case "quit": case "leave": { if (!PlotMain.hasPermission(plr, "plots.cluster.leave")) { PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.leave"); @@ -369,6 +436,8 @@ public class Cluster extends SubCommand { } return true; } + case "admin": + case "helper": case "helpers": { if (!PlotMain.hasPermission(plr, "plots.cluster.helpers")) { PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.helpers"); @@ -399,6 +468,8 @@ public class Cluster extends SubCommand { PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster helpers "); return false; } + case "spawn": + case "home": case "tp": { if (!PlotMain.hasPermission(plr, "plots.cluster.tp")) { PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.tp"); @@ -423,7 +494,10 @@ public class Cluster extends SubCommand { plr.teleport(ClusterManager.getHome(cluster)); return PlayerFunctions.sendMessage(plr, C.CLUSTER_TELEPORTING); } - case "info": { + case "i": + case "info": + case "show": + case "information": { if (!PlotMain.hasPermission(plr, "plots.cluster.info")) { PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.info"); return false; @@ -453,7 +527,7 @@ public class Cluster extends SubCommand { owner = "unknown"; } String name = cluster.getName(); - String size = (cluster.getP2().x - cluster.getP1().x) + "x" + (cluster.getP2().y - cluster.getP1().y); + String size = (cluster.getP2().x - cluster.getP1().x + 1) + "x" + (cluster.getP2().y - cluster.getP1().y + 1); String rights = cluster.hasRights(UUIDHandler.getUUID(plr)) + ""; String message = C.CLUSTER_INFO.s(); @@ -466,6 +540,8 @@ public class Cluster extends SubCommand { PlayerFunctions.sendMessage(plr, message); return true; } + case "sh": + case "setspawn": case "sethome": { if (!PlotMain.hasPermission(plr, "plots.cluster.sethome")) { PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.sethome"); @@ -498,6 +574,4 @@ public class Cluster extends SubCommand { PlayerFunctions.sendMessage(plr, C.CLUSTER_AVAILABLE_ARGS); return false; } - - } 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 bb2614720..cf3fdcc9d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -57,6 +57,7 @@ public enum C { CLUSTER_CANNOT_LEAVE("&cYou must delete or transfer ownership before leaving"), CLUSTER_ADDED_HELPER("&6Successfully added a helper to the cluster"), CLUSTER_REMOVED_HELPER("&6Successfully removed a helper to the cluster"), + CLUSTER_REGENERATED("&6Successfully started cluster regeneration"), CLUSTER_TELEPORTING("&6Teleporting..."), CLUSTER_INFO("&6Current cluster: &7%id%\n&6Name: &7%name%\n&6Owner: &7%owner%\n&6Size: &7%size%\n&6Rights: &7%rights%"), /* @@ -332,7 +333,7 @@ public enum C { * Clearing */ CLEARING_PLOT("&cClearing plot async."), - CLEARING_DONE("&6Done, took &a%time%&6 ms!"), + CLEARING_DONE("&6Clear completed!"), CLEARING_DONE_PACKETS("&6(&a%time% &6ms for packets)"), /* * Claiming diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index da85580c7..6ca343dd5 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -1629,7 +1629,7 @@ public class SQLManager implements AbstractDB { public void run() { PreparedStatement stmt = null; try { - stmt = SQLManager.this.connection.prepareStatement("UPDATE `" + SQLManager.this.prefix + "cluster` SET `pos1_x` = ?, `pos1_z` = ?, `pos2_x` = ?, `pos2_z` = ? WHERE `cluster_id` = ?"); + stmt = SQLManager.this.connection.prepareStatement("UPDATE `" + SQLManager.this.prefix + "cluster` SET `pos1_x` = ?, `pos1_z` = ?, `pos2_x` = ?, `pos2_z` = ? WHERE `id` = ?"); stmt.setInt(1, pos1.x); stmt.setInt(2, pos1.y); stmt.setInt(3, pos2.x); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java index 06c64cc3b..fe03e7d29 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java @@ -10,6 +10,7 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.generator.BlockPopulator; +import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.object.BlockWrapper; import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotGenerator; @@ -18,12 +19,14 @@ import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.PlotHelper; +import com.intellectualcrafters.plot.util.TaskManager; public class AugmentedPopulator extends BlockPopulator { public final PlotWorld plotworld; public final PlotManager manager; public final PlotGenerator generator; + public final PlotCluster cluster; private final int bx; private final int bz; @@ -35,12 +38,18 @@ public class AugmentedPopulator extends BlockPopulator { int a = (j - ((y & 0xF) << 8)); int z = (a >> 4); int x = a - (z << 4); - return (c && (z < bz || z > tz || x < bx || x > tx)) ? null : new BlockWrapper(x, y, z, r[i][j], (byte) 0); + if (r[i] == null) { + return (c && (Z + z < bz || Z + z > tz || X + x < bx || X + x > tx)) ? null : new BlockWrapper(x, y, z, (short) 0, (byte) 0); + } + else { + return (c && (Z + z < bz || Z + z > tz || X + x < bx || X + x > tx)) ? null : new BlockWrapper(x, y, z, r[i][j], (byte) 0); + } } public AugmentedPopulator(String world, PlotGenerator generator, PlotCluster cluster) { + this.cluster = cluster; this.generator = generator; - this.plotworld = generator.getNewPlotWorld(world); + this.plotworld = PlotMain.getWorldSettings(world); this.manager = generator.getPlotManager(); World bukkitWorld = Bukkit.getWorld(world); @@ -55,23 +64,27 @@ public class AugmentedPopulator extends BlockPopulator { this.tz = t.getBlockZ(); // Add the populator - bukkitWorld.getPopulators().add(this); + if (this.plotworld.CLUSTER_ORE) { + bukkitWorld.getPopulators().add(0, this); + } + else { + bukkitWorld.getPopulators().add(this); + } } @Override - public void populate(World world, Random rand, Chunk chunk) { - int X = chunk.getX(); - int Z = chunk.getZ(); - int x = X << 4; - int z = Z << 4; + public void populate(final World world, final Random rand, Chunk chunk) { + final int X = chunk.getX(); + final int Z = chunk.getZ(); + final int x = X << 4; + final int z = Z << 4; int x2 = x + 15; int z2 = z + 15; - boolean inX1 = (x > bx && x < tx); - boolean inX2 = (x2 > bx && x2 < tx); - boolean inZ1 = (z > bz && z < tz); - boolean inZ2 = (z2 > bz && z2 < tz); - + boolean inX1 = (x >= bx && x <= tx); + boolean inX2 = (x2 >= bx && x2 <= tx); + boolean inZ1 = (z >= bz && z <= tz); + boolean inZ2 = (z2 >= bz && z2 <= tz); boolean inX = inX1 || inX2; boolean inZ = inZ1 || inZ2; @@ -79,25 +92,61 @@ public class AugmentedPopulator extends BlockPopulator { if (!inX || !inZ) { return; } - boolean check; - if (!inX1 || !inX2 || !inZ1 || inZ2) { + + final boolean check; + if (!inX1 || !inX2 || !inZ1 || !inZ2) { check = true; } else { check = false; } - short[][] result = generator.generateExtBlockSections(world, rand, X, Z, null); - int d2_length = result[0].length; - for(int i = 0; i < result.length; i++) { - for(int j = 0; j < d2_length; j++) { - BlockWrapper blockInfo = getBlock(x, z, i, j, result, check); - if (blockInfo == null) { - continue; - } - PlotBlock plotblock = new PlotBlock((short) blockInfo.id, (byte) 0 ); - Block block = world.getBlockAt(x + blockInfo.x, blockInfo.y, z + blockInfo.z); - PlotHelper.setBlock(block, plotblock); - } + if (this.plotworld.CLUSTER_ORE) { + populateBlocks(world, rand, X, Z, x, z, check); + TaskManager.runTaskLater(new Runnable() { + @Override + public void run() { + populateBiome(world, x, z); + } + }, 20); + } + else { + TaskManager.runTaskLater(new Runnable() { + @Override + public void run() { + populateBiome(world, x, z); + } + }, 20 + rand.nextInt(10)); + TaskManager.runTaskLater(new Runnable() { + @Override + public void run() { + populateBlocks(world, rand, X, Z, x, z, check); + } + }, 40 + rand.nextInt(10)); } + + } + + private void populateBiome(World world, int x, int z) { + for (int i = 0; i < 16; i++) { + for (int j = 0; j < 16; j++) { + world.setBiome(x + i, z + j, plotworld.PLOT_BIOME); + } + } + } + + private void populateBlocks(World world, Random rand, int X, int Z, int x, int z, boolean check) { + short[][] result = generator.generateExtBlockSections(world, rand, X, Z, null); + int length = result[0].length; + for(int i = 0; i < result.length; i++) { + for(int j = 0; j < length; j++) { + BlockWrapper blockInfo = getBlock(x, z, i, j, result, check); + if (blockInfo == null) { + continue; + } + PlotBlock plotblock = new PlotBlock((short) blockInfo.id, (byte) 0 ); + Block block = world.getBlockAt(x + blockInfo.x, blockInfo.y, z + blockInfo.z); + PlotHelper.setBlock(block, plotblock); + } + } } } \ No newline at end of file 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 c154874d2..20a95cb5e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java @@ -52,6 +52,10 @@ public class HybridGen extends PlotGenerator { * Set to static to re-use the same managet for all Default World Generators */ private static PlotManager manager = null; + /** + * plotworld object + */ + public HybridPlotWorld plotworld = null; /** * Some generator specific variables (implementation dependent) @@ -76,10 +80,6 @@ public class HybridGen extends PlotGenerator { * result object is returned for each generated chunk, do stuff to it */ short[][] result; - /** - * plotworld object - */ - HybridPlotWorld plotworld = null; /** * Faster sudo-random number generator than java.util.random */ @@ -308,7 +308,9 @@ public class HybridGen extends PlotGenerator { for (short x = 0; x < 16; x++) { for (short z = 0; z < 16; z++) { - biomes.setBiome(x, z, this.biome); + if (biomes != null) { + biomes.setBiome(x, z, this.biome); + } int absX = ((sx + x) % this.size); int absZ = ((sz + z) % this.size); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java index e43d79a93..d25e10f3d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java @@ -247,12 +247,13 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi return; } Player player = event.getPlayer(); - if (isInPlot(event.getBlock().getLocation())) { + Location loc = event.getBlock().getLocation(); + if (isInPlot(loc)) { if (event.getBlock().getY() == 0) { event.setCancelled(true); return; } - final Plot plot = getCurrentPlot(event.getBlock().getLocation()); + final Plot plot = getCurrentPlot(loc); if (!plot.hasOwner()) { if (PlotMain.hasPermission(player, "plots.admin.destroy.unowned")) { return; @@ -278,7 +279,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi return; } PlayerFunctions.sendMessage(player, C.NO_PERMISSION, "plots.admin.destroy.road"); - event.setCancelled(true); + if (isCluster(loc)) { event.setCancelled(true); } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @@ -287,20 +288,30 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi if (!isPlotWorld(world)) { return; } - final Plot plot = getCurrentPlot(event.getLocation()); + Location loc = event.getLocation(); + final Plot plot = getCurrentPlot(loc); if (plot != null && plot.hasOwner()) { if (FlagManager.isPlotFlagTrue(plot, "explosion")) { Iterator iter = event.blockList().iterator(); while (iter.hasNext()) { Block b = iter.next(); - if (!getCurrentPlot(b.getLocation()).equals(plot)) { + if (!getCurrentPlot(loc).equals(plot)) { iter.remove(); } } return; } } - event.setCancelled(true); + if (isCluster(loc)) { event.setCancelled(true); } + else { + Iterator iter = event.blockList().iterator(); + while (iter.hasNext()) { + Block b = iter.next(); + if (isCluster(loc)) { + iter.remove(); + } + } + } } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @@ -317,13 +328,14 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } else { final Block b = event.getBlock(); final Player p = (Player) e; - if (!isInPlot(b.getLocation())) { + Location loc = b.getLocation(); + if (!isInPlot(loc)) { if (!PlotMain.hasPermission(p, "plots.admin.build.road")) { PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.build.road"); event.setCancelled(true); } } else { - final Plot plot = getCurrentPlot(b.getLocation()); + final Plot plot = getCurrentPlot(loc); if (plot == null || !plot.hasOwner()) { if (!PlotMain.hasPermission(p, "plots.admin.build.unowned")) { PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.build.unowned"); @@ -332,7 +344,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } else if (!plot.hasRights(p)) { if (!PlotMain.hasPermission(p, "plots.admin.build.other")) { PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.build.other"); - event.setCancelled(true); + if (isCluster(loc)) { event.setCancelled(true); } } } } @@ -340,22 +352,23 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public static void onEntityBlockForm(final EntityBlockFormEvent event) { - final World world = event.getBlock().getWorld(); + public static void onEntityBlockForm(final EntityBlockFormEvent e) { + final World world = e.getBlock().getWorld(); if (!isPlotWorld(world)) { return; } - if ((!(event.getEntity() instanceof Player))) { - event.setCancelled(true); + if ((!(e.getEntity() instanceof Player))) { + if (isCluster(e.getBlock().getLocation())) { e.setCancelled(true); } } } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public static void onBS(final BlockSpreadEvent e) { final Block b = e.getBlock(); - if (isPlotWorld(b.getLocation())) { - if (!isInPlot(b.getLocation())) { - e.setCancelled(true); + Location loc = b.getLocation(); + if (isPlotWorld(loc)) { + if (!isInPlot(loc)) { + if (isCluster(e.getBlock().getLocation())) { e.setCancelled(true); } } } } @@ -363,9 +376,10 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public static void onBF(final BlockFormEvent e) { final Block b = e.getBlock(); - if (isPlotWorld(b.getLocation())) { - if (!isInPlot(b.getLocation())) { - e.setCancelled(true); + Location loc = b.getLocation(); + if (isPlotWorld(loc)) { + if (!isInPlot(loc)) { + if (isCluster(e.getBlock().getLocation())) { e.setCancelled(true); } } } } @@ -373,9 +387,10 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public static void onBD(final BlockDamageEvent e) { final Block b = e.getBlock(); - if (isPlotWorld(b.getLocation())) { - if (!isInPlot(b.getLocation())) { - e.setCancelled(true); + Location loc = b.getLocation(); + if (isPlotWorld(loc)) { + if (!isInPlot(loc)) { + if (isCluster(e.getBlock().getLocation())) { e.setCancelled(true); } } } } @@ -383,9 +398,10 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public static void onFade(final BlockFadeEvent e) { final Block b = e.getBlock(); - if (isPlotWorld(b.getLocation())) { - if (!isInPlot(b.getLocation())) { - e.setCancelled(true); + Location loc = b.getLocation(); + if (isPlotWorld(loc)) { + if (!isInPlot(loc)) { + if (isCluster(e.getBlock().getLocation())) { e.setCancelled(true); } } } } @@ -393,9 +409,10 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public static void onChange(final BlockFromToEvent e) { final Block b = e.getToBlock(); - if (isPlotWorld(b.getLocation())) { - if (!isInPlot(b.getLocation())) { - e.setCancelled(true); + Location loc = b.getLocation(); + if (isPlotWorld(loc)) { + if (!isInPlot(loc)) { + if (isCluster(e.getBlock().getLocation())) { e.setCancelled(true); } } } } @@ -403,9 +420,10 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public static void onGrow(final BlockGrowEvent e) { final Block b = e.getBlock(); - if (isPlotWorld(b.getLocation())) { - if (!isInPlot(b.getLocation())) { - e.setCancelled(true); + Location loc = b.getLocation(); + if (isPlotWorld(loc)) { + if (!isInPlot(loc)) { + if (isCluster(e.getBlock().getLocation())) { e.setCancelled(true); } } } } @@ -415,64 +433,19 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi if (isInPlot(e.getBlock().getLocation())) { for (final Block block : e.getBlocks()) { if (!isInPlot(block.getLocation())) { - e.setCancelled(true); + if (isCluster(e.getBlock().getLocation())) { e.setCancelled(true); } } } } - /* - * if (isInPlot(e.getBlock().getLocation())) { - * e.getDirection(); - * final int modifier = e.getBlocks().size(); - * Location l = e.getBlock().getLocation(); - * { - * if (e.getDirection() == BlockFace.EAST) { - * l = e.getBlock().getLocation().subtract(modifier, 0, 0); - * } else if (e.getDirection() == BlockFace.NORTH) { - * l = e.getBlock().getLocation().subtract(0, 0, modifier); - * } else if (e.getDirection() == BlockFace.SOUTH) { - * l = e.getBlock().getLocation().add(0, 0, modifier); - * } else if (e.getDirection() == BlockFace.WEST) { - * l = e.getBlock().getLocation().add(modifier, 0, 0); - * } - * if (!isInPlot(l)) { - * e.setCancelled(true); - * return; - * } - * } - * for (final Block b : e.getBlocks()) { - * if (!isInPlot(b.getLocation())) { - * return; - * } - * { - * if (e.getDirection() == BlockFace.EAST) { - * if (!isInPlot(b.getLocation().subtract(1, 0, 0))) { - * e.setCancelled(true); - * } - * } else if (e.getDirection() == BlockFace.NORTH) { - * if (!isInPlot(b.getLocation().subtract(0, 0, 1))) { - * e.setCancelled(true); - * } - * } else if (e.getDirection() == BlockFace.SOUTH) { - * if (!isInPlot(b.getLocation().add(0, 0, 1))) { - * e.setCancelled(true); - * } - * } else if (e.getDirection() == BlockFace.WEST) { - * if (!isInPlot(b.getLocation().add(1, 0, 0))) { - * e.setCancelled(true); - * } - * } - * } - * } - * } - */ } @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public static void onBlockPistonRetract(final BlockPistonRetractEvent e) { final Block b = e.getRetractLocation().getBlock(); - if (isPlotWorld(b.getLocation()) && (e.getBlock().getType() == Material.PISTON_STICKY_BASE)) { - if (!isInPlot(b.getLocation())) { - e.setCancelled(true); + Location loc = b.getLocation(); + if (isPlotWorld(loc) && (e.getBlock().getType() == Material.PISTON_STICKY_BASE)) { + if (!isInPlot(loc)) { + if (isCluster(e.getBlock().getLocation())) { e.setCancelled(true); } } } } @@ -484,8 +457,9 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi for (int i = blocks.size() - 1; i >= 0; i--) { if (remove || isPlotWorld(blocks.get(i).getLocation())) { remove = true; - if (!isInPlot(blocks.get(i).getLocation())) { - e.getBlocks().remove(i); + Location loc = blocks.get(i).getLocation(); + if (!isInPlot(loc)) { + if (isCluster(loc)) { e.getBlocks().remove(i); } } } } @@ -505,8 +479,9 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi return; } Player player = event.getPlayer(); - if (isInPlot(event.getClickedBlock().getLocation())) { - final Plot plot = getCurrentPlot(event.getClickedBlock().getLocation()); + Location loc = event.getClickedBlock().getLocation(); + if (isInPlot(loc)) { + final Plot plot = getCurrentPlot(loc); if (!plot.hasOwner()) { if (PlotMain.hasPermission(player, "plots.admin.interact.unowned")) { return; @@ -531,7 +506,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi return; } PlayerFunctions.sendMessage(player, C.NO_PERMISSION, "plots.admin.interact.road"); - event.setCancelled(true); + if (isCluster(loc)) { event.setCancelled(true); } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @@ -552,8 +527,9 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi if (event.getEntity() instanceof Player) { return; } - if (!isInPlot(event.getLocation())) { - event.setCancelled(true); + Location loc = event.getLocation(); + if (!isInPlot(loc)) { + if (isCluster(loc)) { event.setCancelled(true); } } } @@ -579,16 +555,17 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi return; } final Block b = e.getBlock(); + Location loc = b.getLocation(); if (b != null) { if (e.getPlayer() != null) { final Player p = e.getPlayer(); - if (!isInPlot(b.getLocation())) { + if (!isInPlot(loc)) { if (!PlotMain.hasPermission(p, "plots.admin.build.road")) { PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.build.road"); e.setCancelled(true); } } else { - final Plot plot = getCurrentPlot(b.getLocation()); + final Plot plot = getCurrentPlot(loc); if (plot == null || !plot.hasOwner()) { if (!PlotMain.hasPermission(p, "plots.admin.build.unowned")) { PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.build.unowned"); @@ -597,12 +574,12 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } else if (!plot.hasRights(p)) { if (!PlotMain.hasPermission(p, "plots.admin.build.other")) { PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.build.other"); - e.setCancelled(true); + if (isCluster(loc)) { e.setCancelled(true); } } } } } else { - e.setCancelled(true); + if (isCluster(loc)) { e.setCancelled(true); } } } } @@ -640,16 +617,17 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi public static void onBucketEmpty(final PlayerBucketEmptyEvent e) { final BlockFace bf = e.getBlockFace(); final Block b = e.getBlockClicked().getLocation().add(bf.getModX(), bf.getModY(), bf.getModZ()).getBlock(); - if (isPlotWorld(b.getLocation())) { + Location loc = b.getLocation(); + if (isPlotWorld(loc)) { Player p = e.getPlayer(); - if (!isInPlot(b.getLocation())) { + if (!isInPlot(loc)) { if (PlotMain.hasPermission(p, "plots.admin.build.road")) { return; } PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.build.road"); e.setCancelled(true); } else { - final Plot plot = getCurrentPlot(b.getLocation()); + final Plot plot = getCurrentPlot(loc); if (plot == null || !plot.hasOwner()) { if (PlotMain.hasPermission(p, "plots.admin.build.unowned")) { return; @@ -665,7 +643,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi return; } PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.build.other"); - e.setCancelled(true); + if (isCluster(loc)) { e.setCancelled(true); } } } } @@ -700,16 +678,17 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public static void onBucketFill(final PlayerBucketFillEvent e) { final Block b = e.getBlockClicked(); - if (isPlotWorld(b.getLocation())) { + Location loc = b.getLocation(); + if (isPlotWorld(loc)) { Player p = e.getPlayer(); - if (!isInPlot(b.getLocation())) { + if (!isInPlot(loc)) { if (PlotMain.hasPermission(p, "plots.admin.build.road")) { return; } PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.build.road"); e.setCancelled(true); } else { - final Plot plot = getCurrentPlot(b.getLocation()); + final Plot plot = getCurrentPlot(loc); if (plot == null || !plot.hasOwner()) { if (PlotMain.hasPermission(p, "plots.admin.build.unowned")) { return; @@ -726,7 +705,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi return; } PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.build.other"); - e.setCancelled(true); + if (isCluster(loc)) { e.setCancelled(true); } } } } @@ -735,15 +714,16 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public static void onHangingPlace(final HangingPlaceEvent e) { final Block b = e.getBlock(); - if (isPlotWorld(b.getLocation())) { + Location loc = b.getLocation(); + if (isPlotWorld(loc)) { final Player p = e.getPlayer(); - if (!isInPlot(b.getLocation())) { + if (!isInPlot(loc)) { if (!PlotMain.hasPermission(p, "plots.admin.build.road")) { PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.build.road"); e.setCancelled(true); } } else { - final Plot plot = getCurrentPlot(b.getLocation()); + final Plot plot = getCurrentPlot(loc); if (plot == null || !plot.hasOwner()) { if (!PlotMain.hasPermission(p, "plots.admin.build.unowned")) { PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.build.unowned"); @@ -755,7 +735,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } if (!PlotMain.hasPermission(p, "plots.admin.build.other")) { PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.build.other"); - e.setCancelled(true); + if (isCluster(loc)) { e.setCancelled(true); } } } } @@ -787,7 +767,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } if (!PlotMain.hasPermission(p, "plots.admin.destroy.other")) { PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.destroy.other"); - e.setCancelled(true); + if (isCluster(l)) { e.setCancelled(true); } } } } @@ -828,7 +808,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } if (!PlotMain.hasPermission(p, "plots.admin.interact.other")) { PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.interact.other"); - e.setCancelled(true); + if (isCluster(l)) { e.setCancelled(true); } } } } @@ -864,7 +844,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } if (!PlotMain.hasPermission(p, "plots.admin.vehicle.break.other")) { PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.vehicle.break.other"); - e.setCancelled(true); + if (isCluster(l)) { e.setCancelled(true); } } } } @@ -919,7 +899,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } if (!PlotMain.hasPermission(p, "plots.admin.pve.other")) { PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.pve.other"); - e.setCancelled(true); + if (isCluster(l)) { e.setCancelled(true); } } } } @@ -947,7 +927,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } else if (!plot.hasRights(p)) { if (!PlotMain.hasPermission(p, "plots.admin.projectile.other")) { PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.projectile.other"); - e.setHatching(false); + if (isCluster(l)) { e.setHatching(false); } } } } @@ -964,8 +944,9 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi return; } Player player = event.getPlayer(); - if (isInPlot(event.getBlock().getLocation())) { - final Plot plot = getCurrentPlot(event.getBlockPlaced().getLocation()); + Location loc = event.getBlock().getLocation(); + if (isInPlot(loc)) { + final Plot plot = getCurrentPlot(loc); if (!plot.hasOwner() && PlotMain.hasPermission(player, "plots.admin.build.unowned")) { PlayerFunctions.sendMessage(player, C.NO_PERMISSION, "plots.admin.build.unowned"); return; @@ -985,7 +966,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } if (!PlotMain.hasPermission(player, "plots.admin.build.road")) { PlayerFunctions.sendMessage(player, C.NO_PERMISSION, "plots.admin.build.road"); - event.setCancelled(true); + if (isCluster(loc)) { event.setCancelled(true); } } } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotListener.java index 94765cb33..137f285cd 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotListener.java @@ -48,6 +48,7 @@ import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.titles.AbstractTitle; +import com.intellectualcrafters.plot.util.ClusterManager; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.UUIDHandler; import com.sk89q.worldguard.protection.flags.BooleanFlag; @@ -87,6 +88,14 @@ import com.sk89q.worldguard.protection.flags.BooleanFlag; public static boolean isPlotWorld(final World world) { return PlotMain.isPlotWorld(world); } + + public static boolean isCluster(Location location) { + PlotWorld plotworld = PlotMain.getWorldSettings(location.getWorld()); + if (plotworld.REQUIRE_CLUSTER) { + return ClusterManager.getCluster(location) != null; + } + return false; + } public static PlotWorld getPlotWorld(final World world) { return PlotMain.getWorldSettings(world); @@ -107,20 +116,6 @@ import com.sk89q.worldguard.protection.flags.BooleanFlag; return UUIDHandler.getUUID(name); } - // unused - public static void blockChange(final Block block, final Cancellable event) { - final Location loc = block.getLocation(); - final String world = loc.getWorld().getName(); - final PlotManager manager = PlotMain.getPlotManager(world); - if (manager != null) { - final PlotWorld plotworld = PlotMain.getWorldSettings(world); - final PlotId id = manager.getPlotId(plotworld, loc); - if (id == null) { - event.setCancelled(true); - } - } - } - public static boolean enteredPlot(final Location l1, final Location l2) { final PlotId p1 = PlayerFunctions.getPlot(new Location(l1.getWorld(), l1.getBlockX(), 64, l1.getBlockZ())); final PlotId p2 = PlayerFunctions.getPlot(new Location(l2.getWorld(), l2.getBlockX(), 64, l2.getBlockZ())); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java index 74b15e773..b832c06ad 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java @@ -61,6 +61,7 @@ public abstract class PlotWorld { public final static boolean SPAWN_BREEDING_DEFAULT = false; public final static boolean WORLD_BORDER_DEFAULT = false; public static boolean REQUIRE_CLAIM_IN_CLUSTER_DEFAULT = false; + public static boolean CLUSTER_GEN_ORE_DEFAULT = true; // are plot clusters enabled // require claim in cluster @@ -293,6 +294,7 @@ public abstract class PlotWorld { public boolean SPAWN_BREEDING; public boolean WORLD_BORDER; public boolean REQUIRE_CLUSTER = false; + public boolean CLUSTER_ORE; public PlotWorld(final String worldname) { this.worldname = worldname; @@ -305,7 +307,8 @@ public abstract class PlotWorld { */ public void loadDefaultConfiguration(final ConfigurationSection config) { if (Settings.ENABLE_CLUSTERS) { - this.REQUIRE_CLUSTER = config.getBoolean("claim.require_cluster"); + this.REQUIRE_CLUSTER = config.getBoolean("cluster.require-claim-in-cluster"); + this.CLUSTER_ORE = config.getBoolean("cluster.generate-ores"); } this.MOB_SPAWNING = config.getBoolean("natural_mob_spawning"); this.AUTO_MERGE = config.getBoolean("plot.auto_merge"); @@ -371,7 +374,8 @@ public abstract class PlotWorld { options.put("event.spawn.breeding", PlotWorld.SPAWN_BREEDING_DEFAULT); options.put("world.border", PlotWorld.WORLD_BORDER_DEFAULT); if (Settings.ENABLE_CLUSTERS) { - options.put("claim.require_cluster", PlotWorld.REQUIRE_CLAIM_IN_CLUSTER_DEFAULT); + options.put("cluster.require-claim-in-cluster", PlotWorld.REQUIRE_CLAIM_IN_CLUSTER_DEFAULT); + options.put("cluster.generate-ores", PlotWorld.CLUSTER_GEN_ORE_DEFAULT); } final ConfigurationNode[] settings = getSettingNodes(); /* diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java index 81106badd..861ea06f0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java @@ -1,13 +1,22 @@ package com.intellectualcrafters.plot.util; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; +import java.util.Random; import org.bukkit.Bukkit; +import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.generator.BlockPopulator; import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.generator.AugmentedPopulator; import com.intellectualcrafters.plot.object.BlockLoc; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotCluster; @@ -18,7 +27,8 @@ import com.intellectualcrafters.plot.object.PlotWorld; public class ClusterManager { public static HashMap> clusters; - private static PlotCluster last; + private static HashSet regenerating = new HashSet<>(); + public static PlotCluster last; public static boolean contains(PlotCluster cluster, PlotId id) { if (cluster.getP1().x <= id.x && cluster.getP1().y <= id.y && cluster.getP2().x >= id.x && cluster.getP2().y >= id.y) { @@ -191,4 +201,75 @@ public class ClusterManager { public static PlotClusterId getClusterId(PlotCluster cluster) { return new PlotClusterId(cluster.getP1(), cluster.getP2()); } + + public static AugmentedPopulator getPopulator(PlotCluster cluster) { + World world = Bukkit.getWorld(cluster.world); + for (Iterator iterator = world.getPopulators().iterator(); iterator.hasNext();) { + BlockPopulator populator = iterator.next(); + if (populator instanceof AugmentedPopulator) { + if (((AugmentedPopulator) populator).cluster.equals(cluster)) { + return (AugmentedPopulator) populator; + } + } + } + return null; + } + + public static void regenCluster(final PlotCluster cluster) { + if (regenerating.contains(cluster.world + ":" + cluster.getName())) { + return; + } + regenerating.add(cluster.world + ":" + cluster.getName()); + int interval = 1; + int i = 0; + final Random rand = new Random(); + final World world = Bukkit.getWorld(cluster.world); + + Location bot = getClusterBottom(cluster); + Location top = getClusterTop(cluster); + + int minChunkX = bot.getBlockX() >> 4; + int maxChunkX = (top.getBlockX() >> 4) + 1; + int minChunkZ = bot.getBlockZ() >> 4; + int maxChunkZ = (top.getBlockZ() >> 4) + 1; + + final AugmentedPopulator populator = getPopulator(cluster); + final ArrayList chunks = new ArrayList<>(); + + TaskManager.runTaskLater(new Runnable() { + @Override + public void run() { + ClusterManager.regenerating.remove(cluster.world + ":" + cluster.getName()); + Player owner = UUIDHandler.uuidWrapper.getPlayer(cluster.owner); + if (owner != null) { + PlayerFunctions.sendMessage(owner, C.CLEARING_DONE); + } + } + }, interval * chunks.size() + 20); + + // chunks + for (int x = minChunkX; x <= maxChunkX; x++) { + for (int z = minChunkZ; z <= maxChunkZ; z++) { + final Chunk chunk = world.getChunkAt(x, z); + chunks.add(chunk); + } + } + for (final Chunk chunk : chunks) { + i+=interval; + TaskManager.runTaskLater(new Runnable() { + @Override + public void run() { + if (populator == null) { + world.regenerateChunk(chunk.getX(), chunk.getZ()); + chunk.unload(); + chunk.load(); + } + else { + populator.populate(world, rand, chunk); + } + } + }, i); + + } + } } \ No newline at end of file diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlayerFunctions.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlayerFunctions.java index 863a0e978..633ed0a68 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlayerFunctions.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlayerFunctions.java @@ -148,7 +148,7 @@ import com.intellectualcrafters.plot.object.PlotWorld; } final PlotWorld plotworld = PlotMain.getWorldSettings(world); PlotId id = manager.getPlotId(plotworld, loc); - if (plotworld.REQUIRE_CLUSTER) { + if (id!=null && plotworld.REQUIRE_CLUSTER) { if (ClusterManager.getCluster(world, id) == null) { return null; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java index 5bd444233..daa40b6eb 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java @@ -6,4 +6,8 @@ public class TaskManager { public static void runTask(final Runnable r) { PlotMain.getMain().getServer().getScheduler().runTaskAsynchronously(PlotMain.getMain(), r); } + + public static void runTaskLater(final Runnable r, int delay) { + PlotMain.getMain().getServer().getScheduler().runTaskLater(PlotMain.getMain(), r, delay); + } }