T2C-AllayDuplicate/src/main/java/net/t2code/t2callayduplicate/system/Main.java

145 lines
6.3 KiB
Java
Raw Normal View History

2022-11-14 13:32:47 +00:00
package net.t2code.t2callayduplicate.system;
import net.t2code.t2callayduplicate.Hooks.LandsIntegratior;
import net.t2code.t2callayduplicate.Hooks.PlotSquaredIntegration;
import net.t2code.t2callayduplicate.Util;
import net.t2code.t2callayduplicate.commands.CmdExecuter;
import net.t2code.t2callayduplicate.config.ConfigFile;
import net.t2code.t2callayduplicate.event.Event;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate;
import net.t2code.t2codelib.SPIGOT.api.plugins.T2CpluginCheck;
import net.t2code.t2codelib.SPIGOT.api.register.T2Cregister;
import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI;
import org.bukkit.Bukkit;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.util.logging.Level;
public final class Main extends JavaPlugin {
private static Main plugin;
private static Boolean enable = false;
public static File getPath() {
return plugin.getDataFolder();
}
private Event event;
@Override
public void onEnable() {
// Plugin startup logic
plugin = this;
if (!Bukkit.getVersion().contains("1.19") || Bukkit.getVersion().contains("1.19.1")) {
plugin.getLogger().log(Level.SEVERE, "");
plugin.getLogger().log(Level.SEVERE, "");
plugin.getLogger().log(Level.SEVERE, "");
plugin.getLogger().log(Level.SEVERE, "This plugin is only for version 1.19!");
plugin.getLogger().log(Level.SEVERE, "Plugin can not be loaded!");
plugin.getLogger().log(Level.SEVERE, "Our Discord: http://dc.t2code.net\"");
plugin.getLogger().log(Level.SEVERE, "");
plugin.getLogger().log(Level.SEVERE, "");
plugin.getLogger().log(Level.SEVERE, "");
Bukkit.getPluginManager().disablePlugin(this);
return;
}
if (pluginNotFound("T2CodeLib", 96388, Util.getRequiredT2CodeLibVersion())) return;
enable = true;
long long_ = T2Ctemplate.onLoadHeader(Util.getPrefix(), this.getDescription().getAuthors(), this.getDescription().getVersion(), Util.getSpigot(), Util.getDiscord());
2022-11-15 14:40:38 +00:00
2022-11-14 13:32:47 +00:00
Metrics.Bstats();
if (T2CpluginCheck.plotSquared()) {
plotsquared = true;
plotSquaredIntegration = new PlotSquaredIntegration();
T2Csend.console(Util.getPrefix() + " §2Load Hook: §6PlotSquared - " + T2CpluginCheck.pluginInfos("PlotSquared").getDescription().getVersion());
}
if (T2CpluginCheck.pluginCheck("Lands")) {
lands = true;
landsintegrator = new LandsIntegratior(this);
T2Csend.console(Util.getPrefix() + " §2Load Hook: §6Lands - " + T2CpluginCheck.pluginInfos("Lands").getDescription().getVersion());
}
ConfigFile.create();
ConfigFile.select();
2022-11-15 14:40:38 +00:00
T2CupdateAPI.onUpdateCheck(plugin, Util.getPrefix(),Util.getGit(), Util.getSpigotID(), Util.getDiscord()
,ConfigFile.getUpdateCheckOnJoin(),ConfigFile.getUpdateCheckSeePreReleaseUpdates(),ConfigFile.getUpdateCheckTimeInterval());
2022-11-14 13:32:47 +00:00
this.getCommand("t2c-allayduplicate").setExecutor(new CmdExecuter());
T2Cregister.listener(new Event(), this);
T2Ctemplate.onLoadFooter(Util.getPrefix(), long_);
}
@Override
public void onDisable() {
// Plugin shutdown logic
HandlerList.unregisterAll(event);
if (enable) T2Ctemplate.onDisable(Util.getPrefix(), this.getDescription().getAuthors(), this.getDescription().getVersion(), Util.getSpigot(), Util.getDiscord());
}
public static Boolean pluginNotFound(String pl, Integer spigotID, String ver) {
if (Bukkit.getPluginManager().getPlugin(pl) == null) {
plugin.getLogger().log(Level.SEVERE, "Plugin can not be loaded!");
Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §e" + pl + " §4could not be found. Please download it here: "
+ "§6https://spigotmc.org/resources/" + pl + "." + spigotID + " §4to be able to use this plugin.");
Main.plugin.getPluginLoader().disablePlugin(Main.plugin);
return true;
} else {
String plVer = Bukkit.getPluginManager().getPlugin(pl).getDescription().getVersion();
if (ver.contains("_")) {
if (!plVer.equals(ver)) {
plugin.getLogger().log(Level.SEVERE, "Plugin can not be loaded!");
Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §e" + pl + " §4is out of date! This plugin requires the version §2"
+ ver + " §4of §6" + pl + " §4Please use this version! Please download it here: §6https://spigotmc.org/resources/"
+ pl + "." + spigotID + " Or contact us in Discord: http://dc.t2code.net");
Main.plugin.getPluginLoader().disablePlugin(Main.plugin);
return true;
}
return false;
}
String[] split = plVer.split("_");
if (Double.parseDouble(split[0]) < Double.parseDouble(ver)) {
plugin.getLogger().log(Level.SEVERE, "Plugin can not be loaded!");
Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §e" + pl + " §4is out of date! This plugin requires at least version §2"
+ ver + " §4of §6" + pl + " §4Please update it here: §6https://spigotmc.org/resources/" + pl + "." + spigotID
+ " §4to use this version of " + plugin.getDescription().getName() + ".");
Main.plugin.getPluginLoader().disablePlugin(Main.plugin);
return true;
}
return false;
}
}
public static Main getPlugin() {
return plugin;
}
private static boolean plotsquared = false;
private static boolean lands = false;
private static PlotSquaredIntegration plotSquaredIntegration = null;
private static LandsIntegratior landsintegrator = null;
public static boolean isPlotsquared() {
return plotsquared;
}
public static PlotSquaredIntegration getPlotSquaredIntegration() {
return plotSquaredIntegration;
}
public static boolean isLands() {
return lands;
}
public static LandsIntegratior getLandsintegrator() {
return landsintegrator;
}
}