Started working on cluster commands

This commit is contained in:
boy0001 2015-01-29 14:20:29 +11:00
parent cbdb3d307b
commit 61898b0157
14 changed files with 525 additions and 179 deletions

View File

@ -977,15 +977,17 @@ public class PlotMain extends JavaPlugin implements Listener {
config.createSection(path);
}
// TODO Augment the world generation with a custom populator
PlotWorld.REQUIRE_CLAIM_IN_CLUSTER_DEFAULT = true;
plotWorld.saveConfiguration(config.getConfigurationSection(path));
plotWorld.loadConfiguration(config.getConfigurationSection(path));
PlotWorld.REQUIRE_CLAIM_IN_CLUSTER_DEFAULT = false;
try {
config.save(configFile);
} catch (final IOException e) {
e.printStackTrace();
}
// Now add it :p
addPlotWorld(world, plotWorld, plotManager);
}
@ -1368,13 +1370,13 @@ public class PlotMain extends JavaPlugin implements Listener {
MainCommand.subCommands.add(new WE_Anywhere());
}
}
if (Settings.WORLDGUARD) {
if (getServer().getPluginManager().getPlugin("WorldGuard") != null) {
worldGuard = (WorldGuardPlugin) getServer().getPluginManager().getPlugin("WorldGuard");
worldGuardListener = new WorldGuardListener(this);
getServer().getPluginManager().registerEvents(worldGuardListener, this);
}
}
// if (Settings.WORLDGUARD) {
// if (getServer().getPluginManager().getPlugin("WorldGuard") != null) {
// worldGuard = (WorldGuardPlugin) getServer().getPluginManager().getPlugin("WorldGuard");
// worldGuardListener = new WorldGuardListener(this);
// getServer().getPluginManager().registerEvents(worldGuardListener, this);
// }
// }
if (Settings.AUTO_CLEAR) {
ExpireManager.runTask();
}

View File

@ -24,6 +24,7 @@ package com.intellectualcrafters.plot.commands;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
@ -167,6 +168,17 @@ public class Auto extends SubCommand {
return sendMessage(plr, C.NOT_IN_PLOT);
}
PlotCluster cluster = ClusterManager.getCluster(loc);
PlotId bot = cluster.getP1();
PlotId top = cluster.getP2();
PlotId id = new PlotId((bot.x + top.x) / 2, (bot.y + top.y) / 2);
int width = Math.max(top.x - bot.x, top.y - bot.y);
int max = width * width;
// TODO finish cluster auto claiming
for (int i = 0; i <= max; i++) {
id = getNextPlot(id, 1);
}
}
boolean br = false;

View File

@ -0,0 +1,282 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands;
import java.util.HashSet;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotClusterId;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.util.ClusterManager;
import com.intellectualcrafters.plot.util.PlayerFunctions;
import com.intellectualcrafters.plot.util.PlotHelper;
import com.intellectualcrafters.plot.util.UUIDHandler;
public class Cluster extends SubCommand {
public Cluster() {
super(Command.CLUSTER, "Manage a plot cluster", "cluster", CommandCategory.ACTIONS, true);
}
@Override
public boolean execute(final Player plr, final String... args) {
if (!ClusterManager.clusters.containsKey(plr.getWorld().getName())) {
return false;
}
// list, create, delete, resize, invite, kick, leave, helpers, tp
if (args.length == 0) {
// return arguments
PlayerFunctions.sendMessage(plr, C.CLUSTER_AVAILABLE_ARGS);
return false;
}
String sub = args[0].toLowerCase();
switch (sub) {
case "list": {
if (!PlotMain.hasPermission(plr, "plots.cluster.list")) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.list");
return false;
}
if (args.length != 1) {
PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster list");
return false;
}
HashSet<PlotCluster> clusters = ClusterManager.getClusters(plr.getWorld());
PlayerFunctions.sendMessage(plr, C.CLUSTER_LIST_HEADING, clusters.size() + "");
for (PlotCluster cluster : clusters) {
// Ignore unmanaged clusters
if (cluster.settings.getAlias().equals("")) {
continue;
}
if (UUIDHandler.getUUID(plr).equals(cluster.owner)) {
PlayerFunctions.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&a" + cluster.toString());
}
else if (cluster.helpers.contains(UUIDHandler.getUUID(plr))) {
PlayerFunctions.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&3" + cluster.toString());
}
else if (cluster.invited.contains(UUIDHandler.getUUID(plr))) {
PlayerFunctions.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&9" + cluster.toString());
}
else {
PlayerFunctions.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, cluster.toString());
}
}
return true;
}
case "create": {
if (!PlotMain.hasPermission(plr, "plots.cluster.create")) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.create");
return false;
}
if (args.length != 4) {
PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster create <name> <id-bot> <id-top>");
return false;
}
// check pos1 / pos2
PlotId pos1 = PlotHelper.parseId(args[2]);
PlotId pos2 = PlotHelper.parseId(args[3]);
if (pos1 == null || pos2 == null) {
PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_ID);
return false;
}
// check if name is taken
String name = args[1];
for (PlotCluster cluster : ClusterManager.getClusters(plr.getWorld())) {
if (name.equals(cluster.getName())) {
PlayerFunctions.sendMessage(plr, C.ALIAS_IS_TAKEN);
return false;
}
}
//check if overlap
PlotClusterId id = new PlotClusterId(pos1, pos2);
HashSet<PlotCluster> intersects = ClusterManager.getIntersects(plr.getWorld().getName(), id);
if (intersects.size() > 0) {
PlayerFunctions.sendMessage(plr, C.CLUSTER_INTERSECTION, intersects.size() + "");
return false;
}
// create cluster
String world = plr.getWorld().getName();
PlotCluster cluster = new PlotCluster(world, pos1, pos2, UUIDHandler.getUUID(plr));
cluster.settings.setAlias(name);
DBFunc.createCluster(world, cluster);
ClusterManager.clusters.get(world).add(cluster);
PlayerFunctions.sendMessage(plr, C.CLUSTER_ADDED);
return true;
}
case "delete": {
if (!PlotMain.hasPermission(plr, "plots.cluster.delete")) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.delete");
return false;
}
if (args.length != 1) {
PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster delete");
return false;
}
PlotCluster toDelete = ClusterManager.getCluster(plr.getLocation());
if (toDelete == null) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
String world_delete = plr.getWorld().getName();
ClusterManager.clusters.get(world_delete).remove(toDelete);
DBFunc.delete(toDelete);
PlayerFunctions.sendMessage(plr, C.CLUSTER_DELETED);
return true;
}
case "resize": {
if (!PlotMain.hasPermission(plr, "plots.cluster.resize")) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize");
return false;
}
if (args.length != 3) {
PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster resize <pos1> <pos2>");
return false;
}
// check pos1 / pos2
PlotId pos1 = PlotHelper.parseId(args[2]);
PlotId pos2 = PlotHelper.parseId(args[3]);
if (pos1 == null || pos2 == null) {
PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_ID);
return false;
}
// check if in cluster
PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
if (cluster == null) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
//check if overlap
PlotClusterId id = new PlotClusterId(pos1, pos2);
HashSet<PlotCluster> intersects = ClusterManager.getIntersects(plr.getWorld().getName(), id);
if (intersects.size() > 0) {
PlayerFunctions.sendMessage(plr, C.CLUSTER_INTERSECTION, intersects.size() + "");
return false;
}
// resize cluster
DBFunc.resizeCluster(cluster, id);
PlayerFunctions.sendMessage(plr, C.CLUSTER_RESIZED);
return true;
}
case "invite": {
if (!PlotMain.hasPermission(plr, "plots.cluster.invite")) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.invite");
return false;
}
if (args.length != 2) {
PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster invite <player>");
return false;
}
// check if in cluster
PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
if (cluster == null) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
// check uuid
UUID uuid = UUIDHandler.getUUID(args[1]);
if (uuid == null) {
PlayerFunctions.sendMessage(plr, C.INVALID_PLAYER, args[1]);
return false;
}
if (!cluster.hasRights(uuid)) {
// add the user if not added
cluster.invited.add(uuid);
String world = plr.getWorld().getName();
DBFunc.setInvited(world, cluster, uuid);
Player player = UUIDHandler.uuidWrapper.getPlayer(uuid);
if (player != null) {
PlayerFunctions.sendMessage(plr, C.CLUSTER_INVITED, cluster.getName());
}
}
PlayerFunctions.sendMessage(plr, C.CLUSTER_ADDED_USER);
return true;
}
case "kick": {
if (!PlotMain.hasPermission(plr, "plots.cluster.kick")) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.kick");
return false;
}
if (args.length != 2) {
PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster kick <player>");
return false;
}
return true;
}
case "leave": {
if (!PlotMain.hasPermission(plr, "plots.cluster.leave")) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.leave");
return false;
}
if (args.length != 1 && args.length != 2) {
PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster leave [name]");
return false;
}
return true;
}
case "helpers": {
if (!PlotMain.hasPermission(plr, "plots.cluster.helpers")) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.helpers");
return false;
}
if (args.length != 3) {
PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster helpers <add|remove> <player>");
return false;
}
return true;
}
case "tp": {
if (!PlotMain.hasPermission(plr, "plots.cluster.tp")) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.tp");
return false;
}
if (args.length != 2) {
PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster tp <name>");
return false;
}
return true;
}
case "info": {
if (!PlotMain.hasPermission(plr, "plots.cluster.info")) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.info");
return false;
}
if (args.length != 1 && args.length != 2) {
PlayerFunctions.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster info [name]");
return false;
}
return true;
}
}
PlayerFunctions.sendMessage(plr, C.CLUSTER_AVAILABLE_ARGS);
return false;
}
}

View File

@ -36,154 +36,44 @@ public enum Command {
// (Rating system) (ratings can be stored as the average, and number of
// ratings)
// - /plot rate <number out of 10>
CLUSTER("cluster", "cl"),
BUY("buy","b"),
/**
*
*/
CREATEROADSCHEMATIC("createroadschematic"),
/**
*
*/
DEBUGROADREGEN("debugroadregen"),
/**
*
*/
REGENALLROADS("regenallroads"),
/**
*
*/
DEBUGLOADTEST("debugloadtest"),
/**
*
*/
DEBUGSAVETEST("debugsavetest"),
/**
*
*/
UNCLAIM("unclaim"),
/**
*
*/
DEBUGCLEAR("debugclear"),
/**
*
*/
SWAP("swap"),
/**
*
*/
INBOX("inbox"),
/**
*
*/
DEBUGCLAIMTEST("debugclaimtest"),
/**
*
*/
COMMENT("comment", "msg"),
/**
*
*/
TRUSTED("trusted", "trust"),
/**
*
*/
PASTE("paste"),
/**
*
*/
CLIPBOARD("clipboard", "cboard"),
/**
*
*/
COPY("copy"),
/**
*
*/
KICK("kick", "k"),
/**
*
*/
HELPERS("helpers", "hp"),
/**
*
*/
DENIED("denied", "dn"),
/**
*
*/
CLAIM("claim", "c"),
/**
*
*/
MERGE("merge", "m"),
/**
*
*/
UNLINK("unlink", "u"),
/**
*
*/
CLEAR("clear", "clear", new CommandPermission("plots.clear")),
/**
*
*/
DELETE("delete", "d", new CommandPermission("plots.delete")),
/**
*
*/
DEBUG("debug", "debug", new CommandPermission("plots.admin")),
/**
*
*/
INTERFACE("interface", "int", new CommandPermission("plots.interface")),
/**
*
*/
HOME("home", "h"),
/**
*
*/
INFO("info", "i"),
/**
*
*/
LIST("list", "l"),
/**
*
*/
SET("set", "s"),
/**
*
*/
PURGE("purge"),
/**
*
*/
SETUP("setup"),
/**
*
*/
OP("op", "admin"),
/**
*
*/
DEOP("deop", "deadmin"),
/**
*
*/
BAN("ban", "block"),
/**
*
*/
UNBAN("unban", "unblock"),
/**
*
*/
DATABASE("database", "convert"),
/**
*
*/
TP("tp", "tp");
/**

View File

@ -67,7 +67,7 @@ public class Unlink extends SubCommand {
final World world = plr.getWorld();
final PlotId pos1 = PlayerFunctions.getBottomPlot(world, plot).id;
final PlotId pos2 = PlayerFunctions.getTopPlot(world, plot).id;
final ArrayList<PlotId> ids = PlayerFunctions.getPlotSelectionIds(world, pos1, pos2);
final ArrayList<PlotId> ids = PlayerFunctions.getPlotSelectionIds(pos1, pos2);
final PlotUnlinkEvent event = new PlotUnlinkEvent(world, ids);

View File

@ -37,6 +37,18 @@ import com.intellectualsites.translation.bukkit.BukkitTranslation;
* @author Citymonstret
*/
public enum C {
/*
* Cluster
*/
CLUSTER_AVAILABLE_ARGS("&6The following sub commands are available: &clist, create, delete, resize, invite, kick, leave, helpers, info, tp"),
CLUSTER_LIST_HEADING("&cThere are %s clusters in this world"),
CLUSTER_LIST_ELEMENT("&7 - &6%s\n"),
CLUSTER_INTERSECTION("&6The proposed area overlaps with %s existing cluster/s"),
CLUSTER_ADDED("&6Successfully created the cluster."),
CLUSTER_DELETED("&6Successfully deleted the cluster."),
CLUSTER_RESIZED("&6Successfully resized the cluster."),
CLUSTER_ADDED_USER("&6Successfully added user to the cluster."),
CLUSTER_INVITED("&6You have been invited to the following cluster: %s."),
/*
* Border
*/
@ -185,6 +197,7 @@ public enum C {
NAME_LITTLE("&c%s name is too short, &6%s&c<&6%s"),
NO_COMMANDS("&cI'm sorry, but you're not permitted to use any subcommands."),
SUBCOMMAND_SET_OPTIONS_HEADER("&cPossible Values: "),
COMMAND_SYNTAX("&6Usage: &c%s"),
/*
* Player not found
*/
@ -247,6 +260,7 @@ public enum C {
NOT_VALID_BLOCK("&cThat's not a valid block."),
NOT_VALID_NUMBER("&cThat's not a valid number"),
NOT_VALID_PLOT_ID("&cThat's not a valid plot id."),
PLOT_ID_FORM("&cThe plot id must be in the form: &6X;Y &ce.g. &6-5;7"),
NOT_YOUR_PLOT("&cThat is not your plot."),
NO_SUCH_PLOT("&cThere is no such plot"),
PLAYER_HAS_NOT_BEEN_ON("&cThat player hasn't been in the plotworld"),

View File

@ -237,7 +237,13 @@ public interface AbstractDB {
* @param uuid Player that should be removed
*/
public void removeTrusted(final String world, final Plot plot, final UUID uuid);
/**
*
* @param world
* @param cluster
* @param uuid
*/
public void removeInvited(final String world, final PlotCluster cluster, final UUID uuid);
/**
* @param plot Plot Object
* @param uuid Player that should be removed
@ -255,6 +261,13 @@ public interface AbstractDB {
* @param uuid Player that should be added
*/
public void setTrusted(final String world, final Plot plot, final UUID uuid);
/**
*
* @param world
* @param cluster
* @param uuid
*/
public void setInvited(final String world, final PlotCluster cluster, final UUID uuid);
/**
* @param plot Plot Object

View File

@ -116,6 +116,10 @@ public class DBFunc {
dbManager.delete(world, plot);
}
public static void delete(final PlotCluster toDelete) {
dbManager.delete(toDelete);
}
/**
* Create plot settings
*
@ -265,6 +269,16 @@ public class DBFunc {
dbManager.removeTrusted(world, plot, uuid);
}
/**
*
* @param world
* @param plot
* @param uuid
*/
public static void removeInvited(final String world, final PlotCluster cluster, final UUID uuid) {
dbManager.removeInvited(world, cluster, uuid);
}
/**
* @param plot
* @param player
@ -285,6 +299,10 @@ public class DBFunc {
dbManager.setTrusted(world, plot, uuid);
}
public static void setInvited(final String world, final PlotCluster cluster, final UUID uuid) {
dbManager.setInvited(world, cluster, uuid);
}
/**
* @param plot
* @param player

View File

@ -47,6 +47,7 @@ import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotClusterId;
import com.intellectualcrafters.plot.object.PlotComment;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotSettings;
import com.intellectualcrafters.plot.util.ClusterManager;
import com.intellectualcrafters.plot.util.TaskManager;
@ -383,6 +384,7 @@ public class SQLManager implements AbstractDB {
}
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "cluster` (" + "`id` INTEGER PRIMARY KEY AUTOINCREMENT," + "`pos1_x` INT(11) NOT NULL," + "`pos1_z` INT(11) NOT NULL," + "`pos2_x` INT(11) NOT NULL," + "`pos2_z` INT(11) NOT NULL," + "`owner` VARCHAR(45) NOT NULL," + "`world` VARCHAR(45) NOT NULL," + "`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "cluster_helpers` (" + "`cluster_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + "`tier` INT(11) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "cluster_invited` (" + "`cluster_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + "`tier` INT(11) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "cluster_settings` (" + " `cluster_id` INT(11) NOT NULL," + " `biome` VARCHAR(45) DEFAULT 'FOREST'," + " `rain` INT(1) DEFAULT 0," + " `custom_time` TINYINT(1) DEFAULT '0'," + " `time` INT(11) DEFAULT '8000'," + " `deny_entry` TINYINT(1) DEFAULT '0'," + " `alias` VARCHAR(50) DEFAULT NULL," + " `flags` VARCHAR(512) DEFAULT NULL," + " `merged` INT(11) DEFAULT NULL," + " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT'," + " PRIMARY KEY (`cluster_id`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
} else {
@ -395,7 +397,8 @@ public class SQLManager implements AbstractDB {
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_ratings` (`plot_plot_id` INT(11) NOT NULL, `rating` INT(2) NOT NULL, `player` VARCHAR(40) NOT NULL, PRIMARY KEY(`plot_plot_id`))");
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "cluster` (" + "`id` INTEGER PRIMARY KEY AUTOINCREMENT," + "`pos1_x` INT(11) NOT NULL," + "`pos1_z` INT(11) NOT NULL," + "`pos2_x` INT(11) NOT NULL," + "`pos2_z` INT(11) NOT NULL," + "`owner` VARCHAR(45) NOT NULL," + "`world` VARCHAR(45) NOT NULL," + "`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP)");
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "cluster_helpers` (" + "`cluster_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + "`tier` INT(11) NOT NULL" + ")");
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "cluster_helpers` (" + "`cluster_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")");
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "cluster_invited` (" + "`cluster_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")");
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "cluster_settings` (" + " `cluster_id` INT(11) NOT NULL," + " `biome` VARCHAR(45) DEFAULT 'FOREST'," + " `rain` INT(1) DEFAULT 0," + " `custom_time` TINYINT(1) DEFAULT '0'," + " `time` INT(11) DEFAULT '8000'," + " `deny_entry` TINYINT(1) DEFAULT '0'," + " `alias` VARCHAR(50) DEFAULT NULL," + " `flags` VARCHAR(512) DEFAULT NULL," + " `merged` INT(11) DEFAULT NULL," + " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT'," + " PRIMARY KEY (`cluster_id`)" + ")");
}
stmt.executeBatch();
@ -1248,6 +1251,9 @@ public class SQLManager implements AbstractDB {
stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "cluster_helpers` WHERE `cluster_id` = ?");
stmt.setInt(1, id);
stmt.executeUpdate();
stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "cluster_invited` WHERE `cluster_id` = ?");
stmt.setInt(1, id);
stmt.executeUpdate();
stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "cluster` WHERE `id` = ?");
stmt.setInt(1, id);
stmt.executeUpdate();
@ -1350,12 +1356,30 @@ public class SQLManager implements AbstractDB {
PlotMain.sendConsoleSenderMessage("&cCluster " + id + " in cluster_helpers does not exist. Please create the cluster or remove this entry.");
}
}
/*
* Getting invited
*/
r = stmt.executeQuery("SELECT `user_uuid`, `cluster_id` FROM `" + this.prefix + "cluster_invited`");
while (r.next()) {
id = r.getInt("plot_plot_id");
owner = r.getString("user_uuid");
user = uuids.get(owner);
if (user == null) {
user = UUID.fromString(owner);
uuids.put(owner, user);
}
cluster = clusters.get(id);
if (cluster != null) {
cluster.invited.add(user);
} else {
PlotMain.sendConsoleSenderMessage("&cCluster " + id + " in cluster_invited does not exist. Please create the cluster or remove this entry.");
}
}
r = stmt.executeQuery("SELECT * FROM `" + this.prefix + "cluster_settings`");
while (r.next()) {
id = r.getInt("plot_plot_id");
cluster = clusters.get(id);
if (cluster != null) {
final String b = r.getString("biome");
if (b != null) {
for (final Biome mybiome : Biome.values()) {
@ -1432,7 +1456,7 @@ public class SQLManager implements AbstractDB {
}
cluster.settings.flags = flags;
} else {
PlotMain.sendConsoleSenderMessage("&cPLOT " + id + " in plot_settings does not exist. Please create the plot or remove this entry.");
PlotMain.sendConsoleSenderMessage("&cCluster " + id + " in cluster_settings does not exist. Please create the cluster or remove this entry.");
}
}
stmt.close();
@ -1565,8 +1589,9 @@ public class SQLManager implements AbstractDB {
stmt.close();
int id = getClusterId(cluster.world, ClusterManager.getClusterId(cluster));
stmt = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "cluster_settings`(`cluster_id`) VALUES(" + "?)");
stmt = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "cluster_settings`(`cluster_id`, `alias`) VALUES(?, ?" + ")");
stmt.setInt(1, id);
stmt.setString(2, cluster.settings.getAlias());
stmt.executeUpdate();
stmt.close();
} catch (final Exception e) {
@ -1670,4 +1695,43 @@ public class SQLManager implements AbstractDB {
}
return h;
}
@Override
public void removeInvited(String world, final PlotCluster cluster, final UUID uuid) {
TaskManager.runTask(new Runnable() {
@Override
public void run() {
try {
final PreparedStatement statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "cluster_invited` WHERE `cluster_id` = ? AND `user_uuid` = ?");
statement.setInt(1, getClusterId(cluster.world, ClusterManager.getClusterId(cluster)));
statement.setString(2, uuid.toString());
statement.executeUpdate();
statement.close();
} catch (final SQLException e) {
e.printStackTrace();
PlotMain.sendConsoleSenderMessage("&7[WARN] "+"Failed to remove invited for cluster " + cluster);
}
}
});
}
@Override
public void setInvited(String world, final PlotCluster cluster, final UUID uuid) {
TaskManager.runTask(new Runnable() {
@Override
public void run() {
try {
final PreparedStatement statement = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "cluster_invited` (`cluster_id`, `user_uuid`) VALUES(?,?)");
statement.setInt(1, getClusterId(cluster.world, ClusterManager.getClusterId(cluster)));
statement.setString(2, uuid.toString());
statement.executeUpdate();
statement.close();
} catch (final SQLException e) {
PlotMain.sendConsoleSenderMessage("&7[WARN] "+"Failed to set helper for cluster " + cluster);
e.printStackTrace();
}
}
});
}
}

View File

@ -25,32 +25,17 @@ public class AugmentedPopulator extends BlockPopulator {
public final PlotManager manager;
public final PlotGenerator generator;
private final int botx;
private final int botz;
private final int topx;
private final int topz;
private final int bx;
private final int bz;
private final int tx;
private final int tz;
public BlockWrapper getBlock(int X, int Z, int i, int j, short[][] result, boolean check) {
int y_1 = (i << 4);
int y_2 = (j >> 8);
int y = y_1 + y_2;
int z_1 = (j - ((y & 0xF) << 8));
int z = (z_1 >> 4);
int x;
if (check) {
if (z < botz || z > topz) {
return null;
}
x = z_1 - (z << 4);
if (x < botx || x > topx) {
return null;
}
}
else {
x = z_1 - (z << 4);
}
short id = result[i][j];
return new BlockWrapper(x, y, z, id, (byte) 0);
public BlockWrapper getBlock(int X, int Z, int i, int j, short[][] r, boolean c) {
int y = (i << 4) + (j >> 8);
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);
}
public AugmentedPopulator(String world, PlotGenerator generator, PlotCluster cluster) {
@ -60,14 +45,14 @@ public class AugmentedPopulator extends BlockPopulator {
World bukkitWorld = Bukkit.getWorld(world);
Location bot = manager.getPlotBottomLocAbs(plotworld, cluster.getP1());
Location top = manager.getPlotTopLocAbs(plotworld, cluster.getP2()).add(1,0,1);
Location b = manager.getPlotBottomLocAbs(plotworld, cluster.getP1());
Location t = manager.getPlotTopLocAbs(plotworld, cluster.getP2()).add(1,0,1);
this.botx = bot.getBlockX();
this.botz = bot.getBlockZ();
this.bx = b.getBlockX();
this.bz = b.getBlockZ();
this.topx = top.getBlockX();
this.topz = top.getBlockZ();
this.tx = t.getBlockX();
this.tz = t.getBlockZ();
// Add the populator
bukkitWorld.getPopulators().add(this);
@ -82,10 +67,10 @@ public class AugmentedPopulator extends BlockPopulator {
int x2 = x + 15;
int z2 = z + 15;
boolean inX1 = (x > botx && x < topx);
boolean inX2 = (x2 > botx && x2 < topx);
boolean inZ1 = (z > botz && z < topz);
boolean inZ2 = (z2 > botz && z2 < topz);
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;

View File

@ -3,6 +3,10 @@ package com.intellectualcrafters.plot.object;
import java.util.HashSet;
import java.util.UUID;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.database.SQLManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
public class PlotCluster {
public final String world;
@ -11,6 +15,7 @@ public class PlotCluster {
public UUID owner;
public HashSet<UUID> helpers = new HashSet<UUID>();
public HashSet<UUID> invited = new HashSet<UUID>();
private PlotId pos1;
private PlotId pos2;
@ -36,18 +41,35 @@ public class PlotCluster {
this.pos1 = pos1;
this.pos2 = pos2;
this.owner = owner;
this.settings = new PlotSettings(null);
}
public boolean hasRights(UUID uuid) {
return (invited.contains(uuid)|| invited.contains(DBFunc.everyone) || helpers.contains(uuid) || helpers.contains(DBFunc.everyone));
}
public String getName() {
return this.settings.getAlias();
}
@Override
public int hashCode() {
// TODO Auto-generated method stub
return super.hashCode();
return this.pos1.hashCode();
}
@Override
public boolean equals(Object obj) {
// TODO Auto-generated method stub
return super.equals(obj);
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final PlotCluster other = (PlotCluster) obj;
return (this.world.equals(other.world) && this.pos1.equals(other.pos1) && this.pos2.equals(other.pos2));
}
@Override

View File

@ -60,7 +60,7 @@ public abstract class PlotWorld {
public final static boolean SPAWN_CUSTOM_DEFAULT = true;
public final static boolean SPAWN_BREEDING_DEFAULT = false;
public final static boolean WORLD_BORDER_DEFAULT = false;
public final static boolean REQUIRE_CLAIM_IN_CLUSTER_DEFAULT = false;
public static boolean REQUIRE_CLAIM_IN_CLUSTER_DEFAULT = false;
// are plot clusters enabled
// require claim in cluster

View File

@ -4,6 +4,7 @@ import java.util.HashMap;
import java.util.HashSet;
import org.bukkit.Location;
import org.bukkit.World;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.object.Plot;
@ -24,6 +25,17 @@ public class ClusterManager {
return false;
}
public static HashSet<PlotCluster> getClusters(World world) {
return getClusters(world.getName());
}
public static HashSet<PlotCluster> getClusters(String world) {
if (clusters.containsKey(world)) {
return clusters.get(world);
}
return new HashSet<>();
}
public static boolean contains(PlotCluster cluster, Location loc) {
String world = loc.getWorld().getName();
PlotManager manager = PlotMain.getPlotManager(world);
@ -36,6 +48,28 @@ public class ClusterManager {
return false;
}
public static HashSet<PlotCluster> getIntersects(String world, PlotClusterId id) {
if (clusters.containsKey(world)) {
return new HashSet<>();
}
HashSet<PlotCluster> list = new HashSet<PlotCluster>();
for (PlotCluster cluster : clusters.get(world)) {
if (intersects(cluster, id)) {
list.add(cluster);
}
}
return list;
}
public static boolean intersects(PlotCluster cluster, PlotClusterId id) {
PlotId pos1 = cluster.getP1();
PlotId pos2 = cluster.getP2();
if (pos1.x <= id.pos2.x && pos2.x >= id.pos1.x && pos1.y <= id.pos2.y && pos2.y >= id.pos1.y) {
return true;
}
return false;
}
public static PlotCluster getCluster(Plot plot) {
return getCluster(plot.world, plot.id);
}

View File

@ -88,6 +88,16 @@ import com.intellectualcrafters.plot.object.PlotWorld;
}
}
public static PlotId parseId(String arg) {
try {
String[] split = arg.split(";");
return new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1])) ;
}
catch (Exception e) {
return null;
}
}
/**
* direction 0 = north, 1 = south, etc:
*