diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 7c271c3f..e7ba2cb7 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -36,6 +36,7 @@ import ru.gravit.launchserver.socket.ServerSocketHandler; import ru.gravit.launchserver.auth.texture.RequestTextureProvider; import ru.gravit.launchserver.auth.texture.TextureProvider; +import ru.gravit.utils.UniversalJsonAdapter; import ru.gravit.utils.command.CommandHandler; import ru.gravit.utils.command.JLineCommandHandler; import ru.gravit.utils.command.StdCommandHandler; @@ -598,25 +599,25 @@ public LaunchServer(Path dir, boolean testEnv, String[] args) throws IOException public static void initGson() { if (Launcher.gson != null) return; Launcher.gsonBuilder = new GsonBuilder(); - Launcher.gsonBuilder.registerTypeAdapter(AuthProvider.class, new AuthProviderAdapter()); - Launcher.gsonBuilder.registerTypeAdapter(TextureProvider.class, new TextureProviderAdapter()); - Launcher.gsonBuilder.registerTypeAdapter(AuthHandler.class, new AuthHandlerAdapter()); - Launcher.gsonBuilder.registerTypeAdapter(PermissionsHandler.class, new PermissionsHandlerAdapter()); - Launcher.gsonBuilder.registerTypeAdapter(HWIDHandler.class, new HWIDHandlerAdapter()); - Launcher.gsonBuilder.registerTypeAdapter(Component.class, new ComponentAdapter()); - Launcher.gsonBuilder.registerTypeAdapter(ProtectHandler.class, new ProtectHandlerAdapter()); + Launcher.gsonBuilder.registerTypeAdapter(AuthProvider.class, new UniversalJsonAdapter<>(AuthProvider.providers)); + Launcher.gsonBuilder.registerTypeAdapter(TextureProvider.class, new UniversalJsonAdapter<>(TextureProvider.providers)); + Launcher.gsonBuilder.registerTypeAdapter(AuthHandler.class, new UniversalJsonAdapter<>(AuthHandler.providers)); + Launcher.gsonBuilder.registerTypeAdapter(PermissionsHandler.class, new UniversalJsonAdapter<>(PermissionsHandler.providers)); + Launcher.gsonBuilder.registerTypeAdapter(HWIDHandler.class, new UniversalJsonAdapter<>(HWIDHandler.providers)); + Launcher.gsonBuilder.registerTypeAdapter(Component.class, new UniversalJsonAdapter<>(Component.providers)); + Launcher.gsonBuilder.registerTypeAdapter(ProtectHandler.class, new UniversalJsonAdapter<>(ProtectHandler.providers)); Launcher.gson = Launcher.gsonBuilder.create(); //Human readable LaunchServer.gsonBuilder = new GsonBuilder(); LaunchServer.gsonBuilder.setPrettyPrinting(); - LaunchServer.gsonBuilder.registerTypeAdapter(AuthProvider.class, new AuthProviderAdapter()); - LaunchServer.gsonBuilder.registerTypeAdapter(TextureProvider.class, new TextureProviderAdapter()); - LaunchServer.gsonBuilder.registerTypeAdapter(AuthHandler.class, new AuthHandlerAdapter()); - LaunchServer.gsonBuilder.registerTypeAdapter(PermissionsHandler.class, new PermissionsHandlerAdapter()); - LaunchServer.gsonBuilder.registerTypeAdapter(HWIDHandler.class, new HWIDHandlerAdapter()); - LaunchServer.gsonBuilder.registerTypeAdapter(Component.class, new ComponentAdapter()); - LaunchServer.gsonBuilder.registerTypeAdapter(ProtectHandler.class, new ProtectHandlerAdapter()); + LaunchServer.gsonBuilder.registerTypeAdapter(AuthProvider.class, new UniversalJsonAdapter<>(AuthProvider.providers)); + LaunchServer.gsonBuilder.registerTypeAdapter(TextureProvider.class, new UniversalJsonAdapter<>(TextureProvider.providers)); + LaunchServer.gsonBuilder.registerTypeAdapter(AuthHandler.class, new UniversalJsonAdapter<>(AuthHandler.providers)); + LaunchServer.gsonBuilder.registerTypeAdapter(PermissionsHandler.class, new UniversalJsonAdapter<>(PermissionsHandler.providers)); + LaunchServer.gsonBuilder.registerTypeAdapter(HWIDHandler.class, new UniversalJsonAdapter<>(HWIDHandler.providers)); + LaunchServer.gsonBuilder.registerTypeAdapter(Component.class, new UniversalJsonAdapter<>(Component.providers)); + LaunchServer.gsonBuilder.registerTypeAdapter(ProtectHandler.class, new UniversalJsonAdapter<>(ProtectHandler.providers)); LaunchServer.gson = LaunchServer.gsonBuilder.create(); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java index 387b9a5f..6bac735e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java @@ -2,6 +2,7 @@ import ru.gravit.launchserver.auth.AuthException; import ru.gravit.launchserver.auth.provider.AuthProviderResult; +import ru.gravit.utils.ProviderMap; import ru.gravit.utils.helper.VerifyHelper; import java.io.IOException; @@ -11,7 +12,7 @@ import java.util.concurrent.ConcurrentHashMap; public abstract class AuthHandler implements AutoCloseable { - private static final Map> AUTH_HANDLERS = new ConcurrentHashMap<>(4); + public static ProviderMap providers = new ProviderMap<>(); private static boolean registredHandl = false; @@ -19,31 +20,13 @@ public static UUID authError(String message) throws AuthException { throw new AuthException(message); } - - public static void registerHandler(String name, Class adapter) { - VerifyHelper.verifyIDName(name); - VerifyHelper.putIfAbsent(AUTH_HANDLERS, name, Objects.requireNonNull(adapter, "adapter"), - String.format("Auth handler has been already registered: '%s'", name)); - } - - public static Class getHandlerClass(String name) { - return AUTH_HANDLERS.get(name); - } - - public static String getHandlerName(Class clazz) { - for (Map.Entry> e : AUTH_HANDLERS.entrySet()) { - if (e.getValue().equals(clazz)) return e.getKey(); - } - return null; - } - public static void registerHandlers() { if (!registredHandl) { - registerHandler("null", NullAuthHandler.class); - registerHandler("json", JsonAuthHandler.class); - registerHandler("memory", MemoryAuthHandler.class); - registerHandler("mysql", MySQLAuthHandler.class); - registerHandler("request", RequestAuthHandler.class); + providers.registerProvider("null", NullAuthHandler.class); + providers.registerProvider("json", JsonAuthHandler.class); + providers.registerProvider("memory", MemoryAuthHandler.class); + providers.registerProvider("mysql", MySQLAuthHandler.class); + providers.registerProvider("request", RequestAuthHandler.class); registredHandl = true; } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWIDHandler.java index e72f7ef2..9472871e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWIDHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWIDHandler.java @@ -1,6 +1,7 @@ package ru.gravit.launchserver.auth.hwid; import ru.gravit.launcher.HWID; +import ru.gravit.utils.ProviderMap; import ru.gravit.utils.helper.VerifyHelper; import java.util.List; @@ -9,22 +10,16 @@ import java.util.concurrent.ConcurrentHashMap; public abstract class HWIDHandler implements AutoCloseable { - private static final Map> HW_HANDLERS = new ConcurrentHashMap<>(4); + public static ProviderMap providers = new ProviderMap<>(); private static boolean registredHandl = false; - public static void registerHandler(String name, Class adapter) { - VerifyHelper.verifyIDName(name); - VerifyHelper.putIfAbsent(HW_HANDLERS, name, Objects.requireNonNull(adapter, "adapter"), - String.format("HWID handler has been already registered: '%s'", name)); - } - public static void registerHandlers() { if (!registredHandl) { - registerHandler("accept", AcceptHWIDHandler.class); - registerHandler("mysql", MysqlHWIDHandler.class); - registerHandler("json", JsonHWIDHandler.class); - registerHandler("memory", MemoryHWIDHandler.class); + providers.registerProvider("accept", AcceptHWIDHandler.class); + providers.registerProvider("mysql", MysqlHWIDHandler.class); + providers.registerProvider("json", JsonHWIDHandler.class); + providers.registerProvider("memory", MemoryHWIDHandler.class); registredHandl = true; } } @@ -46,15 +41,4 @@ public void check(HWID hwid, String username) throws HWIDException { public abstract List getHwid(String username) throws HWIDException; public abstract void unban(List hwid) throws HWIDException; - - public static Class getHandlerClass(String name) { - return HW_HANDLERS.get(name); - } - - public static String getHandlerName(Class clazz) { - for (Map.Entry> e : HW_HANDLERS.entrySet()) { - if (e.getValue().equals(clazz)) return e.getKey(); - } - return null; - } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/PermissionsHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/PermissionsHandler.java index cf8dad23..bce9ceca 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/PermissionsHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/PermissionsHandler.java @@ -1,6 +1,7 @@ package ru.gravit.launchserver.auth.permissions; import ru.gravit.launcher.ClientPermissions; +import ru.gravit.utils.ProviderMap; import ru.gravit.utils.helper.VerifyHelper; import java.util.Map; @@ -8,32 +9,15 @@ import java.util.concurrent.ConcurrentHashMap; public abstract class PermissionsHandler implements AutoCloseable { - private static final Map> PERMISSIONS_HANDLERS = new ConcurrentHashMap<>(4); + public static ProviderMap providers = new ProviderMap<>(); private static boolean registredHandl = false; - public static void registerHandler(String name, Class adapter) { - VerifyHelper.verifyIDName(name); - VerifyHelper.putIfAbsent(PERMISSIONS_HANDLERS, name, Objects.requireNonNull(adapter, "adapter"), - String.format("Auth handler has been already registered: '%s'", name)); - } - - public static Class getHandlerClass(String name) { - return PERMISSIONS_HANDLERS.get(name); - } - - public static String getHandlerName(Class clazz) { - for (Map.Entry> e : PERMISSIONS_HANDLERS.entrySet()) { - if (e.getValue().equals(clazz)) return e.getKey(); - } - return null; - } - public static void registerHandlers() { if (!registredHandl) { - registerHandler("json", JsonFilePermissionsHandler.class); - registerHandler("json-long", JsonLongFilePermissionsHandler.class); - registerHandler("config", ConfigPermissionsHandler.class); - registerHandler("default", DefaultPermissionsHandler.class); + providers.registerProvider("json", JsonFilePermissionsHandler.class); + providers.registerProvider("json-long", JsonLongFilePermissionsHandler.class); + providers.registerProvider("config", ConfigPermissionsHandler.class); + providers.registerProvider("default", DefaultPermissionsHandler.class); registredHandl = true; } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/protect/ProtectHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/protect/ProtectHandler.java index a6d06c2b..abf56f53 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/protect/ProtectHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/protect/ProtectHandler.java @@ -1,6 +1,7 @@ package ru.gravit.launchserver.auth.protect; import ru.gravit.launchserver.websocket.json.auth.AuthResponse; +import ru.gravit.utils.ProviderMap; import ru.gravit.utils.helper.VerifyHelper; import java.util.Map; @@ -8,30 +9,14 @@ import java.util.concurrent.ConcurrentHashMap; public abstract class ProtectHandler { - private static final Map> PROTECT_HANDLERS = new ConcurrentHashMap<>(4); + public static ProviderMap providers = new ProviderMap<>(); private static boolean registredHandl = false; - public static void registerHandler(String name, Class adapter) { - VerifyHelper.verifyIDName(name); - VerifyHelper.putIfAbsent(PROTECT_HANDLERS, name, Objects.requireNonNull(adapter, "adapter"), - String.format("Protect handler has been already registered: '%s'", name)); - } - - public static Class getHandlerClass(String name) { - return PROTECT_HANDLERS.get(name); - } - - public static String getHandlerName(Class clazz) { - for (Map.Entry> e : PROTECT_HANDLERS.entrySet()) { - if (e.getValue().equals(clazz)) return e.getKey(); - } - return null; - } public static void registerHandlers() { if (!registredHandl) { - registerHandler("none", NoProtectHandler.class); + providers.registerProvider("none", NoProtectHandler.class); registredHandl = true; } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java index 50befb9b..0c157e08 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java @@ -1,6 +1,7 @@ package ru.gravit.launchserver.auth.provider; import ru.gravit.launchserver.auth.AuthException; +import ru.gravit.utils.ProviderMap; import ru.gravit.utils.helper.VerifyHelper; import java.io.IOException; @@ -9,27 +10,21 @@ import java.util.concurrent.ConcurrentHashMap; public abstract class AuthProvider implements AutoCloseable { - private static final Map> AUTH_PROVIDERS = new ConcurrentHashMap<>(8); + public static ProviderMap providers = new ProviderMap<>(); private static boolean registredProv = false; public static AuthProviderResult authError(String message) throws AuthException { throw new AuthException(message); } - - public static void registerProvider(String name, Class adapter) { - VerifyHelper.putIfAbsent(AUTH_PROVIDERS, name, Objects.requireNonNull(adapter, "adapter"), - String.format("Auth provider has been already registered: '%s'", name)); - } - public static void registerProviders() { if (!registredProv) { - registerProvider("null", NullAuthProvider.class); - registerProvider("accept", AcceptAuthProvider.class); - registerProvider("reject", RejectAuthProvider.class); - registerProvider("mysql", MySQLAuthProvider.class); - registerProvider("request", RequestAuthProvider.class); - registerProvider("json", JsonAuthProvider.class); + providers.registerProvider("null", NullAuthProvider.class); + providers.registerProvider("accept", AcceptAuthProvider.class); + providers.registerProvider("reject", RejectAuthProvider.class); + providers.registerProvider("mysql", MySQLAuthProvider.class); + providers.registerProvider("request", RequestAuthProvider.class); + providers.registerProvider("json", JsonAuthProvider.class); registredProv = true; } } @@ -44,17 +39,6 @@ public void preAuth(String login, String password, String customText, String ip) @Override public abstract void close() throws IOException; - public static Class getProviderClass(String name) { - return AUTH_PROVIDERS.get(name); - } - - public static String getProviderName(Class clazz) { - for (Map.Entry> e : AUTH_PROVIDERS.entrySet()) { - if (e.getValue().equals(clazz)) return e.getKey(); - } - return null; - } - public void init() { } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/texture/TextureProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/texture/TextureProvider.java index e9db005e..0ced03c5 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/texture/TextureProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/texture/TextureProvider.java @@ -1,6 +1,7 @@ package ru.gravit.launchserver.auth.texture; import ru.gravit.launcher.profiles.Texture; +import ru.gravit.utils.ProviderMap; import ru.gravit.utils.helper.VerifyHelper; import java.io.IOException; @@ -10,22 +11,16 @@ import java.util.concurrent.ConcurrentHashMap; public abstract class TextureProvider implements AutoCloseable { - private static final Map> TEXTURE_PROVIDERS = new ConcurrentHashMap<>(2); + public static ProviderMap providers = new ProviderMap<>(); private static boolean registredProv = false; - - public static void registerProvider(String name, Class adapter) { - VerifyHelper.putIfAbsent(TEXTURE_PROVIDERS, name, Objects.requireNonNull(adapter, "adapter"), - String.format("Texture provider has been already registered: '%s'", name)); - } - public static void registerProviders() { if (!registredProv) { - registerProvider("null", NullTextureProvider.class); - registerProvider("void", VoidTextureProvider.class); + providers.registerProvider("null", NullTextureProvider.class); + providers.registerProvider("void", VoidTextureProvider.class); // Auth providers that doesn't do nothing :D - registerProvider("request", RequestTextureProvider.class); + providers.registerProvider("request", RequestTextureProvider.class); registredProv = true; } } @@ -38,15 +33,4 @@ public static void registerProviders() { public abstract Texture getSkinTexture(UUID uuid, String username, String client) throws IOException; - - public static Class getProviderClass(String name) { - return TEXTURE_PROVIDERS.get(name); - } - - public static String getProviderName(Class clazz) { - for (Map.Entry> e : TEXTURE_PROVIDERS.entrySet()) { - if (e.getValue().equals(clazz)) return e.getKey(); - } - return null; - } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/components/Component.java b/LaunchServer/src/main/java/ru/gravit/launchserver/components/Component.java index a98c3bc3..5bb117a6 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/components/Component.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/components/Component.java @@ -1,6 +1,7 @@ package ru.gravit.launchserver.components; import ru.gravit.launchserver.LaunchServer; +import ru.gravit.utils.ProviderMap; import ru.gravit.utils.helper.VerifyHelper; import java.util.Map; @@ -8,30 +9,13 @@ import java.util.concurrent.ConcurrentHashMap; public abstract class Component { - private static final Map> COMPONENTS = new ConcurrentHashMap<>(4); + public static ProviderMap providers = new ProviderMap<>(); private static boolean registredComp = false; - public static void registerComponent(String name, Class adapter) { - VerifyHelper.verifyIDName(name); - VerifyHelper.putIfAbsent(COMPONENTS, name, Objects.requireNonNull(adapter, "adapter"), - String.format("Auth handler has been already registered: '%s'", name)); - } - - public static Class getComponentClass(String name) { - return COMPONENTS.get(name); - } - - public static String getComponentName(Class clazz) { - for (Map.Entry> e : COMPONENTS.entrySet()) { - if (e.getValue().equals(clazz)) return e.getKey(); - } - return null; - } - public static void registerComponents() { if (!registredComp) { - registerComponent("authLimiter", AuthLimiterComponent.class); - registerComponent("commandRemover", CommandRemoverComponent.class); + providers.registerProvider("authLimiter", AuthLimiterComponent.class); + providers.registerProvider("commandRemover", CommandRemoverComponent.class); registredComp = true; } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/AuthHandlerAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/AuthHandlerAdapter.java deleted file mode 100644 index 4fdd35c5..00000000 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/AuthHandlerAdapter.java +++ /dev/null @@ -1,35 +0,0 @@ -package ru.gravit.launchserver.config.adapter; - -import com.google.gson.*; -import ru.gravit.launchserver.auth.handler.AuthHandler; -import ru.gravit.utils.helper.LogHelper; - -import java.lang.reflect.Type; - -public class AuthHandlerAdapter implements JsonSerializer, JsonDeserializer { - private static final String PROP_NAME = "type"; - - @Override - public AuthHandler deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { - String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); - Class cls = AuthHandler.getHandlerClass(typename); - if (cls == null) { - LogHelper.error("AuthHandler %s not found", typename); - return null; - } - - - return (AuthHandler) context.deserialize(json, cls); - } - - @Override - public JsonElement serialize(AuthHandler src, Type typeOfSrc, JsonSerializationContext context) { - JsonObject jo = context.serialize(src).getAsJsonObject(); - - @SuppressWarnings("unchecked") - String classPath = AuthHandler.getHandlerName((Class) src.getClass()); - jo.add(PROP_NAME, new JsonPrimitive(classPath)); - - return jo; - } -} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/AuthProviderAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/AuthProviderAdapter.java deleted file mode 100644 index 38f9e119..00000000 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/AuthProviderAdapter.java +++ /dev/null @@ -1,34 +0,0 @@ -package ru.gravit.launchserver.config.adapter; - -import com.google.gson.*; -import ru.gravit.launchserver.auth.provider.AuthProvider; -import ru.gravit.utils.helper.LogHelper; - -import java.lang.reflect.Type; - -public class AuthProviderAdapter implements JsonSerializer, JsonDeserializer { - private static final String PROP_NAME = "type"; - - @Override - public AuthProvider deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { - String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); - Class cls = AuthProvider.getProviderClass(typename); - if (cls == null) { - LogHelper.error("AuthProvider %s not found", typename); - return null; - } - - - return (AuthProvider) context.deserialize(json, cls); - } - - @Override - public JsonElement serialize(AuthProvider src, Type typeOfSrc, JsonSerializationContext context) { - JsonObject jo = context.serialize(src).getAsJsonObject(); - - String classPath = AuthProvider.getProviderName(src.getClass()); - jo.add(PROP_NAME, new JsonPrimitive(classPath)); - - return jo; - } -} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/HWIDHandlerAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/HWIDHandlerAdapter.java deleted file mode 100644 index f16149e9..00000000 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/HWIDHandlerAdapter.java +++ /dev/null @@ -1,34 +0,0 @@ -package ru.gravit.launchserver.config.adapter; - -import com.google.gson.*; -import ru.gravit.launchserver.auth.hwid.HWIDHandler; -import ru.gravit.utils.helper.LogHelper; - -import java.lang.reflect.Type; - -public class HWIDHandlerAdapter implements JsonSerializer, JsonDeserializer { - private static final String PROP_NAME = "type"; - - @Override - public HWIDHandler deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { - String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); - Class cls = HWIDHandler.getHandlerClass(typename); - if (cls == null) { - LogHelper.error("HWIDHandler %s not found", typename); - return null; - } - - - return (HWIDHandler) context.deserialize(json, cls); - } - - @Override - public JsonElement serialize(HWIDHandler src, Type typeOfSrc, JsonSerializationContext context) { - JsonObject jo = context.serialize(src).getAsJsonObject(); - - String classPath = HWIDHandler.getHandlerName(src.getClass()); - jo.add(PROP_NAME, new JsonPrimitive(classPath)); - - return jo; - } -} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/PermissionsHandlerAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/PermissionsHandlerAdapter.java deleted file mode 100644 index 35c30a72..00000000 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/PermissionsHandlerAdapter.java +++ /dev/null @@ -1,34 +0,0 @@ -package ru.gravit.launchserver.config.adapter; - -import com.google.gson.*; -import ru.gravit.launchserver.auth.permissions.PermissionsHandler; -import ru.gravit.utils.helper.LogHelper; - -import java.lang.reflect.Type; - -public class PermissionsHandlerAdapter implements JsonSerializer, JsonDeserializer { - private static final String PROP_NAME = "type"; - - @Override - public PermissionsHandler deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { - String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); - Class cls = PermissionsHandler.getHandlerClass(typename); - if (cls == null) { - LogHelper.error("PermissionsHandler %s not found", typename); - return null; - } - - - return (PermissionsHandler) context.deserialize(json, cls); - } - - @Override - public JsonElement serialize(PermissionsHandler src, Type typeOfSrc, JsonSerializationContext context) { - JsonObject jo = context.serialize(src).getAsJsonObject(); - - String classPath = PermissionsHandler.getHandlerName(src.getClass()); - jo.add(PROP_NAME, new JsonPrimitive(classPath)); - - return jo; - } -} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/TextureProviderAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/TextureProviderAdapter.java deleted file mode 100644 index a67c5635..00000000 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/TextureProviderAdapter.java +++ /dev/null @@ -1,34 +0,0 @@ -package ru.gravit.launchserver.config.adapter; - -import com.google.gson.*; -import ru.gravit.launchserver.auth.texture.TextureProvider; -import ru.gravit.utils.helper.LogHelper; - -import java.lang.reflect.Type; - -public class TextureProviderAdapter implements JsonSerializer, JsonDeserializer { - private static final String PROP_NAME = "type"; - - @Override - public TextureProvider deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { - String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); - Class cls = TextureProvider.getProviderClass(typename); - if (cls == null) { - LogHelper.error("TextureProvider %s not found", typename); - return null; - } - - - return (TextureProvider) context.deserialize(json, cls); - } - - @Override - public JsonElement serialize(TextureProvider src, Type typeOfSrc, JsonSerializationContext context) { - JsonObject jo = context.serialize(src).getAsJsonObject(); - - String classPath = TextureProvider.getProviderName(src.getClass()); - jo.add(PROP_NAME, new JsonPrimitive(classPath)); - - return jo; - } -}