2022-10-25 13:03:07 +00:00
package net.t2code.t2codelib.SPIGOT.system ;
2022-12-22 00:43:40 +00:00
import lombok.Getter ;
2022-10-25 13:03:07 +00:00
import net.kyori.adventure.platform.bukkit.BukkitAudiences ;
import net.milkbowl.vault.economy.Economy ;
import net.milkbowl.vault.permission.Permission ;
2022-12-24 18:05:18 +00:00
import net.t2code.t2codelib.SPIGOT.api.bungeePlayers.T2CbungeePlayers ;
2022-11-03 06:57:53 +00:00
import net.t2code.t2codelib.SPIGOT.api.items.T2CitemVersion ;
2022-10-25 13:03:07 +00:00
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend ;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate ;
import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion ;
import net.t2code.t2codelib.SPIGOT.api.plugins.T2CpluginCheck ;
import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI ;
import net.t2code.t2codelib.SPIGOT.system.bstats.Metrics ;
2022-11-14 00:06:44 +00:00
import net.t2code.t2codelib.SPIGOT.system.cmd.CmdExecuter ;
2023-06-30 15:57:59 +00:00
import net.t2code.t2codelib.SPIGOT.system.cmd.Development ;
2022-11-14 00:06:44 +00:00
import net.t2code.t2codelib.SPIGOT.system.cmd.ReportLogStorage ;
2022-10-25 13:03:07 +00:00
import net.t2code.t2codelib.SPIGOT.system.config.config.ConfigCreate ;
import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig ;
import net.t2code.t2codelib.SPIGOT.system.config.languages.LanguagesCreate ;
import net.t2code.t2codelib.SPIGOT.system.config.languages.SelectLibMsg ;
import net.t2code.t2codelib.Util ;
import org.bukkit.Bukkit ;
2022-11-14 17:45:54 +00:00
import org.bukkit.configuration.file.YamlConfiguration ;
2022-10-25 13:03:07 +00:00
import org.bukkit.entity.Player ;
import org.bukkit.plugin.java.JavaPlugin ;
import java.io.File ;
import java.util.List ;
public final class T2CodeLibMain extends JavaPlugin {
private static T2CodeLibMain plugin ;
private static Economy eco = null ;
private static Permission perm = null ;
private static List < String > autor ;
private static String version ;
2022-12-22 00:43:40 +00:00
@Getter
2022-11-14 17:45:54 +00:00
private static Boolean mmIsLoad = true ;
2022-10-25 13:03:07 +00:00
private static Boolean load = false ;
@Override
public void onEnable ( ) {
// Plugin startup logic
plugin = this ;
autor = plugin . getDescription ( ) . getAuthors ( ) ;
version = plugin . getDescription ( ) . getVersion ( ) ;
2022-11-14 17:45:54 +00:00
try {
adventure = BukkitAudiences . create ( this ) ;
} catch ( Exception e ) {
mmIsLoad = false ;
}
2022-10-25 13:03:07 +00:00
long long_ = T2Ctemplate . onLoadHeader ( Util . getPrefix ( ) , autor , version , Util . getSpigot ( ) , Util . getDiscord ( ) ) ;
2022-12-24 18:05:18 +00:00
checkIsBungee ( ) ;
2022-10-25 13:03:07 +00:00
String prefix = Util . getPrefix ( ) ;
try {
Vault . loadVault ( ) ;
} catch ( InterruptedException e ) {
e . printStackTrace ( ) ;
}
T2CmcVersion . onCheck ( ) ;
2024-03-30 18:41:31 +00:00
if ( T2CmcVersion . isNms1_20_R4 ( ) ) {
2022-10-25 13:03:07 +00:00
T2Csend . console ( prefix + " §4!!!!!!!!!!!!!!!!!!!! " ) ;
T2Csend . console ( prefix ) ;
2024-03-30 18:41:31 +00:00
T2Csend . warning ( plugin , " The 1.20.* (NMS R4) is a very fresh / new version. If there are any bugs in our plugins, please report them to us via our Discord: http://dc.t2code.net " ) ;
2023-07-16 06:22:30 +00:00
T2Csend . console ( prefix ) ;
T2Csend . console ( prefix + " §4!!!!!!!!!!!!!!!!!!!! " ) ;
if ( ! SelectLibConfig . getT2cTestDevelopment ( ) ) {
try {
Thread . sleep ( 5000 ) ;
} catch ( InterruptedException e ) {
e . printStackTrace ( ) ;
}
}
} if ( T2CmcVersion . isMc1_21 ( ) ) {
T2Csend . console ( prefix + " §4!!!!!!!!!!!!!!!!!!!! " ) ;
T2Csend . console ( prefix ) ;
T2Csend . warning ( plugin , " The 1.21 is a very fresh / new version. If there are any bugs in our plugins, please report them to us via our Discord: http://dc.t2code.net " ) ;
2022-10-25 13:03:07 +00:00
T2Csend . console ( prefix ) ;
T2Csend . console ( prefix + " §4!!!!!!!!!!!!!!!!!!!! " ) ;
2022-11-14 17:45:54 +00:00
if ( ! SelectLibConfig . getT2cTestDevelopment ( ) ) {
try {
Thread . sleep ( 5000 ) ;
} catch ( InterruptedException e ) {
e . printStackTrace ( ) ;
}
2022-10-25 13:03:07 +00:00
}
}
T2Csend . console ( prefix + " §3Server run on: §6 " + T2CmcVersion . getMcVersion ( ) + " / " + T2CmcVersion . getNms ( ) ) ;
if ( eco ! = null ) {
String st = eco . getName ( ) ;
if ( eco . getName ( ) . equals ( " CMIEconomy " ) ) st = " CMI " ;
if ( Bukkit . getPluginManager ( ) . getPlugin ( st ) ! = null ) {
T2Csend . console ( prefix + " §3Economy: §6 " + eco . getName ( ) + " - " + Bukkit . getPluginManager ( ) . getPlugin ( st ) . getDescription ( ) . getVersion ( ) + " §7- §e " +
( System . currentTimeMillis ( ) - long_ ) + " ms " ) ;
} else T2Csend . console ( prefix + " §3Economy: §6 " + eco . getName ( ) + " §7- §e " + ( System . currentTimeMillis ( ) - long_ ) + " ms " ) ;
} else T2Csend . console ( prefix + " §3Economy: §4not connected via vault! " + " §7- §e " + ( System . currentTimeMillis ( ) - long_ ) + " ms " ) ;
if ( perm ! = null ) {
if ( Bukkit . getPluginManager ( ) . getPlugin ( perm . getName ( ) ) ! = null ) {
T2Csend . console ( prefix + " §3Permission plugin: §6 " + perm . getName ( ) + " - " + Bukkit . getPluginManager ( ) . getPlugin ( perm . getName ( ) ) . getDescription ( ) . getVersion ( )
+ " §7- §e " + ( System . currentTimeMillis ( ) - long_ ) + " ms " ) ;
} else T2Csend . console ( prefix + " §3Permission plugin: §6 " + perm . getName ( ) + " - §7- §e " + ( System . currentTimeMillis ( ) - long_ ) + " ms " ) ;
} else T2Csend . console ( prefix + " §3Permission plugin: §4not connected via vault! " + " §7- §e " + ( System . currentTimeMillis ( ) - long_ ) + " ms " ) ;
if ( T2CpluginCheck . papi ( ) ) {
T2Csend . console ( prefix + " §3PlaceholderAPI: §6connected " + " §7- §e " + ( System . currentTimeMillis ( ) - long_ ) + " ms " ) ;
}
2023-06-30 15:57:59 +00:00
T2Csend . console ( prefix + " §3Kyori MiniMessage Support: " + ( getMmIsLoad ( ) ? " §2load " : " §4not load " ) + " §7- §e " + ( System . currentTimeMillis ( ) - long_ ) + " ms " ) ;
2023-06-08 04:55:44 +00:00
2022-10-25 13:03:07 +00:00
plugin . getCommand ( " t2code " ) . setExecutor ( new CmdExecuter ( ) ) ;
ConfigCreate . configCreate ( ) ;
2022-11-03 06:57:53 +00:00
T2CitemVersion . scan ( ) ;
2022-10-25 13:03:07 +00:00
LanguagesCreate . langCreate ( ) ;
SelectLibConfig . onSelect ( ) ;
SelectLibMsg . onSelect ( ) ;
2022-11-14 23:36:25 +00:00
T2CupdateAPI . onUpdateCheck ( plugin , prefix , Util . getGit ( ) , Util . getSpigotID ( ) , Util . getDiscord ( ) , SelectLibConfig . getUpdateCheckOnJoin ( ) , SelectLibConfig . getSeePreReleaseUpdates ( ) ,
SelectLibConfig . getUpdateCheckTimeInterval ( ) ) ;
2022-10-25 13:03:07 +00:00
Metrics . Bstats ( plugin , Util . getBstatsID ( ) ) ;
2022-11-10 13:00:59 +00:00
if ( SelectLibConfig . getBungee ( ) ) {
2022-11-03 06:57:53 +00:00
Bukkit . getMessenger ( ) . registerOutgoingPluginChannel ( plugin , " t2c:bcmd " ) ;
2023-06-19 19:17:49 +00:00
T2Csend . debug ( plugin , " registerIncomingPluginChannel §et2c:bcmd " ) ;
2022-12-29 21:02:05 +00:00
2022-12-24 18:05:18 +00:00
Bukkit . getMessenger ( ) . registerOutgoingPluginChannel ( plugin , " t2c:bonlp " ) ;
if ( ! Bukkit . getMessenger ( ) . isIncomingChannelRegistered ( plugin , " t2c:bonlp " ) ) {
T2Csend . debug ( plugin , " registerIncomingPluginChannel §et2c:bonlp " ) ;
Bukkit . getMessenger ( ) . registerIncomingPluginChannel ( plugin , " t2c:bonlp " , new T2CbungeePlayers ( ) ) ;
T2CbungeePlayers . callAllBungeePlayers ( ) ;
}
2022-11-03 06:57:53 +00:00
}
2022-10-25 13:03:07 +00:00
2022-11-14 00:06:44 +00:00
ReportLogStorage . load ( ) ;
2022-10-25 13:03:07 +00:00
Bukkit . getServer ( ) . getPluginManager ( ) . registerEvents ( new JoinEvent ( ) , plugin ) ;
2023-06-30 15:57:59 +00:00
Bukkit . getServer ( ) . getPluginManager ( ) . registerEvents ( new Development ( ) , plugin ) ;
2022-10-25 13:03:07 +00:00
T2Ctemplate . onLoadFooter ( prefix , long_ ) ;
load = true ;
}
@Override
public void onDisable ( ) {
// Plugin shutdown logic
if ( ! load ) return ;
2022-11-14 00:06:44 +00:00
ReportLogStorage . save ( ) ;
2022-10-25 13:03:07 +00:00
if ( SelectLibConfig . getInventoriesCloseByServerStop ( ) ) {
for ( Player player : Bukkit . getOnlinePlayers ( ) ) {
player . closeInventory ( ) ;
}
}
2022-11-03 06:57:53 +00:00
Vault . vaultDisable ( ) ;
2023-06-30 15:57:59 +00:00
T2Ctemplate . onDisable ( Util . getPrefix ( ) , this ) ;
2022-11-14 17:45:54 +00:00
if ( mmIsLoad ) {
2022-10-25 13:03:07 +00:00
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 ;
}
public static T2CodeLibMain getPlugin ( ) {
return plugin ;
}
public static Economy getEco ( ) {
return eco ;
}
public static Permission getPerm ( ) {
return perm ;
}
public static List < String > getAutor ( ) {
return autor ;
}
public static String getVersion ( ) {
return version ;
}
private static BukkitAudiences adventure ;
2022-11-10 13:00:59 +00:00
public BukkitAudiences getAdventure ( ) {
2022-10-25 13:03:07 +00:00
if ( adventure = = null ) {
throw new IllegalStateException ( " Tried to access Adventure when the plugin was disabled! " ) ;
}
return adventure ;
}
2022-11-14 17:45:54 +00:00
private static void checkIsBungee ( ) {
File config = new File ( " spigot.yml " ) ;
YamlConfiguration yamlConfiguration = YamlConfiguration . loadConfiguration ( config ) ;
isBungee = yamlConfiguration . getBoolean ( " settings.bungeecord " ) ;
}
private static Boolean isBungee ;
public static Boolean getIsBungee ( ) {
return isBungee ;
}
public static Boolean getMmIsLoad ( ) {
return mmIsLoad ;
2022-10-25 13:03:07 +00:00
}
}