When you want to spawn a custom entity, e.g. with a custom name or certain items equipped, you must use the method World#spawn(Location, Class<T extends Entity>, Consumer<T>) unless you give a shit about compatibility with other plugins. I’ll explain why. The shitty way Usually, you can easily spawn entities like this: That is fine, as…
Author: mfnalex
Java’s init blocks
Java allows you to use the so called “init blocks”. You can declare static and instance init blocks. The static init blocks will run exactly once, when the ClassLoader loads the class that declares it, and the instance init blocks run everytime you construct a new object, after the actual constructor ran. The general order…
Bukkit vs. Spigot-API vs. CraftBukkit vs. Spigot
Some people are confused about what the difference between Bukkit, Spigot-API, CraftBukkit and Spigot is, so I’ll try to explain. Bukkit is the basic API Bukkit contains all the usual interfaces and enums, like org.bukkit.entity.Player or org.bukkit.Material. For most plugins, this is all you need. It does not contain any implementations, meaning: you cannot “run”…
Switching from Spigot mappings to Mojang mappings
If you are switching from Spigot’s mappings (with class names like EntityZombie, WorldServer, PacketPlayOutSpawnEntity…) to Mojang mappings, you will notice that many of the classes you were using can’t be found anymore, since they now have different names. You will have to change all your references to those classes to their new names. Setup Mojang…
Creating custom heads in Spigot 1.18.1+
Spigot 1.18.1 added the new PlayerProfiles class, which finally allows us to use custom heads without needing any reflection! You can obtain them as normal items, or actually place them down into the world. I’ll show you how both works: Creating a new PlayerProfile First, we gotta create a new PlayerProfile object. To do so,…
Three Common Maven Questions
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 / file name? Changing the file name and output directory of your .jar file simply requires some changes in the maven-jar-plugin. If you don’t have it inside your pom.xml yet,…
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…