implement PrivateMessagePreSendEvent (#3260)

This PR introduces an event to be called just before a private message is sent to a user. This event provides the message sender, the message recipient, and the contents of the message.

This event provides the possibility for greater customization of private messages, such as playing a sound or displaying a boss bar when a private message is received, or filtering private message content.

Closes #726, closes #2097.
This commit is contained in:
triagonal 2020-05-13 17:03:28 +10:00 committed by GitHub
parent 4b967a749b
commit d59fd71ba5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 71 additions and 1 deletions

View file

@ -3,6 +3,7 @@ package com.earth2me.essentials.messaging;
import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.IUser;
import com.earth2me.essentials.User;
import net.ess3.api.events.PrivateMessagePreSendEvent;
import java.lang.ref.WeakReference;
@ -62,6 +63,13 @@ public class SimpleMessageRecipient implements IMessageRecipient {
}
@Override public MessageResponse sendMessage(IMessageRecipient recipient, String message) {
final PrivateMessagePreSendEvent event = new PrivateMessagePreSendEvent(this, recipient, message);
ess.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return MessageResponse.EVENT_CANCELLED;
}
message = event.getMessage();
MessageResponse messageResponse = recipient.onReceiveMessage(this.parent, message);
switch (messageResponse) {
case UNREACHABLE: