Improve readability

This commit is contained in:
filoghost 2021-07-29 19:33:02 +02:00
parent 825b0f2b2e
commit ca50d9247d
2 changed files with 11 additions and 13 deletions

View File

@ -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.");
}

View File

@ -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 {}
}