Broadcast message

Discussion in 'Plugin Development' started by xDUBSTEPx, Sep 23, 2011.

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

    xDUBSTEPx

    Hi was wondering if some one could show me how
    to create a custom broadcast message e.g /test [message]
    broadcasts [message] this would be very helpful:)
     
  2. Offline

    DeadlyScone

    EDIT:
    well on your command /test [mesage]


    and define a string for the [message] and store [message] there.
    EXAMPLE:
    Code:
    String msg;//get the [message] in the command
    for (Player p : world.getPlayers()){
                p.sendMessage(msg);
            }
    and world needs to be defined.


    -basically this gets all the players in the world and broadcasts a message to all of them.
    hope this is what you are looking for
    IF you need more help please ask me. ill be happy to help :)
     
  3. Offline

    desht

    PHP:
    Bukkit.getServer().broadcastMessage(msg);
     
  4. Offline

    xDUBSTEPx

    so if i do this
    public boolean onCommand(CommandSender sender, Command command,
    String label, String[] args) {
    if (command.getName().equalsIgnoreCase("TEST")) {
    Bukkit.getServer().broadcastMessage(msg);

    will that work
     
  5. Offline

    Baummann

    If you want something like /say use this:
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cpmmand, String label, String[] args) {
    2. if (command.getName().equalsIgnoreCase("test")) {
    3. for (int i = 0; i < args.length; i++) {
    4. Bukkit.getServer().broadcastMessage(args[i]);
    5. return true;
    6. }
    7. }
    8. }[/i]
     
    xDUBSTEPx likes this.
  6. Offline

    xDUBSTEPx

    1 prob
    public boolean onCommand(CommandSender sender, Command cpmmand, String label, String[] args){
    if (command.getName().equalsIgnoreCase("test")) {
    for (int i = 0; i < args.length; i++) {
    Bukkit.getServer().broadcastMessage(args);
    return true;}
    }
    } <------- [ERROR]
    }[/I]
     
  7. Offline

    Jogy34

    Problem:
    1. How many open brackets( { ) do you have? (you have 3 open brackets)
    2. How many close brackets ( } ) do you have? (you have 4 close brackets)
    Solution:
    1. Delete the close bracket after the return true; OR
    2. delete the bracket that it says has the error
     
  8. Offline

    xDUBSTEPx

    Thats still helpful but is there a way i can customize what the broadcast looks like instead of [server]:)
     
  9. Offline

    Baummann

    It doesn't have the [Server].
     
  10. Offline

    xDUBSTEPx

    i still have 1 prob
    public boolean onCommand(CommandSender sender, Command cpmmand, String label, String[] args){
    if (command.getName().equalsIgnoreCase("test")) {
    for (int i = 0; i < args.length; i++) {
    Bukkit.getServer().broadcastMessage(args);
    return true;}
    }
    } <------- [ERROR]
    }[/I]

    Please Help :(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  11. Offline

    Feed_Dante

    As mentioned above

    If you have extra brackets, just remove them.
     
  12. Offline

    xDUBSTEPx

    Didint work that just gives me like 5 errors
     
  13. Offline

    Feed_Dante

    Saying you have 5 errors? Unhelpfull
    Saying what those errors are? Helpfull
    Learning Java? Priceless
     
  14. Offline

    xDUBSTEPx

    They are all Syntax error
     
  15. Offline

    Feed_Dante

    Thats like saying "Help, I have a spelling mistake somewhere in this 42 page file!"

    I don't have a crystal ball, you need to be more specific.
     
  16. Offline

    xDUBSTEPx

    look no matter how much i try im not gona get the broadcast thing to work
     
  17. Offline

    Feed_Dante

    I'm not saying give up. I'm just trying to get you to post actual error messages and info so others can help.

    If you posted the exact error & your code I might be able to do something, but I can't guess at what I can't see.

    Note: You should use
    Code:
    [syntax=java][/syntax]
    to post java code to preserve/show line numbers. (Makes it much easier to read on the forum.)
     
  18. Offline

    xDUBSTEPx

    Code:
    package xDUBSTEPx.Test;
    
    import java.util.logging.Logger;
      
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.inventory.ItemStack;
    public class Test extends JavaPlugin {
    
        public static Test plugin;
        public static final Logger log = Logger.getLogger("Minecraft");
     
        @SuppressWarnings("unused")
        private Object player;
        @SuppressWarnings("unused")
        private ChatColor message;
        private Logger command;
     
        @SuppressWarnings("unused")
        @Override
        public void onEnable() {
            PluginManager pm = getServer().getPluginManager();
      
            log.info("[Test] Plugin enabled.");
        }
     
        @Override
        public void onDisable() {
            log.info("[Test] Plugin disabled.");
        }
        public boolean onCommand(CommandSender sender, Command cpmmand, String label, String[] args) {
            if (command.getName().equalsIgnoreCase("test")) {
                 for (int i = 0; i < args.length; i++) {
                         Bukkit.getServer().broadcastMessage(args[i]);
                         return true;
                 }
            }
      }[/i]


    theres my code happy now

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  19. Offline

    Feed_Dante

    And what are the errors? What lines are the errors on? Whats with the [/i] at the end of the file?

    I don't mean to offend and I'm not trying to upset you but it seems to be a struggle to get "Here's what I have; Here's whats wrong; How do I fix it?"
     
  20. Offline

    xDUBSTEPx

    I Have The [/i] on the end because of



    any ways that code didint work

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  21. Offline

    Feed_Dante

    1. Get rid of the [/i], it doesn't belong. (It's most likely the forum's attempt to preserve formatting.)
    2. Post specific errors!!!
     
  22. Offline

    xDUBSTEPx

    Ok This is what i have
    Code:
    public boolean onCommand1(CommandSender sender, Command cpmmand, String label, String[] args) {
                  if (command.getName().equalsIgnoreCase("test")) {
                       for (int i = 0; i < args.length; i++) {
                               Bukkit.getServer().broadcastMessage(args[i]);
                               return true;
                       }
                       }
                  } <------
            }[/i]
    1.my 1 error is this Syntax error, insert "}" to complete ClassBody
     
  23. Offline

    Feed_Dante

    1. It should be onCommand( instead of onCommand1(
    2. [/i] does not belong
    3. That last } matches the { for onCommand, but you still need one to complete the class block; add one } to the end of your file.
     
  24. Offline

    xDUBSTEPx

    I fixed it i added a return statement :cool:
     
  25. @xDUBSTEPx Just a little suggestion: Watch some Java tutorials or read a book about Java.
    It might help you with silly fails like thinking that [/i] is Java code :)
     
  26. Offline

    xDUBSTEPx

    Crap the command dont work it says nothing
    when i type /test fgdsfgdsfg
     
  27. Offline

    Feed_Dante

  28. Offline

    xDUBSTEPx

    yer no errors but nothing happend
    Code:
    name: Test
    main: xDUBSTEPx.Test.Test
    version: 1.0
    author: xDUBSTEPx
    commands:
        help:
            Description: Plugin commands.
            Usage: |
                /help
        test:
            Description: Plugin commands.
            Usage: |
                /test
    And This Is My Main Code
    Code:
    public boolean onCommand1(CommandSender sender, Command cpmmand, String label, String[] args) {
                  if (command.getName().equalsIgnoreCase("test")) {
                       for (int i = 0; i < args.length;) {
                               Bukkit.getServer().broadcastMessage(args[i]);
                               return true;
                       }
                       }
                return false;
                  }
            }
    
    yer

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  29. Offline

    Feed_Dante

    onCommand( not onCommand1(
    remove the 1
     
  30. Offline

    xDUBSTEPx

    but i have to commands
     
Thread Status:
Not open for further replies.

Share This Page