This commit is contained in:
Jesse Boyd 2015-01-28 08:51:56 +11:00
parent cb0296a09f
commit cbdb3d307b
11 changed files with 94 additions and 23 deletions

View File

@ -31,8 +31,10 @@ import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.ClusterManager;
import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlayerFunctions;
import com.intellectualcrafters.plot.util.PlotHelper; import com.intellectualcrafters.plot.util.PlotHelper;
@ -156,6 +158,17 @@ public class Auto extends SubCommand {
} }
// } // }
} }
PlotWorld plotworld = PlotMain.getWorldSettings(world);
if (plotworld.REQUIRE_CLUSTER) {
Location loc = plr.getLocation();
Plot plot = PlotHelper.getCurrentPlot(loc);
if (plot == null) {
return sendMessage(plr, C.NOT_IN_PLOT);
}
PlotCluster cluster = ClusterManager.getCluster(loc);
}
boolean br = false; boolean br = false;
String worldname = world.getName(); String worldname = world.getName();
if ((size_x == 1) && (size_z == 1)) { if ((size_x == 1) && (size_z == 1)) {
@ -189,7 +202,7 @@ public class Auto extends SubCommand {
Claim.claimPlot(plr, plot, teleport, true); Claim.claimPlot(plr, plot, teleport, true);
} }
} }
if (!PlotHelper.mergePlots(plr, world, PlayerFunctions.getPlotSelectionIds(world, start, end))) { if (!PlotHelper.mergePlots(plr, world, PlayerFunctions.getPlotSelectionIds(start, end))) {
return false; return false;
} }
br = true; br = true;

View File

@ -90,7 +90,7 @@ public class Buy extends SubCommand {
double price = initPrice; double price = initPrice;
PlotId id = plot.id; PlotId id = plot.id;
PlotId id2 = PlayerFunctions.getTopPlot(world, plot).id; PlotId id2 = PlayerFunctions.getTopPlot(world, plot).id;
int size = PlayerFunctions.getPlotSelectionIds(world, id, id2).size(); int size = PlayerFunctions.getPlotSelectionIds(id, id2).size();
PlotWorld plotworld = PlotMain.getWorldSettings(world); PlotWorld plotworld = PlotMain.getWorldSettings(world);
if (plotworld.USE_ECONOMY) { if (plotworld.USE_ECONOMY) {
price += plotworld.PLOT_PRICE * size; price += plotworld.PLOT_PRICE * size;

View File

@ -104,7 +104,7 @@ public class DebugClaimTest extends SubCommand {
final ArrayList<Plot> plots = new ArrayList<>(); final ArrayList<Plot> plots = new ArrayList<>();
for (final PlotId id : PlayerFunctions.getPlotSelectionIds(world, min, max)) { for (final PlotId id : PlayerFunctions.getPlotSelectionIds(min, max)) {
final Plot plot = PlotHelper.getPlot(world, id); final Plot plot = PlotHelper.getPlot(world, id);
final boolean contains = PlotMain.getPlots(world).containsKey(plot.id); final boolean contains = PlotMain.getPlots(world).containsKey(plot.id);
if (contains) { if (contains) {

View File

@ -168,7 +168,7 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
final PlotId id = plot.id; final PlotId id = plot.id;
final PlotId id2 = PlayerFunctions.getTopPlot(world, plot).id; final PlotId id2 = PlayerFunctions.getTopPlot(world, plot).id;
final int num = PlayerFunctions.getPlotSelectionIds(world, id, id2).size(); final int num = PlayerFunctions.getPlotSelectionIds(id, id2).size();
final String alias = plot.settings.getAlias().length() > 0 ? plot.settings.getAlias() : "none"; final String alias = plot.settings.getAlias().length() > 0 ? plot.settings.getAlias() : "none";
final String biome = getBiomeAt(plot).toString(); final String biome = getBiomeAt(plot).toString();
final String helpers = getPlayerList(plot.helpers); final String helpers = getPlayerList(plot.helpers);

View File

@ -36,7 +36,7 @@ import com.intellectualcrafters.plot.util.PlayerFunctions;
import com.intellectualcrafters.plot.util.PlotHelper; import com.intellectualcrafters.plot.util.PlotHelper;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
@SuppressWarnings("deprecation") public class SetOwner extends SubCommand { public class SetOwner extends SubCommand {
public SetOwner() { public SetOwner() {
super("setowner", "plots.admin.command.setowner", "Set the plot owner", "setowner {player}", "so", CommandCategory.ACTIONS, true); super("setowner", "plots.admin.command.setowner", "Set the plot owner", "setowner {player}", "so", CommandCategory.ACTIONS, true);
@ -68,7 +68,7 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
final PlotId bot = PlayerFunctions.getBottomPlot(world, plot).id; final PlotId bot = PlayerFunctions.getBottomPlot(world, plot).id;
final PlotId top = PlayerFunctions.getTopPlot(world, plot).id; final PlotId top = PlayerFunctions.getTopPlot(world, plot).id;
final ArrayList<PlotId> plots = PlayerFunctions.getPlotSelectionIds(world, bot, top); final ArrayList<PlotId> plots = PlayerFunctions.getPlotSelectionIds(bot, top);
for (final PlotId id : plots) { for (final PlotId id : plots) {
final Plot current = PlotMain.getPlots(world).get(id); final Plot current = PlotMain.getPlots(world).get(id);

View File

@ -209,6 +209,7 @@ public enum C {
* No <plot> * No <plot>
*/ */
NOT_IN_PLOT("&cYou're not in a plot"), NOT_IN_PLOT("&cYou're not in a plot"),
NOT_IN_CLUSTER("&cYou're not in a plot cluster"),
NOT_IN_PLOT_WORLD("&cYou're not in a plot world"), NOT_IN_PLOT_WORLD("&cYou're not in a plot world"),
NOT_VALID_WORLD("&cThat is not a valid world (case sensitive)"), NOT_VALID_WORLD("&cThat is not a valid world (case sensitive)"),
NOT_VALID_PLOT_WORLD("&cThat is not a valid plot world (case sensitive)"), NOT_VALID_PLOT_WORLD("&cThat is not a valid plot world (case sensitive)"),

View File

@ -49,8 +49,6 @@ public class AugmentedPopulator extends BlockPopulator {
else { else {
x = z_1 - (z << 4); x = z_1 - (z << 4);
} }
short id = result[i][j]; short id = result[i][j];
return new BlockWrapper(x, y, z, id, (byte) 0); return new BlockWrapper(x, y, z, id, (byte) 0);
} }
@ -77,9 +75,6 @@ public class AugmentedPopulator extends BlockPopulator {
@Override @Override
public void populate(World world, Random rand, Chunk chunk) { public void populate(World world, Random rand, Chunk chunk) {
// TODO check if chunk is in any clusters
int X = chunk.getX(); int X = chunk.getX();
int Z = chunk.getZ(); int Z = chunk.getZ();
int x = X << 4; int x = X << 4;

View File

@ -33,6 +33,7 @@ import org.bukkit.configuration.ConfigurationSection;
import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.config.Configuration; import com.intellectualcrafters.plot.config.Configuration;
import com.intellectualcrafters.plot.config.ConfigurationNode; import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
@ -59,6 +60,12 @@ public abstract class PlotWorld {
public final static boolean SPAWN_CUSTOM_DEFAULT = true; public final static boolean SPAWN_CUSTOM_DEFAULT = true;
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 final static boolean REQUIRE_CLAIM_IN_CLUSTER_DEFAULT = false;
// are plot clusters enabled
// require claim in cluster
// TODO make this configurable // TODO make this configurable
// make non static and static_default_valu + add config option // make non static and static_default_valu + add config option
public static List<Material> BLOCKS; /* public static List<Material> BLOCKS; /*
@ -285,6 +292,7 @@ public abstract class PlotWorld {
public boolean SPAWN_CUSTOM; public boolean SPAWN_CUSTOM;
public boolean SPAWN_BREEDING; public boolean SPAWN_BREEDING;
public boolean WORLD_BORDER; public boolean WORLD_BORDER;
public boolean REQUIRE_CLUSTER = false;
public PlotWorld(final String worldname) { public PlotWorld(final String worldname) {
this.worldname = worldname; this.worldname = worldname;
@ -296,6 +304,9 @@ public abstract class PlotWorld {
* @param config Configuration Section * @param config Configuration Section
*/ */
public void loadDefaultConfiguration(final ConfigurationSection config) { public void loadDefaultConfiguration(final ConfigurationSection config) {
if (Settings.ENABLE_CLUSTERS) {
this.REQUIRE_CLUSTER = config.getBoolean("claim.require_cluster");
}
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");
this.PLOT_BIOME = (Biome) Configuration.BIOME.parseString(config.getString("plot.biome")); this.PLOT_BIOME = (Biome) Configuration.BIOME.parseString(config.getString("plot.biome"));
@ -359,6 +370,9 @@ public abstract class PlotWorld {
options.put("event.spawn.custom", PlotWorld.SPAWN_CUSTOM_DEFAULT); options.put("event.spawn.custom", PlotWorld.SPAWN_CUSTOM_DEFAULT);
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) {
options.put("claim.require_cluster", PlotWorld.REQUIRE_CLAIM_IN_CLUSTER_DEFAULT);
}
final ConfigurationNode[] settings = getSettingNodes(); final ConfigurationNode[] settings = getSettingNodes();
/* /*
* Saving generator specific settings * Saving generator specific settings

View File

@ -3,10 +3,15 @@ package com.intellectualcrafters.plot.util;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import org.bukkit.Location;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotClusterId; import com.intellectualcrafters.plot.object.PlotClusterId;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager;
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;
@ -19,20 +24,58 @@ public class ClusterManager {
return false; return false;
} }
public static boolean contains(PlotCluster cluster, Location loc) {
String world = loc.getWorld().getName();
PlotManager manager = PlotMain.getPlotManager(world);
PlotWorld plotworld = PlotMain.getWorldSettings(world);
Location bot = manager.getPlotBottomLocAbs(plotworld, cluster.getP1());
Location top = manager.getPlotTopLocAbs(plotworld, cluster.getP2()).add(1,0,1);
if (bot.getBlockX() < loc.getBlockX() && bot.getBlockZ() < loc.getBlockZ() && top.getBlockX() > loc.getBlockX() && top.getBlockZ() > loc.getBlockZ()) {
return true;
}
return false;
}
public static PlotCluster getCluster(Plot plot) { public static PlotCluster getCluster(Plot plot) {
if (last != null && last.world.equals(plot.world)) { return getCluster(plot.world, plot.id);
if (contains(last, plot.id)) { }
public static PlotCluster getCluster(Location loc) {
String world = loc.getWorld().getName();
if (last != null && last.world.equals(world)) {
if (contains(last, loc)) {
return last; return last;
} }
} }
if (clusters == null) { if (clusters == null) {
return null; return null;
} }
HashSet<PlotCluster> local = clusters.get(plot.world); HashSet<PlotCluster> local = clusters.get(world);
if (local == null) {
return null;
}
for (PlotCluster cluster : local) {
if (contains(cluster, loc)) {
last = cluster;
return cluster;
}
}
return null;
}
public static PlotCluster getCluster(String world, PlotId id) {
if (last != null && last.world.equals(world)) {
if (contains(last, id)) {
return last;
}
}
if (clusters == null) {
return null;
}
HashSet<PlotCluster> local = clusters.get(world);
if (local == null) { if (local == null) {
return null; return null;
} }
PlotId id = plot.id;
for (PlotCluster cluster : local) { for (PlotCluster cluster : local) {
if (contains(cluster, id)) { if (contains(cluster, id)) {
last = cluster; last = cluster;

View File

@ -56,7 +56,7 @@ import com.intellectualcrafters.plot.object.PlotWorld;
return getCurrentPlot(player) != null; return getCurrentPlot(player) != null;
} }
public static ArrayList<PlotId> getPlotSelectionIds(@SuppressWarnings("unused") final World world, final PlotId pos1, final PlotId pos2) { public static ArrayList<PlotId> getPlotSelectionIds(PlotId pos1, final PlotId pos2) {
final ArrayList<PlotId> myplots = new ArrayList<>(); final ArrayList<PlotId> myplots = new ArrayList<>();
for (int x = pos1.x; x <= pos2.x; x++) { for (int x = pos1.x; x <= pos2.x; x++) {
for (int y = pos1.y; y <= pos2.y; y++) { for (int y = pos1.y; y <= pos2.y; y++) {
@ -147,7 +147,13 @@ import com.intellectualcrafters.plot.object.PlotWorld;
return null; return null;
} }
final PlotWorld plotworld = PlotMain.getWorldSettings(world); final PlotWorld plotworld = PlotMain.getWorldSettings(world);
return manager.getPlotId(plotworld, loc); PlotId id = manager.getPlotId(plotworld, loc);
if (plotworld.REQUIRE_CLUSTER) {
if (ClusterManager.getCluster(world, id) == null) {
return null;
}
}
return id;
} }
/** /**
@ -225,7 +231,6 @@ import com.intellectualcrafters.plot.object.PlotWorld;
* *
* @return * @return
*/ */
@SuppressWarnings("SuspiciousNameCombination")
public static int getAllowedPlots(final Player p) { public static int getAllowedPlots(final Player p) {
return PlotMain.hasPermissionRange(p, "plots.plot", Settings.MAX_PLOTS); return PlotMain.hasPermissionRange(p, "plots.plot", Settings.MAX_PLOTS);
} }

View File

@ -397,7 +397,7 @@ import com.intellectualcrafters.plot.object.PlotWorld;
count++; count++;
final PlotId bot = PlayerFunctions.getBottomPlot(world, plot).id; final PlotId bot = PlayerFunctions.getBottomPlot(world, plot).id;
final PlotId top = PlayerFunctions.getTopPlot(world, plot).id; final PlotId top = PlayerFunctions.getTopPlot(world, plot).id;
plots = PlayerFunctions.getPlotSelectionIds(world, new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y)); plots = PlayerFunctions.getPlotSelectionIds(new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y));
if (ownsPlots(world, plots, player, 0)) { if (ownsPlots(world, plots, player, 0)) {
final boolean result = mergePlots(world, plots); final boolean result = mergePlots(world, plots);
if (result) { if (result) {
@ -405,7 +405,7 @@ import com.intellectualcrafters.plot.object.PlotWorld;
continue; continue;
} }
} }
plots = PlayerFunctions.getPlotSelectionIds(world, new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y)); plots = PlayerFunctions.getPlotSelectionIds(new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y));
if (ownsPlots(world, plots, player, 1)) { if (ownsPlots(world, plots, player, 1)) {
final boolean result = mergePlots(world, plots); final boolean result = mergePlots(world, plots);
if (result) { if (result) {
@ -413,7 +413,7 @@ import com.intellectualcrafters.plot.object.PlotWorld;
continue; continue;
} }
} }
plots = PlayerFunctions.getPlotSelectionIds(world, new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1)); plots = PlayerFunctions.getPlotSelectionIds(new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1));
if (ownsPlots(world, plots, player, 2)) { if (ownsPlots(world, plots, player, 2)) {
final boolean result = mergePlots(world, plots); final boolean result = mergePlots(world, plots);
if (result) { if (result) {
@ -421,7 +421,7 @@ import com.intellectualcrafters.plot.object.PlotWorld;
continue; continue;
} }
} }
plots = PlayerFunctions.getPlotSelectionIds(world, new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y)); plots = PlayerFunctions.getPlotSelectionIds(new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y));
if (ownsPlots(world, plots, player, 3)) { if (ownsPlots(world, plots, player, 3)) {
final boolean result = mergePlots(world, plots); final boolean result = mergePlots(world, plots);
if (result) { if (result) {