mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 21:26:45 +01:00
fixes for comment system
This commit is contained in:
parent
b9c36965d8
commit
53b8f8a0d0
@ -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() {
|
||||
|
@ -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 <inbox> [delete <index>|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<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;
|
||||
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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<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);
|
||||
|
||||
|
@ -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<PlotComment> 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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<PlotComment> getComments(final String world, final Plot plot, final String inbox) {
|
||||
final ArrayList<PlotComment> comments = new ArrayList<PlotComment>();
|
||||
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<PlotComment> comments = new ArrayList<PlotComment>();
|
||||
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) {
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
@ -17,6 +17,7 @@ public class BukkitPlayer implements PlotPlayer {
|
||||
public HashSet<String> hasPerm = new HashSet<>();
|
||||
public HashSet<String> 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.
|
||||
@ -26,6 +27,13 @@ public class BukkitPlayer implements PlotPlayer {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public long getPreviousLogin() {
|
||||
if (last == 0) {
|
||||
last = player.getLastPlayed();
|
||||
}
|
||||
return last;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return BukkitUtil.getLocation(this.player);
|
||||
|
@ -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) {
|
||||
// + +
|
||||
|
@ -8,6 +8,9 @@ import java.util.UUID;
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public interface PlotPlayer {
|
||||
|
||||
public long getPreviousLogin();
|
||||
|
||||
public Location getLocation();
|
||||
|
||||
public Location getLocationFull();
|
||||
|
@ -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<PlotComment> comments = null;
|
||||
private List<PlotComment> comments = null;
|
||||
/**
|
||||
* Flags
|
||||
*/
|
||||
@ -168,7 +169,7 @@ public class PlotSettings {
|
||||
return c;
|
||||
}
|
||||
|
||||
public void setComments(final ArrayList<PlotComment> comments) {
|
||||
public void setComments(final List<PlotComment> 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) {
|
||||
removeComment(comment);
|
||||
}
|
||||
|
@ -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<PlotComment> comments = DBFunc.getComments(plot.world, plot, toString());
|
||||
whenDone.value = comments;
|
||||
plot.settings.setComments(comments);
|
||||
whenDone.value = value;
|
||||
if (value != null) {
|
||||
for (PlotComment comment : (ArrayList<PlotComment>) value) {
|
||||
plot.settings.addComment(comment);
|
||||
}
|
||||
}
|
||||
TaskManager.runTask(whenDone);
|
||||
}
|
||||
});
|
||||
|
@ -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<PlotComment>) value) {
|
||||
plot.settings.addComment(comment);
|
||||
}
|
||||
}
|
||||
TaskManager.runTask(whenDone);
|
||||
}
|
||||
});
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user