Help plox

Discussion in 'Plugin Development' started by Ethan Rocks 365, Feb 14, 2016.

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

    Ethan Rocks 365

    Hey can someone tell me how I would make a plugin send a message to a player when they join?
    Like I join the server and it says to me [Prefix]This server uses ____ which was developed by ______ currently in version _._
     
  2. Offline

    mcdorli

    1.: If you do this, make it optional, owners doesn't like it, when a plugin does this.
    2.: Use PlayerJoinEvent, wait 1 tick, and do what you want.
     
  3. Offline

    Ethan Rocks 365

    Could you please send me an ex?
     
  4. Offline

    teej107

  5. Offline

    Ethan Rocks 365

    This help 0% because never does it say where/how i use PlayerJoinEvent

    Heres what i got but when i join no message anyone know why?
    Code:
    public void onPlayerJoin(PlayerJoinEvent e) {
            Player player = (Player) e;
            player.sendMessage("Welcome " + player.getName()+ "Do /website to veiw the website and /teamspeak to veiw the teamspeak!");}
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Feb 16, 2016
  6. Post your entire class.
    And if that is your entire class, try not copy+pasting.
     
  7. Offline

    teej107

    Because you probably didn't register the event and if you did there is an error.
     
  8. Offline

    Ethan Rocks 365

    Idont have accss to it right now. I will send it when i has access
     
  9. Offline

    Zombie_Striker

    Sure, instead of simply helping him or asking for more information, you "roast him" for asking for help.


    @Ethan Rocks 365
    Did you register your class? Did you implment listener? Did you remember the @EventHandler tag?

    [EDIT]: Look again at what you're casting to a player. You're casting an EVENT to a PLAYER.
     
    0566 likes this.
  10. Offline

    Ethan Rocks 365

    @EventHandler i forgot that :p and yes please roast me... please do that
     
  11. Offline

    mythbusterma

    @Ethan Rocks 365

    You said it's when a player joins.

    Like we said before, listen for the PlayerJoinEvent, and send a message one tick later by scheduling a Runnable. What was unclear?
     
  12. Offline

    Ethan Rocks 365

    nothing... I forgot to add the @EventHandler
     
  13. Offline

    JoaoBM

  14. Offline

    Ethan Rocks 365

    But im not shure yet as i cant test it untill my dad is home
     
  15. Offline

    boomboompower

    @Ethan Rocks 365
    The code you have shown, runs every time a player join. Not just the first time.
     
  16. Offline

    Ethan Rocks 365

    I have to modify it...
     
  17. Offline

    Protophite

    just wanted to point out that Player player = (Player) e; won't work.
    e.getPlayer();
     
    Last edited by a moderator: Feb 16, 2016
  18. Offline

    Ethan Rocks 365

    Heres my class but no message on join idk why tho

    Code:
    package plugin.me.turtles;
    
    import java.util.logging.Logger;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class turtles extends JavaPlugin implements Listener
    {  
        Logger myPluginLogger = Bukkit.getLogger();
      
        public void onEnable()
        {
            myPluginLogger.info(ChatColor.RED + "=====<WebSiteInfo>=====");
            myPluginLogger.warning(ChatColor.GREEN + "Enabling WebsiteInfo 1.1");
            myPluginLogger.info(ChatColor.RED + "=====<ThanksForUsing>=====");
            saveDefaultConfig();
            }
       
        public void onDisable()
        {
          
        }
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e) {
            e.getPlayer().sendMessage("Welcome " + e.getPlayer().getName()+ "Do /website to veiw the website and /teamspeak to veiw the teamspeak!");}
        public boolean onCommand(CommandSender theSender, Command cmd, String commandLable, String[] args)
        {
            if(commandLable.equalsIgnoreCase("website"))
            {
                Player thePlayer = (Player)theSender;
                thePlayer.sendMessage(ChatColor.RED + "Our website is " + ChatColor.translateAlternateColorCodes('&', getConfig().getString("website")));
            }  
            if(commandLable.equalsIgnoreCase("teamspeak"))
            {
                Player thePlayer = (Player)theSender;
                thePlayer.sendMessage(ChatColor.RED + "Our teamspeak is " + ChatColor.translateAlternateColorCodes('&', getConfig().getString("teamspeak")));
            }  
            return true;
        }
    }
     
    
     
    Last edited by a moderator: Feb 16, 2016
  19. Offline

    Zombie_Striker

    Please follow Java Naming Conventions and have the name of all classes start with an UpperCase letter. Also, don't randomly create class names. The main class should be the name of your plugin.

    There is no reason to create this logger field. You only reference it in the onEnabled and....

    You don't even need to log your plugin. Bukkit already logs your plugins for you. Now you will have two messages saying the same plugin has been enabled.

    Since this method does nothing, remove it.

    Please fix your formatting, and stay with one type of formatting. Either choose Allmans style and have brackets on their own line or do what is recommend in Java and do what is shown here (BTW, the end bracket should be on it's own line). It should be easy to identify beginning and ends to messages/methods/classes/ect.

    DON'T BLIND CAST! What if the console sends the command (please don't answer "but I will never use the console"). Then this would break your plugin because the console is not a player.
    Use what is recommended which is "cmd.getName()", or at least fix "Label".

    Only return true when the command worked as planned. This says no matter what way the formatted the command they did it correctly. Return true if works the way it should, else return false.

    And now, about your problem XD

    You forgot to register your listener. You have implemented the listener, but you did not register it in the onEnabled.
     
    Last edited: Feb 16, 2016
    0566 likes this.
  20. Offline

    Ethan Rocks 365

    so like this?
    Code:
    //Number 1
    public void onEnable()
        {
            myPluginLogger.info(ChatColor.RED + "=====<WebSiteInfo>=====");
            myPluginLogger.warning(ChatColor.GREEN + "Enabling WebsiteInfo 1.1");
            myPluginLogger.info(ChatColor.RED + "=====<ThanksForUsing>=====");
            saveDefaultConfig();
            public void onEnable()
            plugin.getServer().getPluginManager().registerEvents(onPlayerJoin)
            }
      
            @EventHandler
            public void onPlayerJoin(PlayerJoinEvent e) {
                e.getPlayer().sendMessage("Welcome " + e.getPlayer().getName()+ "Do /website to veiw the website and /teamspeak to veiw the teamspeak!");}
    
            {
    or like this?
    Code:
    ]//Number 2
    public void onEnable()
        {
            myPluginLogger.info(ChatColor.RED + "=====<WebSiteInfo>=====");
            myPluginLogger.warning(ChatColor.GREEN + "Enabling WebsiteInfo 1.1");
            myPluginLogger.info(ChatColor.RED + "=====<ThanksForUsing>=====");
            saveDefaultConfig();
            public void onEnable()
            plugin.getServer().getPluginManager().registerEvents(e)
            }
     
            @EventHandler
            public void onPlayerJoin(PlayerJoinEvent e) {
                e.getPlayer().sendMessage("Welcome " + e.getPlayer().getName()+ "Do /website to veiw the website and /teamspeak to veiw the teamspeak!");
    }
        
     
  21. Offline

    Zombie_Striker

    0566 likes this.
  22. Offline

    Ethan Rocks 365

    so your saying I have bad formatting? How would you like it to be formatted
     
  23. Offline

    Zombie_Striker

    @Ethan Rocks 365
    The problem is not really with your formatting (but you should focus on that). The main problem is that you have a method inside a method , and you are not correctly registering your listener.
     
  24. Offline

    Ethan Rocks 365

    o yea i didnt notice the onEnable inside of the onEnable. This is really hard because my dad put a password on my computer that limits my time on it because I, "spend too much time on it" Because 2 hours on my pc maybe 3 at most is too much(this is over 1 to 2 days) and the event registering would be
    Code:
    new eventListener(this);
    Thats what i got from my research
     
  25. Offline

    Zombie_Striker

    @Ethan Rocks 365
    .registerEvents(The Event class, this);

    This is how you register an event.
     
  26. Offline

    mythbusterma

    @Ethan Rocks 365

    So this "research" you did...did it include the tutorial for writing a Bukkit plugin? You know, the thing that teaches you how to do this?

    http://wiki.bukkit.org/Event_API_Reference

    You have to try. You have to think. Writing code isn't a half-assed affair (or at least, it shouldn't be).
     
    0566, teej107 and Zombie_Striker like this.
  27. Offline

    Ethan Rocks 365

    Yes i read that but its hard to read on a ipod touch as my dad locked me out of my pc...

    You all have taught me something... Never ask for help... UNLESS you have searched the world for the answer...
     
  28. Offline

    teej107

    Because you need to send the message a tick later which is why I linked you to a tutorial on how to do it. Hopefully that "0% help" will actually help you.
     
  29. Offline

    Gerov

  30. Offline

    mythbusterma

    @Ethan Rocks 365

    No, unless you have reviewed the first Google result. And read the tutorial. That is linked at the top of the section.
     
Thread Status:
Not open for further replies.

Share This Page