Add permission to bypass other's msgtoggle (#1955) @Xeyame

* Add permission to bypass other's msgtoggle

Also thanks to MD for helping me with the code :)

* Correct comment

* Remove checking for console in favour of the already existing IUser check

* Fix comments, again

* Re add isIgnoreMsg() check

Accidently removed it, sorry

* Combine 2 checks
This commit is contained in:
Xeyame 2018-05-26 21:43:31 +02:00 committed by md678685
parent 817caf299f
commit 7298393ec9

View File

@ -17,7 +17,7 @@ import java.lang.ref.WeakReference;
* <li>{@link IMessageRecipient#getReplyRecipient()}</li> * <li>{@link IMessageRecipient#getReplyRecipient()}</li>
* <li>{@link IMessageRecipient#setReplyRecipient(IMessageRecipient)}</li> * <li>{@link IMessageRecipient#setReplyRecipient(IMessageRecipient)}</li>
* </ul> * </ul>
* *
* <b>The given {@code parent} must implement the following methods to prevent overflow:</b> * <b>The given {@code parent} must implement the following methods to prevent overflow:</b>
* <ul> * <ul>
* <li>{@link IMessageRecipient#sendMessage(String)}</li> * <li>{@link IMessageRecipient#sendMessage(String)}</li>
@ -25,14 +25,14 @@ import java.lang.ref.WeakReference;
* <li>{@link IMessageRecipient#getDisplayName()}</li> * <li>{@link IMessageRecipient#getDisplayName()}</li>
* <li>{@link IMessageRecipient#isReachable()}</li> * <li>{@link IMessageRecipient#isReachable()}</li>
* </ul> * </ul>
* *
* The reply-recipient is wrapped in a {@link WeakReference}. * The reply-recipient is wrapped in a {@link WeakReference}.
*/ */
public class SimpleMessageRecipient implements IMessageRecipient { public class SimpleMessageRecipient implements IMessageRecipient {
private final IEssentials ess; private final IEssentials ess;
private final IMessageRecipient parent; private final IMessageRecipient parent;
private long lastMessageMs; private long lastMessageMs;
private WeakReference<IMessageRecipient> replyRecipient; private WeakReference<IMessageRecipient> replyRecipient;
@ -42,7 +42,7 @@ public class SimpleMessageRecipient implements IMessageRecipient {
} }
return recipient instanceof User ? (User) recipient : null; return recipient instanceof User ? (User) recipient : null;
} }
public SimpleMessageRecipient(IEssentials ess, IMessageRecipient parent) { public SimpleMessageRecipient(IEssentials ess, IMessageRecipient parent) {
this.ess = ess; this.ess = ess;
this.parent = parent; this.parent = parent;
@ -117,13 +117,12 @@ public class SimpleMessageRecipient implements IMessageRecipient {
if (!isReachable()) { if (!isReachable()) {
return MessageResponse.UNREACHABLE; return MessageResponse.UNREACHABLE;
} }
User user = getUser(this); User user = getUser(this);
boolean afk = false; boolean afk = false;
if (user != null) { if (user != null) {
if (user.isIgnoreMsg() if (user.isIgnoreMsg() && sender instanceof IUser && !((IUser) sender).isAuthorized("essentials.msgtoggle.bypass")) { // Don't ignore console and senders with permission
&& !(sender instanceof Console)) { // Console must never be ignored. return MessageResponse.MESSAGES_IGNORED;
return MessageResponse.MESSAGES_IGNORED;
} }
afk = user.isAfk(); afk = user.isAfk();
// Check whether this recipient ignores the sender, only if the sender is not the console. // Check whether this recipient ignores the sender, only if the sender is not the console.
@ -138,7 +137,7 @@ public class SimpleMessageRecipient implements IMessageRecipient {
// If this recipient doesn't have a reply recipient, initiate by setting the first // If this recipient doesn't have a reply recipient, initiate by setting the first
// message sender to this recipient's replyRecipient. // message sender to this recipient's replyRecipient.
long timeout = ess.getSettings().getLastMessageReplyRecipientTimeout() * 1000; long timeout = ess.getSettings().getLastMessageReplyRecipientTimeout() * 1000;
if (getReplyRecipient() == null || !getReplyRecipient().isReachable() if (getReplyRecipient() == null || !getReplyRecipient().isReachable()
|| System.currentTimeMillis() - this.lastMessageMs > timeout) { || System.currentTimeMillis() - this.lastMessageMs > timeout) {
setReplyRecipient(sender); setReplyRecipient(sender);
} }