2020-01-30 11:50:29 +00:00
|
|
|
package nl.SBDeveloper.V10Lift;
|
|
|
|
|
2020-07-01 20:44:57 +00:00
|
|
|
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;
|
2020-02-21 09:18:59 +00:00
|
|
|
import org.bstats.bukkit.Metrics;
|
2020-02-01 10:25:24 +00:00
|
|
|
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;
|
2020-02-02 20:01:28 +00:00
|
|
|
private static DBManager dbManager;
|
2020-02-27 11:45:05 +00:00
|
|
|
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;
|
|
|
|
|
2020-02-16 07:47:28 +00:00
|
|
|
//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
|
|
|
|
2020-02-27 11:45:05 +00:00
|
|
|
//Load the messages
|
|
|
|
messages = new YamlFile("messages");
|
|
|
|
messages.loadDefaults();
|
|
|
|
|
2020-02-16 07:47:28 +00:00
|
|
|
//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();
|
|
|
|
}
|
|
|
|
|
2020-02-16 07:47:28 +00:00
|
|
|
//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();
|
|
|
|
}
|
|
|
|
|
2020-02-16 07:47:28 +00:00
|
|
|
//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());
|
2020-02-01 10:25:24 +00:00
|
|
|
|
2020-02-16 07:47:28 +00:00
|
|
|
//Register the listeners
|
2020-02-01 10:25:24 +00:00
|
|
|
Bukkit.getPluginManager().registerEvents(new PlayerInteractListener(), this);
|
|
|
|
Bukkit.getPluginManager().registerEvents(new BlockBreakListener(), this);
|
|
|
|
Bukkit.getPluginManager().registerEvents(new SignChangeListener(), this);
|
|
|
|
Bukkit.getPluginManager().registerEvents(new EntityDamageListener(), this);
|
|
|
|
|
2020-02-21 09:18:59 +00:00
|
|
|
//Load metrics
|
2020-02-25 12:34:58 +00:00
|
|
|
Bukkit.getLogger().info("[V10Lift] Loading metrics. Can be disabled in the global bStats config.");
|
2020-02-21 09:18:59 +00:00
|
|
|
Metrics metrics = new Metrics(this, 6564);
|
|
|
|
metrics.addCustomChart(new Metrics.SingleLineChart("lifts", () -> DataManager.getLifts().size()));
|
|
|
|
|
2020-02-16 07:47:28 +00:00
|
|
|
//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) -> {
|
2020-02-21 09:18:59 +00:00
|
|
|
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();
|
2020-02-21 09:18:59 +00:00
|
|
|
} 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-02 20:01:28 +00:00
|
|
|
|
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-16 07:47:28 +00:00
|
|
|
|
2020-02-25 12:14:49 +00:00
|
|
|
dbManager.save();
|
2020-02-02 20:01:28 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-02-27 11:45:05 +00:00
|
|
|
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
|
|
|
}
|