mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 21:26:45 +01:00
PlotComment API tweaks.
Signed-off-by: matt <4009945+MattBDev@users.noreply.github.com>
This commit is contained in:
parent
6ec6c26a10
commit
9101cb9218
@ -11,14 +11,10 @@ import com.github.intellectualsites.plotsquared.plot.util.CommentManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@CommandDeclaration(command = "inbox", description = "Review the comments for a plot",
|
||||
usage = "/plot inbox [inbox] [delete <index>|clear|page]", permission = "plots.inbox",
|
||||
category = CommandCategory.CHAT, requiredType = RequiredType.NONE) public class Inbox
|
||||
extends SubCommand {
|
||||
@CommandDeclaration(command = "inbox", description = "Review the comments for a plot", usage = "/plot inbox [inbox] [delete <index>|clear|page]", permission = "plots.inbox", category = CommandCategory.CHAT, requiredType = RequiredType.NONE)
|
||||
public class Inbox extends SubCommand {
|
||||
|
||||
public void displayComments(PlotPlayer player, List<PlotComment> oldComments, int page) {
|
||||
if (oldComments == null || oldComments.isEmpty()) {
|
||||
@ -150,7 +146,7 @@ import java.util.Optional;
|
||||
}
|
||||
PlotComment comment = value.get(index - 1);
|
||||
inbox.removeComment(plot, comment);
|
||||
plot.getSettings().removeComment(comment);
|
||||
plot.removeComment(comment);
|
||||
MainUtil.sendMessage(player, C.COMMENT_REMOVED, comment.comment);
|
||||
}
|
||||
})) {
|
||||
@ -163,10 +159,9 @@ import java.util.Optional;
|
||||
sendMessage(player, C.NO_PERM_INBOX_MODIFY);
|
||||
}
|
||||
inbox.clearInbox(plot);
|
||||
Optional<ArrayList<PlotComment>> comments =
|
||||
plot.getSettings().getComments(inbox.toString());
|
||||
if (comments.isPresent()) {
|
||||
plot.getSettings().removeComments(comments.get());
|
||||
List<PlotComment> comments = plot.getComments(inbox.toString());
|
||||
if (!comments.isEmpty()) {
|
||||
plot.removeComments(comments);
|
||||
}
|
||||
MainUtil.sendMessage(player, C.COMMENT_REMOVED, "*");
|
||||
return true;
|
||||
|
@ -10,6 +10,7 @@ import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.SquarePlotWorld;
|
||||
import com.github.intellectualsites.plotsquared.plot.listener.PlotListener;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.comment.PlotComment;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.schematic.Schematic;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.*;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue;
|
||||
@ -2991,4 +2992,24 @@ public class Plot {
|
||||
public boolean hasFlag(Flag<?> flag) {
|
||||
return getFlags().containsKey(flag);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") public boolean removeComment(PlotComment comment) {
|
||||
return getSettings().removeComment(comment);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") public void removeComments(List<PlotComment> comments) {
|
||||
getSettings().removeComments(comments);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") public List<PlotComment> getComments(String inbox) {
|
||||
return getSettings().getComments(inbox);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") public void addComment(PlotComment comment) {
|
||||
getSettings().addComment(comment);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") public void setComments(List<PlotComment> list) {
|
||||
getSettings().setComments(list);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.github.intellectualsites.plotsquared.plot.object;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.comment.PlotComment;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -25,12 +26,8 @@ public class PlotSettings {
|
||||
* @deprecated Raw access
|
||||
*/
|
||||
@Deprecated public String alias = "";
|
||||
/**
|
||||
* Comments.
|
||||
*
|
||||
* @deprecated Raw access
|
||||
*/
|
||||
@Deprecated public List<PlotComment> comments = null;
|
||||
|
||||
private List<PlotComment> comments = null;
|
||||
|
||||
/**
|
||||
* The ratings for a plot.
|
||||
@ -142,36 +139,31 @@ public class PlotSettings {
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<ArrayList<PlotComment>> getComments(String inbox) {
|
||||
ArrayList<PlotComment> c = new ArrayList<>();
|
||||
@SuppressWarnings({"UnstableApiUsage"}) public List<PlotComment> getComments(String inbox) {
|
||||
if (this.comments == null) {
|
||||
return Optional.empty();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
for (PlotComment comment : this.comments) {
|
||||
if (comment.inbox.equals(inbox)) {
|
||||
c.add(comment);
|
||||
}
|
||||
}
|
||||
return Optional.of(c);
|
||||
|
||||
return this.comments.stream().filter(comment -> comment.inbox.equals(inbox))
|
||||
.collect(ImmutableList.toImmutableList());
|
||||
}
|
||||
|
||||
public void setComments(List<PlotComment> comments) {
|
||||
void setComments(List<PlotComment> comments) {
|
||||
this.comments = comments;
|
||||
}
|
||||
|
||||
public void removeComment(PlotComment comment) {
|
||||
if (this.comments.contains(comment)) {
|
||||
this.comments.remove(comment);
|
||||
boolean removeComment(PlotComment comment) {
|
||||
if (this.comments == null) {
|
||||
return false;
|
||||
}
|
||||
return this.comments.remove(comment);
|
||||
}
|
||||
|
||||
public void removeComments(List<PlotComment> comments) {
|
||||
for (PlotComment comment : comments) {
|
||||
removeComment(comment);
|
||||
}
|
||||
void removeComments(List<PlotComment> comments) {
|
||||
comments.forEach(this::removeComment);
|
||||
}
|
||||
|
||||
public void addComment(PlotComment comment) {
|
||||
void addComment(PlotComment comment) {
|
||||
if (this.comments == null) {
|
||||
this.comments = new ArrayList<>();
|
||||
}
|
||||
|
@ -7,15 +7,14 @@ import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class InboxOwner extends CommentInbox {
|
||||
|
||||
@Override
|
||||
public boolean getComments(final Plot plot, final RunnableVal<List<PlotComment>> whenDone) {
|
||||
Optional<ArrayList<PlotComment>> comments = plot.getSettings().getComments(toString());
|
||||
if (comments.isPresent()) {
|
||||
whenDone.value = comments.get();
|
||||
List<PlotComment> comments = plot.getComments(toString());
|
||||
if (!comments.isEmpty()) {
|
||||
whenDone.value = comments;
|
||||
TaskManager.runTask(whenDone);
|
||||
return true;
|
||||
}
|
||||
@ -24,10 +23,10 @@ public class InboxOwner extends CommentInbox {
|
||||
whenDone.value = value;
|
||||
if (value != null) {
|
||||
for (PlotComment comment : value) {
|
||||
plot.getSettings().addComment(comment);
|
||||
plot.addComment(comment);
|
||||
}
|
||||
} else {
|
||||
plot.getSettings().setComments(new ArrayList<PlotComment>());
|
||||
plot.setComments(new ArrayList<>());
|
||||
}
|
||||
TaskManager.runTask(whenDone);
|
||||
}
|
||||
@ -39,7 +38,7 @@ public class InboxOwner extends CommentInbox {
|
||||
if (plot.owner == null) {
|
||||
return false;
|
||||
}
|
||||
plot.getSettings().addComment(comment);
|
||||
plot.addComment(comment);
|
||||
DBFunc.setComment(plot, comment);
|
||||
return true;
|
||||
}
|
||||
|
@ -5,17 +5,15 @@ import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class InboxPublic extends CommentInbox {
|
||||
|
||||
@Override
|
||||
public boolean getComments(final Plot plot, final RunnableVal<List<PlotComment>> whenDone) {
|
||||
Optional<ArrayList<PlotComment>> comments = plot.getSettings().getComments(toString());
|
||||
if (comments.isPresent()) {
|
||||
whenDone.value = comments.get();
|
||||
List<PlotComment> comments = plot.getComments(toString());
|
||||
if (!comments.isEmpty()) {
|
||||
whenDone.value = comments;
|
||||
TaskManager.runTask(whenDone);
|
||||
return true;
|
||||
}
|
||||
@ -24,7 +22,7 @@ public class InboxPublic extends CommentInbox {
|
||||
whenDone.value = value;
|
||||
if (value != null) {
|
||||
for (PlotComment comment : value) {
|
||||
plot.getSettings().addComment(comment);
|
||||
plot.addComment(comment);
|
||||
}
|
||||
}
|
||||
TaskManager.runTask(whenDone);
|
||||
@ -34,7 +32,7 @@ public class InboxPublic extends CommentInbox {
|
||||
}
|
||||
|
||||
@Override public boolean addComment(Plot plot, PlotComment comment) {
|
||||
plot.getSettings().addComment(comment);
|
||||
plot.addComment(comment);
|
||||
DBFunc.setComment(plot, comment);
|
||||
return true;
|
||||
}
|
||||
|
@ -20,34 +20,32 @@ public class CommentManager {
|
||||
if (!Settings.Enabled_Components.COMMENT_NOTIFIER || !plot.isOwner(player.getUUID())) {
|
||||
return;
|
||||
}
|
||||
TaskManager.runTaskLaterAsync(new Runnable() {
|
||||
@Override public void run() {
|
||||
Collection<CommentInbox> boxes = CommentManager.inboxes.values();
|
||||
final AtomicInteger count = new AtomicInteger(0);
|
||||
final AtomicInteger size = new AtomicInteger(boxes.size());
|
||||
for (final CommentInbox inbox : inboxes.values()) {
|
||||
inbox.getComments(plot, new RunnableVal<List<PlotComment>>() {
|
||||
@Override public void run(List<PlotComment> value) {
|
||||
int total;
|
||||
if (value != null) {
|
||||
int num = 0;
|
||||
for (PlotComment comment : value) {
|
||||
if (comment.timestamp > getTimestamp(player,
|
||||
inbox.toString())) {
|
||||
num++;
|
||||
}
|
||||
TaskManager.runTaskLaterAsync(() -> {
|
||||
Collection<CommentInbox> boxes = CommentManager.inboxes.values();
|
||||
final AtomicInteger count = new AtomicInteger(0);
|
||||
final AtomicInteger size = new AtomicInteger(boxes.size());
|
||||
for (final CommentInbox inbox : inboxes.values()) {
|
||||
inbox.getComments(plot, new RunnableVal<List<PlotComment>>() {
|
||||
@Override public void run(List<PlotComment> value) {
|
||||
int total;
|
||||
if (value != null) {
|
||||
int num = 0;
|
||||
for (PlotComment comment : value) {
|
||||
if (comment.timestamp > getTimestamp(player,
|
||||
inbox.toString())) {
|
||||
num++;
|
||||
}
|
||||
total = count.addAndGet(num);
|
||||
} else {
|
||||
total = count.get();
|
||||
}
|
||||
if ((size.decrementAndGet() == 0) && (total > 0)) {
|
||||
AbstractTitle.sendTitle(player, "",
|
||||
C.INBOX_NOTIFICATION.s().replaceAll("%s", "" + total));
|
||||
}
|
||||
total = count.addAndGet(num);
|
||||
} else {
|
||||
total = count.get();
|
||||
}
|
||||
});
|
||||
}
|
||||
if ((size.decrementAndGet() == 0) && (total > 0)) {
|
||||
AbstractTitle.sendTitle(player, "",
|
||||
C.INBOX_NOTIFICATION.s().replaceAll("%s", "" + total));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 20);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user