2018-09-17 10:07:32 +03:00
|
|
|
package ru.gravit.launchserver.texture;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Objects;
|
|
|
|
import java.util.UUID;
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
2018-12-26 15:33:49 +03:00
|
|
|
import ru.gravit.launcher.profiles.Texture;
|
|
|
|
import ru.gravit.utils.helper.VerifyHelper;
|
|
|
|
|
2018-12-23 19:22:19 +03:00
|
|
|
public abstract class TextureProvider implements AutoCloseable {
|
2018-12-26 15:33:49 +03:00
|
|
|
private static final Map<String, Class<? extends TextureProvider>> TEXTURE_PROVIDERS = new ConcurrentHashMap<>(2);
|
2018-09-17 10:07:32 +03:00
|
|
|
private static boolean registredProv = false;
|
|
|
|
|
2018-10-13 11:01:10 +03:00
|
|
|
|
2018-12-26 15:33:49 +03:00
|
|
|
public static void registerProvider(String name, Class<? extends TextureProvider> adapter) {
|
2018-09-17 10:07:32 +03:00
|
|
|
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) {
|
2018-12-23 19:22:19 +03:00
|
|
|
registerProvider("null", NullTextureProvider.class);
|
|
|
|
registerProvider("void", VoidTextureProvider.class);
|
2018-09-17 10:07:32 +03:00
|
|
|
|
|
|
|
// Auth providers that doesn't do nothing :D
|
2018-12-23 19:22:19 +03:00
|
|
|
registerProvider("request", RequestTextureProvider.class);
|
2018-09-17 10:07:32 +03:00
|
|
|
registredProv = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public abstract void close() throws IOException;
|
|
|
|
|
2018-10-13 11:01:10 +03:00
|
|
|
|
2018-09-17 10:07:32 +03:00
|
|
|
public abstract Texture getCloakTexture(UUID uuid, String username, String client) throws IOException;
|
|
|
|
|
2018-10-13 11:01:10 +03:00
|
|
|
|
2018-09-17 10:07:32 +03:00
|
|
|
public abstract Texture getSkinTexture(UUID uuid, String username, String client) throws IOException;
|
2018-12-23 20:19:43 +03:00
|
|
|
|
2018-12-26 15:33:49 +03:00
|
|
|
public static Class<? extends TextureProvider> getProviderClass(String name)
|
2018-12-23 20:19:43 +03:00
|
|
|
{
|
|
|
|
return TEXTURE_PROVIDERS.get(name);
|
|
|
|
}
|
2018-12-26 15:33:49 +03:00
|
|
|
public static String getProviderName(Class<? extends TextureProvider> clazz)
|
2018-12-23 20:19:43 +03:00
|
|
|
{
|
2018-12-26 15:33:49 +03:00
|
|
|
for(Map.Entry<String,Class<? extends TextureProvider>> e: TEXTURE_PROVIDERS.entrySet())
|
2018-12-23 20:19:43 +03:00
|
|
|
{
|
|
|
|
if(e.getValue().equals(clazz)) return e.getKey();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2018-09-17 10:07:32 +03:00
|
|
|
}
|