Search in sources :

Example 1 with BroadcastMessageEvent

use of org.bukkit.event.server.BroadcastMessageEvent in project Glowstone by GlowstoneMC.

the class GlowServer method broadcast.

@Override
public int broadcast(String message, String permission) {
    Set<CommandSender> sent = new HashSet<>();
    for (Permissible permissible : getPluginManager().getPermissionSubscriptions(permission)) {
        if (permissible instanceof CommandSender && permissible.hasPermission(permission)) {
            CommandSender cs = ((CommandSender) permissible);
            sent.add(cs);
        }
    }
    BroadcastMessageEvent event = EventFactory.getInstance().callEvent(new BroadcastMessageEvent(message, sent));
    if (event.isCancelled()) {
        return 0;
    }
    sent.forEach(cs -> cs.sendMessage(message));
    return sent.size();
}
Also used : BroadcastMessageEvent(org.bukkit.event.server.BroadcastMessageEvent) Permissible(org.bukkit.permissions.Permissible) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) CommandSender(org.bukkit.command.CommandSender) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 CommandSender (org.bukkit.command.CommandSender)1 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)1 BroadcastMessageEvent (org.bukkit.event.server.BroadcastMessageEvent)1 Permissible (org.bukkit.permissions.Permissible)1