Simplify user manager hierarchy

This commit is contained in:
Jason Penilla committed 2023-08-10 00:42:29 -07:00
1 parent 10b9862c18
commit ef275b5c33
19 files changed
+72 -207

No files matched your search

@@ -37,6 +37,7 @@ import net.draycia.carbon.common.listeners.Listener;
import net.draycia.carbon.common.messages.CarbonMessages; import net.draycia.carbon.common.messages.CarbonMessages;
import net.draycia.carbon.common.messaging.MessagingManager; import net.draycia.carbon.common.messaging.MessagingManager;
import net.draycia.carbon.common.messaging.packets.PacketFactory; import net.draycia.carbon.common.messaging.packets.PacketFactory;
import net.draycia.carbon.common.users.PlatformUserManager;
import net.draycia.carbon.common.users.ProfileCache; import net.draycia.carbon.common.users.ProfileCache;
import net.draycia.carbon.common.users.ProfileResolver; import net.draycia.carbon.common.users.ProfileResolver;
import net.draycia.carbon.common.users.UserManagerInternal; import net.draycia.carbon.common.users.UserManagerInternal;
@@ -72,7 +73,7 @@ public abstract class CarbonChatInternal<C extends CarbonPlayer> implements Carb
final ScheduledExecutorService periodicTasks, final ScheduledExecutorService periodicTasks,
final ProfileCache profileCache, final ProfileCache profileCache,
final ProfileResolver profileResolver, final ProfileResolver profileResolver,
final UserManagerInternal<C> userManager, final PlatformUserManager userManager,
final ExecutionCoordinatorHolder commandExecutor, final ExecutionCoordinatorHolder commandExecutor,
final CarbonServer carbonServer, final CarbonServer carbonServer,
final CarbonMessages carbonMessages, final CarbonMessages carbonMessages,
@@ -86,7 +87,7 @@ public abstract class CarbonChatInternal<C extends CarbonPlayer> implements Carb
this.periodicTasks = periodicTasks; this.periodicTasks = periodicTasks;
this.profileCache = profileCache; this.profileCache = profileCache;
this.profileResolver = profileResolver; this.profileResolver = profileResolver;
this.userManager = userManager; this.userManager = (UserManagerInternal<C>) userManager;
this.commandExecutor = commandExecutor; this.commandExecutor = commandExecutor;
this.carbonServer = carbonServer; this.carbonServer = carbonServer;
this.carbonMessages = carbonMessages; this.carbonMessages = carbonMessages;
@@ -36,6 +36,7 @@ import java.util.UUID;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import net.draycia.carbon.api.channels.ChannelRegistry; import net.draycia.carbon.api.channels.ChannelRegistry;
import net.draycia.carbon.api.event.CarbonEventHandler; import net.draycia.carbon.api.event.CarbonEventHandler;
import net.draycia.carbon.api.users.UserManager;
import net.draycia.carbon.common.channels.CarbonChannelRegistry; import net.draycia.carbon.common.channels.CarbonChannelRegistry;
import net.draycia.carbon.common.command.ArgumentFactory; import net.draycia.carbon.common.command.ArgumentFactory;
import net.draycia.carbon.common.command.argument.PlayerSuggestions; import net.draycia.carbon.common.command.argument.PlayerSuggestions;
@@ -66,6 +67,7 @@ import net.draycia.carbon.common.messaging.packets.PacketFactory;
import net.draycia.carbon.common.users.Backing; import net.draycia.carbon.common.users.Backing;
import net.draycia.carbon.common.users.CarbonPlayerCommon; import net.draycia.carbon.common.users.CarbonPlayerCommon;
import net.draycia.carbon.common.users.NetworkUsers; import net.draycia.carbon.common.users.NetworkUsers;
import net.draycia.carbon.common.users.PlatformUserManager;
import net.draycia.carbon.common.users.UserManagerInternal; import net.draycia.carbon.common.users.UserManagerInternal;
import net.draycia.carbon.common.users.db.mysql.MySQLUserManager; import net.draycia.carbon.common.users.db.mysql.MySQLUserManager;
import net.draycia.carbon.common.users.db.postgresql.PostgreSQLUserManager; import net.draycia.carbon.common.users.db.postgresql.PostgreSQLUserManager;
@@ -142,6 +144,8 @@ public final class CarbonCommonModule extends AbstractModule {
this.bind(ChannelRegistry.class).to(CarbonChannelRegistry.class); this.bind(ChannelRegistry.class).to(CarbonChannelRegistry.class);
this.bind(CarbonEventHandler.class).to(CarbonEventHandlerImpl.class); this.bind(CarbonEventHandler.class).to(CarbonEventHandlerImpl.class);
this.bind(PlayerSuggestions.class).to(NetworkUsers.class); this.bind(PlayerSuggestions.class).to(NetworkUsers.class);
this.bind(new TypeLiteral<UserManager<?>>() {}).to(PlatformUserManager.class);
this.bind(new TypeLiteral<UserManagerInternal<?>>() {}).to(PlatformUserManager.class);
final Multibinder<Listener> listeners = Multibinder.newSetBinder(this.binder(), Listener.class); final Multibinder<Listener> listeners = Multibinder.newSetBinder(this.binder(), Listener.class);
listeners.addBinding().to(DeafenHandler.class); listeners.addBinding().to(DeafenHandler.class);
@@ -19,31 +19,40 @@
*/ */
package net.draycia.carbon.common.users; package net.draycia.carbon.common.users;
import com.google.inject.Inject;
import com.google.inject.Module;
import com.google.inject.Singleton;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier; import org.checkerframework.framework.qual.DefaultQualifier;
@Singleton
@DefaultQualifier(NonNull.class) @DefaultQualifier(NonNull.class)
public abstract class PlatformUserManager<C extends WrappedCarbonPlayer> implements UserManagerInternal<C> { public final class PlatformUserManager implements UserManagerInternal<WrappedCarbonPlayer> {
private final UserManagerInternal<CarbonPlayerCommon> backingManager; private final UserManagerInternal<CarbonPlayerCommon> backingManager;
private final PlayerFactory playerFactory;
public PlatformUserManager(final UserManagerInternal<CarbonPlayerCommon> backingManager) { @Inject
private PlatformUserManager(
final UserManagerInternal<CarbonPlayerCommon> backingManager,
final PlayerFactory playerFactory
) {
this.backingManager = backingManager; this.backingManager = backingManager;
this.playerFactory = playerFactory;
} }
@Override @Override
public CompletableFuture<C> user(final UUID uuid) { public CompletableFuture<WrappedCarbonPlayer> user(final UUID uuid) {
return this.backingManager.user(uuid).thenApply(common -> { return this.backingManager.user(uuid).thenApply(common -> {
final C wrapped = this.wrap(common); final WrappedCarbonPlayer wrapped = this.playerFactory.wrap(common);
common.markTransientLoaded(!wrapped.online()); common.markTransientLoaded(!wrapped.online());
return wrapped; return wrapped;
}); });
} }
protected abstract C wrap(final CarbonPlayerCommon common);
@Override @Override
public void shutdown() { public void shutdown() {
this.backingManager.shutdown(); this.backingManager.shutdown();
@@ -55,7 +64,7 @@ public abstract class PlatformUserManager<C extends WrappedCarbonPlayer> impleme
} }
@Override @Override
public CompletableFuture<Void> saveIfNeeded(final C player) { public CompletableFuture<Void> saveIfNeeded(final WrappedCarbonPlayer player) {
return this.backingManager.saveIfNeeded(player.carbonPlayerCommon()); return this.backingManager.saveIfNeeded(player.carbonPlayerCommon());
} }
@@ -69,4 +78,16 @@ public abstract class PlatformUserManager<C extends WrappedCarbonPlayer> impleme
this.backingManager.cleanup(); this.backingManager.cleanup();
} }
public interface PlayerFactory {
WrappedCarbonPlayer wrap(CarbonPlayerCommon common);
static Module moduleFor(final Class<? extends WrappedCarbonPlayer> carbonPlayerImpl) {
return new FactoryModuleBuilder()
.implement(WrappedCarbonPlayer.class, carbonPlayerImpl)
.build(PlatformUserManager.PlayerFactory.class);
}
}
} }
@@ -35,6 +35,7 @@ import net.draycia.carbon.common.channels.CarbonChannelRegistry;
import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder; import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder;
import net.draycia.carbon.common.messages.CarbonMessages; import net.draycia.carbon.common.messages.CarbonMessages;
import net.draycia.carbon.common.messaging.MessagingManager; import net.draycia.carbon.common.messaging.MessagingManager;
import net.draycia.carbon.common.users.PlatformUserManager;
import net.draycia.carbon.common.users.ProfileCache; import net.draycia.carbon.common.users.ProfileCache;
import net.draycia.carbon.common.users.ProfileResolver; import net.draycia.carbon.common.users.ProfileResolver;
import net.draycia.carbon.fabric.command.DeleteMessageCommand; import net.draycia.carbon.fabric.command.DeleteMessageCommand;
@@ -67,7 +68,7 @@ public final class CarbonChatFabric extends CarbonChatInternal<CarbonPlayerFabri
final @PeriodicTasks ScheduledExecutorService periodicTasks, final @PeriodicTasks ScheduledExecutorService periodicTasks,
final ProfileCache profileCache, final ProfileCache profileCache,
final ProfileResolver profileResolver, final ProfileResolver profileResolver,
final FabricUserManager userManager, final PlatformUserManager userManager,
final ExecutionCoordinatorHolder commandExecutor, final ExecutionCoordinatorHolder commandExecutor,
final CarbonServer carbonServer, final CarbonServer carbonServer,
final CarbonMessages carbonMessages, final CarbonMessages carbonMessages,
@@ -25,11 +25,9 @@ import com.google.inject.AbstractModule;
import com.google.inject.Provider; import com.google.inject.Provider;
import com.google.inject.Provides; import com.google.inject.Provides;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;
import java.nio.file.Path; import java.nio.file.Path;
import net.draycia.carbon.api.CarbonChat; import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.CarbonServer; import net.draycia.carbon.api.CarbonServer;
import net.draycia.carbon.api.users.UserManager;
import net.draycia.carbon.common.CarbonCommonModule; import net.draycia.carbon.common.CarbonCommonModule;
import net.draycia.carbon.common.DataDirectory; import net.draycia.carbon.common.DataDirectory;
import net.draycia.carbon.common.PlatformScheduler; import net.draycia.carbon.common.PlatformScheduler;
@@ -37,11 +35,12 @@ import net.draycia.carbon.common.command.Commander;
import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder; import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder;
import net.draycia.carbon.common.messages.CarbonMessageRenderer; import net.draycia.carbon.common.messages.CarbonMessageRenderer;
import net.draycia.carbon.common.messages.CarbonMessages; import net.draycia.carbon.common.messages.CarbonMessages;
import net.draycia.carbon.common.users.PlatformUserManager;
import net.draycia.carbon.common.users.ProfileResolver; import net.draycia.carbon.common.users.ProfileResolver;
import net.draycia.carbon.common.users.UserManagerInternal;
import net.draycia.carbon.common.util.CloudUtils; import net.draycia.carbon.common.util.CloudUtils;
import net.draycia.carbon.fabric.command.FabricCommander; import net.draycia.carbon.fabric.command.FabricCommander;
import net.draycia.carbon.fabric.command.FabricPlayerCommander; import net.draycia.carbon.fabric.command.FabricPlayerCommander;
import net.draycia.carbon.fabric.users.CarbonPlayerFabric;
import net.draycia.carbon.fabric.users.FabricProfileResolver; import net.draycia.carbon.fabric.users.FabricProfileResolver;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer; import net.fabricmc.loader.api.ModContainer;
@@ -100,8 +99,7 @@ public final class CarbonChatFabricModule extends AbstractModule {
this.bind(CarbonServer.class).to(CarbonServerFabric.class); this.bind(CarbonServer.class).to(CarbonServerFabric.class);
this.bind(ProfileResolver.class).to(FabricProfileResolver.class); this.bind(ProfileResolver.class).to(FabricProfileResolver.class);
this.bind(PlatformScheduler.class).to(FabricScheduler.class); this.bind(PlatformScheduler.class).to(FabricScheduler.class);
this.bind(new TypeLiteral<UserManager<?>>() {}).to(FabricUserManager.class); this.install(PlatformUserManager.PlayerFactory.moduleFor(CarbonPlayerFabric.class));
this.bind(new TypeLiteral<UserManagerInternal<?>>() {}).to(FabricUserManager.class);
this.bind(CarbonMessageRenderer.class).to(FabricMessageRenderer.class); this.bind(CarbonMessageRenderer.class).to(FabricMessageRenderer.class);
} }
@@ -25,6 +25,7 @@ import java.util.List;
import java.util.Objects; import java.util.Objects;
import net.draycia.carbon.api.CarbonServer; import net.draycia.carbon.api.CarbonServer;
import net.draycia.carbon.api.users.CarbonPlayer; import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.users.UserManager;
import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.audience.ForwardingAudience; import net.kyori.adventure.audience.ForwardingAudience;
import net.kyori.adventure.platform.fabric.FabricServerAudiences; import net.kyori.adventure.platform.fabric.FabricServerAudiences;
@@ -37,10 +38,10 @@ import org.jetbrains.annotations.NotNull;
public final class CarbonServerFabric implements CarbonServer, ForwardingAudience.Single { public final class CarbonServerFabric implements CarbonServer, ForwardingAudience.Single {
private final MinecraftServerHolder serverHolder; private final MinecraftServerHolder serverHolder;
private final FabricUserManager userManager; private final UserManager<?> userManager;
@Inject @Inject
private CarbonServerFabric(final MinecraftServerHolder serverHolder, final FabricUserManager userManager) { private CarbonServerFabric(final MinecraftServerHolder serverHolder, final UserManager<?> userManager) {
this.serverHolder = serverHolder; this.serverHolder = serverHolder;
this.userManager = userManager; this.userManager = userManager;
} }
@@ -1,56 +0,0 @@
/*
* CarbonChat
*
* Copyright (c) 2023 Josua Parks (Vicarious)
* Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.draycia.carbon.fabric;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import net.draycia.carbon.common.users.Backing;
import net.draycia.carbon.common.users.CarbonPlayerCommon;
import net.draycia.carbon.common.users.PlatformUserManager;
import net.draycia.carbon.common.users.UserManagerInternal;
import net.draycia.carbon.fabric.users.CarbonPlayerFabric;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@DefaultQualifier(NonNull.class)
@Singleton
public final class FabricUserManager extends PlatformUserManager<CarbonPlayerFabric> {
private final MinecraftServerHolder serverHolder;
private final Provider<CarbonChatFabric> carbonChat;
@Inject
private FabricUserManager(
final @Backing UserManagerInternal<CarbonPlayerCommon> backingManager,
final MinecraftServerHolder serverHolder,
final Provider<CarbonChatFabric> carbonChat
) {
super(backingManager);
this.serverHolder = serverHolder;
this.carbonChat = carbonChat;
}
@Override
protected CarbonPlayerFabric wrap(final CarbonPlayerCommon common) {
return new CarbonPlayerFabric(common, this.serverHolder, this.carbonChat);
}
}
@@ -20,6 +20,8 @@
package net.draycia.carbon.fabric.users; package net.draycia.carbon.fabric.users;
import com.google.inject.Provider; import com.google.inject.Provider;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Optional; import java.util.Optional;
@@ -48,7 +50,8 @@ public class CarbonPlayerFabric extends WrappedCarbonPlayer implements Forwardin
private final MinecraftServerHolder serverHolder; private final MinecraftServerHolder serverHolder;
private final Provider<CarbonChatFabric> carbonChatFabric; private final Provider<CarbonChatFabric> carbonChatFabric;
public CarbonPlayerFabric(final CarbonPlayerCommon carbonPlayerCommon, final MinecraftServerHolder serverHolder, final Provider<CarbonChatFabric> carbonChatFabric) { @AssistedInject
public CarbonPlayerFabric(final @Assisted CarbonPlayerCommon carbonPlayerCommon, final MinecraftServerHolder serverHolder, final Provider<CarbonChatFabric> carbonChatFabric) {
super(carbonPlayerCommon); super(carbonPlayerCommon);
this.serverHolder = serverHolder; this.serverHolder = serverHolder;
this.carbonChatFabric = carbonChatFabric; this.carbonChatFabric = carbonChatFabric;
@@ -34,6 +34,7 @@ import net.draycia.carbon.common.channels.CarbonChannelRegistry;
import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder; import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder;
import net.draycia.carbon.common.messages.CarbonMessages; import net.draycia.carbon.common.messages.CarbonMessages;
import net.draycia.carbon.common.messaging.MessagingManager; import net.draycia.carbon.common.messaging.MessagingManager;
import net.draycia.carbon.common.users.PlatformUserManager;
import net.draycia.carbon.common.users.ProfileCache; import net.draycia.carbon.common.users.ProfileCache;
import net.draycia.carbon.common.users.ProfileResolver; import net.draycia.carbon.common.users.ProfileResolver;
import net.draycia.carbon.paper.hooks.CarbonPAPIPlaceholders; import net.draycia.carbon.paper.hooks.CarbonPAPIPlaceholders;
@@ -72,7 +73,7 @@ public final class CarbonChatPaper extends CarbonChatInternal<CarbonPlayerPaper>
final CarbonChannelRegistry channelRegistry, final CarbonChannelRegistry channelRegistry,
final Provider<MessagingManager> messagingManager, final Provider<MessagingManager> messagingManager,
final CarbonServer carbonServer, final CarbonServer carbonServer,
final PaperUserManager userManager, final PlatformUserManager userManager,
@PeriodicTasks final ScheduledExecutorService periodicTasks, @PeriodicTasks final ScheduledExecutorService periodicTasks,
final ProfileCache profileCache, final ProfileCache profileCache,
final ProfileResolver profileResolver, final ProfileResolver profileResolver,
@@ -25,7 +25,6 @@ import cloud.commandframework.paper.PaperCommandManager;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Provides; import com.google.inject.Provides;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;
import com.google.inject.assistedinject.FactoryModuleBuilder; import com.google.inject.assistedinject.FactoryModuleBuilder;
import java.nio.file.Path; import java.nio.file.Path;
import net.draycia.carbon.api.CarbonChat; import net.draycia.carbon.api.CarbonChat;
@@ -38,8 +37,8 @@ import net.draycia.carbon.common.command.Commander;
import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder; import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder;
import net.draycia.carbon.common.messages.CarbonMessageRenderer; import net.draycia.carbon.common.messages.CarbonMessageRenderer;
import net.draycia.carbon.common.messages.CarbonMessages; import net.draycia.carbon.common.messages.CarbonMessages;
import net.draycia.carbon.common.users.PlatformUserManager;
import net.draycia.carbon.common.users.ProfileResolver; import net.draycia.carbon.common.users.ProfileResolver;
import net.draycia.carbon.common.users.UserManagerInternal;
import net.draycia.carbon.common.util.CloudUtils; import net.draycia.carbon.common.util.CloudUtils;
import net.draycia.carbon.paper.command.PaperCommander; import net.draycia.carbon.paper.command.PaperCommander;
import net.draycia.carbon.paper.command.PaperPlayerCommander; import net.draycia.carbon.paper.command.PaperPlayerCommander;
@@ -114,8 +113,7 @@ public final class CarbonChatPaperModule extends AbstractModule {
this.bind(CarbonServer.class).to(CarbonServerPaper.class); this.bind(CarbonServer.class).to(CarbonServerPaper.class);
this.bind(ProfileResolver.class).to(PaperProfileResolver.class); this.bind(ProfileResolver.class).to(PaperProfileResolver.class);
this.bind(PlatformScheduler.class).to(PaperScheduler.class); this.bind(PlatformScheduler.class).to(PaperScheduler.class);
this.bind(new TypeLiteral<UserManager<?>>() {}).to(PaperUserManager.class); this.install(PlatformUserManager.PlayerFactory.moduleFor(CarbonPlayerPaper.class));
this.bind(new TypeLiteral<UserManagerInternal<?>>() {}).to(PaperUserManager.class);
this.bind(CarbonMessageRenderer.class).to(PaperMessageRenderer.class); this.bind(CarbonMessageRenderer.class).to(PaperMessageRenderer.class);
this.install(new FactoryModuleBuilder().build(CarbonPlayerPaper.Factory.class)); this.install(new FactoryModuleBuilder().build(CarbonPlayerPaper.Factory.class));
} }
@@ -25,6 +25,7 @@ import java.util.List;
import java.util.Objects; import java.util.Objects;
import net.draycia.carbon.api.CarbonServer; import net.draycia.carbon.api.CarbonServer;
import net.draycia.carbon.api.users.CarbonPlayer; import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.users.UserManager;
import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.audience.ForwardingAudience; import net.kyori.adventure.audience.ForwardingAudience;
import org.bukkit.Server; import org.bukkit.Server;
@@ -36,10 +37,10 @@ import org.checkerframework.framework.qual.DefaultQualifier;
public final class CarbonServerPaper implements CarbonServer, ForwardingAudience.Single { public final class CarbonServerPaper implements CarbonServer, ForwardingAudience.Single {
private final Server server; private final Server server;
private final PaperUserManager userManager; private final UserManager<?> userManager;
@Inject @Inject
private CarbonServerPaper(final Server server, final PaperUserManager userManager) { private CarbonServerPaper(final Server server, final UserManager<?> userManager) {
this.server = server; this.server = server;
this.userManager = userManager; this.userManager = userManager;
} }
@@ -62,13 +63,4 @@ public final class CarbonServerPaper implements CarbonServer, ForwardingAudience
.toList(); .toList();
} }
public static boolean isFolia() {
try {
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
return true;
} catch (final ClassNotFoundException ignored) {
return false;
}
}
} }
@@ -1,52 +0,0 @@
/*
* CarbonChat
*
* Copyright (c) 2023 Josua Parks (Vicarious)
* Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.draycia.carbon.paper;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import net.draycia.carbon.common.users.Backing;
import net.draycia.carbon.common.users.CarbonPlayerCommon;
import net.draycia.carbon.common.users.PlatformUserManager;
import net.draycia.carbon.common.users.UserManagerInternal;
import net.draycia.carbon.paper.users.CarbonPlayerPaper;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@DefaultQualifier(NonNull.class)
@Singleton
public final class PaperUserManager extends PlatformUserManager<CarbonPlayerPaper> {
private final CarbonPlayerPaper.Factory playerFactory;
@Inject
private PaperUserManager(
final @Backing UserManagerInternal<CarbonPlayerCommon> backingManager,
final CarbonPlayerPaper.Factory playerFactory
) {
super(backingManager);
this.playerFactory = playerFactory;
}
@Override
protected CarbonPlayerPaper wrap(final CarbonPlayerCommon common) {
return this.playerFactory.wrap(common);
}
}
@@ -26,7 +26,7 @@ import net.draycia.carbon.common.config.ConfigFactory;
import net.draycia.carbon.common.messaging.MessagingManager; import net.draycia.carbon.common.messaging.MessagingManager;
import net.draycia.carbon.common.messaging.packets.PacketFactory; import net.draycia.carbon.common.messaging.packets.PacketFactory;
import net.draycia.carbon.common.users.ProfileCache; import net.draycia.carbon.common.users.ProfileCache;
import net.draycia.carbon.paper.PaperUserManager; import net.draycia.carbon.common.users.UserManagerInternal;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@@ -47,7 +47,7 @@ public class PaperPlayerJoinListener implements Listener {
private final ConfigFactory configFactory; private final ConfigFactory configFactory;
private final Logger logger; private final Logger logger;
private final ProfileCache profileCache; private final ProfileCache profileCache;
private final PaperUserManager userManager; private final UserManagerInternal<?> userManager;
private final Provider<MessagingManager> messaging; private final Provider<MessagingManager> messaging;
private final PacketFactory packetFactory; private final PacketFactory packetFactory;
@@ -56,7 +56,7 @@ public class PaperPlayerJoinListener implements Listener {
final ConfigFactory configFactory, final ConfigFactory configFactory,
final Logger logger, final Logger logger,
final ProfileCache profileCache, final ProfileCache profileCache,
final PaperUserManager userManager, final UserManagerInternal<?> userManager,
final Provider<MessagingManager> messaging, final Provider<MessagingManager> messaging,
final PacketFactory packetFactory final PacketFactory packetFactory
) { ) {
@@ -35,6 +35,7 @@ import net.draycia.carbon.common.channels.CarbonChannelRegistry;
import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder; import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder;
import net.draycia.carbon.common.messages.CarbonMessages; import net.draycia.carbon.common.messages.CarbonMessages;
import net.draycia.carbon.common.messaging.MessagingManager; import net.draycia.carbon.common.messaging.MessagingManager;
import net.draycia.carbon.common.users.PlatformUserManager;
import net.draycia.carbon.common.users.ProfileCache; import net.draycia.carbon.common.users.ProfileCache;
import net.draycia.carbon.common.users.ProfileResolver; import net.draycia.carbon.common.users.ProfileResolver;
import net.draycia.carbon.velocity.listeners.VelocityChatListener; import net.draycia.carbon.velocity.listeners.VelocityChatListener;
@@ -67,7 +68,7 @@ public class CarbonChatVelocity extends CarbonChatInternal<CarbonPlayerVelocity>
final ProfileCache profileCache, final ProfileCache profileCache,
final ProfileResolver profileResolver, final ProfileResolver profileResolver,
final ExecutionCoordinatorHolder commandExecutor, final ExecutionCoordinatorHolder commandExecutor,
final VelocityUserManager userManager, final PlatformUserManager userManager,
final CarbonServerVelocity carbonServer, final CarbonServerVelocity carbonServer,
final CarbonMessages carbonMessages, final CarbonMessages carbonMessages,
final CarbonEventHandler eventHandler, final CarbonEventHandler eventHandler,
@@ -24,7 +24,6 @@ import cloud.commandframework.velocity.VelocityCommandManager;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Provides; import com.google.inject.Provides;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;
import com.velocitypowered.api.plugin.PluginContainer; import com.velocitypowered.api.plugin.PluginContainer;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ProxyServer;
@@ -39,11 +38,12 @@ import net.draycia.carbon.common.command.Commander;
import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder; import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder;
import net.draycia.carbon.common.messages.CarbonMessageRenderer; import net.draycia.carbon.common.messages.CarbonMessageRenderer;
import net.draycia.carbon.common.messages.CarbonMessages; import net.draycia.carbon.common.messages.CarbonMessages;
import net.draycia.carbon.common.users.PlatformUserManager;
import net.draycia.carbon.common.users.ProfileResolver; import net.draycia.carbon.common.users.ProfileResolver;
import net.draycia.carbon.common.users.UserManagerInternal;
import net.draycia.carbon.common.util.CloudUtils; import net.draycia.carbon.common.util.CloudUtils;
import net.draycia.carbon.velocity.command.VelocityCommander; import net.draycia.carbon.velocity.command.VelocityCommander;
import net.draycia.carbon.velocity.command.VelocityPlayerCommander; import net.draycia.carbon.velocity.command.VelocityPlayerCommander;
import net.draycia.carbon.velocity.users.CarbonPlayerVelocity;
import net.draycia.carbon.velocity.users.VelocityProfileResolver; import net.draycia.carbon.velocity.users.VelocityProfileResolver;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@@ -106,8 +106,7 @@ public final class CarbonChatVelocityModule extends AbstractModule {
this.bind(Path.class).annotatedWith(DataDirectory.class).toInstance(this.dataDirectory); this.bind(Path.class).annotatedWith(DataDirectory.class).toInstance(this.dataDirectory);
this.bind(Logger.class).toInstance(this.logger); this.bind(Logger.class).toInstance(this.logger);
this.bind(PlatformScheduler.class).to(PlatformScheduler.RunImmediately.class); this.bind(PlatformScheduler.class).to(PlatformScheduler.RunImmediately.class);
this.bind(new TypeLiteral<UserManager<?>>() {}).to(VelocityUserManager.class); this.install(PlatformUserManager.PlayerFactory.moduleFor(CarbonPlayerVelocity.class));
this.bind(new TypeLiteral<UserManagerInternal<?>>() {}).to(VelocityUserManager.class);
this.bind(CarbonMessageRenderer.class).to(VelocityMessageRenderer.class); this.bind(CarbonMessageRenderer.class).to(VelocityMessageRenderer.class);
} }
@@ -1,50 +0,0 @@
/*
* CarbonChat
*
* Copyright (c) 2023 Josua Parks (Vicarious)
* Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.draycia.carbon.velocity;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.velocitypowered.api.proxy.ProxyServer;
import net.draycia.carbon.common.users.Backing;
import net.draycia.carbon.common.users.CarbonPlayerCommon;
import net.draycia.carbon.common.users.PlatformUserManager;
import net.draycia.carbon.common.users.UserManagerInternal;
import net.draycia.carbon.velocity.users.CarbonPlayerVelocity;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@DefaultQualifier(NonNull.class)
@Singleton
public class VelocityUserManager extends PlatformUserManager<CarbonPlayerVelocity> {
private final ProxyServer proxyServer;
@Inject
public VelocityUserManager(@Backing final UserManagerInternal<CarbonPlayerCommon> proxiedUserManager, final ProxyServer proxyServer) {
super(proxiedUserManager);
this.proxyServer = proxyServer;
}
@Override
protected CarbonPlayerVelocity wrap(final CarbonPlayerCommon common) {
return new CarbonPlayerVelocity(this.proxyServer, common);
}
}
@@ -23,8 +23,8 @@ import com.google.inject.Inject;
import com.velocitypowered.api.event.EventManager; import com.velocitypowered.api.event.EventManager;
import com.velocitypowered.api.event.EventTask; import com.velocitypowered.api.event.EventTask;
import com.velocitypowered.api.event.connection.LoginEvent; import com.velocitypowered.api.event.connection.LoginEvent;
import net.draycia.carbon.common.users.UserManagerInternal;
import net.draycia.carbon.velocity.CarbonVelocityBootstrap; import net.draycia.carbon.velocity.CarbonVelocityBootstrap;
import net.draycia.carbon.velocity.VelocityUserManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier; import org.checkerframework.framework.qual.DefaultQualifier;
@@ -34,12 +34,12 @@ import static net.draycia.carbon.common.util.PlayerUtils.joinExceptionHandler;
@DefaultQualifier(NonNull.class) @DefaultQualifier(NonNull.class)
public class VelocityPlayerJoinListener implements VelocityListener<LoginEvent> { public class VelocityPlayerJoinListener implements VelocityListener<LoginEvent> {
private final VelocityUserManager userManager; private final UserManagerInternal<?> userManager;
private final Logger logger; private final Logger logger;
@Inject @Inject
public VelocityPlayerJoinListener( public VelocityPlayerJoinListener(
final VelocityUserManager userManager, final UserManagerInternal<?> userManager,
final Logger logger final Logger logger
) { ) {
this.userManager = userManager; this.userManager = userManager;
@@ -23,8 +23,8 @@ import com.google.inject.Inject;
import com.velocitypowered.api.event.EventManager; import com.velocitypowered.api.event.EventManager;
import com.velocitypowered.api.event.EventTask; import com.velocitypowered.api.event.EventTask;
import com.velocitypowered.api.event.connection.DisconnectEvent; import com.velocitypowered.api.event.connection.DisconnectEvent;
import net.draycia.carbon.common.users.UserManagerInternal;
import net.draycia.carbon.velocity.CarbonVelocityBootstrap; import net.draycia.carbon.velocity.CarbonVelocityBootstrap;
import net.draycia.carbon.velocity.VelocityUserManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier; import org.checkerframework.framework.qual.DefaultQualifier;
@@ -34,12 +34,12 @@ import static net.draycia.carbon.common.util.PlayerUtils.saveExceptionHandler;
@DefaultQualifier(NonNull.class) @DefaultQualifier(NonNull.class)
public final class VelocityPlayerLeaveListener implements VelocityListener<DisconnectEvent> { public final class VelocityPlayerLeaveListener implements VelocityListener<DisconnectEvent> {
private final VelocityUserManager userManager; private final UserManagerInternal<?> userManager;
private final Logger logger; private final Logger logger;
@Inject @Inject
public VelocityPlayerLeaveListener( public VelocityPlayerLeaveListener(
final VelocityUserManager userManager, final UserManagerInternal<?> userManager,
final Logger logger final Logger logger
) { ) {
this.userManager = userManager; this.userManager = userManager;
@@ -19,6 +19,8 @@
*/ */
package net.draycia.carbon.velocity.users; package net.draycia.carbon.velocity.users;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ProxyServer;
import java.util.Locale; import java.util.Locale;
@@ -42,7 +44,8 @@ public final class CarbonPlayerVelocity extends WrappedCarbonPlayer implements F
private final ProxyServer server; private final ProxyServer server;
public CarbonPlayerVelocity(final ProxyServer server, final CarbonPlayerCommon carbonPlayerCommon) { @AssistedInject
private CarbonPlayerVelocity(final ProxyServer server, @Assisted final CarbonPlayerCommon carbonPlayerCommon) {
super(carbonPlayerCommon); super(carbonPlayerCommon);
this.server = server; this.server = server;
} }