This commit is contained in:
Alexander Söderberg
2020-02-19 23:11:05 +01:00
parent 989d1c57d6
commit 3ffa6cdb6c

View File

@ -2,9 +2,7 @@ package com.github.intellectualsites.plotsquared.plot.commands;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.object.comment.CommentInbox; import com.github.intellectualsites.plotsquared.plot.object.comment.CommentInbox;
import com.github.intellectualsites.plotsquared.plot.object.comment.PlotComment; import com.github.intellectualsites.plotsquared.plot.object.comment.PlotComment;
@ -14,6 +12,7 @@ import com.github.intellectualsites.plotsquared.plot.util.StringMan;
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
import java.util.Arrays; import java.util.Arrays;
import java.util.Locale;
import java.util.Map.Entry; import java.util.Map.Entry;
@CommandDeclaration(command = "comment", aliases = {"msg"}, description = "Comment on a plot", @CommandDeclaration(command = "comment", aliases = {"msg"}, description = "Comment on a plot",
@ -26,40 +25,41 @@ public class Comment extends SubCommand {
StringMan.join(CommentManager.inboxes.keySet(), "|")); StringMan.join(CommentManager.inboxes.keySet(), "|"));
return false; return false;
} }
CommentInbox inbox = CommentManager.inboxes.get(args[0].toLowerCase());
if (inbox == null) { // Attempt to extract a plot out of the first argument
sendMessage(player, Captions.COMMENT_SYNTAX, Plot plot = null;
StringMan.join(CommentManager.inboxes.keySet(), "|")); if (!CommentManager.inboxes.containsKey(args[0].toLowerCase(Locale.ENGLISH))) {
return false; plot = MainUtil.getPlotFromString(player, args[0], false);
} }
Location location = player.getLocation();
PlotId id;
try {
id = PlotId.fromString(args[1]);
} catch (IllegalArgumentException ignored) {
MainUtil.sendMessage(player, Captions.NOT_VALID_PLOT_ID);
return false;
}
Plot plot = MainUtil.getPlotFromString(player, args[1], false);
int index; int index;
if (plot == null) { if (plot == null) {
index = 1; index = 1;
plot = location.getPlotAbs(); plot = player.getLocation().getPlotAbs();
} else { } else {
if (args.length < 4) { if (args.length < 3) {
sendMessage(player, Captions.COMMENT_SYNTAX, sendMessage(player, Captions.COMMENT_SYNTAX,
StringMan.join(CommentManager.inboxes.keySet(), "|")); StringMan.join(CommentManager.inboxes.keySet(), "|"));
return false; return false;
} }
index = 2; index = 2;
} }
CommentInbox inbox = CommentManager.inboxes.get(args[index - 1].toLowerCase());
if (inbox == null) {
sendMessage(player, Captions.COMMENT_SYNTAX,
StringMan.join(CommentManager.inboxes.keySet(), "|"));
return false;
}
if (!inbox.canWrite(plot, player)) { if (!inbox.canWrite(plot, player)) {
sendMessage(player, Captions.NO_PERM_INBOX, ""); sendMessage(player, Captions.NO_PERM_INBOX, "");
return false; return false;
} }
String message = StringMan.join(Arrays.copyOfRange(args, index, args.length), " "); String message = StringMan.join(Arrays.copyOfRange(args, index, args.length), " ");
PlotComment comment = PlotComment comment =
new PlotComment(location.getWorld(), id, message, player.getName(), inbox.toString(), new PlotComment(player.getLocation().getWorld(), plot.getId(), message, player.getName(), inbox.toString(),
System.currentTimeMillis()); System.currentTimeMillis());
boolean result = inbox.addComment(plot, comment); boolean result = inbox.addComment(plot, comment);
if (!result) { if (!result) {