JsonFilePermissionsHandler теперь Reloadable

This commit is contained in:
Gravit 2018-12-26 19:03:34 +07:00
parent e341f144b9
commit 172eb97ce6
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
2 changed files with 29 additions and 1 deletions

View file

@ -364,6 +364,19 @@ public LaunchServer(Path dir) throws IOException, InvalidKeySpecException {
reloadManager = new ReloadManager();
GarbageManager.registerNeedGC(sessionManager);
GarbageManager.registerNeedGC(limiter);
if(config.permissionsHandler instanceof Reloadable)
reloadManager.registerReloadable("permissionsHandler",(Reloadable) config.permissionsHandler);
if(config.authHandler instanceof Reloadable)
reloadManager.registerReloadable("authHandler",(Reloadable) config.authHandler);
for(int i=0;i<config.authProvider.length;++i)
{
AuthProvider provider = config.authProvider[i];
if(provider instanceof Reloadable)
reloadManager.registerReloadable("authHandler".concat(String.valueOf(i)),(Reloadable) provider);
}
if(config.textureProvider instanceof Reloadable)
reloadManager.registerReloadable("textureProvider",(Reloadable) config.textureProvider);
Arrays.stream(config.mirrors).forEach(s -> {
try {
mirrorManager.addMirror(s);

View file

@ -2,6 +2,7 @@
import com.google.gson.reflect.TypeToken;
import ru.gravit.launcher.Launcher;
import ru.gravit.launchserver.Reloadable;
import ru.gravit.launchserver.auth.ClientPermissions;
import ru.gravit.launchserver.manangers.PermissionsManager;
import ru.gravit.utils.helper.IOHelper;
@ -16,9 +17,23 @@
import java.util.HashMap;
import java.util.Map;
public class JsonFilePermissionsHandler extends PermissionsHandler {
public class JsonFilePermissionsHandler extends PermissionsHandler implements Reloadable {
public String filename = "permissions.json";
public static Map<String,ClientPermissions> map;
@Override
public void reload() throws Exception {
map.clear();
Path path = Paths.get(filename);
Type type = new TypeToken<Map<String,ClientPermissions>>(){}.getType();
try(Reader reader = IOHelper.newReader(path))
{
map = Launcher.gson.fromJson(reader,type);
} catch (IOException e) {
LogHelper.error(e);
}
}
public static class Enity
{
public String username;