mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 14:38:48 +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
@@ -54,11 +54,11 @@ public interface ChatChannel extends Keyed, ChatComponentRenderer {
|
||||
/**
|
||||
* Checks if the player may receive messages from this channel.
|
||||
*
|
||||
* @param audience the audience that's receiving messages
|
||||
* @param player the player that's receiving messages
|
||||
* @return if the player may receive messages
|
||||
* @since 2.0.0
|
||||
*/
|
||||
ChannelPermissionResult hearingPermitted(final Audience audience);
|
||||
ChannelPermissionResult hearingPermitted(final CarbonPlayer player);
|
||||
|
||||
/**
|
||||
* Returns a list of all recipients that will receive messages from the sender.
|
||||
@@ -77,7 +77,7 @@ public interface ChatChannel extends Keyed, ChatComponentRenderer {
|
||||
* @return the recipients that may receive messages
|
||||
* @since 2.0.0
|
||||
*/
|
||||
Set<Audience> filterRecipients(final CarbonPlayer sender, final Set<Audience> recipients);
|
||||
Set<CarbonPlayer> filterRecipients(final CarbonPlayer sender, final Set<CarbonPlayer> recipients);
|
||||
|
||||
/**
|
||||
* Messages will be sent in this channel if they start with this prefix.
|
||||
|
||||
@@ -85,7 +85,7 @@ public final class BukkitChatListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
final var recipients = new ArrayList<>(channel.filterRecipients(sender, event.viewers()));
|
||||
final var recipients = new ArrayList<>(channel.recipients(sender));
|
||||
|
||||
final var renderers = new ArrayList<KeyedRenderer>();
|
||||
renderers.add(keyedRenderer(key("carbon", "default"), channel));
|
||||
|
||||
@@ -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