Rework channel registration

Addons should now register any new channels as early as possible to allow for command registration.

Removing channels requires a plugin restart.
This commit is contained in:
Jason Penilla authored and Jason committed 2023-07-12 18:48:43 -07:00
1 parent 2f1023d9f0
commit 88402ed0a6
4 files changed
+98 -68

No files matched your search

@@ -20,6 +20,7 @@
package net.draycia.carbon.api.channels;
import java.util.Set;
import java.util.function.Consumer;
import net.kyori.adventure.key.Key;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -32,15 +33,9 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public interface ChannelRegistry {
/**
* Registers ingame commands for the channel.
* Registers the chat channel with its key.
*
* @param channel the channel to register commands for
* @since 2.1.0
*/
void registerChannelCommands(final ChatChannel channel);
/**
* Registers the chat channel with it's key.
* <p>Registrations will persist when reloading Carbon's configuration.</p>
*
* @param channel the channel to register
* @since 2.1.0
@@ -89,4 +84,15 @@ public interface ChannelRegistry {
*/
ChatChannel keyOrDefault(final Key key);
/**
* The provided action will be executed immediately for all currently registered
* channels.
*
* <p>When new channels are registered, the action will be invoked again for each new channel.</p>
*
* @param action action
* @since 2.1.0
*/
void allKeys(Consumer<Key> action);
}
@@ -20,14 +20,19 @@
package net.draycia.carbon.api.event.events;
import java.util.Set;
import net.draycia.carbon.api.channels.ChatChannel;
import java.util.function.Consumer;
import net.draycia.carbon.api.channels.ChannelRegistry;
import net.draycia.carbon.api.event.CarbonEvent;
import net.kyori.adventure.key.Key;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
/**
* {@link CarbonEvent} that's called when channels are registered.
* {@link CarbonEvent} that's called after new channels are registered.
*
* <p>Note that some invocations of this event may be too early for
* API consumers to be notified. Prefer using {@link ChannelRegistry#allKeys(Consumer)}
* when knowledge of all registered channels is needed.</p>
*
* @since 2.1.0
*/
@@ -35,21 +40,19 @@ import org.checkerframework.framework.qual.DefaultQualifier;
public interface CarbonChannelRegisterEvent extends CarbonEvent {
/**
* The channels that were registered.
* Gets the channel registry.
*
* @return the registered channels
* @return the channel registry
* @since 2.1.0
*/
Set<Key> channelKeys();
ChannelRegistry channelRegistry();
/**
* Registers additional channels to the registry. Does not re-emit the event.
* Gets the key(s) that were registered to trigger this event.
*
* @param key The key the channel is identified with in the registry
* @param channel the channel to register
* @param registerCommands if commands for the channel should be registered
* @return key(s) registered
* @since 2.1.0
*/
void register(final Key key, final ChatChannel channel, final boolean registerCommands);
Set<Key> registered();
}