diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/HolographicDisplays.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/HolographicDisplays.java index 37e67724..c6747e0b 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/HolographicDisplays.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/HolographicDisplays.java @@ -36,6 +36,7 @@ import me.filoghost.holographicdisplays.plugin.placeholder.internal.DefaultPlace import me.filoghost.holographicdisplays.plugin.placeholder.registry.PlaceholderRegistry; import me.filoghost.holographicdisplays.plugin.placeholder.tracking.PlaceholderTracker; import me.filoghost.holographicdisplays.plugin.util.NMSVersion; +import me.filoghost.holographicdisplays.plugin.util.NMSVersion.UnknownVersionException; import org.bstats.bukkit.MetricsLite; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -76,12 +77,6 @@ public class HolographicDisplays extends FCommonsPlugin { "You are probably running CraftBukkit instead of Spigot."); } - if (!NMSVersion.isValid()) { - throw new PluginEnableException( - "Holographic Displays does not support this server version.", - "Supported Spigot versions: from 1.8.3 to 1.17."); - } - if (getCommand("holograms") == null) { throw new PluginEnableException( "Holographic Displays was unable to register the command \"holograms\".", @@ -92,6 +87,10 @@ public class HolographicDisplays extends FCommonsPlugin { try { nmsManager = NMSVersion.getCurrent().createNMSManager(errorCollector); + } catch (UnknownVersionException e) { + throw new PluginEnableException( + "Holographic Displays does not support this server version.", + "Supported Spigot versions: from 1.8.3 to 1.17."); } catch (Throwable t) { throw new PluginEnableException(t, "Couldn't initialize the NMS manager."); } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/util/NMSVersion.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/util/NMSVersion.java index b3f341b2..27d4c5f2 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/util/NMSVersion.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/util/NMSVersion.java @@ -5,7 +5,6 @@ */ package me.filoghost.holographicdisplays.plugin.util; -import me.filoghost.fcommons.Preconditions; import me.filoghost.fcommons.logging.ErrorCollector; import me.filoghost.holographicdisplays.common.nms.NMSManager; import org.bukkit.Bukkit; @@ -48,15 +47,13 @@ public enum NMSVersion { return nmsManagerFactory.create(errorCollector); } - public static NMSVersion getCurrent() { - Preconditions.checkState(isValid(), "Current version is not valid"); + public static NMSVersion getCurrent() throws UnknownVersionException { + if (CURRENT_VERSION == null) { + throw new UnknownVersionException(); + } return CURRENT_VERSION; } - public static boolean isValid() { - return CURRENT_VERSION != null; - } - private static NMSVersion extractCurrentVersion() { Matcher matcher = Pattern.compile("v\\d+_\\d+_R\\d+").matcher(Bukkit.getServer().getClass().getPackage().getName()); if (!matcher.find()) { @@ -78,4 +75,6 @@ public enum NMSVersion { } + public static class UnknownVersionException extends Exception {} + }