52 lines
1.3 KiB
Java
52 lines
1.3 KiB
Java
package me.unurled.sacredrealms.sr;
|
|
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.event.Listener;
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
/** The Manager class is a class that is used to manage data and events. */
|
|
public class Manager implements Listener {
|
|
|
|
/** Create a new manager */
|
|
public Manager() {
|
|
SR.plugin().managers().addManager(this);
|
|
Bukkit.getScheduler()
|
|
.runTaskAsynchronously(
|
|
SR.plugin(),
|
|
() -> {
|
|
load();
|
|
Bukkit.getPluginManager().registerEvents(this, SR.plugin());
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Get an instance of a manager
|
|
*
|
|
* @param clazz The class of the manager
|
|
* @return The instance of the manager
|
|
* @param <T> The type of the manager
|
|
*/
|
|
public static <T extends Manager> T getInstance(@NotNull Class<T> clazz) {
|
|
return clazz.cast(SR.plugin().managers().getManager(clazz));
|
|
}
|
|
|
|
/** Load the manager */
|
|
public void load() {
|
|
loadData();
|
|
}
|
|
|
|
/** Unload the manager */
|
|
public void unload() {
|
|
saveData();
|
|
}
|
|
|
|
/** Save the data */
|
|
public void saveData() {
|
|
/* method empty, so it isn't required by the extended child to implement it */
|
|
}
|
|
|
|
/** Load the data */
|
|
public void loadData() {
|
|
/* method empty, so it isn't required by the extended child to implement it */
|
|
}
|
|
}
|