Rewrote messaging structure for more abstractness.

This commit adds a new boolean-configurable feature called last-message-reply-recipient, defaults to true for new installs and false for old installs, which states whether to use the new messaging functionality or not.
This commit deprecates Console#getCommandSender(Server) and provides Console#getInstance()#getCommandSender() for future usability.
This commit is contained in:
Ali Moghnieh 2015-10-27 17:34:59 +00:00 committed by vemacs
parent 77eb430b0b
commit 447b9db397
14 changed files with 444 additions and 122 deletions

View file

@ -2,8 +2,8 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.Console;
import com.earth2me.essentials.IReplyTo;
import com.earth2me.essentials.User;
import com.earth2me.essentials.messaging.IMessageRecipient;
import com.earth2me.essentials.utils.FormatUtil;
import org.bukkit.Server;
@ -22,43 +22,23 @@ public class Commandr extends EssentialsCommand {
}
String message = getFinalArg(args, 0);
IReplyTo replyTo;
String senderName;
IMessageRecipient messageSender;
if (sender.isPlayer()) {
User user = ess.getUser(sender.getPlayer());
message = FormatUtil.formatMessage(user, "essentials.msg", message);
replyTo = user;
senderName = user.getDisplayName();
messageSender = user;
} else {
message = FormatUtil.replaceFormat(message);
replyTo = Console.getConsoleReplyTo();
senderName = Console.NAME;
messageSender = Console.getInstance();
}
final CommandSource target = replyTo.getReplyTo();
if (target == null || (target.isPlayer() && !target.getPlayer().isOnline())) {
final IMessageRecipient target = messageSender.getReplyRecipient();
// Check to make sure the sender does have a quick-reply recipient, and that the recipient is online.
if (target == null || (target instanceof User && !((User) target).getBase().isOnline())) {
throw new Exception(tl("foreverAlone"));
}
final String targetName = target.isPlayer() ? target.getPlayer().getDisplayName() : Console.NAME;
sender.sendMessage(tl("msgFormat", tl("me"), targetName, message));
if (target.isPlayer()) {
User player = ess.getUser(target.getPlayer());
if (sender.isPlayer() && player.isIgnoredPlayer(ess.getUser(sender.getPlayer()))) {
return;
}
}
target.sendMessage(tl("msgFormat", senderName, tl("me"), message));
replyTo.setReplyTo(target);
if (target != sender) {
if (target.isPlayer()) {
ess.getUser(target.getPlayer()).setReplyTo(sender);
} else {
Console.getConsoleReplyTo().setReplyTo(sender);
}
}
messageSender.sendMessage(target, message);
}
}