Plugin Help and Advice.

Discussion in 'Spigot Plugin Development' started by Aeryes, May 15, 2016.

  1. Hey guys,

    So, today I finished the first part of my first ever Spigot plugin and I was wondering if you guys would be able to take some time to view it and give me some tips on improvements, mistakes and anything else that you might see.

    The plugin at this moment is just a simple Broadcast plugin with a root command and a help command. I have also added a player join and rejoin event. The config that is created is the next part of my plugin where I hope to allow users to set custom join and rejoin messages. I will be moving onto this section tomorrow.

    I have done my best to tidy up my code as best as I could. I am new to Java in general and more especially the Spigot community. I have ran servers etc in the past but only recently have I dived into making plugins and using what I learn to jump start me into the programming world, so go easy on me and help me out :) !!

    Thank you very much for your time guys and I hope my work is of decent standard.
    Below is a github link to my repository for the plugin source code.

    Source (

    Thank you,
  2. In your listener class, you could've done

    if (!(player.hasPlayedBefore() {


    Besides that, just work on some formatting, was a pain reading some of that.
    • Useful Useful x 1
  3. So this doesn't actually affect your code, just the fact to clean it up a bit. these are unnecessary line returns, you should remove them. A class shouldn't have the world 'Class' in it, you might want to rename that to Permissions.
    Overall, you should review the tabs you put here .

    In eclipse, you can use CTRL+SHIFT+F to format the code automatically, that will most likely do the majority of the job for you.

    Actually, why did you make that Permissions class if you don't even use it in Commands?
    • Useful Useful x 1
  4. plugin.yml
    usage: /announceit broadcast <messege> , messege should be message
    I don't think you "need" to register args, there's no permission preset for the commands
    The package shouldn't contain a capital, "com.annouceit.AnnounceIt" also you should use your name so maybe "me.aeryes.announceit"
    Main Class
    You should probably make your fields have a "protected" or "public" or "private" modifier, looks more professional / works better imo
    Code (Java):
    I kind of recommend not using getConfig().options().copyDefaults(true); because that's already done for you in the JavaPlugin#saveDefaultConfig(); method
    Maybe initialize your fields in the onEnable, not outside because it could mess up a little bit if initialized outside, (I think it's better practice, start early)
    You don't need the "Announceit has been enabled" as it already sends that message in the onEnable by itself
    In the onDisable you don't need to clear the handlerlist because it's done for you (AFAIK)
    Again same thing, you don't need the "x has been disabled"
    Permissions class
    You should initialize all of the variables inside of a constructor as it makes it cleaner and less chance of errors (AFAIK)
    Player Listener
    You don't need the == false, just do !player.hasPlayedBefore(), it works better like that, then you can use the else statement and it would work just as fine, maybe a bit better.
    Command Class
    You should put @Override above the onCommand method just so it overrides the base onCommand method (good practice)
    for the announceit don't have the args check mainly because you never check args[0] so it doesn't make sense to have it
    It's nice but you can put all of your args checks inside of a huge if(cmd.getLabel().equalsIgnoreCase("blah") && sender instanceof Player) {} body
    Your command class is very messy, hard to read, please fix that up re-push and I can have a better analysis of the class.

    Disregarding all the changes I suggested I think you made a very solid plugin, nice work!
    • Informative Informative x 1
    • Useful Useful x 1
  5. I would you all but there are so many replies. I will get to work fixing this up and looking into what you guys have said and Ill post an updated repository tomorrow. Thank you for all of the tips and advice I really appreciate it.

    I am gearing up for the future by making the Permissions. I plan to use them as I get further into this plugin. Also I just wanted to practice making them as I haven't done so before.

    What exactly is the function of a protected variable. I have looked it up but just can not grasp it well. I believe it has something to do with not been allowed for use in other packages??
  6. [​IMG]
    • Informative Informative x 1
  7. I can't figure out how to initialize the variables in a constructor and call them in my Main class. Any tips?
  8. You do it the same way e.g:
    Code (Java):
    protected final Class foo;
    public ClassB(){
        foo = do();
  9. Yes but I can't manage to use it in my main class it keeps popping up with errors.
  10. show me the errors please, there shouldn't be any.
  11. It just keeps giving me an error saying create a local variable. I just can't figure it out to be honest.
  12. screenshot? please
  13. Show your code please.