mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 15:16:45 +01:00
New comment system
This commit is contained in:
parent
ade657b1af
commit
b9c36965d8
@ -57,6 +57,7 @@ import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.object.comment.CommentManager;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.ClusterManager;
|
||||
@ -507,6 +508,7 @@ public class PlotSquared {
|
||||
setupConfigs();
|
||||
setupDefaultFlags();
|
||||
setupDatabase();
|
||||
CommentManager.registerDefaultInboxes();
|
||||
// Tasks
|
||||
if (Settings.KILL_ROAD_MOBS) {
|
||||
IMP.runEntityTask();
|
||||
|
@ -21,18 +21,18 @@
|
||||
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;
|
||||
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.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
|
||||
public class Comment extends SubCommand {
|
||||
public Comment() {
|
||||
@ -40,27 +40,45 @@ public class Comment extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return sendMessage(plr, C.NOT_IN_PLOT);
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
if (args.length < 2) {
|
||||
sendMessage(player, C.COMMENT_SYNTAX, StringUtils.join(CommentManager.inboxes.keySet(),"|"));
|
||||
return false;
|
||||
}
|
||||
if (!plot.hasOwner()) {
|
||||
return sendMessage(plr, C.NOT_IN_PLOT);
|
||||
CommentInbox inbox = CommentManager.inboxes.get(args[0].toLowerCase());
|
||||
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");
|
||||
if ((args.length > 1) && recipients.contains(args[0].toLowerCase())) {
|
||||
if (Permissions.hasPermission(plr, "plots.comment." + args[0].toLowerCase())) {
|
||||
final String text = StringUtils.join(Arrays.copyOfRange(args, 1, args.length), " ");
|
||||
final PlotComment comment = new PlotComment(plot.id, text, plr.getName(), recipients.indexOf(args[0].toLowerCase()));
|
||||
plot.settings.addComment(comment);
|
||||
DBFunc.setComment(loc.getWorld(), plot, comment);
|
||||
return sendMessage(plr, C.COMMENT_ADDED);
|
||||
} else {
|
||||
return sendMessage(plr, C.NO_PERMISSION, "plots.comment." + args[0].toLowerCase());
|
||||
Plot plot;
|
||||
Location loc = player.getLocation();
|
||||
PlotId id = PlotId.fromString(args[1]);
|
||||
int index;
|
||||
if (id != null) {
|
||||
if (args.length < 4) {
|
||||
sendMessage(player, C.COMMENT_SYNTAX, StringUtils.join(CommentManager.inboxes.keySet(),"|"));
|
||||
return false;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -25,11 +25,16 @@ 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;
|
||||
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;
|
||||
@ -37,152 +42,141 @@ import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
public class Inbox extends SubCommand {
|
||||
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
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
boolean report = false;
|
||||
if (args.length == 1) {
|
||||
if (args[0].equalsIgnoreCase("reports")) {
|
||||
report = true;
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
final Plot plot = MainUtil.getPlot(player.getLocation());
|
||||
if (args.length < 1) {
|
||||
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox <inbox> [delete <index>|clear|page]");
|
||||
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;
|
||||
}
|
||||
Integer tier;
|
||||
final UUID uuid = plr.getUUID();
|
||||
if (Permissions.hasPermission(plr, "plots.comment.admin")) {
|
||||
tier = 0;
|
||||
} 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 CommentInbox inbox = CommentManager.inboxes.get(args[0].toLowerCase());
|
||||
if (inbox == null) {
|
||||
sendMessage(player, C.INVALID_INBOX, StringUtils.join(CommentManager.inboxes.keySet(),", "));
|
||||
return false;
|
||||
}
|
||||
final boolean below;
|
||||
if (args.length > 0) {
|
||||
below = false;
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "admin":
|
||||
if (tier <= 0) {
|
||||
tier = 0;
|
||||
} else {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.admin");
|
||||
return false;
|
||||
final int page;
|
||||
if (args.length > 1) {
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "delete": {
|
||||
if (!inbox.canModify(plot, player)) {
|
||||
sendMessage(player, C.NO_PERM_INBOX_MODIFY);
|
||||
}
|
||||
break;
|
||||
case "owner":
|
||||
if (tier <= 1) {
|
||||
tier = 1;
|
||||
} else {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.owner");
|
||||
return false;
|
||||
if (args.length != 3) {
|
||||
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox " + inbox.toString() + " delete <index>");
|
||||
}
|
||||
break;
|
||||
case "helper":
|
||||
if (tier <= 2) {
|
||||
tier = 2;
|
||||
} else {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.helper");
|
||||
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;
|
||||
final int index;
|
||||
try {
|
||||
index = Integer.parseInt(args[2]);
|
||||
if (index < 1) {
|
||||
sendMessage(player, C.NOT_VALID_INBOX_INDEX, index + "");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (final PlotComment comment : comments) {
|
||||
DBFunc.removeComment(world, plot, comment);
|
||||
catch (NumberFormatException e) {
|
||||
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");
|
||||
} else {
|
||||
final List<String> recipients = Arrays.asList("A", "O", "H", "T", "E");
|
||||
int count = 1;
|
||||
final StringBuilder message = new StringBuilder(C.COMMENT_HEADER.s());
|
||||
for (final PlotComment comment : comments) {
|
||||
message.append("\n&8[&7" + comment.id + "&8]" + "&c[" + count + "]&6[" + recipients.get(tier2 == -1 ? 0 : tier2) + "] &7" + comment.senderName + "&f: " + comment.comment);
|
||||
count++;
|
||||
|
||||
if (!inbox.getComments(plot, new RunnableVal() {
|
||||
@Override
|
||||
public void run() {
|
||||
List<PlotComment> comments = (List<PlotComment>) value;
|
||||
if (index > comments.size()) {
|
||||
sendMessage(player, C.NOT_VALID_INBOX_INDEX, index + "");
|
||||
}
|
||||
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) {
|
||||
message.append("&cNo messages.");
|
||||
return true;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,6 @@
|
||||
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;
|
||||
|
@ -103,9 +103,14 @@ public enum C {
|
||||
/*
|
||||
* 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"),
|
||||
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_HEADER("$2====== Comments ======"),
|
||||
/*
|
||||
|
@ -302,6 +302,13 @@ public interface AbstractDB {
|
||||
*/
|
||||
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
|
||||
*
|
||||
@ -320,7 +327,7 @@ public interface AbstractDB {
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
@ -238,6 +238,10 @@ public class DBFunc {
|
||||
dbManager.removeComment(world, plot, comment);
|
||||
}
|
||||
|
||||
public static void clearInbox(final Plot plot, final String inbox) {
|
||||
dbManager.clearInbox(plot, inbox);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plot
|
||||
* @param comment
|
||||
@ -249,8 +253,8 @@ public class DBFunc {
|
||||
/**
|
||||
* @param plot
|
||||
*/
|
||||
public static ArrayList<PlotComment> getComments(final String world, final Plot plot, final int tier, final boolean below) {
|
||||
return dbManager.getComments(world, plot, tier, below);
|
||||
public static ArrayList<PlotComment> getComments(final String world, final Plot plot, final String inbox) {
|
||||
return dbManager.getComments(world, plot, inbox);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,13 +28,11 @@ import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -137,9 +135,6 @@ public class SQLManager implements AbstractDB {
|
||||
|
||||
@Override
|
||||
public void createAllSettingsAndHelpers(final ArrayList<Plot> mylist) {
|
||||
|
||||
// TODO create settings
|
||||
|
||||
final int size = mylist.size();
|
||||
int packet;
|
||||
if (PlotSquared.getMySQL() != null) {
|
||||
@ -270,29 +265,6 @@ public class SQLManager implements AbstractDB {
|
||||
stmt.close();
|
||||
} catch (final Exception e) {
|
||||
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` ");
|
||||
for (int i = 0; i < (ids.size() - 2); i++) {
|
||||
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_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," + "`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_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");
|
||||
@ -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_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," + "`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_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" + ")");
|
||||
@ -606,6 +584,22 @@ public class SQLManager implements AbstractDB {
|
||||
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
|
||||
*/
|
||||
@ -1114,47 +1108,77 @@ 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 `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.setString(2, comment.comment);
|
||||
statement.setInt(3, comment.tier);
|
||||
statement.setString(3, comment.inbox);
|
||||
statement.setString(4, comment.senderName);
|
||||
} 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.setInt(2, comment.tier);
|
||||
statement.setString(2, comment.inbox);
|
||||
statement.setString(3, comment.senderName);
|
||||
}
|
||||
statement.executeUpdate();
|
||||
statement.close();
|
||||
} catch (final SQLException e) {
|
||||
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 ArrayList<PlotComment> getComments(final String world, final Plot plot, final int tier, final boolean below) {
|
||||
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
|
||||
public ArrayList<PlotComment> getComments(final String world, final Plot plot, final String inbox) {
|
||||
final ArrayList<PlotComment> comments = new ArrayList<PlotComment>();
|
||||
try {
|
||||
final PreparedStatement statement;
|
||||
final String comparison = below ? ">=" : "=";
|
||||
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(2, tier);
|
||||
statement.setString(2, inbox);
|
||||
} else {
|
||||
statement = this.connection.prepareStatement("SELECT * FROM `" + this.prefix + "plot_comments` WHERE `tier` " + comparison + " ?");
|
||||
statement.setInt(1, tier);
|
||||
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");
|
||||
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);
|
||||
}
|
||||
statement.close();
|
||||
@ -1172,11 +1196,12 @@ 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`, `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.setString(2, comment.comment);
|
||||
statement.setInt(3, comment.tier);
|
||||
statement.setString(4, comment.senderName);
|
||||
statement.setString(3, comment.inbox);
|
||||
statement.setInt(4, (int) (comment.timestamp / 1000));
|
||||
statement.setString(5, comment.senderName);
|
||||
statement.executeUpdate();
|
||||
statement.close();
|
||||
} catch (final SQLException e) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
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;
|
||||
@ -21,12 +20,10 @@ 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,7 +2,6 @@ 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;
|
||||
|
@ -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)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
@ -155,15 +155,15 @@ public class PlotSettings {
|
||||
return "";
|
||||
}
|
||||
|
||||
public ArrayList<PlotComment> getComments(final int tier) {
|
||||
public ArrayList<PlotComment> getComments(final String inbox) {
|
||||
final ArrayList<PlotComment> c = new ArrayList<>();
|
||||
if (this.comments == null) {
|
||||
return null;
|
||||
}
|
||||
for (final PlotComment comment : this.comments) {
|
||||
// if (comment.tier == tier) {
|
||||
// c.add(comment);
|
||||
// }
|
||||
if (comment.inbox.equals(inbox)) {
|
||||
c.add(comment);
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
@ -5,6 +5,10 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
|
||||
public abstract class CommentInbox {
|
||||
|
||||
@Override
|
||||
public abstract String toString();
|
||||
|
||||
public abstract boolean canRead(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 addComment(Plot plot, PlotComment comment);
|
||||
|
||||
public abstract boolean removeComment(Plot plot, PlotComment comment);
|
||||
|
||||
public abstract boolean clearInbox(Plot plot);
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -30,9 +30,11 @@ public class PlotComment {
|
||||
public final String inbox;
|
||||
public final String senderName;
|
||||
public final PlotId id;
|
||||
public final String world;
|
||||
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.comment = comment;
|
||||
this.senderName = senderName;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -1,20 +1,17 @@
|
||||
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