more work

This commit is contained in:
Jesse Boyd 2015-01-25 21:16:10 -07:00
parent 030f2df21c
commit 72713995cd
10 changed files with 560 additions and 60 deletions

View File

@ -98,6 +98,7 @@ 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.titles.DefaultTitle; import com.intellectualcrafters.plot.titles.DefaultTitle;
import com.intellectualcrafters.plot.util.ClusterManager;
import com.intellectualcrafters.plot.util.ConsoleColors; import com.intellectualcrafters.plot.util.ConsoleColors;
import com.intellectualcrafters.plot.util.ExpireManager; import com.intellectualcrafters.plot.util.ExpireManager;
import com.intellectualcrafters.plot.util.Lag; import com.intellectualcrafters.plot.util.Lag;
@ -812,6 +813,7 @@ public class PlotMain extends JavaPlugin implements Listener {
config.set("version", config_ver); config.set("version", config_ver);
final Map<String, Object> options = new HashMap<>(); final Map<String, Object> options = new HashMap<>();
options.put("auto_update", false); options.put("auto_update", false);
options.put("clusters.enabled", Settings.ENABLE_CLUSTERS);
options.put("plotme-alias", Settings.USE_PLOTME_ALIAS); options.put("plotme-alias", Settings.USE_PLOTME_ALIAS);
options.put("plotme-convert.enabled", Settings.CONVERT_PLOTME); options.put("plotme-convert.enabled", Settings.CONVERT_PLOTME);
options.put("claim.max-auto-area", Settings.MAX_AUTO_SIZE); options.put("claim.max-auto-area", Settings.MAX_AUTO_SIZE);
@ -842,6 +844,7 @@ public class PlotMain extends JavaPlugin implements Listener {
config.set(node.getKey(), node.getValue()); config.set(node.getKey(), node.getValue());
} }
} }
Settings.ENABLE_CLUSTERS = config.getBoolean("clusters.enabled");
Settings.DEBUG = config.getBoolean("debug"); Settings.DEBUG = config.getBoolean("debug");
if (Settings.DEBUG) { if (Settings.DEBUG) {
sendConsoleSenderMessage(C.PREFIX.s() + "&6Debug Mode Enabled (Default). Edit the config to turn this off."); sendConsoleSenderMessage(C.PREFIX.s() + "&6Debug Mode Enabled (Default). Edit the config to turn this off.");
@ -1278,6 +1281,9 @@ public class PlotMain extends JavaPlugin implements Listener {
return; return;
} }
plots = DBFunc.getPlots(); plots = DBFunc.getPlots();
if (Settings.ENABLE_CLUSTERS) {
ClusterManager.clusters = DBFunc.getClusters();
}
} }
// TODO: Implement mongo // TODO: Implement mongo
else if (Settings.DB.USE_MONGO) { else if (Settings.DB.USE_MONGO) {
@ -1310,6 +1316,9 @@ public class PlotMain extends JavaPlugin implements Listener {
return; return;
} }
plots = DBFunc.getPlots(); plots = DBFunc.getPlots();
if (Settings.ENABLE_CLUSTERS) {
ClusterManager.clusters = DBFunc.getClusters();
}
} else { } else {
Logger.add(LogLevel.DANGER, "No storage type is set."); Logger.add(LogLevel.DANGER, "No storage type is set.");
sendConsoleSenderMessage(C.PREFIX + "&cNo storage type is set!"); sendConsoleSenderMessage(C.PREFIX + "&cNo storage type is set!");

View File

@ -29,6 +29,7 @@ package com.intellectualcrafters.plot.config;
* @author Empire92 * @author Empire92
*/ */
public class Settings { public class Settings {
public static boolean ENABLE_CLUSTERS = false;
/** /**
* Default UUID_FECTHING: false * Default UUID_FECTHING: false
*/ */

View File

@ -24,12 +24,15 @@ package com.intellectualcrafters.plot.database;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotClusterId;
import com.intellectualcrafters.plot.object.PlotComment; import com.intellectualcrafters.plot.object.PlotComment;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
@ -91,6 +94,8 @@ public interface AbstractDB {
*/ */
public void delete(final String world, final Plot plot); public void delete(final String world, final Plot plot);
public void delete(final PlotCluster cluster);
/** /**
* Create plot settings * Create plot settings
* *
@ -109,11 +114,27 @@ public interface AbstractDB {
*/ */
public int getId(final String world, final PlotId id2); public int getId(final String world, final PlotId id2);
/**
* Get the id of a given plot cluster
*
* @param world Which the plot is located in
* @param pos1 bottom Plot ID
* @param pos2 top Plot ID
*
* @return Integer = Cluster Entry Id
*/
public int getClusterId(final String world, final PlotClusterId id);
/** /**
* @return A linked hashmap containing all plots * @return A linked hashmap containing all plots
*/ */
public LinkedHashMap<String, HashMap<PlotId, Plot>> getPlots(); public LinkedHashMap<String, HashMap<PlotId, Plot>> getPlots();
/**
* @return A hashmap containing all plot clusters
*/
public HashMap<String, HashSet<PlotCluster>> getClusters();
/** /**
* Set the merged status for a plot * Set the merged status for a plot
* *
@ -132,6 +153,21 @@ public interface AbstractDB {
*/ */
public void setFlags(final String world, final Plot plot, final Set<Flag> flags); public void setFlags(final String world, final Plot plot, final Set<Flag> flags);
/**
* Set cluster flags
*
* @param world World in which the plot is located
* @param cluster PlotCluster Object
* @param flags flags to set (flag[])
*/
public void setFlags(final PlotCluster cluster, final Set<Flag> flags);
/**
* Rename a cluster
*/
public void setClusterName(final PlotCluster cluster, final String name);
/** /**
* Set the plot alias * Set the plot alias
* *
@ -163,6 +199,13 @@ public interface AbstractDB {
*/ */
public void setPosition(final String world, final Plot plot, final String position); public void setPosition(final String world, final Plot plot, final String position);
/**
*
* @param cluster
* @param position
*/
public void setPosition(final PlotCluster cluster, final String position);
/** /**
* @param id Plot Entry ID * @param id Plot Entry ID
* *
@ -170,12 +213,25 @@ public interface AbstractDB {
*/ */
public HashMap<String, Object> getSettings(final int id); public HashMap<String, Object> getSettings(final int id);
/**
*
* @param id
* @return
*/
public HashMap<String, Object> getClusterSettings(final int id);
/** /**
* @param plot Plot Object * @param plot Plot Object
* @param uuid Player that should be removed * @param uuid Player that should be removed
*/ */
public void removeHelper(final String world, final Plot plot, final UUID uuid); public void removeHelper(final String world, final Plot plot, final UUID uuid);
/**
* @param cluster PlotCluster Object
* @param uuid Player that should be removed
*/
public void removeHelper(final PlotCluster cluster, final UUID uuid);
/** /**
* @param plot Plot Object * @param plot Plot Object
* @param uuid Player that should be removed * @param uuid Player that should be removed
@ -188,6 +244,12 @@ public interface AbstractDB {
*/ */
public void setHelper(final String world, final Plot plot, final UUID uuid); public void setHelper(final String world, final Plot plot, final UUID uuid);
/**
* @param cluster PlotCluster Object
* @param uuid Player that should be removed
*/
public void setHelper(final PlotCluster cluster, final UUID uuid);
/** /**
* @param plot Plot Object * @param plot Plot Object
* @param uuid Player that should be added * @param uuid Player that should be added
@ -245,4 +307,8 @@ public interface AbstractDB {
public ArrayList<PlotComment> getComments(final String world, final Plot plot, final int tier, boolean below); public ArrayList<PlotComment> getComments(final String world, final Plot plot, final int tier, boolean below);
public void createPlotAndSettings(Plot plot); public void createPlotAndSettings(Plot plot);
public void createCluster(PlotCluster cluster);
public void resizeCluster(PlotCluster current, PlotClusterId resize);
} }

View File

@ -23,12 +23,15 @@ package com.intellectualcrafters.plot.database;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotClusterId;
import com.intellectualcrafters.plot.object.PlotComment; import com.intellectualcrafters.plot.object.PlotComment;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
@ -160,6 +163,10 @@ public class DBFunc {
dbManager.setFlags(world, plot, flags); dbManager.setFlags(world, plot, flags);
} }
public static void setFlags(final PlotCluster cluster, final Set<Flag> flags) {
dbManager.setFlags(cluster, flags);
}
/** /**
* @param plot * @param plot
* @param alias * @param alias
@ -224,6 +231,32 @@ public class DBFunc {
dbManager.removeHelper(world, plot, uuid); dbManager.removeHelper(world, plot, uuid);
} }
/**
* @param cluster
* @param player
*/
public static void removeHelper(final PlotCluster cluster, final UUID uuid) {
dbManager.removeHelper(cluster, uuid);
}
/**
* @param world
* @param cluster
* @param name
*/
public static void createCluster(String world, PlotCluster cluster) {
dbManager.createCluster(cluster);
}
/**
* @param world
* @param current
* @param resize
*/
public static void resizeCluster(PlotCluster current, PlotClusterId resize) {
dbManager.resizeCluster(current, resize);
}
/** /**
* @param plot * @param plot
* @param player * @param player
@ -240,6 +273,10 @@ public class DBFunc {
dbManager.setHelper(world, plot, uuid); dbManager.setHelper(world, plot, uuid);
} }
public static void setHelper(final PlotCluster cluster, final UUID uuid) {
dbManager.setHelper(cluster, uuid);
}
/** /**
* @param plot * @param plot
* @param player * @param player
@ -267,4 +304,16 @@ public class DBFunc {
public static double getRatings(final Plot plot) { public static double getRatings(final Plot plot) {
return dbManager.getRatings(plot); return dbManager.getRatings(plot);
} }
public static HashMap<String, HashSet<PlotCluster>> getClusters() {
return dbManager.getClusters();
}
public static void setPosition(PlotCluster cluster, String position) {
dbManager.setPosition(cluster, position);
}
public static HashMap<String, Object> getClusterSettings(int id) {
return dbManager.getClusterSettings(id);
}
} }

View File

@ -43,8 +43,11 @@ import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
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.PlotClusterId;
import com.intellectualcrafters.plot.object.PlotComment; import com.intellectualcrafters.plot.object.PlotComment;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.util.ClusterManager;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
/** /**
@ -59,6 +62,7 @@ public class SQLManager implements AbstractDB {
public final String CREATE_SETTINGS; public final String CREATE_SETTINGS;
public final String CREATE_HELPERS; public final String CREATE_HELPERS;
public final String CREATE_PLOT; public final String CREATE_PLOT;
public final String CREATE_CLUSTER;
// Private Final // Private Final
private Connection connection; private Connection connection;
private final String prefix; private final String prefix;
@ -83,6 +87,7 @@ public class SQLManager implements AbstractDB {
this.CREATE_SETTINGS = "INSERT INTO `" + this.prefix + "plot_settings` (`plot_plot_id`) values "; this.CREATE_SETTINGS = "INSERT INTO `" + this.prefix + "plot_settings` (`plot_plot_id`) values ";
this.CREATE_HELPERS = "INSERT INTO `" + this.prefix + "plot_helpers` (`plot_plot_id`, `user_uuid`) values "; this.CREATE_HELPERS = "INSERT INTO `" + this.prefix + "plot_helpers` (`plot_plot_id`, `user_uuid`) values ";
this.CREATE_PLOT = "INSERT INTO `" + this.prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) VALUES(?, ?, ?, ?)"; this.CREATE_PLOT = "INSERT INTO `" + this.prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) VALUES(?, ?, ?, ?)";
this.CREATE_CLUSTER = "INSERT INTO `" + this.prefix + "cluster`(`pos1_x`, `pos1_z`, `pos2_x`, `pos2_z`, `owner`, `world`) VALUES(?, ?, ?, ?, ?, ?)";
// schedule reconnect // schedule reconnect
if (PlotMain.getMySQL() != null) { if (PlotMain.getMySQL() != null) {
@ -376,15 +381,22 @@ public class SQLManager implements AbstractDB {
if (add_constraint) { if (add_constraint) {
stmt.addBatch("ALTER TABLE `" + this.prefix + "plot_settings` ADD CONSTRAINT `" + this.prefix + "plot_settings_ibfk_1` FOREIGN KEY (`plot_plot_id`) REFERENCES `" + this.prefix + "plot` (`id`) ON DELETE CASCADE"); stmt.addBatch("ALTER TABLE `" + this.prefix + "plot_settings` ADD CONSTRAINT `" + this.prefix + "plot_settings_ibfk_1` FOREIGN KEY (`plot_plot_id`) REFERENCES `" + this.prefix + "plot` (`id`) ON DELETE CASCADE");
} }
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_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 { } else {
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot` (" + "`id` INTEGER PRIMARY KEY AUTOINCREMENT," + "`plot_id_x` INT(11) NOT NULL," + "`plot_id_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 + "plot` (" + "`id` INTEGER PRIMARY KEY AUTOINCREMENT," + "`plot_id_x` INT(11) NOT NULL," + "`plot_id_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 + "plot_denied` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_denied` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")");
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_helpers` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_helpers` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")");
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_trusted` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_trusted` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")");
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_comments` (" + "`plot_plot_id` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`tier` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ")"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_comments` (" + "`plot_plot_id` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`tier` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ")");
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_settings` (" + " `plot_plot_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 (`plot_plot_id`)" + ")"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_settings` (" + " `plot_plot_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 (`plot_plot_id`)" + ")");
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 + "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_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(); stmt.executeBatch();
stmt.clearBatch(); stmt.clearBatch();
@ -1229,4 +1241,253 @@ public class SQLManager implements AbstractDB {
} }
return 0.0d; return 0.0d;
} }
@Override
public void delete(final PlotCluster cluster) {
ClusterManager.removeCluster(cluster);
TaskManager.runTask(new Runnable() {
@Override
public void run() {
PreparedStatement stmt = null;
final int id = getClusterId(cluster.world, ClusterManager.getClusterId(cluster));
try {
stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "cluster_settings` WHERE `cluster_id` = ?");
stmt.setInt(1, id);
stmt.executeUpdate();
stmt.close();
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` WHERE `id` = ?");
stmt.setInt(1, id);
stmt.executeUpdate();
stmt.close();
} catch (final SQLException e) {
e.printStackTrace();
PlotMain.sendConsoleSenderMessage("&c[ERROR] "+"Failed to delete plot cluster: " + cluster.pos1 + ":" + cluster.pos2);
}
}
});
}
@Override
public int getClusterId(String world, PlotClusterId id) {
PreparedStatement stmt = null;
try {
stmt = this.connection.prepareStatement("SELECT `id` FROM `" + this.prefix + "cluster` WHERE `pos1_x` = ? AND `pos1_z` = ? AND `pos2_x` = ? AND `pos2_z` = ? AND world = ? ORDER BY `timestamp` ASC");
stmt.setInt(1, id.pos1.x);
stmt.setInt(2, id.pos1.y);
stmt.setInt(3, id.pos1.x);
stmt.setInt(3, id.pos2.y);
stmt.setString(5, world);
final ResultSet r = stmt.executeQuery();
int c_id = Integer.MAX_VALUE;
while (r.next()) {
c_id = r.getInt("id");
}
stmt.close();
return c_id;
} catch (final SQLException e) {
e.printStackTrace();
}
return Integer.MAX_VALUE;
}
@Override
public HashMap<String, HashSet<PlotCluster>> getClusters() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setFlags(final PlotCluster cluster, Set<Flag> flags) {
final StringBuilder flag_string = new StringBuilder();
int i = 0;
for (final Flag flag : flags) {
if (i != 0) {
flag_string.append(",");
}
flag_string.append(flag.getKey() + ":" + flag.getValueString().replaceAll(":", "\u00AF").replaceAll(",", "\u00B4"));
i++;
}
TaskManager.runTask(new Runnable() {
@Override
public void run() {
try {
final PreparedStatement stmt = SQLManager.this.connection.prepareStatement("UPDATE `" + SQLManager.this.prefix + "cluster_settings` SET `flags` = ? WHERE `cluster_id` = ?");
stmt.setString(1, flag_string.toString());
stmt.setInt(2, getClusterId(cluster.world, ClusterManager.getClusterId(cluster)));
stmt.execute();
stmt.close();
} catch (final SQLException e) {
e.printStackTrace();
PlotMain.sendConsoleSenderMessage("&7[WARN] "+"Could not set flag for plot " + cluster);
}
}
});
}
@Override
public void setClusterName(final PlotCluster cluster, final String name) {
cluster.settings.setAlias(name);
TaskManager.runTask(new Runnable() {
@Override
public void run() {
PreparedStatement stmt = null;
try {
stmt = SQLManager.this.connection.prepareStatement("UPDATE `" + SQLManager.this.prefix + "cluster_settings` SET `alias` = ? WHERE `cluster_id` = ?");
stmt.setString(1, name);
stmt.setInt(2, getClusterId(cluster.world, ClusterManager.getClusterId(cluster)));
stmt.executeUpdate();
stmt.close();
} catch (final SQLException e) {
PlotMain.sendConsoleSenderMessage("&7[WARN] "+"Failed to set alias for cluster " + cluster);
e.printStackTrace();
}
}
});
}
@Override
public void removeHelper(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_helpers` 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 helper for cluster " + cluster);
}
}
});
}
@Override
public void setHelper(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_helpers` (`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();
}
}
});
}
@Override
public void createCluster(final PlotCluster cluster) {
TaskManager.runTask(new Runnable() {
@Override
public void run() {
PreparedStatement stmt = null;
try {
stmt = SQLManager.this.connection.prepareStatement(SQLManager.this.CREATE_CLUSTER);
stmt.setInt(1, cluster.pos1.x);
stmt.setInt(2, cluster.pos1.y);
stmt.setInt(3, cluster.pos2.x);
stmt.setInt(4, cluster.pos2.y);
stmt.setString(5, cluster.owner.toString());
stmt.setString(6, cluster.world);
stmt.executeUpdate();
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.setInt(1, id);
stmt.executeUpdate();
stmt.close();
} catch (final Exception e) {
e.printStackTrace();
PlotMain.sendConsoleSenderMessage("&c[ERROR] "+"Failed to save cluster " + cluster);
}
}
});
}
@Override
public void resizeCluster(PlotCluster current, PlotClusterId resize) {
// TODO Auto-generated method stub
}
@Override
public void setPosition(final PlotCluster cluster, final String position) {
TaskManager.runTask(new Runnable() {
@Override
public void run() {
PreparedStatement stmt = null;
try {
stmt = SQLManager.this.connection.prepareStatement("UPDATE `" + SQLManager.this.prefix + "cluster_settings` SET `position` = ? WHERE `cluster_id` = ?");
stmt.setString(1, position);
stmt.setInt(2, getClusterId(cluster.world, ClusterManager.getClusterId(cluster)));
stmt.executeUpdate();
stmt.close();
} catch (final SQLException e) {
PlotMain.sendConsoleSenderMessage("&7[WARN] "+"Failed to set position for cluster " + cluster);
e.printStackTrace();
}
}
});
}
@Override
public HashMap<String, Object> getClusterSettings(int id) {
final HashMap<String, Object> h = new HashMap<String, Object>();
PreparedStatement stmt = null;
try {
stmt = this.connection.prepareStatement("SELECT * FROM `" + this.prefix + "cluster_settings` WHERE `cluster_id` = ?");
stmt.setInt(1, id);
final ResultSet r = stmt.executeQuery();
String var;
Object val;
while (r.next()) {
var = "biome";
val = r.getObject(var);
h.put(var, val);
var = "rain";
val = r.getObject(var);
h.put(var, val);
var = "custom_time";
val = r.getObject(var);
h.put(var, val);
var = "time";
val = r.getObject(var);
h.put(var, val);
var = "deny_entry";
val = r.getObject(var);
h.put(var, (short) 0);
var = "alias";
val = r.getObject(var);
h.put(var, val);
var = "position";
val = r.getObject(var);
h.put(var, val);
var = "flags";
val = r.getObject(var);
h.put(var, val);
var = "merged";
val = r.getObject(var);
h.put(var, val);
}
stmt.close();
} catch (final SQLException e) {
PlotMain.sendConsoleSenderMessage("&7[WARN] "+"Failed to load settings for cluster: " + id);
e.printStackTrace();
}
return h;
}
} }

View File

@ -35,6 +35,8 @@ import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.events.PlotFlagAddEvent; import com.intellectualcrafters.plot.events.PlotFlagAddEvent;
import com.intellectualcrafters.plot.events.PlotFlagRemoveEvent; import com.intellectualcrafters.plot.events.PlotFlagRemoveEvent;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotSettings;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
/** /**
@ -63,18 +65,12 @@ import com.intellectualcrafters.plot.object.PlotWorld;
return (getFlag(flag.getKey()) == null) && flags.add(flag); return (getFlag(flag.getKey()) == null) && flags.add(flag);
} }
/** public static Flag getSettingFlag(String world, PlotSettings settings, String flag) {
* Get the value of a flag for a plot (respects flag defaults) ArrayList<Flag> flags = new ArrayList<>();
* @param plot if (settings.flags != null && settings.flags.size() > 0) {
* @param flag flags.addAll(settings.flags);
* @return
*/
public static Flag getPlotFlag(Plot plot, String flag) {
ArrayList<Flag> flags = new ArrayList<>();
if (plot.settings.flags != null && plot.settings.flags.size() > 0) {
flags.addAll(plot.settings.flags);
} }
PlotWorld plotworld = PlotMain.getWorldSettings(plot.world); PlotWorld plotworld = PlotMain.getWorldSettings(world);
if (plotworld != null && plotworld.DEFAULT_FLAGS != null && plotworld.DEFAULT_FLAGS.length > 0) { if (plotworld != null && plotworld.DEFAULT_FLAGS != null && plotworld.DEFAULT_FLAGS.length > 0) {
flags.addAll(Arrays.asList(plotworld.DEFAULT_FLAGS)); flags.addAll(Arrays.asList(plotworld.DEFAULT_FLAGS));
} }
@ -86,12 +82,25 @@ import com.intellectualcrafters.plot.object.PlotWorld;
return null; return null;
} }
/**
* Get the value of a flag for a plot (respects flag defaults)
* @param plot
* @param flag
* @return
*/
public static Flag getPlotFlag(Plot plot, String flag) {
return getSettingFlag(plot.world, plot.settings, flag);
}
public static boolean isPlotFlagTrue(Plot plot, String strFlag) { public static boolean isPlotFlagTrue(Plot plot, String strFlag) {
Flag flag = getPlotFlag(plot, strFlag); Flag flag = getPlotFlag(plot, strFlag);
if (flag == null) { if (flag == null) {
return false; return false;
} }
return flag.getValue().equals("true"); if (flag.getValue() instanceof Boolean) {
return (boolean) flag.getValue();
}
return false;
} }
/** /**
@ -101,10 +110,14 @@ import com.intellectualcrafters.plot.object.PlotWorld;
* @return * @return
*/ */
public static Flag getPlotFlagAbs(Plot plot, String flag) { public static Flag getPlotFlagAbs(Plot plot, String flag) {
if (plot.settings.flags == null || plot.settings.flags.size() == 0) { return getSettingFlagAbs(plot.settings, flag);
}
public static Flag getSettingFlagAbs(PlotSettings settings, String flag) {
if (settings.flags == null || settings.flags.size() == 0) {
return null; return null;
} }
for (final Flag myflag : plot.settings.flags) { for (final Flag myflag : settings.flags) {
if (myflag.getKey().equals(flag)) { if (myflag.getKey().equals(flag)) {
return myflag; return myflag;
} }
@ -132,14 +145,29 @@ import com.intellectualcrafters.plot.object.PlotWorld;
return true; return true;
} }
public static boolean addClusterFlag(PlotCluster cluster, final Flag flag) {
//TODO plot cluster flag event
final Flag hasFlag = getSettingFlag(cluster.world, cluster.settings, flag.getKey());
if (hasFlag != null) {
cluster.settings.flags.remove(hasFlag);
}
cluster.settings.flags.add(flag);
DBFunc.setFlags(cluster, cluster.settings.flags);
return true;
}
/** /**
* *
* @param plot * @param plot
* @return * @return
*/ */
public static Set<Flag> getPlotFlags(Plot plot) { public static Set<Flag> getPlotFlags(Plot plot) {
Set<Flag> plotflags = plot.settings.flags; return getSettingFlags(plot.world, plot.settings);
PlotWorld plotworld = PlotMain.getWorldSettings(plot.world); }
public static Set<Flag> getSettingFlags(String world, PlotSettings settings) {
Set<Flag> plotflags = settings.flags;
PlotWorld plotworld = PlotMain.getWorldSettings(world);
if (plotworld != null && plotworld.DEFAULT_FLAGS != null && plotworld.DEFAULT_FLAGS.length > 0) { if (plotworld != null && plotworld.DEFAULT_FLAGS != null && plotworld.DEFAULT_FLAGS.length > 0) {
plotflags.addAll(Arrays.asList(plotworld.DEFAULT_FLAGS)); plotflags.addAll(Arrays.asList(plotworld.DEFAULT_FLAGS));
} }
@ -164,6 +192,20 @@ import com.intellectualcrafters.plot.object.PlotWorld;
return false; return false;
} }
public static boolean removeClusterFlag(PlotCluster cluster, String flag) {
final Flag hasFlag = getSettingFlag(cluster.world, cluster.settings, flag);
if (hasFlag != null) {
Flag flagObj = FlagManager.getSettingFlagAbs(cluster.settings, flag);
if (flagObj != null) {
//TODO cluster flag add event
cluster.settings.flags.remove(hasFlag);
DBFunc.setFlags(cluster, cluster.settings.flags);
return true;
}
}
return false;
}
public static void setPlotFlags(Plot plot, Set<Flag> flags) { public static void setPlotFlags(Plot plot, Set<Flag> flags) {
if (flags == null) { if (flags == null) {
plot.settings.flags = new HashSet<>(); plot.settings.flags = new HashSet<>();
@ -174,6 +216,16 @@ import com.intellectualcrafters.plot.object.PlotWorld;
DBFunc.setFlags(plot.world, plot, plot.settings.flags); DBFunc.setFlags(plot.world, plot, plot.settings.flags);
} }
public static void setClusterFlags(PlotCluster cluster, Set<Flag> flags) {
if (flags == null) {
cluster.settings.flags = new HashSet<>();
DBFunc.setFlags(cluster, cluster.settings.flags);
return;
}
cluster.settings.flags = flags;
DBFunc.setFlags(cluster, cluster.settings.flags);
}
public static Flag[] removeFlag(final Flag[] flags, final String r) { public static Flag[] removeFlag(final Flag[] flags, final String r) {
final Flag[] f = new Flag[flags.length - 1]; final Flag[] f = new Flag[flags.length - 1];
int index = 0; int index = 0;
@ -278,20 +330,4 @@ import com.intellectualcrafters.plot.object.PlotWorld;
} }
return flags; return flags;
} }
/**
* Get the flags for a plot
*
* @param plot Plot to search in
*
* @return List (AbstractFlag)
*/
public static List<AbstractFlag> getPlotAbstractFlags(final Plot plot) {
final Set<Flag> plotFlags = getPlotFlags(plot);
final List<AbstractFlag> flags = new ArrayList<>();
for (final Flag flag : plotFlags) {
flags.add(flag.getAbstractFlag());
}
return flags;
}
} }

View File

@ -13,7 +13,7 @@ import com.intellectualcrafters.plot.object.PlotBlock;
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;
import com.intellectualcrafters.plot.object.PlotRegion; 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;
@ -22,7 +22,6 @@ public class AugmentedPopulator extends BlockPopulator {
public final PlotGenerator generator; public final PlotGenerator generator;
public final PlotWorld plotworld; public final PlotWorld plotworld;
public final PlotManager manager; public final PlotManager manager;
public HashSet<PlotRegion> regions;
public BlockWrapper getBlock(int i, int j, short[][] result) { public BlockWrapper getBlock(int i, int j, short[][] result) {
@ -37,32 +36,17 @@ public class AugmentedPopulator extends BlockPopulator {
return new BlockWrapper(x, y, z, id, (byte) 0); return new BlockWrapper(x, y, z, id, (byte) 0);
} }
public AugmentedPopulator(PlotGenerator generator, PlotWorld plotworld, PlotManager manager, HashSet<PlotRegion> regions) { public AugmentedPopulator(PlotGenerator generator, PlotWorld plotworld, PlotManager manager) {
this.generator = generator; this.generator = generator;
this.plotworld = plotworld; this.plotworld = plotworld;
this.manager = manager; this.manager = manager;
this.regions = regions;
}
// Check if the augmented populator contains the plot id
public boolean contains(PlotId id) {
// TODO check if any regions contain the id
return false;
}
/**
* Returns false if the proposed region overlaps with an existing region
*/
public boolean addRegion(PlotRegion region) {
boolean contains = false; //TODO check if any regions contain these plots
if (contains) {// contains
return false;
}
return regions.add(region);
} }
@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

@ -0,0 +1,36 @@
package com.intellectualcrafters.plot.object;
import java.util.UUID;
public class PlotCluster {
public PlotSettings settings;
public final String world;
public final PlotId pos1;
public final PlotId pos2;
public final UUID owner;
public PlotCluster(String world, PlotId pos1, PlotId pos2, UUID owner) {
this.world = world;
this.pos1 = pos1;
this.pos2 = pos2;
this.owner = owner;
}
@Override
public int hashCode() {
// TODO Auto-generated method stub
return super.hashCode();
}
@Override
public boolean equals(Object obj) {
// TODO Auto-generated method stub
return super.equals(obj);
}
@Override
public String toString() {
return world + ";" + pos1.x + ";" + pos1.y + ";" + pos2.x + ";" + pos2.y;
}
}

View File

@ -1,11 +1,11 @@
package com.intellectualcrafters.plot.object; package com.intellectualcrafters.plot.object;
public class PlotRegion { public class PlotClusterId {
public final PlotId pos1; public final PlotId pos1;
public final PlotId pos2; public final PlotId pos2;
public PlotRegion(PlotId pos1, PlotId pos2) { public PlotClusterId(PlotId pos1, PlotId pos2) {
this.pos1 = pos1; this.pos1 = pos1;
this.pos2 = pos2; this.pos2 = pos2;
} }

View File

@ -0,0 +1,58 @@
package com.intellectualcrafters.plot.util;
import java.util.HashMap;
import java.util.HashSet;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotClusterId;
import com.intellectualcrafters.plot.object.PlotId;
public class ClusterManager {
public static HashMap<String, HashSet<PlotCluster>> clusters;
private static PlotCluster last;
public static boolean contains(PlotCluster cluster, PlotId id) {
if (cluster.pos1.x <= id.x && cluster.pos1.y <= id.y && cluster.pos2.x >= id.x && cluster.pos2.y >= id.y) {
return true;
}
return false;
}
public static PlotCluster getCluster(Plot plot) {
if (last != null && last.world.equals(plot.world)) {
if (contains(last, plot.id)) {
return last;
}
}
if (clusters == null) {
return null;
}
HashSet<PlotCluster> local = clusters.get(plot.world);
if (local == null) {
return null;
}
PlotId id = plot.id;
for (PlotCluster cluster : local) {
if (contains(cluster, id)) {
last = cluster;
return cluster;
}
}
return null;
}
public static boolean removeCluster(PlotCluster cluster) {
if (clusters != null) {
if (clusters.containsKey(cluster.world)) {
clusters.get(cluster.world).remove(cluster);
return true;
}
}
return false;
}
public static PlotClusterId getClusterId(PlotCluster cluster) {
return new PlotClusterId(cluster.pos1, cluster.pos2);
}
}