mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 21:26:45 +01:00
Fixes #2654
This commit is contained in:
parent
989d1c57d6
commit
3ffa6cdb6c
@ -2,9 +2,7 @@ package com.github.intellectualsites.plotsquared.plot.commands;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
|
||||
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.PlotId;
|
||||
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.PlotComment;
|
||||
@ -14,6 +12,7 @@ import com.github.intellectualsites.plotsquared.plot.util.StringMan;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@CommandDeclaration(command = "comment", aliases = {"msg"}, description = "Comment on a plot",
|
||||
@ -26,40 +25,41 @@ public class Comment extends SubCommand {
|
||||
StringMan.join(CommentManager.inboxes.keySet(), "|"));
|
||||
return false;
|
||||
}
|
||||
CommentInbox inbox = CommentManager.inboxes.get(args[0].toLowerCase());
|
||||
if (inbox == null) {
|
||||
sendMessage(player, Captions.COMMENT_SYNTAX,
|
||||
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 = 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;
|
||||
if (plot == null) {
|
||||
index = 1;
|
||||
plot = location.getPlotAbs();
|
||||
plot = player.getLocation().getPlotAbs();
|
||||
} else {
|
||||
if (args.length < 4) {
|
||||
if (args.length < 3) {
|
||||
sendMessage(player, Captions.COMMENT_SYNTAX,
|
||||
StringMan.join(CommentManager.inboxes.keySet(), "|"));
|
||||
return false;
|
||||
}
|
||||
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)) {
|
||||
sendMessage(player, Captions.NO_PERM_INBOX, "");
|
||||
return false;
|
||||
}
|
||||
|
||||
String message = StringMan.join(Arrays.copyOfRange(args, index, args.length), " ");
|
||||
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());
|
||||
boolean result = inbox.addComment(plot, comment);
|
||||
if (!result) {
|
||||
|
Loading…
Reference in New Issue
Block a user