mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 14:38:49 +00:00
Un-promote ChannelRegistry#byCommandName from API
This commit is contained in:
7 files changed
+23
-31
No files matched your search
@@ -22,7 +22,6 @@ package net.draycia.carbon.api.channels;
|
|||||||
import net.draycia.carbon.api.util.DefaultedKeyValueRegistry;
|
import net.draycia.carbon.api.util.DefaultedKeyValueRegistry;
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
import net.kyori.registry.Registry;
|
import net.kyori.registry.Registry;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registry for chat channels.
|
* Registry for chat channels.
|
||||||
@@ -39,12 +38,4 @@ public interface ChannelRegistry extends Registry<Key, ChatChannel>, DefaultedKe
|
|||||||
*/
|
*/
|
||||||
void registerChannelCommands(final ChatChannel channel);
|
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
|
// https://github.com/SpongePowered/Configurate/blob/1ec74f6474237585aee858b636d9761d237839d5/examples/src/main/java/org/spongepowered/configurate/examples/Transformations.java#L107
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply the transformations to a node.
|
* Apply the transformations to a node.
|
||||||
*
|
*
|
||||||
@@ -477,7 +478,6 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
|
|||||||
return this.defaultValue();
|
return this.defaultValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable ChatChannel byCommandName(final String channelName) {
|
public @Nullable ChatChannel byCommandName(final String channelName) {
|
||||||
for (final ChatChannel channel : this) {
|
for (final ChatChannel channel : this) {
|
||||||
if (channel.commandName().equalsIgnoreCase(channelName)) {
|
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.MinecraftExtrasMetaKeys;
|
||||||
import cloud.commandframework.minecraft.extras.RichDescription;
|
import cloud.commandframework.minecraft.extras.RichDescription;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import net.draycia.carbon.api.CarbonChat;
|
|
||||||
import net.draycia.carbon.api.channels.ChatChannel;
|
import net.draycia.carbon.api.channels.ChatChannel;
|
||||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
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.CarbonCommand;
|
||||||
import net.draycia.carbon.common.command.CommandSettings;
|
import net.draycia.carbon.common.command.CommandSettings;
|
||||||
import net.draycia.carbon.common.command.Commander;
|
import net.draycia.carbon.common.command.Commander;
|
||||||
@@ -40,17 +40,17 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
|||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
public class JoinCommand extends CarbonCommand {
|
public class JoinCommand extends CarbonCommand {
|
||||||
|
|
||||||
final CarbonChat carbonChat;
|
final CarbonChannelRegistry channelRegistry;
|
||||||
final CommandManager<Commander> commandManager;
|
final CommandManager<Commander> commandManager;
|
||||||
final CarbonMessages carbonMessages;
|
final CarbonMessages carbonMessages;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public JoinCommand(
|
public JoinCommand(
|
||||||
final CarbonChat carbonChat,
|
final CarbonChannelRegistry channelRegistry,
|
||||||
final CommandManager<Commander> commandManager,
|
final CommandManager<Commander> commandManager,
|
||||||
final CarbonMessages carbonMessages
|
final CarbonMessages carbonMessages
|
||||||
) {
|
) {
|
||||||
this.carbonChat = carbonChat;
|
this.channelRegistry = channelRegistry;
|
||||||
this.commandManager = commandManager;
|
this.commandManager = commandManager;
|
||||||
this.carbonMessages = carbonMessages;
|
this.carbonMessages = carbonMessages;
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@ public class JoinCommand extends CarbonCommand {
|
|||||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandJoinDescription())
|
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandJoinDescription())
|
||||||
.handler(handler -> {
|
.handler(handler -> {
|
||||||
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
|
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) {
|
if (channel == null) {
|
||||||
this.carbonMessages.channelNotFound(sender);
|
this.carbonMessages.channelNotFound(sender);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ import cloud.commandframework.arguments.standard.StringArgument;
|
|||||||
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
|
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
|
||||||
import cloud.commandframework.minecraft.extras.RichDescription;
|
import cloud.commandframework.minecraft.extras.RichDescription;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import net.draycia.carbon.api.CarbonChat;
|
|
||||||
import net.draycia.carbon.api.channels.ChatChannel;
|
import net.draycia.carbon.api.channels.ChatChannel;
|
||||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
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.CarbonCommand;
|
||||||
import net.draycia.carbon.common.command.CommandSettings;
|
import net.draycia.carbon.common.command.CommandSettings;
|
||||||
import net.draycia.carbon.common.command.Commander;
|
import net.draycia.carbon.common.command.Commander;
|
||||||
@@ -40,17 +40,17 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
|||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
public class LeaveCommand extends CarbonCommand {
|
public class LeaveCommand extends CarbonCommand {
|
||||||
|
|
||||||
final CarbonChat carbonChat;
|
final CarbonChannelRegistry channelRegistry;
|
||||||
final CommandManager<Commander> commandManager;
|
final CommandManager<Commander> commandManager;
|
||||||
final CarbonMessages carbonMessages;
|
final CarbonMessages carbonMessages;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public LeaveCommand(
|
public LeaveCommand(
|
||||||
final CarbonChat carbonChat,
|
final CarbonChannelRegistry channelRegistry,
|
||||||
final CommandManager<Commander> commandManager,
|
final CommandManager<Commander> commandManager,
|
||||||
final CarbonMessages carbonMessages
|
final CarbonMessages carbonMessages
|
||||||
) {
|
) {
|
||||||
this.carbonChat = carbonChat;
|
this.channelRegistry = channelRegistry;
|
||||||
this.commandManager = commandManager;
|
this.commandManager = commandManager;
|
||||||
this.carbonMessages = carbonMessages;
|
this.carbonMessages = carbonMessages;
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ public class LeaveCommand extends CarbonCommand {
|
|||||||
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
|
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
|
||||||
.argument(StringArgument.<Commander>builder("channel").greedy().withSuggestionsProvider((context, s) -> {
|
.argument(StringArgument.<Commander>builder("channel").greedy().withSuggestionsProvider((context, s) -> {
|
||||||
final CarbonPlayer sender = ((PlayerCommander) context.getSender()).carbonPlayer();
|
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())
|
.filter(x -> !sender.leftChannels().contains(x.key()) && x.speechPermitted(sender).permitted())
|
||||||
.map(x -> x.key().value())
|
.map(x -> x.key().value())
|
||||||
.toList();
|
.toList();
|
||||||
@@ -80,7 +80,7 @@ public class LeaveCommand extends CarbonCommand {
|
|||||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandLeaveDescription())
|
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandLeaveDescription())
|
||||||
.handler(handler -> {
|
.handler(handler -> {
|
||||||
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
|
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) {
|
if (channel == null) {
|
||||||
this.carbonMessages.channelNotFound(sender);
|
this.carbonMessages.channelNotFound(sender);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ public final class CarbonChatPaper extends CarbonChatInternal<CarbonPlayerPaper>
|
|||||||
|
|
||||||
if (Bukkit.getPluginManager().isPluginEnabled("DiscordSRV")) {
|
if (Bukkit.getPluginManager().isPluginEnabled("DiscordSRV")) {
|
||||||
this.logger().info("DiscordSRV found! Enabling hook.");
|
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.hooks.chat.ChatHook;
|
||||||
import github.scarsz.discordsrv.util.PluginUtil;
|
import github.scarsz.discordsrv.util.PluginUtil;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import net.draycia.carbon.api.CarbonChat;
|
|
||||||
import net.draycia.carbon.api.channels.ChatChannel;
|
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.event.events.CarbonChatEvent;
|
||||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
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.channels.ConfigChatChannel;
|
||||||
import net.draycia.carbon.common.util.ChannelUtils;
|
import net.draycia.carbon.common.util.ChannelUtils;
|
||||||
import net.draycia.carbon.paper.users.CarbonPlayerPaper;
|
import net.draycia.carbon.paper.users.CarbonPlayerPaper;
|
||||||
@@ -44,19 +45,19 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
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
|
@Inject
|
||||||
public DSRVChatHook(final CarbonChat carbonChat) {
|
private DSRVChatHook(final CarbonEventHandler events, final CarbonChannelRegistry channelRegistry) {
|
||||||
this.carbonChat = carbonChat;
|
this.channelRegistry = channelRegistry;
|
||||||
|
|
||||||
final Cache<ImmutablePair<CarbonPlayer, ChatChannel>, Component> awaitingEvent = Caffeine.newBuilder()
|
final Cache<ImmutablePair<CarbonPlayer, ChatChannel>, Component> awaitingEvent = Caffeine.newBuilder()
|
||||||
.expireAfterWrite(Duration.ofMillis(25))
|
.expireAfterWrite(Duration.ofMillis(25))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
this.carbonChat.eventHandler().subscribe(CarbonChatEvent.class, event -> {
|
events.subscribe(CarbonChatEvent.class, event -> {
|
||||||
final ChatChannel chatChannel = event.chatChannel();
|
final ChatChannel chatChannel = event.chatChannel();
|
||||||
final CarbonPlayer carbonPlayer = event.sender();
|
final CarbonPlayer carbonPlayer = event.sender();
|
||||||
final ImmutablePair<CarbonPlayer, ChatChannel> pair = new ImmutablePair<>(carbonPlayer, chatChannel);
|
final ImmutablePair<CarbonPlayer, ChatChannel> pair = new ImmutablePair<>(carbonPlayer, chatChannel);
|
||||||
@@ -95,7 +96,7 @@ public class DSRVChatHook implements ChatHook {
|
|||||||
@Override
|
@Override
|
||||||
public void broadcastMessageToChannel(final String channel, final github.scarsz.discordsrv.dependencies.kyori.adventure.text.Component message) {
|
public void broadcastMessageToChannel(final String channel, final github.scarsz.discordsrv.dependencies.kyori.adventure.text.Component message) {
|
||||||
final String mmFormattedMessage = MiniMessage.miniMessage().serialize(message);
|
final String mmFormattedMessage = MiniMessage.miniMessage().serialize(message);
|
||||||
ChannelUtils.broadcastMessageToChannel(mmFormattedMessage, this.carbonChat.channelRegistry().byCommandName(channel));
|
ChannelUtils.broadcastMessageToChannel(mmFormattedMessage, this.channelRegistry.byCommandName(channel));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -35,14 +35,14 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public class DiscordMessageListener implements Listener {
|
public final class DiscordMessageListener implements Listener {
|
||||||
|
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
private final JavaPlugin plugin;
|
private final JavaPlugin plugin;
|
||||||
private final Map<Key, MessageType> channelMessageTypes = new HashMap<>();
|
private final Map<Key, MessageType> channelMessageTypes = new HashMap<>();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public DiscordMessageListener(
|
private DiscordMessageListener(
|
||||||
final JavaPlugin plugin,
|
final JavaPlugin plugin,
|
||||||
final CarbonChat carbonChat,
|
final CarbonChat carbonChat,
|
||||||
final Logger logger
|
final Logger logger
|
||||||
|
|||||||
Reference in new issue
Block a user