3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 12:30:06 +01:00

Implement BroadcastMessageEvent

Dieser Commit ist enthalten in:
BillyGalbreath 2017-07-16 18:45:08 -05:00 committet von md_5
Ursprung b1b9ab0df9
Commit d2aa6845f0

Datei anzeigen

@ -80,6 +80,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerChatTabCompleteEvent; import org.bukkit.event.player.PlayerChatTabCompleteEvent;
import org.bukkit.event.server.BroadcastMessageEvent;
import org.bukkit.event.world.WorldInitEvent; import org.bukkit.event.world.WorldInitEvent;
import org.bukkit.event.world.WorldLoadEvent; import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent; import org.bukkit.event.world.WorldUnloadEvent;
@ -1207,18 +1208,27 @@ public final class CraftServer implements Server {
@Override @Override
public int broadcast(String message, String permission) { public int broadcast(String message, String permission) {
int count = 0; Set<CommandSender> recipients = new HashSet<>();
Set<Permissible> permissibles = getPluginManager().getPermissionSubscriptions(permission); for (Permissible permissible : getPluginManager().getPermissionSubscriptions(permission)) {
for (Permissible permissible : permissibles) {
if (permissible instanceof CommandSender && permissible.hasPermission(permission)) { if (permissible instanceof CommandSender && permissible.hasPermission(permission)) {
CommandSender user = (CommandSender) permissible; recipients.add((CommandSender) permissible);
user.sendMessage(message);
count++;
} }
} }
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 @Override