mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-08-07 13:03:00 +00:00
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:
parent
4b967a749b
commit
d59fd71ba5
3 changed files with 71 additions and 1 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue