New comment system

This commit is contained in:
boy0001 2015-04-06 19:59:22 +10:00
parent ade657b1af
commit b9c36965d8
21 changed files with 553 additions and 280 deletions

View File

@ -57,6 +57,7 @@ import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.comment.CommentManager;
import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.ClusterManager; import com.intellectualcrafters.plot.util.ClusterManager;
@ -507,6 +508,7 @@ public class PlotSquared {
setupConfigs(); setupConfigs();
setupDefaultFlags(); setupDefaultFlags();
setupDatabase(); setupDatabase();
CommentManager.registerDefaultInboxes();
// Tasks // Tasks
if (Settings.KILL_ROAD_MOBS) { if (Settings.KILL_ROAD_MOBS) {
IMP.runEntityTask(); IMP.runEntityTask();

View File

@ -21,18 +21,18 @@
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.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
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.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() {
@ -40,27 +40,45 @@ public class Comment extends SubCommand {
} }
@Override @Override
public boolean execute(final PlotPlayer plr, final String... args) { public boolean execute(final PlotPlayer player, final String... args) {
final Location loc = plr.getLocation(); if (args.length < 2) {
final Plot plot = MainUtil.getPlot(loc); sendMessage(player, C.COMMENT_SYNTAX, StringUtils.join(CommentManager.inboxes.keySet(),"|"));
if (plot == null) { return false;
return sendMessage(plr, C.NOT_IN_PLOT);
} }
if (!plot.hasOwner()) { CommentInbox inbox = CommentManager.inboxes.get(args[0].toLowerCase());
return sendMessage(plr, C.NOT_IN_PLOT); if (inbox == null) {
sendMessage(player, C.COMMENT_SYNTAX, StringUtils.join(CommentManager.inboxes.keySet(),"|"));
return false;
} }
final List<String> recipients = Arrays.asList("admin", "owner", "helper", "trusted", "everyone"); Plot plot;
if ((args.length > 1) && recipients.contains(args[0].toLowerCase())) { Location loc = player.getLocation();
if (Permissions.hasPermission(plr, "plots.comment." + args[0].toLowerCase())) { PlotId id = PlotId.fromString(args[1]);
final String text = StringUtils.join(Arrays.copyOfRange(args, 1, args.length), " "); int index;
final PlotComment comment = new PlotComment(plot.id, text, plr.getName(), recipients.indexOf(args[0].toLowerCase())); if (id != null) {
plot.settings.addComment(comment); if (args.length < 4) {
DBFunc.setComment(loc.getWorld(), plot, comment); sendMessage(player, C.COMMENT_SYNTAX, StringUtils.join(CommentManager.inboxes.keySet(),"|"));
return sendMessage(plr, C.COMMENT_ADDED); return false;
} else {
return sendMessage(plr, C.NO_PERMISSION, "plots.comment." + args[0].toLowerCase());
} }
index = 2;
plot = MainUtil.getPlot(loc.getWorld(), id);
} }
return sendMessage(plr, C.COMMENT_SYNTAX); else {
index = 1;
plot = MainUtil.getPlot(loc);
}
if (!inbox.canWrite(plot, player)) {
sendMessage(player, C.NO_PERM_INBOX, "");
return false;
}
String message = StringUtils.join(Arrays.copyOfRange(args,index, args.length), " ");
PlotComment comment = new PlotComment(loc.getWorld(), id, message, player.getName(), inbox.toString(), System.currentTimeMillis());
boolean result = inbox.addComment(plot, comment);
if (!result) {
sendMessage(player, C.NO_PLOT_INBOX, "");
sendMessage(player, C.COMMENT_SYNTAX, StringUtils.join(CommentManager.inboxes.keySet(),"|"));
return false;
}
sendMessage(player, C.COMMENT_ADDED);
return true;
} }
} }

View File

@ -25,11 +25,16 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
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.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.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
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.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.Permissions;
@ -37,152 +42,141 @@ import com.intellectualcrafters.plot.util.TaskManager;
public class Inbox extends SubCommand { public class Inbox extends SubCommand {
public Inbox() { public Inbox() {
super(Command.INBOX, "Review the comments for a plot", "inbox", CommandCategory.ACTIONS, true); super(Command.INBOX, "Review the comments for a plot", "inbox <inbox> [delete <index>|clear|page]", CommandCategory.ACTIONS, true);
}
public void displayComments(PlotPlayer player, List<PlotComment> oldComments, int page) {
PlotComment[] comments = oldComments.toArray(new PlotComment[oldComments.size()]);
if (page < 0) {
page = 0;
}
// Get the total pages
// int totalPages = ((int) Math.ceil(12 *
final int totalPages = (int) Math.ceil(comments.length / 12);
if (page > totalPages) {
page = totalPages;
}
// Only display 12 per page
int max = (page * 12) + 12;
if (max > comments.length) {
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");
PlotComment c;
// This might work xD
for (int x = (page * 12); x < max; x++) {
c = comments[x];
String color;
if (player.getName().equals(c.senderName)) {
color = "&a";
}
else {
color = "&7";
}
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());
} }
@Override @Override
public boolean execute(final PlotPlayer plr, final String... args) { public boolean execute(final PlotPlayer player, final String... args) {
boolean report = false; final Plot plot = MainUtil.getPlot(player.getLocation());
if (args.length == 1) { if (args.length < 1) {
if (args[0].equalsIgnoreCase("reports")) { sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox <inbox> [delete <index>|clear|page]");
report = true; for (CommentInbox inbox : CommentManager.inboxes.values()) {
if (inbox.canRead(plot, player)) {
sendMessage(player, C.INBOX_ITEM, inbox.toString());
}
} }
}
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if ((plot == null) && !report) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if ((plot != null) && !plot.hasOwner()) {
MainUtil.sendMessage(plr, C.NOT_IN_PLOT);
return false; return false;
} }
Integer tier; final CommentInbox inbox = CommentManager.inboxes.get(args[0].toLowerCase());
final UUID uuid = plr.getUUID(); if (inbox == null) {
if (Permissions.hasPermission(plr, "plots.comment.admin")) { sendMessage(player, C.INVALID_INBOX, StringUtils.join(CommentManager.inboxes.keySet(),", "));
tier = 0; return false;
} else if ((plot != null) && plot.isOwner(uuid)) {
tier = 1;
} else if ((plot != null) && plot.helpers.contains(uuid)) {
tier = 2;
} else if ((plot != null) && plot.trusted.contains(uuid)) {
tier = 3;
} else {
tier = 4;
} }
final boolean below; final int page;
if (args.length > 0) { if (args.length > 1) {
below = false; switch (args[1].toLowerCase()) {
switch (args[0].toLowerCase()) { case "delete": {
case "admin": if (!inbox.canModify(plot, player)) {
if (tier <= 0) { sendMessage(player, C.NO_PERM_INBOX_MODIFY);
tier = 0;
} else {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.admin");
return false;
} }
break; if (args.length != 3) {
case "owner": sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox " + inbox.toString() + " delete <index>");
if (tier <= 1) {
tier = 1;
} else {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.owner");
return false;
} }
break; final int index;
case "helper": try {
if (tier <= 2) { index = Integer.parseInt(args[2]);
tier = 2; if (index < 1) {
} else { sendMessage(player, C.NOT_VALID_INBOX_INDEX, index + "");
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.helper"); return false;
return false;
}
break;
case "trusted":
if (tier <= 3) {
tier = 3;
} else {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.trusted");
return false;
}
break;
case "everyone":
if (tier <= 4) {
tier = 4;
} else {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.everyone");
return false;
}
break;
case "reports":
if (tier <= 0) {
tier = -1;
} else {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.admin");
return false;
}
break;
default:
MainUtil.sendMessage(plr, C.INVALID_INBOX, Arrays.copyOfRange(new String[] { "admin", "owner", "helper", "trusted", "everyone" }, Math.max(0, tier), 4));
return false;
}
} else {
below = true;
}
final String world = loc.getWorld();
final int tier2 = tier;
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
ArrayList<PlotComment> comments = null;
if (tier2 == -1) {
comments = DBFunc.getComments(world, null, 0, false);
} else {
comments = plot.settings.getComments(tier2);
}
if (comments == null) {
comments = DBFunc.getComments(world, plot, tier2, below);
plot.settings.setComments(comments);
}
if (args.length == 2) {
final String[] split = args[1].toLowerCase().split(":");
if (!split[0].equals("clear")) {
MainUtil.sendMessage(plr, "&c/plot inbox [tier] [clear][:#]");
return;
}
if (split.length > 1) {
try {
final int index = Integer.parseInt(split[1]);
final PlotComment comment = comments.get(index - 1);
DBFunc.removeComment(world, plot, comment);
plot.settings.removeComment(comment);
MainUtil.sendMessage(plr, C.COMMENT_REMOVED, "1 comment");
return;
} catch (final Exception e) {
MainUtil.sendMessage(plr, "&cInvalid index:\n/plot inbox [tier] [clear][:#]");
return;
} }
} }
for (final PlotComment comment : comments) { catch (NumberFormatException e) {
DBFunc.removeComment(world, plot, comment); sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox " + inbox.toString() + " delete <index>");
return false;
} }
plot.settings.removeComments(comments);
MainUtil.sendMessage(plr, C.COMMENT_REMOVED, "all comments in that category"); if (!inbox.getComments(plot, new RunnableVal() {
} else { @Override
final List<String> recipients = Arrays.asList("A", "O", "H", "T", "E"); public void run() {
int count = 1; List<PlotComment> comments = (List<PlotComment>) value;
final StringBuilder message = new StringBuilder(C.COMMENT_HEADER.s()); if (index > comments.size()) {
for (final PlotComment comment : comments) { sendMessage(player, C.NOT_VALID_INBOX_INDEX, index + "");
message.append("\n&8[&7" + comment.id + "&8]" + "&c[" + count + "]&6[" + recipients.get(tier2 == -1 ? 0 : tier2) + "] &7" + comment.senderName + "&f: " + comment.comment); }
count++; PlotComment comment = comments.get(index - 1);
inbox.removeComment(plot, comment);
plot.settings.removeComment(comment);
MainUtil.sendMessage(player, C.COMMENT_REMOVED, comment.comment);
}
})) {
sendMessage(player, C.NOT_IN_PLOT);
return false;
} }
if (comments.size() == 0) { return true;
message.append("&cNo messages."); }
case "clear": {
if (!inbox.canModify(plot, player)) {
sendMessage(player, C.NO_PERM_INBOX_MODIFY);
} }
MainUtil.sendMessage(plr, message.toString()); inbox.clearInbox(plot);
ArrayList<PlotComment> comments = plot.settings.getComments(inbox.toString());
if (comments != null) {
plot.settings.removeComments(comments);
}
MainUtil.sendMessage(player, C.COMMENT_REMOVED, "*");
return true;
}
default: {
try {
page = Integer.parseInt(args[1]) ;
}
catch (NumberFormatException e) {
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox <inbox> [delete <index>|clear|page]");
return false;
};
} }
} }
}); }
else {
page = 1;
}
if (!inbox.canRead(plot, player)) {
sendMessage(player, C.NO_PERM_INBOX);
return false;
}
if (!inbox.getComments(plot, new RunnableVal() {
@Override
public void run() {
List<PlotComment> comments = (List<PlotComment>) value;
displayComments(player, comments, page);
}
})) {
sendMessage(player, C.NOT_IN_PLOT);
return false;
}
return true; return true;
} }
} }

View File

@ -21,7 +21,6 @@
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

@ -103,9 +103,14 @@ public enum C {
/* /*
* Comment * Comment
*/ */
COMMENT_SYNTAX("$2Use /plots comment <everyone|trusted|helper|owner|admin> <comment>"), NOT_VALID_INBOX_INDEX("$2No comment at index %s"),
INBOX_ITEM("$2 - $4%s"),
COMMENT_SYNTAX("$2Use /plots comment [X;Z] <%s> <comment>"),
INVALID_INBOX("$2That is not a valid inbox.\n$1Accepted values: %s"), INVALID_INBOX("$2That is not a valid inbox.\n$1Accepted values: %s"),
COMMENT_REMOVED("$4Successfully deleted %s."), NO_PERM_INBOX("$2You do not have permission for that inbox"),
NO_PERM_INBOX_MODIFY("$2You do not have permission to modify that inbox"),
NO_PLOT_INBOX("$2You must stand in or supply a plot argument"),
COMMENT_REMOVED("$4Successfully deleted comment/s:n$2 - '$3%s$2'"),
COMMENT_ADDED("$4A comment has been left"), COMMENT_ADDED("$4A comment has been left"),
COMMENT_HEADER("$2====== Comments ======"), COMMENT_HEADER("$2====== Comments ======"),
/* /*

View File

@ -301,6 +301,13 @@ public interface AbstractDB {
* @param comment Comment to remove * @param comment Comment to remove
*/ */
public void removeComment(final String world, final Plot plot, final PlotComment comment); public void removeComment(final String world, final Plot plot, final PlotComment comment);
/**
* Clear an inbox
* @param plot
* @param inbox
*/
public void clearInbox(Plot plot, String inbox);
/** /**
* Set a plot comment * Set a plot comment
@ -320,7 +327,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 int tier, boolean below); public ArrayList<PlotComment> getComments(final String world, final Plot plot, final String inbox);
public void createPlotAndSettings(Plot plot); public void createPlotAndSettings(Plot plot);

View File

@ -237,6 +237,10 @@ public class DBFunc {
public static void removeComment(final String world, final Plot plot, final PlotComment comment) { public static void removeComment(final String world, final Plot plot, final PlotComment comment) {
dbManager.removeComment(world, plot, comment); dbManager.removeComment(world, plot, comment);
} }
public static void clearInbox(final Plot plot, final String inbox) {
dbManager.clearInbox(plot, inbox);
}
/** /**
* @param plot * @param plot
@ -249,8 +253,8 @@ public class DBFunc {
/** /**
* @param plot * @param plot
*/ */
public static ArrayList<PlotComment> getComments(final String world, final Plot plot, final int tier, final boolean below) { public static ArrayList<PlotComment> getComments(final String world, final Plot plot, final String inbox) {
return dbManager.getComments(world, plot, tier, below); return dbManager.getComments(world, plot, inbox);
} }
/** /**

View File

@ -28,13 +28,11 @@ import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@ -137,9 +135,6 @@ public class SQLManager implements AbstractDB {
@Override @Override
public void createAllSettingsAndHelpers(final ArrayList<Plot> mylist) { public void createAllSettingsAndHelpers(final ArrayList<Plot> mylist) {
// TODO create settings
final int size = mylist.size(); final int size = mylist.size();
int packet; int packet;
if (PlotSquared.getMySQL() != null) { if (PlotSquared.getMySQL() != null) {
@ -270,29 +265,6 @@ public class SQLManager implements AbstractDB {
stmt.close(); stmt.close();
} catch (final Exception e) { } catch (final Exception e) {
try { try {
/*
* (" + " `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")
*
* plot_plot_id - nn
* biome - FOREST
* rain - 0
* custom_time 0
* time
*/
StringBuilder unionstmt = new StringBuilder("INSERT INTO `" + this.prefix + "plot_settings` SELECT ? AS `plot_plot_id`, ? AS `biome`, ? AS `rain`, ? AS `custom_time`, ? AS `time`, ? AS `deny_entry`, ? AS `alias`, ? AS `flags`, ? AS `merged`, ? AS `position` "); StringBuilder unionstmt = new StringBuilder("INSERT INTO `" + this.prefix + "plot_settings` SELECT ? AS `plot_plot_id`, ? AS `biome`, ? AS `rain`, ? AS `custom_time`, ? AS `time`, ? AS `deny_entry`, ? AS `alias`, ? AS `flags`, ? AS `merged`, ? AS `position` ");
for (int i = 0; i < (ids.size() - 2); i++) { for (int i = 0; i < (ids.size() - 2); i++) {
unionstmt.append("UNION SELECT ?, ?, ?, ?, ?, ?, ?, ?, ?, ? "); unionstmt.append("UNION SELECT ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ");
@ -490,7 +462,13 @@ 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` (" + "`plot_plot_id` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`tier` 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` (" +
"`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");
@ -506,7 +484,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," + "`tier` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" + ")"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_comments` (" + "`plot_plot_id` INT(11) NOT NULL," + "`comment` VARCHAR(40) NOT NULL," + "`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" + ")");
@ -605,6 +583,22 @@ public class SQLManager implements AbstractDB {
} }
return Integer.MAX_VALUE; return Integer.MAX_VALUE;
} }
public void updateTables() {
try {
final DatabaseMetaData data = this.connection.getMetaData();
ResultSet rs = data.getColumns(null, null, this.prefix + "plot_comments", "plot_id");
if (!rs.next()) {
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.executeBatch();
statement.close();
}
}
catch (SQLException e) {}
}
/** /**
* Load all plots, helpers, denied, trusted, and every setting from DB into a hashmap * Load all plots, helpers, denied, trusted, and every setting from DB into a hashmap
@ -1114,47 +1108,77 @@ 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 `tier` = ? AND `sender` = ?"); 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.setInt(1, getId(world, plot.id));
statement.setString(2, comment.comment); statement.setString(2, comment.comment);
statement.setInt(3, comment.tier); statement.setString(3, comment.inbox);
statement.setString(4, comment.senderName); statement.setString(4, comment.senderName);
} else { } else {
statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `comment` = ? AND `tier` = ? 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);
statement.setInt(2, comment.tier); statement.setString(2, comment.inbox);
statement.setString(3, comment.senderName); statement.setString(3, comment.senderName);
} }
statement.executeUpdate(); statement.executeUpdate();
statement.close(); statement.close();
} catch (final SQLException e) { } catch (final SQLException e) {
e.printStackTrace(); e.printStackTrace();
PlotSquared.log("&7[WARN] " + "Failed to remove helper for plot " + plot.id); PlotSquared.log("&7[WARN] " + "Failed to remove comment for plot " + plot.id);
}
}
});
}
@Override
public void clearInbox(final Plot plot, final String inbox) {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
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);
} else {
statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` `inbox` = ?");
statement.setString(1, inbox);
}
statement.executeUpdate();
statement.close();
} catch (final SQLException e) {
e.printStackTrace();
PlotSquared.log("&7[WARN] " + "Failed to remove comment for plot " + plot.id);
} }
} }
}); });
} }
@Override @Override
public ArrayList<PlotComment> getComments(final String world, final Plot plot, final int tier, final boolean below) { public ArrayList<PlotComment> getComments(final String world, final Plot plot, final String inbox) {
final ArrayList<PlotComment> comments = new ArrayList<PlotComment>(); final ArrayList<PlotComment> comments = new ArrayList<PlotComment>();
try { try {
final PreparedStatement statement; final PreparedStatement statement;
final String comparison = below ? ">=" : "=";
if (plot != null) { if (plot != null) {
statement = this.connection.prepareStatement("SELECT * FROM `" + this.prefix + "plot_comments` WHERE `plot_plot_id` = ? AND `tier` " + comparison + " ?"); 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.setInt(1, getId(plot.world, plot.id));
statement.setInt(2, tier); statement.setString(2, inbox);
} else { } else {
statement = this.connection.prepareStatement("SELECT * FROM `" + this.prefix + "plot_comments` WHERE `tier` " + comparison + " ?"); statement = this.connection.prepareStatement("SELECT * FROM `" + this.prefix + "plot_comments` WHERE `inbox` = ?");
statement.setInt(1, tier); statement.setString(1, inbox);
} }
final ResultSet set = statement.executeQuery(); final ResultSet set = statement.executeQuery();
PlotComment comment; PlotComment comment;
while (set.next()) { while (set.next()) {
final String sender = set.getString("sender"); final String sender = set.getString("sender");
final String msg = set.getString("comment"); final String msg = set.getString("comment");
comment = new PlotComment(plot.id, msg, sender, tier); final int timestamp = set.getInt("timestamp");
if (plot != null) {
comment = new PlotComment(plot.world, plot.id, msg, sender, inbox, timestamp);
}
else {
comment = new PlotComment(null, null, msg, sender, inbox, timestamp);
}
comments.add(comment); comments.add(comment);
} }
statement.close(); statement.close();
@ -1172,11 +1196,12 @@ 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`, `tier`, `sender`) VALUES(?,?,?,?)"); 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.setInt(1, getId(world, plot.id));
statement.setString(2, comment.comment); statement.setString(2, comment.comment);
statement.setInt(3, comment.tier); statement.setString(3, comment.inbox);
statement.setString(4, comment.senderName); statement.setInt(4, (int) (comment.timestamp / 1000));
statement.setString(5, comment.senderName);
statement.executeUpdate(); statement.executeUpdate();
statement.close(); statement.close();
} catch (final SQLException e) { } catch (final SQLException e) {

View File

@ -1,7 +1,6 @@
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;
@ -21,12 +20,10 @@ 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,7 +2,6 @@ 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

@ -172,22 +172,6 @@ public class Plot implements Cloneable {
return (this.denied != null) && ((this.denied.contains(DBFunc.everyone) && !this.isAdded(uuid)) || (!this.isAdded(uuid) && this.denied.contains(uuid))); return (this.denied != null) && ((this.denied.contains(DBFunc.everyone) && !this.isAdded(uuid)) || (!this.isAdded(uuid) && this.denied.contains(uuid)));
} }
/**
* Get the UUID of the owner
*/
// public UUID getOwner() {
// return this.owner_;
// }
/**
* Set the owner
*
* @param uuid
*/
// public void setOwner(final UUID uuid) {
// this.owner_ = uuid;
// }
/** /**
* Get the plot ID * Get the plot ID
*/ */

View File

@ -155,15 +155,15 @@ public class PlotSettings {
return ""; return "";
} }
public ArrayList<PlotComment> getComments(final int tier) { public ArrayList<PlotComment> getComments(final String inbox) {
final ArrayList<PlotComment> c = new ArrayList<>(); final ArrayList<PlotComment> c = new ArrayList<>();
if (this.comments == null) { if (this.comments == null) {
return null; return null;
} }
for (final PlotComment comment : this.comments) { for (final PlotComment comment : this.comments) {
// if (comment.tier == tier) { if (comment.inbox.equals(inbox)) {
// c.add(comment); c.add(comment);
// } }
} }
return c; return c;
} }

View File

@ -5,6 +5,10 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.RunnableVal;
public abstract class CommentInbox { public abstract class CommentInbox {
@Override
public abstract String toString();
public abstract boolean canRead(Plot plot, PlotPlayer player); public abstract boolean canRead(Plot plot, PlotPlayer player);
public abstract boolean canWrite(Plot plot, PlotPlayer player); public abstract boolean canWrite(Plot plot, PlotPlayer player);
@ -24,4 +28,8 @@ public abstract class CommentInbox {
public abstract boolean getComments(Plot plot, RunnableVal whenDone); public abstract boolean getComments(Plot plot, RunnableVal whenDone);
public abstract boolean addComment(Plot plot, PlotComment comment); public abstract boolean addComment(Plot plot, PlotComment comment);
public abstract boolean removeComment(Plot plot, PlotComment comment);
public abstract boolean clearInbox(Plot plot);
} }

View File

@ -0,0 +1,18 @@
package com.intellectualcrafters.plot.object.comment;
import java.util.HashMap;
public class CommentManager {
public static HashMap<String, CommentInbox> inboxes = new HashMap<>();
public static void addInbox(CommentInbox inbox) {
inboxes.put(inbox.toString().toLowerCase(), inbox);
}
public static void registerDefaultInboxes() {
addInbox(new InboxReport());
addInbox(new InboxPublic());
addInbox(new InboxOwner());
}
}

View File

@ -1,12 +0,0 @@
package com.intellectualcrafters.plot.object.comment;
import java.util.HashMap;
public class InboxManager {
public static HashMap<String, CommentInbox> inboxes = new HashMap<>();
public static void addInbox(String name, CommentInbox inbox) {
inboxes.put(name.toLowerCase(), inbox);
}
}

View File

@ -0,0 +1,93 @@
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;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager;
public class InboxOwner extends CommentInbox {
@Override
public boolean canRead(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.read." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.read." + toString() + ".other")));
}
@Override
public boolean canWrite(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.write." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.write." + toString() + ".other")));
}
@Override
public boolean canModify(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.modify." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + toString() + ".other")));
}
@Override
public boolean getComments(final Plot plot, final RunnableVal whenDone) {
if (plot == null || plot.owner == null) {
return false;
}
ArrayList<PlotComment> comments = plot.settings.getComments(toString());
if (comments != null) {
whenDone.value = comments;
TaskManager.runTask(whenDone);
}
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
ArrayList<PlotComment> comments = DBFunc.getComments(plot.world, plot, toString());
whenDone.value = comments;
plot.settings.setComments(comments);
TaskManager.runTask(whenDone);
}
});
return true;
}
@Override
public boolean addComment(Plot plot, PlotComment comment) {
if (plot == null || plot.owner == null) {
return false;
}
plot.settings.addComment(comment);
DBFunc.setComment(plot.world, plot, comment);
return true;
}
@Override
public String toString() {
return "owner";
}
@Override
public boolean removeComment(Plot plot, PlotComment comment) {
if (plot == null || plot.owner == null) {
return false;
}
DBFunc.removeComment(plot.world, plot, comment);
return false;
}
@Override
public boolean clearInbox(Plot plot) {
if (plot == null || plot.owner == null) {
return false;
}
DBFunc.clearInbox(plot, toString());
return false;
}
}

View File

@ -0,0 +1,91 @@
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;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager;
public class InboxPublic extends CommentInbox {
@Override
public boolean canRead(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.read." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.read." + toString() + ".other")));
}
@Override
public boolean canWrite(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.write." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.write." + toString() + ".other")));
}
@Override
public boolean canModify(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.modify." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + toString() + ".other")));
}
@Override
public boolean getComments(final Plot plot, final RunnableVal whenDone) {
if (plot == null || plot.owner == null) {
return false;
}
ArrayList<PlotComment> comments = plot.settings.getComments(toString());
if (comments != null) {
whenDone.value = comments;
TaskManager.runTask(whenDone);
}
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
whenDone.value = DBFunc.getComments(plot.world, plot, toString());
TaskManager.runTask(whenDone);
}
});
return true;
}
@Override
public boolean addComment(Plot plot, PlotComment comment) {
if (plot == null || plot.owner == null) {
return false;
}
plot.settings.addComment(comment);
DBFunc.setComment(plot.world, plot, comment);
return true;
}
@Override
public String toString() {
return "public";
}
@Override
public boolean removeComment(Plot plot, PlotComment comment) {
if (plot == null || plot.owner == null) {
return false;
}
DBFunc.removeComment(plot.world, plot, comment);
return false;
}
@Override
public boolean clearInbox(Plot plot) {
if (plot == null || plot.owner == null) {
return false;
}
DBFunc.clearInbox(plot, toString());
return false;
}
}

View File

@ -0,0 +1,80 @@
package com.intellectualcrafters.plot.object.comment;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotHandler;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager;
public class InboxReport extends CommentInbox {
@Override
public boolean canRead(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.read." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.read." + toString() + ".other")));
}
@Override
public boolean canWrite(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.write." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.write." + toString() + ".other")));
}
@Override
public boolean canModify(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.modify." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + toString() + ".other")));
}
@Override
public boolean getComments(final Plot plot, final RunnableVal whenDone) {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
whenDone.value = DBFunc.getComments(null, null, toString());
TaskManager.runTask(whenDone);
}
});
return true;
}
@Override
public boolean addComment(Plot plot, PlotComment comment) {
if (plot == null || plot.owner == null) {
return false;
}
DBFunc.setComment(plot.world, plot, comment);
return true;
}
@Override
public String toString() {
return "report";
}
@Override
public boolean removeComment(Plot plot, PlotComment comment) {
if (plot == null || plot.owner == null) {
return false;
}
DBFunc.removeComment(plot.world, plot, comment);
return false;
}
@Override
public boolean clearInbox(Plot plot) {
if (plot == null || plot.owner == null) {
return false;
}
DBFunc.clearInbox(plot, toString());
return false;
}
}

View File

@ -30,9 +30,11 @@ public class PlotComment {
public final String inbox; public final String inbox;
public final String senderName; public final String senderName;
public final PlotId id; public final PlotId id;
public final String world;
public final long timestamp; public final long timestamp;
public PlotComment(final PlotId id, final String comment, final String senderName, final String inbox, final long timestamp) { public PlotComment(final String world, final PlotId id, final String comment, final String senderName, final String inbox, final long timestamp) {
this.world = world;
this.id = id; this.id = id;
this.comment = comment; this.comment = comment;
this.senderName = senderName; this.senderName = senderName;

View File

@ -1,38 +0,0 @@
package com.intellectualcrafters.plot.object.comment;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
public class ReportInbox extends CommentInbox {
@Override
public boolean canRead(Plot plot, PlotPlayer player) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean canWrite(Plot plot, PlotPlayer player) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean canModify(Plot plot, PlotPlayer player) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean getComments(Plot plot, RunnableVal whenDone) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean addComment(Plot plot, PlotComment comment) {
// TODO Auto-generated method stub
return false;
}
}

View File

@ -1,20 +1,17 @@
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;