New feature: /mail sendall <message>

Test: #649
This commit is contained in:
Khyperia 2011-12-07 08:46:35 +08:00 committed by snowleo
parent d573671933
commit b49a9ef165

View File

@ -63,6 +63,14 @@ public class Commandmail extends EssentialsCommand
user.sendMessage(_("mailSent")); user.sendMessage(_("mailSent"));
return; return;
} }
if (args.length >= 1 && "sendall".equalsIgnoreCase(args[0]))
{
if (!user.isAuthorized("essentials.mail.sendall"))
{
throw new Exception(_("noMailSendPerm"));
}
ess.scheduleAsyncDelayedTask(new SendAll(ChatColor.stripColor(user.getDisplayName()) + ": " + getFinalArg(args, 2)));
}
if (args.length >= 1 && "clear".equalsIgnoreCase(args[0])) if (args.length >= 1 && "clear".equalsIgnoreCase(args[0]))
{ {
user.setMails(null); user.setMails(null);
@ -103,6 +111,10 @@ public class Commandmail extends EssentialsCommand
sender.sendMessage(_("mailSent")); sender.sendMessage(_("mailSent"));
return; return;
} }
else if (args.length >= 1 && "sendall".equalsIgnoreCase(args[0]))
{
ess.scheduleAsyncDelayedTask(new SendAll("Server: " + getFinalArg(args, 2)));
}
else if (args.length >= 2) else if (args.length >= 2)
{ {
//allow sending from console without "send" argument, since it's the only thing the console can do //allow sending from console without "send" argument, since it's the only thing the console can do
@ -126,4 +138,28 @@ public class Commandmail extends EssentialsCommand
} }
throw new NotEnoughArgumentsException(); throw new NotEnoughArgumentsException();
} }
private class SendAll implements Runnable
{
String message;
public SendAll(String message)
{
this.message = message;
}
@Override
public void run()
{
for (String username : ess.getUserMap().getAllUniqueUsers())
{
User user = ess.getUserMap().getUser(username);
if (user != null)
{
user.addMail(message);
}
}
}
}
} }