diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java index 03408a1b7..2714ae9a1 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java @@ -45,12 +45,19 @@ public class Inbox extends SubCommand { @Override public boolean execute(final Player plr, final String... args) { - if (!PlayerFunctions.isInPlot(plr)) { + boolean report = false; + if (args.length == 1){ + if (args[1].equalsIgnoreCase("reports")) { + report = true; + } + } + + if (!PlayerFunctions.isInPlot(plr) && !report) { PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT); return false; } final Plot plot = PlayerFunctions.getCurrentPlot(plr); - if (!plot.hasOwner()) { + if (plot != null && !plot.hasOwner()) { PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT); return false; } @@ -59,23 +66,24 @@ public class Inbox extends SubCommand { final UUID uuid = UUIDHandler.getUUID(plr); if (PlotMain.hasPermission(plr, "plots.comment.admin")) { tier = 0; - } else if (plot.owner == uuid) { + } else if (plot != null && plot.owner == uuid) { tier = 1; - } else if (plot.helpers.contains(uuid)) { + } else if (plot != null && plot.helpers.contains(uuid)) { tier = 2; - } else if (plot.trusted.contains(uuid)) { + } else if (plot != null && plot.trusted.contains(uuid)) { tier = 3; } else { tier = 4; } - + final boolean below; if (args.length > 0) { + below = false; switch (args[0].toLowerCase()) { case "admin": if (tier <= 0) { tier = 0; } else { - PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX); + PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.admin"); return false; } break; @@ -83,7 +91,7 @@ public class Inbox extends SubCommand { if (tier <= 1) { tier = 1; } else { - PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX); + PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.owner"); return false; } break; @@ -91,7 +99,7 @@ public class Inbox extends SubCommand { if (tier <= 2) { tier = 2; } else { - PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX); + PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.helper"); return false; } break; @@ -99,7 +107,7 @@ public class Inbox extends SubCommand { if (tier <= 3) { tier = 3; } else { - PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX); + PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.trusted"); return false; } break; @@ -107,15 +115,25 @@ public class Inbox extends SubCommand { if (tier <= 4) { tier = 4; } else { - PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX); + PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.everyone"); return false; } break; - case "default": + case "reports": + if (tier <= 0) { + tier = -1; + } else { + PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.admin"); + return false; + } + default: PlayerFunctions.sendMessage(plr, C.INVALID_INBOX, Arrays.copyOfRange(new String[]{"admin", "owner", "helper", "trusted", "everyone"}, tier, 4)); return false; } } + else { + below = true; + } final String world = plr.getWorld().getName(); final int tier2 = tier; @@ -123,9 +141,15 @@ public class Inbox extends SubCommand { Bukkit.getScheduler().runTaskAsynchronously(PlotMain.getMain(), new Runnable() { @Override public void run() { - ArrayList comments = plot.settings.getComments(tier2); + ArrayList 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); + comments = DBFunc.getComments(world, plot, tier2, below); plot.settings.setComments(comments); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java index 03d7e35f2..ee4fca7e4 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -65,7 +65,6 @@ public enum C { */ COMMENT_SYNTAX("&cUse /plots comment "), INVALID_INBOX("&cThat is not a valid inbox.\n&6Accepted values: %s"), - NO_PERM_INBOX("&cYou do not have permission to read that inbox."), COMMENT_REMOVED("&aSuccessfully deleted %s."), COMMENT_ADDED("&aA comment has been left"), /* diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java index aba6f2e1f..3a96a3314 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java @@ -244,7 +244,7 @@ public interface AbstractDB { * * @return Plot Comments within the specified tier */ - public ArrayList getComments(final String world, final Plot plot, final int tier); + public ArrayList getComments(final String world, final Plot plot, final int tier, boolean below); public void createPlotAndSettings(Plot plot); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java index 6f8be1ebf..440765f6a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java @@ -214,8 +214,8 @@ public class DBFunc { /** * @param plot */ - public static ArrayList getComments(final String world, final Plot plot, final int tier) { - return dbManager.getComments(world, plot, tier); + public static ArrayList getComments(final String world, final Plot plot, final int tier, final boolean below) { + return dbManager.getComments(world, plot, tier, below); } /** diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index 383d2b79d..1e73e3fdf 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -977,11 +977,20 @@ public class SQLManager implements AbstractDB { @Override public void run() { try { - final PreparedStatement statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `plot_plot_id` = ? AND `comment` = ? AND `tier` = ? AND `sender` = ?"); - statement.setInt(1, getId(world, plot.id)); - statement.setString(2, comment.comment); - statement.setInt(3, comment.tier); - statement.setString(4, comment.senderName); + 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.setInt(1, getId(world, plot.id)); + statement.setString(2, comment.comment); + statement.setInt(3, comment.tier); + 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.setString(1, comment.comment); + statement.setInt(2, comment.tier); + statement.setString(3, comment.senderName); + } statement.executeUpdate(); statement.close(); } catch (final SQLException e) { @@ -993,12 +1002,20 @@ public class SQLManager implements AbstractDB { } @Override - public ArrayList getComments(final String world, final Plot plot, final int tier) { + public ArrayList getComments(final String world, final Plot plot, final int tier, boolean below) { final ArrayList comments = new ArrayList(); try { - final PreparedStatement statement = this.connection.prepareStatement("SELECT `*` FROM `" + this.prefix + "plot_comments` WHERE `plot_plot_id` = ? AND `tier` <= ?"); - statement.setInt(1, getId(plot.getWorld().getName(), plot.id)); - statement.setInt(2, tier); + final PreparedStatement statement; + String comparison = below ? ">=" : "="; + if (plot != null) { + statement = this.connection.prepareStatement("SELECT `*` FROM `" + this.prefix + "plot_comments` WHERE `plot_plot_id` = ? AND `tier` " + comparison + " ?"); + statement.setInt(1, getId(plot.getWorld().getName(), plot.id)); + statement.setInt(2, tier); + } + else { + statement = this.connection.prepareStatement("SELECT `*` FROM `" + this.prefix + "plot_comments` WHERE `tier` " + comparison + " ?"); + statement.setInt(1, tier); + } final ResultSet set = statement.executeQuery(); PlotComment comment; while (set.next()) {