From 53b8f8a0d05930d080f538634d33953446501eed Mon Sep 17 00:00:00 2001 From: boy0001 Date: Mon, 6 Apr 2015 22:16:24 +1000 Subject: [PATCH] fixes for comment system --- .../plot/commands/Comment.java | 3 + .../plot/commands/Inbox.java | 41 ++++-- .../plot/commands/Move.java | 1 + .../plot/database/AbstractDB.java | 3 +- .../plot/database/DBFunc.java | 5 +- .../plot/database/SQLManager.java | 133 ++++++++++-------- .../plot/generator/BukkitHybridUtils.java | 3 + .../plot/generator/HybridPop.java | 1 + .../plot/object/BukkitPlayer.java | 8 ++ .../plot/object/PlotId.java | 2 +- .../plot/object/PlotPlayer.java | 3 + .../plot/object/PlotSettings.java | 7 +- .../plot/object/comment/InboxOwner.java | 12 +- .../plot/object/comment/InboxPublic.java | 10 +- .../plot/object/comment/InboxReport.java | 6 +- .../plot/util/bukkit/BukkitSetupUtils.java | 3 + 16 files changed, 157 insertions(+), 84 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Comment.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Comment.java index 025351ce0..f07484902 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Comment.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Comment.java @@ -21,10 +21,12 @@ package com.intellectualcrafters.plot.commands; import java.util.Arrays; +import java.util.List; import org.apache.commons.lang.StringUtils; import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; @@ -33,6 +35,7 @@ import com.intellectualcrafters.plot.object.comment.CommentInbox; import com.intellectualcrafters.plot.object.comment.CommentManager; import com.intellectualcrafters.plot.object.comment.PlotComment; import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.Permissions; public class Comment extends SubCommand { public Comment() { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java index 7b4cd9272..a4b93782f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java @@ -21,15 +21,11 @@ package com.intellectualcrafters.plot.commands; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import java.util.UUID; import org.apache.commons.lang.StringUtils; import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.database.DBFunc; -import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.RunnableVal; @@ -37,8 +33,6 @@ import com.intellectualcrafters.plot.object.comment.CommentInbox; import com.intellectualcrafters.plot.object.comment.CommentManager; import com.intellectualcrafters.plot.object.comment.PlotComment; import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.Permissions; -import com.intellectualcrafters.plot.util.TaskManager; public class Inbox extends SubCommand { public Inbox() { @@ -62,7 +56,7 @@ public class Inbox extends SubCommand { max = comments.length; } final StringBuilder string = new StringBuilder(); - string.append(C.PLOT_LIST_HEADER_PAGED.s().replaceAll("plot","review").replaceAll("%cur", page + 1 + "").replaceAll("%max", totalPages + 1 + "").replaceAll("%word%", "all")).append("\n"); + string.append(C.PLOT_LIST_HEADER_PAGED.s().replaceAll("plot","comment").replaceAll("%cur", page + 1 + "").replaceAll("%max", totalPages + 1 + "").replaceAll("%word%", "all")).append("\n"); PlotComment c; // This might work xD for (int x = (page * 12); x < max; x++) { @@ -74,6 +68,7 @@ public class Inbox extends SubCommand { else { color = "&7"; } + System.out.print("PLOT INBOX: " +c.id); string.append("&8[&7#" + x + "&8][&7" + c.world + ";" + c.id + "&8][&7#" + c.senderName + "&8]" + color + c.senderName +"&7 : " + color + c.comment + "\n"); } MainUtil.sendMessage(player, string.toString()); @@ -82,11 +77,30 @@ public class Inbox extends SubCommand { @Override public boolean execute(final PlotPlayer player, final String... args) { final Plot plot = MainUtil.getPlot(player.getLocation()); - if (args.length < 1) { + if (args.length == 0) { sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox [delete |clear|page]"); - for (CommentInbox inbox : CommentManager.inboxes.values()) { + for (final CommentInbox inbox : CommentManager.inboxes.values()) { if (inbox.canRead(plot, player)) { - sendMessage(player, C.INBOX_ITEM, inbox.toString()); + if (!inbox.getComments(plot, new RunnableVal() { + @Override + public void run() { + if (value != null) { + int count = 0; + for (PlotComment comment : (ArrayList) value) { + if (comment.timestamp > player.getPreviousLogin()) { + count++; + } + } + if (count > 0) { + sendMessage(player, C.INBOX_ITEM, "&c" + inbox.toString() + " (" + count + ")"); + return; + } + } + sendMessage(player, C.INBOX_ITEM, inbox.toString()); + } + })) { + sendMessage(player, C.INBOX_ITEM, inbox.toString()); + } } } return false; @@ -174,7 +188,12 @@ public class Inbox extends SubCommand { displayComments(player, comments, page); } })) { - sendMessage(player, C.NOT_IN_PLOT); + if (plot == null) { + sendMessage(player, C.NOT_IN_PLOT); + } + else { + sendMessage(player, C.PLOT_UNOWNED); + } return false; } return true; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Move.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Move.java index 6ea615e2d..20b322201 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Move.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Move.java @@ -21,6 +21,7 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.commands.SubCommand.CommandCategory; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java index 4f4153519..55d22898f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java @@ -33,6 +33,7 @@ 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.object.RunnableVal; import com.intellectualcrafters.plot.object.comment.PlotComment; /** @@ -327,7 +328,7 @@ public interface AbstractDB { * * @return Plot Comments within the specified tier */ - public ArrayList getComments(final String world, final Plot plot, final String inbox); + public void getComments(final String world, final Plot plot, final String inbox, RunnableVal whenDone); public void createPlotAndSettings(Plot plot); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java index 6f4106e40..c15e4be08 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java @@ -35,6 +35,7 @@ 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.object.RunnableVal; import com.intellectualcrafters.plot.object.comment.PlotComment; /** @@ -253,8 +254,8 @@ public class DBFunc { /** * @param plot */ - public static ArrayList getComments(final String world, final Plot plot, final String inbox) { - return dbManager.getComments(world, plot, inbox); + public static void getComments(final String world, final Plot plot, final String inbox, RunnableVal whenDone) { + dbManager.getComments(world, plot, inbox, whenDone); } /** diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index bc2571ff9..fe02c8da2 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -47,6 +47,7 @@ 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.object.RunnableVal; import com.intellectualcrafters.plot.object.comment.PlotComment; import com.intellectualcrafters.plot.util.ClusterManager; import com.intellectualcrafters.plot.util.TaskManager; @@ -104,6 +105,7 @@ public class SQLManager implements AbstractDB { } }, 11000); } + updateTables(); } /** @@ -462,13 +464,7 @@ public class SQLManager implements AbstractDB { stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot` (" + "`id` INT(11) NOT NULL AUTO_INCREMENT," + "`plot_id_x` INT(11) NOT NULL," + "`plot_id_z` INT(11) NOT NULL," + "`owner` VARCHAR(40) NOT NULL," + "`world` VARCHAR(45) NOT NULL," + "`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP," + "PRIMARY KEY (`id`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=0"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_denied` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_helpers` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); - stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_comments` (" + - "`plot_plot_id` INT(11) NOT NULL," + - "`comment` VARCHAR(40) NOT NULL," + - "`inbox` VARCHAR(40) NOT NULL," + - "`timestamp` INT(11) NOT NULL," + - "`sender` VARCHAR(40) NOT NULL" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); + stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_comments` (" + "`world` VARCHAR(40) NOT NULL, `hashcode` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`inbox` VARCHAR(40) NOT NULL," + "`timestamp` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_trusted` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); 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`)," + " UNIQUE KEY `unique_alias` (`alias`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); 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`)) ENGINE=InnoDB DEFAULT CHARSET=utf8"); @@ -484,7 +480,7 @@ public class SQLManager implements AbstractDB { 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_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," + "`inbox` VARCHAR(40) NOT NULL, `timestamp` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ")"); + stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_comments` (" + "`world` VARCHAR(40) NOT NULL, `hashcode` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`inbox` VARCHAR(40) NOT NULL, `timestamp` 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_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(40) NOT NULL," + "`world` VARCHAR(45) NOT NULL," + "`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP" + ")"); @@ -587,17 +583,24 @@ public class SQLManager implements AbstractDB { public void updateTables() { try { final DatabaseMetaData data = this.connection.getMetaData(); - ResultSet rs = data.getColumns(null, null, this.prefix + "plot_comments", "plot_id"); + ResultSet rs = data.getColumns(null, null, this.prefix + "plot_comments", "hashcode"); if (!rs.next()) { + rs.close(); final Statement statement = this.connection.createStatement(); - statement.addBatch("ALTER IGNORE TABLE `" + this.prefix + "plot_comments` ADD `inbox` VARCHAR(11) DEFAULT `public`"); - statement.addBatch("ALTER IGNORE TABLE `" + this.prefix + "plot_comments` ADD `timestamp` INT(11) DEFAULT 0"); - statement.addBatch("ALTER TABLE `" + this.prefix + "plot` DROP `tier`"); + statement.addBatch("DROP TABLE `" + this.prefix + "plot_comments`"); + if (PlotSquared.getMySQL() != null) { + statement.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_comments` (" + "`world` VARCHAR(40) NOT NULL, `hashcode` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`inbox` VARCHAR(40) NOT NULL," + "`timestamp` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); + } + else { + statement.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_comments` (" + "`world` VARCHAR(40) NOT NULL, `hashcode` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`inbox` VARCHAR(40) NOT NULL, `timestamp` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ")"); + } statement.executeBatch(); statement.close(); } } - catch (SQLException e) {} + catch (SQLException e) { + e.printStackTrace(); + } } /** @@ -1108,11 +1111,12 @@ public class SQLManager implements AbstractDB { try { PreparedStatement statement; if (plot != null) { - statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `plot_plot_id` = ? AND `comment` = ? AND `inbox` = ? AND `sender` = ?"); - statement.setInt(1, getId(world, plot.id)); - statement.setString(2, comment.comment); - statement.setString(3, comment.inbox); - statement.setString(4, comment.senderName); + statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `world` = ? AND `hashcode` = ? AND `comment` = ? AND `inbox` = ? AND `sender` = ?"); + statement.setString(1, plot.world); + statement.setInt(2, plot.id.hashCode()); + statement.setString(3, comment.comment); + statement.setString(4, comment.inbox); + statement.setString(5, comment.senderName); } else { statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `comment` = ? AND `inbox` = ? AND `sender` = ?"); statement.setString(1, comment.comment); @@ -1137,9 +1141,10 @@ public class SQLManager implements AbstractDB { try { PreparedStatement statement; if (plot != null) { - statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `plot_plot_id` = ? AND `inbox` = ?"); - statement.setInt(1, getId(plot.world, plot.id)); - statement.setString(2, inbox); + statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `world` = ? AND `hashcode` = ? AND `inbox` = ?"); + statement.setString(1, plot.world); + statement.setInt(2, plot.id.hashCode()); + statement.setString(3, inbox); } else { statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` `inbox` = ?"); statement.setString(1, inbox); @@ -1155,39 +1160,50 @@ public class SQLManager implements AbstractDB { } @Override - public ArrayList getComments(final String world, final Plot plot, final String inbox) { - final ArrayList comments = new ArrayList(); - try { - final PreparedStatement statement; - if (plot != null) { - statement = this.connection.prepareStatement("SELECT * FROM `" + this.prefix + "plot_comments` WHERE `plot_plot_id` = ? AND `inbox` = ?"); - statement.setInt(1, getId(plot.world, plot.id)); - statement.setString(2, inbox); - } else { - statement = this.connection.prepareStatement("SELECT * FROM `" + this.prefix + "plot_comments` WHERE `inbox` = ?"); - statement.setString(1, inbox); - } - final ResultSet set = statement.executeQuery(); - PlotComment comment; - while (set.next()) { - final String sender = set.getString("sender"); - final String msg = set.getString("comment"); - final int timestamp = set.getInt("timestamp"); - if (plot != null) { - comment = new PlotComment(plot.world, plot.id, msg, sender, inbox, timestamp); + public void getComments(final String world, final Plot plot, final String inbox, final RunnableVal whenDone) { + TaskManager.runTaskAsync(new Runnable() { + @Override + public void run() { + final ArrayList comments = new ArrayList(); + try { + final PreparedStatement statement; + if (plot != null) { + statement = connection.prepareStatement("SELECT * FROM `" + prefix + "plot_comments` WHERE `world` = ? AND `hashcode` = ? AND `inbox` = ?"); + statement.setString(1, plot.world); + statement.setInt(2, plot.id.hashCode()); + statement.setString(3, inbox); + } else { + statement = connection.prepareStatement("SELECT * FROM `" + prefix + "plot_comments` WHERE `inbox` = ?"); + statement.setString(1, inbox); + } + final ResultSet set = statement.executeQuery(); + PlotComment comment; + while (set.next()) { + final String sender = set.getString("sender"); + final String world = set.getString("world"); + final int hash = set.getInt("hashcode"); + PlotId id; + if (hash != 0) { + id = PlotId.unpair(hash); + } + else { + id = null; + } + final String msg = set.getString("comment"); + final long timestamp = set.getInt("timestamp") * 1000; + comment = new PlotComment(world, id, msg, sender, inbox, timestamp); + comments.add(comment); + whenDone.value = comments; + TaskManager.runTask(whenDone); + } + statement.close(); + set.close(); + } catch (final SQLException e) { + PlotSquared.log("&7[WARN] " + "Failed to fetch comment"); + e.printStackTrace(); } - else { - comment = new PlotComment(null, null, msg, sender, inbox, timestamp); - } - comments.add(comment); } - statement.close(); - set.close(); - } catch (final SQLException e) { - PlotSquared.log("&7[WARN] " + "Failed to fetch comment"); - e.printStackTrace(); - } - return comments; + }); } @Override @@ -1196,12 +1212,13 @@ public class SQLManager implements AbstractDB { @Override public void run() { try { - final PreparedStatement statement = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_comments` (`plot_plot_id`, `comment`, `inbox`, `timestamp`, `sender`) VALUES(?,?,?,?,?)"); - statement.setInt(1, getId(world, plot.id)); - statement.setString(2, comment.comment); - statement.setString(3, comment.inbox); - statement.setInt(4, (int) (comment.timestamp / 1000)); - statement.setString(5, comment.senderName); + final PreparedStatement statement = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_comments` (`world`, `hashcode`, `comment`, `inbox`, `timestamp`, `sender`) VALUES(?,?,?,?,?,?)"); + statement.setString(1, plot.world); + statement.setInt(2, plot.id.hashCode()); + statement.setString(3, comment.comment); + statement.setString(4, comment.inbox); + statement.setInt(5, (int) (comment.timestamp / 1000)); + statement.setString(6, comment.senderName); statement.executeUpdate(); statement.close(); } catch (final SQLException e) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/BukkitHybridUtils.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/BukkitHybridUtils.java index 307e6075b..95d58aafd 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/BukkitHybridUtils.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/BukkitHybridUtils.java @@ -1,6 +1,7 @@ package com.intellectualcrafters.plot.generator; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -20,10 +21,12 @@ import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; public class BukkitHybridUtils extends HybridUtils { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPop.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPop.java index 7637417e0..677d4b099 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPop.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPop.java @@ -2,6 +2,7 @@ package com.intellectualcrafters.plot.generator; import java.util.HashMap; import java.util.HashSet; +import java.util.Map.Entry; import org.bukkit.World; import org.bukkit.block.Biome; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java index dc7c85592..eb3f83359 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java @@ -17,6 +17,7 @@ public class BukkitPlayer implements PlotPlayer { public HashSet hasPerm = new HashSet<>(); public HashSet noPerm = new HashSet<>(); private int op = 0; + private long last = 0; /** * Please do not use this method. Instead use BukkitUtil.getPlayer(Player), as it caches player objects. @@ -25,6 +26,13 @@ public class BukkitPlayer implements PlotPlayer { public BukkitPlayer(final Player player) { this.player = player; } + + public long getPreviousLogin() { + if (last == 0) { + last = player.getLastPlayed(); + } + return last; + } @Override public Location getLocation() { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotId.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotId.java index ca8ef60d9..5ff26a5ba 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotId.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotId.java @@ -83,7 +83,7 @@ public class PlotId { return this.x + ";" + this.y; } - public PlotId unpair(int hash) { + public static PlotId unpair(int hash) { if (hash >= 0) { if (hash % 2 == 0) { // + + diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java index 7cb9597c6..cb75aa726 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java @@ -8,6 +8,9 @@ import java.util.UUID; * @author Citymonstret */ public interface PlotPlayer { + + public long getPreviousLogin(); + public Location getLocation(); public Location getLocationFull(); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotSettings.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotSettings.java index 4ad70fd4e..b908e7812 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotSettings.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotSettings.java @@ -21,6 +21,7 @@ package com.intellectualcrafters.plot.object; import java.util.ArrayList; +import java.util.List; import java.util.Set; import com.intellectualcrafters.plot.flag.Flag; @@ -52,7 +53,7 @@ public class PlotSettings { /** * Comments */ - private ArrayList comments = null; + private List comments = null; /** * Flags */ @@ -168,7 +169,7 @@ public class PlotSettings { return c; } - public void setComments(final ArrayList comments) { + public void setComments(final List comments) { this.comments = comments; } @@ -178,7 +179,7 @@ public class PlotSettings { } } - public void removeComments(final ArrayList comments) { + public void removeComments(final List comments) { for (final PlotComment comment : comments) { removeComment(comment); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/InboxOwner.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/InboxOwner.java index a3be6f3b9..af17285ad 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/InboxOwner.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/InboxOwner.java @@ -45,13 +45,17 @@ public class InboxOwner extends CommentInbox { if (comments != null) { whenDone.value = comments; TaskManager.runTask(whenDone); + return true; } - TaskManager.runTaskAsync(new Runnable() { + DBFunc.getComments(plot.world, plot, toString(), new RunnableVal() { @Override public void run() { - ArrayList comments = DBFunc.getComments(plot.world, plot, toString()); - whenDone.value = comments; - plot.settings.setComments(comments); + whenDone.value = value; + if (value != null) { + for (PlotComment comment : (ArrayList) value) { + plot.settings.addComment(comment); + } + } TaskManager.runTask(whenDone); } }); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/InboxPublic.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/InboxPublic.java index beaba1b1e..d2668271e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/InboxPublic.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/InboxPublic.java @@ -45,11 +45,17 @@ public class InboxPublic extends CommentInbox { if (comments != null) { whenDone.value = comments; TaskManager.runTask(whenDone); + return true; } - TaskManager.runTaskAsync(new Runnable() { + DBFunc.getComments(plot.world, plot, toString(), new RunnableVal() { @Override public void run() { - whenDone.value = DBFunc.getComments(plot.world, plot, toString()); + whenDone.value = value; + if (value != null) { + for (PlotComment comment : (ArrayList) value) { + plot.settings.addComment(comment); + } + } TaskManager.runTask(whenDone); } }); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/InboxReport.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/InboxReport.java index a7cb7083e..f2af870b7 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/InboxReport.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/comment/InboxReport.java @@ -1,5 +1,7 @@ package com.intellectualcrafters.plot.object.comment; +import java.util.ArrayList; + import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotHandler; @@ -36,10 +38,10 @@ public class InboxReport extends CommentInbox { @Override public boolean getComments(final Plot plot, final RunnableVal whenDone) { - TaskManager.runTaskAsync(new Runnable() { + DBFunc.getComments(null, null, toString(), new RunnableVal() { @Override public void run() { - whenDone.value = DBFunc.getComments(null, null, toString()); + whenDone.value = value; TaskManager.runTask(whenDone); } }); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitSetupUtils.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitSetupUtils.java index 727593950..2e2f04ae1 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitSetupUtils.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitSetupUtils.java @@ -1,17 +1,20 @@ package com.intellectualcrafters.plot.util.bukkit; import java.io.IOException; +import java.util.List; import java.util.Map.Entry; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.World.Environment; import org.bukkit.WorldCreator; +import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.ChunkGenerator; import org.bukkit.plugin.Plugin; import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.ConfigurationNode; +import com.intellectualcrafters.plot.generator.SquarePlotManager; import com.intellectualcrafters.plot.object.PlotGenerator; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.SetupObject;