Did I code this right? MOTD plugin

Discussion in 'Plugin Development' started by Dnewhard, Oct 16, 2011.

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

    Dnewhard

    This is my first plugin, and my server is also not recognizing my plugin, which I would also like to be solved, but...

    I don't know if this will work, I just started coding in Java (My usual languages are C#, C++, etc)
    and I'm hoping I did this right.

    Code:
    package me.main.motd;
    
    import java.util.logging.Logger;
    
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.event.Event;
    import org.bukkit.event.player.PlayerListener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class MOTD extends JavaPlugin{
        public static MOTD plugin;
        public final Logger logger = Logger.getLogger("Minecraft");
        final FileConfiguration config = this.getConfig();
    
        @Override
        public void onDisable() {
            PluginDescriptionFile pdffile = this.getDescription();
            this.logger.info(pdffile + " is now disabled.");
    
        }
    
        @Override
        public void onEnable() {
            config.addDefault("message", "This is the default MOTD message, change it in config.yml");
            saveConfig();
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvent(Event.Type.PLAYER_LOGIN, listener, Event.Priority.Normal, this);
            PluginDescriptionFile pdffile = this.getDescription();
            this.logger.info(pdffile.getName() + " version " + pdffile.getVersion() + " is enabled.");
        }
    
        public final PlayerListener listener = new PlayerListener() {
            @Override
            public void onPlayerLogin(PlayerLoginEvent event) {
                event.getPlayer().sendMessage(config.getString("message"));
            }
        };
    }
     
  2. Offline

    Jaker232

    Make a damn directory line.
     
  3. Offline

    Dnewhard

    Explain.
     
  4. Offline

    Jaker232

    *facepalm*

    Code:java
    1.  
    2. File directory = new File("plugins" + File.separator + "DrinkMilk" + File.separator + "config.yml");
    3. directory.mkdir();
    4.  
     
  5. Offline

    Dnewhard

    Feel free to slap me, that seems insanely obvious now. *kicks self*
     
  6. Offline

    slayercraft

    just wondering if the plugin changes the motd automatically or do you have to change it
     
  7. Offline

    Theodossis

    To start motd type that event:
    Code:
    @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event){
            if (event.getPlayer().isOnline())
                    event.getPlayer().sendMessage(config.getString("message"));
     
  8. Offline

    slayercraft

    Jaker232 would you by anychance be able to make an automated hungergames plugin that doesnt let you join when a game is on and kicks you when you die and changes the motd to in progress when a game is on and has a 30min waiting period between games and it says how many minutes before the game starts.
    if so would you plz send a reply and ill get back to you

    theodossis

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

    Lolmewn

    As Theodossis said, you forgot to add @EventHandler before your event. onPlayerJoin won't work if you don't add it.
    You also have to let your class implement Listener, like this
    Code:java
    1. public class MyClass extends JavaPlugin implements Listener
     
  10. Offline

    ZNickq

    I know that post is old, but you do realise that line is wrong, right? lmao
     
  11. Offline

    md_5

    Next time lets take a look at the date before posting.
    Locked.
     
Thread Status:
Not open for further replies.

Share This Page