mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 14:38:49 +00:00
Add placeholder to clearchat broadcast, fix console not logging chat
This commit is contained in:
6 files changed
+18
-23
No files matched your search
@@ -98,7 +98,7 @@ public final class BasicChatChannel implements ChatChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelPermissionResult hearingPermitted(final Audience audience) {
|
||||
public ChannelPermissionResult hearingPermitted(final CarbonPlayer player) {
|
||||
return ChannelPermissionResult.allowed();
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ public final class BasicChatChannel implements ChatChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Audience> filterRecipients(final CarbonPlayer sender, final Set<Audience> recipients) {
|
||||
public Set<CarbonPlayer> filterRecipients(final CarbonPlayer sender, final Set<CarbonPlayer> recipients) {
|
||||
recipients.removeIf(it -> !this.hearingPermitted(it).permitted());
|
||||
|
||||
return recipients;
|
||||
|
||||
@@ -41,7 +41,6 @@ import net.draycia.carbon.common.messages.placeholders.StringPlaceholderResolver
|
||||
import net.draycia.carbon.common.messages.placeholders.UUIDPlaceholderResolver;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.permission.PermissionChecker;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.moonshine.Moonshine;
|
||||
import net.kyori.moonshine.exception.scan.UnscannableMethodException;
|
||||
@@ -56,6 +55,7 @@ import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||
import org.spongepowered.configurate.objectmapping.meta.Setting;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static net.kyori.adventure.text.Component.empty;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
@ConfigSerializable
|
||||
@@ -140,18 +140,8 @@ public final class ConfigChatChannel implements ChatChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelPermissionResult hearingPermitted(final Audience audience) {
|
||||
final var permission = audience.get(PermissionChecker.POINTER);
|
||||
|
||||
if (permission.isEmpty()) {
|
||||
return ChannelPermissionResult.allowed();
|
||||
}
|
||||
|
||||
if (permission.get().test(this.permission() + ".see")) {
|
||||
return ChannelPermissionResult.allowed();
|
||||
}
|
||||
|
||||
return ChannelPermissionResult.denied(text("Insufficient permissions!"));
|
||||
public ChannelPermissionResult hearingPermitted(final CarbonPlayer player) {
|
||||
return ChannelPermissionResult.allowedIf(empty(), () -> player.hasPermission(this.permission() + ".see"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -171,7 +161,7 @@ public final class ConfigChatChannel implements ChatChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Audience> filterRecipients(final CarbonPlayer sender, final Set<Audience> recipients) {
|
||||
public Set<CarbonPlayer> filterRecipients(final CarbonPlayer sender, final Set<CarbonPlayer> recipients) {
|
||||
try {
|
||||
recipients.removeIf(it -> !this.hearingPermitted(it).permitted());
|
||||
} catch (final UnsupportedOperationException ignored) {
|
||||
|
||||
+5
-1
@@ -55,14 +55,18 @@ public class ClearChatCommand {
|
||||
}
|
||||
|
||||
final Component senderName;
|
||||
final String username;
|
||||
|
||||
if (handler.getSender() instanceof PlayerCommander player) {
|
||||
senderName = CarbonPlayer.renderName(player.carbonPlayer());
|
||||
username = player.carbonPlayer().username();
|
||||
} else {
|
||||
senderName = Component.text("Console");
|
||||
username = "Console";
|
||||
}
|
||||
|
||||
carbonChat.server().sendMessage(configFactory.primaryConfig().clearChatSettings().broadcast(senderName));
|
||||
carbonChat.server().sendMessage(configFactory.primaryConfig().clearChatSettings()
|
||||
.broadcast(senderName, username));
|
||||
})
|
||||
.build();
|
||||
|
||||
|
||||
@@ -57,9 +57,10 @@ public class ClearChatSettings {
|
||||
return this.iterations;
|
||||
}
|
||||
|
||||
public Component broadcast(final Component displayName) {
|
||||
public Component broadcast(final Component displayName, final String username) {
|
||||
return MiniMessage.miniMessage().deserialize(this.broadcast,
|
||||
TemplateResolver.templates(Template.template("display_name", displayName)));
|
||||
TemplateResolver.templates(Template.template("display_name", displayName),
|
||||
Template.template("username", username)));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user