[FEATURE] Изменения названий функций ProviderMap

This commit is contained in:
Gravit 2019-04-27 17:05:49 +07:00
parent 18bfe77c60
commit bb27559314
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
11 changed files with 54 additions and 39 deletions

View file

@ -64,12 +64,7 @@ public void reload() throws Exception {
config = Launcher.gsonManager.gson.fromJson(reader, Config.class); config = Launcher.gsonManager.gson.fromJson(reader, Config.class);
} }
config.verify(); config.verify();
Launcher.applyLauncherEnv(config.env); config.init();
for (AuthProviderPair auth : config.auth) {
auth.init();
}
config.permissionsHandler.init();
config.hwidHandler.init();
} }
public static final class Config { public static final class Config {
@ -201,6 +196,27 @@ public void verify() {
throw new NullPointerException("Netty must not be null"); throw new NullPointerException("Netty must not be null");
} }
} }
public void init()
{
Launcher.applyLauncherEnv(env);
for (AuthProviderPair provider : auth) {
provider.init();
}
permissionsHandler.init();
hwidHandler.init();
if (protectHandler != null) {
protectHandler.checkLaunchServerLicense();
}
LaunchServer.server.registerObject("permissionsHandler", permissionsHandler);
for (int i = 0; i < auth.length; ++i) {
AuthProviderPair pair = auth[i];
LaunchServer.server.registerObject("auth.".concat(pair.name).concat(".provider"), pair.provider);
LaunchServer.server.registerObject("auth.".concat(pair.name).concat(".handler"), pair.handler);
LaunchServer.server.registerObject("auth.".concat(pair.name).concat(".texture"), pair.textureProvider);
}
Arrays.stream(mirrors).forEach(LaunchServer.server.mirrorManager::addMirror);
}
public void close() { public void close() {
try { try {

View file

@ -18,11 +18,11 @@ public static UUID authError(String message) throws AuthException {
public static void registerHandlers() { public static void registerHandlers() {
if (!registredHandl) { if (!registredHandl) {
providers.registerProvider("null", NullAuthHandler.class); providers.register("null", NullAuthHandler.class);
providers.registerProvider("json", JsonAuthHandler.class); providers.register("json", JsonAuthHandler.class);
providers.registerProvider("memory", MemoryAuthHandler.class); providers.register("memory", MemoryAuthHandler.class);
providers.registerProvider("mysql", MySQLAuthHandler.class); providers.register("mysql", MySQLAuthHandler.class);
providers.registerProvider("request", RequestAuthHandler.class); providers.register("request", RequestAuthHandler.class);
registredHandl = true; registredHandl = true;
} }
} }

View file

@ -12,10 +12,10 @@ public abstract class HWIDHandler implements AutoCloseable {
public static void registerHandlers() { public static void registerHandlers() {
if (!registredHandl) { if (!registredHandl) {
providers.registerProvider("accept", AcceptHWIDHandler.class); providers.register("accept", AcceptHWIDHandler.class);
providers.registerProvider("mysql", MysqlHWIDHandler.class); providers.register("mysql", MysqlHWIDHandler.class);
providers.registerProvider("json", JsonHWIDHandler.class); providers.register("json", JsonHWIDHandler.class);
providers.registerProvider("memory", MemoryHWIDHandler.class); providers.register("memory", MemoryHWIDHandler.class);
registredHandl = true; registredHandl = true;
} }
} }

View file

@ -9,10 +9,10 @@ public abstract class PermissionsHandler implements AutoCloseable {
public static void registerHandlers() { public static void registerHandlers() {
if (!registredHandl) { if (!registredHandl) {
providers.registerProvider("json", JsonFilePermissionsHandler.class); providers.register("json", JsonFilePermissionsHandler.class);
providers.registerProvider("json-long", JsonLongFilePermissionsHandler.class); providers.register("json-long", JsonLongFilePermissionsHandler.class);
providers.registerProvider("config", ConfigPermissionsHandler.class); providers.register("config", ConfigPermissionsHandler.class);
providers.registerProvider("default", DefaultPermissionsHandler.class); providers.register("default", DefaultPermissionsHandler.class);
registredHandl = true; registredHandl = true;
} }
} }

View file

@ -11,7 +11,7 @@ public abstract class ProtectHandler {
public static void registerHandlers() { public static void registerHandlers() {
if (!registredHandl) { if (!registredHandl) {
providers.registerProvider("none", NoProtectHandler.class); providers.register("none", NoProtectHandler.class);
registredHandl = true; registredHandl = true;
} }
} }

View file

@ -15,12 +15,12 @@ public static AuthProviderResult authError(String message) throws AuthException
public static void registerProviders() { public static void registerProviders() {
if (!registredProv) { if (!registredProv) {
providers.registerProvider("null", NullAuthProvider.class); providers.register("null", NullAuthProvider.class);
providers.registerProvider("accept", AcceptAuthProvider.class); providers.register("accept", AcceptAuthProvider.class);
providers.registerProvider("reject", RejectAuthProvider.class); providers.register("reject", RejectAuthProvider.class);
providers.registerProvider("mysql", MySQLAuthProvider.class); providers.register("mysql", MySQLAuthProvider.class);
providers.registerProvider("request", RequestAuthProvider.class); providers.register("request", RequestAuthProvider.class);
providers.registerProvider("json", JsonAuthProvider.class); providers.register("json", JsonAuthProvider.class);
registredProv = true; registredProv = true;
} }
} }

View file

@ -12,11 +12,11 @@ public abstract class TextureProvider implements AutoCloseable {
public static void registerProviders() { public static void registerProviders() {
if (!registredProv) { if (!registredProv) {
providers.registerProvider("null", NullTextureProvider.class); providers.register("null", NullTextureProvider.class);
providers.registerProvider("void", VoidTextureProvider.class); providers.register("void", VoidTextureProvider.class);
// Auth providers that doesn't do nothing :D // Auth providers that doesn't do nothing :D
providers.registerProvider("request", RequestTextureProvider.class); providers.register("request", RequestTextureProvider.class);
registredProv = true; registredProv = true;
} }
} }

View file

@ -9,8 +9,8 @@ public abstract class Component {
public static void registerComponents() { public static void registerComponents() {
if (!registredComp) { if (!registredComp) {
providers.registerProvider("authLimiter", AuthLimiterComponent.class); providers.register("authLimiter", AuthLimiterComponent.class);
providers.registerProvider("commandRemover", CommandRemoverComponent.class); providers.register("commandRemover", CommandRemoverComponent.class);
registredComp = true; registredComp = true;
} }
} }

View file

@ -13,7 +13,6 @@
import ru.gravit.launcher.request.Request; import ru.gravit.launcher.request.Request;
import ru.gravit.launcher.request.websockets.RequestInterface; import ru.gravit.launcher.request.websockets.RequestInterface;
import ru.gravit.launcher.serialize.signed.SignedObjectHolder; import ru.gravit.launcher.serialize.signed.SignedObjectHolder;
import ru.gravit.utils.helper.CommonHelper;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import java.nio.file.Path; import java.nio.file.Path;
@ -86,7 +85,7 @@ public static HasherStore getDefaultHasherStore() {
@LauncherAPI @LauncherAPI
public static void registerUserSettings(String typename, Class<? extends UserSettings> clazz) public static void registerUserSettings(String typename, Class<? extends UserSettings> clazz)
{ {
UserSettings.providers.registerProvider(typename, clazz); UserSettings.providers.register(typename, clazz);
} }
@LauncherAPI @LauncherAPI
public static void close() throws Exception public static void close() throws Exception

View file

@ -23,23 +23,23 @@ public String getName()
return name; return name;
} }
public void registerProvider(String name, Class<? extends R> adapter) { public void register(String name, Class<? extends R> adapter) {
VerifyHelper.verifyIDName(name); VerifyHelper.verifyIDName(name);
VerifyHelper.putIfAbsent(PROVIDERS, name, Objects.requireNonNull(adapter, "adapter"), VerifyHelper.putIfAbsent(PROVIDERS, name, Objects.requireNonNull(adapter, "adapter"),
String.format("%s has been already registered: '%s'", this.name, name)); String.format("%s has been already registered: '%s'", this.name, name));
} }
public Class<? extends R> getProviderClass(String name) { public Class<? extends R> getClass(String name) {
return PROVIDERS.get(name); return PROVIDERS.get(name);
} }
public String getProviderName(Class<? extends R> clazz) { public String getName(Class<? extends R> clazz) {
for (Map.Entry<String, Class<? extends R>> e : PROVIDERS.entrySet()) { for (Map.Entry<String, Class<? extends R>> e : PROVIDERS.entrySet()) {
if (e.getValue().equals(clazz)) return e.getKey(); if (e.getValue().equals(clazz)) return e.getKey();
} }
return null; return null;
} }
public Class<? extends R> unregisterProvider(String name) public Class<? extends R> unregister(String name)
{ {
return PROVIDERS.remove(name); return PROVIDERS.remove(name);
} }

View file

@ -24,7 +24,7 @@ public UniversalJsonAdapter(ProviderMap<R> providerMap, String PROP_NAME) {
public R deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { public R deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();
Class<? extends R> cls = providerMap.getProviderClass(typename); Class<? extends R> cls = providerMap.getClass(typename);
if (cls == null) { if (cls == null) {
LogHelper.error("%s %s not found", name, typename); LogHelper.error("%s %s not found", name, typename);
return null; return null;
@ -37,7 +37,7 @@ public JsonElement serialize(R src, Type typeOfSrc, JsonSerializationContext con
JsonObject jo = context.serialize(src).getAsJsonObject(); JsonObject jo = context.serialize(src).getAsJsonObject();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
String classPath = providerMap.getProviderName((Class<? extends R>) src.getClass()); String classPath = providerMap.getName((Class<? extends R>) src.getClass());
jo.add(PROP_NAME, new JsonPrimitive(classPath)); jo.add(PROP_NAME, new JsonPrimitive(classPath));
return jo; return jo;