broadcastMessage() not working

Discussion in 'Plugin Development' started by 1337, Jan 20, 2011.

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

    1337

    broadcastMessage(); wont work for me, i imported org.bukkit.server(); and it still wont work
     
  2. Offline

    MysticX

    Server is not a static class, but the current server will be passed to your main plugin constructor. So you can get the Server object with getServer().
    Also the import should be just "import org.bukkit.Server;" It's case-sensitive and braces are only for methods, not classes.

    This piece of code should work in your plugin class:
    Code:
    getServer().broadcastMessage("type your message here");
     
  3. Offline

    1337

    the () was a typo sorry thanks for that
    --- merged: Jan 20, 2011 8:49 PM ---
    is there not a way to do it in the playerlistener class?
     
  4. Offline

    MysticX

    Sure there is ;)

    Make a new constructor for your listener, give it your plugin.
    Then you can save it somewhere and call plugin.getServer()...

    Code:
    private final YourPlugin plugin;
    
        public YourPluginPlayerListener(YourPlugin instance) {
            this.plugin = instance;
        }
    
    
        public void broadcast() {
             this.plugin.getServer().broadcastMessage("blabla");
        }
    And initialize it with
    Code:
    new YourPluginPlayerListener(this)
    in your main plugin class
     
    Supersam654 likes this.
  5. Offline

    blaatz0r

    A PlayerListener class should have a Plugin variable.

    So that would mean calling

    Code:
    plugin.getServer().broadCastMessage("bla");
    Edit: MysticX beat me to it :)
     
  6. Offline

    1337

    thanks you all so much :)
     
Thread Status:
Not open for further replies.

Share This Page