mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 06:28:53 +00:00
bump fabric to 1.19.4 and change server instance handling
This commit is contained in:
16 files changed
+137
-131
No files matched your search
@@ -27,15 +27,15 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
|||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
public abstract class PlatformUserManager<C extends WrappedCarbonPlayer> implements UserManagerInternal<C> {
|
public abstract class PlatformUserManager<C extends WrappedCarbonPlayer> implements UserManagerInternal<C> {
|
||||||
|
|
||||||
private final UserManagerInternal<CarbonPlayerCommon> wrapped;
|
private final UserManagerInternal<CarbonPlayerCommon> backingManager;
|
||||||
|
|
||||||
public PlatformUserManager(final UserManagerInternal<CarbonPlayerCommon> wrapped) {
|
public PlatformUserManager(final UserManagerInternal<CarbonPlayerCommon> backingManager) {
|
||||||
this.wrapped = wrapped;
|
this.backingManager = backingManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<C> user(final UUID uuid) {
|
public CompletableFuture<C> user(final UUID uuid) {
|
||||||
return this.wrapped.user(uuid).thenApply(common -> {
|
return this.backingManager.user(uuid).thenApply(common -> {
|
||||||
final C wrapped = this.wrap(common);
|
final C wrapped = this.wrap(common);
|
||||||
this.updateTransientLoadedStatus(wrapped);
|
this.updateTransientLoadedStatus(wrapped);
|
||||||
return wrapped;
|
return wrapped;
|
||||||
@@ -48,21 +48,22 @@ public abstract class PlatformUserManager<C extends WrappedCarbonPlayer> impleme
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
this.wrapped.shutdown();
|
this.backingManager.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Void> save(final C player) {
|
public CompletableFuture<Void> save(final C player) {
|
||||||
return this.wrapped.save(player.carbonPlayerCommon());
|
return this.backingManager.save(player.carbonPlayerCommon());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Void> loggedOut(final UUID uuid) {
|
public CompletableFuture<Void> loggedOut(final UUID uuid) {
|
||||||
return this.wrapped.loggedOut(uuid);
|
return this.backingManager.loggedOut(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cleanup() {
|
public void cleanup() {
|
||||||
this.wrapped.cleanup();
|
this.backingManager.cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -15,8 +15,8 @@ dependencies {
|
|||||||
minecraft(libs.fabricMinecraft)
|
minecraft(libs.fabricMinecraft)
|
||||||
mappings(loom.officialMojangMappings())
|
mappings(loom.officialMojangMappings())
|
||||||
modImplementation(libs.fabricLoader)
|
modImplementation(libs.fabricLoader)
|
||||||
modImplementation("net.fabricmc.fabric-api:fabric-api:0.69.1+1.19.3")
|
modImplementation("net.fabricmc.fabric-api:fabric-api:0.76.0+1.19.4")
|
||||||
modImplementation("net.fabricmc.fabric-api:fabric-api-deprecated:0.69.1+1.19.3") // LuckPerms needs to work at dev time
|
modImplementation("net.fabricmc.fabric-api:fabric-api-deprecated:0.76.0+1.19.4") // LuckPerms needs to work at dev time
|
||||||
|
|
||||||
carbon(projects.carbonchatCommon) {
|
carbon(projects.carbonchatCommon) {
|
||||||
exclude("net.kyori", "adventure-api")
|
exclude("net.kyori", "adventure-api")
|
||||||
|
|||||||
@@ -36,13 +36,11 @@ 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.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.fabric.callback.ChatCallback;
|
import net.draycia.carbon.fabric.callback.ChatCallback;
|
||||||
import net.draycia.carbon.fabric.command.DeleteMessageCommand;
|
import net.draycia.carbon.fabric.command.DeleteMessageCommand;
|
||||||
import net.draycia.carbon.fabric.listeners.FabricChatListener;
|
import net.draycia.carbon.fabric.listeners.FabricChatListener;
|
||||||
import net.draycia.carbon.fabric.listeners.FabricChatPreviewListener;
|
import net.draycia.carbon.fabric.listeners.FabricChatPreviewListener;
|
||||||
import net.draycia.carbon.fabric.listeners.FabricPlayerJoinListener;
|
import net.draycia.carbon.fabric.listeners.FabricJoinQuitListener;
|
||||||
import net.draycia.carbon.fabric.listeners.FabricPlayerLeaveListener;
|
|
||||||
import net.draycia.carbon.fabric.users.CarbonPlayerFabric;
|
import net.draycia.carbon.fabric.users.CarbonPlayerFabric;
|
||||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||||
import net.fabricmc.fabric.api.message.v1.ServerMessageDecoratorEvent;
|
import net.fabricmc.fabric.api.message.v1.ServerMessageDecoratorEvent;
|
||||||
@@ -55,20 +53,14 @@ import net.minecraft.core.registries.Registries;
|
|||||||
import net.minecraft.network.chat.ChatType;
|
import net.minecraft.network.chat.ChatType;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
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.checker.nullness.qual.Nullable;
|
|
||||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
import static java.util.Objects.requireNonNull;
|
|
||||||
|
|
||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
@Singleton
|
@Singleton
|
||||||
public final class CarbonChatFabric extends CarbonChatInternal<CarbonPlayerFabric> {
|
public final class CarbonChatFabric extends CarbonChatInternal<CarbonPlayerFabric> {
|
||||||
|
|
||||||
private @Nullable MinecraftServer minecraftServer;
|
|
||||||
|
|
||||||
public static ResourceKey<ChatType> CHAT_TYPE = ResourceKey.create(Registries.CHAT_TYPE, new ResourceLocation("carbon", "chat"));
|
public static ResourceKey<ChatType> CHAT_TYPE = ResourceKey.create(Registries.CHAT_TYPE, new ResourceLocation("carbon", "chat"));
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -79,7 +71,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 UserManagerInternal<CarbonPlayerFabric> userManager,
|
final FabricUserManager userManager,
|
||||||
final ExecutionCoordinatorHolder commandExecutor,
|
final ExecutionCoordinatorHolder commandExecutor,
|
||||||
final CarbonServer carbonServer,
|
final CarbonServer carbonServer,
|
||||||
final CarbonMessages carbonMessages,
|
final CarbonMessages carbonMessages,
|
||||||
@@ -124,20 +116,13 @@ public final class CarbonChatFabric extends CarbonChatInternal<CarbonPlayerFabri
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void registerServerLifecycleListeners() {
|
private void registerServerLifecycleListeners() {
|
||||||
ServerLifecycleEvents.SERVER_STARTING.register(server -> this.minecraftServer = server);
|
ServerLifecycleEvents.SERVER_STOPPED.register(server -> this.shutdown());
|
||||||
ServerLifecycleEvents.SERVER_STOPPED.register(server -> {
|
|
||||||
this.shutdown();
|
|
||||||
this.minecraftServer = null;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerPlayerStatusListeners() {
|
private void registerPlayerStatusListeners() {
|
||||||
ServerPlayConnectionEvents.DISCONNECT.register(this.injector().getInstance(FabricPlayerLeaveListener.class));
|
final FabricJoinQuitListener listener = this.injector().getInstance(FabricJoinQuitListener.class);
|
||||||
ServerPlayConnectionEvents.JOIN.register(this.injector().getInstance(FabricPlayerJoinListener.class));
|
ServerPlayConnectionEvents.DISCONNECT.register(listener);
|
||||||
}
|
ServerPlayConnectionEvents.JOIN.register(listener);
|
||||||
|
|
||||||
public MinecraftServer minecraftServer() {
|
|
||||||
return requireNonNull(this.minecraftServer, "Attempted to get the MinecraftServer instance when one is not active.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean luckPermsLoaded() {
|
public boolean luckPermsLoaded() {
|
||||||
|
|||||||
@@ -106,8 +106,8 @@ public final class CarbonChatFabricModule extends AbstractModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
public PlayerSuggestions playerSuggestions(final Provider<CarbonChatFabric> carbon) {
|
public PlayerSuggestions playerSuggestions(final MinecraftServerHolder serverHolder) {
|
||||||
return (ctx, input) -> carbon.get().minecraftServer().getPlayerList().getPlayers().stream()
|
return (ctx, input) -> serverHolder.requireServer().getPlayerList().getPlayers().stream()
|
||||||
.map(player -> player.getGameProfile().getName())
|
.map(player -> player.getGameProfile().getName())
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,28 +38,28 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
public final class CarbonServerFabric implements CarbonServer, ForwardingAudience.Single {
|
public final class CarbonServerFabric implements CarbonServer, ForwardingAudience.Single {
|
||||||
|
|
||||||
private final CarbonChatFabric carbonChatFabric;
|
private final MinecraftServerHolder serverHolder;
|
||||||
private final FabricUserManager userManager;
|
private final FabricUserManager userManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private CarbonServerFabric(final CarbonChatFabric carbonChatFabric, final FabricUserManager userManager) {
|
private CarbonServerFabric(final MinecraftServerHolder serverHolder, final FabricUserManager userManager) {
|
||||||
this.carbonChatFabric = carbonChatFabric;
|
this.serverHolder = serverHolder;
|
||||||
this.userManager = userManager;
|
this.userManager = userManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Audience audience() {
|
public @NotNull Audience audience() {
|
||||||
return FabricServerAudiences.of(this.carbonChatFabric.minecraftServer()).all();
|
return FabricServerAudiences.of(this.serverHolder.requireServer()).all();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Audience console() {
|
public Audience console() {
|
||||||
return this.carbonChatFabric.minecraftServer().createCommandSourceStack();
|
return this.serverHolder.requireServer().createCommandSourceStack();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<? extends CarbonPlayer> players() {
|
public List<? extends CarbonPlayer> players() {
|
||||||
return this.carbonChatFabric.minecraftServer().getPlayerList().getPlayers().stream()
|
return this.serverHolder.requireServer().getPlayerList().getPlayers().stream()
|
||||||
.map(serverPlayer -> this.userManager.user(serverPlayer.getUUID()).getNow(null))
|
.map(serverPlayer -> this.userManager.user(serverPlayer.getUUID()).getNow(null))
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.toList();
|
.toList();
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
package net.draycia.carbon.fabric;
|
package net.draycia.carbon.fabric;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Provider;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
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;
|
||||||
@@ -33,17 +34,23 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
|||||||
@Singleton
|
@Singleton
|
||||||
public final class FabricUserManager extends PlatformUserManager<CarbonPlayerFabric> {
|
public final class FabricUserManager extends PlatformUserManager<CarbonPlayerFabric> {
|
||||||
|
|
||||||
private final CarbonChatFabric carbonChatFabric;
|
private final MinecraftServerHolder serverHolder;
|
||||||
|
private final Provider<CarbonChatFabric> carbonChat;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private FabricUserManager(final @Backing UserManagerInternal<CarbonPlayerCommon> proxiedUserManager, final CarbonChatFabric carbonChatFabric) {
|
private FabricUserManager(
|
||||||
super(proxiedUserManager);
|
final @Backing UserManagerInternal<CarbonPlayerCommon> backingManager,
|
||||||
this.carbonChatFabric = carbonChatFabric;
|
final MinecraftServerHolder serverHolder,
|
||||||
|
final Provider<CarbonChatFabric> carbonChat
|
||||||
|
) {
|
||||||
|
super(backingManager);
|
||||||
|
this.serverHolder = serverHolder;
|
||||||
|
this.carbonChat = carbonChat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CarbonPlayerFabric wrap(final CarbonPlayerCommon common) {
|
protected CarbonPlayerFabric wrap(final CarbonPlayerCommon common) {
|
||||||
return new CarbonPlayerFabric(common, this.carbonChatFabric);
|
return new CarbonPlayerFabric(common, this.serverHolder, this.carbonChat);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* 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 java.util.Objects;
|
||||||
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
|
@DefaultQualifier(NonNull.class)
|
||||||
|
public final class MinecraftServerHolder {
|
||||||
|
|
||||||
|
private @Nullable MinecraftServer server;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private MinecraftServerHolder() {
|
||||||
|
ServerLifecycleEvents.SERVER_STARTING.register(server -> this.server = server);
|
||||||
|
ServerLifecycleEvents.SERVER_STOPPED.register(server -> this.server = null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MinecraftServer requireServer() {
|
||||||
|
return Objects.requireNonNull(this.server, "server requested when not active");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -26,6 +26,7 @@ import java.util.concurrent.ExecutorService;
|
|||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import net.draycia.carbon.common.util.ConcurrentUtil;
|
||||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.kyori.adventure.audience.MessageType;
|
import net.kyori.adventure.audience.MessageType;
|
||||||
@@ -33,7 +34,6 @@ import net.kyori.adventure.identity.Identity;
|
|||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.util.thread.NamedThreadFactory;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
@@ -54,8 +54,8 @@ public enum ChatCallback {
|
|||||||
private @Nullable ExecutorService chatExecutor;
|
private @Nullable ExecutorService chatExecutor;
|
||||||
private final List<Consumer<Chat>> listeners = new CopyOnWriteArrayList<>();
|
private final List<Consumer<Chat>> listeners = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
private void initExecutor() {
|
private void initExecutor(final Logger logger) {
|
||||||
this.chatExecutor = Executors.newSingleThreadExecutor(new NamedThreadFactory("CarbonChat-Chat-Thread"));
|
this.chatExecutor = Executors.newSingleThreadExecutor(ConcurrentUtil.carbonThreadFactory(logger, "Chat Handling"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void shutdownExecutor() {
|
private void shutdownExecutor() {
|
||||||
@@ -114,7 +114,7 @@ public enum ChatCallback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setup() {
|
public static void setup() {
|
||||||
ServerLifecycleEvents.SERVER_STARTING.register(server -> INSTANCE.initExecutor());
|
ServerLifecycleEvents.SERVER_STARTING.register(server -> INSTANCE.initExecutor(LOGGER));
|
||||||
ServerLifecycleEvents.SERVER_STOPPED.register(server -> INSTANCE.shutdownExecutor());
|
ServerLifecycleEvents.SERVER_STOPPED.register(server -> INSTANCE.shutdownExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+22
-4
@@ -23,25 +23,36 @@ import com.google.inject.Inject;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.draycia.carbon.common.config.ConfigFactory;
|
import net.draycia.carbon.common.config.ConfigFactory;
|
||||||
import net.draycia.carbon.common.users.ProfileCache;
|
import net.draycia.carbon.common.users.ProfileCache;
|
||||||
|
import net.draycia.carbon.common.users.UserManagerInternal;
|
||||||
import net.fabricmc.fabric.api.networking.v1.PacketSender;
|
import net.fabricmc.fabric.api.networking.v1.PacketSender;
|
||||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||||
import net.minecraft.network.protocol.game.ClientboundCustomChatCompletionsPacket;
|
import net.minecraft.network.protocol.game.ClientboundCustomChatCompletionsPacket;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
public class FabricPlayerJoinListener implements ServerPlayConnectionEvents.Join {
|
public class FabricJoinQuitListener implements ServerPlayConnectionEvents.Join, ServerPlayConnectionEvents.Disconnect {
|
||||||
|
|
||||||
private final ProfileCache profileCache;
|
private final ProfileCache profileCache;
|
||||||
|
private final Logger logger;
|
||||||
private final ConfigFactory configFactory;
|
private final ConfigFactory configFactory;
|
||||||
|
private final UserManagerInternal<?> userManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public FabricPlayerJoinListener(final ConfigFactory configFactory, final ProfileCache profileCache) {
|
public FabricJoinQuitListener(
|
||||||
|
final Logger logger,
|
||||||
|
final ConfigFactory configFactory,
|
||||||
|
final ProfileCache profileCache,
|
||||||
|
final UserManagerInternal<?> userManager
|
||||||
|
) {
|
||||||
|
this.logger = logger;
|
||||||
this.configFactory = configFactory;
|
this.configFactory = configFactory;
|
||||||
this.profileCache = profileCache;
|
this.profileCache = profileCache;
|
||||||
|
this.userManager = userManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -54,8 +65,15 @@ public class FabricPlayerJoinListener implements ServerPlayConnectionEvents.Join
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendPacket(new ClientboundCustomChatCompletionsPacket(ClientboundCustomChatCompletionsPacket.Action.SET,
|
sender.sendPacket(new ClientboundCustomChatCompletionsPacket(ClientboundCustomChatCompletionsPacket.Action.SET, suggestions));
|
||||||
suggestions));
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlayDisconnect(final ServerGamePacketListenerImpl handler, final MinecraftServer server) {
|
||||||
|
this.userManager.loggedOut(handler.getPlayer().getGameProfile().getId()).exceptionally(thr -> {
|
||||||
|
this.logger.warn("Exception saving data for player " + handler.getPlayer().getGameProfile().getName() + " with uuid " + handler.getPlayer().getGameProfile().getId());
|
||||||
|
return null;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
-54
@@ -1,54 +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.listeners;
|
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
|
||||||
import net.draycia.carbon.fabric.FabricUserManager;
|
|
||||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
||||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
|
||||||
|
|
||||||
@DefaultQualifier(NonNull.class)
|
|
||||||
public class FabricPlayerLeaveListener implements ServerPlayConnectionEvents.Disconnect {
|
|
||||||
|
|
||||||
private final FabricUserManager userManager;
|
|
||||||
private final Logger logger;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public FabricPlayerLeaveListener(
|
|
||||||
final Logger logger,
|
|
||||||
final FabricUserManager userManager
|
|
||||||
) {
|
|
||||||
this.logger = logger;
|
|
||||||
this.userManager = userManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPlayDisconnect(final ServerGamePacketListenerImpl handler, final MinecraftServer server) {
|
|
||||||
this.userManager.loggedOut(handler.getPlayer().getGameProfile().getId()).exceptionally(thr -> {
|
|
||||||
this.logger.warn("Exception saving data for player " + handler.getPlayer().getGameProfile().getName() + " with uuid " + handler.getPlayer().getGameProfile().getId());
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
package net.draycia.carbon.fabric.users;
|
package net.draycia.carbon.fabric.users;
|
||||||
|
|
||||||
|
import com.google.inject.Provider;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@@ -30,6 +31,7 @@ import net.draycia.carbon.api.util.InventorySlot;
|
|||||||
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||||
import net.draycia.carbon.common.users.WrappedCarbonPlayer;
|
import net.draycia.carbon.common.users.WrappedCarbonPlayer;
|
||||||
import net.draycia.carbon.fabric.CarbonChatFabric;
|
import net.draycia.carbon.fabric.CarbonChatFabric;
|
||||||
|
import net.draycia.carbon.fabric.MinecraftServerHolder;
|
||||||
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.identity.Identity;
|
import net.kyori.adventure.identity.Identity;
|
||||||
@@ -46,10 +48,12 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
|||||||
public class CarbonPlayerFabric extends WrappedCarbonPlayer implements ForwardingAudience.Single {
|
public class CarbonPlayerFabric extends WrappedCarbonPlayer implements ForwardingAudience.Single {
|
||||||
|
|
||||||
private final CarbonPlayerCommon carbonPlayerCommon;
|
private final CarbonPlayerCommon carbonPlayerCommon;
|
||||||
private final CarbonChatFabric carbonChatFabric;
|
private final MinecraftServerHolder serverHolder;
|
||||||
|
private final Provider<CarbonChatFabric> carbonChatFabric;
|
||||||
|
|
||||||
public CarbonPlayerFabric(final CarbonPlayerCommon carbonPlayerCommon, final CarbonChatFabric carbonChatFabric) {
|
public CarbonPlayerFabric(final CarbonPlayerCommon carbonPlayerCommon, final MinecraftServerHolder serverHolder, final Provider<CarbonChatFabric> carbonChatFabric) {
|
||||||
this.carbonPlayerCommon = carbonPlayerCommon;
|
this.carbonPlayerCommon = carbonPlayerCommon;
|
||||||
|
this.serverHolder = serverHolder;
|
||||||
this.carbonChatFabric = carbonChatFabric;
|
this.carbonChatFabric = carbonChatFabric;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +64,7 @@ public class CarbonPlayerFabric extends WrappedCarbonPlayer implements Forwardin
|
|||||||
|
|
||||||
public Optional<ServerPlayer> player() {
|
public Optional<ServerPlayer> player() {
|
||||||
return Optional.ofNullable(
|
return Optional.ofNullable(
|
||||||
this.carbonChatFabric.minecraftServer().getPlayerList()
|
this.serverHolder.requireServer().getPlayerList()
|
||||||
.getPlayer(this.carbonPlayerCommon.uuid())
|
.getPlayer(this.carbonPlayerCommon.uuid())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -109,7 +113,7 @@ public class CarbonPlayerFabric extends WrappedCarbonPlayer implements Forwardin
|
|||||||
}
|
}
|
||||||
|
|
||||||
final @Nullable ServerPlayer player = this.player().orElse(null);
|
final @Nullable ServerPlayer player = this.player().orElse(null);
|
||||||
final @Nullable ServerPlayer otherPlayer = this.carbonChatFabric.minecraftServer()
|
final @Nullable ServerPlayer otherPlayer = this.serverHolder.requireServer()
|
||||||
.getPlayerList().getPlayer(other.uuid());
|
.getPlayerList().getPlayer(other.uuid());
|
||||||
|
|
||||||
if (player == null || otherPlayer == null) {
|
if (player == null || otherPlayer == null) {
|
||||||
@@ -130,7 +134,7 @@ public class CarbonPlayerFabric extends WrappedCarbonPlayer implements Forwardin
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Optional<ServerPlayer> player = this.player();
|
final Optional<ServerPlayer> player = this.player();
|
||||||
final @Nullable ServerPlayer otherPlayer = this.carbonChatFabric.minecraftServer()
|
final @Nullable ServerPlayer otherPlayer = this.serverHolder.requireServer()
|
||||||
.getPlayerList().getPlayer(other.uuid());
|
.getPlayerList().getPlayer(other.uuid());
|
||||||
|
|
||||||
if (player.isEmpty() || otherPlayer == null) {
|
if (player.isEmpty() || otherPlayer == null) {
|
||||||
@@ -184,7 +188,7 @@ public class CarbonPlayerFabric extends WrappedCarbonPlayer implements Forwardin
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String primaryGroup() {
|
public String primaryGroup() {
|
||||||
if (!this.carbonChatFabric.luckPermsLoaded()) {
|
if (!this.carbonChatFabric.get().luckPermsLoaded()) {
|
||||||
return "default";
|
return "default";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,7 +197,7 @@ public class CarbonPlayerFabric extends WrappedCarbonPlayer implements Forwardin
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> groups() {
|
public List<String> groups() {
|
||||||
if (!this.carbonChatFabric.luckPermsLoaded()) {
|
if (!this.carbonChatFabric.get().luckPermsLoaded()) {
|
||||||
return List.of("default");
|
return List.of("default");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import java.util.UUID;
|
|||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import net.draycia.carbon.common.users.MojangProfileResolver;
|
import net.draycia.carbon.common.users.MojangProfileResolver;
|
||||||
import net.draycia.carbon.common.users.ProfileResolver;
|
import net.draycia.carbon.common.users.ProfileResolver;
|
||||||
import net.draycia.carbon.fabric.CarbonChatFabric;
|
import net.draycia.carbon.fabric.MinecraftServerHolder;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
@@ -35,18 +35,18 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
|||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
public final class FabricProfileResolver implements ProfileResolver {
|
public final class FabricProfileResolver implements ProfileResolver {
|
||||||
|
|
||||||
private final CarbonChatFabric carbonChatFabric;
|
private final MinecraftServerHolder serverHolder;
|
||||||
private final ProfileResolver mojang;
|
private final ProfileResolver mojang;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private FabricProfileResolver(final CarbonChatFabric carbonChatFabric, final MojangProfileResolver mojang) {
|
private FabricProfileResolver(final MinecraftServerHolder serverHolder, final MojangProfileResolver mojang) {
|
||||||
this.carbonChatFabric = carbonChatFabric;
|
this.serverHolder = serverHolder;
|
||||||
this.mojang = mojang;
|
this.mojang = mojang;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<@Nullable UUID> resolveUUID(final String username, final boolean cacheOnly) {
|
public CompletableFuture<@Nullable UUID> resolveUUID(final String username, final boolean cacheOnly) {
|
||||||
final @Nullable ServerPlayer online = this.carbonChatFabric.minecraftServer().getPlayerList().getPlayerByName(username);
|
final @Nullable ServerPlayer online = this.serverHolder.requireServer().getPlayerList().getPlayerByName(username);
|
||||||
if (online != null) {
|
if (online != null) {
|
||||||
return CompletableFuture.completedFuture(online.getUUID());
|
return CompletableFuture.completedFuture(online.getUUID());
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ public final class FabricProfileResolver implements ProfileResolver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<@Nullable String> resolveName(final UUID uuid, final boolean cacheOnly) {
|
public CompletableFuture<@Nullable String> resolveName(final UUID uuid, final boolean cacheOnly) {
|
||||||
final @Nullable ServerPlayer online = this.carbonChatFabric.minecraftServer().getPlayerList().getPlayer(uuid);
|
final @Nullable ServerPlayer online = this.serverHolder.requireServer().getPlayerList().getPlayer(uuid);
|
||||||
if (online != null) {
|
if (online != null) {
|
||||||
return CompletableFuture.completedFuture(online.getGameProfile().getName());
|
return CompletableFuture.completedFuture(online.getGameProfile().getName());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,18 +12,18 @@ plugins:
|
|||||||
versions:
|
versions:
|
||||||
indra: 3.0.1
|
indra: 3.0.1
|
||||||
licenser: 0.6.1
|
licenser: 0.6.1
|
||||||
shadow: 7.1.2
|
shadow: 8.1.0
|
||||||
adventure: 4.12.0
|
adventure: 4.13.0
|
||||||
cloud: 1.8.0
|
cloud: 1.8.3
|
||||||
cloudSponge: 1.8.0-SNAPSHOT
|
cloudSponge: 1.8.0-SNAPSHOT
|
||||||
configurate: 4.1.2
|
configurate: 4.1.2
|
||||||
typesafeConfig: 1.4.1
|
typesafeConfig: 1.4.1
|
||||||
checkerQual: 3.28.0
|
checkerQual: 3.32.0
|
||||||
stylecheck: 0.1
|
stylecheck: 0.1
|
||||||
gson: 2.10
|
gson: 2.10
|
||||||
guava: 30.1-jre
|
guava: 30.1-jre
|
||||||
bstats: 3.0.0
|
bstats: 3.0.0
|
||||||
paperApi: 1.19.3-R0.1-SNAPSHOT
|
paperApi: 1.19.4-R0.1-SNAPSHOT
|
||||||
paperLib: 1.0.8-SNAPSHOT
|
paperLib: 1.0.8-SNAPSHOT
|
||||||
kyoriEventApi: 5.0.0-SNAPSHOT
|
kyoriEventApi: 5.0.0-SNAPSHOT
|
||||||
kyoriRegistry: 1.0.0-SNAPSHOT
|
kyoriRegistry: 1.0.0-SNAPSHOT
|
||||||
@@ -32,9 +32,9 @@ versions:
|
|||||||
guice: 5.1.0
|
guice: 5.1.0
|
||||||
velocityApi: 3.1.1
|
velocityApi: 3.1.1
|
||||||
geantyref: 1.3.11
|
geantyref: 1.3.11
|
||||||
fabricMinecraft: 1.19.3
|
fabricMinecraft: 1.19.4
|
||||||
fabricLoader: 0.14.12
|
fabricLoader: 0.14.17
|
||||||
adventurePlatformFabric: 5.6.1
|
adventurePlatformFabric: 5.8.0
|
||||||
luckPermsApi: 5.3
|
luckPermsApi: 5.3
|
||||||
essentialsx: 2.19.3
|
essentialsx: 2.19.3
|
||||||
discordsrv: 1.26.0
|
discordsrv: 1.26.0
|
||||||
@@ -301,7 +301,7 @@ dependencies:
|
|||||||
name: indra-licenser-cadix
|
name: indra-licenser-cadix
|
||||||
version: { ref: indra }
|
version: { ref: indra }
|
||||||
shadow:
|
shadow:
|
||||||
group: gradle.plugin.com.github.johnrengelman
|
group: com.github.johnrengelman
|
||||||
name: shadow
|
name: shadow
|
||||||
version: { ref: shadow }
|
version: { ref: shadow }
|
||||||
licenser:
|
licenser:
|
||||||
|
|||||||
Vendored
BIN
Binary file not shown.
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
@@ -34,8 +34,8 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
|||||||
public final class PaperUserManager extends PlatformUserManager<CarbonPlayerPaper> {
|
public final class PaperUserManager extends PlatformUserManager<CarbonPlayerPaper> {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private PaperUserManager(final @Backing UserManagerInternal<CarbonPlayerCommon> proxiedUserManager) {
|
private PaperUserManager(final @Backing UserManagerInternal<CarbonPlayerCommon> backingManager) {
|
||||||
super(proxiedUserManager);
|
super(backingManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in new issue
Block a user