diff options
-rw-r--r-- | Essentials/src/com/earth2me/essentials/commands/Commandmail.java | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java index d02e5a13a..8a2787d82 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java @@ -63,6 +63,14 @@ public class Commandmail extends EssentialsCommand user.sendMessage(_("mailSent")); 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])) { user.setMails(null); @@ -103,6 +111,10 @@ public class Commandmail extends EssentialsCommand sender.sendMessage(_("mailSent")); return; } + else if (args.length >= 1 && "sendall".equalsIgnoreCase(args[0])) + { + ess.scheduleAsyncDelayedTask(new SendAll("Server: " + getFinalArg(args, 2))); + } else if (args.length >= 2) { //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(); } + + + 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); + } + } + } + } } |