mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 14:38:51 +00:00
Join command permission adjustments (#522)
* Adjust channel permissions base channel perm: allows joining .see: allows seeing messages .speak: allows sending messages * Move #permission to config channel and add #dynamicPermission * add since tag
This commit is contained in:
1 parent
6760e05c93
commit
e97d6eb7f8
14 files changed
+102
-30
No files matched your search
@@ -24,7 +24,6 @@ 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.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.kyori.adventure.key.Keyed;
|
import net.kyori.adventure.key.Keyed;
|
||||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
@@ -38,6 +37,15 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
|||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
public interface ChatChannel extends Keyed, ChatComponentRenderer {
|
public interface ChatChannel extends Keyed, ChatComponentRenderer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Checks if the player may send messages in this channel.
|
||||||
*
|
*
|
||||||
@@ -81,6 +89,24 @@ public interface ChatChannel extends Keyed, ChatComponentRenderer {
|
|||||||
*/
|
*/
|
||||||
boolean shouldRegisterCommands();
|
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.
|
* The text that can be used to refer to this channel in commands.
|
||||||
*
|
*
|
||||||
@@ -97,15 +123,6 @@ public interface ChatChannel extends Keyed, ChatComponentRenderer {
|
|||||||
*/
|
*/
|
||||||
List<String> commandAliases();
|
List<String> commandAliases();
|
||||||
|
|
||||||
/**
|
|
||||||
* The base permission players must have in order to use the channel.<br>
|
|
||||||
* Null return means players do not need any permission.
|
|
||||||
*
|
|
||||||
* @return the permission required to use the channel, or null
|
|
||||||
* @since 2.0.7
|
|
||||||
*/
|
|
||||||
@MonotonicNonNull String permission();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The distance from the sender players must be to receive chat messages.<br>
|
* The distance from the sender players must be to receive chat messages.<br>
|
||||||
* Return of '0' means players must be in the same world/server.<br>
|
* Return of '0' means players must be in the same world/server.<br>
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
|||||||
import org.incendo.cloud.Command;
|
import org.incendo.cloud.Command;
|
||||||
import org.incendo.cloud.CommandManager;
|
import org.incendo.cloud.CommandManager;
|
||||||
import org.incendo.cloud.minecraft.signed.SignedString;
|
import org.incendo.cloud.minecraft.signed.SignedString;
|
||||||
|
import org.incendo.cloud.permission.PredicatePermission;
|
||||||
import org.spongepowered.configurate.ConfigurateException;
|
import org.spongepowered.configurate.ConfigurateException;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
import org.spongepowered.configurate.loader.ConfigurationLoader;
|
import org.spongepowered.configurate.loader.ConfigurationLoader;
|
||||||
@@ -363,15 +364,13 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
|
|||||||
channel.commandAliases(), commandManager.createDefaultCommandMeta())
|
channel.commandAliases(), commandManager.createDefaultCommandMeta())
|
||||||
.optional("message", signedGreedyStringParser());
|
.optional("message", signedGreedyStringParser());
|
||||||
|
|
||||||
if (channel.permission() != null) {
|
if (!channel.dynamicPermission()) {
|
||||||
builder = builder.permission(channel.permission());
|
builder = builder.permission(PredicatePermission.of(sender -> {
|
||||||
|
if (!(sender instanceof CarbonPlayer player)) {
|
||||||
// Add to LuckPerms permission suggestions... lol
|
return true;
|
||||||
//this.carbonChat.server().console().get(PermissionChecker.POINTER).ifPresent(checker -> {
|
}
|
||||||
// checker.test(channel.permission());
|
return channel.joinPermitted(player).permitted();
|
||||||
// checker.test(channel.permission() + ".see");
|
}));
|
||||||
// checker.test(channel.permission() + ".speak");
|
|
||||||
//});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final Key channelKey = channel.key();
|
final Key channelKey = channel.key();
|
||||||
|
|||||||
@@ -160,6 +160,14 @@ public class ConfigChatChannel implements ChatChannel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChannelPermissionResult joinPermitted(final CarbonPlayer player) {
|
||||||
|
return channelPermissionResult(
|
||||||
|
player.hasPermission(this.permission()),
|
||||||
|
() -> this.messages.channelNoPermission(player)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
|
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
|
||||||
return channelPermissionResult(
|
return channelPermissionResult(
|
||||||
@@ -176,6 +184,11 @@ public class ConfigChatChannel implements ChatChannel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean dynamicPermission() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Audience> recipients(final CarbonPlayer sender) {
|
public List<Audience> recipients(final CarbonPlayer sender) {
|
||||||
final List<Audience> recipients = new ArrayList<>();
|
final List<Audience> recipients = new ArrayList<>();
|
||||||
@@ -257,8 +270,7 @@ public class ConfigChatChannel implements ChatChannel {
|
|||||||
return requireNonNull(this.carbonMessages, "Channel message service must not be null!");
|
return requireNonNull(this.carbonMessages, "Channel message service must not be null!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private String permission() {
|
||||||
public String permission() {
|
|
||||||
if (this.permission == null) {
|
if (this.permission == null) {
|
||||||
return "carbon.channel." + this.key().value();
|
return "carbon.channel." + this.key().value();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,14 @@ public class PartyChatChannel extends ConfigChatChannel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChannelPermissionResult joinPermitted(final CarbonPlayer player) {
|
||||||
|
return channelPermissionResult(
|
||||||
|
player.party().join() != null,
|
||||||
|
() -> this.messages.cannotUsePartyChannel(player)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
|
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
|
||||||
return channelPermissionResult(
|
return channelPermissionResult(
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ public final class JoinCommand extends CarbonCommand {
|
|||||||
this.carbonMessages.channelNotFound(sender);
|
this.carbonMessages.channelNotFound(sender);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final ChannelPermissionResult permitted = channel.hearingPermitted(sender);
|
final ChannelPermissionResult permitted = channel.joinPermitted(sender);
|
||||||
if (!permitted.permitted()) {
|
if (!permitted.permitted()) {
|
||||||
sender.sendMessage(permitted.reason());
|
sender.sendMessage(permitted.reason());
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ public final class LeaveCommand extends CarbonCommand {
|
|||||||
.map(Suggestion::suggestion)
|
.map(Suggestion::suggestion)
|
||||||
.toList();
|
.toList();
|
||||||
}))
|
}))
|
||||||
.permission("carbon.join")
|
.permission("carbon.leave")
|
||||||
.senderType(PlayerCommander.class)
|
.senderType(PlayerCommander.class)
|
||||||
.commandDescription(richDescription(this.carbonMessages.commandLeaveDescription()))
|
.commandDescription(richDescription(this.carbonMessages.commandLeaveDescription()))
|
||||||
.handler(handler -> {
|
.handler(handler -> {
|
||||||
@@ -90,7 +90,7 @@ public final class LeaveCommand extends CarbonCommand {
|
|||||||
this.carbonMessages.channelNotFound(sender);
|
this.carbonMessages.channelNotFound(sender);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final ChannelPermissionResult permitted = channel.speechPermitted(sender);
|
final ChannelPermissionResult permitted = channel.joinPermitted(sender);
|
||||||
if (!permitted.permitted()) {
|
if (!permitted.permitted()) {
|
||||||
sender.sendMessage(permitted.reason());
|
sender.sendMessage(permitted.reason());
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public class MessagePacketHandler implements Listener {
|
|||||||
final Component networkMessage = e.renderFor(sender);
|
final Component networkMessage = e.renderFor(sender);
|
||||||
|
|
||||||
return new ChatMessagePacket(serverId, sender.uuid(),
|
return new ChatMessagePacket(serverId, sender.uuid(),
|
||||||
event.chatChannel().permission(), event.chatChannel().key(), sender.username(), networkMessage);
|
event.chatChannel().key(), sender.username(), networkMessage);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
|||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
public class MessagingManager {
|
public class MessagingManager {
|
||||||
|
|
||||||
private static final byte protocolVersion = 0;
|
private static final byte protocolVersion = 1;
|
||||||
|
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
private final UUID serverId;
|
private final UUID serverId;
|
||||||
|
|||||||
-4
@@ -67,14 +67,12 @@ public final class ChatMessagePacket extends CarbonPacket {
|
|||||||
public ChatMessagePacket(
|
public ChatMessagePacket(
|
||||||
final @NotNull UUID serverId,
|
final @NotNull UUID serverId,
|
||||||
final UUID userId,
|
final UUID userId,
|
||||||
final String channelPermission,
|
|
||||||
final Key channelKey,
|
final Key channelKey,
|
||||||
final String username,
|
final String username,
|
||||||
final Component message
|
final Component message
|
||||||
) {
|
) {
|
||||||
super(serverId);
|
super(serverId);
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
this.channelPermission = channelPermission;
|
|
||||||
this.channelKey = channelKey;
|
this.channelKey = channelKey;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
@@ -83,7 +81,6 @@ public final class ChatMessagePacket extends CarbonPacket {
|
|||||||
@Override
|
@Override
|
||||||
public void read(final io.netty.buffer.@NotNull ByteBuf buffer) {
|
public void read(final io.netty.buffer.@NotNull ByteBuf buffer) {
|
||||||
this.userId = this.readUUID(buffer);
|
this.userId = this.readUUID(buffer);
|
||||||
this.channelPermission = this.readString(buffer);
|
|
||||||
this.channelKey = this.readKey(buffer);
|
this.channelKey = this.readKey(buffer);
|
||||||
this.username = this.readString(buffer);
|
this.username = this.readString(buffer);
|
||||||
this.message = this.readComponent(buffer);
|
this.message = this.readComponent(buffer);
|
||||||
@@ -92,7 +89,6 @@ public final class ChatMessagePacket extends CarbonPacket {
|
|||||||
@Override
|
@Override
|
||||||
public void write(final io.netty.buffer.@NotNull ByteBuf buffer) {
|
public void write(final io.netty.buffer.@NotNull ByteBuf buffer) {
|
||||||
this.writeUUID(this.userId, buffer);
|
this.writeUUID(this.userId, buffer);
|
||||||
this.writeString(this.channelPermission, buffer);
|
|
||||||
this.writeKey(this.channelKey, buffer);
|
this.writeKey(this.channelKey, buffer);
|
||||||
this.writeString(this.username, buffer);
|
this.writeString(this.username, buffer);
|
||||||
this.writeComponent(this.message, buffer);
|
this.writeComponent(this.message, buffer);
|
||||||
|
|||||||
@@ -64,6 +64,14 @@ public class AllianceChannel extends AbstractFactionsChannel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChannelPermissionResult joinPermitted(final CarbonPlayer player) {
|
||||||
|
return channelPermissionResult(
|
||||||
|
this.hasRelations(player, Relation.ALLY),
|
||||||
|
() -> this.messages.cannotUseFactionAllianceChannel(player)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
|
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
|
||||||
return channelPermissionResult(
|
return channelPermissionResult(
|
||||||
|
|||||||
@@ -61,6 +61,14 @@ public class FactionChannel extends AbstractFactionsChannel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChannelPermissionResult joinPermitted(final CarbonPlayer player) {
|
||||||
|
return channelPermissionResult(
|
||||||
|
this.faction(player) != null,
|
||||||
|
() -> this.messages.cannotUseFactionChannel(player)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
|
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
|
||||||
return channelPermissionResult(
|
return channelPermissionResult(
|
||||||
|
|||||||
@@ -64,6 +64,14 @@ public class TruceChannel extends AbstractFactionsChannel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChannelPermissionResult joinPermitted(final CarbonPlayer player) {
|
||||||
|
return channelPermissionResult(
|
||||||
|
this.hasRelations(player, Relation.TRUCE),
|
||||||
|
() -> this.messages.cannotUseTruceChannel(player)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
|
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
|
||||||
return channelPermissionResult(
|
return channelPermissionResult(
|
||||||
|
|||||||
@@ -64,6 +64,14 @@ public class McmmoPartyChannel extends ConfigChatChannel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChannelPermissionResult joinPermitted(final CarbonPlayer player) {
|
||||||
|
return channelPermissionResult(
|
||||||
|
this.party(player) != null,
|
||||||
|
() -> this.messages.cannotUseMcmmoPartyChannel(player)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
|
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
|
||||||
return channelPermissionResult(
|
return channelPermissionResult(
|
||||||
|
|||||||
+8
@@ -52,6 +52,14 @@ abstract class ResidentListChannel<T extends ResidentList> extends ConfigChatCha
|
|||||||
|
|
||||||
protected abstract @Nullable T residentList(CarbonPlayer player);
|
protected abstract @Nullable T residentList(CarbonPlayer player);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChannelPermissionResult joinPermitted(final CarbonPlayer player) {
|
||||||
|
return channelPermissionResult(
|
||||||
|
this.residentList(player) != null,
|
||||||
|
() -> this.cannotUseChannel(player)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
|
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
|
||||||
return channelPermissionResult(
|
return channelPermissionResult(
|
||||||
|
|||||||
Reference in new issue
Block a user