mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-03 06:57:39 +01:00
Add UserMailEvent
This commit is contained in:
parent
bfae6c5c69
commit
3131cadf65
@ -1,9 +1,11 @@
|
|||||||
package com.earth2me.essentials;
|
package com.earth2me.essentials;
|
||||||
|
|
||||||
import net.ess3.api.IUser;
|
import net.ess3.api.IUser;
|
||||||
import net.essentialsx.api.v2.services.mail.MailService;
|
import net.essentialsx.api.v2.events.UserMailEvent;
|
||||||
import net.essentialsx.api.v2.services.mail.MailMessage;
|
import net.essentialsx.api.v2.services.mail.MailMessage;
|
||||||
import net.essentialsx.api.v2.services.mail.MailSender;
|
import net.essentialsx.api.v2.services.mail.MailSender;
|
||||||
|
import net.essentialsx.api.v2.services.mail.MailService;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.ServicePriority;
|
import org.bukkit.plugin.ServicePriority;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
@ -35,6 +37,12 @@ public class MailServiceImpl implements MailService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendMail(IUser recipient, MailMessage message) {
|
private void sendMail(IUser recipient, MailMessage message) {
|
||||||
|
final UserMailEvent event = new UserMailEvent(recipient, message);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final ArrayList<MailMessage> messages = recipient.getMailMessages();
|
final ArrayList<MailMessage> messages = recipient.getMailMessages();
|
||||||
messages.add(0, message);
|
messages.add(0, message);
|
||||||
recipient.setMailList(messages);
|
recipient.setMailList(messages);
|
||||||
|
@ -0,0 +1,58 @@
|
|||||||
|
package net.essentialsx.api.v2.events;
|
||||||
|
|
||||||
|
import net.ess3.api.IUser;
|
||||||
|
import net.essentialsx.api.v2.services.mail.MailMessage;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when mail is sent to a {@link net.ess3.api.IUser IUser} by another player or the console.
|
||||||
|
*/
|
||||||
|
public class UserMailEvent extends Event implements Cancellable {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
private final IUser recipient;
|
||||||
|
private final MailMessage message;
|
||||||
|
private boolean canceled;
|
||||||
|
|
||||||
|
public UserMailEvent(IUser recipient, MailMessage message) {
|
||||||
|
this.recipient = recipient;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the recipient of this mail.
|
||||||
|
* @return the recipient.
|
||||||
|
*/
|
||||||
|
public IUser getRecipient() {
|
||||||
|
return recipient;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the underlying {@link MailMessage} for this mail.
|
||||||
|
* @return the message.
|
||||||
|
*/
|
||||||
|
public MailMessage getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.canceled = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return canceled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user