149 lines
6.6 KiB
Java
149 lines
6.6 KiB
Java
package net.t2code.commandguiv2.Spigot;
|
|
|
|
import lombok.Getter;
|
|
import net.t2code.commandguiv2.Spigot.objects.Function;
|
|
import net.t2code.commandguiv2.Spigot.system.Load;
|
|
import net.t2code.commandguiv2.Spigot.objects.Gui;
|
|
import net.t2code.commandguiv2.Spigot.database.MySQL;
|
|
import net.t2code.commandguiv2.Spigot.system.Plugman;
|
|
import net.t2code.commandguiv2.Util;
|
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2C_Send;
|
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2C_Template;
|
|
import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2C_McVersion;
|
|
import net.t2code.t2codelib.SPIGOT.api.plugins.T2C_PluginCheck;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.plugin.Plugin;
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
import java.io.File;
|
|
import java.util.*;
|
|
import java.util.logging.Level;
|
|
|
|
public final class Main extends JavaPlugin {
|
|
|
|
public static ArrayList<String> proxyJoinPlayers = new ArrayList<>();
|
|
|
|
public static File getPath() {
|
|
return plugin.getDataFolder();
|
|
}
|
|
|
|
private static Boolean enable = false;
|
|
public static Boolean legacy = false;
|
|
|
|
public static String version;
|
|
|
|
public static List<String> autor;
|
|
|
|
@Getter
|
|
private static Main plugin;
|
|
|
|
public static Boolean PaPi = false;
|
|
public static Boolean PlotSquaredGUI = false;
|
|
public static Boolean LuckyBox = false;
|
|
public static Boolean PlugManGUI = false;
|
|
|
|
public static HashMap<String, Gui> guiHashMap = new HashMap<>();
|
|
public static ArrayList<String> allAliases = new ArrayList<>();
|
|
|
|
public static HashMap<String, Function> functionHashMap = new HashMap<>();
|
|
|
|
@Override
|
|
public void onEnable() {
|
|
// Plugin startup logic
|
|
plugin = this;
|
|
autor = this.getDescription().getAuthors();
|
|
version = this.getDescription().getVersion();
|
|
if (pluginNotFound("T2CodeLib", 96388, Util.getRequiredT2CodeLibVersion())) return;
|
|
if (T2C_McVersion.isMc1_8() || T2C_McVersion.isMc1_9() || T2C_McVersion.isMc1_10() || T2C_McVersion.isMc1_11() || T2C_McVersion.isMc1_12() || T2C_McVersion.isMc1_13() ||
|
|
T2C_McVersion.isMc1_14() || T2C_McVersion.isMc1_15() || T2C_McVersion.isNms1_16_R1()) {
|
|
legacy = true;
|
|
}
|
|
|
|
if (T2C_PluginCheck.pluginCheck("CommandGUI")) {
|
|
T2C_Send.error( plugin, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
|
T2C_Send.error( plugin,"");
|
|
T2C_Send.error( plugin,"An older version of the plugin T2C-CommandGUI was found!");
|
|
T2C_Send.error( plugin,"This plugin is now called T2C-CommandGUI and no longer CommandGUI!");
|
|
T2C_Send.error( plugin,"Please remove the older version (CommandGUI)!");
|
|
T2C_Send.error( plugin,this.getName() + " version: " + this.getDescription().getVersion() + " could not be loaded!");
|
|
T2C_Send.error( plugin,"");
|
|
T2C_Send.error( plugin,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
|
Main.plugin.getPluginLoader().disablePlugin(Main.plugin);
|
|
return;
|
|
}
|
|
getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
|
if (T2C_PluginCheck.papi()) {
|
|
PaPi = true;
|
|
}
|
|
Load.onLoad(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getSpigotID(), Util.getDiscord(), Util.getBstatsID());
|
|
enable = true;
|
|
}
|
|
|
|
public static void addonLoad() {
|
|
if (T2C_PluginCheck.plotSquaredGUI()) {
|
|
PlotSquaredGUI = true;
|
|
addonEnable(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("PlotSquaredGUI")));
|
|
}
|
|
|
|
if (T2C_PluginCheck.luckyBox()) {
|
|
LuckyBox = true;
|
|
addonEnable(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("T2C-LuckyBox")));
|
|
}
|
|
|
|
if (T2C_PluginCheck.plugManGUI()) {
|
|
PlugManGUI = true;
|
|
addonEnable(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("PlugManGUI")));
|
|
}
|
|
}
|
|
|
|
public static void addonEnable(Plugin plugin) {
|
|
T2C_Send.console(Util.getPrefix() + " §aAddon for: §e" + plugin.getName() + "§7 - Version: " + plugin.getDescription().getVersion() + " §aloaded successfully!");
|
|
}
|
|
|
|
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 = Objects.requireNonNull(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 or contact us in Discord: §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 void sendTryCatch(Class c, StackTraceElement line) {
|
|
T2C_Send.error(plugin,c.getName() + " Line: " + line.getLineNumber());
|
|
}
|
|
|
|
@Override
|
|
public void onDisable() {
|
|
// Plugin shutdown logic
|
|
if (enable) T2C_Template.onDisable(Util.getPrefix(), plugin);
|
|
Plugman.unLoad();
|
|
MySQL.close();
|
|
}
|
|
|
|
}
|