mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
misc cleanup
This commit is contained in:
1 parent
1403955028
commit
6add891319
16 files changed
+99
-181
No files matched your search
@@ -186,7 +186,6 @@ public abstract class CarbonChatInternal<C extends CarbonPlayer> implements Carb
|
||||
return (IMessageRenderer<T, String, Component, Component>) this.renderer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable PacketService packetService() {
|
||||
return this.messagingManager.get().packetService();
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ import net.draycia.carbon.api.event.CarbonEventHandler;
|
||||
import net.draycia.carbon.api.event.events.CarbonChatEvent;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.util.KeyedRenderer;
|
||||
import net.draycia.carbon.common.CarbonChatInternal;
|
||||
import net.draycia.carbon.common.DataDirectory;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.PlayerCommander;
|
||||
@@ -99,7 +100,7 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
|
||||
private @MonotonicNonNull Key defaultKey;
|
||||
//private @MonotonicNonNull ChatChannel basicChannel;
|
||||
private final CarbonMessages carbonMessages;
|
||||
private final CarbonChat carbonChat;
|
||||
private final CarbonChatInternal<?> carbonChat;
|
||||
|
||||
private final BiMap<Key, ChatChannel> channelMap = Maps.synchronizedBiMap(HashBiMap.create());
|
||||
|
||||
@@ -120,7 +121,7 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
|
||||
this.configFactory = configFactory;
|
||||
this.carbonMessages = carbonMessages;
|
||||
//this.basicChannel = basicChannel;
|
||||
this.carbonChat = carbonChat;
|
||||
this.carbonChat = (CarbonChatInternal<?>) carbonChat;
|
||||
|
||||
events.subscribe(CarbonReloadEvent.class, event -> this.reloadRegisteredConfigChannels());
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.Function;
|
||||
@@ -44,8 +45,8 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
public abstract class CachingUserManager implements UserManagerInternal<CarbonPlayerCommon> {
|
||||
|
||||
protected final Logger logger;
|
||||
protected final ExecutorService executor;
|
||||
protected final ProfileResolver profileResolver;
|
||||
private final ExecutorService executor;
|
||||
private final MembersInjector<CarbonPlayerCommon> playerInjector;
|
||||
private final Provider<MessagingManager> messagingManager;
|
||||
private final PacketFactory packetFactory;
|
||||
@@ -54,14 +55,13 @@ public abstract class CachingUserManager implements UserManagerInternal<CarbonPl
|
||||
|
||||
protected CachingUserManager(
|
||||
final Logger logger,
|
||||
final ExecutorService executorService,
|
||||
final ProfileResolver profileResolver,
|
||||
final MembersInjector<CarbonPlayerCommon> playerInjector,
|
||||
final Provider<MessagingManager> messagingManager,
|
||||
final PacketFactory packetFactory
|
||||
) {
|
||||
this.logger = logger;
|
||||
this.executor = executorService;
|
||||
this.executor = Executors.newSingleThreadExecutor(ConcurrentUtil.carbonThreadFactory(logger, this.getClass().getSimpleName()));
|
||||
this.profileResolver = profileResolver;
|
||||
this.playerInjector = playerInjector;
|
||||
this.messagingManager = messagingManager;
|
||||
@@ -72,6 +72,12 @@ public abstract class CachingUserManager implements UserManagerInternal<CarbonPl
|
||||
|
||||
protected abstract CarbonPlayerCommon loadOrCreate(UUID uuid);
|
||||
|
||||
protected abstract void saveSync(CarbonPlayerCommon player);
|
||||
|
||||
private CompletableFuture<Void> save(final CarbonPlayerCommon player) {
|
||||
return CompletableFuture.runAsync(() -> this.saveSync(player), this.executor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveCompleteMessageReceived(final UUID playerId) {
|
||||
this.cacheLock.lock();
|
||||
@@ -96,8 +102,6 @@ public abstract class CachingUserManager implements UserManagerInternal<CarbonPl
|
||||
});
|
||||
}
|
||||
|
||||
protected abstract CompletableFuture<Void> save(CarbonPlayerCommon player);
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CarbonPlayerCommon> user(final UUID uuid) {
|
||||
this.cacheLock.lock();
|
||||
|
||||
@@ -37,15 +37,13 @@ public abstract class PlatformUserManager<C extends WrappedCarbonPlayer> impleme
|
||||
public CompletableFuture<C> user(final UUID uuid) {
|
||||
return this.backingManager.user(uuid).thenApply(common -> {
|
||||
final C wrapped = this.wrap(common);
|
||||
this.updateTransientLoadedStatus(wrapped);
|
||||
common.markTransientLoaded(!wrapped.online());
|
||||
return wrapped;
|
||||
});
|
||||
}
|
||||
|
||||
protected abstract C wrap(final CarbonPlayerCommon common);
|
||||
|
||||
protected abstract void updateTransientLoadedStatus(C wrapped);
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
this.backingManager.shutdown();
|
||||
|
||||
@@ -28,6 +28,7 @@ import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.util.InventorySlot;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
@@ -43,7 +44,15 @@ import org.jetbrains.annotations.NotNull;
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public abstract class WrappedCarbonPlayer implements CarbonPlayer {
|
||||
|
||||
public abstract CarbonPlayerCommon carbonPlayerCommon();
|
||||
protected final CarbonPlayerCommon carbonPlayerCommon;
|
||||
|
||||
protected WrappedCarbonPlayer(final CarbonPlayerCommon carbonPlayerCommon) {
|
||||
this.carbonPlayerCommon = carbonPlayerCommon;
|
||||
}
|
||||
|
||||
public CarbonPlayerCommon carbonPlayerCommon() {
|
||||
return this.carbonPlayerCommon;
|
||||
}
|
||||
|
||||
public @Nullable User user() {
|
||||
return LuckPermsProvider.get().getUserManager().getUser(this.uuid());
|
||||
@@ -60,22 +69,22 @@ public abstract class WrappedCarbonPlayer implements CarbonPlayer {
|
||||
|
||||
@Override
|
||||
public boolean ignoring(final UUID player) {
|
||||
return this.carbonPlayerCommon().ignoring(player);
|
||||
return this.carbonPlayerCommon.ignoring(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ignoring(final CarbonPlayer player) {
|
||||
return this.carbonPlayerCommon().ignoring(player);
|
||||
return this.carbonPlayerCommon.ignoring(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ignoring(final UUID player, final boolean nowIgnoring) {
|
||||
this.carbonPlayerCommon().ignoring(player, nowIgnoring);
|
||||
this.carbonPlayerCommon.ignoring(player, nowIgnoring);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ignoring(final CarbonPlayer player, final boolean nowIgnoring) {
|
||||
this.carbonPlayerCommon().ignoring(player, nowIgnoring);
|
||||
this.carbonPlayerCommon.ignoring(player, nowIgnoring);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -120,37 +129,37 @@ public abstract class WrappedCarbonPlayer implements CarbonPlayer {
|
||||
|
||||
@Override
|
||||
public String username() {
|
||||
return this.carbonPlayerCommon().username();
|
||||
return this.carbonPlayerCommon.username();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomDisplayName() {
|
||||
return this.carbonPlayerCommon().hasCustomDisplayName();
|
||||
return this.carbonPlayerCommon.hasCustomDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Component displayName() {
|
||||
return this.carbonPlayerCommon().displayName();
|
||||
return this.carbonPlayerCommon.displayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayName(final @Nullable Component displayName) {
|
||||
this.carbonPlayerCommon().displayName(displayName);
|
||||
this.carbonPlayerCommon.displayName(displayName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID uuid() {
|
||||
return this.carbonPlayerCommon().uuid();
|
||||
return this.carbonPlayerCommon.uuid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Component createItemHoverComponent(final InventorySlot slot) {
|
||||
return this.carbonPlayerCommon().createItemHoverComponent(slot);
|
||||
return this.carbonPlayerCommon.createItemHoverComponent(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Locale locale() {
|
||||
return this.carbonPlayerCommon().locale();
|
||||
return this.carbonPlayerCommon.locale();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -183,82 +192,113 @@ public abstract class WrappedCarbonPlayer implements CarbonPlayer {
|
||||
|
||||
@Override
|
||||
public @Nullable ChatChannel selectedChannel() {
|
||||
return this.carbonPlayerCommon().selectedChannel();
|
||||
return this.carbonPlayerCommon.selectedChannel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectedChannel(final @Nullable ChatChannel chatChannel) {
|
||||
this.carbonPlayerCommon().selectedChannel(chatChannel);
|
||||
this.carbonPlayerCommon.selectedChannel(chatChannel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean muted() {
|
||||
return this.carbonPlayerCommon().muted();
|
||||
return this.carbonPlayerCommon.muted();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void muted(final boolean muted) {
|
||||
this.carbonPlayerCommon().muted(muted);
|
||||
this.carbonPlayerCommon.muted(muted);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deafened() {
|
||||
return this.carbonPlayerCommon().deafened();
|
||||
return this.carbonPlayerCommon.deafened();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deafened(final boolean deafened) {
|
||||
this.carbonPlayerCommon().deafened(deafened);
|
||||
this.carbonPlayerCommon.deafened(deafened);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean spying() {
|
||||
return this.carbonPlayerCommon().spying();
|
||||
return this.carbonPlayerCommon.spying();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spying(final boolean spying) {
|
||||
this.carbonPlayerCommon().spying(spying);
|
||||
this.carbonPlayerCommon.spying(spying);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessageAsPlayer(final String message) {
|
||||
this.carbonPlayerCommon().sendMessageAsPlayer(message);
|
||||
this.carbonPlayerCommon.sendMessageAsPlayer(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean online() {
|
||||
return this.carbonPlayerCommon().online();
|
||||
return this.carbonPlayerCommon.online();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable UUID whisperReplyTarget() {
|
||||
return this.carbonPlayerCommon().whisperReplyTarget();
|
||||
return this.carbonPlayerCommon.whisperReplyTarget();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whisperReplyTarget(final @Nullable UUID uuid) {
|
||||
this.carbonPlayerCommon().whisperReplyTarget(uuid);
|
||||
this.carbonPlayerCommon.whisperReplyTarget(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable UUID lastWhisperTarget() {
|
||||
return this.carbonPlayerCommon().lastWhisperTarget();
|
||||
return this.carbonPlayerCommon.lastWhisperTarget();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lastWhisperTarget(final @Nullable UUID uuid) {
|
||||
this.carbonPlayerCommon().lastWhisperTarget(uuid);
|
||||
this.carbonPlayerCommon.lastWhisperTarget(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Identity identity() {
|
||||
return this.carbonPlayerCommon().identity();
|
||||
return this.carbonPlayerCommon.identity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean vanished() {
|
||||
return this.carbonPlayerCommon().vanished();
|
||||
return this.carbonPlayerCommon.vanished();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Key> leftChannels() {
|
||||
return this.carbonPlayerCommon.leftChannels();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void joinChannel(final ChatChannel channel) {
|
||||
this.carbonPlayerCommon.joinChannel(channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void leaveChannel(final ChatChannel channel) {
|
||||
this.carbonPlayerCommon.leaveChannel(channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final @Nullable Object other) {
|
||||
if (other == null || this.getClass() != other.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final WrappedCarbonPlayer that = (WrappedCarbonPlayer) other;
|
||||
|
||||
return this.carbonPlayerCommon.equals(that.carbonPlayerCommon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.carbonPlayerCommon.hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,14 +22,11 @@ package net.draycia.carbon.common.users.db;
|
||||
import com.google.inject.MembersInjector;
|
||||
import com.google.inject.Provider;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executors;
|
||||
import net.draycia.carbon.common.messaging.MessagingManager;
|
||||
import net.draycia.carbon.common.messaging.packets.PacketFactory;
|
||||
import net.draycia.carbon.common.users.CachingUserManager;
|
||||
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||
import net.draycia.carbon.common.users.ProfileResolver;
|
||||
import net.draycia.carbon.common.util.ConcurrentUtil;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
@@ -55,7 +52,6 @@ public abstract class DatabaseUserManager extends CachingUserManager {
|
||||
) {
|
||||
super(
|
||||
logger,
|
||||
Executors.newSingleThreadExecutor(ConcurrentUtil.carbonThreadFactory(logger, "DatabaseUserManager")),
|
||||
profileResolver,
|
||||
playerInjector,
|
||||
messagingManager,
|
||||
@@ -66,8 +62,8 @@ public abstract class DatabaseUserManager extends CachingUserManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final CompletableFuture<Void> save(final CarbonPlayerCommon player) {
|
||||
return CompletableFuture.runAsync(() -> this.jdbi.withHandle(handle -> {
|
||||
public final void saveSync(final CarbonPlayerCommon player) {
|
||||
this.jdbi.withHandle(handle -> {
|
||||
this.bindPlayerArguments(handle.createUpdate(this.locator.query("save-player")), player)
|
||||
.execute();
|
||||
|
||||
@@ -91,7 +87,7 @@ public abstract class DatabaseUserManager extends CachingUserManager {
|
||||
}
|
||||
// TODO: save ignoredplayers
|
||||
return null;
|
||||
}), this.executor);
|
||||
});
|
||||
}
|
||||
|
||||
abstract protected Update bindPlayerArguments(final Update update, final CarbonPlayerCommon player);
|
||||
|
||||
@@ -29,8 +29,6 @@ import java.io.Reader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executors;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.common.DataDirectory;
|
||||
@@ -42,7 +40,6 @@ import net.draycia.carbon.common.users.CachingUserManager;
|
||||
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||
import net.draycia.carbon.common.users.PersistentUserProperty;
|
||||
import net.draycia.carbon.common.users.ProfileResolver;
|
||||
import net.draycia.carbon.common.util.ConcurrentUtil;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
@@ -68,7 +65,6 @@ public class JSONUserManager extends CachingUserManager {
|
||||
) throws IOException {
|
||||
super(
|
||||
logger,
|
||||
Executors.newSingleThreadExecutor(ConcurrentUtil.carbonThreadFactory(logger, "JSONUserManager")),
|
||||
profileResolver,
|
||||
playerInjector,
|
||||
messagingManager,
|
||||
@@ -123,22 +119,20 @@ public class JSONUserManager extends CachingUserManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> save(final CarbonPlayerCommon player) {
|
||||
return CompletableFuture.runAsync(() -> {
|
||||
final Path userFile = this.userFile(player.uuid());
|
||||
public void saveSync(final CarbonPlayerCommon player) {
|
||||
final Path userFile = this.userFile(player.uuid());
|
||||
|
||||
try {
|
||||
final String json = this.serializer.toJson(player);
|
||||
try {
|
||||
final String json = this.serializer.toJson(player);
|
||||
|
||||
if (json == null || json.isBlank()) {
|
||||
throw new IllegalStateException("No data to save - toJson returned null or blank.");
|
||||
}
|
||||
|
||||
Files.writeString(userFile, json);
|
||||
} catch (final IOException exception) {
|
||||
throw new RuntimeException("Exception while saving data for player [%s]".formatted(player.username()), exception);
|
||||
if (json == null || json.isBlank()) {
|
||||
throw new IllegalStateException("No data to save - toJson returned null or blank.");
|
||||
}
|
||||
}, this.executor);
|
||||
|
||||
Files.writeString(userFile, json);
|
||||
} catch (final IOException exception) {
|
||||
throw new RuntimeException("Exception while saving data for player [%s]".formatted(player.username()), exception);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user