Improve the channel permissions API (#523)

* Improve the channel permissions API

* Don't check join permission when leaving a channel

* Adjust suggestions
This commit is contained in:
Jason Penilla authored and GitHub committed 2024-08-19 17:24:33 -07:00
1 parent a1c37ad84a
commit 2faaa2dcda
17 files changed
+239 -217

No files matched your search

@@ -0,0 +1,108 @@
/*
* CarbonChat
*
* Copyright (c) 2024 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.api.channels;
import java.util.function.Function;
import net.draycia.carbon.api.users.CarbonPlayer;
/**
* Permissions handling for a channel.
*
* @since 3.0.0
*/
public interface ChannelPermissions {
/**
* Checks if the player may join this channel.
*
* @param carbonPlayer the player attempting to join
* @return if the player may join
* @since 3.0.0
*/
ChannelPermissionResult joinPermitted(CarbonPlayer carbonPlayer);
/**
* Checks if the player may send messages in this channel.
*
* @param carbonPlayer the player attempting to speak
* @return if the player may speak
* @since 3.0.0
*/
ChannelPermissionResult speechPermitted(CarbonPlayer carbonPlayer);
/**
* Checks if the player may receive messages from this channel.
*
* @param player the player that's receiving messages
* @return if the player may receive messages
* @since 3.0.0
*/
ChannelPermissionResult hearingPermitted(CarbonPlayer player);
/**
* Returns whether the result of {@link #joinPermitted(CarbonPlayer)} is dynamic.
*
* <p>An example of a dynamic permissions is the built-in party channel that only allows players in a party to join.</p>
*
* <p>An example of static permissions is the built-in config channels that simply check permission strings. The fact that a player's
* permissions may change during gameplay does not make the permission dynamic, as the server will resend commands on permission changes.</p>
*
* <p>If the result is static, then we can avoid sending commands to the player that they will just get denied use
* of on execute. If it's dynamic, we must send the command regardless in case they gain permission later.</p>
*
* @return whether the permissions are dynamic
* @since 3.0.0
*/
boolean dynamic();
/**
* Creates a new {@link ChannelPermissions} that performs the same check for
* {@link #joinPermitted(CarbonPlayer)}, {@link #hearingPermitted(CarbonPlayer)},
* and {@link #speechPermitted(CarbonPlayer)}.
*
* @param check permission check
* @return new permissions object
* @since 3.0.0
*/
static ChannelPermissions uniformDynamic(final Function<CarbonPlayer, ChannelPermissionResult> check) {
return new ChannelPermissions() {
@Override
public ChannelPermissionResult joinPermitted(final CarbonPlayer player) {
return check.apply(player);
}
@Override
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
return check.apply(player);
}
@Override
public ChannelPermissionResult hearingPermitted(final CarbonPlayer player) {
return check.apply(player);
}
@Override
public boolean dynamic() {
return true;
}
};
}
}
@@ -109,4 +109,18 @@ public interface ChannelRegistry {
*/
void allKeys(Consumer<Key> action);
/**
* Create a {@link ChannelPermissions channel permissions handler} for the provided base permission string.
*
* <p>The handler will check the base permission for joins, {@literal <base>.see} for receiving/seeing messages,
* and {@literal <base>.speak} for speaking/sending messages.</p>
*
* <p>The built-in deny messages are used, same as user-configured config channels.</p>
*
* @param permission permission string
* @return permission handler
* @since 3.0.0
*/
ChannelPermissions permission(String permission);
}
@@ -38,31 +38,12 @@ import org.checkerframework.framework.qual.DefaultQualifier;
public interface ChatChannel extends Keyed, ChatComponentRenderer {
/**
* Checks if the player may join this channel.
* Returns the permissions handler for the channel.
*
* @param carbonPlayer the player attempting to join
* @return if the player may join
* @return the permissions handler
* @since 3.0.0
*/
ChannelPermissionResult joinPermitted(CarbonPlayer carbonPlayer);
/**
* Checks if the player may send messages in this channel.
*
* @param carbonPlayer the player attempting to speak
* @return if the player may speak
* @since 3.0.0
*/
ChannelPermissionResult speechPermitted(CarbonPlayer carbonPlayer);
/**
* Checks if the player may receive messages from this channel.
*
* @param player the player that's receiving messages
* @return if the player may receive messages
* @since 3.0.0
*/
ChannelPermissionResult hearingPermitted(CarbonPlayer player);
ChannelPermissions permissions();
/**
* Returns a list of all recipients that will receive messages from the sender.
@@ -89,24 +70,6 @@ public interface ChatChannel extends Keyed, ChatComponentRenderer {
*/
boolean shouldRegisterCommands();
/**
* Returns whether the result of {@link #joinPermitted(CarbonPlayer)} is dynamic.
*
* <p>An example of a dynamic permissions is the built-in party channel that only allows players in a party to join.</p>
*
* <p>An example of static permissions is the built-in config channels that simply check permission strings. The fact that a player's
* permissions may change during gameplay does not make the permission dynamic, as the server will resend commands on permission changes.</p>
*
* <p>If the result is static, then we can avoid sending commands to the player that they will just get denied use
* of on execute. If it's dynamic, we must send the command regardless in case they gain permission later.</p>
*
* @return whether the permissions are dynamic
* @since 3.0.0
*/
default boolean dynamicPermission() {
return true;
}
/**
* The text that can be used to refer to this channel in commands.
*
@@ -41,6 +41,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import net.draycia.carbon.api.channels.ChannelPermissions;
import net.draycia.carbon.api.channels.ChannelRegistry;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.event.CarbonEventHandler;
@@ -364,12 +365,12 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
channel.commandAliases(), commandManager.createDefaultCommandMeta())
.optional("message", signedGreedyStringParser());
if (!channel.dynamicPermission()) {
if (!channel.permissions().dynamic()) {
builder = builder.permission(PredicatePermission.of(sender -> {
if (!(sender instanceof CarbonPlayer player)) {
return true;
}
return channel.joinPermitted(player).permitted();
return channel.permissions().joinPermitted(player).permitted();
}));
}
@@ -516,4 +517,8 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
);
}
@Override
public ChannelPermissions permission(final String permission) {
return new ChannelPermissionsImpl(permission, this.carbonMessages);
}
}
@@ -0,0 +1,58 @@
/*
* CarbonChat
*
* Copyright (c) 2024 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.common.channels;
import net.draycia.carbon.api.channels.ChannelPermissionResult;
import net.draycia.carbon.api.channels.ChannelPermissions;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.common.messages.CarbonMessages;
import static net.draycia.carbon.api.channels.ChannelPermissionResult.channelPermissionResult;
public record ChannelPermissionsImpl(String permission, CarbonMessages messages) implements ChannelPermissions {
@Override
public ChannelPermissionResult joinPermitted(final CarbonPlayer player) {
return channelPermissionResult(
player.hasPermission(this.permission()),
() -> this.messages.channelNoPermission(player)
);
}
@Override
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
return channelPermissionResult(
player.hasPermission(this.permission() + ".speak"),
() -> this.messages.channelNoPermission(player)
);
}
@Override
public ChannelPermissionResult hearingPermitted(final CarbonPlayer player) {
return channelPermissionResult(
player.hasPermission(this.permission() + ".see"),
() -> this.messages.channelNoPermission(player)
);
}
@Override
public boolean dynamic() {
return false;
}
}
@@ -29,7 +29,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import net.draycia.carbon.api.CarbonServer;
import net.draycia.carbon.api.channels.ChannelPermissionResult;
import net.draycia.carbon.api.channels.ChannelPermissions;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.common.channels.messages.ConfigChannelMessageSource;
@@ -64,7 +64,6 @@ import org.spongepowered.configurate.objectmapping.meta.Comment;
import org.spongepowered.configurate.objectmapping.meta.Setting;
import static java.util.Objects.requireNonNull;
import static net.draycia.carbon.api.channels.ChannelPermissionResult.channelPermissionResult;
@ConfigSerializable
@DefaultQualifier(NonNull.class)
@@ -161,32 +160,8 @@ public class ConfigChatChannel implements ChatChannel {
}
@Override
public ChannelPermissionResult joinPermitted(final CarbonPlayer player) {
return channelPermissionResult(
player.hasPermission(this.permission()),
() -> this.messages.channelNoPermission(player)
);
}
@Override
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
return channelPermissionResult(
player.hasPermission(this.permission() + ".speak"),
() -> this.messages.channelNoPermission(player)
);
}
@Override
public ChannelPermissionResult hearingPermitted(final CarbonPlayer player) {
return channelPermissionResult(
player.hasPermission(this.permission() + ".see") && !player.leftChannels().contains(this.key),
() -> this.messages.channelNoPermission(player)
);
}
@Override
public boolean dynamicPermission() {
return false;
public ChannelPermissions permissions() {
return new ChannelPermissionsImpl(this.permission(), this.messages);
}
@Override
@@ -194,7 +169,7 @@ public class ConfigChatChannel implements ChatChannel {
final List<Audience> recipients = new ArrayList<>();
for (final CarbonPlayer player : this.server.players()) {
if (this.hearingPermitted(player).permitted()) {
if (this.permissions().hearingPermitted(player).permitted() && !player.leftChannels().contains(this.key)) {
recipients.add(player);
}
}
@@ -19,23 +19,20 @@
*/
package net.draycia.carbon.common.channels;
import com.google.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import net.draycia.carbon.api.channels.ChannelPermissionResult;
import net.draycia.carbon.api.channels.ChannelPermissions;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.users.Party;
import net.draycia.carbon.common.channels.messages.ConfigChannelMessageSource;
import net.draycia.carbon.common.messages.CarbonMessages;
import net.draycia.carbon.common.messages.SourcedAudience;
import net.draycia.carbon.common.users.WrappedCarbonPlayer;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier;
@@ -50,8 +47,6 @@ public class PartyChatChannel extends ConfigChatChannel {
public static final String FILE_NAME = "partychat.conf";
private transient @MonotonicNonNull @Inject CarbonMessages messages;
public PartyChatChannel() {
this.key = Key.key("carbon", "partychat");
this.commandAliases = List.of("pc");
@@ -63,27 +58,11 @@ public class PartyChatChannel extends ConfigChatChannel {
}
@Override
public ChannelPermissionResult joinPermitted(final CarbonPlayer player) {
return channelPermissionResult(
public ChannelPermissions permissions() {
return ChannelPermissions.uniformDynamic(player -> channelPermissionResult(
player.party().join() != null,
() -> this.messages.cannotUsePartyChannel(player)
);
}
@Override
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
return channelPermissionResult(
player.party().join() != null,
() -> this.messages.cannotUsePartyChannel(player)
);
}
@Override
public ChannelPermissionResult hearingPermitted(final CarbonPlayer player) {
return channelPermissionResult(
player.party().join() != null,
() -> this.messages.cannotUsePartyChannel(player)
);
));
}
@Override
@@ -20,6 +20,7 @@
package net.draycia.carbon.common.command.commands;
import com.google.inject.Inject;
import java.util.Objects;
import net.draycia.carbon.api.channels.ChannelPermissionResult;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.users.CarbonPlayer;
@@ -71,12 +72,18 @@ public final class JoinCommand extends CarbonCommand {
@Override
public void init() {
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
.required("channel", greedyStringParser(), SuggestionProvider.blocking(
(context, s) -> {
final CarbonPlayer sender = ((PlayerCommander) context.sender()).carbonPlayer();
return sender.leftChannels().stream().map(Key::value).map(Suggestion::suggestion).toList();
}
))
.required("channel", greedyStringParser(), SuggestionProvider.blocking((context, s) -> {
final CarbonPlayer sender = ((PlayerCommander) context.sender()).carbonPlayer();
return sender.leftChannels().stream()
.map(this.channelRegistry::channel)
.filter(Objects::nonNull)
.filter(channel -> channel.permissions().joinPermitted(sender).permitted()
|| channel.permissions().hearingPermitted(sender).permitted()
|| channel.permissions().speechPermitted(sender).permitted())
.map(channel -> channel.key().value())
.map(Suggestion::suggestion)
.toList();
}))
.permission("carbon.join")
.senderType(PlayerCommander.class)
.commandDescription(richDescription(this.carbonMessages.commandJoinDescription()))
@@ -87,7 +94,7 @@ public final class JoinCommand extends CarbonCommand {
this.carbonMessages.channelNotFound(sender);
return;
}
final ChannelPermissionResult permitted = channel.joinPermitted(sender);
final ChannelPermissionResult permitted = channel.permissions().joinPermitted(sender);
if (!permitted.permitted()) {
sender.sendMessage(permitted.reason());
return;
@@ -20,7 +20,7 @@
package net.draycia.carbon.common.command.commands;
import com.google.inject.Inject;
import net.draycia.carbon.api.channels.ChannelPermissionResult;
import java.util.Objects;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.common.channels.CarbonChannelRegistry;
@@ -75,7 +75,9 @@ public final class LeaveCommand extends CarbonCommand {
final CarbonPlayer sender = ((PlayerCommander) context.sender()).carbonPlayer();
return this.channelRegistry.keys().stream()
.map(this.channelRegistry::channel)
.filter(x -> !sender.leftChannels().contains(x.key()) && x.speechPermitted(sender).permitted())
.filter(Objects::nonNull)
.filter(x -> !sender.leftChannels().contains(x.key())
&& (x.permissions().joinPermitted(sender).permitted() || x.permissions().hearingPermitted(sender).permitted() || x.permissions().speechPermitted(sender).permitted()))
.map(x -> x.key().value())
.map(Suggestion::suggestion)
.toList();
@@ -90,11 +92,6 @@ public final class LeaveCommand extends CarbonCommand {
this.carbonMessages.channelNotFound(sender);
return;
}
final ChannelPermissionResult permitted = channel.joinPermitted(sender);
if (!permitted.permitted()) {
sender.sendMessage(permitted.reason());
return;
}
if (sender.leftChannels().contains(channel.key())) {
this.carbonMessages.channelAlreadyLeft(sender);
return;
@@ -70,7 +70,7 @@ public abstract class ChatListenerInternal {
}
protected @Nullable CarbonChatEventImpl prepareAndEmitChatEvent(final CarbonPlayer sender, final String messageContent, final @Nullable SignedMessage signedMessage, final ChatChannel channel) {
final ChannelPermissionResult permitted = channel.speechPermitted(sender);
final ChannelPermissionResult permitted = channel.permissions().speechPermitted(sender);
if (!permitted.permitted()) {
sender.sendMessage(permitted.reason());
return null;
@@ -248,7 +248,7 @@ public abstract class WrappedCarbonPlayer implements CarbonPlayer {
continue;
}
if (text.startsWith(prefix) && chatChannel.speechPermitted(this).permitted()) {
if (text.startsWith(prefix) && chatChannel.permissions().speechPermitted(this).permitted()) {
channel = chatChannel;
formattedMessage = formattedMessage.replaceText(TextReplacementConfig.builder()
.once()
@@ -35,7 +35,7 @@ public final class ChannelUtils {
// TODO: Emit events
for (final CarbonPlayer recipient : CarbonChatProvider.carbonChat().server().players()) {
if (channel.hearingPermitted(recipient).permitted()) {
if (channel.permissions().hearingPermitted(recipient).permitted() && !recipient.leftChannels().contains(channel.key())) {
recipient.sendMessage(msg);
}
}
@@ -28,11 +28,10 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import net.draycia.carbon.api.channels.ChannelPermissionResult;
import net.draycia.carbon.api.channels.ChannelPermissions;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.users.UserManager;
import net.draycia.carbon.common.channels.messages.ConfigChannelMessageSource;
import net.draycia.carbon.common.messages.CarbonMessages;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.key.Key;
import org.bukkit.entity.Player;
@@ -50,7 +49,6 @@ public class AllianceChannel extends AbstractFactionsChannel {
public static final String FILE_NAME = "factionsuuid-alliancechat.conf";
private transient @MonotonicNonNull @Inject CarbonMessages messages;
private transient @MonotonicNonNull @Inject UserManager<?> users;
public AllianceChannel() {
@@ -65,27 +63,11 @@ public class AllianceChannel extends AbstractFactionsChannel {
}
@Override
public ChannelPermissionResult joinPermitted(final CarbonPlayer player) {
return channelPermissionResult(
public ChannelPermissions permissions() {
return ChannelPermissions.uniformDynamic(player -> channelPermissionResult(
this.hasRelations(player, Relation.ALLY),
() -> this.messages.cannotUseFactionAllianceChannel(player)
);
}
@Override
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
return channelPermissionResult(
this.hasRelations(player, Relation.ALLY),
() -> this.messages.cannotUseFactionAllianceChannel(player)
);
}
@Override
public ChannelPermissionResult hearingPermitted(final CarbonPlayer player) {
return channelPermissionResult(
this.hasRelations(player, Relation.ALLY),
() -> this.messages.cannotUseFactionAllianceChannel(player)
);
));
}
@Override
@@ -25,11 +25,10 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import net.draycia.carbon.api.channels.ChannelPermissionResult;
import net.draycia.carbon.api.channels.ChannelPermissions;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.users.UserManager;
import net.draycia.carbon.common.channels.messages.ConfigChannelMessageSource;
import net.draycia.carbon.common.messages.CarbonMessages;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.key.Key;
import org.bukkit.entity.Player;
@@ -47,7 +46,6 @@ public class FactionChannel extends AbstractFactionsChannel {
public static final String FILE_NAME = "factionsuuid-factionchat.conf";
private transient @MonotonicNonNull @Inject CarbonMessages messages;
private transient @MonotonicNonNull @Inject UserManager<?> users;
public FactionChannel() {
@@ -62,27 +60,11 @@ public class FactionChannel extends AbstractFactionsChannel {
}
@Override
public ChannelPermissionResult joinPermitted(final CarbonPlayer player) {
return channelPermissionResult(
public ChannelPermissions permissions() {
return ChannelPermissions.uniformDynamic(player -> channelPermissionResult(
this.faction(player) != null,
() -> this.messages.cannotUseFactionChannel(player)
);
}
@Override
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
return channelPermissionResult(
this.faction(player) != null,
() -> this.messages.cannotUseFactionChannel(player)
);
}
@Override
public ChannelPermissionResult hearingPermitted(final CarbonPlayer player) {
return channelPermissionResult(
this.faction(player) != null,
() -> this.messages.cannotUseFactionChannel(player)
);
));
}
@Override
@@ -28,7 +28,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import net.draycia.carbon.api.channels.ChannelPermissionResult;
import net.draycia.carbon.api.channels.ChannelPermissions;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.users.UserManager;
import net.draycia.carbon.common.channels.messages.ConfigChannelMessageSource;
@@ -65,27 +65,11 @@ public class TruceChannel extends AbstractFactionsChannel {
}
@Override
public ChannelPermissionResult joinPermitted(final CarbonPlayer player) {
return channelPermissionResult(
public ChannelPermissions permissions() {
return ChannelPermissions.uniformDynamic(player -> channelPermissionResult(
this.hasRelations(player, Relation.TRUCE),
() -> this.messages.cannotUseTruceChannel(player)
);
}
@Override
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
return channelPermissionResult(
this.hasRelations(player, Relation.TRUCE),
() -> this.messages.cannotUseTruceChannel(player)
);
}
@Override
public ChannelPermissionResult hearingPermitted(final CarbonPlayer player) {
return channelPermissionResult(
this.hasRelations(player, Relation.TRUCE),
() -> this.messages.cannotUseTruceChannel(player)
);
));
}
@Override
@@ -26,7 +26,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import net.draycia.carbon.api.channels.ChannelPermissionResult;
import net.draycia.carbon.api.channels.ChannelPermissions;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.users.UserManager;
import net.draycia.carbon.common.channels.ConfigChatChannel;
@@ -65,27 +65,11 @@ public class McmmoPartyChannel extends ConfigChatChannel {
}
@Override
public ChannelPermissionResult joinPermitted(final CarbonPlayer player) {
return channelPermissionResult(
public ChannelPermissions permissions() {
return ChannelPermissions.uniformDynamic(player -> channelPermissionResult(
this.party(player) != null,
() -> this.messages.cannotUseMcmmoPartyChannel(player)
);
}
@Override
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
return channelPermissionResult(
this.party(player) != null,
() -> this.messages.cannotUseMcmmoPartyChannel(player)
);
}
@Override
public ChannelPermissionResult hearingPermitted(final CarbonPlayer player) {
return channelPermissionResult(
this.party(player) != null,
() -> this.messages.cannotUseMcmmoPartyChannel(player)
);
));
}
@Override
@@ -25,7 +25,7 @@ import com.palmergames.bukkit.towny.object.ResidentList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.draycia.carbon.api.channels.ChannelPermissionResult;
import net.draycia.carbon.api.channels.ChannelPermissions;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.users.UserManager;
import net.draycia.carbon.common.channels.ConfigChatChannel;
@@ -53,27 +53,11 @@ abstract class ResidentListChannel<T extends ResidentList> extends ConfigChatCha
protected abstract @Nullable T residentList(CarbonPlayer player);
@Override
public ChannelPermissionResult joinPermitted(final CarbonPlayer player) {
return channelPermissionResult(
public ChannelPermissions permissions() {
return ChannelPermissions.uniformDynamic(player -> channelPermissionResult(
this.residentList(player) != null,
() -> this.cannotUseChannel(player)
);
}
@Override
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
return channelPermissionResult(
this.residentList(player) != null,
() -> this.cannotUseChannel(player)
);
}
@Override
public ChannelPermissionResult hearingPermitted(final CarbonPlayer player) {
return channelPermissionResult(
this.residentList(player) != null,
() -> this.cannotUseChannel(player)
);
));
}
@Override