Skip to content

A few improvements to the classes #2

Description

@DarkSeraphim
  • Don't statically fetch the plugin instance, use dependency injection instead (pass it through the constructor, as a parameter)
  • Do mind the random imports.
  • Don't use public on fields unless they're final & immutable (or at least, 99% of the time).
  • Do use == for enum comparison (the enum class does this in it's equals method anyway, but == is null safe).
  • Do prefer if (!statement) { return; } // rest of code over if (statement) { // rest of code } as it reduces nesting depth by a great deal (EDIT: some classes seem to use it, some don't).
  • Sometimes there's still section signs, try to stick to ChatColor.
  • Do avoid asynchronous tasks for small things, and absolutely do avoid them when Bukkit / Minecraft is involved and it's not guaranteed to be thread safe.
  • Do prefer Runnables over BukkitRunnable if you're not using the cancel() method. (this means you should probably use it in all cases of runTask and runTaskLater).
  • Liskov Substitution Principle! Program against abstractions rather than implementations (i.e. use List rather than ArrayList, Set rather than HashSet, Map rather than HashMap, etc, when choosing a type for a variable, parameter or field).
  • Sets are faster than Lists. Importing a List once and converting it to a Set will give you a nice performance boost if your List gets large.

And sometimes a few spelling errors which I cannot bother to link (but who cares about that, the compiler sure doesn't).

Still, probably one of the cleaner tutorials I've seen online.

[EDIT] Seems it doesn't like multiline codeblocks in lists :/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions