Plugin Help - Broadcast a message to all players

Discussion in 'Plugin Development' started by vYN, Jan 9, 2012.

  1. Offline

    vYN

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Hi. I'm trying to make my plugin broadcast a message to every player online... but i can't figure out how to do that.. for example when a player throws an egg. The plugin will broadcast Who throw an egg like this: "Name throw an egg"

    Thanks in advance.
  2. Offline

    nala3

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    this.getServer().broadcastMessage("message");
  3. Offline

    vYN

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    :O it worked Thanks!!!

    haha new problem xD on my getDisplayName it says "null Throws an egg!"
  4. Offline

    nala3

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Player p = event.getPlayer();

    this.getServer().broadcastMessage(p + " threw an egg!');
  5. Offline

    T145

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Making a plugin that broadcasts a message for everything a player does would get kind of annoying, don't you think? I know some of my admin friends who got trolled hard in their chat from using plugins that relate to the idea your planning. Spamming eggs everywhere to generate mobs of chickens is really obnoxious, but having each egg spammed through chat may only worsen the situation.
  6. Offline

    vYN

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    hehe i know it will. i'm just doing this to learn some new stuff. like a learning curve that goes upwards xD
  7. Offline

    vYN

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    hmm ok. now it says "CraftPlayer{name=GudfareN} Throws an egg!"
  8. Offline

    nala3

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    then I think you imported the wrong Player :)
  9. Offline

    vYN

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    hmm ok...

    Code:
            public void onPlayerEggThrow(PlayerEggThrowEvent event) {
                Player p = event.getPlayer();
                getServer().broadcastMessage(p + " Throws an egg!");
                }
  10. Offline

    nala3

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    make sure you imported:
    import org.bukkit.entity.Player;
  11. Offline

    vYN

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    That is imported yes..
  12. Offline

    nala3

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    ohh derp I am dumb.
    Code:
    public void onPlayerEggThrow(PlayerEggThrowEvent event) {
                String p = event.getPlayer().toString();
                this.getServer().broadcastMessage(p + " Throws an egg!");
            }
    

    This post has been edited 2 times. It was last edited by nala3 Jan 9, 2012.
  13. Offline

    vYN

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    when i'm adding "this." infront of getServer it gies me an error....

    Code:
    The method getServer() is undefined for the type Main.AutoMSGPlayerListener
  14. Offline

    nala3

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    just get rid of the this I just wrote it in a hurry :p
  15. Offline

    vYN

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    hmm ok. for some reason it still gives me "CraftPlayer{name=GudfareN} Throws an egg!"

    i feel so noob at this lol xD

    This post has been edited 1 time. It was last edited by Gudfaren Jan 9, 2012.
  16. Offline

    nala3

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    hmm. well I'm not very good at helping, I know what I am doing (most of the time) but I can't explain for my life :p
  17. Offline

    vYN

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    hehe ok. Thanks anyway. u got me a huge step forwards!
  18. Offline

    nkrecklow

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    If you don't know how to get the plugin instance, you should read up on Java and Bukkit before continuing.
    Anyways, this would do just that.
    Code:
    public void onPlayerEggThrow(PlayerEggThrowEvent event) {
         String name = event.getPlayer().getName();
         plugin.getServer().broadcastMessage(name + " threw an egg!");
    }
  19. Offline

    nala3

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    ohh getName, herp-a-derp XD
    Have not had to use that before, it is now noted
  20. Offline

    vYN

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Hehe that fixed it. Thanks for all the help.
  21. Offline

    vYN

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Hi. One more question... sorry..
    How do i send a message from the plugin to the player that issues the command for the plugin?

    Code:java
    1.  
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    2. if(cmd.getName().equalsIgnoreCase("egghatcher")){
    3. getServer().broadcastMessage(ChatColor.BLUE + "From Plugin" + ChatColor.GREEN +" Test");
    4. return true;
    5. }
    6. return false;

    This post has been edited 2 times. It was last edited by Gudfaren Jan 10, 2012.
  22. Online

    number1_Master

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Code:java
    1. Player player = (Player) sender; //this sets player as the sender
    2. //now instead of getServer().broadcast (...)
    3. player.sendMessage("This is my message!");
  23. Offline

    vYN

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Code:java
    1.  
    2. yay it works like a dream. but if i want to do it from an event..
    3.  
    4.  
    5. [CODE]public void onPlayerEggThrow(PlayerEggThrowEvent event)[/CODE]
    6.  
    7. just copied the top part of the event.

    This post has been edited 2 times. It was last edited by Gudfaren Jan 10, 2012.
  24. Online

    number1_Master

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    then:
    Code:java
    1. Player player = event.getPlayer();
    2. player.sendMessage("Awesome Message! :D");
  25. Offline

    vYN

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Code:java
    1.  
    2. Thanks! it worked
    nunber1_Master likes this.

Share This Page