-
-
Notifications
You must be signed in to change notification settings - Fork 45
Getting the plugin instance
games647 edited this page Mar 29, 2015
·
6 revisions
In order to access the ScoreboardStats in the onEnable() method, you need to tell Bukkit to load your plugin after ScoreboardStats. You can do this either with softdepend or depend in your plugin.yml.
Softdepend means that your plugin can still work without ScoreboardStats. Depend would check if the the plugin is available and if not your plugin won't be enabled. (See BukkitWiki)
...
softdepend:
- Plugin1
- ScoreboardStats
- Plugin2
...
...
softdepend: [Plugin1, ScoreboardStats, Plugin3]
...
private void getPluginInstance() {
//You should check if the plugin is available first
//otherwise it would throw a NoClassDefFoundError
if (Bukkit.getPluginManager().isPluginEnabled("ScoreboardStats")) {
//Added in 1.7.2
ScoreboardStats scoreboardStats = JavaPlugin
.getPlugin(ScoreboardStats.class);
}
}
private void getPluginInstance() {
//returns null if plugin wasn't found
Plugin plugin = Bukkit.getPluginManager().getPlugin("ScoreboardStats");
//you should check this before casting
ScoreboardStats scoreboardstats = (ScoreboardStats) plugin;
}