use of com.plotsquared.core.plot.comment.PlotComment in project PlotSquared by IntellectualSites.
the class Inbox method displayComments.
public void displayComments(PlotPlayer<?> player, List<PlotComment> oldComments, int page) {
if (oldComments == null || oldComments.isEmpty()) {
player.sendMessage(TranslatableCaption.of("comment.inbox_empty"));
return;
}
PlotComment[] comments = oldComments.toArray(new PlotComment[0]);
if (page < 0) {
page = 0;
}
// Get the total pages
// int totalPages = ((int) Math.ceil(12 *
int totalPages = (int) Math.ceil(comments.length / 12);
if (page > totalPages) {
page = totalPages;
}
// Only display 12 per page
int max = page * 12 + 12;
if (max > comments.length) {
max = comments.length;
}
TextComponent.Builder builder = Component.text();
builder.append(MINI_MESSAGE.parse(TranslatableCaption.of("list.comment_list_header_paged").getComponent(player) + '\n', Template.of("amount", String.valueOf(comments.length)), Template.of("cur", String.valueOf(page + 1)), Template.of("max", String.valueOf(totalPages + 1)), Template.of("word", "all")));
// This might work xD
for (int x = page * 12; x < max; x++) {
PlotComment comment = comments[x];
Component commentColored;
if (player.getName().equals(comment.senderName)) {
commentColored = MINI_MESSAGE.parse(TranslatableCaption.of("list.comment_list_by_lister").getComponent(player), Template.of("comment", comment.comment));
} else {
commentColored = MINI_MESSAGE.parse(TranslatableCaption.of("list.comment_list_by_other").getComponent(player), Template.of("comment", comment.comment));
}
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 commenter = Template.of("commenter", comment.senderName);
Template commentTemplate = Template.of("comment", commentColored);
builder.append(MINI_MESSAGE.parse(TranslatableCaption.of("list.comment_list_comment").getComponent(player), number, world, plot_id, commenter, commentTemplate));
}
player.sendMessage(StaticCaption.of(MINI_MESSAGE.serialize(builder.build())));
}
use of com.plotsquared.core.plot.comment.PlotComment in project PlotSquared by IntellectualSites.
the class Inbox method onCommand.
@Override
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
final Plot plot = player.getCurrentPlot();
if (plot == null) {
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
return false;
}
if (!plot.hasOwner()) {
player.sendMessage(TranslatableCaption.of("info.plot_unowned"));
return false;
}
if (args.length == 0) {
sendUsage(player);
for (final CommentInbox inbox : CommentManager.inboxes.values()) {
if (inbox.canRead(plot, player)) {
if (!inbox.getComments(plot, new RunnableVal<>() {
@Override
public void run(List<PlotComment> value) {
if (value != null) {
int total = 0;
int unread = 0;
for (PlotComment comment : value) {
total++;
if (comment.timestamp > CommentManager.getTimestamp(player, inbox.toString())) {
unread++;
}
}
if (total != 0) {
player.sendMessage(TranslatableCaption.of("comment.inbox_item"), Template.of("value", inbox + " (" + total + '/' + unread + ')'));
return;
}
}
player.sendMessage(TranslatableCaption.of("comment.inbox_item"), Template.of("value", inbox.toString()));
}
})) {
player.sendMessage(TranslatableCaption.of("comment.inbox_item"), Template.of("value", inbox.toString()));
}
}
}
return false;
}
final CommentInbox inbox = CommentManager.inboxes.get(args[0].toLowerCase());
if (inbox == null) {
player.sendMessage(TranslatableCaption.of("comment.invalid_inbox"), Template.of("list", StringMan.join(CommentManager.inboxes.keySet(), ", ")));
return false;
}
final MetaDataKey<Long> metaDataKey = MetaDataKey.of(String.format("inbox:%s", inbox), new TypeLiteral<>() {
});
try (final MetaDataAccess<Long> metaDataAccess = player.accessTemporaryMetaData(metaDataKey)) {
metaDataAccess.set(System.currentTimeMillis());
}
final int page;
if (args.length > 1) {
switch(args[1].toLowerCase()) {
case "delete":
if (!inbox.canModify(plot, player)) {
player.sendMessage(TranslatableCaption.of("comment.no_perm_inbox_modify"));
return false;
}
if (args.length != 3) {
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"), Template.of("value", "/plot inbox " + inbox + " delete <index>"));
return true;
}
final int index;
try {
index = Integer.parseInt(args[2]);
if (index < 1) {
player.sendMessage(TranslatableCaption.of("comment.not_valid_inbox_index"), Templates.of("number", index));
return false;
}
} catch (NumberFormatException ignored) {
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"), Template.of("value", "/plot inbox " + inbox + " delete <index>"));
return false;
}
if (!inbox.getComments(plot, new RunnableVal<>() {
@Override
public void run(List<PlotComment> value) {
if (index > value.size()) {
player.sendMessage(TranslatableCaption.of("comment.not_valid_inbox_index"), Templates.of("number", index));
return;
}
PlotComment comment = value.get(index - 1);
inbox.removeComment(plot, comment);
boolean success = plot.getPlotCommentContainer().removeComment(comment);
if (success) {
player.sendMessage(TranslatableCaption.of("comment.comment_removed_success"), Template.of("value", comment.comment));
} else {
player.sendMessage(TranslatableCaption.of("comment.comment_removed_failure"));
}
}
})) {
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
return false;
}
return true;
case "clear":
if (!inbox.canModify(plot, player)) {
player.sendMessage(TranslatableCaption.of("comment.no_perm_inbox_modify"));
}
inbox.clearInbox(plot);
List<PlotComment> 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);
}
return true;
default:
try {
page = Integer.parseInt(args[1]);
} catch (NumberFormatException ignored) {
sendUsage(player);
return false;
}
}
} else {
page = 1;
}
if (!inbox.canRead(plot, player)) {
player.sendMessage(TranslatableCaption.of("comment.no_perm_inbox"));
return false;
}
if (!inbox.getComments(plot, new RunnableVal<>() {
@Override
public void run(List<PlotComment> value) {
displayComments(player, value, page);
}
})) {
player.sendMessage(TranslatableCaption.of("info.plot_unowned"));
return false;
}
return true;
}
use of com.plotsquared.core.plot.comment.PlotComment in project PlotSquared by IntellectualSites.
the class Comment method onCommand.
@Override
public boolean onCommand(PlotPlayer<?> player, String[] args) {
if (args.length < 2) {
player.sendMessage(TranslatableCaption.of("comment.comment_syntax"), Template.of("command", "/plot comment [X;Z]"), Template.of("list", StringMan.join(CommentManager.inboxes.keySet(), "|")));
return false;
}
// Attempt to extract a plot out of the first argument
Plot plot = null;
if (!CommentManager.inboxes.containsKey(args[0].toLowerCase(Locale.ENGLISH))) {
plot = Plot.getPlotFromString(player, args[0], false);
}
int index;
if (plot == null) {
index = 1;
plot = player.getLocation().getPlotAbs();
} else {
if (args.length < 3) {
player.sendMessage(TranslatableCaption.of("comment.comment_syntax"), Template.of("command", "/plot comment [X;Z]"), Template.of("list", StringMan.join(CommentManager.inboxes.keySet(), "|")));
return false;
}
index = 2;
}
CommentInbox inbox = CommentManager.inboxes.get(args[index - 1].toLowerCase());
if (inbox == null) {
player.sendMessage(TranslatableCaption.of("comment.comment_syntax"), Template.of("command", "/plot comment [X;Z]"), Template.of("list", StringMan.join(CommentManager.inboxes.keySet(), "|")));
return false;
}
if (!inbox.canWrite(plot, player)) {
player.sendMessage(TranslatableCaption.of("comment.no_perm_inbox"));
return false;
}
String message = StringMan.join(Arrays.copyOfRange(args, index, args.length), " ");
PlotComment comment = new PlotComment(player.getLocation().getWorldName(), plot.getId(), message, player.getName(), inbox.toString(), System.currentTimeMillis());
boolean result = inbox.addComment(plot, comment);
if (!result) {
player.sendMessage(TranslatableCaption.of("comment.no_plot_inbox"));
player.sendMessage(TranslatableCaption.of("comment.comment_syntax"), Template.of("command", "/plot comment [X;Z]"), Template.of("list", StringMan.join(CommentManager.inboxes.keySet(), "|")));
return false;
}
for (final PlotPlayer<?> pp : PlotSquared.platform().playerManager().getPlayers()) {
if (pp.getAttribute("chatspy")) {
pp.sendMessage(StaticCaption.of("/plot comment " + StringMan.join(args, " ")));
}
}
player.sendMessage(TranslatableCaption.of("comment.comment_added"));
return true;
}
Aggregations