246 lines
11 KiB
Java
246 lines
11 KiB
Java
package net.t2code.t2codelib.SPIGOT.system;
|
|
|
|
import lombok.Getter;
|
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
|
import net.milkbowl.vault.economy.Economy;
|
|
import net.milkbowl.vault.permission.Permission;
|
|
import net.t2code.t2codelib.SPIGOT.api.bungeePlayers.T2C_BungeePlayers;
|
|
import net.t2code.t2codelib.SPIGOT.api.debug.T2C_Debug;
|
|
import net.t2code.t2codelib.SPIGOT.api.items.T2C_ItemVersion;
|
|
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.minecraftVersion.T2C_NmsEnum;
|
|
import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2C_NmsVersions;
|
|
import net.t2code.t2codelib.SPIGOT.api.plugins.T2C_PluginCheck;
|
|
import net.t2code.t2codelib.SPIGOT.api.update.T2C_UpdateAPI;
|
|
import net.t2code.t2codelib.SPIGOT.system.bstats.Metrics;
|
|
import net.t2code.t2codelib.SPIGOT.system.cmd.CmdExecuter;
|
|
import net.t2code.t2codelib.SPIGOT.system.cmd.Development;
|
|
import net.t2code.t2codelib.SPIGOT.system.cmd.ReportLogStorage;
|
|
import net.t2code.t2codelib.SPIGOT.system.config.config.T2C_LibConfig;
|
|
import net.t2code.t2codelib.SPIGOT.system.config.languages.T2CLibLanguages;
|
|
import net.t2code.t2codelib.T2CplatformDetector;
|
|
import net.t2code.t2codelib.Util;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import java.io.File;
|
|
import java.util.List;
|
|
import java.util.logging.Logger;
|
|
|
|
public final class T2CodeLibMain extends JavaPlugin {
|
|
@Getter
|
|
private static T2CodeLibMain plugin;
|
|
@Getter
|
|
private static Economy eco = null;
|
|
@Getter
|
|
private static Permission perm = null;
|
|
|
|
@Getter
|
|
private static List<String> autor;
|
|
@Getter
|
|
private static String version;
|
|
|
|
@Getter
|
|
private static Boolean mmIsLoad = true;
|
|
@Getter
|
|
private static Boolean load = false;
|
|
@Getter
|
|
private static T2CplatformDetector.PlatformType plattform;
|
|
|
|
|
|
@Override
|
|
public void onEnable() {
|
|
// Plugin startup logic
|
|
plugin = this;
|
|
autor = plugin.getDescription().getAuthors();
|
|
// logger = getLogger();
|
|
version = plugin.getDescription().getVersion();
|
|
|
|
try {
|
|
adventure = BukkitAudiences.create(this);
|
|
} catch (Exception e) {
|
|
mmIsLoad = false;
|
|
}
|
|
plattform = T2CplatformDetector.detectPlatform();
|
|
load();
|
|
}
|
|
|
|
private void load() {
|
|
long long_ = T2C_Template.onLoadHeader(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord());
|
|
|
|
checkIsBungee();
|
|
String prefix = Util.getPrefix();
|
|
|
|
try {
|
|
Vault.loadVault();
|
|
} catch (InterruptedException e) {
|
|
T2C_Send.sendException(e, getLogger());
|
|
}
|
|
T2C_McVersion.onCheck();
|
|
|
|
if (T2C_NmsVersions.getT2CnmsEnum() == T2C_NmsEnum.not_support) {
|
|
T2C_Send.sendStartTextCenter(prefix, "", true);
|
|
T2C_Send.sendStartTextCenter(prefix, "", true);
|
|
T2C_Send.sendStartTextCenter(prefix, "§4!!!!!!!!!!!!!!!!!!!!", true);
|
|
T2C_Send.sendStartTextCenter(prefix, "", true);
|
|
T2C_Send.sendStartTextCenter(prefix, "The " + T2C_McVersion.getMcVersion() + " is a very fresh / new version.", true);
|
|
T2C_Send.sendStartTextCenter(prefix, "The plugin may not yet be supported on this server!", true);
|
|
T2C_Send.sendStartTextCenter(prefix, "If there are any bugs in our plugins,", true);
|
|
T2C_Send.sendStartTextCenter(prefix, "please report them to us via our Discord: http://dc.t2code.net", true);
|
|
T2C_Send.sendStartTextCenter(prefix, "", true);
|
|
T2C_Send.sendStartTextCenter(prefix, "§4!!!!!!!!!!!!!!!!!!!!", true);
|
|
T2C_Send.sendStartTextCenter(prefix, "", true);
|
|
T2C_Send.sendStartTextCenter(prefix, "", true);
|
|
try {
|
|
Thread.sleep(5000);
|
|
} catch (InterruptedException ignored) {
|
|
}
|
|
}
|
|
if (T2C_McVersion.isMc1_22()) {
|
|
T2C_Send.sendStartTextCenter(prefix, "", true);
|
|
T2C_Send.sendStartTextCenter(prefix, "", true);
|
|
T2C_Send.sendStartTextCenter(prefix, "§4!!!!!!!!!!!!!!!!!!!!", true);
|
|
T2C_Send.sendStartTextCenter(prefix, "", true);
|
|
T2C_Send.sendStartTextCenter(prefix, "The 1.22 is a very fresh / new version.", true);
|
|
T2C_Send.sendStartTextCenter(prefix, "If there are any bugs in our plugins,", true);
|
|
T2C_Send.sendStartTextCenter(prefix, "please report them to us via our Discord: http://dc.t2code.net", true);
|
|
T2C_Send.sendStartTextCenter(prefix, "", true);
|
|
T2C_Send.sendStartTextCenter(prefix, "§4!!!!!!!!!!!!!!!!!!!!", true);
|
|
T2C_Send.sendStartTextCenter(prefix, "", true);
|
|
T2C_Send.sendStartTextCenter(prefix, "", true);
|
|
try {
|
|
Thread.sleep(2000);
|
|
} catch (InterruptedException ignored) {
|
|
|
|
}
|
|
}
|
|
T2C_Template.onLoadSeparateStroke(prefix);
|
|
T2C_Send.sendStartTextCenter(prefix, "§2Server run on:", true);
|
|
T2C_Send.sendStartTextCenter(prefix, "§3NMS: §6" + T2C_McVersion.getNms(), true);
|
|
T2C_Send.sendStartTextCenter(prefix, "§3Platform: §6" + plattform.name(), true);
|
|
T2C_Send.sendStartTextCenter(prefix, "§3Bukkit Version: §6" + T2C_McVersion.getBukkitVersion(), true);
|
|
T2C_Send.sendStartTextCenter(prefix, "§3Server Version: §6" + T2C_McVersion.getMcVersion(), true);
|
|
|
|
T2C_Template.onLoadSeparateStroke(prefix);
|
|
if (eco != null) {
|
|
String st = eco.getName();
|
|
if (eco.getName().equals("CMIEconomy")) st = "CMI";
|
|
if (Bukkit.getPluginManager().getPlugin(st) != null) {
|
|
T2C_Send.sendStartTextCenter(prefix, "§3Economy: §6" + eco.getName() + " - " + Bukkit.getPluginManager().getPlugin(st).getDescription().getVersion() + " §7- §e" +
|
|
(System.currentTimeMillis() - long_) + "ms", true);
|
|
} else
|
|
T2C_Send.sendStartTextCenter(prefix, "§3Economy: §6" + eco.getName() + " §7- §e" + (System.currentTimeMillis() - long_) + "ms", true);
|
|
} else
|
|
T2C_Send.sendStartTextCenter(prefix, "§3Economy: §4not connected via vault!" + " §7- §e" + (System.currentTimeMillis() - long_) + "ms", true);
|
|
|
|
if (perm != null) {
|
|
if (Bukkit.getPluginManager().getPlugin(perm.getName()) != null) {
|
|
T2C_Send.sendStartTextCenter(prefix, "§3Permission plugin: §6" + perm.getName() + " - " + Bukkit.getPluginManager().getPlugin(perm.getName()).getDescription().getVersion()
|
|
+ " §7- §e" + (System.currentTimeMillis() - long_) + "ms", true);
|
|
} else
|
|
T2C_Send.sendStartTextCenter(prefix, "§3Permission plugin: §6" + perm.getName() + " - §7- §e" + (System.currentTimeMillis() - long_) + "ms", true);
|
|
} else
|
|
T2C_Send.sendStartTextCenter(prefix, "§3Permission plugin: §4not connected via vault!" + " §7- §e" + (System.currentTimeMillis() - long_) + "ms", true);
|
|
|
|
if (T2C_PluginCheck.papi()) {
|
|
T2C_Send.sendStartTextCenter(prefix, "§3PlaceholderAPI: §6connected" + " §7- §e" + (System.currentTimeMillis() - long_) + "ms", true);
|
|
}
|
|
|
|
T2C_Send.sendStartTextCenter(prefix, "§3Kyori MiniMessage Support: " + (getMmIsLoad() ? "§2load" : "§4not load") + " §7- §e" + (System.currentTimeMillis() - long_) + "ms", true);
|
|
|
|
|
|
plugin.getCommand("t2code").setExecutor(new CmdExecuter());
|
|
|
|
T2C_Template.onLoadSeparateStroke(prefix);
|
|
T2C_LibConfig.set(false);
|
|
|
|
T2C_ItemVersion.scan();
|
|
T2CLibLanguages.set(false);
|
|
|
|
T2C_Template.onLoadSeparateStroke(prefix);
|
|
T2C_Send.sendStartTextCenter(prefix, "§3Use Proxy: §6" + (boolean) T2C_LibConfig.VALUES.proxy.getValue(), true);
|
|
T2C_Send.sendStartTextCenter(prefix, "§3serverUUID: §6" + T2C_LibConfig.VALUES.serverUUID.getValue(), true);
|
|
|
|
T2C_UpdateAPI.onUpdateCheck(plugin, prefix, Util.getGit(), Util.getSpigotID(), Util.getDiscord(),
|
|
(boolean) T2C_LibConfig.VALUES.updateCheckOnJoin.getValue(),
|
|
(boolean) T2C_LibConfig.VALUES.seePreReleaseUpdates.getValue(),
|
|
(int) T2C_LibConfig.VALUES.updateCheckTimeInterval.getValue());
|
|
Metrics.Bstats(plugin, Util.getBstatsID());
|
|
if ((boolean) T2C_LibConfig.VALUES.proxy.getValue()) {
|
|
Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, Util.getPluginChannel_ProxyCommand());
|
|
T2C_Debug.debug(plugin, "registerIncomingPluginChannel §e" + Util.getPluginChannel_ProxyCommand());
|
|
|
|
Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, Util.getPluginChannel_ProxyOnlinePlayers());
|
|
if (!Bukkit.getMessenger().isIncomingChannelRegistered(plugin, Util.getPluginChannel_ProxyOnlinePlayers())) {
|
|
T2C_Debug.debug(plugin, "registerIncomingPluginChannel §e" + Util.getPluginChannel_ProxyOnlinePlayers());
|
|
Bukkit.getMessenger().registerIncomingPluginChannel(plugin, Util.getPluginChannel_ProxyOnlinePlayers(), new T2C_BungeePlayers());
|
|
T2C_BungeePlayers.callAllBungeePlayers();
|
|
}
|
|
}
|
|
|
|
ReportLogStorage.load();
|
|
Bukkit.getServer().getPluginManager().registerEvents(new JoinEvent(), plugin);
|
|
Bukkit.getServer().getPluginManager().registerEvents(new Development(), plugin);
|
|
T2C_Template.onLoadFooter(prefix, long_);
|
|
load = true;
|
|
}
|
|
|
|
@Override
|
|
public void onDisable() {
|
|
// Plugin shutdown logic
|
|
if (!load) return;
|
|
ReportLogStorage.save();
|
|
if ((boolean) T2C_LibConfig.VALUES.inventoriesCloseByServerStop.getValue()) {
|
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
|
player.closeInventory();
|
|
}
|
|
}
|
|
|
|
Vault.vaultDisable();
|
|
T2C_Template.onDisable(Util.getPrefix(), this);
|
|
if (mmIsLoad) {
|
|
if (this.adventure != null) {
|
|
this.adventure.close();
|
|
this.adventure = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static File getPath() {
|
|
return plugin.getDataFolder();
|
|
}
|
|
|
|
static void setEco(Economy eco) {
|
|
T2CodeLibMain.eco = eco;
|
|
}
|
|
|
|
static void setPerm(Permission perm) {
|
|
T2CodeLibMain.perm = perm;
|
|
}
|
|
|
|
private static BukkitAudiences adventure;
|
|
|
|
public BukkitAudiences getAdventure() {
|
|
if (adventure == null) {
|
|
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
|
|
}
|
|
return adventure;
|
|
}
|
|
|
|
private static void checkIsBungee() {
|
|
File config = new File("spigot.yml");
|
|
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
|
|
|
|
isBungee = yamlConfiguration.getBoolean("settings.bungeecord");
|
|
}
|
|
|
|
@Getter
|
|
private static Boolean isBungee;
|
|
|
|
}
|