Added cluster regeneration

This commit is contained in:
boy0001 2015-01-31 18:09:48 +11:00
parent d0fd8f09c1
commit 25355f4906
13 changed files with 390 additions and 188 deletions

View File

@ -82,6 +82,7 @@ import com.intellectualcrafters.plot.events.PlotDeleteEvent;
import com.intellectualcrafters.plot.flag.AbstractFlag; import com.intellectualcrafters.plot.flag.AbstractFlag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.flag.FlagValue; import com.intellectualcrafters.plot.flag.FlagValue;
import com.intellectualcrafters.plot.generator.AugmentedPopulator;
import com.intellectualcrafters.plot.generator.HybridGen; import com.intellectualcrafters.plot.generator.HybridGen;
import com.intellectualcrafters.plot.generator.HybridPlotManager; import com.intellectualcrafters.plot.generator.HybridPlotManager;
import com.intellectualcrafters.plot.generator.HybridPlotWorld; 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.WorldEditListener;
import com.intellectualcrafters.plot.listeners.WorldGuardListener; import com.intellectualcrafters.plot.listeners.WorldGuardListener;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotGenerator; import com.intellectualcrafters.plot.object.PlotGenerator;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotManager;
@ -277,7 +279,7 @@ public class PlotMain extends JavaPlugin implements Listener {
final String[] nodes = perm.split("\\."); final String[] nodes = perm.split("\\.");
final StringBuilder n = new StringBuilder(); final StringBuilder n = new StringBuilder();
for (int i = 0; i < (nodes.length - 1); i++) { for (int i = 0; i < (nodes.length - 1); i++) {
n.append(nodes[i]).append("."); n.append(nodes[i] + ("."));
if (player.hasPermission(n + "*")) { if (player.hasPermission(n + "*")) {
return true; return true;
} }
@ -967,13 +969,22 @@ public class PlotMain extends JavaPlugin implements Listener {
PlotWorld.REQUIRE_CLAIM_IN_CLUSTER_DEFAULT = true; PlotWorld.REQUIRE_CLAIM_IN_CLUSTER_DEFAULT = true;
plotWorld.saveConfiguration(config.getConfigurationSection(path)); plotWorld.saveConfiguration(config.getConfigurationSection(path));
plotWorld.loadConfiguration(config.getConfigurationSection(path)); plotWorld.loadDefaultConfiguration(config.getConfigurationSection(path));
PlotWorld.REQUIRE_CLAIM_IN_CLUSTER_DEFAULT = false; PlotWorld.REQUIRE_CLAIM_IN_CLUSTER_DEFAULT = false;
try { try {
config.save(configFile); config.save(configFile);
} catch (final IOException e) { } catch (final IOException e) {
e.printStackTrace(); 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 // Now add it :p
addPlotWorld(world, plotWorld, plotManager); addPlotWorld(world, plotWorld, plotManager);
} }

View File

@ -177,14 +177,14 @@ public class Auto extends SubCommand {
PlotId top = cluster.getP2(); PlotId top = cluster.getP2();
PlotId origin = new PlotId((bot.x + top.x) / 2, (bot.y + top.y) / 2); PlotId origin = new PlotId((bot.x + top.x) / 2, (bot.y + top.y) / 2);
PlotId id = new PlotId(0, 0); 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; int max = width * width;
// //
for (int i = 0; i <= max; i++) { for (int i = 0; i <= max; i++) {
PlotId currentId = new PlotId(origin.x + id.x, origin.y + id.y); PlotId currentId = new PlotId(origin.x + id.x, origin.y + id.y);
Plot current = PlotHelper.getPlot(world, currentId); Plot current = PlotHelper.getPlot(world, currentId);
if (current != null && !current.hasOwner() && cluster.equals(ClusterManager.getCluster(current))) { if (current != null && (current.hasOwner() == false) && (current.settings.isMerged() == false) && cluster.equals(ClusterManager.getCluster(current))) {
Claim.claimPlot(plr, plot, true, true); Claim.claimPlot(plr, current, true, true);
return true; return true;
} }
id = getNextPlot(id, 1); id = getNextPlot(id, 1);

View File

@ -21,16 +21,21 @@
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.generator.BlockPopulator;
import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc; 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.BlockLoc;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotCluster;
@ -59,6 +64,7 @@ public class Cluster extends SubCommand {
} }
String sub = args[0].toLowerCase(); String sub = args[0].toLowerCase();
switch (sub) { switch (sub) {
case "l":
case "list": { case "list": {
if (!PlotMain.hasPermission(plr, "plots.cluster.list")) { if (!PlotMain.hasPermission(plr, "plots.cluster.list")) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.list"); PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.list");
@ -88,6 +94,7 @@ public class Cluster extends SubCommand {
} }
return true; return true;
} }
case "c":
case "create": { case "create": {
if (!PlotMain.hasPermission(plr, "plots.cluster.create")) { if (!PlotMain.hasPermission(plr, "plots.cluster.create")) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.create"); PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.create");
@ -115,7 +122,7 @@ public class Cluster extends SubCommand {
//check if overlap //check if overlap
PlotClusterId id = new PlotClusterId(pos1, pos2); PlotClusterId id = new PlotClusterId(pos1, pos2);
HashSet<PlotCluster> intersects = ClusterManager.getIntersects(plr.getWorld().getName(), id); HashSet<PlotCluster> 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() + ""); PlayerFunctions.sendMessage(plr, C.CLUSTER_INTERSECTION, intersects.size() + "");
return false; return false;
} }
@ -136,9 +143,15 @@ public class Cluster extends SubCommand {
DBFunc.setInvited(world, cluster, plot.owner); 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); PlayerFunctions.sendMessage(plr, C.CLUSTER_ADDED);
return true; return true;
} }
case "disband":
case "del":
case "delete": { case "delete": {
if (!PlotMain.hasPermission(plr, "plots.cluster.delete")) { if (!PlotMain.hasPermission(plr, "plots.cluster.delete")) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.delete"); PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.delete");
@ -163,10 +176,6 @@ public class Cluster extends SubCommand {
return false; return false;
} }
} }
if (cluster == null) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
if (!cluster.owner.equals(UUIDHandler.getUUID(plr))) { if (!cluster.owner.equals(UUIDHandler.getUUID(plr))) {
if (!PlotMain.hasPermission(plr, "plots.cluster.delete.other")) { if (!PlotMain.hasPermission(plr, "plots.cluster.delete.other")) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "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()); PlotWorld plotworld = PlotMain.getWorldSettings(plr.getWorld());
if (plotworld.REQUIRE_CLUSTER) { if (plotworld.REQUIRE_CLUSTER) {
ArrayList<Plot> toRemove = new ArrayList<>();
for (Plot plot : PlotMain.getPlots(plr.getWorld()).values()) { for (Plot plot : PlotMain.getPlots(plr.getWorld()).values()) {
PlotCluster other = ClusterManager.getCluster(plot); PlotCluster other = ClusterManager.getCluster(plot);
if (cluster.equals(other)) { if (cluster.equals(other)) {
String world = plr.getWorld().getName(); toRemove.add(plot);
DBFunc.delete(world, plot);
} }
} }
for (Plot plot : toRemove) {
DBFunc.delete(plot.world, plot);
}
} }
String world_delete = plr.getWorld().getName();
ClusterManager.clusters.get(world_delete).remove(cluster);
DBFunc.delete(cluster); DBFunc.delete(cluster);
if (plotworld.REQUIRE_CLUSTER) {
for (Iterator<BlockPopulator> iterator = plr.getWorld().getPopulators().iterator(); iterator.hasNext();) {
BlockPopulator populator = iterator.next();
if (populator instanceof AugmentedPopulator) {
if (((AugmentedPopulator) populator).cluster.equals(cluster)) {
iterator.remove();
}
}
}
}
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); PlayerFunctions.sendMessage(plr, C.CLUSTER_DELETED);
return true; return true;
} }
case "res":
case "resize": { case "resize": {
if (!PlotMain.hasPermission(plr, "plots.cluster.resize")) { if (!PlotMain.hasPermission(plr, "plots.cluster.resize")) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize"); PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize");
@ -199,8 +225,8 @@ public class Cluster extends SubCommand {
return false; return false;
} }
// check pos1 / pos2 // check pos1 / pos2
PlotId pos1 = PlotHelper.parseId(args[2]); PlotId pos1 = PlotHelper.parseId(args[1]);
PlotId pos2 = PlotHelper.parseId(args[3]); PlotId pos2 = PlotHelper.parseId(args[2]);
if (pos1 == null || pos2 == null) { if (pos1 == null || pos2 == null) {
PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_ID); PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_ID);
return false; return false;
@ -220,8 +246,8 @@ public class Cluster extends SubCommand {
//check if overlap //check if overlap
PlotClusterId id = new PlotClusterId(pos1, pos2); PlotClusterId id = new PlotClusterId(pos1, pos2);
HashSet<PlotCluster> intersects = ClusterManager.getIntersects(plr.getWorld().getName(), id); HashSet<PlotCluster> intersects = ClusterManager.getIntersects(plr.getWorld().getName(), id);
if (intersects.size() > 0) { if (intersects.size() > 1) {
PlayerFunctions.sendMessage(plr, C.CLUSTER_INTERSECTION, intersects.size() + ""); PlayerFunctions.sendMessage(plr, C.CLUSTER_INTERSECTION, (intersects.size() - 1) + "");
return false; return false;
} }
// resize cluster // resize cluster
@ -229,6 +255,44 @@ public class Cluster extends SubCommand {
PlayerFunctions.sendMessage(plr, C.CLUSTER_RESIZED); PlayerFunctions.sendMessage(plr, C.CLUSTER_RESIZED);
return true; 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": { case "invite": {
if (!PlotMain.hasPermission(plr, "plots.cluster.invite")) { if (!PlotMain.hasPermission(plr, "plots.cluster.invite")) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "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); PlayerFunctions.sendMessage(plr, C.CLUSTER_ADDED_USER);
return true; return true;
} }
case "k":
case "remove":
case "kick": { case "kick": {
if (!PlotMain.hasPermission(plr, "plots.cluster.kick")) { if (!PlotMain.hasPermission(plr, "plots.cluster.kick")) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "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); PlayerFunctions.sendMessage(plr, C.CLUSTER_KICKED_USER);
return true; return true;
} }
case "quit":
case "leave": { case "leave": {
if (!PlotMain.hasPermission(plr, "plots.cluster.leave")) { if (!PlotMain.hasPermission(plr, "plots.cluster.leave")) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.leave"); PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.leave");
@ -369,6 +436,8 @@ public class Cluster extends SubCommand {
} }
return true; return true;
} }
case "admin":
case "helper":
case "helpers": { case "helpers": {
if (!PlotMain.hasPermission(plr, "plots.cluster.helpers")) { if (!PlotMain.hasPermission(plr, "plots.cluster.helpers")) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "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 <add|remove> <player>"); PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster helpers <add|remove> <player>");
return false; return false;
} }
case "spawn":
case "home":
case "tp": { case "tp": {
if (!PlotMain.hasPermission(plr, "plots.cluster.tp")) { if (!PlotMain.hasPermission(plr, "plots.cluster.tp")) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "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)); plr.teleport(ClusterManager.getHome(cluster));
return PlayerFunctions.sendMessage(plr, C.CLUSTER_TELEPORTING); return PlayerFunctions.sendMessage(plr, C.CLUSTER_TELEPORTING);
} }
case "info": { case "i":
case "info":
case "show":
case "information": {
if (!PlotMain.hasPermission(plr, "plots.cluster.info")) { if (!PlotMain.hasPermission(plr, "plots.cluster.info")) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.info"); PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.info");
return false; return false;
@ -453,7 +527,7 @@ public class Cluster extends SubCommand {
owner = "unknown"; owner = "unknown";
} }
String name = cluster.getName(); 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 rights = cluster.hasRights(UUIDHandler.getUUID(plr)) + "";
String message = C.CLUSTER_INFO.s(); String message = C.CLUSTER_INFO.s();
@ -466,6 +540,8 @@ public class Cluster extends SubCommand {
PlayerFunctions.sendMessage(plr, message); PlayerFunctions.sendMessage(plr, message);
return true; return true;
} }
case "sh":
case "setspawn":
case "sethome": { case "sethome": {
if (!PlotMain.hasPermission(plr, "plots.cluster.sethome")) { if (!PlotMain.hasPermission(plr, "plots.cluster.sethome")) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "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); PlayerFunctions.sendMessage(plr, C.CLUSTER_AVAILABLE_ARGS);
return false; return false;
} }
} }

View File

@ -57,6 +57,7 @@ public enum C {
CLUSTER_CANNOT_LEAVE("&cYou must delete or transfer ownership before leaving"), CLUSTER_CANNOT_LEAVE("&cYou must delete or transfer ownership before leaving"),
CLUSTER_ADDED_HELPER("&6Successfully added a helper to the cluster"), CLUSTER_ADDED_HELPER("&6Successfully added a helper to the cluster"),
CLUSTER_REMOVED_HELPER("&6Successfully removed 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_TELEPORTING("&6Teleporting..."),
CLUSTER_INFO("&6Current cluster: &7%id%\n&6Name: &7%name%\n&6Owner: &7%owner%\n&6Size: &7%size%\n&6Rights: &7%rights%"), 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
*/ */
CLEARING_PLOT("&cClearing plot async."), 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)"), CLEARING_DONE_PACKETS("&6(&a%time% &6ms for packets)"),
/* /*
* Claiming * Claiming

View File

@ -1629,7 +1629,7 @@ public class SQLManager implements AbstractDB {
public void run() { public void run() {
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { 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(1, pos1.x);
stmt.setInt(2, pos1.y); stmt.setInt(2, pos1.y);
stmt.setInt(3, pos2.x); stmt.setInt(3, pos2.x);

View File

@ -10,6 +10,7 @@ import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.BlockPopulator;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.object.BlockWrapper; import com.intellectualcrafters.plot.object.BlockWrapper;
import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotGenerator; 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.PlotCluster;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.PlotHelper; import com.intellectualcrafters.plot.util.PlotHelper;
import com.intellectualcrafters.plot.util.TaskManager;
public class AugmentedPopulator extends BlockPopulator { public class AugmentedPopulator extends BlockPopulator {
public final PlotWorld plotworld; public final PlotWorld plotworld;
public final PlotManager manager; public final PlotManager manager;
public final PlotGenerator generator; public final PlotGenerator generator;
public final PlotCluster cluster;
private final int bx; private final int bx;
private final int bz; private final int bz;
@ -35,12 +38,18 @@ public class AugmentedPopulator extends BlockPopulator {
int a = (j - ((y & 0xF) << 8)); int a = (j - ((y & 0xF) << 8));
int z = (a >> 4); int z = (a >> 4);
int x = a - (z << 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) { public AugmentedPopulator(String world, PlotGenerator generator, PlotCluster cluster) {
this.cluster = cluster;
this.generator = generator; this.generator = generator;
this.plotworld = generator.getNewPlotWorld(world); this.plotworld = PlotMain.getWorldSettings(world);
this.manager = generator.getPlotManager(); this.manager = generator.getPlotManager();
World bukkitWorld = Bukkit.getWorld(world); World bukkitWorld = Bukkit.getWorld(world);
@ -55,23 +64,27 @@ public class AugmentedPopulator extends BlockPopulator {
this.tz = t.getBlockZ(); this.tz = t.getBlockZ();
// Add the populator // Add the populator
if (this.plotworld.CLUSTER_ORE) {
bukkitWorld.getPopulators().add(0, this);
}
else {
bukkitWorld.getPopulators().add(this); bukkitWorld.getPopulators().add(this);
} }
}
@Override @Override
public void populate(World world, Random rand, Chunk chunk) { public void populate(final World world, final Random rand, Chunk chunk) {
int X = chunk.getX(); final int X = chunk.getX();
int Z = chunk.getZ(); final int Z = chunk.getZ();
int x = X << 4; final int x = X << 4;
int z = Z << 4; final int z = Z << 4;
int x2 = x + 15; int x2 = x + 15;
int z2 = z + 15; int z2 = z + 15;
boolean inX1 = (x > bx && x < tx); boolean inX1 = (x >= bx && x <= tx);
boolean inX2 = (x2 > bx && x2 < tx); boolean inX2 = (x2 >= bx && x2 <= tx);
boolean inZ1 = (z > bz && z < tz); boolean inZ1 = (z >= bz && z <= tz);
boolean inZ2 = (z2 > bz && z2 < tz); boolean inZ2 = (z2 >= bz && z2 <= tz);
boolean inX = inX1 || inX2; boolean inX = inX1 || inX2;
boolean inZ = inZ1 || inZ2; boolean inZ = inZ1 || inZ2;
@ -79,17 +92,53 @@ public class AugmentedPopulator extends BlockPopulator {
if (!inX || !inZ) { if (!inX || !inZ) {
return; return;
} }
boolean check;
if (!inX1 || !inX2 || !inZ1 || inZ2) { final boolean check;
if (!inX1 || !inX2 || !inZ1 || !inZ2) {
check = true; check = true;
} }
else { else {
check = false; check = false;
} }
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); short[][] result = generator.generateExtBlockSections(world, rand, X, Z, null);
int d2_length = result[0].length; int length = result[0].length;
for(int i = 0; i < result.length; i++) { for(int i = 0; i < result.length; i++) {
for(int j = 0; j < d2_length; j++) { for(int j = 0; j < length; j++) {
BlockWrapper blockInfo = getBlock(x, z, i, j, result, check); BlockWrapper blockInfo = getBlock(x, z, i, j, result, check);
if (blockInfo == null) { if (blockInfo == null) {
continue; continue;

View File

@ -52,6 +52,10 @@ public class HybridGen extends PlotGenerator {
* Set to static to re-use the same managet for all Default World Generators * Set to static to re-use the same managet for all Default World Generators
*/ */
private static PlotManager manager = null; private static PlotManager manager = null;
/**
* plotworld object
*/
public HybridPlotWorld plotworld = null;
/** /**
* Some generator specific variables (implementation dependent) * 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 * result object is returned for each generated chunk, do stuff to it
*/ */
short[][] result; short[][] result;
/**
* plotworld object
*/
HybridPlotWorld plotworld = null;
/** /**
* Faster sudo-random number generator than java.util.random * 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 x = 0; x < 16; x++) {
for (short z = 0; z < 16; z++) { for (short z = 0; z < 16; z++) {
if (biomes != null) {
biomes.setBiome(x, z, this.biome); biomes.setBiome(x, z, this.biome);
}
int absX = ((sx + x) % this.size); int absX = ((sx + x) % this.size);
int absZ = ((sz + z) % this.size); int absZ = ((sz + z) % this.size);

View File

@ -247,12 +247,13 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
return; return;
} }
Player player = event.getPlayer(); Player player = event.getPlayer();
if (isInPlot(event.getBlock().getLocation())) { Location loc = event.getBlock().getLocation();
if (isInPlot(loc)) {
if (event.getBlock().getY() == 0) { if (event.getBlock().getY() == 0) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
final Plot plot = getCurrentPlot(event.getBlock().getLocation()); final Plot plot = getCurrentPlot(loc);
if (!plot.hasOwner()) { if (!plot.hasOwner()) {
if (PlotMain.hasPermission(player, "plots.admin.destroy.unowned")) { if (PlotMain.hasPermission(player, "plots.admin.destroy.unowned")) {
return; return;
@ -278,7 +279,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
return; return;
} }
PlayerFunctions.sendMessage(player, C.NO_PERMISSION, "plots.admin.destroy.road"); 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) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@ -287,20 +288,30 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
if (!isPlotWorld(world)) { if (!isPlotWorld(world)) {
return; return;
} }
final Plot plot = getCurrentPlot(event.getLocation()); Location loc = event.getLocation();
final Plot plot = getCurrentPlot(loc);
if (plot != null && plot.hasOwner()) { if (plot != null && plot.hasOwner()) {
if (FlagManager.isPlotFlagTrue(plot, "explosion")) { if (FlagManager.isPlotFlagTrue(plot, "explosion")) {
Iterator<Block> iter = event.blockList().iterator(); Iterator<Block> iter = event.blockList().iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
Block b = iter.next(); Block b = iter.next();
if (!getCurrentPlot(b.getLocation()).equals(plot)) { if (!getCurrentPlot(loc).equals(plot)) {
iter.remove(); iter.remove();
} }
} }
return; return;
} }
} }
event.setCancelled(true); if (isCluster(loc)) { event.setCancelled(true); }
else {
Iterator<Block> iter = event.blockList().iterator();
while (iter.hasNext()) {
Block b = iter.next();
if (isCluster(loc)) {
iter.remove();
}
}
}
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
@ -317,13 +328,14 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
} else { } else {
final Block b = event.getBlock(); final Block b = event.getBlock();
final Player p = (Player) e; final Player p = (Player) e;
if (!isInPlot(b.getLocation())) { Location loc = b.getLocation();
if (!isInPlot(loc)) {
if (!PlotMain.hasPermission(p, "plots.admin.build.road")) { if (!PlotMain.hasPermission(p, "plots.admin.build.road")) {
PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.build.road"); PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.build.road");
event.setCancelled(true); event.setCancelled(true);
} }
} else { } else {
final Plot plot = getCurrentPlot(b.getLocation()); final Plot plot = getCurrentPlot(loc);
if (plot == null || !plot.hasOwner()) { if (plot == null || !plot.hasOwner()) {
if (!PlotMain.hasPermission(p, "plots.admin.build.unowned")) { if (!PlotMain.hasPermission(p, "plots.admin.build.unowned")) {
PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "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)) { } else if (!plot.hasRights(p)) {
if (!PlotMain.hasPermission(p, "plots.admin.build.other")) { if (!PlotMain.hasPermission(p, "plots.admin.build.other")) {
PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "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) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public static void onEntityBlockForm(final EntityBlockFormEvent event) { public static void onEntityBlockForm(final EntityBlockFormEvent e) {
final World world = event.getBlock().getWorld(); final World world = e.getBlock().getWorld();
if (!isPlotWorld(world)) { if (!isPlotWorld(world)) {
return; return;
} }
if ((!(event.getEntity() instanceof Player))) { if ((!(e.getEntity() instanceof Player))) {
event.setCancelled(true); if (isCluster(e.getBlock().getLocation())) { e.setCancelled(true); }
} }
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public static void onBS(final BlockSpreadEvent e) { public static void onBS(final BlockSpreadEvent e) {
final Block b = e.getBlock(); final Block b = e.getBlock();
if (isPlotWorld(b.getLocation())) { Location loc = b.getLocation();
if (!isInPlot(b.getLocation())) { if (isPlotWorld(loc)) {
e.setCancelled(true); 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) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public static void onBF(final BlockFormEvent e) { public static void onBF(final BlockFormEvent e) {
final Block b = e.getBlock(); final Block b = e.getBlock();
if (isPlotWorld(b.getLocation())) { Location loc = b.getLocation();
if (!isInPlot(b.getLocation())) { if (isPlotWorld(loc)) {
e.setCancelled(true); 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) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public static void onBD(final BlockDamageEvent e) { public static void onBD(final BlockDamageEvent e) {
final Block b = e.getBlock(); final Block b = e.getBlock();
if (isPlotWorld(b.getLocation())) { Location loc = b.getLocation();
if (!isInPlot(b.getLocation())) { if (isPlotWorld(loc)) {
e.setCancelled(true); 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) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public static void onFade(final BlockFadeEvent e) { public static void onFade(final BlockFadeEvent e) {
final Block b = e.getBlock(); final Block b = e.getBlock();
if (isPlotWorld(b.getLocation())) { Location loc = b.getLocation();
if (!isInPlot(b.getLocation())) { if (isPlotWorld(loc)) {
e.setCancelled(true); 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) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public static void onChange(final BlockFromToEvent e) { public static void onChange(final BlockFromToEvent e) {
final Block b = e.getToBlock(); final Block b = e.getToBlock();
if (isPlotWorld(b.getLocation())) { Location loc = b.getLocation();
if (!isInPlot(b.getLocation())) { if (isPlotWorld(loc)) {
e.setCancelled(true); 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) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public static void onGrow(final BlockGrowEvent e) { public static void onGrow(final BlockGrowEvent e) {
final Block b = e.getBlock(); final Block b = e.getBlock();
if (isPlotWorld(b.getLocation())) { Location loc = b.getLocation();
if (!isInPlot(b.getLocation())) { if (isPlotWorld(loc)) {
e.setCancelled(true); 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())) { if (isInPlot(e.getBlock().getLocation())) {
for (final Block block : e.getBlocks()) { for (final Block block : e.getBlocks()) {
if (!isInPlot(block.getLocation())) { 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) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public static void onBlockPistonRetract(final BlockPistonRetractEvent e) { public static void onBlockPistonRetract(final BlockPistonRetractEvent e) {
final Block b = e.getRetractLocation().getBlock(); final Block b = e.getRetractLocation().getBlock();
if (isPlotWorld(b.getLocation()) && (e.getBlock().getType() == Material.PISTON_STICKY_BASE)) { Location loc = b.getLocation();
if (!isInPlot(b.getLocation())) { if (isPlotWorld(loc) && (e.getBlock().getType() == Material.PISTON_STICKY_BASE)) {
e.setCancelled(true); 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--) { for (int i = blocks.size() - 1; i >= 0; i--) {
if (remove || isPlotWorld(blocks.get(i).getLocation())) { if (remove || isPlotWorld(blocks.get(i).getLocation())) {
remove = true; remove = true;
if (!isInPlot(blocks.get(i).getLocation())) { Location loc = blocks.get(i).getLocation();
e.getBlocks().remove(i); if (!isInPlot(loc)) {
if (isCluster(loc)) { e.getBlocks().remove(i); }
} }
} }
} }
@ -505,8 +479,9 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
return; return;
} }
Player player = event.getPlayer(); Player player = event.getPlayer();
if (isInPlot(event.getClickedBlock().getLocation())) { Location loc = event.getClickedBlock().getLocation();
final Plot plot = getCurrentPlot(event.getClickedBlock().getLocation()); if (isInPlot(loc)) {
final Plot plot = getCurrentPlot(loc);
if (!plot.hasOwner()) { if (!plot.hasOwner()) {
if (PlotMain.hasPermission(player, "plots.admin.interact.unowned")) { if (PlotMain.hasPermission(player, "plots.admin.interact.unowned")) {
return; return;
@ -531,7 +506,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
return; return;
} }
PlayerFunctions.sendMessage(player, C.NO_PERMISSION, "plots.admin.interact.road"); 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) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@ -552,8 +527,9 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
if (event.getEntity() instanceof Player) { if (event.getEntity() instanceof Player) {
return; return;
} }
if (!isInPlot(event.getLocation())) { Location loc = event.getLocation();
event.setCancelled(true); if (!isInPlot(loc)) {
if (isCluster(loc)) { event.setCancelled(true); }
} }
} }
@ -579,16 +555,17 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
return; return;
} }
final Block b = e.getBlock(); final Block b = e.getBlock();
Location loc = b.getLocation();
if (b != null) { if (b != null) {
if (e.getPlayer() != null) { if (e.getPlayer() != null) {
final Player p = e.getPlayer(); final Player p = e.getPlayer();
if (!isInPlot(b.getLocation())) { if (!isInPlot(loc)) {
if (!PlotMain.hasPermission(p, "plots.admin.build.road")) { if (!PlotMain.hasPermission(p, "plots.admin.build.road")) {
PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.build.road"); PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.build.road");
e.setCancelled(true); e.setCancelled(true);
} }
} else { } else {
final Plot plot = getCurrentPlot(b.getLocation()); final Plot plot = getCurrentPlot(loc);
if (plot == null || !plot.hasOwner()) { if (plot == null || !plot.hasOwner()) {
if (!PlotMain.hasPermission(p, "plots.admin.build.unowned")) { if (!PlotMain.hasPermission(p, "plots.admin.build.unowned")) {
PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "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)) { } else if (!plot.hasRights(p)) {
if (!PlotMain.hasPermission(p, "plots.admin.build.other")) { if (!PlotMain.hasPermission(p, "plots.admin.build.other")) {
PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.build.other"); PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.build.other");
e.setCancelled(true); if (isCluster(loc)) { e.setCancelled(true); }
} }
} }
} }
} else { } 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) { public static void onBucketEmpty(final PlayerBucketEmptyEvent e) {
final BlockFace bf = e.getBlockFace(); final BlockFace bf = e.getBlockFace();
final Block b = e.getBlockClicked().getLocation().add(bf.getModX(), bf.getModY(), bf.getModZ()).getBlock(); 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(); Player p = e.getPlayer();
if (!isInPlot(b.getLocation())) { if (!isInPlot(loc)) {
if (PlotMain.hasPermission(p, "plots.admin.build.road")) { if (PlotMain.hasPermission(p, "plots.admin.build.road")) {
return; return;
} }
PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.build.road"); PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.build.road");
e.setCancelled(true); e.setCancelled(true);
} else { } else {
final Plot plot = getCurrentPlot(b.getLocation()); final Plot plot = getCurrentPlot(loc);
if (plot == null || !plot.hasOwner()) { if (plot == null || !plot.hasOwner()) {
if (PlotMain.hasPermission(p, "plots.admin.build.unowned")) { if (PlotMain.hasPermission(p, "plots.admin.build.unowned")) {
return; return;
@ -665,7 +643,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
return; return;
} }
PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.build.other"); 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) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public static void onBucketFill(final PlayerBucketFillEvent e) { public static void onBucketFill(final PlayerBucketFillEvent e) {
final Block b = e.getBlockClicked(); final Block b = e.getBlockClicked();
if (isPlotWorld(b.getLocation())) { Location loc = b.getLocation();
if (isPlotWorld(loc)) {
Player p = e.getPlayer(); Player p = e.getPlayer();
if (!isInPlot(b.getLocation())) { if (!isInPlot(loc)) {
if (PlotMain.hasPermission(p, "plots.admin.build.road")) { if (PlotMain.hasPermission(p, "plots.admin.build.road")) {
return; return;
} }
PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.build.road"); PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.build.road");
e.setCancelled(true); e.setCancelled(true);
} else { } else {
final Plot plot = getCurrentPlot(b.getLocation()); final Plot plot = getCurrentPlot(loc);
if (plot == null || !plot.hasOwner()) { if (plot == null || !plot.hasOwner()) {
if (PlotMain.hasPermission(p, "plots.admin.build.unowned")) { if (PlotMain.hasPermission(p, "plots.admin.build.unowned")) {
return; return;
@ -726,7 +705,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
return; return;
} }
PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.build.other"); 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) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public static void onHangingPlace(final HangingPlaceEvent e) { public static void onHangingPlace(final HangingPlaceEvent e) {
final Block b = e.getBlock(); final Block b = e.getBlock();
if (isPlotWorld(b.getLocation())) { Location loc = b.getLocation();
if (isPlotWorld(loc)) {
final Player p = e.getPlayer(); final Player p = e.getPlayer();
if (!isInPlot(b.getLocation())) { if (!isInPlot(loc)) {
if (!PlotMain.hasPermission(p, "plots.admin.build.road")) { if (!PlotMain.hasPermission(p, "plots.admin.build.road")) {
PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.build.road"); PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "plots.admin.build.road");
e.setCancelled(true); e.setCancelled(true);
} }
} else { } else {
final Plot plot = getCurrentPlot(b.getLocation()); final Plot plot = getCurrentPlot(loc);
if (plot == null || !plot.hasOwner()) { if (plot == null || !plot.hasOwner()) {
if (!PlotMain.hasPermission(p, "plots.admin.build.unowned")) { if (!PlotMain.hasPermission(p, "plots.admin.build.unowned")) {
PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "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")) { if (!PlotMain.hasPermission(p, "plots.admin.build.other")) {
PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "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")) { if (!PlotMain.hasPermission(p, "plots.admin.destroy.other")) {
PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "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")) { if (!PlotMain.hasPermission(p, "plots.admin.interact.other")) {
PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "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")) { if (!PlotMain.hasPermission(p, "plots.admin.vehicle.break.other")) {
PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "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")) { if (!PlotMain.hasPermission(p, "plots.admin.pve.other")) {
PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "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)) { } else if (!plot.hasRights(p)) {
if (!PlotMain.hasPermission(p, "plots.admin.projectile.other")) { if (!PlotMain.hasPermission(p, "plots.admin.projectile.other")) {
PlayerFunctions.sendMessage(p, C.NO_PERMISSION, "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; return;
} }
Player player = event.getPlayer(); Player player = event.getPlayer();
if (isInPlot(event.getBlock().getLocation())) { Location loc = event.getBlock().getLocation();
final Plot plot = getCurrentPlot(event.getBlockPlaced().getLocation()); if (isInPlot(loc)) {
final Plot plot = getCurrentPlot(loc);
if (!plot.hasOwner() && PlotMain.hasPermission(player, "plots.admin.build.unowned")) { if (!plot.hasOwner() && PlotMain.hasPermission(player, "plots.admin.build.unowned")) {
PlayerFunctions.sendMessage(player, C.NO_PERMISSION, "plots.admin.build.unowned"); PlayerFunctions.sendMessage(player, C.NO_PERMISSION, "plots.admin.build.unowned");
return; return;
@ -985,7 +966,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
} }
if (!PlotMain.hasPermission(player, "plots.admin.build.road")) { if (!PlotMain.hasPermission(player, "plots.admin.build.road")) {
PlayerFunctions.sendMessage(player, C.NO_PERMISSION, "plots.admin.build.road"); PlayerFunctions.sendMessage(player, C.NO_PERMISSION, "plots.admin.build.road");
event.setCancelled(true); if (isCluster(loc)) { event.setCancelled(true); }
} }
} }
} }

View File

@ -48,6 +48,7 @@ import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.titles.AbstractTitle; import com.intellectualcrafters.plot.titles.AbstractTitle;
import com.intellectualcrafters.plot.util.ClusterManager;
import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlayerFunctions;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.sk89q.worldguard.protection.flags.BooleanFlag; import com.sk89q.worldguard.protection.flags.BooleanFlag;
@ -88,6 +89,14 @@ import com.sk89q.worldguard.protection.flags.BooleanFlag;
return PlotMain.isPlotWorld(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) { public static PlotWorld getPlotWorld(final World world) {
return PlotMain.getWorldSettings(world); return PlotMain.getWorldSettings(world);
} }
@ -107,20 +116,6 @@ import com.sk89q.worldguard.protection.flags.BooleanFlag;
return UUIDHandler.getUUID(name); 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) { 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 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())); final PlotId p2 = PlayerFunctions.getPlot(new Location(l2.getWorld(), l2.getBlockX(), 64, l2.getBlockZ()));

View File

@ -61,6 +61,7 @@ public abstract class PlotWorld {
public final static boolean SPAWN_BREEDING_DEFAULT = false; public final static boolean SPAWN_BREEDING_DEFAULT = false;
public final static boolean WORLD_BORDER_DEFAULT = false; public final static boolean WORLD_BORDER_DEFAULT = false;
public static boolean REQUIRE_CLAIM_IN_CLUSTER_DEFAULT = false; public static boolean REQUIRE_CLAIM_IN_CLUSTER_DEFAULT = false;
public static boolean CLUSTER_GEN_ORE_DEFAULT = true;
// are plot clusters enabled // are plot clusters enabled
// require claim in cluster // require claim in cluster
@ -293,6 +294,7 @@ public abstract class PlotWorld {
public boolean SPAWN_BREEDING; public boolean SPAWN_BREEDING;
public boolean WORLD_BORDER; public boolean WORLD_BORDER;
public boolean REQUIRE_CLUSTER = false; public boolean REQUIRE_CLUSTER = false;
public boolean CLUSTER_ORE;
public PlotWorld(final String worldname) { public PlotWorld(final String worldname) {
this.worldname = worldname; this.worldname = worldname;
@ -305,7 +307,8 @@ public abstract class PlotWorld {
*/ */
public void loadDefaultConfiguration(final ConfigurationSection config) { public void loadDefaultConfiguration(final ConfigurationSection config) {
if (Settings.ENABLE_CLUSTERS) { 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.MOB_SPAWNING = config.getBoolean("natural_mob_spawning");
this.AUTO_MERGE = config.getBoolean("plot.auto_merge"); 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("event.spawn.breeding", PlotWorld.SPAWN_BREEDING_DEFAULT);
options.put("world.border", PlotWorld.WORLD_BORDER_DEFAULT); options.put("world.border", PlotWorld.WORLD_BORDER_DEFAULT);
if (Settings.ENABLE_CLUSTERS) { 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(); final ConfigurationNode[] settings = getSettingNodes();
/* /*

View File

@ -1,13 +1,22 @@
package com.intellectualcrafters.plot.util; package com.intellectualcrafters.plot.util;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.Random;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.generator.BlockPopulator;
import com.intellectualcrafters.plot.PlotMain; 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.BlockLoc;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotCluster;
@ -18,7 +27,8 @@ import com.intellectualcrafters.plot.object.PlotWorld;
public class ClusterManager { public class ClusterManager {
public static HashMap<String, HashSet<PlotCluster>> clusters; public static HashMap<String, HashSet<PlotCluster>> clusters;
private static PlotCluster last; private static HashSet<String> regenerating = new HashSet<>();
public static PlotCluster last;
public static boolean contains(PlotCluster cluster, PlotId id) { 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) { 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) { public static PlotClusterId getClusterId(PlotCluster cluster) {
return new PlotClusterId(cluster.getP1(), cluster.getP2()); return new PlotClusterId(cluster.getP1(), cluster.getP2());
} }
public static AugmentedPopulator getPopulator(PlotCluster cluster) {
World world = Bukkit.getWorld(cluster.world);
for (Iterator<BlockPopulator> 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<Chunk> 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);
}
}
} }

View File

@ -148,7 +148,7 @@ import com.intellectualcrafters.plot.object.PlotWorld;
} }
final PlotWorld plotworld = PlotMain.getWorldSettings(world); final PlotWorld plotworld = PlotMain.getWorldSettings(world);
PlotId id = manager.getPlotId(plotworld, loc); PlotId id = manager.getPlotId(plotworld, loc);
if (plotworld.REQUIRE_CLUSTER) { if (id!=null && plotworld.REQUIRE_CLUSTER) {
if (ClusterManager.getCluster(world, id) == null) { if (ClusterManager.getCluster(world, id) == null) {
return null; return null;
} }

View File

@ -6,4 +6,8 @@ public class TaskManager {
public static void runTask(final Runnable r) { public static void runTask(final Runnable r) {
PlotMain.getMain().getServer().getScheduler().runTaskAsynchronously(PlotMain.getMain(), 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);
}
} }