Identity changes / improvements

This commit is contained in:
Draycia committed 2020-10-16 22:48:14 -07:00
1 parent 00de18d936
commit 00f1a23f4f
11 files changed
+49 -37

No files matched your search

@@ -3,6 +3,7 @@ package net.draycia.carbon.api.channels;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.api.users.PlayerUser;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -36,9 +37,11 @@ public interface ChatChannel extends Audience {
boolean canPlayerSee(@NonNull PlayerUser target, boolean checkSpying);
void sendComponents(@NonNull final Map<? extends CarbonUser, Component> components);
void sendComponents(@NonNull final Identity identity,
@NonNull final Map<? extends CarbonUser, Component> components);
void sendComponentsAndLog(@NonNull final Map<? extends CarbonUser, Component> components);
void sendComponentsAndLog(@NonNull final Identity identity,
@NonNull final Map<? extends CarbonUser, Component> components);
@NonNull String name();
@@ -2,10 +2,11 @@ package net.draycia.carbon.api.users;
import net.draycia.carbon.api.channels.ChatChannel;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.identity.Identified;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
public interface CarbonUser extends Audience {
public interface CarbonUser extends Audience, Identified {
boolean hasPermission(@NonNull String permission);
@@ -86,7 +86,7 @@ public class BukkitChatListener implements Listener {
continue;
}
entry.getKey().sendMessage(Identity.identity(event.getPlayer().getUniqueId()), entry.getValue());
entry.getKey().sendMessage(user.identity(), entry.getValue());
if (user.equals(entry.getKey())) {
event.setFormat(PlainComponentSerializer.plain().serialize(entry.getValue())
@@ -95,7 +95,7 @@ public class BukkitChatListener implements Listener {
}
} else {
Bukkit.getScheduler().runTaskAsynchronously(this.carbonChat, () -> {
selectedChannel.sendComponentsAndLog(
selectedChannel.sendComponentsAndLog(user.identity(),
selectedChannel.parseMessage(user, event.getMessage(), false));
// if (this.carbonChat.getConfig().getBoolean("show-tips")) {
@@ -1,11 +1,10 @@
package net.draycia.carbon.bukkit.users;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.users.ConsoleUser;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.audience.ForwardingAudience;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.bukkit.Bukkit;
import org.bukkit.command.ConsoleCommandSender;
@@ -13,22 +12,23 @@ import org.bukkit.plugin.Plugin;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Collections;
public class BukkitConsoleUser implements ConsoleUser, ForwardingAudience.Single {
public class BukkitConsoleUser implements ConsoleUser, ForwardingAudience {
private @NonNull final CarbonChat carbonChat;
private @NonNull final Iterable<Audience> audience;
private @NonNull final Audience audience;
public BukkitConsoleUser(@NonNull final ConsoleCommandSender sender) {
final Plugin plugin = Bukkit.getPluginManager().getPlugin("CarbonChat-Bukkit");
final Plugin plugin = Bukkit.getPluginManager().getPlugin("CarbonChat");
this.carbonChat = CarbonChatProvider.carbonChat();
this.audience = Collections.singletonList(BukkitAudiences.create(plugin).sender(sender));
this.audience = BukkitAudiences.create(plugin).sender(sender);
}
@Override
public @NonNull Iterable<? extends Audience> audiences() {
public @NonNull Identity identity() {
return Identity.nil();
}
@Override
public @NonNull Audience audience() {
return this.audience;
}
@@ -51,7 +51,7 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single {
private transient @Nullable ChatChannel selectedChannel = null;
public BukkitPlayerUser() {
this.carbonChat = (CarbonChatBukkit) Bukkit.getPluginManager().getPlugin("CarbonChat-Bukkit");
this.carbonChat = (CarbonChatBukkit) Bukkit.getPluginManager().getPlugin("CarbonChat");
}
public BukkitPlayerUser(@NonNull final UUID uuid) {
@@ -59,6 +59,11 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single {
this.uuid = uuid;
}
@Override
public @NonNull Identity identity() {
return Identity.identity(this.uuid());
}
@Override
public @NonNull Audience audience() {
return this.carbonChat.messageProcessor().audiences().player(this.uuid());
@@ -382,13 +387,13 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single {
if (offlineTarget.isOnline()) {
if (offlineSender.isOnline()) {
sender.sendMessage(Identity.identity(sender.uuid()), toPlayerComponent);
sender.sendMessage(sender.identity(), toPlayerComponent);
if (sender.shadowMuted()) {
return;
}
this.sendMessage(Identity.identity(sender.uuid()), fromPlayerComponent);
this.sendMessage(sender.identity(), fromPlayerComponent);
sender.replyTarget(this);
this.replyTarget(sender);
@@ -426,7 +431,7 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single {
return;
}
sender.sendMessage(Identity.identity(sender.uuid()), toPlayerComponent);
sender.sendMessage(sender.identity(), toPlayerComponent);
this.carbonChat.messageManager().sendMessage("whisper-component", sender.uuid(), byteArray -> {
byteArray.writeLong(this.uuid().getMostSignificantBits());
@@ -447,7 +452,7 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single {
continue;
}
user.sendMessage(Identity.identity(sender.uuid()), this.carbonChat.messageProcessor()
user.sendMessage(sender.identity(), this.carbonChat.messageProcessor()
.processMessage(this.carbonChat.translations().spyWhispers(), "message", message,
"targetname", targetOfflineName, "sendername", senderOfflineName, "target", targetName,
"sender", senderName));
@@ -196,30 +196,30 @@ public class CarbonChatChannel implements TextChannel {
}
@Override
public void sendComponents(@NonNull final Map<? extends CarbonUser, Component> components) {
public void sendComponents(@NonNull final Identity identity,
@NonNull final Map<? extends CarbonUser, Component> components) {
for (final Map.Entry<? extends CarbonUser, Component> entry : components.entrySet()) {
if (entry.getValue().equals(Component.empty())) {
continue;
}
// TODO: pass in Identity sender?
entry.getKey().sendMessage(Identity.nil(), entry.getValue());
entry.getKey().sendMessage(identity, entry.getValue());
}
}
@Override
public void sendComponentsAndLog(@NonNull final Map<? extends CarbonUser, Component> components) {
public void sendComponentsAndLog(@NonNull final Identity identity,
@NonNull final Map<? extends CarbonUser, Component> components) {
for (final Map.Entry<? extends CarbonUser, Component> entry : components.entrySet()) {
if (entry.getValue().equals(Component.empty())) {
continue;
}
// TODO: pass in Identifiable sender?
entry.getKey().sendMessage(Identity.nil(), entry.getValue());
entry.getKey().sendMessage(identity, entry.getValue());
if (entry instanceof ConsoleUser) {
this.carbonChat.messageProcessor().audiences().console()
.sendMessage(Identity.nil(), entry.getValue());
.sendMessage(identity, entry.getValue());
}
}
}
@@ -308,7 +308,7 @@ public class CarbonChatChannel implements TextChannel {
public void sendComponent(@NonNull final PlayerUser player, @NonNull final Component component) {
for (final PlayerUser user : this.audiences()) {
if (!user.ignoringUser(player)) {
user.sendMessage(Identity.identity(player.uuid()), component);
user.sendMessage(player.identity(), component);
}
}
}
@@ -177,20 +177,22 @@ public class CarbonWhisperChannel implements WhisperChannel {
}
@Override
public void sendComponents(@NonNull final Map<? extends CarbonUser, Component> components) {
public void sendComponents(@NonNull final Identity identity,
@NonNull final Map<? extends CarbonUser, Component> components) {
for (final Map.Entry<? extends CarbonUser, Component> entry : components.entrySet()) {
entry.getKey().sendMessage(Identity.nil(), entry.getValue());
entry.getKey().sendMessage(identity, entry.getValue());
}
}
@Override
public void sendComponentsAndLog(@NonNull final Map<? extends CarbonUser, Component> components) {
public void sendComponentsAndLog(@NonNull final Identity identity,
@NonNull final Map<? extends CarbonUser, Component> components) {
for (final Map.Entry<? extends CarbonUser, Component> entry : components.entrySet()) {
entry.getKey().sendMessage(Identity.nil(), entry.getValue());
if (entry.getKey() instanceof ConsoleUser) {
this.carbonChat.messageProcessor().audiences().console()
.sendMessage(Identity.nil(), entry.getValue());
.sendMessage(identity, entry.getValue());
}
}
}
@@ -61,6 +61,7 @@ public class AliasedChannelCommand {
private void sendMessage(@NonNull final CommandContext<CarbonUser> context) {
context.<String>getOptional("message").ifPresent(message -> {
this.chatChannel().sendComponentsAndLog(
context.getSender().identity(),
this.chatChannel().parseMessage((PlayerUser) context.getSender(), message, false));
});
}
@@ -68,7 +68,7 @@ public class ChannelCommand {
final ChatChannel channel = context.get("channel");
final String message = context.get("message");
channel.sendComponentsAndLog(channel.parseMessage((PlayerUser) context.getSender(),
channel.sendComponentsAndLog(context.getSender().identity(), channel.parseMessage((PlayerUser) context.getSender(),
message, false));
}
@@ -50,14 +50,14 @@ public class MeCommand {
"displayname", user.displayName(), "message", message);
if (user.shadowMuted()) {
user.sendMessage(Identity.identity(user.uuid()), component);
user.sendMessage(user.identity(), component);
} else {
for (final PlayerUser onlineUser : this.carbonChat.userService().onlineUsers()) {
if (onlineUser.ignoringUser(user)) {
continue;
}
onlineUser.sendMessage(Identity.identity(user.uuid()), component);
onlineUser.sendMessage(user.identity(), component);
}
}
}
@@ -75,7 +75,7 @@ public class SudoChannelCommand {
final ChatChannel channel = context.get("channel");
final String message = context.get("message");
channel.sendComponentsAndLog(channel.parseMessage(user, message, false));
channel.sendComponentsAndLog(user.identity(), channel.parseMessage(user, message, false));
}
}