add T2CplatformDetector

This commit is contained in:
JaTiTV 2024-06-17 23:53:01 +02:00
parent b8c65cb537
commit 2ac9c890f6
2 changed files with 51 additions and 0 deletions

View File

@ -21,6 +21,7 @@ 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.config.SelectLibConfig;
import net.t2code.t2codelib.SPIGOT.system.config.languages.LanguagesCreate; import net.t2code.t2codelib.SPIGOT.system.config.languages.LanguagesCreate;
import net.t2code.t2codelib.SPIGOT.system.config.languages.SelectLibMsg; import net.t2code.t2codelib.SPIGOT.system.config.languages.SelectLibMsg;
import net.t2code.t2codelib.T2CplatformDetector;
import net.t2code.t2codelib.Util; import net.t2code.t2codelib.Util;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@ -41,6 +42,7 @@ public final class T2CodeLibMain extends JavaPlugin {
@Getter @Getter
private static Boolean mmIsLoad = true; private static Boolean mmIsLoad = true;
private static Boolean load = false; private static Boolean load = false;
private static T2CplatformDetector.PlatformType plattform;
@Override @Override
public void onEnable() { public void onEnable() {
@ -48,6 +50,7 @@ public final class T2CodeLibMain extends JavaPlugin {
plugin = this; plugin = this;
autor = plugin.getDescription().getAuthors(); autor = plugin.getDescription().getAuthors();
version = plugin.getDescription().getVersion(); version = plugin.getDescription().getVersion();
plattform = T2CplatformDetector.detectPlatform();
try { try {
adventure = BukkitAudiences.create(this); adventure = BukkitAudiences.create(this);
} catch (Exception e) { } catch (Exception e) {
@ -95,6 +98,7 @@ public final class T2CodeLibMain extends JavaPlugin {
} }
T2Ctemplate.onLoadSeparateStroke(prefix); T2Ctemplate.onLoadSeparateStroke(prefix);
T2Csend.console(prefix + " §2Server run on:"); T2Csend.console(prefix + " §2Server run on:");
T2Csend.console(prefix + " §3Platform: §6" + plattform.name());
T2Csend.console(prefix + " §3mcVersion: §6" + T2CmcVersion.getMcVersion()); T2Csend.console(prefix + " §3mcVersion: §6" + T2CmcVersion.getMcVersion());
T2Csend.console(prefix + " §3bukkitVersion: §6" + T2CmcVersion.getBukkitVersion()); T2Csend.console(prefix + " §3bukkitVersion: §6" + T2CmcVersion.getBukkitVersion());
T2Csend.console(prefix + " §3nms: §6" + T2CmcVersion.getNms()); T2Csend.console(prefix + " §3nms: §6" + T2CmcVersion.getNms());

View File

@ -0,0 +1,47 @@
package net.t2code.t2codelib;// This class was created by JaTiTV.
public class T2CplatformDetector {
public static PlatformType detectPlatform;
public enum PlatformType {
SPIGOT,
PAPER,
BUNGEECORD,
UNKNOWN
}
public static PlatformType detectPlatform() {
// Check for Bukkit/Spigot/Paper
try {
Class.forName("org.bukkit.Bukkit");
if (isPaper()) {
return PlatformType.PAPER;
} else {
return PlatformType.SPIGOT;
}
} catch (ClassNotFoundException e) {
// Not a Bukkit/Spigot/Paper server
}
// Check for BungeeCord
try {
Class.forName("net.md_5.bungee.api.ProxyServer");
return PlatformType.BUNGEECORD;
} catch (ClassNotFoundException e) {
// Not a BungeeCord server
}
return PlatformType.UNKNOWN;
}
private static boolean isPaper() {
// Paper has the PaperConfig class, which Spigot and Bukkit do not have
try {
Class.forName("com.destroystokyo.paper.PaperConfig");
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
}