mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FEATURE] Изменения названий функций ProviderMap
This commit is contained in:
parent
18bfe77c60
commit
bb27559314
11 changed files with 54 additions and 39 deletions
|
@ -64,12 +64,7 @@ public void reload() throws Exception {
|
|||
config = Launcher.gsonManager.gson.fromJson(reader, Config.class);
|
||||
}
|
||||
config.verify();
|
||||
Launcher.applyLauncherEnv(config.env);
|
||||
for (AuthProviderPair auth : config.auth) {
|
||||
auth.init();
|
||||
}
|
||||
config.permissionsHandler.init();
|
||||
config.hwidHandler.init();
|
||||
config.init();
|
||||
}
|
||||
|
||||
public static final class Config {
|
||||
|
@ -201,6 +196,27 @@ public void verify() {
|
|||
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() {
|
||||
try {
|
||||
|
|
|
@ -18,11 +18,11 @@ public static UUID authError(String message) throws AuthException {
|
|||
|
||||
public static void registerHandlers() {
|
||||
if (!registredHandl) {
|
||||
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);
|
||||
providers.register("null", NullAuthHandler.class);
|
||||
providers.register("json", JsonAuthHandler.class);
|
||||
providers.register("memory", MemoryAuthHandler.class);
|
||||
providers.register("mysql", MySQLAuthHandler.class);
|
||||
providers.register("request", RequestAuthHandler.class);
|
||||
registredHandl = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ public abstract class HWIDHandler implements AutoCloseable {
|
|||
|
||||
public static void registerHandlers() {
|
||||
if (!registredHandl) {
|
||||
providers.registerProvider("accept", AcceptHWIDHandler.class);
|
||||
providers.registerProvider("mysql", MysqlHWIDHandler.class);
|
||||
providers.registerProvider("json", JsonHWIDHandler.class);
|
||||
providers.registerProvider("memory", MemoryHWIDHandler.class);
|
||||
providers.register("accept", AcceptHWIDHandler.class);
|
||||
providers.register("mysql", MysqlHWIDHandler.class);
|
||||
providers.register("json", JsonHWIDHandler.class);
|
||||
providers.register("memory", MemoryHWIDHandler.class);
|
||||
registredHandl = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,10 +9,10 @@ public abstract class PermissionsHandler implements AutoCloseable {
|
|||
|
||||
public static void registerHandlers() {
|
||||
if (!registredHandl) {
|
||||
providers.registerProvider("json", JsonFilePermissionsHandler.class);
|
||||
providers.registerProvider("json-long", JsonLongFilePermissionsHandler.class);
|
||||
providers.registerProvider("config", ConfigPermissionsHandler.class);
|
||||
providers.registerProvider("default", DefaultPermissionsHandler.class);
|
||||
providers.register("json", JsonFilePermissionsHandler.class);
|
||||
providers.register("json-long", JsonLongFilePermissionsHandler.class);
|
||||
providers.register("config", ConfigPermissionsHandler.class);
|
||||
providers.register("default", DefaultPermissionsHandler.class);
|
||||
registredHandl = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ public abstract class ProtectHandler {
|
|||
|
||||
public static void registerHandlers() {
|
||||
if (!registredHandl) {
|
||||
providers.registerProvider("none", NoProtectHandler.class);
|
||||
providers.register("none", NoProtectHandler.class);
|
||||
registredHandl = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,12 +15,12 @@ public static AuthProviderResult authError(String message) throws AuthException
|
|||
|
||||
public static void registerProviders() {
|
||||
if (!registredProv) {
|
||||
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);
|
||||
providers.register("null", NullAuthProvider.class);
|
||||
providers.register("accept", AcceptAuthProvider.class);
|
||||
providers.register("reject", RejectAuthProvider.class);
|
||||
providers.register("mysql", MySQLAuthProvider.class);
|
||||
providers.register("request", RequestAuthProvider.class);
|
||||
providers.register("json", JsonAuthProvider.class);
|
||||
registredProv = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,11 +12,11 @@ public abstract class TextureProvider implements AutoCloseable {
|
|||
|
||||
public static void registerProviders() {
|
||||
if (!registredProv) {
|
||||
providers.registerProvider("null", NullTextureProvider.class);
|
||||
providers.registerProvider("void", VoidTextureProvider.class);
|
||||
providers.register("null", NullTextureProvider.class);
|
||||
providers.register("void", VoidTextureProvider.class);
|
||||
|
||||
// Auth providers that doesn't do nothing :D
|
||||
providers.registerProvider("request", RequestTextureProvider.class);
|
||||
providers.register("request", RequestTextureProvider.class);
|
||||
registredProv = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@ public abstract class Component {
|
|||
|
||||
public static void registerComponents() {
|
||||
if (!registredComp) {
|
||||
providers.registerProvider("authLimiter", AuthLimiterComponent.class);
|
||||
providers.registerProvider("commandRemover", CommandRemoverComponent.class);
|
||||
providers.register("authLimiter", AuthLimiterComponent.class);
|
||||
providers.register("commandRemover", CommandRemoverComponent.class);
|
||||
registredComp = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
import ru.gravit.launcher.request.Request;
|
||||
import ru.gravit.launcher.request.websockets.RequestInterface;
|
||||
import ru.gravit.launcher.serialize.signed.SignedObjectHolder;
|
||||
import ru.gravit.utils.helper.CommonHelper;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
@ -86,7 +85,7 @@ public static HasherStore getDefaultHasherStore() {
|
|||
@LauncherAPI
|
||||
public static void registerUserSettings(String typename, Class<? extends UserSettings> clazz)
|
||||
{
|
||||
UserSettings.providers.registerProvider(typename, clazz);
|
||||
UserSettings.providers.register(typename, clazz);
|
||||
}
|
||||
@LauncherAPI
|
||||
public static void close() throws Exception
|
||||
|
|
|
@ -23,23 +23,23 @@ public String getName()
|
|||
return name;
|
||||
}
|
||||
|
||||
public void registerProvider(String name, Class<? extends R> adapter) {
|
||||
public void register(String name, Class<? extends R> adapter) {
|
||||
VerifyHelper.verifyIDName(name);
|
||||
VerifyHelper.putIfAbsent(PROVIDERS, name, Objects.requireNonNull(adapter, "adapter"),
|
||||
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);
|
||||
}
|
||||
|
||||
public String getProviderName(Class<? extends R> clazz) {
|
||||
public String getName(Class<? extends R> clazz) {
|
||||
for (Map.Entry<String, Class<? extends R>> e : PROVIDERS.entrySet()) {
|
||||
if (e.getValue().equals(clazz)) return e.getKey();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Class<? extends R> unregisterProvider(String name)
|
||||
public Class<? extends R> unregister(String name)
|
||||
{
|
||||
return PROVIDERS.remove(name);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public UniversalJsonAdapter(ProviderMap<R> providerMap, String PROP_NAME) {
|
|||
|
||||
public R deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
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) {
|
||||
LogHelper.error("%s %s not found", name, typename);
|
||||
return null;
|
||||
|
@ -37,7 +37,7 @@ public JsonElement serialize(R src, Type typeOfSrc, JsonSerializationContext con
|
|||
JsonObject jo = context.serialize(src).getAsJsonObject();
|
||||
|
||||
@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));
|
||||
|
||||
return jo;
|
||||
|
|
Loading…
Reference in a new issue