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…
Month: December 2021
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…