Fixup inbox javadocs

This commit is contained in:
NotMyFault 2021-04-30 19:04:44 +02:00
parent 812442fbbc
commit 11af33f2d5
No known key found for this signature in database
GPG Key ID: 158F5701A6AAD00C
7 changed files with 57 additions and 23 deletions

View File

@ -57,7 +57,7 @@ import java.util.stream.Collectors;
requiredType = RequiredType.PLAYER) requiredType = RequiredType.PLAYER)
public class Inbox extends SubCommand { public class Inbox extends SubCommand {
public void displayComments(PlotPlayer player, List<PlotComment> oldComments, int page) { public void displayComments(PlotPlayer<?> player, List<PlotComment> oldComments, int page) {
if (oldComments == null || oldComments.isEmpty()) { if (oldComments == null || oldComments.isEmpty()) {
player.sendMessage(TranslatableCaption.of("comment.inbox_empty")); player.sendMessage(TranslatableCaption.of("comment.inbox_empty"));
return; return;
@ -102,7 +102,7 @@ public class Inbox extends SubCommand {
} }
Template number = Template.of("number", String.valueOf(x)); Template number = Template.of("number", String.valueOf(x));
Template world = Template.of("world", comment.world); 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 commenter = Template.of("commenter", comment.senderName);
Template commentTemplate = Template.of("comment", commentColored); Template commentTemplate = Template.of("comment", commentColored);
builder.append(MINI_MESSAGE builder.append(MINI_MESSAGE
@ -133,7 +133,7 @@ public class Inbox extends SubCommand {
sendUsage(player); sendUsage(player);
for (final CommentInbox inbox : CommentManager.inboxes.values()) { for (final CommentInbox inbox : CommentManager.inboxes.values()) {
if (inbox.canRead(plot, player)) { if (inbox.canRead(plot, player)) {
if (!inbox.getComments(plot, new RunnableVal<List<PlotComment>>() { if (!inbox.getComments(plot, new RunnableVal<>() {
@Override @Override
public void run(List<PlotComment> value) { public void run(List<PlotComment> value) {
if (value != null) { if (value != null) {
@ -179,7 +179,7 @@ public class Inbox extends SubCommand {
} }
final MetaDataKey<Long> metaDataKey = MetaDataKey.of( final MetaDataKey<Long> metaDataKey = MetaDataKey.of(
String.format("inbox:%s", inbox.toString()), String.format("inbox:%s", inbox.toString()),
new TypeLiteral<Long>() { new TypeLiteral<>() {
} }
); );
try (final MetaDataAccess<Long> metaDataAccess = player.accessTemporaryMetaData(metaDataKey)) { try (final MetaDataAccess<Long> metaDataAccess = player.accessTemporaryMetaData(metaDataKey)) {
@ -217,7 +217,7 @@ public class Inbox extends SubCommand {
return false; return false;
} }
if (!inbox.getComments(plot, new RunnableVal<List<PlotComment>>() { if (!inbox.getComments(plot, new RunnableVal<>() {
@Override @Override
public void run(List<PlotComment> value) { public void run(List<PlotComment> value) {
if (index > value.size()) { if (index > value.size()) {
@ -238,8 +238,6 @@ public class Inbox extends SubCommand {
} else { } else {
player.sendMessage( player.sendMessage(
TranslatableCaption.of("comment.comment_removed_failure")); TranslatableCaption.of("comment.comment_removed_failure"));
} }
} }
})) { })) {
@ -254,12 +252,12 @@ public class Inbox extends SubCommand {
inbox.clearInbox(plot); inbox.clearInbox(plot);
List<PlotComment> comments = plot.getPlotCommentContainer().getComments(inbox.toString()); List<PlotComment> comments = plot.getPlotCommentContainer().getComments(inbox.toString());
if (!comments.isEmpty()) { if (!comments.isEmpty()) {
plot.getPlotCommentContainer().removeComments(comments);
}
player.sendMessage( player.sendMessage(
TranslatableCaption.of("comment.comment_removed_success"), TranslatableCaption.of("comment.comment_removed_success"),
Template.of("value", "*") Template.of("value", String.valueOf(comments))
); );
plot.getPlotCommentContainer().removeComments(comments);
}
return true; return true;
default: default:
try { try {
@ -276,7 +274,7 @@ public class Inbox extends SubCommand {
player.sendMessage(TranslatableCaption.of("comment.no_perm_inbox")); player.sendMessage(TranslatableCaption.of("comment.no_perm_inbox"));
return false; return false;
} }
if (!inbox.getComments(plot, new RunnableVal<List<PlotComment>>() { if (!inbox.getComments(plot, new RunnableVal<>() {
@Override @Override
public void run(List<PlotComment> value) { public void run(List<PlotComment> value) {
displayComments(player, value, page); displayComments(player, value, page);

View File

@ -38,7 +38,12 @@ public abstract class CommentInbox {
@Override @Override
public abstract String toString(); 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)) { if (Permissions.hasPermission(player, "plots.inbox.read." + toString(), true)) {
return plot.isOwner(player.getUUID()) || Permissions return plot.isOwner(player.getUUID()) || Permissions
.hasPermission(player, "plots.inbox.read." + toString() + ".other", true); .hasPermission(player, "plots.inbox.read." + toString() + ".other", true);
@ -46,7 +51,12 @@ public abstract class CommentInbox {
return false; 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) { if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.write." + toString(), true); 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)); .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)) { if (Permissions.hasPermission(player, "plots.inbox.modify." + toString(), true)) {
return plot.isOwner(player.getUUID()) || Permissions return plot.isOwner(player.getUUID()) || Permissions
.hasPermission(player, "plots.inbox.modify." + toString() + ".other", true); .hasPermission(player, "plots.inbox.modify." + toString() + ".other", true);
@ -74,12 +90,24 @@ public abstract class CommentInbox {
*/ */
public abstract boolean getComments(Plot plot, RunnableVal<List<PlotComment>> whenDone); public abstract boolean getComments(Plot plot, RunnableVal<List<PlotComment>> whenDone);
/**
* @param plot plot
* @param comment the comment to add
* @return success or not
*/
public abstract boolean addComment(Plot plot, PlotComment comment); public abstract boolean addComment(Plot plot, PlotComment comment);
/**
* @param plot plot
* @param comment the comment to remove
*/
public void removeComment(Plot plot, PlotComment comment) { public void removeComment(Plot plot, PlotComment comment) {
DBFunc.removeComment(plot, comment); DBFunc.removeComment(plot, comment);
} }
/**
* @param plot plot
*/
public void clearInbox(Plot plot) { public void clearInbox(Plot plot) {
DBFunc.clearInbox(plot, toString()); DBFunc.clearInbox(plot, toString());
} }

View File

@ -49,7 +49,7 @@ public class CommentManager {
public static final HashMap<String, CommentInbox> inboxes = new HashMap<>(); public static final HashMap<String, CommentInbox> 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())) { if (!Settings.Enabled_Components.COMMENT_NOTIFIER || !plot.isOwner(player.getUUID())) {
return; return;
} }
@ -58,7 +58,7 @@ public class CommentManager {
final AtomicInteger count = new AtomicInteger(0); final AtomicInteger count = new AtomicInteger(0);
final AtomicInteger size = new AtomicInteger(boxes.size()); final AtomicInteger size = new AtomicInteger(boxes.size());
for (final CommentInbox inbox : inboxes.values()) { for (final CommentInbox inbox : inboxes.values()) {
inbox.getComments(plot, new RunnableVal<List<PlotComment>>() { inbox.getComments(plot, new RunnableVal<>() {
@Override @Override
public void run(List<PlotComment> value) { public void run(List<PlotComment> value) {
int total; int total;
@ -87,14 +87,22 @@ public class CommentManager {
}, TaskTime.seconds(1L)); }, 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) { public static long getTimestamp(PlotPlayer<?> player, String inbox) {
final MetaDataKey<Long> inboxKey = MetaDataKey.of(String.format("inbox:%s", inbox), new TypeLiteral<Long>() { final MetaDataKey<Long> inboxKey = MetaDataKey.of(String.format("inbox:%s", inbox), new TypeLiteral<>() {
}); });
try (final MetaDataAccess<Long> inboxAccess = player.accessTemporaryMetaData(inboxKey)) { try (final MetaDataAccess<Long> inboxAccess = player.accessTemporaryMetaData(inboxKey)) {
return inboxAccess.get().orElse(player.getLastPlayed()); return inboxAccess.get().orElse(player.getLastPlayed());
} }
} }
/**
* @param inbox the inbox to add
*/
public static void addInbox(CommentInbox inbox) { public static void addInbox(CommentInbox inbox) {
inboxes.put(inbox.toString().toLowerCase(), inbox); inboxes.put(inbox.toString().toLowerCase(), inbox);
} }

View File

@ -43,7 +43,7 @@ public class InboxOwner extends CommentInbox {
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
return true; return true;
} }
DBFunc.getComments(plot, toString(), new RunnableVal<List<PlotComment>>() { DBFunc.getComments(plot, toString(), new RunnableVal<>() {
@Override @Override
public void run(List<PlotComment> value) { public void run(List<PlotComment> value) {
whenDone.value = value; whenDone.value = value;

View File

@ -42,7 +42,7 @@ public class InboxPublic extends CommentInbox {
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
return true; return true;
} }
DBFunc.getComments(plot, toString(), new RunnableVal<List<PlotComment>>() { DBFunc.getComments(plot, toString(), new RunnableVal<>() {
@Override @Override
public void run(List<PlotComment> value) { public void run(List<PlotComment> value) {
whenDone.value = value; whenDone.value = value;

View File

@ -36,7 +36,7 @@ public class InboxReport extends CommentInbox {
@Override @Override
public boolean getComments(Plot plot, final RunnableVal<List<PlotComment>> whenDone) { public boolean getComments(Plot plot, final RunnableVal<List<PlotComment>> whenDone) {
DBFunc.getComments(plot, toString(), new RunnableVal<List<PlotComment>>() { DBFunc.getComments(plot, toString(), new RunnableVal<>() {
@Override @Override
public void run(List<PlotComment> value) { public void run(List<PlotComment> value) {
whenDone.value = value; whenDone.value = value;

View File

@ -359,8 +359,8 @@
"working.claimed": "<prefix><dark_aqua>You successfully claimed the plot <plot>.</dark_aqua>", "working.claimed": "<prefix><dark_aqua>You successfully claimed the plot <plot>.</dark_aqua>",
"working.progress": "<prefix><gray>Current progress: </gray><gold><progress></gold><gray>%</gray>", "working.progress": "<prefix><gray>Current progress: </gray><gold><progress></gold><gray>%</gray>",
"working.component_complete": "<prefix><gold>Component generation has finished for plot <plot>.</gold>", "working.component_complete": "<prefix><gold>Component generation has finished for plot <plot>.</gold>",
"list.comment_list_header_paged": "<gray>(Page </gray><gold><cur></gold><gray>/</gray><gold><max></gold><gray>) </gray><gold>List of <amount> comments</gold>", "list.comment_list_header_paged": "<gray>(Page </gray><gold><cur></gold><gray>/</gray><gold><max></gold><gray>) </gray><gold>List of <amount> comment(s):</gold>",
"list.comment_list_comment": "<dark_gray>[</dark_gray><gray>#<number></gray><dark_gray>[</dark_gray><gray><world>;<plot_id></gray><dark_gray>][</dark_gray><gold><commenter></gold><dark_gray>]</dark_gray><comment>\n", "list.comment_list_comment": "<dark_gray>[</dark_gray><gray>#<number></gray><dark_gray>] [</dark_gray><gray><world>;<plot_id></gray><dark_gray>] [</dark_gray><gold><commenter></gold><dark_gray>]: </dark_gray><comment>\n",
"list.comment_list_by_lister": "<green><comment></green>", "list.comment_list_by_lister": "<green><comment></green>",
"list.comment_list_by_other": "<gray><comment></gray>", "list.comment_list_by_other": "<gray><comment></gray>",
"list.clickable": "<gray> (interactive)</gray>", "list.clickable": "<gray> (interactive)</gray>",