mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 22:15:45 +00:00
fixup profileresolver injection
This commit is contained in:
3 files changed
+11
-12
No files matched your search
@@ -40,12 +40,14 @@ public abstract class CachingUserManager implements UserManagerInternal<CarbonPl
|
|||||||
|
|
||||||
protected final Logger logger;
|
protected final Logger logger;
|
||||||
protected final ExecutorService executor;
|
protected final ExecutorService executor;
|
||||||
|
protected final ProfileResolver profileResolver;
|
||||||
private final ReentrantLock cacheLock;
|
private final ReentrantLock cacheLock;
|
||||||
private final Map<UUID, CompletableFuture<CarbonPlayerCommon>> cache;
|
private final Map<UUID, CompletableFuture<CarbonPlayerCommon>> cache;
|
||||||
|
|
||||||
protected CachingUserManager(final Logger logger, final ExecutorService executorService) {
|
protected CachingUserManager(final Logger logger, final ExecutorService executorService, final ProfileResolver profileResolver) {
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.executor = executorService;
|
this.executor = executorService;
|
||||||
|
this.profileResolver = profileResolver;
|
||||||
this.cacheLock = new ReentrantLock();
|
this.cacheLock = new ReentrantLock();
|
||||||
this.cache = new HashMap<>();
|
this.cache = new HashMap<>();
|
||||||
}
|
}
|
||||||
@@ -57,7 +59,11 @@ public abstract class CachingUserManager implements UserManagerInternal<CarbonPl
|
|||||||
this.cacheLock.lock();
|
this.cacheLock.lock();
|
||||||
try {
|
try {
|
||||||
return this.cache.computeIfAbsent(uuid, $ -> {
|
return this.cache.computeIfAbsent(uuid, $ -> {
|
||||||
final CompletableFuture<CarbonPlayerCommon> future = CompletableFuture.supplyAsync(() -> this.loadOrCreate(uuid), this.executor);
|
final CompletableFuture<CarbonPlayerCommon> future = CompletableFuture.supplyAsync(() -> {
|
||||||
|
final CarbonPlayerCommon player = this.loadOrCreate(uuid);
|
||||||
|
player.profileResolver = this.profileResolver;
|
||||||
|
return player;
|
||||||
|
}, this.executor);
|
||||||
this.attachPostLoad(uuid, future);
|
this.attachPostLoad(uuid, future);
|
||||||
return future;
|
return future;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -39,13 +39,11 @@ public abstract class DatabaseUserManager extends CachingUserManager {
|
|||||||
|
|
||||||
protected final Jdbi jdbi;
|
protected final Jdbi jdbi;
|
||||||
protected final QueriesLocator locator;
|
protected final QueriesLocator locator;
|
||||||
protected final ProfileResolver profileResolver;
|
|
||||||
|
|
||||||
protected DatabaseUserManager(final Jdbi jdbi, final QueriesLocator locator, final Logger logger, final ProfileResolver profileResolver) {
|
protected DatabaseUserManager(final Jdbi jdbi, final QueriesLocator locator, final Logger logger, final ProfileResolver profileResolver) {
|
||||||
super(logger, Executors.newSingleThreadExecutor(ConcurrentUtil.carbonThreadFactory(logger, "DatabaseUserManager")));
|
super(logger, Executors.newSingleThreadExecutor(ConcurrentUtil.carbonThreadFactory(logger, "DatabaseUserManager")), profileResolver);
|
||||||
this.jdbi = jdbi;
|
this.jdbi = jdbi;
|
||||||
this.locator = locator;
|
this.locator = locator;
|
||||||
this.profileResolver = profileResolver;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ public class JSONUserManager extends CachingUserManager {
|
|||||||
private static final String EMPTY_USER_UUID = "f81d4fae-7dec-11d0-a765-00a0c91e6bf6";
|
private static final String EMPTY_USER_UUID = "f81d4fae-7dec-11d0-a765-00a0c91e6bf6";
|
||||||
private final Gson serializer;
|
private final Gson serializer;
|
||||||
private final Path userDirectory;
|
private final Path userDirectory;
|
||||||
private final ProfileResolver profileResolver;
|
|
||||||
private final String emptyUserJson;
|
private final String emptyUserJson;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -61,9 +60,8 @@ public class JSONUserManager extends CachingUserManager {
|
|||||||
final Logger logger,
|
final Logger logger,
|
||||||
final ProfileResolver profileResolver
|
final ProfileResolver profileResolver
|
||||||
) throws IOException {
|
) throws IOException {
|
||||||
super(logger, Executors.newSingleThreadExecutor(ConcurrentUtil.carbonThreadFactory(logger, "JSONUserManager")));
|
super(logger, Executors.newSingleThreadExecutor(ConcurrentUtil.carbonThreadFactory(logger, "JSONUserManager")), profileResolver);
|
||||||
this.userDirectory = dataDirectory.resolve("users");
|
this.userDirectory = dataDirectory.resolve("users");
|
||||||
this.profileResolver = profileResolver;
|
|
||||||
|
|
||||||
Files.createDirectories(this.userDirectory);
|
Files.createDirectories(this.userDirectory);
|
||||||
|
|
||||||
@@ -89,7 +87,6 @@ public class JSONUserManager extends CachingUserManager {
|
|||||||
if (player == null) {
|
if (player == null) {
|
||||||
throw new IllegalStateException("Player file found but was empty.");
|
throw new IllegalStateException("Player file found but was empty.");
|
||||||
}
|
}
|
||||||
player.profileResolver = this.profileResolver;
|
|
||||||
player.leftChannels().removeIf(channel -> CarbonChatProvider.carbonChat()
|
player.leftChannels().removeIf(channel -> CarbonChatProvider.carbonChat()
|
||||||
.channelRegistry()
|
.channelRegistry()
|
||||||
.get(channel) == null);
|
.get(channel) == null);
|
||||||
@@ -100,9 +97,7 @@ public class JSONUserManager extends CachingUserManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final CarbonPlayerCommon player = new CarbonPlayerCommon(null /* Username will be resolved when requested */, uuid);
|
return new CarbonPlayerCommon(null /* Username will be resolved when requested */, uuid);
|
||||||
player.profileResolver = this.profileResolver;
|
|
||||||
return player;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Path userFile(final UUID id) {
|
private Path userFile(final UUID id) {
|
||||||
|
|||||||
Reference in new issue
Block a user