mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-13 19:52:03 +01:00
Add isReachable API to IMessageRecipient.
Add translatable message recentlyForeverAlone. Add behaviour that preserves reply-recipient only if they are reachable, and update reply-recipient if they are not reachable. Fixes #248
This commit is contained in:
parent
e5ebeaf724
commit
26045e2ec0
@ -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
|
||||
|
@ -717,6 +717,10 @@ public class User extends UserData implements Comparable<User>, 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);
|
||||
|
@ -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);
|
||||
|
@ -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 <b>NOT</b> received as a result of the receiver ignoring all messages. */
|
||||
MESSAGES_IGNORED,
|
||||
/** States that the message was <b>NOT</b> received as a result of the sender being ignored by the recipient. */
|
||||
SENDER_IGNORED;
|
||||
SENDER_IGNORED,
|
||||
/** States that the message was <b>NOT</b> 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}
|
||||
|
@ -23,6 +23,7 @@ import java.lang.ref.WeakReference;
|
||||
* <li>{@link IMessageRecipient#sendMessage(String)}</li>
|
||||
* <li>{@link IMessageRecipient#getName()}</li>
|
||||
* <li>{@link IMessageRecipient#getDisplayName()}</li>
|
||||
* <li>{@link IMessageRecipient#isReachable()}</li>
|
||||
* </ul>
|
||||
*
|
||||
* 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}
|
||||
* <p />
|
||||
|
@ -121,6 +121,7 @@ fireworkSyntax=\u00a76Firework parameters\:\u00a7c color\:<color> [fade\:<color>
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user