Add missing impl

This commit is contained in:
Draycia committed 2021-05-21 03:59:13 -07:00
1 parent 83d755e356
commit a213ed8d9f
6 files changed
+27 -17

No files matched your search

@@ -46,6 +46,8 @@ public interface ChatChannel extends Keyed {
/**
* Represents the result of a channel permission check.
*
* @since 2.0.0
*/
record ChannelPermissionResult(boolean permitted, Component reason) {
@@ -1,16 +1,13 @@
package net.draycia.carbon.api.events;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.util.ChatComponentRenderer;
import net.draycia.carbon.api.util.KeyedRenderer;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
import java.util.List;
import java.util.Map;
/**
* {@link CancellableCarbonEvent} that's called when chat components are rendered for online players.
@@ -18,7 +18,7 @@ import org.checkerframework.framework.qual.DefaultQualifier;
public interface KeyedRenderer extends Keyed, ChatComponentRenderer {
/**
* Creates a new renderer with the corresponding key
* Creates a new renderer with the corresponding key.
*
* @param key the renderer's key
* @param renderer the chat renderer
@@ -29,6 +29,11 @@ public interface KeyedRenderer extends Keyed, ChatComponentRenderer {
return new Impl(key, renderer);
}
/**
* Implementation of the keyed renderer.
*
* @since 2.0.0
*/
record Impl(@NonNull Key key, ChatComponentRenderer renderer) implements KeyedRenderer {
@Override
@@ -38,9 +38,7 @@ public final class BukkitChatListener implements Listener {
for (final Player bukkitRecipient : event.recipients()) {
final var recipient = this.userManager.carbonPlayer(bukkitRecipient.getUniqueId());
// The naming is a little backwards, ChatChannel#mayReceiveMessages
// TODO: Change it at some point
if (recipient != null && channel.mayReceiveMessages(recipient)) {
if (recipient != null && channel.hearingPermitted(recipient).permitted()) {
recipients.add(recipient);
}
}
@@ -30,18 +30,26 @@ public class VanillaChatChannel implements ChatChannel {
return translatable("chat.type.text", name.color(TextColor.color(0xff0000)), message);
};
@Override
public boolean mayReceiveMessages(final CarbonPlayer player) {
return true;
}
@Override
public boolean maySendMessages(final CarbonPlayer player) {
return true;
}
private final Key key = Key.key("carbon", "vanilla");
@Override
public ChatComponentRenderer renderer() {
return this.renderer;
}
@Override
public ChannelPermissionResult speechPermitted(final CarbonPlayer carbonPlayer) {
return ChannelPermissionResult.allowed();
}
@Override
public ChannelPermissionResult hearingPermitted(final CarbonPlayer carbonPlayer) {
return ChannelPermissionResult.allowed();
}
@Override
public @NonNull Key key() {
return this.key;
}
}
@@ -45,7 +45,7 @@ public final class SpongeChatListener {
for (final ServerPlayer spongeRecipient : Sponge.server().onlinePlayers()) {
final var recipient = this.userManager.carbonPlayer(spongeRecipient.uniqueId());
if (recipient != null && channel.mayReceiveMessages(recipient)) {
if (recipient != null && channel.hearingPermitted(recipient).permitted()) {
recipients.add(recipient);
}
}