Get player for an broadcast

Discussion in 'Spigot Plugin Development' started by jessegeerts, May 7, 2015.

Thread Status:
Not open for further replies.
  1. Hey guys i want to broadcast an message with the name of the player inside but i have this:
    Code (Text):

    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitScheduler;

    public class PexReload extends JavaPlugin{

       
       
         public void onEnable()
         {
           BukkitScheduler scheduler = Bukkit.getScheduler();
           scheduler.scheduleSyncRepeatingTask(this, new Runnable()
           {
             public void run()
             {
               Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "pex reload");
             }
           }, 300L, 300L);
           scheduler.scheduleSyncRepeatingTask(this, new Runnable()
           {
             public void run()
             {
               Player e = e.getPlayer();
               Bukkit.getServer().broadcastMessage("Welcome " + e.getPlayer().getName() + "To this server!");
               Bukkit.getServer().broadcastMessage("Do you like the server and you want to help out?");
               Bukkit.getServer().broadcastMessage("Consider by donating!");
             }
           }, 0L, 12000L);
           scheduler.scheduleSyncRepeatingTask(this, new Runnable()
           {
             public void run() {}
           }, 0L, 6000L);
         }
    }
     
     
  2. Hello anyone i need quick help :(
     
  3. I would recommend learning some basic Java first. There are just way to many things wrong with the code u posted.
     
    • Agree Agree x 1
  4. i watched the video of pogostick29dev about the scheduler =/
     
    • Funny Funny x 1
  5. Watching a video on the scheduler does not really teach you java.. Or not to the extent that watching a Java tutorial will anyway.
     
    • Agree Agree x 1
  6. but sorry what i am going to say but that answer didnt helped me
     
  7. You need to learn Java first. Example you created a Player variable named "e" and then tried to assign it a value from e.getPlayer(); that tells me you don't understand the basics of Java.
     
  8. Hey, your variable is wrong. Set your variable to this:
    Player p = e.getPlayer();
    When you need to get the name use
    p.getName();

    Or create a variable:
    String name = p.getName();

    EDIT: Learn Java though.
     
  9. Inkzzz

    Resource Staff

    Also I wouldn't pressure or tell players to donate; it's highly unprofessional.
     
  10. Everybody makes mistakes with coding etc but we are people so we can LEARN from the mistakes what me made
     
    • Optimistic Optimistic x 1
  11. Is it fixed?
     
    • Optimistic Optimistic x 1
  12. nope
     
  13. Solved!
    Code (Text):
    package me.jesseke55.main;

    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitScheduler;

    public class Main extends JavaPlugin{

        public void onEnable()
        {
            BukkitScheduler scheduler = Bukkit.getScheduler();
            scheduler.scheduleSyncRepeatingTask(this, new Runnable()
            {
                public void run()
                {
                    Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "pex reload");
                }
            }, 300L, 300L);
            scheduler.scheduleSyncRepeatingTask(this, new Runnable()
            {
                public void run()
                {
                    for(Player p : Bukkit.getOnlinePlayers()){
                        Bukkit.getServer().broadcastMessage("Welcome " + p.getName() + "To this server!");
                        Bukkit.getServer().broadcastMessage("Do you like the server and you want to help out?");
                        Bukkit.getServer().broadcastMessage("Consider by donating!");
                    }
                }
            }, 0L, 12000L);
         
            scheduler.scheduleSyncRepeatingTask(this, new Runnable()
            {
                public void run() {}
            }, 0L, 6000L);
        }  
    }

     
     
    [​IMG]
     
  14. Yeah but you should maybe add colours with it too, it looks ugly without colour, maybe add a prefix so it's like [{Servername} >> Hi there {playername}, maybe you should consider donating to {servername} for some awesome perks the pride of helping us out!
    Just a suggestion :3
     
  15. thanks!
     
  16. thanks for the idea :D
     
  17. Np skype me if you need more help
     
  18. Don't spoonfeed people, he hasn't learned from this.
     
  19. gigosaurus

    Supporter

    Still unsure why you want to reload pex every 15 seconds, send a message to every player welcoming every player every 10 minutes, and have an empty scheduler running every 5 minutes.
     
Thread Status:
Not open for further replies.