mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-29 16:46:45 +01:00
basic plot reporting
This commit is contained in:
parent
a29484a825
commit
6a238fe099
@ -45,12 +45,19 @@ public class Inbox extends SubCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final Player plr, final String... args) {
|
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);
|
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
final Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
||||||
if (!plot.hasOwner()) {
|
if (plot != null && !plot.hasOwner()) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
|
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -59,23 +66,24 @@ public class Inbox extends SubCommand {
|
|||||||
final UUID uuid = UUIDHandler.getUUID(plr);
|
final UUID uuid = UUIDHandler.getUUID(plr);
|
||||||
if (PlotMain.hasPermission(plr, "plots.comment.admin")) {
|
if (PlotMain.hasPermission(plr, "plots.comment.admin")) {
|
||||||
tier = 0;
|
tier = 0;
|
||||||
} else if (plot.owner == uuid) {
|
} else if (plot != null && plot.owner == uuid) {
|
||||||
tier = 1;
|
tier = 1;
|
||||||
} else if (plot.helpers.contains(uuid)) {
|
} else if (plot != null && plot.helpers.contains(uuid)) {
|
||||||
tier = 2;
|
tier = 2;
|
||||||
} else if (plot.trusted.contains(uuid)) {
|
} else if (plot != null && plot.trusted.contains(uuid)) {
|
||||||
tier = 3;
|
tier = 3;
|
||||||
} else {
|
} else {
|
||||||
tier = 4;
|
tier = 4;
|
||||||
}
|
}
|
||||||
|
final boolean below;
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
|
below = false;
|
||||||
switch (args[0].toLowerCase()) {
|
switch (args[0].toLowerCase()) {
|
||||||
case "admin":
|
case "admin":
|
||||||
if (tier <= 0) {
|
if (tier <= 0) {
|
||||||
tier = 0;
|
tier = 0;
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX);
|
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.admin");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -83,7 +91,7 @@ public class Inbox extends SubCommand {
|
|||||||
if (tier <= 1) {
|
if (tier <= 1) {
|
||||||
tier = 1;
|
tier = 1;
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX);
|
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.owner");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -91,7 +99,7 @@ public class Inbox extends SubCommand {
|
|||||||
if (tier <= 2) {
|
if (tier <= 2) {
|
||||||
tier = 2;
|
tier = 2;
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX);
|
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.helper");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -99,7 +107,7 @@ public class Inbox extends SubCommand {
|
|||||||
if (tier <= 3) {
|
if (tier <= 3) {
|
||||||
tier = 3;
|
tier = 3;
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX);
|
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.trusted");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -107,15 +115,25 @@ public class Inbox extends SubCommand {
|
|||||||
if (tier <= 4) {
|
if (tier <= 4) {
|
||||||
tier = 4;
|
tier = 4;
|
||||||
} else {
|
} else {
|
||||||
PlayerFunctions.sendMessage(plr, C.NO_PERM_INBOX);
|
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.inbox.everyone");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
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));
|
PlayerFunctions.sendMessage(plr, C.INVALID_INBOX, Arrays.copyOfRange(new String[]{"admin", "owner", "helper", "trusted", "everyone"}, tier, 4));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
below = true;
|
||||||
|
}
|
||||||
|
|
||||||
final String world = plr.getWorld().getName();
|
final String world = plr.getWorld().getName();
|
||||||
final int tier2 = tier;
|
final int tier2 = tier;
|
||||||
@ -123,9 +141,15 @@ public class Inbox extends SubCommand {
|
|||||||
Bukkit.getScheduler().runTaskAsynchronously(PlotMain.getMain(), new Runnable() {
|
Bukkit.getScheduler().runTaskAsynchronously(PlotMain.getMain(), new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
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) {
|
if (comments == null) {
|
||||||
comments = DBFunc.getComments(world, plot, tier2);
|
comments = DBFunc.getComments(world, plot, tier2, below);
|
||||||
plot.settings.setComments(comments);
|
plot.settings.setComments(comments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +65,6 @@ public enum C {
|
|||||||
*/
|
*/
|
||||||
COMMENT_SYNTAX("&cUse /plots comment <everyone|trusted|helper|owner|admin> <comment>"),
|
COMMENT_SYNTAX("&cUse /plots comment <everyone|trusted|helper|owner|admin> <comment>"),
|
||||||
INVALID_INBOX("&cThat is not a valid inbox.\n&6Accepted values: %s"),
|
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_REMOVED("&aSuccessfully deleted %s."),
|
||||||
COMMENT_ADDED("&aA comment has been left"),
|
COMMENT_ADDED("&aA comment has been left"),
|
||||||
/*
|
/*
|
||||||
|
@ -244,7 +244,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);
|
public ArrayList<PlotComment> getComments(final String world, final Plot plot, final int tier, boolean below);
|
||||||
|
|
||||||
public void createPlotAndSettings(Plot plot);
|
public void createPlotAndSettings(Plot plot);
|
||||||
}
|
}
|
||||||
|
@ -214,8 +214,8 @@ public class DBFunc {
|
|||||||
/**
|
/**
|
||||||
* @param plot
|
* @param plot
|
||||||
*/
|
*/
|
||||||
public static ArrayList<PlotComment> getComments(final String world, final Plot plot, final int tier) {
|
public static ArrayList<PlotComment> getComments(final String world, final Plot plot, final int tier, final boolean below) {
|
||||||
return dbManager.getComments(world, plot, tier);
|
return dbManager.getComments(world, plot, tier, below);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -977,11 +977,20 @@ public class SQLManager implements AbstractDB {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
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` = ?");
|
PreparedStatement statement;
|
||||||
statement.setInt(1, getId(world, plot.id));
|
if (plot != null) {
|
||||||
statement.setString(2, comment.comment);
|
statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `plot_plot_id` = ? AND `comment` = ? AND `tier` = ? AND `sender` = ?");
|
||||||
statement.setInt(3, comment.tier);
|
statement.setInt(1, getId(world, plot.id));
|
||||||
statement.setString(4, comment.senderName);
|
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.executeUpdate();
|
||||||
statement.close();
|
statement.close();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
@ -993,12 +1002,20 @@ public class SQLManager implements AbstractDB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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>();
|
final ArrayList<PlotComment> comments = new ArrayList<PlotComment>();
|
||||||
try {
|
try {
|
||||||
final PreparedStatement statement = this.connection.prepareStatement("SELECT `*` FROM `" + this.prefix + "plot_comments` WHERE `plot_plot_id` = ? AND `tier` <= ?");
|
final PreparedStatement statement;
|
||||||
statement.setInt(1, getId(plot.getWorld().getName(), plot.id));
|
String comparison = below ? ">=" : "=";
|
||||||
statement.setInt(2, tier);
|
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();
|
final ResultSet set = statement.executeQuery();
|
||||||
PlotComment comment;
|
PlotComment comment;
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user