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

@@ -386,11 +386,11 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
builder = builder.permission(channel.permission());
// Add to LuckPerms permission suggestions... lol
this.carbonChat.server().console().get(PermissionChecker.POINTER).ifPresent(checker -> {
checker.test(channel.permission());
checker.test(channel.permission() + ".see");
checker.test(channel.permission() + ".speak");
});
//this.carbonChat.server().console().get(PermissionChecker.POINTER).ifPresent(checker -> {
// checker.test(channel.permission());
// checker.test(channel.permission() + ".see");
// checker.test(channel.permission() + ".speak");
//});
}
final Key channelKey = channel.key();
@@ -19,10 +19,12 @@
*/
package net.draycia.carbon.common.config;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import net.kyori.adventure.key.Key;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier;
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
import org.spongepowered.configurate.objectmapping.meta.Comment;
@@ -58,6 +60,9 @@ public class PrimaryConfig {
""")
private Map<String, String> customPlaceholders = Map.of();
@Comment("The suggestions shown when using the TAB key in chat.")
private List<String> customChatSuggestions = List.of();
@Comment("Various settings related to pinging players in channels.")
private PingSettings pingSettings = new PingSettings();
@@ -87,6 +92,10 @@ public class PrimaryConfig {
return this.customPlaceholders;
}
public @Nullable List<String> customChatSuggestions() {
return this.customChatSuggestions;
}
public PingSettings pings() {
return this.pingSettings;
}
@@ -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));
}
}