Add config option to control chat suggestions on fabric

This commit is contained in:
Draycia committed 2022-07-09 20:10:01 -07:00
1 parent e00adf644f
commit 12c2c3c7a1
5 files changed
+74 -11

No files matched your search

@@ -41,6 +41,7 @@ import net.draycia.carbon.common.util.ListenerUtils;
import net.draycia.carbon.common.util.PlayerUtils;
import net.draycia.carbon.fabric.callback.ChatCallback;
import net.draycia.carbon.fabric.listeners.FabricChatListener;
import net.draycia.carbon.fabric.listeners.FabricPlayerJoinListener;
import net.draycia.carbon.fabric.listeners.FabricPlayerLeaveListener;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
@@ -126,6 +127,7 @@ public final class CarbonChatFabric implements ModInitializer, CarbonChat {
private void registerPlayerStatusListeners() {
ServerPlayConnectionEvents.DISCONNECT.register(this.injector.getInstance(FabricPlayerLeaveListener.class));
ServerPlayConnectionEvents.JOIN.register(this.injector.getInstance(FabricPlayerJoinListener.class));
}
private void registerTickListeners() {
@@ -69,12 +69,7 @@ public final class CarbonChatFabricModule extends AbstractModule {
public CommandManager<Commander> commandManager() {
final FabricServerCommandManager<Commander> commandManager = new FabricServerCommandManager<>(
AsynchronousCommandExecutionCoordinator.<Commander>newBuilder().build(),
commandSourceStack -> {
if (commandSourceStack.getEntity() instanceof ServerPlayer) {
return new FabricPlayerCommander(this.carbonChat, commandSourceStack);
}
return FabricCommander.from(commandSourceStack);
},
FabricCommander::from,
commander -> ((FabricCommander) commander).commandSourceStack()
);
@@ -0,0 +1,57 @@
/*
* CarbonChat
*
* Copyright (c) 2021 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 java.util.List;
import net.draycia.carbon.common.config.ConfigFactory;
import net.draycia.carbon.common.config.PrimaryConfig;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.minecraft.network.protocol.game.ClientboundCustomChatCompletionsPacket;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier;
@DefaultQualifier(NonNull.class)
public class FabricPlayerJoinListener implements ServerPlayConnectionEvents.Join {
private ConfigFactory configFactory;
@Inject
public FabricPlayerJoinListener(final ConfigFactory configFactory) {
this.configFactory = configFactory;
}
@Override
public void onPlayReady(final ServerGamePacketListenerImpl handler, PacketSender sender, final MinecraftServer server) {
final @Nullable List<String> suggestions = this.configFactory.primaryConfig().customChatSuggestions();
if (suggestions == null || suggestions.isEmpty()) {
return;
}
sender.sendPacket(new ClientboundCustomChatCompletionsPacket(ClientboundCustomChatCompletionsPacket.Action.SET,
suggestions));
}
}