People just getting started with maven always ask me the same 3 questions, so here’s a a short FAQ! How to change the output directory? Read this. How to shade dependencies and what it means Sometimes you are using certain libraries (for example, my CustomBlockData class, or similar stuff) that is not already present at…
Don’t jump off bridges, or: Why you shouldn’t use Exceptions to control code flow
Exceptions are a wonderful thing. They can let your code recover from unexpected situations in a nice and clean way, if you use them properly. That does not mean that you should always rely on them though. For example, imagine this: Most highways have guardrails in the middle to avoid cars going into oncoming traffic….
Manually installing .jar files to your local Maven repository
Sometimes you have a certain .jar file that you need as dependency, but the author of that .jar was too lazy to properly upload it to a public repository. That’s bad, but not a problem. There are two ways to solve this, but only one proper way. The proper way: install the dependency The proper…
Why the GPL does NOT directly apply to all Spigot plugins
Many people claim that all Spigot plugins have to follow the GPL license. This is a common false statement made by people who have not studied the basics of contract law. Disclaimer The following text only represents the opinion of the author, who has studied law and is an approved lawyer in Germany as the…
Accessing your main instance from another class
You often need a reference to your main instance (the instance of your class that extends JavaPlugin) in some of your other classes. There’s two basic concepts for this. Choose whichever you like more. Method #1: Static Getter First way is to create a static method called getInstance() or similar in your main class. You…
Understanding Lambdas and Method References
Lambdas and Method references can be used to make your code way shorter, and (sometimes) more readable by getting rid of anonymous classes. What are Anonymous Classes? Anonymous classes are like local classes without a name. Imagine you have the following code: We hereby declare and instantiate a class implementing java.lang.Runnable that just prints some…
NMS: Use Mojang maps for your Spigot plugins with Maven or Gradle
If you need to access NMS classes from inside your Spigot plugin, it is a very good idea to use the so called Mojang mappings. Disclaimer: This post is written for 1.20.4. If you use another version, you of course have to replace every occurance of “1.20.4” with the version you actually use. What are…
Give your variables descriptive names, FFS!
Most people who get started with Spigot development somehow think it’s a good idea to make everything as short as possible (at least in terms of naming variables). This is considered bad practice for a good reason. What’s the problem? Let’s imagine this is your code: In this example, it is obvious in line 4…
Avoiding the arrow anti-pattern
When you read this, chances are high that someone saw your code and decided that you did something that is considered horribly bad: using the arrow anti-pattern. What the arrow anti-pattern is Look at the following code: It looks like a huge arrow (>) symbol. It’s ugly, unreadable and hard to maintain. Now, let’s say…
Using NMS classes with Maven
Many people are confused on how to use NMS classes when they’re new to writing Bukkit/Spigot plugins because their IDE doesn’t find those classes. Don’t worry. What is NMS? NMS refers to net.minecraft.server. This package contains all the classes that Mojang wrote for the vanilla Minecraft Server. You can use them to change the server’s…