From 11af33f2d52d72067d1193817e1ea4f7f60ad911 Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Fri, 30 Apr 2021 19:04:44 +0200 Subject: [PATCH] Fixup inbox javadocs --- .../com/plotsquared/core/command/Inbox.java | 22 ++++++------ .../core/plot/comment/CommentInbox.java | 34 +++++++++++++++++-- .../core/plot/comment/CommentManager.java | 14 ++++++-- .../core/plot/comment/InboxOwner.java | 2 +- .../core/plot/comment/InboxPublic.java | 2 +- .../core/plot/comment/InboxReport.java | 2 +- Core/src/main/resources/lang/messages_en.json | 4 +-- 7 files changed, 57 insertions(+), 23 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/command/Inbox.java b/Core/src/main/java/com/plotsquared/core/command/Inbox.java index d8707a847..ae1cc4a08 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Inbox.java +++ b/Core/src/main/java/com/plotsquared/core/command/Inbox.java @@ -57,7 +57,7 @@ import java.util.stream.Collectors; requiredType = RequiredType.PLAYER) public class Inbox extends SubCommand { - public void displayComments(PlotPlayer player, List oldComments, int page) { + public void displayComments(PlotPlayer player, List oldComments, int page) { if (oldComments == null || oldComments.isEmpty()) { player.sendMessage(TranslatableCaption.of("comment.inbox_empty")); return; @@ -102,7 +102,7 @@ public class Inbox extends SubCommand { } Template number = Template.of("number", String.valueOf(x)); Template world = Template.of("world", comment.world); - Template plot_id = Template.of("plot_id", comment.id.getX() + "" + comment.id.getY()); + Template plot_id = Template.of("plot_id", comment.id.getX() + ";" + comment.id.getY()); Template commenter = Template.of("commenter", comment.senderName); Template commentTemplate = Template.of("comment", commentColored); builder.append(MINI_MESSAGE @@ -133,7 +133,7 @@ public class Inbox extends SubCommand { sendUsage(player); for (final CommentInbox inbox : CommentManager.inboxes.values()) { if (inbox.canRead(plot, player)) { - if (!inbox.getComments(plot, new RunnableVal>() { + if (!inbox.getComments(plot, new RunnableVal<>() { @Override public void run(List value) { if (value != null) { @@ -179,7 +179,7 @@ public class Inbox extends SubCommand { } final MetaDataKey metaDataKey = MetaDataKey.of( String.format("inbox:%s", inbox.toString()), - new TypeLiteral() { + new TypeLiteral<>() { } ); try (final MetaDataAccess metaDataAccess = player.accessTemporaryMetaData(metaDataKey)) { @@ -217,7 +217,7 @@ public class Inbox extends SubCommand { return false; } - if (!inbox.getComments(plot, new RunnableVal>() { + if (!inbox.getComments(plot, new RunnableVal<>() { @Override public void run(List value) { if (index > value.size()) { @@ -238,8 +238,6 @@ public class Inbox extends SubCommand { } else { player.sendMessage( TranslatableCaption.of("comment.comment_removed_failure")); - - } } })) { @@ -254,12 +252,12 @@ public class Inbox extends SubCommand { inbox.clearInbox(plot); List comments = plot.getPlotCommentContainer().getComments(inbox.toString()); if (!comments.isEmpty()) { + player.sendMessage( + TranslatableCaption.of("comment.comment_removed_success"), + Template.of("value", String.valueOf(comments)) + ); plot.getPlotCommentContainer().removeComments(comments); } - player.sendMessage( - TranslatableCaption.of("comment.comment_removed_success"), - Template.of("value", "*") - ); return true; default: try { @@ -276,7 +274,7 @@ public class Inbox extends SubCommand { player.sendMessage(TranslatableCaption.of("comment.no_perm_inbox")); return false; } - if (!inbox.getComments(plot, new RunnableVal>() { + if (!inbox.getComments(plot, new RunnableVal<>() { @Override public void run(List value) { displayComments(player, value, page); diff --git a/Core/src/main/java/com/plotsquared/core/plot/comment/CommentInbox.java b/Core/src/main/java/com/plotsquared/core/plot/comment/CommentInbox.java index b0fbb0ba2..233c53841 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/comment/CommentInbox.java +++ b/Core/src/main/java/com/plotsquared/core/plot/comment/CommentInbox.java @@ -38,7 +38,12 @@ public abstract class CommentInbox { @Override public abstract String toString(); - public boolean canRead(Plot plot, PlotPlayer player) { + /** + * @param plot the plot's inbox to read + * @param player the player trying to read the comment + * @return the inbox, otherwise {@code false} false + */ + public boolean canRead(Plot plot, PlotPlayer player) { if (Permissions.hasPermission(player, "plots.inbox.read." + toString(), true)) { return plot.isOwner(player.getUUID()) || Permissions .hasPermission(player, "plots.inbox.read." + toString() + ".other", true); @@ -46,7 +51,12 @@ public abstract class CommentInbox { return false; } - public boolean canWrite(Plot plot, PlotPlayer player) { + /** + * @param plot the plot's inbox to write to + * @param player the player trying to write the comment + * @return true if the player can write a comment on the plot + */ + public boolean canWrite(Plot plot, PlotPlayer player) { if (plot == null) { return Permissions.hasPermission(player, "plots.inbox.write." + toString(), true); } @@ -55,7 +65,13 @@ public abstract class CommentInbox { .hasPermission(player, "plots.inbox.write." + toString() + ".other", true)); } - public boolean canModify(Plot plot, PlotPlayer player) { + /** + * @param plot the plot's inbox to write to + * @param player the player trying to modify the inbox + * @return true if the player can write a comment on the plot + */ + @SuppressWarnings({"BooleanMethodIsAlwaysInverted"}) + public boolean canModify(Plot plot, PlotPlayer player) { if (Permissions.hasPermission(player, "plots.inbox.modify." + toString(), true)) { return plot.isOwner(player.getUUID()) || Permissions .hasPermission(player, "plots.inbox.modify." + toString() + ".other", true); @@ -74,12 +90,24 @@ public abstract class CommentInbox { */ public abstract boolean getComments(Plot plot, RunnableVal> whenDone); + /** + * @param plot plot + * @param comment the comment to add + * @return success or not + */ public abstract boolean addComment(Plot plot, PlotComment comment); + /** + * @param plot plot + * @param comment the comment to remove + */ public void removeComment(Plot plot, PlotComment comment) { DBFunc.removeComment(plot, comment); } + /** + * @param plot plot + */ public void clearInbox(Plot plot) { DBFunc.clearInbox(plot, toString()); } diff --git a/Core/src/main/java/com/plotsquared/core/plot/comment/CommentManager.java b/Core/src/main/java/com/plotsquared/core/plot/comment/CommentManager.java index ca8dc7ac7..adfc4df75 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/comment/CommentManager.java +++ b/Core/src/main/java/com/plotsquared/core/plot/comment/CommentManager.java @@ -49,7 +49,7 @@ public class CommentManager { public static final HashMap inboxes = new HashMap<>(); - public static void sendTitle(final PlotPlayer player, final Plot plot) { + public static void sendTitle(final PlotPlayer player, final Plot plot) { if (!Settings.Enabled_Components.COMMENT_NOTIFIER || !plot.isOwner(player.getUUID())) { return; } @@ -58,7 +58,7 @@ public class CommentManager { final AtomicInteger count = new AtomicInteger(0); final AtomicInteger size = new AtomicInteger(boxes.size()); for (final CommentInbox inbox : inboxes.values()) { - inbox.getComments(plot, new RunnableVal>() { + inbox.getComments(plot, new RunnableVal<>() { @Override public void run(List value) { int total; @@ -87,14 +87,22 @@ public class CommentManager { }, TaskTime.seconds(1L)); } + /** + * @param player The player the inbox belongs to + * @param inbox the inbox + * @return the time in milliseconds when the player was last seen online + */ public static long getTimestamp(PlotPlayer player, String inbox) { - final MetaDataKey inboxKey = MetaDataKey.of(String.format("inbox:%s", inbox), new TypeLiteral() { + final MetaDataKey inboxKey = MetaDataKey.of(String.format("inbox:%s", inbox), new TypeLiteral<>() { }); try (final MetaDataAccess inboxAccess = player.accessTemporaryMetaData(inboxKey)) { return inboxAccess.get().orElse(player.getLastPlayed()); } } + /** + * @param inbox the inbox to add + */ public static void addInbox(CommentInbox inbox) { inboxes.put(inbox.toString().toLowerCase(), inbox); } diff --git a/Core/src/main/java/com/plotsquared/core/plot/comment/InboxOwner.java b/Core/src/main/java/com/plotsquared/core/plot/comment/InboxOwner.java index a4c1bc860..bdbc6d31f 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/comment/InboxOwner.java +++ b/Core/src/main/java/com/plotsquared/core/plot/comment/InboxOwner.java @@ -43,7 +43,7 @@ public class InboxOwner extends CommentInbox { TaskManager.runTask(whenDone); return true; } - DBFunc.getComments(plot, toString(), new RunnableVal>() { + DBFunc.getComments(plot, toString(), new RunnableVal<>() { @Override public void run(List value) { whenDone.value = value; diff --git a/Core/src/main/java/com/plotsquared/core/plot/comment/InboxPublic.java b/Core/src/main/java/com/plotsquared/core/plot/comment/InboxPublic.java index bed8cc671..9cc0a43e4 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/comment/InboxPublic.java +++ b/Core/src/main/java/com/plotsquared/core/plot/comment/InboxPublic.java @@ -42,7 +42,7 @@ public class InboxPublic extends CommentInbox { TaskManager.runTask(whenDone); return true; } - DBFunc.getComments(plot, toString(), new RunnableVal>() { + DBFunc.getComments(plot, toString(), new RunnableVal<>() { @Override public void run(List value) { whenDone.value = value; diff --git a/Core/src/main/java/com/plotsquared/core/plot/comment/InboxReport.java b/Core/src/main/java/com/plotsquared/core/plot/comment/InboxReport.java index 31556c43d..0ac40229a 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/comment/InboxReport.java +++ b/Core/src/main/java/com/plotsquared/core/plot/comment/InboxReport.java @@ -36,7 +36,7 @@ public class InboxReport extends CommentInbox { @Override public boolean getComments(Plot plot, final RunnableVal> whenDone) { - DBFunc.getComments(plot, toString(), new RunnableVal>() { + DBFunc.getComments(plot, toString(), new RunnableVal<>() { @Override public void run(List value) { whenDone.value = value; diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index 4b5b70da8..c8b9bd829 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -359,8 +359,8 @@ "working.claimed": "You successfully claimed the plot .", "working.progress": "Current progress: %", "working.component_complete": "Component generation has finished for plot .", - "list.comment_list_header_paged": "(Page /) List of comments", - "list.comment_list_comment": "[#[;][]\n", + "list.comment_list_header_paged": "(Page /) List of comment(s):", + "list.comment_list_comment": "[#] [;] []: \n", "list.comment_list_by_lister": "", "list.comment_list_by_other": "", "list.clickable": " (interactive)",