Merge pull request #229 from Hexaoxide/replace-nickname-command-flags

This commit is contained in:
Josua Parks authored and GitHub committed 2023-02-02 12:51:25 -08:00
commit 07bdbe4bd0
16 files changed
+311 -197

No files matched your search

+2
View File
@@ -4,6 +4,7 @@ plugins {
repositories { repositories {
gradlePluginPortal() gradlePluginPortal()
mavenCentral()
maven("https://repo.stellardrift.ca/repository/snapshots/") maven("https://repo.stellardrift.ca/repository/snapshots/")
} }
@@ -12,6 +13,7 @@ dependencies {
implementation(libs.indraCommon) implementation(libs.indraCommon)
implementation(libs.indraLicenseHeader) implementation(libs.indraLicenseHeader)
implementation(libs.licenser) implementation(libs.licenser)
implementation("org.spongepowered:configurate-yaml:4.0.0")
// https://github.com/gradle/gradle/issues/15383#issuecomment-779893192 // https://github.com/gradle/gradle/issues/15383#issuecomment-779893192
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
@@ -0,0 +1,49 @@
import io.leangen.geantyref.TypeToken
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Provider
import org.gradle.kotlin.dsl.listProperty
import org.spongepowered.configurate.ConfigurationNode
import org.spongepowered.configurate.yaml.NodeStyle
import org.spongepowered.configurate.yaml.YamlConfigurationLoader
import javax.inject.Inject
abstract class CarbonPermissionsExtension @Inject constructor(private val objects: ObjectFactory) {
abstract val yaml: RegularFileProperty
val permissions: Provider<List<Permission>> = create()
private fun create(): ListProperty<Permission> = objects.listProperty<Permission>().also {
it.set(yaml.map { file ->
val loader = YamlConfigurationLoader.builder()
.path(file.asFile.toPath())
.nodeStyle(NodeStyle.BLOCK)
.build()
loader.load().childrenMap().map { (name, child) ->
loadPermission(name as String, child)
}
})
it.disallowChanges()
it.finalizeValueOnRead()
}
private fun loadPermission(name: String, node: ConfigurationNode): Permission {
return if (node.isMap) {
Permission(
name,
node.node("description").string,
node.node("children").takeIf { c -> !c.virtual() }
?.get(object : TypeToken<HashMap<String, Boolean>>() {})
)
} else {
Permission(name, node.string, null)
}
}
data class Permission(
val string: String,
val description: String?,
val children: Map<String, Boolean>?
)
}
@@ -0,0 +1,2 @@
val ext = extensions.create("carbonPermission", CarbonPermissionsExtension::class.java)
ext.yaml.convention(rootProject.layout.projectDirectory.file("common/src/main/resources/carbon-permissions.yml"))
@@ -27,12 +27,14 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.function.Predicate;
import net.draycia.carbon.api.CarbonChatProvider; import net.draycia.carbon.api.CarbonChatProvider;
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.api.util.SourcedAudience; import net.draycia.carbon.api.util.SourcedAudience;
import net.draycia.carbon.common.channels.messages.ConfigChannelMessageSource; import net.draycia.carbon.common.channels.messages.ConfigChannelMessageSource;
import net.draycia.carbon.common.channels.messages.ConfigChannelMessages; import net.draycia.carbon.common.channels.messages.ConfigChannelMessages;
import net.draycia.carbon.common.command.Commander;
import net.draycia.carbon.common.messages.SourcedMessageSender; import net.draycia.carbon.common.messages.SourcedMessageSender;
import net.draycia.carbon.common.messages.SourcedReceiverResolver; import net.draycia.carbon.common.messages.SourcedReceiverResolver;
import net.draycia.carbon.common.messages.placeholders.BooleanPlaceholderResolver; import net.draycia.carbon.common.messages.placeholders.BooleanPlaceholderResolver;
@@ -175,21 +177,29 @@ public final class ConfigChatChannel implements ChatChannel {
Map.entry("newline", StandardTags.newline()) Map.entry("newline", StandardTags.newline())
); );
public static Component parseMessageTags(final Commander sender, final String message) {
return parseMessageTags(message, sender::hasPermission);
}
public static Component parseMessageTags(final CarbonPlayer sender, final String message) { public static Component parseMessageTags(final CarbonPlayer sender, final String message) {
if (!sender.hasPermission("carbon.messagetags")) { return parseMessageTags(message, sender::hasPermission);
}
public static Component parseMessageTags(final String message, final Predicate<String> permission) {
if (!permission.test("carbon.messagetags")) {
return Component.text(message); return Component.text(message);
} }
final TagResolver.Builder resolver = TagResolver.builder(); final TagResolver.Builder resolver = TagResolver.builder();
for (final Map.Entry<String, TagResolver> entry : DEFAULT_TAGS.entrySet()) { for (final Map.Entry<String, TagResolver> entry : DEFAULT_TAGS.entrySet()) {
if (sender.hasPermission("carbon.messagetags." + entry.getKey())) { if (permission.test("carbon.messagetags." + entry.getKey())) {
resolver.resolver(entry.getValue()); resolver.resolver(entry.getValue());
} }
} }
for (final TextDecoration decoration : TextDecoration.values()) { for (final TextDecoration decoration : TextDecoration.values()) {
if (!sender.hasPermission("carbon.messagetags." + decoration.name())) { if (!permission.test("carbon.messagetags." + decoration.name())) {
continue; continue;
} }
@@ -23,4 +23,6 @@ import net.kyori.adventure.audience.Audience;
public interface Commander extends Audience { public interface Commander extends Audience {
boolean hasPermission(String permission);
} }
@@ -20,10 +20,10 @@
package net.draycia.carbon.common.command.commands; package net.draycia.carbon.common.command.commands;
import cloud.commandframework.CommandManager; import cloud.commandframework.CommandManager;
import cloud.commandframework.arguments.compound.FlagArgument; 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 cloud.commandframework.permission.Permission; import com.google.common.base.Suppliers;
import com.google.inject.Inject; import com.google.inject.Inject;
import java.util.function.Supplier; import java.util.function.Supplier;
import net.draycia.carbon.api.users.CarbonPlayer; import net.draycia.carbon.api.users.CarbonPlayer;
@@ -33,15 +33,14 @@ import net.draycia.carbon.common.command.CommandSettings;
import net.draycia.carbon.common.command.Commander; import net.draycia.carbon.common.command.Commander;
import net.draycia.carbon.common.command.PlayerCommander; import net.draycia.carbon.common.command.PlayerCommander;
import net.draycia.carbon.common.command.argument.CarbonPlayerArgument; import net.draycia.carbon.common.command.argument.CarbonPlayerArgument;
import net.draycia.carbon.common.command.argument.OptionValueParser;
import net.draycia.carbon.common.command.argument.PlayerSuggestions; import net.draycia.carbon.common.command.argument.PlayerSuggestions;
import net.draycia.carbon.common.messages.CarbonMessages; import net.draycia.carbon.common.messages.CarbonMessages;
import net.draycia.carbon.common.util.CloudUtils;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component; 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.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier; import org.checkerframework.framework.qual.DefaultQualifier;
import org.jetbrains.annotations.Nullable;
@DefaultQualifier(NonNull.class) @DefaultQualifier(NonNull.class)
public class NicknameCommand extends CarbonCommand { public class NicknameCommand extends CarbonCommand {
@@ -73,106 +72,102 @@ public class NicknameCommand extends CarbonCommand {
@Override @Override
public void init() { public void init() {
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
// TODO: Allow UUID input for target player // TODO: Allow UUID input for target player
.flag(this.commandManager.flagBuilder("player") final var selfRoot = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases());
.withAliases("p") final var othersRoot = selfRoot.literal("player")
.withDescription(RichDescription.of(this.carbonMessages.commandNicknameArgumentPlayer())) .argument(
.withArgument(CarbonPlayerArgument.builder("player").withMessages(this.carbonMessages).withSuggestionsProvider(this.playerSuggestions).asOptional()) CarbonPlayerArgument.builder("player")
.withPermission(Permission.of("carbon.nickname.others")) .withMessages(this.carbonMessages)
) .withSuggestionsProvider(this.playerSuggestions),
.flag(this.commandManager.flagBuilder("nickname") RichDescription.of(this.carbonMessages.commandNicknameArgumentPlayer())
.withAliases("n") );
.withDescription(RichDescription.of(this.carbonMessages.commandNicknameArgumentNickname()))
.withArgument(FlagArgument.<Commander, String>ofType(String.class, "value") // Check nickname
.withParser(new OptionValueParser<>()) this.commandManager.command(selfRoot.permission("carbon.nickname")
.asOptional()
.build())
.withPermission(Permission.of("carbon.nickname.set"))
)
.flag(this.commandManager.flagBuilder("reset")
.withAliases("r")
.withDescription(RichDescription.of(this.carbonMessages.commandNicknameArgumentReset()))
.withPermission(Permission.of("carbon.nickname.set"))
)
.permission("carbon.nickname")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandNicknameDescription()) .meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandNicknameDescription())
.handler(handler -> { .handler(ctx -> this.checkOwnNickname(CloudUtils.nonPlayerMustProvidePlayer(this.carbonMessages, ctx.getSender()))));
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer(); this.commandManager.command(othersRoot.permission("carbon.nickname.others")
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandNicknameOthersDescription())
.handler(ctx -> this.checkOthersNickname(ctx.getSender(), ctx.get("player"))));
if (handler.flags().contains("reset")) { // Set nickname
final CarbonPlayer target = handler.flags().contains("player") ? this.commandManager.command(selfRoot.permission("carbon.nickname.set")
handler.flags().get("player") : sender; .meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandNicknameSetDescription())
.argument(StringArgument.greedy("nickname"), RichDescription.of(this.carbonMessages.commandNicknameArgumentNickname()))
.handler(ctx -> this.applyNickname(ctx.getSender(), CloudUtils.nonPlayerMustProvidePlayer(this.carbonMessages, ctx.getSender()), ctx.get("nickname"))));
this.commandManager.command(othersRoot.permission("carbon.nickname.others.set")
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandNicknameOthersSetDescription())
.argument(StringArgument.greedy("nickname"), RichDescription.of(this.carbonMessages.commandNicknameArgumentNickname()))
.handler(ctx -> this.applyNickname(ctx.getSender(), ctx.get("player"), ctx.get("nickname"))));
// Reset/remove nickname
this.commandManager.command(selfRoot.permission("carbon.nickname.set")
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandNicknameResetDescription())
.literal("reset")
.handler(ctx -> this.resetNickname(ctx.getSender(), CloudUtils.nonPlayerMustProvidePlayer(this.carbonMessages, ctx.getSender()))));
this.commandManager.command(othersRoot.permission("carbon.nickname.others.set")
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandNicknameOthersResetDescription())
.literal("reset")
.handler(ctx -> this.resetNickname(ctx.getSender(), ctx.get("player"))));
}
private void resetNickname(final Commander sender, final CarbonPlayer target) {
target.displayName(null); target.displayName(null);
if (sender instanceof PlayerCommander playerCommander
&& playerCommander.carbonPlayer().uuid().equals(target.uuid())) {
this.carbonMessages.nicknameReset(target); this.carbonMessages.nicknameReset(target);
} else {
if (sender != target) {
this.carbonMessages.nicknameResetOthers(sender, target.username()); this.carbonMessages.nicknameResetOthers(sender, target.username());
} }
return;
} }
// Setting nickname private void applyNickname(final Commander sender, final CarbonPlayer target, final String nick) {
if (handler.flags().contains("nickname")) { // Lazy since the sender might not have permission to set the nickname
// Lazy since the player might not have permission to set the nickname final Supplier<Component> parsedNick = Suppliers.memoize(() -> parseNickname(sender, nick));
final var ref = new Object() {
@Nullable Component cached = null;
};
final Supplier<Component> lazyNickname = () -> {
if (ref.cached != null) {
return ref.cached;
}
ref.cached = ConfigChatChannel.parseMessageTags(sender, handler.flags().get("nickname")); if (sender instanceof PlayerCommander playerCommander
return ref.cached; && playerCommander.carbonPlayer().uuid().equals(target.uuid())) {
};
final @MonotonicNonNull CarbonPlayer target = handler.flags().get("player");
// Setting other player's nickname
if (target != null && !target.equals(sender)) {
this.carbonMessages.nicknameSet(target, lazyNickname.get());
this.carbonMessages.nicknameSetOthers(sender, target.username(), lazyNickname.get());
} else {
// Setting own nickname // Setting own nickname
if (!sender.hasPermission("carbon.nickname.self")) { target.displayName(parsedNick.get());
this.carbonMessages.nicknameCannotSetOwn(sender); this.carbonMessages.nicknameSet(sender, parsedNick.get());
return;
}
sender.displayName(lazyNickname.get());
this.carbonMessages.nicknameSet(sender, lazyNickname.get());
}
} else if (handler.flags().contains("player")) {
// Checking other player's nickname
final CarbonPlayer target = handler.flags().get("player");
if (target.displayName() != null) {
this.carbonMessages.nicknameShowOthers(sender, target.username(), target.displayName());
} else { } else {
this.carbonMessages.nicknameShowOthersUnset(sender, target.username()); // Setting other player's nickname
this.carbonMessages.nicknameSet(target, parsedNick.get());
this.carbonMessages.nicknameSetOthers(sender, target.username(), parsedNick.get());
} }
} else {
// Checking own nickname
if (!sender.hasPermission("carbon.nickname.self")) {
this.carbonMessages.nicknameCannotSeeOwn(sender);
return;
} }
private void checkOwnNickname(final CarbonPlayer sender) {
if (sender.displayName() != null) { if (sender.displayName() != null) {
this.carbonMessages.nicknameShow(sender, sender.username(), sender.displayName()); this.carbonMessages.nicknameShow(sender, sender.username(), sender.displayName());
} else { } else {
this.carbonMessages.nicknameShowUnset(sender, sender.username()); this.carbonMessages.nicknameShowUnset(sender, sender.username());
} }
} }
})
.build();
this.commandManager.command(command); private void checkOthersNickname(final Audience sender, final CarbonPlayer target) {
if (target.displayName() != null) {
this.carbonMessages.nicknameShowOthers(sender, target.username(), target.displayName());
} else {
this.carbonMessages.nicknameShowOthersUnset(sender, target.username());
}
}
private static Component parseNickname(final Commander sender, final String nick) {
// trim one level of quotes, to allow for nicknames which collide with command literals
return ConfigChatChannel.parseMessageTags(sender, trimQuotes(nick));
}
private static String trimQuotes(final String string) {
if (string.length() < 3) {
return string;
}
final char first = string.charAt(0);
if ((first == '\'' || first == '"') && string.endsWith(String.valueOf(first))) {
return string.substring(1, string.length() - 1);
}
return string;
} }
} }
@@ -0,0 +1,59 @@
/*
* CarbonChat
*
* Copyright (c) 2023 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.command.exception;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import net.kyori.adventure.util.ComponentMessageThrowable;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier;
@DefaultQualifier(NonNull.class)
public final class CommandCompleted extends RuntimeException implements ComponentMessageThrowable {
private static final long serialVersionUID = -2370043338216128339L;
private final @Nullable Component message;
private CommandCompleted(final @Nullable Component message) {
this.message = message;
}
public static CommandCompleted withoutMessage() {
return new CommandCompleted(null);
}
public static CommandCompleted withMessage(final ComponentLike message) {
return new CommandCompleted(message.asComponent());
}
@Override
public @Nullable Component componentMessage() {
return this.message;
}
@Override
public String getMessage() {
return PlainTextComponentSerializer.plainText().serializeOr(this.message, "No message.");
}
}
@@ -190,12 +190,6 @@ public interface CarbonMessages {
@Message("nickname.reset.others") @Message("nickname.reset.others")
void nicknameResetOthers(final Audience audience, final String target); void nicknameResetOthers(final Audience audience, final String target);
@Message("nickname.set.self.error")
void nicknameCannotSetOwn(final Audience audience);
@Message("nickname.see.self.error")
void nicknameCannotSeeOwn(final Audience audience);
/* /*
* ============================================================= * =============================================================
* ========================== Ignore =========================== * ========================== Ignore ===========================
@@ -257,6 +251,9 @@ public interface CarbonMessages {
@Message("error.command.invalid_syntax") @Message("error.command.invalid_syntax")
void errorCommandInvalidSyntax(final Audience audience, final Component syntax); void errorCommandInvalidSyntax(final Audience audience, final Component syntax);
@Message("error.command.command_needs_player")
Component commandNeedsPlayer();
/* /*
* ============================================================= * =============================================================
* =================== Command Documentation =================== * =================== Command Documentation ===================
@@ -323,12 +320,24 @@ public interface CarbonMessages {
@Message("command.nickname.argument.nickname") @Message("command.nickname.argument.nickname")
Component commandNicknameArgumentNickname(); Component commandNicknameArgumentNickname();
@Message("command.nickname.argument.reset") @Message("command.nickname.reset.description")
Component commandNicknameArgumentReset(); Component commandNicknameResetDescription();
@Message("command.nickname.set.description")
Component commandNicknameSetDescription();
@Message("command.nickname.description") @Message("command.nickname.description")
Component commandNicknameDescription(); Component commandNicknameDescription();
@Message("command.nickname.others.reset.description")
Component commandNicknameOthersResetDescription();
@Message("command.nickname.others.set.description")
Component commandNicknameOthersSetDescription();
@Message("command.nickname.others.description")
Component commandNicknameOthersDescription();
@Message("command.reload.description") @Message("command.reload.description")
Component commandReloadDescription(); Component commandReloadDescription();
@@ -39,6 +39,7 @@ import net.draycia.carbon.api.users.CarbonPlayer;
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;
import net.draycia.carbon.common.command.PlayerCommander;
import net.draycia.carbon.common.command.commands.ClearChatCommand; import net.draycia.carbon.common.command.commands.ClearChatCommand;
import net.draycia.carbon.common.command.commands.ContinueCommand; import net.draycia.carbon.common.command.commands.ContinueCommand;
import net.draycia.carbon.common.command.commands.DebugCommand; import net.draycia.carbon.common.command.commands.DebugCommand;
@@ -55,6 +56,7 @@ import net.draycia.carbon.common.command.commands.UnignoreCommand;
import net.draycia.carbon.common.command.commands.UnmuteCommand; import net.draycia.carbon.common.command.commands.UnmuteCommand;
import net.draycia.carbon.common.command.commands.UpdateUsernameCommand; import net.draycia.carbon.common.command.commands.UpdateUsernameCommand;
import net.draycia.carbon.common.command.commands.WhisperCommand; import net.draycia.carbon.common.command.commands.WhisperCommand;
import net.draycia.carbon.common.command.exception.CommandCompleted;
import net.draycia.carbon.common.config.CommandConfig; import net.draycia.carbon.common.config.CommandConfig;
import net.draycia.carbon.common.config.ConfigFactory; import net.draycia.carbon.common.config.ConfigFactory;
import net.draycia.carbon.common.messages.CarbonMessages; import net.draycia.carbon.common.messages.CarbonMessages;
@@ -178,6 +180,15 @@ public final class CloudUtils {
}); });
commandManager.registerExceptionHandler(CommandExecutionException.class, (sender, exception) -> { commandManager.registerExceptionHandler(CommandExecutionException.class, (sender, exception) -> {
final Throwable cause = exception.getCause(); final Throwable cause = exception.getCause();
if (cause instanceof CommandCompleted completed) {
final @Nullable Component msg = completed.componentMessage();
if (msg != null) {
sender.sendMessage(msg);
}
return;
}
cause.printStackTrace(); cause.printStackTrace();
final StringWriter writer = new StringWriter(); final StringWriter writer = new StringWriter();
@@ -189,4 +200,11 @@ public final class CloudUtils {
}); });
} }
public static CarbonPlayer nonPlayerMustProvidePlayer(final CarbonMessages messages, final Commander commander) {
if (commander instanceof PlayerCommander playerCommander) {
return playerCommander.carbonPlayer();
}
throw CommandCompleted.withMessage(messages.commandNeedsPlayer());
}
} }
@@ -0,0 +1,35 @@
carbon.clearchat:
description: "Clears the chat for all players except those with carbon.chearchat.exempt."
children:
carbon.clearchat.clear: true
carbon.clearchat.clear: "Clears the chat for all players except those with carbon.chearchat.exempt."
carbon.clearchat.exempt: "Exempts the player from having their chat cleared when /clearchat is executed."
carbon.debug: "Allows the sender to quickly check what carbon think's the player's primary and non-primary groups are."
carbon.help: "Shows Carbon's help menu, detailing each part of Carbon's commands."
carbon.hideidentity: "Prevents messages from the player from being blocked clientside."
carbon.ignore: "Ignores the player, hiding messages they send in chat and in whispers."
carbon.ignore.exempt: "Prevents the player from being ignored."
carbon.ignore.unignore: "Removes the player from the sender's ignore list."
carbon.itemlink: "Shows the player's held or equipped item in chat."
carbon.mute: "Mutes the player, preventing them from sending messages or whispers."
carbon.mute.exempt: "Prevents the player from being muted."
carbon.mute.info: "Shows if the player is muted or now."
carbon.mute.notify: "Notifies the player when someone else has been mute."
carbon.mute.unmute: "Unmutes the player, allowing them to use chat and send whispers."
carbon.nickname: "Checks your nickname."
carbon.nickname.set: "Set or remove your nickname."
carbon.nickname.others: "Checks other player's nicknames."
carbon.nickname.others.set: "Set or remove other player's nicknames."
carbon.nickname.style.color: "Allows the use of colors in nicknames."
carbon.nickname.style.gradient: "Allows the use of gradients in nicknames."
carbon.nickname.style.decorations: "Allows the use of decorations in nicknames."
carbon.nickname.style.hoverEvent: "Allows the use of hover events in nicknames."
carbon.nickname.style.clickEvent: "Allows the use of click events in nicknames."
carbon.nickname.style.insertion: "Allows the use of insertions in nicknames."
carbon.nickname.style.rainbow: "Allows the use of the rainbow tag in nicknames."
carbon.nickname.style.reset: "Allows the use of the reset tag in nicknames."
carbon.reload: "Reloads Carbon's config, channel settings, and translations."
carbon.whisper: "Sends private messages to other players."
carbon.whisper.continue: "Sends a message to the last player you whispered."
carbon.whisper.reply: "Sends a message to the last player who messaged you."
carbon.whisper.vanished: "Allows the player to send messages to vanished players."
@@ -32,9 +32,13 @@ command.muteinfo.argument.player=The name of the player.
command.muteinfo.argument.uuid=The UUID of the player. command.muteinfo.argument.uuid=The UUID of the player.
command.muteinfo.description=Shows if players are muted or not. command.muteinfo.description=Shows if players are muted or not.
command.nickname.argument.nickname=The nickname to set. command.nickname.argument.nickname=The nickname to set.
command.nickname.argument.player=The name of the target player. Without this flag, the sender is the target. command.nickname.argument.player=The name of the target player.
command.nickname.argument.reset=Removes any set nickname from the target. command.nickname.description=Shows your nickname.
command.nickname.description=Sets and shows player nicknames. command.nickname.set.description=Sets your nickname.
command.nickname.reset.description=Removes your nickname.
command.nickname.others.description=Shows player nicknames.
command.nickname.others.set.description=Sets player nicknames.
command.nickname.others.reset.description=Removes any set nickname from the target.
command.reload.description=Reloads Carbon's config, channel settings, and translations. Will not load or unload any channels. command.reload.description=Reloads Carbon's config, channel settings, and translations. Will not load or unload any channels.
command.reply.argument.message=The message to reply with. command.reply.argument.message=The message to reply with.
command.reply.description=Sends a message to the last player that messaged you. command.reply.description=Sends a message to the last player that messaged you.
@@ -58,9 +62,10 @@ config.reload.success=<green>Config reloaded successfully
error.command.argument_parsing=<red>Invalid command argument: <gray><throwable_message> error.command.argument_parsing=<red>Invalid command argument: <gray><throwable_message>
error.command.command_execution=<hover:show_text:"<throwable_message>\n<stacktrace>\n<gray><italic> Click to copy"><click:copy_to_clipboard:<stacktrace>><red>An internal error occurred while attempting to perform this command. error.command.command_execution=<hover:show_text:"<throwable_message>\n<stacktrace>\n<gray><italic> Click to copy"><click:copy_to_clipboard:<stacktrace>><red>An internal error occurred while attempting to perform this command.
error.command.invalid_player=No player found for input '<input>' error.command.invalid_player=No player found for input '<input>'
error.command.invalid_sender=<red>Invalid command sender. You must be of type <gray><senderType> error.command.invalid_sender=<red>Invalid command sender. You must be of type <gray><sender_type>
error.command.invalid_syntax=<red>Invalid command syntax. Correct command syntax is: <white>/</white><gray><syntax></gray> error.command.invalid_syntax=<red>Invalid command syntax. Correct command syntax is: <white>/</white><gray><syntax></gray>
error.command.no_permission=<red>I'm sorry, but you do not have permission to perform this command.\nPlease contact the server administrators if you believe that this is in error. error.command.no_permission=<red>I'm sorry, but you do not have permission to perform this command.\nPlease contact the server administrators if you believe that this is in error.
error.command.command_needs_player=<red>Non-players must provide the player argument to execute this command.
ignore.already_ignored=<red>You are already ignoring <target> ignore.already_ignored=<red>You are already ignoring <target>
ignore.exempt=<red>You cannot ignore <target> ignore.exempt=<red>You cannot ignore <target>
ignore.invalid_target=<red>No target found ignore.invalid_target=<red>No target found
@@ -81,7 +86,6 @@ mute.unmute.alert.target=<green>You have been unmuted
mute.unmute.no_target=<red>No specified player to unmute. mute.unmute.no_target=<red>No specified player to unmute.
nickname.reset.others=<green><target></green><gold>'s nickname was reset nickname.reset.others=<green><target></green><gold>'s nickname was reset
nickname.reset=<gold>Your nickname was reset nickname.reset=<gold>Your nickname was reset
nickname.see.self.error=<red>You cannot see your own nickname
nickname.set.others=<green>You set </green><target><green>'s nickname to </green><nickname> nickname.set.others=<green>You set </green><target><green>'s nickname to </green><nickname>
nickname.set=<green>Your nickname has been set to </green><nickname> nickname.set=<green>Your nickname has been set to </green><nickname>
nickname.show.others.unset=<target><red> does not have a nickname set nickname.show.others.unset=<target><red> does not have a nickname set
@@ -19,6 +19,7 @@
*/ */
package net.draycia.carbon.fabric.command; package net.draycia.carbon.fabric.command;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.draycia.carbon.common.command.Commander; import net.draycia.carbon.common.command.Commander;
import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.audience.ForwardingAudience; import net.kyori.adventure.audience.ForwardingAudience;
@@ -41,6 +42,12 @@ public interface FabricCommander extends Commander, ForwardingAudience.Single {
} }
record FabricCommanderImpl(CommandSourceStack commandSourceStack) implements FabricCommander { record FabricCommanderImpl(CommandSourceStack commandSourceStack) implements FabricCommander {
@Override
public boolean hasPermission(final String permission) {
return Permissions.check(this.commandSourceStack, permission, this.commandSourceStack.getServer().getOperatorUserPermissionLevel());
}
} }
} }
@@ -20,6 +20,7 @@
package net.draycia.carbon.fabric.command; package net.draycia.carbon.fabric.command;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.draycia.carbon.api.CarbonChat; import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.users.CarbonPlayer; import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.common.command.PlayerCommander; import net.draycia.carbon.common.command.PlayerCommander;
@@ -52,4 +53,9 @@ public record FabricPlayerCommander(
); );
} }
@Override
public boolean hasPermission(final String permission) {
return Permissions.check(this.commandSourceStack, permission, this.commandSourceStack.getServer().getOperatorUserPermissionLevel());
}
} }
+6 -100
View File
@@ -2,6 +2,7 @@ plugins {
id("carbon.shadow-platform") id("carbon.shadow-platform")
id("net.minecrell.plugin-yml.bukkit") id("net.minecrell.plugin-yml.bukkit")
id("xyz.jpenilla.run-paper") id("xyz.jpenilla.run-paper")
id("carbon.permissions")
} }
dependencies { dependencies {
@@ -47,106 +48,11 @@ bukkit {
depend = listOf("LuckPerms") depend = listOf("LuckPerms")
softDepend = listOf("PlaceholderAPI", "EssentialsDiscord", "DiscordSRV") softDepend = listOf("PlaceholderAPI", "EssentialsDiscord", "DiscordSRV")
website = GITHUB_REPO_URL website = GITHUB_REPO_URL
permissions {
register("carbon.clearchat") {
description = "Clears the chat for all players except those with carbon.chearchat.exempt."
childrenMap = mapOf("carbon.clearchat.clear" to true)
}
register("carbon.clearchat.clear") {
description = "Clears the chat for all players except those with carbon.chearchat.exempt."
}
register("carbon.clearchat.exempt") {
description = "Exempts the player from having their chat cleared when /clearchat is executed."
}
register("carbon.debug") {
description = "Allows the sender to quickly check what carbon think's the player's primary and non-primary groups are."
}
register("carbon.help") {
description = "Shows Carbon's help menu, detailing each part of Carbon's commands."
}
register("carbon.hideidentity") {
description = "Prevents messages from the player from being blocked clientside."
}
register("carbon.ignore") {
description = "Ignores the player, hiding messages they send in chat and in whispers."
}
register("carbon.ignore.exempt") {
description = "Prevents the player from being ignored."
}
register("carbon.ignore.unignore") {
description = "Removes the player from the sender's ignore list."
}
register("carbon.itemlink") {
description = "Shows the player's held or equipped item in chat."
}
register("carbon.mute") {
description = "Mutes the player, preventing them from sending messages or whispers."
}
register("carbon.mute.exempt") {
description = "Prevents the player from being muted."
}
register("carbon.mute.info") {
description = "Shows if the player is muted or now."
}
register("carbon.mute.notify") {
description = "Notifies the player when someone else has been mute."
}
register("carbon.mute.unmute") {
description = "Unmutes the player, allowing them to use chat and send whispers."
}
register("carbon.nickname") {
description = "The nickname command, by default shows your nickname."
}
register("carbon.nickname.others") {
description = "Checks/sets other player's nicknames."
}
register("carbon.nickname.see") {
description = "Checks your/other player's nicknames."
}
register("carbon.nickname.self") {
description = "Checks/sets your nickname."
}
register("carbon.nickname.set") {
description = "Sets your/other player's nicknames."
}
register("carbon.nickname.style.color") {
description = "Allows the use of colors in nicknames."
}
register("carbon.nickname.style.gradient") {
description = "Allows the use of gradients in nicknames."
}
register("carbon.nickname.style.decorations") {
description = "Allows the use of decorations in nicknames."
}
register("carbon.nickname.style.hoverEvent") {
description = "Allows the use of hover events in nicknames."
}
register("carbon.nickname.style.clickEvent") {
description = "Allows the use of click events in nicknames."
}
register("carbon.nickname.style.insertion") {
description = "Allows the use of insertions in nicknames."
}
register("carbon.nickname.style.rainbow") {
description = "Allows the use of the rainbow tag in nicknames."
}
register("carbon.nickname.style.reset") {
description = "Allows the use of the reset tag in nicknames."
}
register("carbon.reload") {
description = "Reloads Carbon's config, channel settings, and translations."
}
register("carbon.whisper") {
description = "Sends private messages to other players."
}
register("carbon.whisper.continue") {
description = "Sends a message to the last player you whispered."
}
register("carbon.whisper.reply") {
description = "Sends a message to the last player who messaged you."
}
register("carbon.whisper.vanished") {
description = "Allows the player to send messages to vanished players."
} }
carbonPermission.permissions.get().forEach {
bukkit.permissions.register(it.string) {
description = it.description
childrenMap = it.children
} }
} }
@@ -42,6 +42,11 @@ public interface PaperCommander extends Commander, ForwardingAudience.Single {
return this.commandSender; return this.commandSender;
} }
@Override
public boolean hasPermission(final String permission) {
return this.commandSender.hasPermission(permission);
}
} }
} }
@@ -51,4 +51,9 @@ public record PaperPlayerCommander(
return requireNonNull(this.server.userManager().carbonPlayer(this.player.getUniqueId()).join().player(), "No CarbonPlayer for logged in Player!"); return requireNonNull(this.server.userManager().carbonPlayer(this.player.getUniqueId()).join().player(), "No CarbonPlayer for logged in Player!");
} }
@Override
public boolean hasPermission(final String permission) {
return this.player.hasPermission(permission);
}
} }