mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-11-26 20:16:18 +01:00
Refactor Nms class to be more readable and make it final
This commit is contained in:
parent
1e0de3d844
commit
f66964b2ee
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user