diff --git a/src/main/java/io/github/simplexdev/simplexcore/SimplexCorePlugin.java b/src/main/java/io/github/simplexdev/simplexcore/SimplexCorePlugin.java index a97d698..5902940 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/SimplexCorePlugin.java +++ b/src/main/java/io/github/simplexdev/simplexcore/SimplexCorePlugin.java @@ -30,6 +30,7 @@ public final class SimplexCorePlugin extends SimplexAddon { instances.getRegistry().register(this); instances.getCommandLoader().classpath(Command_info.class).load(); instances.getConfig().reload(); + instances.getInternals().reload(); // SimplexListener.register(new DependencyListener(), this); new Announcer(); diff --git a/src/main/java/io/github/simplexdev/simplexcore/utils/Constants.java b/src/main/java/io/github/simplexdev/simplexcore/utils/Constants.java index 73e7127..d168297 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/utils/Constants.java +++ b/src/main/java/io/github/simplexdev/simplexcore/utils/Constants.java @@ -11,33 +11,34 @@ import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitScheduler; +import java.io.File; import java.util.logging.Logger; public final class Constants { private static final SimplexCorePlugin plugin = JavaPlugin.getPlugin(SimplexCorePlugin.class); - private static final Server server = plugin.getServer(); - private static final Logger logger = plugin.getLogger(); - private static final PluginManager manager = server.getPluginManager(); - private static final BukkitScheduler scheduler = server.getScheduler(); public static SimplexCorePlugin getPlugin() { return plugin; } public static Server getServer() { - return server; + return plugin.getServer(); } public static Logger getLogger() { - return logger; + return plugin.getServer().getLogger(); } public static PluginManager getManager() { - return manager; + return plugin.getServer().getPluginManager(); } public static BukkitScheduler getScheduler() { - return scheduler; + return plugin.getServer().getScheduler(); + } + + public static File getDataFolder() { + return plugin.getDataFolder(); } } diff --git a/src/main/java/io/github/simplexdev/simplexcore/utils/Instances.java b/src/main/java/io/github/simplexdev/simplexcore/utils/Instances.java index cd83b86..063246b 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/utils/Instances.java +++ b/src/main/java/io/github/simplexdev/simplexcore/utils/Instances.java @@ -10,6 +10,7 @@ public final class Instances { private final DependencyManagement dpm = new DependencyManagement(); private final Yaml config = new YamlFactory(Constants.getPlugin()).setDefaultPathways(); private final TimeValues time = new TimeValues(); + private final Yaml internals = new YamlFactory(Constants.getPlugin()).from("internals.yml", Constants.getDataFolder(), "internals.yml"); public synchronized AddonRegistry getRegistry() { return AddonRegistry.getInstance(); @@ -30,4 +31,6 @@ public final class Instances { public Yaml getConfig() { return config; } + + public Yaml getInternals() { return internals; } } diff --git a/src/main/java/io/github/simplexdev/simplexcore/utils/Utilities.java b/src/main/java/io/github/simplexdev/simplexcore/utils/Utilities.java index 824dbd5..cbb659a 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/utils/Utilities.java +++ b/src/main/java/io/github/simplexdev/simplexcore/utils/Utilities.java @@ -2,17 +2,21 @@ package io.github.simplexdev.simplexcore.utils; import io.github.simplexdev.api.func.Path; import io.github.simplexdev.simplexcore.ban.BanType; +import org.bukkit.Bukkit; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.SplittableRandom; import java.util.function.Consumer; +import java.util.regex.Pattern; import java.util.stream.Stream; public final class Utilities { private static final SplittableRandom random = new SplittableRandom(); private static final SplittableRandom numbers = new SplittableRandom(); + private static final List versions = Constants.getPlugin().getInstances().getInternals().getStringList(pathway("supported_versions")); + private static final List list = new ArrayList<>() {{ add('0'); add('1'); @@ -73,4 +77,31 @@ public final class Utilities { public static Path pathway(String pathway) { return () -> pathway; } + + public static String getNMSVersion() { + return Bukkit.getServer().getClass().getPackage().getName().substring(23).replaceFirst("v", ""); + } + + public static String[] formatVersion(String version) { + return (version).split(":"); + } + + public static boolean matchVersions() { + return versions.contains(getNMSVersion()); + } + + public static String getSpigotVersion() { + if (!matchVersions()) return "UNKNOWN"; + + for (String version : versions) { + String nms = formatVersion(version)[0]; + String spigot = formatVersion(version)[1]; + if (nms.equalsIgnoreCase(getNMSVersion())) { + return spigot; + } + } + + throw new RuntimeException("Unable to determine the Spigot version: NMS v" + + getNMSVersion() + " is not supported!"); + } } \ No newline at end of file diff --git a/src/main/resources/internals.yml b/src/main/resources/internals.yml new file mode 100644 index 0000000..ea2c796 --- /dev/null +++ b/src/main/resources/internals.yml @@ -0,0 +1,11 @@ +supported_versions: + - 1_10_R1:1.10.2 + - 1_11_R1:1.11 + - 1_12_R1:1.12 + - 1_13_R1:1.13 + - 1_13_R2:1.13.1 + - 1_14_R1:1.14 + - 1_15_R1:1.15 + - 1_16_R1:1.16.1 + - 1_16_R2:1.16.3 + - 1_16_R3:1.16.4 \ No newline at end of file