diff --git a/Essentials/src/com/earth2me/essentials/Console.java b/Essentials/src/com/earth2me/essentials/Console.java index 23db84039..2b442d2c8 100644 --- a/Essentials/src/com/earth2me/essentials/Console.java +++ b/Essentials/src/com/earth2me/essentials/Console.java @@ -50,6 +50,10 @@ public final class Console implements IMessageRecipient { @Override public void sendMessage(String message) { getCommandSender().sendMessage(message); } + + @Override public boolean isReachable() { + return true; + } /* ================================ * >> DELEGATE METHODS diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java index 18917fa02..9b7a88edf 100644 --- a/Essentials/src/com/earth2me/essentials/User.java +++ b/Essentials/src/com/earth2me/essentials/User.java @@ -717,6 +717,10 @@ public class User extends UserData implements Comparable, IMessageRecipien public String getName() { return this.getBase().getName(); } + + @Override public boolean isReachable() { + return getBase().isOnline(); + } @Override public MessageResponse sendMessage(IMessageRecipient recipient, String message) { return this.messageRecipient.sendMessage(recipient, message); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandr.java b/Essentials/src/com/earth2me/essentials/commands/Commandr.java index f82f1c635..9907eda23 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandr.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandr.java @@ -34,9 +34,8 @@ public class Commandr extends EssentialsCommand { } 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())) { + // Check to make sure the sender does have a quick-reply recipient + if (target == null) { throw new Exception(tl("foreverAlone")); } messageSender.sendMessage(target, message); diff --git a/Essentials/src/com/earth2me/essentials/messaging/IMessageRecipient.java b/Essentials/src/com/earth2me/essentials/messaging/IMessageRecipient.java index bf2d9c8b9..d30eb91b9 100644 --- a/Essentials/src/com/earth2me/essentials/messaging/IMessageRecipient.java +++ b/Essentials/src/com/earth2me/essentials/messaging/IMessageRecipient.java @@ -56,6 +56,13 @@ public interface IMessageRecipient { */ String getDisplayName(); + /** + * Returns whether this recipient is reachable. A case where the recipient is not reachable is if they are offline. + * + * @return whether this recipient is reachable + */ + boolean isReachable(); + /** * Returns the {@link IMessageRecipient} this recipient should send replies to. * @@ -82,7 +89,9 @@ public interface IMessageRecipient { /** States that the message was NOT received as a result of the receiver ignoring all messages. */ MESSAGES_IGNORED, /** States that the message was NOT received as a result of the sender being ignored by the recipient. */ - SENDER_IGNORED; + SENDER_IGNORED, + /** States that the message was NOT received as a result of the recipient being unreachable. */ + UNREACHABLE; /** * Returns whether this response is a success. In other words equal to {@link #SUCCESS} or {@link #SUCCESS_BUT_AFK} diff --git a/Essentials/src/com/earth2me/essentials/messaging/SimpleMessageRecipient.java b/Essentials/src/com/earth2me/essentials/messaging/SimpleMessageRecipient.java index a3284ef63..5bdda34e6 100644 --- a/Essentials/src/com/earth2me/essentials/messaging/SimpleMessageRecipient.java +++ b/Essentials/src/com/earth2me/essentials/messaging/SimpleMessageRecipient.java @@ -23,6 +23,7 @@ import java.lang.ref.WeakReference; *
  • {@link IMessageRecipient#sendMessage(String)}
  • *
  • {@link IMessageRecipient#getName()}
  • *
  • {@link IMessageRecipient#getDisplayName()}
  • + *
  • {@link IMessageRecipient#isReachable()}
  • * * * The reply-recipient is wrapped in a {@link WeakReference}. @@ -56,6 +57,8 @@ public class SimpleMessageRecipient implements IMessageRecipient { @Override public MessageResponse sendMessage(IMessageRecipient recipient, String message) { MessageResponse messageResponse = recipient.onReceiveMessage(this.parent, message); switch (messageResponse) { + case UNREACHABLE: + sendMessage(tl("recentlyForeverAlone", recipient.getDisplayName())); case MESSAGES_IGNORED: sendMessage(tl("msgIgnore", recipient.getDisplayName())); break; @@ -79,6 +82,10 @@ public class SimpleMessageRecipient implements IMessageRecipient { @Override public MessageResponse onReceiveMessage(IMessageRecipient sender, String message) { + if (!isReachable()) { + return MessageResponse.UNREACHABLE; + } + User user = this.parent instanceof User ? (User) this.parent : null; boolean afk = false; if (user != null) { @@ -98,7 +105,7 @@ public class SimpleMessageRecipient implements IMessageRecipient { if (ess.getSettings().isLastMessageReplyRecipient()) { // If this recipient doesn't have a reply recipient, initiate by setting the first // message sender to this recipient's replyRecipient. - if (getReplyRecipient() == null) { + if (!isReachable()) { setReplyRecipient(sender); } } else { // Old message functionality, always set the reply recipient to the last person who sent us a message. @@ -107,6 +114,10 @@ public class SimpleMessageRecipient implements IMessageRecipient { return afk ? MessageResponse.SUCCESS_BUT_AFK : MessageResponse.SUCCESS; } + @Override public boolean isReachable() { + return this.parent.isReachable(); + } + /** * {@inheritDoc} *

    diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index b25851730..d792aeef4 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -121,6 +121,7 @@ fireworkSyntax=\u00a76Firework parameters\:\u00a7c color\: [fade\: flyMode=\u00a76Set fly mode\u00a7c {0} \u00a76for {1}\u00a76. flying=flying foreverAlone=\u00a74You have nobody to whom you can reply. +recentlyForeverAlone=\u00a74{0} recently went offline. fullStack=\u00a74You already have a full stack. gameMode=\u00a76Set game mode\u00a7c {0} \u00a76for \u00a7c{1}\u00a76. gcWorld=\u00a76{0} "\u00a7c{1}\u00a76"\: \u00a7c{2}\u00a76 chunks, \u00a7c{3}\u00a76 entities, \u00a7c{4}\u00a76 tiles.