MOTD Advanced

Discussion in 'Plugin Development' started by Ziddia, Mar 15, 2011.

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

    Ziddia

    Hey,
    This is going to be my first plugin. I am trying to create a basic plugin which creates a MOTD for each different rank (putting hooks into Nijikokun's Permissions, of course(Or whoever's running it now))

    Anyway, I am getting my Java stuff ready and while I wait I write a bit of code for it. Credits to MadMonkeyCo for the base of this ^^

    Code for my main class:

    Code:
    package com.Ziddia.MOTDAdvanced;
    import org.bukkit.event.Event;
    import org.bukkit.event.Event.Priority;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class motd extends JavaPlugin{
        public static motd instance;
        private final MOTDAdvancedPlayerListener playerListener = new MOTDAdvancedPlayerListener();
        PluginDescriptionFile pdfFile = this.getDescription();
        @Override
        public void onEnable() {
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvent(Event.Type.PLAYER_LOGIN, playerListener, Priority.Normal, this);
            System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!");
        }
        @Override
        public void onDisable() {
            System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is disabled!");
        }
    Code for my listener:

    Code:
    package com.Ziddia.MOTDAdvanced;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerListener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.event.player.PlayerLoginEvent.Result;
    
    public class motdPlayerListener extends PlayerListener{
        @Override
        public void onPlayerLogin(PlayerLoginEvent event) {
            Player player = event.getPlayer();
            player.sendMessage("WELCOME TO AN AWESOME SERVER!!!");
        }
    }
    And the code for my plugin.yml:

    Code:
    name: MOTDAdvanced
    main: com.Ziddia.MOTDAdvanced.motd
    version: 1.0
    Now, I know that I haven't got the code in for the configuration of this. What I want to make is a config file with things like "builder-motd=Welcome Builder!" and "admin-motd=Welcome Sir!"

    I was wondering where I could put that- MadMonkeyCo said that the code base he made for the config file should be a separate class. What do I do with the rest of my code, then, to connect the two together?

    If you don't understand or want to see the original code, go here:
    http://forums.bukkit.org/threads/developers-please-help-new-guy.8539/

    Because I know I'm not good at explaining this stuff.

    Also, I want to know if you can find any bugs or problems with the code please.

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

    MadMonkeyCo

    I will help you with that as well. You need to create a new class, lets say you name it motdSettings that will hold the class for the config. Then you change the name of the class in the code I gave you to motdSettings. You will also have to change the class constructor.
    Now you can use the class in your main class. I already explained to you how to do it in the other post.
    If you need a code example let me know.
     
  3. Offline

    Ziddia

    Code:
    package ca.ziddia.motd;
    
    public class MOTDAdvanced {package ca.ziddia.motd;
    import org.bukkit.event.Event;
    import org.bukkit.event.Event.Priority;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class MOTDAdvanced extends JavaPlugin{
     public static motd instance;
     private final MOTDAdvancedPlayerListener playerListener = new motdPlayerListener();
    PluginDescriptionFile pdfFile = this.getDescription();
     @Override
     public void onEnable() {
         PluginManager pm = getServer().getPluginManager();
         pm.registerEvent(Event.Type.PLAYER_LOGIN, playerListener, Priority.Normal, this);
         System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!");
     }
     @Override
     public void onDisable() {
         System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is disabled!");
    
     }
    
    There's the code, dunno how it looks here :/

    Anyway, I get a few errors on Eclipse- is that normal?

    E.g.- Last line where it just has a } says "Multiple markers at this line:
    Syntax error, insert "}" to complete ClassBody
    Syntax error, insert "}" to complete ClassBody
     
  4. Offline

    MadMonkeyCo

    Remove line 3 and add an extra } at the end of your code.
    If you look at the top part of your code you see the problem is obvious.
    Also change "public static motd instance;" to "public static MOTDAdvanced instance"
    It needs to be "public static <class> instance" if you're going to use it. In this case you are.
     
  5. Offline

    Ziddia

    Okay thanks, I can see the problem on line 3 I think... Is it something to do with the fact it is an event called Event?
    That doesn't seem to make sense...

    Anyway I will fix it and do the listener and yml tomorrow, going to bed now...

    For your reference, I will be back on in about 11 hours, talk to you then or later tomorrow

    Expect the basic MOTD plugin tomorrow (no permissions support then though obviously- will speak to you tomorrow about hooks and the config file and stuff.

    And btw, Ty so much for all this, I'm well on my way to living my dream now :D
     
Thread Status:
Not open for further replies.

Share This Page