mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 14:38:49 +00:00
Add channel permission contracts (#142)
This commit is contained in:
1 file changed
+55
-20
@@ -2,34 +2,21 @@ package net.draycia.carbon.api.channels;
|
|||||||
|
|
||||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||||
import net.draycia.carbon.api.util.ChatComponentRenderer;
|
import net.draycia.carbon.api.util.ChatComponentRenderer;
|
||||||
|
import net.kyori.adventure.key.Keyed;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
|
import static net.kyori.adventure.text.Component.empty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ChatChannel interface, supplies a formatter and filters recipients.
|
* ChatChannel interface, supplies a formatter and filters recipients.<br>
|
||||||
|
* Extends Keyed for identification purposes.
|
||||||
*
|
*
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
public interface ChatChannel {
|
public interface ChatChannel extends Keyed {
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the player may receive messages from this channel.
|
|
||||||
*
|
|
||||||
* @param player the player
|
|
||||||
* @return if the player may receive this channel's messages
|
|
||||||
* @since 2.0.0
|
|
||||||
*/
|
|
||||||
boolean mayReceiveMessages(final CarbonPlayer player);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the player may send messages in this channel.
|
|
||||||
*
|
|
||||||
* @param player the player
|
|
||||||
* @return if the player may send messages in this channel
|
|
||||||
* @since 2.0.0
|
|
||||||
*/
|
|
||||||
boolean maySendMessages(final CarbonPlayer player);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This channel's renderer.
|
* This channel's renderer.
|
||||||
@@ -39,4 +26,52 @@ public interface ChatChannel {
|
|||||||
*/
|
*/
|
||||||
ChatComponentRenderer renderer();
|
ChatComponentRenderer renderer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the player may send messages in this channel.
|
||||||
|
*
|
||||||
|
* @param carbonPlayer the player attempting to speak
|
||||||
|
* @return if the player may speak
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
ChannelPermissionResult speechPermitted(final CarbonPlayer carbonPlayer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the player may receive messages from this channel.
|
||||||
|
*
|
||||||
|
* @param carbonPlayer the player that's receiving messages
|
||||||
|
* @return if the player may receive messages
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
ChannelPermissionResult hearingPermitted(final CarbonPlayer carbonPlayer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the result of a channel permission check.
|
||||||
|
*/
|
||||||
|
record ChannelPermissionResult(boolean permitted, Component reason) {
|
||||||
|
|
||||||
|
private static final ChannelPermissionResult ALLOWED =
|
||||||
|
new ChannelPermissionResult(true, empty());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a result denoting that the player is permitted for the action.
|
||||||
|
*
|
||||||
|
* @return that the action is allowed
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public static ChannelPermissionResult allowed() {
|
||||||
|
return ALLOWED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a result denoting that the player is denied for the action.
|
||||||
|
*
|
||||||
|
* @return that the action is denied
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public static ChannelPermissionResult denied(final Component reason) {
|
||||||
|
return new ChannelPermissionResult(false, reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user