V10Lift/src/main/lombok/nl/SBDeveloper/V10Lift/V10LiftPlugin.java

145 lines
5.7 KiB
Java
Raw Normal View History

2020-01-30 11:50:29 +00:00
package nl.SBDeveloper.V10Lift;
import nl.SBDeveloper.V10Lift.api.V10LiftAPI;
import nl.SBDeveloper.V10Lift.commands.V10LiftCommand;
import nl.SBDeveloper.V10Lift.commands.V10LiftTabCompleter;
import nl.SBDeveloper.V10Lift.listeners.BlockBreakListener;
import nl.SBDeveloper.V10Lift.listeners.EntityDamageListener;
import nl.SBDeveloper.V10Lift.listeners.PlayerInteractListener;
import nl.SBDeveloper.V10Lift.listeners.SignChangeListener;
import nl.SBDeveloper.V10Lift.managers.DBManager;
import nl.SBDeveloper.V10Lift.managers.DataManager;
import nl.SBDeveloper.V10Lift.managers.VaultManager;
import nl.SBDeveloper.V10Lift.sbutils.UpdateManager;
import nl.SBDeveloper.V10Lift.sbutils.YamlFile;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
2020-01-30 11:50:29 +00:00
import org.bukkit.plugin.java.JavaPlugin;
2020-02-03 13:44:22 +00:00
import java.sql.SQLException;
2020-02-27 14:24:56 +00:00
import java.time.LocalDate;
2020-02-03 14:10:28 +00:00
import java.util.Objects;
2020-02-03 13:44:22 +00:00
2020-01-30 11:50:29 +00:00
public class V10LiftPlugin extends JavaPlugin {
private static V10LiftPlugin instance;
2020-02-06 18:46:15 +00:00
private static YamlFile config;
private static DBManager dbManager;
private static YamlFile messages;
2020-01-30 11:50:29 +00:00
private static V10LiftAPI api;
2020-02-25 09:34:19 +00:00
private static boolean vault = false;
2020-01-30 11:50:29 +00:00
@Override
public void onEnable() {
instance = this;
//Load the config
2020-02-06 18:46:15 +00:00
config = new YamlFile("config");
config.loadDefaults();
2020-01-30 11:50:29 +00:00
//Load the messages
messages = new YamlFile("messages");
messages.loadDefaults();
//Load the database
2020-02-06 18:46:15 +00:00
dbManager = new DBManager("data");
2020-02-03 13:44:22 +00:00
try {
dbManager.load();
2020-02-25 12:14:49 +00:00
} catch (SQLException e) {
2020-02-03 13:44:22 +00:00
e.printStackTrace();
}
//Load the API
2020-01-30 11:50:29 +00:00
api = new V10LiftAPI();
2020-02-25 09:34:19 +00:00
//Load vault if found
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") != null) {
2020-02-25 12:34:58 +00:00
Bukkit.getLogger().info("[V10Lift] Loading Vault hook for group whitelist support.");
2020-02-25 09:34:19 +00:00
vault = true;
VaultManager.setupPermissions();
}
//Load the command
2020-02-03 14:10:28 +00:00
Objects.requireNonNull(getCommand("v10lift"), "Internal error! Command not found.").setExecutor(new V10LiftCommand());
2020-02-21 09:51:37 +00:00
Objects.requireNonNull(getCommand("v10lift"), "Internal error! Command not found.").setTabCompleter(new V10LiftTabCompleter());
//Register the listeners
Bukkit.getPluginManager().registerEvents(new PlayerInteractListener(), this);
Bukkit.getPluginManager().registerEvents(new BlockBreakListener(), this);
Bukkit.getPluginManager().registerEvents(new SignChangeListener(), this);
Bukkit.getPluginManager().registerEvents(new EntityDamageListener(), this);
//Load metrics
2020-02-25 12:34:58 +00:00
Bukkit.getLogger().info("[V10Lift] Loading metrics. Can be disabled in the global bStats config.");
Metrics metrics = new Metrics(this, 6564);
metrics.addCustomChart(new Metrics.SingleLineChart("lifts", () -> DataManager.getLifts().size()));
//Load the update checker
2020-02-21 09:23:01 +00:00
if (!getSConfig().getFile().contains("CheckUpdates") || getSConfig().getFile().getBoolean("CheckUpdates")) {
2020-04-15 10:50:04 +00:00
UpdateManager manager = new UpdateManager(this, 72317, UpdateManager.CheckType.SPIGOT);
manager.handleResponse((versionResponse, version) -> {
if (versionResponse == UpdateManager.VersionResponse.FOUND_NEW) {
Bukkit.getLogger().warning("[V10Lift] There is a new version available! Current: " + this.getDescription().getVersion() + " New: " + version);
2020-04-15 10:50:04 +00:00
Bukkit.getLogger().info("[V10Lift] Trying to download...");
manager.handleDownloadResponse((downloadResponse, path) -> {
if (downloadResponse == UpdateManager.DownloadResponse.DONE) {
Bukkit.getLogger().info("[V10Lift] Update done! After a restart, it should be loaded.");
} else if (downloadResponse == UpdateManager.DownloadResponse.UNAVAILABLE) {
Bukkit.getLogger().warning("[V10Lift] Couldn't download the update, because it's not a Spigot resource.");
} else if (downloadResponse == UpdateManager.DownloadResponse.ERROR) {
Bukkit.getLogger().severe("[V10Lift] Unable to download the newest file.");
}
}).runUpdate();
} else if (versionResponse == UpdateManager.VersionResponse.LATEST) {
Bukkit.getLogger().info("[V10Lift] You are running the latest version [" + this.getDescription().getVersion() + "]!");
} else if (versionResponse == UpdateManager.VersionResponse.UNAVAILABLE) {
Bukkit.getLogger().severe("[V10Lift] Unable to perform an update check.");
}
}).check();
}
2020-02-03 13:44:22 +00:00
Bukkit.getLogger().info("[V10Lift] Plugin loaded successfully!");
2020-02-27 14:24:56 +00:00
//1 month sponsored advertising
if (LocalDate.now().getMonthValue() == 3) {
Bukkit.getLogger().info("[V10Lift] FrogNetwork! Een server met Minetopia, F1 Racing en #soon meer! Join via play.frognetwork.eu");
}
2020-01-30 11:50:29 +00:00
}
@Override
public void onDisable() {
2020-02-03 17:30:41 +00:00
V10LiftPlugin.getDBManager().removeFromData();
2020-02-25 12:14:49 +00:00
dbManager.save();
dbManager.closeConnection();
2020-02-03 17:30:41 +00:00
instance = null;
2020-01-30 11:50:29 +00:00
}
public static V10LiftPlugin getInstance() {
return instance;
}
2020-02-06 18:46:15 +00:00
public static YamlFile getSConfig() {
2020-01-30 11:50:29 +00:00
return config;
}
2020-02-03 14:40:49 +00:00
public static DBManager getDBManager() {
return dbManager;
}
public static YamlFile getMessages() {
return messages;
}
2020-01-30 11:50:29 +00:00
public static V10LiftAPI getAPI() {
return api;
}
2020-02-25 09:34:19 +00:00
public static boolean isVaultEnabled() {
return vault;
}
2020-01-30 11:50:29 +00:00
}