mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 14:38:49 +00:00
more progress towards sponge module usability
This commit is contained in:
7 files changed
+80
-92
No files matched your search
@@ -2,20 +2,22 @@ package net.draycia.carbon.sponge;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.channels.ChannelRegistry;
|
||||
import net.draycia.carbon.api.events.CarbonEventHandler;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.api.util.RenderedMessage;
|
||||
import net.draycia.carbon.api.util.SourcedAudience;
|
||||
import net.draycia.carbon.common.CarbonChatCommon;
|
||||
import net.draycia.carbon.common.channels.CarbonChannelRegistry;
|
||||
import net.draycia.carbon.common.messages.CarbonMessageService;
|
||||
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||
import net.draycia.carbon.common.users.WrappedCarbonPlayer;
|
||||
import net.draycia.carbon.sponge.listeners.SpongeChatListener;
|
||||
import net.draycia.carbon.sponge.users.CarbonPlayerSponge;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.moonshine.message.IMessageRenderer;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -34,7 +36,7 @@ import org.spongepowered.plugin.builtin.jvm.Plugin;
|
||||
|
||||
@Plugin("carbonchat")
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class CarbonChatSponge extends CarbonChatCommon {
|
||||
public final class CarbonChatSponge implements CarbonChat {
|
||||
|
||||
private static final Set<Class<?>> LISTENER_CLASSES = Set.of(
|
||||
SpongeChatListener.class
|
||||
@@ -48,7 +50,7 @@ public final class CarbonChatSponge extends CarbonChatCommon {
|
||||
private final Logger logger;
|
||||
private final Path dataDirectory;
|
||||
private final PluginContainer pluginContainer;
|
||||
private final UserManager<CarbonPlayerSponge> userManager;
|
||||
private final UserManager<CarbonPlayerCommon> userManager;
|
||||
private final CarbonEventHandler eventHandler = new CarbonEventHandler();
|
||||
private final IMessageRenderer<SourcedAudience, String, RenderedMessage, Component> messageRenderer;
|
||||
|
||||
@@ -65,14 +67,12 @@ public final class CarbonChatSponge extends CarbonChatCommon {
|
||||
|
||||
this.pluginContainer = pluginContainer;
|
||||
|
||||
this.injector = injector.createChildInjector(new CarbonChatSpongeModule(
|
||||
this, dataDirectory, pluginContainer));
|
||||
|
||||
this.injector = injector.createChildInjector(new CarbonChatSpongeModule(this, dataDirectory, pluginContainer));
|
||||
this.logger = logger;
|
||||
this.messageService = this.injector.getInstance(CarbonMessageService.class);
|
||||
this.channelRegistry = this.injector.getInstance(ChannelRegistry.class);
|
||||
this.carbonServerSponge = this.injector.getInstance(CarbonServerSponge.class);
|
||||
this.userManager = this.injector.getInstance(UserManager.class);
|
||||
this.userManager = this.injector.getInstance(com.google.inject.Key.get(new TypeLiteral<UserManager<CarbonPlayerCommon>>() {}));
|
||||
this.messageRenderer = this.injector.getInstance(SpongeMessageRenderer.class);
|
||||
this.dataDirectory = dataDirectory;
|
||||
|
||||
@@ -80,8 +80,6 @@ public final class CarbonChatSponge extends CarbonChatCommon {
|
||||
game.eventManager().registerListeners(this.pluginContainer, this.injector.getInstance(clazz));
|
||||
}
|
||||
//metricsFactory.make(BSTATS_PLUGIN_ID);
|
||||
|
||||
this.initialize(this.injector);
|
||||
}
|
||||
|
||||
@Listener
|
||||
@@ -102,7 +100,7 @@ public final class CarbonChatSponge extends CarbonChatCommon {
|
||||
|
||||
private void savePlayers() {
|
||||
for (final var player : this.server().players()) {
|
||||
this.userManager().savePlayer(player).thenAccept(result -> {
|
||||
this.userManager().savePlayer(((WrappedCarbonPlayer) player).carbonPlayerCommon()).thenAccept(result -> {
|
||||
if (result.player() == null) {
|
||||
this.server().console().sendMessage(result.reason());
|
||||
}
|
||||
@@ -110,7 +108,7 @@ public final class CarbonChatSponge extends CarbonChatCommon {
|
||||
}
|
||||
}
|
||||
|
||||
public UserManager<CarbonPlayerSponge> userManager() {
|
||||
public UserManager<CarbonPlayerCommon> userManager() {
|
||||
return this.userManager;
|
||||
}
|
||||
|
||||
@@ -144,7 +142,7 @@ public final class CarbonChatSponge extends CarbonChatCommon {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final @NonNull CarbonEventHandler eventHandler() {
|
||||
public @NonNull CarbonEventHandler eventHandler() {
|
||||
return this.eventHandler;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import net.draycia.carbon.api.CarbonServer;
|
||||
import net.draycia.carbon.common.CarbonCommonModule;
|
||||
import net.draycia.carbon.common.ForCarbon;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.util.CloudUtils;
|
||||
import net.draycia.carbon.sponge.command.SpongeCommander;
|
||||
import net.draycia.carbon.sponge.command.SpongePlayerCommander;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
@@ -22,16 +23,16 @@ import org.spongepowered.plugin.PluginContainer;
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class CarbonChatSpongeModule extends AbstractModule {
|
||||
|
||||
private final CarbonChatSponge carbonChatSponge;
|
||||
private final CarbonChatSponge carbonChat;
|
||||
private final Path configDir;
|
||||
private final PluginContainer pluginContainer;
|
||||
|
||||
public CarbonChatSpongeModule(
|
||||
final CarbonChatSponge carbonChatSponge,
|
||||
final CarbonChatSponge carbonChat,
|
||||
final Path configDir,
|
||||
final PluginContainer pluginContainer
|
||||
) {
|
||||
this.carbonChatSponge = carbonChatSponge;
|
||||
this.carbonChat = carbonChat;
|
||||
this.configDir = configDir;
|
||||
this.pluginContainer = pluginContainer;
|
||||
}
|
||||
@@ -45,13 +46,15 @@ public final class CarbonChatSpongeModule extends AbstractModule {
|
||||
commander -> ((SpongeCommander) commander).commandCause(),
|
||||
commandCause -> {
|
||||
if (commandCause.subject() instanceof ServerPlayer player) {
|
||||
return new SpongePlayerCommander(this.carbonChatSponge, player, commandCause);
|
||||
return new SpongePlayerCommander(this.carbonChat, player, commandCause);
|
||||
}
|
||||
|
||||
return SpongeCommander.from(commandCause);
|
||||
}
|
||||
);
|
||||
|
||||
CloudUtils.decorateCommandManager(commandManager, this.carbonChat.messageService());
|
||||
|
||||
commandManager.parserMapper().cloudNumberSuggestions(true);
|
||||
|
||||
return commandManager;
|
||||
@@ -62,7 +65,7 @@ public final class CarbonChatSpongeModule extends AbstractModule {
|
||||
this.install(new CarbonCommonModule());
|
||||
|
||||
this.bind(Path.class).annotatedWith(ForCarbon.class).toInstance(this.configDir);
|
||||
this.bind(CarbonChat.class).toInstance(this.carbonChatSponge);
|
||||
this.bind(CarbonChat.class).toInstance(this.carbonChat);
|
||||
this.bind(CarbonServer.class).to(CarbonServerSponge.class);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user