From f66964b2eeb01f5d9b8250a8adc480472f81d94b Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Sat, 10 Jun 2023 22:14:45 +0200 Subject: [PATCH] Refactor Nms class to be more readable and make it final --- Core/src/main/java/com/songoda/core/nms/Nms.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Core/src/main/java/com/songoda/core/nms/Nms.java b/Core/src/main/java/com/songoda/core/nms/Nms.java index 7b01821e..a0d0bfbb 100644 --- a/Core/src/main/java/com/songoda/core/nms/Nms.java +++ b/Core/src/main/java/com/songoda/core/nms/Nms.java @@ -2,21 +2,26 @@ package com.songoda.core.nms; import com.songoda.core.compatibility.ServerVersion; -public class Nms { - protected static NmsImplementations impl; +public final class Nms { + private static NmsImplementations cachedImplementation; /** * @return The implementations for the current server version */ public static NmsImplementations getImplementations() throws UnsupportedServerVersionException { - if (impl == null) { + if (cachedImplementation == null) { try { - impl = (NmsImplementations) Class.forName("com.songoda.core.nms." + ServerVersion.getServerVersionString() + ".NmsImplementationsImpl").getConstructors()[0].newInstance(); + Class implementationClazz = Class.forName(getImplementationClassName()); + cachedImplementation = (NmsImplementations) implementationClazz.getConstructors()[0].newInstance(); } catch (ReflectiveOperationException ex) { throw new UnsupportedServerVersionException(ex); } } - return impl; + return cachedImplementation; + } + + private static String getImplementationClassName() { + return String.format("com.songoda.core.nms.%s.NmsImplementationsImpl", ServerVersion.getServerVersionString()); } }