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

@@ -34,6 +34,7 @@ import net.draycia.carbon.common.channels.CarbonChannelRegistry;
import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder;
import net.draycia.carbon.common.messages.CarbonMessages;
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.ProfileResolver;
import net.draycia.carbon.paper.hooks.CarbonPAPIPlaceholders;
@@ -72,7 +73,7 @@ public final class CarbonChatPaper extends CarbonChatInternal<CarbonPlayerPaper>
final CarbonChannelRegistry channelRegistry,
final Provider<MessagingManager> messagingManager,
final CarbonServer carbonServer,
final PaperUserManager userManager,
final PlatformUserManager userManager,
@PeriodicTasks final ScheduledExecutorService periodicTasks,
final ProfileCache profileCache,
final ProfileResolver profileResolver,
@@ -25,7 +25,6 @@ import cloud.commandframework.paper.PaperCommandManager;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import java.nio.file.Path;
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.messages.CarbonMessageRenderer;
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.UserManagerInternal;
import net.draycia.carbon.common.util.CloudUtils;
import net.draycia.carbon.paper.command.PaperCommander;
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(ProfileResolver.class).to(PaperProfileResolver.class);
this.bind(PlatformScheduler.class).to(PaperScheduler.class);
this.bind(new TypeLiteral<UserManager<?>>() {}).to(PaperUserManager.class);
this.bind(new TypeLiteral<UserManagerInternal<?>>() {}).to(PaperUserManager.class);
this.install(PlatformUserManager.PlayerFactory.moduleFor(CarbonPlayerPaper.class));
this.bind(CarbonMessageRenderer.class).to(PaperMessageRenderer.class);
this.install(new FactoryModuleBuilder().build(CarbonPlayerPaper.Factory.class));
}
@@ -25,6 +25,7 @@ import java.util.List;
import java.util.Objects;
import net.draycia.carbon.api.CarbonServer;
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.ForwardingAudience;
import org.bukkit.Server;
@@ -36,10 +37,10 @@ import org.checkerframework.framework.qual.DefaultQualifier;
public final class CarbonServerPaper implements CarbonServer, ForwardingAudience.Single {
private final Server server;
private final PaperUserManager userManager;
private final UserManager<?> userManager;
@Inject
private CarbonServerPaper(final Server server, final PaperUserManager userManager) {
private CarbonServerPaper(final Server server, final UserManager<?> userManager) {
this.server = server;
this.userManager = userManager;
}
@@ -62,13 +63,4 @@ public final class CarbonServerPaper implements CarbonServer, ForwardingAudience
.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.packets.PacketFactory;
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.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@@ -47,7 +47,7 @@ public class PaperPlayerJoinListener implements Listener {
private final ConfigFactory configFactory;
private final Logger logger;
private final ProfileCache profileCache;
private final PaperUserManager userManager;
private final UserManagerInternal<?> userManager;
private final Provider<MessagingManager> messaging;
private final PacketFactory packetFactory;
@@ -56,7 +56,7 @@ public class PaperPlayerJoinListener implements Listener {
final ConfigFactory configFactory,
final Logger logger,
final ProfileCache profileCache,
final PaperUserManager userManager,
final UserManagerInternal<?> userManager,
final Provider<MessagingManager> messaging,
final PacketFactory packetFactory
) {