use of com.earth2me.essentials.IUser in project Essentials by drtshock.
the class SimpleMessageRecipient method sendMessage.
@Override
public MessageResponse sendMessage(IMessageRecipient recipient, String message) {
MessageResponse messageResponse = recipient.onReceiveMessage(this.parent, message);
switch(messageResponse) {
case UNREACHABLE:
sendMessage(tl("recentlyForeverAlone", recipient.getDisplayName()));
break;
case MESSAGES_IGNORED:
sendMessage(tl("msgIgnore", recipient.getDisplayName()));
break;
case SENDER_IGNORED:
break;
// When this recipient is AFK, notify the sender. Then, proceed to send the message.
case SUCCESS_BUT_AFK:
// Currently, only IUser can be afk, so we unsafely cast to get the afk message.
if (((IUser) recipient).getAfkMessage() != null) {
sendMessage(tl("userAFKWithMessage", recipient.getDisplayName(), ((IUser) recipient).getAfkMessage()));
} else {
sendMessage(tl("userAFK", recipient.getDisplayName()));
}
default:
sendMessage(tl("msgFormat", tl("me"), recipient.getDisplayName(), message));
// Better Social Spy
User senderUser = getUser(this);
User recipientUser = getUser(recipient);
if (// not null if player.
senderUser != null && // Dont spy on chats involving socialspy exempt players
!senderUser.isAuthorized("essentials.chat.spy.exempt") && (recipientUser != null && !recipientUser.isAuthorized("essentials.chat.spy.exempt"))) {
for (User onlineUser : ess.getOnlineUsers()) {
if (onlineUser.isSocialSpyEnabled() && // Don't send socialspy messages to message sender/receiver to prevent spam
!onlineUser.equals(senderUser) && !onlineUser.equals(recipient)) {
onlineUser.sendMessage(tl("socialSpyPrefix") + tl("msgFormat", getDisplayName(), recipient.getDisplayName(), message));
}
}
}
}
// If the message was a success, set this sender's reply-recipient to the current recipient.
if (messageResponse.isSuccess()) {
setReplyRecipient(recipient);
}
return messageResponse;
}
use of com.earth2me.essentials.IUser in project Essentials by drtshock.
the class SimpleMessageRecipient method onReceiveMessage.
@Override
public MessageResponse onReceiveMessage(IMessageRecipient sender, String message) {
if (!isReachable()) {
return MessageResponse.UNREACHABLE;
}
User user = getUser(this);
boolean afk = false;
if (user != null) {
if (user.isIgnoreMsg() && !(sender instanceof Console)) {
// Console must never be ignored.
return MessageResponse.MESSAGES_IGNORED;
}
afk = user.isAfk();
// Check whether this recipient ignores the sender, only if the sender is not the console.
if (sender instanceof IUser && user.isIgnoredPlayer((IUser) sender)) {
return MessageResponse.SENDER_IGNORED;
}
}
// Display the formatted message to this recipient.
sendMessage(tl("msgFormat", sender.getDisplayName(), tl("me"), message));
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.
long timeout = ess.getSettings().getLastMessageReplyRecipientTimeout() * 1000;
if (getReplyRecipient() == null || !getReplyRecipient().isReachable() || System.currentTimeMillis() - this.lastMessageMs > timeout) {
setReplyRecipient(sender);
}
} else {
// Old message functionality, always set the reply recipient to the last person who sent us a message.
setReplyRecipient(sender);
}
this.lastMessageMs = System.currentTimeMillis();
return afk ? MessageResponse.SUCCESS_BUT_AFK : MessageResponse.SUCCESS;
}