fixes for comment system

This commit is contained in:
boy0001 2015-04-06 22:16:24 +10:00
parent b9c36965d8
commit 53b8f8a0d0
16 changed files with 157 additions and 84 deletions

View File

@ -21,10 +21,12 @@
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId; 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.CommentManager;
import com.intellectualcrafters.plot.object.comment.PlotComment; import com.intellectualcrafters.plot.object.comment.PlotComment;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
public class Comment extends SubCommand { public class Comment extends SubCommand {
public Comment() { public Comment() {

View File

@ -21,15 +21,11 @@
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.UUID;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import com.intellectualcrafters.plot.config.C; 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.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal; 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.CommentManager;
import com.intellectualcrafters.plot.object.comment.PlotComment; import com.intellectualcrafters.plot.object.comment.PlotComment;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager;
public class Inbox extends SubCommand { public class Inbox extends SubCommand {
public Inbox() { public Inbox() {
@ -62,7 +56,7 @@ public class Inbox extends SubCommand {
max = comments.length; max = comments.length;
} }
final StringBuilder string = new StringBuilder(); 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; PlotComment c;
// This might work xD // This might work xD
for (int x = (page * 12); x < max; x++) { for (int x = (page * 12); x < max; x++) {
@ -74,6 +68,7 @@ public class Inbox extends SubCommand {
else { else {
color = "&7"; 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"); 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()); MainUtil.sendMessage(player, string.toString());
@ -82,11 +77,30 @@ public class Inbox extends SubCommand {
@Override @Override
public boolean execute(final PlotPlayer player, final String... args) { public boolean execute(final PlotPlayer player, final String... args) {
final Plot plot = MainUtil.getPlot(player.getLocation()); final Plot plot = MainUtil.getPlot(player.getLocation());
if (args.length < 1) { if (args.length == 0) {
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox <inbox> [delete <index>|clear|page]"); sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox <inbox> [delete <index>|clear|page]");
for (CommentInbox inbox : CommentManager.inboxes.values()) { for (final CommentInbox inbox : CommentManager.inboxes.values()) {
if (inbox.canRead(plot, player)) { 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<PlotComment>) 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; return false;
@ -174,7 +188,12 @@ public class Inbox extends SubCommand {
displayComments(player, comments, page); 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 false;
} }
return true; return true;

View File

@ -21,6 +21,7 @@
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.commands.SubCommand.CommandCategory;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;

View File

@ -33,6 +33,7 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotClusterId; import com.intellectualcrafters.plot.object.PlotClusterId;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.comment.PlotComment; import com.intellectualcrafters.plot.object.comment.PlotComment;
/** /**
@ -327,7 +328,7 @@ public interface AbstractDB {
* *
* @return Plot Comments within the specified tier * @return Plot Comments within the specified tier
*/ */
public ArrayList<PlotComment> 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); public void createPlotAndSettings(Plot plot);

View File

@ -35,6 +35,7 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotClusterId; import com.intellectualcrafters.plot.object.PlotClusterId;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.comment.PlotComment; import com.intellectualcrafters.plot.object.comment.PlotComment;
/** /**
@ -253,8 +254,8 @@ public class DBFunc {
/** /**
* @param plot * @param plot
*/ */
public static ArrayList<PlotComment> getComments(final String world, final Plot plot, final String inbox) { public static void getComments(final String world, final Plot plot, final String inbox, RunnableVal whenDone) {
return dbManager.getComments(world, plot, inbox); dbManager.getComments(world, plot, inbox, whenDone);
} }
/** /**

View File

@ -47,6 +47,7 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotClusterId; import com.intellectualcrafters.plot.object.PlotClusterId;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.comment.PlotComment; import com.intellectualcrafters.plot.object.comment.PlotComment;
import com.intellectualcrafters.plot.util.ClusterManager; import com.intellectualcrafters.plot.util.ClusterManager;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
@ -104,6 +105,7 @@ public class SQLManager implements AbstractDB {
} }
}, 11000); }, 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` (" + "`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_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_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` (" + 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");
"`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_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_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_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"); 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_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," + "`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_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(40) NOT NULL," + "`world` VARCHAR(45) NOT NULL," + "`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP" + ")"); 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() { public void updateTables() {
try { try {
final DatabaseMetaData data = this.connection.getMetaData(); 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()) { if (!rs.next()) {
rs.close();
final Statement statement = this.connection.createStatement(); final Statement statement = this.connection.createStatement();
statement.addBatch("ALTER IGNORE TABLE `" + this.prefix + "plot_comments` ADD `inbox` VARCHAR(11) DEFAULT `public`"); statement.addBatch("DROP TABLE `" + this.prefix + "plot_comments`");
statement.addBatch("ALTER IGNORE TABLE `" + this.prefix + "plot_comments` ADD `timestamp` INT(11) DEFAULT 0"); if (PlotSquared.getMySQL() != null) {
statement.addBatch("ALTER TABLE `" + this.prefix + "plot` DROP `tier`"); 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.executeBatch();
statement.close(); statement.close();
} }
} }
catch (SQLException e) {} catch (SQLException e) {
e.printStackTrace();
}
} }
/** /**
@ -1108,11 +1111,12 @@ public class SQLManager implements AbstractDB {
try { try {
PreparedStatement statement; PreparedStatement statement;
if (plot != null) { 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 = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `world` = ? AND `hashcode` = ? AND `comment` = ? AND `inbox` = ? AND `sender` = ?");
statement.setInt(1, getId(world, plot.id)); statement.setString(1, plot.world);
statement.setString(2, comment.comment); statement.setInt(2, plot.id.hashCode());
statement.setString(3, comment.inbox); statement.setString(3, comment.comment);
statement.setString(4, comment.senderName); statement.setString(4, comment.inbox);
statement.setString(5, comment.senderName);
} else { } else {
statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `comment` = ? AND `inbox` = ? AND `sender` = ?"); statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `comment` = ? AND `inbox` = ? AND `sender` = ?");
statement.setString(1, comment.comment); statement.setString(1, comment.comment);
@ -1137,9 +1141,10 @@ public class SQLManager implements AbstractDB {
try { try {
PreparedStatement statement; PreparedStatement statement;
if (plot != null) { if (plot != null) {
statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `plot_plot_id` = ? AND `inbox` = ?"); statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `world` = ? AND `hashcode` = ? AND `inbox` = ?");
statement.setInt(1, getId(plot.world, plot.id)); statement.setString(1, plot.world);
statement.setString(2, inbox); statement.setInt(2, plot.id.hashCode());
statement.setString(3, inbox);
} else { } else {
statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` `inbox` = ?"); statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` `inbox` = ?");
statement.setString(1, inbox); statement.setString(1, inbox);
@ -1155,39 +1160,50 @@ public class SQLManager implements AbstractDB {
} }
@Override @Override
public ArrayList<PlotComment> getComments(final String world, final Plot plot, final String inbox) { public void getComments(final String world, final Plot plot, final String inbox, final RunnableVal whenDone) {
final ArrayList<PlotComment> comments = new ArrayList<PlotComment>(); TaskManager.runTaskAsync(new Runnable() {
try { @Override
final PreparedStatement statement; public void run() {
if (plot != null) { final ArrayList<PlotComment> comments = new ArrayList<PlotComment>();
statement = this.connection.prepareStatement("SELECT * FROM `" + this.prefix + "plot_comments` WHERE `plot_plot_id` = ? AND `inbox` = ?"); try {
statement.setInt(1, getId(plot.world, plot.id)); final PreparedStatement statement;
statement.setString(2, inbox); if (plot != null) {
} else { statement = connection.prepareStatement("SELECT * FROM `" + prefix + "plot_comments` WHERE `world` = ? AND `hashcode` = ? AND `inbox` = ?");
statement = this.connection.prepareStatement("SELECT * FROM `" + this.prefix + "plot_comments` WHERE `inbox` = ?"); statement.setString(1, plot.world);
statement.setString(1, inbox); statement.setInt(2, plot.id.hashCode());
} statement.setString(3, inbox);
final ResultSet set = statement.executeQuery(); } else {
PlotComment comment; statement = connection.prepareStatement("SELECT * FROM `" + prefix + "plot_comments` WHERE `inbox` = ?");
while (set.next()) { statement.setString(1, inbox);
final String sender = set.getString("sender"); }
final String msg = set.getString("comment"); final ResultSet set = statement.executeQuery();
final int timestamp = set.getInt("timestamp"); PlotComment comment;
if (plot != null) { while (set.next()) {
comment = new PlotComment(plot.world, plot.id, msg, sender, inbox, timestamp); 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 @Override
@ -1196,12 +1212,13 @@ public class SQLManager implements AbstractDB {
@Override @Override
public void run() { public void run() {
try { try {
final PreparedStatement statement = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_comments` (`plot_plot_id`, `comment`, `inbox`, `timestamp`, `sender`) VALUES(?,?,?,?,?)"); final PreparedStatement statement = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_comments` (`world`, `hashcode`, `comment`, `inbox`, `timestamp`, `sender`) VALUES(?,?,?,?,?,?)");
statement.setInt(1, getId(world, plot.id)); statement.setString(1, plot.world);
statement.setString(2, comment.comment); statement.setInt(2, plot.id.hashCode());
statement.setString(3, comment.inbox); statement.setString(3, comment.comment);
statement.setInt(4, (int) (comment.timestamp / 1000)); statement.setString(4, comment.inbox);
statement.setString(5, comment.senderName); statement.setInt(5, (int) (comment.timestamp / 1000));
statement.setString(6, comment.senderName);
statement.executeUpdate(); statement.executeUpdate();
statement.close(); statement.close();
} catch (final SQLException e) { } catch (final SQLException e) {

View File

@ -1,6 +1,7 @@
package com.intellectualcrafters.plot.generator; package com.intellectualcrafters.plot.generator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; 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.Plot;
import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
public class BukkitHybridUtils extends HybridUtils { public class BukkitHybridUtils extends HybridUtils {

View File

@ -2,6 +2,7 @@ package com.intellectualcrafters.plot.generator;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map.Entry;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;

View File

@ -17,6 +17,7 @@ public class BukkitPlayer implements PlotPlayer {
public HashSet<String> hasPerm = new HashSet<>(); public HashSet<String> hasPerm = new HashSet<>();
public HashSet<String> noPerm = new HashSet<>(); public HashSet<String> noPerm = new HashSet<>();
private int op = 0; private int op = 0;
private long last = 0;
/** /**
* Please do not use this method. Instead use BukkitUtil.getPlayer(Player), as it caches player objects. * 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) { public BukkitPlayer(final Player player) {
this.player = player; this.player = player;
} }
public long getPreviousLogin() {
if (last == 0) {
last = player.getLastPlayed();
}
return last;
}
@Override @Override
public Location getLocation() { public Location getLocation() {

View File

@ -83,7 +83,7 @@ public class PlotId {
return this.x + ";" + this.y; return this.x + ";" + this.y;
} }
public PlotId unpair(int hash) { public static PlotId unpair(int hash) {
if (hash >= 0) { if (hash >= 0) {
if (hash % 2 == 0) { if (hash % 2 == 0) {
// + + // + +

View File

@ -8,6 +8,9 @@ import java.util.UUID;
* @author Citymonstret * @author Citymonstret
*/ */
public interface PlotPlayer { public interface PlotPlayer {
public long getPreviousLogin();
public Location getLocation(); public Location getLocation();
public Location getLocationFull(); public Location getLocationFull();

View File

@ -21,6 +21,7 @@
package com.intellectualcrafters.plot.object; package com.intellectualcrafters.plot.object;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Set; import java.util.Set;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
@ -52,7 +53,7 @@ public class PlotSettings {
/** /**
* Comments * Comments
*/ */
private ArrayList<PlotComment> comments = null; private List<PlotComment> comments = null;
/** /**
* Flags * Flags
*/ */
@ -168,7 +169,7 @@ public class PlotSettings {
return c; return c;
} }
public void setComments(final ArrayList<PlotComment> comments) { public void setComments(final List<PlotComment> comments) {
this.comments = comments; this.comments = comments;
} }
@ -178,7 +179,7 @@ public class PlotSettings {
} }
} }
public void removeComments(final ArrayList<PlotComment> comments) { public void removeComments(final List<PlotComment> comments) {
for (final PlotComment comment : comments) { for (final PlotComment comment : comments) {
removeComment(comment); removeComment(comment);
} }

View File

@ -45,13 +45,17 @@ public class InboxOwner extends CommentInbox {
if (comments != null) { if (comments != null) {
whenDone.value = comments; whenDone.value = comments;
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
return true;
} }
TaskManager.runTaskAsync(new Runnable() { DBFunc.getComments(plot.world, plot, toString(), new RunnableVal() {
@Override @Override
public void run() { public void run() {
ArrayList<PlotComment> comments = DBFunc.getComments(plot.world, plot, toString()); whenDone.value = value;
whenDone.value = comments; if (value != null) {
plot.settings.setComments(comments); for (PlotComment comment : (ArrayList<PlotComment>) value) {
plot.settings.addComment(comment);
}
}
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
} }
}); });

View File

@ -45,11 +45,17 @@ public class InboxPublic extends CommentInbox {
if (comments != null) { if (comments != null) {
whenDone.value = comments; whenDone.value = comments;
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
return true;
} }
TaskManager.runTaskAsync(new Runnable() { DBFunc.getComments(plot.world, plot, toString(), new RunnableVal() {
@Override @Override
public void run() { public void run() {
whenDone.value = DBFunc.getComments(plot.world, plot, toString()); whenDone.value = value;
if (value != null) {
for (PlotComment comment : (ArrayList<PlotComment>) value) {
plot.settings.addComment(comment);
}
}
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
} }
}); });

View File

@ -1,5 +1,7 @@
package com.intellectualcrafters.plot.object.comment; package com.intellectualcrafters.plot.object.comment;
import java.util.ArrayList;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotHandler; import com.intellectualcrafters.plot.object.PlotHandler;
@ -36,10 +38,10 @@ public class InboxReport extends CommentInbox {
@Override @Override
public boolean getComments(final Plot plot, final RunnableVal whenDone) { public boolean getComments(final Plot plot, final RunnableVal whenDone) {
TaskManager.runTaskAsync(new Runnable() { DBFunc.getComments(null, null, toString(), new RunnableVal() {
@Override @Override
public void run() { public void run() {
whenDone.value = DBFunc.getComments(null, null, toString()); whenDone.value = value;
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
} }
}); });

View File

@ -1,17 +1,20 @@
package com.intellectualcrafters.plot.util.bukkit; package com.intellectualcrafters.plot.util.bukkit;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
import org.bukkit.WorldCreator; import org.bukkit.WorldCreator;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.ConfigurationNode; import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.generator.SquarePlotManager;
import com.intellectualcrafters.plot.object.PlotGenerator; import com.intellectualcrafters.plot.object.PlotGenerator;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.SetupObject; import com.intellectualcrafters.plot.object.SetupObject;