Feedback/advice on my code and plugin?

Discussion in 'Spigot Plugin Development' started by YonatanX, Jun 5, 2017.

  1. I'm looking for feedback for my source code and plugin itself, I know there are lots of bad habits so I'd like you guys to point them out.

    Features include:
    · Freeze the entire server.
    · Freeze a player.
    · Inventory Lock (while also providing a way to communicate)
    · Configurable

    SOURCE: https://github.com/yoloprobro/FreezePlus/
     
  2. Advice: Please do not static abuse... static is for handling memory, not making it yourself easier
     
    • Agree Agree x 2
    • Like Like x 1
  3. Like the guy above said, don't abuse static.
     
    • Like Like x 1
  4. Creating methods that execute another method and called once is not useful..

    Code (Text):
    private void createConfig(){
       this.saveDefaultConfig();
    }
     
    • Like Like x 1
    • Agree Agree x 1
  5. Thank you all. What about now, anything else?
     
  6. This is more of a style choice, but I think it's better to return early rather than nest code deeper and deeper.

    Instead of
    Code (Text):
    if (something) {
        if (something else) {
            if (let's go deeper) {
                if (does it ever end?!) {
                    // Do stuff
                } else error4;
            } else error3;
        } else error2;
    } else error1;
    Try this
    Code (Text):
    if (!something) {
        error1;
        return;
    }
    if (!something else) {
        error2;
        return;
    }
    if (!let's go deeper) {
        error3;
        return;
    }
    if (!does it ever end!?) {
        error4;
        return;
    }
    // do stuff
    It looks nicer. Easier to read and follow. Less horizontal scrolling. Easier to debug. Etc.
     
    • Agree Agree x 2
    • Like Like x 1