|
| 1 | +package com.dfsek.terra.bukkit; |
| 2 | + |
| 3 | +import org.slf4j.Logger; |
| 4 | +import org.slf4j.LoggerFactory; |
| 5 | + |
| 6 | +import com.dfsek.terra.bukkit.util.VersionUtil; |
| 7 | + |
| 8 | +import java.util.List; |
| 9 | + |
| 10 | + |
| 11 | +public interface NMSInitializer { |
| 12 | + List<String> SUPPORTED_VERSIONS = List.of("v1.21.9", "v1.21.10"); |
| 13 | + String MINECRAFT_VERSION = VersionUtil.getMinecraftVersionInfo().toString(); |
| 14 | + String TERRA_PACKAGE = NMSInitializer.class.getPackageName(); |
| 15 | + |
| 16 | + static PlatformImpl init(TerraBukkitPlugin plugin) { |
| 17 | + Logger logger = LoggerFactory.getLogger(NMSInitializer.class); |
| 18 | + |
| 19 | + if (!SUPPORTED_VERSIONS.contains(MINECRAFT_VERSION)) { |
| 20 | + logger.error("You are running your server on Minecraft version {} which is not supported by this version of Terra.", MINECRAFT_VERSION); |
| 21 | + |
| 22 | + String bypassKey = "IKnowThereAreNoNMSBindingsFor" + MINECRAFT_VERSION.replace(".", "_") + "ButIWillProceedAnyway"; |
| 23 | + if(System.getProperty(bypassKey) == null) { |
| 24 | + logger.error("Because of this **TERRA HAS BEEN DISABLED**."); |
| 25 | + logger.error("Do not come ask us why it is not working."); |
| 26 | + logger.error("If you wish to proceed anyways, you can add the JVM System Property \"{}\" to enable the plugin.", bypassKey); |
| 27 | + return null; |
| 28 | + } else { |
| 29 | + logger.error(""); |
| 30 | + logger.error(""); |
| 31 | + for(int i = 0; i < 20; i++) { |
| 32 | + logger.error("PROCEEDING WITH AN EXISTING TERRA WORLD WILL RESULT IN CORRUPTION!!!"); |
| 33 | + } |
| 34 | + logger.error(""); |
| 35 | + logger.error(""); |
| 36 | + logger.error("We will not give you any support for issues that may arise."); |
| 37 | + logger.error("Since you enabled the \"{}\" flag, we won't disable Terra. But be warned.", bypassKey); |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + return constructPlatform(plugin); |
| 42 | + } |
| 43 | + |
| 44 | + private static PlatformImpl constructPlatform(TerraBukkitPlugin plugin) { |
| 45 | + try { |
| 46 | + Class<?> platformClass = Class.forName(TERRA_PACKAGE + ".nms.NMSPlatform"); |
| 47 | + return (PlatformImpl) platformClass |
| 48 | + .getConstructor(TerraBukkitPlugin.class) |
| 49 | + .newInstance(plugin); |
| 50 | + } catch(ReflectiveOperationException e) { |
| 51 | + throw new RuntimeException("Error initializing NMS bindings. Report this to Terra.", e); |
| 52 | + } |
| 53 | + } |
| 54 | +} |
0 commit comments