Refactor ChatUser

This commit is contained in:
Draycia committed 2020-10-13 01:11:22 -07:00
1 parent f9515f98fb
commit 941d7ee096
56 files changed
+455 -354

No files matched your search

@@ -11,7 +11,7 @@ import net.draycia.carbon.api.events.ChatFormatEvent;
import net.draycia.carbon.api.events.MessageContextEvent;
import net.draycia.carbon.api.events.PreChatFormatEvent;
import net.draycia.carbon.api.events.ReceiverContextEvent;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.api.Context;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
@@ -51,7 +51,7 @@ public class CarbonChatChannel implements TextChannel {
}
@Override
public boolean testContext(@NonNull final ChatUser sender, @NonNull final ChatUser target) {
public boolean testContext(@NonNull final CarbonUser sender, @NonNull final CarbonUser target) {
final ReceiverContextEvent event = new ReceiverContextEvent(this, sender, target);
CarbonEvents.post(event);
@@ -60,15 +60,15 @@ public class CarbonChatChannel implements TextChannel {
}
@Override
public boolean canPlayerUse(@NonNull final ChatUser user) {
public boolean canPlayerUse(@NonNull final CarbonUser user) {
return user.permissible() && user.hasPermission("carbonchat.channels." + this.name() + ".use");
}
@Override
public @NonNull List<@NonNull ChatUser> audiences() {
final List<ChatUser> audience = new ArrayList<>();
public @NonNull List<@NonNull CarbonUser> audiences() {
final List<CarbonUser> audience = new ArrayList<>();
for (final ChatUser user : this.carbonChat.userService().onlineUsers()) {
for (final CarbonUser user : this.carbonChat.userService().onlineUsers()) {
if (this.canPlayerSee(user, true)) {
audience.add(user);
}
@@ -97,7 +97,7 @@ public class CarbonChatChannel implements TextChannel {
// }
@Override
public @NonNull Map<ChatUser, Component> parseMessage(@NonNull final ChatUser user, @NonNull final Collection<@NonNull ChatUser> recipients, @NonNull final String message, final boolean fromRemote) {
public @NonNull Map<CarbonUser, Component> parseMessage(@NonNull final CarbonUser user, @NonNull final Collection<@NonNull CarbonUser> recipients, @NonNull final String message, final boolean fromRemote) {
//this.updateUserNickname(user);
final MessageContextEvent event = new MessageContextEvent(this, user);
@@ -130,10 +130,10 @@ public class CarbonChatChannel implements TextChannel {
displayName = user.displayName();
}
final Map<ChatUser, Component> users = new HashMap<>();
final Map<CarbonUser, Component> users = new HashMap<>();
// Iterate through players who should receive messages in this channel
for (final ChatUser target : recipients) {
for (final CarbonUser target : recipients) {
// Call second format event. Used for relational stuff (placeholders etc)
final ChatFormatEvent formatEvent = new ChatFormatEvent(user, target, this, preFormatEvent.format(), preFormatEvent.message());
@@ -194,8 +194,8 @@ public class CarbonChatChannel implements TextChannel {
}
@Override
public void sendComponents(@NonNull final Map<ChatUser, Component> components) {
for (final Map.Entry<ChatUser, Component> entry : components.entrySet()) {
public void sendComponents(@NonNull final Map<CarbonUser, Component> components) {
for (final Map.Entry<CarbonUser, Component> entry : components.entrySet()) {
if (entry.getValue().equals(Component.empty())) {
continue;
}
@@ -205,8 +205,8 @@ public class CarbonChatChannel implements TextChannel {
}
@Override
public void sendComponentsAndLog(@NonNull final Map<ChatUser, Component> components) {
for (final Map.Entry<ChatUser, Component> entry : components.entrySet()) {
public void sendComponentsAndLog(@NonNull final Map<CarbonUser, Component> components) {
for (final Map.Entry<CarbonUser, Component> entry : components.entrySet()) {
if (entry.getValue().equals(Component.empty())) {
continue;
}
@@ -220,11 +220,11 @@ public class CarbonChatChannel implements TextChannel {
}
@Override
public @NonNull Map<ChatUser, Component> parseMessage(@NonNull final ChatUser user, @NonNull final String message, final boolean fromRemote) {
public @NonNull Map<CarbonUser, Component> parseMessage(@NonNull final CarbonUser user, @NonNull final String message, final boolean fromRemote) {
return this.parseMessage(user, this.audiences(), message, fromRemote);
}
public @Nullable String format(@NonNull final ChatUser user) {
public @Nullable String format(@NonNull final CarbonUser user) {
for (final String group : this.groupOverrides()) {
if (this.userHasGroup(user, group)) {
final String format = this.format(group);
@@ -242,7 +242,7 @@ public class CarbonChatChannel implements TextChannel {
}
}
private boolean userHasGroup(@NonNull final ChatUser user, @NonNull final String group) {
private boolean userHasGroup(@NonNull final CarbonUser user, @NonNull final String group) {
if (user.hasGroup(group)) {
return true;
}
@@ -254,7 +254,7 @@ public class CarbonChatChannel implements TextChannel {
return false;
}
private @NonNull String firstFoundUserFormat(@NonNull final ChatUser user) {
private @NonNull String firstFoundUserFormat(@NonNull final CarbonUser user) {
for (final Group group : user.groups()) {
final String groupFormat = this.format(group);
@@ -266,7 +266,7 @@ public class CarbonChatChannel implements TextChannel {
return this.defaultFormat();
}
private @NonNull String primaryGroupFormat(@NonNull final ChatUser user) {
private @NonNull String primaryGroupFormat(@NonNull final CarbonUser user) {
final Group primaryGroup = user.primaryGroup();
final String primaryGroupFormat = this.format(primaryGroup);
@@ -291,7 +291,7 @@ public class CarbonChatChannel implements TextChannel {
return this.options().format(group);
}
private boolean isUserSpying(@NonNull final ChatUser sender, @NonNull final ChatUser target) {
private boolean isUserSpying(@NonNull final CarbonUser sender, @NonNull final CarbonUser target) {
if (!this.canPlayerSee(sender, target, false)) {
return target.channelSettings(this).spying();
}
@@ -300,8 +300,8 @@ public class CarbonChatChannel implements TextChannel {
}
@Override
public void sendComponent(@NonNull final ChatUser player, @NonNull final Component component) {
for (final ChatUser user : this.audiences()) {
public void sendComponent(@NonNull final CarbonUser player, @NonNull final Component component) {
for (final CarbonUser user : this.audiences()) {
if (!user.ignoringUser(player)) {
user.sendMessage(component);
}
@@ -316,7 +316,7 @@ public class CarbonChatChannel implements TextChannel {
}
@Override
public boolean canPlayerSee(@NonNull final ChatUser target, final boolean checkSpying) {
public boolean canPlayerSee(@NonNull final CarbonUser target, final boolean checkSpying) {
if (checkSpying && target.permissible() && target.hasPermission("carbonchat.spy." + this.name())) {
if (target.channelSettings(this).spying()) {
return true;
@@ -334,7 +334,7 @@ public class CarbonChatChannel implements TextChannel {
return true;
}
public boolean canPlayerSee(@NonNull final ChatUser sender, @NonNull final ChatUser target, final boolean checkSpying) {
public boolean canPlayerSee(@NonNull final CarbonUser sender, @NonNull final CarbonUser target, final boolean checkSpying) {
if (!this.canPlayerSee(target, checkSpying)) {
return false;
@@ -348,7 +348,7 @@ public class CarbonChatChannel implements TextChannel {
}
@Override
public @Nullable TextColor channelColor(@NonNull final ChatUser user) {
public @Nullable TextColor channelColor(@NonNull final CarbonUser user) {
final TextColor userColor = user.channelSettings(this).color();
if (userColor != null) {
@@ -6,7 +6,7 @@ import net.draycia.carbon.api.channels.WhisperChannel;
import net.draycia.carbon.api.events.ChatComponentEvent;
import net.draycia.carbon.api.events.ChatFormatEvent;
import net.draycia.carbon.api.events.misc.CarbonEvents;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.api.users.ConsoleUser;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
@@ -26,42 +26,42 @@ public class CarbonWhisperChannel implements WhisperChannel {
private @NonNull final CarbonChat carbonChat;
private @NonNull final ChatUser sender;
private @NonNull final ChatUser audience;
private @NonNull final CarbonUser sender;
private @NonNull final CarbonUser audience;
public CarbonWhisperChannel(@NonNull final ChatUser sender, @NonNull final ChatUser audience) {
public CarbonWhisperChannel(@NonNull final CarbonUser sender, @NonNull final CarbonUser audience) {
this.carbonChat = CarbonChatProvider.carbonChat();
this.sender = sender;
this.audience = audience;
}
@Override
public @NonNull ChatUser sender() {
public @NonNull CarbonUser sender() {
return this.sender;
}
@Override
public @NonNull ChatUser audience() {
public @NonNull CarbonUser audience() {
return this.audience;
}
@Override
public @Nullable TextColor channelColor(@NonNull final ChatUser user) {
public @Nullable TextColor channelColor(@NonNull final CarbonUser user) {
return NamedTextColor.WHITE;
}
@Override
public @NonNull Map<ChatUser, Component> parseMessage(@NonNull final ChatUser user, @NonNull final String message,
final boolean fromRemote) {
public @NonNull Map<CarbonUser, Component> parseMessage(@NonNull final CarbonUser user, @NonNull final String message,
final boolean fromRemote) {
return this.parseMessage(user, Collections.singleton(this.audience()), message, fromRemote);
}
@Override
public @NonNull Map<ChatUser, Component> parseMessage(@NonNull final ChatUser user,
@NonNull final Collection<@NonNull ChatUser> recipients,
@NonNull final String message, final boolean fromRemote) {
public @NonNull Map<CarbonUser, Component> parseMessage(@NonNull final CarbonUser user,
@NonNull final Collection<@NonNull CarbonUser> recipients,
@NonNull final String message, final boolean fromRemote) {
// TODO: extract to method, this is just the same thing but twice
final Map<ChatUser, Component> result = new HashMap<>();
final Map<CarbonUser, Component> result = new HashMap<>();
// Formats
final String senderFormat = this.senderFormat();
@@ -160,30 +160,30 @@ public class CarbonWhisperChannel implements WhisperChannel {
}
@Override
public boolean canPlayerUse(@NonNull final ChatUser user) {
public boolean canPlayerUse(@NonNull final CarbonUser user) {
return user.equals(this.sender);
}
@Override
public boolean canPlayerSee(@NonNull final ChatUser sender, @NonNull final ChatUser target, final boolean checkSpying) {
public boolean canPlayerSee(@NonNull final CarbonUser sender, @NonNull final CarbonUser target, final boolean checkSpying) {
return (checkSpying && target.spyingWhispers()) || (sender.equals(this.sender) && target.equals(this.audience));
}
@Override
public boolean canPlayerSee(@NonNull final ChatUser target, final boolean checkSpying) {
public boolean canPlayerSee(@NonNull final CarbonUser target, final boolean checkSpying) {
return false;
}
@Override
public void sendComponents(@NonNull final Map<ChatUser, Component> components) {
for (final Map.Entry<ChatUser, Component> entry : components.entrySet()) {
public void sendComponents(@NonNull final Map<CarbonUser, Component> components) {
for (final Map.Entry<CarbonUser, Component> entry : components.entrySet()) {
entry.getKey().sendMessage(entry.getValue());
}
}
@Override
public void sendComponentsAndLog(@NonNull final Map<ChatUser, Component> components) {
for (final Map.Entry<ChatUser, Component> entry : components.entrySet()) {
public void sendComponentsAndLog(@NonNull final Map<CarbonUser, Component> components) {
for (final Map.Entry<CarbonUser, Component> entry : components.entrySet()) {
entry.getKey().sendMessage(entry.getValue());
if (entry.getKey() instanceof ConsoleUser) {
@@ -6,7 +6,8 @@ import com.intellectualsites.commands.context.CommandContext;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.channels.TextChannel;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.api.users.PlayerUser;
import org.checkerframework.checker.nullness.qual.NonNull;
public class AliasedChannelCommand {
@@ -17,14 +18,14 @@ public class AliasedChannelCommand {
private @NonNull final String commandName;
public AliasedChannelCommand(@NonNull final CommandManager<ChatUser> commandManager, @NonNull final TextChannel chatChannel) {
public AliasedChannelCommand(@NonNull final CommandManager<CarbonUser> commandManager, @NonNull final TextChannel chatChannel) {
this.carbonChat = CarbonChatProvider.carbonChat();
this.chatChannel = chatChannel;
this.commandName = chatChannel.key();
commandManager.command(
commandManager.commandBuilder(this.commandName)
.withSenderType(ChatUser.class) // player
.withSenderType(PlayerUser.class) // player
.withPermission("carbonchat.channel")
.handler(this::channel)
.build()
@@ -32,7 +33,7 @@ public class AliasedChannelCommand {
commandManager.command(
commandManager.commandBuilder(this.commandName)
.withSenderType(ChatUser.class) // player
.withSenderType(PlayerUser.class) // player
.withPermission("carbonchat.channel.message")
.argument(StringArgument.required("message"))
.handler(this::sendMessage)
@@ -40,8 +41,8 @@ public class AliasedChannelCommand {
);
}
private void channel(@NonNull final CommandContext<ChatUser> context) {
final ChatUser user = context.getSender();
private void channel(@NonNull final CommandContext<CarbonUser> context) {
final PlayerUser user = (PlayerUser)context.getSender();
if (user.channelSettings(this.chatChannel()).ignored()) {
user.sendMessage(this.carbonChat.messageProcessor().processMessage(this.chatChannel().cannotUseMessage(),
@@ -54,7 +55,7 @@ public class AliasedChannelCommand {
user.selectedChannel(this.chatChannel());
}
private void sendMessage(@NonNull final CommandContext<ChatUser> context) {
private void sendMessage(@NonNull final CommandContext<CarbonUser> context) {
context.<String>get("message").ifPresent(message -> {
this.chatChannel().sendComponentsAndLog(
this.chatChannel().parseMessage(context.getSender(), message, false));
@@ -8,7 +8,8 @@ import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.channels.TextChannel;
import net.draycia.carbon.api.commands.settings.CommandSettings;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.api.users.PlayerUser;
import net.draycia.carbon.common.utils.CommandUtils;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -16,7 +17,7 @@ public class ChannelCommand {
private @NonNull final CarbonChat carbonChat;
public ChannelCommand(@NonNull final CommandManager<ChatUser> commandManager) {
public ChannelCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("channel");
@@ -28,7 +29,7 @@ public class ChannelCommand {
commandManager.command(
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
commandManager.createDefaultCommandMeta())
.withSenderType(ChatUser.class) // player
.withSenderType(PlayerUser.class) // player
.withPermission("carbonchat.channel")
.argument(CommandUtils.channelArgument())
.argument(StringArgument.optional("message")) // carbonchat.channel.message
@@ -43,8 +44,8 @@ public class ChannelCommand {
);
}
private void channel(@NonNull final CommandContext<ChatUser> context) {
final ChatUser user = context.getSender();
private void channel(@NonNull final CommandContext<CarbonUser> context) {
final PlayerUser user = (PlayerUser)context.getSender();
final TextChannel channel = context.getRequired("channel");
if (user.channelSettings(channel).ignored()) {
@@ -58,7 +59,7 @@ public class ChannelCommand {
user.selectedChannel(channel);
}
private void sendMessage(@NonNull final CommandContext<ChatUser> context) {
private void sendMessage(@NonNull final CommandContext<CarbonUser> context) {
final ChatChannel channel = context.getRequired("channel");
final String message = context.getRequired("message");
@@ -5,8 +5,9 @@ import com.intellectualsites.commands.context.CommandContext;
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.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.api.commands.settings.CommandSettings;
import net.draycia.carbon.api.users.PlayerUser;
import net.draycia.carbon.common.utils.CommandUtils;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
@@ -21,7 +22,7 @@ public class ChannelListCommand {
private @NonNull final CarbonChat carbonChat;
public ChannelListCommand(@NonNull final CommandManager<ChatUser> commandManager) {
public ChannelListCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("channellist");
@@ -33,8 +34,9 @@ public class ChannelListCommand {
commandManager.command(
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
commandManager.createDefaultCommandMeta())
.withSenderType(ChatUser.class) // console & player
.withSenderType(CarbonUser.class) // console & player
.withPermission("carbonchat.channellist")
// TODO: make this return a PlayerUser
.argument(CommandUtils.optionalChatUserArgument()) // carbonchat.channellist.other
.handler(context -> {
if (context.get("user").isPresent()) {
@@ -47,13 +49,13 @@ public class ChannelListCommand {
);
}
public void channelListSelf(@NonNull final CommandContext<ChatUser> context) {
public void channelListSelf(@NonNull final CommandContext<CarbonUser> context) {
this.listAndSend(context.getSender(), context.getSender(), this.carbonChat.channelRegistry().iterator());
}
public void channelListOther(@NonNull final CommandContext<ChatUser> context) {
final ChatUser sender = context.getSender();
final ChatUser user = context.getRequired("user");
public void channelListOther(@NonNull final CommandContext<CarbonUser> context) {
final CarbonUser sender = context.getSender();
final PlayerUser user = context.getRequired("user");
if (!user.online()) {
final String mustBeOnline = this.carbonChat.translations().userMustBeOnline();
@@ -65,7 +67,7 @@ public class ChannelListCommand {
this.listAndSend(sender, user, allChannels);
}
private void listAndSend(@NonNull final ChatUser sender, @NonNull final ChatUser user,
private void listAndSend(@NonNull final CarbonUser sender, @NonNull final CarbonUser user,
@NonNull final Iterator<ChatChannel> allChannels) {
ChatChannel channel;
final List<ChatChannel> canSee = new ArrayList<>();
@@ -5,7 +5,7 @@ import com.intellectualsites.commands.context.CommandContext;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.commands.settings.CommandSettings;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -13,7 +13,7 @@ public class ChatReloadCommand {
private @NonNull final CarbonChat carbonChat;
public ChatReloadCommand(@NonNull final CommandManager<ChatUser> commandManager) {
public ChatReloadCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("chatreload");
@@ -25,14 +25,14 @@ public class ChatReloadCommand {
commandManager.command(
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
commandManager.createDefaultCommandMeta())
.withSenderType(ChatUser.class) // player & console
.withSenderType(CarbonUser.class) // player & console
.withPermission("carbonchat.reload")
.handler(this::reloadConfig)
.build()
);
}
private void reloadConfig(@NonNull final CommandContext<ChatUser> context) {
private void reloadConfig(@NonNull final CommandContext<CarbonUser> context) {
this.carbonChat.reloadConfig();
final Component message = this.carbonChat.messageProcessor()
@@ -4,7 +4,7 @@ import com.intellectualsites.commands.CommandManager;
import com.intellectualsites.commands.context.CommandContext;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.api.commands.settings.CommandSettings;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -13,7 +13,7 @@ public class ClearChatCommand {
private @NonNull final CarbonChat carbonChat;
public ClearChatCommand(@NonNull final CommandManager<ChatUser> commandManager) {
public ClearChatCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("clearchat");
@@ -25,19 +25,19 @@ public class ClearChatCommand {
commandManager.command(
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
commandManager.createDefaultCommandMeta())
.withSenderType(ChatUser.class) // player & console
.withSenderType(CarbonUser.class) // player & console
.withPermission("carbonchat.clearchat.clear")
.handler(this::clearChat)
.build()
);
}
private void clearChat(@NonNull final CommandContext<ChatUser> context) {
private void clearChat(@NonNull final CommandContext<CarbonUser> context) {
final String sender = context.getSender().name();
final String format = this.carbonChat.moderationSettings().clearChat().message();
final Component component = this.carbonChat.messageProcessor().processMessage(format, "br", "\n");
for (final ChatUser user : this.carbonChat.userService().onlineUsers()) {
for (final CarbonUser user : this.carbonChat.userService().onlineUsers()) {
if (user.hasPermission("carbonchat.clearchat.exempt")) {
final String message = this.carbonChat.translations().clearExempt();
user.sendMessage(this.carbonChat.messageProcessor().processMessage(message, "player", sender));
@@ -5,7 +5,8 @@ import com.intellectualsites.commands.context.CommandContext;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.commands.settings.CommandSettings;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.api.users.PlayerUser;
import net.draycia.carbon.common.utils.CommandUtils;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -14,7 +15,7 @@ public class IgnoreCommand {
private @NonNull final CarbonChat carbonChat;
public IgnoreCommand(@NonNull final CommandManager<ChatUser> commandManager) {
public IgnoreCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("ignore");
@@ -26,7 +27,7 @@ public class IgnoreCommand {
commandManager.command(
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
commandManager.createDefaultCommandMeta())
.withSenderType(ChatUser.class) // console & player
.withSenderType(PlayerUser.class) // player
.withPermission("carbonchat.ignore")
.argument(CommandUtils.chatUserArgument())
.handler(this::ignoreUser)
@@ -34,9 +35,9 @@ public class IgnoreCommand {
);
}
private void ignoreUser(@NonNull final CommandContext<ChatUser> context) {
final ChatUser sender = context.getSender();
final ChatUser targetUser = context.getRequired("user");
private void ignoreUser(@NonNull final CommandContext<CarbonUser> context) {
final PlayerUser sender = (PlayerUser)context.getSender();
final PlayerUser targetUser = context.getRequired("user");
if (sender.ignoringUser(targetUser)) {
sender.ignoringUser(targetUser, false);
@@ -5,8 +5,9 @@ import com.intellectualsites.commands.arguments.standard.StringArgument;
import com.intellectualsites.commands.context.CommandContext;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.api.commands.settings.CommandSettings;
import net.draycia.carbon.api.users.PlayerUser;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -14,7 +15,7 @@ public class MeCommand {
private @NonNull final CarbonChat carbonChat;
public MeCommand(@NonNull final CommandManager<ChatUser> commandManager) {
public MeCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("me");
@@ -26,16 +27,16 @@ public class MeCommand {
commandManager.command(
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
commandManager.createDefaultCommandMeta())
.withSenderType(ChatUser.class) // console & player
.withSenderType(PlayerUser.class) // player
.withPermission("carbonchat.me")
.argument(StringArgument.<ChatUser>newBuilder("message").greedy().build())
.argument(StringArgument.<CarbonUser>newBuilder("message").greedy().build())
.handler(this::message)
.build()
);
}
private void message(@NonNull final CommandContext<ChatUser> context) {
final ChatUser user = context.getSender();
private void message(@NonNull final CommandContext<CarbonUser> context) {
final PlayerUser user = (PlayerUser)context.getSender();
final String message = context.<String>getRequired("message").replace("</pre>", "");
String format = this.carbonChat.translations().roleplayFormat();
@@ -50,7 +51,7 @@ public class MeCommand {
if (user.shadowMuted()) {
user.sendMessage(component);
} else {
for (final ChatUser onlineUser : this.carbonChat.userService().onlineUsers()) {
for (final PlayerUser onlineUser : this.carbonChat.userService().onlineUsers()) {
if (onlineUser.ignoringUser(user)) {
continue;
}
@@ -7,8 +7,8 @@ import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.commands.settings.CommandSettings;
import net.draycia.carbon.api.config.ChannelSettings;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.api.users.PlayerUser;
import net.draycia.carbon.api.users.UserChannelSettings;
import net.draycia.carbon.common.channels.CarbonWhisperChannel;
import net.draycia.carbon.common.utils.CommandUtils;
@@ -20,7 +20,7 @@ public class MessageCommand {
private @NonNull final CarbonChat carbonChat;
public MessageCommand(@NonNull final CommandManager<ChatUser> commandManager) {
public MessageCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat();
final CarbonChat carbonChat = CarbonChatProvider.carbonChat();
@@ -33,18 +33,18 @@ public class MessageCommand {
commandManager.command(
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
commandManager.createDefaultCommandMeta())
.withSenderType(ChatUser.class) // player
.withSenderType(PlayerUser.class) // player
.withPermission("carbonchat.message")
.argument(CommandUtils.chatUserArgument())
.argument(StringArgument.<ChatUser>newBuilder("message").greedy().asOptional().build())
.argument(StringArgument.<CarbonUser>newBuilder("message").greedy().asOptional().build())
.handler(this::sendMessage)
.build()
);
}
private void sendMessage(@NonNull final CommandContext<ChatUser> context) {
final ChatUser sender = context.getSender();
final ChatUser receiver = context.getRequired("user");
private void sendMessage(@NonNull final CommandContext<CarbonUser> context) {
final PlayerUser sender = (PlayerUser)context.getSender();
final PlayerUser receiver = context.getRequired("user");
if (sender.equals(receiver)) {
final String message = this.carbonChat.translations().cannotWhisperSelf();
@@ -5,8 +5,9 @@ import com.intellectualsites.commands.context.CommandContext;
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.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.api.commands.settings.CommandSettings;
import net.draycia.carbon.api.users.PlayerUser;
import net.draycia.carbon.api.users.UserChannelSettings;
import net.draycia.carbon.common.utils.CommandUtils;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -15,7 +16,7 @@ public class MsgToggleCommand {
private @NonNull final CarbonChat carbonChat;
public MsgToggleCommand(@NonNull final CommandManager<ChatUser> commandManager) {
public MsgToggleCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("msgtoggle");
@@ -27,13 +28,14 @@ public class MsgToggleCommand {
commandManager.command(
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
commandManager.createDefaultCommandMeta())
.withSenderType(ChatUser.class) // player & console
.withSenderType(CarbonUser.class) // player & console
.withPermission("carbonchat.msgtoggle")
.argument(CommandUtils.optionalChatUserArgument()) // carbonchat.msgtoggle.other
.handler(context -> {
if (context.get("user").isPresent()) {
this.toggleOther(context);
} else {
} else if (context.getSender() instanceof PlayerUser) {
// TODO: better handling of this
this.toggleSelf(context);
}
})
@@ -41,8 +43,8 @@ public class MsgToggleCommand {
);
}
private void toggleSelf(@NonNull final CommandContext<ChatUser> context) {
final ChatUser user = context.getSender();
private void toggleSelf(@NonNull final CommandContext<CarbonUser> context) {
final PlayerUser user = (PlayerUser)context.getSender();
final ChatChannel channel = this.carbonChat.channelRegistry().get("whisper");
final String message;
@@ -62,9 +64,9 @@ public class MsgToggleCommand {
user.sendMessage(this.carbonChat.messageProcessor().processMessage(message));
}
private void toggleOther(@NonNull final CommandContext<ChatUser> context) {
final ChatUser sender = context.getSender();
final ChatUser user = context.getRequired("user");
private void toggleOther(@NonNull final CommandContext<CarbonUser> context) {
final CarbonUser sender = context.getSender();
final PlayerUser user = context.getRequired("user");
final ChatChannel channel = this.carbonChat.channelRegistry().get("whisper");
final String message;
@@ -4,8 +4,9 @@ import com.intellectualsites.commands.CommandManager;
import com.intellectualsites.commands.context.CommandContext;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.api.commands.settings.CommandSettings;
import net.draycia.carbon.api.users.PlayerUser;
import net.draycia.carbon.common.utils.CommandUtils;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -14,7 +15,7 @@ public class MuteCommand {
private @NonNull final CarbonChat carbonChat;
public MuteCommand(@NonNull final CommandManager<ChatUser> commandManager) {
public MuteCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("mute");
@@ -26,7 +27,7 @@ public class MuteCommand {
commandManager.command(
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
commandManager.createDefaultCommandMeta())
.withSenderType(ChatUser.class) // player
.withSenderType(CarbonUser.class) // player & console
.withPermission("carbonchat.mute")
.argument(CommandUtils.chatUserArgument())
.handler(this::mute)
@@ -34,16 +35,16 @@ public class MuteCommand {
);
}
private void mute(@NonNull final CommandContext<ChatUser> context) {
final ChatUser user = context.getSender();
final ChatUser target = context.getRequired("user");
private void mute(@NonNull final CommandContext<CarbonUser> context) {
final CarbonUser user = context.getSender();
final PlayerUser target = context.getRequired("user");
if (user.muted()) {
user.muted(false);
if (target.muted()) {
target.muted(false);
final String format = this.carbonChat.translations().noLongerMuted();
final Component message = this.carbonChat.messageProcessor().processMessage(format,
"player", target.name());
"player", target.name(), "sender", user.name());
user.sendMessage(message);
} else {
@@ -53,12 +54,12 @@ public class MuteCommand {
if (target.hasPermission("carbonchat.mute.exempt")) {
format = this.carbonChat.translations().muteExempt();
} else {
user.muted(true);
target.muted(true);
format = this.carbonChat.translations().nowMuted();
}
final Component message = this.carbonChat.messageProcessor().processMessage(format,
"player", target.name());
"player", target.name(), "sender", user.name());
user.sendMessage(message);
}
@@ -6,7 +6,8 @@ import com.intellectualsites.commands.context.CommandContext;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.commands.settings.CommandSettings;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.api.users.PlayerUser;
import net.draycia.carbon.common.utils.CommandUtils;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -14,7 +15,7 @@ public class NicknameCommand {
private @NonNull final CarbonChat carbonChat;
public NicknameCommand(@NonNull final CommandManager<ChatUser> commandManager) {
public NicknameCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("nickname");
@@ -26,14 +27,15 @@ public class NicknameCommand {
commandManager.command(
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
commandManager.createDefaultCommandMeta())
.withSenderType(ChatUser.class) // player
.withSenderType(CarbonUser.class) // player & console
.withPermission("carbonchat.nickname")
.argument(StringArgument.required("nickname"))
.argument(CommandUtils.optionalChatUserArgument()) // carbonchat.nickname.other
.handler(context -> {
if (context.get("user").isPresent()) {
this.nicknameOther(context);
} else {
} else if (context.getSender() instanceof PlayerUser) {
// TODO: better handling of this
this.nicknameSelf(context);
}
})
@@ -41,8 +43,8 @@ public class NicknameCommand {
);
}
private void nicknameSelf(@NonNull final CommandContext<ChatUser> context) {
final ChatUser user = context.getSender();
private void nicknameSelf(@NonNull final CommandContext<CarbonUser> context) {
final PlayerUser user = (PlayerUser)context.getSender();
String nickname = context.getRequired("nickname");
if (nickname.equalsIgnoreCase("off") || nickname.equalsIgnoreCase(user.name())) {
@@ -61,11 +63,11 @@ public class NicknameCommand {
user.sendMessage(this.carbonChat.messageProcessor().processMessage(
message, "nickname", nickname == null ? "" : nickname,
"user", user.name()));
"user", user.name(), "sender", context.getSender().name()));
}
private void nicknameOther(@NonNull final CommandContext<ChatUser> context) {
final ChatUser target = context.getRequired("user");
private void nicknameOther(@NonNull final CommandContext<CarbonUser> context) {
final PlayerUser target = context.getRequired("user");
String nickname = context.getRequired("nickname");
if (nickname.equalsIgnoreCase("off") ||
@@ -85,7 +87,7 @@ public class NicknameCommand {
context.getSender().sendMessage(this.carbonChat.messageProcessor().processMessage(
message, "nickname", nickname == null ? "" : nickname,
"user", target.name()));
"user", target.name(), "sender", context.getSender().name()));
}
}
@@ -5,8 +5,9 @@ import com.intellectualsites.commands.arguments.standard.StringArgument;
import com.intellectualsites.commands.context.CommandContext;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.api.commands.settings.CommandSettings;
import net.draycia.carbon.api.users.PlayerUser;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -14,7 +15,7 @@ public class ReplyCommand {
private @NonNull final CarbonChat carbonChat;
public ReplyCommand(@NonNull final CommandManager<ChatUser> commandManager) {
public ReplyCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("reply");
@@ -26,16 +27,16 @@ public class ReplyCommand {
commandManager.command(
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
commandManager.createDefaultCommandMeta())
.withSenderType(ChatUser.class) // player
.withSenderType(PlayerUser.class) // player
.withPermission("carbonchat.reply")
.argument(StringArgument.<ChatUser>newBuilder("message").greedy().build())
.argument(StringArgument.<CarbonUser>newBuilder("message").greedy().build())
.handler(this::reply)
.build()
);
}
private void reply(@NonNull final CommandContext<ChatUser> context) {
final ChatUser user = context.getSender();
private void reply(@NonNull final CommandContext<CarbonUser> context) {
final PlayerUser user = (PlayerUser)context.getSender();
final String input = context.getRequired("message");
if (input.isEmpty()) {
@@ -56,7 +57,7 @@ public class ReplyCommand {
return;
}
final ChatUser targetUser = this.carbonChat.userService().wrap(user.replyTarget());
final PlayerUser targetUser = this.carbonChat.userService().wrap(user.replyTarget());
targetUser.sendMessage(user, input);
}
@@ -4,8 +4,9 @@ import com.intellectualsites.commands.CommandManager;
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.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.api.commands.settings.CommandSettings;
import net.draycia.carbon.api.users.PlayerUser;
import net.draycia.carbon.api.users.UserChannelSettings;
import net.kyori.adventure.text.format.TextColor;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -14,7 +15,7 @@ public class SetColorCommand {
private @NonNull final CarbonChat carbonChat;
public SetColorCommand(@NonNull final CommandManager<ChatUser> commandManager) {
public SetColorCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("setcolor");
@@ -28,11 +29,12 @@ public class SetColorCommand {
commandManager.command(
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
commandManager.createDefaultCommandMeta())
.withSenderType(ChatUser.class) // player
.withSenderType(PlayerUser.class) // player
.withPermission("carbonchat.setcolor")
// TODO: colorArgument
//.argument(CommandUtils.colorArgument())
.handler(context -> {
final ChatUser user = context.getSender();
final PlayerUser user = (PlayerUser)context.getSender();
final TextColor color = context.getRequired("color");
if (!user.hasPermission("carbonchat.setcolor." + channel.key())) {
@@ -4,8 +4,9 @@ import com.intellectualsites.commands.CommandManager;
import com.intellectualsites.commands.context.CommandContext;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.api.commands.settings.CommandSettings;
import net.draycia.carbon.api.users.PlayerUser;
import net.draycia.carbon.common.utils.CommandUtils;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -14,7 +15,7 @@ public class ShadowMuteCommand {
private @NonNull final CarbonChat carbonChat;
public ShadowMuteCommand(@NonNull final CommandManager<ChatUser> commandManager) {
public ShadowMuteCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("shadowmute");
@@ -26,7 +27,7 @@ public class ShadowMuteCommand {
commandManager.command(
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
commandManager.createDefaultCommandMeta())
.withSenderType(ChatUser.class) // player
.withSenderType(CarbonUser.class) // player & console
.withPermission("carbonchat.shadowmute")
.argument(CommandUtils.chatUserArgument())
.handler(this::shadowMute)
@@ -34,12 +35,12 @@ public class ShadowMuteCommand {
);
}
private void shadowMute(@NonNull final CommandContext<ChatUser> context) {
final ChatUser user = context.getSender();
final ChatUser target = context.getRequired("user");
private void shadowMute(@NonNull final CommandContext<CarbonUser> context) {
final CarbonUser user = context.getSender();
final PlayerUser target = context.getRequired("user");
if (user.shadowMuted()) {
user.shadowMuted(false);
if (target.shadowMuted()) {
target.shadowMuted(false);
final String format = this.carbonChat.translations().noLongerShadowMuted();
final Component message = this.carbonChat.messageProcessor().processMessage(format,
@@ -53,7 +54,7 @@ public class ShadowMuteCommand {
if (target.hasPermission("carbonchat.mute.exempt")) {
format = this.carbonChat.translations().shadowMuteExempt();
} else {
user.shadowMuted(true);
target.shadowMuted(true);
format = this.carbonChat.translations().nowShadowMuted();
}
@@ -7,8 +7,9 @@ import com.intellectualsites.commands.context.CommandContext;
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.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.api.commands.settings.CommandSettings;
import net.draycia.carbon.api.users.PlayerUser;
import net.draycia.carbon.api.users.UserChannelSettings;
import net.draycia.carbon.common.utils.CommandUtils;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -17,7 +18,7 @@ public class SpyChannelCommand {
private @NonNull final CarbonChat carbonChat;
public SpyChannelCommand(@NonNull final CommandManager<ChatUser> commandManager) {
public SpyChannelCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("spy");
@@ -30,7 +31,7 @@ public class SpyChannelCommand {
commandManager.command(
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
commandManager.createDefaultCommandMeta())
.withSenderType(ChatUser.class) // player
.withSenderType(PlayerUser.class) // player
.withPermission("carbonchat.spy")
.argument(CommandUtils.channelArgument())
.handler(this::spyChannel)
@@ -40,7 +41,7 @@ public class SpyChannelCommand {
commandManager.command(
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
commandManager.createDefaultCommandMeta())
.withSenderType(ChatUser.class) // player
.withSenderType(PlayerUser.class) // player
.withPermission("carbonchat.spy")
.argument(StaticArgument.required("whispers"))
.handler(this::spyWhispers)
@@ -50,7 +51,7 @@ public class SpyChannelCommand {
commandManager.command(
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
commandManager.createDefaultCommandMeta())
.withSenderType(ChatUser.class) // player
.withSenderType(PlayerUser.class) // player
.withPermission("carbonchat.spy")
.argument(StaticArgument.required("everything"))
.argument(BooleanArgument.required("enabled"))
@@ -59,8 +60,8 @@ public class SpyChannelCommand {
);
}
private void spyChannel(@NonNull final CommandContext<ChatUser> context) {
final ChatUser user = context.getSender();
private void spyChannel(@NonNull final CommandContext<CarbonUser> context) {
final PlayerUser user = (PlayerUser)context.getSender();
final ChatChannel chatChannel = context.getRequired("channel");
final String message;
@@ -79,8 +80,8 @@ public class SpyChannelCommand {
"color", "<color:" + chatChannel.channelColor(user).toString() + ">", "channel", chatChannel.name()));
}
private void spyWhispers(@NonNull final CommandContext<ChatUser> context) {
final ChatUser user = context.getSender();
private void spyWhispers(@NonNull final CommandContext<CarbonUser> context) {
final PlayerUser user = (PlayerUser)context.getSender();
final String message;
@@ -95,8 +96,8 @@ public class SpyChannelCommand {
user.sendMessage(this.carbonChat.messageProcessor().processMessage(message));
}
private void spyEverything(@NonNull final CommandContext<ChatUser> context) {
final ChatUser user = context.getSender();
private void spyEverything(@NonNull final CommandContext<CarbonUser> context) {
final PlayerUser user = (PlayerUser)context.getSender();
final Boolean shouldSpy = context.getRequired("enabled");
final String message;
@@ -6,7 +6,7 @@ import com.intellectualsites.commands.context.CommandContext;
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.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.api.commands.settings.CommandSettings;
import net.draycia.carbon.common.utils.CommandUtils;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -15,7 +15,7 @@ public class SudoChannelCommand {
private @NonNull final CarbonChat carbonChat;
public SudoChannelCommand(@NonNull final CommandManager<ChatUser> commandManager) {
public SudoChannelCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("sudochannel");
@@ -27,11 +27,11 @@ public class SudoChannelCommand {
commandManager.command(
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
commandManager.createDefaultCommandMeta())
.withSenderType(ChatUser.class) // player
.withSenderType(CarbonUser.class) // player
.withPermission("carbonchat.channel.others.message")
.argument(CommandUtils.chatUserArgument())
.argument(CommandUtils.channelArgument())
.argument(StringArgument.<ChatUser>newBuilder("message").greedy().asOptional().build())
.argument(StringArgument.<CarbonUser>newBuilder("message").greedy().asOptional().build())
.handler(context -> {
if (context.get("message").isPresent()) {
this.sendMessageOther(context);
@@ -43,9 +43,9 @@ public class SudoChannelCommand {
);
}
private void otherChannel(@NonNull final CommandContext<ChatUser> context) {
final ChatUser sender = context.getSender();
final ChatUser user = context.getRequired("user");
private void otherChannel(@NonNull final CommandContext<CarbonUser> context) {
final CarbonUser sender = context.getSender();
final CarbonUser user = context.getRequired("user");
final ChatChannel channel = context.getRequired("channel");
user.selectedChannel(channel);
@@ -62,8 +62,8 @@ public class SudoChannelCommand {
"player", user.name()));
}
private void sendMessageOther(@NonNull final CommandContext<ChatUser> context) {
final ChatUser user = context.getRequired("user");
private void sendMessageOther(@NonNull final CommandContext<CarbonUser> context) {
final CarbonUser user = context.getRequired("user");
final ChatChannel channel = context.getRequired("channel");
final String message = context.getRequired("message");
@@ -5,8 +5,9 @@ import com.intellectualsites.commands.context.CommandContext;
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.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.api.commands.settings.CommandSettings;
import net.draycia.carbon.api.users.PlayerUser;
import net.draycia.carbon.api.users.UserChannelSettings;
import net.draycia.carbon.common.utils.CommandUtils;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -15,7 +16,7 @@ public class ToggleCommand {
private @NonNull final CarbonChat carbonChat;
public ToggleCommand(@NonNull final CommandManager<ChatUser> commandManager) {
public ToggleCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("toggle");
@@ -27,14 +28,14 @@ public class ToggleCommand {
commandManager.command(
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
commandManager.createDefaultCommandMeta())
.withSenderType(ChatUser.class) // player & console
.withSenderType(CarbonUser.class) // player & console
.withPermission("carbonchat.toggle")
.argument(CommandUtils.channelArgument())
.argument(CommandUtils.optionalChatUserArgument()) // carbonchat.toggle.other
.handler(context -> {
if (context.get("user").isPresent()) {
this.toggleOther(context);
} else {
} else if (context.getSender() instanceof PlayerUser) {
this.toggleSelf(context);
}
})
@@ -42,8 +43,8 @@ public class ToggleCommand {
);
}
private void toggleSelf(@NonNull final CommandContext<ChatUser> context) {
final ChatUser user = context.getSender();
private void toggleSelf(@NonNull final CommandContext<CarbonUser> context) {
final PlayerUser user = (PlayerUser)context.getSender();
final ChatChannel channel = context.getRequired("channel");
final String message;
@@ -64,9 +65,9 @@ public class ToggleCommand {
"color", "<color:" + channel.channelColor(user).toString() + ">", "channel", channel.name()));
}
private void toggleOther(@NonNull final CommandContext<ChatUser> context) {
final ChatUser sender = context.getSender();
final ChatUser user = context.getRequired("user");
private void toggleOther(@NonNull final CommandContext<CarbonUser> context) {
final CarbonUser sender = context.getSender();
final PlayerUser user = context.getRequired("user");
final ChatChannel channel = context.getRequired("channel");
final String message;
@@ -1,7 +1,7 @@
package net.draycia.carbon.common.commands.misc;
import com.intellectualsites.commands.CommandManager;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.common.commands.ChannelCommand;
import net.draycia.carbon.common.commands.ChannelListCommand;
import net.draycia.carbon.common.commands.ChatReloadCommand;
@@ -25,7 +25,7 @@ public final class CommandRegistrar {
}
public static void registerCommands(@NonNull final CommandManager<ChatUser> commandManager) {
public static void registerCommands(@NonNull final CommandManager<CarbonUser> commandManager) {
new ChannelCommand(commandManager);
new ChannelListCommand(commandManager);
new ChatReloadCommand(commandManager);
@@ -5,7 +5,7 @@ import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.events.UserEvent;
import net.draycia.carbon.api.events.misc.CarbonEvents;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
public class PlayerJoinListener {
@@ -13,7 +13,7 @@ public class PlayerJoinListener {
final CarbonChat carbonChat = CarbonChatProvider.carbonChat();
CarbonEvents.register(UserEvent.Join.class, event -> {
final ChatUser user = event.user();
final CarbonUser user = event.user();
carbonChat.userService().validate(user);
@@ -3,7 +3,7 @@ package net.draycia.carbon.common.messaging;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import net.draycia.carbon.api.messaging.MessageService;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.UUID;
@@ -13,7 +13,7 @@ import java.util.function.Consumer;
public class EmptyMessageService implements MessageService {
@Override
public void registerUserMessageListener(@NonNull final String key, @NonNull final BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener) {
public void registerUserMessageListener(@NonNull final String key, @NonNull final BiConsumer<@NonNull CarbonUser, @NonNull ByteArrayDataInput> listener) {
// do nothing
}
@@ -5,7 +5,7 @@ import net.draycia.carbon.api.channels.TextChannel;
import net.draycia.carbon.api.messaging.MessageService;
import com.google.common.io.ByteArrayDataOutput;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -88,7 +88,7 @@ public class MessageManager {
this.messageService().registerUUIDMessageListener("channel-component", (uuid, byteArray) -> {
final ChatChannel channel = this.carbonChat.channelRegistry().get(byteArray.readUTF());
final ChatUser user = this.carbonChat.userService().wrap(uuid);
final CarbonUser user = this.carbonChat.userService().wrap(uuid);
if (channel instanceof TextChannel) {
final Component component = this.carbonChat.gsonSerializer().deserialize(byteArray.readUTF());
@@ -102,7 +102,7 @@ public class MessageManager {
this.messageService().registerUUIDMessageListener("whisper-component", (uuid, byteArray) -> {
final UUID recipient = new UUID(byteArray.readLong(), byteArray.readLong());
final ChatUser target = this.carbonChat.userService().wrap(recipient);
final CarbonUser target = this.carbonChat.userService().wrap(recipient);
final String message = byteArray.readUTF();
if (!target.ignoringUser(uuid)) {
@@ -9,7 +9,7 @@ import io.lettuce.core.pubsub.StatefulRedisPubSubConnection;
import io.lettuce.core.pubsub.api.sync.RedisPubSubCommands;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.messaging.MessageService;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.api.config.RedisCredentials;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -22,7 +22,7 @@ import java.util.function.Consumer;
public class RedisMessageService implements MessageService {
private @NonNull final Map<@NonNull String, @NonNull BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput>> userLoadedListeners = new HashMap<>();
private @NonNull final Map<@NonNull String, @NonNull BiConsumer<@NonNull CarbonUser, @NonNull ByteArrayDataInput>> userLoadedListeners = new HashMap<>();
private @NonNull final Map<@NonNull String, @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput>> userNotLoadedListeners = new HashMap<>();
@@ -68,10 +68,10 @@ public class RedisMessageService implements MessageService {
}
private void receiveMessage(@NonNull final UUID uuid, @NonNull final String key, @NonNull final ByteArrayDataInput value) {
final ChatUser user = this.carbonChat.userService().wrapIfLoaded(uuid);
final CarbonUser user = this.carbonChat.userService().wrapIfLoaded(uuid);
if (user != null) {
for (final Map.Entry<String, BiConsumer<ChatUser, ByteArrayDataInput>> listener : this.userLoadedListeners.entrySet()) {
for (final Map.Entry<String, BiConsumer<CarbonUser, ByteArrayDataInput>> listener : this.userLoadedListeners.entrySet()) {
if (key.equals(listener.getKey())) {
listener.getValue().accept(user, value);
}
@@ -86,7 +86,7 @@ public class RedisMessageService implements MessageService {
}
@Override
public void registerUserMessageListener(@NonNull final String key, @NonNull final BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener) {
public void registerUserMessageListener(@NonNull final String key, @NonNull final BiConsumer<@NonNull CarbonUser, @NonNull ByteArrayDataInput> listener) {
this.userLoadedListeners.put(key, listener);
this.subscribeSync.subscribe(key);
}
@@ -9,7 +9,7 @@ import com.google.gson.GsonBuilder;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.api.users.UserService;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -26,7 +26,7 @@ import java.util.concurrent.ExecutionException;
import java.util.function.Function;
import java.util.function.Supplier;
public class JSONUserService<T extends ChatUser> implements UserService<T> {
public class JSONUserService<T extends CarbonUser> implements UserService<T> {
private @NonNull final CarbonChat carbonChat;
private @NonNull final Gson gson = new GsonBuilder().setPrettyPrinting().create();
@@ -39,7 +39,7 @@ public class JSONUserService<T extends ChatUser> implements UserService<T> {
.removalListener(this::saveUser)
.build(CacheLoader.from(this::loadUser));
public JSONUserService(@NonNull final Class<? extends ChatUser> userType,
public JSONUserService(@NonNull final Class<? extends CarbonUser> userType,
@NonNull final CarbonChat carbonChat,
@NonNull final Supplier<@NonNull Iterable<@NonNull T>> supplier,
@NonNull final Function<UUID, T> userFactory,
@@ -13,7 +13,7 @@ import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.cache.RemovalNotification;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.api.users.UserService;
import net.draycia.carbon.api.config.SQLCredentials;
import net.kyori.adventure.text.format.TextColor;
@@ -31,7 +31,7 @@ import java.util.concurrent.ExecutionException;
import java.util.function.Function;
import java.util.function.Supplier;
public class MySQLUserService<T extends ChatUser> implements UserService<T> {
public class MySQLUserService<T extends CarbonUser> implements UserService<T> {
private @NonNull final CarbonChat carbonChat;
private @NonNull final Database database;
@@ -1,6 +1,6 @@
package net.draycia.carbon.common.utils;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.TextDecoration;
@@ -21,7 +21,7 @@ public final class ColorUtils {
return parseColor(null, input);
}
public @Nullable static TextColor parseColor(@Nullable final ChatUser user, @Nullable String input) {
public @Nullable static TextColor parseColor(@Nullable final CarbonUser user, @Nullable String input) {
if (input == null || input.isEmpty()) {
return NamedTextColor.WHITE;
}
@@ -6,7 +6,7 @@ import com.intellectualsites.commands.context.CommandContext;
import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.channels.TextChannel;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.api.users.UserService;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -19,8 +19,8 @@ public final class CommandUtils {
}
// TODO: turn this into a proper class that handles suggestions
public static CommandArgument<ChatUser, TextChannel> channelArgument() {
return CommandArgument.<ChatUser, TextChannel>ofType(TextChannel.class, "channel")
public static CommandArgument<CarbonUser, TextChannel> channelArgument() {
return CommandArgument.<CarbonUser, TextChannel>ofType(TextChannel.class, "channel")
.asRequired()
.withParser((c, i) -> {
final String input = i.poll();
@@ -44,22 +44,22 @@ public final class CommandUtils {
.build();
}
public static CommandArgument<ChatUser, ChatUser> optionalChatUserArgument() {
return CommandArgument.<ChatUser, ChatUser>ofType(ChatUser.class, "user")
public static CommandArgument<CarbonUser, CarbonUser> optionalChatUserArgument() {
return CommandArgument.<CarbonUser, CarbonUser>ofType(CarbonUser.class, "user")
.asOptional()
.withParser(CommandUtils::parse)
.build();
}
// TODO: turn this into a proper class that handles suggestions
public static CommandArgument<ChatUser, ChatUser> chatUserArgument() {
return CommandArgument.<ChatUser, ChatUser>ofType(ChatUser.class, "user")
public static CommandArgument<CarbonUser, CarbonUser> chatUserArgument() {
return CommandArgument.<CarbonUser, CarbonUser>ofType(CarbonUser.class, "user")
.asRequired()
.withParser(CommandUtils::parse)
.build();
}
private static @NonNull ArgumentParseResult<ChatUser> parse(final CommandContext<ChatUser> c, final Queue<String> i) {
private static @NonNull ArgumentParseResult<CarbonUser> parse(final CommandContext<CarbonUser> c, final Queue<String> i) {
final String input = i.poll();
if (input == null) {
@@ -67,7 +67,7 @@ public final class CommandUtils {
}
final UserService<?> userService = CarbonChatProvider.carbonChat().userService();
final ChatUser user = userService.wrap(userService.resolve(input));
final CarbonUser user = userService.wrap(userService.resolve(input));
if (user != null) {
return ArgumentParseResult.success(user);