summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBillyGalbreath <Blake.Galbreath@GMail.com>2017-07-16 18:45:08 -0500
committermd_5 <git@md-5.net>2017-07-28 16:53:43 +1000
commitd2aa6845f0084a2b8ced01010ef80713c2d371ff (patch)
tree339083bdf892c0fee8137bc3a40996e79aabc03b
parentb1b9ab0df94c3b4b5c2613b7bf6347be10e864fc (diff)
downloadcraftbukkit-d2aa6845f0084a2b8ced01010ef80713c2d371ff.tar
craftbukkit-d2aa6845f0084a2b8ced01010ef80713c2d371ff.tar.gz
craftbukkit-d2aa6845f0084a2b8ced01010ef80713c2d371ff.tar.lz
craftbukkit-d2aa6845f0084a2b8ced01010ef80713c2d371ff.tar.xz
craftbukkit-d2aa6845f0084a2b8ced01010ef80713c2d371ff.zip
Implement BroadcastMessageEvent
-rw-r--r--src/main/java/org/bukkit/craftbukkit/CraftServer.java26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 89c1d3a2..0a5a11d8 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -80,6 +80,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerChatTabCompleteEvent;
+import org.bukkit.event.server.BroadcastMessageEvent;
import org.bukkit.event.world.WorldInitEvent;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent;
@@ -1207,18 +1208,27 @@ public final class CraftServer implements Server {
@Override
public int broadcast(String message, String permission) {
- int count = 0;
- Set<Permissible> permissibles = getPluginManager().getPermissionSubscriptions(permission);
-
- for (Permissible permissible : permissibles) {
+ Set<CommandSender> recipients = new HashSet<>();
+ for (Permissible permissible : getPluginManager().getPermissionSubscriptions(permission)) {
if (permissible instanceof CommandSender && permissible.hasPermission(permission)) {
- CommandSender user = (CommandSender) permissible;
- user.sendMessage(message);
- count++;
+ recipients.add((CommandSender) permissible);
}
}
- return count;
+ BroadcastMessageEvent broadcastMessageEvent = new BroadcastMessageEvent(message, recipients);
+ getPluginManager().callEvent(broadcastMessageEvent);
+
+ if (broadcastMessageEvent.isCancelled()) {
+ return 0;
+ }
+
+ message = broadcastMessageEvent.getMessage();
+
+ for (CommandSender recipient : recipients) {
+ recipient.sendMessage(message);
+ }
+
+ return recipients.size();
}
@Override