Un-promote ChannelRegistry#byCommandName from API

This commit is contained in:
Jason Penilla committed 2023-06-24 18:04:58 -07:00
1 parent 0d72883ab9
commit 8e59a14fdb
7 files changed
+24 -32

No files matched your search

@@ -22,7 +22,6 @@ package net.draycia.carbon.api.channels;
import net.draycia.carbon.api.util.DefaultedKeyValueRegistry;
import net.kyori.adventure.key.Key;
import net.kyori.registry.Registry;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Registry for chat channels.
@@ -39,12 +38,4 @@ public interface ChannelRegistry extends Registry<Key, ChatChannel>, DefaultedKe
*/
void registerChannelCommands(final ChatChannel channel);
/**
* Gets the channel with the corresponding command name.
*
* @param channelName the command used to speak in the channel
* @return the channel
*/
@Nullable ChatChannel byCommandName(final String channelName);
}
@@ -142,6 +142,7 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
}
// https://github.com/SpongePowered/Configurate/blob/1ec74f6474237585aee858b636d9761d237839d5/examples/src/main/java/org/spongepowered/configurate/examples/Transformations.java#L107
/**
* Apply the transformations to a node.
*
@@ -149,7 +150,7 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
* occurred</p>
*
* @param node the node to transform
* @param <N> node type
* @param <N> node type
* @return provided node, after transformation
*/
public static <N extends ConfigurationNode> N updateNode(final N node) throws ConfigurateException {
@@ -477,7 +478,6 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
return this.defaultValue();
}
@Override
public @Nullable ChatChannel byCommandName(final String channelName) {
for (final ChatChannel channel : this) {
if (channel.commandName().equalsIgnoreCase(channelName)) {
@@ -24,9 +24,9 @@ import cloud.commandframework.arguments.standard.StringArgument;
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
import cloud.commandframework.minecraft.extras.RichDescription;
import com.google.inject.Inject;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.common.channels.CarbonChannelRegistry;
import net.draycia.carbon.common.command.CarbonCommand;
import net.draycia.carbon.common.command.CommandSettings;
import net.draycia.carbon.common.command.Commander;
@@ -40,17 +40,17 @@ import org.checkerframework.framework.qual.DefaultQualifier;
@DefaultQualifier(NonNull.class)
public class JoinCommand extends CarbonCommand {
final CarbonChat carbonChat;
final CarbonChannelRegistry channelRegistry;
final CommandManager<Commander> commandManager;
final CarbonMessages carbonMessages;
@Inject
public JoinCommand(
final CarbonChat carbonChat,
final CarbonChannelRegistry channelRegistry,
final CommandManager<Commander> commandManager,
final CarbonMessages carbonMessages
) {
this.carbonChat = carbonChat;
this.channelRegistry = channelRegistry;
this.commandManager = commandManager;
this.carbonMessages = carbonMessages;
}
@@ -77,7 +77,7 @@ public class JoinCommand extends CarbonCommand {
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandJoinDescription())
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
final @Nullable ChatChannel channel = this.carbonChat.channelRegistry().byCommandName(handler.get("channel"));
final @Nullable ChatChannel channel = this.channelRegistry.byCommandName(handler.get("channel"));
if (channel == null) {
this.carbonMessages.channelNotFound(sender);
return;
@@ -24,9 +24,9 @@ import cloud.commandframework.arguments.standard.StringArgument;
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
import cloud.commandframework.minecraft.extras.RichDescription;
import com.google.inject.Inject;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.common.channels.CarbonChannelRegistry;
import net.draycia.carbon.common.command.CarbonCommand;
import net.draycia.carbon.common.command.CommandSettings;
import net.draycia.carbon.common.command.Commander;
@@ -40,17 +40,17 @@ import org.checkerframework.framework.qual.DefaultQualifier;
@DefaultQualifier(NonNull.class)
public class LeaveCommand extends CarbonCommand {
final CarbonChat carbonChat;
final CarbonChannelRegistry channelRegistry;
final CommandManager<Commander> commandManager;
final CarbonMessages carbonMessages;
@Inject
public LeaveCommand(
final CarbonChat carbonChat,
final CarbonChannelRegistry channelRegistry,
final CommandManager<Commander> commandManager,
final CarbonMessages carbonMessages
) {
this.carbonChat = carbonChat;
this.channelRegistry = channelRegistry;
this.commandManager = commandManager;
this.carbonMessages = carbonMessages;
}
@@ -70,7 +70,7 @@ public class LeaveCommand extends CarbonCommand {
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
.argument(StringArgument.<Commander>builder("channel").greedy().withSuggestionsProvider((context, s) -> {
final CarbonPlayer sender = ((PlayerCommander) context.getSender()).carbonPlayer();
return this.carbonChat.channelRegistry().stream()
return this.channelRegistry.stream()
.filter(x -> !sender.leftChannels().contains(x.key()) && x.speechPermitted(sender).permitted())
.map(x -> x.key().value())
.toList();
@@ -80,7 +80,7 @@ public class LeaveCommand extends CarbonCommand {
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandLeaveDescription())
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
final @Nullable ChatChannel channel = this.carbonChat.channelRegistry().byCommandName(handler.get("channel"));
final @Nullable ChatChannel channel = this.channelRegistry.byCommandName(handler.get("channel"));
if (channel == null) {
this.carbonMessages.channelNotFound(sender);
return;
@@ -125,7 +125,7 @@ public final class CarbonChatPaper extends CarbonChatInternal<CarbonPlayerPaper>
if (Bukkit.getPluginManager().isPluginEnabled("DiscordSRV")) {
this.logger().info("DiscordSRV found! Enabling hook.");
DiscordSRV.getPlugin().getPluginHooks().add(new DSRVChatHook(this));
DiscordSRV.getPlugin().getPluginHooks().add(this.injector().getInstance(DSRVChatHook.class));
}
}
@@ -30,10 +30,11 @@ import github.scarsz.discordsrv.dependencies.kyori.adventure.text.minimessage.Mi
import github.scarsz.discordsrv.hooks.chat.ChatHook;
import github.scarsz.discordsrv.util.PluginUtil;
import java.time.Duration;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.event.CarbonEventHandler;
import net.draycia.carbon.api.event.events.CarbonChatEvent;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.common.channels.CarbonChannelRegistry;
import net.draycia.carbon.common.channels.ConfigChatChannel;
import net.draycia.carbon.common.util.ChannelUtils;
import net.draycia.carbon.paper.users.CarbonPlayerPaper;
@@ -44,19 +45,19 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.checkerframework.checker.nullness.qual.Nullable;
public class DSRVChatHook implements ChatHook {
public final class DSRVChatHook implements ChatHook {
private final CarbonChat carbonChat;
private final CarbonChannelRegistry channelRegistry;
@Inject
public DSRVChatHook(final CarbonChat carbonChat) {
this.carbonChat = carbonChat;
private DSRVChatHook(final CarbonEventHandler events, final CarbonChannelRegistry channelRegistry) {
this.channelRegistry = channelRegistry;
final Cache<ImmutablePair<CarbonPlayer, ChatChannel>, Component> awaitingEvent = Caffeine.newBuilder()
.expireAfterWrite(Duration.ofMillis(25))
.build();
this.carbonChat.eventHandler().subscribe(CarbonChatEvent.class, event -> {
events.subscribe(CarbonChatEvent.class, event -> {
final ChatChannel chatChannel = event.chatChannel();
final CarbonPlayer carbonPlayer = event.sender();
final ImmutablePair<CarbonPlayer, ChatChannel> pair = new ImmutablePair<>(carbonPlayer, chatChannel);
@@ -95,7 +96,7 @@ public class DSRVChatHook implements ChatHook {
@Override
public void broadcastMessageToChannel(final String channel, final github.scarsz.discordsrv.dependencies.kyori.adventure.text.Component message) {
final String mmFormattedMessage = MiniMessage.miniMessage().serialize(message);
ChannelUtils.broadcastMessageToChannel(mmFormattedMessage, this.carbonChat.channelRegistry().byCommandName(channel));
ChannelUtils.broadcastMessageToChannel(mmFormattedMessage, this.channelRegistry.byCommandName(channel));
}
@Override
@@ -35,14 +35,14 @@ import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import org.checkerframework.checker.nullness.qual.Nullable;
public class DiscordMessageListener implements Listener {
public final class DiscordMessageListener implements Listener {
private final CarbonChat carbonChat;
private final JavaPlugin plugin;
private final Map<Key, MessageType> channelMessageTypes = new HashMap<>();
@Inject
public DiscordMessageListener(
private DiscordMessageListener(
final JavaPlugin plugin,
final CarbonChat carbonChat,
final Logger logger