-
Notifications
You must be signed in to change notification settings - Fork 201
Basic tutorial
This basic tutorial will explain you how to check that HolographicDisplays is enabled (if stricly required) and how to create your first hologram.
First of all, use the latest version of HolographicDisplays while coding and ask your plugin's users to do the same. The API is constantly being expanded, and some methods could be missing in previous versions.
To use the API, you have to check if the plugin is installed and enabled. You can use the following code in your plugin.yml and in your onEnable() to check that the plugin is installed and enabled.
Add a soft-dependency to your plugin.yml:
softdepend: [HolographicDisplays]
If you use depend
in place of softdepend
your users will see an error on the console when the server starts if HolographicDisplays is not enabled, and your onEnable()
will not be called. I personally prefer to use softdepend
because you can customize the error message.
If HolographicDisplays is strictly required, you can use the following code:
@Override
public void onEnable() {
if (!Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays")) {
getLogger().severe("*** HolographicDisplays is not installed or not enabled. ***");
getLogger().severe("*** This plugin will be disabled. ***");
this.setEnabled(false);
return;
}
// Rest of the code
}
If it's not strictly required, you can just check if the plugin is enabled, and use a field in your plugin to see if you should make calls to the API:
private boolean useHolographicDisplays;
@Override
public void onEnable() {
useHolographicDisplays = Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays");
// Rest of the code
}
The API is a class called HologramsAPI, all the methods are static. With the method createHologram(...)
you can create a hologram with some lines. The method returns the hologram just created.
Example:
Plugin plugin = ... // Your plugin's instance
Location where = ... // A Location object
Hologram hologram = HologramsAPI.createHologram(plugin, where);
hologram.appendTextLine("A hologram line");
Done! With just two lines of code you created a hologram.
Javadocs: //TODO
Source: click here
Check out the Hologram class for a list of applicable methods.