Broadcasting message [Multiple ways]

Discussion in 'Resources' started by CraftThatBlock, May 7, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    CraftThatBlock

    Hey! Here is a couple methods to broadcast:

    Classical:
    Code:
    Bukkit.broadcastMessage(message);
    This DOES broad to the console. To broadcast only to console, use Bukkit.getLogger().info("Sup console");

    A bit more advance but very expandable (see bellow)
    Code:
    for(Player player : Bukkit.getOnlinePlayers()){
        player.sendMessage(message);
    }
    
    You can boardcast to people only if they have an item in their inventory or a permission:
    Item:

    Code:
    for(Player player : Bukkit.getOnlinePlayers()){
        if(player.getInventory().contains(Material.DIAMOND){
            player.sendMessage(message);
        }
    }
    


    Permission:

    Code:
    for(Player player : Bukkit.getOnlinePlayers()){
        if(player.hasPermission("this.is.a.permission")){
            player.sendMessage(message);
        }
    }
    
    (For permission, you can also use Bukkit.broadcast(message, permission); )
     
    Matroxko and InspectorFacepalm like this.
  2. Offline

    DarkBladee12

    CraftThatBlock What's the point of this? I think you can figure that out by yourself easily...
     
  3. Offline

    Garris0n

    Useful for those new to bukkit...don't assume everybody has the same experience as you.
     
  4. Offline

    DarkBladee12

    Garris0n There are many awesome tutorials out for upcoming devs, where you'll learn that stuff ;)
     
  5. Offline

    Garris0n

    Doesn't mean this hurts anybody by being posted. For all you know somebody will be searching in 5 minutes how to do this, find this thread, and realize how to broadcast, check inventories, and check permissions all in one.
     
  6. Offline

    CraftThatBlock

    This is meant for newer people to show that they have multiple options.
     
  7. Offline

    tweety49

    Thanks, I found this useful :)
     
  8. Offline

    Ultimate_n00b

    Bukkit.broadcast("Message", "Some.Permission"); Does that not work for permissions?
     
  9. Offline

    bobacadodl

    It works with every permissions plugin except PermissionsEX, IIRC.
     
Thread Status:
Not open for further replies.

Share This Page