forked from PyvesB/advanced-achievements
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathAdvancedAchievements.java
More file actions
84 lines (69 loc) · 3.26 KB
/
AdvancedAchievements.java
File metadata and controls
84 lines (69 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package com.hm.achievement;
import com.hm.achievement.api.AdvancedAchievementsAPI;
import com.hm.achievement.api.AdvancedAchievementsBukkitAPI;
import com.hm.achievement.exception.PluginLoadError;
import com.hm.achievement.lifecycle.PluginLoader;
import com.hm.achievement.module.CleanableModule;
import com.hm.achievement.module.CommandModule;
import com.hm.achievement.module.ConfigModule;
import com.hm.achievement.module.DatabaseModule;
import com.hm.achievement.module.ReloadableModule;
import com.hm.achievement.module.ServerVersionModule;
import dagger.BindsInstance;
import dagger.Component;
import jakarta.inject.Singleton;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
@Singleton
@Component(modules = {CleanableModule.class, CommandModule.class, ConfigModule.class, DatabaseModule.class, ReloadableModule.class, ServerVersionModule.class})
interface AdvancedAchievementsComponent {
PluginLoader pluginLoader();
AdvancedAchievementsBukkitAPI advancedAchievementsBukkitAPI();
@Component.Builder
interface Builder {
@BindsInstance
Builder advancedAchievements(AdvancedAchievements advancedAchievements);
@BindsInstance
Builder logger(Logger logger);
@SuppressWarnings("ClassEscapesDefinedScope")
AdvancedAchievementsComponent build();
}
}
/**
* Bukkit instantiates an instance of this class and calls the onEnable and onDisable methods when relevant. This class
* is the root of the dependency graph constructed with Dagger and is used to bind the instance created by Bukkit with
* the rest of the plugin modules. It delegates the actual enabling and disabling operations to the PluginLoader class.
*
* @author Pyves
*/
public class AdvancedAchievements extends JavaPlugin {
private PluginLoader pluginLoader;
private AdvancedAchievementsAPI advancedAchievementsAPI;
@Override
public void onEnable() {
long startTime = System.currentTimeMillis();
// DaggerAdvancedAchievementsComponent is generated by Dagger. Add target/generated-sources/annotations to your
// build path if the IDE complains here. In any case this will not actually prevent you from compiling.
AdvancedAchievementsComponent advancedAchievementsComponent = DaggerAdvancedAchievementsComponent.builder().advancedAchievements(this).logger(getLogger()).build();
pluginLoader = advancedAchievementsComponent.pluginLoader();
advancedAchievementsAPI = advancedAchievementsComponent.advancedAchievementsBukkitAPI();
try {
pluginLoader.loadAdvancedAchievements();
} catch (PluginLoadError e) {
getLogger().log(Level.SEVERE, "A non recoverable error was encountered while loading the plugin, disabling it:", e);
Bukkit.getPluginManager().disablePlugin(this);
return;
}
getLogger().info("Plugin has finished loading and is ready to run! Took " + (System.currentTimeMillis() - startTime) + "ms.");
}
@Override
public void onDisable() {
pluginLoader.disableAdvancedAchievements();
}
@SuppressWarnings("unused")
public AdvancedAchievementsAPI getAdvancedAchievementsAPI() {
return advancedAchievementsAPI;
}
}