basic plot reporting

This commit is contained in:
Jesse Boyd 2015-01-15 01:22:45 +11:00
parent a29484a825
commit 6a238fe099
5 changed files with 67 additions and 27 deletions

View File

@ -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<PlotComment> comments = plot.settings.getComments(tier2);
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);
comments = DBFunc.getComments(world, plot, tier2, below);
plot.settings.setComments(comments);
}

View File

@ -65,7 +65,6 @@ public enum C {
*/
COMMENT_SYNTAX("&cUse /plots comment <everyone|trusted|helper|owner|admin> <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"),
/*

View File

@ -244,7 +244,7 @@ public interface AbstractDB {
*
* @return Plot Comments within the specified tier
*/
public ArrayList<PlotComment> getComments(final String world, final Plot plot, final int tier);
public ArrayList<PlotComment> getComments(final String world, final Plot plot, final int tier, boolean below);
public void createPlotAndSettings(Plot plot);
}

View File

@ -214,8 +214,8 @@ public class DBFunc {
/**
* @param plot
*/
public static ArrayList<PlotComment> getComments(final String world, final Plot plot, final int tier) {
return dbManager.getComments(world, plot, tier);
public static ArrayList<PlotComment> getComments(final String world, final Plot plot, final int tier, final boolean below) {
return dbManager.getComments(world, plot, tier, below);
}
/**

View File

@ -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<PlotComment> getComments(final String world, final Plot plot, final int tier) {
public ArrayList<PlotComment> getComments(final String world, final Plot plot, final int tier, boolean below) {
final ArrayList<PlotComment> comments = new ArrayList<PlotComment>();
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()) {