Solved My 1st plugin: help!

Discussion in 'Spigot Plugin Development' started by NamerPRO, Jun 18, 2018.

?

My question might be stupid :(

  1. Don't worry, I was a noob too when started :)

    6 vote(s)
    100.0%
  2. Something between [:j

    0 vote(s)
    0.0%
  3. Yes! I always knew you are a noob :c

    0 vote(s)
    0.0%
  4. I have no opinion about that!

    0 vote(s)
    0.0%
Thread Status:
Not open for further replies.
  1. I made a plugin (my 1st one) and I'd like to know whats wrong here? It doesn't show a message to chat.

    Problem lines:
    Code (Java):
    event.setJoinMessage(event.getPlayer().getName() + " joined my server :)");
    Code (Java):
    event.setQuitMessage(event.getPlayer().getName() + " left my server :(");
    Code is here:
    Code (Java):
    package ru.namerpro;

    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;

    public class mainListener extends JavaPlugin implements Listener{
       
        public void onEnable() {
            getLogger().info("Plugin Enabled!");
        }
       
        public void onDisable() {
            getLogger().info("Plugin Disabled!");
        }
       
        @EventHandler
        public void onJoin(PlayerJoinEvent event) {
            event.setJoinMessage(event.getPlayer().getName() + " joined my server :)");
        }
       
        @EventHandler
        public void onLeave(PlayerQuitEvent event) {
            event.setQuitMessage(event.getPlayer().getName() + " left my server :(");
        }
       
    }
     
  2. Also does somebody know any plugin development books?
     
  3. You forgot to register your events. No Spigot books exist, you can learn with a Java one. I suggest Effective Java 2nd edition and Clean Code
     
  4. Websites like Lynda.com are very good. My Dad got a free licence from the company he works for so I use it whenever I want to improve my practices.
     
  5. You forgot to do
    Code (Text):
    Bukkit.getServer().getPluginManager().registerEvents(this, this)
    type that in the on enable
     
    • Agree Agree x 1
  6. There are plenty of spigot/bukkit tutorials on youtube as well. The API hasn't changed too much to make them irrelevant, but Domboing is correct with the answer to your problem
     
  7. Just because you've just started off you likely wont know what this means.
    The first "this" relates to the class which is the listener, as you register events in your main class you can just reference the class you're in using "this". If you were registering an event in another class you'd do the following:
    Code (Text):
    Bukkit.getServer().getPluginManager().registerEvents(new otherClassListener, this);
    //The "otherClassListener" would be a class other than Main
     
    The second "this" is the instance of your plugin which as you're registering in the main class it's just "this"
     
  8. Thanks to all. I did it :)!!!
     
Thread Status:
Not open for further replies.