The-SourceCode/Bukkit_Coding_Tutorial

A few improvements to the classes

DarkSeraphim opened this issue · 2 comments

  • 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 :/

X-yl commented

Adding on to this,

  • Follow Java naming conventions! No uppercase letters in packages!!!
  • indent your damned code.
  • Don't use the bungee ChatColor
  • You use your own serialisation for Location even though it implements ConfigurationSerializable.
  • Using NMS methods for no apparent reason
  • Not using @OverRide annotations.
  • There are more...

Actually, these also apply to your other repositories. Please actually know what you're doing before you make tutorials for others to soak up your bad practice.

Shout-out from the Spigot forums. Your tutorials have apparently become quite popular, and users often suggest them. Unfortunately, you don't hit the nail on the head every-time which is what is expected of a tutorial. Especially one that is targeted towards beginners.

Add Java colouration on your GitHub code!!!