2023-08-13 14:00:38 +00:00
|
|
|
package tech.sbdevelopment.v10lift;
|
2020-01-30 11:50:29 +00:00
|
|
|
|
2023-08-13 14:19:15 +00:00
|
|
|
import lombok.Getter;
|
|
|
|
import org.bstats.bukkit.Metrics;
|
|
|
|
import org.bstats.charts.SingleLineChart;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
2023-08-13 14:00:38 +00:00
|
|
|
import tech.sbdevelopment.v10lift.commands.V10LiftCommand;
|
|
|
|
import tech.sbdevelopment.v10lift.commands.V10LiftTabCompleter;
|
|
|
|
import tech.sbdevelopment.v10lift.listeners.BlockBreakListener;
|
|
|
|
import tech.sbdevelopment.v10lift.listeners.EntityDamageListener;
|
|
|
|
import tech.sbdevelopment.v10lift.listeners.PlayerInteractListener;
|
|
|
|
import tech.sbdevelopment.v10lift.listeners.SignChangeListener;
|
|
|
|
import tech.sbdevelopment.v10lift.managers.DBManager;
|
|
|
|
import tech.sbdevelopment.v10lift.managers.DataManager;
|
|
|
|
import tech.sbdevelopment.v10lift.managers.VaultManager;
|
|
|
|
import tech.sbdevelopment.v10lift.sbutils.ConfigUpdater;
|
|
|
|
import tech.sbdevelopment.v10lift.sbutils.UpdateManager;
|
|
|
|
import tech.sbdevelopment.v10lift.sbutils.YamlFile;
|
2020-01-30 11:50:29 +00:00
|
|
|
|
2021-04-07 08:41:01 +00:00
|
|
|
import java.io.IOException;
|
2020-02-03 13:44:22 +00:00
|
|
|
import java.sql.SQLException;
|
2021-04-07 08:41:01 +00:00
|
|
|
import java.util.Collections;
|
2020-02-03 13:44:22 +00:00
|
|
|
|
2020-01-30 11:50:29 +00:00
|
|
|
public class V10LiftPlugin extends JavaPlugin {
|
|
|
|
|
2023-08-13 14:19:15 +00:00
|
|
|
@Getter
|
2020-01-30 11:50:29 +00:00
|
|
|
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;
|
2023-08-13 14:19:15 +00:00
|
|
|
@Getter
|
2020-02-27 11:45:05 +00:00
|
|
|
private static YamlFile messages;
|
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
|
|
|
|
2021-04-07 08:41:01 +00:00
|
|
|
//And update config
|
|
|
|
try {
|
|
|
|
ConfigUpdater.update(this, "config.yml", config.getJavaFile(), Collections.emptyList());
|
|
|
|
} catch (IOException e) {
|
|
|
|
Bukkit.getLogger().warning("[V10Lift] Couldn't update the config.yml. Please check the stacktrace below.");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
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) {
|
2021-04-07 08:41:01 +00:00
|
|
|
Bukkit.getLogger().warning("[V10Lift] Couldn't connect to the SQLite database. Please check the stacktrace below.");
|
2020-02-03 13:44:22 +00:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
2020-02-25 09:34:19 +00:00
|
|
|
//Load vault if found
|
2021-04-07 08:41:01 +00:00
|
|
|
if (VaultManager.setupPermissions()) {
|
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;
|
|
|
|
}
|
|
|
|
|
2020-02-16 07:47:28 +00:00
|
|
|
//Load the command
|
2021-03-24 11:15:01 +00:00
|
|
|
getCommand("v10lift").setExecutor(new V10LiftCommand());
|
|
|
|
getCommand("v10lift").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);
|
2021-06-08 14:36:16 +00:00
|
|
|
metrics.addCustomChart(new SingleLineChart("lifts", () -> DataManager.getLifts().size()));
|
2020-02-21 09:18:59 +00:00
|
|
|
|
2020-02-16 07:47:28 +00:00
|
|
|
//Load the update checker
|
2021-04-07 08:41:01 +00:00
|
|
|
if (getSConfig().getFile().getBoolean("UpdateChecker.Enabled")) {
|
|
|
|
UpdateManager updateManager = new UpdateManager(this, 72317);
|
|
|
|
|
|
|
|
updateManager.handleResponse((versionResponse, version) -> {
|
|
|
|
switch (versionResponse) {
|
|
|
|
case FOUND_NEW:
|
|
|
|
Bukkit.getLogger().warning("[V10Lift] There is a new version available! Current: " + this.getDescription().getVersion() + " New: " + version.get());
|
|
|
|
if (getSConfig().getFile().getBoolean("UpdateChecker.DownloadOnUpdate")) {
|
|
|
|
Bukkit.getLogger().info("[V10Lift] Trying to download the update. This could take some time...");
|
|
|
|
|
|
|
|
updateManager.handleDownloadResponse((downloadResponse, fileName) -> {
|
|
|
|
switch (downloadResponse) {
|
|
|
|
case DONE:
|
|
|
|
Bukkit.getLogger().info("[V10Lift] Update downloaded! If you restart your server, it will be loaded. Filename: " + fileName);
|
|
|
|
break;
|
|
|
|
case ERROR:
|
|
|
|
Bukkit.getLogger().severe("[V10Lift] Something went wrong when trying downloading the latest version.");
|
|
|
|
break;
|
|
|
|
case UNAVAILABLE:
|
|
|
|
Bukkit.getLogger().warning("[V10Lift] Unable to download the latest version.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}).runUpdate();
|
2020-04-15 10:50:04 +00:00
|
|
|
}
|
2021-04-07 08:41:01 +00:00
|
|
|
break;
|
|
|
|
case LATEST:
|
|
|
|
Bukkit.getLogger().info("[V10Lift] You are running the latest version [" + this.getDescription().getVersion() + "]!");
|
|
|
|
break;
|
|
|
|
case THIS_NEWER:
|
|
|
|
Bukkit.getLogger().info("[V10Lift] You are running a newer version [" + this.getDescription().getVersion() + "]! This is probably fine.");
|
|
|
|
break;
|
|
|
|
case UNAVAILABLE:
|
|
|
|
Bukkit.getLogger().severe("[V10Lift] Unable to perform an update check.");
|
|
|
|
break;
|
2020-02-21 09:18:59 +00:00
|
|
|
}
|
|
|
|
}).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-01-30 11:50:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDisable() {
|
2022-06-15 09:14:15 +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
|
|
|
}
|
|
|
|
|
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-25 09:34:19 +00:00
|
|
|
public static boolean isVaultEnabled() {
|
|
|
|
return vault;
|
|
|
|
}
|
2020-01-30 11:50:29 +00:00
|
|
|
}
|